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

Commit

Permalink
hotplug: add default_bridges to configuration file
Browse files Browse the repository at this point in the history
default_bridges allows user specify how many PCI bridges
must be included in the VM, this allow to hot plug until
~150 devices

fixes #831

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Dec 1, 2017
1 parent 7ce8c5a commit 91d5df2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ PROXYPATH := $(PKGLIBEXECDIR)/$(PROXYCMD)
DEFVCPUS := 1
# Default memory size in MiB
DEFMEMSZ := 2048
#Default number of bridges
DEFBRIDGES := 1

DEFDISABLEBLOCK := false
DEFENABLEMEMPREALLOC := false
Expand Down Expand Up @@ -176,6 +178,7 @@ USER_VARS += SHIMPATH
USER_VARS += SYSCONFDIR
USER_VARS += DEFVCPUS
USER_VARS += DEFMEMSZ
USER_VARS += DEFBRIDGES
USER_VARS += DEFDISABLEBLOCK
USER_VARS += DEFENABLEMEMPREALLOC
USER_VARS += DEFENABLEHUGEPAGES
Expand Down Expand Up @@ -229,6 +232,7 @@ const defaultRuntimeRun = "$(PKGRUNDIR)"

const defaultVCPUCount uint32 = $(DEFVCPUS)
const defaultMemSize uint32 = $(DEFMEMSZ) // MiB
const defaultBridgesCount uint32 = $(DEFBRIDGES)
const defaultDisableBlockDeviceUse bool = $(DEFDISABLEBLOCK)
const defaultEnableMemPrealloc bool = $(DEFENABLEMEMPREALLOC)
const defaultEnableHugePages bool = $(DEFENABLEHUGEPAGES)
Expand Down Expand Up @@ -299,6 +303,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@SHIMPATH@|$(SHIMPATH)|g" \
-e "s|@DEFVCPUS@|$(DEFVCPUS)|g" \
-e "s|@DEFMEMSZ@|$(DEFMEMSZ)|g" \
-e "s|@DEFBRIDGES@|$(DEFBRIDGES)|g" \
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
-e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \
-e "s|@DEFENABLEHUGEPAGES@|$(DEFENABLEHUGEPAGES)|g" \
Expand Down
18 changes: 18 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const (

// supported agent component types
hyperstartAgentTableType = "hyperstart"

// the maximum amount of PCI bridges that can be cold plugged in a VM
maxPCIBridges uint32 = 5
)

var (
Expand All @@ -82,6 +85,7 @@ type hypervisor struct {
MachineType string `toml:"machine_type"`
DefaultVCPUs int32 `toml:"default_vcpus"`
DefaultMemSz uint32 `toml:"default_memory"`
DefaultBridges uint32 `toml:"default_bridges"`
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
MemPrealloc bool `toml:"enable_mem_prealloc"`
HugePages bool `toml:"enable_hugepages"`
Expand Down Expand Up @@ -203,6 +207,18 @@ func (h hypervisor) defaultMemSz() uint32 {
return h.DefaultMemSz
}

func (h hypervisor) defaultBridges() uint32 {
if h.DefaultBridges == 0 {
return defaultBridgesCount
}

if h.DefaultBridges > maxPCIBridges {
return maxPCIBridges
}

return h.DefaultBridges
}

func (p proxy) path() string {
if p.Path == "" {
return defaultProxyPath
Expand Down Expand Up @@ -264,6 +280,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
HypervisorMachineType: machineType,
DefaultVCPUs: h.defaultVCPUs(),
DefaultMemSz: h.defaultMemSz(),
DefaultBridges: h.defaultBridges(),
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
MemPrealloc: h.MemPrealloc,
HugePages: h.HugePages,
Expand Down Expand Up @@ -369,6 +386,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
HypervisorMachineType: defaultMachineType,
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
DefaultBridges: defaultBridgesCount,
MemPrealloc: defaultEnableMemPrealloc,
HugePages: defaultEnableHugePages,
Mlock: !defaultEnableSwap,
Expand Down
13 changes: 13 additions & 0 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ machine_accelerators="@MACHINEACCELERATORS@"
# > 255 --> will be set to 255
default_vcpus = -1


# Bridges can be used to hot plug devices.
# Limitations:
# * Currently only pci bridges are supported
# * Until 30 devices per bridge can be hot plugged.
# * Until 5 PCI bridges can be cold plugged per VM.
# This limitation could be a bug in qemu or in the kernel
# Default number of bridges per POD/VM:
# unspecified or 0 --> will be set to @DEFBRIDGES@
# > 1 <= 5 --> will be set to the specified number
# > 5 --> will be set to 5
default_bridges = @DEFBRIDGES@

# Default memory size in MiB for POD/VM.
# If unspecified then it will be set @DEFMEMSZ@ MiB.
#default_memory = @DEFMEMSZ@
Expand Down
23 changes: 21 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
DisableBlockDeviceUse: disableBlockDevice,
Mlock: !defaultEnableSwap,
DefaultBridges: defaultBridgesCount,
Mlock: !defaultEnableSwap,
}

agentConfig := vc.HyperConfig{}
Expand Down Expand Up @@ -506,7 +507,8 @@ func TestMinimalRuntimeConfig(t *testing.T) {
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
DisableBlockDeviceUse: defaultDisableBlockDeviceUse,
Mlock: !defaultEnableSwap,
DefaultBridges: defaultBridgesCount,
Mlock: !defaultEnableSwap,
}

expectedAgentConfig := vc.HyperConfig{}
Expand Down Expand Up @@ -904,6 +906,23 @@ func TestGetDefaultConfigFile(t *testing.T) {
assert.Error(err)
}

func TestDefaultBridges(t *testing.T) {
assert := assert.New(t)

h := hypervisor{DefaultBridges: 0}

bridges := h.defaultBridges()
assert.Equal(defaultBridgesCount, bridges)

h.DefaultBridges = maxPCIBridges + 1
bridges = h.defaultBridges()
assert.Equal(maxPCIBridges, bridges)

h.DefaultBridges = maxPCIBridges
bridges = h.defaultBridges()
assert.Equal(maxPCIBridges, bridges)
}

func TestDefaultFirmware(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit 91d5df2

Please sign in to comment.