From f6b91fd742484e2285bb8476d4cb1ac839af0328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Van=C3=AD=C4=8Dek?= Date: Fri, 2 Jun 2023 00:22:03 +0200 Subject: [PATCH] Verify mount appears as containers wrote to unmounted directories. --- main.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index a565820..423e478 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ import ( "os/user" "path/filepath" "strconv" + "strings" "sync" "time" @@ -275,13 +276,23 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) return &volume.MountResponse{}, fmt.Errorf("unexpected error mounting '%s' error: %s", r.Name, err.Error()) } - // The drawback of running the mount in the foreground is there is no way to tell if it failed - // to initially connect. So we just wait a fixed amount of time and check for process exit. - time.Sleep(1 * time.Second) - if cmd.ProcessState != nil { - // The process has exited so consider an error occured - log.WithFields(log.Fields{"name": r.Name, "exitStatus": cmd.ProcessState.ExitCode()}).Error("Volume mount failed") - return &volume.MountResponse{}, fmt.Errorf("unexpected error mounting '%s' exist status: %v", r.Name, cmd.ProcessState.ExitCode()) + // The drawback of running the mount in the foreground is there is no easy way to tell if it failed + // to initially connect. So we just wait a fixed amount of time and check for process exit or mount + // success. + for { + // Check for process exit + time.Sleep(100 * time.Millisecond) + if cmd.ProcessState != nil { + // The process has exited so consider an error occured + log.WithFields(log.Fields{"name": r.Name, "exitStatus": cmd.ProcessState.ExitCode()}).Error("Volume mount failed") + return &volume.MountResponse{}, fmt.Errorf("unexpected error mounting '%s' exist status: %v", r.Name, cmd.ProcessState.ExitCode()) + } + + // Check for mount + mount := exec.Command("df", "--output=fstype", v.Volume.Mountpoint) + if out, err := mount.CombinedOutput(); err == nil && strings.Index(string(out), "fuse.objectivefs") >= 0 { + break + } } log.WithFields(log.Fields{"name": r.Name}).Info("Volume mounted")