[PATCH 4/4] fuse4fs: set iomap backing device blocksize

Darrick J. Wong
2025-09-16T01:09:27Z

If we're running as an unprivileged iomap fuse server, we must ask the
kernel to set the blocksize of the block device.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fuse4fs/fuse4fs.c | 41 +++++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 0e43e99c3c080d..40171a8cab5279 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -1371,6 +1371,21 @@ static int fuse4fs_service(struct fuse4fs *ff, struct fuse_session *se,

return 0;
}
+
+int fuse4fs_service_set_bdev_blocksize(struct fuse4fs *ff, int dev_index)
+{
+ int ret;
+
+ ret = fuse_lowlevel_iomap_set_blocksize(ff->fusedev_fd, dev_index,
+ ff->fs->blocksize);
+ if (ret) {
+ err_printf(ff, "%s: cannot set blocksize %u: %s\n", __func__,
+ ff->fs->blocksize, strerror(errno));
+ return -EIO;
+ }
+
+ return 0;
+}
#else
# define fuse4fs_is_service(...) (false)
# define fuse4fs_service_connect(...) (0)
@@ -1382,6 +1397,7 @@ static int fuse4fs_service(struct fuse4fs *ff, struct fuse_session *se,
# define fuse4fs_service_openfs(...) (EOPNOTSUPP)
# define fuse4fs_service_configure_iomap(...) (EOPNOTSUPP)
# define fuse4fs_service(...) (EOPNOTSUPP)
+# define fuse4fs_service_set_bdev_blocksize(...) (EOPNOTSUPP)
#endif

static errcode_t fuse4fs_acquire_lockfile(struct fuse4fs *ff)
@@ -6798,21 +6814,19 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
{
errcode_t err;
int fd;
+ int dev_index;
int ret;

err = io_channel_get_fd(ff->fs->io, &fd);
if (err)
return translate_error(ff->fs, 0, err);

- ret = fuse4fs_set_bdev_blocksize(ff, fd);
- if (ret)
- return ret;
-
- ret = fuse_lowlevel_iomap_device_add(ff->fuse, fd, 0);
- if (ret < 0) {
- dbg_printf(ff, "%s: cannot register iomap dev fd=%d, err=%d\n",
- __func__, fd, -ret);
- return translate_error(ff->fs, 0, -ret);
+ dev_index = fuse_lowlevel_iomap_device_add(ff->fuse, fd, 0);
+ if (dev_index < 0) {
+ ret = -dev_index;
+ dbg_printf(ff, "%s: cannot register iomap dev fd=%d: %s\n",
+ __func__, fd, strerror(ret));
+ return translate_error(ff->fs, 0, ret);
}

dbg_printf(ff, "%s: registered iomap dev fd=%d iomap_dev=%u\n",
@@ -6820,7 +6834,14 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)

fuse4fs_configure_atomic_write(ff, fd);

- ff->iomap_dev = ret;
+ if (fuse4fs_is_service(ff))
+ ret = fuse4fs_service_set_bdev_blocksize(ff, dev_index);
+ else
+ ret = fuse4fs_set_bdev_blocksize(ff, fd);
+ if (ret)
+ return ret;
+
+ ff->iomap_dev = dev_index;
return 0;
}