Other Status of VirtFS

It would be interesting to see if this works out on going from a FreeBSD host to a Windows guest.

From what I remember for when I did some research before on Window's implementation of Plan 9, including some more recent research; it did indicate there may be some issues in it. From what it looks like, when MS implemented 9P for WSL; they did it all with very narrow blinders on. If anyone is a little interested in a little of MS's 9P implementation; this link (from 2020) goes into detail of how it was implemented. https://www.mcafee.com/blogs/other-blogs/mcafee-labs/hunting-for-blues-the-wsl-plan-9-protocol-bsod/
 
For sure I would be interested if bhyve supported the nested VMs. But it doesn't ,so I can't enable the WSL 2 ecosystem inside the Windows VM and without WSL2 there isn't any 9P for Windows.
 
I have no idea what the situation is in regards to Windows 11 on if they made 9P available without WSL enabled. The other part that doesn't help, is more of it looking like MS's 9P was implemented to communicate through a virtual/loopback socket too.
 
I'm running FreeBSD 13.1 as host and as a VM with bhyve. I've tried to compile the 9pnet and the 9pfs modules that I've got from the swills repo here :

https://github.com/swills/virtfs-9p-kmod

what I did has been to copy the directory virtio,which contains the directories called 9pfs and 9pnet on the folder virtfs-9p-kmod-master/sys/modules and I gave a make and this is what happened :

Code:
mario@marietto:/usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pnet # sudo make

