mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 18:47:03 +00:00
hypervisor: rename DefaultVCPUs and DefaultMemSz
Now that we only use hypervisor config to set them, they are not overridden by other configs. So drop the default prefix. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
7af8e6c641
commit
a1537a5271
@ -80,9 +80,9 @@ type hypervisor struct {
|
|||||||
KernelParams string `toml:"kernel_params"`
|
KernelParams string `toml:"kernel_params"`
|
||||||
MachineType string `toml:"machine_type"`
|
MachineType string `toml:"machine_type"`
|
||||||
BlockDeviceDriver string `toml:"block_device_driver"`
|
BlockDeviceDriver string `toml:"block_device_driver"`
|
||||||
DefaultVCPUs int32 `toml:"default_vcpus"`
|
NumVCPUs int32 `toml:"default_vcpus"`
|
||||||
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
|
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
|
||||||
DefaultMemSz uint32 `toml:"default_memory"`
|
MemorySize uint32 `toml:"default_memory"`
|
||||||
DefaultBridges uint32 `toml:"default_bridges"`
|
DefaultBridges uint32 `toml:"default_bridges"`
|
||||||
Msize9p uint32 `toml:"msize_9p"`
|
Msize9p uint32 `toml:"msize_9p"`
|
||||||
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
|
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
|
||||||
@ -202,14 +202,14 @@ func (h hypervisor) machineType() string {
|
|||||||
func (h hypervisor) defaultVCPUs() uint32 {
|
func (h hypervisor) defaultVCPUs() uint32 {
|
||||||
numCPUs := goruntime.NumCPU()
|
numCPUs := goruntime.NumCPU()
|
||||||
|
|
||||||
if h.DefaultVCPUs < 0 || h.DefaultVCPUs > int32(numCPUs) {
|
if h.NumVCPUs < 0 || h.NumVCPUs > int32(numCPUs) {
|
||||||
return uint32(numCPUs)
|
return uint32(numCPUs)
|
||||||
}
|
}
|
||||||
if h.DefaultVCPUs == 0 { // or unspecified
|
if h.NumVCPUs == 0 { // or unspecified
|
||||||
return defaultVCPUCount
|
return defaultVCPUCount
|
||||||
}
|
}
|
||||||
|
|
||||||
return uint32(h.DefaultVCPUs)
|
return uint32(h.NumVCPUs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h hypervisor) defaultMaxVCPUs() uint32 {
|
func (h hypervisor) defaultMaxVCPUs() uint32 {
|
||||||
@ -232,11 +232,11 @@ func (h hypervisor) defaultMaxVCPUs() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h hypervisor) defaultMemSz() uint32 {
|
func (h hypervisor) defaultMemSz() uint32 {
|
||||||
if h.DefaultMemSz < 8 {
|
if h.MemorySize < 8 {
|
||||||
return defaultMemSize // MiB
|
return defaultMemSize // MiB
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.DefaultMemSz
|
return h.MemorySize
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h hypervisor) defaultBridges() uint32 {
|
func (h hypervisor) defaultBridges() uint32 {
|
||||||
@ -360,9 +360,9 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
|||||||
MachineAccelerators: machineAccelerators,
|
MachineAccelerators: machineAccelerators,
|
||||||
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
||||||
HypervisorMachineType: machineType,
|
HypervisorMachineType: machineType,
|
||||||
DefaultVCPUs: h.defaultVCPUs(),
|
NumVCPUs: h.defaultVCPUs(),
|
||||||
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
|
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
|
||||||
DefaultMemSz: h.defaultMemSz(),
|
MemorySize: h.defaultMemSz(),
|
||||||
DefaultBridges: h.defaultBridges(),
|
DefaultBridges: h.defaultBridges(),
|
||||||
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
|
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
|
||||||
MemPrealloc: h.MemPrealloc,
|
MemPrealloc: h.MemPrealloc,
|
||||||
@ -477,9 +477,9 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
|
|||||||
FirmwarePath: defaultFirmwarePath,
|
FirmwarePath: defaultFirmwarePath,
|
||||||
MachineAccelerators: defaultMachineAccelerators,
|
MachineAccelerators: defaultMachineAccelerators,
|
||||||
HypervisorMachineType: defaultMachineType,
|
HypervisorMachineType: defaultMachineType,
|
||||||
DefaultVCPUs: defaultVCPUCount,
|
NumVCPUs: defaultVCPUCount,
|
||||||
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
||||||
DefaultMemSz: defaultMemSize,
|
MemorySize: defaultMemSize,
|
||||||
DefaultBridges: defaultBridgesCount,
|
DefaultBridges: defaultBridgesCount,
|
||||||
MemPrealloc: defaultEnableMemPrealloc,
|
MemPrealloc: defaultEnableMemPrealloc,
|
||||||
HugePages: defaultEnableHugePages,
|
HugePages: defaultEnableHugePages,
|
||||||
|
@ -132,9 +132,9 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
|||||||
ImagePath: imagePath,
|
ImagePath: imagePath,
|
||||||
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
||||||
HypervisorMachineType: machineType,
|
HypervisorMachineType: machineType,
|
||||||
DefaultVCPUs: defaultVCPUCount,
|
NumVCPUs: defaultVCPUCount,
|
||||||
DefaultMaxVCPUs: uint32(goruntime.NumCPU()),
|
DefaultMaxVCPUs: uint32(goruntime.NumCPU()),
|
||||||
DefaultMemSz: defaultMemSize,
|
MemorySize: defaultMemSize,
|
||||||
DisableBlockDeviceUse: disableBlockDevice,
|
DisableBlockDeviceUse: disableBlockDevice,
|
||||||
BlockDeviceDriver: defaultBlockDeviceDriver,
|
BlockDeviceDriver: defaultBlockDeviceDriver,
|
||||||
DefaultBridges: defaultBridgesCount,
|
DefaultBridges: defaultBridgesCount,
|
||||||
@ -521,9 +521,9 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
|||||||
ImagePath: defaultImagePath,
|
ImagePath: defaultImagePath,
|
||||||
InitrdPath: defaultInitrdPath,
|
InitrdPath: defaultInitrdPath,
|
||||||
HypervisorMachineType: defaultMachineType,
|
HypervisorMachineType: defaultMachineType,
|
||||||
DefaultVCPUs: defaultVCPUCount,
|
NumVCPUs: defaultVCPUCount,
|
||||||
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
||||||
DefaultMemSz: defaultMemSize,
|
MemorySize: defaultMemSize,
|
||||||
DisableBlockDeviceUse: defaultDisableBlockDeviceUse,
|
DisableBlockDeviceUse: defaultDisableBlockDeviceUse,
|
||||||
DefaultBridges: defaultBridgesCount,
|
DefaultBridges: defaultBridgesCount,
|
||||||
Mlock: !defaultEnableSwap,
|
Mlock: !defaultEnableSwap,
|
||||||
@ -790,13 +790,13 @@ func TestHypervisorDefaults(t *testing.T) {
|
|||||||
assert.Equal(h.machineType(), machineType, "custom hypervisor machine type wrong")
|
assert.Equal(h.machineType(), machineType, "custom hypervisor machine type wrong")
|
||||||
|
|
||||||
// auto inferring
|
// auto inferring
|
||||||
h.DefaultVCPUs = -1
|
h.NumVCPUs = -1
|
||||||
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")
|
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")
|
||||||
|
|
||||||
h.DefaultVCPUs = 2
|
h.NumVCPUs = 2
|
||||||
assert.Equal(h.defaultVCPUs(), uint32(2), "default vCPU number is wrong")
|
assert.Equal(h.defaultVCPUs(), uint32(2), "default vCPU number is wrong")
|
||||||
|
|
||||||
h.DefaultVCPUs = int32(numCPUs) + 1
|
h.NumVCPUs = int32(numCPUs) + 1
|
||||||
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")
|
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")
|
||||||
|
|
||||||
h.DefaultMaxVCPUs = 2
|
h.DefaultMaxVCPUs = 2
|
||||||
@ -809,7 +809,7 @@ func TestHypervisorDefaults(t *testing.T) {
|
|||||||
h.DefaultMaxVCPUs = uint32(maxvcpus) + 1
|
h.DefaultMaxVCPUs = uint32(maxvcpus) + 1
|
||||||
assert.Equal(h.defaultMaxVCPUs(), uint32(numCPUs), "default max vCPU number is wrong")
|
assert.Equal(h.defaultMaxVCPUs(), uint32(numCPUs), "default max vCPU number is wrong")
|
||||||
|
|
||||||
h.DefaultMemSz = 1024
|
h.MemorySize = 1024
|
||||||
assert.Equal(h.defaultMemSz(), uint32(1024), "default memory size is wrong")
|
assert.Equal(h.defaultMemSz(), uint32(1024), "default memory size is wrong")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1207,12 +1207,12 @@ func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
|
|||||||
tomlConf := tomlConfig{
|
tomlConf := tomlConfig{
|
||||||
Hypervisor: map[string]hypervisor{
|
Hypervisor: map[string]hypervisor{
|
||||||
qemuHypervisorTableType: {
|
qemuHypervisorTableType: {
|
||||||
DefaultVCPUs: int32(vcpus),
|
NumVCPUs: int32(vcpus),
|
||||||
DefaultMemSz: uint32(mem),
|
MemorySize: uint32(mem),
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Kernel: "/",
|
Kernel: "/",
|
||||||
Image: "/",
|
Image: "/",
|
||||||
Firmware: "/",
|
Firmware: "/",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1220,7 +1220,7 @@ func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
|
|||||||
err := updateRuntimeConfig("", tomlConf, &config)
|
err := updateRuntimeConfig("", tomlConf, &config)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
assert.Equal(expectedVMConfig, config.HypervisorConfig.DefaultMemSz)
|
assert.Equal(expectedVMConfig, config.HypervisorConfig.MemorySize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateRuntimeConfigurationFactoryConfig(t *testing.T) {
|
func TestUpdateRuntimeConfigurationFactoryConfig(t *testing.T) {
|
||||||
|
@ -858,8 +858,8 @@ func TestStatusSandboxSuccessfulStateReady(t *testing.T) {
|
|||||||
KernelPath: filepath.Join(testDir, testKernel),
|
KernelPath: filepath.Join(testDir, testKernel),
|
||||||
ImagePath: filepath.Join(testDir, testImage),
|
ImagePath: filepath.Join(testDir, testImage),
|
||||||
HypervisorPath: filepath.Join(testDir, testHypervisor),
|
HypervisorPath: filepath.Join(testDir, testHypervisor),
|
||||||
DefaultVCPUs: defaultVCPUs,
|
NumVCPUs: defaultVCPUs,
|
||||||
DefaultMemSz: defaultMemSzMiB,
|
MemorySize: defaultMemSzMiB,
|
||||||
DefaultBridges: defaultBridges,
|
DefaultBridges: defaultBridges,
|
||||||
BlockDeviceDriver: defaultBlockDriver,
|
BlockDeviceDriver: defaultBlockDriver,
|
||||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||||
@ -916,8 +916,8 @@ func TestStatusSandboxSuccessfulStateRunning(t *testing.T) {
|
|||||||
KernelPath: filepath.Join(testDir, testKernel),
|
KernelPath: filepath.Join(testDir, testKernel),
|
||||||
ImagePath: filepath.Join(testDir, testImage),
|
ImagePath: filepath.Join(testDir, testImage),
|
||||||
HypervisorPath: filepath.Join(testDir, testHypervisor),
|
HypervisorPath: filepath.Join(testDir, testHypervisor),
|
||||||
DefaultVCPUs: defaultVCPUs,
|
NumVCPUs: defaultVCPUs,
|
||||||
DefaultMemSz: defaultMemSzMiB,
|
MemorySize: defaultMemSzMiB,
|
||||||
DefaultBridges: defaultBridges,
|
DefaultBridges: defaultBridges,
|
||||||
BlockDeviceDriver: defaultBlockDriver,
|
BlockDeviceDriver: defaultBlockDriver,
|
||||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||||
|
@ -154,13 +154,13 @@ type HypervisorConfig struct {
|
|||||||
// enable debug output where available.
|
// enable debug output where available.
|
||||||
Debug bool
|
Debug bool
|
||||||
|
|
||||||
// DefaultVCPUs specifies default number of vCPUs for the VM.
|
// NumVCPUs specifies default number of vCPUs for the VM.
|
||||||
// Sandbox configuration VMConfig.VCPUs overwrites this.
|
// Sandbox configuration VMConfig.VCPUs overwrites this.
|
||||||
DefaultVCPUs uint32
|
NumVCPUs uint32
|
||||||
|
|
||||||
// DefaultMem specifies default memory size in MiB for the VM.
|
// DefaultMem specifies default memory size in MiB for the VM.
|
||||||
// Sandbox configuration VMConfig.Memory overwrites this.
|
// Sandbox configuration VMConfig.Memory overwrites this.
|
||||||
DefaultMemSz uint32
|
MemorySize uint32
|
||||||
|
|
||||||
// DefaultBridges specifies default number of bridges for the VM.
|
// DefaultBridges specifies default number of bridges for the VM.
|
||||||
// Bridges can be used to hot plug devices
|
// Bridges can be used to hot plug devices
|
||||||
|
@ -43,7 +43,7 @@ func Example_createAndStartSandbox() {
|
|||||||
KernelPath: "/usr/share/kata-containers/vmlinux.container",
|
KernelPath: "/usr/share/kata-containers/vmlinux.container",
|
||||||
ImagePath: "/usr/share/kata-containers/kata-containers.img",
|
ImagePath: "/usr/share/kata-containers/kata-containers.img",
|
||||||
HypervisorPath: "/usr/bin/qemu-system-x86_64",
|
HypervisorPath: "/usr/bin/qemu-system-x86_64",
|
||||||
DefaultMemSz: 1024,
|
MemorySize: 1024,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use hyperstart default values for the agent.
|
// Use hyperstart default values for the agent.
|
||||||
|
@ -94,8 +94,8 @@ func (f *factory) log() *logrus.Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resetHypervisorConfig(config *vc.HypervisorConfig) {
|
func resetHypervisorConfig(config *vc.HypervisorConfig) {
|
||||||
config.DefaultVCPUs = 0
|
config.NumVCPUs = 0
|
||||||
config.DefaultMemSz = 0
|
config.MemorySize = 0
|
||||||
config.BootToBeTemplate = false
|
config.BootToBeTemplate = false
|
||||||
config.BootFromTemplate = false
|
config.BootFromTemplate = false
|
||||||
config.MemoryPath = ""
|
config.MemoryPath = ""
|
||||||
@ -175,16 +175,16 @@ func (f *factory) GetVM(ctx context.Context, config vc.VMConfig) (*vc.VM, error)
|
|||||||
|
|
||||||
online := false
|
online := false
|
||||||
baseConfig := f.base.Config().HypervisorConfig
|
baseConfig := f.base.Config().HypervisorConfig
|
||||||
if baseConfig.DefaultVCPUs < hypervisorConfig.DefaultVCPUs {
|
if baseConfig.NumVCPUs < hypervisorConfig.NumVCPUs {
|
||||||
err = vm.AddCPUs(hypervisorConfig.DefaultVCPUs - baseConfig.DefaultVCPUs)
|
err = vm.AddCPUs(hypervisorConfig.NumVCPUs - baseConfig.NumVCPUs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
online = true
|
online = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if baseConfig.DefaultMemSz < hypervisorConfig.DefaultMemSz {
|
if baseConfig.MemorySize < hypervisorConfig.MemorySize {
|
||||||
err = vm.AddMemory(hypervisorConfig.DefaultMemSz - baseConfig.DefaultMemSz)
|
err = vm.AddMemory(hypervisorConfig.MemorySize - baseConfig.MemorySize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -218,12 +218,12 @@ func TestFactoryGetVM(t *testing.T) {
|
|||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
// CPU hotplug
|
// CPU hotplug
|
||||||
vmConfig.HypervisorConfig.DefaultVCPUs++
|
vmConfig.HypervisorConfig.NumVCPUs++
|
||||||
_, err = f.GetVM(ctx, vmConfig)
|
_, err = f.GetVM(ctx, vmConfig)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
// Memory hotplug
|
// Memory hotplug
|
||||||
vmConfig.HypervisorConfig.DefaultMemSz += 128
|
vmConfig.HypervisorConfig.MemorySize += 128
|
||||||
_, err = f.GetVM(ctx, vmConfig)
|
_, err = f.GetVM(ctx, vmConfig)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ func (t *template) prepareTemplateFiles() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
flags := uintptr(syscall.MS_NOSUID | syscall.MS_NODEV)
|
flags := uintptr(syscall.MS_NOSUID | syscall.MS_NODEV)
|
||||||
opts := fmt.Sprintf("size=%dM", t.config.HypervisorConfig.DefaultMemSz+8)
|
opts := fmt.Sprintf("size=%dM", t.config.HypervisorConfig.MemorySize+8)
|
||||||
if err = syscall.Mount("tmpfs", t.statePath, "tmpfs", flags, opts); err != nil {
|
if err = syscall.Mount("tmpfs", t.statePath, "tmpfs", flags, opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ func buildSandboxConfig(context *cli.Context) (vc.SandboxConfig, error) {
|
|||||||
KernelPath: kernelPath,
|
KernelPath: kernelPath,
|
||||||
ImagePath: "/usr/share/clear-containers/clear-containers.img",
|
ImagePath: "/usr/share/clear-containers/clear-containers.img",
|
||||||
HypervisorMachineType: machineType,
|
HypervisorMachineType: machineType,
|
||||||
DefaultMemSz: uint32(vmMemory),
|
MemorySize: uint32(vmMemory),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := buildKernelParams(&hypervisorConfig); err != nil {
|
if err := buildKernelParams(&hypervisorConfig); err != nil {
|
||||||
|
@ -175,14 +175,14 @@ type HypervisorConfig struct {
|
|||||||
// it will be used for the sandbox's kernel path instead of KernelPath.
|
// it will be used for the sandbox's kernel path instead of KernelPath.
|
||||||
customAssets map[assetType]*asset
|
customAssets map[assetType]*asset
|
||||||
|
|
||||||
// DefaultVCPUs specifies default number of vCPUs for the VM.
|
// NumVCPUs specifies default number of vCPUs for the VM.
|
||||||
DefaultVCPUs uint32
|
NumVCPUs uint32
|
||||||
|
|
||||||
//DefaultMaxVCPUs specifies the maximum number of vCPUs for the VM.
|
//DefaultMaxVCPUs specifies the maximum number of vCPUs for the VM.
|
||||||
DefaultMaxVCPUs uint32
|
DefaultMaxVCPUs uint32
|
||||||
|
|
||||||
// DefaultMem specifies default memory size in MiB for the VM.
|
// DefaultMem specifies default memory size in MiB for the VM.
|
||||||
DefaultMemSz uint32
|
MemorySize uint32
|
||||||
|
|
||||||
// DefaultBridges specifies default number of bridges for the VM.
|
// DefaultBridges specifies default number of bridges for the VM.
|
||||||
// Bridges can be used to hot plug devices
|
// Bridges can be used to hot plug devices
|
||||||
@ -273,12 +273,12 @@ func (conf *HypervisorConfig) valid() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.DefaultVCPUs == 0 {
|
if conf.NumVCPUs == 0 {
|
||||||
conf.DefaultVCPUs = defaultVCPUs
|
conf.NumVCPUs = defaultVCPUs
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.DefaultMemSz == 0 {
|
if conf.MemorySize == 0 {
|
||||||
conf.DefaultMemSz = defaultMemSzMiB
|
conf.MemorySize = defaultMemSzMiB
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.DefaultBridges == 0 {
|
if conf.DefaultBridges == 0 {
|
||||||
|
@ -193,8 +193,8 @@ func TestHypervisorConfigDefaults(t *testing.T) {
|
|||||||
KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel),
|
KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel),
|
||||||
ImagePath: fmt.Sprintf("%s/%s", testDir, testImage),
|
ImagePath: fmt.Sprintf("%s/%s", testDir, testImage),
|
||||||
HypervisorPath: "",
|
HypervisorPath: "",
|
||||||
DefaultVCPUs: defaultVCPUs,
|
NumVCPUs: defaultVCPUs,
|
||||||
DefaultMemSz: defaultMemSzMiB,
|
MemorySize: defaultMemSzMiB,
|
||||||
DefaultBridges: defaultBridges,
|
DefaultBridges: defaultBridges,
|
||||||
BlockDeviceDriver: defaultBlockDriver,
|
BlockDeviceDriver: defaultBlockDriver,
|
||||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||||
|
@ -417,7 +417,7 @@ func updateVMConfig(ocispec CompatOCISpec, config *RuntimeConfig) error {
|
|||||||
}
|
}
|
||||||
// Use some math magic to round up to the nearest Mb.
|
// Use some math magic to round up to the nearest Mb.
|
||||||
// This has the side effect that we can never have <1Mb assigned.
|
// This has the side effect that we can never have <1Mb assigned.
|
||||||
config.HypervisorConfig.DefaultMemSz = uint32((memBytes + (1024*1024 - 1)) / (1024 * 1024))
|
config.HypervisorConfig.MemorySize = uint32((memBytes + (1024*1024 - 1)) / (1024 * 1024))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -258,7 +258,7 @@ func TestUpdateVmConfig(t *testing.T) {
|
|||||||
|
|
||||||
config := RuntimeConfig{
|
config := RuntimeConfig{
|
||||||
HypervisorConfig: vc.HypervisorConfig{
|
HypervisorConfig: vc.HypervisorConfig{
|
||||||
DefaultMemSz: 2048,
|
MemorySize: 2048,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ func TestUpdateVmConfig(t *testing.T) {
|
|||||||
|
|
||||||
err := updateVMConfig(ocispec, &config)
|
err := updateVMConfig(ocispec, &config)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.Equal(config.HypervisorConfig.DefaultMemSz, expectedMem)
|
assert.Equal(config.HypervisorConfig.MemorySize, expectedMem)
|
||||||
|
|
||||||
limitBytes = -128 * 1024 * 1024
|
limitBytes = -128 * 1024 * 1024
|
||||||
ocispec.Linux.Resources.Memory.Limit = &limitBytes
|
ocispec.Linux.Resources.Memory.Limit = &limitBytes
|
||||||
@ -297,7 +297,7 @@ func TestUpdateVmConfig(t *testing.T) {
|
|||||||
ocispec.Linux.Resources.Memory = &specs.LinuxMemory{Limit: &limitBytes}
|
ocispec.Linux.Resources.Memory = &specs.LinuxMemory{Limit: &limitBytes}
|
||||||
err = updateVMConfig(ocispec, &config)
|
err = updateVMConfig(ocispec, &config)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.NotEqual(config.HypervisorConfig.DefaultMemSz, expectedMem)
|
assert.NotEqual(config.HypervisorConfig.MemorySize, expectedMem)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStatusToOCIStateSuccessful(t *testing.T, cStatus vc.ContainerStatus, expected specs.State) {
|
func testStatusToOCIStateSuccessful(t *testing.T, cStatus vc.ContainerStatus, expected specs.State) {
|
||||||
|
@ -248,7 +248,7 @@ func (q *qemu) init(ctx context.Context, id string, hypervisorConfig *Hypervisor
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) cpuTopology() govmmQemu.SMP {
|
func (q *qemu) cpuTopology() govmmQemu.SMP {
|
||||||
return q.arch.cpuTopology(q.config.DefaultVCPUs, q.config.DefaultMaxVCPUs)
|
return q.arch.cpuTopology(q.config.NumVCPUs, q.config.DefaultMaxVCPUs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) hostMemMB() (uint64, error) {
|
func (q *qemu) hostMemMB() (uint64, error) {
|
||||||
@ -269,7 +269,7 @@ func (q *qemu) memoryTopology() (govmmQemu.Memory, error) {
|
|||||||
return govmmQemu.Memory{}, err
|
return govmmQemu.Memory{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
memMb := uint64(q.config.DefaultMemSz)
|
memMb := uint64(q.config.MemorySize)
|
||||||
|
|
||||||
return q.arch.memoryTopology(memMb, hostMemMb), nil
|
return q.arch.memoryTopology(memMb, hostMemMb), nil
|
||||||
}
|
}
|
||||||
@ -1033,12 +1033,12 @@ func (q *qemu) hotplugMemory(memDev *memoryDevice, op operation) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculate current memory
|
// calculate current memory
|
||||||
currentMemory := int(q.config.DefaultMemSz) + q.state.HotpluggedMemory
|
currentMemory := int(q.config.MemorySize) + q.state.HotpluggedMemory
|
||||||
|
|
||||||
// Don't exceed the maximum amount of memory
|
// Don't exceed the maximum amount of memory
|
||||||
if currentMemory+memDev.sizeMB > int(maxMem) {
|
if currentMemory+memDev.sizeMB > int(maxMem) {
|
||||||
return fmt.Errorf("Unable to hotplug %d MiB memory, the SB has %d MiB and the maximum amount is %d MiB",
|
return fmt.Errorf("Unable to hotplug %d MiB memory, the SB has %d MiB and the maximum amount is %d MiB",
|
||||||
memDev.sizeMB, currentMemory, q.config.DefaultMemSz)
|
memDev.sizeMB, currentMemory, q.config.MemorySize)
|
||||||
}
|
}
|
||||||
|
|
||||||
return q.hotplugAddMemory(memDev)
|
return q.hotplugAddMemory(memDev)
|
||||||
|
@ -24,8 +24,8 @@ func newQemuConfig() HypervisorConfig {
|
|||||||
ImagePath: testQemuImagePath,
|
ImagePath: testQemuImagePath,
|
||||||
InitrdPath: testQemuInitrdPath,
|
InitrdPath: testQemuInitrdPath,
|
||||||
HypervisorPath: testQemuPath,
|
HypervisorPath: testQemuPath,
|
||||||
DefaultVCPUs: defaultVCPUs,
|
NumVCPUs: defaultVCPUs,
|
||||||
DefaultMemSz: defaultMemSzMiB,
|
MemorySize: defaultMemSzMiB,
|
||||||
DefaultBridges: defaultBridges,
|
DefaultBridges: defaultBridges,
|
||||||
BlockDeviceDriver: defaultBlockDriver,
|
BlockDeviceDriver: defaultBlockDriver,
|
||||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||||
@ -129,7 +129,7 @@ func TestQemuCPUTopology(t *testing.T) {
|
|||||||
q := &qemu{
|
q := &qemu{
|
||||||
arch: &qemuArchBase{},
|
arch: &qemuArchBase{},
|
||||||
config: HypervisorConfig{
|
config: HypervisorConfig{
|
||||||
DefaultVCPUs: uint32(vcpus),
|
NumVCPUs: uint32(vcpus),
|
||||||
DefaultMaxVCPUs: uint32(vcpus),
|
DefaultMaxVCPUs: uint32(vcpus),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -150,10 +150,13 @@ func TestQemuCPUTopology(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQemuMemoryTopology(t *testing.T) {
|
func TestQemuMemoryTopology(t *testing.T) {
|
||||||
mem := 1000
|
mem := uint32(1000)
|
||||||
|
|
||||||
q := &qemu{
|
q := &qemu{
|
||||||
arch: &qemuArchBase{},
|
arch: &qemuArchBase{},
|
||||||
|
config: HypervisorConfig{
|
||||||
|
MemorySize: mem,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
hostMemKb, err := getHostMemorySizeKb(procMemInfo)
|
hostMemKb, err := getHostMemorySizeKb(procMemInfo)
|
||||||
|
@ -111,8 +111,8 @@ func NewVM(ctx context.Context, config VMConfig) (*VM, error) {
|
|||||||
id: id,
|
id: id,
|
||||||
hypervisor: hypervisor,
|
hypervisor: hypervisor,
|
||||||
agent: agent,
|
agent: agent,
|
||||||
cpu: config.HypervisorConfig.DefaultVCPUs,
|
cpu: config.HypervisorConfig.NumVCPUs,
|
||||||
memory: config.HypervisorConfig.DefaultMemSz,
|
memory: config.HypervisorConfig.MemorySize,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user