Intruduce stacking filesystem vfs helpers
Subsystems (3)
Amir Goldstein
maintainercover Intruduce stacking filesystem vfs helpers
Christian,
These patches essentially just lift some overlayfs code to common file fs/backing_file.c.
They are based on vfs.rw and overlayfs-next branches.
The motivation is (per Miklos' request) to reuse common stacking code for the FUSE passthrough patches that I am shaping up for upstream.
I have been testing those patches with my fuse-backing-fd development branch [1] for quite some time and I think both you and Miklos gave a conceptual ACK to some version of this work, but the patches were never publicly posted.
I am aiming the FUSE passthough work for the 6.9 dev cycle and I was contemplating whether I should queue these up for 6.8 merge window to give them time to mature before 6.9 merge window.
If I do that, would you preffer to take these patches via the vfs tree or will you be ok with me including them in the overlayfs PR for 6.8?
Miklos,
Are you ok with including this in overlayfs PR for 6.8?
Thanks,
Amir.
[1] https://github.com/amir73il/linux/commits/fuse-backing-fd
Amir Goldstein (4):
fs: prepare for stackable filesystems backing file helpers
fs: factor out backing_file_{read,write}_iter() helpers
fs: factor out backing_file_splice_{read,write}() helpers
fs: factor out backing_file_mmap() helper
MAINTAINERS | 9 + fs/Kconfig | 4 + fs/Makefile | 1 + fs/backing-file.c | 324 +++++++++++++++++++++++++++++++++++ fs/open.c | 38 ---- fs/overlayfs/Kconfig | 1 + fs/overlayfs/file.c | 245 ++++---------------------- fs/overlayfs/overlayfs.h | 8 +- fs/overlayfs/super.c | 11 +- include/linux/backing-file.h | 42 +++++ include/linux/fs.h | 3 - 11 files changed, 423 insertions(+), 263 deletions(-) create mode 100644 fs/backing-file.c create mode 100644 include/linux/backing-file.h
Signature · 1 line
2.34.1
Amir Goldstein
maintainerRFC PATCH 1/4 fs: prepare for stackable filesystems backing file helpers
In preparation for factoring out some backing file io helpers from overlayfs, move backing_file_open() into a new file fs/backing-file.c and header.
Add a MAINTAINERS entry for stackable filesystems and add a Kconfig FS_STACK which stackable filesystems need to select.
For now, the backing_file struct, the backing_file alloc/free functions and the backing_file_real_path() accessor remain internal to file_table.c. We may change that in the future.
--- MAINTAINERS | 9 +++++++ fs/Kconfig | 4 +++ fs/Makefile | 1 + fs/backing-file.c | 48 ++++++++++++++++++++++++++++++++++++ fs/open.c | 38 ---------------------------- fs/overlayfs/Kconfig | 1 + fs/overlayfs/file.c | 1 + include/linux/backing-file.h | 17 +++++++++++++ include/linux/fs.h | 3 --- 9 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 fs/backing-file.c create mode 100644 include/linux/backing-file.h
MAINTAINERS +9 -0
@@ -8186,6 +8186,15 @@ S: Supported F: fs/iomap/ F: include/linux/iomap.h +FILESYSTEMS [STACKABLE] +M: Miklos Szeredi <[email protected]> +M: Amir Goldstein <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: fs/backing-file.c +F: include/linux/backing-file.h + FINTEK F75375S HARDWARE MONITOR AND FAN CONTROLLER DRIVER M: Riku Voipio <[email protected]> L: [email protected]
fs/Kconfig +4 -0
@@ -18,6 +18,10 @@ config VALIDATE_FS_PARSER config FS_IOMAP bool +# Stackable filesystems +config FS_STACK + bool + config BUFFER_HEAD bool
fs/Makefile +1 -0
@@ -39,6 +39,7 @@ obj-$(CONFIG_COMPAT_BINFMT_ELF) += compat_binfmt_elf.o obj-$(CONFIG_BINFMT_ELF_FDPIC) += binfmt_elf_fdpic.o obj-$(CONFIG_BINFMT_FLAT) += binfmt_flat.o +obj-$(CONFIG_FS_STACK) += backing-file.o obj-$(CONFIG_FS_MBCACHE) += mbcache.o obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o obj-$(CONFIG_NFS_COMMON) += nfs_common/
fs/backing-file.c new file +48 -0
48 lines not on this page · raw message
fs/open.c +0 -38
@@ -1184,44 +1184,6 @@ struct file *kernel_file_open(const struct path *path, int flags, }EXPORT_SYMBOL_GPL (kernel_file_open); -/** -* backing_file_open - open a backing file for kernel internal use -* @user_path: path that the user reuqested to open -* @flags: open flags -* @real_path: path of the backing file -* @cred: credentials for open -* -* Open a backing file for a stackable filesystem (e.g., overlayfs). -* @user_path may be on the stackable filesystem and @real_path on the -* underlying filesystem. In this case, we want to be able to return the -* @user_path of the stackable filesystem. This is done by embedding the -* returned file into a container structure that also stores the stacked -* file's path, which can be retrieved using backing_file_user_path(). -*/ -struct file *backing_file_open (const struct path *user_path,int flags, -const struct path *real_path, -const struct cred *cred) -{ -struct file *f; -int error; - - f =alloc_empty_backing_file (flags, cred); -if (IS_ERR (f)) -return f; - -path_get (user_path); - *backing_file_user_path (f) = *user_path; - f->f_path = *real_path; - error =do_dentry_open (f,d_inode (real_path->dentry),NULL ); -if (error) { -fput (f); - f =ERR_PTR (error); - } - -return f; -} -EXPORT_SYMBOL_GPL (backing_file_open); -#define WILL_CREATE (flags) (flags & (O_CREAT | __O_TMPFILE))#define O_PATH_FLAGS (O_DIRECTORY | O_NOFOLLOW | O_PATH | O_CLOEXEC)
fs/overlayfs/Kconfig +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config OVERLAY_FS tristate "Overlay filesystem support" + select FS_STACK select EXPORTFS help An overlay filesystem combines two filesystems - an 'upper' filesystem
fs/overlayfs/file.c +1 -0
@@ -13,6 +13,7 @@#include <linux/security.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/backing-file.h> #include "overlayfs.h" #include "../internal.h" /* for sb_init_dio_done_wq */
include/linux/backing-file.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Common helpers for stackable filesystems and backing files. +* +* Copyright (C) 2023 CTERA Networks. +*/ + +#ifndef _LINUX_BACKING_FILE_H +#define _LINUX_BACKING_FILE_H + +#include <linux/file.h> + +struct file *backing_file_open (const struct path *user_path,int flags, +const struct path *real_path, +const struct cred *cred); + +#endif /* _LINUX_BACKING_FILE_H */
include/linux/fs.h +0 -3
@@ -2575,9 +2575,6 @@ struct file *dentry_open(const struct path *path, int flags, const struct cred *creds);struct file *dentry_create (const struct path *path,int flags,umode_t mode,const struct cred *cred); -struct file *backing_file_open (const struct path *user_path,int flags, -const struct path *real_path, -const struct cred *cred);struct path *backing_file_user_path (struct file *f);/*
Signature · 1 line
2.34.1
Amir Goldstein
maintainerRFC PATCH 2/4 fs: factor out backing_file_{read,write}_iter() helpers
In reply to Amir GoldsteinOverlayfs submits files io to backing files on other filesystems. Factor out some common helpers to perform io to backing files, into fs/backing-file.c.
--- fs/backing-file.c | 204 +++++++++++++++++++++++++++++++++++ fs/overlayfs/file.c | 188 +++----------------------------- fs/overlayfs/overlayfs.h | 8 +- fs/overlayfs/super.c | 11 +- include/linux/backing-file.h | 15 +++ 5 files changed, 241 insertions(+), 185 deletions(-)
fs/backing-file.c +204 -0
@@ -2,6 +2,9 @@/* * Common helpers for stackable filesystems and backing files. * +* Forked from fs/overlayfs/file.c. +* +* Copyright (C) 2017 Red Hat, Inc. * Copyright (C) 2023 CTERA Networks. */
@@ -46,3 +49,204 @@ struct file *backing_file_open(const struct path *user_path, int flags,return f; }EXPORT_SYMBOL_GPL (backing_file_open); + +struct backing_aio { +struct kiocb iocb; +refcount_t ref; +struct kiocb *orig_iocb; +/* used for aio completion */ +void (*end_write)(struct file *); +struct work_struct work; +long res; +}; + +static struct kmem_cache *backing_aio_cachep; + +#define BACKING_IOCB_MASK \ + (IOCB_NOWAIT | IOCB_HIPRI | IOCB_DSYNC | IOCB_SYNC | IOCB_APPEND) + +static rwf_t iocb_to_rw_flags (int flags) +{ +return (__force rwf_t)(flags &BACKING_IOCB_MASK ); +} + +static void backing_aio_put (struct backing_aio *aio) +{ +if (refcount_dec_and_test (&aio->ref)) { +fput (aio->iocb.ki_filp); +kmem_cache_free (backing_aio_cachep, aio); + } +} + +static void backing_aio_cleanup (struct backing_aio *aio,long res) +{ +struct kiocb *iocb = &aio->iocb; +struct kiocb *orig_iocb = aio->orig_iocb; + +if (aio->end_write) + aio->end_write (orig_iocb->ki_filp); + + orig_iocb->ki_pos = iocb->ki_pos; +backing_aio_put (aio); +} + +static void backing_aio_rw_complete (struct kiocb *iocb,long res) +{ + struct backing_aio *aio = container_of(iocb, struct backing_aio, iocb); +struct kiocb *orig_iocb = aio->orig_iocb; + +if (iocb->ki_flags &IOCB_WRITE ) +kiocb_end_write (iocb); + +backing_aio_cleanup (aio, res); + orig_iocb->ki_complete (orig_iocb, res); +} + +static void backing_aio_complete_work (struct work_struct *work) +{ + struct backing_aio *aio = container_of(work, struct backing_aio, work); + +backing_aio_rw_complete (&aio->iocb, aio->res); +} + +static void backing_aio_queue_completion (struct kiocb *iocb,long res) +{ + struct backing_aio *aio = container_of(iocb, struct backing_aio, iocb); + +/* +* Punt to a work queue to serialize updates of mtime/size. +*/ + aio->res = res; +INIT_WORK (&aio->work, backing_aio_complete_work); +queue_work (file_inode (aio->orig_iocb->ki_filp)->i_sb->s_dio_done_wq, + &aio->work); +} + +static int backing_aio_init_wq (struct kiocb *iocb) +{ +struct super_block *sb =file_inode (iocb->ki_filp)->i_sb; + +if (sb->s_dio_done_wq) +return 0 ; + +return sb_init_dio_done_wq (sb); +} + + +ssize_t backing_file_read_iter (struct file *file,struct iov_iter *iter, +struct kiocb *iocb,int flags, +struct backing_file_ctx *ctx) +{ +struct backing_aio *aio =NULL ; +const struct cred *old_cred; +ssize_t ret; + +if (!iov_iter_count (iter)) +return 0 ; + +if (iocb->ki_flags &IOCB_DIRECT && + !(file->f_mode &FMODE_CAN_ODIRECT )) +return -EINVAL ; + + old_cred =override_creds (ctx->cred); +if (is_sync_kiocb (iocb)) { +rwf_t rwf =iocb_to_rw_flags (flags); + + ret =vfs_iter_read (file, iter, &iocb->ki_pos, rwf); + }else { + ret = -ENOMEM ; + aio =kmem_cache_zalloc (backing_aio_cachep,GFP_KERNEL ); +if (!aio) + goto out; + + aio->orig_iocb = iocb; +kiocb_clone (&aio->iocb, iocb,get_file (file)); + aio->iocb.ki_complete = backing_aio_rw_complete; +refcount_set (&aio->ref,2 ); + ret =vfs_iocb_iter_read (file, &aio->iocb, iter); +backing_aio_put (aio); +if (ret != -EIOCBQUEUED ) +backing_aio_cleanup (aio, ret); + } +out: +revert_creds (old_cred); + +if (ctx->accessed) + ctx->accessed (ctx->user_file); + +return ret; +} +EXPORT_SYMBOL_GPL (backing_file_read_iter); + +ssize_t backing_file_write_iter (struct file *file,struct iov_iter *iter, +struct kiocb *iocb,int flags, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +ssize_t ret; + +if (!iov_iter_count (iter)) +return 0 ; + + ret =file_remove_privs (ctx->user_file); +if (ret) +return ret; + +if (iocb->ki_flags &IOCB_DIRECT && + !(file->f_mode &FMODE_CAN_ODIRECT )) +return -EINVAL ; + +/* +* Stacked filesystems don't support deferred completions, don't copy +* this property in case it is set by the issuer. +*/ + flags &= ~IOCB_DIO_CALLER_COMP ; + + old_cred =override_creds (ctx->cred); +if (is_sync_kiocb (iocb)) { +rwf_t rwf =iocb_to_rw_flags (flags); + + ret =vfs_iter_write (file, iter, &iocb->ki_pos, rwf); +if (ctx->end_write) + ctx->end_write (ctx->user_file); + }else { +struct backing_aio *aio; + + ret =backing_aio_init_wq (iocb); +if (ret) + goto out; + + ret = -ENOMEM ; + aio =kmem_cache_zalloc (backing_aio_cachep,GFP_KERNEL ); +if (!aio) + goto out; + + aio->orig_iocb = iocb; + aio->end_write = ctx->end_write; +kiocb_clone (&aio->iocb, iocb,get_file (file)); + aio->iocb.ki_flags = flags; + aio->iocb.ki_complete = backing_aio_queue_completion; +refcount_set (&aio->ref,2 ); + ret =vfs_iocb_iter_write (file, &aio->iocb, iter); +backing_aio_put (aio); +if (ret != -EIOCBQUEUED ) +backing_aio_cleanup (aio, ret); + } +out: +revert_creds (old_cred); + +return ret; +} +EXPORT_SYMBOL_GPL (backing_file_write_iter); + +static int __init backing_aio_init (void ) +{ + backing_aio_cachep =kmem_cache_create ("backing_aio" , +sizeof (struct backing_aio ), +0 ,SLAB_HWCACHE_ALIGN ,NULL ); +if (!backing_aio_cachep) +return -ENOMEM ; + +return 0 ; +} +fs_initcall (backing_aio_init);
fs/overlayfs/file.c +13 -175
239 lines not on this page · raw message
fs/overlayfs/overlayfs.h +6 -2
@@ -425,6 +425,12 @@ int ovl_want_write(struct dentry *dentry);void ovl_drop_write (struct dentry *dentry);struct dentry *ovl_workdir (struct dentry *dentry);const struct cred *ovl_override_creds (struct super_block *sb); + +static inline const struct cred *ovl_creds (struct super_block *sb) +{ +return OVL_FS (sb)->creator_cred; +} +int ovl_can_decode_fh (struct super_block *sb);struct dentry *ovl_indexdir (struct super_block *sb);bool ovl_index_all (struct super_block *sb);
@@ -837,8 +843,6 @@ struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct dentry *workdir,/* file.c */ extern const struct file_operations ovl_file_operations; -int __init ovl_aio_request_cache_init (void ); -void ovl_aio_request_cache_destroy (void );int ovl_real_fileattr_get (const struct path *realpath,struct fileattr *fa);int ovl_real_fileattr_set (const struct path *realpath,struct fileattr *fa);int ovl_fileattr_get (struct dentry *dentry,struct fileattr *fa);
fs/overlayfs/super.c +3 -8
@@ -1500,14 +1500,10 @@ static int __init ovl_init(void)if (ovl_inode_cachep ==NULL )return -ENOMEM ; - err =ovl_aio_request_cache_init (); -if (!err) { - err =register_filesystem (&ovl_fs_type); -if (!err) -return 0 ; + err =register_filesystem (&ovl_fs_type); +if (!err) +return 0 ; -ovl_aio_request_cache_destroy (); - }kmem_cache_destroy (ovl_inode_cachep);return err;
@@ -1523,7 +1519,6 @@ static void __exit ovl_exit(void)*/ rcu_barrier ();kmem_cache_destroy (ovl_inode_cachep); -ovl_aio_request_cache_destroy (); }module_init (ovl_init);
include/linux/backing-file.h +15 -0
@@ -9,9 +9,24 @@#define _LINUX_BACKING_FILE_H#include <linux/file.h> +#include <linux/uio.h> +#include <linux/fs.h> + +struct backing_file_ctx { +const struct cred *cred; +struct file *user_file; +void (*accessed)(struct file *); +void (*end_write)(struct file *); +};struct file *backing_file_open (const struct path *user_path,int flags,const struct path *real_path,const struct cred *cred); +ssize_t backing_file_read_iter (struct file *file,struct iov_iter *iter, +struct kiocb *iocb,int flags, +struct backing_file_ctx *ctx); +ssize_t backing_file_write_iter (struct file *file,struct iov_iter *iter, +struct kiocb *iocb,int flags, +struct backing_file_ctx *ctx);#endif /* _LINUX_BACKING_FILE_H */
Signature · 1 line
2.34.1
Amir Goldstein
maintainerRFC PATCH 3/4 fs: factor out backing_file_splice_{read,write}() helpers
In reply to Amir GoldsteinThere is not much in those helpers, but it makes sense to have them logically next to the backing_file_{read,write}_iter() helpers as they may grow more common logic in the future.
--- fs/backing-file.c | 45 ++++++++++++++++++++++++++++++++++++ fs/overlayfs/file.c | 33 +++++++++++--------------- include/linux/backing-file.h | 8 +++++++ 3 files changed, 66 insertions(+), 20 deletions(-)
fs/backing-file.c +45 -0
@@ -10,6 +10,7 @@#include <linux/fs.h> #include <linux/backing-file.h> +#include <linux/splice.h> #include "internal.h"
@@ -239,6 +240,50 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter, }EXPORT_SYMBOL_GPL (backing_file_write_iter); +ssize_t backing_file_splice_read (struct file *in,loff_t *ppos, +struct pipe_inode_info *pipe,size_t len, +unsigned int flags, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +ssize_t ret; + + old_cred =override_creds (ctx->cred); + ret =vfs_splice_read (in, ppos, pipe, len, flags); +revert_creds (old_cred); + +if (ctx->accessed) + ctx->accessed (ctx->user_file); + +return ret; +} +EXPORT_SYMBOL_GPL (backing_file_splice_read); + +ssize_t backing_file_splice_write (struct pipe_inode_info *pipe, +struct file *out,loff_t *ppos,size_t len, +unsigned int flags, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +ssize_t ret; + + ret =file_remove_privs (ctx->user_file); +if (ret) +return ret; + + old_cred =override_creds (ctx->cred); +file_start_write (out); + ret =iter_file_splice_write (pipe, out, ppos, len, flags); +file_end_write (out); +revert_creds (old_cred); + +if (ctx->end_write) + ctx->end_write (ctx->user_file); + +return ret; +} +EXPORT_SYMBOL_GPL (backing_file_splice_write); +static int __init backing_aio_init (void ) { backing_aio_cachep = kmem_cache_create("backing_aio",
fs/overlayfs/file.c +13 -20
@@ -9,7 +9,6 @@#include <linux/xattr.h> #include <linux/uio.h> #include <linux/uaccess.h> -#include <linux/splice.h> #include <linux/security.h> #include <linux/mm.h> #include <linux/fs.h>
@@ -332,20 +331,21 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { - const struct cred *old_cred; struct fd real;ssize_t ret; +struct backing_file_ctx ctx = { + .cred =ovl_creds (file_inode (in)->i_sb), + .user_file = in, + .accessed = ovl_file_accessed, + }; ret =ovl_real_fdget (in, &real);if (ret)return ret; - old_cred =ovl_override_creds (file_inode (in)->i_sb); - ret =vfs_splice_read (real.file, ppos, pipe, len, flags); -revert_creds (old_cred); -ovl_file_accessed (in); - + ret =backing_file_splice_read (real.file, ppos, pipe, len, flags, &ctx);fdput (real); +return ret; }
@@ -361,30 +361,23 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, loff_t *ppos, size_t len, unsigned int flags) { struct fd real; -const struct cred *old_cred;struct inode *inode =file_inode (out);ssize_t ret; +struct backing_file_ctx ctx = { + .cred =ovl_creds (inode->i_sb), + .user_file = out, + .end_write = ovl_file_modified, + };inode_lock (inode);/* Update mode */ ovl_copyattr (inode); - ret =file_remove_privs (out); -if (ret) - goto out_unlock; ret =ovl_real_fdget (out, &real);if (ret) goto out_unlock; - old_cred =ovl_override_creds (inode->i_sb); -file_start_write (real.file); - - ret =iter_file_splice_write (pipe, real.file, ppos, len, flags); - -file_end_write (real.file); -/* Update size */ -ovl_file_modified (out); -revert_creds (old_cred); + ret =backing_file_splice_write (pipe, real.file, ppos, len, flags, &ctx);fdput (real); out_unlock:
include/linux/backing-file.h +8 -0
@@ -28,5 +28,13 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,ssize_t backing_file_write_iter (struct file *file,struct iov_iter *iter,struct kiocb *iocb,int flags,struct backing_file_ctx *ctx); +ssize_t backing_file_splice_read (struct file *in,loff_t *ppos, +struct pipe_inode_info *pipe,size_t len, +unsigned int flags, +struct backing_file_ctx *ctx); +ssize_t backing_file_splice_write (struct pipe_inode_info *pipe, +struct file *out,loff_t *ppos,size_t len, +unsigned int flags, +struct backing_file_ctx *ctx);#endif /* _LINUX_BACKING_FILE_H */
Signature · 1 line
2.34.1
Amir Goldstein
maintainerRFC PATCH 4/4 fs: factor out backing_file_mmap() helper
In reply to Amir GoldsteinAssert that the file object is allocated in a backing_file container so that file_user_path() could be used to display the user path and not the backing file's path in /proc/<pid>/maps.
--- fs/backing-file.c | 27 +++++++++++++++++++++++++++ fs/overlayfs/file.c | 23 ++++++----------------- include/linux/backing-file.h | 2 ++ 3 files changed, 35 insertions(+), 17 deletions(-)
fs/backing-file.c +27 -0
@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/backing-file.h> #include <linux/splice.h> +#include <linux/mm.h> #include "internal.h"
@@ -284,6 +285,32 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, }EXPORT_SYMBOL_GPL (backing_file_splice_write); +int backing_file_mmap (struct file *file,struct vm_area_struct *vma, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +int ret; + +if (WARN_ON_ONCE (!(file->f_mode &FMODE_BACKING )) || +WARN_ON_ONCE (ctx->user_file != vma->vm_file)) +return -EIO ; + +if (!file->f_op->mmap) +return -ENODEV ; + +vma_set_file (vma, file); + + old_cred =override_creds (ctx->cred); + ret =call_mmap (vma->vm_file, vma); +revert_creds (old_cred); + +if (ctx->accessed) + ctx->accessed (ctx->user_file); + +return ret; +} +EXPORT_SYMBOL_GPL (backing_file_mmap); +static int __init backing_aio_init (void ) { backing_aio_cachep = kmem_cache_create("backing_aio",
fs/overlayfs/file.c +6 -17
@@ -10,7 +10,6 @@#include <linux/uio.h> #include <linux/uaccess.h> #include <linux/security.h> -#include <linux/mm.h> #include <linux/fs.h> #include <linux/backing-file.h> #include "overlayfs.h"
@@ -415,23 +414,13 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)static int ovl_mmap (struct file *file,struct vm_area_struct *vma) {struct file *realfile = file->private_data; -const struct cred *old_cred; -int ret; - -if (!realfile->f_op->mmap) -return -ENODEV ; - -if (WARN_ON (file != vma->vm_file)) -return -EIO ; - -vma_set_file (vma, realfile); - - old_cred =ovl_override_creds (file_inode (file)->i_sb); - ret =call_mmap (vma->vm_file, vma); -revert_creds (old_cred); -ovl_file_accessed (file); +struct backing_file_ctx ctx = { + .cred =ovl_creds (file_inode (file)->i_sb), + .user_file = file, + .accessed = ovl_file_accessed, + }; -return ret; +return backing_file_mmap (realfile, vma, &ctx); }static long ovl_fallocate (struct file *file,int mode,loff_t offset,loff_t len)
include/linux/backing-file.h +2 -0
@@ -36,5 +36,7 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, struct file *out, loff_t *ppos, size_t len, unsigned int flags, struct backing_file_ctx *ctx); +int backing_file_mmap (struct file *file,struct vm_area_struct *vma, +struct backing_file_ctx *ctx);#endif /* _LINUX_BACKING_FILE_H */
Signature · 1 line
2.34.1
Christian Brauner
maintainerRe: [RFC][PATCH 4/4] fs: factor out backing_file_mmap() helper
Quoted 24 lines · Amir Goldstein
Assert that the file object is allocated in a
backing_filecontainer so thatfile_user_path()could be used to display the user path and not the backing file's path in /proc/<pid>/maps.Signed-off-by Amir Goldstein <[email protected]>--- fs/backing-file.c | 27 +++++++++++++++++++++++++++ fs/overlayfs/file.c | 23 ++++++----------------- include/linux/backing-file.h | 2 ++ 3 files changed, 35 insertions(+), 17 deletions(-)fs/backing-file.c +1
-0@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/backing-file.h> #include <linux/splice.h> +#include <linux/mm.h> #include "internal.h"
fs/backing-file.c ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, · line 294
Quoted 10 lines
fs/backing-file.c +7
-0@@ -284,6 +285,32 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, }EXPORT_SYMBOL_GPL (backing_file_splice_write); +int backing_file_mmap (struct file *file,struct vm_area_struct *vma, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +int ret; + + if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||
Couldn't that WARN_ON_ONCE() be in every one of these helpers in this series? IOW, when would you ever want to use a backing_file_*() helper on a non-backing file?
Amir Goldstein
maintainerRe: [RFC][PATCH 4/4] fs: factor out backing_file_mmap() helper
Quoted 29 lines · Christian Brauner
Quoted 27 lines · Amir Goldstein
Assert that the file object is allocated in a
backing_filecontainer so thatfile_user_path()could be used to display the user path and not the backing file's path in /proc/<pid>/maps.Signed-off-by Amir Goldstein <[email protected]>--- fs/backing-file.c | 27 +++++++++++++++++++++++++++ fs/overlayfs/file.c | 23 ++++++----------------- include/linux/backing-file.h | 2 ++ 3 files changed, 35 insertions(+), 17 deletions(-)fs/backing-file.c +1
-0@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/backing-file.h> #include <linux/splice.h> +#include <linux/mm.h> #include "internal.h" @@ -284,6 +285,32 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, }EXPORT_SYMBOL_GPL (backing_file_splice_write);
Quoted 11 lines
fs/backing-file.c ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, · line 294
Quoted 7 lines
fs/backing-file.c +7
-0+int backing_file_mmap (struct file *file,struct vm_area_struct *vma, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +int ret; + + if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||Couldn't that
WARN_ON_ONCE()be in every one of these helpers in this series? IOW, when would you ever want to use a backing_file_*() helper on a non-backing file?
AFAIK, the call chain below backing_file_splice*() and backing_file_*_iter() helpers never end up accessing file_user_path() or assuming that fd of file is installed in fd table, so there is no strong reason to enforce this with an assertion.
We can do it for clarity of semantics, in case one of the call chains will start assuming a struct backing_file in the future. WDIT?
Thanks,
Amir.
Amir Goldstein
maintainerRe: [RFC][PATCH 4/4] fs: factor out backing_file_mmap() helper
Quoted 43 lines · Amir Goldstein
Quoted 29 lines · Christian Brauner
Quoted 27 lines · Amir Goldstein
Assert that the file object is allocated in a
backing_filecontainer so thatfile_user_path()could be used to display the user path and not the backing file's path in /proc/<pid>/maps.Signed-off-by Amir Goldstein <[email protected]>--- fs/backing-file.c | 27 +++++++++++++++++++++++++++ fs/overlayfs/file.c | 23 ++++++----------------- include/linux/backing-file.h | 2 ++ 3 files changed, 35 insertions(+), 17 deletions(-)fs/backing-file.c +1
-0@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/backing-file.h> #include <linux/splice.h> +#include <linux/mm.h> #include "internal.h" @@ -284,6 +285,32 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, }EXPORT_SYMBOL_GPL (backing_file_splice_write);Quoted 11 lines
fs/backing-file.c ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, · line 294
Quoted 7 lines
fs/backing-file.c +7
-0+int backing_file_mmap (struct file *file,struct vm_area_struct *vma, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +int ret; + + if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||Couldn't that
WARN_ON_ONCE()be in every one of these helpers in this series? IOW, when would you ever want to use a backing_file_*() helper on a non-backing file?
Quoted 7 lines
AFAIK, the call chain below backing_file_splice*() and backing_file_*_iter() helpers never end up accessing
file_user_path()or assuming that fd of file is installed in fd table, so there is no strong reason to enforce this with an assertion.We can do it for clarity of semantics, in case one of the call chains will start assuming a struct
backing_filein the future. WDIT?
Doh! WDYT?
Thanks,
Amir.
Christian Brauner
maintainerRe: [RFC][PATCH 4/4] fs: factor out backing_file_mmap() helper
Quoted 44 lines · Amir Goldstein
Quoted 43 lines · Amir Goldstein
Quoted 40 lines · Christian Brauner
Quoted 24 lines · Amir Goldstein
Assert that the file object is allocated in a
backing_filecontainer so thatfile_user_path()could be used to display the user path and not the backing file's path in /proc/<pid>/maps.Signed-off-by Amir Goldstein <[email protected]>--- fs/backing-file.c | 27 +++++++++++++++++++++++++++ fs/overlayfs/file.c | 23 ++++++----------------- include/linux/backing-file.h | 2 ++ 3 files changed, 35 insertions(+), 17 deletions(-)fs/backing-file.c +1
-0@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/backing-file.h> #include <linux/splice.h> +#include <linux/mm.h> #include "internal.h" fs/backing-file.c ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, · line 294
Quoted 10 lines
fs/backing-file.c +7
-0@@ -284,6 +285,32 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, }EXPORT_SYMBOL_GPL (backing_file_splice_write); +int backing_file_mmap (struct file *file,struct vm_area_struct *vma, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +int ret; + + if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||Couldn't that
WARN_ON_ONCE()be in every one of these helpers in this series? IOW, when would you ever want to use a backing_file_*() helper on a non-backing file?
Quoted 4 lines
Quoted 4 lines
AFAIK, the call chain below backing_file_splice*() and backing_file_*_iter() helpers never end up accessing
file_user_path()or assuming that fd of file is installed in fd table, so there is no strong reason to enforce this with an assertion.
Yeah, but you do use an override_cred() call and you do have that backing_file_ctx. It smells like a bug if anyone would pass in a non-backing file.
Quoted 5 lines
Quoted 3 lines
We can do it for clarity of semantics, in case one of the call chains will start assuming a struct
backing_filein the future. WDIT?Doh! WDYT?
I'd add it as the whole series is predicated on this being used for backing files.
Amir Goldstein
maintainerRe: [RFC][PATCH 4/4] fs: factor out backing_file_mmap() helper
Quoted 56 lines · Christian Brauner
Quoted 44 lines · Amir Goldstein
Quoted 43 lines · Amir Goldstein
Quoted 40 lines · Christian Brauner
Quoted 24 lines · Amir Goldstein
Assert that the file object is allocated in a
backing_filecontainer so thatfile_user_path()could be used to display the user path and not the backing file's path in /proc/<pid>/maps.Signed-off-by Amir Goldstein <[email protected]>--- fs/backing-file.c | 27 +++++++++++++++++++++++++++ fs/overlayfs/file.c | 23 ++++++----------------- include/linux/backing-file.h | 2 ++ 3 files changed, 35 insertions(+), 17 deletions(-)fs/backing-file.c +1
-0@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/backing-file.h> #include <linux/splice.h> +#include <linux/mm.h> #include "internal.h" fs/backing-file.c ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, · line 294
Quoted 10 lines
fs/backing-file.c +7
-0@@ -284,6 +285,32 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, }EXPORT_SYMBOL_GPL (backing_file_splice_write); +int backing_file_mmap (struct file *file,struct vm_area_struct *vma, +struct backing_file_ctx *ctx) +{ +const struct cred *old_cred; +int ret; + + if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||Couldn't that
WARN_ON_ONCE()be in every one of these helpers in this series? IOW, when would you ever want to use a backing_file_*() helper on a non-backing file?Quoted 4 lines
Quoted 4 lines
AFAIK, the call chain below backing_file_splice*() and backing_file_*_iter() helpers never end up accessing
file_user_path()or assuming that fd of file is installed in fd table, so there is no strong reason to enforce this with an assertion.Yeah, but you do use an
override_cred()call and you do have thatbacking_file_ctx. It smells like a bug if anyone would pass in a non-backing file.Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
We can do it for clarity of semantics, in case one of the call chains will start assuming a struct
backing_filein the future. WDIT?Doh! WDYT?
I'd add it as the whole series is predicated on this being used for backing files.
Sure. Will do.
Thanks,
Amir.
Christian Brauner
maintainerQuoted 1 line
If I do that, would you preffer to take these patches via the vfs tree
I would prefer if you:
* Add the vfs infrastructure stuff on top of what's in vfs.file. There's also currently a conflict between this series and what's in there.
* Pull vfs.file into overlayfs.
* Port overlayfs to the new infrastructure.
io_uring already depends on vfs.file as well.
If this is straightforward I can include it in v6.8. The VFS prs will go out the week before January 7.
Amir Goldstein
maintainerQuoted 7 lines · Christian Brauner
Quoted 2 lines
If I do that, would you preffer to take these patches via the vfs tree
I would prefer if you:
* Add the vfs infrastructure stuff on top of what's in vfs.file. There's also currently a conflict between this series and what's in there.
I did not notice any actual conflicts with vfs.file. They do change the same files, but nothing that git can't handle. Specifically, FMODE_BACKING was excepted from the fput() changes, so also no logic changes that I noticed.
The only conflict I know of is with the vfs.rw branch, the move of *_start_write() into *__iter_write(), therefore, these patches are already based on top of vfs.rw.
I've just pushed branch backing_file rebased over both vfs.rw and vfs.file to:
https://github.com/amir73il/linux/commits/backing_file
Started to run overlayfs tests to see if vfs.file has unforeseen impact that I missed in review.
Quoted 3 lines
* Pull vfs.file into overlayfs.
* Port overlayfs to the new infrastructure.
Wait, do you mean add the backing_file_*() helpers and only then convert overlayfs to use them?
I think that would be harder to review (also in retrospect) so the "factor out ... helper" patches that move code from overlayfs to fs/backing_file.c are easier to follow.
Or did you mean something else?
Quoted 4 lines
io_uringalready depends on vfs.file as well.If this is straightforward I can include it in v6.8. The VFS prs will go out the week before January 7.
Well, unless I misunderstood you, that was straightforward. The only complexity is the order and dependency among the PRs.
If I am not mistaken, backing_file could be applied directly on top of vfs.rw and sent right after it, or along with it (via your tree)?
If I am not mistaken, backing_file is independent of vfs.file, but surely it could be sent after vfs.file.
The changes I currently have in overlayfs-next for 6.8 are very mild and do not conflict with any of the aforementioned work.
If you prefer that I send the PR for backing_file via overlayfs tree, I can do that, even in the second part of the merge window, after vfs.file and vfs.rw are merged, but in that case, I would like to be able to treat vfs.rw and stable from here on, so that I can pull it into overlayfs-next and put backing_file to soak in linux-next.
Let me know how you want to deal with that.
Thanks,
Amir.
Christian Brauner
maintainerQuoted 6 lines · Amir Goldstein
Quoted 5 lines · Christian Brauner
Quoted 2 lines
If I do that, would you preffer to take these patches via the vfs tree
I would prefer if you:
Quoted 7 lines
Quoted 2 lines
* Add the vfs infrastructure stuff on top of what's in vfs.file. There's also currently a conflict between this series and what's in there.
I did not notice any actual conflicts with vfs.file. They do change the same files, but nothing that git can't handle. Specifically,
FMODE_BACKINGwas excepted from thefput()changes, so also no logic changes that I noticed.
Huh, let me retry while writing this mail:
✓ [PATCH RFC 1/4] fs: prepare for stackable filesystems backing file helpers
+ Link: https://lore.kernel.org/r/[email protected]
+ Signed-off-by: Christian Brauner <[email protected]>
✓ [PATCH RFC 2/4] fs: factor out backing_file_{read,write}_iter() helpers
+ Link: https://lore.kernel.org/r/[email protected]
+ Signed-off-by: Christian Brauner <[email protected]>
✓ [PATCH RFC 3/4] fs: factor out backing_file_splice_{read,write}() helpers
+ Link: https://lore.kernel.org/r/[email protected]
+ Signed-off-by: Christian Brauner <[email protected]>
✓ [PATCH RFC 4/4] fs: factor out backing_file_mmap() helper
+ Link: https://lore.kernel.org/r/[email protected]
+ Signed-off-by: Christian Brauner <[email protected]>
---
✓ Signed: DKIM/gmail.com
---
Total patches: 4
---
Applying: fs: prepare for stackable filesystems backing file helpers
Applying: fs: factor out backing_file_{read,write}_iter() helpers Patch failed at 0002 fs: factor out backing_file_{read,write}_iter() helpers When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
error: sha1 information is lacking or useless (fs/overlayfs/file.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Ok, I see that I didn't include your branch so git got confused by missing overlayfs changes that you have in your tree and thus failed to apply here.
Quoted 4 lines
The only conflict I know of is with the vfs.rw branch, the move of
*_start_write()into*__iter_write(), therefore, these patches are already based on top of vfs.rw.
Aha, there we go.
Quoted 12 lines
I've just pushed branch
backing_filerebased over both vfs.rw and vfs.file to:
https://github.com/amir73il/linux/commits/backing_fileStarted to run overlayfs tests to see if vfs.file has unforeseen impact that I missed in review.
Quoted 3 lines
* Pull vfs.file into overlayfs.
* Port overlayfs to the new infrastructure.
Quoted 6 lines
Wait, do you mean add the backing_file_*() helpers and only then convert overlayfs to use them?
I think that would be harder to review (also in retrospect) so the "factor out ... helper" patches that move code from overlayfs to
fs/backing_file.care easier to follow.
It depends. Here I think it's a bit similar to David's netfs library stuff where a bunch of infra is added. Then the conversion is on top of that. However, I have no mandatory rule here.
Quoted 5 lines
Or did you mean something else?
Quoted 2 lines
io_uringalready depends on vfs.file as well.
Quoted 8 lines
Quoted 2 lines
If this is straightforward I can include it in v6.8. The VFS prs will go out the week before January 7.
Well, unless I misunderstood you, that was straightforward. The only complexity is the order and dependency among the PRs.
If I am not mistaken,
backing_filecould be applied directly on top of vfs.rw and sent right after it, or along with it (via your tree)?
Along with it.