diff --git a/Makefile b/Makefile index 2b001808..15e73e09 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,7 @@ PKGLIBEXECDIR := $(LIBEXECDIR)/$(CCDIR) KERNELPATH := $(PKGDATADIR)/vmlinuz.container IMAGEPATH := $(PKGDATADIR)/clear-containers.img FIRMWAREPATH := +MACHINEACCELERATORS := KERNELPARAMS := @@ -158,6 +159,7 @@ USER_VARS += IMAGEPATH USER_VARS += MACHINETYPE USER_VARS += KERNELPATH USER_VARS += FIRMWAREPATH +USER_VARS += MACHINEACCELERATORS USER_VARS += KERNELPARAMS USER_VARS += LIBEXECDIR USER_VARS += LOCALSTATEDIR @@ -218,6 +220,7 @@ var defaultHypervisorPath = "$(QEMUPATH)" var defaultImagePath = "$(IMAGEPATH)" var defaultKernelPath = "$(KERNELPATH)" var defaultFirmwarePath = "$(FIRMWAREPATH)" +var defaultMachineAccelerators = "$(MACHINEACCELERATORS)" var defaultShimPath = "$(SHIMPATH)" const defaultKernelParams = "$(KERNELPARAMS)" @@ -289,6 +292,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION -e "s|@IMAGEPATH@|$(IMAGEPATH)|g" \ -e "s|@KERNELPATH@|$(KERNELPATH)|g" \ -e "s|@FIRMWAREPATH@|$(FIRMWAREPATH)|g" \ + -e "s|@MACHINEACCELERATORS@|$(MACHINEACCELERATORS)|g" \ -e "s|@KERNELPARAMS@|$(KERNELPARAMS)|g" \ -e "s|@LOCALSTATEDIR@|$(LOCALSTATEDIR)|g" \ -e "s|@PKGLIBEXECDIR@|$(PKGLIBEXECDIR)|g" \ diff --git a/config.go b/config.go index 515d18b0..2f31f6bd 100644 --- a/config.go +++ b/config.go @@ -77,6 +77,7 @@ type hypervisor struct { Kernel string `toml:"kernel"` Image string `toml:"image"` Firmware string `toml:"firmware"` + MachineAccelerators string `toml:"machine_accelerators"` KernelParams string `toml:"kernel_params"` MachineType string `toml:"machine_type"` DefaultVCPUs int32 `toml:"default_vcpus"` @@ -148,6 +149,21 @@ func (h hypervisor) firmware() (string, error) { return resolvePath(p) } +func (h hypervisor) machineAccelerators() string { + var machineAccelerators string + accelerators := strings.Split(h.MachineAccelerators, ",") + acceleratorsLen := len(accelerators) + for i := 0; i < acceleratorsLen; i++ { + if accelerators[i] != "" { + machineAccelerators += strings.Trim(accelerators[i], "\r\t\n ") + "," + } + } + + machineAccelerators = strings.Trim(machineAccelerators, ",") + + return machineAccelerators +} + func (h hypervisor) kernelParams() string { if h.KernelParams == "" { return defaultKernelParams @@ -229,6 +245,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { return vc.HypervisorConfig{}, err } + machineAccelerators := h.machineAccelerators() kernelParams := h.kernelParams() machineType := h.machineType() @@ -237,6 +254,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { KernelPath: kernel, ImagePath: image, FirmwarePath: firmware, + MachineAccelerators: machineAccelerators, KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)), HypervisorMachineType: machineType, DefaultVCPUs: h.defaultVCPUs(), @@ -341,6 +359,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat KernelPath: defaultKernelPath, ImagePath: defaultImagePath, FirmwarePath: defaultFirmwarePath, + MachineAccelerators: defaultMachineAccelerators, HypervisorMachineType: defaultMachineType, DefaultVCPUs: defaultVCPUCount, DefaultMemSz: defaultMemSize, diff --git a/config/configuration.toml.in b/config/configuration.toml.in index 6ef9fbc3..9779c35e 100644 --- a/config/configuration.toml.in +++ b/config/configuration.toml.in @@ -14,6 +14,11 @@ kernel_params = "@KERNELPARAMS@" # If you want that qemu uses the default firmware leave this option empty firmware = "@FIRMWAREPATH@" +# Machine accelerators +# comma-separated list of machine accelerators to pass to the hypervisor. +# For example, `machine_accelerators = "nosmm,nosmbus,nosata,nopit,static-prt,nofw"` +machine_accelerators="@MACHINEACCELERATORS@" + # Default number of vCPUs per POD/VM: # unspecified or 0 --> will be set to @DEFVCPUS@ # < 0 --> will be set to the actual number of physical cores diff --git a/config_test.go b/config_test.go index d3723f89..7e495cf9 100644 --- a/config_test.go +++ b/config_test.go @@ -919,3 +919,50 @@ func TestDefaultFirmware(t *testing.T) { assert.NoError(err) assert.NotEmpty(p) } + +func TestDefaultMachineAccelerators(t *testing.T) { + assert := assert.New(t) + machineAccelerators := "abc,123,rgb" + h := hypervisor{MachineAccelerators: machineAccelerators} + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "" + h.MachineAccelerators = machineAccelerators + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc" + h.MachineAccelerators = machineAccelerators + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc,123" + h.MachineAccelerators = "abc,,123" + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc,123" + h.MachineAccelerators = ",,abc,,123,,," + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc,123" + h.MachineAccelerators = "abc,,123,,," + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc" + h.MachineAccelerators = ",,abc," + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc" + h.MachineAccelerators = ", , abc , ," + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc" + h.MachineAccelerators = " abc " + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc,123" + h.MachineAccelerators = ", abc , 123 ," + assert.Equal(machineAccelerators, h.machineAccelerators()) + + machineAccelerators = "abc,123" + h.MachineAccelerators = ",, abc ,,, 123 ,," + assert.Equal(machineAccelerators, h.machineAccelerators()) +}