Thread (17 messages) 17 messages, 3 authors, 2021-06-11
STALE1862d
Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 4/7] fuse: Add dedicated filesystem context ops for submounts

From: Greg Kurz <hidden>
Date: 2021-06-04 16:12:25
Also in: lkml
Subsystem: filesystems (vfs and infrastructure), fuse filesystem [core], the rest, virtio file system · Maintainers: Alexander Viro, Christian Brauner, Miklos Szeredi, Linus Torvalds, German Maglione, Vivek Goyal, Stefan Hajnoczi

The creation of a submount is open-coded in fuse_dentry_automount().
This brings a lot of complexity and we recently had to fix bugs
because we weren't setting SB_BORN or because we were unlocking
sb->s_umount before sb was fully configured. Most of these could
have been avoided by using the mount API instead of open-coding.

Basically, this means coming up with a proper ->get_tree()
implementation for submounts and call vfs_get_tree(), or better
fc_mount().

The creation of the superblock for submounts is quite different from
the root mount. Especially, it doesn't require to allocate a FUSE
filesystem context, nor to parse parameters.

Introduce a dedicated context ops for submounts to make this clear.
This is just a placeholder for now, fuse_get_tree_submount() will
be populated in a subsequent patch.

Only visible change is that we stop allocating/freeing a useless FUSE
filesystem context with submounts.

Signed-off-by: Greg Kurz <redacted>
---
 fs/fuse/fuse_i.h    |  5 +++++
 fs/fuse/inode.c     | 16 ++++++++++++++++
 fs/fuse/virtio_fs.c |  3 +++
 3 files changed, 24 insertions(+)
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 7e463e220053..862ad317bc89 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1097,6 +1097,11 @@ int fuse_fill_super_submount(struct super_block *sb,
  */
 bool fuse_mount_remove(struct fuse_mount *fm);
 
+/*
+ * Setup context ops for submounts
+ */
+int fuse_init_fs_context_submount(struct fs_context *fsc);
+
 /*
  * Shut down the connection (possibly sending DESTROY request).
  */
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 393e36b74dc4..fa96a3762ea2 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1313,6 +1313,22 @@ int fuse_fill_super_submount(struct super_block *sb,
 	return 0;
 }
 
+static int fuse_get_tree_submount(struct fs_context *fsc)
+{
+	return 0;
+}
+
+static const struct fs_context_operations fuse_context_submount_ops = {
+	.get_tree	= fuse_get_tree_submount,
+};
+
+int fuse_init_fs_context_submount(struct fs_context *fsc)
+{
+	fsc->ops = &fuse_context_submount_ops;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(fuse_init_fs_context_submount);
+
 int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
 {
 	struct fuse_dev *fud = NULL;
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index bcb8a02e2d8b..e68467cc765c 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1496,6 +1496,9 @@ static int virtio_fs_init_fs_context(struct fs_context *fsc)
 {
 	struct fuse_fs_context *ctx;
 
+	if (fsc->purpose == FS_CONTEXT_FOR_SUBMOUNT)
+		return fuse_init_fs_context_submount(fsc);
+
 	ctx = kzalloc(sizeof(struct fuse_fs_context), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
-- 
2.31.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help