18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci.. _virtiofs_index: 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci=================================================== 68c2ecf20Sopenharmony_civirtiofs: virtio-fs host<->guest shared file system 78c2ecf20Sopenharmony_ci=================================================== 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci- Copyright (C) 2019 Red Hat, Inc. 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciIntroduction 128c2ecf20Sopenharmony_ci============ 138c2ecf20Sopenharmony_ciThe virtiofs file system for Linux implements a driver for the paravirtualized 148c2ecf20Sopenharmony_ciVIRTIO "virtio-fs" device for guest<->host file system sharing. It allows a 158c2ecf20Sopenharmony_ciguest to mount a directory that has been exported on the host. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciGuests often require access to files residing on the host or remote systems. 188c2ecf20Sopenharmony_ciUse cases include making files available to new guests during installation, 198c2ecf20Sopenharmony_cibooting from a root file system located on the host, persistent storage for 208c2ecf20Sopenharmony_cistateless or ephemeral guests, and sharing a directory between guests. 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciAlthough it is possible to use existing network file systems for some of these 238c2ecf20Sopenharmony_citasks, they require configuration steps that are hard to automate and they 248c2ecf20Sopenharmony_ciexpose the storage network to the guest. The virtio-fs device was designed to 258c2ecf20Sopenharmony_cisolve these problems by providing file system access without networking. 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciFurthermore the virtio-fs device takes advantage of the co-location of the 288c2ecf20Sopenharmony_ciguest and host to increase performance and provide semantics that are not 298c2ecf20Sopenharmony_cipossible with network file systems. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciUsage 328c2ecf20Sopenharmony_ci===== 338c2ecf20Sopenharmony_ciMount file system with tag ``myfs`` on ``/mnt``: 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci.. code-block:: sh 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci guest# mount -t virtiofs myfs /mnt 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ciPlease see https://virtio-fs.gitlab.io/ for details on how to configure QEMU 408c2ecf20Sopenharmony_ciand the virtiofsd daemon. 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciMount options 438c2ecf20Sopenharmony_ci------------- 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_civirtiofs supports general VFS mount options, for example, remount, 468c2ecf20Sopenharmony_ciro, rw, context, etc. It also supports FUSE mount options. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ciatime behavior 498c2ecf20Sopenharmony_ci^^^^^^^^^^^^^^ 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciThe atime-related mount options, for example, noatime, strictatime, 528c2ecf20Sopenharmony_ciare ignored. The atime behavior for virtiofs is the same as the 538c2ecf20Sopenharmony_ciunderlying filesystem of the directory that has been exported 548c2ecf20Sopenharmony_cion the host. 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciInternals 578c2ecf20Sopenharmony_ci========= 588c2ecf20Sopenharmony_ciSince the virtio-fs device uses the FUSE protocol for file system requests, the 598c2ecf20Sopenharmony_civirtiofs file system for Linux is integrated closely with the FUSE file system 608c2ecf20Sopenharmony_ciclient. The guest acts as the FUSE client while the host acts as the FUSE 618c2ecf20Sopenharmony_ciserver. The /dev/fuse interface between the kernel and userspace is replaced 628c2ecf20Sopenharmony_ciwith the virtio-fs device interface. 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciFUSE requests are placed into a virtqueue and processed by the host. The 658c2ecf20Sopenharmony_ciresponse portion of the buffer is filled in by the host and the guest handles 668c2ecf20Sopenharmony_cithe request completion. 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciMapping /dev/fuse to virtqueues requires solving differences in semantics 698c2ecf20Sopenharmony_cibetween /dev/fuse and virtqueues. Each time the /dev/fuse device is read, the 708c2ecf20Sopenharmony_ciFUSE client may choose which request to transfer, making it possible to 718c2ecf20Sopenharmony_ciprioritize certain requests over others. Virtqueues have queue semantics and 728c2ecf20Sopenharmony_ciit is not possible to change the order of requests that have been enqueued. 738c2ecf20Sopenharmony_ciThis is especially important if the virtqueue becomes full since it is then 748c2ecf20Sopenharmony_ciimpossible to add high priority requests. In order to address this difference, 758c2ecf20Sopenharmony_cithe virtio-fs device uses a "hiprio" virtqueue specifically for requests that 768c2ecf20Sopenharmony_cihave priority over normal requests. 77