Skip to contentSkip to conversation

9p: add support for root file systems

PATCH Superseded Changbin Du 3 participants 7 messages May 5, 2021 – May 6, 2021

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover 9p: add support for root file systems

Just like cifs and nfs, this short series enables rootfs support for 9p. Bellow is an example which mounts v9fs with tag 'r' as rootfs in qemu guest via virtio transport.

  $ qemu-system-x86_64 -enable-kvm -cpu host -m 1024 \
        -virtfs local,path=$rootfs_dir,mount_tag=r,security_model=passthrough,id=r \
        -kernel /path/to/linux/arch/x86/boot/bzImage -nographic \
        -append "root=/dev/v9fs v9fsroot=r,trans=virtio rw console=ttyS0 3"

Changbin Du (3):
9p: add support for root file systems
9p: doc: move to a new dedicated folder
9p: doc: add v9fsroot description

 Documentation/filesystems/index.rst         |  2 +-
 Documentation/filesystems/{ => v9fs}/9p.rst |  0
 Documentation/filesystems/v9fs/index.rst    | 12 ++++
 Documentation/filesystems/v9fs/v9fsroot.rst | 52 +++++++++++++++++
 fs/9p/Kconfig                               |  6 ++
 fs/9p/Makefile                              |  1 +
 fs/9p/v9fsroot.c                            | 64 +++++++++++++++++++++
 include/linux/root_dev.h                    |  1 +
 init/do_mounts.c                            | 46 +++++++++++++++
 9 files changed, 183 insertions(+), 1 deletion(-)
 rename Documentation/filesystems/{ => v9fs}/9p.rst (100%)
 create mode 100644 Documentation/filesystems/v9fs/index.rst
 create mode 100644 Documentation/filesystems/v9fs/v9fsroot.rst
 create mode 100644 fs/9p/v9fsroot.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/3 9p: add support for root file systems

This introduces a new kernel command-line option called 'v9fsroot=' which will tell the kernel to mount the root file system by utilizing the 9p protocol.

This allows us to mount host folder as rootfs for guest linux in qemu. Bellow is an example which mounts v9fs with tag 'r' as rootfs in qemu guest via virtio transport.

  $ qemu-system-x86_64 -enable-kvm -cpu host -m 1024 \
      -virtfs local,path=$rootfs_dir,mount_tag=r,security_model=passthrough,id=r \
      -kernel /path/to/linux/arch/x86/boot/bzImage -nographic \
      -append "root=/dev/v9fs v9fsroot=r,trans=virtio rw console=ttyS0 3"
---
 fs/9p/Kconfig            |  6 ++++
 fs/9p/Makefile           |  1 +
 fs/9p/v9fsroot.c         | 64 ++++++++++++++++++++++++++++++++++++++++
 include/linux/root_dev.h |  1 +
 init/do_mounts.c         | 46 +++++++++++++++++++++++++++++
 5 files changed, 118 insertions(+)
 create mode 100644 fs/9p/v9fsroot.c
fs/9p/Kconfig +6 -0
index 09fd4a185fd2..71c5a49f9a27 100644
@@ -42,3 +42,9 @@ config 9P_FS_SECURITY
 
 	  If you are not using a security module that requires using
 	  extended attributes for file security labels, say N.
+
+config 9P_FS_ROOT
+	bool "9p root file system"
+	depends on 9P_FS=y
+	help
+	  Enables root file system support over 9p protocol.
fs/9p/Makefile +1 -0
index e7800a5c7395..bc2a4ef10049 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_9P_FS) := 9p.o
 
 9p-$(CONFIG_9P_FSCACHE) += cache.o
 9p-$(CONFIG_9P_FS_POSIX_ACL) += acl.o
+9p-$(CONFIG_9P_FS_ROOT) += v9fsroot.o
fs/9p/v9fsroot.c new file +64 -0

64 lines not on this page · raw message

