aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeihao Jiang <weihau.chiang@gmail.com>2025-05-23 00:50:07 +0800
committerGitHub <noreply@github.com>2025-05-22 09:50:07 -0700
commit874b4a553594e94b1b21f7f09c1c9a618a3fac78 (patch)
treeb721c2c06d4fdb76ec6ae26ae387671ab72eaab4
parent165af32d6b738daa14b84fb6e3c8891f4b46135b (diff)
downloadseaweedfs-874b4a553594e94b1b21f7f09c1c9a618a3fac78.tar.xz
seaweedfs-874b4a553594e94b1b21f7f09c1c9a618a3fac78.zip
Ensure `weed fuse` master process exits after mounted (#6809)
* Ensure fuse master process wait for mounted * Validate parent PID input in fuse command
-rw-r--r--weed/command/fuse.go23
-rw-r--r--weed/command/mount.go2
-rw-r--r--weed/command/mount_std.go10
3 files changed, 33 insertions, 2 deletions
diff --git a/weed/command/fuse.go b/weed/command/fuse.go
index beed3349e..92ccf4673 100644
--- a/weed/command/fuse.go
+++ b/weed/command/fuse.go
@@ -2,9 +2,12 @@ package command
import (
"fmt"
+ "math"
"os"
+ "os/signal"
"strconv"
"strings"
+ "syscall"
"time"
)
@@ -105,6 +108,14 @@ func runFuse(cmd *Command, args []string) bool {
switch parameter.name {
case "child":
masterProcess = false
+ if parsed, err := strconv.ParseInt(parameter.value, 10, 64); err == nil {
+ if parsed > math.MaxInt || parsed <= 0 {
+ panic(fmt.Errorf("parent PID %s is invalid", err))
+ }
+ mountOptions.fuseCommandPid = int(parsed)
+ } else {
+ panic(fmt.Errorf("parent PID %s is invalid", err))
+ }
case "arg0":
mountOptions.dir = &parameter.value
case "filer":
@@ -211,7 +222,12 @@ func runFuse(cmd *Command, args []string) bool {
panic(err)
}
- argv := append(os.Args, "-o", "child")
+ // pass our PID to the child process
+ pid := os.Getpid()
+ argv := append(os.Args, "-o", "child="+strconv.Itoa(pid))
+
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, syscall.SIGUSR1)
attr := os.ProcAttr{}
attr.Env = os.Environ()
@@ -228,7 +244,10 @@ func runFuse(cmd *Command, args []string) bool {
panic(fmt.Errorf("master process can not release child process: %s", err))
}
- return true
+ select {
+ case <-c:
+ return true
+ }
}
if fusermountPath != "" {
diff --git a/weed/command/mount.go b/weed/command/mount.go
index 4fbcc0505..21e49f236 100644
--- a/weed/command/mount.go
+++ b/weed/command/mount.go
@@ -34,6 +34,7 @@ type MountOptions struct {
localSocket *string
disableXAttr *bool
extraOptions []string
+ fuseCommandPid int
}
var (
@@ -72,6 +73,7 @@ func init() {
mountOptions.debugPort = cmdMount.Flag.Int("debug.port", 6061, "http port for debugging")
mountOptions.localSocket = cmdMount.Flag.String("localSocket", "", "default to /tmp/seaweedfs-mount-<mount_dir_hash>.sock")
mountOptions.disableXAttr = cmdMount.Flag.Bool("disableXAttr", false, "disable xattr")
+ mountOptions.fuseCommandPid = 0
mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file")
mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file")
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index 631091e80..c419d5697 100644
--- a/weed/command/mount_std.go
+++ b/weed/command/mount_std.go
@@ -13,6 +13,7 @@ import (
"runtime"
"strconv"
"strings"
+ "syscall"
"time"
"github.com/hanwen/go-fuse/v2/fuse"
@@ -268,6 +269,15 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
unmount.Unmount(dir)
})
+ if mountOptions.fuseCommandPid != 0 {
+ // send a signal to the parent process to notify that the mount is ready
+ err = syscall.Kill(mountOptions.fuseCommandPid, syscall.SIGUSR1)
+ if err != nil {
+ fmt.Printf("failed to notify parent process: %v\n", err)
+ return false
+ }
+ }
+
grpcS := pb.NewGrpcServer()
mount_pb.RegisterSeaweedMountServer(grpcS, seaweedFileSystem)
reflection.Register(grpcS)