machine -> /usr/src/sys/amd64/include
x86 -> /usr/src/sys/x86/include
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/device_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/bus_if.m -h
:> opt_cam.h
touch opt_global.h
Warning: Object directory not changed from original /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pnet
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pnet/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.trans_virtio.o -MTtrans_virtio.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-error=unused-but-set-variable -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pnet/../../../dev/virtio/9pnet/trans_virtio.c -o trans_virtio.o
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pnet/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.client.o -MTclient.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-error=unused-but-set-variable -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pnet/../../../dev/virtio/9pnet/client.c -o client.o
/usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pnet/../../../dev/virtio/9pnet/client.c:253:12: error: add explicit braces to avoid dangling else [-Werror,-Wdangling-else]
                } else if (req->rc->id == P9PROTO_RLERROR) {
                  ^
1 error generated.
*** Error code 1

mario@marietto:/usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs # sudo make

machine -> /usr/src/sys/amd64/include
x86 -> /usr/src/sys/x86/include
awk -f /usr/src/sys/tools/vnode_if.awk /usr/src/sys/kern/vnode_if.src -p
awk -f /usr/src/sys/tools/vnode_if.awk /usr/src/sys/kern/vnode_if.src -q
awk -f /usr/src/sys/tools/vnode_if.awk /usr/src/sys/kern/vnode_if.src -h
touch opt_global.h
Warning: Object directory not changed from original /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.virtfs_subr.o -MTvirtfs_subr.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-error=unused-but-set-variable -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs/../../../dev/virtio/9pfs/virtfs_subr.c -o virtfs_subr.o
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.virtfs_vfops.o -MTvirtfs_vfops.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-error=unused-but-set-variable -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs/../../../dev/virtio/9pfs/virtfs_vfops.c -o virtfs_vfops.o
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.virtfs_vnops.o -MTvirtfs_vnops.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-error=unused-but-set-variable -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs/../../../dev/virtio/9pfs/virtfs_vnops.c -o virtfs_vnops.o
/usr/home/marietto/Downloads/virtfs-9p-kmod-master/sys/modules/virtio/9pfs/../../../dev/virtio/9pfs/virtfs_vnops.c:1627:9: error: assigning to 'char *' from 'const char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
        symtgt = ap->a_target;
               ^ ~~~~~~~~~~~~
1 error generated.
*** Error code 1

Did I make a mistake ?
 
Last edited:
make CWARNFLAGS="-Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else"

Code:
mario@marietto:/sys/modules/virtio/9pfs # sudo make CWARNFLAGS="-Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else"

[Creating objdir /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pfs...]
machine -> /usr/src/sys/amd64/include
x86 -> /usr/src/sys/x86/include
awk -f /usr/src/sys/tools/vnode_if.awk /usr/src/sys/kern/vnode_if.src -p
awk -f /usr/src/sys/tools/vnode_if.awk /usr/src/sys/kern/vnode_if.src -q
awk -f /usr/src/sys/tools/vnode_if.awk /usr/src/sys/kern/vnode_if.src -h
touch opt_global.h
cc  -O2 -pipe -fno-common  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pfs/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.virtfs_subr.o -MTvirtfs_subr.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/src/sys/modules/virtio/9pfs/../../../dev/virtio/9pfs/virtfs_subr.c -o virtfs_subr.o
cc  -O2 -pipe -fno-common  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pfs/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.virtfs_vfops.o -MTvirtfs_vfops.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/src/sys/modules/virtio/9pfs/../../../dev/virtio/9pfs/virtfs_vfops.c -o virtfs_vfops.o
cc  -O2 -pipe -fno-common  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pfs/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.virtfs_vnops.o -MTvirtfs_vnops.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/src/sys/modules/virtio/9pfs/../../../dev/virtio/9pfs/virtfs_vnops.c -o virtfs_vnops.o
ld -m elf_x86_64_fbsd -d -warn-common --build-id=sha1 -T /usr/src/sys/conf/ldscript.kmod.amd64 -r -d  -o virtio_9pfs.ko virtfs_subr.o virtfs_vfops.o virtfs_vnops.o
:> export_syms
awk -f /usr/src/sys/conf/kmod_syms.awk virtio_9pfs.ko  export_syms | xargs -J% objcopy % virtio_9pfs.ko
objcopy --strip-debug virtio_9pfs.ko

mario@marietto:/sys/modules/virtio/9pfs # sudo make install

install -T release -o root -g wheel -m 555   virtio_9pfs.ko /boot/modules/
kldxref /boot/modules

mario@marietto:/sys/modules/virtio/9pnet # sudo make CWARNFLAGS="-Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else"

[Creating objdir /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pnet...]
machine -> /usr/src/sys/amd64/include
x86 -> /usr/src/sys/x86/include
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/device_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/bus_if.m -h
:> opt_cam.h
touch opt_global.h
cc  -O2 -pipe -fno-common  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pnet/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.trans_virtio.o -MTtrans_virtio.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/src/sys/modules/virtio/9pnet/../../../dev/virtio/9pnet/trans_virtio.c -o trans_virtio.o
cc  -O2 -pipe -fno-common  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pnet/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.client.o -MTclient.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/src/sys/modules/virtio/9pnet/../../../dev/virtio/9pnet/client.c -o client.o
cc  -O2 -pipe -fno-common  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /usr/obj/usr/src/amd64.amd64/sys/modules/virtio/9pnet/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.protocol.o -MTprotocol.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-sign -Wno-dangling-else   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/src/sys/modules/virtio/9pnet/../../../dev/virtio/9pnet/protocol.c -o protocol.o
ld -m elf_x86_64_fbsd -d -warn-common --build-id=sha1 -T /usr/src/sys/conf/ldscript.kmod.amd64 -r -d  -o virtio_9pnet.ko trans_virtio.o client.o protocol.o
:> export_syms
awk -f /usr/src/sys/conf/kmod_syms.awk virtio_9pnet.ko  export_syms | xargs -J% objcopy % virtio_9pnet.ko
objcopy --strip-debug virtio_9pnet.ko

mario@marietto:/sys/modules/virtio/9pnet # sudo make install
install -T release -o root -g wheel -m 555   virtio_9pnet.ko /boot/modules/
kldxref /boot/modules

nice. it seems that it has been compiled without errors !!!
 
Memorandum :

With bhyve you can use virtio-9p to share a host directory with a Linux or FreeBSD VM/guest. For the first one add something like the following to the bhyve command line:

Code:
-s 28,virtio-9p,sharename=/

In the guest Linux VM you need something like :

Code:
mkdir /host
mount -t 9p -o trans=virtio,version=9p2000.L,rw sharename /host

For the second one add these flags to bhyve:

Code:
-s 28,virtio-9p,9p=/

In the bhyve FreeBSD/VM, load the module and then:

Code:
kldload virtio_9pfs.ko,virtio_9pnet.ko
mkdir /host
mount -t virtfs -o trans=virtio 9p /host
 
@Swills says :

Add these flags to bhyve: -s 28,virtio-9p,9p=/

but Im not sure that's the correct flags to add to bhyve. Usually I add these ones,instead :

-s 28,virtio-9p,sharename=/
 
You need to tell bhyve about each file-tree you want to connect via virtio-9p. For example, the bhyve command line may have

-s 8,virtio-9p,foo=/usr/foo \
-s 9,virtio-9p,obj=/usr/obj \


In the VM you will have /etc/fstab entries such as

foo /usr/bar virtfs trans=virtio,late 0 0
obj /usr/obj virtfs trans=virtio,ro,late 0 0
 
Back
Top