From 9e87fa21cfa740496a7ddae6e7c5165d56727f18 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Thu, 5 Jul 2018 14:52:03 +0100 Subject: [PATCH] config: add shared_fs option Add a config option to select between virtio-9p and virtiofs. This option currently has no effect and will be used in a later patch. Signed-off-by: Stefan Hajnoczi --- Makefile | 3 +++ cli/config/configuration-qemu.toml.in | 5 +++++ pkg/katautils/config.go | 23 +++++++++++++++++++++ virtcontainers/device/config/config.go | 8 +++++++ virtcontainers/documentation/api/1.0/api.md | 5 +++++ virtcontainers/hypervisor.go | 5 +++++ 6 files changed, 49 insertions(+) diff --git a/Makefile b/Makefile index 32b4f1d3cc..7025341431 100644 --- a/Makefile +++ b/Makefile @@ -156,6 +156,7 @@ DEFAULTEXPFEATURES := [] DEFENTROPYSOURCE := /dev/urandom DEFDISABLEBLOCK := false +DEFSHAREDFS := virtio-9p DEFENABLEIOTHREADS := false DEFENABLEMEMPREALLOC := false DEFENABLEHUGEPAGES := false @@ -320,6 +321,7 @@ USER_VARS += DEFAULTEXPFEATURES USER_VARS += DEFDISABLEBLOCK USER_VARS += DEFBLOCKSTORAGEDRIVER_FC USER_VARS += DEFBLOCKSTORAGEDRIVER_QEMU +USER_VARS += DEFSHAREDFS USER_VARS += DEFENABLEIOTHREADS USER_VARS += DEFENABLEMEMPREALLOC USER_VARS += DEFENABLEHUGEPAGES @@ -456,6 +458,7 @@ $(GENERATED_FILES): %: %.in $(MAKEFILE_LIST) VERSION .git-commit -e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \ -e "s|@DEFBLOCKSTORAGEDRIVER_FC@|$(DEFBLOCKSTORAGEDRIVER_FC)|g" \ -e "s|@DEFBLOCKSTORAGEDRIVER_QEMU@|$(DEFBLOCKSTORAGEDRIVER_QEMU)|g" \ + -e "s|@DEFSHAREDFS@|$(DEFSHAREDFS)|g" \ -e "s|@DEFENABLEIOTHREADS@|$(DEFENABLEIOTHREADS)|g" \ -e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \ -e "s|@DEFENABLEHUGEPAGES@|$(DEFENABLEHUGEPAGES)|g" \ diff --git a/cli/config/configuration-qemu.toml.in b/cli/config/configuration-qemu.toml.in index c7fd600c44..43b910c2b5 100644 --- a/cli/config/configuration-qemu.toml.in +++ b/cli/config/configuration-qemu.toml.in @@ -97,6 +97,11 @@ default_memory = @DEFMEMSZ@ # 9pfs is used instead to pass the rootfs. disable_block_device_use = @DEFDISABLEBLOCK@ +# Shared file system type: +# - virtio-9p (default) +# - virtio-fs +shared_fs = "@DEFSHAREDFS@" + # Block storage driver to be used for the hypervisor in case the container # rootfs is backed by a block device. This is virtio-scsi, virtio-blk # or nvdimm. diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index 99cf9a3cd7..31b58ef2a8 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -92,6 +92,7 @@ type hypervisor struct { MachineType string `toml:"machine_type"` BlockDeviceDriver string `toml:"block_device_driver"` EntropySource string `toml:"entropy_source"` + SharedFS string `toml:"shared_fs"` BlockDeviceCacheSet bool `toml:"block_device_cache_set"` BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"` BlockDeviceCacheNoflush bool `toml:"block_device_cache_noflush"` @@ -326,6 +327,22 @@ func (h hypervisor) blockDeviceDriver() (string, error) { return "", fmt.Errorf("Invalid hypervisor block storage driver %v specified (supported drivers: %v)", h.BlockDeviceDriver, supportedBlockDrivers) } +func (h hypervisor) sharedFS() (string, error) { + supportedSharedFS := []string{config.Virtio9P, config.VirtioFS} + + if h.SharedFS == "" { + return config.Virtio9P, nil + } + + for _, fs := range supportedSharedFS { + if fs == h.SharedFS { + return h.SharedFS, nil + } + } + + return "", fmt.Errorf("Invalid hypervisor shared file system %v specified (supported file systems: %v)", h.SharedFS, supportedSharedFS) +} + func (h hypervisor) msize9p() uint32 { if h.Msize9p == 0 { return defaultMsize9p @@ -521,6 +538,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { return vc.HypervisorConfig{}, err } + sharedFS, err := h.sharedFS() + if err != nil { + return vc.HypervisorConfig{}, err + } + useVSock := false if h.useVSock() { if utils.SupportsVsocks() { @@ -548,6 +570,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { EntropySource: h.GetEntropySource(), DefaultBridges: h.defaultBridges(), DisableBlockDeviceUse: h.DisableBlockDeviceUse, + SharedFS: sharedFS, MemPrealloc: h.MemPrealloc, HugePages: h.HugePages, Mlock: !h.Swap, diff --git a/virtcontainers/device/config/config.go b/virtcontainers/device/config/config.go index 13eaeff352..e32ba93883 100644 --- a/virtcontainers/device/config/config.go +++ b/virtcontainers/device/config/config.go @@ -52,6 +52,14 @@ const ( Nvdimm = "nvdimm" ) +const ( + // Virtio9P means use virtio-9p for the shared file system + Virtio9P = "virtio-9p" + + // VirtioFS means use virtio-fs for the shared file system + VirtioFS = "virtio-fs" +) + // Defining these as a variable instead of a const, to allow // overriding this in the tests. diff --git a/virtcontainers/documentation/api/1.0/api.md b/virtcontainers/documentation/api/1.0/api.md index 0ec8fdc25a..69b92ebd25 100644 --- a/virtcontainers/documentation/api/1.0/api.md +++ b/virtcontainers/documentation/api/1.0/api.md @@ -138,6 +138,11 @@ type HypervisorConfig struct { // DisableBlockDeviceUse disallows a block device from being used. DisableBlockDeviceUse bool + // Shared file system type: + // - virtio-9p (default) + // - virtio-fs + SharedFS string + // KernelParams are additional guest kernel parameters. KernelParams []Param diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index 5546794455..6945d62d60 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -215,6 +215,11 @@ type HypervisorConfig struct { // entropy (/dev/random, /dev/urandom or real hardware RNG device) EntropySource string + // Shared file system type: + // - virtio-9p (default) + // - virtio-fs + SharedFS string + // customAssets is a map of assets. // Each value in that map takes precedence over the configured assets. // For example, if there is a value for the "kernel" key in this map,