From f4e98bd3c6e6ff32e6b3076fcef63b532f593348 Mon Sep 17 00:00:00 2001 From: jiefenghuang Date: Fri, 23 Aug 2024 17:59:42 +0800 Subject: [PATCH] feat(fuse): support write size config (#5087) Signed-off-by: jiefenghuang --- cmd/mount_unix.go | 18 ++++++++++++++---- pkg/fuse/fuse.go | 6 +++--- pkg/vfs/vfs.go | 1 - 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cmd/mount_unix.go b/cmd/mount_unix.go index 74b14e649e9d..b8fac24c2d08 100644 --- a/cmd/mount_unix.go +++ b/cmd/mount_unix.go @@ -49,6 +49,7 @@ import ( "github.com/juicedata/juicefs/pkg/meta" "github.com/juicedata/juicefs/pkg/object" "github.com/juicedata/juicefs/pkg/utils" + "github.com/juicedata/juicefs/pkg/version" "github.com/juicedata/juicefs/pkg/vfs" ) @@ -312,6 +313,11 @@ func fuseFlags() []cli.Flag { Usage: "disable `default_permissions` option, only for testing", Hidden: true, }, + &cli.StringFlag{ + Name: "max-write", + Usage: "maximum write size for fuse request", + Value: "128K", + }, &cli.StringFlag{ Name: "o", Usage: "other FUSE options", @@ -407,8 +413,8 @@ func getFuserMountVersion() string { } func setFuseOption(c *cli.Context, format *meta.Format, vfsConf *vfs.Config) { - rawOpts, mt, noxattr, noacl := genFuseOptExt(c, format) - options := vfs.FuseOptions(fuse.GenFuseOpt(vfsConf, rawOpts, mt, noxattr, noacl)) + rawOpts, mt, noxattr, noacl, maxWrite := genFuseOptExt(c, format) + options := vfs.FuseOptions(fuse.GenFuseOpt(vfsConf, rawOpts, mt, noxattr, noacl, maxWrite)) vfsConf.FuseOpts = &options } @@ -495,12 +501,12 @@ func prepareMp(mp string) { } } -func genFuseOptExt(c *cli.Context, format *meta.Format) (fuseOpt string, mt int, noxattr, noacl bool) { +func genFuseOptExt(c *cli.Context, format *meta.Format) (fuseOpt string, mt int, noxattr, noacl bool, maxWrite int) { enableXattr := c.Bool("enable-xattr") if format.EnableACL { enableXattr = true } - return genFuseOpt(c, format.Name), 1, !enableXattr, !format.EnableACL + return genFuseOpt(c, format.Name), 1, !enableXattr, !format.EnableACL, int(utils.ParseBytes(c, "max-write", 'B')) } func shutdownGraceful(mp string) { @@ -568,6 +574,10 @@ func canShutdownGracefully(mp string, newConf *vfs.Config) bool { logger.Infof("different volume %s != %s, mount on top of it", oldConf.Format.Name, newConf.Format.Name) return false } + oldVersion := version.Parse(oldConf.Version) + if ret, _ := version.CompareVersions(oldVersion, version.Parse("1.2.0")); ret <= 0 { + oldConf.FuseOpts.MaxWrite = 128 * 1024 + } if oldConf.FuseOpts != nil && !reflect.DeepEqual(oldConf.FuseOpts.StripOptions(), newConf.FuseOpts.StripOptions()) { logger.Infof("different options, mount on top of it: %v != %v", oldConf.FuseOpts.StripOptions(), newConf.FuseOpts.StripOptions()) return false diff --git a/pkg/fuse/fuse.go b/pkg/fuse/fuse.go index 397bde02bf5e..cb4903a22351 100644 --- a/pkg/fuse/fuse.go +++ b/pkg/fuse/fuse.go @@ -452,7 +452,7 @@ func Serve(v *vfs.VFS, options string, xattrs, ioctl bool) error { opt.DontUmask = conf.Format.EnableACL opt.DisableXAttrs = !xattrs opt.EnableIoctl = ioctl - opt.MaxWrite = 1 << 20 + opt.MaxWrite = conf.FuseOpts.MaxWrite opt.MaxReadAhead = 1 << 20 opt.DirectMount = true opt.AllowOther = os.Getuid() == 0 @@ -517,7 +517,7 @@ func Serve(v *vfs.VFS, options string, xattrs, ioctl bool) error { return nil } -func GenFuseOpt(conf *vfs.Config, options string, mt int, noxattr, noacl bool) fuse.MountOptions { +func GenFuseOpt(conf *vfs.Config, options string, mt int, noxattr, noacl bool, maxWrite int) fuse.MountOptions { var opt fuse.MountOptions opt.FsName = "JuiceFS:" + conf.Format.Name opt.Name = "juicefs" @@ -527,7 +527,7 @@ func GenFuseOpt(conf *vfs.Config, options string, mt int, noxattr, noacl bool) f opt.DisableXAttrs = noxattr opt.EnableAcl = !noacl opt.IgnoreSecurityLabels = noacl - opt.MaxWrite = 1 << 20 + opt.MaxWrite = maxWrite opt.MaxReadAhead = 1 << 20 opt.DirectMount = true opt.DontUmask = true diff --git a/pkg/vfs/vfs.go b/pkg/vfs/vfs.go index 73a3a5fb2f7f..4c6a25d9f7c8 100644 --- a/pkg/vfs/vfs.go +++ b/pkg/vfs/vfs.go @@ -106,7 +106,6 @@ func (o FuseOptions) StripOptions() FuseOptions { // ignore there options because they cannot be configured by users o.Name = "" o.MaxBackground = 0 - o.MaxWrite = 0 o.MaxReadAhead = 0 o.DirectMount = false o.DontUmask = false