Virtfs is a virtualization aware filesystem passthrough..Sharing host files on the guest through generic network file systems like NFS and CIFS suffer from major performance and feature deficiencies as these protocols are not designed or optimized for virtualization. To address the needs of
the virtualization paradigm, a new paravirtualized file system called VirtFS has been intorduced. Virtfs takes features of 9p2000.L protocol.
Using virtfs, you can share filesystem of host to the guest system. It works via para virtual transport mechanism called ‘virtio’. Virtfs has been implemented with ‘zero copy’ mechanism. This is a key advantage of VirtFS compared to using a network file system which would always require at least one (but usually more) data copies.
There are mainly 2 components in this implementation.
1) virtio-9p-pci device ::
This will be used to transport protocol messages and data between the host
and the guest.
2) ‘fsdev’ device :
This is used to define the export file system characteristics like file
system type, security model .
For more about the implementation details,please look at reference section..
Below is demo of this feature in “qemu” , “kvm”, “libvirt” environment.
Host system details : Fedora 15 :
[root@humbles-lap Desktop]$ cat /etc/redhat-release
Fedora release 15 (Lovelock)
[root@humbles-lap Desktop]$ uname -r
2.6.43.5-2.fc15.x86_64
Guest System details: Fedora 16:
[root@localhost mnt]# cat /etc/redhat-release
Fedora release 16 (Verne)
[root@localhost mnt]# uname -r
3.1.0-7.fc16.x86_64
[root@localhost mnt]#
First of all, check support for above mentioned components ( virtio-9p-pci & fsdev) in host system qemu-kvm binary..
Host:
[root@humbles-lap Desktop]$ qemu-kvm –help|grep virtfs
-virtfs local,path=path,mount_tag=tag,security_model=[mapped|passthrough|none]
[root@humbles-lap Desktop]$ qemu-kvm device ?
name “virtio-9p-pci”, bus PCI
[root@humbles-lap Desktop]# lsmod |grep virt
9pnet_virtio 13416 0
9pnet 73543 1 9pnet_virtio
virtio_net 23133 0
[root@humbles-lap Desktop]#
Guest Kernel has to support 9p:
[root@humbles-lap bin]# grep 9P /boot/config-$(uname -r)
CONFIG_NET_9P=m
CONFIG_NET_9P_VIRTIO=m
CONFIG_NET_9P_RDMA=m
# CONFIG_NET_9P_DEBUG is not set
CONFIG_9P_FS=m
CONFIG_9P_FSCACHE=y
CONFIG_9P_FS_POSIX_ACL=y
IN HOST SYSTEM:
—————————————————-
The below string has to be specified with ‘qemu-kvm’ process to export a ‘virtfs’ filesystem for guest.
-virtfs local,path=[path to share],security_model=[mapped|passthrough|
none],mount_tag=[mount tag]
Where : Path = Sharing filesystem path
security_model: This can be either “mapped” or “passthrough”..
mount_tag: This is the idenitifier which can be used in guest when moutning.
The easiest way for defining this is, placing it in the guest configuration file..
< source dir='/misc/shared'/>
< address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
After placing this in “guest configuration” file:
Start the guest :
ex: virsh create Fedora-16.xml
Check for “qemu-kvm” process to know whether “virtfs” options has been picked properly..
[root@humbles-lap Desktop]# ps aux |grep qemu-kvm
qemu 7473 0.8 8.0 1356940 314552 ? Sl 17:00 0:27 /usr/bin/qemu-kvm -S -M pc-0.14 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name Fedora-16 -uuid 75d12600-d3c5-9bb1-7d0a-5ed0e550f5ee -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/Fedora-16.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -boot c -drive file=/var/lib/libvirt/images/Fedora-16.img,if=none,id=drive-virtio-disk0,boot=on,format=raw -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0 -drive if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -fsdev local,security_model=passthrough,id=fsdev-fs0,path=/misc/shared -device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=test_mount,bus=pci.0,addr=0x6 -netdev tap,fd=24,id=hostnet0,vhost=on,vhostfd=25 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:80:db:8d,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -usb -device usb-tablet,id=input0 -vnc 127.0.0.1:0 -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
IN GUEST SYSTEM:
You have to mount the shared filesystem using “9p” . Use below command for the same:
#mount -t 9p -o trans=virtio test_mount /mnt
Where,
Filesyste type: 9p
Transport mechanism: virtio
Mount tag: This is the tag ‘test_mount’ which used when sharing from host system.
Mount Point: /mnt
Check for filesystem :
HOST
[root@humbles-lap shared]# pwd
/misc/shared
[root@humbles-lap shared]# echo “Hi Guest” –> virtfs_file
[root@humbles-lap shared]#
GUEST:
[root@localhost mnt]# mount |grep test_mount
test_mount on /mnt type 9p (rw,relatime,sync,dirsync,trans=virtio)
[root@localhost mnt]# pwd
/mnt
[root@localhost mnt]# cat virtfs_file
Hi Guest
Reference: www.kernel.org/doc/ols/2010/ols2010-pages-109-120.pdf
1 thought on “Share host filsystem to guest using virtfs 9p filesystem passthrough”
Comments are closed.