include/linux/root_dev.h +1 -0
index 4e78651371ba..becd0ee2ff87 100644
@@ -9,6 +9,7 @@
 enum {
 	Root_NFS = MKDEV(UNNAMED_MAJOR, 255),
 	Root_CIFS = MKDEV(UNNAMED_MAJOR, 254),
+	Root_V9FS = MKDEV(UNNAMED_MAJOR, 253),
 	Root_RAM0 = MKDEV(RAMDISK_MAJOR, 0),
 	Root_RAM1 = MKDEV(RAMDISK_MAJOR, 1),
 	Root_FD0 = MKDEV(FLOPPY_MAJOR, 0),
init/do_mounts.c +46 -0

64 lines not on this page · raw message

Signature · 1 line
2.30.2
#5 lore raw

PATCH 2/3 9p: doc: move to a new dedicated folder

In reply to Changbin Du

Later we will add another documentation for v9fs.

---
 Documentation/filesystems/index.rst         |  2 +-
 Documentation/filesystems/{ => v9fs}/9p.rst |  0
 Documentation/filesystems/v9fs/index.rst    | 11 +++++++++++
 3 files changed, 12 insertions(+), 1 deletion(-)
 rename Documentation/filesystems/{ => v9fs}/9p.rst (100%)
 create mode 100644 Documentation/filesystems/v9fs/index.rst
Documentation/filesystems/index.rst +1 -1
index d4853cb919d2..e53992636a49 100644
@@ -63,7 +63,7 @@ Documentation for filesystem implementations.
 .. toctree::
    :maxdepth: 2
 
-   9p
+   v9fs/index
    adfs
    affs
    afs
Documentation/filesystems/v9fs/9p.rst renamed from Documentation/filesystems/9p.rst +0 -0
similarity index 100%
rename from Documentation/filesystems/9p.rst
rename to Documentation/filesystems/v9fs/9p.rst
Documentation/filesystems/v9fs/index.rst new file +11 -0
new file mode 100644
index 000000000000..a1e45b89e2a2
@@ -0,0 +1,11 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+====
+v9fs
+====
+
+.. toctree::
+   :maxdepth: 6
+   :numbered:
+
+   9p
Signature · 1 line
2.30.2
#6 lore raw

PATCH 3/3 9p: doc: add v9fsroot description

In reply to Changbin Du

This documentation is modified from cifs/cifsroot.rst.

---
 Documentation/filesystems/v9fs/index.rst    |  1 +
 Documentation/filesystems/v9fs/v9fsroot.rst | 52 +++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 Documentation/filesystems/v9fs/v9fsroot.rst
Documentation/filesystems/v9fs/index.rst +1 -0
index a1e45b89e2a2..65e1ceb04c9c 100644
@@ -9,3 +9,4 @@ v9fs
    :numbered:
 
    9p
+   v9fsroot
Documentation/filesystems/v9fs/v9fsroot.rst new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.30.2
#2 lore raw
In reply to Changbin Du

Why has this only been sent to direct maintainers and linux-doc@vger ? Please resend to at least v9fs-developer@sf, linux-fs@vger and whoever get_maintainer.pl deems appropriate for init/do_mounts.c changes (added the two lists to this mail)

As a whole for the series: I'm personally not sure I'd encourage this, it can currently be done with an initrd if someone cares enough and if we're going to add all remote filesystems that way there's going to be no end to it.

That being said, I'm not 100% opposed to it if there is demand; but I'll expect you to help with whatever bug reports people come up with using this option.

Changbin Du wrote on Wed, May 05, 2021 at 08:07:46PM +0800:

fs/9p/v9fsroot.c line 3

Quoted 9 lines
fs/9p/v9fsroot.c new file +3 -0
new file mode 100644
index 000000000000..7dd91cc3814f
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SMB root file system support

copy-paste error from fs/cifs/cifsroot.c

Quoted 19 lines
fs/9p/v9fsroot.c new file +19 -0
+ *
+ * Copyright (c) 2021 Changbin Du <[email protected]>
+ */
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/types.h>
+#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/root_dev.h>
+#include <linux/kernel.h>
+
+static char root_dev[2048] __initdata = "";
+static char root_opts[1024] __initdata = "";
+
+/* v9fsroot=<path>[,options] */
+static int __init v9fs_root_setup(char *line)
+{
+	char *s;
+	int len;

fs/9p/v9fsroot.c line 32

Quoted 10 lines
fs/9p/v9fsroot.c new file +10 -0
+
+	ROOT_DEV = Root_V9FS;
+
+	if (strlen(line) >= 1) {
+		/* make s point to ',' or '\0' at end of line */
+		s = strchrnul(line, ',');
+		/* len is strlen(unc) + '\0' */
+		len = s - line + 1;
+		if (len > sizeof(root_dev)) {
+			printk(KERN_ERR "Root-V9FS: path too long\n");

9p has its own p9_debug helper; it's a bit awkward because even P9_DEBUG_ERROR right now is not displayed by default so I'm not against pr_err or pr_warn for important messages (I'd like to replace all such messages by either at some point), but at least stick to pr_xyz(...) rather than printk(KERN_XYZ...)

fs/9p/v9fsroot.c line 39

Quoted 7 lines
fs/9p/v9fsroot.c new file +7 -0
+			return 1;
+		}
+		strlcpy(root_dev, line, len);
+		if (*s) {
+			int n = snprintf(root_opts,
+					 sizeof(root_opts), "%s,%s",
+					 DEFAULT_MNT_OPTS, s + 1);

Did you actually run with this? DEFAULT_MNT_OPTS is not defined here.

fs/9p/v9fsroot.c line 48

Quoted 9 lines
fs/9p/v9fsroot.c new file +9 -0
+			if (n >= sizeof(root_opts)) {
+				printk(KERN_ERR "Root-V9FS: mount options string too long\n");
+				root_opts[sizeof(root_opts)-1] = '\0';
+				return 1;
+			}
+		}
+	}
+
+	return 1;

I'm also surprised this only ever returns 1, the cifs codes does the same but I'd be surprised the mount can work without a tag so there certainly should be some difference between working and not working?

I'd also expect ROOT_DEV to only be set on success, this doesn't make sense to trigger 9p mounting mechanisms with something that can't be mounted, leading to a long timeout (5+10+15+30*2 seconds) before a hard error when the hard error can be given right away.

Quoted 99 lines
fs/9p/v9fsroot.c new file +16 -0
+}
+
+__setup("v9fsroot=", v9fs_root_setup);
+
+int __init v9fs_root_data(char **dev, char **opts)
+{
+	if (!root_dev[0]) {
+		printk(KERN_ERR "Root-V9FS: no rootdev specified\n");
+		return -1;
+	}
+
+	*dev = root_dev;
+	*opts = root_opts;
+
+	return 0;
+}
include/linux/root_dev.h +1 -0
index 4e78651371ba..becd0ee2ff87 100644
@@ -9,6 +9,7 @@
 enum {
 	Root_NFS = MKDEV(UNNAMED_MAJOR, 255),
 	Root_CIFS = MKDEV(UNNAMED_MAJOR, 254),
+	Root_V9FS = MKDEV(UNNAMED_MAJOR, 253),
 	Root_RAM0 = MKDEV(RAMDISK_MAJOR, 0),
 	Root_RAM1 = MKDEV(RAMDISK_MAJOR, 1),
 	Root_FD0 = MKDEV(FLOPPY_MAJOR, 0),
init/do_mounts.c +46 -0
index a78e44ee6adb..60af89983a6b 100644
@@ -287,6 +287,8 @@ dev_t name_to_dev_t(const char *name)
 		return Root_NFS;
 	if (strcmp(name, "/dev/cifs") == 0)
 		return Root_CIFS;
+	if (strcmp(name, "/dev/v9fs") == 0)
+		return Root_V9FS;
 	if (strcmp(name, "/dev/ram") == 0)
 		return Root_RAM0;
 #ifdef CONFIG_BLOCK
@@ -536,6 +538,43 @@ static int __init mount_cifs_root(void)
 }
 #endif
 
+#ifdef CONFIG_9P_FS_ROOT
+
+extern int v9fs_root_data(char **dev, char **opts);
+
+#define V9FSROOT_TIMEOUT_MIN	5
+#define V9FSROOT_TIMEOUT_MAX	30
+#define V9FSROOT_RETRY_MAX	5
+
+static int __init mount_v9fs_root(void)
+{
+	char *root_dev, *root_data;
+	unsigned int timeout;
+	int try, err;
+
+	err = v9fs_root_data(&root_dev, &root_data);
+	if (err != 0)
+		return 0;
+
+	timeout = V9FSROOT_TIMEOUT_MIN;
+	for (try = 1; ; try++) {
+		err = do_mount_root(root_dev, "9p",
+				    root_mountflags, root_data);
+		if (err == 0)
+			return 1;
+		if (try > V9FSROOT_RETRY_MAX)
+			break;
+
+		/* Wait, in case the server refused us immediately */
+		ssleep(timeout);
+		timeout <<= 1;
+		if (timeout > V9FSROOT_TIMEOUT_MAX)
+			timeout = V9FSROOT_TIMEOUT_MAX;
+	}
+	return 0;
+}
+#endif
+
 void __init mount_root(void)
 {
 #ifdef CONFIG_ROOT_NFS
@@ -552,6 +591,13 @@ void __init mount_root(void)
 		return;
 	}
 #endif
+#ifdef CONFIG_9P_FS_ROOT
+	if (ROOT_DEV == Root_V9FS) {
+		if (!mount_v9fs_root())
+			printk(KERN_ERR "VFS: Unable to mount root fs via 9p.\n");
+		return;
+	}
+#endif
 #ifdef CONFIG_BLOCK
 	{
 		int err = create_dev("/dev/root", ROOT_DEV);
Signature · 1 line
Dominique
#3 lore raw
Quoted 4 lines · Dominique Martinet

As a whole for the series: I'm personally not sure I'd encourage this, it can currently be done with an initrd if someone cares enough and if we're going to add all remote filesystems that way there's going to be no end to it.

personally, I'd be *very* interested in that, especially for specially tailored vm grid workloads. please keep me in the loop.

--mtx

Signature · 8 lines
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert
werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren
GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
[email protected] -- +49-151-27565287
#4 lore raw
In reply to Dominique Martinet
Quoted 5 lines · Dominique Martinet

Why has this only been sent to direct maintainers and linux-doc@vger ? Please resend to at least v9fs-developer@sf, linux-fs@vger and whoever get_maintainer.pl deems appropriate for init/do_mounts.c changes (added the two lists to this mail)

I made a typing mistake and then...

Quoted 10 lines

As a whole for the series: I'm personally not sure I'd encourage this, it can currently be done with an initrd if someone cares enough and if we're going to add all remote filesystems that way there's going to be no end to it.

That being said, I'm not 100% opposed to it if there is demand; but I'll expect you to help with whatever bug reports people come up with using this option.

No problem, I can help with any issues related to this. It is worth doint this especially for some virtulizaion scenarioes.

Quoted 14 lines

Changbin Du wrote on Wed, May 05, 2021 at 08:07:46PM +0800:

fs/9p/v9fsroot.c line 3

Quoted 9 lines
fs/9p/v9fsroot.c new file +3 -0
new file mode 100644
index 000000000000..7dd91cc3814f
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SMB root file system support

copy-paste error from fs/cifs/cifsroot.c

Sorry, I'll fix it.

Quoted 27 lines
Quoted 27 lines
fs/9p/v9fsroot.c new file +27 -0
+ *
+ * Copyright (c) 2021 Changbin Du <[email protected]>
+ */
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/types.h>
+#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/root_dev.h>
+#include <linux/kernel.h>
+
+static char root_dev[2048] __initdata = "";
+static char root_opts[1024] __initdata = "";
+
+/* v9fsroot=<path>[,options] */
+static int __init v9fs_root_setup(char *line)
+{
+	char *s;
+	int len;
+
+	ROOT_DEV = Root_V9FS;
+
+	if (strlen(line) >= 1) {
+		/* make s point to ',' or '\0' at end of line */
+		s = strchrnul(line, ',');
+		/* len is strlen(unc) + '\0' */
+		len = s - line + 1;
Quoted 9 lines

fs/9p/v9fsroot.c line 32

Quoted 2 lines
fs/9p/v9fsroot.c new file +2 -0
+		if (len > sizeof(root_dev)) {
+			printk(KERN_ERR "Root-V9FS: path too long\n");

9p has its own p9_debug helper; it's a bit awkward because even P9_DEBUG_ERROR right now is not displayed by default so I'm not against pr_err or pr_warn for important messages (I'd like to replace all such messages by either at some point), but at least stick to pr_xyz(...) rather than printk(KERN_XYZ...)

okay, will use pr_err() instead then.

Quoted 10 lines

fs/9p/v9fsroot.c line 39

Quoted 7 lines
fs/9p/v9fsroot.c new file +7 -0
+			return 1;
+		}
+		strlcpy(root_dev, line, len);
+		if (*s) {
+			int n = snprintf(root_opts,
+					 sizeof(root_opts), "%s,%s",
+					 DEFAULT_MNT_OPTS, s + 1);

Did you actually run with this? DEFAULT_MNT_OPTS is not defined here.

oops, my bad that I forgot to test the latest change.

Quoted 5 lines
Quoted 5 lines
fs/9p/v9fsroot.c new file +5 -0
+			if (n >= sizeof(root_opts)) {
+				printk(KERN_ERR "Root-V9FS: mount options string too long\n");
+				root_opts[sizeof(root_opts)-1] = '\0';
+				return 1;
+			}
Quoted 9 lines

fs/9p/v9fsroot.c line 48

Quoted 4 lines
fs/9p/v9fsroot.c new file +4 -0
+		}
+	}
+
+	return 1;

I'm also surprised this only ever returns 1, the cifs codes does the same but I'd be surprised the mount can work without a tag so there certainly should be some difference between working and not working?

I think this returns 1 just means the "v9fsroot=" kernel parameter is handled so do not need further processing. But this doesn't mean the mount options can work.

Quoted 5 lines

I'd also expect ROOT_DEV to only be set on success, this doesn't make sense to trigger 9p mounting mechanisms with something that can't be mounted, leading to a long timeout (5+10+15+30*2 seconds) before a hard error when the hard error can be given right away.

Sure, will only set ROOT_DEV after basic option checking.

Quoted 101 lines
Quoted 99 lines
fs/9p/v9fsroot.c new file +16 -0
+}
+
+__setup("v9fsroot=", v9fs_root_setup);
+
+int __init v9fs_root_data(char **dev, char **opts)
+{
+	if (!root_dev[0]) {
+		printk(KERN_ERR "Root-V9FS: no rootdev specified\n");
+		return -1;
+	}
+
+	*dev = root_dev;
+	*opts = root_opts;
+
+	return 0;
+}
include/linux/root_dev.h +1 -0
index 4e78651371ba..becd0ee2ff87 100644
@@ -9,6 +9,7 @@
 enum {
 	Root_NFS = MKDEV(UNNAMED_MAJOR, 255),
 	Root_CIFS = MKDEV(UNNAMED_MAJOR, 254),
+	Root_V9FS = MKDEV(UNNAMED_MAJOR, 253),
 	Root_RAM0 = MKDEV(RAMDISK_MAJOR, 0),
 	Root_RAM1 = MKDEV(RAMDISK_MAJOR, 1),
 	Root_FD0 = MKDEV(FLOPPY_MAJOR, 0),
init/do_mounts.c +46 -0
index a78e44ee6adb..60af89983a6b 100644
@@ -287,6 +287,8 @@ dev_t name_to_dev_t(const char *name)
 		return Root_NFS;
 	if (strcmp(name, "/dev/cifs") == 0)
 		return Root_CIFS;
+	if (strcmp(name, "/dev/v9fs") == 0)
+		return Root_V9FS;
 	if (strcmp(name, "/dev/ram") == 0)
 		return Root_RAM0;
 #ifdef CONFIG_BLOCK
@@ -536,6 +538,43 @@ static int __init mount_cifs_root(void)
 }
 #endif
 
+#ifdef CONFIG_9P_FS_ROOT
+
+extern int v9fs_root_data(char **dev, char **opts);
+
+#define V9FSROOT_TIMEOUT_MIN	5
+#define V9FSROOT_TIMEOUT_MAX	30
+#define V9FSROOT_RETRY_MAX	5
+
+static int __init mount_v9fs_root(void)
+{
+	char *root_dev, *root_data;
+	unsigned int timeout;
+	int try, err;
+
+	err = v9fs_root_data(&root_dev, &root_data);
+	if (err != 0)
+		return 0;
+
+	timeout = V9FSROOT_TIMEOUT_MIN;
+	for (try = 1; ; try++) {
+		err = do_mount_root(root_dev, "9p",
+				    root_mountflags, root_data);
+		if (err == 0)
+			return 1;
+		if (try > V9FSROOT_RETRY_MAX)
+			break;
+
+		/* Wait, in case the server refused us immediately */
+		ssleep(timeout);
+		timeout <<= 1;
+		if (timeout > V9FSROOT_TIMEOUT_MAX)
+			timeout = V9FSROOT_TIMEOUT_MAX;
+	}
+	return 0;
+}
+#endif
+
 void __init mount_root(void)
 {
 #ifdef CONFIG_ROOT_NFS
@@ -552,6 +591,13 @@ void __init mount_root(void)
 		return;
 	}
 #endif
+#ifdef CONFIG_9P_FS_ROOT
+	if (ROOT_DEV == Root_V9FS) {
+		if (!mount_v9fs_root())
+			printk(KERN_ERR "VFS: Unable to mount root fs via 9p.\n");
+		return;
+	}
+#endif
 #ifdef CONFIG_BLOCK
 	{
 		int err = create_dev("/dev/root", ROOT_DEV);
Signature · 1 line
Dominique
Signature · 2 lines
Cheers,
Changbin Du