From d61405b3ca9c34022921d1af48ff704da75b8ae3 Mon Sep 17 00:00:00 2001 From: Roman Vanicek Date: Tue, 19 Mar 2024 20:12:23 +0100 Subject: [PATCH] Fix missing snapshot mount directory. --- main.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 231b641..1cb2e9e 100644 --- a/main.go +++ b/main.go @@ -327,8 +327,8 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) if expectedSnapshots, err := generateSnapshotsFromRulesForNow(strings.TrimSpace(string(snapshotRulesB))); err == nil { log.WithFields(log.Fields{"name": r.Name, "expectedSnapshots": expectedSnapshots}).Trace("Expected snapshots") if existingSnapshotsB, err := applyEnv(exec.Command("/sbin/mount.objectivefs", "list", "-sz", v.Fs), v.Env).Output(); err == nil { - log.WithFields(log.Fields{"name": r.Name, "existingSnapshots": existingSnapshotsB}).Trace("Existing snapshots") if existingSnapshots, err := parseExistingSnapshots(string(existingSnapshotsB), v.Fs); err == nil { + log.WithFields(log.Fields{"name": r.Name, "existingSnapshots": existingSnapshots}).Trace("Existing snapshots") if existingMounts, err := getMountedSnaphots(snapshotsPath); err == nil { log.WithFields(log.Fields{"name": r.Name, "existingMounts": existingMounts}).Trace("Existing snapshot mounts") @@ -357,11 +357,15 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) // Add new mounts for i, name := range setMinus(setIntersect(existingSnapshots, expectedSnapshots), existingMounts) { dest := filepath.Join(snapshotsPath, i) - // Note: There is a missing "mount" argument so the mount continues running in a background process - if err := applyEnv(exec.Command("/sbin/mount.objectivefs", name, dest), v.Env).Run(); err != nil { - log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to mount a new snapshot.") + if err := os.Mkdir(dest, os.ModePerm); err == nil || os.IsExist(err) { + // Note: There is a missing "mount" argument so the mount continues running in a background process + if err := applyEnv(exec.Command("/sbin/mount.objectivefs", name, dest), v.Env).Run(); err != nil { + log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to mount a new snapshot.") + } else { + log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Debug("Snapshot mounted.") + } } else { - log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Debug("Snapshot mounted.") + log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to create directory for a snapshot.") } } } else {