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

Commit 9a27ac2

Browse files
author
Eric Ernst
authored
Merge pull request #1016 from stefanha/virtio-fs-core
Add virtio-fs support (alternative to virtio-9p)
2 parents 4c5527f + 0a69eb8 commit 9a27ac2

File tree

18 files changed

+351
-31
lines changed

18 files changed

+351
-31
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
[[constraint]]
5050
name = "github.com/intel/govmm"
51-
revision = "35a8fd3ca9a36461b7dcf24e3b292f6e1ea4e71a"
51+
revision = "b3e7a9e78463a10f2a19e1a966c76a3afb215781"
5252

5353
[[constraint]]
5454
name = "github.com/kata-containers/agent"

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ DEFAULTEXPFEATURES := []
156156
DEFENTROPYSOURCE := /dev/urandom
157157

158158
DEFDISABLEBLOCK := false
159+
DEFSHAREDFS := virtio-9p
160+
DEFVIRTIOFSDAEMON :=
161+
# Default DAX mapping cache size in MiB
162+
DEFVIRTIOFSCACHESIZE := 8192
163+
DEFVIRTIOFSCACHE := always
159164
DEFENABLEIOTHREADS := false
160165
DEFENABLEMEMPREALLOC := false
161166
DEFENABLEHUGEPAGES := false
@@ -320,6 +325,10 @@ USER_VARS += DEFAULTEXPFEATURES
320325
USER_VARS += DEFDISABLEBLOCK
321326
USER_VARS += DEFBLOCKSTORAGEDRIVER_FC
322327
USER_VARS += DEFBLOCKSTORAGEDRIVER_QEMU
328+
USER_VARS += DEFSHAREDFS
329+
USER_VARS += DEFVIRTIOFSDAEMON
330+
USER_VARS += DEFVIRTIOFSCACHESIZE
331+
USER_VARS += DEFVIRTIOFSCACHE
323332
USER_VARS += DEFENABLEIOTHREADS
324333
USER_VARS += DEFENABLEMEMPREALLOC
325334
USER_VARS += DEFENABLEHUGEPAGES
@@ -456,6 +465,10 @@ $(GENERATED_FILES): %: %.in $(MAKEFILE_LIST) VERSION .git-commit
456465
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
457466
-e "s|@DEFBLOCKSTORAGEDRIVER_FC@|$(DEFBLOCKSTORAGEDRIVER_FC)|g" \
458467
-e "s|@DEFBLOCKSTORAGEDRIVER_QEMU@|$(DEFBLOCKSTORAGEDRIVER_QEMU)|g" \
468+
-e "s|@DEFSHAREDFS@|$(DEFSHAREDFS)|g" \
469+
-e "s|@DEFVIRTIOFSDAEMON@|$(DEFVIRTIOFSDAEMON)|g" \
470+
-e "s|@DEFVIRTIOFSCACHESIZE@|$(DEFVIRTIOFSCACHESIZE)|g" \
471+
-e "s|@DEFVIRTIOFSCACHE@|$(DEFVIRTIOFSCACHE)|g" \
459472
-e "s|@DEFENABLEIOTHREADS@|$(DEFENABLEIOTHREADS)|g" \
460473
-e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \
461474
-e "s|@DEFENABLEHUGEPAGES@|$(DEFENABLEHUGEPAGES)|g" \

cli/config/configuration-qemu.toml.in

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,32 @@ default_memory = @DEFMEMSZ@
9797
# 9pfs is used instead to pass the rootfs.
9898
disable_block_device_use = @DEFDISABLEBLOCK@
9999

100+
# Shared file system type:
101+
# - virtio-9p (default)
102+
# - virtio-fs
103+
shared_fs = "@DEFSHAREDFS@"
104+
105+
# Path to vhost-user-fs daemon.
106+
virtio_fs_daemon = "@DEFVIRTIOFSDAEMON@"
107+
108+
# Default size of DAX cache in MiB
109+
virtio_fs_cache_size = @DEFVIRTIOFSCACHESIZE@
110+
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+
100126
# Block storage driver to be used for the hypervisor in case the container
101127
# rootfs is backed by a block device. This is virtio-scsi, virtio-blk
102128
# or nvdimm.

