162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci.. _virtiofs_index: 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci=================================================== 662306a36Sopenharmony_civirtiofs: virtio-fs host<->guest shared file system 762306a36Sopenharmony_ci=================================================== 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci- Copyright (C) 2019 Red Hat, Inc. 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciIntroduction 1262306a36Sopenharmony_ci============ 1362306a36Sopenharmony_ciThe virtiofs file system for Linux implements a driver for the paravirtualized 1462306a36Sopenharmony_ciVIRTIO "virtio-fs" device for guest<->host file system sharing. It allows a 1562306a36Sopenharmony_ciguest to mount a directory that has been exported on the host. 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ciGuests often require access to files residing on the host or remote systems. 1862306a36Sopenharmony_ciUse cases include making files available to new guests during installation, 1962306a36Sopenharmony_cibooting from a root file system located on the host, persistent storage for 2062306a36Sopenharmony_cistateless or ephemeral guests, and sharing a directory between guests. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciAlthough it is possible to use existing network file systems for some of these 2362306a36Sopenharmony_citasks, they require configuration steps that are hard to automate and they 2462306a36Sopenharmony_ciexpose the storage network to the guest. The virtio-fs device was designed to 2562306a36Sopenharmony_cisolve these problems by providing file system access without networking. 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciFurthermore the virtio-fs device takes advantage of the co-location of the 2862306a36Sopenharmony_ciguest and host to increase performance and provide semantics that are not 2962306a36Sopenharmony_cipossible with network file systems. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciUsage 3262306a36Sopenharmony_ci===== 3362306a36Sopenharmony_ciMount file system with tag ``myfs`` on ``/mnt``: 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci.. code-block:: sh 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci guest# mount -t virtiofs myfs /mnt 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ciPlease see https://virtio-fs.gitlab.io/ for details on how to configure QEMU 4062306a36Sopenharmony_ciand the virtiofsd daemon. 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ciMount options 4362306a36Sopenharmony_ci------------- 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_civirtiofs supports general VFS mount options, for example, remount, 4662306a36Sopenharmony_ciro, rw, context, etc. It also supports FUSE mount options. 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ciatime behavior 4962306a36Sopenharmony_ci^^^^^^^^^^^^^^ 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ciThe atime-related mount options, for example, noatime, strictatime, 5262306a36Sopenharmony_ciare ignored. The atime behavior for virtiofs is the same as the 5362306a36Sopenharmony_ciunderlying filesystem of the directory that has been exported 5462306a36Sopenharmony_cion the host. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciInternals 5762306a36Sopenharmony_ci========= 5862306a36Sopenharmony_ciSince the virtio-fs device uses the FUSE protocol for file system requests, the 5962306a36Sopenharmony_civirtiofs file system for Linux is integrated closely with the FUSE file system 6062306a36Sopenharmony_ciclient. The guest acts as the FUSE client while the host acts as the FUSE 6162306a36Sopenharmony_ciserver. The /dev/fuse interface between the kernel and userspace is replaced 6262306a36Sopenharmony_ciwith the virtio-fs device interface. 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciFUSE requests are placed into a virtqueue and processed by the host. The 6562306a36Sopenharmony_ciresponse portion of the buffer is filled in by the host and the guest handles 6662306a36Sopenharmony_cithe request completion. 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciMapping /dev/fuse to virtqueues requires solving differences in semantics 6962306a36Sopenharmony_cibetween /dev/fuse and virtqueues. Each time the /dev/fuse device is read, the 7062306a36Sopenharmony_ciFUSE client may choose which request to transfer, making it possible to 7162306a36Sopenharmony_ciprioritize certain requests over others. Virtqueues have queue semantics and 7262306a36Sopenharmony_ciit is not possible to change the order of requests that have been enqueued. 7362306a36Sopenharmony_ciThis is especially important if the virtqueue becomes full since it is then 7462306a36Sopenharmony_ciimpossible to add high priority requests. In order to address this difference, 7562306a36Sopenharmony_cithe virtio-fs device uses a "hiprio" virtqueue specifically for requests that 7662306a36Sopenharmony_cihave priority over normal requests. 77