Fix snapshot unmount order. Fix setMinus.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-03-19 19:44:49 +01:00
parent 649ddabe08
commit 474470c6d8

21
main.go
View File

@@ -331,15 +331,6 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
if existingSnapshots, err := parseExistingSnapshots(string(existingSnapshotsB), v.Fs); err == nil {
if existingMounts, err := getMountedSnaphots(snapshotsPath); err == nil {
log.WithFields(log.Fields{"name": r.Name, "existingMounts": existingMounts}).Trace("Existing snapshot mounts")
// Destroy old snapshots
for i, name := range setMinus(existingSnapshots, expectedSnapshots) {
expectedOutput := "Snapshot '" + name + "' destroyed."
if output, err := applyEnv(exec.Command("/sbin/mount.objectivefs", "destroy", name, "-f"), v.Env).Output(); err != nil || strings.TrimSpace(string(output)) != expectedOutput {
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to destroy an expired snapshot.")
} else {
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Debug("Snapshot destroyed.")
}
}
// Remove mounts of expired snapshots
for i, path := range setMinus(existingMounts, expectedSnapshots) {
@@ -353,6 +344,16 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
}
}
// Destroy old snapshots
for i, name := range setMinus(existingSnapshots, expectedSnapshots) {
expectedOutput := "Snapshot '" + name + "' destroyed."
if output, err := applyEnv(exec.Command("/sbin/mount.objectivefs", "destroy", name, "-f"), v.Env).Output(); err != nil || strings.TrimSpace(string(output)) != expectedOutput {
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to destroy an expired snapshot.")
} else {
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Debug("Snapshot destroyed.")
}
}
// Add new mounts
for i, name := range setMinus(setIntersect(existingSnapshots, expectedSnapshots), existingMounts) {
dest := filepath.Join(snapshotsPath, i)
@@ -655,7 +656,7 @@ func isObjectiveFsMount(path string) (bool, error) {
func setMinus[TKey comparable, TValue any, TValue2 any](a map[TKey]TValue, b map[TKey]TValue2) map[TKey]TValue {
var result = make(map[TKey]TValue)
for i, j := range a {
if _, contains := b[i]; contains {
if _, contains := b[i]; !contains {
result[i] = j
}
}