Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
hypervisor: add machine_accelerators option in config file
Browse files Browse the repository at this point in the history
machine_accelerators allows user to use specific machine
accelerators

fixes #826

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Nov 28, 2017
1 parent 3583bca commit 006b591
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ PKGLIBEXECDIR := $(LIBEXECDIR)/$(CCDIR)
KERNELPATH := $(PKGDATADIR)/vmlinuz.container
IMAGEPATH := $(PKGDATADIR)/clear-containers.img
FIRMWAREPATH :=
MACHINEACCELERATORS :=

KERNELPARAMS :=

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -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" \
Expand Down
19 changes: 19 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -229,6 +245,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
return vc.HypervisorConfig{}, err
}

machineAccelerators := h.machineAccelerators()
kernelParams := h.kernelParams()
machineType := h.machineType()

Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 006b591

Please sign in to comment.