From 474470c6d8a8a03c1c87d4ebc1ef61dff6cdda8a Mon Sep 17 00:00:00 2001 From: Roman Vanicek Date: Tue, 19 Mar 2024 19:44:49 +0100 Subject: [PATCH] Fix snapshot unmount order. Fix setMinus. --- main.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 33aeb79..231b641 100644 --- a/main.go +++ b/main.go @@ -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 } }