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

Commit

Permalink
Merge pull request #369 from wcwxyz/config-kernel-params
Browse files Browse the repository at this point in the history
config: support kernel parameters
  • Loading branch information
jodh-intel committed Aug 8, 2017
2 parents bcfc581 + 528772f commit 939f7e3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 16 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ PKGLIBEXECDIR := $(LIBEXECDIR)/$(CCDIR)
KERNELPATH := $(PKGDATADIR)/vmlinux.container
IMAGEPATH := $(PKGDATADIR)/clear-containers.img

KERNELPARAMS :=

# The CentOS/RHEL hypervisor binary is not called qemu-lite
ifeq (,$(filter-out centos rhel,$(distro)))
QEMUCMD := qemu-system-x86_64
Expand Down Expand Up @@ -131,6 +133,7 @@ USER_VARS += GLOBALLOGPATH
USER_VARS += IMAGEPATH
USER_VARS += MACHINETYPE
USER_VARS += KERNELPATH
USER_VARS += KERNELPARAMS
USER_VARS += LIBEXECDIR
USER_VARS += LOCALSTATEDIR
USER_VARS += PAUSEBINRELPATH
Expand Down Expand Up @@ -184,6 +187,7 @@ const version = "$(VERSION)"
const defaultHypervisorPath = "$(QEMUPATH)"
const defaultImagePath = "$(IMAGEPATH)"
const defaultKernelPath = "$(KERNELPATH)"
const defaultKernelParams = "$(KERNELPARAMS)"
const defaultMachineType = "$(MACHINETYPE)"
const defaultPauseRootPath = "$(PAUSEROOTPATH)"
const defaultProxyURL = "$(PROXYURL)"
Expand Down Expand Up @@ -235,6 +239,7 @@ $(CONFIG): $(CONFIG_IN) $(GENERATED_FILES)
-e "s|@CONFIG_IN@|$(CONFIG_IN)|g" \
-e "s|@IMAGEPATH@|$(IMAGEPATH)|g" \
-e "s|@KERNELPATH@|$(KERNELPATH)|g" \
-e "s|@KERNELPARAMS@|$(KERNELPARAMS)|g" \
-e "s|@LOCALSTATEDIR@|$(LOCALSTATEDIR)|g" \
-e "s|@PAUSEROOTPATH@|$(PAUSEROOTPATH)|g" \
-e "s|@PKGLIBEXECDIR@|$(PKGLIBEXECDIR)|g" \
Expand Down
20 changes: 15 additions & 5 deletions cc-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"os"
"path/filepath"
"strings"

"github.com/BurntSushi/toml"
vc "github.com/containers/virtcontainers"
Expand All @@ -30,7 +31,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.1"
const formatVersion = "1.0.2"

// defaultOutputFile is the default output file to write the gathered
// information to.
Expand All @@ -48,6 +49,12 @@ type PathInfo struct {
Resolved string
}

// KernelInfo stores kernel details
type KernelInfo struct {
Location PathInfo
Parameters string
}

