Skip to contentSkip to conversation

Duplicate submounts in the guest

RFC In review Max Reitz 4 participants 29 messages May 6, 2020 – May 8, 2020

Subsystems (2)
lore
Share & tools
lore

Max Reitz

author
#0 lore raw

Hi,

This RFC consists of two patch series, one for virtiofsd (i.e., to be applied to the qemu repo), and one for Linux.

The problem it wants to solve is that virtiofsd just passes through the stat.st_ino value from the host to the guest, without taking stat.st_dev into account. Therefore, it is generally impossible to uniquely identify nodes in the guest by their st_dev/st_ino combinations.

One way to fix this would be to derive some algorithm to derive a unique st_ino value from the st_dev/st_ino combination on the host, but this is not always possible.

So what this series does it basically passing through st_dev alongside
st_ino: We can let the guest create auto-mounted submounts for every host mount point, so that they get their own dedicated st_dev. This is similar to what NFS does with the crossmnt option.

Announcing submounts to the guest (the FUSE client) is done by the FUSE server (virtiofsd) of setting st_rdev to a non-zero value (e.g. st_dev) for every mount point.

In this version here, duplicate mounts on the host (same st_dev) will not necessarily have the same st_dev in the guest. That would be more complicated to implement, and there is probably no real need to.

Furthermore, note that virtiofsd identifies files based on st_dev/st_ino, so if you do have duplicate mounts on the guest, it is very much possible that you will run into problems when trying to pass them through to the guest (because virtiofsd may treat them as one and the same tree).

Signature · 1 line
2.26.2
author
#1 lore raw

cover fuse: Auto-mounted submounts

Hi,

As explained in the common cover letter (<[email protected]>),
we want the Linux FUSE driver to be able to create auto-mounted submounts for every submount on the host.

To do so, we need to allow multiple super blocks per fuse_conn, which is done by splitting an SB-specific fuse_mount structure off of fuse_conn, so there can be multiple fuse_mounts per fuse_conn.

We can then create new super blocks (with anonymous block devices backing them) for every submount point, letting them point to a shared fuse_conn structure.

Max Reitz (5):
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    | 131 ++++++++++++++++++--------
 fs/fuse/control.c   | 194 +++++++++++++++++++-------------------
 fs/fuse/dev.c       | 215 ++++++++++++++++++++++++------------------
 fs/fuse/dir.c       | 191 +++++++++++++++++++++++++++-----------
 fs/fuse/file.c      | 212 +++++++++++++++++++++---------------------
 fs/fuse/inode.c     | 221 ++++++++++++++++++++++++++++++--------------
 fs/fuse/readdir.c   |  10 +-
 fs/fuse/virtio_fs.c |  40 +++++---
 fs/fuse/xattr.c     |  34 +++----
 9 files changed, 766 insertions(+), 482 deletions(-)
Signature · 1 line
2.26.2
author
#2 lore raw

RFC 1/5 fuse: Store fuse_conn in fuse_req

Every 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
index ca344bf71404..f857b371f5a9 100644
@@ -359,6 +359,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
index 97eec7522bf2..f4e8ca9e8ef4 100644
@@ -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
author
#3 lore raw

RFC 2/5 fuse: Drop fuse_conn parameter where possible

In reply to Max Reitz

With 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
index f857b371f5a9..2f510e9eb967 100644
@@ -925,7 +925,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
index bade74768903..3d2c36c9e75e 100644
@@ -283,7 +283,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__);
@@ -298,7 +297,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 */
@@ -329,7 +328,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);
 		}
 	}
 }
@@ -490,7 +489,6 @@ static void virtio_fs_requests_done_work(struct work_struct *work)
 	struct virtio_fs_vq *fsvq = container_of(work, struct virtio_fs_vq,
 						 done_work);
 	struct fuse_pqueue *fpq = &fsvq->fud->pq;
-	struct fuse_conn *fc = fsvq->fud->fc;
 	struct virtqueue *vq = fsvq->vq;
 	struct fuse_req *req;
 	struct fuse_args_pages *ap;
@@ -543,7 +541,7 @@ static void virtio_fs_requests_done_work(struct work_struct *work)
 		list_del_init(&req->list);
 		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
author
#4 lore raw

RFC 3/5 fuse: Split fuse_mount off of fuse_conn

In reply to Max Reitz

From: Max Reitz <[email protected]>

We 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.

---
 fs/fuse/fuse_i.h    | 117 +++++++++++++++++-------
 fs/fuse/control.c   | 194 ++++++++++++++++++++--------------------
 fs/fuse/dev.c       | 160 +++++++++++++++++++--------------
 fs/fuse/dir.c       | 106 +++++++++++-----------
 fs/fuse/file.c      | 212 ++++++++++++++++++++++----------------------
 fs/fuse/inode.c     | 128 +++++++++++++++++---------
 fs/fuse/readdir.c   |  10 +--
 fs/fuse/virtio_fs.c |  29 ++++--
 fs/fuse/xattr.c     |  34 +++----
 9 files changed, 563 insertions(+), 427 deletions(-)
fs/fuse/fuse_i.h +83 -34
index 2f510e9eb967..3b2b47e2e966 100644
@@ -47,10 +47,10 @@
 /** Number of dentries for each connection in the control filesystem */
 #define FUSE_CTL_NUM_DENTRIES 5
 
-/** List of active connections */
-extern struct list_head fuse_conn_list;
+/** List of mounted filesystems */
+extern struct list_head fuse_mount_list;
 
-/** Global mutex protecting fuse_conn_list and the control filesystem */
+/** Global mutex protecting fuse_mount_list and the control filesystem */
 extern struct mutex fuse_mutex;
 
 /** Module parameters */
