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 #1037 from amshinde/config-block-driver
Browse files Browse the repository at this point in the history
Add configuration for hypervisor block storage driver
  • Loading branch information
jodh-intel authored Mar 2, 2018
2 parents 1b1256d + dc15173 commit b1f8bdc
Show file tree
Hide file tree
Showing 22 changed files with 287 additions and 183 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

[[constraint]]
name = "github.com/containers/virtcontainers"
revision = "7d4e2f13a04aa73e0d876cdd7f1cf018d15e50bd"
revision = "494b46c5bfa0c305fa3e2ad9d15ca12af2c148a5"

[prune]
non-go = true
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ DEFBRIDGES := 1
DEFNETWORKMODEL := macvtap

DEFDISABLEBLOCK := false
DEFBLOCKSTORAGEDRIVER := virtio-scsi
DEFENABLEMEMPREALLOC := false
DEFENABLEHUGEPAGES := false
DEFENABLESWAP := false
Expand Down Expand Up @@ -294,6 +295,7 @@ USER_VARS += DEFMEMSZ
USER_VARS += DEFBRIDGES
USER_VARS += DEFNETWORKMODEL
USER_VARS += DEFDISABLEBLOCK
USER_VARS += DEFBLOCKSTORAGEDRIVER
USER_VARS += DEFENABLEMEMPREALLOC
USER_VARS += DEFENABLEHUGEPAGES
USER_VARS += DEFENABLESWAP
Expand Down Expand Up @@ -402,6 +404,7 @@ const defaultMemSize uint32 = $(DEFMEMSZ) // MiB
const defaultBridgesCount uint32 = $(DEFBRIDGES)
const defaultInterNetworkingModel = "$(DEFNETWORKMODEL)"
const defaultDisableBlockDeviceUse bool = $(DEFDISABLEBLOCK)
const defaultBlockDeviceDriver = "$(DEFBLOCKSTORAGEDRIVER)"
const defaultEnableMemPrealloc bool = $(DEFENABLEMEMPREALLOC)
const defaultEnableHugePages bool = $(DEFENABLEHUGEPAGES)
const defaultEnableSwap bool = $(DEFENABLESWAP)
Expand Down Expand Up @@ -489,6 +492,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@DEFBRIDGES@|$(DEFBRIDGES)|g" \
-e "s|@DEFNETWORKMODEL@|$(DEFNETWORKMODEL)|g" \
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
-e "s|@DEFBLOCKSTORAGEDRIVER@|$(DEFBLOCKSTORAGEDRIVER)|g" \
-e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \
-e "s|@DEFENABLEHUGEPAGES@|$(DEFENABLEHUGEPAGES)|g" \
-e "s|@DEFENABLEMSWAP@|$(DEFENABLESWAP)|g" \
Expand Down
18 changes: 10 additions & 8 deletions cc-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.8"
const formatVersion = "1.0.9"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
Expand Down Expand Up @@ -76,10 +76,11 @@ type RuntimeVersionInfo struct {

// HypervisorInfo stores hypervisor details
type HypervisorInfo struct {
MachineType string
Version string
Path string
Debug bool
MachineType string
Version string
Path string
Debug bool
BlockDeviceDriver string
}

// ProxyInfo stores proxy details
Expand Down Expand Up @@ -269,9 +270,10 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
}

return HypervisorInfo{
MachineType: config.HypervisorConfig.HypervisorMachineType,
Version: version,
Path: hypervisorPath,
MachineType: config.HypervisorConfig.HypervisorMachineType,
Version: version,
Path: hypervisorPath,
BlockDeviceDriver: config.HypervisorConfig.BlockDeviceDriver,
}
}

Expand Down
11 changes: 7 additions & 4 deletions cc-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
shimPath := filepath.Join(prefixDir, "cc-shim")
proxyPath := filepath.Join(prefixDir, "cc-proxy")
disableBlock := true
blockStorageDriver := "virtio-scsi"

// override
defaultProxyPath = proxyPath
Expand Down Expand Up @@ -110,7 +111,8 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
shimPath,
testProxyURL,
logPath,
disableBlock)
disableBlock,
blockStorageDriver)

configFile = path.Join(prefixDir, "runtime.toml")
err = createConfig(configFile, runtimeConfig)
Expand Down Expand Up @@ -232,9 +234,10 @@ model name : %s

func getExpectedHypervisor(config oci.RuntimeConfig) HypervisorInfo {
return HypervisorInfo{
Version: testHypervisorVersion,
Path: config.HypervisorConfig.HypervisorPath,
MachineType: config.HypervisorConfig.HypervisorMachineType,
Version: testHypervisorVersion,
Path: config.HypervisorConfig.HypervisorPath,
MachineType: config.HypervisorConfig.HypervisorMachineType,
BlockDeviceDriver: config.HypervisorConfig.BlockDeviceDriver,
}
}