cli/kata-env.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type HypervisorInfo struct {
9292
MemorySlots uint32
9393
Debug bool
9494
UseVSock bool
95+
SharedFS string
9596
}
9697

9798
// ProxyInfo stores proxy details
@@ -352,6 +353,7 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
352353
UseVSock: config.HypervisorConfig.UseVSock,
353354
MemorySlots: config.HypervisorConfig.MemSlots,
354355
EntropySource: config.HypervisorConfig.EntropySource,
356+
SharedFS: config.HypervisorConfig.SharedFS,
355357
}
356358
}
357359

cli/kata-env_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const testHypervisorVersion = "QEMU emulator version 2.7.0+git.741f430a96-6.1, C
3737

3838
var (
3939
hypervisorDebug = false
40+
enableVirtioFS = false
4041
proxyDebug = false
4142
runtimeDebug = false
4243
runtimeTrace = false
@@ -91,6 +92,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
9192
enableIOThreads := true
9293
hotplugVFIOOnRootBus := true
9394
disableNewNetNs := false
95+
sharedFS := "virtio-9p"
9496

9597
filesToCreate := []string{
9698
hypervisorPath,
@@ -126,6 +128,10 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
126128
return "", oci.RuntimeConfig{}, err
127129
}
128130

131+
if enableVirtioFS {
132+
sharedFS = "virtio-fs"
133+
}
134+
129135
hypConfig := katautils.GetDefaultHypervisorConfig()
130136

131137
configFileOptions := katatestutils.RuntimeConfigOptions{
@@ -157,6 +163,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
157163
NetmonDebug: netmonDebug,
158164
AgentDebug: agentDebug,
159165
AgentTrace: agentTrace,
166+
SharedFS: sharedFS,
160167
}
161168

162169
runtimeConfig := katatestutils.MakeRuntimeConfigFileData(configFileOptions)
@@ -321,6 +328,7 @@ func getExpectedHypervisor(config oci.RuntimeConfig) HypervisorInfo {
321328
MemorySlots: config.HypervisorConfig.MemSlots,
322329
Debug: config.HypervisorConfig.Debug,
323330
EntropySource: config.HypervisorConfig.EntropySource,
331+
SharedFS: config.HypervisorConfig.SharedFS,
324332
}
325333
}
326334

