Skip to content

Commit 37ae132

Browse files
committed
Attempt to add passthrough support
Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com>
1 parent 789f587 commit 37ae132

File tree

14 files changed

+175
-10
lines changed

14 files changed

+175
-10
lines changed

backend/combine/combine.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,13 @@ func (o *Object) SetTier(tier string) error {
11401140
return do.SetTier(tier)
11411141
}
11421142

1143+
// Fd returns the Fd of the Object
1144+
//
1145+
// It should return fs.ErrorNotImplemented if it's not available
1146+
func (o *Object) Fd(ctx context.Context, flags int) (uintptr, error) {
1147+
return 0, fs.ErrorNotImplemented
1148+
}
1149+
11431150
// Check the interfaces are satisfied
11441151
var (
11451152
_ fs.Fs = (*Fs)(nil)

backend/compress/compress.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func init() {
8989
Help: `GZIP compression level (-2 to 9).
9090
9191
Generally -1 (default, equivalent to 5) is recommended.
92-
Levels 1 to 9 increase compression at the cost of speed. Going past 6
92+
Levels 1 to 9 increase compression at the cost of speed. Going past 6
9393
generally offers very little return.
9494
9595
Level -2 uses Huffman encoding only. Only use if you know what you
@@ -103,7 +103,7 @@ Level 0 turns off compression.`,
103103
In this case the compressed file will need to be cached to determine
104104
it's size.
105105
106-
Files smaller than this limit will be cached in RAM, files larger than
106+
Files smaller than this limit will be cached in RAM, files larger than
107107
this limit will be cached on disk.`,
108108
Default: fs.SizeSuffix(20 * 1024 * 1024),
109109
Advanced: true,
@@ -1498,6 +1498,13 @@ func (o *Object) ID() string {
14981498
return do.ID()
14991499
}
15001500

1501+
// Fd returns the Fd of the Object
1502+
//
1503+
// It should return fs.ErrorNotImplemented if it's not available
1504+
func (o *Object) Fd(ctx context.Context, flags int) (uintptr, error) {
1505+
return 0, fs.ErrorNotImplemented
1506+
}
1507+
15011508
// Name of the remote (as passed into NewFs)
15021509
func (f *Fs) Name() string {
15031510
return f.name

backend/crypt/crypt.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ problem that should be investigated.`,
144144
Name: "filename_encoding",
145145
Help: `How to encode the encrypted filename to text string.
146146
147-
This option could help with shortening the encrypted filename. The
147+
This option could help with shortening the encrypted filename. The
148148
suitable option would depend on the way your remote count the filename
149149
length and if it's case sensitive.`,
150150
Default: "base32",
@@ -167,7 +167,7 @@ length and if it's case sensitive.`,
167167
Name: "suffix",
168168
Help: `If this is set it will override the default suffix of ".bin".
169169
170-
Setting suffix to "none" will result in an empty suffix. This may be useful
170+
Setting suffix to "none" will result in an empty suffix. This may be useful
171171
when the path length is critical.`,
172172
Default: ".bin",
173173
Advanced: true,
@@ -1268,6 +1268,13 @@ func (o *Object) MimeType(ctx context.Context) string {
12681268
return ""
12691269
}
12701270

1271+
// Fd returns the Fd of the Object
1272+
//
1273+
// It should return fs.ErrorNotImplemented if it's not available
1274+
func (o *Object) Fd(ctx context.Context, flags int) (uintptr, error) {
1275+
return 0, fs.ErrorNotImplemented
1276+
}
1277+
12711278
// Check the interfaces are satisfied
12721279
var (
12731280
_ fs.Fs = (*Fs)(nil)

backend/hasher/hasher.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,17 @@ func (o *Object) SetMetadata(ctx context.Context, metadata fs.Metadata) error {
546546
return do.SetMetadata(ctx, metadata)
547547
}
548548

549+
// Fd returns the Fd of the Object
550+
//
551+
// It should return fs.ErrorNotImplemented if it's not available
552+
func (o *Object) Fd(ctx context.Context, flags int) (uintptr, error) {
553+
do, ok := o.Object.(fs.Fder)
554+
if !ok {
555+
return 0, fs.ErrorNotImplemented
556+
}
557+
return do.Fd(ctx, flags)
558+
}
559+
549560
// Check the interfaces are satisfied
550561
var (
551562
_ fs.Fs = (*Fs)(nil)

backend/local/local.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,19 @@ func cleanRootPath(s string, noUNC bool, enc encoder.MultiEncoder) string {
17131713
return s
17141714
}
17151715

1716+
// Fd returns the Fd of the Object
1717+
//
1718+
// It should return fs.ErrorNotImplemented if it's not available
1719+
func (o *Object) Fd(ctx context.Context, flags int) (uintptr, error) {
1720+
osFile, err := file.OpenFile(o.path, flags, 0)
1721+
if err != nil {
1722+
return 0, fmt.Errorf("failed to open file: %s: %w", o.path, err)
1723+
}
1724+
fileFd := osFile.Fd()
1725+
fs.Infof(o, "Returning fd: %s: %d", o.path, fileFd)
1726+
return fileFd, nil
1727+
}
1728+
17161729
// Items returns the count of items in this directory or this
17171730
// directory and subdirectories if known, -1 for unknown
17181731
func (d *Directory) Items() int64 {

backend/union/entry.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ func (d *Directory) ModTime(ctx context.Context) (t time.Time) {
219219
return t
220220
}
221221

222+
// Fd returns the Fd of the Object
223+
//
224+
// It should return fs.ErrorNotImplemented if it's not available
225+
func (o *Object) Fd(ctx context.Context, flags int) (uintptr, error) {
226+
do, ok := o.Object.Object.(fs.Fder)
227+
if !ok {
228+
return 0, fs.ErrorNotImplemented
229+
}
230+
return do.Fd(ctx, flags)
231+
}
232+
222233
// Size returns the size of the directory
223234
// It returns the sum of all candidates
224235
func (d *Directory) Size() (s int64) {

backend/union/upstream/upstream.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,17 @@ func (o *Object) SetMetadata(ctx context.Context, metadata fs.Metadata) error {
333333
return do.SetMetadata(ctx, metadata)
334334
}
335335

336+
// Fd returns the Fd of the Object
337+
//
338+
// It should return fs.ErrorNotImplemented if it's not available
339+
func (o *Object) Fd(ctx context.Context, flags int) (uintptr, error) {
340+
do, ok := o.Object.(fs.Fder)
341+
if !ok {
342+
return 0, fs.ErrorNotImplemented
343+
}
344+
return do.Fd(ctx, flags)
345+
}
346+
336347
// Metadata returns metadata for an DirEntry
337348
//
338349
// It should return nil if there is no Metadata

cmd/mount2/file.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,19 @@ func (f *FileHandle) Setattr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.
149149
}
150150

151151
var _ fusefs.FileSetattrer = (*FileHandle)(nil)
152+
153+
// PassthroughFd returns the file descriptor of the file if the remote supports passthrough
154+
func (f *FileHandle) PassthroughFd() (int, bool) {
155+
_, ok := f.h.Node().(*vfs.File)
156+
if !ok {
157+
return 0, false
158+
}
159+
160+
fileFd := f.h.Fd()
161+
if fileFd == 0 {
162+
return 0, false
163+
}
164+
return int(fileFd), true
165+
}
166+
167+
var _ fusefs.FilePassthroughFder = (*FileHandle)(nil)

cmd/mount2/mount.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func mountOptions(fsys *FS, f fs.Fs, opt *mountlib.Options) (mountOpts *fuse.Mou
3333
MaxReadAhead: int(fsys.opt.MaxReadAhead),
3434
MaxWrite: 1024 * 1024, // Linux v4.20+ caps requests at 1 MiB
3535
DisableReadDirPlus: true,
36+
MaxStackDepth: fsys.opt.MaxStackDepth,
3637

3738
// RememberInodes: true,
3839
// SingleThreaded: true,

cmd/mountlib/mount.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@ var OptionsInfo = fs.Options{{
118118
Default: fs.Tristate{},
119119
Help: "Tell the OS the mount is case insensitive (true) or sensitive (false) regardless of the backend (auto)",
120120
Groups: "Mount",
121+
}, {
122+
Name: "max_stack_depth",
123+
Default: 1,
124+
Help: "Maximum stacking depth for passthrough files. Defaults to 1",
125+
Groups: "Mount",
121126
}, {
122127
Name: "direct_io",
123128
Default: false,
124-
Help: "Use Direct IO, disables caching of data",
129+
Help: "Use Direct IO, disables the page cache",
125130
Groups: "Mount",
126131
}, {
127132
Name: "volname",
@@ -189,6 +194,7 @@ type Options struct {
189194
NetworkMode bool `config:"network_mode"` // Windows only
190195
DirectIO bool `config:"direct_io"` // use Direct IO for file access
191196
CaseInsensitive fs.Tristate `config:"mount_case_insensitive"`
197+
MaxStackDepth int `config:"max_stack_depth"`
192198
}
193199

194200
type (

0 commit comments

Comments
 (0)