Skip to content

Commit

Permalink
feat(fuse): support write size config (#5087)
Browse files Browse the repository at this point in the history
Signed-off-by: jiefenghuang <[email protected]>
  • Loading branch information
jiefenghuang authored Aug 23, 2024
1 parent 730489b commit f4e98bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
18 changes: 14 additions & 4 deletions cmd/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/fuse/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f4e98bd

Please sign in to comment.