@@ -498,6 +506,7 @@ func TestEnvGetEnvInfo(t *testing.T) {
498506
// options are tested.
499507
for _, toggle := range []bool{false, true} {
500508
hypervisorDebug = toggle
509+
enableVirtioFS = toggle
501510
proxyDebug = toggle
502511
runtimeDebug = toggle
503512
runtimeTrace = toggle

pkg/katatestutils/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type RuntimeConfigOptions struct {
2727
BlockDeviceDriver string
2828
AgentTraceMode string
2929
AgentTraceType string
30+
SharedFS string
3031
DisableBlock bool
3132
EnableIOThreads bool
3233
HotplugVFIOOnRootBus bool
@@ -61,6 +62,8 @@ func MakeRuntimeConfigFileData(config RuntimeConfigOptions) string {
6162
msize_9p = ` + strconv.FormatUint(uint64(config.DefaultMsize9p), 10) + `
6263
enable_debug = ` + strconv.FormatBool(config.HypervisorDebug) + `
6364
guest_hook_path = "` + config.DefaultGuestHookPath + `"
65+
shared_fs = "` + config.SharedFS + `"
66+
virtio_fs_daemon = "/path/to/virtiofsd"
6467
6568
[proxy.kata]
6669
enable_debug = ` + strconv.FormatBool(config.ProxyDebug) + `

pkg/katautils/config.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type hypervisor struct {
9292
MachineType string `toml:"machine_type"`
9393
BlockDeviceDriver string `toml:"block_device_driver"`
9494
EntropySource string `toml:"entropy_source"`
95+
SharedFS string `toml:"shared_fs"`
96+
VirtioFSDaemon string `toml:"virtio_fs_daemon"`
97+
VirtioFSCache string `toml:"virtio_fs_cache"`
98+
VirtioFSCacheSize uint32 `toml:"virtio_fs_cache_size"`
9599
BlockDeviceCacheSet bool `toml:"block_device_cache_set"`
96100
BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"`
97101
BlockDeviceCacheNoflush bool `toml:"block_device_cache_noflush"`
@@ -326,6 +330,22 @@ func (h hypervisor) blockDeviceDriver() (string, error) {
326330
return "", fmt.Errorf("Invalid hypervisor block storage driver %v specified (supported drivers: %v)", h.BlockDeviceDriver, supportedBlockDrivers)
327331
}
328332

333+
func (h hypervisor) sharedFS() (string, error) {
334+
supportedSharedFS := []string{config.Virtio9P, config.VirtioFS}
335+
336+
if h.SharedFS == "" {
337+
return config.Virtio9P, nil
338+
}
339+
340+
for _, fs := range supportedSharedFS {
341+
if fs == h.SharedFS {
342+
return h.SharedFS, nil
343+
}
344+
}
345+
346+
return "", fmt.Errorf("Invalid hypervisor shared file system %v specified (supported file systems: %v)", h.SharedFS, supportedSharedFS)
347+
}
348+
329349
func (h hypervisor) msize9p() uint32 {
330350
if h.Msize9p == 0 {
331351
return defaultMsize9p
@@ -521,6 +541,16 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
521541
return vc.HypervisorConfig{}, err
522542
}
523543

544+
sharedFS, err := h.sharedFS()
545+
if err != nil {
546+
return vc.HypervisorConfig{}, err
547+
}
548+
549+
if sharedFS == config.VirtioFS && h.VirtioFSDaemon == "" {
550+
return vc.HypervisorConfig{},
551+
errors.New("cannot enable virtio-fs without daemon path in configuration file")
552+
}
553+
524554
useVSock := false
525555
if h.useVSock() {
526556
if utils.SupportsVsocks() {
@@ -548,6 +578,10 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
548578
EntropySource: h.GetEntropySource(),
549579
DefaultBridges: h.defaultBridges(),
550580
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
581+
SharedFS: sharedFS,
582+
VirtioFSDaemon: h.VirtioFSDaemon,
583+
VirtioFSCacheSize: h.VirtioFSCacheSize,
584+
VirtioFSCache: h.VirtioFSCache,
551585
MemPrealloc: h.MemPrealloc,
552586
HugePages: h.HugePages,
553587
Mlock: !h.Swap,

pkg/katautils/config_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
8383
enableIOThreads := true
8484
hotplugVFIOOnRootBus := true
8585
disableNewNetNs := false
86+
sharedFS := "virtio-9p"
8687

8788
configFileOptions := ktu.RuntimeConfigOptions{
8889
Hypervisor: "qemu",
@@ -113,6 +114,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
113114
NetmonDebug: netmonDebug,
114115
AgentDebug: agentDebug,
115116
AgentTrace: agentTrace,
117+
SharedFS: sharedFS,
116118
}
117119

118120
runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions)
@@ -160,6 +162,8 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
160162
MemSlots: defaultMemSlots,
161163
EntropySource: defaultEntropySource,
162164
GuestHookPath: defaultGuestHookPath,
165+
SharedFS: sharedFS,
166+
VirtioFSDaemon: "/path/to/virtiofsd",
163167
}
164168

165169
agentConfig := vc.KataAgentConfig{}

vendor/github.com/intel/govmm/qemu/qemu.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)