forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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"
Signed-off-by: Changbin Du <changbin.du@gmail.com>- Loading branch information
1 parent
acda97a
commit 96098f751038703cc0fda4f018236d240a86930d
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // SPDX-License-Identifier: GPL-2.0 | ||
| /* | ||
| * 9p root file system support | ||
| * | ||
| * Copyright (c) 2021 Changbin Du <changbin.du@gmail.com> | ||
| */ | ||
| #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; | ||
|
|
||
| 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)) { | ||
| pr_err("Root-V9FS: path too long\n"); | ||
| return 1; | ||
| } | ||
| strscpy(root_dev, line, len); | ||
|
|
||
| if (*s) { | ||
| int n = snprintf(root_opts, | ||
| sizeof(root_opts), "%s", | ||
| s + 1); | ||
| if (n >= sizeof(root_opts)) { | ||
| pr_err("Root-V9FS: mount options string too long\n"); | ||
| root_opts[sizeof(root_opts)-1] = '\0'; | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ROOT_DEV = Root_V9FS; | ||
| return 1; | ||
| } | ||
|
|
||
| __setup("v9fsroot=", v9fs_root_setup); | ||
|
|
||
| int __init v9fs_root_data(char **dev, char **opts) | ||
| { | ||
| if (!root_dev[0]) { | ||
| pr_err("Root-V9FS: no rootdev specified\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| *dev = root_dev; | ||
| *opts = root_opts; | ||
|
|
||
| return 0; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters