xref: /OK3568_Linux_fs/kernel/Documentation/filesystems/virtiofs.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun.. _virtiofs_index:
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun===================================================
6*4882a593Smuzhiyunvirtiofs: virtio-fs host<->guest shared file system
7*4882a593Smuzhiyun===================================================
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun- Copyright (C) 2019 Red Hat, Inc.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunIntroduction
12*4882a593Smuzhiyun============
13*4882a593SmuzhiyunThe virtiofs file system for Linux implements a driver for the paravirtualized
14*4882a593SmuzhiyunVIRTIO "virtio-fs" device for guest<->host file system sharing.  It allows a
15*4882a593Smuzhiyunguest to mount a directory that has been exported on the host.
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunGuests often require access to files residing on the host or remote systems.
18*4882a593SmuzhiyunUse cases include making files available to new guests during installation,
19*4882a593Smuzhiyunbooting from a root file system located on the host, persistent storage for
20*4882a593Smuzhiyunstateless or ephemeral guests, and sharing a directory between guests.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunAlthough it is possible to use existing network file systems for some of these
23*4882a593Smuzhiyuntasks, they require configuration steps that are hard to automate and they
24*4882a593Smuzhiyunexpose the storage network to the guest.  The virtio-fs device was designed to
25*4882a593Smuzhiyunsolve these problems by providing file system access without networking.
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunFurthermore the virtio-fs device takes advantage of the co-location of the
28*4882a593Smuzhiyunguest and host to increase performance and provide semantics that are not
29*4882a593Smuzhiyunpossible with network file systems.
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunUsage
32*4882a593Smuzhiyun=====
33*4882a593SmuzhiyunMount file system with tag ``myfs`` on ``/mnt``:
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun.. code-block:: sh
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun  guest# mount -t virtiofs myfs /mnt
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunPlease see https://virtio-fs.gitlab.io/ for details on how to configure QEMU
40*4882a593Smuzhiyunand the virtiofsd daemon.
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunMount options
43*4882a593Smuzhiyun-------------
44*4882a593Smuzhiyun
45*4882a593Smuzhiyunvirtiofs supports general VFS mount options, for example, remount,
46*4882a593Smuzhiyunro, rw, context, etc. It also supports FUSE mount options.
47*4882a593Smuzhiyun
48*4882a593Smuzhiyunatime behavior
49*4882a593Smuzhiyun^^^^^^^^^^^^^^
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunThe atime-related mount options, for example, noatime, strictatime,
52*4882a593Smuzhiyunare ignored. The atime behavior for virtiofs is the same as the
53*4882a593Smuzhiyununderlying filesystem of the directory that has been exported
54*4882a593Smuzhiyunon the host.
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunInternals
57*4882a593Smuzhiyun=========
58*4882a593SmuzhiyunSince the virtio-fs device uses the FUSE protocol for file system requests, the
59*4882a593Smuzhiyunvirtiofs file system for Linux is integrated closely with the FUSE file system
60*4882a593Smuzhiyunclient.  The guest acts as the FUSE client while the host acts as the FUSE
61*4882a593Smuzhiyunserver.  The /dev/fuse interface between the kernel and userspace is replaced
62*4882a593Smuzhiyunwith the virtio-fs device interface.
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunFUSE requests are placed into a virtqueue and processed by the host.  The
65*4882a593Smuzhiyunresponse portion of the buffer is filled in by the host and the guest handles
66*4882a593Smuzhiyunthe request completion.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunMapping /dev/fuse to virtqueues requires solving differences in semantics
69*4882a593Smuzhiyunbetween /dev/fuse and virtqueues.  Each time the /dev/fuse device is read, the
70*4882a593SmuzhiyunFUSE client may choose which request to transfer, making it possible to
71*4882a593Smuzhiyunprioritize certain requests over others.  Virtqueues have queue semantics and
72*4882a593Smuzhiyunit is not possible to change the order of requests that have been enqueued.
73*4882a593SmuzhiyunThis is especially important if the virtqueue becomes full since it is then
74*4882a593Smuzhiyunimpossible to add high priority requests.  In order to address this difference,
75*4882a593Smuzhiyunthe virtio-fs device uses a "hiprio" virtqueue specifically for requests that
76*4882a593Smuzhiyunhave priority over normal requests.
77