From 7295525c80625b5503ffda4df75595c3ccaf9a94 Mon Sep 17 00:00:00 2001 From: Weiwei Date: Tue, 6 Aug 2024 10:32:01 +0800 Subject: [PATCH] get fuse fd from csi (#4991) Signed-off-by: weiwei --- cmd/mount_unix.go | 9 ++++++++- cmd/passfd.go | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/mount_unix.go b/cmd/mount_unix.go index 16105f8aeb38..2ebbee7f092b 100644 --- a/cmd/mount_unix.go +++ b/cmd/mount_unix.go @@ -43,12 +43,13 @@ import ( "time" "github.com/juicedata/godaemon" + "github.com/urfave/cli/v2" + "github.com/juicedata/juicefs/pkg/fuse" "github.com/juicedata/juicefs/pkg/meta" "github.com/juicedata/juicefs/pkg/object" "github.com/juicedata/juicefs/pkg/utils" "github.com/juicedata/juicefs/pkg/vfs" - "github.com/urfave/cli/v2" ) func showThreadStack(agentAddr string) { @@ -418,6 +419,9 @@ func genFuseOpt(c *cli.Context, name string) string { } func prepareMp(mp string) { + if csiCommPath != "" { + return + } var fi os.FileInfo var ino uint64 err := utils.WithTimeout(func() error { @@ -515,6 +519,9 @@ func shutdownGraceful(mp string) { } func canShutdownGracefully(mp string, newConf *vfs.Config) bool { + if csiCommPath != "" { + return false + } var ino uint64 var err error err = utils.WithTimeout(func() error { diff --git a/cmd/passfd.go b/cmd/passfd.go index 95bbc7adc5a0..eed338053f95 100644 --- a/cmd/passfd.go +++ b/cmd/passfd.go @@ -100,6 +100,7 @@ var fuseMu sync.Mutex var fuseFd int = 0 var fuseSetting = []byte("FUSE") var serverAddress string = fmt.Sprintf("/tmp/fuse_fd_comm.%d", os.Getpid()) +var csiCommPath = os.Getenv("JFS_SUPER_COMM") func handleFDRequest(conn *net.UnixConn) { defer conn.Close() @@ -132,6 +133,12 @@ func handleFDRequest(conn *net.UnixConn) { logger.Debugf("recv FUSE fd: %d", fds[0]) fuseFd = fds[0] fuseSetting = msg + if csiCommPath != "" { + err = sendFuseFd(csiCommPath, fuseSetting, fuseFd) + if err != nil { + logger.Warnf("send fd to %s: %v", csiCommPath, err) + } + } } else { for _, fd := range fds { _ = syscall.Close(fd) @@ -142,6 +149,12 @@ func handleFDRequest(conn *net.UnixConn) { } func serveFuseFD(path string) { + if csiCommPath != "" { + fd, fSetting := getFuseFd(csiCommPath) + if fd > 0 { + fuseFd, fuseSetting = fd, fSetting + } + } _ = os.Remove(path) sock, err := net.Listen("unix", path) if err != nil {