Skip to content

Commit

Permalink
get fuse fd from csi (#4991)
Browse files Browse the repository at this point in the history
Signed-off-by: weiwei <[email protected]>
  • Loading branch information
zwwhdls authored Aug 6, 2024
1 parent a300cae commit 7295525
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions cmd/passfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 7295525

Please sign in to comment.