Blog/Virtiofsd wrapper

From Forza's ramblings
Sunset over lake Långsjön

Virtio-fs[edit | edit source]

Virtio-fs is a shared filesystem used in virtualisation environments. It allows a guest inside a VM to access a shared directory on the host, as if it was a local filsystem inside the guest.

Other approaches to allow guests access to local directories have included NFS, Samba or plan9 network filesystems. These have the drawback of added overhead and latency compared to local filesystems. Virtiofs was developed to take advantage of the locality between the guest and the host or hypervisor to improve performance.

virtiofsd in Rust language[edit | edit source]

QEMU includes a daemon virtiofsd which is used for handling the communication between the guest and the host.

The development of the built-in virtiofsd has been deprecated in favor of a new version written in Rust instead of C.

The Rust version has more features and should have better performance and memory safety than the previous c-lang version.

Wrapper script[edit | edit source]

The libvirt XML specification doesn't yet include all the new features. Therefore a wrapper may be used to include additional options.

options="--inode-file-handles=mandatory --announce-submounts"
exec /opt/virtiofsd-rust/ $options "$@"

Currently, the available options are:

--killpriv-v2 / --no-killpriv-v2

The full documentation can be found at

To use the wrapper script, use the <binary> element in the domain XML using virsh edit

<filesystem type='mount' accessmode='passthrough'>
  <driver type='virtiofs' ats='on'/>
  <binary path='/opt/virtiofsd-rust/'/>
  <source dir='/mnt/share/'/>
  <target dir='share'/>

Mount a share directory in the guest[edit | edit source]

Use the <target dir='share'/> name when mounting the directory in the guest.

# mount -t virtiofs share /mnt/share/
# df /mnt/share/
Filesystem    Size    Used    Available  Use% Mounted on
share         18.2T   17.0T   1.2T       93%  /media/share