Browse Source

Ensure `weed fuse` master process exits after mounted (#6809)

* Ensure fuse master process wait for mounted

* Validate parent PID input in fuse command
pull/6811/head
Weihao Jiang 2 weeks ago
committed by GitHub
parent
commit
874b4a5535
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 23
      weed/command/fuse.go
  2. 2
      weed/command/mount.go
  3. 10
      weed/command/mount_std.go

23
weed/command/fuse.go

@ -2,9 +2,12 @@ package command
import ( import (
"fmt" "fmt"
"math"
"os" "os"
"os/signal"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
) )
@ -105,6 +108,14 @@ func runFuse(cmd *Command, args []string) bool {
switch parameter.name { switch parameter.name {
case "child": case "child":
masterProcess = false 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": case "arg0":
mountOptions.dir = &parameter.value mountOptions.dir = &parameter.value
case "filer": case "filer":
@ -211,7 +222,12 @@ func runFuse(cmd *Command, args []string) bool {
panic(err) 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 := os.ProcAttr{}
attr.Env = os.Environ() 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)) panic(fmt.Errorf("master process can not release child process: %s", err))
} }
return true
select {
case <-c:
return true
}
} }
if fusermountPath != "" { if fusermountPath != "" {

2
weed/command/mount.go

@ -34,6 +34,7 @@ type MountOptions struct {
localSocket *string localSocket *string
disableXAttr *bool disableXAttr *bool
extraOptions []string extraOptions []string
fuseCommandPid int
} }
var ( var (
@ -72,6 +73,7 @@ func init() {
mountOptions.debugPort = cmdMount.Flag.Int("debug.port", 6061, "http port for debugging") 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.localSocket = cmdMount.Flag.String("localSocket", "", "default to /tmp/seaweedfs-mount-<mount_dir_hash>.sock")
mountOptions.disableXAttr = cmdMount.Flag.Bool("disableXAttr", false, "disable xattr") mountOptions.disableXAttr = cmdMount.Flag.Bool("disableXAttr", false, "disable xattr")
mountOptions.fuseCommandPid = 0
mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file") mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file")
mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file") mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file")

10
weed/command/mount_std.go

@ -13,6 +13,7 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
@ -268,6 +269,15 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
unmount.Unmount(dir) 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() grpcS := pb.NewGrpcServer()
mount_pb.RegisterSeaweedMountServer(grpcS, seaweedFileSystem) mount_pb.RegisterSeaweedMountServer(grpcS, seaweedFileSystem)
reflection.Register(grpcS) reflection.Register(grpcS)

Loading…
Cancel
Save