Skip to content

Commit 52da885

Browse files
lostjefflebsbernd
authored andcommitted
fuse: add support for explicit export disabling
open_by_handle_at(2) can fail with -ESTALE with a valid handle returned by a previous name_to_handle_at(2) for evicted fuse inodes, which is especially common when entry_valid_timeout is 0, e.g. when the fuse daemon is in "cache=none" mode. The time sequence is like: name_to_handle_at(2) # succeed evict fuse inode open_by_handle_at(2) # fail The root cause is that, with 0 entry_valid_timeout, the dput() called in name_to_handle_at(2) will trigger iput -> evict(), which will send FUSE_FORGET to the daemon. The following open_by_handle_at(2) will send a new FUSE_LOOKUP request upon inode cache miss since the previous inode eviction. Then the fuse daemon may fail the FUSE_LOOKUP request with -ENOENT as the cached metadata of the requested inode has already been cleaned up during the previous FUSE_FORGET. The returned -ENOENT is treated as -ESTALE when open_by_handle_at(2) returns. This confuses the application somehow, as open_by_handle_at(2) fails when the previous name_to_handle_at(2) succeeds. The returned errno is also confusing as the requested file is not deleted and already there. It is reasonable to fail name_to_handle_at(2) early in this case, after which the application can fallback to open(2) to access files. Since this issue typically appears when entry_valid_timeout is 0 which is configured by the fuse daemon, the fuse daemon is the right person to explicitly disable the export when required. Also considering FUSE_EXPORT_SUPPORT actually indicates the support for lookups of "." and "..", and there are existing fuse daemons supporting export without FUSE_EXPORT_SUPPORT set, for compatibility, we add a new INIT flag for such purpose. Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> (cherry picked from commit e022f6a)
1 parent 573e7ab commit 52da885

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

fs/fuse/inode.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,11 @@ static struct dentry *fuse_get_parent(struct dentry *child)
11731173
return parent;
11741174
}
11751175

1176+
/* only for fid encoding; no support for file handle */
1177+
static const struct export_operations fuse_export_fid_operations = {
1178+
.encode_fh = fuse_encode_fh,
1179+
};
1180+
11761181
static const struct export_operations fuse_export_operations = {
11771182
.fh_to_dentry = fuse_fh_to_dentry,
11781183
.fh_to_parent = fuse_fh_to_parent,
@@ -1356,6 +1361,8 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
13561361
fc->direct_io_allow_mmap = 1;
13571362
if (flags & FUSE_OVER_IO_URING && fuse_uring_enabled())
13581363
fc->io_uring = 1;
1364+
if (flags & FUSE_NO_EXPORT_SUPPORT)
1365+
fm->sb->s_export_op = &fuse_export_fid_operations;
13591366
} else {
13601367
ra_pages = fc->max_read / PAGE_SIZE;
13611368
fc->no_lock = 1;
@@ -1402,7 +1409,8 @@ void fuse_send_init(struct fuse_mount *fm)
14021409
FUSE_NO_OPENDIR_SUPPORT | FUSE_EXPLICIT_INVAL_DATA |
14031410
FUSE_HANDLE_KILLPRIV_V2 | FUSE_SETXATTR_EXT | FUSE_INIT_EXT |
14041411
FUSE_SECURITY_CTX | FUSE_CREATE_SUPP_GROUP |
1405-
FUSE_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP;
1412+
FUSE_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP |
1413+
FUSE_NO_EXPORT_SUPPORT;
14061414
#ifdef CONFIG_FUSE_DAX
14071415
if (fm->fc->dax)
14081416
flags |= FUSE_MAP_ALIGNMENT;
@@ -1606,6 +1614,7 @@ static int fuse_fill_super_submount(struct super_block *sb,
16061614
sb->s_bdi = bdi_get(parent_sb->s_bdi);
16071615

16081616
sb->s_xattr = parent_sb->s_xattr;
1617+
sb->s_export_op = parent_sb->s_export_op;
16091618
sb->s_time_gran = parent_sb->s_time_gran;
16101619
sb->s_blocksize = parent_sb->s_blocksize;
16111620
sb->s_blocksize_bits = parent_sb->s_blocksize_bits;

include/uapi/linux/fuse.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@
211211
* 7.39
212212
* - add FUSE_DIRECT_IO_ALLOW_MMAP
213213
* - add FUSE_STATX and related structures
214+
*
215+
* 7.40
216+
* - add max_stack_depth to fuse_init_out, add FUSE_PASSTHROUGH init flag
217+
* - add backing_id to fuse_open_out, add FOPEN_PASSTHROUGH open flag
218+
* - add FUSE_NO_EXPORT_SUPPORT init flag
219+
*
214220
* 7.42
215221
* - Add FUSE_OVER_IO_URING and all other io-uring related flags and data
216222
* structures:
@@ -419,6 +425,7 @@ struct fuse_file_lock {
419425
* symlink and mknod (single group that matches parent)
420426
* FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
421427
* FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
428+
* FUSE_NO_EXPORT_SUPPORT: explicitly disable export support
422429
* FUSE_OVER_IO_URING: Indicate that client supports io-uring
423430
*/
424431
#define FUSE_ASYNC_READ (1 << 0)
@@ -459,6 +466,7 @@ struct fuse_file_lock {
459466
#define FUSE_CREATE_SUPP_GROUP (1ULL << 34)
460467
#define FUSE_HAS_EXPIRE_ONLY (1ULL << 35)
461468
#define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
469+
#define FUSE_NO_EXPORT_SUPPORT (1ULL << 38)
462470

463471
/* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
464472
#define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP

0 commit comments

Comments
 (0)