@@ -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;
@@ -251,7 +252,7 @@ struct fuse_args {
 	bool page_replace: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 {
@@ -360,8 +361,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;
@@ -496,9 +497,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 */
@@ -728,18 +729,6 @@ struct fuse_conn {
 	/** Negotiated minor version */
 	unsigned minor;
 
-	/** Entry on the fuse_conn_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];
-
-	/** number of dentries used in the above array */
-	int ctl_ndents;
-
 	/** Key for lock owner ID scrambling */
 	u32 scramble_key[4];
 
@@ -749,24 +738,69 @@ struct fuse_conn {
 	/** Called on final put */
 	void (*release)(struct fuse_conn *);
 
+	/** List of device instances belonging to this connection */
+	struct list_head devices;
+
+	/** List of filesystems using this connection */
+	struct list_head mounts;
+};
+
+/**
+ * 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. */
 	struct super_block *sb;
 
 	/** Read/write semaphore to hold when accessing sb. */
 	struct rw_semaphore killsb;
 
-	/** List of device instances belonging to this connection */
-	struct list_head devices;
+	/** Dentries in the control filesystem */
+	struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
+
+	/** number of dentries used in the above array */
+	int ctl_ndents;
+
+	/** Entry on the fuse_mount_list */
+	struct list_head entry;
+
+	/** Entry on fc->mounts */
+	struct list_head fc_entry;
 };
 
-static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
+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)
@@ -850,7 +884,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);
 
@@ -870,7 +904,7 @@ int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
 /**
  * Notify poll wakeup
  */
