git clone https://gitlab.com/virtio-fs/linux.git git checkout virtio-fs-devConfigure, build and install this kernel inside your guest VM, ensuring that the following config options are selected:
CONFIG_VIRTIO CONFIG_VIRTIO_FS CONFIG_DAX CONFIG_FS_DAX CONFIG_DAX_DRIVER CONFIG_ZONE_DEVICEBuild and install the kernel in the guest, on most distros this can be most easily achieved with the commandline:
make -j 8 && make -j 8 modules && make -j 8 modules_install && make -j 8 installBoot the guest and ensure it boots normally.
Note: An alternative is to build the kernel on the host and pass the kernel on the QEMU command line; although this can take some work to get initrd's to work right.
git clone https://gitlab.com/virtio-fs/qemu.gitInside the checkout create a build directory, and from inside that build directory:
../configure --prefix=$PWD --target-list=x86_64-softmmu make -j 8now also build the virtiofsd included in the qemu source:
make -j 8 virtiofsd
First start virtiofsd daemon:
In the qemu build directory, run:./virtiofsd --socket-path=/tmp/vhostqemu -o source=$TESTDIR -o cache=alwaysThe socket path will also be passed to the QEMU.
-chardev socket,id=char0,path=/tmp/vhostqemu
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfsThe tag name is arbitrary and must match the tag given in the guests mount command.
-m 4G -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on -numa node,memdev=mem
./x86_64-softmmu/qemu-system-x86_64 -M pc -cpu host --enable-kvm -smp 2 \ -m 4G -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on -numa node,memdev=mem \ -chardev socket,id=char0,path=/tmp/vhostqemu -device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs \ -chardev stdio,mux=on,id=mon -mon chardev=mon,mode=readline -device virtio-serial-pci -device virtconsole,chardev=mon -vga none -display none \ -drive if=virtio,file=rootfsimage.qcow2That assumes that 'rootfsimage.qcow2' is the VM built with the modified kernel. Log into the guest as root, and issue the mount command:
mount -t virtiofs myfs /mnt
Note that Linux 4.19-based virtiofs kernels required a different mount syntax mount -t virtio_fs none /mnt -o tag=myfs,rootmode=040000,user_id=0,group_id=0 instead.
The contents of the /mnt directory in the guest should now reflect the $TESTDIR on the host.The device section of the qemu command line changes to:
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs,cache-size=2GInside the guest the mount command becomes:
mount -t virtiofs myfs /mnt -o dax
Note that Linux 4.19-based virtiofs kernels required a different mount syntax mount -t virtio_fs none /mnt -o tag=myfs,rootmode=040000,user_id=0,group_id=0,dax instead.
Note that the size of the 'cache' used doesn't increase the host RAM used directly, since it's just a mapping area for files.git clone https://gitlab.com/virtio-fs/ireg.gitand build with:
make
./ireg &Start virtiofsd, passing it the flag to set the caching mode to shared:
./virtiofsd -o virtio_socket=/tmp/vhostqemu / -o source=/home/dgilbert/virtio-fs/fs -o sharedStart qemu chanding the device option to point to the shared meta-data table:
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs,cache-size=2G,versiontable=/dev/shm/fuse_shared_versionsThe mount options are unchanged.