Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/fs/fuse/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ func MountFlags(fuseConf *meta.FuseConfig) []cli.Flag {
Value: false,
Usage: "Assume all directory objects (\"dir/\") exist (default: false)",
},
&cli.BoolFlag{
Name: "background",
Aliases: []string{"d"},
Value: false,
Usage: "run in backGround",
},
}
}

Expand Down
29 changes: 28 additions & 1 deletion cmd/fs/fuse/service/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"syscall"
"time"

utils2 "github.com/PaddlePaddle/PaddleFlow/pkg/fs/client/utils"
libfuse "github.com/hanwen/go-fuse/v2/fuse"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -234,6 +235,10 @@ func mount(c *cli.Context) error {
return err
}

if c.Bool("background") {
daemonRun()
}

if !c.Bool("local") {
stopChan := make(chan struct{})
defer close(stopChan)
Expand All @@ -248,7 +253,7 @@ func mount(c *cli.Context) error {
}
}

log.Debugf("start mount service")
log.Infof("start mount service on %v", c.String("mount-point"))
server, err := fuse.Server(c.String("mount-point"), *opts)
if err != nil {
log.Fatalf("mount fail: %v", err)
Expand Down Expand Up @@ -279,6 +284,9 @@ func InitVFS(c *cli.Context, registry *prometheus.Registry) error {
server := c.String("server")
if c.Bool("local") == true {
localRoot := c.String("local-root")
if localRoot == "" {
localRoot = "./mock"
}
if localRoot == "" || localRoot == "/" {
log.Errorf("invalid localRoot: [%s]", localRoot)
return fmt.Errorf("invalid localRoot: [%s]", localRoot)
Expand Down Expand Up @@ -420,6 +428,9 @@ func InitVFS(c *cli.Context, registry *prometheus.Registry) error {
CachePath: c.String("data-cache-path"),
},
}
if fsMeta.Properties == nil {
fsMeta.Properties = make(map[string]string)
}
if c.Bool("no-implicit-dir") {
fsMeta.Properties[common.ImplicitDir] = "false"
} else {
Expand Down Expand Up @@ -460,3 +471,19 @@ func signalHandle(mp string) {
}
}()
}

func daemonRun() {
err := makeDaemon()
if err != nil {
log.Fatalf("Failed to make daemon: %s", err)
}
if runtime.GOOS == "linux" {
log.SetOutput(os.Stderr)
}
}

func makeDaemon() error {
var attrs utils2.DaemonAttr
_, _, err := utils2.MakeDaemon(&attrs)
return err
}
65 changes: 65 additions & 0 deletions cmd/fs/fuse/service/mount_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package service

import (
"github.com/PaddlePaddle/PaddleFlow/pkg/fs/utils"
"github.com/PaddlePaddle/PaddleFlow/pkg/version"
"github.com/urfave/cli/v2"
"os"
"testing"
"time"
)

const testMountPoint = "./mock"

func MockMain(args []string) error {
cli.VersionFlag = &cli.BoolFlag{
Name: "version", Aliases: []string{"V"},
Usage: "print only the version",
}
app := &cli.App{
Name: "pfs-fuse",
Usage: "A POSIX file system built on kv DB and object storage.",
Version: version.InfoStr(),
Copyright: "Apache License 2.0",
HideHelpCommand: true,
EnableBashCompletion: true,
Commands: []*cli.Command{
CmdMount(),
CmdUmount(),
},
}
return app.Run(args)
}

func mountTemp(t *testing.T) {
os.MkdirAll(testMountPoint, 0755)
mountArgs := []string{"", "mount", "-mp", testMountPoint, "--local", "true", "--local-root", testMountPoint, "-d", "true"}

go func() {
if err := MockMain(mountArgs); err != nil {
t.Errorf("mount failed: %s", err)
}
}()
time.Sleep(3 * time.Second)

inode, err := utils.GetFileInode(testMountPoint)
if err != nil {
t.Fatalf("get file inode failed: %s", err)
}
if inode != 1 {
t.Fatalf("mount failed: inode of %s is not 1", testMountPoint)
} else {
t.Logf("mount %s success", testMountPoint)
}
}

func umountTemp(t *testing.T) {
if err := MockMain([]string{"", "umount", testMountPoint}); err != nil {
t.Fatalf("umount failed: %s", err)
}
}

func TestMountBackground(t *testing.T) {
mountTemp(t)
defer umountTemp(t)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/go-chi/chi v1.5.4
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.4.2
github.com/hanwen/go-fuse/v2 v2.2.0
github.com/hanwen/go-fuse/v2 v2.5.1
github.com/jcmturner/gokrb5/v8 v8.4.4
github.com/jinzhu/copier v0.3.2
github.com/johannesboyne/gofakes3 v0.0.0-20220627085814-c3ac35da23b2
Expand Down Expand Up @@ -147,7 +147,7 @@ require (
go.opencensus.io v0.22.5 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4G
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hanwen/go-fuse/v2 v2.2.0 h1:jo5QZYmBLNcl9ovypWaQ5yXMSSV+Ch68xoC3rtZvvBM=
github.com/hanwen/go-fuse/v2 v2.2.0/go.mod h1:B1nGE/6RBFyBRC1RRnf23UpwCdyJ31eukw34oAKukAc=
github.com/hanwen/go-fuse/v2 v2.5.1 h1:OQBE8zVemSocRxA4OaFJbjJ5hlpCmIWbGr7r0M4uoQQ=
github.com/hanwen/go-fuse/v2 v2.5.1/go.mod h1:xKwi1cF7nXAOBCXujD5ie0ZKsxc8GGSA1rlMJc+8IJs=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -716,6 +718,7 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd h1:aY7OQNf2XqY/JQ6qREWamhI/81os/agb2BAGpcx5yWI=
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -1242,6 +1245,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
Loading