From 58276fc8921fc8b62798173a16d1f79acb37ea21 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Fri, 6 Oct 2017 14:11:31 -0500 Subject: [PATCH 1/3] hypervisor: add bios option in configuration file This patch adds a new option in configuration file this will allow users specify the path to a specific firmware, if a path is not specified qemu uses the default firmware (bios-256k.bin) Fixes #686 Signed-off-by: Julio Montes --- Makefile | 4 ++++ config.go | 21 +++++++++++++++++++++ config/configuration.toml.in | 4 ++++ config_test.go | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/Makefile b/Makefile index 7011f8b7..2b001808 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,7 @@ PKGLIBEXECDIR := $(LIBEXECDIR)/$(CCDIR) KERNELPATH := $(PKGDATADIR)/vmlinuz.container IMAGEPATH := $(PKGDATADIR)/clear-containers.img +FIRMWAREPATH := KERNELPARAMS := @@ -156,6 +157,7 @@ USER_VARS += DESTTARGET USER_VARS += IMAGEPATH USER_VARS += MACHINETYPE USER_VARS += KERNELPATH +USER_VARS += FIRMWAREPATH USER_VARS += KERNELPARAMS USER_VARS += LIBEXECDIR USER_VARS += LOCALSTATEDIR @@ -215,6 +217,7 @@ var version = "$(VERSION)" var defaultHypervisorPath = "$(QEMUPATH)" var defaultImagePath = "$(IMAGEPATH)" var defaultKernelPath = "$(KERNELPATH)" +var defaultFirmwarePath = "$(FIRMWAREPATH)" var defaultShimPath = "$(SHIMPATH)" const defaultKernelParams = "$(KERNELPARAMS)" @@ -285,6 +288,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION -e "s|@CONFIG_IN@|$(CONFIG_IN)|g" \ -e "s|@IMAGEPATH@|$(IMAGEPATH)|g" \ -e "s|@KERNELPATH@|$(KERNELPATH)|g" \ + -e "s|@FIRMWAREPATH@|$(FIRMWAREPATH)|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 ee7ddc42..515d18b0 100644 --- a/config.go +++ b/config.go @@ -76,6 +76,7 @@ type hypervisor struct { Path string `toml:"path"` Kernel string `toml:"kernel"` Image string `toml:"image"` + Firmware string `toml:"firmware"` KernelParams string `toml:"kernel_params"` MachineType string `toml:"machine_type"` DefaultVCPUs int32 `toml:"default_vcpus"` @@ -134,6 +135,19 @@ func (h hypervisor) image() (string, error) { return resolvePath(p) } +func (h hypervisor) firmware() (string, error) { + p := h.Firmware + + if p == "" { + if defaultFirmwarePath == "" { + return "", nil + } + p = defaultFirmwarePath + } + + return resolvePath(p) +} + func (h hypervisor) kernelParams() string { if h.KernelParams == "" { return defaultKernelParams @@ -210,6 +224,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { return vc.HypervisorConfig{}, err } + firmware, err := h.firmware() + if err != nil { + return vc.HypervisorConfig{}, err + } + kernelParams := h.kernelParams() machineType := h.machineType() @@ -217,6 +236,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { HypervisorPath: hypervisor, KernelPath: kernel, ImagePath: image, + FirmwarePath: firmware, KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)), HypervisorMachineType: machineType, DefaultVCPUs: h.defaultVCPUs(), @@ -320,6 +340,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat HypervisorPath: defaultHypervisorPath, KernelPath: defaultKernelPath, ImagePath: defaultImagePath, + FirmwarePath: defaultFirmwarePath, HypervisorMachineType: defaultMachineType, DefaultVCPUs: defaultVCPUCount, DefaultMemSz: defaultMemSize, diff --git a/config/configuration.toml.in b/config/configuration.toml.in index 4f76482f..6ef9fbc3 100644 --- a/config/configuration.toml.in +++ b/config/configuration.toml.in @@ -10,6 +10,10 @@ machine_type = "@MACHINETYPE@" # trouble running pre-2.15 glibc kernel_params = "@KERNELPARAMS@" +# Path to the firmware. +# If you want that qemu uses the default firmware leave this option empty +firmware = "@FIRMWAREPATH@" + # 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 aa086023..d3723f89 100644 --- a/config_test.go +++ b/config_test.go @@ -899,3 +899,23 @@ func TestGetDefaultConfigFile(t *testing.T) { _, err = getDefaultConfigFile() assert.Error(err) } + +func TestDefaultFirmware(t *testing.T) { + assert := assert.New(t) + + f, err := ioutil.TempFile(os.TempDir(), "qboot.bin") + assert.NoError(err) + assert.NoError(f.Close()) + defer os.RemoveAll(f.Name()) + + h := hypervisor{} + defaultFirmwarePath = "" + p, err := h.firmware() + assert.NoError(err) + assert.Empty(p) + + defaultFirmwarePath = f.Name() + p, err = h.firmware() + assert.NoError(err) + assert.NotEmpty(p) +} From 3ee4f1e879d4037947ada01f96a9d7c88ea3882e Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Mon, 9 Oct 2017 12:08:26 -0500 Subject: [PATCH 2/3] hypervisor: add machine_accelerators option in config file machine_accelerators allows user to use specific machine accelerators Signed-off-by: Julio Montes --- Makefile | 4 ++++ config.go | 8 ++++++++ config/configuration.toml.in | 3 +++ config_test.go | 9 +++++++++ 4 files changed, 24 insertions(+) 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..881784d9 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,10 @@ func (h hypervisor) firmware() (string, error) { return resolvePath(p) } +func (h hypervisor) machineAccelerators() string { + return h.MachineAccelerators +} + func (h hypervisor) kernelParams() string { if h.KernelParams == "" { return defaultKernelParams @@ -229,6 +234,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { return vc.HypervisorConfig{}, err } + machineAccelerators := h.machineAccelerators() kernelParams := h.kernelParams() machineType := h.machineType() @@ -237,6 +243,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 +348,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..d223ed70 100644 --- a/config/configuration.toml.in +++ b/config/configuration.toml.in @@ -14,6 +14,9 @@ kernel_params = "@KERNELPARAMS@" # If you want that qemu uses the default firmware leave this option empty firmware = "@FIRMWAREPATH@" +# Machine accelerators +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..b6dd23d6 100644 --- a/config_test.go +++ b/config_test.go @@ -919,3 +919,12 @@ func TestDefaultFirmware(t *testing.T) { assert.NoError(err) assert.NotEmpty(p) } + +func TestDefaultMachineAccelerators(t *testing.T) { + assert := assert.New(t) + const machineAccelerators = "abc,123,rgb" + + h := hypervisor{MachineAccelerators: machineAccelerators} + + assert.Equal(machineAccelerators, h.machineAccelerators()) +} From c18204be5cf2daa3f58d190d48d71489abf5043e Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Mon, 9 Oct 2017 12:11:33 -0500 Subject: [PATCH 3/3] hypervisor: switch to q35 switch from Qemu pc to Qemu q35 fixes #706 Signed-off-by: Julio Montes --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 15e73e09..62e69f20 100644 --- a/Makefile +++ b/Makefile @@ -88,11 +88,11 @@ KERNELPARAMS := ifeq (,$(filter-out centos rhel,$(distro))) QEMUCMD := qemu-system-x86_64 else -QEMUCMD := qemu-lite-system-x86_64 +QEMUCMD := qemu-cc-system-x86_64 endif QEMUPATH := $(QEMUBINDIR)/$(QEMUCMD) -MACHINETYPE := pc +MACHINETYPE := q35 SHIMCMD := cc-shim SHIMPATH := $(PKGLIBEXECDIR)/$(SHIMCMD)