-int fuse_notify_poll_wakeup(struct fuse_conn *fc,
+int fuse_notify_poll_wakeup(struct fuse_mount *fm,
 			    struct fuse_notify_poll_wakeup_out *outarg);
 
 /**
@@ -918,8 +952,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);
 
 /**
@@ -959,11 +993,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);
+
+/**
+ * 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
@@ -982,12 +1031,12 @@ void fuse_kill_sb_anon(struct super_block *sb);
 /**
  * Add connection to control filesystem
  */
-int fuse_ctl_add_conn(struct fuse_conn *fc);
+int fuse_ctl_add_conn(struct fuse_mount *fm);
 
 /**
  * Remove connection from control filesystem
  */
-void fuse_ctl_remove_conn(struct fuse_conn *fc);
+void fuse_ctl_remove_conn(struct fuse_mount *fm);
 
 /**
  * Is file type valid?
@@ -1031,7 +1080,7 @@ int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
 int fuse_reverse_inval_entry(struct super_block *sb, 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 +99 -95

388 lines not on this page · raw message

fs/fuse/dev.c +91 -69

442 lines not on this page · raw message

fs/fuse/dir.c +54 -52

372 lines not on this page · raw message

fs/fuse/file.c +108 -104

715 lines not on this page · raw message

fs/fuse/inode.c +84 -44

301 lines not on this page · raw message

fs/fuse/readdir.c +5 -5
index 90e3f01bd796..3b5e91045871 100644
@@ -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 +22 -7
index 3d2c36c9e75e..492ddd34ecd9 100644
@@ -1035,7 +1035,8 @@ static const struct fuse_iqueue_ops virtio_fs_fiq_ops = {
 
 static int virtio_fs_fill_super(struct super_block *sb)
 {
-	struct fuse_conn *fc = get_fuse_conn_super(sb);
+	struct fuse_mount *fm = get_fuse_mount_super(sb);
+	struct fuse_conn *fc = fm->fc;
 	struct virtio_fs *fs = fc->iq.priv;
 	unsigned int i;
 	int err;
@@ -1090,7 +1091,7 @@ static int virtio_fs_fill_super(struct super_block *sb)
 
 	/* Previous unmount will stop all queues. Start these again */
 	virtio_fs_start_all_queues(fs);
-	fuse_send_init(fc);
+	fuse_send_init(fm);
 	mutex_unlock(&virtio_fs_mutex);
 	return 0;
 
@@ -1135,9 +1136,10 @@ static void virtio_kill_sb(struct super_block *sb)
 static int virtio_fs_test_super(struct super_block *sb,
 				struct fs_context *fsc)
 {
-	struct fuse_conn *fc = fsc->s_fs_info;
+	struct fuse_mount *fsc_fm = fsc->s_fs_info;
+	struct fuse_mount *sb_fm = get_fuse_mount_super(sb);
 
-	return fc->iq.priv == get_fuse_conn_super(sb)->iq.priv;
+	return fsc_fm->fc->iq.priv == sb_fm->fc->iq.priv;
 }
 
 static int virtio_fs_set_super(struct super_block *sb,
@@ -1147,7 +1149,7 @@ static int virtio_fs_set_super(struct super_block *sb,
 
 	err = get_anon_bdev(&sb->s_dev);
 	if (!err)
-		fuse_conn_get(fsc->s_fs_info);
+		fuse_mount_get(fsc->s_fs_info);
 
 	return err;
 }
@@ -1157,6 +1159,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
 	struct virtio_fs *fs;
 	struct super_block *sb;
 	struct fuse_conn *fc;
+	struct fuse_mount *fm;
 	int err;
 
 	/* This gets a reference on virtio_fs object. This ptr gets installed
@@ -1177,14 +1180,26 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
 		return -ENOMEM;
 	}
 
+	fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
+	if (!fm) {
+		mutex_lock(&virtio_fs_mutex);
+		virtio_fs_put(fs);
+		mutex_unlock(&virtio_fs_mutex);
+		kfree(fc);
+		return -ENOMEM;
+	}
+
 	fuse_conn_init(fc, get_user_ns(current_user_ns()), &virtio_fs_fiq_ops,
 		       fs);
 	fc->release = fuse_free_conn;
 	fc->delete_stale = true;
 
-	fsc->s_fs_info = fc;
-	sb = sget_fc(fsc, virtio_fs_test_super, virtio_fs_set_super);
+	fuse_mount_init(fm, fc);
 	fuse_conn_put(fc);
+
+	fsc->s_fs_info = fm;
+	sb = sget_fc(fsc, virtio_fs_test_super, virtio_fs_set_super);
+	fuse_mount_put(fm);
 	if (IS_ERR(sb))
 		return PTR_ERR(sb);
 
fs/fuse/xattr.c +17 -17
index 20d052e08b3b..371bdcbc7233 100644
@@ -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
#5 lore raw

Re: [Virtio-fs] [RFC 3/5] fuse: Split fuse_mount off of fuse_conn

Quoted 8 lines · Max Reitz

From: Max Reitz <[email protected]>

We 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.

I have the following high level comments:

Control filesystem: each fuse_mount gets a new entry, but they are all
aliases. I think we should just stick with just one entry for the
connection (and perhaps a symlink for each additional mount, but this is of secondary importance).

BDI: we need to call set_bdi_congested/clear_bdi_congested for *all* mounts of a connection. Might make sense to look into getting rid of bdi congestion handling completely, but this is not something I have a good insight into right now.

Notification: please create a fuse_ilookup() that takes fc and returns
(sb, inode) pair and call this instead ilookup5(). This way the loop
is moved to the place where it's actually necessary.

Thanks,
Miklos

author
#6 lore raw

Re: [Virtio-fs] [RFC 3/5] fuse: Split fuse_mount off of fuse_conn

Quoted 3 lines · Miklos Szeredi
Quoted 2 lines · Max Reitz

From: Max Reitz <[email protected]>

Oops.

Quoted 6 lines
Quoted 5 lines

We 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.

Quoted 6 lines

I have the following high level comments:

Control filesystem: each fuse_mount gets a new entry, but they are all
aliases. I think we should just stick with just one entry for the
connection (and perhaps a symlink for each additional mount, but this is of secondary importance).

I have to admit that I didn’t spend much thought on any of this, but just went with what worked. Since one of the functions in control.c require the super block, I went with fuse_mount.

I suppose for fuse_ctl_add_conn() (for @name), we can simply use the first fuse_mount’s device ID.

Quoted 2 lines

BDI: we need to call set_bdi_congested/clear_bdi_congested for *all* mounts of a connection.

OK, then one entry per fuse_conn will work.

But do we need to do the same in fuse_request_end() and fuse_request_queue_background()?

Quoted 7 lines

Might make sense to look into getting rid of
bdi congestion handling completely, but this is not something I have a good insight into right now.

Notification: please create a fuse_ilookup() that takes fc and returns
(sb, inode) pair and call this instead ilookup5(). This way the loop
is moved to the place where it's actually necessary.

Hm, sounds a bit cumbersome for the fuse_notify_* functions that don’t directly call ilookup5(). But they always have a callee that does, so I suppose I’ll just have to move that up to the caller. That should work then.

Thanks!

Max

#7 lore raw

Re: [Virtio-fs] [RFC 3/5] fuse: Split fuse_mount off of fuse_conn

Quoted 21 lines · Max Reitz
Quoted 3 lines · Miklos Szeredi
Quoted 2 lines · Max Reitz

From: Max Reitz <[email protected]>

Oops.

Quoted 6 lines
Quoted 5 lines

We 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.

Quoted 6 lines

I have the following high level comments:

Control filesystem: each fuse_mount gets a new entry, but they are all
aliases. I think we should just stick with just one entry for the
connection (and perhaps a symlink for each additional mount, but this is of secondary importance).

Quoted 6 lines

I have to admit that I didn’t spend much thought on any of this, but just went with what worked. Since one of the functions in control.c require the super block, I went with fuse_mount.

I suppose for fuse_ctl_add_conn() (for @name), we can simply use the first fuse_mount’s device ID.

Yes.

Quoted 8 lines
Quoted 3 lines

BDI: we need to call set_bdi_congested/clear_bdi_congested for *all* mounts of a connection.

OK, then one entry per fuse_conn will work.

But do we need to do the same in fuse_request_end() and fuse_request_queue_background()?

Definitely. Otherwise one bdi could have its congestion state set, and the other one cleared. Not good.

Even better: share the bdi between submounts. This would make a lot more sense and remove the need for loops.

Quoted 5 lines
Quoted 5 lines

Might make sense to look into getting rid of
bdi congestion handling completely, but this is not something I have a good insight into right now.

Quoted 8 lines
Quoted 3 lines

Notification: please create a fuse_ilookup() that takes fc and returns
(sb, inode) pair and call this instead ilookup5(). This way the loop
is moved to the place where it's actually necessary.

Hm, sounds a bit cumbersome for the fuse_notify_* functions that don’t directly call ilookup5(). But they always have a callee that does, so I suppose I’ll just have to move that up to the caller. That should work then.

I'd rather say: move the fc down to the callee. The kill_sb mutex can remain in fuse_conn, so callers shouldn't need an sb.

Thanks,
Miklos

author
#8 lore raw

Re: [Virtio-fs] [RFC 3/5] fuse: Split fuse_mount off of fuse_conn

Quoted 37 lines · Miklos Szeredi
Quoted 21 lines · Max Reitz
Quoted 3 lines · Miklos Szeredi
Quoted 2 lines · Max Reitz

From: Max Reitz <[email protected]>

Oops.

Quoted 6 lines
Quoted 5 lines

We 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.

Quoted 6 lines

I have the following high level comments:

Control filesystem: each fuse_mount gets a new entry, but they are all
aliases. I think we should just stick with just one entry for the
connection (and perhaps a symlink for each additional mount, but this is of secondary importance).

Quoted 6 lines

I have to admit that I didn’t spend much thought on any of this, but just went with what worked. Since one of the functions in control.c require the super block, I went with fuse_mount.

I suppose for fuse_ctl_add_conn() (for @name), we can simply use the first fuse_mount’s device ID.

Yes.

Quoted 6 lines
Quoted 3 lines

BDI: we need to call set_bdi_congested/clear_bdi_congested for *all* mounts of a connection.

OK, then one entry per fuse_conn will work.

Quoted 8 lines
Quoted 2 lines

But do we need to do the same in fuse_request_end() and fuse_request_queue_background()?

Definitely. Otherwise one bdi could have its congestion state set, and the other one cleared. Not good.

Even better: share the bdi between submounts. This would make a lot more sense and remove the need for loops.

Hm, isn’t bdi related to the (anonymous) block device “serving” the super block, and thus the st_dev value? (Which is necessarily different for all fuse_mounts)

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Might make sense to look into getting rid of
bdi congestion handling completely, but this is not something I have a good insight into right now.

Notification: please create a fuse_ilookup() that takes fc and returns
(sb, inode) pair and call this instead ilookup5(). This way the loop
is moved to the place where it's actually necessary.

Quoted 7 lines
Quoted 4 lines

Hm, sounds a bit cumbersome for the fuse_notify_* functions that don’t directly call ilookup5(). But they always have a callee that does, so I suppose I’ll just have to move that up to the caller. That should work then.

I'd rather say: move the fc down to the callee. The kill_sb mutex can remain in fuse_conn, so callers shouldn't need an sb.

OK.

Max

#9 lore raw

Re: [Virtio-fs] [RFC 3/5] fuse: Split fuse_mount off of fuse_conn

Quoted 9 lines · Max Reitz
Quoted 2 lines · Miklos Szeredi

Even better: share the bdi between submounts. This would make a lot more sense and remove the need for loops.

Hm, isn’t bdi related to the (anonymous) block device “serving” the super block, and thus the st_dev value? (Which is necessarily different for all fuse_mounts)

BDI is normally an object bound to a block device, but a block device can have multiple partitions, each having different st_dev values. So yes, a bdi *can* be shared by multiple super blocks, and this very much makes sense in the case of fuse submounts sharing a connection.

Thanks,
Miklos

author
#10 lore raw

Re: [Virtio-fs] [RFC 3/5] fuse: Split fuse_mount off of fuse_conn

Quoted 7 lines · Miklos Szeredi
Quoted 6 lines · Max Reitz
Quoted 2 lines · Miklos Szeredi

Even better: share the bdi between submounts. This would make a lot more sense and remove the need for loops.

Quoted 8 lines
Quoted 3 lines

Hm, isn’t bdi related to the (anonymous) block device “serving” the super block, and thus the st_dev value? (Which is necessarily different for all fuse_mounts)

BDI is normally an object bound to a block device, but a block device can have multiple partitions, each having different st_dev values. So yes, a bdi *can* be shared by multiple super blocks, and this very much makes sense in the case of fuse submounts sharing a connection.

OK. Seems like all I’d need to do is let fuse_bdi_init() clone (bdi_get()) the existing BDI for submounts. However, the BDI’s name (in sysfs) is going to be based on the root mount’s st_dev. Is that a problem?

(Sorry if I’m asking questions whose answer seem obvious to you, but I’m afraid I’m rather new to everything, and it all still overwhelms me a bit.)

Max

#11 lore raw

Re: [Virtio-fs] [RFC 3/5] fuse: Split fuse_mount off of fuse_conn

Quoted 13 lines · Max Reitz
Quoted 11 lines · Miklos Szeredi
Quoted 9 lines · Max Reitz
Quoted 2 lines · Miklos Szeredi

Even better: share the bdi between submounts. This would make a lot more sense and remove the need for loops.

Hm, isn’t bdi related to the (anonymous) block device “serving” the super block, and thus the st_dev value? (Which is necessarily different for all fuse_mounts)

Quoted 8 lines
Quoted 4 lines

BDI is normally an object bound to a block device, but a block device can have multiple partitions, each having different st_dev values. So yes, a bdi *can* be shared by multiple super blocks, and this very much makes sense in the case of fuse submounts sharing a connection.

OK. Seems like all I’d need to do is let fuse_bdi_init() clone (bdi_get()) the existing BDI for submounts. However, the BDI’s name (in sysfs) is going to be based on the root mount’s st_dev. Is that a problem?

I don't think that's a problem.

Quoted 2 lines

(Sorry if I’m asking questions whose answer seem obvious to you, but I’m afraid I’m rather new to everything, and it all still overwhelms me a bit.)

Don't be sorry :)

Thanks,
Miklos

author
#12 lore raw

RFC 4/5 fuse: Allow fuse_fill_super_common() for submounts

In reply to Max Reitz

Submounts 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.

---
 fs/fuse/fuse_i.h    | 10 +++--
 fs/fuse/inode.c     | 89 +++++++++++++++++++++++++++++++++------------
 fs/fuse/virtio_fs.c |  2 +-
 3 files changed, 74 insertions(+), 27 deletions(-)
fs/fuse/fuse_i.h +7 -3
index 3b2b47e2e966..d8528aa97386 100644
@@ -1015,11 +1015,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 +66 -23

150 lines not on this page · raw message

fs/fuse/virtio_fs.c +1 -1
index 492ddd34ecd9..38100f096421 100644
@@ -1075,7 +1075,7 @@ static int virtio_fs_fill_super(struct super_block *sb)
 	}
 
 	ctx.fudptr = (void **)&fs->vqs[VQ_REQUEST].fud;
-	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
author
#13 lore raw

RFC 5/5 fuse: Implement crossmounts

In reply to Max Reitz

With this commit, FUSE servers can indicate crossmount points by putting the mounted filesystem's st_dev into st_rdev (which is otherwise unused for directories). 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).

We could keep a mapping of "server-reported st_rdev" to "anonymous st_dev" (as returned by get_anon_bdev()), and thus use the same st_dev for multiple superblocks, but that probably has pitfalls that are not worth risking for something that most likely nobody needs.

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       | 85 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/inode.c     |  6 ++--
 fs/fuse/virtio_fs.c |  1 +
 4 files changed, 93 insertions(+), 2 deletions(-)
fs/fuse/fuse_i.h +3 -0
index d8528aa97386..af73d60253d8 100644
@@ -723,6 +723,9 @@ struct fuse_conn {
 	/* Do not show mount options */
 	unsigned int no_mount_options: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 +85 -0

103 lines not on this page · raw message

fs/fuse/inode.c +4 -2
index ff30d30b3faf..77a386cad12f 100644
@@ -253,9 +253,11 @@ 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)) {
 		fuse_init_dir(inode);
-	else if (S_ISLNK(inode->i_mode))
+		if (attr->rdev && get_fuse_conn(inode)->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
index 38100f096421..53dae0ee5ab1 100644
@@ -1193,6 +1193,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);
 	fuse_conn_put(fc);
Signature · 1 line
2.26.2
author
#14 lore raw

cover virtiofsd: Announce submounts

In reply to Max Reitz

Hi,

As explained in the common cover letter (<[email protected]>),
we want to let the guest mirror the mount structure on the host.

To do so, we need to set st_rdev to a non-zero value[1] for mount points, and this is what this series makes virtiofsd do (optionally, because some users may prefer not to pass this information through to the guest).

[1] In practice, any non-zero value will do, but we might want it to be st_dev so the guest might in the future special-case duplicate mounts (by using a single block device for them, so they all get the same st_dev).

Max Reitz (2):
virtiofsd: Store every lo_inode's parent_dev
virtiofsd: Set st_rdev for sub-mount points

 tools/virtiofsd/passthrough_ll.c | 79 ++++++++++++++++++++++++++++----
 1 file changed, 70 insertions(+), 9 deletions(-)
Signature · 1 line
2.26.2
author
#15 lore raw

RFC 1/2 virtiofsd: Store every lo_inode's parent_dev

We want to detect mount points in the shared tree. We report them to the guest by setting st_rdev to their st_dev, but because the FUSE client will create a submount for every directory that has st_rdev set, we must do this only for the actual mount points.

We can detect mount points by comparing a directory's st_dev with its parent's st_dev. To be able to do so, we need to store the parent's st_dev in the lo_inode object.

---
 tools/virtiofsd/passthrough_ll.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/virtiofsd/passthrough_ll.c +20 -0
index 3ba1d90984..6cf471d31a 100644
@@ -124,6 +124,14 @@ struct lo_inode {
     GHashTable *posix_locks; /* protected by lo_inode->plock_mutex */
 
     mode_t filetype;
+
+    /*
+     * So we can detect crossmount roots
+     * (As such, this only needs to be valid for directories.  Note
+     * that files can have multiple parents due to hard links, and so
+     * their parent_dev may fluctuate.)
+     */
+    dev_t parent_dev;
 };
 
 struct lo_cred {
@@ -673,6 +681,9 @@ retry:
     *parent = p;
     memmove(path, last, strlen(last) + 1);
 
+    /* Use this opportunity to update the inode's parent_dev */
+    inode->parent_dev = p->key.dev;
+
     return 0;
 
 fail_unref:
@@ -950,6 +961,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
         g_hash_table_insert(lo->inodes, &inode->key, inode);
         pthread_mutex_unlock(&lo->mutex);
     }
+    inode->parent_dev = dir->key.dev;
     e->ino = inode->fuse_ino;
     lo_inode_put(lo, &inode);
     lo_inode_put(lo, &dir);
@@ -1208,6 +1220,14 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
     fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n", (unsigned long long)parent,
              name, (unsigned long long)e.ino);
 
