fuse: disallow dynamic inode blksize changes
Subsystems (2)
cover fuse: disallow dynamic inode blksize changes
With fuse now using iomap for writeback handling, inode blocksize changes are problematic because iomap relies on the inode blocksize value for its internal bitmap logic.
There are a few options for addressing this, as discussed in [1].
a) add "u8 blkbits" to iomap internals (struct iomap_folio_state) and change iomap logic to use this static value instead of using inode->i_blkbits
b) remove all folios for the inode from the page cache and synchronize that with modifying inode->i_blkbits
(unfortunately this does not work, see [1] for more details)
c) disallow the inode blocksize from changing dynamically in fuse
In the discussion in [1], we decided to go with c) given that servers don't have a good use case for dynamically modifying the blocksize and it doesn't seem likely that servers use this. If the server wishes to set a constant blocksize for all inodes, then from patch 2, this can be done at mount time through the -oblksize= configuration option.
Thanks,
Joanne
Joanne Koong (2):
fuse: disallow dynamic inode blksize changes
fuse: add blksize configuration at mount for non-fuseblk servers
fs/fuse/dir.c | 9 +-------- fs/fuse/inode.c | 18 +++++++++--------- include/uapi/linux/fuse.h | 4 ++-- 3 files changed, 12 insertions(+), 19 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/2 fuse: disallow dynamic inode blksize changes
With fuse using iomap, which relies on inode->i_blkbits for its internal bitmap tracking, disallow fuse servers from dynamically changing the inode blocksize.
"attr->blksize = sx->blksize;" is retained in fuse_statx_to_attr() so that any attempts by the server to change the blksize through the statx reply is surfaced to dmesg.
--- fs/fuse/dir.c | 9 +-------- fs/fuse/inode.c | 6 ++---- include/uapi/linux/fuse.h | 4 ++-- 3 files changed, 5 insertions(+), 14 deletions(-)
fs/fuse/dir.c +1 -8
@@ -1180,7 +1180,6 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,static void fuse_fillattr (struct mnt_idmap *idmap,struct inode *inode,struct fuse_attr *attr,struct kstat *stat) { -unsigned int blkbits;struct fuse_conn *fc =get_fuse_conn (inode);vfsuid_t vfsuid =make_vfsuid (idmap, fc->user_ns,make_kuid (fc->user_ns, attr->uid));
@@ -1202,13 +1201,7 @@ static void fuse_fillattr(struct mnt_idmap *idmap, struct inode *inode, stat->ctime.tv_nsec = attr->ctimensec; stat->size = attr->size; stat->blocks = attr->blocks; - -if (attr->blksize !=0 ) - blkbits =ilog2 (attr->blksize); -else - blkbits = inode->i_sb->s_blocksize_bits; - - stat->blksize =1 << blkbits; + stat->blksize =1 << inode->i_sb->s_blocksize_bits; }static void fuse_statx_to_attr (struct fuse_statx *sx,struct fuse_attr *attr)
fs/fuse/inode.c +2 -4
@@ -285,10 +285,8 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, } } -if (attr->blksize !=0 ) - inode->i_blkbits =ilog2 (attr->blksize); -else - inode->i_blkbits = inode->i_sb->s_blocksize_bits; +if (attr->blksize && attr->blksize != inode->i_sb->s_blocksize) +pr_warn_ratelimited ("changing blksize attribute is a no-op\n" );/* * Don't set the sticky bit in i_mode, unless we want the VFS
include/uapi/linux/fuse.h +2 -2
@@ -293,7 +293,7 @@ struct fuse_attr {uint32_t uid;uint32_t gid;uint32_t rdev; -uint32_t blksize; +uint32_t blksize;/* not used */ uint32_t flags; };
@@ -309,7 +309,7 @@ struct fuse_sx_time {struct fuse_statx {uint32_t mask; -uint32_t blksize; +uint32_t blksize;/* not used */ uint64_t attributes;uint32_t nlink;uint32_t uid;
Signature · 1 line
2.47.3
Miklos Szeredi
maintainerQuoted 8 lines · Joanne Koong
With fuse using iomap, which relies on
inode->i_blkbitsfor its internal bitmap tracking, disallow fuse servers from dynamically changing the inode blocksize."
attr->blksize=sx->blksize;" is retained infuse_statx_to_attr()so that any attempts by the server to change the blksize through the statx reply is surfaced to dmesg.
I expect no big breakage, but I'm quite sure that message will scare some people for no good reason. I'd just keep a copy of attr->blksize in fuse_inode and present that in stx_blksize, while keeping the internal i_blkbits consistent.
Thoughts?
Thanks,
Miklos
Quoted 11 lines · Miklos Szeredi
Quoted 8 lines · Joanne Koong
With fuse using iomap, which relies on
inode->i_blkbitsfor its internal bitmap tracking, disallow fuse servers from dynamically changing the inode blocksize."
attr->blksize=sx->blksize;" is retained infuse_statx_to_attr()so that any attempts by the server to change the blksize through the statx reply is surfaced to dmesg.
Quoted 6 lines
I expect no big breakage, but I'm quite sure that message will scare some people for no good reason. I'd just keep a copy of
attr->blksizeinfuse_inodeand present that instx_blksize, while keeping the internali_blkbitsconsistent.Thoughts?
That sounds great and will make things simpler. We don't need the 2nd patch then, I'll drop that in v2.
Thanks,
Joanne
Quoted 3 lines
Thanks,
Miklos
PATCH 2/2 fuse: add blksize configuration at mount for non-fuseblk servers
In reply to Joanne KoongThis allows fuse servers to pass in at mount time the blocksize that should be used for its inodes. Previously this was only supported for fuseblk servers and non-fuseblk servers could only specify blocksize dynamically through server replies (which is now disallowed).
This gives a way for non-fuseblk fuse servers to specify the blocksize. The block size must be a power of 2 and >= FUSE_DEFAULT_BLKSIZE (which is also already a requirement for fuseblk servers).
If the blocksize option is not set, the blocksize will be the default value (FUSE_DEFAULT_BLKSIZE for fuseblk servers and PAGE_SIZE for non-fuseblk servers).
--- fs/fuse/inode.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/fuse/inode.c +7 -5
@@ -871,8 +871,9 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)break ;case OPT_BLKSIZE : -if (!ctx->is_bdev) -return invalfc (fsc,"blksize only supported for fuseblk" ); +if (result.uint_32 <FUSE_DEFAULT_BLKSIZE || + !is_power_of_2 (result.uint_32)) +return invalfc (fsc,"Invalid blksize" ); ctx->blksize = result.uint_32;break ;
@@ -1806,8 +1807,8 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) goto err;#endif }else { - sb->s_blocksize =PAGE_SIZE ; - sb->s_blocksize_bits =PAGE_SHIFT ; + sb->s_blocksize = ctx->blksize; + sb->s_blocksize_bits =ilog2 (sb->s_blocksize); } sb->s_subtype = ctx->subtype;
@@ -2007,7 +2008,6 @@ static int fuse_init_fs_context(struct fs_context *fsc)return -ENOMEM ; ctx->max_read = ~0 ; - ctx->blksize =FUSE_DEFAULT_BLKSIZE ; ctx->legacy_opts_show = true;#ifdef CONFIG_BLOCK
@@ -2017,6 +2017,8 @@ static int fuse_init_fs_context(struct fs_context *fsc) }#endif + ctx->blksize = ctx->is_bdev ?FUSE_DEFAULT_BLKSIZE :PAGE_SIZE ; + fsc->fs_private = ctx; fsc->ops = &fuse_context_ops;return 0 ;
Signature · 1 line
2.47.3