Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

mount,cmount,mount2: add --direct-io flag to force uncached access

Nick Craig-Wooda67688dcc7aa
diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go
index 4ba22ea30..ea66e3bd6 100644
--- a/cmd/cmount/fs.go
+++ b/cmd/cmount/fs.go
@@ -27,6 +27,7 @@ const fhUnset = ^uint64(0)
type FS struct {
VFS *vfs.VFS
f fs.Fs
+ opt *mountlib.Options
ready chan (struct{})
mu sync.Mutex // to protect the below
handles []vfs.Handle
@@ -34,10 +35,11 @@ type FS struct {
}
// NewFS makes a new FS
-func NewFS(VFS *vfs.VFS) *FS {
+func NewFS(VFS *vfs.VFS, opt *mountlib.Options) *FS {
fsys := &FS{
VFS: VFS,
f: VFS.Fs(),
+ opt: opt,
ready: make(chan (struct{})),
}
return fsys
@@ -309,6 +311,9 @@ func (fsys *FS) OpenEx(path string, fi *fuse.FileInfo_t) (errc int) {
if entry := handle.Node().DirEntry(); entry != nil && entry.Size() < 0 {
fi.DirectIo = true
}
+ if fsys.opt.DirectIO {
+ fi.DirectIo = true
+ }
fi.Fh = fsys.openHandle(handle)
return 0
diff --git a/cmd/cmount/mount.go b/cmd/cmount/mount.go
index d6d684d04..583a48427 100644
--- a/cmd/cmount/mount.go
+++ b/cmd/cmount/mount.go
@@ -149,7 +149,7 @@ func mount(VFS *vfs.VFS, mountPath string, opt *mountlib.Options) (<-chan error,
fs.Debugf(nil, "Mounting on %q (%q)", mountpoint, opt.VolumeName)
// Create underlying FS
- fsys := NewFS(VFS)
+ fsys := NewFS(VFS, opt)
host := fuse.NewFileSystemHost(fsys)
host.SetCapReaddirPlus(true) // only works on Windows
if opt.CaseInsensitive.Valid {
diff --git a/cmd/mount/file.go b/cmd/mount/file.go
index f745dcc7b..a660bcafa 100644
--- a/cmd/mount/file.go
+++ b/cmd/mount/file.go
@@ -78,6 +78,9 @@ func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenR
if entry := handle.Node().DirEntry(); entry != nil && entry.Size() < 0 {
resp.Flags |= fuse.OpenDirectIO
}
+ if f.fsys.opt.DirectIO {
+ resp.Flags |= fuse.OpenDirectIO
+ }
return &FileHandle{handle}, nil
}
diff --git a/cmd/mount2/node.go b/cmd/mount2/node.go
index 0ba1aded4..ee830b51b 100644
--- a/cmd/mount2/node.go
+++ b/cmd/mount2/node.go
@@ -158,6 +158,9 @@ func (n *Node) Open(ctx context.Context, flags uint32) (fh fusefs.FileHandle, fu
if entry := n.node.DirEntry(); entry != nil && entry.Size() < 0 {
fuseFlags |= fuse.FOPEN_DIRECT_IO
}
+ if n.fsys.opt.DirectIO {
+ fuseFlags |= fuse.FOPEN_DIRECT_IO
+ }
return newFileHandle(handle, n.fsys), fuseFlags, 0
}
diff --git a/cmd/mountlib/mount.go b/cmd/mountlib/mount.go
index 34795be60..739c83ff4 100644
--- a/cmd/mountlib/mount.go
+++ b/cmd/mountlib/mount.go
@@ -52,6 +52,7 @@ type Options struct {
DaemonTimeout time.Duration // OSXFUSE only
AsyncRead bool
NetworkMode bool // Windows only
+ DirectIO bool // use Direct IO for file access
CaseInsensitive fs.Tristate
}
@@ -145,6 +146,7 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.BoolVarP(flagSet, &Opt.WritebackCache, "write-back-cache", "", Opt.WritebackCache, "Makes kernel buffer writes before sending them to rclone (without this, writethrough caching is used) (not supported on Windows)", "Mount")
flags.StringVarP(flagSet, &Opt.DeviceName, "devname", "", Opt.DeviceName, "Set the device name - default is remote:path", "Mount")
flags.FVarP(flagSet, &Opt.CaseInsensitive, "mount-case-insensitive", "", "Tell the OS the mount is case insensitive (true) or sensitive (false) regardless of the backend (auto)", "Mount")
+ flags.BoolVarP(flagSet, &Opt.DirectIO, "direct-io", "", Opt.DirectIO, "Use Direct IO, disables caching of data", "Mount")
// Windows and OSX
flags.StringVarP(flagSet, &Opt.VolumeName, "volname", "", Opt.VolumeName, "Set the volume name (supported on Windows and OSX only)", "Mount")
// OSX only