+    /*
+     * No need to update inode->parent_dev, because
+     * (1) We cannot, the inode now has more than one parent,
+     * (2) Directories cannot have more than one parent, so link()
+     *     does not work for them; but parent_dev only needs to be
+     *     valid for directories.
+     */
+
     fuse_reply_entry(req, &e);
     lo_inode_put(lo, &parent_inode);
     lo_inode_put(lo, &inode);
Signature · 1 line
2.26.2
author
#16 lore raw

RFC 2/2 virtiofsd: Set st_rdev for sub-mount points

In reply to Max Reitz

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

---
 tools/virtiofsd/passthrough_ll.c | 59 +++++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 9 deletions(-)
tools/virtiofsd/passthrough_ll.c +50 -9
index 6cf471d31a..abf9d33493 100644
@@ -159,6 +159,7 @@ struct lo_data {
     int timeout_set;
     int readdirplus_set;
     int readdirplus_clear;
+    int announce_submounts;
     struct lo_inode root;
     GHashTable *inodes; /* protected by lo->mutex */
     struct lo_map ino_map; /* protected by lo->mutex */
@@ -187,6 +188,7 @@ static const struct fuse_opt lo_opts[] = {
     { "norace", offsetof(struct lo_data, norace), 1 },
     { "readdirplus", offsetof(struct lo_data, readdirplus_set), 1 },
     { "no_readdirplus", offsetof(struct lo_data, readdirplus_clear), 1 },
+    { "announce_submounts", offsetof(struct lo_data, announce_submounts), 1 },
     FUSE_OPT_END
 };
 static bool use_syslog = false;
@@ -582,17 +584,42 @@ static void lo_init(void *userdata, struct fuse_conn_info *conn)
     }
 }
 
