forked from Ivasoft/objectivefs-docker-volume
Use tmpfs for snapshots
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
20
main.go
20
main.go
@@ -183,6 +183,12 @@ func umount(v *ofsVolume, rt *ofsVolumeRt) error {
|
||||
log.WithFields(log.Fields{"name": v.Volume.Name, "snapshot": i}).Trace("Snapshot unmounted on unmount.")
|
||||
}
|
||||
}
|
||||
|
||||
if err := exec.Command("umount", snapshotsPath).Run(); err != nil {
|
||||
log.WithFields(log.Fields{"name": v.Volume.Name}).Warn("Failed to unmount a snapshots tmpfs on unmount.")
|
||||
} else {
|
||||
log.WithFields(log.Fields{"name": v.Volume.Name}).Trace("Snapshot tmpfs unmounted on unmount.")
|
||||
}
|
||||
} else {
|
||||
log.WithFields(log.Fields{"name": v.Volume.Name, "Error": err}).Warn("Cannot determine existing snapshot mounts on unmount")
|
||||
}
|
||||
@@ -339,6 +345,12 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
|
||||
}
|
||||
}
|
||||
|
||||
// Mount a tmpfs there so it becomes machine specific and we can promptly delete directories
|
||||
// that are outside of filteredSnapshots
|
||||
if err := exec.Command("/bin/mount", "-t", "tmpfs", "-o", "size=8m", "tmpfs", snapshotsPath).Run(); err != nil {
|
||||
log.WithFields(log.Fields{"name": r.Name, "directory": snapshotsDirectory}).Warn("Failed to create tmpfs in the snapshots mount directory.")
|
||||
}
|
||||
|
||||
for cmd.ProcessState == nil {
|
||||
if snapshotRulesB, err := applyEnv(exec.Command("/sbin/mount.objectivefs", "snapshot", "-l", v.Fs), v.Env).Output(); err == nil {
|
||||
log.WithFields(log.Fields{"name": r.Name, "snapshotRules": string(snapshotRulesB)}).Debug("Current snapshot rules")
|
||||
@@ -367,8 +379,6 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
|
||||
}
|
||||
|
||||
// Unmount snapshots that are no longer in filteredSnapshots to conserve RAM
|
||||
// Note: We cannot remove the directory as other machines may have different
|
||||
// filteredSnapshots and may be using them.
|
||||
for i, path := range setMinus(existingMounts, setIntersect(expectedSnapshots, filteredSnapshots)) {
|
||||
if err := exec.Command("umount", path).Run(); err != nil {
|
||||
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to unmount an expired snapshot.")
|
||||
@@ -378,9 +388,9 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
|
||||
}
|
||||
|
||||
// Remove left-over dirs of expired snapshots
|
||||
// Note: That is directories that no other machine would use as the snapshots are not
|
||||
// mounted due to filteredSnapshots but because they are not even in expectedSnapshots.
|
||||
for i, path := range setMinus(existingMountDirs, expectedSnapshots) {
|
||||
// Note: As our root shall be on tmpfs deleting the directories does not affect
|
||||
// other machines with different filteredSnapshots
|
||||
for i, path := range setMinus(existingMountDirs, setIntersect(expectedSnapshots, filteredSnapshots)) {
|
||||
if err := os.Remove(path); err != nil {
|
||||
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to remove directory of an expired snapshot.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user