fuse: containerize ext4 for safer operation
Subsystems (8)
PATCH 9/10 fuse: overlay iomap inode info in struct fuse_inode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
It's not possible for a regular file to use iomap mode and writeback caching at the same time, so we can save some memory in struct fuse_inode by overlaying them in the union. This is a separate patch because C unions are rather unsafe and I prefer any errors to be bisectable to this patch.
--- fs/fuse/fuse_i.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/fuse/fuse_i.h +4 -1
@@ -199,8 +199,11 @@ struct fuse_inode {/* waitq for direct-io completion */ wait_queue_head_t direct_io_waitq; + }; #ifdef CONFIG_FUSE_IOMAP + /* regular file iomap mode */ + struct { /* pending io completions */ spinlock_t ioend_lock; struct work_struct ioend_work;
@@ -208,8 +211,8 @@ struct fuse_inode {/* cached iomap mappings */ struct fuse_iomap_cache cache; -#endif }; +#endif /* readdir cache (directory only) */ struct {
PATCH 10/10 fuse: enable iomap
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Remove the guard that we used to avoid bisection problems.
--- fs/fuse/file_iomap.c | 3 --- 1 file changed, 3 deletions(-)
fs/fuse/file_iomap.c +0 -3
@@ -105,9 +105,6 @@ void fuse_iomap_sysfs_cleanup(struct kobject *fuse_kobj)bool fuse_iomap_enabled (void ) { -/* Don't let anyone touch iomap until the end of the patchset. */ -return false; -/* * There are fears that a fuse+iomap server could somehow DoS the * system by doing things like going out to lunch during a writeback
PATCH v6 8/8 fuse: run fuse servers as a contained service
In reply to Darrick J. WongHi all,
This patchset defines the necessary communication protocols and library code so that users can mount fuse servers that run in unprivileged systemd service containers. That in turn allows unprivileged untrusted mounts, because the worst that can happen is that a malicious image crashes the fuse server and the mount dies, instead of corrupting the kernel. As part of the delegation, add a new ioctl allowing any process with an open fusedev fd to ask for permission for anyone with that fusedev fd to use iomap.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-service-container
---
Commits in this patchset:
* fuse: allow privileged mount helpers to pre-approve iomap usage
* fuse: set iomap backing device block size
--- fs/fuse/fuse_dev_i.h | 32 +++++++++++++++++++-- fs/fuse/fuse_i.h | 12 ++++++++ include/uapi/linux/fuse.h | 8 +++++ fs/fuse/dev.c | 13 +++++---- fs/fuse/file_iomap.c | 67 ++++++++++++++++++++++++++++++++++++++++++++- fs/fuse/inode.c | 18 ++++++++---- 6 files changed, 134 insertions(+), 16 deletions(-)
PATCH 1/2 fuse: allow privileged mount helpers to pre-approve iomap usage
From: Darrick J. Wong <[email protected]>
For the upcoming safemount functionality in libfuse, we will create a privileged "mount.safe" helper that starts the fuse server in a completely unprivileged systemd container. The mount helper will pass the mount options and fds for /dev/fuse and any other files requested by the fuse server into the container via a Unix socket.
Currently, the ability to turn on iomap for fuse depends on a module parameter and the process that calls mount() having the CAP_SYS_RAWIO capability. However, the unprivilged fuse server might want to query the /dev/fuse fd for iomap capabilities before mount or FUSE_INIT so that it can get ready.
Similar to FUSE_DEV_SYNC_INIT, add a new bit for iomap that can be squirreled away in file->private_data and an ioctl to set that bit. That way the privileged mount helper can pass its iomap privilege to the contained fuse server without the fuse server needing to have CAP_SYS_RAWIO.
--- fs/fuse/fuse_dev_i.h | 32 +++++++++++++++++++++++++++++--- fs/fuse/fuse_i.h | 9 +++++++++ include/uapi/linux/fuse.h | 1 + fs/fuse/dev.c | 11 +++++------ fs/fuse/file_iomap.c | 43 ++++++++++++++++++++++++++++++++++++++++++- fs/fuse/inode.c | 18 ++++++++++++------ 6 files changed, 98 insertions(+), 16 deletions(-)
fs/fuse/fuse_dev_i.h +29 -3
@@ -39,8 +39,10 @@ struct fuse_copy_state { } ring; }; -#define FUSE_DEV_SYNC_INIT ((struct fuse_dev *) 1) -#define FUSE_DEV_PTR_MASK (~1UL) +#define FUSE_DEV_SYNC_INIT (1UL << 0) +#define FUSE_DEV_INHERIT_IOMAP (1UL << 1) +#define FUSE_DEV_FLAGS_MASK (FUSE_DEV_SYNC_INIT | FUSE_DEV_INHERIT_IOMAP) +#define FUSE_DEV_PTR_MASK (~FUSE_DEV_FLAGS_MASK)static inline struct fuse_dev *__fuse_get_dev (struct file *file) {
@@ -50,7 +52,31 @@ static inline struct fuse_dev *__fuse_get_dev(struct file *file)*/ struct fuse_dev *fud =READ_ONCE (file->private_data); -return (typeof (fud)) ((unsigned long ) fud &FUSE_DEV_PTR_MASK ); +return (typeof (fud)) ((uintptr_t )fud &FUSE_DEV_PTR_MASK ); +} + +static inline struct fuse_dev *__fuse_get_dev_and_flags (struct file *file, +uintptr_t *flagsp) +{ +/* +* Lockless access is OK, because file->private data is set +* once during mount and is valid until the file is released. +*/ +struct fuse_dev *fud =READ_ONCE (file->private_data); + + *flagsp = ((uintptr_t )fud) &FUSE_DEV_FLAGS_MASK ; +return (typeof (fud)) ((uintptr_t ) fud &FUSE_DEV_PTR_MASK ); +} + +static inline int __fuse_set_dev_flags (struct file *file,uintptr_t flag) +{ +uintptr_t old_flags =0 ; + +if (__fuse_get_dev_and_flags (file, &old_flags)) +return -EINVAL ; + +WRITE_ONCE (file->private_data, (struct fuse_dev *)(old_flags | flag)); +return 0 ; }struct fuse_dev *fuse_get_dev (struct file *file);
fs/fuse/fuse_i.h +9 -0
@@ -990,6 +990,13 @@ struct fuse_conn {/* Enable fs/iomap for file operations */ unsigned int iomap:1; +/* +* Are filesystems using this connection allowed to use iomap? This is +* determined by the privilege level of the process that initiated the +* mount() call. +*/ + unsigned int may_iomap:1; +/* Use io_uring for communication */ unsigned int io_uring;
@@ -1847,6 +1854,7 @@ void fuse_iomap_release_truncate(struct inode *inode);void fuse_iomap_copied_file_range (struct inode *inode,loff_t offset,size_t written); +int fuse_dev_ioctl_add_iomap (struct file *file);int fuse_dev_ioctl_iomap_support (struct file *file,struct fuse_iomap_support __user *argp); int fuse_iomap_dev_inval(struct fuse_conn *fc,
@@ -1898,6 +1906,7 @@ int fuse_iomap_inval(struct fuse_conn *fc,# define fuse_iomap_open_truncate (...) ((void)0)# define fuse_iomap_release_truncate (...) ((void)0)# define fuse_iomap_copied_file_range (...) ((void)0) +# define fuse_dev_ioctl_add_iomap (...) (-EOPNOTSUPP)# define fuse_dev_ioctl_iomap_support (...) (-EOPNOTSUPP)# define fuse_iomap_dev_inval (...) (-ENOSYS)# define fuse_iomap_fadvise NULL
include/uapi/linux/fuse.h +1 -0
@@ -1204,6 +1204,7 @@ struct fuse_iomap_support { struct fuse_backing_map)#define FUSE_DEV_IOC_BACKING_CLOSE _IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)#define FUSE_DEV_IOC_SYNC_INIT _IO(FUSE_DEV_IOC_MAGIC, 3) +#define FUSE_DEV_IOC_ADD_IOMAP _IO(FUSE_DEV_IOC_MAGIC, 99)#define FUSE_DEV_IOC_IOMAP_SUPPORT _IOR(FUSE_DEV_IOC_MAGIC, 99, \ struct fuse_iomap_support)
fs/fuse/dev.c +5 -6
@@ -1558,7 +1558,7 @@ struct fuse_dev *fuse_get_dev(struct file *file)return fud; err =wait_event_interruptible (fuse_dev_waitq, -READ_ONCE (file->private_data) !=FUSE_DEV_SYNC_INIT ); +__fuse_get_dev (file) !=NULL );if (err)return ERR_PTR (err);
@@ -2761,13 +2761,10 @@ static long fuse_dev_ioctl_backing_close(struct file *file, __u32 __user *argp)static long fuse_dev_ioctl_sync_init (struct file *file) { -int err = -EINVAL ; +int err;mutex_lock (&fuse_mutex); -if (!__fuse_get_dev (file)) { -WRITE_ONCE (file->private_data,FUSE_DEV_SYNC_INIT ); - err =0 ; - } + err =__fuse_set_dev_flags (file,FUSE_DEV_SYNC_INIT );mutex_unlock (&fuse_mutex);return err; }
@@ -2792,6 +2789,8 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,case FUSE_DEV_IOC_IOMAP_SUPPORT :return fuse_dev_ioctl_iomap_support (file, argp); +case FUSE_DEV_IOC_ADD_IOMAP : +return fuse_dev_ioctl_add_iomap (file);default :return -ENOTTY ;
fs/fuse/file_iomap.c +42 -1
66 lines not on this page · raw message
fs/fuse/inode.c +12 -6
@@ -1043,6 +1043,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm, fc->name_max =FUSE_NAME_LOW_MAX ; fc->timeout.req_timeout =0 ; fc->root_nodeid =FUSE_ROOT_ID ; + fc->may_iomap =fuse_iomap_enabled ();if (IS_ENABLED (CONFIG_FUSE_BACKING ))fuse_backing_files_init (fc);
@@ -1575,7 +1576,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,if (flags &FUSE_REQUEST_TIMEOUT ) timeout = arg->request_timeout; -if ((flags &FUSE_IOMAP ) &&fuse_iomap_enabled ()) { +if ((flags &FUSE_IOMAP ) && fc->may_iomap) { fc->iomap =1 ;pr_warn ("EXPERIMENTAL iomap feature enabled. Use at your own risk!" );
@@ -1662,7 +1663,7 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)*/ if (fuse_uring_enabled ()) flags |=FUSE_OVER_IO_URING ; -if (fuse_iomap_enabled ()) +if (fm->fc->may_iomap) flags |=FUSE_IOMAP ; ia->in.flags = flags;
@@ -2046,11 +2047,16 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)mutex_lock (&fuse_mutex); err = -EINVAL ; -if (ctx->fudptr && *ctx->fudptr) { -if (*ctx->fudptr ==FUSE_DEV_SYNC_INIT ) - fc->sync_init =1 ; -else +if (ctx->fudptr) { +uintptr_t raw = (uintptr_t )(*ctx->fudptr); +uintptr_t flags = raw &FUSE_DEV_FLAGS_MASK ; + +if (raw &FUSE_DEV_PTR_MASK ) goto err_unlock; +if (flags &FUSE_DEV_SYNC_INIT ) + fc->sync_init =1 ; +if (flags &FUSE_DEV_INHERIT_IOMAP ) + fc->may_iomap =1 ; } err =fuse_ctl_add_conn (fc);
PATCH 2/2 fuse: set iomap backing device block size
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a new ioctl so that an unprivileged fuse server can set the block size of a bdev that's opened for iomap usage.
--- fs/fuse/fuse_i.h | 3 +++ include/uapi/linux/fuse.h | 7 +++++++ fs/fuse/dev.c | 2 ++ fs/fuse/file_iomap.c | 24 ++++++++++++++++++++++++ 4 files changed, 36 insertions(+)
fs/fuse/fuse_i.h +3 -0
@@ -1857,6 +1857,8 @@ void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,int fuse_dev_ioctl_add_iomap (struct file *file);int fuse_dev_ioctl_iomap_support (struct file *file,struct fuse_iomap_support __user *argp); +int fuse_dev_ioctl_iomap_set_blocksize (struct file *file, +struct fuse_iomap_backing_info __user *argp);int fuse_iomap_dev_inval (struct fuse_conn *fc,const struct fuse_iomap_dev_inval_out *arg);
@@ -1908,6 +1910,7 @@ int fuse_iomap_inval(struct fuse_conn *fc,# define fuse_iomap_copied_file_range (...) ((void)0)# define fuse_dev_ioctl_add_iomap (...) (-EOPNOTSUPP)# define fuse_dev_ioctl_iomap_support (...) (-EOPNOTSUPP) +# define fuse_dev_ioctl_iomap_set_blocksize (...) (-EOPNOTSUPP)# define fuse_iomap_dev_inval (...) (-ENOSYS)# define fuse_iomap_fadvise NULL# define fuse_inode_caches_iomaps (...) (false)
include/uapi/linux/fuse.h +7 -0
@@ -1197,6 +1197,11 @@ struct fuse_iomap_support {uint64_t padding; }; +struct fuse_iomap_backing_info { +uint32_t backing_id; +uint32_t blocksize; +}; +/* Device ioctls: */ #define FUSE_DEV_IOC_MAGIC 229#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1207,6 +1212,8 @@ struct fuse_iomap_support {#define FUSE_DEV_IOC_ADD_IOMAP _IO(FUSE_DEV_IOC_MAGIC, 99)#define FUSE_DEV_IOC_IOMAP_SUPPORT _IOR(FUSE_DEV_IOC_MAGIC, 99, \ struct fuse_iomap_support) +#define FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE _IOW(FUSE_DEV_IOC_MAGIC, 99, \ + struct fuse_iomap_backing_info)struct fuse_lseek_in {uint64_t fh;
fs/fuse/dev.c +2 -0
@@ -2791,6 +2791,8 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,return fuse_dev_ioctl_iomap_support (file, argp);case FUSE_DEV_IOC_ADD_IOMAP :return fuse_dev_ioctl_add_iomap (file); +case FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE : +return fuse_dev_ioctl_iomap_set_blocksize (file, argp);default :return -ENOTTY ;
fs/fuse/file_iomap.c +24 -0
@@ -2800,3 +2800,27 @@ int fuse_iomap_inval(struct fuse_conn *fc,up_read (&fc->killsb);return ret ? ret : ret2; } + +int fuse_dev_ioctl_iomap_set_blocksize (struct file *file, +struct fuse_iomap_backing_info __user *argp) +{ +struct fuse_iomap_backing_info fbi; +struct fuse_dev *fud =fuse_get_dev (file); +struct fuse_backing *fb; +int ret; + +if (IS_ERR (fud)) +return PTR_ERR (fud); + +if (copy_from_user (&fbi, argp,sizeof (fbi))) +return -EFAULT ; + + fb =fuse_backing_lookup (fud->fc, &fuse_iomap_backing_ops, + fbi.backing_id); +if (!fb) +return -ENOENT ; + + ret =set_blocksize (fb->file, fbi.blocksize); +fuse_backing_put (fb); +return ret; +}
PATCH v6 1/5 libfuse: allow servers to use iomap for better file IO performance
In reply to Darrick J. WongHi all,
This series connects libfuse to the iomap-enabled fuse driver in Linux to get fuse servers out of the business of handling file I/O themselves. By keeping the IO path mostly within the kernel, we can dramatically improve the speed of disk-based filesystems. This enables us to move all the filesystem metadata parsing code out of the kernel and into userspace, which means that we can containerize them for security without losing a lot of performance.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-fileio
---
Commits in this patchset:
* libfuse: bump kernel and library ABI versions
* libfuse: add kernel gates for FUSE_IOMAP
* libfuse: add fuse commands for iomap_begin and end
* libfuse: add upper level iomap commands
* libfuse: add a lowlevel notification to add a new device to iomap
* libfuse: add upper-level iomap add device function
* libfuse: add iomap ioend low level handler
* libfuse: add upper level iomap ioend commands
* libfuse: add a reply function to send FUSE_ATTR_* to the kernel
* libfuse: connect high level fuse library to fuse_reply_attr_iflags
* libfuse: support direct I/O through iomap
* libfuse: don't allow hardlinking of iomap files in the upper level fuse library
* libfuse: allow discovery of the kernel's iomap capabilities
* libfuse: add lower level iomap_config implementation
* libfuse: add upper level iomap_config implementation
* libfuse: add low level code to invalidate iomap block device ranges
* libfuse: add upper-level API to invalidate parts of an iomap block device
* libfuse: add atomic write support
* libfuse: create a helper to transform an open regular file into an open loopdev
* libfuse: add swapfile support for iomap files
* libfuse: add lower-level filesystem freeze, thaw, and shutdown requests
* libfuse: add upper-level filesystem freeze, thaw, and shutdown events
--- include/fuse.h | 101 ++++++++ include/fuse_common.h | 141 +++++++++++ include/fuse_kernel.h | 130 ++++++++++ include/fuse_loopdev.h | 27 ++ include/fuse_lowlevel.h | 278 ++++++++++++++++++++++ ChangeLog.rst | 12 + include/meson.build | 4 lib/fuse.c | 584 +++++++++++++++++++++++++++++++++++++++++++---- lib/fuse_loopdev.c | 403 ++++++++++++++++++++++++++++++++ lib/fuse_lowlevel.c | 437 ++++++++++++++++++++++++++++++++++- lib/fuse_versionscript | 21 ++ lib/meson.build | 5 meson.build | 13 + 13 files changed, 2080 insertions(+), 76 deletions(-) create mode 100644 include/fuse_loopdev.h create mode 100644 lib/fuse_loopdev.c
PATCH 1/22 libfuse: bump kernel and library ABI versions
From: Darrick J. Wong <[email protected]>
Bump the kernel ABI version to 7.99 and the libfuse ABI version to 3.99 to start our development. This patch exists to avoid confusion during the prototyping stage.
--- include/fuse_kernel.h | 4 +++- ChangeLog.rst | 12 +++++++++++- lib/fuse_versionscript | 3 +++ lib/meson.build | 2 +- meson.build | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-)
include/fuse_kernel.h +3 -1
@@ -239,6 +239,8 @@* 7.45 * - add FUSE_COPY_FILE_RANGE_64 * - add struct fuse_copy_file_range_out +* +* 7.99 */ #ifndef _LINUX_FUSE_H
@@ -274,7 +276,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 45 +#define FUSE_KERNEL_MINOR_VERSION 99/** The node ID of the root inode */ #define FUSE_ROOT_ID 1
ChangeLog.rst +11 -1
@@ -1,4 +1,14 @@ -libfuse 3.18 +libfuse 3.99 + +libfuse 3.99-rc0 (2025-07-18) +=============================== + +* Add prototypes of iomap and syncfs (djwong) + +libfuse 3.18-rc0 (2025-07-18) +=============================== + +* Add statx, among other things (djwong) libfuse 3.17.1-rc0 (2024-02.10) ===============================
lib/fuse_versionscript +3 -0
@@ -218,6 +218,9 @@ FUSE_3.18 { fuse_fs_statx; } FUSE_3.17; +FUSE_3.99 { +} FUSE_3.18; + # Local Variables: # indent-tabs-mode: t # End:
lib/meson.build +1 -1
@@ -49,7 +49,7 @@ libfuse = library('fuse3', dependencies: deps, install: true, link_depends: 'fuse_versionscript', - c_args: [ '-DFUSE_USE_VERSION=317', + c_args: [ '-DFUSE_USE_VERSION=399', '-DFUSERMOUNT_DIR="@0@"'.format(fusermount_path) ], link_args: ['-Wl,--version-script,' + meson.current_source_dir() + '/fuse_versionscript' ])
meson.build +1 -1
@@ -1,5 +1,5 @@ project('libfuse3', ['c'], - version: '3.18.0-rc0', # Version with RC suffix + version: '3.99.0-rc0', # Version with RC suffix meson_version: '>= 0.60.0', default_options: [ 'buildtype=debugoptimized',
PATCH 2/22 libfuse: add kernel gates for FUSE_IOMAP
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add some flags to query and request kernel support for filesystem iomap for regular files.
--- include/fuse_common.h | 5 +++++ include/fuse_kernel.h | 3 +++ lib/fuse_lowlevel.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-)
include/fuse_common.h +5 -0
@@ -512,6 +512,11 @@ struct fuse_loop_config_v1 {*/ #define FUSE_CAP_OVER_IO_URING (1UL << 31) +/** +* Client supports using iomap for regular file operations +*/ +#define FUSE_CAP_IOMAP (1ULL << 32) +/** * Ioctl flags *
include/fuse_kernel.h +3 -0
@@ -241,6 +241,7 @@* - add struct fuse_copy_file_range_out * * 7.99 +* - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations */ #ifndef _LINUX_FUSE_H
@@ -449,6 +450,7 @@ struct fuse_file_lock {* FUSE_OVER_IO_URING: Indicate that client supports io-uring * FUSE_REQUEST_TIMEOUT: kernel supports timing out requests. * init_out.request_timeout contains the timeout (in secs) +* FUSE_IOMAP: Client supports iomap for regular file operations */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -496,6 +498,7 @@ struct fuse_file_lock {#define FUSE_ALLOW_IDMAP (1ULL << 40)#define FUSE_OVER_IO_URING (1ULL << 41)#define FUSE_REQUEST_TIMEOUT (1ULL << 42) +#define FUSE_IOMAP (1ULL << 43)/** * CUSE INIT request/reply flags
lib/fuse_lowlevel.c +11 -1
@@ -2746,7 +2746,10 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, se->conn.capable_ext |=FUSE_CAP_NO_EXPORT_SUPPORT ;if (inargflags &FUSE_OVER_IO_URING ) se->conn.capable_ext |=FUSE_CAP_OVER_IO_URING ; - +if (inargflags &FUSE_IOMAP ) + se->conn.capable_ext |=FUSE_CAP_IOMAP ; +/* Don't let anyone touch iomap until the end of the patchset. */ + se->conn.capable_ext &= ~FUSE_CAP_IOMAP ; }else { se->conn.max_readahead =0 ; }
@@ -2792,6 +2795,9 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, FUSE_CAP_READDIRPLUS_AUTO);LL_SET_DEFAULT (1 ,FUSE_CAP_OVER_IO_URING ); +/* servers need to opt-in to iomap explicitly */ +LL_SET_DEFAULT (0 ,FUSE_CAP_IOMAP ); +/* This could safely become default, but libfuse needs an API extension * to support it * LL_SET_DEFAULT(1, FUSE_CAP_SETXATTR_EXT);
@@ -2909,6 +2915,8 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, outargflags |=FUSE_REQUEST_TIMEOUT ; outarg.request_timeout = se->conn.request_timeout; } +if (se->conn.want_ext &FUSE_CAP_IOMAP ) + outargflags |=FUSE_IOMAP ; outarg.max_readahead = se->conn.max_readahead; outarg.max_write = se->conn.max_write;
@@ -2943,6 +2951,8 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in,if (se->conn.want_ext &FUSE_CAP_PASSTHROUGH )fuse_log (FUSE_LOG_DEBUG ," max_stack_depth=%u\n" , outarg.max_stack_depth); +if (se->conn.want_ext &FUSE_CAP_IOMAP ) +fuse_log (FUSE_LOG_DEBUG ," iomap=1\n" ); }if (arg->minor <5 ) outargsize =FUSE_COMPAT_INIT_OUT_SIZE ;
PATCH 3/22 libfuse: add fuse commands for iomap_begin and end
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach the low level API how to handle iomap begin and end commands that we get from the kernel.
--- include/fuse_common.h | 71 +++++++++++++++++++++++++++++++++ include/fuse_kernel.h | 40 ++++++++++++++++++ include/fuse_lowlevel.h | 59 +++++++++++++++++++++++++++ lib/fuse_lowlevel.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++ lib/fuse_versionscript | 3 + 5 files changed, 275 insertions(+)
include/fuse_common.h +71 -0
@@ -1135,7 +1135,78 @@ bool fuse_get_feature_flag(struct fuse_conn_info *conn, uint64_t flag);*/ int fuse_convert_to_conn_want_ext (struct fuse_conn_info *conn); +/** +* iomap operations. +* These APIs are introduced in version 399 (FUSE_MAKE_VERSION(3, 99)). +*/ +/* mapping types; see corresponding IOMAP_TYPE_ */ +#define FUSE_IOMAP_TYPE_HOLE (0) +#define FUSE_IOMAP_TYPE_DELALLOC (1) +#define FUSE_IOMAP_TYPE_MAPPED (2) +#define FUSE_IOMAP_TYPE_UNWRITTEN (3) +#define FUSE_IOMAP_TYPE_INLINE (4) + +/* fuse-specific mapping type indicating that writes use the read mapping */ +#define FUSE_IOMAP_TYPE_PURE_OVERWRITE (255) + +#define FUSE_IOMAP_DEV_NULL (0U)/* null device cookie */ + +/* mapping flags passed back from iomap_begin; see corresponding IOMAP_F_ */ +#define FUSE_IOMAP_F_NEW (1U << 0) +#define FUSE_IOMAP_F_DIRTY (1U << 1) +#define FUSE_IOMAP_F_SHARED (1U << 2) +#define FUSE_IOMAP_F_MERGED (1U << 3) +#define FUSE_IOMAP_F_BOUNDARY (1U << 4) +#define FUSE_IOMAP_F_ANON_WRITE (1U << 5) +#define FUSE_IOMAP_F_ATOMIC_BIO (1U << 6) + +/* fuse-specific mapping flag asking for ->iomap_end call */ +#define FUSE_IOMAP_F_WANT_IOMAP_END (1U << 7) + +/* mapping flags passed to iomap_end */ +#define FUSE_IOMAP_F_SIZE_CHANGED (1U << 8) +#define FUSE_IOMAP_F_STALE (1U << 9) + +/* operation flags from iomap; see corresponding IOMAP_* */ +#define FUSE_IOMAP_OP_WRITE (1U << 0) +#define FUSE_IOMAP_OP_ZERO (1U << 1) +#define FUSE_IOMAP_OP_REPORT (1U << 2) +#define FUSE_IOMAP_OP_FAULT (1U << 3) +#define FUSE_IOMAP_OP_DIRECT (1U << 4) +#define FUSE_IOMAP_OP_NOWAIT (1U << 5) +#define FUSE_IOMAP_OP_OVERWRITE_ONLY (1U << 6) +#define FUSE_IOMAP_OP_UNSHARE (1U << 7) +#define FUSE_IOMAP_OP_DAX (1U << 8) +#define FUSE_IOMAP_OP_ATOMIC (1U << 9) +#define FUSE_IOMAP_OP_DONTCACHE (1U << 10) + +/* pagecache writeback operation */ +#define FUSE_IOMAP_OP_WRITEBACK (1U << 31) + +#define FUSE_IOMAP_NULL_ADDR (-1ULL)/* addr is not valid */ + +struct fuse_file_iomap { +uint64_t addr;/* disk offset of mapping, bytes */ +uint64_t offset;/* file offset of mapping, bytes */ +uint64_t length;/* length of mapping, bytes */ +uint16_t type;/* FUSE_IOMAP_TYPE_* */ +uint16_t flags;/* FUSE_IOMAP_F_* */ +uint32_t dev;/* device cookie */ +}; + +static inline bool fuse_iomap_is_write (unsigned int opflags) +{ +return opflags & (FUSE_IOMAP_OP_WRITE |FUSE_IOMAP_OP_ZERO | +FUSE_IOMAP_OP_UNSHARE |FUSE_IOMAP_OP_WRITEBACK ); +} + +static inline bool fuse_iomap_need_write_allocate (unsigned int opflags, +const struct fuse_file_iomap *map) +{ +return map->type ==FUSE_IOMAP_TYPE_HOLE && + !(opflags &FUSE_IOMAP_OP_ZERO ); +}/* ----------------------------------------------------------- * * Compatibility stuff *
include/fuse_kernel.h +40 -0
@@ -668,6 +668,9 @@ enum fuse_opcode {FUSE_STATX =52 ,FUSE_COPY_FILE_RANGE_64 =53 , +FUSE_IOMAP_BEGIN =4094 , +FUSE_IOMAP_END =4095 , +/* CUSE specific operations */ CUSE_INIT = 4096,
@@ -1305,4 +1308,41 @@ struct fuse_uring_cmd_req { uint8_t padding[6]; }; +struct fuse_iomap_io { +uint64_t offset;/* file offset of mapping, bytes */ +uint64_t length;/* length of mapping, bytes */ +uint64_t addr;/* disk offset of mapping, bytes */ +uint16_t type;/* FUSE_IOMAP_TYPE_* */ +uint16_t flags;/* FUSE_IOMAP_F_* */ +uint32_t dev;/* device cookie */ +}; + +struct fuse_iomap_begin_in { +uint32_t opflags;/* FUSE_IOMAP_OP_* */ +uint32_t reserved;/* zero */ +uint64_t attr_ino;/* matches fuse_attr:ino */ +uint64_t pos;/* file position, in bytes */ +uint64_t count;/* operation length, in bytes */ +}; + +struct fuse_iomap_begin_out { +/* read file data from here */ +struct fuse_iomap_io read; + +/* write file data to here, if applicable */ +struct fuse_iomap_io write; +}; + +struct fuse_iomap_end_in { +uint32_t opflags;/* FUSE_IOMAP_OP_* */ +uint32_t reserved;/* zero */ +uint64_t attr_ino;/* matches fuse_attr:ino */ +uint64_t pos;/* file position, in bytes */ +uint64_t count;/* operation length, in bytes */ +int64_t written;/* bytes processed */ + +/* mapping that the kernel acted upon */ +struct fuse_iomap_io map; +}; +#endif /* _LINUX_FUSE_H */
include/fuse_lowlevel.h +59 -0
71 lines not on this page · raw message
lib/fuse_lowlevel.c +102 -0
120 lines not on this page · raw message
lib/fuse_versionscript +3 -0
@@ -219,6 +219,9 @@ FUSE_3.18 { } FUSE_3.17; FUSE_3.99 { + global: + fuse_iomap_pure_overwrite; + fuse_reply_iomap_begin; } FUSE_3.18; # Local Variables:
PATCH 4/22 libfuse: add upper level iomap commands
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach the upper level fuse library about the iomap begin and end operations, and connect it to the lower level. This is needed for fuse2fs to start using iomap.
--- include/fuse.h | 17 +++++++++ lib/fuse.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+)
include/fuse.h +17 -0
@@ -864,6 +864,23 @@ struct fuse_operations {*/ int (*statx)(const char *path,int flags,int mask,struct statx *stxbuf,struct fuse_file_info *fi); + +/** +* Send a mapping to the kernel so that a file IO operation can run. +*/ +int (*iomap_begin) (const char *path,uint64_t nodeid, +uint64_t attr_ino,off_t pos_in, +uint64_t length_in,uint32_t opflags_in, +struct fuse_file_iomap *read_out, +struct fuse_file_iomap *write_out); + +/** +* Respond to the outcome of a previous file mapping operation. +*/ +int (*iomap_end) (const char *path,uint64_t nodeid,uint64_t attr_ino, +off_t pos_in,uint64_t length_in, +uint32_t opflags_in,ssize_t written_in, +const struct fuse_file_iomap *iomap); };/** Extra context that may be needed by some filesystems
lib/fuse.c +102 -0
120 lines not on this page · raw message
PATCH 5/22 libfuse: add a lowlevel notification to add a new device to iomap
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Plumb in the pieces needed to attach block devices to a fuse+iomap mount for use with iomap operations. This enables us to have filesystems where the metadata could live somewhere else, but the actual file IO goes to locally attached storage.
--- include/fuse_kernel.h | 7 +++++++ include/fuse_lowlevel.h | 29 ++++++++++++++++++++++++++++ lib/fuse_lowlevel.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ lib/fuse_versionscript | 2 ++ 4 files changed, 87 insertions(+)
include/fuse_kernel.h +7 -0
@@ -1127,6 +1127,13 @@ struct fuse_notify_retrieve_in {uint64_t dummy4; }; +#define FUSE_BACKING_TYPE_MASK (0xFF) +#define FUSE_BACKING_TYPE_PASSTHROUGH (0) +#define FUSE_BACKING_TYPE_IOMAP (1) +#define FUSE_BACKING_MAX_TYPE (FUSE_BACKING_TYPE_IOMAP) + +#define FUSE_BACKING_FLAGS_ALL (FUSE_BACKING_TYPE_MASK) +struct fuse_backing_map {int32_t fd;uint32_t flags;
include/fuse_lowlevel.h +29 -0
@@ -1998,6 +1998,35 @@ int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,int fuse_lowlevel_notify_retrieve (struct fuse_session *se,fuse_ino_t ino,size_t size,off_t offset,void *cookie); +/** +* Attach an open file descriptor to a fuse+iomap mount. Currently must be +* a block device. +* +* Added in FUSE protocol version 7.99. If the kernel does not support +* this (or a newer) version, the function will return -ENOSYS and do +* nothing. +* +* @param se the session object +* @param fd file descriptor of an open block device +* @param flags flags for the operation; none defined so far +* @return positive nonzero device id on success, or negative errno on failure +*/ +int fuse_lowlevel_iomap_device_add (struct fuse_session *se,int fd, +unsigned int flags); + +/** +* Detach an open file from a fuse+iomap mount. Must be a device id returned +* by fuse_lowlevel_iomap_device_add. +* +* Added in FUSE protocol version 7.99. If the kernel does not support +* this (or a newer) version, the function will return -ENOSYS and do +* nothing. +* +* @param se the session object +* @param device_id device index as returned by fuse_lowlevel_iomap_device_add +* @return 0 on success, or negative errno on failure +*/ +int fuse_lowlevel_iomap_device_remove (struct fuse_session *se,int device_id);/* ----------------------------------------------------------- * * Utility functions *
lib/fuse_lowlevel.c +49 -0
55 lines not on this page · raw message
lib/fuse_versionscript +2 -0
@@ -222,6 +222,8 @@ FUSE_3.99 { global: fuse_iomap_pure_overwrite; fuse_reply_iomap_begin; + fuse_lowlevel_iomap_device_add; + fuse_lowlevel_iomap_device_remove; } FUSE_3.18; # Local Variables:
PATCH 6/22 libfuse: add upper-level iomap add device function
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make it so that the upper level fuse library can add iomap devices too.
--- include/fuse.h | 19 +++++++++++++++++++ lib/fuse.c | 16 ++++++++++++++++ lib/fuse_versionscript | 2 ++ 3 files changed, 37 insertions(+)
include/fuse.h +19 -0
@@ -1381,6 +1381,25 @@ void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn, struct fuse_config *cfg);void fuse_fs_destroy (struct fuse_fs *fs); +/** +* Attach an open file descriptor to a fuse+iomap mount. Currently must be +* a block device. +* +* @param fd file descriptor of an open block device +* @param flags flags for the operation; none defined so far +* @return positive nonzero device id on success, or negative errno on failure +*/ +int fuse_fs_iomap_device_add (int fd,unsigned int flags); + +/** +* Detach an open file from a fuse+iomap mount. Must be a device id returned +* by fuse_lowlevel_iomap_device_add. +* +* @param device_id device index as returned by fuse_lowlevel_iomap_device_add +* @return 0 on success, or negative errno on failure +*/ +int fuse_fs_iomap_device_remove (int device_id); +int fuse_notify_poll (struct fuse_pollhandle *ph);/**
lib/fuse.c +16 -0
@@ -2836,6 +2836,22 @@ static int fuse_fs_iomap_end(struct fuse_fs *fs, const char *path, written, iomap); } +int fuse_fs_iomap_device_add (int fd,unsigned int flags) +{ +struct fuse_context *ctxt =fuse_get_context (); +struct fuse_session *se =fuse_get_session (ctxt->fuse); + +return fuse_lowlevel_iomap_device_add (se, fd, flags); +} + +int fuse_fs_iomap_device_remove (int device_id) +{ +struct fuse_context *ctxt =fuse_get_context (); +struct fuse_session *se =fuse_get_session (ctxt->fuse); + +return fuse_lowlevel_iomap_device_remove (se, device_id); +} +static void fuse_lib_setattr (fuse_req_t req,fuse_ino_t ino,struct stat *attr,int valid,struct fuse_file_info *fi) {
lib/fuse_versionscript +2 -0
@@ -224,6 +224,8 @@ FUSE_3.99 { fuse_reply_iomap_begin; fuse_lowlevel_iomap_device_add; fuse_lowlevel_iomap_device_remove; + fuse_fs_iomap_device_add; + fuse_fs_iomap_device_remove; } FUSE_3.18; # Local Variables:
PATCH 7/22 libfuse: add iomap ioend low level handler
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach the low level library about the iomap ioend handler, which gets called by the kernel when we finish a file write that isn't a pure overwrite operation.
--- include/fuse_common.h | 13 +++++++++++++ include/fuse_kernel.h | 11 +++++++++++ include/fuse_lowlevel.h | 20 ++++++++++++++++++++ lib/fuse_lowlevel.c | 23 +++++++++++++++++++++++ 4 files changed, 67 insertions(+)
include/fuse_common.h +13 -0
@@ -1208,6 +1208,19 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags, !(opflags &FUSE_IOMAP_OP_ZERO ); } +/* out of place write extent */ +#define FUSE_IOMAP_IOEND_SHARED (1U << 0) +/* unwritten extent */ +#define FUSE_IOMAP_IOEND_UNWRITTEN (1U << 1) +/* don't merge into previous ioend */ +#define FUSE_IOMAP_IOEND_BOUNDARY (1U << 2) +/* is direct I/O */ +#define FUSE_IOMAP_IOEND_DIRECT (1U << 3) +/* is append ioend */ +#define FUSE_IOMAP_IOEND_APPEND (1U << 4) +/* is pagecache writeback */ +#define FUSE_IOMAP_IOEND_WRITEBACK (1U << 5) +/* ----------------------------------------------------------- * * Compatibility stuff * * ----------------------------------------------------------- */
include/fuse_kernel.h +11 -0
@@ -668,6 +668,7 @@ enum fuse_opcode {FUSE_STATX =52 ,FUSE_COPY_FILE_RANGE_64 =53 , +FUSE_IOMAP_IOEND =4093 ,FUSE_IOMAP_BEGIN =4094 , FUSE_IOMAP_END = 4095,
@@ -1352,4 +1353,14 @@ struct fuse_iomap_end_in { struct fuse_iomap_io map; }; +struct fuse_iomap_ioend_in { +uint32_t ioendflags;/* FUSE_IOMAP_IOEND_* */ +int32_t error;/* negative errno or 0 */ +uint64_t attr_ino;/* matches fuse_attr:ino */ +uint64_t pos;/* file position, in bytes */ +uint64_t new_addr;/* disk offset of new mapping, in bytes */ +uint32_t written;/* bytes processed */ +uint32_t reserved1;/* zero */ +}; +#endif /* _LINUX_FUSE_H */
include/fuse_lowlevel.h +20 -0
@@ -1379,6 +1379,26 @@ struct fuse_lowlevel_ops {void (*iomap_end) (fuse_req_t req,fuse_ino_t nodeid,uint64_t attr_ino,off_t pos,uint64_t count,uint32_t opflags,ssize_t written,const struct fuse_file_iomap *iomap); + +/** +* Complete an iomap IO operation +* +* Valid replies: +* fuse_reply_err +* +* @param req request handle +* @param nodeid the inode number +* @param attr_ino inode number as told by fuse_attr::ino +* @param pos position in file, in bytes +* @param written number of bytes processed, or a negative errno +* @param ioendflags mask of FUSE_IOMAP_IOEND_ flags specifying operation +* @param error errno code of what went wrong +* @param new_addr disk address of new mapping, in bytes +*/ +void (*iomap_ioend) (fuse_req_t req,fuse_ino_t nodeid, +uint64_t attr_ino,off_t pos,size_t written, +uint32_t ioendflags,int error, +uint64_t new_addr); };/**
lib/fuse_lowlevel.c +23 -0
@@ -2696,6 +2696,27 @@ static void do_iomap_end(fuse_req_t req, const fuse_ino_t nodeid,_do_iomap_end (req, nodeid, inarg,NULL ); } +static void _do_iomap_ioend (fuse_req_t req,const fuse_ino_t nodeid, +const void *op_in,const void *in_payload) +{ +const struct fuse_iomap_ioend_in *arg = op_in; + (void )in_payload; + (void )nodeid; + +if (req->se->op.iomap_ioend) + req->se->op.iomap_ioend (req, nodeid, arg->attr_ino, arg->pos, + arg->written, arg->ioendflags, + arg->error, arg->new_addr); +else +fuse_reply_err (req,ENOSYS ); +} + +static void do_iomap_ioend (fuse_req_t req,const fuse_ino_t nodeid, +const void *inarg) +{ +_do_iomap_ioend (req, nodeid, inarg,NULL ); +} +static bool want_flags_valid (uint64_t capable,uint64_t want) {uint64_t unknown_flags = want & (~capable);
@@ -3605,6 +3626,7 @@ static struct { [FUSE_STATX] = { do_statx, "STATX" }, [FUSE_IOMAP_BEGIN] = { do_iomap_begin, "IOMAP_BEGIN" }, [FUSE_IOMAP_END] = { do_iomap_end, "IOMAP_END" }, + [FUSE_IOMAP_IOEND] = { do_iomap_ioend, "IOMAP_IOEND" }, [CUSE_INIT] = { cuse_lowlevel_init, "CUSE_INIT" }, };
@@ -3663,6 +3685,7 @@ static struct { [FUSE_STATX] = { _do_statx, "STATX" }, [FUSE_IOMAP_BEGIN] = { _do_iomap_begin, "IOMAP_BEGIN" }, [FUSE_IOMAP_END] = { _do_iomap_end, "IOMAP_END" }, + [FUSE_IOMAP_IOEND] = { _do_iomap_ioend, "IOMAP_IOEND" }, [CUSE_INIT] = { _cuse_lowlevel_init, "CUSE_INIT" }, };
PATCH 8/22 libfuse: add upper level iomap ioend commands
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach the upper level fuse library about iomap ioend events, which happen when a write that isn't a pure overwrite completes.
--- include/fuse.h | 8 ++++++++ lib/fuse.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
include/fuse.h +8 -0
@@ -881,6 +881,14 @@ struct fuse_operations { off_t pos_in, uint64_t length_in, uint32_t opflags_in, ssize_t written_in, const struct fuse_file_iomap *iomap); + +/** +* Respond to the outcome of a file IO operation. +*/ +int (*iomap_ioend) (const char *path,uint64_t nodeid, +uint64_t attr_ino,off_t pos_in,size_t written_in, +uint32_t ioendflags_in,int error_in, +uint64_t new_addr_in); };/** Extra context that may be needed by some filesystems
lib/fuse.c +46 -0
64 lines not on this page · raw message
PATCH 9/22 libfuse: add a reply function to send FUSE_ATTR_* to the kernel
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create new fuse_reply_{attr,create,entry}_iflags functions so that we can send FUSE_ATTR_* flags to the kernel when instantiating an inode. Servers are expected to send FUSE_IFLAG_* values, which will be translated into what the kernel can understand.
--- include/fuse_common.h | 3 ++ include/fuse_lowlevel.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++ lib/fuse_lowlevel.c | 64 ++++++++++++++++++++++++++++-------- lib/fuse_versionscript | 4 ++ 4 files changed, 139 insertions(+), 15 deletions(-)
include/fuse_common.h +3 -0
@@ -1221,6 +1221,9 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,/* is pagecache writeback */ #define FUSE_IOMAP_IOEND_WRITEBACK (1U << 5) +/* enable fsdax */ +#define FUSE_IFLAG_DAX (1U << 0) +/* ----------------------------------------------------------- * * Compatibility stuff * * ----------------------------------------------------------- */
include/fuse_lowlevel.h +83 -0
161 lines not on this page · raw message
lib/fuse_lowlevel.c +49 -15
140 lines not on this page · raw message
lib/fuse_versionscript +4 -0
@@ -226,6 +226,10 @@ FUSE_3.99 { fuse_lowlevel_iomap_device_remove; fuse_fs_iomap_device_add; fuse_fs_iomap_device_remove; + fuse_reply_attr_iflags; + fuse_reply_create_iflags; + fuse_reply_entry_iflags; + fuse_add_direntry_plus_iflags; } FUSE_3.18; # Local Variables:
PATCH 10/22 libfuse: connect high level fuse library to fuse_reply_attr_iflags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new ->getattr_iflags function so that iomap filesystems can set the appropriate in-kernel inode flags on instantiation.
--- include/fuse.h | 7 ++ lib/fuse.c | 191 ++++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 151 insertions(+), 47 deletions(-)
include/fuse.h +7 -0
@@ -889,6 +889,13 @@ struct fuse_operations { uint64_t attr_ino, off_t pos_in, size_t written_in, uint32_t ioendflags_in, int error_in, uint64_t new_addr_in); + +/** +* Get file attributes and FUSE_IFLAG_* flags. Otherwise the same as +* getattr. +*/ +int (*getattr_iflags) (const char *path,struct stat *buf, +unsigned int *iflags,struct fuse_file_info *fi); };/** Extra context that may be needed by some filesystems
lib/fuse.c +144 -47
447 lines not on this page · raw message
PATCH 11/22 libfuse: support direct I/O through iomap
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make it so that fuse servers can ask the kernel fuse driver to use iomap to support direct IO.
--- include/fuse_common.h | 2 ++ include/fuse_kernel.h | 3 +++ lib/fuse_lowlevel.c | 2 ++ 3 files changed, 7 insertions(+)
include/fuse_common.h +2 -0
@@ -1223,6 +1223,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,/* enable fsdax */ #define FUSE_IFLAG_DAX (1U << 0) +/* use iomap for this inode */ +#define FUSE_IFLAG_IOMAP (1U << 1)/* ----------------------------------------------------------- * * Compatibility stuff *
include/fuse_kernel.h +3 -0
@@ -242,6 +242,7 @@* * 7.99 * - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations +* - add FUSE_ATTR_IOMAP to enable iomap for specific inodes */ #ifndef _LINUX_FUSE_H
@@ -582,9 +583,11 @@ struct fuse_file_lock {* * FUSE_ATTR_SUBMOUNT: Object is a submount root * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode +* FUSE_ATTR_IOMAP: Use iomap for this inode */ #define FUSE_ATTR_SUBMOUNT (1 << 0)#define FUSE_ATTR_DAX (1 << 1) +#define FUSE_ATTR_IOMAP (1 << 2)/** * Open flags
lib/fuse_lowlevel.c +2 -0
@@ -125,6 +125,8 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr, attr->flags =0 ;if (iflags &FUSE_IFLAG_DAX ) attr->flags |=FUSE_ATTR_DAX ; +if (iflags &FUSE_IFLAG_IOMAP ) + attr->flags |=FUSE_ATTR_IOMAP ; }static void convert_attr (const struct fuse_setattr_in *attr,struct stat *stbuf)
PATCH 12/22 libfuse: don't allow hardlinking of iomap files in the upper level fuse library
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The upper level fuse library creates a separate node object for every (i)node referenced by a directory entry. Unfortunately, it doesn't account for the possibility of hardlinks, which means that we can create multiple nodeids that refer to the same hardlinked inode. Inode locking in iomap mode in the kernel relies there only being one inode object for a hardlinked file, so we cannot allow anyone to hardlink an iomap file. The client had better not turn on iomap for an existing hardlinked file.
--- include/fuse.h | 18 ++++++++++ lib/fuse.c | 90 +++++++++++++++++++++++++++++++++++++++++++----- lib/fuse_versionscript | 2 + 3 files changed, 101 insertions(+), 9 deletions(-)
include/fuse.h +18 -0
@@ -1415,6 +1415,24 @@ int fuse_fs_iomap_device_add(int fd, unsigned int flags);*/ int fuse_fs_iomap_device_remove (int device_id); +/** +* Decide if we can enable iomap mode for a particular file for an upper-level +* fuse server. +* +* @param statbuf stat information for the file. +* @return true if it can be enabled, false if not. +*/ +bool fuse_fs_can_enable_iomap (const struct stat *statbuf); + +/** +* Decide if we can enable iomap mode for a particular file for an upper-level +* fuse server. +* +* @param statxbuf statx information for the file. +* @return true if it can be enabled, false if not. +*/ +bool fuse_fs_can_enable_iomapx (const struct statx *statxbuf); +int fuse_notify_poll (struct fuse_pollhandle *ph);/**
lib/fuse.c +81 -9
108 lines not on this page · raw message
lib/fuse_versionscript +2 -0
@@ -230,6 +230,8 @@ FUSE_3.99 { fuse_reply_create_iflags; fuse_reply_entry_iflags; fuse_add_direntry_plus_iflags; + fuse_fs_can_enable_iomap; + fuse_fs_can_enable_iomapx; } FUSE_3.18; # Local Variables:
PATCH 13/22 libfuse: allow discovery of the kernel's iomap capabilities
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a library function so that we can discover the kernel's iomap capabilities ahead of time.
--- include/fuse_common.h | 7 +++++++ include/fuse_kernel.h | 7 +++++++ include/fuse_lowlevel.h | 10 ++++++++++ lib/fuse_lowlevel.c | 19 +++++++++++++++++++ lib/fuse_versionscript | 1 + 5 files changed, 44 insertions(+)
include/fuse_common.h +7 -0
@@ -534,6 +534,13 @@ struct fuse_loop_config_v1 {#define FUSE_IOCTL_MAX_IOV 256 +/** +* iomap discovery flags +* +* FUSE_IOMAP_SUPPORT_FILEIO: basic file I/O functionality through iomap +*/ +#define FUSE_IOMAP_SUPPORT_FILEIO (1ULL << 0) +/** * Connection information, passed to the ->init() method *
include/fuse_kernel.h +7 -0
@@ -1144,12 +1144,19 @@ struct fuse_backing_map {uint64_t padding; }; +struct fuse_iomap_support { +uint64_t flags; +uint64_t padding; +}; +/* Device ioctls: */ #define FUSE_DEV_IOC_MAGIC 229#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)#define FUSE_DEV_IOC_BACKING_OPEN _IOW(FUSE_DEV_IOC_MAGIC, 1, \ struct fuse_backing_map)#define FUSE_DEV_IOC_BACKING_CLOSE _IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t) +#define FUSE_DEV_IOC_IOMAP_SUPPORT _IOR(FUSE_DEV_IOC_MAGIC, 99, \ + struct fuse_iomap_support)struct fuse_lseek_in {uint64_t fh;
include/fuse_lowlevel.h +10 -0
@@ -2576,6 +2576,16 @@ bool fuse_req_is_uring(fuse_req_t req);int fuse_req_get_payload (fuse_req_t req,char **payload,size_t *payload_sz,void **mr); + +/** +* Discover the kernel's iomap capabilities. Returns FUSE_CAP_IOMAP_* flags. +* +* @param fd open file descriptor to a fuse device, or -1 if you're running +* in the same process that will call mount(). +* @return FUSE_IOMAP_SUPPORT_* flags +*/ +uint64_t fuse_lowlevel_discover_iomap (int fd); + #ifdef __cplusplus }#endif
lib/fuse_lowlevel.c +19 -0
@@ -4709,3 +4709,22 @@ int fuse_session_exited(struct fuse_session *se)return exited ?1 :0 ; } + +uint64_t fuse_lowlevel_discover_iomap (int fd) +{ +struct fuse_iomap_support ios = { }; + +if (fd >=0 ) { +ioctl (fd,FUSE_DEV_IOC_IOMAP_SUPPORT , &ios); +return ios.flags; + } + + fd =open ("/dev/fuse" ,O_RDONLY |O_CLOEXEC ); +if (fd <0 ) +return 0 ; + +ioctl (fd,FUSE_DEV_IOC_IOMAP_SUPPORT , &ios); +close (fd); + +return ios.flags; +}
lib/fuse_versionscript +1 -0
@@ -232,6 +232,7 @@ FUSE_3.99 { fuse_add_direntry_plus_iflags; fuse_fs_can_enable_iomap; fuse_fs_can_enable_iomapx; + fuse_lowlevel_discover_iomap; } FUSE_3.18; # Local Variables:
PATCH 14/22 libfuse: add lower level iomap_config implementation
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add FUSE_IOMAP_CONFIG helpers to the low level fuse library.
--- include/fuse_common.h | 31 ++++++++++++++++++ include/fuse_kernel.h | 31 ++++++++++++++++++ include/fuse_lowlevel.h | 27 +++++++++++++++ lib/fuse_lowlevel.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ lib/fuse_versionscript | 1 + 5 files changed, 172 insertions(+)
include/fuse_common.h +31 -0
@@ -1233,6 +1233,37 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,/* use iomap for this inode */ #define FUSE_IFLAG_IOMAP (1U << 1) +/* Which fields are set in fuse_iomap_config_out? */ +#define FUSE_IOMAP_CONFIG_SID (1 << 0ULL) +#define FUSE_IOMAP_CONFIG_UUID (1 << 1ULL) +#define FUSE_IOMAP_CONFIG_BLOCKSIZE (1 << 2ULL) +#define FUSE_IOMAP_CONFIG_MAX_LINKS (1 << 3ULL) +#define FUSE_IOMAP_CONFIG_TIME (1 << 4ULL) +#define FUSE_IOMAP_CONFIG_MAXBYTES (1 << 5ULL) + +struct fuse_iomap_config { +uint64_t flags;/* FUSE_IOMAP_CONFIG_* */ + +char s_id[32 ];/* Informational name */ +char s_uuid[16 ];/* UUID */ + +uint8_t s_uuid_len;/* length of s_uuid */ + +uint8_t s_pad[3 ];/* must be zeroes */ + +uint32_t s_blocksize;/* fs block size */ +uint32_t s_max_links;/* max hard links */ + +/* Granularity of c/m/atime in ns (cannot be worse than a second) */ +uint32_t s_time_gran; + +/* Time limits for c/m/atime in seconds */ +int64_t s_time_min; +int64_t s_time_max; + +int64_t s_maxbytes;/* max file size */ +}; +/* ----------------------------------------------------------- * * Compatibility stuff * * ----------------------------------------------------------- */
include/fuse_kernel.h +31 -0
@@ -243,6 +243,7 @@* 7.99 * - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations * - add FUSE_ATTR_IOMAP to enable iomap for specific inodes +* - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry */ #ifndef _LINUX_FUSE_H
@@ -671,6 +672,7 @@ enum fuse_opcode {FUSE_STATX =52 ,FUSE_COPY_FILE_RANGE_64 =53 , +FUSE_IOMAP_CONFIG =4092 ,FUSE_IOMAP_IOEND =4093 ,FUSE_IOMAP_BEGIN =4094 , FUSE_IOMAP_END = 4095,
@@ -1373,4 +1375,33 @@ struct fuse_iomap_ioend_in { uint32_t reserved1; /* zero */ }; +struct fuse_iomap_config_in { +uint64_t flags;/* supported FUSE_IOMAP_CONFIG_* flags */ +int64_t maxbytes;/* max supported file size */ +uint64_t padding[6 ];/* zero */ +}; + +struct fuse_iomap_config_out { +uint64_t flags;/* FUSE_IOMAP_CONFIG_* */ + +char s_id[32 ];/* Informational name */ +char s_uuid[16 ];/* UUID */ + +uint8_t s_uuid_len;/* length of s_uuid */ + +uint8_t s_pad[3 ];/* must be zeroes */ + +uint32_t s_blocksize;/* fs block size */ +uint32_t s_max_links;/* max hard links */ + +/* Granularity of c/m/atime in ns (cannot be worse than a second) */ +uint32_t s_time_gran; + +/* Time limits for c/m/atime in seconds */ +int64_t s_time_min; +int64_t s_time_max; + +int64_t s_maxbytes;/* max file size */ +}; +#endif /* _LINUX_FUSE_H */
include/fuse_lowlevel.h +27 -0
@@ -1408,6 +1408,20 @@ struct fuse_lowlevel_ops { uint64_t attr_ino, off_t pos, size_t written, uint32_t ioendflags, int error, uint64_t new_addr); + +/** +* Configure the filesystem geometry for iomap mode +* +* Valid replies: +* fuse_reply_iomap_config +* fuse_reply_err +* +* @param req request handle +* @param flags FUSE_IOMAP_CONFIG_* flags that can be passed back +* @param maxbytes maximum supported file size +*/ +void (*iomap_config) (fuse_req_t req,uint64_t flags, +uint64_t maxbytes); };/**
@@ -1898,6 +1912,19 @@ void fuse_iomap_pure_overwrite(struct fuse_file_iomap *write,int fuse_reply_iomap_begin (fuse_req_t req,const struct fuse_file_iomap *read,const struct fuse_file_iomap *write); +/** +* Reply with iomap configuration +* +* Possible requests: +* iomap_config +* +* @param req request handle +* @param cfg iomap configuration +* @return zero for success, -errno for failure to send reply +*/ +int fuse_reply_iomap_config (fuse_req_t req, +const struct fuse_iomap_config *cfg); +/* ----------------------------------------------------------- * * Notification * * ----------------------------------------------------------- */
lib/fuse_lowlevel.c +82 -0
100 lines not on this page · raw message
lib/fuse_versionscript +1 -0
@@ -233,6 +233,7 @@ FUSE_3.99 { fuse_fs_can_enable_iomap; fuse_fs_can_enable_iomapx; fuse_lowlevel_discover_iomap; + fuse_reply_iomap_config; } FUSE_3.18; # Local Variables:
PATCH 15/22 libfuse: add upper level iomap_config implementation
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add FUSE_IOMAP_CONFIG helpers to the upper level fuse library.
--- include/fuse.h | 7 +++++++ lib/fuse.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
include/fuse.h +7 -0
@@ -896,6 +896,13 @@ struct fuse_operations {*/ int (*getattr_iflags) (const char *path,struct stat *buf,unsigned int *iflags,struct fuse_file_info *fi); + +/** +* Configure the filesystem geometry that will be used by iomap +* files. +*/ +int (*iomap_config) (uint64_t supported_flags,off_t maxbytes, +struct fuse_iomap_config *cfg); };/** Extra context that may be needed by some filesystems
lib/fuse.c +37 -0
@@ -2942,6 +2942,23 @@ static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path, ioendflags, error, new_addr); } +static int fuse_fs_iomap_config (struct fuse_fs *fs,uint64_t flags, +uint64_t maxbytes, +struct fuse_iomap_config *cfg) +{ +fuse_get_context ()->private_data = fs->user_data; +if (!fs->op.iomap_config) +return -ENOSYS ; + +if (fs->debug) { +fuse_log (FUSE_LOG_DEBUG , +"iomap_config flags 0x%llx maxbytes %lld\n" , + (unsigned long long )flags, (long long )maxbytes); + } + +return fs->op.iomap_config (flags, maxbytes, cfg); +} +static void fuse_lib_setattr (fuse_req_t req,fuse_ino_t ino,struct stat *attr,int valid,struct fuse_file_info *fi) {
@@ -4796,6 +4813,25 @@ static void fuse_lib_iomap_ioend(fuse_req_t req, fuse_ino_t nodeid,reply_err (req, err); } +static void fuse_lib_iomap_config (fuse_req_t req,uint64_t flags, +uint64_t maxbytes) +{ +struct fuse_iomap_config cfg = { }; +struct fuse *f =req_fuse_prepare (req); +struct fuse_intr_data d; +int err; + +fuse_prepare_interrupt (f, req, &d); + err =fuse_fs_iomap_config (f->fs, flags, maxbytes, &cfg); +fuse_finish_interrupt (f, req, &d); +if (err) { +reply_err (req, err); +return ; + } + +fuse_reply_iomap_config (req, &cfg); +} +static int clean_delay (struct fuse *f) {/*
@@ -4900,6 +4936,7 @@ static struct fuse_lowlevel_ops fuse_path_ops = { .iomap_begin = fuse_lib_iomap_begin, .iomap_end = fuse_lib_iomap_end, .iomap_ioend = fuse_lib_iomap_ioend, + .iomap_config = fuse_lib_iomap_config, };int fuse_notify_poll (struct fuse_pollhandle *ph)
PATCH 16/22 libfuse: add low level code to invalidate iomap block device ranges
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make it easier to invalidate the page cache for a block device that is being used in conjunction with iomap. This allows a fuse server to kill all cached data for a block that is being freed, so that block reuse doesn't result in file corruption.
--- include/fuse_kernel.h | 9 +++++++++ include/fuse_lowlevel.h | 15 +++++++++++++++ lib/fuse_lowlevel.c | 22 ++++++++++++++++++++++ lib/fuse_versionscript | 1 + 4 files changed, 47 insertions(+)
include/fuse_kernel.h +9 -0
@@ -244,6 +244,7 @@* - add FUSE_IOMAP and iomap_{begin,end,ioend} for regular file operations * - add FUSE_ATTR_IOMAP to enable iomap for specific inodes * - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry +* - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges */ #ifndef _LINUX_FUSE_H
@@ -694,6 +695,7 @@ enum fuse_notify_code {FUSE_NOTIFY_DELETE =6 ,FUSE_NOTIFY_RESEND =7 ,FUSE_NOTIFY_INC_EPOCH =8 , +FUSE_NOTIFY_IOMAP_DEV_INVAL =99 , FUSE_NOTIFY_CODE_MAX, };
@@ -1404,4 +1406,11 @@ struct fuse_iomap_config_out { int64_t s_maxbytes; /* max file size */ }; +struct fuse_iomap_dev_inval { +uint32_t dev;/* device cookie */ +uint32_t reserved;/* zero */ + +uint64_t offset;/* range to invalidate pagecache, bytes */ +uint64_t length; +};#endif /* _LINUX_FUSE_H */
include/fuse_lowlevel.h +15 -0
@@ -2158,6 +2158,21 @@ int fuse_lowlevel_iomap_device_add(struct fuse_session *se, int fd,*/ int fuse_lowlevel_iomap_device_remove (struct fuse_session *se,int device_id); +/* +* Invalidate the page cache of a block device opened for use with iomap. +* +* Added in FUSE protocol version 7.99. If the kernel does not support +* this (or a newer) version, the function will return -ENOSYS and do +* nothing. +* +* @param se the session object +* @param dev device cookie returned by fuse_lowlevel_iomap_add_device +* @param offset start of the range to invalidate, in bytes +* @return length length of the range to invalidate, in bytes +*/ +int fuse_lowlevel_iomap_device_invalidate (struct fuse_session *se,int dev, +off_t offset,off_t length); +/* ----------------------------------------------------------- * * Utility functions * * ----------------------------------------------------------- */
lib/fuse_lowlevel.c +22 -0
@@ -3548,6 +3548,28 @@ int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,return res; } +int fuse_lowlevel_iomap_device_invalidate (struct fuse_session *se,int dev, +off_t offset,off_t length) +{ +struct fuse_iomap_dev_inval arg = { + .dev = dev, + .offset = offset, + .length = length, + }; +struct iovec iov[2 ]; + +if (!se) +return -EINVAL ; + +if (!(se->conn.want_ext &FUSE_CAP_IOMAP )) +return -ENOSYS ; + + iov[1 ].iov_base = &arg; + iov[1 ].iov_len =sizeof (arg); + +return send_notify_iov (se,FUSE_NOTIFY_IOMAP_DEV_INVAL , iov,2 ); +} +struct fuse_retrieve_req {struct fuse_notify_req nreq;void *cookie;
lib/fuse_versionscript +1 -0
@@ -234,6 +234,7 @@ FUSE_3.99 { fuse_fs_can_enable_iomapx; fuse_lowlevel_discover_iomap; fuse_reply_iomap_config; + fuse_lowlevel_iomap_device_invalidate; } FUSE_3.18; # Local Variables:
PATCH 17/22 libfuse: add upper-level API to invalidate parts of an iomap block device
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Wire up the upper-level wrappers tofuse_lowlevel_iomap_invalidate_device.
--- include/fuse.h | 10 ++++++++++ lib/fuse.c | 9 +++++++++ lib/fuse_versionscript | 1 + 3 files changed, 20 insertions(+)
include/fuse.h +10 -0
@@ -1422,6 +1422,16 @@ int fuse_fs_iomap_device_add(int fd, unsigned int flags);*/ int fuse_fs_iomap_device_remove (int device_id); +/** +* Invalidate any pagecache for the given iomap (block) device. +* +* @param device_id device index as returned by fuse_lowlevel_iomap_device_add +* @param offset starting offset of the range to invalidate +* @param length length of the range to invalidate +* @return 0 on success, or negative errno on failure +*/ +int fuse_fs_iomap_device_invalidate (int device_id,off_t offset,off_t length); +/** * Decide if we can enable iomap mode for a particular file for an upper-level * fuse server.
lib/fuse.c +9 -0
@@ -2921,6 +2921,15 @@ int fuse_fs_iomap_device_remove(int device_id)return fuse_lowlevel_iomap_device_remove (se, device_id); } +int fuse_fs_iomap_device_invalidate (int device_id,off_t offset,off_t length) +{ +struct fuse_context *ctxt =fuse_get_context (); +struct fuse_session *se =fuse_get_session (ctxt->fuse); + +return fuse_lowlevel_iomap_device_invalidate (se, device_id, offset, + length); +} + static int fuse_fs_iomap_ioend(struct fuse_fs *fs, const char *path, uint64_t nodeid, uint64_t attr_ino, off_t pos, size_t written, uint32_t ioendflags, int error,
lib/fuse_versionscript +1 -0
@@ -235,6 +235,7 @@ FUSE_3.99 { fuse_lowlevel_discover_iomap; fuse_reply_iomap_config; fuse_lowlevel_iomap_device_invalidate; + fuse_fs_iomap_device_invalidate; } FUSE_3.18; # Local Variables:
PATCH 18/22 libfuse: add atomic write support
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add the single flag that we need to turn on atomic write support in fuse.
--- include/fuse_common.h | 4 ++++ include/fuse_kernel.h | 3 +++ lib/fuse_lowlevel.c | 2 ++ 3 files changed, 9 insertions(+)
include/fuse_common.h +4 -0
@@ -540,6 +540,8 @@ struct fuse_loop_config_v1 {* FUSE_IOMAP_SUPPORT_FILEIO: basic file I/O functionality through iomap */ #define FUSE_IOMAP_SUPPORT_FILEIO (1ULL << 0) +/* untorn writes through iomap */ +#define FUSE_IOMAP_SUPPORT_ATOMIC (1ULL << 1)/** * Connection information, passed to the ->init() method
@@ -1232,6 +1234,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,#define FUSE_IFLAG_DAX (1U << 0)/* use iomap for this inode */ #define FUSE_IFLAG_IOMAP (1U << 1) +/* enable untorn writes */ +#define FUSE_IFLAG_ATOMIC (1U << 2)/* Which fields are set in fuse_iomap_config_out? */ #define FUSE_IOMAP_CONFIG_SID (1 << 0ULL)
include/fuse_kernel.h +3 -0
@@ -245,6 +245,7 @@* - add FUSE_ATTR_IOMAP to enable iomap for specific inodes * - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry * - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges +* - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support */ #ifndef _LINUX_FUSE_H
@@ -586,10 +587,12 @@ struct fuse_file_lock {* FUSE_ATTR_SUBMOUNT: Object is a submount root * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode * FUSE_ATTR_IOMAP: Use iomap for this inode +* FUSE_ATTR_ATOMIC: Enable untorn writes */ #define FUSE_ATTR_SUBMOUNT (1 << 0)#define FUSE_ATTR_DAX (1 << 1)#define FUSE_ATTR_IOMAP (1 << 2) +#define FUSE_ATTR_ATOMIC (1 << 3)/** * Open flags
lib/fuse_lowlevel.c +2 -0
@@ -127,6 +127,8 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr, attr->flags |=FUSE_ATTR_DAX ;if (iflags &FUSE_IFLAG_IOMAP ) attr->flags |=FUSE_ATTR_IOMAP ; +if (iflags &FUSE_IFLAG_ATOMIC ) + attr->flags |=FUSE_ATTR_ATOMIC ; }static void convert_attr (const struct fuse_setattr_in *attr,struct stat *stbuf)
PATCH 19/22 libfuse: create a helper to transform an open regular file into an open loopdev
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a helper function to configure a loop device for an open regular file fd, and then return an open fd to the loop device. This will enable the use of fuse+iomap file servers with filesystem image files.
--- include/fuse_loopdev.h | 27 +++ include/meson.build | 4 lib/fuse_loopdev.c | 403 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/fuse_versionscript | 1 lib/meson.build | 3 meson.build | 11 + 6 files changed, 448 insertions(+), 1 deletion(-) create mode 100644 include/fuse_loopdev.h create mode 100644 lib/fuse_loopdev.c
include/fuse_loopdev.h new file +27 -0
@@ -0,0 +1,27 @@ +/* FUSE: Filesystem in Userspace +Copyright (C) 2025 Oracle. +Author: Darrick J. Wong <[email protected]> + +This program can be distributed under the terms of the GNU LGPLv2. +See the file LGPL2.txt. +*/ +#ifndef FUSE_LOOPDEV_H_ +#define FUSE_LOOPDEV_H_ + +/** +* If possible, set up a loop device for the given file fd. Return the opened +* loop device fd and the path to the loop device. The loop device will be +* removed when the last close() occurs. +* +* @param file_fd an open file +* @param open_flags O_* flags that were used to open file_fd +* @param path path to the open file +* @param timeout spend this much time waiting to lock the file +* @param loop_fd set to an open fd to the new loop device or -1 if inappropriate +* @param loop_dev (optional) set to a pointer to the path to the loop device +* @return 0 for success, or -1 on error +*/ +int fuse_loopdev_setup (int file_fd,int open_flags,const char *path, +unsigned int timeout,int *loop_fd,char **loop_dev); + +#endif /* FUSE_LOOPDEV_H_ */
include/meson.build +4 -0
@@ -1,4 +1,8 @@ libfuse_headers = [ 'fuse.h', 'fuse_common.h', 'fuse_lowlevel.h', 'fuse_opt.h', 'cuse_lowlevel.h', 'fuse_log.h' ] +if private_cfg.get('FUSE_LOOPDEV_ENABLED') + libfuse_headers += [ 'fuse_loopdev.h' ] +endif + install_headers(libfuse_headers, subdir: 'fuse3')
lib/fuse_loopdev.c new file +403 -0
403 lines not on this page · raw message
lib/fuse_versionscript +1 -0
@@ -236,6 +236,7 @@ FUSE_3.99 { fuse_reply_iomap_config; fuse_lowlevel_iomap_device_invalidate; fuse_fs_iomap_device_invalidate; + fuse_loopdev_setup; } FUSE_3.18; # Local Variables:
lib/meson.build +2 -1
@@ -2,7 +2,8 @@ libfuse_sources = ['fuse.c', 'fuse_i.h', 'fuse_loop.c', 'fuse_loop_mt.c', 'fuse_lowlevel.c', 'fuse_misc.h', 'fuse_opt.c', 'fuse_signals.c', 'buffer.c', 'cuse_lowlevel.c', 'helper.c', 'modules/subdir.c', 'mount_util.c', - 'fuse_log.c', 'compat.c', 'util.c', 'util.h' ] + 'fuse_log.c', 'compat.c', 'util.c', 'util.h', + 'fuse_loopdev.c' ] if host_machine.system().startswith('linux') libfuse_sources += [ 'mount.c' ]
meson.build +11 -0
@@ -153,7 +153,18 @@ private_cfg.set('HAVE_STRUCT_STAT_ST_ATIMESPEC', cc.has_member('struct stat', 'st_atimespec', prefix: include_default + '#include <sys/stat.h>', args: args_default)) +private_cfg.set('HAVE_STRUCT_LOOP_CONFIG_INFO', + cc.has_member('struct loop_config', 'info', + prefix: include_default + '#include <linux/loop.h>', + args: args_default)) +private_cfg.set('HAVE_STATX_BASIC_STATS', + cc.has_member('struct statx', 'stx_ino', + prefix: include_default + '#include <sys/stat.h>', + args: args_default)) +private_cfg.set('FUSE_LOOPDEV_ENABLED', \ + private_cfg.get('HAVE_STRUCT_LOOP_CONFIG_INFO') and \ + private_cfg.get('HAVE_STATX_BASIC_STATS')) private_cfg.set('USDT_ENABLED', get_option('enable-usdt')) # Check for liburing with SQE128 support
PATCH 20/22 libfuse: add swapfile support for iomap files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add flags for swapfile activation and deactivation.
--- include/fuse_common.h | 5 +++++ 1 file changed, 5 insertions(+)
include/fuse_common.h +5 -0
@@ -1190,6 +1190,9 @@ int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn);#define FUSE_IOMAP_OP_ATOMIC (1U << 9)#define FUSE_IOMAP_OP_DONTCACHE (1U << 10) +/* swapfile config operation */ +#define FUSE_IOMAP_OP_SWAPFILE (1U << 30) +/* pagecache writeback operation */ #define FUSE_IOMAP_OP_WRITEBACK (1U << 31)
@@ -1229,6 +1232,8 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,#define FUSE_IOMAP_IOEND_APPEND (1U << 4)/* is pagecache writeback */ #define FUSE_IOMAP_IOEND_WRITEBACK (1U << 5) +/* swapfile deactivation */ +#define FUSE_IOMAP_IOEND_SWAPOFF (1U << 6)/* enable fsdax */ #define FUSE_IFLAG_DAX (1U << 0)
PATCH 21/22 libfuse: add lower-level filesystem freeze, thaw, and shutdown requests
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Pass the kernel's filesystem freeze, thaw, and shutdown requests through to low level fuse servers.
--- include/fuse_kernel.h | 12 +++++++++ include/fuse_lowlevel.h | 35 +++++++++++++++++++++++++++ lib/fuse_lowlevel.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+)
include/fuse_kernel.h +12 -0
@@ -676,6 +676,10 @@ enum fuse_opcode {FUSE_STATX =52 ,FUSE_COPY_FILE_RANGE_64 =53 , +FUSE_FREEZE_FS =4089 , +FUSE_UNFREEZE_FS =4090 , +FUSE_SHUTDOWN_FS =4091 , +FUSE_IOMAP_CONFIG =4092 ,FUSE_IOMAP_IOEND =4093 , FUSE_IOMAP_BEGIN = 4094,
@@ -1225,6 +1229,14 @@ struct fuse_syncfs_in {uint64_t padding; }; +struct fuse_freezefs_in { +uint64_t unlinked; +}; + +struct fuse_shutdownfs_in { +uint64_t flags; +}; +/* * For each security context, send fuse_secctx with size of security context * fuse_secctx will be followed by security context name and this in turn
include/fuse_lowlevel.h +35 -0
@@ -1422,6 +1422,41 @@ struct fuse_lowlevel_ops {*/ void (*iomap_config) (fuse_req_t req,uint64_t flags,uint64_t maxbytes); + +/** +* Freeze the filesystem +* +* Valid replies: +* fuse_reply_err +* +* @param req request handle +* @param ino the root inode number +* @param unlinked count of open unlinked inodes +*/ +void (*freezefs) (fuse_req_t req,fuse_ino_t ino,uint64_t unlinked); + +/** +* Thaw the filesystem +* +* Valid replies: +* fuse_reply_err +* +* @param req request handle +* @param ino the root inode number +*/ +void (*unfreezefs) (fuse_req_t req,fuse_ino_t ino); + +/** +* Shut down the filesystem +* +* Valid replies: +* fuse_reply_err +* +* @param req request handle +* @param ino the root inode number +* @param flags zero, currently +*/ +void (*shutdownfs) (fuse_req_t req,fuse_ino_t ino,uint64_t flags); };/**
lib/fuse_lowlevel.c +60 -0
78 lines not on this page · raw message
PATCH 22/22 libfuse: add upper-level filesystem freeze, thaw, and shutdown events
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Pass filesystem freeze, thaw, and shutdown requests from the low level library to the upper level library so that those fuse servers can handle the events.
--- include/fuse.h | 15 +++++++++ lib/fuse.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+)
include/fuse.h +15 -0
@@ -903,6 +903,21 @@ struct fuse_operations {*/ int (*iomap_config) (uint64_t supported_flags,off_t maxbytes,struct fuse_iomap_config *cfg); + +/** +* Freeze the filesystem +*/ +int (*freezefs) (const char *path,uint64_t unlinked_files); + +/** +* Thaw the filesystem +*/ +int (*unfreezefs) (const char *path); + +/** +* Shut down the filesystem +*/ +int (*shutdownfs) (const char *path,uint64_t flags); };/** Extra context that may be needed by some filesystems
lib/fuse.c +95 -0
113 lines not on this page · raw message
PATCH v6 2/5 libfuse: allow servers to specify root node id
In reply to Darrick J. WongHi all,
This series grants fuse servers full control over the entire node id address space by allowing them to specify the nodeid of the root directory. With this new feature, fuse4fs will not have to translate node ids.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-root-nodeid
---
Commits in this patchset:
* libfuse: allow root_nodeid mount option
--- lib/mount.c | 1 + 1 file changed, 1 insertion(+)
PATCH 1/1 libfuse: allow root_nodeid mount option
From: Darrick J. Wong <[email protected]>
Allow this mount option so that fuse servers can configure the root nodeid if they want to.
--- lib/mount.c | 1 + 1 file changed, 1 insertion(+)
lib/mount.c +1 -0
@@ -100,6 +100,7 @@ static const struct fuse_opt fuse_mount_opts[] = {FUSE_OPT_KEY ("defcontext=" ,KEY_KERN_OPT ),FUSE_OPT_KEY ("rootcontext=" ,KEY_KERN_OPT ),FUSE_OPT_KEY ("max_read=" ,KEY_KERN_OPT ), +FUSE_OPT_KEY ("root_nodeid=" ,KEY_KERN_OPT ),FUSE_OPT_KEY ("user=" ,KEY_MTAB_OPT ),FUSE_OPT_KEY ("-n" ,KEY_MTAB_OPT ), FUSE_OPT_KEY("-r", KEY_RO),
PATCH v6 3/5 libfuse: implement syncfs
In reply to Darrick J. WongHi all,
Implement syncfs in libfuse so that iomap-compatible fuse servers can receive syncfs commands, and enable fuse servers to transmit inode flags to the kernel so that it can enforce sync, immutable, and append. Also enable some of the timestamp update mount options.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-attrs
---
Commits in this patchset:
* libfuse: add strictatime/lazytime mount options
* libfuse: set sync, immutable, and append when loading files
* libfuse: wire up FUSE_SYNCFS to the low level library
* libfuse: add syncfs support to the upper library
--- include/fuse.h | 5 +++++ include/fuse_common.h | 6 ++++++ include/fuse_kernel.h | 8 ++++++++ include/fuse_lowlevel.h | 16 ++++++++++++++++ lib/fuse.c | 31 +++++++++++++++++++++++++++++++ lib/fuse_lowlevel.c | 25 +++++++++++++++++++++++++ lib/mount.c | 18 ++++++++++++++++-- 7 files changed, 107 insertions(+), 2 deletions(-)
PATCH 1/4 libfuse: add strictatime/lazytime mount options
From: Darrick J. Wong <[email protected]>
fuse+iomap leaves the kernel completely in charge of handling timestamps. Add the lazytime and strictatime mount options so that fuse+iomap filesystems can take advantage of those options.
--- lib/mount.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
lib/mount.c +16 -2
@@ -117,9 +117,16 @@ static const struct fuse_opt fuse_mount_opts[] = {FUSE_OPT_KEY ("dirsync" ,KEY_KERN_FLAG ),FUSE_OPT_KEY ("noatime" ,KEY_KERN_FLAG ),FUSE_OPT_KEY ("nodiratime" ,KEY_KERN_FLAG ), -FUSE_OPT_KEY ("nostrictatime" ,KEY_KERN_FLAG ),FUSE_OPT_KEY ("symfollow" ,KEY_KERN_FLAG ),FUSE_OPT_KEY ("nosymfollow" ,KEY_KERN_FLAG ), +#ifdef MS_LAZYTIME +FUSE_OPT_KEY ("lazytime" ,KEY_KERN_FLAG ), +FUSE_OPT_KEY ("nolazytime" ,KEY_KERN_FLAG ), +#endif +#ifdef MS_STRICTATIME +FUSE_OPT_KEY ("strictatime" ,KEY_KERN_FLAG ), +FUSE_OPT_KEY ("nostrictatime" ,KEY_KERN_FLAG ), +#endifFUSE_OPT_END };
@@ -189,11 +196,18 @@ static const struct mount_flags mount_flags[] = { {"noatime", MS_NOATIME, 1}, {"nodiratime", MS_NODIRATIME, 1}, {"norelatime", MS_RELATIME, 0}, - {"nostrictatime", MS_STRICTATIME, 0}, {"symfollow", MS_NOSYMFOLLOW, 0}, {"nosymfollow", MS_NOSYMFOLLOW, 1}, #ifndef __NetBSD__ {"dirsync", MS_DIRSYNC, 1}, +#endif +#ifdef MS_LAZYTIME + {"lazytime", MS_LAZYTIME, 1}, + {"nolazytime", MS_LAZYTIME, 0}, +#endif +#ifdef MS_STRICTATIME + {"strictatime", MS_STRICTATIME, 1}, + {"nostrictatime", MS_STRICTATIME, 0}, #endif {NULL, 0, 0} };
PATCH 2/4 libfuse: set sync, immutable, and append when loading files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add these three fuse_attr::flags bits so that servers can mark a file as immutable or append-only and have the kernel advertise and enforce that.
--- include/fuse_common.h | 6 ++++++ include/fuse_kernel.h | 8 ++++++++ lib/fuse_lowlevel.c | 6 ++++++ 3 files changed, 20 insertions(+)
include/fuse_common.h +6 -0
@@ -1241,6 +1241,12 @@ static inline bool fuse_iomap_need_write_allocate(unsigned int opflags,#define FUSE_IFLAG_IOMAP (1U << 1)/* enable untorn writes */ #define FUSE_IFLAG_ATOMIC (1U << 2) +/* file writes are synchronous */ +#define FUSE_IFLAG_SYNC (1U << 3) +/* file is immutable */ +#define FUSE_IFLAG_IMMUTABLE (1U << 4) +/* file is append only */ +#define FUSE_IFLAG_APPEND (1U << 5)/* Which fields are set in fuse_iomap_config_out? */ #define FUSE_IOMAP_CONFIG_SID (1 << 0ULL)
include/fuse_kernel.h +8 -0
@@ -246,6 +246,8 @@* - add FUSE_IOMAP_CONFIG so the fuse server can configure more fs geometry * - add FUSE_NOTIFY_IOMAP_DEV_INVAL to invalidate iomap bdev ranges * - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support +* - add FUSE_ATTR_{SYNC,IMMUTABLE,APPEND} for VFS enforcement of file +* attributes */ #ifndef _LINUX_FUSE_H
@@ -588,11 +590,17 @@ struct fuse_file_lock {* FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode * FUSE_ATTR_IOMAP: Use iomap for this inode * FUSE_ATTR_ATOMIC: Enable untorn writes +* FUSE_ATTR_SYNC: File writes are always synchronous +* FUSE_ATTR_IMMUTABLE: File is immutable +* FUSE_ATTR_APPEND: File is append-only */ #define FUSE_ATTR_SUBMOUNT (1 << 0)#define FUSE_ATTR_DAX (1 << 1)#define FUSE_ATTR_IOMAP (1 << 2)#define FUSE_ATTR_ATOMIC (1 << 3) +#define FUSE_ATTR_SYNC (1 << 4) +#define FUSE_ATTR_IMMUTABLE (1 << 5) +#define FUSE_ATTR_APPEND (1 << 6)/** * Open flags
lib/fuse_lowlevel.c +6 -0
@@ -129,6 +129,12 @@ static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr, attr->flags |=FUSE_ATTR_IOMAP ;if (iflags &FUSE_IFLAG_ATOMIC ) attr->flags |=FUSE_ATTR_ATOMIC ; +if (iflags &FUSE_IFLAG_SYNC ) + attr->flags |=FUSE_ATTR_SYNC ; +if (iflags &FUSE_IFLAG_IMMUTABLE ) + attr->flags |=FUSE_ATTR_IMMUTABLE ; +if (iflags &FUSE_IFLAG_APPEND ) + attr->flags |=FUSE_ATTR_APPEND ; }static void convert_attr (const struct fuse_setattr_in *attr,struct stat *stbuf)
PATCH 3/4 libfuse: wire up FUSE_SYNCFS to the low level library
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create hooks in the lowlevel library for syncfs.
--- include/fuse_lowlevel.h | 16 ++++++++++++++++ lib/fuse_lowlevel.c | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+)
include/fuse_lowlevel.h +16 -0
@@ -1457,6 +1457,22 @@ struct fuse_lowlevel_ops {* @param flags zero, currently */ void (*shutdownfs) (fuse_req_t req,fuse_ino_t ino,uint64_t flags); + +/* +* Flush the entire filesystem to disk. +* +* If this request is answered with an error code of ENOSYS, this is +* treated as a permanent failure, i.e. all future syncfs() requests +* will fail with the same error code without being sent to the +* filesystem process. +* +* Valid replies: +* fuse_reply_err +* +* @param req request handle +* @param ino the inode number +*/ +void (*syncfs) (fuse_req_t req,fuse_ino_t ino); };/**
lib/fuse_lowlevel.c +19 -0
@@ -2895,6 +2895,23 @@ static void do_shutdownfs(fuse_req_t req, const fuse_ino_t nodeid,_do_shutdownfs (req, nodeid, inarg,NULL ); } +static void _do_syncfs (fuse_req_t req,const fuse_ino_t nodeid, +const void *op_in,const void *in_payload) +{ + (void )op_in; + (void )in_payload; + +if (req->se->op.syncfs) + req->se->op.syncfs (req, nodeid); +else +fuse_reply_err (req,ENOSYS ); +} + +static void do_syncfs (fuse_req_t req,const fuse_ino_t nodeid,const void *inarg) +{ +_do_syncfs (req, nodeid, inarg,NULL ); +} +static bool want_flags_valid (uint64_t capable,uint64_t want) {uint64_t unknown_flags = want & (~capable);
@@ -3824,6 +3841,7 @@ static struct { [FUSE_COPY_FILE_RANGE_64] = { do_copy_file_range_64, "COPY_FILE_RANGE_64" }, [FUSE_LSEEK] = { do_lseek, "LSEEK" }, [FUSE_STATX] = { do_statx, "STATX" }, + [FUSE_SYNCFS] = { do_syncfs, "SYNCFS" }, [FUSE_FREEZE_FS] = { do_freezefs, "FREEZE" }, [FUSE_UNFREEZE_FS] = { do_unfreezefs, "UNFREEZE" }, [FUSE_SHUTDOWN_FS] = { do_shutdownfs, "SHUTDOWN" },
@@ -3887,6 +3905,7 @@ static struct { [FUSE_COPY_FILE_RANGE_64] = { _do_copy_file_range_64, "COPY_FILE_RANGE_64" }, [FUSE_LSEEK] = { _do_lseek, "LSEEK" }, [FUSE_STATX] = { _do_statx, "STATX" }, + [FUSE_SYNCFS] = { _do_syncfs, "SYNCFS" }, [FUSE_FREEZE_FS] = { _do_freezefs, "FREEZE" }, [FUSE_UNFREEZE_FS] = { _do_unfreezefs, "UNFREEZE" }, [FUSE_SHUTDOWN_FS] = { _do_shutdownfs, "SHUTDOWN" },
PATCH 4/4 libfuse: add syncfs support to the upper library
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support syncfs in the upper level library.
--- include/fuse.h | 5 +++++ lib/fuse.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/fuse.h +5 -0
@@ -918,6 +918,11 @@ struct fuse_operations {* Shut down the filesystem */ int (*shutdownfs) (const char *path,uint64_t flags); + +/* +* Flush the entire filesystem to disk. +*/ +int (*syncfs) (const char *path); };/** Extra context that may be needed by some filesystems
lib/fuse.c +31 -0
@@ -3000,6 +3000,16 @@ static int fuse_fs_shutdownfs(struct fuse_fs *fs, const char *path,return fs->op.shutdownfs (path, flags); } +static int fuse_fs_syncfs (struct fuse_fs *fs,const char *path) +{ +fuse_get_context ()->private_data = fs->user_data; +if (!fs->op.syncfs) +return -ENOSYS ; +if (fs->debug) +fuse_log (FUSE_LOG_DEBUG ,"syncfs[%s]\n" , path); +return fs->op.syncfs (path); +} +static void fuse_lib_setattr (fuse_req_t req,fuse_ino_t ino,struct stat *attr,int valid,struct fuse_file_info *fi) {
@@ -4933,6 +4943,26 @@ static void fuse_lib_shutdownfs(fuse_req_t req, fuse_ino_t ino, uint64_t flags)reply_err (req, err); } +static void fuse_lib_syncfs (fuse_req_t req,fuse_ino_t ino) +{ +struct fuse *f =req_fuse_prepare (req); +struct fuse_intr_data d; +char *path; +int err; + + err =get_path (f, ino, &path); +if (err) { +reply_err (req, err); +return ; + } + +fuse_prepare_interrupt (f, req, &d); + err =fuse_fs_syncfs (f->fs, path); +fuse_finish_interrupt (f, req, &d); +free_path (f, ino, path); +reply_err (req, err); +} +static int clean_delay (struct fuse *f) {/*
@@ -5034,6 +5064,7 @@ static struct fuse_lowlevel_ops fuse_path_ops = {#ifdef HAVE_STATX .statx = fuse_lib_statx, #endif + .syncfs = fuse_lib_syncfs, .freezefs = fuse_lib_freezefs, .unfreezefs = fuse_lib_unfreezefs, .shutdownfs = fuse_lib_shutdownfs,
PATCH v6 4/5 libfuse: cache iomap mappings for even better file IO performance
In reply to Darrick J. WongHi all,
This series improves the performance (and correctness for some filesystems) by adding the ability to cache iomap mappings in the kernel. For filesystems that can change mapping states during pagecache writeback (e.g. unwritten extent conversion) this is absolutely necessary to deal with races with writes to the pagecache because writeback does not take i_rwsem. For everyone else, it simply eliminates roundtrips to userspace.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-iomap-cache
---
Commits in this patchset:
* libfuse: enable iomap cache management for lowlevel fuse
* libfuse: add upper-level iomap cache management
* libfuse: enable iomap
--- include/fuse.h | 31 +++++++++++++++++++ include/fuse_common.h | 12 ++++++++ include/fuse_kernel.h | 26 ++++++++++++++++ include/fuse_lowlevel.h | 41 ++++++++++++++++++++++++++ lib/fuse.c | 30 +++++++++++++++++++ lib/fuse_lowlevel.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++- lib/fuse_versionscript | 4 +++ 7 files changed, 217 insertions(+), 2 deletions(-)
PATCH 1/3 libfuse: enable iomap cache management for lowlevel fuse
From: Darrick J. Wong <[email protected]>
Add the library methods so that fuse servers can manage an in-kernel iomap cache. This enables better performance on small IOs and is required if the filesystem needs synchronization between pagecache writes and writeback.
--- include/fuse_common.h | 12 ++++++++ include/fuse_kernel.h | 26 +++++++++++++++++ include/fuse_lowlevel.h | 41 ++++++++++++++++++++++++++ lib/fuse_lowlevel.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++ lib/fuse_versionscript | 2 + 5 files changed, 154 insertions(+)
include/fuse_common.h +12 -0
@@ -1158,6 +1158,10 @@ int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn);/* fuse-specific mapping type indicating that writes use the read mapping */ #define FUSE_IOMAP_TYPE_PURE_OVERWRITE (255) +/* fuse-specific mapping type saying the server has populated the cache */ +#define FUSE_IOMAP_TYPE_RETRY_CACHE (254) +/* do not upsert this mapping */ +#define FUSE_IOMAP_TYPE_NOCACHE (253)#define FUSE_IOMAP_DEV_NULL (0U)/* null device cookie */
@@ -1279,6 +1283,14 @@ struct fuse_iomap_config{int64_t s_maxbytes;/* max file size */ }; +/* invalidate to end of file */ +#define FUSE_IOMAP_INVAL_TO_EOF (~0ULL) + +struct fuse_iomap_inval { +uint64_t offset;/* file offset to invalidate, bytes */ +uint64_t length;/* length to invalidate, bytes */ +}; +/* ----------------------------------------------------------- * * Compatibility stuff * * ----------------------------------------------------------- */
include/fuse_kernel.h +26 -0
@@ -248,6 +248,8 @@* - add FUSE_ATTR_ATOMIC for single-fsblock atomic write support * - add FUSE_ATTR_{SYNC,IMMUTABLE,APPEND} for VFS enforcement of file * attributes +* - add FUSE_NOTIFY_IOMAP_UPSERT and FUSE_NOTIFY_IOMAP_INVAL so fuse servers +* can cache iomappings in the kernel */ #ifndef _LINUX_FUSE_H
@@ -711,6 +713,8 @@ enum fuse_notify_code {FUSE_NOTIFY_RESEND =7 ,FUSE_NOTIFY_INC_EPOCH =8 ,FUSE_NOTIFY_IOMAP_DEV_INVAL =99 , +FUSE_NOTIFY_IOMAP_UPSERT =100 , +FUSE_NOTIFY_IOMAP_INVAL =101 , FUSE_NOTIFY_CODE_MAX, };
@@ -1436,4 +1440,26 @@ struct fuse_iomap_dev_inval {uint64_t offset;/* range to invalidate pagecache, bytes */ uint64_t length; }; + +struct fuse_iomap_inval_out { +uint64_t nodeid;/* Inode ID */ +uint64_t attr_ino;/* matches fuse_attr:ino */ + +uint64_t read_offset;/* range to invalidate read iomaps, bytes */ +uint64_t read_length;/* can be FUSE_IOMAP_INVAL_TO_EOF */ + +uint64_t write_offset;/* range to invalidate write iomaps, bytes */ +uint64_t write_length;/* can be FUSE_IOMAP_INVAL_TO_EOF */ +}; + +struct fuse_iomap_upsert_out { +uint64_t nodeid;/* Inode ID */ +uint64_t attr_ino;/* matches fuse_attr:ino */ + +/* read file data from here */ +struct fuse_iomap_io read; + +/* write file data to here, if applicable */ +struct fuse_iomap_io write; +};#endif /* _LINUX_FUSE_H */
include/fuse_lowlevel.h +41 -0
47 lines not on this page · raw message
lib/fuse_lowlevel.c +73 -0
79 lines not on this page · raw message
lib/fuse_versionscript +2 -0
@@ -237,6 +237,8 @@ FUSE_3.99 { fuse_lowlevel_iomap_device_invalidate; fuse_fs_iomap_device_invalidate; fuse_loopdev_setup; + fuse_lowlevel_notify_iomap_upsert; + fuse_lowlevel_notify_iomap_inval; } FUSE_3.18; # Local Variables:
PATCH 2/3 libfuse: add upper-level iomap cache management
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make it so that upper-level fuse servers can use the iomap cache too.
--- include/fuse.h | 31 +++++++++++++++++++++++++++++++ lib/fuse.c | 30 ++++++++++++++++++++++++++++++ lib/fuse_versionscript | 2 ++ 3 files changed, 63 insertions(+)
include/fuse.h +31 -0
@@ -1470,6 +1470,37 @@ bool fuse_fs_can_enable_iomap(const struct stat *statbuf);*/ bool fuse_fs_can_enable_iomapx (const struct statx *statxbuf); +/* +* Upsert some file mapping information into the kernel. This is necessary +* for filesystems that require coordination of mapping state changes between +* buffered writes and writeback, and desirable for better performance +* elsewhere. +* +* @param nodeid the inode number +* @param attr_ino inode number as told by fuse_attr::ino +* @param read mapping information for file reads +* @param write mapping information for file writes +* @return zero for success, -errno for failure +*/ +int fuse_fs_iomap_upsert (uint64_t nodeid,uint64_t attr_ino, +const struct fuse_file_iomap *read, +const struct fuse_file_iomap *write); + +/** +* Invalidate some file mapping information in the kernel. +* +* @param nodeid the inode number +* @param attr_ino inode number as told by fuse_attr::ino +* @param read_off start of the range of read mappings to invalidate +* @param read_len length of the range of read mappings to invalidate +* @param write_off start of the range of write mappings to invalidate +* @param write_len length of the range of write mappings to invalidate +* @return zero for success, -errno for failure +*/ +int fuse_fs_iomap_inval (uint64_t nodeid,uint64_t attr_ino,loff_t read_off, +uint64_t read_len,loff_t write_off, +uint64_t write_len); +int fuse_notify_poll (struct fuse_pollhandle *ph);/**
lib/fuse.c +30 -0
@@ -3010,6 +3010,36 @@ static int fuse_fs_syncfs(struct fuse_fs *fs, const char *path)return fs->op.syncfs (path); } +int fuse_fs_iomap_upsert (uint64_t nodeid,uint64_t attr_ino, +const struct fuse_file_iomap *read, +const struct fuse_file_iomap *write) +{ +struct fuse_context *ctxt =fuse_get_context (); +struct fuse_session *se =fuse_get_session (ctxt->fuse); + +return fuse_lowlevel_notify_iomap_upsert (se, nodeid, attr_ino, + read, write); +} + +int fuse_fs_iomap_inval (uint64_t nodeid,uint64_t attr_ino,loff_t read_off, +uint64_t read_len,loff_t write_off, +uint64_t write_len) +{ +struct fuse_context *ctxt =fuse_get_context (); +struct fuse_session *se =fuse_get_session (ctxt->fuse); +struct fuse_iomap_inval read = { + .offset = read_off, + .length = read_len, + }; +struct fuse_iomap_inval write = { + .offset = write_off, + .length = write_len, + }; + +return fuse_lowlevel_notify_iomap_inval (se, nodeid, attr_ino, &read, + &write); +} +static void fuse_lib_setattr (fuse_req_t req,fuse_ino_t ino,struct stat *attr,int valid,struct fuse_file_info *fi) {
lib/fuse_versionscript +2 -0
@@ -239,6 +239,8 @@ FUSE_3.99 { fuse_loopdev_setup; fuse_lowlevel_notify_iomap_upsert; fuse_lowlevel_notify_iomap_inval; + fuse_fs_iomap_upsert; + fuse_fs_iomap_inval; } FUSE_3.18; # Local Variables:
PATCH 3/3 libfuse: enable iomap
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Remove the guard that we used to avoid bisection problems.
--- lib/fuse_lowlevel.c | 2 -- 1 file changed, 2 deletions(-)
lib/fuse_lowlevel.c +0 -2
@@ -3111,8 +3111,6 @@ _do_init(fuse_req_t req, const fuse_ino_t nodeid, const void *op_in, se->conn.capable_ext |=FUSE_CAP_OVER_IO_URING ;if (inargflags &FUSE_IOMAP ) se->conn.capable_ext |=FUSE_CAP_IOMAP ; -/* Don't let anyone touch iomap until the end of the patchset. */ - se->conn.capable_ext &= ~FUSE_CAP_IOMAP ; }else { se->conn.max_readahead =0 ; }
PATCH v6 5/5 libfuse: run fuse servers as a contained service
In reply to Darrick J. WongHi all,
This patchset defines the necessary communication protocols and library code so that users can mount fuse servers that run in unprivileged systemd service containers. That in turn allows unprivileged untrusted mounts, because the worst that can happen is that a malicious image crashes the fuse server and the mount dies, instead of corrupting the kernel. As part of the delegation, add a new ioctl allowing any process with an open fusedev fd to ask for permission for anyone with that fusedev fd to use iomap.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fuse-service-container
---
Commits in this patchset:
* libfuse: add systemd/inetd socket service mounting helper
* libfuse: integrate fuse services into mount.fuse3
* libfuse: delegate iomap privilege from mount.service to fuse services
* libfuse: enable setting iomap block device block size
* fuservicemount: create loop devices for regular files
--- include/fuse_kernel.h | 8 include/fuse_lowlevel.h | 23 + include/fuse_service.h | 170 +++++++ include/fuse_service_priv.h | 112 ++++ lib/fuse_i.h | 5 util/mount_service.h | 41 ++ doc/fuservicemount3.8 | 32 + doc/meson.build | 3 include/meson.build | 4 lib/fuse_lowlevel.c | 16 + lib/fuse_service.c | 828 +++++++++++++++++++++++++++++++++ lib/fuse_service_stub.c | 91 ++++ lib/fuse_versionscript | 16 + lib/helper.c | 53 ++ lib/meson.build | 14 + lib/mount.c | 57 ++ meson.build | 36 + meson_options.txt | 6 util/fuservicemount.c | 66 +++ util/meson.build | 13 - util/mount.fuse.c | 58 +- util/mount_service.c | 1086 +++++++++++++++++++++++++++++++++++++++++++ 22 files changed, 2701 insertions(+), 37 deletions(-) create mode 100644 include/fuse_service.h create mode 100644 include/fuse_service_priv.h create mode 100644 util/mount_service.h create mode 100644 doc/fuservicemount3.8 create mode 100644 lib/fuse_service.c create mode 100644 lib/fuse_service_stub.c create mode 100644 util/fuservicemount.c create mode 100644 util/mount_service.c
PATCH 1/5 libfuse: add systemd/inetd socket service mounting helper
From: Darrick J. Wong <[email protected]>
Create a mount.service helper that can start a fuse server that runs as a socket-based systemd (or inetd) service. To make things simpler for fuse server authors, define a new library interface to wrap all the functionality so that they don't have to know the details
This enables untrusted ext4 mounts via systemd service containers, which avoids the problem of malicious filesystems compromising the integrity of the running kernel through memory corruption.
--- include/fuse_service.h | 153 +++++++ include/fuse_service_priv.h | 101 ++++ lib/fuse_i.h | 5 util/mount_service.h | 32 + doc/fuservicemount3.8 | 24 + doc/meson.build | 3 include/meson.build | 4 lib/fuse_service.c | 776 ++++++++++++++++++++++++++++++++++ lib/fuse_service_stub.c | 91 ++++ lib/fuse_versionscript | 13 + lib/helper.c | 53 ++ lib/meson.build | 14 + lib/mount.c | 57 ++- meson.build | 36 ++ meson_options.txt | 6 util/fuservicemount.c | 18 + util/meson.build | 9 util/mount_service.c | 970 +++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 2351 insertions(+), 14 deletions(-) create mode 100644 include/fuse_service.h create mode 100644 include/fuse_service_priv.h create mode 100644 util/mount_service.h create mode 100644 doc/fuservicemount3.8 create mode 100644 lib/fuse_service.c create mode 100644 lib/fuse_service_stub.c create mode 100644 util/fuservicemount.c create mode 100644 util/mount_service.c
include/fuse_service.h new file +153 -0
@@ -0,0 +1,153 @@ +/* FUSE: Filesystem in Userspace +Copyright (C) 2025 Oracle. +Author: Darrick J. Wong <[email protected]> + +This program can be distributed under the terms of the GNU LGPLv2. +See the file LGPL2.txt. +*/ +#ifndef FUSE_SERVICE_H_ +#define FUSE_SERVICE_H_ + +struct fuse_service ; + +/** +* Accept a socket created by mount.service for information exchange. +* +* @param sfp pointer to pointer to a service context +* @return -1 on error, 0 on success +*/ +int fuse_service_accept (struct fuse_service **sfp); + +/** +* Has the fuse server accepted a service context? +* +* @param sf service context +*/ +static inline bool fuse_service_accepted (struct fuse_service *sf) +{ +return sf !=NULL ; +} + +/** +* Release all resources associated with the service context. +* +* @param sfp service context +*/ +void fuse_service_release (struct fuse_service *sf); + +/** +* Destroy a service context and release all resources +* +* @param sfp pointer to pointer to a service context +*/ +void fuse_service_destroy (struct fuse_service **sfp); + +/** +* Append the command line arguments from the mount service helper to an +* existing fuse_args structure. The fuse_args should have been initialized +* with the argc and argv passed to main(). +* +* @param sfp service context +* @param args arguments to modify (input+output) +* @return -1 on success, 0 on success +*/ +int fuse_service_append_args (struct fuse_service *sf,struct fuse_args *args); + +/** +* Generate the effective fuse server command line from the args structure. +* The args structure should be the outcome from fuse_service_append_args. +* The resulting string is suitable for setproctitle and must be freed by the +* callre. +* +* @param argc argument count passed to main() +* @param argv argument vector passed to main() +* @param args fuse args structure +* @return effective command line string, or NULL +*/ +char *fuse_service_cmdline (int argc,char *argv[],struct fuse_args *args); + +/** +* Take the fuse device fd passed from the mount.service helper +* +* @return device fd on success, -1 on error +*/ +int fuse_service_take_fusedev (struct fuse_service *sfp); + +/** +* Utility function to parse common options for simple file systems +* using the low-level API. A help text that describes the available +* options can be printed with `fuse_cmdline_help`. A single +* non-option argument is treated as the mountpoint. Multiple +* non-option arguments will result in an error. +* +* If neither -o subtype= or -o fsname= options are given, a new +* subtype option will be added and set to the basename of the program +* (the fsname will remain unset, and then defaults to "fuse"). +* +* Known options will be removed from *args*, unknown options will +* remain. The mountpoint will not be checked here; that is the job of +* mount.service. +* +* @param args argument vector (input+output) +* @param opts output argument for parsed options +* @return 0 on success, -1 on failure +*/ +int fuse_service_parse_cmdline_opts (struct fuse_args *args, +struct fuse_cmdline_opts *opts); + +/** +* Ask the mount.service helper to open a file on behalf of the fuse server. +* +* @param sf service context +* @param path path to file +* @param open_flags O_ flags +* @param create_mode mode with which to create the file +* @param request_flags set of FUSE_SERVICE_REQUEST_* flags +* @return 0 on success, -1 on failure +*/ +int fuse_service_request_file (struct fuse_service *sf,const char *path, +int open_flags,mode_t create_mode, +unsigned int request_flags); + +/** +* Receive a file perviously requested. +* +* @param sf service context +* @param path to file +* @fdp pointer to file descriptor, which will be set to -1 if the file could +* not be opened +* @return -1 on socket communication failure, 0 otherwise +*/ +int fuse_service_receive_file (struct fuse_service *sf, +const char *path,int *fdp); + +/** +* Prevent the mount.service server from sending us any more open files. +* +* @param sf service context +*/ +int fuse_service_finish_file_requests (struct fuse_service *sf); + +/** +* Ask the mount.service helper to mount the filesystem for us. The fuse client +* will begin sending requests to the fuse server immediately after this. +* +* @param sf service context +* @param se fuse session +* @param mountpoint place to mount the filesystem +* @return 0 on success, -1 on error +*/ +int fuse_service_mount (struct fuse_service *sf,struct fuse_session *se, +const char *mountpoint); + +/** +* Bid farewell to the mount.service helper. It is still necessary to call +* fuse_service_destroy after this. +* +* @param sf service context +* @param error any additional errors to send to the mount helper +* @return 0 on success, -1 on error +*/ +int fuse_service_send_goodbye (struct fuse_service *sf,int error); + +#endif /* FUSE_SERVICE_H_ */
include/fuse_service_priv.h new file +101 -0
101 lines not on this page · raw message
lib/fuse_i.h +5 -0
@@ -217,6 +217,11 @@ unsigned get_max_read(struct mount_opts *o);void fuse_kern_unmount (const char *mountpoint,int fd);int fuse_kern_mount (const char *mountpoint,struct mount_opts *mo); +char *fuse_mountopts_fstype (const struct mount_opts *mo); +char *fuse_mountopts_source (const struct mount_opts *mo,const char *devname); +char *fuse_mountopts_kernel_opts (const struct mount_opts *mo); +unsigned int fuse_mountopts_flags (const struct mount_opts *mo); +int fuse_send_reply_iov_nofree (fuse_req_t req,int error,struct iovec *iov,int count);void fuse_free_req (fuse_req_t req);
util/mount_service.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +FUSE: Filesystem in Userspace +Copyright (C) 2025 Oracle. +Author: Darrick J. Wong <[email protected]> + +This program can be distributed under the terms of the GNU GPLv2. +See the file GPL2.txt. +*/ +#ifndef MOUNT_SERVICE_H_ +#define MOUNT_SERVICE_H_ + +/** +* Connect to a fuse service socket and try to mount the filesystem as +* specified with the CLI arguments. +* +* @argc argument count +* @argv vector of argument strings +* @return EXIT_SUCCESS for success, EXIT_FAILURE if mount fails +*/ +int mount_service_main (int argc,char *argv[]); + +/** +* Return the fuse filesystem subtype from a full fuse filesystem type +* specification. IOWs, fuse.Y -> Y; fuseblk.Z -> Z; or A -> A. The returned +* pointer is within the caller's string. +* +* @param fstype full fuse filesystem type +* @return fuse subtype +*/ +const char *mount_service_subtype (const char *fstype); + +#endif /* MOUNT_SERVICE_H_ */
doc/fuservicemount3.8 new file +24 -0
@@ -0,0 +1,24 @@ +.TH fuservicemount3 "8" +.SH NAME +fuservicemount3 \- mount a FUSE filesystem that runs as a system socket service +.SH SYNOPSIS +.B fuservicemount3 +.B source +.B mountpoint +.BI -t " fstype" +[ +.I options +] +.SH DESCRIPTION +Mount a filesystem using a FUSE server that runs as a socket service. +These servers can be contained using the platform's service management +framework. +.SH "AUTHORS" +.LP +The author of the fuse socket service code is Darrick J. Wong <[email protected]>. +Debian GNU/Linux distribution. +.SH SEE ALSO +.BR fusermount3 (1) +.BR fusermount (1) +.BR mount (8) +.BR fuse (4)
doc/meson.build +3 -0
@@ -2,3 +2,6 @@ if not platform.endswith('bsd') and platform != 'dragonfly' install_man('fusermount3.1', 'mount.fuse3.8') endif +if private_cfg.get('HAVE_SERVICEMOUNT', false) + install_man('fuservicemount3.8') +endif
include/meson.build +4 -0
@@ -5,4 +5,8 @@ if private_cfg.get('FUSE_LOOPDEV_ENABLED') libfuse_headers += [ 'fuse_loopdev.h' ] endif +if private_cfg.get('HAVE_SERVICEMOUNT', false) + libfuse_headers += [ 'fuse_service.h' ] +endif + install_headers(libfuse_headers, subdir: 'fuse3')
lib/fuse_service.c new file +776 -0
776 lines not on this page · raw message
lib/fuse_service_stub.c new file +91 -0
91 lines not on this page · raw message
lib/fuse_versionscript +13 -0
@@ -241,6 +241,19 @@ FUSE_3.99 { fuse_lowlevel_notify_iomap_inval; fuse_fs_iomap_upsert; fuse_fs_iomap_inval; + + fuse_service_accept; + fuse_service_append_args; + fuse_service_destroy; + fuse_service_finish_file_requests; + fuse_service_mount; + fuse_service_cmdline; + fuse_service_parse_cmdline_opts; + fuse_service_receive_file; + fuse_service_release; + fuse_service_request_file; + fuse_service_send_goodbye; + fuse_service_take_fusedev; } FUSE_3.18; # Local Variables:
lib/helper.c +53 -0
71 lines not on this page · raw message
lib/meson.build +13 -1
@@ -11,6 +11,12 @@ else libfuse_sources += [ 'mount_bsd.c' ] endif +if private_cfg.get('HAVE_SERVICEMOUNT', false) + libfuse_sources += [ 'fuse_service.c' ] +else + libfuse_sources += [ 'fuse_service_stub.c' ] +endif + deps = [ thread_dep ] if private_cfg.get('HAVE_ICONV') libfuse_sources += [ 'modules/iconv.c' ]
@@ -55,13 +61,19 @@ libfuse = library('fuse3', link_args: ['-Wl,--version-script,' + meson.current_source_dir() + '/fuse_versionscript' ]) +vars = [] +if private_cfg.get('HAVE_SERVICEMOUNT', false) + service_socket_dir = private_cfg.get_unquoted('FUSE_SERVICE_SOCKET_DIR', '') + vars += ['service_socket_dir=' + service_socket_dir] +endif pkg = import('pkgconfig') pkg.generate(libraries: [ libfuse, '-lpthread' ], libraries_private: '-ldl', version: meson.project_version(), name: 'fuse3', description: 'Filesystem in Userspace', - subdirs: 'fuse3') + subdirs: 'fuse3', + variables: vars) libfuse_dep = declare_dependency(include_directories: include_dirs, link_with: libfuse, dependencies: deps)
lib/mount.c +44 -13
74 lines not on this page · raw message
meson.build +36 -0
@@ -69,6 +69,11 @@ args_default = [ '-D_GNU_SOURCE' ] # private_cfg = configuration_data() private_cfg.set_quoted('PACKAGE_VERSION', meson.project_version()) +service_socket_dir = get_option('service-socket-dir') +if service_socket_dir == '' + service_socket_dir = '/run/filesystems' +endif +private_cfg.set_quoted('FUSE_SERVICE_SOCKET_DIR', service_socket_dir) # Test for presence of some functions test_funcs = [ 'fork', 'fstatat', 'openat', 'readlinkat', 'pipe2',
@@ -191,6 +196,37 @@ if get_option('enable-io-uring') and liburing.found() and libnuma.found() endif endif +# Check for systemd support +systemd_system_unit_dir = get_option('systemdsystemunitdir') +if systemd_system_unit_dir == '' + systemd = dependency('systemd', required: false) + if systemd.found() + systemd_system_unit_dir = systemd.get_variable(pkgconfig: 'systemd_system_unit_dir') + endif +endif + +if systemd_system_unit_dir == '' + warning('could not determine systemdsystemunitdir, systemd stuff will not be installed') +else + private_cfg.set_quoted('SYSTEMD_SYSTEM_UNIT_DIR', systemd_system_unit_dir) + private_cfg.set('HAVE_SYSTEMD', true) +endif + +# Check for libc SCM_RIGHTS support (aka Linux) +code = ''' +#include <sys/socket.h> +int main(void) { + int moo = SCM_RIGHTS; + return moo; +}''' +if cc.links(code, name: 'libc SCM_RIGHTS support') + private_cfg.set('HAVE_SCM_RIGHTS', true) +endif + +if private_cfg.get('HAVE_SCM_RIGHTS', false) and private_cfg.get('HAVE_SYSTEMD', false) + private_cfg.set('HAVE_SERVICEMOUNT', true) +endif + # # Compiler configuration #
meson_options.txt +6 -0
@@ -27,3 +27,9 @@ option('enable-usdt', type : 'boolean', value : false, option('enable-io-uring', type: 'boolean', value: true, description: 'Enable fuse-over-io-uring support') + +option('service-socket-dir', type : 'string', value : '', + description: 'Where to install fuse server sockets (if empty, /run/filesystems)') + +option('systemdsystemunitdir', type : 'string', value : '', + description: 'Where to install systemd unit files (if empty, query pkg-config(1))')
util/fuservicemount.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +FUSE: Filesystem in Userspace +Copyright (C) 2025 Oracle. +Author: Darrick J. Wong <[email protected]> + +This program can be distributed under the terms of the GNU GPLv2. +See the file GPL2.txt. +*/ +/* This program does the mounting of FUSE filesystems that run in systemd */ + +#define _GNU_SOURCE +#include "fuse_config.h" +#include "mount_service.h" + +int main (int argc,char *argv[]) +{ +return mount_service_main (argc, argv); +}
util/meson.build +9 -0
@@ -6,6 +6,15 @@ executable('fusermount3', ['fusermount.c', '../lib/mount_util.c', '../lib/util.c install_dir: get_option('bindir'), c_args: '-DFUSE_CONF="@0@"'.format(fuseconf_path)) +if private_cfg.get('HAVE_SERVICEMOUNT', false) + executable('fuservicemount3', ['mount_service.c', 'fuservicemount.c'], + include_directories: include_dirs, + link_with: [ libfuse ], + install: true, + install_dir: get_option('sbindir'), + c_args: '-DFUSE_USE_VERSION=317') +endif + executable('mount.fuse3', ['mount.fuse.c'], include_directories: include_dirs, link_with: [ libfuse ],
util/mount_service.c new file +970 -0
970 lines not on this page · raw message
PATCH 2/5 libfuse: integrate fuse services into mount.fuse3
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach mount.fuse3 how to start fuse via service, if present.
--- util/mount_service.h | 9 ++++++++ doc/fuservicemount3.8 | 10 ++++++++ util/fuservicemount.c | 48 +++++++++++++++++++++++++++++++++++++++++ util/meson.build | 4 +++ util/mount.fuse.c | 58 +++++++++++++++++++++++++++++++------------------ util/mount_service.c | 18 +++++++++++++++ 6 files changed, 124 insertions(+), 23 deletions(-)
util/mount_service.h +9 -0
@@ -29,4 +29,13 @@ int mount_service_main(int argc, char *argv[]);*/ const char *mount_service_subtype (const char *fstype); +/** +* Discover if there is a fuse service socket for the given fuse subtype. +* +* @param subtype subtype of a fuse filesystem type (e.g. Y from +* mount_service_subtype) +* @return true if available, false if not +*/ +bool mount_service_present (const char *subtype); +#endif /* MOUNT_SERVICE_H_ */
doc/fuservicemount3.8 +9 -1
@@ -7,12 +7,20 @@ .SH SYNOPSIS .B mountpoint .BI -t " fstype" [ -.I options +.BI -o " options" ] + +.B fuservicemount3 +.BI -t " fstype" +.B --check + .SH DESCRIPTION Mount a filesystem using a FUSE server that runs as a socket service. These servers can be contained using the platform's service management framework. + +The second form checks if there is a FUSE service available for the given +filesystem type. .SH "AUTHORS" .LP The author of the fuse socket service code is Darrick J. Wong <[email protected]>.
util/fuservicemount.c +48 -0
58 lines not on this page · raw message
util/meson.build +3 -1
@@ -6,7 +6,9 @@ executable('fusermount3', ['fusermount.c', '../lib/mount_util.c', '../lib/util.c install_dir: get_option('bindir'), c_args: '-DFUSE_CONF="@0@"'.format(fuseconf_path)) +mount_fuse3_sources = ['mount.fuse.c'] if private_cfg.get('HAVE_SERVICEMOUNT', false) + mount_fuse3_sources += ['mount_service.c'] executable('fuservicemount3', ['mount_service.c', 'fuservicemount.c'], include_directories: include_dirs, link_with: [ libfuse ],
@@ -15,7 +17,7 @@ if private_cfg.get('HAVE_SERVICEMOUNT', false) c_args: '-DFUSE_USE_VERSION=317') endif -executable('mount.fuse3', ['mount.fuse.c'], +executable('mount.fuse3', mount_fuse3_sources, include_directories: include_dirs, link_with: [ libfuse ], install: true,
util/mount.fuse.c +37 -21
82 lines not on this page · raw message
util/mount_service.c +18 -0
@@ -968,3 +968,21 @@ int mount_service_main(int argc, char *argv[])mount_service_destroy (&mo);return ret; } + +bool mount_service_present (const char *fstype) +{ +struct stat stbuf; +char path[PATH_MAX ]; +int ret; + +snprintf (path,sizeof (path),FUSE_SERVICE_SOCKET_DIR "/%s" , fstype); + ret =stat (path, &stbuf); +if (ret) +return false; + +if (!S_ISSOCK (stbuf.st_mode)) +return false; + + ret =access (path,R_OK |W_OK ); +return ret ==0 ; +}
PATCH 3/5 libfuse: delegate iomap privilege from mount.service to fuse services
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable the mount.service helper to attach whatever privileges it might have to enable iomap to a /dev/fuse fd before passing that fd to the fuse server. Assuming that the fuse service itself does not have sufficient privilege to enable iomap on its own, it can now inherit that privilege via the fd.
--- include/fuse_kernel.h | 1 + include/fuse_lowlevel.h | 11 +++++++ include/fuse_service.h | 11 +++++++ include/fuse_service_priv.h | 10 +++++++ lib/fuse_lowlevel.c | 5 +++ lib/fuse_service.c | 49 +++++++++++++++++++++++++++++++++ lib/fuse_versionscript | 2 + util/mount_service.c | 64 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 152 insertions(+), 1 deletion(-)
include/fuse_kernel.h +1 -0
@@ -1178,6 +1178,7 @@ struct fuse_iomap_support {#define FUSE_DEV_IOC_BACKING_OPEN _IOW(FUSE_DEV_IOC_MAGIC, 1, \ struct fuse_backing_map)#define FUSE_DEV_IOC_BACKING_CLOSE _IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t) +#define FUSE_DEV_IOC_ADD_IOMAP _IO(FUSE_DEV_IOC_MAGIC, 99)#define FUSE_DEV_IOC_IOMAP_SUPPORT _IOR(FUSE_DEV_IOC_MAGIC, 99, \ struct fuse_iomap_support)
include/fuse_lowlevel.h +10 -1
@@ -2710,7 +2710,6 @@ bool fuse_req_is_uring(fuse_req_t req);int fuse_req_get_payload (fuse_req_t req,char **payload,size_t *payload_sz,void **mr); -/** * Discover the kernel's iomap capabilities. Returns FUSE_CAP_IOMAP_* flags. *
@@ -2720,6 +2719,16 @@ int fuse_req_get_payload(fuse_req_t req, char **payload, size_t *payload_sz,*/ uint64_t fuse_lowlevel_discover_iomap (int fd); +/** +* Request that iomap capabilities be added to this fuse device. This enables +* a privileged mount helper to convey the privileges that allow iomap usage to +* a completely unprivileged fuse server. +* +* @param fd open file descriptor to a fuse device +* @return 0 on success, -1 on failure with errno set +*/ +int fuse_lowlevel_add_iomap (int fd); + #ifdef __cplusplus }#endif
include/fuse_service.h +11 -0
@@ -128,6 +128,17 @@ int fuse_service_receive_file(struct fuse_service *sf,*/ int fuse_service_finish_file_requests (struct fuse_service *sf); +/** +* Attach iomap to the fuse connection. +* +* @param sf service context +* @param mandatory true if the server requires iomap +* @param error result of trying to enable iomap +* @return 0 on success, -1 on error +*/ +int fuse_service_configure_iomap (struct fuse_service *sf,bool mandatory, +int *error); +/** * Ask the mount.service helper to mount the filesystem for us. The fuse client * will begin sending requests to the fuse server immediately after this.
include/fuse_service_priv.h +10 -0
@@ -32,6 +32,7 @@ struct fuse_service_memfd_argv {#define FUSE_SERVICE_MNTPT_CMD 0x4d4e5450/* MNTP */ #define FUSE_SERVICE_MOUNT_CMD 0x444f4954/* DOIT */ #define FUSE_SERVICE_BYE_CMD 0x42594545/* BYEE */ +#define FUSE_SERVICE_IOMAP_CMD 0x494f4d41/* IOMA */ /* mount.service sends replies to the fuse server */ #define FUSE_SERVICE_OPEN_REPLY 0x46494c45/* FILE */
@@ -72,6 +73,15 @@ static inline size_t sizeof_fuse_service_open_command(size_t pathlen)return sizeof (struct fuse_service_open_command ) + pathlen +1 ; } +#define FUSE_IOMAP_MODE_OPTIONAL 0x503F/* P? */ +#define FUSE_IOMAP_MODE_MANDATORY 0x5021/* P! */ + +struct fuse_service_iomap_command { +struct fuse_service_packet p; +__be16 mode; +__be16 padding; +}; +struct fuse_service_string_command {struct fuse_service_packet p;char value[];
lib/fuse_lowlevel.c +5 -0
@@ -4990,3 +4990,8 @@ uint64_t fuse_lowlevel_discover_iomap(int fd)return ios.flags; } + +int fuse_lowlevel_add_iomap (int fd) +{ +return ioctl (fd,FUSE_DEV_IOC_ADD_IOMAP ); +}
lib/fuse_service.c +49 -0
55 lines not on this page · raw message
lib/fuse_versionscript +2 -0
@@ -241,9 +241,11 @@ FUSE_3.99 { fuse_lowlevel_notify_iomap_inval; fuse_fs_iomap_upsert; fuse_fs_iomap_inval; + fuse_lowlevel_add_iomap; fuse_service_accept; fuse_service_append_args; + fuse_service_configure_iomap; fuse_service_destroy; fuse_service_finish_file_requests; fuse_service_mount;
util/mount_service.c +64 -0
94 lines not on this page · raw message
PATCH 4/5 libfuse: enable setting iomap block device block size
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a means for an unprivileged fuse server to set the block size of a block device that it previously opened and associated with the fuse connection.
--- include/fuse_kernel.h | 7 +++++++ include/fuse_lowlevel.h | 12 ++++++++++++ lib/fuse_lowlevel.c | 11 +++++++++++ lib/fuse_versionscript | 1 + 4 files changed, 31 insertions(+)
include/fuse_kernel.h +7 -0
@@ -1172,6 +1172,11 @@ struct fuse_iomap_support {uint64_t padding; }; +struct fuse_iomap_backing_info { +uint32_t backing_id; +uint32_t blocksize; +}; +/* Device ioctls: */ #define FUSE_DEV_IOC_MAGIC 229#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1181,6 +1186,8 @@ struct fuse_iomap_support {#define FUSE_DEV_IOC_ADD_IOMAP _IO(FUSE_DEV_IOC_MAGIC, 99)#define FUSE_DEV_IOC_IOMAP_SUPPORT _IOR(FUSE_DEV_IOC_MAGIC, 99, \ struct fuse_iomap_support) +#define FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE _IOW(FUSE_DEV_IOC_MAGIC, 99, \ + struct fuse_iomap_backing_info)struct fuse_lseek_in {uint64_t fh;
include/fuse_lowlevel.h +12 -0
@@ -2729,6 +2729,18 @@ uint64_t fuse_lowlevel_discover_iomap(int fd);*/ int fuse_lowlevel_add_iomap (int fd); +/** +* Set the block size of an open block device that has been opened for use with +* iomap. +* +* @param fd open file descriptor to a fuse device +* @param dev_index device index returned by fuse_lowlevel_iomap_device_add +* @param blocksize block size in bytes +* @return 0 on success, -1 on failure with errno set +*/ +int fuse_lowlevel_iomap_set_blocksize (int fd,int dev_index, +unsigned int blocksize); + #ifdef __cplusplus }#endif
lib/fuse_lowlevel.c +11 -0
@@ -4995,3 +4995,14 @@ int fuse_lowlevel_add_iomap(int fd) {return ioctl (fd,FUSE_DEV_IOC_ADD_IOMAP ); } + +int fuse_lowlevel_iomap_set_blocksize (int fd,int dev_index, +unsigned int blocksize) +{ +struct fuse_iomap_backing_info fbi = { + .backing_id = dev_index, + .blocksize = blocksize, + }; + +return ioctl (fd,FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE , &fbi); +}
lib/fuse_versionscript +1 -0
@@ -256,6 +256,7 @@ FUSE_3.99 { fuse_service_request_file; fuse_service_send_goodbye; fuse_service_take_fusedev; + fuse_lowlevel_iomap_set_blocksize; } FUSE_3.18; # Local Variables:
PATCH 5/5 fuservicemount: create loop devices for regular files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If a fuse server asks fuservicemount to open a regular file, try to create an auto-clear loop device so that the fuse server can use iomap.
--- include/fuse_service.h | 6 ++++++ include/fuse_service_priv.h | 3 ++- lib/fuse_service.c | 5 ++++- util/mount_service.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-)
include/fuse_service.h +6 -0
@@ -95,6 +95,12 @@ int fuse_service_take_fusedev(struct fuse_service *sfp);int fuse_service_parse_cmdline_opts (struct fuse_args *args,struct fuse_cmdline_opts *opts); +/** +* If the file opened is a regular file, try to create a loop device for it. +* If successful, the loop device is returned; if not, the regular file is. +*/ +#define FUSE_SERVICE_REQUEST_FILE_TRYLOOP (1U << 0) +/** * Ask the mount.service helper to open a file on behalf of the fuse server. *
include/fuse_service_priv.h +2 -1
@@ -58,7 +58,8 @@ static inline size_t sizeof_fuse_service_requested_file(size_t pathlen)return sizeof (struct fuse_service_requested_file ) + pathlen +1 ; } -#define FUSE_SERVICE_OPEN_FLAGS (0) +#define FUSE_SERVICE_OPEN_TRYLOOP (1U << 0) +#define FUSE_SERVICE_OPEN_FLAGS (FUSE_SERVICE_OPEN_TRYLOOP)struct fuse_service_open_command {struct fuse_service_packet p;
lib/fuse_service.c +4 -1
@@ -152,7 +152,7 @@ int fuse_service_receive_file(struct fuse_service *sf, const char *path,return recv_requested_file (sf->sockfd, path, fdp); } -#define FUSE_SERVICE_REQUEST_FILE_FLAGS (0) +#define FUSE_SERVICE_REQUEST_FILE_FLAGS (FUSE_SERVICE_REQUEST_FILE_TRYLOOP) int fuse_service_request_file(struct fuse_service *sf, const char *path, int open_flags, mode_t create_mode,
@@ -177,6 +177,9 @@ int fuse_service_request_file(struct fuse_service *sf, const char *path,return -1 ; } +if (request_flags &FUSE_SERVICE_REQUEST_FILE_TRYLOOP ) + rqflags |=FUSE_SERVICE_OPEN_TRYLOOP ; + cmd =calloc (1 , iov.iov_len);if (!cmd) {perror ("fuse: alloc service file request" );
util/mount_service.c +34 -0
@@ -25,15 +25,20 @@#include <limits.h> #include <sys/stat.h> #include <arpa/inet.h> +#ifdef HAVE_STRUCT_LOOP_CONFIG_INFO +# include <linux/loop.h> +#endif #include "mount_util.h" #include "util.h" #include "fuse_i.h" #include "fuse_service_priv.h" +#include "fuse_loopdev.h" #include "mount_service.h" #define FUSE_KERN_DEVICE_ENV "FUSE_KERN_DEVICE"#define FUSE_DEV "/dev/fuse" +#define LOOPCTL "/dev/loop-control"struct mount_service {/* alleged fuse subtype based on -t cli argument */
@@ -542,6 +547,35 @@ static int mount_service_handle_open_cmd(struct mount_service *mo,return mount_service_send_file_error (mo, error, oc->path); } +if (request_flags &FUSE_SERVICE_OPEN_TRYLOOP ) { +int loop_fd =-1 ; + + ret =fuse_loopdev_setup (fd,ntohl (oc->open_flags), oc->path, +5 , &loop_fd,NULL ); +if (ret) { +/* +* If the setup function returned EBUSY, there is +* already a loop device backed by this file, so we +* must return an error. For any other type of error +* we'll send back the first file we opened. +*/ +if (errno ==EBUSY ) { + ret =mount_service_send_file_error (mo, errno, + oc->path); +close (fd); +return ret; + } + }else if (loop_fd >=0 ) { +/* +* Send back the loop device instead of the file. +*/ + ret =mount_service_send_file (mo, oc->path, loop_fd); +close (loop_fd); +close (fd); +return ret; + } + } + ret =mount_service_send_file (mo, oc->path, fd);close (fd);return ret;
PATCH v6 1/6 fuse2fs: use fuse iomap data paths for better file I/O performance
In reply to Darrick J. WongHi all,
Switch fuse2fs to use the new iomap file data IO paths instead of pushing it very slowly through the /dev/fuse connection. For local filesystems, all we have to do is respond to requests for file to device mappings; the rest of the IO hot path stays within the kernel. This means that we can get rid of all file data block processing within fuse2fs.
Because we're not pinning dirty pages through a potentially slow network connection, we don't need the heavy BDI throttling for which most fuse servers have become infamous. Yes, mapping lookups for writeback can stall, but mappings are small as compared to data and this situation exists for all kernel filesystems as well.
The performance of this new data path is quite stunning: on a warm system, streaming reads and writes through the pagecache go from 60-90MB/s to 2-2.5GB/s. Direct IO reads and writes improve from the same baseline to 2.5-8GB/s. FIEMAP and SEEK_DATA/SEEK_HOLE now work too. The kernel ext4 driver can manage about 1.6GB/s for pagecache IO and about 2.6-8.5GB/s, which means that fuse2fs is about as fast as the kernel for streaming file IO.
Random 4k buffered IO is not so good: plain fuse2fs pokes along at 25-50MB/s, whereas fuse2fs with iomap manages 90-1300MB/s. The kernel can do 900-1300MB/s. Random directio is worse: plain fuse2fs does 20-30MB/s, fuse-iomap does about 30-35MB/s, and the kernel does 40-55MB/s. I suspect that metadata heavy workloads do not perform well on fuse2fs because libext2fs wasn't designed for that and it doesn't even have a journal to absorb all the fsync writes. We also probably need iomap caching really badly.
These performance numbers are slanted: my machine is 12 years old, and fuse2fs is VERY poorly optimized for performance. It contains a single Big Filesystem Lock which nukes multi-threaded scalability. There's no inode cache nor is there a proper buffer cache, which means that fuse2fs reads metadata in from disk and checksums it on EVERY ACCESS. Sad!
Despite these gaps, this RFC demonstrates that it's feasible to run the metadata parsing parts of a filesystem in userspace while not sacrificing much performance. We now have a vehicle to move the filesystems out of the kernel, where they can be containerized so that malicious filesystems can be contained, somewhat.
iomap mode also calls FUSE_DESTROY before unmounting the filesystem, so for capable systems, fuse2fs doesn't need to run in fuseblk mode anymore.
However, there are some major warts remaining:
1. The iomap cookie validation is not present, which can lead to subtle races between pagecache zeroing and writeback on filesystems that support unwritten and delalloc mappings.
2. Mappings ought to be cached in the kernel for more speed.
3. iomap doesn't support things like fscrypt or fsverity, and I haven't yet figured out how inline data is supposed to work.
4. I would like to be able to turn on fuse+iomap on a per-inode basis, which currently isn't possible because the kernel fuse driver will iget inodes prior to calling FUSE_GETATTR to discover the properties of the inode it just read.
5. ext4 doesn't support out of place writes so I don't know if that actually works correctly.
6. iomap is an inode-based service, not a file-based service. This means that we /must/ push ext2's inode numbers into the kernel via FUSE_GETATTR so that it can report those same numbers back out through the FUSE_IOMAP_* calls. However, the fuse kernel uses a separate nodeid to index its incore inode, so we have to pass those too so that notifications work properly.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
Comments and questions are, as always, welcome.
e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-iomap-fileio
---
Commits in this patchset:
* fuse2fs: implement bare minimum iomap for file mapping reporting
* fuse2fs: add iomap= mount option
* fuse2fs: implement iomap configuration
* fuse2fs: register block devices for use with iomap
* fuse2fs: implement directio file reads
* fuse2fs: add extent dump function for debugging
* fuse2fs: implement direct write support
* fuse2fs: turn on iomap for pagecache IO
* fuse2fs: don't zero bytes in punch hole
* fuse2fs: don't do file data block IO when iomap is enabled
* fuse2fs: try to create loop device when ext4 device is a regular file
* fuse2fs: enable file IO to inline data files
* fuse2fs: set iomap-related inode flags
* fuse2fs: configure block device block size
* fuse4fs: separate invalidation
* fuse2fs: implement statx
* fuse2fs: enable atomic writes
--- configure | 88 ++ configure.ac | 54 + fuse4fs/fuse4fs.1.in | 6 fuse4fs/fuse4fs.c | 1780 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/config.h.in | 6 misc/fuse2fs.1.in | 6 misc/fuse2fs.c | 1845 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 3761 insertions(+), 24 deletions(-)
PATCH 1/17 fuse2fs: implement bare minimum iomap for file mapping reporting
From: Darrick J. Wong <[email protected]>
Add enough of an iomap implementation that we can do FIEMAP and SEEK_DATA and SEEK_HOLE.
--- configure | 48 +++++ configure.ac | 31 +++ fuse4fs/fuse4fs.c | 521 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/config.h.in | 3 misc/fuse2fs.c | 521 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1122 insertions(+), 2 deletions(-)
configure +48 -0
@@ -14212,6 +14212,7 @@ printf "%s\n" "yes" >&6; } fi +have_fuse_iomap= if test -n "$FUSE_LIB" then FUSE_USE_VERSION=314
@@ -14237,12 +14238,59 @@ See \`config.log' for more details" "$LINENO" 5; } fi done + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for iomap_begin in libfuse" >&5 +printf %s "checking for iomap_begin in libfuse... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #define _GNU_SOURCE + #define _FILE_OFFSET_BITS 64 + #define FUSE_USE_VERSION 399 + #include <fuse.h> + +int +main (void) +{ + + struct fuse_operations fs_ops = { + .iomap_begin = NULL, + .iomap_end = NULL, + }; + struct fuse_file_iomap narf = { }; + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + have_fuse_iomap=yes + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + if test "$have_fuse_iomap" = yes + then + FUSE_USE_VERSION=399 + fi fi if test -n "$FUSE_USE_VERSION" then printf "%s\n" "#define FUSE_USE_VERSION $FUSE_USE_VERSION" >>confdefs.h +fi +if test -n "$have_fuse_iomap" +then + +printf "%s\n" "#define HAVE_FUSE_IOMAP 1" >>confdefs.h + fi have_fuse_lowlevel=
configure.ac +31 -0
@@ -1382,6 +1382,7 @@ dnl dnl Set FUSE_USE_VERSION, which is how fuse servers build against a particular dnl libfuse ABI. Currently we link against the libfuse 3.14 ABI (hence 314) dnl +have_fuse_iomap= if test -n "$FUSE_LIB" then FUSE_USE_VERSION=314
@@ -1391,12 +1392,42 @@ then [AC_MSG_FAILURE([Cannot build against fuse3 headers])], [#define _FILE_OFFSET_BITS 64 #define FUSE_USE_VERSION 314]) + + dnl + dnl Check if the fuse library supports iomap, which requires a higher + dnl FUSE_USE_VERSION ABI version (3.99) + dnl + AC_MSG_CHECKING(for iomap_begin in libfuse) + AC_LINK_IFELSE( + [ AC_LANG_PROGRAM([[ + #define _GNU_SOURCE + #define _FILE_OFFSET_BITS 64 + #define FUSE_USE_VERSION 399 + #include <fuse.h> + ]], [[ + struct fuse_operations fs_ops = { + .iomap_begin = NULL, + .iomap_end = NULL, + }; + struct fuse_file_iomap narf = { }; + ]]) + ], have_fuse_iomap=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + if test "$have_fuse_iomap" = yes + then + FUSE_USE_VERSION=399 + fi fi if test -n "$FUSE_USE_VERSION" then AC_DEFINE_UNQUOTED(FUSE_USE_VERSION, $FUSE_USE_VERSION, [Define to the version of FUSE to use]) fi +if test -n "$have_fuse_iomap" +then + AC_DEFINE(HAVE_FUSE_IOMAP, 1, [Define to 1 if fuse supports iomap]) +fi dnl dnl Check if the FUSE lowlevel library is supported
fuse4fs/fuse4fs.c +520 -1
593 lines not on this page · raw message
lib/config.h.in +3 -0
@@ -76,6 +76,9 @@ /* Define to 1 if fuse supports lowlevel API */ #undef HAVE_FUSE_LOWLEVEL +/* Define to 1 if fuse supports iomap */ +#undef HAVE_FUSE_IOMAP + /* Define to 1 if you have the Mac OS X function CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */ #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
misc/fuse2fs.c +520 -1
593 lines not on this page · raw message
PATCH 2/17 fuse2fs: add iomap= mount option
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a mount option to control iomap usage so that we can test before and after scenarios.
--- fuse4fs/fuse4fs.1.in | 6 ++++++ fuse4fs/fuse4fs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.1.in | 6 ++++++ misc/fuse2fs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+)
fuse4fs/fuse4fs.1.in +6 -0
@@ -75,6 +75,12 @@ .SS "fuse4fs options:" \fB-o\fR fuse4fs_debug enable fuse4fs debugging .TP +\fB-o\fR iomap= +If set to \fI1\fR, requires iomap to be enabled. +If set to \fI0\fR, forbids use of iomap. +If set to \fIdefault\fR (or not set), enables iomap if present. +This substantially improves the performance of the fuse4fs server. +.TP \fB-o\fR kernel Behave more like the kernel ext4 driver in the following ways: Allows processes owned by other users to access the filesystem.
fuse4fs/fuse4fs.c +46 -0
100 lines not on this page · raw message
misc/fuse2fs.1.in +6 -0
@@ -75,6 +75,12 @@ .SS "fuse2fs options:" \fB-o\fR fuse2fs_debug enable fuse2fs debugging .TP +\fB-o\fR iomap= +If set to \fI1\fR, requires iomap to be enabled. +If set to \fI0\fR, forbids use of iomap. +If set to \fIdefault\fR (or not set), enables iomap if present. +This substantially improves the performance of the fuse2fs server. +.TP \fB-o\fR kernel Behave more like the kernel ext4 driver in the following ways: Allows processes owned by other users to access the filesystem.
misc/fuse2fs.c +46 -0
100 lines not on this page · raw message
PATCH 3/17 fuse2fs: implement iomap configuration
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Upload the filesystem geometry to the kernel when asked.
--- fuse4fs/fuse4fs.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-- misc/fuse2fs.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 186 insertions(+), 6 deletions(-)
fuse4fs/fuse4fs.c +93 -3
@@ -196,6 +196,10 @@ static inline uint64_t round_down(uint64_t b, unsigned int align)# define FL_ZERO_RANGE_FLAG (0)#endif +#ifndef NSEC_PER_SEC +# define NSEC_PER_SEC (1000000000L) +#endif +errcode_t ext2fs_check_ext3_journal (ext2_filsys fs);errcode_t ext2fs_run_ext3_journal (ext2_filsys *fs);
@@ -967,9 +971,9 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)EXT4_INODE_GET_XTIME (i_mtime, &mtime, pinode);get_now (&now); - datime = atime.tv_sec + ((double )atime.tv_nsec /1000000000 ); - dmtime = mtime.tv_sec + ((double )mtime.tv_nsec /1000000000 ); - dnow = now.tv_sec + ((double )now.tv_nsec /1000000000 ); + datime = atime.tv_sec + ((double )atime.tv_nsec /NSEC_PER_SEC ); + dmtime = mtime.tv_sec + ((double )mtime.tv_nsec /NSEC_PER_SEC ); + dnow = now.tv_sec + ((double )now.tv_nsec /NSEC_PER_SEC );/* * If atime is newer than mtime and atime hasn't been updated in thirty
@@ -6221,6 +6225,91 @@ static void op_iomap_end(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare, fuse_reply_err(req, 0); } + +/* +* Maximal extent format file size. +* Resulting logical blkno at s_maxbytes must fit in our on-disk +* extent format containers, within a sector_t, and within i_blocks +* in the vfs. ext4 inode has 48 bits of i_block in fsblock units, +* so that won't be a limiting factor. +* +* However there is other limiting factor. We do store extents in the form +* of starting block and length, hence the resulting length of the extent +* covering maximum file size must fit into on-disk format containers as +* well. Given that length is always by 1 unit bigger than max unit (because +* we count 0 as well) we have to lower the s_maxbytes by one fs block. +* +* Note, this does *not* consider any metadata overhead for vfs i_blocks. +*/ +static off_t fuse4fs_max_size (struct fuse4fs *ff,off_t upper_limit) +{ +off_t res; + +if (!ext2fs_has_feature_huge_file (ff->fs->super)) { + upper_limit = (1LL <<32 ) -1 ; + +/* total blocks in file system block size */ + upper_limit >>= (ff->blocklog -9 ); + upper_limit <<= ff->blocklog; + } + +/* +* 32-bit extent-start container, ee_block. We lower the maxbytes +* by one fs block, so ee_len can cover the extent of maximum file +* size +*/ + res = (1LL <<32 ) -1 ; + res <<= ff->blocklog; + +/* Sanity check against vm- & vfs- imposed limits */ +if (res > upper_limit) + res = upper_limit; + +return res; +} + +static void op_iomap_config (fuse_req_t req,uint64_t flags,uint64_t maxbytes) +{ +struct fuse_iomap_config cfg = { }; +struct fuse4fs *ff =fuse4fs_get (req); +ext2_filsys fs; + +FUSE4FS_CHECK_CONTEXT (req); + +dbg_printf (ff,"%s: flags=0x%llx maxbytes=0x%llx\n" , __func__, + (unsigned long long )flags, + (unsigned long long )maxbytes); + fs =fuse4fs_start (ff); + + cfg.flags |=FUSE_IOMAP_CONFIG_UUID ; +memcpy (cfg.s_uuid, fs->super->s_uuid,sizeof (cfg.s_uuid)); + cfg.s_uuid_len =sizeof (fs->super->s_uuid); + + cfg.flags |=FUSE_IOMAP_CONFIG_BLOCKSIZE ; + cfg.s_blocksize =FUSE4FS_FSB_TO_B (ff,1 ); + +/* +* If there inode is large enough to house i_[acm]time_extra then we +* can turn on nanosecond timestamps; i_crtime was the next field added +* after i_atime_extra. +*/ + cfg.flags |=FUSE_IOMAP_CONFIG_TIME ; +if (fs->super->s_inode_size >= + offsetof(struct ext2_inode_large , i_crtime)) { + cfg.s_time_gran =1 ; + cfg.s_time_max =EXT4_EXTRA_TIMESTAMP_MAX ; + }else { + cfg.s_time_gran =NSEC_PER_SEC ; + cfg.s_time_max =EXT4_NON_EXTRA_TIMESTAMP_MAX ; + } + cfg.s_time_min =EXT4_TIMESTAMP_MIN ; + + cfg.flags |=FUSE_IOMAP_CONFIG_MAXBYTES ; + cfg.s_maxbytes =fuse4fs_max_size (ff, maxbytes); + +fuse4fs_finish (ff,0 ); +fuse_reply_iomap_config (req, &cfg); +}#endif /* HAVE_FUSE_IOMAP */ static struct fuse_lowlevel_ops fs_ops = {
@@ -6269,6 +6358,7 @@ static struct fuse_lowlevel_ops fs_ops = {#ifdef HAVE_FUSE_IOMAP .iomap_begin = op_iomap_begin, .iomap_end = op_iomap_end, + .iomap_config = op_iomap_config,#endif /* HAVE_FUSE_IOMAP */ };
misc/fuse2fs.c +93 -3
120 lines not on this page · raw message
PATCH 4/17 fuse2fs: register block devices for use with iomap
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Register the ext4 block device with the kernel for use with iomap.
--- fuse4fs/fuse4fs.c | 44 ++++++++++++++++++++++++++++++++++++++++---- misc/fuse2fs.c | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 8 deletions(-)
fuse4fs/fuse4fs.c +40 -4
@@ -272,6 +272,7 @@ struct fuse4fs {#ifdef HAVE_FUSE_IOMAP enum fuse4fs_feature_toggle iomap_want;enum fuse4fs_iomap_state iomap_state; +uint32_t iomap_dev;#endif unsigned int blockmask;unsigned long offset;
@@ -6015,7 +6016,7 @@ static errcode_t fuse4fs_iomap_begin_extent(struct fuse4fs *ff, uint64_t ino, }/* Mapping overlaps startoff, report this. */ - iomap->dev =FUSE_IOMAP_DEV_NULL ; + iomap->dev = ff->iomap_dev; iomap->addr =FUSE4FS_FSB_TO_B (ff, extent.e_pblk); iomap->offset =FUSE4FS_FSB_TO_B (ff, extent.e_lblk); iomap->length =FUSE4FS_FSB_TO_B (ff, extent.e_len);
@@ -6048,13 +6049,14 @@ static int fuse4fs_iomap_begin_indirect(struct fuse4fs *ff, uint64_t ino,if (err)return translate_error (fs, ino, err); - iomap->dev =FUSE_IOMAP_DEV_NULL ; iomap->offset =FUSE4FS_FSB_TO_B (ff, startoff); iomap->flags |=FUSE_IOMAP_F_MERGED ;if (startblock) { + iomap->dev = ff->iomap_dev; iomap->addr =FUSE4FS_FSB_TO_B (ff, startblock); iomap->type =FUSE_IOMAP_TYPE_MAPPED ; }else { + iomap->dev =FUSE_IOMAP_DEV_NULL ; iomap->addr =FUSE_IOMAP_NULL_ADDR ; iomap->type =FUSE_IOMAP_TYPE_HOLE ; }
@@ -6268,11 +6270,36 @@ static off_t fuse4fs_max_size(struct fuse4fs *ff, off_t upper_limit)return res; } +static int fuse4fs_iomap_config_devices (struct fuse4fs *ff) +{ +errcode_t err; +int fd; +int ret; + + err =io_channel_get_fd (ff->fs->io, &fd); +if (err) +return translate_error (ff->fs,0 , err); + + 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); + } + +dbg_printf (ff,"%s: registered iomap dev fd=%d iomap_dev=%u\n" , + __func__, fd, ff->iomap_dev); + + ff->iomap_dev = ret; +return 0 ; +} +static void op_iomap_config (fuse_req_t req,uint64_t flags,uint64_t maxbytes) {struct fuse_iomap_config cfg = { };struct fuse4fs *ff =fuse4fs_get (req);ext2_filsys fs; +int ret =0 ;FUSE4FS_CHECK_CONTEXT (req);
@@ -6307,8 +6334,16 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes) cfg.flags |=FUSE_IOMAP_CONFIG_MAXBYTES ; cfg.s_maxbytes =fuse4fs_max_size (ff, maxbytes); -fuse4fs_finish (ff,0 ); - fuse_reply_iomap_config(req, &cfg); + ret =fuse4fs_iomap_config_devices (ff); +if (ret) + goto out_unlock; + +out_unlock: +fuse4fs_finish (ff, ret); +if (ret) +fuse_reply_err (req, -ret); +else + fuse_reply_iomap_config(req, &cfg); }#endif /* HAVE_FUSE_IOMAP */
@@ -6767,6 +6802,7 @@ int main(int argc, char *argv[])#ifdef HAVE_FUSE_IOMAP .iomap_want = FT_DEFAULT, .iomap_state = IOMAP_UNKNOWN, + .iomap_dev = FUSE_IOMAP_DEV_NULL,#endif };errcode_t err;
misc/fuse2fs.c +38 -4
95 lines not on this page · raw message
PATCH 5/17 fuse2fs: implement directio file reads
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Implement file reads via iomap. Currently only directio is supported.
--- fuse4fs/fuse4fs.c | 14 +++++++++++++- misc/fuse2fs.c | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-)
fuse4fs/fuse4fs.c +13 -1
@@ -6138,7 +6138,19 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino, uint64_t count, uint32_t opflags, struct fuse_file_iomap *read) { - return -ENOSYS; + if (!(opflags & FUSE_IOMAP_OP_DIRECT)) + return -ENOSYS; + +/* fall back to slow path for inline data reads */ +if (inode->i_flags &EXT4_INLINE_DATA_FL ) +return -ENOSYS ; + +if (inode->i_flags &EXT4_EXTENTS_FL ) +return fuse4fs_iomap_begin_extent (ff, ino, inode, pos, count, + opflags, read); + +return fuse4fs_iomap_begin_indirect (ff, ino, inode, pos, count, + opflags, read); } static int fuse4fs_iomap_begin_write(struct fuse4fs *ff, ext2_ino_t ino,
misc/fuse2fs.c +13 -1
@@ -5584,7 +5584,19 @@ static int fuse2fs_iomap_begin_read(struct fuse2fs *ff, ext2_ino_t ino, uint64_t count, uint32_t opflags, struct fuse_file_iomap *read) { - return -ENOSYS; + if (!(opflags & FUSE_IOMAP_OP_DIRECT)) + return -ENOSYS; + +/* fall back to slow path for inline data reads */ +if (inode->i_flags &EXT4_INLINE_DATA_FL ) +return -ENOSYS ; + +if (inode->i_flags &EXT4_EXTENTS_FL ) +return fuse2fs_iomap_begin_extent (ff, ino, inode, pos, count, + opflags, read); + +return fuse2fs_iomap_begin_indirect (ff, ino, inode, pos, count, + opflags, read); } static int fuse2fs_iomap_begin_write(struct fuse2fs *ff, ext2_ino_t ino,
PATCH 6/17 fuse2fs: add extent dump function for debugging
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a function to dump an inode's extent map for debugging purposes. This helped debug a problem with generic/299 failing on 1k fsblock filesystems:
--- a/tests/generic/299.out 2025-07-15 14:45:15.030113607 -0700
+++ b/tests/generic/299.out.bad 2025-07-16 19:33:50.889344998 -0700
@@ -3,3 +3,4 @@ QA output created by 299
Run fio with random aio-dio pattern
Start fallocate/truncate loop
+fio: io_u error on file /opt/direct_aio.0.0: Input/output error: write offset=2602827776, buflen=131072
(The cause of this was misuse of the libext2fs extent code)
--- fuse4fs/fuse4fs.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+)
fuse4fs/fuse4fs.c +73 -0
@@ -889,6 +889,74 @@ static inline int fuse4fs_iomap_enabled(const struct fuse4fs *ff)# define fuse4fs_iomap_enabled (...) (0)#endif +static inline void fuse4fs_dump_extents (struct fuse4fs *ff,ext2_ino_t ino, +struct ext2_inode_large *inode, +const char *why) +{ +ext2_filsys fs = ff->fs; +unsigned int nr =0 ; +blk64_t blockcount =0 ; +struct ext2_inode_large xinode; +struct ext2fs_extent extent; +ext2_extent_handle_t extents; +int op =EXT2_EXTENT_ROOT ; +errcode_t retval; + +if (!inode) { + inode = &xinode; + + retval =fuse4fs_read_inode (fs, ino, inode); +if (retval) { +com_err (__func__, retval,_ ("reading ino %u" ), ino); +return ; + } + } + +if (!(inode->i_flags &EXT4_EXTENTS_FL )) +return ; + +printf ("%s: %s ino=%u isize %llu iblocks %llu\n" , __func__, why, ino, +EXT2_I_SIZE (inode), + (ext2fs_get_stat_i_blocks (fs,EXT2_INODE (inode)) *512 ) / + fs->blocksize); +fflush (stdout); + + retval =ext2fs_extent_open (fs, ino, &extents); +if (retval) { +com_err (__func__, retval,_ ("opening extents of ino \"%u\"" ), + ino); +return ; + } + +while ((retval =ext2fs_extent_get (extents, op, &extent)) ==0 ) { + op =EXT2_EXTENT_NEXT ; + +if (extent.e_flags &EXT2_EXTENT_FLAGS_SECOND_VISIT ) +continue ; + +printf ("[%u]: %s ino=%u lblk 0x%llx pblk 0x%llx len 0x%x flags 0x%x\n" , + nr++, why, ino, extent.e_lblk, extent.e_pblk, + extent.e_len, extent.e_flags); +fflush (stdout); +if (extent.e_flags &EXT2_EXTENT_FLAGS_LEAF ) + blockcount += extent.e_len; +else + blockcount++; + } +if (retval ==EXT2_ET_EXTENT_NO_NEXT ) + retval =0 ; +if (retval) { +com_err (__func__, retval, ("getting extents of ino %u" ), + ino); + } +if (inode->i_file_acl) + blockcount++; +printf ("%s: %s sum(e_len) %llu\n" , __func__, why, blockcount); +fflush (stdout); + +ext2fs_extent_free (extents); +} +static void get_now (struct timespec *now) {#ifdef CLOCK_REALTIME
@@ -6210,6 +6278,11 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare, read.type, read.flags); +/* Not filling even the first byte will make the kernel unhappy. */ +if (ff->debug && (read.offset > pos || + read.offset + read.length <= pos)) +fuse4fs_dump_extents (ff, ino, &inode,"BAD DATA" ); + out_unlock:fuse4fs_finish (ff, ret);if (ret)
misc/fuse2fs.c +73 -0
85 lines not on this page · raw message
PATCH 7/17 fuse2fs: implement direct write support
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Wire up an iomap_begin method that can allocate into holes so that we can do directio writes.
--- fuse4fs/fuse4fs.c | 473 +++++++++++++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 470 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 937 insertions(+), 6 deletions(-)
fuse4fs/fuse4fs.c +470 -3
@@ -6221,12 +6221,106 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino, opflags, read); } +static int fuse4fs_iomap_write_allocate (struct fuse4fs *ff,ext2_ino_t ino, +struct ext2_inode_large *inode, +off_t pos,uint64_t count, +uint32_t opflags, +struct fuse_file_iomap *read, +bool *dirty) +{ +ext2_filsys fs = ff->fs; +blk64_t startoff =FUSE4FS_B_TO_FSBT (ff, pos); +blk64_t stopoff =FUSE4FS_B_TO_FSB (ff, pos + count); +blk64_t old_iblocks; +errcode_t err; +int ret; + +dbg_printf (ff, +"%s: ino=%d startoff 0x%llx blockcount 0x%llx\n" , + __func__, ino, startoff, stopoff - startoff); + +if (!fuse4fs_can_allocate (ff, stopoff - startoff)) +return -ENOSPC ; + + old_iblocks =ext2fs_get_stat_i_blocks (fs,EXT2_INODE (inode)); + err =ext2fs_fallocate (fs,EXT2_FALLOCATE_FORCE_UNINIT , ino, +EXT2_INODE (inode), ~0ULL , startoff, + stopoff - startoff); +if (err) +return translate_error (fs, ino, err); + +/* +* New allocations for file data blocks on indirect mapped files are +* zeroed through the IO manager so we have to flush it to disk. +*/ +if (!(inode->i_flags &EXT4_EXTENTS_FL ) && + old_iblocks !=ext2fs_get_stat_i_blocks (fs,EXT2_INODE (inode))) { + err =io_channel_flush (fs->io); +if (err) +return translate_error (fs, ino, err); + } + +/* pick up the newly allocated mapping */ + ret =fuse4fs_iomap_begin_read (ff, ino, inode, pos, count, opflags, + read); +if (ret) +return ret; + + read->flags |=FUSE_IOMAP_F_DIRTY ; + *dirty = true; +return 0 ; +} + +static off_t fuse4fs_max_file_size (const struct fuse4fs *ff, +const struct ext2_inode_large *inode) +{ +ext2_filsys fs = ff->fs; +blk64_t addr_per_block, max_map_block; + +if (inode->i_flags &EXT4_EXTENTS_FL ) { + max_map_block = (1ULL <<32 ) -1 ; + }else { + addr_per_block = fs->blocksize >>2 ; + max_map_block = addr_per_block; + max_map_block += addr_per_block * addr_per_block; + max_map_block += addr_per_block * addr_per_block * addr_per_block; + max_map_block +=12 ; + } + +return FUSE4FS_FSB_TO_B (ff, max_map_block) + (fs->blocksize -1 ); +} +static int fuse4fs_iomap_begin_write (struct fuse4fs *ff,ext2_ino_t ino,struct ext2_inode_large *inode,off_t pos,uint64_t count,uint32_t opflags, -struct fuse_file_iomap *read) +struct fuse_file_iomap *read, +bool *dirty) { -return -ENOSYS ; +off_t max_size =fuse4fs_max_file_size (ff, inode); +int ret; + +if (!(opflags &FUSE_IOMAP_OP_DIRECT )) +return -ENOSYS ; + +if (pos >= max_size) +return -EFBIG ; + +if (pos >= max_size - count) + count = max_size - pos; + + ret =fuse4fs_iomap_begin_read (ff, ino, inode, pos, count, opflags, + read); +if (ret) +return ret; + +if (fuse_iomap_need_write_allocate (opflags, read)) { + ret =fuse4fs_iomap_write_allocate (ff, ino, inode, pos, count, + opflags, read, dirty); +if (ret) +return ret; + } + +return 0 ; } static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
@@ -6238,6 +6332,7 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,ext2_filsys fs;ext2_ino_t ino;errcode_t err; +bool dirty = false;int ret =0 ;FUSE4FS_CHECK_CONTEXT (req);
@@ -6261,7 +6356,7 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare, opflags, &read); else if (fuse_iomap_is_write(opflags)) ret =fuse4fs_iomap_begin_write (ff, ino, &inode, pos, count, - opflags, &read); + opflags, &read, &dirty); else ret =fuse4fs_iomap_begin_read (ff, ino, &inode, pos, count, opflags, &read);
@@ -6283,6 +6378,14 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare, read.offset + read.length <= pos))fuse4fs_dump_extents (ff, ino, &inode,"BAD DATA" ); +if (dirty) { + err =fuse4fs_write_inode (fs, ino, &inode); +if (err) { + ret =translate_error (fs, ino, err); + goto out_unlock; + } + } + out_unlock:fuse4fs_finish (ff, ret);if (ret)
@@ -6430,6 +6533,369 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes) else fuse_reply_iomap_config(req, &cfg); } + +static inline bool fuse4fs_can_merge_mappings(const struct ext2fs_extent *left, + const struct ext2fs_extent *right) +{ +uint64_t max_len = (left->e_flags &EXT2_EXTENT_FLAGS_UNINIT ) ? +EXT_UNINIT_MAX_LEN :EXT_INIT_MAX_LEN ; + + return left->e_lblk + left->e_len == right->e_lblk && + left->e_pblk + left->e_len == right->e_pblk && + (left->e_flags & EXT2_EXTENT_FLAGS_UNINIT) == + (right->e_flags & EXT2_EXTENT_FLAGS_UNINIT) && + (uint64_t)left->e_len + right->e_len <= max_len; +} + +static int fuse4fs_try_merge_mappings(struct fuse4fs *ff, ext2_ino_t ino, + ext2_extent_handle_t handle, + blk64_t startoff) +{ +ext2_filsys fs = ff->fs; +struct ext2fs_extent left, right; +errcode_t err; + +/* Look up the mappings before startoff */ + err =fuse4fs_get_mapping_at (ff, handle, startoff -1 , &left); +if (err ==EXT2_ET_EXTENT_NOT_FOUND ) +return 0 ; +if (err) +return translate_error (fs, ino, err); + +/* Look up the mapping at startoff */ + err =fuse4fs_get_mapping_at (ff, handle, startoff, &right); +if (err ==EXT2_ET_EXTENT_NOT_FOUND ) +return 0 ; +if (err) +return translate_error (fs, ino, err); + +/* Can we combine them? */ +if (!fuse4fs_can_merge_mappings (&left, &right)) +return 0 ; + +/* +* Delete the mapping after startoff because libext2fs cannot handle +* overlapping mappings. +*/ + err =ext2fs_extent_delete (handle,0 ); +DUMP_EXTENT (ff,"remover" , startoff, err, &right); +if (err) +return translate_error (fs, ino, err); + + err =ext2fs_extent_fix_parents (handle); +DUMP_EXTENT (ff,"fixremover" , startoff, err, &right); +if (err) +return translate_error (fs, ino, err); + +/* Move back and lengthen the mapping before startoff */ + err =ext2fs_extent_goto (handle, left.e_lblk); +DUMP_EXTENT (ff,"movel" , startoff -1 , err, &left); +if (err) +return translate_error (fs, ino, err); + + left.e_len += right.e_len; + err =ext2fs_extent_replace (handle,0 , &left); +DUMP_EXTENT (ff,"replacel" , startoff -1 , err, &left); +if (err) +return translate_error (fs, ino, err); + + err =ext2fs_extent_fix_parents (handle); +DUMP_EXTENT (ff,"fixreplacel" , startoff -1 , err, &left); +if (err) +return translate_error (fs, ino, err); + +return 0 ; +} + +static int fuse4fs_convert_unwritten_mapping (struct fuse4fs *ff, +ext2_ino_t ino, +struct ext2_inode_large *inode, +ext2_extent_handle_t handle, +blk64_t *cursor,blk64_t stopoff) +{ +ext2_filsys fs = ff->fs; +struct ext2fs_extent extent; +blk64_t startoff = *cursor; +errcode_t err; + +/* +* Find the mapping at startoff. Note that we can find holes because +* the mapping data can change due to racing writes. +*/ + err =fuse4fs_get_mapping_at (ff, handle, startoff, &extent); +if (err ==EXT2_ET_EXTENT_NOT_FOUND ) { +/* +* If we didn't find any mappings at all then the file is +* completely sparse. There's nothing to convert. +*/ + *cursor = stopoff; +return 0 ; + } +if (err) +return translate_error (fs, ino, err); + +/* +* The mapping is completely to the left of the range that we want. +* Let's see what's in the next extent, if there is one. +*/ +if (startoff >= extent.e_lblk + extent.e_len) { +/* +* Mapping ends to the left of the current position. Try to +* find the next mapping. If there is no next mapping, then +* we're done. +*/ + err =fuse4fs_get_next_mapping (ff, handle, startoff, &extent); +if (err ==EXT2_ET_EXTENT_NOT_FOUND ) { + *cursor = stopoff; +return 0 ; + } +if (err) +return translate_error (fs, ino, err); + } + +/* +* The mapping is completely to the right of the range that we want, +* so we're done. +*/ +if (extent.e_lblk >= stopoff) { + *cursor = stopoff; +return 0 ; + } + +/* +* At this point, we have a mapping that overlaps (startoff, stopoff]. +* If the mapping is already written, move on to the next one. +*/ +if (!(extent.e_flags &EXT2_EXTENT_FLAGS_UNINIT )) + goto next; + +if (startoff > extent.e_lblk) { +struct ext2fs_extent newex = extent; + +/* +* Unwritten mapping starts before startoff. Shorten +* the previous mapping... +*/ + newex.e_len = startoff - extent.e_lblk; + err =ext2fs_extent_replace (handle,0 , &newex); +DUMP_EXTENT (ff,"shortenp" , startoff, err, &newex); +if (err) +return translate_error (fs, ino, err); + + err =ext2fs_extent_fix_parents (handle); +DUMP_EXTENT (ff,"fixshortenp" , startoff, err, &newex); +if (err) +return translate_error (fs, ino, err); + +/* ...and create new written mapping at startoff. */ + extent.e_len -= newex.e_len; + extent.e_lblk += newex.e_len; + extent.e_pblk += newex.e_len; + extent.e_flags = newex.e_flags & ~EXT2_EXTENT_FLAGS_UNINIT ; + + err =ext2fs_extent_insert (handle, +EXT2_EXTENT_INSERT_AFTER , + &extent); +DUMP_EXTENT (ff,"insertx" , startoff, err, &extent); +if (err) +return translate_error (fs, ino, err); + + err =ext2fs_extent_fix_parents (handle); +DUMP_EXTENT (ff,"fixinsertx" , startoff, err, &extent); +if (err) +return translate_error (fs, ino, err); + } + +if (extent.e_lblk + extent.e_len > stopoff) { +struct ext2fs_extent newex = extent; + +/* +* Unwritten mapping ends after stopoff. Shorten the current +* mapping... +*/ + extent.e_len = stopoff - extent.e_lblk; + extent.e_flags &= ~EXT2_EXTENT_FLAGS_UNINIT ; + + err =ext2fs_extent_replace (handle,0 , &extent); +DUMP_EXTENT (ff,"shortenn" , startoff, err, &extent); +if (err) +return translate_error (fs, ino, err); + + err =ext2fs_extent_fix_parents (handle); +DUMP_EXTENT (ff,"fixshortenn" , startoff, err, &extent); +if (err) +return translate_error (fs, ino, err); + +/* ..and create a new unwritten mapping at stopoff. */ + newex.e_pblk += extent.e_len; + newex.e_lblk += extent.e_len; + newex.e_len -= extent.e_len; + newex.e_flags |=EXT2_EXTENT_FLAGS_UNINIT ; + + err =ext2fs_extent_insert (handle, +EXT2_EXTENT_INSERT_AFTER , + &newex); +DUMP_EXTENT (ff,"insertn" , startoff, err, &newex); +if (err) +return translate_error (fs, ino, err); + + err =ext2fs_extent_fix_parents (handle); +DUMP_EXTENT (ff,"fixinsertn" , startoff, err, &newex); +if (err) +return translate_error (fs, ino, err); + } + +/* Still unwritten? Update the state. */ +if (extent.e_flags &EXT2_EXTENT_FLAGS_UNINIT ) { + extent.e_flags &= ~EXT2_EXTENT_FLAGS_UNINIT ; + + err =ext2fs_extent_replace (handle,0 , &extent); +DUMP_EXTENT (ff,"replacex" , startoff, err, &extent); +if (err) +return translate_error (fs, ino, err); + + err =ext2fs_extent_fix_parents (handle); +DUMP_EXTENT (ff,"fixreplacex" , startoff, err, &extent); +if (err) +return translate_error (fs, ino, err); + } + +next: +/* Try to merge with the previous extent */ +if (startoff >0 ) { + err =fuse4fs_try_merge_mappings (ff, ino, handle, startoff); +if (err) +return translate_error (fs, ino, err); + } + + *cursor = extent.e_lblk + extent.e_len; +return 0 ; +} + +static int fuse4fs_convert_unwritten_mappings (struct fuse4fs *ff, +ext2_ino_t ino, +struct ext2_inode_large *inode, +off_t pos,size_t written) +{ +ext2_extent_handle_t handle; +ext2_filsys fs = ff->fs; +blk64_t startoff =FUSE4FS_B_TO_FSBT (ff, pos); +const blk64_t stopoff =FUSE4FS_B_TO_FSB (ff, pos + written); +errcode_t err; +int ret; + + err =ext2fs_extent_open2 (fs, ino,EXT2_INODE (inode), &handle); +if (err) +return translate_error (fs, ino, err); + +/* Walk every mapping in the range, converting them. */ +while (startoff < stopoff) { +blk64_t old_startoff = startoff; + + ret =fuse4fs_convert_unwritten_mapping (ff, ino, inode, handle, + &startoff, stopoff); +if (ret) + goto out_handle; +if (startoff <= old_startoff) { +/* Do not go backwards. */ + ret =translate_error (fs, ino,EXT2_ET_INODE_CORRUPTED ); + goto out_handle; + } + } + +/* Try to merge the right edge */ + ret =fuse4fs_try_merge_mappings (ff, ino, handle, stopoff); +out_handle: +ext2fs_extent_free (handle); +return ret; +} + +static void op_iomap_ioend (fuse_req_t req,fuse_ino_t fino,uint64_t dontcare, +off_t pos,size_t written,uint32_t ioendflags, +int error,uint64_t new_addr) +{ +struct fuse4fs *ff =fuse4fs_get (req); +struct ext2_inode_large inode; +ext2_filsys fs; +ext2_ino_t ino; +errcode_t err; +bool dirty = false; +int ret =0 ; + +FUSE4FS_CHECK_CONTEXT (req); +FUSE4FS_CONVERT_FINO (req, &ino, fino); + +dbg_printf (ff, +"%s: ino=%d pos=0x%llx written=0x%zx ioendflags=0x%x error=%d new_addr=0x%llx\n" , + __func__, ino, + (unsigned long long )pos, + written, + ioendflags, + error, + (unsigned long long )new_addr); + +if (error) { +fuse_reply_err (req, -error); +return ; + } + + fs =fuse4fs_start (ff); + +/* should never see these ioend types */ +if (ioendflags &FUSE_IOMAP_IOEND_SHARED ) { + ret =translate_error (fs, ino,EXT2_ET_FILESYSTEM_CORRUPTED ); + goto out_unlock; + } + + err =fuse4fs_read_inode (fs, ino, &inode); +if (err) { + ret =translate_error (fs, ino, err); + goto out_unlock; + } + +if (ioendflags &FUSE_IOMAP_IOEND_UNWRITTEN ) { +/* unwritten extents are only supported on extents files */ +if (!(inode.i_flags &EXT4_EXTENTS_FL )) { + ret =translate_error (fs, ino, +EXT2_ET_FILESYSTEM_CORRUPTED ); + goto out_unlock; + } + + ret =fuse4fs_convert_unwritten_mappings (ff, ino, &inode, + pos, written); +if (ret) + goto out_unlock; + + dirty = true; + } + +if (ioendflags &FUSE_IOMAP_IOEND_APPEND ) { +ext2_off64_t isize =EXT2_I_SIZE (&inode); + +if (pos + written > isize) { + err =ext2fs_inode_size_set (fs,EXT2_INODE (&inode), + pos + written); +if (err) { + ret =translate_error (fs, ino, err); + goto out_unlock; + } + + dirty = true; + } + } + +if (dirty) { + err =fuse4fs_write_inode (fs, ino, &inode); +if (err) { + ret =translate_error (fs, ino, err); + goto out_unlock; + } + } + +out_unlock: +fuse4fs_finish (ff, ret); +fuse_reply_err (req, -ret); +}#endif /* HAVE_FUSE_IOMAP */ static struct fuse_lowlevel_ops fs_ops = {
@@ -6479,6 +6945,7 @@ static struct fuse_lowlevel_ops fs_ops = { .iomap_begin = op_iomap_begin, .iomap_end = op_iomap_end, .iomap_config = op_iomap_config, + .iomap_ioend = op_iomap_ioend,#endif /* HAVE_FUSE_IOMAP */ };
misc/fuse2fs.c +467 -3
510 lines not on this page · raw message
PATCH 8/17 fuse2fs: turn on iomap for pagecache IO
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Turn on iomap for pagecache IO to regular files.
--- fuse4fs/fuse4fs.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------ misc/fuse2fs.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 108 insertions(+), 14 deletions(-)
fuse4fs/fuse4fs.c +54 -7
@@ -6206,9 +6206,6 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino, uint64_t count, uint32_t opflags, struct fuse_file_iomap *read) { - if (!(opflags & FUSE_IOMAP_OP_DIRECT)) - return -ENOSYS; - /* fall back to slow path for inline data reads */ if (inode->i_flags & EXT4_INLINE_DATA_FL) return -ENOSYS;
@@ -6299,9 +6296,6 @@ static int fuse4fs_iomap_begin_write(struct fuse4fs *ff, ext2_ino_t ino,off_t max_size =fuse4fs_max_file_size (ff, inode);int ret; -if (!(opflags &FUSE_IOMAP_OP_DIRECT )) -return -ENOSYS ; -if (pos >= max_size)return -EFBIG ;
@@ -6394,12 +6388,51 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,fuse_reply_iomap_begin (req, &read,NULL ); } +static int fuse4fs_iomap_append_setsize (struct fuse4fs *ff,ext2_ino_t ino, +loff_t newsize) +{ +ext2_filsys fs = ff->fs; +struct ext2_inode_large inode; +ext2_off64_t isize; +errcode_t err; + +dbg_printf (ff,"%s: ino=%u newsize=%llu\n" , __func__, ino, + (unsigned long long )newsize); + + err =fuse4fs_read_inode (fs, ino, &inode); +if (err) +return translate_error (fs, ino, err); + + isize =EXT2_I_SIZE (&inode); +if (newsize <= isize) +return 0 ; + +dbg_printf (ff,"%s: ino=%u oldsize=%llu newsize=%llu\n" , __func__, ino, + (unsigned long long )isize, + (unsigned long long )newsize); + +/* +* XXX cheesily update the ondisk size even though we only want to do +* the incore size until writeback happens +*/ + err =ext2fs_inode_size_set (fs,EXT2_INODE (&inode), newsize); +if (err) +return translate_error (fs, ino, err); + + err =fuse4fs_write_inode (fs, ino, &inode); +if (err) +return translate_error (fs, ino, err); + +return 0 ; +} +static void op_iomap_end (fuse_req_t req,fuse_ino_t fino,uint64_t dontcare,off_t pos,uint64_t count,uint32_t opflags,ssize_t written,const struct fuse_file_iomap *iomap) {struct fuse4fs *ff =fuse4fs_get (req);ext2_ino_t ino; +int ret =0 ;FUSE4FS_CHECK_CONTEXT (req);FUSE4FS_CONVERT_FINO (req, &ino, fino);
@@ -6413,7 +6446,21 @@ static void op_iomap_end(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare, written, iomap->flags); -fuse_reply_err (req,0 ); +fuse4fs_start (ff); + +/* XXX is this really necessary? */ +if ((opflags &FUSE_IOMAP_OP_WRITE ) && + !(opflags &FUSE_IOMAP_OP_DIRECT ) && + (iomap->flags &FUSE_IOMAP_F_SIZE_CHANGED ) && + written >0 ) { + ret =fuse4fs_iomap_append_setsize (ff, ino, pos + written); +if (ret) + goto out_unlock; + } + +out_unlock: +fuse4fs_finish (ff, ret); +fuse_reply_err (req, -ret); }/*
misc/fuse2fs.c +54 -7
90 lines not on this page · raw message
PATCH 9/17 fuse2fs: don't zero bytes in punch hole
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When iomap is in use for the pagecache, it will take care of zeroing the unaligned parts of punched out regions so we don't have to do it ourselves.
--- fuse4fs/fuse4fs.c | 8 ++++++++ misc/fuse2fs.c | 9 +++++++++ 2 files changed, 17 insertions(+)
fuse4fs/fuse4fs.c +8 -0
@@ -5636,6 +5636,10 @@ static errcode_t fuse4fs_zero_middle(struct fuse4fs *ff, ext2_ino_t ino,int retflags;errcode_t err; +/* the kernel does this for us in iomap mode */ +if (fuse4fs_iomap_enabled (ff)) +return 0 ; +if (!*buf) { err =ext2fs_get_mem (fs->blocksize, buf);if (err)
@@ -5672,6 +5676,10 @@ static errcode_t fuse4fs_zero_edge(struct fuse4fs *ff, ext2_ino_t ino,off_t residue;errcode_t err; +/* the kernel does this for us in iomap mode */ +if (fuse4fs_iomap_enabled (ff)) +return 0 ; + residue =FUSE4FS_OFF_IN_FSB (ff, offset);if (residue ==0 )return 0 ;
misc/fuse2fs.c +9 -0
@@ -726,6 +726,7 @@ static inline int fuse2fs_iomap_enabled(const struct fuse2fs *ff) }#else # define fuse2fs_iomap_enabled (...) (0) +# define fuse2fs_iomap_enabled (...) (0)#endif static inline void fuse2fs_dump_extents(struct fuse2fs *ff, ext2_ino_t ino,
@@ -5083,6 +5084,10 @@ static errcode_t clean_block_middle(struct fuse2fs *ff, ext2_ino_t ino,int retflags;errcode_t err; +/* the kernel does this for us in iomap mode */ +if (fuse2fs_iomap_enabled (ff)) +return 0 ; +if (!*buf) { err =ext2fs_get_mem (fs->blocksize, buf);if (err)
@@ -5119,6 +5124,10 @@ static errcode_t clean_block_edge(struct fuse2fs *ff, ext2_ino_t ino,off_t residue;errcode_t err; +/* the kernel does this for us in iomap mode */ +if (fuse2fs_iomap_enabled (ff)) +return 0 ; + residue =FUSE2FS_OFF_IN_FSB (ff, offset);if (residue ==0 )return 0 ;
PATCH 10/17 fuse2fs: don't do file data block IO when iomap is enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When iomap is in use for the page cache, the kernel will take care of all the file data block IO for us, including zeroing of punched ranges and post-EOF bytes. fuse2fs only needs to do IO for inline data.
Therefore, set the NOBLOCKIO ext2_file flag so that libext2fs will not do any regular file IO to or from disk blocks at all.
--- fuse4fs/fuse4fs.c | 11 +++++++- misc/fuse2fs.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 2 deletions(-)
fuse4fs/fuse4fs.c +10 -1
@@ -3708,9 +3708,14 @@ static int fuse4fs_truncate(struct fuse4fs *ff, ext2_ino_t ino, off_t new_size)ext2_file_t file;__u64 old_isize;errcode_t err; +int flags =EXT2_FILE_WRITE ;int ret =0 ; - err =ext2fs_file_open (fs, ino,EXT2_FILE_WRITE , &file); +/* the kernel handles all eof zeroing for us in iomap mode */ +if (fuse4fs_iomap_enabled (ff)) + flags |=EXT2_FILE_NOBLOCKIO ; + + err =ext2fs_file_open (fs, ino, flags, &file);if (err)return translate_error (fs, ino, err);
@@ -3805,6 +3810,10 @@ static int fuse4fs_open_file(struct fuse4fs *ff, const struct fuse_ctx *ctxt,if (linked) check |=L_OK ; +/* the kernel handles all block IO for us in iomap mode */ +if (fuse4fs_iomap_enabled (ff)) + file->open_flags |=EXT2_FILE_NOBLOCKIO ; +/* * If the caller wants to truncate the file, we need to ask for full * write access even if the caller claims to be appending.
misc/fuse2fs.c +71 -1
92 lines not on this page · raw message
PATCH 11/17 fuse2fs: try to create loop device when ext4 device is a regular file
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If the filesystem device is a regular file, try to create a loop device for it so that we can take advantage of iomap.
--- configure | 40 +++++++++++++++++++ configure.ac | 23 +++++++++++ fuse4fs/fuse4fs.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/config.h.in | 3 + misc/fuse2fs.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 286 insertions(+), 3 deletions(-)
configure +40 -0
@@ -14293,6 +14293,46 @@ printf "%s\n" "#define HAVE_FUSE_IOMAP 1" >>confdefs.h fi +if test -n "$have_fuse_iomap"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fuse_loopdev.h in libfuse" >&5 +printf %s "checking for fuse_loopdev.h in libfuse... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #define _GNU_SOURCE + #define _FILE_OFFSET_BITS 64 + #define FUSE_USE_VERSION 399 + #include <fuse_loopdev.h> + +int +main (void) +{ + + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + have_fuse_loopdev=yes + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +fi +if test -n "$have_fuse_loopdev" +then + +printf "%s\n" "#define HAVE_FUSE_LOOPDEV 1" >>confdefs.h + +fi + have_fuse_lowlevel= if test -n "$FUSE_USE_VERSION" then
configure.ac +23 -0
@@ -1429,6 +1429,29 @@ then AC_DEFINE(HAVE_FUSE_IOMAP, 1, [Define to 1 if fuse supports iomap]) fi +dnl +dnl Check if fuse library has fuse_loopdev.h, which it only gained after adding +dnl iomap support. +dnl +if test -n "$have_fuse_iomap"; then + AC_MSG_CHECKING(for fuse_loopdev.h in libfuse) + AC_LINK_IFELSE( + [ AC_LANG_PROGRAM([[ + #define _GNU_SOURCE + #define _FILE_OFFSET_BITS 64 + #define FUSE_USE_VERSION 399 + #include <fuse_loopdev.h> + ]], [[ + ]]) + ], have_fuse_loopdev=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) +fi +if test -n "$have_fuse_loopdev" +then + AC_DEFINE(HAVE_FUSE_LOOPDEV, 1, [Define to 1 if fuse supports loopdev operations]) +fi + dnl dnl Check if the FUSE lowlevel library is supported dnl
fuse4fs/fuse4fs.c +110 -1
185 lines not on this page · raw message
lib/config.h.in +3 -0
@@ -79,6 +79,9 @@ /* Define to 1 if fuse supports iomap */ #undef HAVE_FUSE_IOMAP +/* Define to 1 if fuse supports loopdev operations */ +#undef HAVE_FUSE_LOOPDEV + /* Define to 1 if you have the Mac OS X function CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */ #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
misc/fuse2fs.c +110 -2
186 lines not on this page · raw message
PATCH 12/17 fuse2fs: enable file IO to inline data files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable file reads and writes from inline data files.
--- fuse4fs/fuse4fs.c | 3 ++- misc/fuse2fs.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-)
fuse4fs/fuse4fs.c +2 -1
@@ -6331,7 +6331,8 @@ static int fuse4fs_iomap_begin_read(struct fuse4fs *ff, ext2_ino_t ino, {/* fall back to slow path for inline data reads */ if (inode->i_flags &EXT4_INLINE_DATA_FL ) -return -ENOSYS ; +return fuse4fs_iomap_begin_inline (ff, ino, inode, pos, count, + read);if (inode->i_flags &EXT4_EXTENTS_FL ) return fuse4fs_iomap_begin_extent(ff, ino, inode, pos, count,
misc/fuse2fs.c +40 -2
88 lines not on this page · raw message
PATCH 13/17 fuse2fs: set iomap-related inode flags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Set FUSE_IFLAG_* when we do a getattr, so that all files will have iomap enabled.
--- fuse4fs/fuse4fs.c | 46 +++++++++++++++++++++++++++++++++++----------- misc/fuse2fs.c | 20 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-)
fuse4fs/fuse4fs.c +35 -11
@@ -2037,6 +2037,7 @@ static void op_init(void *userdata, struct fuse_conn_info *conn)struct fuse4fs_stat {struct fuse_entry_param entry; +unsigned int iflags; }; static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,
@@ -2102,9 +2103,29 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino, entry->attr_timeout =FUSE4FS_ATTR_TIMEOUT ; entry->entry_timeout =FUSE4FS_ATTR_TIMEOUT ; + fstat->iflags =0 ; +#ifdef HAVE_FUSE_IOMAP +if (fuse4fs_iomap_enabled (ff)) + fstat->iflags |=FUSE_IFLAG_IOMAP ; +#endif +return 0 ; } +#if FUSE_VERSION <FUSE_MAKE_VERSION (3 ,99 ) +#define fuse_reply_entry_iflags (req, entry, iflags) \ + fuse_reply_entry((req), (entry)) + +#define fuse_reply_attr_iflags (req, entry, iflags, timeout) \ + fuse_reply_attr((req), (entry), (timeout)) + +#define fuse_add_direntry_plus_iflags (req, buf, sz, name, iflags, entry, dirpos) \ + fuse_add_direntry_plus((req), (buf), (sz), (name), (entry), (dirpos)) + +#define fuse_reply_create_iflags (req, entry, iflags, fp) \ + fuse_reply_create((req), (entry), (fp)) +#endif +static void op_lookup (fuse_req_t req,fuse_ino_t fino,const char *name) {struct fuse4fs_stat fstat;
@@ -2135,7 +2156,7 @@ static void op_lookup(fuse_req_t req, fuse_ino_t fino, const char *name)if (ret)fuse_reply_err (req, -ret);else -fuse_reply_entry (req, &fstat.entry); +fuse_reply_entry_iflags (req, &fstat.entry, fstat.iflags); } static void op_getattr(fuse_req_t req, fuse_ino_t fino,
@@ -2155,8 +2176,8 @@ static void op_getattr(fuse_req_t req, fuse_ino_t fino,if (ret)fuse_reply_err (req, -ret);else -fuse_reply_attr (req, &fstat.entry.attr, - fstat.entry.attr_timeout); +fuse_reply_attr_iflags (req, &fstat.entry.attr, fstat.iflags, + fstat.entry.attr_timeout); }static void op_readlink (fuse_req_t req,fuse_ino_t fino)
@@ -2434,7 +2455,7 @@ static void fuse4fs_reply_entry(fuse_req_t req, ext2_ino_t ino,return ; } -fuse_reply_entry (req, &fstat.entry); +fuse_reply_entry_iflags (req, &fstat.entry, fstat.iflags); } static void op_mknod(fuse_req_t req, fuse_ino_t fino, const char *name,
@@ -4755,10 +4776,13 @@ static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)), namebuf[dirent->name_len &0xFF ] =0 ;if (i->readdirplus) { - entrysize =fuse_add_direntry_plus (i->req, i->buf + i->bufused, - i->bufsz - i->bufused, - namebuf, &fstat.entry, - i->dirpos); + entrysize =fuse_add_direntry_plus_iflags (i->req, + i->buf + i->bufused, + i->bufsz - i->bufused, + namebuf, + fstat.iflags, + &fstat.entry, + i->dirpos); }else { entrysize = fuse_add_direntry(i->req, i->buf + i->bufused, i->bufsz - i->bufused, namebuf,
@@ -4983,7 +5007,7 @@ static void op_create(fuse_req_t req, fuse_ino_t fino, const char *name,if (ret)fuse_reply_err (req, -ret);else -fuse_reply_create (req, &fstat.entry, fp); +fuse_reply_create_iflags (req, &fstat.entry, fstat.iflags, fp); }#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,17 )
@@ -5182,8 +5206,8 @@ static void op_setattr(fuse_req_t req, fuse_ino_t fino, struct stat *attr,if (ret)fuse_reply_err (req, -ret);else -fuse_reply_attr (req, &fstat.entry.attr, - fstat.entry.attr_timeout); +fuse_reply_attr_iflags (req, &fstat.entry.attr, fstat.iflags, + fstat.entry.attr_timeout); }#define FUSE4FS_MODIFIABLE_IFLAGS \
misc/fuse2fs.c +20 -0
@@ -1972,6 +1972,23 @@ static int op_getattr(const char *path, struct stat *statbuf,return ret; } +#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,99 ) +static int op_getattr_iflags (const char *path,struct stat *statbuf, +unsigned int *iflags,struct fuse_file_info *fi) +{ +int ret =op_getattr (path, statbuf, fi); + +if (ret) +return ret; + +if (fuse_fs_can_enable_iomap (statbuf)) + *iflags |=FUSE_IFLAG_IOMAP ; + +return 0 ; +} +#endif + +static int op_readlink (const char *path,char *buf,size_t len) {struct fuse2fs *ff =fuse2fs_get ();
@@ -6647,6 +6664,9 @@ static struct fuse_operations fs_ops = {#ifdef SUPPORT_FALLOCATE .fallocate = op_fallocate,#endif +#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,99 ) + .getattr_iflags = op_getattr_iflags, +#endif #ifdef HAVE_FUSE_IOMAP .iomap_begin = op_iomap_begin, .iomap_end = op_iomap_end,
PATCH 14/17 fuse2fs: configure block device block size
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Set the blocksize of the block device to the filesystem blocksize. This prevents the bdev pagecache from caching file data blocks that iomap will read and write directly. Cache duplication is dangerous.
--- fuse4fs/fuse4fs.c | 43 +++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
fuse4fs/fuse4fs.c +43 -0
@@ -6653,6 +6653,45 @@ static off_t fuse4fs_max_size(struct fuse4fs *ff, off_t upper_limit)return res; } +/* +* Set the block device's blocksize to the fs blocksize. +* +* This is required to avoid creating uptodate bdev pagecache that aliases file +* data blocks because iomap reads and writes directly to file data blocks. +*/ +static int fuse4fs_set_bdev_blocksize (struct fuse4fs *ff,int fd) +{ +int blocksize = ff->fs->blocksize; +int set_error; +int ret; + + ret =ioctl (fd,BLKBSZSET , &blocksize); +if (!ret) +return 0 ; + +/* +* Save the original errno so we can report that if the block device +* blocksize isn't set in an agreeable way. +*/ + set_error = errno; + + ret =ioctl (fd,BLKBSZGET , &blocksize); +if (ret) + goto out_bad; + +/* Pretend that BLKBSZSET rejected our proposed block size */ +if (blocksize > ff->fs->blocksize) { + set_error =EINVAL ; + goto out_bad; + } + +return 0 ; +out_bad: +err_printf (ff,"%s: cannot set blocksize %u: %s\n" , __func__, + blocksize,strerror (set_error)); +return -EIO ; +} +static int fuse4fs_iomap_config_devices (struct fuse4fs *ff) {errcode_t err;
@@ -6663,6 +6702,10 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)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",
misc/fuse2fs.c +43 -0
55 lines not on this page · raw message
PATCH 15/17 fuse4fs: separate invalidation
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use the new stuff
--- fuse4fs/fuse4fs.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+)
fuse4fs/fuse4fs.c +61 -0
@@ -281,6 +281,9 @@ struct fuse4fs {enum fuse4fs_iomap_state iomap_state;uint32_t iomap_dev;uint64_t iomap_cap; +void (*old_alloc_stats)(ext2_filsys fs,blk64_t blk,int inuse); +void (*old_alloc_stats_range)(ext2_filsys fs,blk64_t blk,blk_t num, +int inuse);#endif unsigned int blockmask;unsigned long offset;
@@ -6720,6 +6723,51 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)return 0 ; } +static void fuse4fs_invalidate_bdev (struct fuse4fs *ff,blk64_t blk,blk_t num) +{ +off_t offset =FUSE4FS_FSB_TO_B (ff, blk); +off_t length =FUSE4FS_FSB_TO_B (ff, num); +int ret; + + ret =fuse_lowlevel_iomap_device_invalidate (ff->fuse, ff->iomap_dev, + offset, length); +if (!ret) +return ; + +if (num ==1 ) +err_printf (ff,"%s %llu: %s\n" , +_ ("error invalidating block" ), + (unsigned long long )blk, +strerror (ret)); +else +err_printf (ff,"%s %llu-%llu: %s\n" , +_ ("error invalidating blocks" ), + (unsigned long long )blk, + (unsigned long long )blk + num -1 , +strerror (ret)); +} + +static void fuse4fs_alloc_stats (ext2_filsys fs,blk64_t blk,int inuse) +{ +struct fuse4fs *ff = fs->priv_data; + +if (inuse <0 ) +fuse4fs_invalidate_bdev (ff, blk,1 ); +if (ff->old_alloc_stats) + ff->old_alloc_stats (fs, blk, inuse); +} + +static void fuse4fs_alloc_stats_range (ext2_filsys fs,blk64_t blk,blk_t num, +int inuse) +{ +struct fuse4fs *ff = fs->priv_data; + +if (inuse <0 ) +fuse4fs_invalidate_bdev (ff, blk, num); +if (ff->old_alloc_stats_range) + ff->old_alloc_stats_range (fs, blk, num, inuse); +} +static void op_iomap_config (fuse_req_t req,uint64_t flags,uint64_t maxbytes) {struct fuse_iomap_config cfg = { };
@@ -6764,6 +6812,19 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)if (ret) goto out_unlock; +/* +* If we let iomap do all file block IO, then we need to watch for +* freed blocks so that we can invalidate any page cache that might +* get written to the block deivce. +*/ +if (fuse4fs_iomap_enabled (ff)) { +ext2fs_set_block_alloc_stats_callback (ff->fs, + fuse4fs_alloc_stats, &ff->old_alloc_stats); +ext2fs_set_block_alloc_stats_range_callback (ff->fs, + fuse4fs_alloc_stats_range, + &ff->old_alloc_stats_range); + } + out_unlock:fuse4fs_finish (ff, ret);if (ret)
misc/fuse2fs.c +60 -0
78 lines not on this page · raw message
PATCH 16/17 fuse2fs: implement statx
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Implement statx.
--- fuse4fs/fuse4fs.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 267 insertions(+)
fuse4fs/fuse4fs.c +136 -0
@@ -24,6 +24,7 @@#include <sys/xattr.h> #endif #include <sys/ioctl.h> +#include <sys/sysmacros.h> #include <unistd.h> #include <ctype.h> #include <assert.h>
@@ -2183,6 +2184,138 @@ static void op_getattr(fuse_req_t req, fuse_ino_t fino, fstat.entry.attr_timeout); } +#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,18 ) && defined(STATX_BASIC_STATS ) +static inline void fuse4fs_set_statx_attr (struct statx *stx, +uint64_t statx_flag,int set) +{ +if (set) + stx->stx_attributes |= statx_flag; + stx->stx_attributes_mask |= statx_flag; +} + +static void fuse4fs_statx_directio (struct fuse4fs *ff,struct statx *stx) +{ +struct statx devx; +errcode_t err; +int fd; + + err =io_channel_get_fd (ff->fs->io, &fd); +if (err) +return ; + + err =statx (fd,"" ,AT_EMPTY_PATH ,STATX_DIOALIGN , &devx); +if (err) +return ; +if (!(devx.stx_mask &STATX_DIOALIGN )) +return ; + + stx->stx_mask |=STATX_DIOALIGN ; + stx->stx_dio_mem_align = devx.stx_dio_mem_align; + stx->stx_dio_offset_align = devx.stx_dio_offset_align; +} + +static int fuse4fs_statx (struct fuse4fs *ff,ext2_ino_t ino,int statx_mask, +struct statx *stx) +{ +struct ext2_inode_large inode; +ext2_filsys fs = ff->fs;; +dev_t fakedev =0 ; +errcode_t err; +struct timespec tv; + + err =fuse4fs_read_inode (fs, ino, &inode); +if (err) +return translate_error (fs, ino, err); + +memcpy (&fakedev, fs->super->s_uuid,sizeof (fakedev)); + stx->stx_mask =STATX_BASIC_STATS ; + stx->stx_dev_major =major (fakedev); + stx->stx_dev_minor =minor (fakedev); + stx->stx_ino = ino; + stx->stx_mode = inode.i_mode; + stx->stx_nlink = inode.i_links_count; + stx->stx_uid =inode_uid (inode); + stx->stx_gid =inode_gid (inode); + stx->stx_size =EXT2_I_SIZE (&inode); + stx->stx_blksize = fs->blocksize; + stx->stx_blocks =ext2fs_get_stat_i_blocks (fs, +EXT2_INODE (&inode)); +EXT4_INODE_GET_XTIME (i_atime, &tv, &inode); + stx->stx_atime.tv_sec = tv.tv_sec; + stx->stx_atime.tv_nsec = tv.tv_nsec; + +EXT4_INODE_GET_XTIME (i_mtime, &tv, &inode); + stx->stx_mtime.tv_sec = tv.tv_sec; + stx->stx_mtime.tv_nsec = tv.tv_nsec; + +EXT4_INODE_GET_XTIME (i_ctime, &tv, &inode); + stx->stx_ctime.tv_sec = tv.tv_sec; + stx->stx_ctime.tv_nsec = tv.tv_nsec; + +if (EXT4_FITS_IN_INODE (&inode, i_crtime)) { + stx->stx_mask |=STATX_BTIME ; +EXT4_INODE_GET_XTIME (i_crtime, &tv, &inode); + stx->stx_btime.tv_sec = tv.tv_sec; + stx->stx_btime.tv_nsec = tv.tv_nsec; + } + +dbg_printf (ff,"%s: ino=%d atime=%lld.%d mtime=%lld.%d ctime=%lld.%d btime=%lld.%d\n" , + __func__, ino, + (long long int )stx->stx_atime.tv_sec, stx->stx_atime.tv_nsec, + (long long int )stx->stx_mtime.tv_sec, stx->stx_mtime.tv_nsec, + (long long int )stx->stx_ctime.tv_sec, stx->stx_ctime.tv_nsec, + (long long int )stx->stx_btime.tv_sec, stx->stx_btime.tv_nsec); + +if (LINUX_S_ISCHR (inode.i_mode) || +LINUX_S_ISBLK (inode.i_mode)) { +if (inode.i_block[0 ]) { + stx->stx_rdev_major =major (inode.i_block[0 ]); + stx->stx_rdev_minor =minor (inode.i_block[0 ]); + }else { + stx->stx_rdev_major =major (inode.i_block[1 ]); + stx->stx_rdev_minor =minor (inode.i_block[1 ]); + } + } + +fuse4fs_set_statx_attr (stx,STATX_ATTR_COMPRESSED , + inode.i_flags &EXT2_COMPR_FL ); +fuse4fs_set_statx_attr (stx,STATX_ATTR_IMMUTABLE , + inode.i_flags &EXT2_IMMUTABLE_FL ); +fuse4fs_set_statx_attr (stx,STATX_ATTR_APPEND , + inode.i_flags &EXT2_APPEND_FL ); +fuse4fs_set_statx_attr (stx,STATX_ATTR_NODUMP , + inode.i_flags &EXT2_NODUMP_FL ); + +fuse4fs_statx_directio (ff, stx); + +return 0 ; +} + +static void op_statx (fuse_req_t req,fuse_ino_t fino,int flags,int mask, +struct fuse_file_info *fi) +{ +struct statx stx = { }; +struct fuse4fs *ff =fuse4fs_get (req); +ext2_ino_t ino; +int ret =0 ; + +FUSE4FS_CHECK_CONTEXT (req); +FUSE4FS_CONVERT_FINO (req, &ino, fino); +fuse4fs_start (ff); + ret =fuse4fs_statx (ff, ino, mask, &stx); +if (ret) + goto out; +out: +fuse4fs_finish (ff, ret); +if (ret) +fuse_reply_err (req, -ret); +else +fuse_reply_statx (req,0 , &stx,FUSE4FS_ATTR_TIMEOUT ); +} +#else +# define op_statx NULL +#endif +static void op_readlink (fuse_req_t req,fuse_ino_t fino) {struct ext2_inode inode;
@@ -7240,6 +7373,9 @@ static struct fuse_lowlevel_ops fs_ops = {#ifdef SUPPORT_FALLOCATE .fallocate = op_fallocate,#endif +#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,18 ) + .statx = op_statx, +#endif #ifdef HAVE_FUSE_IOMAP .iomap_begin = op_iomap_begin, .iomap_end = op_iomap_end,
misc/fuse2fs.c +131 -0
149 lines not on this page · raw message
PATCH 17/17 fuse2fs: enable atomic writes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Advertise the single-fsblock atomic write capability that iomap can do.
--- fuse4fs/fuse4fs.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 2 deletions(-)
fuse4fs/fuse4fs.c +66 -1
@@ -285,6 +285,9 @@ struct fuse4fs {void (*old_alloc_stats)(ext2_filsys fs,blk64_t blk,int inuse);void (*old_alloc_stats_range)(ext2_filsys fs,blk64_t blk,blk_t num,int inuse); +#ifdef STATX_WRITE_ATOMIC +unsigned int awu_min, awu_max; +#endif #endif unsigned int blockmask;unsigned long offset;
@@ -910,10 +913,22 @@ static inline bool fuse4fs_can_iomap(const struct fuse4fs *ff) {return ff->iomap_cap &FUSE_IOMAP_SUPPORT_FILEIO ; } + +static inline bool fuse4fs_iomap_supports_hw_atomic (const struct fuse4fs *ff) +{ + return fuse4fs_iomap_enabled(ff) && + (ff->iomap_cap & FUSE_IOMAP_SUPPORT_ATOMIC) && +#ifdef STATX_WRITE_ATOMIC + ff->awu_min >0 && ff->awu_min >0 ; +#else +0 ; +#endif +}#else # define fuse4fs_iomap_enabled (...) (0)# define fuse4fs_discover_iomap (...) ((void)0)# define fuse4fs_can_iomap (...) (false) +# define fuse4fs_iomap_supports_hw_atomic (...) (0)#endif static inline void fuse4fs_dump_extents(struct fuse4fs *ff, ext2_ino_t ino,
@@ -2109,8 +2124,12 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino, fstat->iflags =0 ;#ifdef HAVE_FUSE_IOMAP -if (fuse4fs_iomap_enabled (ff)) +if (fuse4fs_iomap_enabled (ff)) { fstat->iflags |=FUSE_IFLAG_IOMAP ; + +if (fuse4fs_iomap_supports_hw_atomic (ff)) + fstat->iflags |=FUSE_IFLAG_ATOMIC ; + }#endif return 0 ;
@@ -2288,6 +2307,15 @@ static int fuse4fs_statx(struct fuse4fs *ff, ext2_ino_t ino, int statx_mask,fuse4fs_statx_directio (ff, stx); +#ifdef STATX_WRITE_ATOMIC +if (fuse4fs_iomap_supports_hw_atomic (ff)) { + stx->stx_mask |=STATX_WRITE_ATOMIC ; + stx->stx_atomic_write_unit_min = ff->awu_min; + stx->stx_atomic_write_unit_max = ff->awu_max; + stx->stx_atomic_write_segments_max =1 ; + } +#endif +return 0 ; }
@@ -6664,6 +6692,9 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare, } } +if (opflags &FUSE_IOMAP_OP_ATOMIC ) + read.flags |=FUSE_IOMAP_F_ATOMIC_BIO ; + out_unlock:fuse4fs_finish (ff, ret);if (ret)
@@ -6828,6 +6859,38 @@ static int fuse4fs_set_bdev_blocksize(struct fuse4fs *ff, int fd)return -EIO ; } +#ifdef STATX_WRITE_ATOMIC +static void fuse4fs_configure_atomic_write (struct fuse4fs *ff,int bdev_fd) +{ +struct statx devx; +unsigned int awu_min, awu_max; +int ret; + +if (!ext2fs_has_feature_extents (ff->fs->super)) +return ; + + ret =statx (bdev_fd,"" ,AT_EMPTY_PATH ,STATX_WRITE_ATOMIC , &devx); +if (ret) +return ; +if (!(devx.stx_mask &STATX_WRITE_ATOMIC )) +return ; + + awu_min =max (ff->fs->blocksize, devx.stx_atomic_write_unit_min); + awu_max =min (ff->fs->blocksize, devx.stx_atomic_write_unit_max); +if (awu_min > awu_max) +return ; + +log_printf (ff,"%s awu_min: %u, awu_max: %u\n" , +_ ("Supports (experimental) DIO atomic writes" ), + awu_min, awu_max); + + ff->awu_min = awu_min; + ff->awu_max = awu_max; +} +#else +# define fuse4fs_configure_atomic_write (...) ((void)0) +#endif +static int fuse4fs_iomap_config_devices (struct fuse4fs *ff) {errcode_t err;
@@ -6852,6 +6915,8 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)dbg_printf (ff,"%s: registered iomap dev fd=%d iomap_dev=%u\n" , __func__, fd, ff->iomap_dev); +fuse4fs_configure_atomic_write (ff, fd); + ff->iomap_dev = ret;return 0 ; }
misc/fuse2fs.c +68 -1
122 lines not on this page · raw message
PATCH v6 2/6 fuse4fs: specify the root node id
In reply to Darrick J. WongHi all,
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
Comments and questions are, as always, welcome.
e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-root-nodeid
---
Commits in this patchset:
* fuse2fs: implement freeze and shutdown requests
* fuse4fs: don't use inode number translation when possible
--- fuse4fs/fuse4fs.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++--- misc/fuse2fs.c | 84 +++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 6 deletions(-)
PATCH 1/2 fuse2fs: implement freeze and shutdown requests
From: Darrick J. Wong <[email protected]>
Handle freezing and shutting down the filesystem if requested.
--- fuse4fs/fuse4fs.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+)
fuse4fs/fuse4fs.c +91 -0
@@ -228,6 +228,7 @@ struct fuse4fs_file_handle {enum fuse4fs_opstate {F4OP_READONLY , +F4OP_WRITABLE_FROZEN ,F4OP_WRITABLE ,F4OP_SHUTDOWN , };
@@ -6153,6 +6154,91 @@ static void op_fallocate(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)), }#endif /* SUPPORT_FALLOCATE */ +#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,99 ) +static void op_freezefs (fuse_req_t req,fuse_ino_t ino,uint64_t unlinked) +{ +struct fuse4fs *ff =fuse4fs_get (req); +ext2_filsys fs; +errcode_t err; +int ret =0 ; + +FUSE4FS_CHECK_CONTEXT (req); + fs =fuse4fs_start (ff); + +if (ff->opstate ==F4OP_WRITABLE ) { +if (fs->super->s_error_count) + fs->super->s_state |=EXT2_ERROR_FS ; +else if (!unlinked) + fs->super->s_state |=EXT2_VALID_FS ; +ext2fs_mark_super_dirty (fs); + err =ext2fs_set_gdt_csum (fs); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + + err =ext2fs_flush2 (fs,0 ); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + + ff->opstate =F4OP_WRITABLE_FROZEN ; + } + +out_unlock: + fs->super->s_state &= ~EXT2_VALID_FS ; +fuse4fs_finish (ff, ret); +fuse_reply_err (req, -ret); +} + +static void op_unfreezefs (fuse_req_t req,fuse_ino_t ino) +{ +struct fuse4fs *ff =fuse4fs_get (req); +ext2_filsys fs; +errcode_t err; +int ret =0 ; + +FUSE4FS_CHECK_CONTEXT (req); + fs =fuse4fs_start (ff); + +if (ff->opstate ==F4OP_WRITABLE_FROZEN ) { +if (fs->super->s_error_count) + fs->super->s_state |=EXT2_ERROR_FS ; + fs->super->s_state &= ~EXT2_VALID_FS ; +ext2fs_mark_super_dirty (fs); + err =ext2fs_set_gdt_csum (fs); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + + err =ext2fs_flush2 (fs,0 ); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + + ff->opstate =F4OP_WRITABLE ; + } + +out_unlock: +fuse4fs_finish (ff, ret); +fuse_reply_err (req, -ret); +} + +static void op_shutdownfs (fuse_req_t req,fuse_ino_t ino,uint64_t flags) +{ +const struct fuse_ctx *ctxt =fuse_req_ctx (req); +struct fuse4fs *ff =fuse4fs_get (req); +int ret; + + ret =ioctl_shutdown (ff, ctxt,NULL ,NULL ,0 ); + +fuse_reply_err (req, -ret); +} +#endif +#ifdef HAVE_FUSE_IOMAP static void fuse4fs_iomap_hole (struct fuse4fs *ff,struct fuse_file_iomap *iomap,off_t pos,uint64_t count)
@@ -7441,6 +7527,11 @@ static struct fuse_lowlevel_ops fs_ops = {#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,18 ) .statx = op_statx,#endif +#if FUSE_VERSION >=FUSE_MAKE_VERSION (3 ,99 ) + .freezefs = op_freezefs, + .unfreezefs = op_unfreezefs, + .shutdownfs = op_shutdownfs, +#endif #ifdef HAVE_FUSE_IOMAP .iomap_begin = op_iomap_begin, .iomap_end = op_iomap_end,
misc/fuse2fs.c +84 -0
102 lines not on this page · raw message
PATCH 2/2 fuse4fs: don't use inode number translation when possible
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Prior to the integration of iomap into fuse, the fuse client (aka the kernel) required that the root directory have an inumber of FUSE_ROOT_ID, which is 1. However, the ext2 filesystem defines the root inode number to be EXT2_ROOT_INO, which is 2. This dissonance means that we have to have translator functions, and that any access to inumber 1 (the ext2 badblocks file) will instead redirect to the root directory.
That's horrible. Use the new mount option to set the root directory nodeid to EXT2_ROOT_INO so that we don't need this translation.
--- fuse4fs/fuse4fs.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
fuse4fs/fuse4fs.c +24 -6
@@ -273,6 +273,7 @@ struct fuse4fs {int directio;int acl;int dirsync; +int translate_inums;enum fuse4fs_opstate opstate;int logfd;
@@ -345,17 +346,19 @@ struct fuse4fs {#define FUSE4FS_CHECK_CONTEXT_INIT (req) \ __FUSE4FS_CHECK_CONTEXT((req), abort(), abort()) -static inline void fuse4fs_ino_from_fuse (ext2_ino_t *inop,fuse_ino_t fino) +static inline void fuse4fs_ino_from_fuse (const struct fuse4fs *ff, +ext2_ino_t *inop,fuse_ino_t fino) { -if (fino ==FUSE_ROOT_ID ) +if (ff->translate_inums && fino ==FUSE_ROOT_ID ) *inop =EXT2_ROOT_INO ;else *inop = fino; } -static inline void fuse4fs_ino_to_fuse (fuse_ino_t *finop,ext2_ino_t ino) +static inline void fuse4fs_ino_to_fuse (const struct fuse4fs *ff, +fuse_ino_t *finop,ext2_ino_t ino) { -if (ino ==EXT2_ROOT_INO ) +if (ff->translate_inums && ino ==EXT2_ROOT_INO ) *finop =FUSE_ROOT_ID ;else *finop = ino;
@@ -371,7 +374,7 @@ static inline void fuse4fs_ino_to_fuse(fuse_ino_t *finop, ext2_ino_t ino)fuse_reply_err ((req),EIO ); \return ; \ } \ -fuse4fs_ino_from_fuse (ext2_inop, fuse_ino); \ +fuse4fs_ino_from_fuse (fuse4fs_get (req), ext2_inop, fuse_ino); \ }while (0 ) static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
@@ -2118,7 +2121,7 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino, statbuf->st_rdev = inodep->i_block[1 ]; } -fuse4fs_ino_to_fuse (&entry->ino, ino); +fuse4fs_ino_to_fuse (ff, &entry->ino, ino); entry->generation = inodep->i_generation; entry->attr_timeout =FUSE4FS_ATTR_TIMEOUT ; entry->entry_timeout =FUSE4FS_ATTR_TIMEOUT ;
@@ -7773,6 +7776,20 @@ static void fuse4fs_compute_libfuse_args(struct fuse4fs *ff, "-oallow_other,default_permissions,suid,dev"); } +if (fuse4fs_can_iomap (ff)) { +/* +* The root_nodeid mount option was added when iomap support +* was added to fuse. This enables us to control the root +* nodeid in the kernel, which enables a 1:1 translation of +* ext2 to kernel inumbers. +*/ +snprintf (extra_args,BUFSIZ ,"-oroot_nodeid=%d" , +EXT2_ROOT_INO ); +fuse_opt_add_arg (args, extra_args); + ff->translate_inums =0 ; + } + +if (ff->debug) {int i;
@@ -7950,6 +7967,7 @@ int main(int argc, char *argv[])#ifdef HAVE_FUSE_LOOPDEV .loop_fd = -1, #endif + .translate_inums = 1, };errcode_t err;FILE *orig_stderr = stderr;
PATCH v6 3/6 fuse2fs: handle timestamps and ACLs correctly when iomap is enabled
In reply to Darrick J. WongHi all,
When iomap is enabled for a fuse file, we try to keep as much of the file IO path in the kernel as we possibly can. That means no calling out to the fuse server in the IO path when we can avoid it. However, the existing FUSE architecture defers all file attributes to the fuse server -- [cm]time updates, ACL metadata management, set[ug]id removal, and permissions checking thereof, etc.
We'd really rather do all these attribute updates in the kernel, and only push them to the fuse server when it's actually necessary (e.g. fsync). Furthermore, the POSIX ACL code has the weird behavior that if the access ACL can be represented entirely by i_mode bits, it will change the mode and delete the ACL, which fuse servers generally don't seem to implement.
IOWs, we want consistent and correct (as defined by fstests) behavior of file attributes in iomap mode. Let's make the kernel manage all that and push the results to userspace as needed. This improves performance even further, since it's sort of like writeback_cache mode but more aggressive.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
Comments and questions are, as always, welcome.
e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-iomap-attrs
---
Commits in this patchset:
* fuse2fs: add strictatime/lazytime mount options
* fuse2fs: skip permission checking on utimens when iomap is enabled
* fuse2fs: let the kernel tell us about acl/mode updates
* fuse2fs: better debugging for file mode updates
* fuse2fs: debug timestamp updates
* fuse2fs: use coarse timestamps for iomap mode
* fuse2fs: add tracing for retrieving timestamps
* fuse2fs: enable syncfs
* fuse2fs: skip the gdt write in op_destroy if syncfs is working
* fuse2fs: set sync, immutable, and append at file load time
* fuse4fs: increase attribute timeout in iomap mode
--- fuse4fs/fuse4fs.1.in | 6 + fuse4fs/fuse4fs.c | 245 ++++++++++++++++++++++++++++++----------- misc/fuse2fs.1.in | 6 + misc/fuse2fs.c | 301 ++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 421 insertions(+), 137 deletions(-)
PATCH 1/11 fuse2fs: add strictatime/lazytime mount options
From: Darrick J. Wong <[email protected]>
In iomap mode, we can support the strictatime/lazytime mount options. Add them to fuse2fs.
--- fuse4fs/fuse4fs.1.in | 6 ++++++ fuse4fs/fuse4fs.c | 28 +++++++++++++++++++++++++++- misc/fuse2fs.1.in | 6 ++++++ misc/fuse2fs.c | 27 +++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-)
fuse4fs/fuse4fs.1.in +6 -0
@@ -90,6 +90,9 @@ .SS "fuse4fs options:" .I nosuid ) later. .TP +\fB-o\fR lazytime +if iomap is enabled, enable lazy updates of timestamps +.TP \fB-o\fR lockfile=path use this file to control access to the filesystem .TP
@@ -98,6 +101,9 @@ .SS "fuse4fs options:" .TP \fB-o\fR norecovery do not replay the journal and mount the file system read-only +.TP +\fB-o\fR strictatime +if iomap is enabled, update atime on every access .SS "FUSE options:" .TP \fB-d -o\fR debug
fuse4fs/fuse4fs.c +27 -1
@@ -274,6 +274,7 @@ struct fuse4fs {int acl;int dirsync;int translate_inums; +int iomap_passthrough_options;enum fuse4fs_opstate opstate;int logfd;
@@ -1376,6 +1377,12 @@ static errcode_t fuse4fs_check_support(struct fuse4fs *ff)return EXT2_ET_FILESYSTEM_CORRUPTED ; } +if (ff->iomap_passthrough_options && !fuse4fs_can_iomap (ff)) { +err_printf (ff,"%s\n" , +_ ("Some mount options require iomap." )); +return EINVAL ; + } +return 0 ; }
@@ -1999,6 +2006,8 @@ static void fuse4fs_iomap_enable(struct fuse_conn_info *conn,if (!fuse4fs_iomap_enabled (ff)) {if (ff->iomap_want ==FT_ENABLE )err_printf (ff,"%s\n" ,_ ("Could not enable iomap." )); +if (ff->iomap_passthrough_options) +err_printf (ff,"%s\n" ,_ ("Some mount options require iomap." ));return ; } }
@@ -7570,6 +7579,7 @@ enum { FUSE4FS_ERRORS_BEHAVIOR,#ifdef HAVE_FUSE_IOMAP FUSE4FS_IOMAP , + FUSE4FS_IOMAP_PASSTHROUGH, #endif };
@@ -7596,6 +7606,17 @@ static struct fuse_opt fuse4fs_opts[] = { FUSE4FS_OPT("timing", timing, 1),#endif +#ifdef HAVE_FUSE_IOMAP +#ifdef MS_LAZYTIME + FUSE_OPT_KEY("lazytime", FUSE4FS_IOMAP_PASSTHROUGH), + FUSE_OPT_KEY("nolazytime", FUSE4FS_IOMAP_PASSTHROUGH), +#endif +#ifdef MS_STRICTATIME + FUSE_OPT_KEY("strictatime", FUSE4FS_IOMAP_PASSTHROUGH), + FUSE_OPT_KEY("nostrictatime", FUSE4FS_IOMAP_PASSTHROUGH), +#endif +#endif + FUSE_OPT_KEY("user_xattr", FUSE4FS_IGNORED), FUSE_OPT_KEY("noblock_validity", FUSE4FS_IGNORED), FUSE_OPT_KEY("nodelalloc", FUSE4FS_IGNORED),
@@ -7622,6 +7643,12 @@ static int fuse4fs_opt_proc(void *data, const char *arg,struct fuse4fs *ff = data;switch (key) { +#ifdef HAVE_FUSE_IOMAP +case FUSE4FS_IOMAP_PASSTHROUGH : + ff->iomap_passthrough_options =1 ; +/* pass through to libfuse */ +return 1 ; +#endif case FUSE4FS_DIRSYNC : ff->dirsync =1 ;/* pass through to libfuse */
@@ -7789,7 +7816,6 @@ static void fuse4fs_compute_libfuse_args(struct fuse4fs *ff, ff->translate_inums =0 ; } -if (ff->debug) {int i;
misc/fuse2fs.1.in +6 -0
@@ -90,6 +90,9 @@ .SS "fuse2fs options:" .I nosuid ) later. .TP +\fB-o\fR lazytime +if iomap is enabled, enable lazy updates of timestamps +.TP \fB-o\fR lockfile=path use this file to control access to the filesystem .TP
@@ -98,6 +101,9 @@ .SS "fuse2fs options:" .TP \fB-o\fR norecovery do not replay the journal and mount the file system read-only +.TP +\fB-o\fR strictatime +if iomap is enabled, update atime on every access .SS "FUSE options:" .TP \fB-d -o\fR debug
misc/fuse2fs.c +27 -0
@@ -267,6 +267,7 @@ struct fuse2fs {int directio;int acl;int dirsync; +int iomap_passthrough_options;enum fuse2fs_opstate opstate;int logfd;
@@ -1191,6 +1192,12 @@ static errcode_t fuse2fs_check_support(struct fuse2fs *ff)return EXT2_ET_FILESYSTEM_CORRUPTED ; } +if (ff->iomap_passthrough_options && !fuse2fs_can_iomap (ff)) { +err_printf (ff,"%s\n" , +_ ("Some mount options require iomap." )); +return EINVAL ; + } +return 0 ; }
@@ -1805,6 +1812,8 @@ static void fuse2fs_iomap_enable(struct fuse_conn_info *conn,if (!fuse2fs_iomap_enabled (ff)) {if (ff->iomap_want ==FT_ENABLE )err_printf (ff,"%s\n" ,_ ("Could not enable iomap." )); +if (ff->iomap_passthrough_options) +err_printf (ff,"%s\n" ,_ ("Some mount options require iomap." ));return ; } }
@@ -7087,6 +7096,7 @@ enum { FUSE2FS_ERRORS_BEHAVIOR,#ifdef HAVE_FUSE_IOMAP FUSE2FS_IOMAP , + FUSE2FS_IOMAP_PASSTHROUGH, #endif };
@@ -7113,6 +7123,17 @@ static struct fuse_opt fuse2fs_opts[] = { FUSE2FS_OPT("timing", timing, 1),#endif +#ifdef HAVE_FUSE_IOMAP +#ifdef MS_LAZYTIME + FUSE_OPT_KEY("lazytime", FUSE2FS_IOMAP_PASSTHROUGH), + FUSE_OPT_KEY("nolazytime", FUSE2FS_IOMAP_PASSTHROUGH), +#endif +#ifdef MS_STRICTATIME + FUSE_OPT_KEY("strictatime", FUSE2FS_IOMAP_PASSTHROUGH), + FUSE_OPT_KEY("nostrictatime", FUSE2FS_IOMAP_PASSTHROUGH), +#endif +#endif + FUSE_OPT_KEY("user_xattr", FUSE2FS_IGNORED), FUSE_OPT_KEY("noblock_validity", FUSE2FS_IGNORED), FUSE_OPT_KEY("nodelalloc", FUSE2FS_IGNORED),
@@ -7139,6 +7160,12 @@ static int fuse2fs_opt_proc(void *data, const char *arg,struct fuse2fs *ff = data;switch (key) { +#ifdef HAVE_FUSE_IOMAP +case FUSE2FS_IOMAP_PASSTHROUGH : + ff->iomap_passthrough_options =1 ; +/* pass through to libfuse */ +return 1 ; +#endif case FUSE2FS_DIRSYNC : ff->dirsync =1 ;/* pass through to libfuse */
PATCH 2/11 fuse2fs: skip permission checking on utimens when iomap is enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When iomap is enabled, the kernel is in charge of enforcing permissions checks on timestamp updates for files. We needn't do that in userspace anymore.
--- fuse4fs/fuse4fs.c | 11 +++++++---- misc/fuse2fs.c | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-)
fuse4fs/fuse4fs.c +7 -4
@@ -5263,13 +5263,16 @@ static int fuse4fs_utimens(struct fuse4fs *ff, const struct fuse_ctx *ctxt,/* * ext4 allows timestamp updates of append-only files but only if we're -* setting to current time +* setting to current time. If iomap is enabled, the kernel does the +* permission checking for timestamp updates; skip the access check. */ if (aact ==TA_NOW && mact ==TA_NOW ) access |=A_OK ; - ret =fuse4fs_inum_access (ff, ctxt, ino, access); -if (ret) -return ret; +if (!fuse4fs_iomap_enabled (ff)) { + ret =fuse4fs_inum_access (ff, ctxt, ino, access); +if (ret) +return ret; + }if (aact !=TA_OMIT )EXT4_INODE_SET_XTIME (i_atime, &atime, inode);
misc/fuse2fs.c +7 -4
@@ -4917,13 +4917,16 @@ static int op_utimens(const char *path, const struct timespec ctv[2],/* * ext4 allows timestamp updates of append-only files but only if we're -* setting to current time +* setting to current time. If iomap is enabled, the kernel does the +* permission checking for timestamp updates; skip the access check. */ if (ctv[0 ].tv_nsec ==UTIME_NOW && ctv[1 ].tv_nsec ==UTIME_NOW ) access |=A_OK ; - ret =check_inum_access (ff, ino, access); -if (ret) - goto out; +if (!fuse2fs_iomap_enabled (ff)) { + ret =check_inum_access (ff, ino, access); +if (ret) + goto out; + } err =fuse2fs_read_inode (fs, ino, &inode);if (err) {
PATCH 3/11 fuse2fs: let the kernel tell us about acl/mode updates
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When the kernel is running in iomap mode, it will also manage all the ACL updates and the resulting file mode changes for us. Disable the manual implementation of it in fuse2fs.
--- fuse4fs/fuse4fs.c | 4 ++-- misc/fuse2fs.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
fuse4fs/fuse4fs.c +2 -2
@@ -2499,7 +2499,7 @@ static int fuse4fs_propagate_default_acls(struct fuse4fs *ff, ext2_ino_t parent,size_t deflen;int ret; -if (!ff->acl ||S_ISDIR (mode)) +if (!ff->acl ||S_ISDIR (mode) ||fuse4fs_iomap_enabled (ff))return 0 ; ret = fuse4fs_getxattr(ff, parent, XATTR_NAME_POSIX_ACL_DEFAULT, &def,
@@ -3925,7 +3925,7 @@ static int fuse4fs_chmod(struct fuse4fs *ff, fuse_req_t req, ext2_ino_t ino,* of the user's groups, but FUSE only tells us about the primary * group. */ -if (!fuse4fs_is_superuser (ff, ctxt)) { +if (!fuse4fs_iomap_enabled (ff) && !fuse4fs_is_superuser (ff, ctxt)) { ret =fuse4fs_in_file_group (ff, req, inode);if (ret <0 )return ret;
misc/fuse2fs.c +2 -2
@@ -2301,7 +2301,7 @@ static int propagate_default_acls(struct fuse2fs *ff, ext2_ino_t parent,size_t deflen;int ret; -if (!ff->acl ||S_ISDIR (mode)) +if (!ff->acl ||S_ISDIR (mode) ||fuse2fs_iomap_enabled (ff))return 0 ; ret = __getxattr(ff, parent, XATTR_NAME_POSIX_ACL_DEFAULT, &def,
@@ -3630,7 +3630,7 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)* of the user's groups, but FUSE only tells us about the primary * group. */ -if (!is_superuser (ff, ctxt)) { +if (!fuse2fs_iomap_enabled (ff) && !is_superuser (ff, ctxt)) { ret =in_file_group (ctxt, &inode);if (ret <0 ) goto out;
PATCH 4/11 fuse2fs: better debugging for file mode updates
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Improve the tracing of a chmod operation so that we can debug file mode updates.
--- fuse4fs/fuse4fs.c | 10 ++++++---- misc/fuse2fs.c | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-)
fuse4fs/fuse4fs.c +6 -4
@@ -3908,6 +3908,7 @@ static int fuse4fs_chmod(struct fuse4fs *ff, fuse_req_t req, ext2_ino_t ino, mode_t mode, struct ext2_inode_large *inode) { const struct fuse_ctx *ctxt = fuse_req_ctx(req); +mode_t new_mode;int ret =0 ;dbg_printf (ff,"%s: ino=%d mode=0%o\n" , __func__, ino, mode);
@@ -3934,11 +3935,12 @@ static int fuse4fs_chmod(struct fuse4fs *ff, fuse_req_t req, ext2_ino_t ino, mode &= ~S_ISGID ; } - inode->i_mode &= ~0xFFF ; - inode->i_mode |= mode &0xFFF ; + new_mode = (inode->i_mode & ~0xFFF ) | (mode &0xFFF ); -dbg_printf (ff,"%s: ino=%d new_mode=0%o\n" , - __func__, ino, inode->i_mode); +dbg_printf (ff,"%s: ino=%d old_mode=0%o new_mode=0%o\n" , + __func__, ino, inode->i_mode, new_mode); + + inode->i_mode = new_mode;return 0 ; }
misc/fuse2fs.c +7 -5
@@ -3601,6 +3601,7 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)errcode_t err;ext2_ino_t ino;struct ext2_inode_large inode; +mode_t new_mode;int ret =0 ;FUSE2FS_CHECK_CONTEXT (ff);
@@ -3639,11 +3640,12 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) mode &= ~S_ISGID ; } - inode.i_mode &= ~0xFFF ; - inode.i_mode |= mode &0xFFF ; + new_mode = (inode.i_mode & ~0xFFF ) | (mode &0xFFF ); -dbg_printf (ff,"%s: path=%s new_mode=0%o ino=%d\n" , __func__, - path, inode.i_mode, ino); +dbg_printf (ff,"%s: path=%s old_mode=0%o new_mode=0%o ino=%d\n" , + __func__, path, inode.i_mode, new_mode, ino); + + inode.i_mode = new_mode; ret =update_ctime (fs, ino, &inode);if (ret)
@@ -3663,12 +3665,12 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)static int op_chown (const char *path,uid_t owner,gid_t group,struct fuse_file_info *fi) { +struct ext2_inode_large inode;struct fuse_context *ctxt =fuse_get_context ();struct fuse2fs *ff =fuse2fs_get ();ext2_filsys fs;errcode_t err;ext2_ino_t ino; -struct ext2_inode_large inode;int ret =0 ;FUSE2FS_CHECK_CONTEXT (ff);
PATCH 5/11 fuse2fs: debug timestamp updates
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add tracing for timestamp updates to files.
--- misc/fuse2fs.c | 97 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 36 deletions(-)
misc/fuse2fs.c +61 -36
@@ -864,7 +864,8 @@ static void increment_version(struct ext2_inode_large *inode) inode->i_version_hi = ver >>32 ; } -static void init_times (struct ext2_inode_large *inode) +static void fuse2fs_init_timestamps (struct fuse2fs *ff,ext2_ino_t ino, +struct ext2_inode_large *inode) {struct timespec now;
@@ -874,11 +875,15 @@ static void init_times(struct ext2_inode_large *inode)EXT4_INODE_SET_XTIME (i_mtime, &now, inode);EXT4_EINODE_SET_XTIME (i_crtime, &now, inode);increment_version (inode); + +dbg_printf (ff,"%s: ino=%u time %ld:%lu\n" , __func__, ino, now.tv_sec, + now.tv_nsec); } -static int update_ctime (ext2_filsys fs,ext2_ino_t ino, -struct ext2_inode_large *pinode) +static int fuse2fs_update_ctime (struct fuse2fs *ff,ext2_ino_t ino, +struct ext2_inode_large *pinode) { +ext2_filsys fs = ff->fs;errcode_t err;struct timespec now;struct ext2_inode_large inode;
@@ -889,6 +894,10 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,if (pinode) {increment_version (pinode);EXT4_INODE_SET_XTIME (i_ctime, &now, pinode); + +dbg_printf (ff,"%s: ino=%u ctime %ld:%lu\n" , __func__, ino, + now.tv_sec, now.tv_nsec); +return 0 ; }
@@ -900,6 +909,9 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,increment_version (&inode);EXT4_INODE_SET_XTIME (i_ctime, &now, &inode); +dbg_printf (ff,"%s: ino=%u ctime %ld:%lu\n" , __func__, ino, + now.tv_sec, now.tv_nsec); + err =fuse2fs_write_inode (fs, ino, &inode);if (err)return translate_error (fs, ino, err);
@@ -907,8 +919,9 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,return 0 ; } -static int update_atime (ext2_filsys fs,ext2_ino_t ino) +static int fuse2fs_update_atime (struct fuse2fs *ff,ext2_ino_t ino) { +ext2_filsys fs = ff->fs;errcode_t err;struct ext2_inode_large inode, *pinode;struct timespec atime, mtime, now;
@@ -927,6 +940,10 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino) dmtime = mtime.tv_sec + ((double )mtime.tv_nsec /NSEC_PER_SEC ); dnow = now.tv_sec + ((double )now.tv_nsec /NSEC_PER_SEC ); +dbg_printf (ff,"%s: ino=%u atime %ld:%lu mtime %ld:%lu now %ld:%lu\n" , + __func__, ino, atime.tv_sec, atime.tv_nsec, mtime.tv_sec, + mtime.tv_nsec, now.tv_sec, now.tv_nsec); +/* * If atime is newer than mtime and atime hasn't been updated in thirty * seconds, skip the atime update. Same idea as Linux "relatime". Use
@@ -943,9 +960,10 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)return 0 ; } -static int update_mtime (ext2_filsys fs,ext2_ino_t ino, -struct ext2_inode_large *pinode) +static int fuse2fs_update_mtime (struct fuse2fs *ff,ext2_ino_t ino, +struct ext2_inode_large *pinode) { +ext2_filsys fs = ff->fs;errcode_t err;struct ext2_inode_large inode;struct timespec now;
@@ -955,6 +973,10 @@ static int update_mtime(ext2_filsys fs, ext2_ino_t ino,EXT4_INODE_SET_XTIME (i_mtime, &now, pinode);EXT4_INODE_SET_XTIME (i_ctime, &now, pinode);increment_version (pinode); + +dbg_printf (ff,"%s: ino=%u mtime/ctime %ld:%lu\n" , + __func__, ino, now.tv_sec, now.tv_nsec); +return 0 ; }
@@ -967,6 +989,9 @@ static int update_mtime(ext2_filsys fs, ext2_ino_t ino,EXT4_INODE_SET_XTIME (i_ctime, &now, &inode);increment_version (&inode); +dbg_printf (ff,"%s: ino=%u mtime/ctime %ld:%lu\n" , + __func__, ino, now.tv_sec, now.tv_nsec); + err =fuse2fs_write_inode (fs, ino, &inode);if (err)return translate_error (fs, ino, err);
@@ -2222,7 +2247,7 @@ static int op_readlink(const char *path, char *buf, size_t len) buf[len] =0 ;if (fuse2fs_is_writeable (ff)) { - ret =update_atime (fs, ino); + ret =fuse2fs_update_atime (ff, ino);if (ret) goto out; }
@@ -2496,7 +2521,7 @@ static int op_mknod(const char *path, mode_t mode, dev_t dev) goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse2fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -2519,7 +2544,7 @@ static int op_mknod(const char *path, mode_t mode, dev_t dev) } inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse2fs_init_timestamps (ff, child, &inode); err =fuse2fs_write_inode (fs, child, &inode);if (err) { ret =translate_error (fs, child, err);
@@ -2605,7 +2630,7 @@ static int op_mkdir(const char *path, mode_t mode) goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse2fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -2632,7 +2657,7 @@ static int op_mkdir(const char *path, mode_t mode)if (parent_sgid) inode.i_mode |=S_ISGID ; inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse2fs_init_timestamps (ff, child, &inode); err =fuse2fs_write_inode (fs, child, &inode);if (err) {
@@ -2715,7 +2740,7 @@ static int fuse2fs_unlink(struct fuse2fs *ff, const char *path,if (err)return translate_error (fs, dir, err); - ret =update_mtime (fs, dir,NULL ); + ret =fuse2fs_update_mtime (ff, dir,NULL );if (ret)return ret;
@@ -2806,7 +2831,7 @@ static int remove_inode(struct fuse2fs *ff, ext2_ino_t ino)ext2fs_set_dtime (fs,EXT2_INODE (&inode)); } - ret =update_ctime (fs, ino, &inode); + ret =fuse2fs_update_ctime (ff, ino, &inode);if (ret)return ret;
@@ -2976,7 +3001,7 @@ static int __op_rmdir(struct fuse2fs *ff, const char *path) goto out; }ext2fs_dec_nlink (EXT2_INODE (&inode)); - ret =update_mtime (fs, rds.parent, &inode); + ret =fuse2fs_update_mtime (ff, rds.parent, &inode);if (ret) goto out; err =fuse2fs_write_inode (fs, rds.parent, &inode);
@@ -3073,7 +3098,7 @@ static int op_symlink(const char *src, const char *dest) }/* Update parent dir's mtime */ - ret =update_mtime (fs, parent,NULL ); + ret =fuse2fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -3097,7 +3122,7 @@ static int op_symlink(const char *src, const char *dest)fuse2fs_set_uid (&inode, ctxt->uid);fuse2fs_set_gid (&inode, gid); inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse2fs_init_timestamps (ff, child, &inode); err =fuse2fs_write_inode (fs, child, &inode);if (err) {
@@ -3382,11 +3407,11 @@ static int op_rename(const char *from, const char *to, }/* Update timestamps */ - ret =update_ctime (fs, from_ino,NULL ); + ret =fuse2fs_update_ctime (ff, from_ino,NULL );if (ret) goto out2; - ret =update_mtime (fs, to_dir_ino,NULL ); + ret =fuse2fs_update_mtime (ff, to_dir_ino,NULL );if (ret) goto out2;
@@ -3480,7 +3505,7 @@ static int op_link(const char *src, const char *dest) }ext2fs_inc_nlink (fs,EXT2_INODE (&inode)); - ret =update_ctime (fs, ino, &inode); + ret =fuse2fs_update_ctime (ff, ino, &inode);if (ret) goto out2;
@@ -3499,7 +3524,7 @@ static int op_link(const char *src, const char *dest) goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse2fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -3647,7 +3672,7 @@ static int op_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) inode.i_mode = new_mode; - ret =update_ctime (fs, ino, &inode); + ret =fuse2fs_update_ctime (ff, ino, &inode);if (ret) goto out;
@@ -3714,7 +3739,7 @@ static int op_chown(const char *path, uid_t owner, gid_t group,fuse2fs_set_gid (&inode, group); } - ret =update_ctime (fs, ino, &inode); + ret =fuse2fs_update_ctime (ff, ino, &inode);if (ret) goto out;
@@ -3844,7 +3869,7 @@ static int fuse2fs_truncate(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)if (err)return translate_error (fs, ino, err); - ret =update_mtime (fs, ino,NULL ); + ret =fuse2fs_update_mtime (ff, ino,NULL );if (ret)return ret;
@@ -4072,7 +4097,7 @@ static int op_read(const char *path EXT2FS_ATTR((unused)), char *buf, }if (fh->check_flags !=X_OK &&fuse2fs_is_writeable (ff)) { - ret =update_atime (fs, fh->ino); + ret =fuse2fs_update_atime (ff, fh->ino);if (ret) goto out; }
@@ -4156,7 +4181,7 @@ static int op_write(const char *path EXT2FS_ATTR((unused)), goto out; } - ret =update_mtime (fs, fh->ino,NULL ); + ret =fuse2fs_update_mtime (ff, fh->ino,NULL );if (ret) goto out;
@@ -4518,7 +4543,7 @@ static int op_setxattr(const char *path EXT2FS_ATTR((unused)), goto out2; } - ret =update_ctime (fs, ino,NULL ); + ret =fuse2fs_update_ctime (ff, ino,NULL ); out2: err =ext2fs_xattrs_close (&h);if (!ret && err)
@@ -4612,7 +4637,7 @@ static int op_removexattr(const char *path, const char *key) goto out2; } - ret =update_ctime (fs, ino,NULL ); + ret =fuse2fs_update_ctime (ff, ino,NULL ); out2: err =ext2fs_xattrs_close (&h);if (err && !ret)
@@ -4730,7 +4755,7 @@ static int op_readdir(const char *path EXT2FS_ATTR((unused)), void *buf, }if (fuse2fs_is_writeable (ff)) { - ret =update_atime (i.fs, fh->ino); + ret =fuse2fs_update_atime (ff, fh->ino);if (ret) goto out; }
@@ -4835,7 +4860,7 @@ static int op_create(const char *path, mode_t mode, struct fuse_file_info *fp) goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse2fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -4866,7 +4891,7 @@ static int op_create(const char *path, mode_t mode, struct fuse_file_info *fp) } inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse2fs_init_timestamps (ff, child, &inode); err =fuse2fs_write_inode (fs, child, &inode);if (err) { ret =translate_error (fs, child, err);
@@ -4950,7 +4975,7 @@ static int op_utimens(const char *path, const struct timespec ctv[2],if (tv[1 ].tv_nsec !=UTIME_OMIT )EXT4_INODE_SET_XTIME (i_mtime, &tv[1 ], &inode);#endif /* UTIME_OMIT */ - ret =update_ctime (fs, ino, &inode); + ret =fuse2fs_update_ctime (ff, ino, &inode);if (ret) goto out;
@@ -5018,7 +5043,7 @@ static int ioctl_setflags(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,if (ret)return ret; - ret =update_ctime (fs, fh->ino, &inode); + ret =fuse2fs_update_ctime (ff, fh->ino, &inode);if (ret)return ret;
@@ -5065,7 +5090,7 @@ static int ioctl_setversion(struct fuse2fs *ff, struct fuse2fs_file_handle *fh, inode.i_generation = generation; - ret =update_ctime (fs, fh->ino, &inode); + ret =fuse2fs_update_ctime (ff, fh->ino, &inode);if (ret)return ret;
@@ -5196,7 +5221,7 @@ static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,if (ext2fs_inode_includes (inode_size, i_projid)) inode.i_projid = fsx->fsx_projid; - ret =update_ctime (fs, fh->ino, &inode); + ret =fuse2fs_update_ctime (ff, fh->ino, &inode);if (ret)return ret;
@@ -5468,7 +5493,7 @@ static int fuse2fs_allocate_range(struct fuse2fs *ff, } } - err =update_mtime (fs, fh->ino, &inode); + err =fuse2fs_update_mtime (ff, fh->ino, &inode);if (err)return err;
@@ -5641,7 +5666,7 @@ static int fuse2fs_punch_range(struct fuse2fs *ff,return translate_error (fs, fh->ino, err); } - err =update_mtime (fs, fh->ino, &inode); + err =fuse2fs_update_mtime (ff, fh->ino, &inode);if (err)return err;
PATCH 6/11 fuse2fs: use coarse timestamps for iomap mode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In iomap mode, the kernel is responsible for maintaining timestamps because file writes don't upcall to fuse2fs. The kernel's predicate for deciding if [cm]time should be updated bases its decisions off [cm]time being an exact match for the coarse clock (instead of checking that [cm]time < coarse_clock) which means that fuse2fs setting a fine-grained timestamp that is slightly ahead of the coarse clock can result in timestamps appearing to go backwards. generic/423 doesn't like seeing btime > ctime from statx, so we'll use the coarse clock in iomap mode.
--- fuse4fs/fuse4fs.c | 110 +++++++++++++++++++++++++++++++---------------------- misc/fuse2fs.c | 34 ++++++++++++---- 2 files changed, 90 insertions(+), 54 deletions(-)
fuse4fs/fuse4fs.c +65 -45
@@ -1004,8 +1004,24 @@ static inline void fuse4fs_dump_extents(struct fuse4fs *ff, ext2_ino_t ino,ext2fs_extent_free (extents); } -static void get_now (struct timespec *now) +static void fuse4fs_get_now (struct fuse4fs *ff,struct timespec *now) { +#ifdef CLOCK_REALTIME_COARSE +/* +* In iomap mode, the kernel is responsible for maintaining timestamps +* because file writes don't upcall to fuse4fs. The kernel's predicate +* for deciding if [cm]time should be updated bases its decisions off +* [cm]time being an exact match for the coarse clock (instead of +* checking that [cm]time < coarse_clock) which means that fuse4fs +* setting a fine-grained timestamp that is slightly ahead of the +* coarse clock can result in timestamps appearing to go backwards. +* generic/423 doesn't like seeing btime > ctime from statx, so we'll +* use the coarse clock in iomap mode. +*/ +if (fuse4fs_iomap_enabled (ff) && + !clock_gettime (CLOCK_REALTIME_COARSE , now)) +return ; +#endif #ifdef CLOCK_REALTIME if (!clock_gettime (CLOCK_REALTIME , now))return ;
@@ -1028,11 +1044,12 @@ static void increment_version(struct ext2_inode_large *inode) inode->i_version_hi = ver >>32 ; } -static void init_times (struct ext2_inode_large *inode) +static void fuse4fs_init_timestamps (struct fuse4fs *ff, +struct ext2_inode_large *inode) {struct timespec now; -get_now (&now); +fuse4fs_get_now (ff, &now);EXT4_INODE_SET_XTIME (i_atime, &now, inode);EXT4_INODE_SET_XTIME (i_ctime, &now, inode);EXT4_INODE_SET_XTIME (i_mtime, &now, inode);
@@ -1040,14 +1057,15 @@ static void init_times(struct ext2_inode_large *inode)increment_version (inode); } -static int update_ctime (ext2_filsys fs,ext2_ino_t ino, -struct ext2_inode_large *pinode) +static int fuse4fs_update_ctime (struct fuse4fs *ff,ext2_ino_t ino, +struct ext2_inode_large *pinode) { -errcode_t err;struct timespec now;struct ext2_inode_large inode; +ext2_filsys fs = ff->fs; +errcode_t err; -get_now (&now); +fuse4fs_get_now (ff, &now);/* If user already has a inode buffer, just update that */ if (pinode) {
@@ -1071,12 +1089,13 @@ static int update_ctime(ext2_filsys fs, ext2_ino_t ino,return 0 ; } -static int update_atime (ext2_filsys fs,ext2_ino_t ino) +static int fuse4fs_update_atime (struct fuse4fs *ff,ext2_ino_t ino) { -errcode_t err;struct ext2_inode_large inode, *pinode;struct timespec atime, mtime, now; +ext2_filsys fs = ff->fs;double datime, dmtime, dnow; +errcode_t err; err =fuse4fs_read_inode (fs, ino, &inode);if (err)
@@ -1085,7 +1104,7 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino) pinode = &inode;EXT4_INODE_GET_XTIME (i_atime, &atime, pinode);EXT4_INODE_GET_XTIME (i_mtime, &mtime, pinode); -get_now (&now); +fuse4fs_get_now (ff, &now); datime = atime.tv_sec + ((double )atime.tv_nsec /NSEC_PER_SEC ); dmtime = mtime.tv_sec + ((double )mtime.tv_nsec /NSEC_PER_SEC );
@@ -1107,15 +1126,16 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)return 0 ; } -static int update_mtime (ext2_filsys fs,ext2_ino_t ino, -struct ext2_inode_large *pinode) +static int fuse4fs_update_mtime (struct fuse4fs *ff,ext2_ino_t ino, +struct ext2_inode_large *pinode) { -errcode_t err;struct ext2_inode_large inode;struct timespec now; +ext2_filsys fs = ff->fs; +errcode_t err;if (pinode) { -get_now (&now); +fuse4fs_get_now (ff, &now);EXT4_INODE_SET_XTIME (i_mtime, &now, pinode);EXT4_INODE_SET_XTIME (i_ctime, &now, pinode);increment_version (pinode);
@@ -1126,7 +1146,7 @@ static int update_mtime(ext2_filsys fs, ext2_ino_t ino,if (err)return translate_error (fs, ino, err); -get_now (&now); +fuse4fs_get_now (ff, &now);EXT4_INODE_SET_XTIME (i_mtime, &now, &inode);EXT4_INODE_SET_XTIME (i_ctime, &now, &inode);increment_version (&inode);
@@ -2416,7 +2436,7 @@ static void op_readlink(fuse_req_t req, fuse_ino_t fino) buf[len] =0 ;if (fuse4fs_is_writeable (ff)) { - ret =update_atime (fs, ino); + ret =fuse4fs_update_atime (ff, ino);if (ret) goto out; }
@@ -2685,7 +2705,7 @@ static void op_mknod(fuse_req_t req, fuse_ino_t fino, const char *name, goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse4fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -2708,7 +2728,7 @@ static void op_mknod(fuse_req_t req, fuse_ino_t fino, const char *name, } inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse4fs_init_timestamps (ff, &inode); err =fuse4fs_write_inode (fs, child, &inode);if (err) { ret =translate_error (fs, child, err);
@@ -2770,7 +2790,7 @@ static void op_mkdir(fuse_req_t req, fuse_ino_t fino, const char *name, goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse4fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -2796,7 +2816,7 @@ static void op_mkdir(fuse_req_t req, fuse_ino_t fino, const char *name,if (parent_sgid) inode.i_mode |=S_ISGID ; inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse4fs_init_timestamps (ff, &inode); err =fuse4fs_write_inode (fs, child, &inode);if (err) {
@@ -3147,7 +3167,7 @@ static int fuse4fs_remove_inode(struct fuse4fs *ff, ext2_ino_t ino) inode.i_links_count--; } - ret =update_ctime (fs, ino, &inode); + ret =fuse4fs_update_ctime (ff, ino, &inode);if (ret)return ret;
@@ -3219,7 +3239,7 @@ static int fuse4fs_unlink(struct fuse4fs *ff, ext2_ino_t parent, goto out; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse4fs_update_mtime (ff, parent,NULL );if (ret) goto out; out:
@@ -3353,7 +3373,7 @@ static int fuse4fs_rmdir(struct fuse4fs *ff, ext2_ino_t parent, goto out; }ext2fs_dec_nlink (EXT2_INODE (&inode)); - ret =update_mtime (fs, rds.parent, &inode); + ret =fuse4fs_update_mtime (ff, rds.parent, &inode);if (ret) goto out; err =fuse4fs_write_inode (fs, rds.parent, &inode);
@@ -3457,7 +3477,7 @@ static void op_symlink(fuse_req_t req, const char *target, fuse_ino_t fino, }/* Update parent dir's mtime */ - ret =update_mtime (fs, parent,NULL ); + ret =fuse4fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -3480,7 +3500,7 @@ static void op_symlink(fuse_req_t req, const char *target, fuse_ino_t fino,fuse4fs_set_uid (&inode, ctxt->uid);fuse4fs_set_gid (&inode, gid); inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse4fs_init_timestamps (ff, &inode); err =fuse4fs_write_inode (fs, child, &inode);if (err) {
@@ -3711,11 +3731,11 @@ static void op_rename(fuse_req_t req, fuse_ino_t from_parent, const char *from, }/* Update timestamps */ - ret =update_ctime (fs, from_ino,NULL ); + ret =fuse4fs_update_ctime (ff, from_ino,NULL );if (ret) goto out; - ret =update_mtime (fs, to_dir_ino,NULL ); + ret =fuse4fs_update_mtime (ff, to_dir_ino,NULL );if (ret) goto out;
@@ -3794,7 +3814,7 @@ static void op_link(fuse_req_t req, fuse_ino_t child_fino, }ext2fs_inc_nlink (fs,EXT2_INODE (&inode)); - ret =update_ctime (fs, child, &inode); + ret =fuse4fs_update_ctime (ff, child, &inode);if (ret) goto out2;
@@ -3811,7 +3831,7 @@ static void op_link(fuse_req_t req, fuse_ino_t child_fino, goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse4fs_update_mtime (ff, parent,NULL );if (ret) goto out2;
@@ -4047,7 +4067,7 @@ static int fuse4fs_truncate(struct fuse4fs *ff, ext2_ino_t ino, off_t new_size)if (err)return translate_error (fs, ino, err); - ret =update_mtime (fs, ino,NULL ); + ret =fuse4fs_update_mtime (ff, ino,NULL );if (ret)return ret;
@@ -4249,7 +4269,7 @@ static void op_read(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)), }if (fh->check_flags !=X_OK &&fuse4fs_is_writeable (ff)) { - ret =update_atime (fs, fh->ino); + ret =fuse4fs_update_atime (ff, fh->ino);if (ret) goto out; }
@@ -4323,7 +4343,7 @@ static void op_write(fuse_req_t req, fuse_ino_t fino EXT2FS_ATTR((unused)), goto out; } - ret =update_mtime (fs, fh->ino,NULL ); + ret =fuse4fs_update_mtime (ff, fh->ino,NULL );if (ret) goto out;
@@ -4770,7 +4790,7 @@ static void op_setxattr(fuse_req_t req, fuse_ino_t fino, const char *key, goto out2; } - ret =update_ctime (fs, ino,NULL ); + ret =fuse4fs_update_ctime (ff, ino,NULL ); out2: err =ext2fs_xattrs_close (&h);if (!ret && err)
@@ -4864,7 +4884,7 @@ static void op_removexattr(fuse_req_t req, fuse_ino_t fino, const char *key) goto out2; } - ret =update_ctime (fs, ino,NULL ); + ret =fuse4fs_update_ctime (ff, ino,NULL ); out2: err =ext2fs_xattrs_close (&h);if (err && !ret)
@@ -5011,7 +5031,7 @@ static void __op_readdir(fuse_req_t req, fuse_ino_t fino, size_t size, }if (fuse4fs_is_writeable (ff)) { - ret =update_atime (i.fs, fh->ino); + ret =fuse4fs_update_atime (i.ff, fh->ino);if (ret) goto out; }
@@ -5111,7 +5131,7 @@ static void op_create(fuse_req_t req, fuse_ino_t fino, const char *name, goto out2; } - ret =update_mtime (fs, parent,NULL ); + ret =fuse4fs_update_mtime (ff, parent,NULL );if (ret) goto out2; }else {
@@ -5152,7 +5172,7 @@ static void op_create(fuse_req_t req, fuse_ino_t fino, const char *name, } inode.i_generation = ff->next_generation++; -init_times (&inode); +fuse4fs_init_timestamps (ff, &inode); err =fuse4fs_write_inode (fs, child, &inode);if (err) { ret =translate_error (fs, child, err);
@@ -5231,7 +5251,7 @@ static int fuse4fs_utimens(struct fuse4fs *ff, const struct fuse_ctx *ctxt,int ret =0 ;if (to_set & (FUSE_SET_ATTR_ATIME_NOW |FUSE_SET_ATTR_MTIME_NOW )) -get_now (&now); +fuse4fs_get_now (ff, &now);if (to_set &FUSE_SET_ATTR_ATIME_NOW ) { atime = now;
@@ -5369,7 +5389,7 @@ static void op_setattr(fuse_req_t req, fuse_ino_t fino, struct stat *attr, }/* Update ctime for any attribute change */ - ret =update_ctime (fs, ino, &inode); + ret =fuse4fs_update_ctime (ff, ino, &inode);if (ret) goto out;
@@ -5451,7 +5471,7 @@ static int ioctl_setflags(struct fuse4fs *ff, const struct fuse_ctx *ctxt,if (ret)return ret; - ret =update_ctime (fs, fh->ino, &inode); + ret =fuse4fs_update_ctime (ff, fh->ino, &inode);if (ret)return ret;
@@ -5504,7 +5524,7 @@ static int ioctl_setversion(struct fuse4fs *ff, const struct fuse_ctx *ctxt, inode.i_generation = *indata; - ret =update_ctime (fs, fh->ino, &inode); + ret =fuse4fs_update_ctime (ff, fh->ino, &inode);if (ret)return ret;
@@ -5640,7 +5660,7 @@ static int ioctl_fssetxattr(struct fuse4fs *ff, const struct fuse_ctx *ctxt,if (ext2fs_inode_includes (inode_size, i_projid)) inode.i_projid = fsx->fsx_projid; - ret =update_ctime (fs, fh->ino, &inode); + ret =fuse4fs_update_ctime (ff, fh->ino, &inode);if (ret)return ret;
@@ -5936,7 +5956,7 @@ static int fuse4fs_allocate_range(struct fuse4fs *ff, } } - err =update_mtime (fs, fh->ino, &inode); + err =fuse4fs_update_mtime (ff, fh->ino, &inode);if (err)return err;
@@ -6109,7 +6129,7 @@ static int fuse4fs_punch_range(struct fuse4fs *ff,return translate_error (fs, fh->ino, err); } - err =update_mtime (fs, fh->ino, &inode); + err =fuse4fs_update_mtime (ff, fh->ino, &inode);if (err)return err;
@@ -8271,7 +8291,7 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err, error_message(err), func, line);/* Make a note in the error log */ -get_now (&now); +fuse4fs_get_now (ff, &now);ext2fs_set_tstamp (fs->super, s_last_error_time, now.tv_sec); fs->super->s_last_error_ino = ino; fs->super->s_last_error_line = line;
misc/fuse2fs.c +25 -9
@@ -840,8 +840,24 @@ static inline void fuse2fs_dump_extents(struct fuse2fs *ff, ext2_ino_t ino,ext2fs_extent_free (extents); } -static void get_now (struct timespec *now) +static void fuse2fs_get_now (struct fuse2fs *ff,struct timespec *now) { +#ifdef CLOCK_REALTIME_COARSE +/* +* In iomap mode, the kernel is responsible for maintaining timestamps +* because file writes don't upcall to fuse2fs. The kernel's predicate +* for deciding if [cm]time should be updated bases its decisions off +* [cm]time being an exact match for the coarse clock (instead of +* checking that [cm]time < coarse_clock) which means that fuse2fs +* setting a fine-grained timestamp that is slightly ahead of the +* coarse clock can result in timestamps appearing to go backwards. +* generic/423 doesn't like seeing btime > ctime from statx, so we'll +* use the coarse clock in iomap mode. +*/ +if (fuse2fs_iomap_enabled (ff) && + !clock_gettime (CLOCK_REALTIME_COARSE , now)) +return ; +#endif #ifdef CLOCK_REALTIME if (!clock_gettime (CLOCK_REALTIME , now))return ;
@@ -869,7 +885,7 @@ static void fuse2fs_init_timestamps(struct fuse2fs *ff, ext2_ino_t ino, {struct timespec now; -get_now (&now); +fuse2fs_get_now (ff, &now);EXT4_INODE_SET_XTIME (i_atime, &now, inode);EXT4_INODE_SET_XTIME (i_ctime, &now, inode);EXT4_INODE_SET_XTIME (i_mtime, &now, inode);
@@ -888,7 +904,7 @@ static int fuse2fs_update_ctime(struct fuse2fs *ff, ext2_ino_t ino,struct timespec now;struct ext2_inode_large inode; -get_now (&now); +fuse2fs_get_now (ff, &now);/* If user already has a inode buffer, just update that */ if (pinode) {
@@ -934,7 +950,7 @@ static int fuse2fs_update_atime(struct fuse2fs *ff, ext2_ino_t ino) pinode = &inode;EXT4_INODE_GET_XTIME (i_atime, &atime, pinode);EXT4_INODE_GET_XTIME (i_mtime, &mtime, pinode); -get_now (&now); +fuse2fs_get_now (ff, &now); datime = atime.tv_sec + ((double )atime.tv_nsec /NSEC_PER_SEC ); dmtime = mtime.tv_sec + ((double )mtime.tv_nsec /NSEC_PER_SEC );
@@ -969,7 +985,7 @@ static int fuse2fs_update_mtime(struct fuse2fs *ff, ext2_ino_t ino,struct timespec now;if (pinode) { -get_now (&now); +fuse2fs_get_now (ff, &now);EXT4_INODE_SET_XTIME (i_mtime, &now, pinode);EXT4_INODE_SET_XTIME (i_ctime, &now, pinode);increment_version (pinode);
@@ -984,7 +1000,7 @@ static int fuse2fs_update_mtime(struct fuse2fs *ff, ext2_ino_t ino,if (err)return translate_error (fs, ino, err); -get_now (&now); +fuse2fs_get_now (ff, &now);EXT4_INODE_SET_XTIME (i_mtime, &now, &inode);EXT4_INODE_SET_XTIME (i_ctime, &now, &inode);increment_version (&inode);
@@ -4965,9 +4981,9 @@ static int op_utimens(const char *path, const struct timespec ctv[2], tv[1 ] = ctv[1 ];#ifdef UTIME_NOW if (tv[0 ].tv_nsec ==UTIME_NOW ) -get_now (tv); +fuse2fs_get_now (ff, tv);if (tv[1 ].tv_nsec ==UTIME_NOW ) -get_now (tv +1 ); +fuse2fs_get_now (ff, tv +1 );#endif /* UTIME_NOW */ #ifdef UTIME_OMIT if (tv[0 ].tv_nsec !=UTIME_OMIT )
@@ -7708,7 +7724,7 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err, error_message(err), func, line);/* Make a note in the error log */ -get_now (&now); +fuse2fs_get_now (ff, &now);ext2fs_set_tstamp (fs->super, s_last_error_time, now.tv_sec); fs->super->s_last_error_ino = ino; fs->super->s_last_error_line = line;
PATCH 7/11 fuse2fs: add tracing for retrieving timestamps
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add tracing for retrieving timestamps so we can debug the weird behavior.
--- misc/fuse2fs.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
misc/fuse2fs.c +14 -6
@@ -1940,9 +1940,11 @@ static void *op_init(struct fuse_conn_info *conn,return ff; } -static int stat_inode (ext2_filsys fs,ext2_ino_t ino,struct stat *statbuf) +static int fuse2fs_stat (struct fuse2fs *ff,ext2_ino_t ino, +struct stat *statbuf) {struct ext2_inode_large inode; +ext2_filsys fs = ff->fs;dev_t fakedev =0 ;errcode_t err;int ret =0 ;
@@ -1981,6 +1983,13 @@ static int stat_inode(ext2_filsys fs, ext2_ino_t ino, struct stat *statbuf)#else statbuf->st_ctime = tv.tv_sec;#endif + +dbg_printf (ff,"%s: ino=%d atime=%lld.%ld mtime=%lld.%ld ctime=%lld.%ld\n" , + __func__, ino, + (long long int )statbuf->st_atim.tv_sec, statbuf->st_atim.tv_nsec, + (long long int )statbuf->st_mtim.tv_sec, statbuf->st_mtim.tv_nsec, + (long long int )statbuf->st_ctim.tv_sec, statbuf->st_ctim.tv_nsec); +if (LINUX_S_ISCHR (inode.i_mode) ||LINUX_S_ISBLK (inode.i_mode)) {if (inode.i_block[0 ])
@@ -2027,16 +2036,15 @@ static int op_getattr(const char *path, struct stat *statbuf, struct fuse_file_info *fi) {struct fuse2fs *ff =fuse2fs_get (); -ext2_filsys fs;ext2_ino_t ino;int ret =0 ;FUSE2FS_CHECK_CONTEXT (ff); - fs =fuse2fs_start (ff); +fuse2fs_start (ff); ret =fuse2fs_file_ino (ff, path, fi, &ino);if (ret) goto out; - ret =stat_inode (fs, ino, statbuf); + ret =fuse2fs_stat (ff, ino, statbuf); out:fuse2fs_finish (ff, ret);return ret;
@@ -3826,7 +3834,7 @@ static int fuse2fs_file_uses_iomap(struct fuse2fs *ff, ext2_ino_t ino)if (!fuse2fs_iomap_enabled (ff))return 0 ; - ret =stat_inode (ff->fs, ino, &statbuf); + ret =fuse2fs_stat (ff, ino, &statbuf);if (ret)return ret;
@@ -4728,7 +4736,7 @@ static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)), (unsigned long long)i->dirpos);if (i->flags ==FUSE_READDIR_PLUS ) { - ret =stat_inode (i->fs, dirent->inode, &stat); + ret =fuse2fs_stat (i->ff, dirent->inode, &stat);if (ret)return DIRENT_ABORT ; }
PATCH 8/11 fuse2fs: enable syncfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable syncfs calls in fuse2fs.
--- fuse4fs/fuse4fs.c | 32 ++++++++++++++++++++++++++++++++ misc/fuse2fs.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
fuse4fs/fuse4fs.c +32 -0
@@ -6271,7 +6271,38 @@ static void op_shutdownfs(fuse_req_t req, fuse_ino_t ino, uint64_t flags)int ret; ret =ioctl_shutdown (ff, ctxt,NULL ,NULL ,0 ); +fuse_reply_err (req, -ret); +} +static void op_syncfs (fuse_req_t req,fuse_ino_t ino) +{ +struct fuse4fs *ff =fuse4fs_get (req); +ext2_filsys fs; +errcode_t err; +int ret =0 ; + +FUSE4FS_CHECK_CONTEXT (req); + fs =fuse4fs_start (ff); + +if (ff->opstate ==F4OP_WRITABLE ) { +if (fs->super->s_error_count) + fs->super->s_state |=EXT2_ERROR_FS ; +ext2fs_mark_super_dirty (fs); + err =ext2fs_set_gdt_csum (fs); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + + err =ext2fs_flush2 (fs,0 ); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + } + +out_unlock: +fuse4fs_finish (ff, ret);fuse_reply_err (req, -ret); }#endif
@@ -7568,6 +7599,7 @@ static struct fuse_lowlevel_ops fs_ops = { .freezefs = op_freezefs, .unfreezefs = op_unfreezefs, .shutdownfs = op_shutdownfs, + .syncfs = op_syncfs,#endif #ifdef HAVE_FUSE_IOMAP .iomap_begin = op_iomap_begin,
misc/fuse2fs.c +34 -0
@@ -5829,6 +5829,39 @@ static int op_shutdownfs(const char *path, uint64_t flags)return ioctl_shutdown (ff,NULL ,NULL ); } + +static int op_syncfs (const char *path) +{ +struct fuse2fs *ff =fuse2fs_get (); +ext2_filsys fs; +errcode_t err; +int ret =0 ; + +FUSE2FS_CHECK_CONTEXT (ff); +dbg_printf (ff,"%s: path=%s\n" , __func__, path); + fs =fuse2fs_start (ff); + +if (ff->opstate ==F2OP_WRITABLE ) { +if (fs->super->s_error_count) + fs->super->s_state |=EXT2_ERROR_FS ; +ext2fs_mark_super_dirty (fs); + err =ext2fs_set_gdt_csum (fs); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + + err =ext2fs_flush2 (fs,0 ); +if (err) { + ret =translate_error (fs,0 , err); + goto out_unlock; + } + } + +out_unlock: +fuse2fs_finish (ff, ret); +return ret; +}#endif #ifdef HAVE_FUSE_IOMAP
@@ -7114,6 +7147,7 @@ static struct fuse_operations fs_ops = { .freezefs = op_freezefs, .unfreezefs = op_unfreezefs, .shutdownfs = op_shutdownfs, + .syncfs = op_syncfs,#endif #ifdef HAVE_FUSE_IOMAP .iomap_begin = op_iomap_begin,
PATCH 9/11 fuse2fs: skip the gdt write in op_destroy if syncfs is working
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
As an umount-time performance enhancement, don't bother to write the group descriptor tables in op_destroy if we know that op_syncfs will do it for us. That only happens if iomap is enabled.
--- fuse4fs/fuse4fs.c | 19 ++++++++++++++++--- misc/fuse2fs.c | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-)
fuse4fs/fuse4fs.c +16 -3
@@ -275,6 +275,7 @@ struct fuse4fs {int dirsync;int translate_inums;int iomap_passthrough_options; +int write_gdt_on_destroy;enum fuse4fs_opstate opstate;int logfd;
@@ -1840,9 +1841,11 @@ static void op_destroy(void *userdata)if (fs->super->s_error_count) fs->super->s_state |=EXT2_ERROR_FS ;ext2fs_mark_super_dirty (fs); - err =ext2fs_set_gdt_csum (fs); -if (err) -translate_error (fs,0 , err); +if (ff->write_gdt_on_destroy) { + err =ext2fs_set_gdt_csum (fs); +if (err) +translate_error (fs,0 , err); + } err =ext2fs_flush2 (fs,0 );if (err)
@@ -6301,6 +6304,15 @@ static void op_syncfs(fuse_req_t req, fuse_ino_t ino) } } +/* +* When iomap is enabled, the kernel will call syncfs right before +* calling the destroy method. If any syncfs succeeds, then we know +* that there will be a last syncfs and that it will write the GDT, so +* destroy doesn't need to waste time doing that. +*/ +if (fuse4fs_iomap_enabled (ff)) + ff->write_gdt_on_destroy =0 ; + out_unlock:fuse4fs_finish (ff, ret);fuse_reply_err (req, -ret);
@@ -8051,6 +8063,7 @@ int main(int argc, char *argv[]) .loop_fd = -1, #endif .translate_inums = 1, + .write_gdt_on_destroy = 1, };errcode_t err;FILE *orig_stderr = stderr;
misc/fuse2fs.c +16 -3
@@ -268,6 +268,7 @@ struct fuse2fs {int acl;int dirsync;int iomap_passthrough_options; +int write_gdt_on_destroy;enum fuse2fs_opstate opstate;int logfd;
@@ -1667,9 +1668,11 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))if (fs->super->s_error_count) fs->super->s_state |=EXT2_ERROR_FS ;ext2fs_mark_super_dirty (fs); - err =ext2fs_set_gdt_csum (fs); -if (err) -translate_error (fs,0 , err); +if (ff->write_gdt_on_destroy) { + err =ext2fs_set_gdt_csum (fs); +if (err) +translate_error (fs,0 , err); + } err =ext2fs_flush2 (fs,0 );if (err)
@@ -5858,6 +5861,15 @@ static int op_syncfs(const char *path) } } +/* +* When iomap is enabled, the kernel will call syncfs right before +* calling the destroy method. If any syncfs succeeds, then we know +* that there will be a last syncfs and that it will write the GDT, so +* destroy doesn't need to waste time doing that. +*/ +if (fuse2fs_iomap_enabled (ff)) + ff->write_gdt_on_destroy =0 ; + out_unlock:fuse2fs_finish (ff, ret);return ret;
@@ -7494,6 +7506,7 @@ int main(int argc, char *argv[])#ifdef HAVE_FUSE_LOOPDEV .loop_fd = -1, #endif + .write_gdt_on_destroy = 1, };errcode_t err;FILE *orig_stderr = stderr;
PATCH 10/11 fuse2fs: set sync, immutable, and append at file load time
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convey these three inode flags to the kernel when we're loading a file. This way the kernel can advertise and enforce those flags so that the fuse server doesn't have to.
--- fuse4fs/fuse4fs.c | 16 ++++++++++++++++ misc/fuse2fs.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 15 deletions(-)
fuse4fs/fuse4fs.c +16 -0
@@ -2159,6 +2159,22 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino, entry->entry_timeout =FUSE4FS_ATTR_TIMEOUT ; fstat->iflags =0 ; + +#ifdef FUSE_IFLAG_SYNC +if (inodep->i_flags &EXT2_SYNC_FL ) + fstat->iflags |=FUSE_IFLAG_SYNC ; +#endif + +#ifdef FUSE_IFLAG_IMMUTABLE +if (inodep->i_flags &EXT2_IMMUTABLE_FL ) + fstat->iflags |=FUSE_IFLAG_IMMUTABLE ; +#endif + +#ifdef FUSE_IFLAG_APPEND +if (inodep->i_flags &EXT2_APPEND_FL ) + fstat->iflags |=FUSE_IFLAG_APPEND ; +#endif +#ifdef HAVE_FUSE_IOMAP if (fuse4fs_iomap_enabled (ff)) { fstat->iflags |=FUSE_IFLAG_IOMAP ;
misc/fuse2fs.c +38 -15
103 lines not on this page · raw message
PATCH 11/11 fuse4fs: increase attribute timeout in iomap mode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In iomap mode, we trust the kernel to cache file attributes, because it is critical to keep all of the file IO permissions checking in the kernel as part of keeping all the file IO paths in the kernel. Therefore, increase the attribute timeout to 30 seconds to reduce the number of upcalls even further.
--- fuse4fs/fuse4fs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fuse4fs/fuse4fs.c +12 -3
@@ -123,7 +123,8 @@#endif #endif /* !defined(ENODATA) */ -#define FUSE4FS_ATTR_TIMEOUT (0.0) +#define FUSE4FS_IOMAP_ATTR_TIMEOUT (0.0) +#define FUSE4FS_ATTR_TIMEOUT (30.0)static inline uint64_t round_up (uint64_t b,unsigned int align) {
@@ -2155,8 +2156,14 @@ static int fuse4fs_stat_inode(struct fuse4fs *ff, ext2_ino_t ino,fuse4fs_ino_to_fuse (ff, &entry->ino, ino); entry->generation = inodep->i_generation; - entry->attr_timeout =FUSE4FS_ATTR_TIMEOUT ; - entry->entry_timeout =FUSE4FS_ATTR_TIMEOUT ; + +if (fuse4fs_iomap_enabled (ff)) { + entry->attr_timeout =FUSE4FS_IOMAP_ATTR_TIMEOUT ; + entry->entry_timeout =FUSE4FS_IOMAP_ATTR_TIMEOUT ; + }else { + entry->attr_timeout =FUSE4FS_ATTR_TIMEOUT ; + entry->entry_timeout =FUSE4FS_ATTR_TIMEOUT ; + } fstat->iflags =0 ;
@@ -2389,6 +2396,8 @@ static void op_statx(fuse_req_t req, fuse_ino_t fino, int flags, int mask,fuse4fs_finish (ff, ret);if (ret)fuse_reply_err (req, -ret); +else if (fuse4fs_iomap_enabled (ff)) +fuse_reply_statx (req,0 , &stx,FUSE4FS_IOMAP_ATTR_TIMEOUT );else fuse_reply_statx (req,0 , &stx,FUSE4FS_ATTR_TIMEOUT ); }
PATCH v6 4/6 fuse2fs: cache iomap mappings for even better file IO performance
In reply to Darrick J. WongHi all,
This series improves the performance (and correctness for some filesystems) by adding the ability to cache iomap mappings in the kernel. For filesystems that can change mapping states during pagecache writeback (e.g. unwritten extent conversion) this is absolutely necessary to deal with races with writes to the pagecache because writeback does not take i_rwsem. For everyone else, it simply eliminates roundtrips to userspace.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
Comments and questions are, as always, welcome.
e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-iomap-cache
---
Commits in this patchset:
* fuse2fs: enable caching of iomaps
* fuse2fs: be smarter about caching iomaps
* fuse2fs: enable iomap
--- fuse4fs/fuse4fs.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++---- misc/fuse2fs.c | 50 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 96 insertions(+), 8 deletions(-)
PATCH 1/3 fuse2fs: enable caching of iomaps
From: Darrick J. Wong <[email protected]>
Cache the iomaps we generate in the kernel for better performance.
--- fuse4fs/fuse4fs.c | 25 +++++++++++++++++++++++++ misc/fuse2fs.c | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
fuse4fs/fuse4fs.c +25 -0
@@ -293,6 +293,8 @@ struct fuse4fs {#ifdef STATX_WRITE_ATOMIC unsigned int awu_min, awu_max;#endif +/* options set by fuse_opt_parse must be of type int */ +int iomap_cache;#endif unsigned int blockmask;unsigned long offset;
@@ -6886,6 +6888,24 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,if (opflags &FUSE_IOMAP_OP_ATOMIC ) read.flags |=FUSE_IOMAP_F_ATOMIC_BIO ; +/* +* Cache the mapping in the kernel so that we can reuse them for +* subsequent IO. +*/ +if (ff->iomap_cache) { + ret =fuse_lowlevel_notify_iomap_upsert (ff->fuse, fino, ino, + &read,NULL ); +if (ret) { + ret =translate_error (fs, ino, -ret); + goto out_unlock; + }else { +/* Tell the kernel to retry from cache */ + read.type =FUSE_IOMAP_TYPE_RETRY_CACHE ; + read.dev =FUSE_IOMAP_DEV_NULL ; + read.addr =FUSE_IOMAP_NULL_ADDR ; + } + } + out_unlock:fuse4fs_finish (ff, ret);if (ret)
@@ -7699,6 +7719,10 @@ static struct fuse_opt fuse4fs_opts[] = {#ifdef HAVE_CLOCK_MONOTONIC FUSE4FS_OPT("timing", timing, 1),#endif +#ifdef HAVE_FUSE_IOMAP + FUSE4FS_OPT("iomap_cache", iomap_cache, 1), + FUSE4FS_OPT("noiomap_cache", iomap_cache, 0), +#endif #ifdef HAVE_FUSE_IOMAP #ifdef MS_LAZYTIME
@@ -8083,6 +8107,7 @@ int main(int argc, char *argv[]) .iomap_want = FT_DEFAULT, .iomap_state = IOMAP_UNKNOWN, .iomap_dev = FUSE_IOMAP_DEV_NULL, + .iomap_cache = 1,#endif #ifdef HAVE_FUSE_LOOPDEV .loop_fd = -1,
misc/fuse2fs.c +24 -0
@@ -285,6 +285,8 @@ struct fuse2fs {#ifdef STATX_WRITE_ATOMIC unsigned int awu_min, awu_max;#endif +/* options set by fuse_opt_parse must be of type int */ +int iomap_cache;#endif unsigned int blockmask;unsigned long offset;
@@ -6440,6 +6442,23 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,if (opflags &FUSE_IOMAP_OP_ATOMIC ) read->flags |=FUSE_IOMAP_F_ATOMIC_BIO ; +/* +* Cache the mapping in the kernel so that we can reuse them for +* subsequent IO. +*/ +if (ff->iomap_cache) { + ret =fuse_fs_iomap_upsert (nodeid, attr_ino, read,NULL ); +if (ret) { + ret =translate_error (fs, attr_ino, -ret); + goto out_unlock; + }else { +/* Tell the kernel to retry from cache */ + read->type =FUSE_IOMAP_TYPE_RETRY_CACHE ; + read->dev =FUSE_IOMAP_DEV_NULL ; + read->addr =FUSE_IOMAP_NULL_ADDR ; + } + } + out_unlock:fuse2fs_finish (ff, ret);return ret;
@@ -7245,6 +7264,10 @@ static struct fuse_opt fuse2fs_opts[] = {#ifdef HAVE_CLOCK_MONOTONIC FUSE2FS_OPT("timing", timing, 1),#endif +#ifdef HAVE_FUSE_IOMAP + FUSE2FS_OPT("iomap_cache", iomap_cache, 1), + FUSE2FS_OPT("noiomap_cache", iomap_cache, 0), +#endif #ifdef HAVE_FUSE_IOMAP #ifdef MS_LAZYTIME
@@ -7525,6 +7548,7 @@ int main(int argc, char *argv[]) .iomap_want = FT_DEFAULT, .iomap_state = IOMAP_UNKNOWN, .iomap_dev = FUSE_IOMAP_DEV_NULL, + .iomap_cache = 1,#endif #ifdef HAVE_FUSE_LOOPDEV .loop_fd = -1,
PATCH 2/3 fuse2fs: be smarter about caching iomaps
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
There's no point in caching iomaps when we're initiating a disk write to an unwritten region -- we'll just replace the mapping in the ioend. Save ourselves a bit of overhead by screening for that.
--- fuse4fs/fuse4fs.c | 27 ++++++++++++++++++++++++++- misc/fuse2fs.c | 24 +++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-)
fuse4fs/fuse4fs.c +26 -1
@@ -6822,6 +6822,31 @@ static int fuse4fs_iomap_begin_write(struct fuse4fs *ff, ext2_ino_t ino,return 0 ; } +static inline int fuse4fs_should_cache_iomap (struct fuse4fs *ff, +uint32_t opflags, +const struct fuse_file_iomap *map) +{ +if (!ff->iomap_cache) +return 0 ; + +/* XXX I think this is stupid */ +return 1 ; + +/* +* Don't cache small unwritten extents that are being written to the +* device because the overhead of keeping the cache updated will tank +* performance. +*/ +if ((opflags & (FUSE_IOMAP_OP_WRITE |FUSE_IOMAP_OP_DIRECT )) ==0 ) +return 1 ; +if (map->type !=FUSE_IOMAP_TYPE_UNWRITTEN ) +return 1 ; +if (map->length >=FUSE4FS_FSB_TO_B (ff,16 )) +return 1 ; + +return 0 ; +} +static void op_iomap_begin (fuse_req_t req,fuse_ino_t fino,uint64_t dontcare,off_t pos,uint64_t count,uint32_t opflags) {
@@ -6892,7 +6917,7 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,* Cache the mapping in the kernel so that we can reuse them for * subsequent IO. */ -if (ff->iomap_cache) { +if (fuse4fs_should_cache_iomap (ff, opflags, &read)) { ret =fuse_lowlevel_notify_iomap_upsert (ff->fuse, fino, ino, &read,NULL );if (ret) {
misc/fuse2fs.c +23 -1
@@ -6374,6 +6374,28 @@ static int fuse2fs_iomap_begin_write(struct fuse2fs *ff, ext2_ino_t ino,return 0 ; } +static inline int fuse2fs_should_cache_iomap (struct fuse2fs *ff, +uint32_t opflags, +const struct fuse_file_iomap *map) +{ +if (!ff->iomap_cache) +return 0 ; + +/* +* Don't cache small unwritten extents that are being written to the +* device because the overhead of keeping the cache updated will tank +* performance. +*/ +if ((opflags & (FUSE_IOMAP_OP_WRITE |FUSE_IOMAP_OP_DIRECT )) ==0 ) +return 1 ; +if (map->type !=FUSE_IOMAP_TYPE_UNWRITTEN ) +return 1 ; +if (map->length >=FUSE2FS_FSB_TO_B (ff,16 )) +return 1 ; + +return 0 ; +} + static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino, off_t pos, uint64_t count, uint32_t opflags, struct fuse_file_iomap *read,
@@ -6446,7 +6468,7 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,* Cache the mapping in the kernel so that we can reuse them for * subsequent IO. */ -if (ff->iomap_cache) { +if (fuse2fs_should_cache_iomap (ff, opflags, read)) { ret =fuse_fs_iomap_upsert (nodeid, attr_ino, read,NULL );if (ret) { ret =translate_error (fs, attr_ino, -ret);
PATCH 3/3 fuse2fs: enable iomap
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that iomap functionality is complete, enable this for users.
--- fuse4fs/fuse4fs.c | 4 ---- misc/fuse2fs.c | 4 ---- 2 files changed, 8 deletions(-)
fuse4fs/fuse4fs.c +0 -4
@@ -2017,10 +2017,6 @@ static inline int fuse_set_feature_flag(struct fuse_conn_info *conn,static void fuse4fs_iomap_enable (struct fuse_conn_info *conn,struct fuse4fs *ff) { -/* Don't let anyone touch iomap until the end of the patchset. */ - ff->iomap_state =IOMAP_DISABLED ; -return ; -/* iomap only works with block devices */ if (ff->iomap_state !=IOMAP_DISABLED &&fuse4fs_on_bdev (ff) &&fuse_set_feature_flag (conn,FUSE_CAP_IOMAP ))
misc/fuse2fs.c +0 -4
@@ -1843,10 +1843,6 @@ static inline int fuse_set_feature_flag(struct fuse_conn_info *conn,static void fuse2fs_iomap_enable (struct fuse_conn_info *conn,struct fuse2fs *ff) { -/* Don't let anyone touch iomap until the end of the patchset. */ - ff->iomap_state =IOMAP_DISABLED ; -return ; -/* iomap only works with block devices */ if (ff->iomap_state !=IOMAP_DISABLED &&fuse2fs_on_bdev (ff) &&fuse_set_feature_flag (conn,FUSE_CAP_IOMAP ))
PATCH v6 5/6 fuse2fs: improve block and inode caching
In reply to Darrick J. WongHi all,
This series ports the libext2fs inode cache to the new cache.c hashtable code that was added for fuse4fs unlinked file support and improves on the UNIX I/O manager's block cache by adding a new I/O manager that does its own caching. Now we no longer have statically sized buffer caching for the two fuse servers.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
Comments and questions are, as always, welcome.
e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-caching
---
Commits in this patchset:
* libsupport: add caching IO manager
* iocache: add the actual buffer cache
* iocache: bump buffer mru priority every 50 accesses
* fuse2fs: enable caching IO manager
* fuse2fs: increase inode cache size
* libext2fs: improve caching for inodes
--- lib/ext2fs/ext2fsP.h | 13 + lib/support/cache.h | 1 lib/support/iocache.h | 17 + debugfs/Makefile.in | 8 e2fsck/Makefile.in | 12 - fuse4fs/Makefile.in | 11 - fuse4fs/fuse4fs.c | 8 lib/ext2fs/Makefile.in | 14 - lib/ext2fs/inode.c | 215 ++++++++++--- lib/ext2fs/io_manager.c | 3 lib/support/Makefile.in | 6 lib/support/cache.c | 16 + lib/support/iocache.c | 765 +++++++++++++++++++++++++++++++++++++++++++++++ misc/Makefile.in | 12 - misc/fuse2fs.c | 10 + resize/Makefile.in | 11 - tests/fuzz/Makefile.in | 4 tests/progs/Makefile.in | 4 18 files changed, 1040 insertions(+), 90 deletions(-) create mode 100644 lib/support/iocache.h create mode 100644 lib/support/iocache.c
PATCH 1/6 libsupport: add caching IO manager
From: Darrick J. Wong <[email protected]>
Start creating a caching IO manager so that we can have better caching of metadata blocks in fuse2fs. For now it's just a passthrough cache.
--- lib/support/iocache.h | 17 +++ lib/ext2fs/io_manager.c | 3 lib/support/Makefile.in | 6 + lib/support/iocache.c | 317 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 lib/support/iocache.h create mode 100644 lib/support/iocache.c
lib/support/iocache.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* iocache.h - IO cache +* +* Copyright (C) 2025 Oracle. +* +* %Begin-Header% +* This file may be redistributed under the terms of the GNU Public +* License. +* %End-Header% +*/ +#ifndef __IOCACHE_H__ +#define __IOCACHE_H__ + +errcode_t iocache_set_backing_manager (io_manager manager); +extern io_manager iocache_io_manager; + +#endif /* __IOCACHE_H__ */
lib/ext2fs/io_manager.c +3 -0
@@ -16,9 +16,12 @@#if HAVE_SYS_TYPES_H #include <sys/types.h> #endif +#include <stdbool.h> #include "ext2_fs.h" #include "ext2fs.h" +#include "support/list.h" +#include "support/cache.h" errcode_t io_channel_set_options (io_channel channel,const char *opts) {
lib/support/Makefile.in +5 -1
@@ -15,6 +15,7 @@ all:: OBJS= bthread.o \ cstring.o \ + iocache.o \ mkquota.o \ plausible.o \ profile.o \
@@ -44,7 +45,8 @@ SRCS= $(srcdir)/argv_parse.c \ $(srcdir)/quotaio_v2.c \ $(srcdir)/dict.c \ $(srcdir)/devname.c \ - $(srcdir)/cache.c + $(srcdir)/cache.c \ + $(srcdir)/iocache.c LIBRARY= libsupport LIBDIR= support
@@ -191,3 +193,5 @@ devname.o: $(srcdir)/devname.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/devname.h $(srcdir)/nls-enable.h cache.o: $(srcdir)/cache.c $(top_builddir)/lib/config.h \ $(srcdir)/cache.h $(srcdir)/list.h $(srcdir)/xbitops.h +iocache.o: $(srcdir)/iocache.c $(top_builddir)/lib/config.h \ + $(srcdir)/iocache.h $(srcdir)/cache.h $(srcdir)/list.h $(srcdir)/xbitops.h
lib/support/iocache.c new file +317 -0
317 lines not on this page · raw message
PATCH 2/6 iocache: add the actual buffer cache
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Wire up buffer caching into our new caching IO manager.
--- lib/support/iocache.c | 483 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 461 insertions(+), 22 deletions(-)
lib/support/iocache.c +461 -22
@@ -9,46 +9,287 @@* %End-Header% */ #include "config.h" +#include <assert.h> +#include <stdbool.h> +#include <pthread.h> +#include <unistd.h> +#include <limits.h> #include "ext2fs/ext2_fs.h" #include "ext2fs/ext2fs.h" #include "ext2fs/ext2fsP.h" #include "support/iocache.h" +#include "support/list.h" +#include "support/cache.h" #define IOCACHE_IO_CHANNEL_MAGIC 0x424F5254/* BORT */ static io_manager iocache_backing_manager; +static inline uint64_t B_TO_FSBT (io_channel channel,uint64_t number) { +return number / channel->block_size; +} + +static inline uint64_t B_TO_FSB (io_channel channel,uint64_t number) { +return (number + channel->block_size -1 ) / channel->block_size; +} +struct iocache_private_data {int magic; -io_channel real; +io_channel real;/* lower level io channel */ +io_channel channel;/* cache channel */ +struct cache cache; +pthread_mutex_t stats_lock; +struct struct_io_stats io_stats; +unsigned long long write_errors; }; +#define IOCACHEDATA (cache) \ + (container_of(cache, struct iocache_private_data, cache)) +static struct iocache_private_data *IOCACHE (io_channel channel) {return (struct iocache_private_data *)channel->private_data; } -static errcode_t iocache_read_error (io_channel channel,unsigned long block, -int count,void *data,size_t size, -int actual_bytes_read,errcode_t error) +struct iocache_buf { +struct cache_node node; +struct list_head list; +blk64_t block; +void *buf; +errcode_t write_error; +unsigned int uptodate:1 ; +unsigned int dirty:1 ; +}; + +static inline void iocache_buf_lock (struct iocache_buf *ubuf) +{ +pthread_mutex_lock (&ubuf->node.cn_mutex); +} + +static inline void iocache_buf_unlock (struct iocache_buf *ubuf) +{ +pthread_mutex_unlock (&ubuf->node.cn_mutex); +} + +struct iocache_key { +blk64_t block; +}; + +#define IOKEY (key) ((struct iocache_key *)(key)) +#define IOBUF (node) (container_of((node), struct iocache_buf, node)) + +static unsigned int +iocache_hash (cache_key_t key,unsigned int hashsize,unsigned int hashshift) +{ +uint64_t hashval =IOKEY (key)->block; +uint64_t tmp; + + tmp = hashval ^ (GOLDEN_RATIO_PRIME + hashval) /CACHE_LINE_SIZE ; + tmp = tmp ^ ((tmp ^GOLDEN_RATIO_PRIME ) >> hashshift); +return tmp % hashsize; +} + +static int iocache_compare (struct cache_node *node,cache_key_t key) +{ +struct iocache_buf *ubuf =IOBUF (node); +struct iocache_key *ukey =IOKEY (key); + +if (ubuf->block == ukey->block) +return CACHE_HIT ; + +return CACHE_MISS ; +} + +static struct cache_node *iocache_alloc_node (struct cache *cache, +cache_key_t key) +{ +struct iocache_private_data *data =IOCACHEDATA (cache); +struct iocache_key *ukey =IOKEY (key); +struct iocache_buf *ubuf; +errcode_t retval; + + retval =ext2fs_get_mem (sizeof (struct iocache_buf ), &ubuf); +if (retval) +return NULL ; +memset (ubuf,0 ,sizeof (*ubuf)); + + retval =io_channel_alloc_buf (data->channel,0 , &ubuf->buf); +if (retval) { +free (ubuf); +return NULL ; + } +memset (ubuf->buf,0 , data->channel->block_size); + +INIT_LIST_HEAD (&ubuf->list); + ubuf->block = ukey->block; +return &ubuf->node; +} + +static bool iocache_flush_node (struct cache *cache,struct cache_node *node) +{ +struct iocache_private_data *data =IOCACHEDATA (cache); +struct iocache_buf *ubuf =IOBUF (node); +errcode_t retval; + +if (ubuf->dirty) { + retval =io_channel_write_blk64 (data->real, ubuf->block,1 , + ubuf->buf); +if (retval) { + ubuf->write_error = retval; + data->write_errors++; + }else { + ubuf->dirty =0 ; + ubuf->write_error =0 ; + } + } + +return ubuf->dirty; +} + +static void iocache_relse (struct cache *cache,struct cache_node *node) +{ +struct iocache_buf *ubuf =IOBUF (node); + +ext2fs_free_mem (&ubuf->buf); +ext2fs_free_mem (&ubuf); +} + +static unsigned int iocache_bulkrelse (struct cache *cache, +struct list_head *list) +{ +struct cache_node *cn, *n; +int count =0 ; + +if (list_empty (list)) +return 0 ; + +list_for_each_entry_safe (cn, n, list, cn_mru) { +iocache_relse (cache, cn); + count++; + } + +return count; +} + +/* Flush all dirty buffers in the cache to disk. */ +static errcode_t iocache_flush_cache (struct iocache_private_data *data) +{ +return cache_flush (&data->cache) ?0 :EIO ; +} + +/* Flush all dirty buffers in this range of the cache to disk. */ +static errcode_t iocache_flush_range (struct iocache_private_data *data, +blk64_t block,uint64_t count) +{ +uint64_t i; +bool still_dirty = false; + +for (i =0 ; i < count; i++) { +struct iocache_key ukey = { + .block = block + i, + }; +struct cache_node *node; + +cache_node_get (&data->cache, &ukey,CACHE_GET_INCORE , + &node); +if (!node) +continue ; + +/* cache_flush holds cn_mutex across the node flush */ +pthread_mutex_unlock (&node->cn_mutex); + still_dirty |=iocache_flush_node (&data->cache, node); +pthread_mutex_unlock (&node->cn_mutex); + +cache_node_put (&data->cache, node); + } + +return still_dirty ?EIO :0 ; +} + +static void iocache_add_list (struct cache *cache,struct cache_node *node, +void *data) +{ +struct iocache_buf *ubuf =IOBUF (node); +struct list_head *list = data; + +assert (node->cn_count ==0 || node->cn_count ==1 ); + +iocache_buf_lock (ubuf); +cache_node_grab (cache, node); +list_add_tail (&ubuf->list, list); +iocache_buf_unlock (ubuf); +} + +static void iocache_invalidate_bufs (struct iocache_private_data *data, +struct list_head *list) +{ +struct iocache_buf *ubuf, *n; + +list_for_each_entry_safe (ubuf, n, list, list) { +struct iocache_key ukey = { + .block = ubuf->block, + }; + +assert (ubuf->node.cn_count ==1 ); + +iocache_buf_lock (ubuf); + ubuf->dirty =0 ; +list_del_init (&ubuf->list); +iocache_buf_unlock (ubuf); + +cache_node_put (&data->cache, &ubuf->node); +cache_node_purge (&data->cache, &ukey, &ubuf->node); + } +} + +/* +* Remove all blocks from the cache. Dirty contents are discarded. Buffer +* refcounts must be zero! +*/ +static void iocache_invalidate_cache (struct iocache_private_data *data) { -io_channel iocache_channel = channel->app_data; +LIST_HEAD (list); -return iocache_channel->read_error (iocache_channel, block, count, data, - size, actual_bytes_read, error); +cache_walk (&data->cache, iocache_add_list, &list); +iocache_invalidate_bufs (data, &list); } -static errcode_t iocache_write_error (io_channel channel,unsigned long block, -int count,const void *data,size_t size, -int actual_bytes_written, -errcode_t error) +/* +* Remove a range of blocks from the cache. Dirty contents are discarded. +* Buffer refcounts must be zero! +*/ +static void iocache_invalidate_range (struct iocache_private_data *data, +blk64_t block,uint64_t count) { -io_channel iocache_channel = channel->app_data; +LIST_HEAD (list); +uint64_t i; -return iocache_channel->write_error (iocache_channel, block, count, data, - size, actual_bytes_written, error); +for (i =0 ; i < count; i++) { +struct iocache_key ukey = { + .block = block + i, + }; +struct cache_node *node; + +cache_node_get (&data->cache, &ukey,CACHE_GET_INCORE , + &node); +if (node) { +iocache_add_list (&data->cache, node, &list); +cache_node_put (&data->cache, node); + } + } +iocache_invalidate_bufs (data, &list); } +static const struct cache_operations iocache_ops = { + .hash = iocache_hash, + .alloc = iocache_alloc_node, + .flush = iocache_flush_node, + .relse = iocache_relse, + .compare = iocache_compare, + .bulkrelse = iocache_bulkrelse, + .resize = cache_gradual_resize, +}; +static errcode_t iocache_open (const char *name,int flags,io_channel *channel) {io_channel io =NULL ;
@@ -65,6 +306,9 @@ static errcode_t iocache_open(const char *name, int flags, io_channel *channel)if (retval)return retval; +/* disable any static cache in the lower io manager */ +io_channel_set_options (real,"cache=off" ); + retval =ext2fs_get_mem (sizeof (struct struct_io_channel ), &io);if (retval) goto out_backing;
@@ -76,12 +320,19 @@ static errcode_t iocache_open(const char *name, int flags, io_channel *channel) goto out_channel;memset (data,0 ,sizeof (struct iocache_private_data )); data->magic =IOCACHE_IO_CHANNEL_MAGIC ; + data->io_stats.num_fields =4 ; + data->channel = io; io->manager = iocache_io_manager; retval =ext2fs_get_mem (strlen (name) +1 , &io->name);if (retval) goto out_data; + retval =cache_init (CACHE_AUTO_SHRINK ,1U <<10 , &iocache_ops, + &data->cache); +if (retval) + goto out_name; +strcpy (io->name, name); io->private_data = data; io->block_size = real->block_size;
@@ -91,12 +342,14 @@ static errcode_t iocache_open(const char *name, int flags, io_channel *channel) io->flags = real->flags; data->real = real; real->app_data = io; - real->read_error = iocache_read_error; - real->write_error = iocache_write_error; + +pthread_mutex_init (&data->stats_lock,NULL ); *channel = io;return 0 ; +out_name: +ext2fs_free_mem (&io->name); out_data:ext2fs_free_mem (&data); out_channel:
@@ -116,6 +369,10 @@ static errcode_t iocache_close(io_channel channel)if (--channel->refcount >0 )return 0 ; +pthread_mutex_destroy (&data->stats_lock); +cache_flush (&data->cache); +cache_purge (&data->cache); +cache_destroy (&data->cache);if (data->real) retval =io_channel_close (data->real);ext2fs_free_mem (&channel->private_data);
@@ -134,6 +391,11 @@ static errcode_t iocache_set_blksize(io_channel channel, int blksize)EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); + retval =iocache_flush_cache (data); +if (retval) +return retval; +iocache_invalidate_cache (data); + retval =io_channel_set_blksize (data->real, blksize);if (retval)return retval;
@@ -145,21 +407,34 @@ static errcode_t iocache_set_blksize(io_channel channel, int blksize)static errcode_t iocache_flush (io_channel channel) {struct iocache_private_data *data =IOCACHE (channel); +errcode_t retval =0 ; +errcode_t retval2;EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); -return io_channel_flush (data->real); + retval =iocache_flush_cache (data); + retval2 =io_channel_flush (data->real); +if (retval) +return retval; +return retval2; }static errcode_t iocache_write_byte (io_channel channel,unsigned long offset,int count,const void *buf) {struct iocache_private_data *data =IOCACHE (channel); +blk64_t bno =B_TO_FSBT (channel, offset); +blk64_t next_bno =B_TO_FSB (channel, offset + count); +errcode_t retval;EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); + retval =iocache_flush_range (data, bno, next_bno - bno); +if (retval) +return retval; +iocache_invalidate_range (data, bno, next_bno - bno);return io_channel_write_byte (data->real, offset, count, buf); }
@@ -170,6 +445,31 @@ static errcode_t iocache_set_option(io_channel channel, const char *option,EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); +errcode_t retval; + +/* don't let unix io cache= options leak through */ +if (!strcmp (option,"cache" )) +return 0 ; + +if (!strcmp (option,"cache_blocks" )) { +long long size; + +if (!arg) +return EXT2_ET_INVALID_ARGUMENT ; + + errno =0 ; + size =strtoll (arg,NULL ,0 ); +if (errno || size ==0 || size >UINT_MAX ) +return EXT2_ET_INVALID_ARGUMENT ; + +cache_set_maxcount (&data->cache, size); +return 0 ; + } + + retval =iocache_flush_cache (data); +if (retval) +return retval; +iocache_invalidate_cache (data);return data->real->manager->set_option (data->real, option, arg); }
@@ -181,31 +481,157 @@ static errcode_t iocache_get_stats(io_channel channel, io_stats *io_stats)EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); -return data->real->manager->get_stats (data->real, io_stats); +/* +* Yes, io_stats is a double-pointer, and we let the caller scribble on +* our stats struct WITHOUT LOCKING! +*/ +if (io_stats) + *io_stats = &data->io_stats; +return 0 ; +} + +static void iocache_update_stats (struct iocache_private_data *data, +unsigned long long bytes_read, +unsigned long long bytes_written, +int cache_op) +{ +pthread_mutex_lock (&data->stats_lock); + data->io_stats.bytes_read += bytes_read; + data->io_stats.bytes_written += bytes_written; +if (cache_op ==CACHE_HIT ) + data->io_stats.cache_hits++; +else + data->io_stats.cache_misses++; +pthread_mutex_unlock (&data->stats_lock); }static errcode_t iocache_read_blk64 (io_channel channel,unsigned long long block,int count,void *buf) { +struct iocache_key ukey = { + .block = block, + };struct iocache_private_data *data =IOCACHE (channel); +unsigned long long i; +errcode_t retval;EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); -return io_channel_read_blk64 (data->real, block, count, buf); +/* +* If we're doing an odd-sized read, flush out the cache and then do a +* direct read. +*/ +if (count <0 ) { +uint64_t fsbcount =B_TO_FSB (channel, -count); + + retval =iocache_flush_range (data, block, fsbcount); +if (retval) +return retval; +iocache_invalidate_range (data, block, fsbcount); +iocache_update_stats (data,0 ,0 ,CACHE_MISS ); +return io_channel_read_blk64 (data->real, block, count, buf); + } + +for (i =0 ; i < count; i++, ukey.block++, buf += channel->block_size) { +struct cache_node *node; +struct iocache_buf *ubuf; + +cache_node_get (&data->cache, &ukey,0 , &node); +if (!node) { +/* cannot instantiate cache, just do a direct read */ + retval =io_channel_read_blk64 (data->real, ukey.block, +1 , buf); +if (retval) +return retval; +iocache_update_stats (data, channel->block_size,0 , +CACHE_MISS ); +continue ; + } + + ubuf =IOBUF (node); +iocache_buf_lock (ubuf); +if (!ubuf->uptodate) { + retval =io_channel_read_blk64 (data->real, ukey.block, +1 , ubuf->buf); +if (!retval) { + ubuf->uptodate =1 ; +iocache_update_stats (data, channel->block_size, +0 ,CACHE_MISS ); + } + }else { +iocache_update_stats (data, channel->block_size,0 , +CACHE_HIT ); + } +if (ubuf->uptodate) +memcpy (buf, ubuf->buf, channel->block_size); +iocache_buf_unlock (ubuf); +cache_node_put (&data->cache, node); +if (retval) +return retval; + } + +return 0 ; }static errcode_t iocache_write_blk64 (io_channel channel,unsigned long long block,int count,const void *buf) { +struct iocache_key ukey = { + .block = block, + };struct iocache_private_data *data =IOCACHE (channel); +unsigned long long i; +errcode_t retval;EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); -return io_channel_write_blk64 (data->real, block, count, buf); +/* +* If we're doing an odd-sized write, flush out the cache and then do a +* direct write. +*/ +if (count <0 ) { +uint64_t fsbcount =B_TO_FSB (channel, -count); + + retval =iocache_flush_range (data, block, fsbcount); +if (retval) +return retval; +iocache_invalidate_range (data, block, fsbcount); +iocache_update_stats (data,0 ,0 ,CACHE_MISS ); +return io_channel_write_blk64 (data->real, block, count, buf); + } + +for (i =0 ; i < count; i++, ukey.block++, buf += channel->block_size) { +struct cache_node *node; +struct iocache_buf *ubuf; + +cache_node_get (&data->cache, &ukey,0 , &node); +if (!node) { +/* cannot instantiate cache, do a direct write */ + retval =io_channel_write_blk64 (data->real, ukey.block, +1 , buf); +if (retval) +return retval; +iocache_update_stats (data,0 , channel->block_size, +CACHE_MISS ); +continue ; + } + + ubuf =IOBUF (node); +iocache_buf_lock (ubuf); +memcpy (ubuf->buf, buf, channel->block_size); +iocache_update_stats (data,0 , channel->block_size, + ubuf->uptodate ?CACHE_HIT :CACHE_MISS ); + ubuf->dirty =1 ; + ubuf->uptodate =1 ; +iocache_buf_unlock (ubuf); +cache_node_put (&data->cache, node); + } + +return 0 ; } static errcode_t iocache_read_blk(io_channel channel, unsigned long block,
@@ -224,11 +650,17 @@ static errcode_t iocache_discard(io_channel channel, unsigned long long block, unsigned long long count) {struct iocache_private_data *data =IOCACHE (channel); +errcode_t retval;EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); -return io_channel_discard (data->real, block, count); + retval =io_channel_discard (data->real, block, count); +if (retval) +return retval; + +iocache_invalidate_range (data, block, count); +return 0 ; } static errcode_t iocache_cache_readahead(io_channel channel,
@@ -247,11 +679,17 @@ static errcode_t iocache_zeroout(io_channel channel, unsigned long long block, unsigned long long count) {struct iocache_private_data *data =IOCACHE (channel); +errcode_t retval;EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); -return io_channel_zeroout (data->real, block, count); + retval =io_channel_zeroout (data->real, block, count); +if (retval) +return retval; + +iocache_invalidate_range (data, block, count); +return 0 ; }static errcode_t iocache_get_fd (io_channel channel,int *fd)
@@ -273,6 +711,7 @@ static errcode_t iocache_invalidate_blocks(io_channel channel,EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );EXT2_CHECK_MAGIC (data,IOCACHE_IO_CHANNEL_MAGIC ); +iocache_invalidate_range (data, block, count);return io_channel_invalidate_blocks (data->real, block, count); }
PATCH 3/6 iocache: bump buffer mru priority every 50 accesses
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If a buffer is hot enough to survive more than 50 access without being reclaimed, bump its priority to the next MRU so it sticks around longer.
--- lib/support/cache.h | 1 + lib/support/cache.c | 16 ++++++++++++++++ lib/support/iocache.c | 9 +++++++++ 3 files changed, 26 insertions(+)
lib/support/cache.h +1 -0
@@ -180,5 +180,6 @@ int cache_node_purge(struct cache *, cache_key_t, struct cache_node *);void cache_report (FILE *fp,const char *,struct cache *);int cache_overflowed (struct cache *);struct cache_node *cache_node_grab (struct cache *cache,struct cache_node *node); +void cache_node_bump_priority (struct cache *cache,struct cache_node *node);#endif /* __CACHE_H__ */
lib/support/cache.c +16 -0
@@ -678,6 +678,22 @@ cache_node_put(cache_shrink (cache); } +/* Bump the priority of a cache node. Caller must hold cn_mutex. */ +void +cache_node_bump_priority ( +struct cache *cache, +struct cache_node *node) +{ +int *priop; + +if (node->cn_priority ==CACHE_DIRTY_PRIORITY ) + priop = &node->cn_old_priority; +else + priop = &node->cn_priority; +if (*priop <CACHE_MAX_PRIORITY ) + (*priop)++; +} + void cache_node_set_priority( struct cache * cache,
lib/support/iocache.c +9 -0
@@ -57,6 +57,7 @@ struct iocache_buf {blk64_t block;void *buf;errcode_t write_error; +uint8_t access; unsigned int uptodate:1; unsigned int dirty:1; };
@@ -566,6 +567,10 @@ static errcode_t iocache_read_blk64(io_channel channel, }if (ubuf->uptodate)memcpy (buf, ubuf->buf, channel->block_size); +if (++ubuf->access >50 ) { +cache_node_bump_priority (&data->cache, node); + ubuf->access =0 ; + }iocache_buf_unlock (ubuf);cache_node_put (&data->cache, node);if (retval)
@@ -627,6 +632,10 @@ static errcode_t iocache_write_blk64(io_channel channel, ubuf->uptodate ? CACHE_HIT : CACHE_MISS); ubuf->dirty =1 ; ubuf->uptodate =1 ; +if (++ubuf->access >50 ) { +cache_node_bump_priority (&data->cache, node); + ubuf->access =0 ; + }iocache_buf_unlock (ubuf);cache_node_put (&data->cache, node); }
PATCH 4/6 fuse2fs: enable caching IO manager
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable the new dynamic iocache I/O manager in the fuse server, and turn off all the other cache control.
--- fuse4fs/Makefile.in | 3 ++- fuse4fs/fuse4fs.c | 4 +++- misc/Makefile.in | 4 +++- misc/fuse2fs.c | 6 +++++- 4 files changed, 13 insertions(+), 4 deletions(-)
fuse4fs/Makefile.in +2 -1
@@ -147,7 +147,8 @@ fuse4fs.o: $(srcdir)/fuse4fs.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/ext2fsP.h \ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \ $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \ - $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h + $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \ + $(top_srcdir)/lib/support/iocache.h journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/../debugfs/journal.h \ $(top_srcdir)/e2fsck/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
fuse4fs/fuse4fs.c +3 -1
@@ -56,6 +56,7 @@#include "support/bthread.h" #include "support/list.h" #include "support/cache.h" +#include "support/iocache.h" #include "../version.h" #include "uuid/uuid.h"
@@ -1575,6 +1576,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff) flags |=EXT2_FLAG_DIRECT_IO ;dbg_printf (ff,"opening with flags=0x%x\n" , flags); +iocache_set_backing_manager (unix_io_manager); err =fuse4fs_try_losetup (ff, flags);if (err)
@@ -1612,7 +1614,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff) deadline =init_deadline (FUSE4FS_OPEN_TIMEOUT ); do { err = ext2fs_open2(fuse4fs_device(ff), options, flags, 0, 0, - unix_io_manager, &ff->fs); + iocache_io_manager, &ff->fs); if ((err == EPERM || err == EACCES) && (!ff->ro || (flags & EXT2_FLAG_RW))) { /*
misc/Makefile.in +3 -1
@@ -880,7 +880,9 @@ fuse2fs.o: $(srcdir)/fuse2fs.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/ext2fsP.h \ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \ - $(top_srcdir)/lib/e2p/e2p.h + $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \ + $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \ + $(top_srcdir)/lib/support/iocache.h e2fuzz.o: $(srcdir)/e2fuzz.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
misc/fuse2fs.c +5 -1
@@ -53,6 +53,9 @@#include "ext2fs/ext2_fs.h" #include "ext2fs/ext2fsP.h" #include "support/bthread.h" +#include "support/list.h" +#include "support/cache.h" +#include "support/iocache.h" #include "../version.h" #include "uuid/uuid.h"
@@ -1405,6 +1408,7 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff) flags |=EXT2_FLAG_DIRECT_IO ;dbg_printf (ff,"opening with flags=0x%x\n" , flags); +iocache_set_backing_manager (unix_io_manager); err =fuse2fs_try_losetup (ff, flags);if (err)
@@ -1442,7 +1446,7 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff) deadline =init_deadline (FUSE2FS_OPEN_TIMEOUT ); do { err = ext2fs_open2(fuse2fs_device(ff), options, flags, 0, 0, - unix_io_manager, &ff->fs); + iocache_io_manager, &ff->fs); if ((err == EPERM || err == EACCES) && (!ff->ro || (flags & EXT2_FLAG_RW))) { /*
PATCH 5/6 fuse2fs: increase inode cache size
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Increase the internal inode cache size. Does this improve performance any?
--- fuse4fs/fuse4fs.c | 4 ++++ misc/fuse2fs.c | 4 ++++ 2 files changed, 8 insertions(+)
fuse4fs/fuse4fs.c +4 -0
@@ -1687,6 +1687,10 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff)if (err)return translate_error (ff->fs,0 , err); + err =ext2fs_create_inode_cache (ff->fs,1024 ); +if (err) +return translate_error (ff->fs,0 , err); + ff->fs->priv_data = ff; ff->blocklog =u_log2 (ff->fs->blocksize); ff->blockmask = ff->fs->blocksize -1 ;
misc/fuse2fs.c +4 -0
@@ -1515,6 +1515,10 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff)log_printf (ff,"%s %s.\n" ,_ ("mounted filesystem" ), uuid); } + err =ext2fs_create_inode_cache (ff->fs,1024 ); +if (err) +return translate_error (ff->fs,0 , err); + ff->fs->priv_data = ff; ff->blocklog =u_log2 (ff->fs->blocksize); ff->blockmask = ff->fs->blocksize -1 ;
PATCH 6/6 libext2fs: improve caching for inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use our new cache code to improve the ondisk inode cache inside libext2fs. Oops, list.h duplication, and libext2fs needs to link against libsupport now.
--- lib/ext2fs/ext2fsP.h | 13 ++- debugfs/Makefile.in | 8 +- e2fsck/Makefile.in | 12 +-- fuse4fs/Makefile.in | 8 +- lib/ext2fs/Makefile.in | 14 ++- lib/ext2fs/inode.c | 215 +++++++++++++++++++++++++++++++++++++---------- misc/Makefile.in | 8 +- resize/Makefile.in | 11 +- tests/fuzz/Makefile.in | 4 - tests/progs/Makefile.in | 4 - 10 files changed, 212 insertions(+), 85 deletions(-)
lib/ext2fs/ext2fsP.h +9 -4
@@ -82,21 +82,26 @@ struct dir_context {errcode_t errcode; }; +#include "support/list.h" +#include "support/cache.h" +/* * Inode cache structure */ struct ext2_inode_cache {void * buffer;blk64_t buffer_blk; -int cache_last; -unsigned int cache_size;int refcount; -struct ext2_inode_cache_ent *cache; +struct cache cache; };struct ext2_inode_cache_ent { +struct cache_node node;ext2_ino_t ino; -struct ext2_inode *inode; +uint8_t access; + +/* bytes representing a host-endian ext2_inode_large object */ +char raw[]; };/*
debugfs/Makefile.in +4 -4
@@ -38,15 +38,15 @@ SRCS= debug_cmds.c $(srcdir)/debugfs.c $(srcdir)/util.c $(srcdir)/ls.c \ $(srcdir)/../e2fsck/recovery.c $(srcdir)/do_journal.c \ $(srcdir)/do_orphan.c -LIBS= $(LIBSUPPORT) $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \ +LIBS= $(LIBEXT2FS) $(LIBSUPPORT) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \ $(LIBUUID) $(LIBMAGIC) $(SYSLIBS) $(LIBARCHIVE) -DEPLIBS= $(DEPLIBSUPPORT) $(LIBEXT2FS) $(LIBE2P) $(DEPLIBSS) $(DEPLIBCOM_ERR) \ +DEPLIBS= $(LIBEXT2FS) $(DEPLIBSUPPORT) $(LIBE2P) $(DEPLIBSS) $(DEPLIBCOM_ERR) \ $(DEPLIBBLKID) $(DEPLIBUUID) -STATIC_LIBS= $(STATIC_LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBSS) \ +STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBSS) \ $(STATIC_LIBCOM_ERR) $(STATIC_LIBBLKID) $(STATIC_LIBUUID) \ $(STATIC_LIBE2P) $(LIBMAGIC) $(SYSLIBS) -STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSS) \ +STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) $(DEPSTATIC_LIBSS) \ $(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBUUID) \ $(DEPSTATIC_LIBE2P)
e2fsck/Makefile.in +6 -6
@@ -16,22 +16,22 @@ PROGS= e2fsck MANPAGES= e2fsck.8 FMANPAGES= e2fsck.conf.5 -LIBS= $(LIBSUPPORT) $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBBLKID) $(LIBUUID) \ +LIBS= $(LIBEXT2FS) $(LIBSUPPORT) $(LIBCOM_ERR) $(LIBBLKID) $(LIBUUID) \ $(LIBINTL) $(LIBE2P) $(LIBMAGIC) $(SYSLIBS) -DEPLIBS= $(DEPLIBSUPPORT) $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBBLKID) \ +DEPLIBS= $(LIBEXT2FS) $(DEPLIBSUPPORT) $(DEPLIBCOM_ERR) $(DEPLIBBLKID) \ $(DEPLIBUUID) $(DEPLIBE2P) -STATIC_LIBS= $(STATIC_LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \ +STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) \ $(STATIC_LIBBLKID) $(STATIC_LIBUUID) $(LIBINTL) $(STATIC_LIBE2P) \ $(LIBMAGIC) $(SYSLIBS) -STATIC_DEPLIBS= $(DEPSTATIC_LIBSUPPORT) $(STATIC_LIBEXT2FS) \ +STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) \ $(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBBLKID) \ $(DEPSTATIC_LIBUUID) $(DEPSTATIC_LIBE2P) -PROFILED_LIBS= $(PROFILED_LIBSUPPORT) $(PROFILED_LIBEXT2FS) \ +PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBSUPPORT) \ $(PROFILED_LIBCOM_ERR) $(PROFILED_LIBBLKID) $(PROFILED_LIBUUID) \ $(PROFILED_LIBE2P) $(LIBINTL) $(LIBMAGIC) $(SYSLIBS) -PROFILED_DEPLIBS= $(DEPPROFILED_LIBSUPPORT) $(PROFILED_LIBEXT2FS) \ +PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBSUPPORT) \ $(DEPPROFILED_LIBCOM_ERR) $(DEPPROFILED_LIBBLKID) \ $(DEPPROFILED_LIBUUID) $(DEPPROFILED_LIBE2P)
fuse4fs/Makefile.in +4 -4
@@ -30,11 +30,11 @@ SRCS=\ LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT) DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBSUPPORT) -PROFILED_LIBS= $(LIBSUPPORT) $(PROFILED_LIBEXT2FS) $(PROFILED_LIBCOM_ERR) -PROFILED_DEPLIBS= $(DEPLIBSUPPORT) $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBCOM_ERR) +PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBSUPPORT) $(PROFILED_LIBCOM_ERR) +PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBSUPPORT) $(DEPPROFILED_LIBCOM_ERR) -STATIC_LIBS= $(LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) -STATIC_DEPLIBS= $(DEPLIBSUPPORT) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) +STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR) LIBS_E2P= $(LIBE2P) $(LIBCOM_ERR) DEPLIBS_E2P= $(LIBE2P) $(DEPLIBCOM_ERR)
lib/ext2fs/Makefile.in +8 -6
@@ -246,7 +246,7 @@ ELF_SO_VERSION = 2 ELF_IMAGE = libext2fs ELF_MYDIR = ext2fs ELF_INSTALL_DIR = $(root_libdir) -ELF_OTHER_LIBS = -lcom_err +ELF_OTHER_LIBS = -lcom_err $(top_builddir)/../lib/libsupport.a BSDLIB_VERSION = 2.1 BSDLIB_IMAGE = libext2fs
@@ -503,8 +503,8 @@ tst_extents: $(srcdir)/extent.c $(DEBUG_OBJS) $(DEPSTATIC_LIBSS) libext2fs.a \ $(E) " LD $@" $(Q) $(CC) -o tst_extents $(srcdir)/extent.c \ $(ALL_CFLAGS) $(ALL_LDFLAGS) -DDEBUG $(DEBUG_OBJS) \ - $(STATIC_LIBSS) $(STATIC_LIBE2P) $(LIBSUPPORT) \ - $(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) \ + $(STATIC_LIBSS) $(STATIC_LIBE2P) \ + $(STATIC_LIBEXT2FS) $(LIBSUPPORT) $(LIBBLKID) $(LIBUUID) \ $(STATIC_LIBCOM_ERR) $(SYSLIBS) -I $(top_srcdir)/debugfs tst_libext2fs: $(DEBUG_OBJS) \
@@ -512,8 +512,8 @@ tst_libext2fs: $(DEBUG_OBJS) \ $(DEPLIBBLKID) $(DEPSTATIC_LIBCOM_ERR) $(DEPLIBSUPPORT) $(E) " LD $@" $(Q) $(CC) -o tst_libext2fs $(ALL_LDFLAGS) -DDEBUG $(DEBUG_OBJS) \ - $(STATIC_LIBSS) $(STATIC_LIBE2P) $(LIBSUPPORT) \ - $(STATIC_LIBEXT2FS) $(LIBBLKID) $(LIBUUID) $(LIBMAGIC) \ + $(STATIC_LIBSS) $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) \ + $(LIBSUPPORT) $(LIBBLKID) $(LIBUUID) $(LIBMAGIC) \ $(STATIC_LIBCOM_ERR) $(SYSLIBS) $(LIBARCHIVE) -I $(top_srcdir)/debugfs tst_inline: $(srcdir)/inline.c $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
@@ -976,7 +976,9 @@ inode.o: $(srcdir)/inode.c $(top_builddir)/lib/config.h \ $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \ $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \ - $(srcdir)/hashmap.h $(srcdir)/bitops.h $(srcdir)/e2image.h + $(srcdir)/hashmap.h $(srcdir)/bitops.h $(srcdir)/e2image.h \ + $(srcdir)/../support/cache.h $(srcdir)/../support/list.h \ + $(srcdir)/../support/xbitops.h inode_io.o: $(srcdir)/inode_io.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
lib/ext2fs/inode.c +167 -48
302 lines not on this page · raw message
misc/Makefile.in +4 -4
@@ -115,11 +115,11 @@ SRCS= $(srcdir)/tune2fs.c $(srcdir)/mklost+found.c $(srcdir)/mke2fs.c $(srcdir)/ LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT) DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBSUPPORT) -PROFILED_LIBS= $(LIBSUPPORT) $(PROFILED_LIBEXT2FS) $(PROFILED_LIBCOM_ERR) -PROFILED_DEPLIBS= $(DEPLIBSUPPORT) $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBCOM_ERR) +PROFILED_LIBS= $(PROFILED_LIBEXT2FS) $(PROFILED_LIBSUPPORT) $(PROFILED_LIBCOM_ERR) +PROFILED_DEPLIBS= $(PROFILED_LIBEXT2FS) $(DEPPROFILED_LIBSUPPORT) $(DEPPROFILED_LIBCOM_ERR) -STATIC_LIBS= $(LIBSUPPORT) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) -STATIC_DEPLIBS= $(DEPLIBSUPPORT) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) $(STATIC_LIBCOM_ERR) +STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) $(DEPSTATIC_LIBCOM_ERR) LIBS_E2P= $(LIBE2P) $(LIBCOM_ERR) DEPLIBS_E2P= $(LIBE2P) $(DEPLIBCOM_ERR)
resize/Makefile.in +6 -5
@@ -28,12 +28,13 @@ SRCS= $(srcdir)/extent.c \ $(srcdir)/resource_track.c \ $(srcdir)/sim_progress.c -LIBS= $(LIBE2P) $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBINTL) $(SYSLIBS) -DEPLIBS= $(LIBE2P) $(LIBEXT2FS) $(DEPLIBCOM_ERR) +LIBS= $(LIBE2P) $(LIBEXT2FS) $(LIBSUPPORT) $(LIBCOM_ERR) $(LIBINTL) $(SYSLIBS) +DEPLIBS= $(LIBE2P) $(LIBEXT2FS) $(DEPLIBSUPPORT) $(DEPLIBCOM_ERR) -STATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \ - $(LIBINTL) $(SYSLIBS) -DEPSTATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) +STATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \ + $(STATIC_LIBCOM_ERR) $(LIBINTL) $(SYSLIBS) +DEPSTATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) \ + $(DEPSTATIC_LIBCOM_ERR) .c.o: $(E) " CC $<"
tests/fuzz/Makefile.in +2 -2
@@ -24,9 +24,9 @@ LOCAL_LDFLAGS= @fuzzer_ldflags@ LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBSUPPORT) DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) $(DEPLIBSUPPORT) -STATIC_LIBS= $(LIBSUPPORT) $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) \ +STATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBSUPPORT) \ $(STATIC_LIBCOM_ERR) -STATIC_DEPLIBS= $(DEPLIBSUPPORT) $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) \ +STATIC_DEPLIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSUPPORT) \ $(DEPSTATIC_LIBCOM_ERR) FUZZ_LDFLAGS= $(ALL_LDFLAGS)
tests/progs/Makefile.in +2 -2
@@ -23,8 +23,8 @@ TEST_ICOUNT_OBJS= test_icount.o test_icount_cmds.o SRCS= $(srcdir)/test_icount.c \ $(srcdir)/test_rel.c -LIBS= $(LIBEXT2FS) $(LIBSS) $(LIBCOM_ERR) $(SYSLIBS) -DEPLIBS= $(LIBEXT2FS) $(DEPLIBSS) $(DEPLIBCOM_ERR) +LIBS= $(LIBEXT2FS) $(LIBSUPPORT) $(LIBSS) $(LIBCOM_ERR) $(SYSLIBS) +DEPLIBS= $(LIBEXT2FS) $(DEPLIBSUPPORT) $(DEPLIBSS) $(DEPLIBCOM_ERR) .c.o: $(E) " CC $<"
PATCH v6 6/6 fuse4fs: run servers as a contained service
In reply to Darrick J. WongHi all,
In this final series of the fuse-iomap prototype, we package the newly created fuse4fs server into a systemd socket service. This service can be used by the "mount.service" helper in libfuse to implement untrusted unprivileged mounts.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
Comments and questions are, as always, welcome.
e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse4fs-service-container
---
Commits in this patchset:
* libext2fs: fix MMP code to work with unixfd IO manager
* fuse4fs: enable safe service mode
* fuse4fs: set proc title when in fuse service mode
* fuse4fs: set iomap backing device blocksize
* fuse4fs: ask for loop devices when opening via fuservicemount
* fuse4fs: make MMP work correctly in safe service mode
* debian: update packaging for fuse4fs service
--- lib/ext2fs/ext2fs.h | 1 MCONFIG.in | 1 configure | 181 ++++++++++++++++++++ configure.ac | 69 ++++++++ debian/e2fsprogs.install | 7 + debian/fuse4fs.install | 3 debian/rules | 3 fuse4fs/Makefile.in | 42 ++++- fuse4fs/fuse4fs.c | 383 +++++++++++++++++++++++++++++++++++++++++-- fuse4fs/fuse4fs.socket.in | 17 ++ fuse4fs/[email protected] | 95 +++++++++++ lib/config.h.in | 6 + lib/ext2fs/mmp.c | 82 +++++++++ util/subst.conf.in | 2 14 files changed, 867 insertions(+), 25 deletions(-) mode change 100644 => 100755 debian/fuse4fs.install create mode 100644 fuse4fs/fuse4fs.socket.in create mode 100644 fuse4fs/[email protected]
PATCH 1/7 libext2fs: fix MMP code to work with unixfd IO manager
From: Darrick J. Wong <[email protected]>
The MMP code wants to be able to read and write the MMP block directly to storage so that the pagecache does not get in the way. This is critical for correct operation of MMP, because it is guarding against two cluster nodes trying to change the filesystem at the same time.
Unfortunately there's no convenient way to tell an IO manager to perform a particular IO in directio mode, so the MMP code open()s the filesystem source device a second time so that it can set O_DIRECT and maintain its own file position independently of the IO channel. This is a gross layering violation.
For unprivileged containerized fuse4fs, we're going to have a privileged mount helper pass us the fd to the block device, so we'll be using the unixfd IO manager. Unfortunately, if the unixfd IO manager is in use, the filesystem "source" will be a string representation of the fd number, and MMP breaks.
Fix this (sort of) by detecting the unixfd IO manager and duplicating the open fd if it's in use. This adds a requirement that the unixfd originally be opened in O_DIRECT mode if the filesystem is on a block device, but that's the best we can do here.
--- lib/ext2fs/ext2fs.h | 1 + lib/ext2fs/mmp.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-)
lib/ext2fs/ext2fs.h +1 -0
@@ -229,6 +229,7 @@ typedef struct ext2_file *ext2_file_t;* Internal flags for use by the ext2fs library only */ #define EXT2_FLAG2_USE_FAKE_TIME 0x000000001 +#define EXT2_FLAG2_MMP_USE_IOCHANNEL 0x000000002/* * Special flag in the ext2 inode i_flag field that means that this is
lib/ext2fs/mmp.c +81 -1
118 lines not on this page · raw message
PATCH 2/7 fuse4fs: enable safe service mode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make it possible to run fuse4fs as a safe systemd service, wherein the fuse server only has access to the fds that we pass in.
--- MCONFIG.in | 1 configure | 133 +++++++++++++++++++++ configure.ac | 45 +++++++ fuse4fs/Makefile.in | 40 ++++++ fuse4fs/fuse4fs.c | 276 ++++++++++++++++++++++++++++++++++++++++++- fuse4fs/fuse4fs.socket.in | 17 +++ fuse4fs/[email protected] | 95 +++++++++++++++ lib/config.h.in | 3 util/subst.conf.in | 2 9 files changed, 600 insertions(+), 12 deletions(-) create mode 100644 fuse4fs/fuse4fs.socket.in create mode 100644 fuse4fs/[email protected]
MCONFIG.in +1 -0
@@ -42,6 +42,7 @@ HAVE_CROND = @have_crond@ CROND_DIR = @crond_dir@ HAVE_SYSTEMD = @have_systemd@ SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@ +HAVE_FUSE_SERVICE = @have_fuse_service@ @SET_MAKE@
configure +133 -0
157 lines not on this page · raw message
configure.ac +45 -0
51 lines not on this page · raw message
fuse4fs/Makefile.in +36 -4
@@ -17,6 +17,13 @@ UMANPAGES= @FUSE4FS_CMT@UPROGS+=fuse4fs @FUSE4FS_CMT@UMANPAGES+=fuse4fs.1 +ifeq ($(HAVE_SYSTEMD),yes) +SERVICE_FILES += fuse4fs.socket [email protected] +INSTALLDIRS_TGT += installdirs-systemd +INSTALL_TGT += install-systemd +UNINSTALL_TGT += uninstall-systemd +endif + FUSE4FS_OBJS= fuse4fs.o journal.o recovery.o revoke.o PROFILED_FUSE4FS_OJBS= profiled/fuse4fs.o profiled/journal.o \
@@ -54,7 +61,7 @@ DEPEND_CFLAGS = -I$(top_srcdir)/e2fsck @PROFILE_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -g -pg -o profiled/$*.o -c $< all:: profiled $(SPROGS) $(UPROGS) $(USPROGS) $(SMANPAGES) $(UMANPAGES) \ - $(FMANPAGES) $(LPROGS) + $(FMANPAGES) $(LPROGS) $(SERVICE_FILES) all-static::
@@ -71,6 +78,14 @@ fuse4fs: $(FUSE4FS_OBJS) $(DEPLIBS) $(DEPLIBBLKID) $(DEPLIBUUID) \ $(LIBFUSE) $(LIBBLKID) $(LIBUUID) $(LIBEXT2FS) $(LIBINTL) \ $(CLOCK_GETTIME_LIB) $(SYSLIBS) $(LIBS_E2P) +%.socket: %.socket.in $(DEP_SUBSTITUTE) + $(E) " SUBST $@" + $(Q) $(SUBSTITUTE_UPTIME) $< $@ + +%.service: %.service.in $(DEP_SUBSTITUTE) + $(E) " SUBST $@" + $(Q) $(SUBSTITUTE_UPTIME) $< $@ + journal.o: $(srcdir)/../debugfs/journal.c $(E) " CC $<" $(Q) $(CC) -c $(JOURNAL_CFLAGS) -I$(srcdir) \
@@ -93,11 +108,15 @@ fuse4fs.1: $(DEP_SUBSTITUTE) $(srcdir)/fuse4fs.1.in $(E) " SUBST $@" $(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/fuse4fs.1.in fuse4fs.1 -installdirs: +installdirs: $(INSTALLDIRS_TGT) $(E) " MKDIR_P $(bindir) $(man1dir)" $(Q) $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir) -install: all $(UMANPAGES) installdirs +installdirs-systemd: + $(E) " MKDIR_P $(SYSTEMD_SYSTEM_UNIT_DIR)" + $(Q) $(MKDIR_P) $(DESTDIR)$(SYSTEMD_SYSTEM_UNIT_DIR) + +install: all $(UMANPAGES) installdirs $(INSTALL_TGT) $(Q) for i in $(UPROGS); do \ $(ES) " INSTALL $(bindir)/$$i"; \ $(INSTALL_PROGRAM) $$i $(DESTDIR)$(bindir)/$$i; \
@@ -110,13 +129,19 @@ install: all $(UMANPAGES) installdirs $(INSTALL_DATA) $$i $(DESTDIR)$(man1dir)/$$i; \ done +install-systemd: $(SERVICE_FILES) installdirs-systemd + $(Q) for i in $(SERVICE_FILES); do \ + $(ES) " INSTALL_DATA $(SYSTEMD_SYSTEM_UNIT_DIR)/$$i"; \ + $(INSTALL_DATA) $$i $(DESTDIR)$(SYSTEMD_SYSTEM_UNIT_DIR)/$$i; \ + done + install-strip: install $(Q) for i in $(UPROGS); do \ $(E) " STRIP $(bindir)/$$i"; \ $(STRIP) $(DESTDIR)$(bindir)/$$i; \ done -uninstall: +uninstall: $(UNINSTALL_TGT) for i in $(UPROGS); do \ $(RM) -f $(DESTDIR)$(bindir)/$$i; \ done
@@ -124,9 +149,16 @@ uninstall: $(RM) -f $(DESTDIR)$(man1dir)/$$i; \ done +uninstall-systemd: + for i in $(SERVICE_FILES); do \ + $(RM) -f $(DESTDIR)$(SYSTEMD_SYSTEM_UNIT_DIR)/$$i; \ + done + clean:: $(RM) -f $(UPROGS) $(UMANPAGES) profile.h \ fuse4fs.profiled \ + $(SERVICE_FILES) \ + fuse4fs.socket \ profiled/*.o \#* *.s *.o *.a *~ core gmon.out mostlyclean: clean
fuse4fs/fuse4fs.c +268 -8
391 lines not on this page · raw message
fuse4fs/fuse4fs.socket.in new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2025 Oracle. All Rights Reserved. +# Author: Darrick J. Wong <[email protected]> +[Unit] +Description=Socket for ext4 Service + +[Socket] +ListenSequentialPacket=@fuse_service_socket_dir@/ext2 +ListenSequentialPacket=@fuse_service_socket_dir@/ext3 +ListenSequentialPacket=@fuse_service_socket_dir@/ext4 +Accept=yes +SocketMode=0660 +RemoveOnStop=yes + +[Install] +WantedBy=sockets.target
fuse4fs/[email protected] new file +95 -0
95 lines not on this page · raw message
lib/config.h.in +3 -0
@@ -82,6 +82,9 @@ /* Define to 1 if fuse supports loopdev operations */ #undef HAVE_FUSE_LOOPDEV +/* Define to 1 if fuse supports service */ +#undef HAVE_FUSE_SERVICE + /* Define to 1 if you have the Mac OS X function CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */ #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
util/subst.conf.in +2 -0
@@ -24,3 +24,5 @@ root_bindir @root_bindir@ libdir @libdir@ $exec_prefix @exec_prefix@ pkglibexecdir @libexecdir@/e2fsprogs +bindir @bindir@ +fuse_service_socket_dir @fuse_service_socket_dir@
PATCH 3/7 fuse4fs: set proc title when in fuse service mode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When in fuse service mode, set the proc title so that we can identify fuse servers by mount arguments.
--- configure | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 24 ++++++++++++++++++++++++ fuse4fs/Makefile.in | 2 +- fuse4fs/fuse4fs.c | 23 ++++++++++++++++++++++- lib/config.h.in | 3 +++ 5 files changed, 98 insertions(+), 2 deletions(-)
configure +48 -0
@@ -701,6 +701,7 @@ gcc_ranlib gcc_ar UNI_DIFF_OPTS SEM_INIT_LIB +LIBBSD_LIB FUSE4FS_CMT FUSE2FS_CMT fuse_service_socket_dir
@@ -14639,6 +14640,53 @@ fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for setproctitle in -lbsd" >&5 +printf %s "checking for setproctitle in -lbsd... " >&6; } +if test ${ac_cv_lib_bsd_setproctitle+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_check_lib_save_LIBS=$LIBS +LIBS="-lbsd $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +char setproctitle (); +int +main (void) +{ +return setproctitle (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_lib_bsd_setproctitle=yes +else $as_nop + ac_cv_lib_bsd_setproctitle=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_setproctitle" >&5 +printf "%s\n" "$ac_cv_lib_bsd_setproctitle" >&6; } +if test "x$ac_cv_lib_bsd_setproctitle" = xyes +then : + LIBBSD_LIB=-lbsd +fi + + +if test "$ac_cv_lib_bsd_setproctitle" = yes ; then + printf "%s\n" "#define HAVE_SETPROCTITLE 1" >>confdefs.h + +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for PR_SET_IO_FLUSHER" >&5 printf %s "checking for PR_SET_IO_FLUSHER... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext
configure.ac +24 -0
@@ -1597,6 +1597,30 @@ AS_HELP_STRING([--disable-fuse4fs],[do not build fuse4fs]), ) AC_SUBST(FUSE4FS_CMT) +dnl +dnl see if setproctitle exists +dnl +AC_CHECK_LIB(bsd, setproctitle, [LIBBSD_LIB=-lbsd]) +AC_SUBST(LIBBSD_LIB) +if test "$ac_cv_lib_bsd_setproctitle" = yes ; then + AC_DEFINE(HAVE_SETPROCTITLE, 1, Define to 1 if setproctitle]) +fi + +dnl AC_LINK_IFELSE( +dnl [ AC_LANG_PROGRAM([[ +dnl #define _GNU_SOURCE +dnl #include <bsd/unistd.h> +dnl ]], [[ +dnl setproctitle_init(argc, argv, environ); +dnl setproctitle("-What sourcery is this???"); +dnl ]]) +dnl ], have_setproctitle=yes +dnl AC_MSG_RESULT(yes), +dnl AC_MSG_RESULT(no)) +dnl if test "$setproctitle" = yes; then +dnl AC_DEFINE(HAVE_SETPROCTITLE, 1, [Define to 1 if setproctitle exists]) +dnl fi + dnl dnl see if PR_SET_IO_FLUSHER exists dnl
fuse4fs/Makefile.in +1 -1
@@ -76,7 +76,7 @@ fuse4fs: $(FUSE4FS_OBJS) $(DEPLIBS) $(DEPLIBBLKID) $(DEPLIBUUID) \ $(E) " LD $@" $(Q) $(CC) $(ALL_LDFLAGS) -o fuse4fs $(FUSE4FS_OBJS) $(LIBS) \ $(LIBFUSE) $(LIBBLKID) $(LIBUUID) $(LIBEXT2FS) $(LIBINTL) \ - $(CLOCK_GETTIME_LIB) $(SYSLIBS) $(LIBS_E2P) + $(CLOCK_GETTIME_LIB) $(SYSLIBS) $(LIBS_E2P) @LIBBSD_LIB@ %.socket: %.socket.in $(DEP_SUBSTITUTE) $(E) " SUBST $@"
fuse4fs/fuse4fs.c +22 -1
@@ -49,6 +49,9 @@#ifdef HAVE_FUSE_SERVICE # include <sys/mount.h> # include <fuse_service.h> +# ifdef HAVE_SETPROCTITLE +# include <bsd/unistd.h> +# endif #endif #ifdef __SET_FOB_FOR_FUSE# undef _FILE_OFFSET_BITS
@@ -1444,10 +1447,24 @@ static int fuse4fs_service_connect(struct fuse4fs *ff, struct fuse_args *args)if (fuse4fs_is_service (ff))fuse_service_append_args (ff->service, args); -return 0 ; } +static void fuse4fs_service_set_proc_cmdline (struct fuse4fs *ff,int argc, +char *argv[], +struct fuse_args *args) +{ +char *cmdline; + +setproctitle_init (argc, argv, environ); + cmdline =fuse_service_cmdline (argc, argv, args); +if (!cmdline) +return ; + +setproctitle ("-%s" , cmdline); +free (cmdline); +} +static inline int fuse4fs_service_parse_cmdline (struct fuse_args *args,struct fuse_cmdline_opts *opts)
@@ -1593,6 +1610,7 @@ static int fuse4fs_service(struct fuse4fs *ff, struct fuse_session *se, }#else # define fuse4fs_service_connect (...) (0) +# define fuse4fs_service_set_proc_cmdline (...) ((void)0)# define fuse4fs_service_parse_cmdline (...) (EOPNOTSUPP)# define fuse4fs_service_release (...) ((void)0)# define fuse4fs_service_close_bdev (...) ((void)0)
@@ -8387,6 +8405,9 @@ int main(int argc, char *argv[])exit (1 ); } +if (fuse4fs_is_service (&fctx)) +fuse4fs_service_set_proc_cmdline (&fctx, argc, argv, &args); + ret =fuse_opt_parse (&args, &fctx, fuse4fs_opts, fuse4fs_opt_proc);if (ret)exit (1 );
lib/config.h.in +3 -0
@@ -361,6 +361,9 @@ /* Define to 1 if you have the `setmntent' function. */ #undef HAVE_SETMNTENT +/* Define to 1 if setproctitle */ +#undef HAVE_SETPROCTITLE + /* Define to 1 if you have the `setresgid' function. */ #undef HAVE_SETRESGID
PATCH 4/7 fuse4fs: set iomap backing device blocksize
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If we're running as an unprivileged iomap fuse server, we must ask the kernel to set the blocksize of the block device.
--- fuse4fs/fuse4fs.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)
fuse4fs/fuse4fs.c +31 -10
@@ -1608,6 +1608,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_service_connect (...) (0)# define fuse4fs_service_set_proc_cmdline (...) ((void)0)
@@ -1619,6 +1634,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)
@@ -7355,21 +7371,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",
@@ -7377,7 +7391,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 ; }
PATCH 5/7 fuse4fs: ask for loop devices when opening via fuservicemount
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When requesting a file, ask the fuservicemount program to transform an open regular file into a loop device for us, so that we can use iomap even when the filesystem is actually an image file.
--- fuse4fs/fuse4fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fuse4fs/fuse4fs.c +2 -1
@@ -1523,7 +1523,8 @@ static int fuse4fs_service_get_config(struct fuse4fs *ff) do { ret = fuse_service_request_file(ff->service, ff->device, - open_flags, 0, 0); + open_flags, 0, + FUSE_SERVICE_REQUEST_FILE_TRYLOOP); if (ret) return ret;
PATCH 6/7 fuse4fs: make MMP work correctly in safe service mode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Normally, the libext2fs MMP code open()s a complete separate file descriptor to read and write the MMP block so that it can have its own private open file with its own access mode and file position. However, if the unixfd IO manager is in use, it will reuse the io channel, which means that MMP and the unixfd share the same open file and hence the access mode and file position.
MMP requires directio access to block devices so that changes are immediately visible on other nodes. Therefore, we need the IO channel (and thus the filesystem) to be running in directio mode if MMP is in use.
To make this work correctly with the sole unixfd IO manager user (fuse4fs in unprivileged service mode), we must set O_DIRECT on the bdev fd and mount the filesystem in directio mode.
--- fuse4fs/fuse4fs.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-)
fuse4fs/fuse4fs.c +47 -3
@@ -1559,13 +1559,57 @@ static int fuse4fs_service_get_config(struct fuse4fs *ff) }static errcode_t fuse4fs_service_openfs (struct fuse4fs *ff,char *options, -int flags) +int *flags) { +struct stat statbuf;char path[32 ]; +errcode_t retval; +int ret; + + ret =fstat (ff->bdev_fd, &statbuf); +if (ret) +return errno;snprintf (path,sizeof (path),"%d" , ff->bdev_fd);iocache_set_backing_manager (unixfd_io_manager); -return ext2fs_open2 (path, options, flags,0 ,0 , iocache_io_manager, + +/* +* Open the filesystem with SKIP_MMP so that we can find out if the +* filesystem actually has MMP. +*/ + retval =ext2fs_open2 (path, options, *flags |EXT2_FLAG_SKIP_MMP ,0 ,0 , + iocache_io_manager, &ff->fs); +if (retval) +return retval; + +/* +* If the fs doesn't have MMP then we're good to go. Otherwise close +* the filesystem so that we can reopen it with MMP enabled. +*/ +if (!ext2fs_has_feature_mmp (ff->fs->super)) +return 0 ; + + retval =ext2fs_close_free (&ff->fs); +if (retval) +return retval; + +/* +* If the filesystem is not on a regular file, MMP will share the same +* fd as the unixfd IO channel. We need to set O_DIRECT on the bdev_fd +* and open the filesystem in directio mode. +*/ +if (!S_ISREG (statbuf.st_mode)) { +int fflags =fcntl (ff->bdev_fd,F_GETFL ); + + ret =fcntl (ff->bdev_fd,F_SETFL , fflags |O_DIRECT ); +if (ret) +return EXT2_ET_MMP_OPEN_DIRECT ; + + ff->directio =1 ; + *flags |=EXT2_FLAG_DIRECT_IO ; + } + +return ext2fs_open2 (path, options, *flags,0 ,0 , iocache_io_manager, &ff->fs); }
@@ -1846,7 +1890,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff) deadline =init_deadline (FUSE4FS_OPEN_TIMEOUT ); do { if (fuse4fs_is_service(ff)) - err = fuse4fs_service_openfs(ff, options, flags); + err = fuse4fs_service_openfs(ff, options, &flags); else err = ext2fs_open2(fuse4fs_device(ff), options, flags, 0, 0, iocache_io_manager, &ff->fs);
PATCH 7/7 debian: update packaging for fuse4fs service
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Update the Debian packaging code so that we can create fuse4fs service containers.
--- debian/e2fsprogs.install | 7 ++++++- debian/fuse4fs.install | 3 +++ debian/rules | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) mode change 100644 => 100755 debian/fuse4fs.install
debian/e2fsprogs.install +6 -1
@@ -50,4 +50,9 @@ usr/share/man/man8/resize2fs.8 usr/share/man/man8/tune2fs.8 etc [linux-any] ${deb_udevudevdir}/rules.d -[linux-any] ${deb_systemdsystemunitdir} +[linux-any] ${deb_systemdsystemunitdir}/[email protected] +[linux-any] ${deb_systemdsystemunitdir}/[email protected] +[linux-any] ${deb_systemdsystemunitdir}/e2scrub_all.service +[linux-any] ${deb_systemdsystemunitdir}/e2scrub_all.timer +[linux-any] ${deb_systemdsystemunitdir}/[email protected] +[linux-any] ${deb_systemdsystemunitdir}/e2scrub_reap.service
debian/fuse4fs.install +3 -0
@@ -1,2 +1,5 @@ +#!/usr/bin/dh-exec usr/bin/fuse4fs usr/share/man/man1/fuse4fs.1 +[linux-any] ${deb_systemdsystemunitdir}/fuse4fs.socket +[linux-any] ${deb_systemdsystemunitdir}/[email protected]
debian/rules +3 -0
@@ -173,6 +173,9 @@ override_dh_installinfo: ifneq ($(DEB_HOST_ARCH_OS), hurd) override_dh_installsystemd: dh_installsystemd -p e2fsprogs --no-restart-after-upgrade --no-stop-on-upgrade e2scrub_all.timer e2scrub_reap.service +ifeq ($(SKIP_FUSE2FS),) + dh_installsystemd -p fuse4fs fuse4fs.socket +endif endif override_dh_makeshlibs:
PATCH v6 1/1 fstests: support ext4 fuse testing
In reply to Darrick J. WongHi all,
Various test adjustments to support testing the fuse ext4 server (fuse2fs) as if it were the kernel ext4 driver. This supports QAing the fuse-iomap prototype project.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=fuse2fs
---
Commits in this patchset:
* misc: adapt tests to handle the fuse ext[234] drivers
* generic/740: don't run this test for fuse ext* implementations
* ext/052: use popdir.pl for much faster directory creation
* common/rc: skip test if swapon doesn't work
* common/rc: streamline _scratch_remount
* ext/039: require metadata journalling
* populate: don't check for htree directories on fuse.ext4
* misc: convert _scratch_mount -o remount to _scratch_remount
* misc: use explicitly $FSTYP'd mount calls
* common/ext4: explicitly format with $FSTYP
* tests/ext*: refactor open-coded _scratch_mkfs_sized calls
* generic/732: disable for fuse.ext4
* defrag: fix ext4 defrag ioctl test
* misc: explicitly require online resize support
* ext4/004: disable for fuse2fs
* generic/679: disable for fuse2fs
* ext4/045: don't run the long dirent test on fuse2fs
* generic/338: skip test if we can't mount with strictatime
* generic/563: fuse doesn't support cgroup-aware writeback accounting
* misc: use a larger buffer size for pwrites
* ext4/046: don't run this test if dioread_nolock not supported
* generic/631: don't run test if we can't mount overlayfs
* generic/{409,410,411,589}: check for stacking mount support
* generic: add _require_hardlinks to tests that require hardlinks
* ext4/001: check for fiemap support
* generic/622: check that strictatime/lazytime actually work
* generic/050: skip test because fuse2fs doesn't have stable output
* generic/405: don't stall on mkfs asking for input
* ext4/006: fix this test
* ext4/009: fix ENOSPC errors
* ext4/022: enabl
* generic/730: adapt test for fuse filesystems
* fuse2fs: hack around weird corruption problems
---
check | 24 ++
common/casefold | 4
common/config | 11 +
common/defrag | 4
common/encrypt | 16 +-
common/ext4 | 20 ++
common/log | 10 +
common/populate | 15 +-
common/quota | 9 +
common/rc | 109 ++++++++---
common/report | 2
common/verity | 8 -
src/popdir.pl | 9 +
tests/btrfs/015 | 2
tests/btrfs/032 | 2
tests/btrfs/082 | 2
tests/btrfs/139 | 2
tests/btrfs/193 | 2
tests/btrfs/199 | 2
tests/btrfs/219 | 12 +
tests/btrfs/259 | 2
tests/ext4/001 | 1
tests/ext4/003 | 3
tests/ext4/004 | 2
tests/ext4/006 | 4
tests/ext4/009 | 11 +
tests/ext4/022 | 9 +
tests/ext4/022.cfg | 1
tests/ext4/022.out.default | 0
tests/ext4/022.out.fuse2fs | 432 ++++++++++++++++++++++++++++++++++++++++++++
tests/ext4/032 | 6 -
tests/ext4/033 | 7 +
tests/ext4/035 | 4
tests/ext4/039 | 1
tests/ext4/045 | 12 +
tests/ext4/046 | 8 -
tests/ext4/052 | 9 +
tests/ext4/053 | 2
tests/ext4/059 | 2
tests/ext4/060 | 2
tests/ext4/306 | 7 -
tests/f2fs/005 | 2
tests/generic/020 | 2
tests/generic/027 | 4
tests/generic/042 | 4
tests/generic/050 | 4
tests/generic/067 | 6 -
tests/generic/079 | 1
tests/generic/081 | 2
tests/generic/082 | 4
tests/generic/085 | 2
tests/generic/108 | 2
tests/generic/223 | 4
tests/generic/235 | 4
tests/generic/286 | 8 -
tests/generic/294 | 2
tests/generic/323 | 2
tests/generic/338 | 2
tests/generic/361 | 4
tests/generic/405 | 2
tests/generic/409 | 1
tests/generic/410 | 1
tests/generic/411 | 1
tests/generic/423 | 1
tests/generic/441 | 2
tests/generic/449 | 2
tests/generic/459 | 2
tests/generic/496 | 2
tests/generic/511 | 2
tests/generic/536 | 2
tests/generic/563 | 8 +
tests/generic/589 | 1
tests/generic/597 | 1
tests/generic/620 | 2
tests/generic/621 | 2
tests/generic/622 | 4
tests/generic/631 | 22 ++
tests/generic/648 | 4
tests/generic/679 | 2
tests/generic/704 | 2
tests/generic/730 | 15 +-
tests/generic/732 | 1
tests/generic/740 | 3
tests/generic/741 | 8 +
tests/generic/744 | 6 -
tests/generic/746 | 8 -
tests/generic/765 | 4
tests/xfs/014 | 4
tests/xfs/017 | 4
tests/xfs/049 | 2
tests/xfs/073 | 8 -
tests/xfs/074 | 4
tests/xfs/075 | 2
tests/xfs/078 | 2
tests/xfs/148 | 4
tests/xfs/149 | 4
tests/xfs/189 | 4
tests/xfs/196 | 2
tests/xfs/199 | 2
tests/xfs/206 | 2
tests/xfs/216 | 2
tests/xfs/217 | 2
tests/xfs/250 | 2
tests/xfs/289 | 2
tests/xfs/291 | 2
tests/xfs/423 | 4
tests/xfs/507 | 2
tests/xfs/513 | 2
tests/xfs/606 | 4
tests/xfs/609 | 2
tests/xfs/610 | 2
tests/xfs/613 | 2
tests/xfs/806 | 2
113 files changed, 828 insertions(+), 206 deletions(-)
create mode 100644 tests/ext4/022.cfg
rename tests/ext4/{022.out => 022.out.default} (100%)
create mode 100644 tests/ext4/022.out.fuse2fsPATCH 1/33 misc: adapt tests to handle the fuse ext[234] drivers
From: Darrick J. Wong <[email protected]>
It would be useful to be able to run fstests against the userspace ext[234] driver program fuse2fs. A convention (at least on Debian) seems to be to install fuse drivers as /sbin/mount.fuse.XXX so that users can run "mount -t fuse.XXX" to start a fuse driver for a disk-based filesystem type XXX.
Therefore, we'll adopt the practice of setting FSTYP=fuse.ext4 to test ext4 with fuse2fs. Change all the library code as needed to handle this new type alongside all the existing ext[234] checks, which seems a little cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4, which also would require even more treewide cleanups to work properly because most fstests code switches on $FSTYP alone.
--- check | 24 +++++++++++++++++------- common/casefold | 4 ++++ common/config | 11 ++++++++--- common/defrag | 2 +- common/encrypt | 16 ++++++++-------- common/log | 10 +++++----- common/populate | 14 +++++++------- common/quota | 9 +++++++++ common/rc | 50 +++++++++++++++++++++++++++++--------------------- common/report | 2 +- common/verity | 8 ++++---- tests/generic/020 | 2 +- tests/generic/067 | 2 +- tests/generic/441 | 2 +- tests/generic/496 | 2 +- tests/generic/621 | 2 +- tests/generic/740 | 2 +- tests/generic/746 | 4 ++-- tests/generic/765 | 4 ++-- 19 files changed, 103 insertions(+), 67 deletions(-)
check +17 -7
@@ -140,12 +140,25 @@ get_sub_group_list() echo $grpl } +get_group_dirs() +{ + local fsgroup="$FSTYP" + + case "$FSTYP" in + ext2|ext3|fuse.ext[234]) + fsgroup=ext4 + ;; + esac + + echo $SRC_GROUPS + echo $fsgroup +} + get_group_list() { local grp=$1 local grpl="" local sub=$(dirname $grp) - local fsgroup="$FSTYP" if [ -n "$sub" -a "$sub" != "." -a -d "$SRC_DIR/$sub" ]; then # group is given as <subdir>/<group> (e.g. xfs/quick)
@@ -154,10 +167,7 @@ get_group_list() return fi - if [ "$FSTYP" = ext2 -o "$FSTYP" = ext3 ]; then - fsgroup=ext4 - fi - for d in $SRC_GROUPS $fsgroup; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi
@@ -171,7 +181,7 @@ get_group_list() get_all_tests() { touch $tmp.list - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi
@@ -387,7 +397,7 @@ if [ -n "$FUZZ_REWRITE_DURATION" ]; then fi if [ -n "$subdir_xfile" ]; then - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do [ -f $SRC_DIR/$d/$subdir_xfile ] || continue for f in `sed "s/#.*$//" $SRC_DIR/$d/$subdir_xfile`; do exclude_tests+=($d/$f)
common/casefold +4 -0
@@ -6,6 +6,10 @@ _has_casefold_kernel_support() { case $FSTYP in + fuse.ext[234]) + # fuse2fs does not support casefolding + false + ;; ext4) test -f '/sys/fs/ext4/features/casefold' ;;
common/config +8 -3
@@ -386,6 +386,11 @@ _common_mount_opts() overlay) echo $OVERLAY_MOUNT_OPTIONS ;; + fuse.ext[234]) + # fuse sets up secure defaults, so we must explicitly tell + # fuse2fs to use the more relaxed kernel access behaviors. + echo "-o kernel $EXT_MOUNT_OPTIONS" + ;; ext2|ext3|ext4) # acls & xattrs aren't turned on by default on ext$FOO echo "-o acl,user_xattr $EXT_MOUNT_OPTIONS"
@@ -472,7 +477,7 @@ _mkfs_opts() _fsck_opts() { case $FSTYP in - ext2|ext3|ext4) + ext2|ext3|fuse.ext[234]|ext4) export FSCK_OPTIONS="-nf" ;; reiser*)
@@ -514,11 +519,11 @@ _source_specific_fs() . ./common/btrfs ;; - ext4) + fuse.ext4|ext4) [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found" . ./common/ext4 ;; - ext2|ext3) + ext2|ext3|fuse.ext[23]) . ./common/ext4 ;; f2fs)
common/defrag +1 -1
@@ -12,7 +12,7 @@ _require_defrag() _require_xfs_io_command "falloc" DEFRAG_PROG="$XFS_FSR_PROG" ;; - ext4) + fuse.ext4|ext4) testfile="$TEST_DIR/$$-test.defrag" donorfile="$TEST_DIR/$$-donor.defrag" bsize=`_get_block_size $TEST_DIR`
common/encrypt +8 -8
@@ -191,7 +191,7 @@ _require_hw_wrapped_key_support() _scratch_mkfs_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) _scratch_mkfs -O encrypt ;; ubifs)
@@ -210,7 +210,7 @@ _scratch_mkfs_encrypted() _scratch_mkfs_sized_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) MKFS_OPTIONS="$MKFS_OPTIONS -O encrypt" _scratch_mkfs_sized $* ;; *)
@@ -225,7 +225,7 @@ _scratch_mkfs_sized_encrypted() _scratch_mkfs_stable_inodes_encrypted() { case $FSTYP in - ext4) + fuse.ext4|ext4) if ! _scratch_mkfs -O encrypt -O stable_inodes; then _notrun "-O stable_inodes is not supported" fi
@@ -330,7 +330,7 @@ _num_to_hex() _get_fs_keyprefix() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) echo $FSTYP ;; *)
@@ -557,7 +557,7 @@ _get_encryption_nonce() local inode=$2 case $FSTYP in - ext4) + fuse.ext4|ext4) # Use debugfs to dump the special xattr named "c", which is the # file's fscrypt_context. This produces a line like: #
@@ -605,7 +605,7 @@ _require_get_encryption_nonce_support() { echo "Checking for _get_encryption_nonce() support for $FSTYP" >> $seqres.full case $FSTYP in - ext4) + fuse.ext4|ext4) _require_command "$DEBUGFS_PROG" debugfs ;; f2fs)
@@ -631,7 +631,7 @@ _get_ciphertext_filename() local dir_inode=$3 case $FSTYP in - ext4) + fuse.ext4|ext4) # Extract the filename from the debugfs output line like: # # 131075 100644 (1) 0 0 0 22-Apr-2019 16:54 \xa2\x85\xb0z\x13\xe9\x09\x86R\xed\xdc\xce\xad\x14d\x19
@@ -685,7 +685,7 @@ _require_get_ciphertext_filename_support() { echo "Checking for _get_ciphertext_filename() support for $FSTYP" >> $seqres.full case $FSTYP in - ext4) + fuse.ext4|ext4) # Verify that the "ls -l -r" debugfs command is supported and # that it hex-encodes non-ASCII characters, rather than using an # ambiguous escaping method. This requires e2fsprogs v1.45.1 or
common/log +5 -5
@@ -228,7 +228,7 @@ _scratch_dump_log() f2fs) $DUMP_F2FS_PROG $SCRATCH_DEV ;; - ext4) + fuse.ext[34]|ext[34]) $DEBUGFS_PROG -R "logdump -a" $SCRATCH_DEV ;; *)
@@ -245,7 +245,7 @@ _test_dump_log() f2fs) $DUMP_F2FS_PROG $TEST_DEV ;; - ext4) + fuse.ext[34]|ext[34]) $DEBUGFS_PROG -R "logdump -a" $TEST_DEV ;; *)
@@ -262,7 +262,7 @@ _print_logstate() f2fs) dirty=$(_scratch_f2fs_logstate) ;; - ext4) + fuse.ext[34]|ext[34]) dirty=$(_scratch_ext4_logstate) ;; *)
@@ -531,7 +531,7 @@ _require_logstate() _notrun "This test requires dump.f2fs utility." fi ;; - ext4) + fuse.ext[34]|ext[34]) if [ -z "$DUMPE2FS_PROG" ]; then _notrun "This test requires dumpe2fs utility." fi
@@ -599,7 +599,7 @@ _get_log_configs() f2fs) _f2fs_log_config ;; - ext4) + fuse.ext[34]|ext[34]) _ext4_log_config ;; *)
common/populate +7 -7
@@ -21,7 +21,7 @@ _require_populate_commands() { _require_command "$WIPEFS_PROG" "wipefs" _require_scratch_xfs_mdrestore ;; - ext*) + fuse.ext[234]|ext[234]) _require_command "$DUMPE2FS_PROG" "dumpe2fs" _require_command "$E2IMAGE_PROG" "e2image" ;;
@@ -61,7 +61,7 @@ __populate_fail() { _scratch_xfs_metadump "$metadump" "${mdargs[@]}" ;; - ext4) + fuse.ext[234]|ext[234]) _scratch_unmount _ext4_metadump "${SCRATCH_DEV}" "$metadump" ;;
@@ -978,7 +978,7 @@ _scratch_populate() { _scratch_xfs_populate _scratch_xfs_populate_check ;; - "ext2"|"ext3"|"ext4") + fuse.ext[234]|ext[234]) _scratch_ext4_populate _scratch_ext4_populate_check ;;
@@ -1072,7 +1072,7 @@ _scratch_populate_cache_tag() { fi case "${FSTYP}" in - "ext4") + fuse.ext[234]|ext[234]) extra_descr="LOGDEV_SIZE ${logdev_sz}" ;; "xfs")
@@ -1095,7 +1095,7 @@ _scratch_populate_restore_cached() { _scratch_xfs_mdrestore "${metadump}" return $? ;; - "ext2"|"ext3"|"ext4") + fuse.ext[234]|ext[234]) local logdev=none [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \ logdev=$SCRATCH_LOGDEV
@@ -1130,7 +1130,7 @@ _scratch_populate_save_metadump() "$rtdev" compress "${mdargs[@]}" res=$? ;; - "ext2"|"ext3"|"ext4") + fuse.ext[234]|ext[234]) _ext4_metadump "${SCRATCH_DEV}" "${metadump_file}" compress res=$? ;;
@@ -1168,7 +1168,7 @@ _scratch_populate_cached() { _scratch_xfs_populate $@ _scratch_xfs_populate_check ;; - "ext2"|"ext3"|"ext4") + fuse.ext[234]|ext[234]) _scratch_ext4_populate $@ _scratch_ext4_populate_check ;;
common/quota +9 -0
@@ -12,6 +12,9 @@ _require_quota() [ -n "$QUOTA_PROG" ] || _notrun "Quota user tools not installed" case $FSTYP in + fuse.ext[234]) + _notrun "quota not supported on fuse.ext[234]" + ;; ext2|ext3|ext4|f2fs) if [ ! -d /proc/sys/fs/quota ]; then _notrun "Installed kernel does not support quotas"
@@ -163,6 +166,9 @@ _require_getnextquota() _scratch_enable_pquota() { case $FSTYP in + fuse.ext[234]) + _notrun "fuse.ext[234] doesn't support project quota" + ;; ext2|ext3|ext4) tune2fs -O quota,project $SCRATCH_DEV >>$seqres.full 2>&1 _try_scratch_mount >/dev/null 2>&1 \
@@ -335,6 +341,9 @@ _check_quota_usage() VFS_QUOTA=0 case $FSTYP in + fuse.ext[234]) + echo "fuse.ext[234] doesn't support quota" + ;; ext2|ext3|ext4|f2fs|gfs2|bcachefs) VFS_QUOTA=1 quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
common/rc +29 -21
180 lines not on this page · raw message
common/report +1 -1
@@ -77,7 +77,7 @@ __generate_report_vars() { # Add per-filesystem variables to the report variable list test "$FSTYP" = "xfs" && __generate_xfs_report_vars - [[ "$FSTYP" == ext[0-9]* ]] && __generate_ext4_report_vars + [[ "$FSTYP" =~ ext[0-9]* ]] && __generate_ext4_report_vars # Optional environmental variables for varname in "${REPORT_ENV_LIST_OPT[@]}"; do
common/verity +4 -4
@@ -198,7 +198,7 @@ _require_fsverity_corruption() _scratch_mkfs_verity() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) _scratch_mkfs -O verity ;; btrfs)
@@ -216,7 +216,7 @@ _scratch_mkfs_verity() _scratch_mkfs_encrypted_verity() { case $FSTYP in - ext4) + fuse.ext4|ext4) _scratch_mkfs -O encrypt,verity ;; f2fs)
@@ -386,7 +386,7 @@ _fsv_scratch_corrupt_merkle_tree() local offset=$2 case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) # ext4 and f2fs store the Merkle tree after the file contents # itself, starting at the next 65536-byte aligned boundary. (( offset += ($(_get_filesize $file) + 65535) & ~65535 ))
@@ -417,7 +417,7 @@ _fsv_scratch_corrupt_merkle_tree() _require_fsverity_max_file_size_limit() { case $FSTYP in - btrfs|ext4|f2fs) + btrfs|fuse.ext4|ext4|f2fs) ;; *) _notrun "$FSTYP does not store verity data past EOF; no special file size limit"
tests/generic/020 +1 -1
@@ -59,7 +59,7 @@ _attr_get_max() xfs|udf|pvfs2|9p|ceph|fuse|nfs|ceph-fuse) max_attrs=1000 ;; - ext2|ext3|ext4) + ext2|ext3|fuse.ext[234]|ext4) # For 4k blocksizes, most of the attributes have an attr_name of # "attribute_NN" which is 12, and "value_NN" which is 8. # But for larger block sizes, we start having extended
tests/generic/067 +1 -1
@@ -56,7 +56,7 @@ mount_free_loopdev() mount_wrong_fstype() { local fs=ext4 - if [ "$FSTYP" == "ext4" ]; then + if [[ "$FSTYP" =~ ext4 ]]; then fs=xfs fi echo "# mount with wrong fs type" >>$seqres.full
tests/generic/441 +1 -1
@@ -33,7 +33,7 @@ case $FSTYP in btrfs) _notrun "btrfs has a specialized test for this" ;; - ext3|ext4|xfs|bcachefs) + ext3|fuse.ext[234]|ext4|xfs|bcachefs) # Do the more thorough test if we have a logdev _has_logdev && sflag='' ;;
tests/generic/496 +1 -1
@@ -52,7 +52,7 @@ $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full # ext4/xfs should not fail for swapon on fallocated files case $FSTYP in -ext4|xfs) +fuse.ext[234]|ext4|xfs) "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \ _fail "swapon failed on fallocated file" ;;
tests/generic/621 +1 -1
@@ -144,7 +144,7 @@ done # directories); otherwise e2fsck doesn't check for duplicate filenames. echo -e "\n# Checking for duplicate filenames via fsck" _scratch_unmount -if [ "$FSTYP" = ext4 ]; then +if [[ "$FSTYP" =~ ext4 ]]; then if ! e2fsck -f -y -D $SCRATCH_DEV &>> $seqres.full; then _log_err "filesystem on $SCRATCH_DEV is inconsistent" fi
tests/generic/740 +1 -1
@@ -36,7 +36,7 @@ do postargs="" # for any special post-device options case "$fs" in - ext2|ext3|ext4) + ext2|ext3|fuse.ext[234]|ext4) preargs="-F" ;; cramfs)
tests/generic/746 +2 -2
@@ -26,7 +26,7 @@ btrfs) _require_fs_space $TEST_DIR 3145728 fssize=3000 ;; -ext4) +fuse.ext[234]|ext4) _require_dumpe2fs ;; xfs)
@@ -65,7 +65,7 @@ get_holes() get_free_sectors() { case $FSTYP in - ext4) + fuse.ext[234]|ext4) _unmount $loop_mnt $DUMPE2FS_PROG $loop_dev 2>&1 | grep " Free blocks" | cut -d ":" -f2- | \ tr ',' '\n' | $SED_PROG 's/^ //' | \
tests/generic/765 +2 -2
@@ -28,7 +28,7 @@ get_supported_bsize() fi done ;; - "ext4") + fuse.ext[234]|"ext4") min_bsize=1024 max_bsize=$(_get_page_size) ;;
@@ -50,7 +50,7 @@ get_mkfs_opts() "xfs") mkfs_opts="-b size=$bsize" ;; - "ext4") + fuse.ext[234]|"ext4") mkfs_opts="-b $bsize" ;; *)
Amir Goldstein
maintainerRe: [PATCH 01/33] misc: adapt tests to handle the fuse ext[234] drivers
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
It would be useful to be able to run fstests against the userspace ext[234] driver program fuse2fs. A convention (at least on Debian) seems to be to install fuse drivers as
/sbin/mount.fuse.XXXso that users can run "mount -t fuse.XXX" to start a fuse driver for a disk-based filesystem type XXX.
Quoted 7 lines
Therefore, we'll adopt the practice of setting FSTYP=fuse.ext4 to test ext4 with fuse2fs. Change all the library code as needed to handle this new type alongside all the existing ext[234] checks, which seems a little cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4, which also would require even more treewide cleanups to work properly because most fstests code switches on $FSTYP alone.
I agree that FSTYP=fuse.ext4 is cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4
but it is not extendable to future (e.g. fuse.xfs) and it is still a bit ugly.
Consider:
FSTYP=fuse.ext4
MKFSTYP=ext4
I think this is the correct abstraction - fuse2fs/ext4 are formatted that same and mounted differently
See how some of your patch looks nicer and naturally extends to the imaginary fuse.xfs...
Quoted 90 lines
Signed-off-by "Darrick J. Wong" <[email protected]>--- check | 24 +++++++++++++++++------- common/casefold | 4 ++++ common/config | 11 ++++++++--- common/defrag | 2 +- common/encrypt | 16 ++++++++-------- common/log | 10 +++++----- common/populate | 14 +++++++------- common/quota | 9 +++++++++ common/rc | 50 +++++++++++++++++++++++++++++--------------------- common/report | 2 +- common/verity | 8 ++++---- tests/generic/020 | 2 +- tests/generic/067 | 2 +- tests/generic/441 | 2 +- tests/generic/496 | 2 +- tests/generic/621 | 2 +- tests/generic/740 | 2 +- tests/generic/746 | 4 ++-- tests/generic/765 | 4 ++-- 19 files changed, 103 insertions(+), 67 deletions(-)check +17
-7@@ -140,12 +140,25 @@ get_sub_group_list() echo $grpl } +get_group_dirs() +{ + local fsgroup="$FSTYP" + + case "$FSTYP" in + ext2|ext3|fuse.ext[234]) + fsgroup=ext4 + ;; + esac + + echo $SRC_GROUPS + echo $fsgroup +} + get_group_list() { local grp=$1 local grpl="" local sub=$(dirname $grp) - local fsgroup="$FSTYP" if [ -n "$sub" -a "$sub" != "." -a -d "$SRC_DIR/$sub" ]; then # group is given as <subdir>/<group> (e.g. xfs/quick)@@ -154,10 +167,7 @@ get_group_list() return fi - if [ "$FSTYP" = ext2 -o "$FSTYP" = ext3 ]; then - fsgroup=ext4 - fi - for d in $SRC_GROUPS $fsgroup; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi@@ -171,7 +181,7 @@ get_group_list() get_all_tests() { touch $tmp.list - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi@@ -387,7 +397,7 @@ if [ -n "$FUZZ_REWRITE_DURATION" ]; then fi if [ -n "$subdir_xfile" ]; then - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do [ -f $SRC_DIR/$d/$subdir_xfile ] || continue for f in `sed "s/#.*$//" $SRC_DIR/$d/$subdir_xfile`; do exclude_tests+=($d/$f)common/casefold +0
-0
common/casefold line 12
Quoted 7 lines
common/casefold +4
-0@@ -6,6 +6,10 @@ _has_casefold_kernel_support() { case $FSTYP in + fuse.ext[234]) + # fuse2fs does not support casefolding + false + ;;
This would not be needed
Quoted 20 lines
common/casefold +0
-0ext4) test -f '/sys/fs/ext4/features/casefold' ;;common/config +5
-0@@ -386,6 +386,11 @@ _common_mount_opts() overlay) echo $OVERLAY_MOUNT_OPTIONS ;; + fuse.ext[234]) + # fuse sets up secure defaults, so we must explicitly tell + # fuse2fs to use the more relaxed kernel access behaviors. + echo "-o kernel $EXT_MOUNT_OPTIONS" + ;; ext2|ext3|ext4) # acls & xattrs aren't turned on by default on ext$FOO echo "-o acl,user_xattr $EXT_MOUNT_OPTIONS"
common/config _mkfs_opts() · line 479
Quoted 3 lines
common/config +0
-0@@ -472,7 +477,7 @@ _mkfs_opts() _fsck_opts() { case $FSTYP in
This would obviously be $MKFSTYP with no further changes
Quoted 7 lines
common/config +1
-1- ext2|ext3|ext4) + ext2|ext3|fuse.ext[234]|ext4) export FSCK_OPTIONS="-nf" ;; reiser*)@@ -514,11 +519,11 @@ _source_specific_fs()
common/config _source_specific_fs() · line 527
Quoted 10 lines
common/config +2
-2. ./common/btrfs ;; - ext4) + fuse.ext4|ext4) [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found" . ./common/ext4 ;; - ext2|ext3) + ext2|ext3|fuse.ext[23]) . ./common/ext4
same here
Quoted 7 lines
common/config +0
-0;; f2fs)common/defrag +0
-0
common/defrag _require_defrag() · line 18
Quoted 8 lines
common/defrag +1
-1@@ -12,7 +12,7 @@ _require_defrag() _require_xfs_io_command "falloc" DEFRAG_PROG="$XFS_FSR_PROG" ;; - ext4) + fuse.ext4|ext4) testfile="$TEST_DIR/$$-test.defrag" donorfile="$TEST_DIR/$$-donor.defrag" bsize=`_get_block_size $TEST_DIR`
and here
common/encrypt _require_hw_wrapped_key_support() · line 196
Quoted 12 lines
common/encrypt +1
-1@@ -191,7 +191,7 @@ _require_hw_wrapped_key_support() _scratch_mkfs_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) _scratch_mkfs -O encrypt ;;
and here
common/encrypt _scratch_mkfs_encrypted() · line 215
Quoted 9 lines
common/encrypt +1
-1ubifs)@@ -210,7 +210,7 @@ _scratch_mkfs_encrypted() _scratch_mkfs_sized_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) MKFS_OPTIONS="$MKFS_OPTIONS -O encrypt" _scratch_mkfs_sized $* ;;
and here... I think you got my point.
Thanks,
Amir.
Re: [PATCH 01/33] misc: adapt tests to handle the fuse ext[234] drivers
Quoted 27 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
It would be useful to be able to run fstests against the userspace ext[234] driver program fuse2fs. A convention (at least on Debian) seems to be to install fuse drivers as
/sbin/mount.fuse.XXXso that users can run "mount -t fuse.XXX" to start a fuse driver for a disk-based filesystem type XXX.Quoted 7 lines
Therefore, we'll adopt the practice of setting FSTYP=fuse.ext4 to test ext4 with fuse2fs. Change all the library code as needed to handle this new type alongside all the existing ext[234] checks, which seems a little cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4, which also would require even more treewide cleanups to work properly because most fstests code switches on $FSTYP alone.
I agree that FSTYP=fuse.ext4 is cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4
but it is not extendable to future (e.g. fuse.xfs) and it is still a bit ugly.Consider:
FSTYP=fuse.ext4
MKFSTYP=ext4
Quoted 5 lines
I think this is the correct abstraction - fuse2fs/ext4 are formatted that same and mounted differently
See how some of your patch looks nicer and naturally extends to the imaginary fuse.xfs...
Maybe I'd rather do it the other way around for fuse4fs:
FSTYP=ext4
MOUNT_FSTYP=fuse.ext4
(obviously, MOUNT_FSTYP=$FSTYP if the test runner hasn't overridden it)
Where $MOUNT_FSTYP is what you pass to mount -t and what you'd see in /proc/mounts. The only weirdness with that is that some of the helpers will end up with code like:
case $FSTYP in ext4) # do ext4 stuff ;; esac case $MOUNT_FSTYP in fuse.ext4) # do fuse4fs stuff that overrides ext4 ;; esac
which would be a little weird.
_scratch_mount would end up with:
$MOUNT_PROG -t $MOUNT_FSTYP ...
and detecting it would be
grep -q -w $MOUNT_FSTYP /proc/mounts || _fail "booooo"
Hrm?
--D
Quoted 195 lines
Quoted 91 lines
Signed-off-by "Darrick J. Wong" <[email protected]>--- check | 24 +++++++++++++++++------- common/casefold | 4 ++++ common/config | 11 ++++++++--- common/defrag | 2 +- common/encrypt | 16 ++++++++-------- common/log | 10 +++++----- common/populate | 14 +++++++------- common/quota | 9 +++++++++ common/rc | 50 +++++++++++++++++++++++++++++--------------------- common/report | 2 +- common/verity | 8 ++++---- tests/generic/020 | 2 +- tests/generic/067 | 2 +- tests/generic/441 | 2 +- tests/generic/496 | 2 +- tests/generic/621 | 2 +- tests/generic/740 | 2 +- tests/generic/746 | 4 ++-- tests/generic/765 | 4 ++-- 19 files changed, 103 insertions(+), 67 deletions(-)check +17
-7@@ -140,12 +140,25 @@ get_sub_group_list() echo $grpl } +get_group_dirs() +{ + local fsgroup="$FSTYP" + + case "$FSTYP" in + ext2|ext3|fuse.ext[234]) + fsgroup=ext4 + ;; + esac + + echo $SRC_GROUPS + echo $fsgroup +} + get_group_list() { local grp=$1 local grpl="" local sub=$(dirname $grp) - local fsgroup="$FSTYP" if [ -n "$sub" -a "$sub" != "." -a -d "$SRC_DIR/$sub" ]; then # group is given as <subdir>/<group> (e.g. xfs/quick)@@ -154,10 +167,7 @@ get_group_list() return fi - if [ "$FSTYP" = ext2 -o "$FSTYP" = ext3 ]; then - fsgroup=ext4 - fi - for d in $SRC_GROUPS $fsgroup; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi@@ -171,7 +181,7 @@ get_group_list() get_all_tests() { touch $tmp.list - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi@@ -387,7 +397,7 @@ if [ -n "$FUZZ_REWRITE_DURATION" ]; then fi if [ -n "$subdir_xfile" ]; then - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do [ -f $SRC_DIR/$d/$subdir_xfile ] || continue for f in `sed "s/#.*$//" $SRC_DIR/$d/$subdir_xfile`; do exclude_tests+=($d/$f)common/casefold +0
-0common/casefold line 12
Quoted 7 lines
common/casefold +4
-0@@ -6,6 +6,10 @@ _has_casefold_kernel_support() { case $FSTYP in + fuse.ext[234]) + # fuse2fs does not support casefolding + false + ;;This would not be needed
Quoted 20 lines
common/casefold +0
-0ext4) test -f '/sys/fs/ext4/features/casefold' ;;common/config +5
-0@@ -386,6 +386,11 @@ _common_mount_opts() overlay) echo $OVERLAY_MOUNT_OPTIONS ;; + fuse.ext[234]) + # fuse sets up secure defaults, so we must explicitly tell + # fuse2fs to use the more relaxed kernel access behaviors. + echo "-o kernel $EXT_MOUNT_OPTIONS" + ;; ext2|ext3|ext4) # acls & xattrs aren't turned on by default on ext$FOO echo "-o acl,user_xattr $EXT_MOUNT_OPTIONS"common/config _mkfs_opts() · line 479
Quoted 3 lines
common/config +0
-0@@ -472,7 +477,7 @@ _mkfs_opts() _fsck_opts() { case $FSTYP inThis would obviously be $MKFSTYP with no further changes
Quoted 7 lines
common/config +1
-1- ext2|ext3|ext4) + ext2|ext3|fuse.ext[234]|ext4) export FSCK_OPTIONS="-nf" ;; reiser*)@@ -514,11 +519,11 @@ _source_specific_fs()common/config _source_specific_fs() · line 527
Quoted 10 lines
common/config +2
-2. ./common/btrfs ;; - ext4) + fuse.ext4|ext4) [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found" . ./common/ext4 ;; - ext2|ext3) + ext2|ext3|fuse.ext[23]) . ./common/ext4same here
Quoted 7 lines
common/config +0
-0;; f2fs)common/defrag +0
-0common/defrag _require_defrag() · line 18
Quoted 8 lines
common/defrag +1
-1@@ -12,7 +12,7 @@ _require_defrag() _require_xfs_io_command "falloc" DEFRAG_PROG="$XFS_FSR_PROG" ;; - ext4) + fuse.ext4|ext4) testfile="$TEST_DIR/$$-test.defrag" donorfile="$TEST_DIR/$$-donor.defrag" bsize=`_get_block_size $TEST_DIR`and here
common/encrypt _require_hw_wrapped_key_support() · line 196
Quoted 12 lines
common/encrypt +1
-1@@ -191,7 +191,7 @@ _require_hw_wrapped_key_support() _scratch_mkfs_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) _scratch_mkfs -O encrypt ;;and here
common/encrypt _scratch_mkfs_encrypted() · line 215
Quoted 9 lines
common/encrypt +1
-1ubifs)@@ -210,7 +210,7 @@ _scratch_mkfs_encrypted() _scratch_mkfs_sized_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) MKFS_OPTIONS="$MKFS_OPTIONS -O encrypt" _scratch_mkfs_sized $* ;;and here... I think you got my point.
Thanks,
Amir.
Amir Goldstein
maintainerRe: [PATCH 01/33] misc: adapt tests to handle the fuse ext[234] drivers
Quoted 32 lines · Darrick J. Wong
Quoted 30 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
It would be useful to be able to run fstests against the userspace ext[234] driver program fuse2fs. A convention (at least on Debian) seems to be to install fuse drivers as
/sbin/mount.fuse.XXXso that users can run "mount -t fuse.XXX" to start a fuse driver for a disk-based filesystem type XXX.Quoted 7 lines
Therefore, we'll adopt the practice of setting FSTYP=fuse.ext4 to test ext4 with fuse2fs. Change all the library code as needed to handle this new type alongside all the existing ext[234] checks, which seems a little cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4, which also would require even more treewide cleanups to work properly because most fstests code switches on $FSTYP alone.
I agree that FSTYP=fuse.ext4 is cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4
but it is not extendable to future (e.g. fuse.xfs) and it is still a bit ugly.Consider:
FSTYP=fuse.ext4
MKFSTYP=ext4I think this is the correct abstraction - fuse2fs/ext4 are formatted that same and mounted differently
Quoted 8 lines
Quoted 2 lines
See how some of your patch looks nicer and naturally extends to the imaginary fuse.xfs...
Maybe I'd rather do it the other way around for fuse4fs:
FSTYP=ext4
MOUNT_FSTYP=fuse.ext4
Sounds good. Will need to see the final patch.
Quoted 12 lines
(obviously, MOUNT_FSTYP=$FSTYP if the test runner hasn't overridden it)
Where $MOUNT_FSTYP is what you pass to mount -t and what you'd see in
/proc/mounts. The only weirdness with that is that some of the helpers will end up with code like:case $FSTYP in
ext4)
# do ext4 stuff
;;
esac
Quoted 8 lines
case $MOUNT_FSTYP in
fuse.ext4)
# do fuse4fs stuff that overrides ext4 ;;
esacwhich would be a little weird.
Sounds weird, but there is always going to be weirdness somewhere - need to pick the least weird result or most easy to understand code IMO.
Quoted 9 lines
_scratch_mountwould end up with:$MOUNT_PROG -t $MOUNT_FSTYP ...and detecting it would be
grep -q -w $MOUNT_FSTYP /proc/mounts || _fail "booooo"Hrm?
Those look obviously nice.
Maybe the answer is to have all MOUNT_FSTYP, MKFS_FSTYP and FSTYP and use whichever best fits in the context.
Thanks,
Amir.
Re: [PATCH 01/33] misc: adapt tests to handle the fuse ext[234] drivers
Quoted 75 lines · Amir Goldstein
Quoted 32 lines · Darrick J. Wong
Quoted 30 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
It would be useful to be able to run fstests against the userspace ext[234] driver program fuse2fs. A convention (at least on Debian) seems to be to install fuse drivers as
/sbin/mount.fuse.XXXso that users can run "mount -t fuse.XXX" to start a fuse driver for a disk-based filesystem type XXX.Quoted 7 lines
Therefore, we'll adopt the practice of setting FSTYP=fuse.ext4 to test ext4 with fuse2fs. Change all the library code as needed to handle this new type alongside all the existing ext[234] checks, which seems a little cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4, which also would require even more treewide cleanups to work properly because most fstests code switches on $FSTYP alone.
I agree that FSTYP=fuse.ext4 is cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4
but it is not extendable to future (e.g. fuse.xfs) and it is still a bit ugly.Consider:
FSTYP=fuse.ext4
MKFSTYP=ext4I think this is the correct abstraction - fuse2fs/ext4 are formatted that same and mounted differently
Quoted 8 lines
Quoted 2 lines
See how some of your patch looks nicer and naturally extends to the imaginary fuse.xfs...
Maybe I'd rather do it the other way around for fuse4fs:
FSTYP=ext4
MOUNT_FSTYP=fuse.ext4Sounds good. Will need to see the final patch.
Quoted 12 lines
(obviously, MOUNT_FSTYP=$FSTYP if the test runner hasn't overridden it)
Where $MOUNT_FSTYP is what you pass to mount -t and what you'd see in
/proc/mounts. The only weirdness with that is that some of the helpers will end up with code like:case $FSTYP in
ext4)
# do ext4 stuff
;;
esacQuoted 8 lines
case $MOUNT_FSTYP in
fuse.ext4)
# do fuse4fs stuff that overrides ext4 ;;
esacwhich would be a little weird.
Sounds weird, but there is always going to be weirdness somewhere - need to pick the least weird result or most easy to understand code IMO.
Quoted 6 lines
_scratch_mountwould end up with:$MOUNT_PROG -t $MOUNT_FSTYP ...and detecting it would be
Quoted 8 lines
Quoted 3 lines
grep -q -w $MOUNT_FSTYP /proc/mounts || _fail "booooo"Hrm?
Those look obviously nice.
Maybe the answer is to have all
MOUNT_FSTYP,MKFS_FSTYPand FSTYP and use whichever best fits in the context.
Hrmm well I would /like/ avoid adding MKFS_FSTYP since ext4 is ext4, no matter whether we're using the kernel or fuse42fs. Do you have a use case for adding such a thing?
--D
Quoted 3 lines
Thanks,
Amir.
Amir Goldstein
maintainerRe: [PATCH 01/33] misc: adapt tests to handle the fuse ext[234] drivers
Quoted 81 lines · Darrick J. Wong
Quoted 79 lines · Amir Goldstein
Quoted 32 lines · Darrick J. Wong
Quoted 30 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
It would be useful to be able to run fstests against the userspace ext[234] driver program fuse2fs. A convention (at least on Debian) seems to be to install fuse drivers as
/sbin/mount.fuse.XXXso that users can run "mount -t fuse.XXX" to start a fuse driver for a disk-based filesystem type XXX.Quoted 7 lines
Therefore, we'll adopt the practice of setting FSTYP=fuse.ext4 to test ext4 with fuse2fs. Change all the library code as needed to handle this new type alongside all the existing ext[234] checks, which seems a little cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4, which also would require even more treewide cleanups to work properly because most fstests code switches on $FSTYP alone.
I agree that FSTYP=fuse.ext4 is cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4
but it is not extendable to future (e.g. fuse.xfs) and it is still a bit ugly.Consider:
FSTYP=fuse.ext4
MKFSTYP=ext4I think this is the correct abstraction - fuse2fs/ext4 are formatted that same and mounted differently
Quoted 8 lines
Quoted 2 lines
See how some of your patch looks nicer and naturally extends to the imaginary fuse.xfs...
Maybe I'd rather do it the other way around for fuse4fs:
FSTYP=ext4
MOUNT_FSTYP=fuse.ext4Sounds good. Will need to see the final patch.
Quoted 12 lines
(obviously, MOUNT_FSTYP=$FSTYP if the test runner hasn't overridden it)
Where $MOUNT_FSTYP is what you pass to mount -t and what you'd see in
/proc/mounts. The only weirdness with that is that some of the helpers will end up with code like:case $FSTYP in
ext4)
# do ext4 stuff
;;
esacQuoted 8 lines
case $MOUNT_FSTYP in
fuse.ext4)
# do fuse4fs stuff that overrides ext4 ;;
esacwhich would be a little weird.
Sounds weird, but there is always going to be weirdness somewhere - need to pick the least weird result or most easy to understand code IMO.
Quoted 9 lines
_scratch_mountwould end up with:$MOUNT_PROG -t $MOUNT_FSTYP ...and detecting it would be
grep -q -w $MOUNT_FSTYP /proc/mounts || _fail "booooo"Hrm?
Quoted 9 lines
Quoted 4 lines
Those look obviously nice.
Maybe the answer is to have all
MOUNT_FSTYP,MKFS_FSTYPand FSTYP and use whichever best fits in the context.Hrmm well I would /like/ avoid adding
MKFS_FSTYPsince ext4 is ext4, no matter whether we're using the kernel or fuse42fs. Do you have a use case for adding such a thing?
No use case, beyond more flexibility in writing clear code. I agree with Zorro that ext4 is not only ext4.
ext4 is ext4 on-disk format and it is ext4 driver and this ambiguity can be a source of confusion sometimes.
I don't see the problem with defining MKFS_FSTYP the controversial part IMO is what FSTYP should be referring to, the flesh or the spirit...
Trying to think up a use case, ntfs has at least 3 Linux drivers that I know of (ntfs,ntfs3 and fuse.ntfs-3g) and another one that was recently proposed (ntfsplus). At least some have also their matching mkfs and should be able to cross mount an ntfs formatted by other mkfs.
So testing any variation of MKFS_FSTYP and MOUNT_FSTYP makes sense.
Using MKFS_FSTYP in mkfs and fsck helpers and using MOUNT_FSTYP in mount helpers is always good practice IMO.
My intuition is that FSTYP should be defined to whichever results in less churn and less weird looking code, but I don't know which one that would be.
Thanks,
Amir.
Re: [PATCH 01/33] misc: adapt tests to handle the fuse ext[234] drivers
In reply to Darrick J. WongQuoted 11 lines · Darrick J. Wong
Quoted 10 lines · Amir Goldstein
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
It would be useful to be able to run fstests against the userspace ext[234] driver program fuse2fs. A convention (at least on Debian) seems to be to install fuse drivers as
/sbin/mount.fuse.XXXso that users can run "mount -t fuse.XXX" to start a fuse driver for a disk-based filesystem type XXX.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Therefore, we'll adopt the practice of setting FSTYP=fuse.ext4 to test ext4 with fuse2fs. Change all the library code as needed to handle this new type alongside all the existing ext[234] checks, which seems a little cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4, which also would require even more treewide cleanups to work properly because most fstests code switches on $FSTYP alone.
Thanks Darrick, a big patchset again :)
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
I agree that FSTYP=fuse.ext4 is cleaner than FSTYP=fuse FUSE_SUBTYPE=ext4
but it is not extendable to future (e.g. fuse.xfs) and it is still a bit ugly.Consider:
FSTYP=fuse.ext4
MKFSTYP=ext4
No matter this ^^^, or ...
Quoted 11 lines
Quoted 6 lines
I think this is the correct abstraction - fuse2fs/ext4 are formatted that same and mounted differently
See how some of your patch looks nicer and naturally extends to the imaginary fuse.xfs...
Maybe I'd rather do it the other way around for fuse4fs:
FSTYP=ext4
MOUNT_FSTYP=fuse.ext4
... this ^^^, I think this discussion brings in a topic:
If the same on-disk fstype can be mounted with different drivers, what does original $FSTYP stand for? Is it stand for the running fs driver, or the the on-disk fs type? Besides the code looks ugly or not, the basic parameters must be clear in meaning I think.
If the same on-disk fstype can be mounted with different drivers, we might need two parameters to avoid this confusion. Due to we sometimes depends on the on-disk type, e.g. mkfs, fsck, xfs_db, metadump and so on, sometimes depend on running-time fs driver, e.g. mount, quota and so on.
We can let FSTYP stands for the running-time fs driver, as it's mostly treated as that I think. And set MKFSTYP=$FSTYP by default, if MKFSTYP isn't specified. Then change those "FSTYP judgement" code to MKFSTYP, if they need ondisk fstype actually.
I don't mind the parameter name, but the meaning should not be confused. What do you think? Feel free to correct me if I miss anything.
Thanks,
Zorro
Quoted 229 lines
(obviously, MOUNT_FSTYP=$FSTYP if the test runner hasn't overridden it)
Where $MOUNT_FSTYP is what you pass to mount -t and what you'd see in
/proc/mounts. The only weirdness with that is that some of the helpers will end up with code like:case $FSTYP in ext4) # do ext4 stuff ;; esac case $MOUNT_FSTYP in fuse.ext4) # do fuse4fs stuff that overrides ext4 ;; esacwhich would be a little weird.
_scratch_mountwould end up with:$MOUNT_PROG -t $MOUNT_FSTYP ...and detecting it would be
grep -q -w $MOUNT_FSTYP /proc/mounts || _fail "booooo"Hrm?
--D
Quoted 195 lines
Quoted 91 lines
Signed-off-by "Darrick J. Wong" <[email protected]>--- check | 24 +++++++++++++++++------- common/casefold | 4 ++++ common/config | 11 ++++++++--- common/defrag | 2 +- common/encrypt | 16 ++++++++-------- common/log | 10 +++++----- common/populate | 14 +++++++------- common/quota | 9 +++++++++ common/rc | 50 +++++++++++++++++++++++++++++--------------------- common/report | 2 +- common/verity | 8 ++++---- tests/generic/020 | 2 +- tests/generic/067 | 2 +- tests/generic/441 | 2 +- tests/generic/496 | 2 +- tests/generic/621 | 2 +- tests/generic/740 | 2 +- tests/generic/746 | 4 ++-- tests/generic/765 | 4 ++-- 19 files changed, 103 insertions(+), 67 deletions(-)check +17
-7@@ -140,12 +140,25 @@ get_sub_group_list() echo $grpl } +get_group_dirs() +{ + local fsgroup="$FSTYP" + + case "$FSTYP" in + ext2|ext3|fuse.ext[234]) + fsgroup=ext4 + ;; + esac + + echo $SRC_GROUPS + echo $fsgroup +} + get_group_list() { local grp=$1 local grpl="" local sub=$(dirname $grp) - local fsgroup="$FSTYP" if [ -n "$sub" -a "$sub" != "." -a -d "$SRC_DIR/$sub" ]; then # group is given as <subdir>/<group> (e.g. xfs/quick)@@ -154,10 +167,7 @@ get_group_list() return fi - if [ "$FSTYP" = ext2 -o "$FSTYP" = ext3 ]; then - fsgroup=ext4 - fi - for d in $SRC_GROUPS $fsgroup; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi@@ -171,7 +181,7 @@ get_group_list() get_all_tests() { touch $tmp.list - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do if ! test -d "$SRC_DIR/$d" ; then continue fi@@ -387,7 +397,7 @@ if [ -n "$FUZZ_REWRITE_DURATION" ]; then fi if [ -n "$subdir_xfile" ]; then - for d in $SRC_GROUPS $FSTYP; do + for d in $(get_group_dirs); do [ -f $SRC_DIR/$d/$subdir_xfile ] || continue for f in `sed "s/#.*$//" $SRC_DIR/$d/$subdir_xfile`; do exclude_tests+=($d/$f)common/casefold +0
-0common/casefold line 12
Quoted 7 lines
common/casefold +4
-0@@ -6,6 +6,10 @@ _has_casefold_kernel_support() { case $FSTYP in + fuse.ext[234]) + # fuse2fs does not support casefolding + false + ;;This would not be needed
Quoted 20 lines
common/casefold +0
-0ext4) test -f '/sys/fs/ext4/features/casefold' ;;common/config +5
-0@@ -386,6 +386,11 @@ _common_mount_opts() overlay) echo $OVERLAY_MOUNT_OPTIONS ;; + fuse.ext[234]) + # fuse sets up secure defaults, so we must explicitly tell + # fuse2fs to use the more relaxed kernel access behaviors. + echo "-o kernel $EXT_MOUNT_OPTIONS" + ;; ext2|ext3|ext4) # acls & xattrs aren't turned on by default on ext$FOO echo "-o acl,user_xattr $EXT_MOUNT_OPTIONS"common/config _mkfs_opts() · line 479
Quoted 3 lines
common/config +0
-0@@ -472,7 +477,7 @@ _mkfs_opts() _fsck_opts() { case $FSTYP inThis would obviously be $MKFSTYP with no further changes
Quoted 7 lines
common/config +1
-1- ext2|ext3|ext4) + ext2|ext3|fuse.ext[234]|ext4) export FSCK_OPTIONS="-nf" ;; reiser*)@@ -514,11 +519,11 @@ _source_specific_fs()common/config _source_specific_fs() · line 527
Quoted 10 lines
common/config +2
-2. ./common/btrfs ;; - ext4) + fuse.ext4|ext4) [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found" . ./common/ext4 ;; - ext2|ext3) + ext2|ext3|fuse.ext[23]) . ./common/ext4same here
Quoted 7 lines
common/config +0
-0;; f2fs)common/defrag +0
-0common/defrag _require_defrag() · line 18
Quoted 8 lines
common/defrag +1
-1@@ -12,7 +12,7 @@ _require_defrag() _require_xfs_io_command "falloc" DEFRAG_PROG="$XFS_FSR_PROG" ;; - ext4) + fuse.ext4|ext4) testfile="$TEST_DIR/$$-test.defrag" donorfile="$TEST_DIR/$$-donor.defrag" bsize=`_get_block_size $TEST_DIR`and here
common/encrypt _require_hw_wrapped_key_support() · line 196
Quoted 12 lines
common/encrypt +1
-1@@ -191,7 +191,7 @@ _require_hw_wrapped_key_support() _scratch_mkfs_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) _scratch_mkfs -O encrypt ;;and here
common/encrypt _scratch_mkfs_encrypted() · line 215
Quoted 9 lines
common/encrypt +1
-1ubifs)@@ -210,7 +210,7 @@ _scratch_mkfs_encrypted() _scratch_mkfs_sized_encrypted() { case $FSTYP in - ext4|f2fs) + fuse.ext4|ext4|f2fs) MKFS_OPTIONS="$MKFS_OPTIONS -O encrypt" _scratch_mkfs_sized $* ;;and here... I think you got my point.
Thanks,
Amir.
PATCH 2/33 generic/740: don't run this test for fuse ext* implementations
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
mke2fs disables foreign filesystem detection no matter what type you pass in, so we need to block this for both fuse server variants.
--- common/rc | 2 +- tests/generic/740 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
common/rc +1 -1
@@ -1889,7 +1889,7 @@ _do() # _exclude_fs() { - [ "$1" = "$FSTYP" ] && \ + [[ $FSTYP =~ $1 ]] && \ _notrun "not suitable for this filesystem type: $FSTYP" }
tests/generic/740 +1 -0
@@ -17,6 +17,7 @@ _begin_fstest mkfs auto quick _exclude_fs ext2 _exclude_fs ext3 _exclude_fs ext4 +_exclude_fs fuse.ext[234] _exclude_fs jfs _exclude_fs ocfs2 _exclude_fs udf
Amir Goldstein
maintainerRe: [PATCH 02/33] generic/740: don't run this test for fuse ext* implementations
Quoted 18 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
mke2fs disables foreign filesystem detection no matter what type you pass in, so we need to block this for both fuse server variants.
Signed-off-by "Darrick J. Wong" <[email protected]>--- common/rc | 2 +- tests/generic/740 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)common/rc +0
-0
common/rc _do() · line 1893
Quoted 6 lines
common/rc +1
-1@@ -1889,7 +1889,7 @@ _do() # _exclude_fs() { - [ "$1" = "$FSTYP" ] && \ + [[ $FSTYP =~ $1 ]] && \ _notrun "not suitable for this filesystem type: $FSTYP"
If you accept my previous suggestion of MKFSTYP, then could add:
[[ $MKFSTYP =~ $1 ]] && \
_notrun "not suitable for this filesystem on-disk
format: $MKFSTYP"
Quoted 9 lines
common/rc +0
-0}tests/generic/740 +0
-0
tests/generic/740 _begin_fstest mkfs auto quick · line 23
Quoted 7 lines
tests/generic/740 +1
-0@@ -17,6 +17,7 @@ _begin_fstest mkfs auto quick _exclude_fs ext2 _exclude_fs ext3 _exclude_fs ext4 +_exclude_fs fuse.ext[234] _exclude_fs jfs _exclude_fs ocfs2 _exclude_fs udf
And then you wont need to add fuse.ext[234] to exclude list
At the (very faint) risk of having a test that only wants to exclude ext4 and does not want to exclude fuse.ext4, I think this is worth it.
Thanks,
Amir.
Re: [PATCH 02/33] generic/740: don't run this test for fuse ext* implementations
Quoted 52 lines · Amir Goldstein
Quoted 18 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
mke2fs disables foreign filesystem detection no matter what type you pass in, so we need to block this for both fuse server variants.
Signed-off-by "Darrick J. Wong" <[email protected]>--- common/rc | 2 +- tests/generic/740 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)common/rc +0
-0common/rc _do() · line 1893
Quoted 6 lines
common/rc +1
-1@@ -1889,7 +1889,7 @@ _do() # _exclude_fs() { - [ "$1" = "$FSTYP" ] && \ + [[ $FSTYP =~ $1 ]] && \ _notrun "not suitable for this filesystem type: $FSTYP"If you accept my previous suggestion of MKFSTYP, then could add:
[[ $MKFSTYP =~ $1 ]] && \
_notrun"not suitable for this filesystem on-disk
format: $MKFSTYP"Quoted 9 lines
common/rc +0
-0}tests/generic/740 +0
-0tests/generic/740 _begin_fstest mkfs auto quick · line 23
Quoted 7 lines
tests/generic/740 +1
-0@@ -17,6 +17,7 @@ _begin_fstest mkfs auto quick _exclude_fs ext2 _exclude_fs ext3 _exclude_fs ext4 +_exclude_fs fuse.ext[234] _exclude_fs jfs _exclude_fs ocfs2 _exclude_fs udfAnd then you wont need to add fuse.ext[234] to exclude list
Quoted 2 lines
At the (very faint) risk of having a test that only wants to exclude ext4 and does not want to exclude fuse.ext4, I think this is worth it.
I guess we could try to do [[ $MKFSTYP =~ ^$1 ]]; ?
--D
Quoted 3 lines
Thanks,
Amir.