+/**
+ * Call fstatat() and set st_rdev whenever a directory's st_dev
+ * differs from the rparent's st_dev (@parent_dev).  This will
+ * announce submounts to the FUSE client (unless @announce_submounts
+ * is false).
+ */
+static int do_fstatat(int dirfd, const char *pathname, struct stat *statbuf,
+                      int flags, dev_t parent_dev, bool announce_submounts)
+{
+    int res = fstatat(dirfd, pathname, statbuf, flags);
+    if (res == -1) {
+        return res;
+    }
+
+    if (statbuf->st_dev != parent_dev && S_ISDIR(statbuf->st_mode) &&
+        announce_submounts)
+    {
+        statbuf->st_rdev = statbuf->st_dev;
+    }
+
+    return 0;
+}
+
 static void lo_getattr(fuse_req_t req, fuse_ino_t ino,
                        struct fuse_file_info *fi)
 {
     int res;
     struct stat buf;
     struct lo_data *lo = lo_data(req);
+    struct lo_inode *inode = lo_inode(req, ino);
 
     (void)fi;
 
-    res =
-        fstatat(lo_fd(req, ino), "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(inode->fd, "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW,
+                     inode->parent_dev, lo->announce_submounts);
+    lo_inode_put(lo, &inode);
     if (res == -1) {
         return (void)fuse_reply_err(req, errno);
     }
@@ -645,7 +672,9 @@ retry:
         pthread_mutex_unlock(&lo->mutex);
     } else {
         *last = '\0';
-        res = fstatat(AT_FDCWD, last == path ? "/" : path, &stat, 0);
+        /* Pass parent_dev=0 because st_rdev will be ignored anyway */
+        res = do_fstatat(AT_FDCWD, last == path ? "/" : path, &stat, 0, 0,
+                         lo->announce_submounts);
         if (res == -1) {
             if (!retries) {
                 fuse_log(FUSE_LOG_WARNING,
@@ -663,7 +692,8 @@ retry:
         }
     }
     last++;
-    res = fstatat(p->fd, last, &stat, AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(p->fd, last, &stat, AT_SYMLINK_NOFOLLOW, p->key.dev,
+                     lo->announce_submounts);
     if (res == -1) {
         if (!retries) {
             fuse_log(FUSE_LOG_WARNING,
@@ -925,7 +955,8 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
         goto out_err;
     }
 
-    res = fstatat(newfd, "", &e->attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(newfd, "", &e->attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW,
+                     dir->key.dev, lo->announce_submounts);
     if (res == -1) {
         goto out_err;
     }
@@ -1207,7 +1238,9 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
         goto out_err;
     }
 
-    res = fstatat(inode->fd, "", &e.attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(inode->fd, "", &e.attr,
+                     AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW,
+                     parent_inode->key.dev, lo->announce_submounts);
     if (res == -1) {
         goto out_err;
     }
@@ -1246,14 +1279,22 @@ static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent,
 {
     int res;
     struct stat attr;
+    struct lo_data *lo = lo_data(req);
+    struct lo_inode *dir = lo_inode(req, parent);
 
-    res = fstatat(lo_fd(req, parent), name, &attr,
-                  AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    if (!dir) {
+        return NULL;
+    }
+
+    res = do_fstatat(dir->fd, name, &attr,
+                     AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW, dir->key.dev,
+                     lo->announce_submounts);
+    lo_inode_put(lo, &dir);
     if (res == -1) {
         return NULL;
     }
 
-    return lo_find(lo_data(req), &attr);
+    return lo_find(lo, &attr);
 }
 
 static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
Signature · 1 line
2.26.2
#17 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

Quoted 10 lines · * Max Reitz ([email protected]) wrote:

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

Does this need to be wired to a flag in the INIT message (like say FUSE_ASYNC_READ) to indicate that the kernel/daemon supports this, or is it really safe just to start sending the changed rdev?

Dave

Quoted 144 lines
---
 tools/virtiofsd/passthrough_ll.c | 59 +++++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 9 deletions(-)
tools/virtiofsd/passthrough_ll.c +50 -9
index 6cf471d31a..abf9d33493 100644
@@ -159,6 +159,7 @@ struct lo_data {
     int timeout_set;
     int readdirplus_set;
     int readdirplus_clear;
+    int announce_submounts;
     struct lo_inode root;
     GHashTable *inodes; /* protected by lo->mutex */
     struct lo_map ino_map; /* protected by lo->mutex */
@@ -187,6 +188,7 @@ static const struct fuse_opt lo_opts[] = {
     { "norace", offsetof(struct lo_data, norace), 1 },
     { "readdirplus", offsetof(struct lo_data, readdirplus_set), 1 },
     { "no_readdirplus", offsetof(struct lo_data, readdirplus_clear), 1 },
+    { "announce_submounts", offsetof(struct lo_data, announce_submounts), 1 },
     FUSE_OPT_END
 };
 static bool use_syslog = false;
@@ -582,17 +584,42 @@ static void lo_init(void *userdata, struct fuse_conn_info *conn)
     }
 }
 
+/**
+ * Call fstatat() and set st_rdev whenever a directory's st_dev
+ * differs from the rparent's st_dev (@parent_dev).  This will
+ * announce submounts to the FUSE client (unless @announce_submounts
+ * is false).
+ */
+static int do_fstatat(int dirfd, const char *pathname, struct stat *statbuf,
+                      int flags, dev_t parent_dev, bool announce_submounts)
+{
+    int res = fstatat(dirfd, pathname, statbuf, flags);
+    if (res == -1) {
+        return res;
+    }
+
+    if (statbuf->st_dev != parent_dev && S_ISDIR(statbuf->st_mode) &&
+        announce_submounts)
+    {
+        statbuf->st_rdev = statbuf->st_dev;
+    }
+
+    return 0;
+}
+
 static void lo_getattr(fuse_req_t req, fuse_ino_t ino,
                        struct fuse_file_info *fi)
 {
     int res;
     struct stat buf;
     struct lo_data *lo = lo_data(req);
+    struct lo_inode *inode = lo_inode(req, ino);
 
     (void)fi;
 
-    res =
-        fstatat(lo_fd(req, ino), "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(inode->fd, "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW,
+                     inode->parent_dev, lo->announce_submounts);
+    lo_inode_put(lo, &inode);
     if (res == -1) {
         return (void)fuse_reply_err(req, errno);
     }
@@ -645,7 +672,9 @@ retry:
         pthread_mutex_unlock(&lo->mutex);
     } else {
         *last = '\0';
-        res = fstatat(AT_FDCWD, last == path ? "/" : path, &stat, 0);
+        /* Pass parent_dev=0 because st_rdev will be ignored anyway */
+        res = do_fstatat(AT_FDCWD, last == path ? "/" : path, &stat, 0, 0,
+                         lo->announce_submounts);
         if (res == -1) {
             if (!retries) {
                 fuse_log(FUSE_LOG_WARNING,
@@ -663,7 +692,8 @@ retry:
         }
     }
     last++;
-    res = fstatat(p->fd, last, &stat, AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(p->fd, last, &stat, AT_SYMLINK_NOFOLLOW, p->key.dev,
+                     lo->announce_submounts);
     if (res == -1) {
         if (!retries) {
             fuse_log(FUSE_LOG_WARNING,
@@ -925,7 +955,8 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
         goto out_err;
     }
 
-    res = fstatat(newfd, "", &e->attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(newfd, "", &e->attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW,
+                     dir->key.dev, lo->announce_submounts);
     if (res == -1) {
         goto out_err;
     }
@@ -1207,7 +1238,9 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
         goto out_err;
     }
 
-    res = fstatat(inode->fd, "", &e.attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    res = do_fstatat(inode->fd, "", &e.attr,
+                     AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW,
+                     parent_inode->key.dev, lo->announce_submounts);
     if (res == -1) {
         goto out_err;
     }
@@ -1246,14 +1279,22 @@ static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent,
 {
     int res;
     struct stat attr;
+    struct lo_data *lo = lo_data(req);
+    struct lo_inode *dir = lo_inode(req, parent);
 
-    res = fstatat(lo_fd(req, parent), name, &attr,
-                  AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    if (!dir) {
+        return NULL;
+    }
+
+    res = do_fstatat(dir->fd, name, &attr,
+                     AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW, dir->key.dev,
+                     lo->announce_submounts);
+    lo_inode_put(lo, &dir);
     if (res == -1) {
         return NULL;
     }
 
-    return lo_find(lo_data(req), &attr);
+    return lo_find(lo, &attr);
 }
 
 static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
Signature · 6 lines
2.26.2

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#18 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Max Reitz ([email protected]) wrote:

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

Quoted 5 lines
Quoted 1 line

Does this need to be wired to a flag in the INIT message (like say FUSE_ASYNC_READ) to indicate that the kernel/daemon supports this, or is it really safe just to start sending the changed rdev?

I supposed it to be safe, given that rdev is never used for anything but device files, so basically it was just a reserved field for directories.

Max

#19 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

Quoted 12 lines · Max Reitz
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Max Reitz ([email protected]) wrote:

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Does this need to be wired to a flag in the INIT message (like say FUSE_ASYNC_READ) to indicate that the kernel/daemon supports this, or is it really safe just to start sending the changed rdev?

I supposed it to be safe, given that rdev is never used for anything but device files, so basically it was just a reserved field for directories.

You assume only directories can be mounted, but that's not so. A device can also be the source or destination of a bind mount.

We need to extend fuse_entry_out with a flags field. We could possibly reuse the upper bits of entry_valid (i.e. timeouts above say INT_MAX seconds could be taken as "infinity"). Unfortunately that's not as easy as splitting it into two fields due to endianness :(

Thanks,
Miklos

author
#20 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

Quoted 19 lines · Miklos Szeredi
Quoted 18 lines · Max Reitz
Quoted 15 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Max Reitz ([email protected]) wrote:

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

Does this need to be wired to a flag in the INIT message (like say FUSE_ASYNC_READ) to indicate that the kernel/daemon supports this, or is it really safe just to start sending the changed rdev?

Quoted 5 lines
Quoted 2 lines

I supposed it to be safe, given that rdev is never used for anything but device files, so basically it was just a reserved field for directories.

You assume only directories can be mounted, but that's not so. A device can also be the source or destination of a bind mount.

Well, I mostly thought this case wouldn’t be too important. But I suppose it doesn’t make sense to decide now that it’s never going to be important.

Quoted 4 lines

We need to extend fuse_entry_out with a flags field. We could possibly reuse the upper bits of entry_valid (i.e. timeouts above say INT_MAX seconds could be taken as "infinity"). Unfortunately that's not as easy as splitting it into two fields due to endianness :(

For the time being, a single bit would be sufficient to signify whether there should be a submount at all. We could add a field with a submount ID (i.e., st_dev from the host) in the future when we decide we want/need to ensure that two inodes with the same st_dev on the host also have the same st_dev in the guest.

Max

#21 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

Quoted 23 lines · * Max Reitz ([email protected]) wrote:
Quoted 22 lines · Miklos Szeredi
Quoted 20 lines · Max Reitz
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Max Reitz ([email protected]) wrote:

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

Quoted 5 lines
Quoted 1 line

Does this need to be wired to a flag in the INIT message (like say FUSE_ASYNC_READ) to indicate that the kernel/daemon supports this, or is it really safe just to start sending the changed rdev?

I supposed it to be safe, given that rdev is never used for anything but device files, so basically it was just a reserved field for directories.

Quoted 6 lines
Quoted 2 lines

You assume only directories can be mounted, but that's not so. A device can also be the source or destination of a bind mount.

Well, I mostly thought this case wouldn’t be too important. But I suppose it doesn’t make sense to decide now that it’s never going to be important.

It's quite common in kata to bind mount individual /etc files - I'm not clear if that's this particular case.

Dave

Quoted 5 lines
Quoted 4 lines

We need to extend fuse_entry_out with a flags field. We could possibly reuse the upper bits of entry_valid (i.e. timeouts above say INT_MAX seconds could be taken as "infinity"). Unfortunately that's not as easy as splitting it into two fields due to endianness :(

Quoted 8 lines

For the time being, a single bit would be sufficient to signify whether there should be a submount at all. We could add a field with a submount ID (i.e., st_dev from the host) in the future when we decide we want/need to ensure that two inodes with the same st_dev on the host also have the same st_dev in the guest.

Max

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#22 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

In reply to Max Reitz
Quoted 36 lines · Max Reitz
Quoted 19 lines · Miklos Szeredi
Quoted 18 lines · Max Reitz
Quoted 15 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Max Reitz ([email protected]) wrote:

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

Does this need to be wired to a flag in the INIT message (like say FUSE_ASYNC_READ) to indicate that the kernel/daemon supports this, or is it really safe just to start sending the changed rdev?

Quoted 5 lines
Quoted 2 lines

I supposed it to be safe, given that rdev is never used for anything but device files, so basically it was just a reserved field for directories.

You assume only directories can be mounted, but that's not so. A device can also be the source or destination of a bind mount.

Well, I mostly thought this case wouldn’t be too important. But I suppose it doesn’t make sense to decide now that it’s never going to be important.

Quoted 4 lines

We need to extend fuse_entry_out with a flags field. We could possibly reuse the upper bits of entry_valid (i.e. timeouts above say INT_MAX seconds could be taken as "infinity"). Unfortunately that's not as easy as splitting it into two fields due to endianness :(

Quoted 5 lines

For the time being, a single bit would be sufficient to signify whether there should be a submount at all. We could add a field with a submount ID (i.e., st_dev from the host) in the future when we decide we want/need to ensure that two inodes with the same st_dev on the host also have the same st_dev in the guest.

Hmm, do we need a separate bit, then? Couldn't the kernel decide based on st_dev whether a new submount is needed? I.e. return root st_dev in INIT reply, store it in root fuse_mount and lookups compare attr.dev to fm->st_dev.

Thanks,
Miklos

author
#23 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

Quoted 43 lines · Miklos Szeredi
Quoted 36 lines · Max Reitz
Quoted 19 lines · Miklos Szeredi
Quoted 18 lines · Max Reitz
Quoted 15 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Max Reitz ([email protected]) wrote:

Whenever we encounter a directory with an st_dev that differs from that of its parent, we set st_rdev accordingly so the guest can create a submount for it.

Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure.

Does this need to be wired to a flag in the INIT message (like say FUSE_ASYNC_READ) to indicate that the kernel/daemon supports this, or is it really safe just to start sending the changed rdev?

Quoted 5 lines
Quoted 2 lines

I supposed it to be safe, given that rdev is never used for anything but device files, so basically it was just a reserved field for directories.

You assume only directories can be mounted, but that's not so. A device can also be the source or destination of a bind mount.

Well, I mostly thought this case wouldn’t be too important. But I suppose it doesn’t make sense to decide now that it’s never going to be important.

Quoted 4 lines

We need to extend fuse_entry_out with a flags field. We could possibly reuse the upper bits of entry_valid (i.e. timeouts above say INT_MAX seconds could be taken as "infinity"). Unfortunately that's not as easy as splitting it into two fields due to endianness :(

Quoted 5 lines

For the time being, a single bit would be sufficient to signify whether there should be a submount at all. We could add a field with a submount ID (i.e., st_dev from the host) in the future when we decide we want/need to ensure that two inodes with the same st_dev on the host also have the same st_dev in the guest.

Quoted 4 lines

Hmm, do we need a separate bit, then? Couldn't the kernel decide based on st_dev whether a new submount is needed? I.e. return root st_dev in INIT reply, store it in root fuse_mount and lookups compare attr.dev to fm->st_dev.

That was the idea, but there is no fuse_attr.dev, which is why I (ab)used fuse_attr.rdev instead.

Max

#24 lore raw

Re: [Virtio-fs] [RFC 2/2] virtiofsd: Set st_rdev for sub-mount points

Quoted 10 lines · Max Reitz
Quoted 4 lines · Miklos Szeredi

Hmm, do we need a separate bit, then? Couldn't the kernel decide based on st_dev whether a new submount is needed? I.e. return root st_dev in INIT reply, store it in root fuse_mount and lookups compare attr.dev to fm->st_dev.

That was the idea, but there is no fuse_attr.dev, which is why I (ab)used fuse_attr.rdev instead.

Ah, right.

Thanks,
Miklos

#25 lore raw
In reply to Max Reitz
Quoted 10 lines · * Max Reitz ([email protected]) wrote:

Hi,

This RFC consists of two patch series, one for virtiofsd (i.e., to be applied to the qemu repo), and one for Linux.

The problem it wants to solve is that virtiofsd just passes through the stat.st_ino value from the host to the guest, without taking stat.st_dev into account. Therefore, it is generally impossible to uniquely identify nodes in the guest by their st_dev/st_ino combinations.

Quoted 8 lines

One way to fix this would be to derive some algorithm to derive a unique st_ino value from the st_dev/st_ino combination on the host, but this is not always possible.

So what this series does it basically passing through st_dev alongside
st_ino: We can let the guest create auto-mounted submounts for every host mount point, so that they get their own dedicated st_dev. This is similar to what NFS does with the crossmnt option.

Nice; this should probably get cc'd to fuse-devel and/or put as a pull into their github to see what they have to say.

Dave

Quoted 8 lines

Announcing submounts to the guest (the FUSE client) is done by the FUSE server (virtiofsd) of setting st_rdev to a non-zero value (e.g. st_dev) for every mount point.

In this version here, duplicate mounts on the host (same st_dev) will not necessarily have the same st_dev in the guest. That would be more complicated to implement, and there is probably no real need to.

Quoted 13 lines

Furthermore, note that virtiofsd identifies files based on st_dev/st_ino, so if you do have duplicate mounts on the guest, it is very much possible that you will run into problems when trying to pass them through to the guest (because virtiofsd may treat them as one and the same tree).

Signature · 6 lines
2.26.2

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#26 lore raw
Quoted 15 lines · Dr. David Alan Gilbert
Quoted 14 lines · * Max Reitz ([email protected]) wrote:

Hi,

This RFC consists of two patch series, one for virtiofsd (i.e., to be applied to the qemu repo), and one for Linux.

The problem it wants to solve is that virtiofsd just passes through the stat.st_ino value from the host to the guest, without taking stat.st_dev into account. Therefore, it is generally impossible to uniquely identify nodes in the guest by their st_dev/st_ino combinations.

One way to fix this would be to derive some algorithm to derive a unique st_ino value from the st_dev/st_ino combination on the host, but this is not always possible.

Quoted 7 lines
Quoted 4 lines

So what this series does it basically passing through st_dev alongside
st_ino: We can let the guest create auto-mounted submounts for every host mount point, so that they get their own dedicated st_dev. This is similar to what NFS does with the crossmnt option.

Nice; this should probably get cc'd to fuse-devel and/or put as a pull into their github to see what they have to say.

Sure, I just thought maybe I should gather some opinions here first. :)

Max

maintainer
#27 lore raw
In reply to Max Reitz
Quoted 19 lines · Max Reitz

Hi,

This RFC consists of two patch series, one for virtiofsd (i.e., to be applied to the qemu repo), and one for Linux.

The problem it wants to solve is that virtiofsd just passes through the stat.st_ino value from the host to the guest, without taking stat.st_dev into account. Therefore, it is generally impossible to uniquely identify nodes in the guest by their st_dev/st_ino combinations.

One way to fix this would be to derive some algorithm to derive a unique st_ino value from the st_dev/st_ino combination on the host, but this is not always possible.

So what this series does it basically passing through st_dev alongside
st_ino: We can let the guest create auto-mounted submounts for every host mount point, so that they get their own dedicated st_dev. This is similar to what NFS does with the crossmnt option.

Quoted 7 lines

Announcing submounts to the guest (the FUSE client) is done by the FUSE server (virtiofsd) of setting st_rdev to a non-zero value (e.g. st_dev) for every mount point.

In this version here, duplicate mounts on the host (same st_dev) will not necessarily have the same st_dev in the guest. That would be more complicated to implement, and there is probably no real need to.

Hi Max,

What's duplicate mount. Is it two bind bounts created from same filesystem.

So two bind mounts which have same st_dev on host, will appear to come from two different devices in guest (different st_dev), right?

Vivek

Quoted 14 lines

Furthermore, note that virtiofsd identifies files based on st_dev/st_ino, so if you do have duplicate mounts on the guest, it is very much possible that you will run into problems when trying to pass them through to the guest (because virtiofsd may treat them as one and the same tree).

Signature · 6 lines
2.26.2

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs
author
#28 lore raw
Quoted 24 lines · Vivek Goyal
Quoted 23 lines · Max Reitz

Hi,

This RFC consists of two patch series, one for virtiofsd (i.e., to be applied to the qemu repo), and one for Linux.

The problem it wants to solve is that virtiofsd just passes through the stat.st_ino value from the host to the guest, without taking stat.st_dev into account. Therefore, it is generally impossible to uniquely identify nodes in the guest by their st_dev/st_ino combinations.

One way to fix this would be to derive some algorithm to derive a unique st_ino value from the st_dev/st_ino combination on the host, but this is not always possible.

So what this series does it basically passing through st_dev alongside
st_ino: We can let the guest create auto-mounted submounts for every host mount point, so that they get their own dedicated st_dev. This is similar to what NFS does with the crossmnt option.

Announcing submounts to the guest (the FUSE client) is done by the FUSE server (virtiofsd) of setting st_rdev to a non-zero value (e.g. st_dev) for every mount point.

Quoted 8 lines
Quoted 3 lines

In this version here, duplicate mounts on the host (same st_dev) will not necessarily have the same st_dev in the guest. That would be more complicated to implement, and there is probably no real need to.

Hi Max,

What's duplicate mount. Is it two bind bounts created from same filesystem.

For example; or the same filesystem from the same device twice (mount /dev/loop0 a; mount /dev/loop0 b).

Quoted 2 lines

So two bind mounts which have same st_dev on host, will appear to come from two different devices in guest (different st_dev), right?

Yes.

Max