Expand Down
20 changes: 20 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type hypervisor struct {
DefaultMemSz uint32 `toml:"default_memory"`
DefaultBridges uint32 `toml:"default_bridges"`
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
BlockDeviceDriver string `toml:"block_device_driver"`
MemPrealloc bool `toml:"enable_mem_prealloc"`
HugePages bool `toml:"enable_hugepages"`
Swap bool `toml:"enable_swap"`
Expand Down Expand Up @@ -217,6 +218,18 @@ func (h hypervisor) defaultBridges() uint32 {
return h.DefaultBridges
}

func (h hypervisor) blockDeviceDriver() (string, error) {
if h.BlockDeviceDriver == "" {
return defaultBlockDeviceDriver, nil
}

if h.BlockDeviceDriver != vc.VirtioSCSI && h.BlockDeviceDriver != vc.VirtioBlock {
return "", fmt.Errorf("Invalid value %s provided for hypervisor block storage driver, can be either %s or %s", h.BlockDeviceDriver, vc.VirtioSCSI, vc.VirtioBlock)
}

return h.BlockDeviceDriver, nil
}

func (p proxy) path() string {
if p.Path == "" {
return defaultProxyPath
Expand Down Expand Up @@ -268,6 +281,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
kernelParams := h.kernelParams()
machineType := h.machineType()

blockDriver, err := h.blockDeviceDriver()
if err != nil {
return vc.HypervisorConfig{}, err
}

return vc.HypervisorConfig{
HypervisorPath: hypervisor,
KernelPath: kernel,
Expand All @@ -285,6 +303,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
Mlock: !h.Swap,
Debug: h.Debug,
DisableNestingChecks: h.DisableNestingChecks,
BlockDeviceDriver: blockDriver,
}, nil
}

Expand Down Expand Up @@ -386,6 +405,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
Mlock: !defaultEnableSwap,
Debug: defaultEnableDebug,
DisableNestingChecks: defaultDisableNestingChecks,
BlockDeviceDriver: defaultBlockDeviceDriver,
}

err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel)
Expand Down
5 changes: 5 additions & 0 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ default_bridges = @DEFBRIDGES@
# 9pfs is used instead to pass the rootfs.
disable_block_device_use = @DEFDISABLEBLOCK@

# Block storage driver to be used for the hypervisor in case the container
# rootfs is backed by a block device. This is either virtio-scsi or
# virtio-blk.
block_device_driver = "@DEFBLOCKSTORAGEDRIVER@"

# Enable pre allocation of VM RAM, default false
# Enabling this will result in lower container density
# as all of the memory will be allocated and locked
Expand Down
8 changes: 6 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ type testRuntimeConfig struct {
LogPath string
}

func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath string, disableBlock bool) string {
func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath string, disableBlock bool, blockDeviceDriver string) string {
return `
# Clear Containers runtime configuration file
[hypervisor.` + hypervisor + `]
path = "` + hypervisorPath + `"
kernel = "` + kernelPath + `"
block_device_driver = "` + blockDeviceDriver + `"
kernel_params = "` + kernelParams + `"
image = "` + imagePath + `"
machine_type = "` + machineType + `"
Expand Down Expand Up @@ -99,8 +100,9 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
logPath := path.Join(logDir, "runtime.log")
machineType := "machineType"
disableBlockDevice := true
blockDeviceDriver := "virtio-scsi"

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

configPath := path.Join(dir, "runtime.toml")
err = createConfig(configPath, runtimeConfigFileData)
Expand Down Expand Up @@ -135,6 +137,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
DisableBlockDeviceUse: disableBlockDevice,
BlockDeviceDriver: defaultBlockDeviceDriver,
DefaultBridges: defaultBridgesCount,
Mlock: !defaultEnableSwap,
}
Expand Down Expand Up @@ -518,6 +521,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
DisableBlockDeviceUse: defaultDisableBlockDeviceUse,
DefaultBridges: defaultBridgesCount,
Mlock: !defaultEnableSwap,
BlockDeviceDriver: defaultBlockDeviceDriver,
}

expectedAgentConfig := vc.HyperConfig{}
Expand Down
14 changes: 0 additions & 14 deletions vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING

This file was deleted.

1 change: 0 additions & 1 deletion vendor/github.com/containerd/cri-containerd/test/e2e

This file was deleted.

64 changes: 14 additions & 50 deletions vendor/github.com/containers/virtcontainers/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b1f8bdc

Please sign in to comment.