// CPUInfo stores host CPU details
type CPUInfo struct {
Vendor string
Expand Down Expand Up @@ -124,7 +131,7 @@ type EnvInfo struct {
Runtime RuntimeInfo
Hypervisor HypervisorInfo
Image PathInfo
Kernel PathInfo
Kernel KernelInfo
Proxy ProxyInfo
Shim ShimInfo
Agent AgentInfo
Expand Down Expand Up @@ -325,9 +332,12 @@ func getEnvInfo(configFile, logfilePath string, config oci.RuntimeConfig) (env E
Resolved: resolvedHypervisor.ImagePath,
}

kernel := PathInfo{
Path: config.HypervisorConfig.KernelPath,
Resolved: resolvedHypervisor.KernelPath,
kernel := KernelInfo{
Location: PathInfo{
Path: config.HypervisorConfig.KernelPath,
Resolved: resolvedHypervisor.KernelPath,
},
Parameters: strings.Join(vc.SerializeParams(config.HypervisorConfig.KernelParams, "="), " "),
}

env = EnvInfo{
Expand Down
24 changes: 16 additions & 8 deletions cc-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
hypervisorPath := filepath.Join(prefixDir, "hypervisor")
kernelPath := filepath.Join(prefixDir, "kernel")
imagePath := filepath.Join(prefixDir, "image")
kernelParams := "foo=bar xyz"
machineType := "machineType"
shimPath := filepath.Join(prefixDir, "cc-shim")
proxyPath := filepath.Join(prefixDir, "cc-proxy")
Expand Down Expand Up @@ -103,6 +104,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
hypervisorPath,
kernelPath,
imagePath,
kernelParams,
machineType,
shimPath,
agentPauseRoot,
Expand Down Expand Up @@ -261,10 +263,13 @@ func getExpectedImage(config oci.RuntimeConfig) PathInfo {
}
}

func getExpectedKernel(config oci.RuntimeConfig) PathInfo {
return PathInfo{
Path: config.HypervisorConfig.KernelPath,
Resolved: config.HypervisorConfig.KernelPath,
func getExpectedKernel(config oci.RuntimeConfig) KernelInfo {
return KernelInfo{
Location: PathInfo{
Path: config.HypervisorConfig.KernelPath,
Resolved: config.HypervisorConfig.KernelPath,
},
Parameters: strings.Join(vc.SerializeParams(config.HypervisorConfig.KernelParams, "="), " "),
}
}

Expand Down Expand Up @@ -556,7 +561,7 @@ func TestCCEnvGetEnvInfoNoKernel(t *testing.T) {
expected, err := getExpectedSettings(config, tmpdir, configFile, logFile)
assert.NoError(t, err)

err = os.Remove(expected.Kernel.Resolved)
err = os.Remove(expected.Kernel.Location.Resolved)
assert.NoError(t, err)

_, err = getEnvInfo(configFile, logFile, config)
Expand Down Expand Up @@ -910,9 +915,12 @@ func testCCEnvShowSettings(t *testing.T, tmpdir string, tmpfile *os.File) error
Resolved: "/resolved/image/path",
}

ccKernel := PathInfo{
Path: "/kernel/path",
Resolved: "/resolved/kernel/path",
ccKernel := KernelInfo{
Location: PathInfo{
Path: "/kernel/path",
Resolved: "/resolved/kernel/path",
},
Parameters: "foo=bar xyz",
}

ccProxy := ProxyInfo{
Expand Down
13 changes: 12 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
goruntime "runtime"
"strings"

"github.com/BurntSushi/toml"
vc "github.com/containers/virtcontainers"
Expand Down Expand Up @@ -76,6 +77,7 @@ type hypervisor struct {
Path string `toml:"path"`
Kernel string `toml:"kernel"`
Image string `toml:"image"`
KernelParams string `toml:"kernel_params"`
MachineType string `toml:"machine_type"`
DefaultVCPUs int32 `toml:"default_vcpus"`
DefaultMemSz uint32 `toml:"default_memory"`
Expand Down Expand Up @@ -122,6 +124,14 @@ func (h hypervisor) image() string {
return h.Image
}

func (h hypervisor) kernelParams() string {
if h.KernelParams == "" {
return defaultKernelParams
}

return h.KernelParams
}

func (h hypervisor) machineType() string {
if h.MachineType == "" {
return defaultMachineType
Expand Down Expand Up @@ -180,6 +190,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
hypervisor := h.path()
kernel := h.kernel()
image := h.image()
kernelParams := h.kernelParams()
machineType := h.machineType()

for _, file := range []string{hypervisor, kernel, image} {
Expand All @@ -188,11 +199,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
fmt.Errorf("File does not exist: %v", file)
}
}

return vc.HypervisorConfig{
HypervisorPath: hypervisor,
KernelPath: kernel,
ImagePath: image,
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
HypervisorMachineType: machineType,
DefaultVCPUs: h.defaultVCPUs(),
DefaultMemSz: h.defaultMemSz(),
Expand Down
4 changes: 4 additions & 0 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ path = "@QEMUPATH@"
kernel = "@KERNELPATH@"
image = "@IMAGEPATH@"
machine_type = "@MACHINETYPE@"
# Optional space-separated list of options to pass to the guest kernel.
# For example, use `kernel_params = "vsyscall=emulate"` if you are having
# trouble running pre-2.15 glibc
kernel_params = "@KERNELPARAMS@"
# 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
12 changes: 10 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ type testRuntimeConfig struct {
LogPath string
}

func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, machineType, shimPath, agentPauseRootPath, proxyURL, logPath string, disableBlock bool) string {
func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, agentPauseRootPath, proxyURL, logPath string, disableBlock bool) string {
return `
# Clear Containers runtime configuration file
[hypervisor.` + hypervisor + `]
path = "` + hypervisorPath + `"
kernel = "` + kernelPath + `"
kernel_params = "` + kernelParams + `"
image = "` + imagePath + `"
machine_type = "` + machineType + `"
default_vcpus = ` + strconv.FormatUint(uint64(defaultVCPUCount), 10) + `
Expand Down Expand Up @@ -94,6 +95,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf

hypervisorPath := path.Join(dir, "hypervisor")
kernelPath := path.Join(dir, "kernel")
kernelParams := "foo=bar xyz"
imagePath := path.Join(dir, "image")
shimPath := path.Join(dir, "shim")
agentPauseRootPath := path.Join(dir, "agentPauseRoot")
Expand All @@ -104,7 +106,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
machineType := "machineType"
disableBlockDevice := true

runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, machineType, shimPath, agentPauseRootPath, proxyURL, logPath, disableBlockDevice)
runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, agentPauseRootPath, proxyURL, logPath, disableBlockDevice)

configPath := path.Join(dir, "runtime.toml")
err = createConfig(configPath, runtimeConfigFileData)
Expand Down Expand Up @@ -139,6 +141,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
HypervisorPath: hypervisorPath,
KernelPath: kernelPath,
ImagePath: imagePath,
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
HypervisorMachineType: machineType,
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
Expand Down Expand Up @@ -798,6 +801,7 @@ func TestHypervisorDefaults(t *testing.T) {
assert.Equal(t, h.path(), defaultHypervisorPath, "default hypervisor path wrong")
assert.Equal(t, h.kernel(), defaultKernelPath, "default hypervisor kernel wrong")
assert.Equal(t, h.image(), defaultImagePath, "default hypervisor image wrong")
assert.Equal(t, h.kernelParams(), defaultKernelParams, "default hypervisor image wrong")
assert.Equal(t, h.machineType(), defaultMachineType, "default hypervisor machine type wrong")
assert.Equal(t, h.defaultVCPUs(), defaultVCPUCount, "default vCPU number is wrong")
assert.Equal(t, h.defaultMemSz(), defaultMemSize, "default memory size is wrong")
Expand All @@ -810,6 +814,10 @@ func TestHypervisorDefaults(t *testing.T) {
h.Kernel = kernel
assert.Equal(t, h.kernel(), kernel, "custom hypervisor kernel wrong")

kernelParams := "foo=bar xyz"
h.KernelParams = kernelParams
assert.Equal(t, h.kernelParams(), kernelParams, "custom hypervisor kernel parameterms wrong")

image := "foo"
h.Image = image
assert.Equal(t, h.image(), image, "custom hypervisor image wrong")
Expand Down

0 comments on commit 939f7e3

Please sign in to comment.