fuse: Mirror virtio-fs submounts
Subsystems (2)
cover fuse: Mirror virtio-fs submounts
RFC: https://www.redhat.com/archives/virtio-fs/2020-May/msg00018.html
Branch: https://github.com/XanClic/linux.git virtiofs-submounts-v2
(Note that there is an accompanying QEMU series
“virtiofsd: Announce submounts to the guest”;
https://www.redhat.com/archives/virtio-fs/2020-September/msg00016.html)
Hi,
When using virtio-fs, we want all nodes that have a unique st_dev/st_ino combination on the host to have such a unique combination in the guest as well. To do so, we introduce a flags field to fuse_attr, where virtiofsd can announce submounts. All such entries are then translated to auto-mounts by the FUSE driver in the guest.
Because this is something that we probably do not want to enable unconditionally for traditional FUSE servers, it is currently limited to virtio-fs.
(For virtio-fs, we can leave the decision of whether to enable this feature or not to virtiofsd, because with it residing on the host, it has higher privileges than the guest anyway.)
For this to do something useful, you need to apply the “virtiofsd:
Announce submounts to the guest” series to qemu (which also provides a test there).
Implementation-wise, this series splits off everything that is superblock-specific from fuse_conn into a new fuse_mount structure, so that a single fuse_conn can have multiple fuse_mounts and thus multiple superblocks. Each submount’s superblock then gets its own anonymous block device so the filesystem receives a unique st_dev value.
Max Reitz (9):
fuse: Add fuse_attr.flags
fuse: Add FUSE_ATTR_SUBMOUNT
fuse: Add FUSE_ATTR_FLAGS
fuse: Announce FUSE_ATTR_FLAGS
fuse: Store fuse_conn in fuse_req
fuse: Drop fuse_conn parameter where possible
fuse: Split fuse_mount off of fuse_conn
fuse: Allow fuse_fill_super_common() for submounts
fuse: Implement crossmounts
fs/fuse/fuse_i.h | 136 ++++++++++++++---- include/uapi/linux/fuse.h | 11 +- fs/fuse/control.c | 28 +++- fs/fuse/dev.c | 161 ++++++++++----------- fs/fuse/dir.c | 198 +++++++++++++++++++------- fs/fuse/file.c | 211 ++++++++++++++-------------- fs/fuse/inode.c | 288 +++++++++++++++++++++++++++++--------- fs/fuse/readdir.c | 10 +- fs/fuse/virtio_fs.c | 73 ++++++---- fs/fuse/xattr.c | 34 ++--- 10 files changed, 765 insertions(+), 385 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/9 fuse: Add fuse_attr.flags
This field (when present) can provide additional information about filesystem entries.
--- include/uapi/linux/fuse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/fuse.h +1 -1
@@ -231,7 +231,7 @@ struct fuse_attr {uint32_t gid;uint32_t rdev;uint32_t blksize; -uint32_t padding; +uint32_t flags; };struct fuse_kstatfs {
Signature · 1 line
2.26.2
Re: [Virtio-fs] [PATCH 1/9] fuse: Add fuse_attr.flags
Quoted 7 lines · Max Reitz
This field (when present) can provide additional information about filesystem entries.
Signed-off-by Max Reitz <[email protected]>--- include/uapi/linux/fuse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 2/9 fuse: Add FUSE_ATTR_SUBMOUNT
In reply to Max ReitzThis is a flag for fuse_attr.flags that indicates that the given entry resides on a different filesystem than the parent, and as such should have a different st_dev.
--- include/uapi/linux/fuse.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/uapi/linux/fuse.h +7 -0
@@ -417,6 +417,13 @@ struct fuse_file_lock {*/ #define FUSE_FSYNC_FDATASYNC (1 << 0) +/** +* fuse_attr flags +* +* FUSE_ATTR_SUBMOUNT: File/directory is a submount point +*/ +#define FUSE_ATTR_SUBMOUNT (1 << 0) +enum fuse_opcode {FUSE_LOOKUP =1 ,FUSE_FORGET =2 ,/* no reply */
Signature · 1 line
2.26.2
Stefan Hajnoczi
maintainerRe: [Virtio-fs] [PATCH 2/9] fuse: Add FUSE_ATTR_SUBMOUNT
Quoted 14 lines · Max Reitz
This is a flag for fuse_attr.flags that indicates that the given entry resides on a different filesystem than the parent, and as such should have a different
st_dev.Signed-off-by Max Reitz <[email protected]>--- include/uapi/linux/fuse.h | 7 +++++++ 1 file changed, 7 insertions(+)include/uapi/linux/fuse.h +0
-0
include/uapi/linux/fuse.h struct fuse_file_lock { · line 425
Quoted 9 lines
include/uapi/linux/fuse.h +6
-0@@ -417,6 +417,13 @@ struct fuse_file_lock {*/ #define FUSE_FSYNC_FDATASYNC (1 << 0) +/** +* fuse_attr flags +* +* FUSE_ATTR_SUBMOUNT: File/directory is a submount point +*/ +#define FUSE_ATTR_SUBMOUNT (1 << 0)
If you respin, please add a little more detail here. How should clients act when this flag is detected (which FUSE messages should they send to deal with submounts)?
Stefan
Miklos Szeredi
maintainerRe: [Virtio-fs] [fuse-devel] [PATCH 2/9] fuse: Add FUSE_ATTR_SUBMOUNT
Quoted 19 lines · Stefan Hajnoczi
Quoted 17 lines · Max Reitz
This is a flag for fuse_attr.flags that indicates that the given entry resides on a different filesystem than the parent, and as such should have a different
st_dev.Signed-off-by Max Reitz <[email protected]>--- include/uapi/linux/fuse.h | 7 +++++++ 1 file changed, 7 insertions(+)include/uapi/linux/fuse.h +0
-0@@ -417,6 +417,13 @@ struct fuse_file_lock {*/ #define FUSE_FSYNC_FDATASYNC (1 << 0)
Quoted 8 lines
include/uapi/linux/fuse.h struct fuse_file_lock { · line 425
Quoted 6 lines
include/uapi/linux/fuse.h +6
-0+/** +* fuse_attr flags +* +* FUSE_ATTR_SUBMOUNT: File/directory is a submount point +*/ +#define FUSE_ATTR_SUBMOUNT (1 << 0)If you respin, please add a little more detail here. How should clients
I'm just reviewing/queuing this, so no need to respin.
Quoted 2 lines
act when this flag is detected (which FUSE messages should they send to deal with submounts)?
Actually, no new messages, since the reply containing FUSE_ATTR_SUBMOUNT already refers to the submount root. I'll fix the description.
And since there's no separate information for the actual mount point (userspace can't obtain it) AT_NO_AUTOMOUNT users become confused due to the dummy mountpoint becoming visible with all the wrong data. Maybe the fix is to force automount even with AT_NO_AUTOMOUNT. Will look into that.
Thanks,
Miklos
Re: [Virtio-fs] [fuse-devel] [PATCH 2/9] fuse: Add FUSE_ATTR_SUBMOUNT
Quoted 29 lines · Miklos Szeredi
Quoted 19 lines · Stefan Hajnoczi
Quoted 17 lines · Max Reitz
This is a flag for fuse_attr.flags that indicates that the given entry resides on a different filesystem than the parent, and as such should have a different
st_dev.Signed-off-by Max Reitz <[email protected]>--- include/uapi/linux/fuse.h | 7 +++++++ 1 file changed, 7 insertions(+)include/uapi/linux/fuse.h +0
-0@@ -417,6 +417,13 @@ struct fuse_file_lock {*/ #define FUSE_FSYNC_FDATASYNC (1 << 0)Quoted 8 lines
include/uapi/linux/fuse.h struct fuse_file_lock { · line 425
Quoted 6 lines
include/uapi/linux/fuse.h +6
-0+/** +* fuse_attr flags +* +* FUSE_ATTR_SUBMOUNT: File/directory is a submount point +*/ +#define FUSE_ATTR_SUBMOUNT (1 << 0)If you respin, please add a little more detail here. How should clients
Quoted 8 lines
I'm just reviewing/queuing this, so no need to respin.
Quoted 2 lines
act when this flag is detected (which FUSE messages should they send to deal with submounts)?
Actually, no new messages, since the reply containing
FUSE_ATTR_SUBMOUNTalready refers to the submount root. I'll fix the description.
Perhaps it’s still useful to note how this flag is supposed to be handled; i.e. that it’s a hint to the kernel to create an auto-mounted submount.
Quoted 5 lines
And since there's no separate information for the actual mount point (userspace can't obtain it)
AT_NO_AUTOMOUNTusers become confused due to the dummy mountpoint becoming visible with all the wrong data. Maybe the fix is to force automount even withAT_NO_AUTOMOUNT. Will look into that.
If that’s possible... Though Dave did mention that it seems intentional that auto-mounts aren’t mounted on stat, so as not to overwhelm the system on a plain ls call.
Max
Miklos Szeredi
maintainerRe: [Virtio-fs] [fuse-devel] [PATCH 2/9] fuse: Add FUSE_ATTR_SUBMOUNT
Quoted 50 lines · Max Reitz
Quoted 29 lines · Miklos Szeredi
Quoted 19 lines · Stefan Hajnoczi
Quoted 17 lines · Max Reitz
This is a flag for fuse_attr.flags that indicates that the given entry resides on a different filesystem than the parent, and as such should have a different
st_dev.Signed-off-by Max Reitz <[email protected]>--- include/uapi/linux/fuse.h | 7 +++++++ 1 file changed, 7 insertions(+)include/uapi/linux/fuse.h +0
-0@@ -417,6 +417,13 @@ struct fuse_file_lock {*/ #define FUSE_FSYNC_FDATASYNC (1 << 0)Quoted 8 lines
include/uapi/linux/fuse.h struct fuse_file_lock { · line 425
Quoted 6 lines
include/uapi/linux/fuse.h +6
-0+/** +* fuse_attr flags +* +* FUSE_ATTR_SUBMOUNT: File/directory is a submount point +*/ +#define FUSE_ATTR_SUBMOUNT (1 << 0)If you respin, please add a little more detail here. How should clients
Quoted 8 lines
I'm just reviewing/queuing this, so no need to respin.
Quoted 2 lines
act when this flag is detected (which FUSE messages should they send to deal with submounts)?
Actually, no new messages, since the reply containing
FUSE_ATTR_SUBMOUNTalready refers to the submount root. I'll fix the description.Perhaps it’s still useful to note how this flag is supposed to be handled; i.e. that it’s a hint to the kernel to create an auto-mounted submount.
Quoted 5 lines
And since there's no separate information for the actual mount point (userspace can't obtain it)
AT_NO_AUTOMOUNTusers become confused due to the dummy mountpoint becoming visible with all the wrong data. Maybe the fix is to force automount even withAT_NO_AUTOMOUNT. Will look into that.
Quoted 3 lines
If that’s possible... Though Dave did mention that it seems intentional that auto-mounts aren’t mounted on stat, so as not to overwhelm the system on a plain ls call.
Oh, this is subtle. Big automount maps (like a automounted home
directory on a muti-user server) definitely don't want automounts on an ls. Static mounts being exported to virtiofs probably won't result in an automount storm, but would benefit from find being less broken.
If on the other hand virtiofs is re-exporting a big automount map, then it would make sense to inherit this behavior. But at this stage that's just overdesign.
For now let's just see how the current no-automount behavior works in real life.
Thanks,
Miklos
PATCH 3/9 fuse: Add FUSE_ATTR_FLAGS
In reply to Max ReitzThe client sets this flag when it expects fuse_attr.flags (instead of just padding). The server sets it when it will provide a proper value for it.
--- include/uapi/linux/fuse.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/fuse.h +2 -0
@@ -314,6 +314,7 @@ struct fuse_file_lock {* FUSE_NO_OPENDIR_SUPPORT: kernel supports zero-message opendir * FUSE_EXPLICIT_INVAL_DATA: only invalidate cached pages on explicit request * FUSE_MAP_ALIGNMENT: map_alignment field is valid +* FUSE_ATTR_FLAGS: fuse_attr.flags is present and valid */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -342,6 +343,7 @@ struct fuse_file_lock {#define FUSE_NO_OPENDIR_SUPPORT (1 << 24)#define FUSE_EXPLICIT_INVAL_DATA (1 << 25)#define FUSE_MAP_ALIGNMENT (1 << 26) +#define FUSE_ATTR_FLAGS (1 << 27)/** * CUSE INIT request/reply flags
Signature · 1 line
2.26.2
Re: [Virtio-fs] [PATCH 3/9] fuse: Add FUSE_ATTR_FLAGS
Quoted 8 lines · Max Reitz
The client sets this flag when it expects fuse_attr.flags (instead of just padding). The server sets it when it will provide a proper value for it.
Signed-off-by Max Reitz <[email protected]>--- include/uapi/linux/fuse.h | 2 ++ 1 file changed, 2 insertions(+)
PATCH 4/9 fuse: Announce FUSE_ATTR_FLAGS
In reply to Max ReitzWe do not have to interpret fuse_attr.flags, but we can let servers know that we do expect a value there.
--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/inode.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-)
fs/fuse/fuse_i.h +3 -0
@@ -720,6 +720,9 @@ struct fuse_conn {/* Do not show mount options */ unsigned int no_mount_options:1; +/* fuse_attr.flags is present and valid */ + unsigned int attr_flags:1; +/** The number of requests waiting for completion */ atomic_t num_waiting;
fs/fuse/inode.c +4 -1
@@ -965,6 +965,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_args *args, min_t(unsigned int, FUSE_MAX_MAX_PAGES, max_t(unsigned int, arg->max_pages, 1)); } +if (arg->flags &FUSE_ATTR_FLAGS ) + fc->attr_flags =1 ; }else { ra_pages = fc->max_read /PAGE_SIZE ; fc->no_lock =1 ;
@@ -1002,7 +1004,8 @@ void fuse_send_init(struct fuse_conn *fc)FUSE_WRITEBACK_CACHE |FUSE_NO_OPEN_SUPPORT |FUSE_PARALLEL_DIROPS |FUSE_HANDLE_KILLPRIV |FUSE_POSIX_ACL |FUSE_ABORT_ERROR |FUSE_MAX_PAGES |FUSE_CACHE_SYMLINKS | -FUSE_NO_OPENDIR_SUPPORT |FUSE_EXPLICIT_INVAL_DATA ; +FUSE_NO_OPENDIR_SUPPORT |FUSE_EXPLICIT_INVAL_DATA | +FUSE_ATTR_FLAGS ; ia->args.opcode =FUSE_INIT ; ia->args.in_numargs =1 ; ia->args.in_args[0 ].size =sizeof (ia->in);
Signature · 1 line
2.26.2
Re: [Virtio-fs] [PATCH 4/9] fuse: Announce FUSE_ATTR_FLAGS
Quoted 8 lines · Max Reitz
We do not have to interpret fuse_attr.flags, but we can let servers know that we do expect a value there.
Signed-off-by Max Reitz <[email protected]>--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/inode.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-)
PATCH 5/9 fuse: Store fuse_conn in fuse_req
In reply to Max ReitzEvery fuse_req belongs to a fuse_conn. Right now, we always know which fuse_conn that is based on the respective device, but we want to allow multiple (sub)mounts per single connection, and then the corresponding filesystem is not going to be so trivial to obtain.
Storing a pointer to the associated fuse_conn in every fuse_req will allow us to trivially find any request's superblock (and thus filesystem) even then.
--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/dev.c | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-)
fs/fuse/fuse_i.h +3 -0
@@ -360,6 +360,9 @@ struct fuse_req {/** virtio-fs's physically contiguous buffer for in and out args */ void *argbuf;#endif + +/** fuse_conn this request belongs to */ +struct fuse_conn *fc; };struct fuse_iqueue ;
fs/fuse/dev.c +7 -6
@@ -40,20 +40,21 @@ static struct fuse_dev *fuse_get_dev(struct file *file)return READ_ONCE (file->private_data); } -static void fuse_request_init (struct fuse_req *req) +static void fuse_request_init (struct fuse_conn *fc,struct fuse_req *req) {INIT_LIST_HEAD (&req->list);INIT_LIST_HEAD (&req->intr_entry);init_waitqueue_head (&req->waitq);refcount_set (&req->count,1 );__set_bit (FR_PENDING , &req->flags); + req->fc = fc; } -static struct fuse_req *fuse_request_alloc (gfp_t flags) +static struct fuse_req *fuse_request_alloc (struct fuse_conn *fc,gfp_t flags) {struct fuse_req *req =kmem_cache_zalloc (fuse_req_cachep, flags);if (req) -fuse_request_init (req); +fuse_request_init (fc, req);return req; }
@@ -125,7 +126,7 @@ static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background)if (fc->conn_error) goto out; - req =fuse_request_alloc (GFP_KERNEL ); + req =fuse_request_alloc (fc,GFP_KERNEL ); err = -ENOMEM ;if (!req) {if (for_background)
@@ -480,7 +481,7 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)if (args->force) {atomic_inc (&fc->num_waiting); - req =fuse_request_alloc (GFP_KERNEL | __GFP_NOFAIL); + req =fuse_request_alloc (fc,GFP_KERNEL | __GFP_NOFAIL);if (!args->nocreds)fuse_force_creds (fc, req);
@@ -547,7 +548,7 @@ int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,if (args->force) {WARN_ON (!args->nocreds); - req =fuse_request_alloc (gfp_flags); + req =fuse_request_alloc (fc, gfp_flags);if (!req)return -ENOMEM ;__set_bit (FR_BACKGROUND , &req->flags);
Signature · 1 line
2.26.2
Re: [Virtio-fs] [PATCH 5/9] fuse: Store fuse_conn in fuse_req
Quoted 9 lines · Max Reitz
Every
fuse_reqbelongs to afuse_conn. Right now, we always know whichfuse_connthat is based on the respective device, but we want to allow multiple (sub)mounts per single connection, and then the corresponding filesystem is not going to be so trivial to obtain.Storing a pointer to the associated
fuse_connin everyfuse_reqwill allow us to trivially find any request's superblock (and thus filesystem) even then.
Quoted 5 lines
Signed-off-by Max Reitz <[email protected]>--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/dev.c | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-)
PATCH 6/9 fuse: Drop fuse_conn parameter where possible
In reply to Max ReitzWith the last commit, all functions that handle some existing fuse_req no longer need to be given the associated fuse_conn, because they can get it from the fuse_req object.
--- fs/fuse/fuse_i.h | 2 +- fs/fuse/dev.c | 70 +++++++++++++++++++++++++-------------------- fs/fuse/virtio_fs.c | 8 ++---- 3 files changed, 43 insertions(+), 37 deletions(-)
fs/fuse/fuse_i.h +1 -1
@@ -929,7 +929,7 @@ int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,/** * End a finished request */ -void fuse_request_end (struct fuse_conn *fc,struct fuse_req *req); +void fuse_request_end (struct fuse_req *req);/* Abort all requests */ void fuse_abort_conn (struct fuse_conn *fc);
fs/fuse/dev.c +39 -31
228 lines not on this page · raw message
fs/fuse/virtio_fs.c +3 -5
@@ -289,7 +289,6 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work)struct fuse_req *req; struct virtio_fs_vq *fsvq = container_of(work, struct virtio_fs_vq, dispatch_work.work); -struct fuse_conn *fc = fsvq->fud->fc;int ret;pr_debug ("virtio-fs: worker %s called.\n" , __func__);
@@ -304,7 +303,7 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work)list_del_init (&req->list);spin_unlock (&fsvq->lock); -fuse_request_end (fc, req); +fuse_request_end (req); }/* Dispatch pending requests */
@@ -335,7 +334,7 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work)spin_unlock (&fsvq->lock);pr_err ("virtio-fs: virtio_fs_enqueue_req() failed %d\n" , ret); -fuse_request_end (fc, req); +fuse_request_end (req); } } }
@@ -495,7 +494,6 @@ static void virtio_fs_request_complete(struct fuse_req *req, struct virtio_fs_vq *fsvq) {struct fuse_pqueue *fpq = &fsvq->fud->pq; -struct fuse_conn *fc = fsvq->fud->fc;struct fuse_args *args;struct fuse_args_pages *ap;unsigned int len, i, thislen;
@@ -528,7 +526,7 @@ static void virtio_fs_request_complete(struct fuse_req *req,clear_bit (FR_SENT , &req->flags);spin_unlock (&fpq->lock); -fuse_request_end (fc, req); +fuse_request_end (req);spin_lock (&fsvq->lock);dec_in_flight_req (fsvq);spin_unlock (&fsvq->lock);
Signature · 1 line
2.26.2
Re: [Virtio-fs] [PATCH 6/9] fuse: Drop fuse_conn parameter where possible
Quoted 10 lines · Max Reitz
With the last commit, all functions that handle some existing
fuse_reqno longer need to be given the associatedfuse_conn, because they can get it from thefuse_reqobject.Signed-off-by Max Reitz <[email protected]>--- fs/fuse/fuse_i.h | 2 +- fs/fuse/dev.c | 70 +++++++++++++++++++++++++-------------------- fs/fuse/virtio_fs.c | 8 ++---- 3 files changed, 43 insertions(+), 37 deletions(-)
PATCH 7/9 fuse: Split fuse_mount off of fuse_conn
In reply to Max ReitzWe want to allow submounts for the same fuse_conn, but with different superblocks so that each of the submounts has its own device ID. To do so, we need to split all mount-specific information off of fuse_conn into a new fuse_mount structure, so that multiple mounts can share a single fuse_conn.
We need to take care only to perform connection-level actions once (i.e. when the fuse_conn and thus the first fuse_mount are established, or when the last fuse_mount and thus the fuse_conn are destroyed). For example, fuse_sb_destroy() must invoke fuse_send_destroy() until the last superblock is released.
To do so, we keep track of which fuse_mount is the root mount and perform all fuse_conn-level actions only when this fuse_mount is involved.
--- fs/fuse/fuse_i.h | 119 ++++++++++++++++++++----- fs/fuse/control.c | 28 ++++-- fs/fuse/dev.c | 106 +++++++++++----------- fs/fuse/dir.c | 111 +++++++++++------------ fs/fuse/file.c | 211 ++++++++++++++++++++++---------------------- fs/fuse/inode.c | 147 ++++++++++++++++++++++-------- fs/fuse/readdir.c | 10 +-- fs/fuse/virtio_fs.c | 62 ++++++++----- fs/fuse/xattr.c | 34 +++---- 9 files changed, 502 insertions(+), 326 deletions(-)
fs/fuse/fuse_i.h +95 -24
@@ -161,12 +161,13 @@ enum { };struct fuse_conn ; +struct fuse_mount ;struct fuse_release_args ;/** FUSE specific file data */ struct fuse_file {/** Fuse connection for this file */ -struct fuse_conn *fc; +struct fuse_mount *fm;/* Argument space reserved for release */ struct fuse_release_args *release_args;
@@ -252,7 +253,7 @@ struct fuse_args { bool may_block:1;struct fuse_in_arg in_args[3 ];struct fuse_arg out_args[2 ]; -void (*end)(struct fuse_conn *fc,struct fuse_args *args,int error); +void (*end)(struct fuse_mount *fm,struct fuse_args *args,int error); };struct fuse_args_pages {
@@ -361,8 +362,8 @@ struct fuse_req {void *argbuf;#endif -/** fuse_conn this request belongs to */ -struct fuse_conn *fc; +/** fuse_mount this request belongs to */ +struct fuse_mount *fm; };struct fuse_iqueue ;
@@ -497,9 +498,9 @@ struct fuse_fs_context {/** * A Fuse connection. * -* This structure is created, when the filesystem is mounted, and is -* destroyed, when the client device is closed and the filesystem is -* unmounted. +* This structure is created, when the root filesystem is mounted, and +* is destroyed, when the client device is closed and the last +* fuse_mount is destroyed. */ struct fuse_conn {/** Lock protecting accessess to members of this structure */
@@ -732,12 +733,9 @@ struct fuse_conn {/** Negotiated minor version */ unsigned minor; -/** Entry on the fuse_conn_list */ +/** Entry on the fuse_mount_list */ struct list_head entry; -/** Device ID from super block */ -dev_t dev; -/** Dentries in the control filesystem */ struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES ];
@@ -753,24 +751,71 @@ struct fuse_conn {/** Called on final put */ void (*release)(struct fuse_conn *); -/** Super block for this connection. */ -struct super_block *sb; - -/** Read/write semaphore to hold when accessing sb. */ +/** +* Read/write semaphore to hold when accessing the sb of any +* fuse_mount belonging to this connection +*/ struct rw_semaphore killsb;/** List of device instances belonging to this connection */ struct list_head devices; + +/** List of filesystems using this connection */ +struct list_head mounts; }; -static inline struct fuse_conn *get_fuse_conn_super (struct super_block *sb) +/** +* Represents a mounted filesystem, potentially a submount. +* +* This object allows sharing a fuse_conn between separate mounts to +* allow submounts with dedicated superblocks and thus separate device +* IDs. +*/ +struct fuse_mount { +/** Underlying (potentially shared) connection to the FUSE server */ +struct fuse_conn *fc; + +/** Refcount */ +refcount_t count; + +/** Device ID from super block */ +dev_t dev; + +/** +* Super block for this connection (fc->killsb must be held +* when accessing this). +*/ +struct super_block *sb; + +/** Entry on fc->mounts */ +struct list_head fc_entry; + +/** True for root mounts, false for submounts */ +bool root; +}; + +static inline struct fuse_mount *get_fuse_mount_super (struct super_block *sb) {return sb->s_fs_info; } +static inline struct fuse_conn *get_fuse_conn_super (struct super_block *sb) +{ +struct fuse_mount *fm =get_fuse_mount_super (sb); + +return fm ? fm->fc :NULL ; +} + +static inline struct fuse_mount *get_fuse_mount (struct inode *inode) +{ +return get_fuse_mount_super (inode->i_sb); +} +static inline struct fuse_conn *get_fuse_conn (struct inode *inode) { -return get_fuse_conn_super (inode->i_sb); +struct fuse_mount *fm =get_fuse_mount (inode); + +return fm ? fm->fc :NULL ; }static inline struct fuse_inode *get_fuse_inode (struct inode *inode)
@@ -854,7 +899,7 @@ void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,*/ int fuse_open_common (struct inode *inode,struct file *file,bool isdir); -struct fuse_file *fuse_file_alloc (struct fuse_conn *fc); +struct fuse_file *fuse_file_alloc (struct fuse_mount *fm);void fuse_file_free (struct fuse_file *ff);void fuse_finish_open (struct inode *inode,struct file *file);
@@ -922,8 +967,8 @@ void __exit fuse_ctl_cleanup(void);/** * Simple request sending that does request allocation and freeing */ -ssize_t fuse_simple_request (struct fuse_conn *fc,struct fuse_args *args); -int fuse_simple_background (struct fuse_conn *fc,struct fuse_args *args, +ssize_t fuse_simple_request (struct fuse_mount *fm,struct fuse_args *args); +int fuse_simple_background (struct fuse_mount *fm,struct fuse_args *args,gfp_t gfp_flags);/**
@@ -963,11 +1008,26 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,*/ void fuse_conn_put (struct fuse_conn *fc); +/** +* Acquire reference to fuse_mount +*/ +struct fuse_mount *fuse_mount_get (struct fuse_mount *fm); + +/** +* Initialize fuse_mount for a given fuse_conn +*/ +void fuse_mount_init (struct fuse_mount *fm,struct fuse_conn *fc,bool root); + +/** +* Release reference to fuse_mount +*/ +void fuse_mount_put (struct fuse_mount *fm); +struct fuse_dev *fuse_dev_alloc_install (struct fuse_conn *fc);struct fuse_dev *fuse_dev_alloc (void );void fuse_dev_install (struct fuse_dev *fud,struct fuse_conn *fc);void fuse_dev_free (struct fuse_dev *fud); -void fuse_send_init (struct fuse_conn *fc); +void fuse_send_init (struct fuse_mount *fm);/** * Fill in superblock and initialize fuse connection
@@ -1016,10 +1076,21 @@ void fuse_flush_writepages(struct inode *inode);void fuse_set_nowrite (struct inode *inode);void fuse_release_nowrite (struct inode *inode); +/** +* Scan all fuse_mounts belonging to fc to find the first where +* ilookup5() returns a result. Return that result and the +* respective fuse_mount in *fm (unless fm is NULL). +* +* The caller must hold fc->killsb. +*/ +struct inode *fuse_ilookup (struct fuse_conn *fc,unsigned long hashval, +int (*test)(struct inode *,void *), +void *data,struct fuse_mount **fm); +/** * File-system tells the kernel to invalidate cache for the given node id. */ -int fuse_reverse_inval_inode (struct super_block *sb,u64 nodeid, +int fuse_reverse_inval_inode (struct fuse_conn *fc,u64 nodeid,loff_t offset,loff_t len);/**
@@ -1032,10 +1103,10 @@ int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,* - is a file or oan empty directory * then the dentry is unhashed (d_delete()). */ -int fuse_reverse_inval_entry (struct super_block *sb,u64 parent_nodeid, +int fuse_reverse_inval_entry (struct fuse_conn *fc,u64 parent_nodeid,u64 child_nodeid,struct qstr *name); -int fuse_do_open (struct fuse_conn *fc,u64 nodeid,struct file *file, +int fuse_do_open (struct fuse_mount *fm,u64 nodeid,struct file *file,bool isdir);/**
fs/fuse/control.c +22 -6
@@ -164,6 +164,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file, {unsigned val;struct fuse_conn *fc; +struct fuse_mount *first_fm =NULL ;ssize_t ret; ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
@@ -176,13 +177,22 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,spin_lock (&fc->bg_lock); fc->congestion_threshold = val; -if (fc->sb) { + +/* +* Get any fuse_mount belonging to this fuse_conn; s_bdi is +* shared between all of them +*/ +if (!list_empty (&fc->mounts)) + first_fm = list_first_entry(&fc->mounts, struct fuse_mount, + fc_entry); + +if (first_fm && first_fm->sb) {if (fc->num_background < fc->congestion_threshold) { -clear_bdi_congested (fc->sb->s_bdi,BLK_RW_SYNC ); -clear_bdi_congested (fc->sb->s_bdi,BLK_RW_ASYNC ); +clear_bdi_congested (first_fm->sb->s_bdi,BLK_RW_SYNC ); +clear_bdi_congested (first_fm->sb->s_bdi,BLK_RW_ASYNC ); }else { -set_bdi_congested (fc->sb->s_bdi,BLK_RW_SYNC ); -set_bdi_congested (fc->sb->s_bdi,BLK_RW_ASYNC ); +set_bdi_congested (first_fm->sb->s_bdi,BLK_RW_SYNC ); +set_bdi_congested (first_fm->sb->s_bdi,BLK_RW_ASYNC ); } }spin_unlock (&fc->bg_lock);
@@ -263,14 +273,20 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,int fuse_ctl_add_conn (struct fuse_conn *fc) {struct dentry *parent; +struct fuse_mount *first_fm;char name[32 ];if (!fuse_control_sb)return 0 ; +if (list_empty (&fc->mounts)) +return 0 ; + + first_fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry); +sprintf (name,"%u" , first_fm->dev); + parent = fuse_control_sb->s_root;inc_nlink (d_inode (parent)); -sprintf (name,"%u" , fc->dev); parent =fuse_ctl_add_dentry (parent, fc, name,S_IFDIR |0500 ,2 , &simple_dir_inode_operations, &simple_dir_operations);
fs/fuse/dev.c +50 -56
305 lines not on this page · raw message
fs/fuse/dir.c +57 -54
389 lines not on this page · raw message
fs/fuse/file.c +107 -104
713 lines not on this page · raw message
fs/fuse/inode.c +108 -39
307 lines not on this page · raw message
fs/fuse/readdir.c +5 -5
@@ -252,7 +252,7 @@ static int fuse_direntplus_link(struct file *file,static void fuse_force_forget (struct file *file,u64 nodeid) {struct inode *inode =file_inode (file); -struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_mount *fm =get_fuse_mount (inode);struct fuse_forget_in inarg;FUSE_ARGS (args);
@@ -266,7 +266,7 @@ static void fuse_force_forget(struct file *file, u64 nodeid) args.force = true; args.noreply = true; -fuse_simple_request (fc, &args); +fuse_simple_request (fm, &args);/* ignore errors */ }
@@ -320,7 +320,7 @@ static int fuse_readdir_uncached(struct file *file, struct dir_context *ctx)ssize_t res;struct page *page;struct inode *inode =file_inode (file); -struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_mount *fm =get_fuse_mount (inode);struct fuse_io_args ia = {};struct fuse_args_pages *ap = &ia.ap;struct fuse_page_desc desc = { .length =PAGE_SIZE };
@@ -337,7 +337,7 @@ static int fuse_readdir_uncached(struct file *file, struct dir_context *ctx) ap->pages = &page; ap->descs = &desc;if (plus) { - attr_version =fuse_get_attr_version (fc); + attr_version =fuse_get_attr_version (fm->fc);fuse_read_args_fill (&ia, file, ctx->pos,PAGE_SIZE ,FUSE_READDIRPLUS ); }else {
@@ -345,7 +345,7 @@ static int fuse_readdir_uncached(struct file *file, struct dir_context *ctx) FUSE_READDIR); } locked =fuse_lock_inode (inode); - res =fuse_simple_request (fc, &ap->args); + res =fuse_simple_request (fm, &ap->args);fuse_unlock_inode (inode, locked);if (res >=0 ) {if (!res) {
fs/fuse/virtio_fs.c +41 -21
119 lines not on this page · raw message
fs/fuse/xattr.c +17 -17
@@ -14,12 +14,12 @@int fuse_setxattr (struct inode *inode,const char *name,const void *value,size_t size,int flags) { -struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_mount *fm =get_fuse_mount (inode);FUSE_ARGS (args);struct fuse_setxattr_in inarg;int err; -if (fc->no_setxattr) +if (fm->fc->no_setxattr)return -EOPNOTSUPP ;memset (&inarg,0 ,sizeof (inarg));
@@ -34,9 +34,9 @@ int fuse_setxattr(struct inode *inode, const char *name, const void *value, args.in_args[1 ].value = name; args.in_args[2 ].size = size; args.in_args[2 ].value = value; - err =fuse_simple_request (fc, &args); + err =fuse_simple_request (fm, &args);if (err == -ENOSYS ) { - fc->no_setxattr =1 ; + fm->fc->no_setxattr =1 ; err = -EOPNOTSUPP ; }if (!err) {
@@ -49,13 +49,13 @@ int fuse_setxattr(struct inode *inode, const char *name, const void *value,ssize_t fuse_getxattr (struct inode *inode,const char *name,void *value,size_t size) { -struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_mount *fm =get_fuse_mount (inode);FUSE_ARGS (args);struct fuse_getxattr_in inarg;struct fuse_getxattr_out outarg;ssize_t ret; -if (fc->no_getxattr) +if (fm->fc->no_getxattr)return -EOPNOTSUPP ;memset (&inarg,0 ,sizeof (inarg));
@@ -77,11 +77,11 @@ ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, args.out_args[0 ].size =sizeof (outarg); args.out_args[0 ].value = &outarg; } - ret =fuse_simple_request (fc, &args); + ret =fuse_simple_request (fm, &args);if (!ret && !size) ret =min_t (ssize_t, outarg.size,XATTR_SIZE_MAX );if (ret == -ENOSYS ) { - fc->no_getxattr =1 ; + fm->fc->no_getxattr =1 ; ret = -EOPNOTSUPP ; }return ret;
@@ -107,16 +107,16 @@ static int fuse_verify_xattr_list(char *list, size_t size)ssize_t fuse_listxattr (struct dentry *entry,char *list,size_t size) {struct inode *inode =d_inode (entry); -struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_mount *fm =get_fuse_mount (inode);FUSE_ARGS (args);struct fuse_getxattr_in inarg;struct fuse_getxattr_out outarg;ssize_t ret; -if (!fuse_allow_current_process (fc)) +if (!fuse_allow_current_process (fm->fc))return -EACCES ; -if (fc->no_listxattr) +if (fm->fc->no_listxattr)return -EOPNOTSUPP ;memset (&inarg,0 ,sizeof (inarg));
@@ -136,13 +136,13 @@ ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) args.out_args[0 ].size =sizeof (outarg); args.out_args[0 ].value = &outarg; } - ret =fuse_simple_request (fc, &args); + ret =fuse_simple_request (fm, &args);if (!ret && !size) ret =min_t (ssize_t, outarg.size,XATTR_LIST_MAX );if (ret >0 && size) ret =fuse_verify_xattr_list (list, ret);if (ret == -ENOSYS ) { - fc->no_listxattr =1 ; + fm->fc->no_listxattr =1 ; ret = -EOPNOTSUPP ; }return ret;
@@ -150,11 +150,11 @@ ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)int fuse_removexattr (struct inode *inode,const char *name) { -struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_mount *fm =get_fuse_mount (inode);FUSE_ARGS (args);int err; -if (fc->no_removexattr) +if (fm->fc->no_removexattr)return -EOPNOTSUPP ; args.opcode =FUSE_REMOVEXATTR ;
@@ -162,9 +162,9 @@ int fuse_removexattr(struct inode *inode, const char *name) args.in_numargs =1 ; args.in_args[0 ].size =strlen (name) +1 ; args.in_args[0 ].value = name; - err =fuse_simple_request (fc, &args); + err =fuse_simple_request (fm, &args);if (err == -ENOSYS ) { - fc->no_removexattr =1 ; + fm->fc->no_removexattr =1 ; err = -EOPNOTSUPP ; }if (!err) {
Signature · 1 line
2.26.2
Stefan Hajnoczi
maintainerRe: [Virtio-fs] [PATCH 7/9] fuse: Split fuse_mount off of fuse_conn
Quoted 13 lines · Max Reitz
fs/fuse/control.c +8
-1@@ -176,13 +177,22 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,spin_lock (&fc->bg_lock); fc->congestion_threshold = val; -if (fc->sb) { + +/* +* Get any fuse_mount belonging to this fuse_conn; s_bdi is +* shared between all of them +*/ +if (!list_empty (&fc->mounts)) + first_fm = list_first_entry(&fc->mounts, struct fuse_mount, + fc_entry);
...
Quoted 5 lines
fs/fuse/control.c +1
-0@@ -263,14 +273,20 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,int fuse_ctl_add_conn (struct fuse_conn *fc) {struct dentry *parent; +struct fuse_mount *first_fm;
fs/fuse/control.c static struct dentry *fuse_ctl_add_dentry(struct dentry *parent, · line 286
Quoted 10 lines
fs/fuse/control.c +5
-0char name[32 ];if (!fuse_control_sb)return 0 ; +if (list_empty (&fc->mounts)) +return 0 ; + + first_fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry); +sprintf (name,"%u" , first_fm->dev);
How does locking work for struct fuse_mount? Are there any locking rules that can be documented?
Stefan
Re: [Virtio-fs] [PATCH 7/9] fuse: Split fuse_mount off of fuse_conn
Quoted 25 lines · Stefan Hajnoczi
Quoted 13 lines · Max Reitz
fs/fuse/control.c +8
-1@@ -176,13 +177,22 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,spin_lock (&fc->bg_lock); fc->congestion_threshold = val; -if (fc->sb) { + +/* +* Get any fuse_mount belonging to this fuse_conn; s_bdi is +* shared between all of them +*/ +if (!list_empty (&fc->mounts)) + first_fm = list_first_entry(&fc->mounts, struct fuse_mount, + fc_entry);...
Quoted 10 lines
fs/fuse/control.c +1
-0@@ -263,14 +273,20 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,int fuse_ctl_add_conn (struct fuse_conn *fc) {struct dentry *parent; +struct fuse_mount *first_fm;char name[32 ];if (!fuse_control_sb)return 0 ;
Quoted 8 lines
fs/fuse/control.c static struct dentry *fuse_ctl_add_dentry(struct dentry *parent, · line 286
Quoted 5 lines
fs/fuse/control.c +5
-0+if (list_empty (&fc->mounts)) +return 0 ; + + first_fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry); +sprintf (name,"%u" , first_fm->dev);How does locking work for struct
fuse_mount? Are there any locking rules that can be documented?
Hm. I just hoped the largely mechanical conversion of fuse_conn to fuse_mount would ensure nothing breaks.
There are locks protecting the superblock and fuse_conn as a whole (which basically includes the associated fuse_mounts). I suspect we could get better (i.e., finer) granularity by giving each fuse_mount its own lock, and then releasing the fuse_conn lock while we switch over to the fuse_mount lock.
That seems bug-prone, though, and probably doesn’t even help performance that much. I mean, in the most common case, you won’t have submounts, so each fuse_conn has exactly one fuse_mount, so having a separate lock for the latter won’t help.
Max
PATCH 8/9 fuse: Allow fuse_fill_super_common() for submounts
In reply to Max ReitzSubmounts have their own superblock, which needs to be initialized. However, they do not have a fuse_fs_context associated with them, and the root node's attributes should be taken from the mountpoint's node.
Extend fuse_fill_super_common() to work for submounts by making the @ctx parameter optional, and by adding a @submount_finode parameter.
(There is a plain "unsigned" in an existing code block that is being indented by this commit. Extend it to "unsigned int" so checkpatch does not complain.)
--- fs/fuse/fuse_i.h | 10 ++-- fs/fuse/inode.c | 129 +++++++++++++++++++++++++++++++++++--------- fs/fuse/virtio_fs.c | 2 +- 3 files changed, 112 insertions(+), 29 deletions(-)
fs/fuse/fuse_i.h +7 -3
@@ -1030,11 +1030,15 @@ void fuse_dev_free(struct fuse_dev *fud);void fuse_send_init (struct fuse_mount *fm);/** -* Fill in superblock and initialize fuse connection +* Fill in superblock and initialize fuse connection for root mounts. * @sb: partially-initialized superblock to fill in -* @ctx: mount context +* @ctx: mount context (for root mounts) +* @submount_finode: For submounts: The fuse_inode of the parent +* filesystem where this submount is mounted +* (NULL for root mounts) */ -int fuse_fill_super_common (struct super_block *sb,struct fuse_fs_context *ctx); +int fuse_fill_super_common (struct super_block *sb,struct fuse_fs_context *ctx, +struct fuse_inode *submount_finode);/** * Disassociate fuse connection from superblock and kill the superblock
fs/fuse/inode.c +104 -25
191 lines not on this page · raw message
fs/fuse/virtio_fs.c +1 -1
@@ -1112,7 +1112,7 @@ static int virtio_fs_fill_super(struct super_block *sb)/* virtiofs allocates and installs its own fuse devices */ ctx.fudptr =NULL ; - err =fuse_fill_super_common (sb, &ctx); + err =fuse_fill_super_common (sb, &ctx,NULL );if (err <0 ) goto err_free_fuse_devs;
Signature · 1 line
2.26.2
PATCH 9/9 fuse: Implement crossmounts
In reply to Max ReitzWith this commit, FUSE servers can indicate crossmount points by setting the respective fuse_attr.flags flag. The inode will then be marked as S_AUTOMOUNT, and the .d_automount implementation creates a new submount at that location, so that the submount gets a distinct st_dev value.
Note that all submounts get a distinct superblock and a distinct st_dev value, so for virtio-fs, even if the same filesystem is mounted more than once on the host, none of its mount points will have the same st_dev. We need distinct superblocks because the superblock points to the root node, but the different host mounts may show different trees (e.g. due to submounts in some of them, but not in others).
Right now, this behavior is only enabled when fuse_conn.auto_submounts is set, which is the case only for virtio-fs.
--- fs/fuse/fuse_i.h | 3 ++ fs/fuse/dir.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/inode.c | 9 +++-- fs/fuse/virtio_fs.c | 1 + 4 files changed, 98 insertions(+), 2 deletions(-)
fs/fuse/fuse_i.h +3 -0
@@ -727,6 +727,9 @@ struct fuse_conn {/* fuse_attr.flags is present and valid */ unsigned int attr_flags:1; +/* Auto-mount submounts announced by the server */ + unsigned int auto_submounts:1; +/** The number of requests waiting for completion */ atomic_t num_waiting;
fs/fuse/dir.c +87 -0
105 lines not on this page · raw message
fs/fuse/inode.c +7 -2
@@ -255,9 +255,14 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)if (S_ISREG (inode->i_mode)) {fuse_init_common (inode);fuse_init_file_inode (inode); - }else if (S_ISDIR (inode->i_mode)) + }else if (S_ISDIR (inode->i_mode)) { +struct fuse_conn *fc =get_fuse_conn (inode); +fuse_init_dir (inode); -else if (S_ISLNK (inode->i_mode)) +if (fc->attr_flags && (attr->flags &FUSE_ATTR_SUBMOUNT ) && + fc->auto_submounts) + inode->i_flags |=S_AUTOMOUNT ; + }else if (S_ISLNK (inode->i_mode))fuse_init_symlink (inode);else if (S_ISCHR (inode->i_mode) ||S_ISBLK (inode->i_mode) ||S_ISFIFO (inode->i_mode) ||S_ISSOCK (inode->i_mode)) {
fs/fuse/virtio_fs.c +1 -0
@@ -1231,6 +1231,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc) fs); fc->release = fuse_free_conn; fc->delete_stale = true; + fc->auto_submounts = true;fuse_mount_init (fm, fc, true);fuse_conn_put (fc);
Signature · 1 line
2.26.2
Stefan Hajnoczi
maintainerQuoted 5 lines · Max Reitz
When using virtio-fs, we want all nodes that have a unique st_dev/st_ino combination on the host to have such a unique combination in the guest as well. To do so, we introduce a flags field to
fuse_attr, where virtiofsd can announce submounts. All such entries are then translated to auto-mounts by the FUSE driver in the guest.
The easy parts look good. I'm leaving the hard parts to Miklos :).
Stefan
Miklos Szeredi
maintainerPushed an updated version to fuse.git#submounts.
Also attached incremental patch (against rebase of virtiofs-submounts-v2 on fuse.git#for-next).
Changes:
1) rebased on top of DAX patches
2) fixed CUSE
3) added locking for fc->mounts list
4) dissociate lifetime of fc from lifetime of root mount
5) do not hash mountpoint inodes
6) add FUSE_SUBMOUNTS init flag (replaces FUSE_ATTR_FLAGS but
slightly different usage)
7) various cleanups
Note, the effect of 5 can only be observed if the same directory is bind mounted into multiple places:
HOST:
cd /mnt
mkdir 1 2
mount --bind /dev/shm 1
mount --bind /dev/shm 2
GUEST:
mount -t virtiofs mnt /mnt
cd /mnt/1
ls ../2/bin/pwd
If the mountpoint is hashed, then the "ls ../2" will basically result in /mnt/1 inode being moved to /mnt/2, which is not what we want. I don't think there's any negative side effect of the mountpoint being unhashed, but this is a bit subtle.
On the server side, keying on just st_ino/st_dev is a really crude way of mapping out mounts. Take this example:
HOST:
cd /mnt
mkdir 1
mount --bind /dev/shm 1
cd 1
mkdir 2
mount --bind /mnt 2
ls /mnt/1/2/1
GUEST:
mount -t virtiofs mnt /mnt
ls /mnt/1/2/1
2
ls /mnt/1/2/1/2/1/2/1/
2
So what we really need is keying on mount ID as well.
Attaching an incremental patch to do that. Needs v5.8 kernel on host to actually make a difference, but commit fa2fcf4f1df1 ("statx: add mount ID") is trivial to backport to any kernel that has statx.
Please review and test. If there are no major issues, this should be good to go for v5.10.
Thanks,
Miklos
fs/fuse/control.c +10 -16
@@ -164,7 +164,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file, {unsigned val;struct fuse_conn *fc; -struct fuse_mount *first_fm =NULL ; +struct fuse_mount *fm;ssize_t ret; ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
@@ -175,6 +175,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,if (!fc) goto out; +down_read (&fc->killsb);spin_lock (&fc->bg_lock); fc->congestion_threshold = val;
@@ -182,20 +183,19 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,* Get any fuse_mount belonging to this fuse_conn; s_bdi is * shared between all of them */ -if (!list_empty (&fc->mounts)) - first_fm = list_first_entry(&fc->mounts, struct fuse_mount, - fc_entry); -if (first_fm && first_fm->sb) { +if (!list_empty (&fc->mounts)) { + fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry);if (fc->num_background < fc->congestion_threshold) { -clear_bdi_congested (first_fm->sb->s_bdi,BLK_RW_SYNC ); -clear_bdi_congested (first_fm->sb->s_bdi,BLK_RW_ASYNC ); +clear_bdi_congested (fm->sb->s_bdi,BLK_RW_SYNC ); +clear_bdi_congested (fm->sb->s_bdi,BLK_RW_ASYNC ); }else { -set_bdi_congested (first_fm->sb->s_bdi,BLK_RW_SYNC ); -set_bdi_congested (first_fm->sb->s_bdi,BLK_RW_ASYNC ); +set_bdi_congested (fm->sb->s_bdi,BLK_RW_SYNC ); +set_bdi_congested (fm->sb->s_bdi,BLK_RW_ASYNC ); } }spin_unlock (&fc->bg_lock); +up_read (&fc->killsb);fuse_conn_put (fc); out:return ret;
@@ -273,20 +273,14 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,int fuse_ctl_add_conn (struct fuse_conn *fc) {struct dentry *parent; -struct fuse_mount *first_fm;char name[32 ];if (!fuse_control_sb)return 0 ; -if (list_empty (&fc->mounts)) -return 0 ; - - first_fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry); -sprintf (name,"%u" , first_fm->dev); - parent = fuse_control_sb->s_root;inc_nlink (d_inode (parent)); +sprintf (name,"%u" , fc->dev); parent =fuse_ctl_add_dentry (parent, fc, name,S_IFDIR |0500 ,2 , &simple_dir_inode_operations, &simple_dir_operations);
fs/fuse/cuse.c +12 -9
@@ -57,6 +57,7 @@struct cuse_conn {struct list_head list;/* linked on cuse_conntbl */ +struct fuse_mount fm;/* Dummy mount referencing fc */ struct fuse_conn fc;/* fuse connection */ struct cdev *cdev;/* associated character device */ struct device *dev;/* device representing @cdev */
@@ -134,7 +135,7 @@ static int cuse_open(struct inode *inode, struct file *file)* Generic permission check is already done against the chrdev * file, proceed to open. */ - rc =fuse_do_open (&cc->fc,0 , file,0 ); + rc =fuse_do_open (&cc->fm,0 , file,0 );if (rc)fuse_conn_put (&cc->fc);return rc;
@@ -143,10 +144,10 @@ static int cuse_open(struct inode *inode, struct file *file)static int cuse_release (struct inode *inode,struct file *file) {struct fuse_file *ff = file->private_data; -struct fuse_conn *fc = ff->fc; +struct fuse_mount *fm = ff->fm;fuse_sync_release (NULL , ff, file->f_flags); -fuse_conn_put (fc); +fuse_conn_put (fm->fc);return 0 ; }
@@ -155,7 +156,7 @@ static long cuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {struct fuse_file *ff = file->private_data; -struct cuse_conn *cc =fc_to_cc (ff->fc); +struct cuse_conn *cc =fc_to_cc (ff->fm->fc);unsigned int flags =0 ;if (cc->unrestricted_ioctl)
@@ -168,7 +169,7 @@ static long cuse_file_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {struct fuse_file *ff = file->private_data; -struct cuse_conn *cc =fc_to_cc (ff->fc); +struct cuse_conn *cc =fc_to_cc (ff->fm->fc);unsigned int flags =FUSE_IOCTL_COMPAT ;if (cc->unrestricted_ioctl)
@@ -313,9 +314,10 @@ struct cuse_init_args {* required data structures for it. Please read the comment at the * top of this file for high level overview. */ -static void cuse_process_init_reply (struct fuse_conn *fc, +static void cuse_process_init_reply (struct fuse_mount *fm,struct fuse_args *args,int error) { +struct fuse_conn *fc = fm->fc;struct cuse_init_args *ia =container_of (args,typeof (*ia), ap.args);struct fuse_args_pages *ap = &ia->ap;struct cuse_conn *cc =fc_to_cc (fc), *pos;
@@ -424,7 +426,7 @@ static int cuse_send_init(struct cuse_conn *cc) {int rc;struct page *page; -struct fuse_conn *fc = &cc->fc; +struct fuse_mount *fm = &cc->fm;struct cuse_init_args *ia;struct fuse_args_pages *ap;
@@ -460,7 +462,7 @@ static int cuse_send_init(struct cuse_conn *cc) ia->desc.length = ap->args.out_args[1 ].size; ap->args.end = cuse_process_init_reply; - rc =fuse_simple_background (fc, &ap->args,GFP_KERNEL ); + rc =fuse_simple_background (fm, &ap->args,GFP_KERNEL );if (rc) {kfree (ia); err_free_page:
@@ -506,7 +508,8 @@ static int cuse_channel_open(struct inode *inode, struct file *file)* Limit the cuse channel to requests that can * be represented in file->f_cred->user_ns. */ -fuse_conn_init (&cc->fc, file->f_cred->user_ns, &fuse_dev_fiq_ops,NULL ); +fuse_conn_init (&cc->fc, &cc->fm, file->f_cred->user_ns, + &fuse_dev_fiq_ops,NULL ); fud =fuse_dev_alloc_install (&cc->fc);if (!fud) {
fs/fuse/dev.c +2 -2
@@ -1574,7 +1574,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,down_read (&fc->killsb); err = -ENOENT ; - inode =fuse_ilookup (fc, nodeid, fuse_inode_eq, &nodeid,NULL ); + inode =fuse_ilookup (fc, nodeid,NULL );if (!inode) goto out_up_killsb;
@@ -1744,7 +1744,7 @@ static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size, err = -ENOENT ; nodeid = outarg.nodeid; - inode =fuse_ilookup (fc, nodeid, fuse_inode_eq, &nodeid, &fm); + inode =fuse_ilookup (fc, nodeid, &fm);if (inode) { err =fuse_retrieve (fm, inode, &outarg);iput (inode);
fs/fuse/dir.c +14 -26
@@ -238,7 +238,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) ret = -ENOENT ;if (!ret) { fi =get_fuse_inode (inode); -if (outarg.nodeid !=get_node_id (inode)) { +if (outarg.nodeid !=get_node_id (inode) || + (bool )IS_AUTOMOUNT (inode) != (bool ) (outarg.attr.flags &FUSE_ATTR_SUBMOUNT )) {fuse_queue_forget (fm->fc, forget, outarg.nodeid,1 ); goto invalid;
@@ -300,18 +301,6 @@ static int fuse_dentry_delete(const struct dentry *dentry)return time_before64 (fuse_dentry_time (dentry),get_jiffies_64 ()); } -static int fuse_submount_set_super (struct super_block *sb, -struct fs_context *fsc) -{ -int err; - - err =get_anon_bdev (&sb->s_dev); -if (!err) -fuse_mount_get (fsc->s_fs_info); - -return err; -} -/* * Create a fuse_mount object with a new superblock (with path->dentry * as the root), and return that mount so it can be auto-mounted on
@@ -324,7 +313,7 @@ static struct vfsmount *fuse_dentry_automount(struct path *path)struct fuse_conn *fc = parent_fm->fc;struct fuse_mount *fm;struct vfsmount *mnt; -struct fuse_inode *mp_finode =get_fuse_inode (d_inode (path->dentry)); +struct fuse_inode *mp_fi =get_fuse_inode (d_inode (path->dentry));struct super_block *sb;int err;
@@ -339,20 +328,18 @@ static struct vfsmount *fuse_dentry_automount(struct path *path)if (!fm) goto out_put_fsc; -/* Create new fuse_mount for the existing fuse_conn */ -fuse_mount_init (fm, fc, false); - -/* Get (new) superblock for this new fuse_mount */ +refcount_set (&fm->count,1 ); fsc->s_fs_info = fm; - sb =sget_fc (fsc,NULL , fuse_submount_set_super); -fuse_mount_put (fm); + sb =sget_fc (fsc,NULL , set_anon_super_fc);if (IS_ERR (sb)) { err =PTR_ERR (sb); +fuse_mount_put (fm); goto out_put_fsc; } + fm->fc =fuse_conn_get (fc); -/* Initialize superblock, making @mp_finode its root */ - err =fuse_fill_super_common (sb,NULL , mp_finode); +/* Initialize superblock, making @mp_fi its root */ + err =fuse_fill_super_submount (sb, mp_fi);if (err) goto out_put_sb;
@@ -361,15 +348,17 @@ static struct vfsmount *fuse_dentry_automount(struct path *path)/* We are done configuring the superblock, so unlock it */ up_write (&sb->s_umount); +down_write (&fc->killsb); +list_add_tail (&fm->fc_entry, &fc->mounts); +up_write (&fc->killsb); +/* Create the submount */ mnt =vfs_create_mount (fsc);if (IS_ERR (mnt)) { err =PTR_ERR (mnt); goto out_put_fsc; } -mntget (mnt); -put_fs_context (fsc);return mnt;
@@ -1098,8 +1087,7 @@ int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,struct dentry *dir;struct dentry *entry; - parent =fuse_ilookup (fc, parent_nodeid, fuse_inode_eq, &parent_nodeid, -NULL ); + parent =fuse_ilookup (fc, parent_nodeid,NULL );if (!parent)return -ENOENT ;
fs/fuse/file.c +4 -3
@@ -218,12 +218,13 @@ void fuse_finish_open(struct inode *inode, struct file *file)int fuse_open_common (struct inode *inode,struct file *file,bool isdir) {struct fuse_mount *fm =get_fuse_mount (inode); +struct fuse_conn *fc = fm->fc;int err;bool is_wb_truncate = (file->f_flags &O_TRUNC ) && - fm->fc->atomic_o_trunc && - fm->fc->writeback_cache; + fc->atomic_o_trunc && + fc->writeback_cache;bool dax_truncate = (file->f_flags &O_TRUNC ) && - fm->fc->atomic_o_trunc &&FUSE_IS_DAX (inode); + fc->atomic_o_trunc &&FUSE_IS_DAX (inode); err =generic_file_open (inode, file);if (err)
fs/fuse/fuse_i.h +36 -41
148 lines not on this page · raw message
fs/fuse/inode.c +172 -165
540 lines not on this page · raw message
fs/fuse/virtio_fs.c +36 -37
104 lines not on this page · raw message
include/uapi/linux/fuse.h +7 -4
@@ -172,6 +172,9 @@* - add FUSE_WRITE_KILL_PRIV flag * - add FUSE_SETUPMAPPING and FUSE_REMOVEMAPPING * - add map_alignment to fuse_init_out, add FUSE_MAP_ALIGNMENT flag +* +* 7.32 +* - add flags to fuse_attr, add FUSE_ATTR_SUBMOUNT, add FUSE_SUBMOUNTS */ #ifndef _LINUX_FUSE_H
@@ -207,7 +210,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 31 +#define FUSE_KERNEL_MINOR_VERSION 32/** The node ID of the root inode */ #define FUSE_ROOT_ID 1
@@ -316,7 +319,7 @@ struct fuse_file_lock {* FUSE_MAP_ALIGNMENT: init_out.map_alignment contains log2(byte alignment) for * foffset and moffset fields in struct * fuse_setupmapping_out and fuse_removemapping_one. -* FUSE_ATTR_FLAGS: fuse_attr.flags is present and valid +* FUSE_SUBMOUNTS: kernel supports auto-mounting directory submounts */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -345,7 +348,7 @@ struct fuse_file_lock {#define FUSE_NO_OPENDIR_SUPPORT (1 << 24)#define FUSE_EXPLICIT_INVAL_DATA (1 << 25)#define FUSE_MAP_ALIGNMENT (1 << 26) -#define FUSE_ATTR_FLAGS (1 << 27) +#define FUSE_SUBMOUNTS (1 << 27)/** * CUSE INIT request/reply flags
@@ -424,7 +427,7 @@ struct fuse_file_lock {/** * fuse_attr flags * -* FUSE_ATTR_SUBMOUNT: File/directory is a submount point +* FUSE_ATTR_SUBMOUNT: Object is a submount root */ #define FUSE_ATTR_SUBMOUNT (1 << 0)
configure +18 -0
@@ -5816,6 +5816,21 @@ if compile_prog "" "" ; then have_copy_file_range=yes fi +############################################### +# Check if statx is provided by glibc +have_statx=no +cat > $TMPC << EOF +#include <sys/stat.h> +int main(void) { + struct statx buf; + statx(0, "", 0, STATX_BASIC_STATS, &buf); + return 0; +} +EOF +if compile_prog "" "" ; then + have_statx=yes +fi + ########################################## # check if struct fsxattr is available via linux/fs.h
@@ -6869,6 +6884,9 @@ fi if test "$have_copy_file_range" = "yes" ; then echo "HAVE_COPY_FILE_RANGE=y" >> $config_host_mak fi +if test "$have_statx" = "yes" ; then + echo "HAVE_STATX=y" >> $config_host_mak +fi if test "$vte" = "yes" ; then echo "CONFIG_VTE=y" >> $config_host_mak echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
tools/virtiofsd/passthrough_ll.c +81 -66
304 lines not on this page · raw message
tools/virtiofsd/passthrough_seccomp.c +1 -0
@@ -76,6 +76,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (mremap),SCMP_SYS (munmap),SCMP_SYS (newfstatat), +SCMP_SYS (statx),SCMP_SYS (open),SCMP_SYS (openat), SCMP_SYS(ppoll),
Quoted 7 lines · Miklos Szeredi
Pushed an updated version to fuse.git#submounts.
Also attached incremental patch (against rebase of virtiofs-submounts-v2 on fuse.git#for-next).
Changes:
Quoted 8 lines
1) rebased on top of DAX patches
2) fixed CUSE
3) added locking forfc->mountslist
4) dissociate lifetime of fc from lifetime of root mount
5) do not hash mountpoint inodes
6) addFUSE_SUBMOUNTSinit flag (replacesFUSE_ATTR_FLAGSbut
slightly different usage)
7) various cleanups
Wow. Thanks! I’ll take a closer look once I can.
Quoted 33 lines
Note, the effect of 5 can only be observed if the same directory is bind mounted into multiple places:
HOST:
cd /mnt
mkdir 1 2
mount --bind/dev/shm1
mount --bind/dev/shm2GUEST:
mount -t virtiofs mnt /mnt
cd/mnt/1
ls ../2/bin/pwdIf the mountpoint is hashed, then the "ls ../2" will basically result in
/mnt/1inode being moved to/mnt/2, which is not what we want. I don't think there's any negative side effect of the mountpoint being unhashed, but this is a bit subtle.On the server side, keying on just st_ino/st_dev is a really crude way of mapping out mounts. Take this example:
HOST:
cd /mnt
mkdir 1
mount --bind/dev/shm1
cd 1
mkdir 2
mount --bind /mnt 2
ls/mnt/1/2/1
Quoted 8 lines
GUEST:
mount -t virtiofs mnt /mnt
ls/mnt/1/2/1
2
ls/mnt/1/2/1/2/1/2/1/
2So what we really need is keying on mount ID as well.
Yes, I’ve noticed this, too. I just didn’t care to fix it here, because it’s a pre-existing issue (I believe), and it isn’t related to the submount-automount implementation – it’s just a bug in virtiofsd, basically.
Quoted 5 lines
Attaching an incremental patch to do that. Needs v5.8 kernel on host to actually make a difference, but commit
fa2fcf4f1df1("statx: add mount ID") is trivial to backport to any kernel that has statx.Please review and test.
Will do.
Quoted 2 lines
If there are no major issues, this should be
good to go for v5.10.
Great :)
Max
Quoted 15 lines · Miklos Szeredi
Pushed an updated version to fuse.git#submounts.
Also attached incremental patch (against rebase of virtiofs-submounts-v2 on fuse.git#for-next).
Changes:
1) rebased on top of DAX patches
2) fixed CUSE
3) added locking forfc->mountslist
4) dissociate lifetime of fc from lifetime of root mount
5) do not hash mountpoint inodes
6) addFUSE_SUBMOUNTSinit flag (replacesFUSE_ATTR_FLAGSbut
slightly different usage)
7) various cleanups
[...]
Quoted 2 lines
Please review and test. If there are no major issues, this should be good to go for v5.10.
submounts-update.patch looks good to me. Thanks again!
(I have to admit I found it quite hard to review because it’s the 7 changes noted above rolled into a single diff, so it took me quite a while.)
The only thing I noticed was that fuse_init_node() shouldn’t declare @fc any longer. (I also don’t quite understand why in fuse_i.h some /** are replaced by /*, but that isn’t really relevant.)
(I’ll look at virtiofsd-use-mount-id.patch tomorrow.)
Max
Quoted 56 lines · Miklos Szeredi
Pushed an updated version to fuse.git#submounts.
Also attached incremental patch (against rebase of virtiofs-submounts-v2 on fuse.git#for-next).
Changes:
1) rebased on top of DAX patches
2) fixed CUSE
3) added locking forfc->mountslist
4) dissociate lifetime of fc from lifetime of root mount
5) do not hash mountpoint inodes
6) addFUSE_SUBMOUNTSinit flag (replacesFUSE_ATTR_FLAGSbut
slightly different usage)
7) various cleanupsNote, the effect of 5 can only be observed if the same directory is bind mounted into multiple places:
HOST:
cd /mnt
mkdir 1 2
mount --bind/dev/shm1
mount --bind/dev/shm2GUEST:
mount -t virtiofs mnt /mnt
cd/mnt/1
ls ../2/bin/pwdIf the mountpoint is hashed, then the "ls ../2" will basically result in
/mnt/1inode being moved to/mnt/2, which is not what we want. I don't think there's any negative side effect of the mountpoint being unhashed, but this is a bit subtle.On the server side, keying on just st_ino/st_dev is a really crude way of mapping out mounts. Take this example:
HOST:
cd /mnt
mkdir 1
mount --bind/dev/shm1
cd 1
mkdir 2
mount --bind /mnt 2
ls/mnt/1/2/1GUEST:
mount -t virtiofs mnt /mnt
ls/mnt/1/2/1
2
ls/mnt/1/2/1/2/1/2/1/
2
Quoted 8 lines
So what we really need is keying on mount ID as well.
Attaching an incremental patch to do that. Needs v5.8 kernel on host to actually make a difference, but commit
fa2fcf4f1df1("statx: add mount ID") is trivial to backport to any kernel that has statx.Please review and test. If there are no major issues, this should be good to go for v5.10.
As for the virtiofsd patch, I wonder about:
Quoted 1 line
#if 0 &&
defined(HAVE_STATX)&&STATX_MNT_ID
Shouldn’t the 0 not be there? And should STATX_MNT_ID be wrapped in defined()?
Furthermore I wonder why you have removed the parent_dev logic. With your patch, FUSE_ATTR_SUBMOUNT can be announced only by those functions that invoke lo_do_lookup(). Is it OK to do so only there, and not every time a fuse_attr is returned (be it as part of fuse_entry_out, as by lo_link(), or directly by lo_getattr())?
(Also, the virtiofsd series will need a bit of an update with FUSE_SUBMOUNTS replacing FUSE_ATTR_FLAGS.)
Max
Miklos Szeredi
maintainerQuoted 67 lines · Max Reitz
Quoted 56 lines · Miklos Szeredi
Pushed an updated version to fuse.git#submounts.
Also attached incremental patch (against rebase of virtiofs-submounts-v2 on fuse.git#for-next).
Changes:
1) rebased on top of DAX patches
2) fixed CUSE
3) added locking forfc->mountslist
4) dissociate lifetime of fc from lifetime of root mount
5) do not hash mountpoint inodes
6) addFUSE_SUBMOUNTSinit flag (replacesFUSE_ATTR_FLAGSbut
slightly different usage)
7) various cleanupsNote, the effect of 5 can only be observed if the same directory is bind mounted into multiple places:
HOST:
cd /mnt
mkdir 1 2
mount --bind/dev/shm1
mount --bind/dev/shm2GUEST:
mount -t virtiofs mnt /mnt
cd/mnt/1
ls ../2/bin/pwdIf the mountpoint is hashed, then the "ls ../2" will basically result in
/mnt/1inode being moved to/mnt/2, which is not what we want. I don't think there's any negative side effect of the mountpoint being unhashed, but this is a bit subtle.On the server side, keying on just st_ino/st_dev is a really crude way of mapping out mounts. Take this example:
HOST:
cd /mnt
mkdir 1
mount --bind/dev/shm1
cd 1
mkdir 2
mount --bind /mnt 2
ls/mnt/1/2/1GUEST:
mount -t virtiofs mnt /mnt
ls/mnt/1/2/1
2
ls/mnt/1/2/1/2/1/2/1/
2Quoted 8 lines
So what we really need is keying on mount ID as well.
Attaching an incremental patch to do that. Needs v5.8 kernel on host to actually make a difference, but commit
fa2fcf4f1df1("statx: add mount ID") is trivial to backport to any kernel that has statx.Please review and test. If there are no major issues, this should be good to go for v5.10.
Quoted 6 lines
As for the virtiofsd patch, I wonder about:
Quoted 1 line
#if 0 &&
defined(HAVE_STATX)&&STATX_MNT_IDShouldn’t the 0 not be there? And should
STATX_MNT_IDbe wrapped indefined()?
Right, that was left there from testing.
Quoted 5 lines
Furthermore I wonder why you have removed the
parent_devlogic. With your patch,FUSE_ATTR_SUBMOUNTcan be announced only by those functions that invokelo_do_lookup(). Is it OK to do so only there, and not every time afuse_attris returned (be it as part offuse_entry_out, as bylo_link(), or directly bylo_getattr())?
No, object creation never results in a mounted object. If the newly created object is mounted on at a later time, the revalidate logic will take care of that.
Quoted 3 lines
(Also, the virtiofsd series will need a bit of an update with
FUSE_SUBMOUNTSreplacingFUSE_ATTR_FLAGS.)
Yes,
Thanks,
Miklos
Quoted 83 lines · Miklos Szeredi
Quoted 67 lines · Max Reitz
Quoted 56 lines · Miklos Szeredi
Pushed an updated version to fuse.git#submounts.
Also attached incremental patch (against rebase of virtiofs-submounts-v2 on fuse.git#for-next).
Changes:
1) rebased on top of DAX patches
2) fixed CUSE
3) added locking forfc->mountslist
4) dissociate lifetime of fc from lifetime of root mount
5) do not hash mountpoint inodes
6) addFUSE_SUBMOUNTSinit flag (replacesFUSE_ATTR_FLAGSbut
slightly different usage)
7) various cleanupsNote, the effect of 5 can only be observed if the same directory is bind mounted into multiple places:
HOST:
cd /mnt
mkdir 1 2
mount --bind/dev/shm1
mount --bind/dev/shm2GUEST:
mount -t virtiofs mnt /mnt
cd/mnt/1
ls ../2/bin/pwdIf the mountpoint is hashed, then the "ls ../2" will basically result in
/mnt/1inode being moved to/mnt/2, which is not what we want. I don't think there's any negative side effect of the mountpoint being unhashed, but this is a bit subtle.On the server side, keying on just st_ino/st_dev is a really crude way of mapping out mounts. Take this example:
HOST:
cd /mnt
mkdir 1
mount --bind/dev/shm1
cd 1
mkdir 2
mount --bind /mnt 2
ls/mnt/1/2/1GUEST:
mount -t virtiofs mnt /mnt
ls/mnt/1/2/1
2
ls/mnt/1/2/1/2/1/2/1/
2Quoted 8 lines
So what we really need is keying on mount ID as well.
Attaching an incremental patch to do that. Needs v5.8 kernel on host to actually make a difference, but commit
fa2fcf4f1df1("statx: add mount ID") is trivial to backport to any kernel that has statx.Please review and test. If there are no major issues, this should be good to go for v5.10.
Quoted 6 lines
As for the virtiofsd patch, I wonder about:
Quoted 1 line
#if 0 &&
defined(HAVE_STATX)&&STATX_MNT_IDShouldn’t the 0 not be there? And should
STATX_MNT_IDbe wrapped indefined()?Right, that was left there from testing.
Quoted 5 lines
Furthermore I wonder why you have removed the
parent_devlogic. With your patch,FUSE_ATTR_SUBMOUNTcan be announced only by those functions that invokelo_do_lookup(). Is it OK to do so only there, and not every time afuse_attris returned (be it as part offuse_entry_out, as bylo_link(), or directly bylo_getattr())?
Quoted 3 lines
No, object creation never results in a mounted object. If the newly created object is mounted on at a later time, the revalidate logic will take care of that.
So lo_getattr() is not an issue either, because all mount operations will be handled by the revalidate logic?
Max
Miklos Szeredi
maintainerQuoted 6 lines · Max Reitz
Quoted 3 lines
No, object creation never results in a mounted object. If the newly created object is mounted on at a later time, the revalidate logic will take care of that.
So
lo_getattr()is not an issue either, because all mount operations will be handled by the revalidate logic?
Right. Attribute revalidation is done by GETATTR and lookup revalidation is done by LOOKUP. Setting the automount point in case of attribute revalidation would not make any difference, since no lookup is being performed at that point.
Thanks,
Miklos