Skip to content

Commit

Permalink
config: Add configuration option for hypervisor block storage driver
Browse files Browse the repository at this point in the history
Block devices can be passed using either virio-scsi or
virtio-block.

Fixes clearcontainers#1036

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Feb 28, 2018
1 parent accaa9d commit 1768dd5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
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
4 changes: 3 additions & 1 deletion 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
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 @@ -218,6 +219,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 @@ -269,6 +282,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 @@ -286,6 +304,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
Mlock: !h.Swap,
Debug: h.Debug,
DisableNestingChecks: h.DisableNestingChecks,
BlockDeviceDriver: blockDriver,
}, nil
}

Expand Down Expand Up @@ -387,6 +406,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

0 comments on commit 1768dd5

Please sign in to comment.