Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit f2234d2

Browse files
dagrhstefanhaRH
authored andcommitted
virtiofs: Add cache option
Several cache modes are supported by virtio-fs. They affect the performance and consistency characteristics of the file system. For the time being cache="none" is recommended, but the other modes can be experimented with. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1 parent ec0fb68 commit f2234d2

File tree

7 files changed

+30
-1
lines changed

7 files changed

+30
-1
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ DEFSHAREDFS := virtio-9p
160160
DEFVIRTIOFSDAEMON :=
161161
# Default DAX mapping cache size in MiB
162162
DEFVIRTIOFSCACHESIZE := 8192
163+
DEFVIRTIOFSCACHE := always
163164
DEFENABLEIOTHREADS := false
164165
DEFENABLEMEMPREALLOC := false
165166
DEFENABLEHUGEPAGES := false
@@ -327,6 +328,7 @@ USER_VARS += DEFBLOCKSTORAGEDRIVER_QEMU
327328
USER_VARS += DEFSHAREDFS
328329
USER_VARS += DEFVIRTIOFSDAEMON
329330
USER_VARS += DEFVIRTIOFSCACHESIZE
331+
USER_VARS += DEFVIRTIOFSCACHE
330332
USER_VARS += DEFENABLEIOTHREADS
331333
USER_VARS += DEFENABLEMEMPREALLOC
332334
USER_VARS += DEFENABLEHUGEPAGES
@@ -466,6 +468,7 @@ $(GENERATED_FILES): %: %.in $(MAKEFILE_LIST) VERSION .git-commit
466468
-e "s|@DEFSHAREDFS@|$(DEFSHAREDFS)|g" \
467469
-e "s|@DEFVIRTIOFSDAEMON@|$(DEFVIRTIOFSDAEMON)|g" \
468470
-e "s|@DEFVIRTIOFSCACHESIZE@|$(DEFVIRTIOFSCACHESIZE)|g" \
471+
-e "s|@DEFVIRTIOFSCACHE@|$(DEFVIRTIOFSCACHE)|g" \
469472
-e "s|@DEFENABLEIOTHREADS@|$(DEFENABLEIOTHREADS)|g" \
470473
-e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \
471474
-e "s|@DEFENABLEHUGEPAGES@|$(DEFENABLEHUGEPAGES)|g" \

cli/config/configuration-qemu.toml.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ virtio_fs_daemon = "@DEFVIRTIOFSDAEMON@"
108108
# Default size of DAX cache in GiB
109109
virtio_fs_cache_size = @DEFVIRTIOFSCACHESIZE@
110110

111+
# Cache mode:
112+
#
113+
# - none
114+
# Metadata, data, and pathname lookup are not cached in guest. They are
115+
# always fetched from host and any changes are immediately pushed to host.
116+
#
117+
# - auto
118+
# Metadata and pathname lookup cache expires after a configured amount of
119+
# time (default is 1 second). Data is cached while the file is open (close
120+
# to open consistency).
121+
#
122+
# - always
123+
# Metadata, data, and pathname lookup are cached in guest and never expire.
124+
virtio_fs_cache = "@DEFVIRTIOFSCACHE@"
125+
111126
# Block storage driver to be used for the hypervisor in case the container
112127
# rootfs is backed by a block device. This is virtio-scsi, virtio-blk
113128
# or nvdimm.

pkg/katautils/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type hypervisor struct {
9494
EntropySource string `toml:"entropy_source"`
9595
SharedFS string `toml:"shared_fs"`
9696
VirtioFSDaemon string `toml:"virtio_fs_daemon"`
97+
VirtioFSCache string `toml:"virtio_fs_cache"`
9798
VirtioFSCacheSize uint32 `toml:"virtio_fs_cache_size"`
9899
BlockDeviceCacheSet bool `toml:"block_device_cache_set"`
99100
BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"`
@@ -580,6 +581,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
580581
SharedFS: sharedFS,
581582
VirtioFSDaemon: h.VirtioFSDaemon,
582583
VirtioFSCacheSize: h.VirtioFSCacheSize,
584+
VirtioFSCache: h.VirtioFSCache,
583585
MemPrealloc: h.MemPrealloc,
584586
HugePages: h.HugePages,
585587
Mlock: !h.Swap,

virtcontainers/device/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ type VhostUserDeviceAttrs struct {
189189
// These are only meaningful for vhost user fs devices
190190
Tag string
191191
CacheSize uint32
192+
Cache string
192193
}
193194

194195
// GetHostPathFunc is function pointer used to mock GetHostPath in tests.

virtcontainers/documentation/api/1.0/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ type HypervisorConfig struct {
149149
// VirtioFSCacheSize is the virtio-fs DAX cache size in MiB
150150
VirtioFSCacheSize uint32
151151

152+
// VirtioFSCache cache mode for fs version cache or "none"
153+
VirtioFSCache string
154+
152155
// KernelParams are additional guest kernel parameters.
153156
KernelParams []Param
154157

virtcontainers/hypervisor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ type HypervisorConfig struct {
226226
// VirtioFSDaemon is the virtio-fs vhost-user daemon path
227227
VirtioFSDaemon string
228228

229+
// VirtioFSCache cache mode for fs version cache or "none"
230+
VirtioFSCache string
231+
229232
// customAssets is a map of assets.
230233
// Each value in that map takes precedence over the configured assets.
231234
// For example, if there is a value for the "kernel" key in this map,

virtcontainers/qemu.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ func (q *qemu) startSandbox(timeout int) error {
600600
sourcePath := filepath.Join(kataHostSharedDir, q.id)
601601
cmd := exec.Command(q.config.VirtioFSDaemon,
602602
"-o", "vhost_user_socket="+sockPath,
603-
"-o", "source="+sourcePath)
603+
"-o", "source="+sourcePath,
604+
"-o", "cache="+q.config.VirtioFSCache)
604605
stderr, err := cmd.StderrPipe()
605606
if err != nil {
606607
return err
@@ -1379,6 +1380,7 @@ func (q *qemu) addDevice(devInfo interface{}, devType deviceType) error {
13791380
Tag: v.MountTag,
13801381
Type: config.VhostUserFS,
13811382
CacheSize: q.config.VirtioFSCacheSize,
1383+
Cache: q.config.VirtioFSCache,
13821384
}
13831385
vhostDev.SocketPath = sockPath
13841386
vhostDev.DevID = id

0 commit comments

Comments
 (0)