mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 02:56:18 +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"`
|
||||
MachineType string `toml:"machine_type"`
|
||||
BlockDeviceDriver string `toml:"block_device_driver"`
|
||||
DefaultVCPUs int32 `toml:"default_vcpus"`
|
||||
NumVCPUs int32 `toml:"default_vcpus"`
|
||||
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
|
||||
DefaultMemSz uint32 `toml:"default_memory"`
|
||||
MemorySize uint32 `toml:"default_memory"`
|
||||
DefaultBridges uint32 `toml:"default_bridges"`
|
||||
Msize9p uint32 `toml:"msize_9p"`
|
||||
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
|
||||
@ -202,14 +202,14 @@ func (h hypervisor) machineType() string {
|
||||
func (h hypervisor) defaultVCPUs() uint32 {
|
||||
numCPUs := goruntime.NumCPU()
|
||||
|
||||
if h.DefaultVCPUs < 0 || h.DefaultVCPUs > int32(numCPUs) {
|
||||
if h.NumVCPUs < 0 || h.NumVCPUs > int32(numCPUs) {
|
||||
return uint32(numCPUs)
|
||||
}
|
||||
if h.DefaultVCPUs == 0 { // or unspecified
|
||||
if h.NumVCPUs == 0 { // or unspecified
|
||||
return defaultVCPUCount
|
||||
}
|
||||
|
||||
return uint32(h.DefaultVCPUs)
|
||||
return uint32(h.NumVCPUs)
|
||||
}
|
||||
|
||||
func (h hypervisor) defaultMaxVCPUs() uint32 {
|
||||
@ -232,11 +232,11 @@ func (h hypervisor) defaultMaxVCPUs() uint32 {
|
||||
}
|
||||
|
||||
func (h hypervisor) defaultMemSz() uint32 {
|
||||
if h.DefaultMemSz < 8 {
|
||||
if h.MemorySize < 8 {
|
||||
return defaultMemSize // MiB
|
||||
}
|
||||
|
||||
return h.DefaultMemSz
|
||||
return h.MemorySize
|
||||
}
|
||||
|
||||
func (h hypervisor) defaultBridges() uint32 {
|
||||
@ -360,9 +360,9 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
||||
MachineAccelerators: machineAccelerators,
|
||||
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
||||
HypervisorMachineType: machineType,
|
||||
DefaultVCPUs: h.defaultVCPUs(),
|
||||
NumVCPUs: h.defaultVCPUs(),
|
||||
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
|
||||
DefaultMemSz: h.defaultMemSz(),
|
||||
MemorySize: h.defaultMemSz(),
|
||||
DefaultBridges: h.defaultBridges(),
|
||||
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
|
||||
MemPrealloc: h.MemPrealloc,
|
||||
@ -477,9 +477,9 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
|
||||
FirmwarePath: defaultFirmwarePath,
|
||||
MachineAccelerators: defaultMachineAccelerators,
|
||||
HypervisorMachineType: defaultMachineType,
|
||||
DefaultVCPUs: defaultVCPUCount,
|
||||
NumVCPUs: defaultVCPUCount,
|
||||
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
||||
DefaultMemSz: defaultMemSize,
|
||||
MemorySize: defaultMemSize,
|
||||
DefaultBridges: defaultBridgesCount,
|
||||
MemPrealloc: defaultEnableMemPrealloc,
|
||||
HugePages: defaultEnableHugePages,
|
||||
|
@ -132,9 +132,9 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
ImagePath: imagePath,
|
||||
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
||||
HypervisorMachineType: machineType,
|
||||
DefaultVCPUs: defaultVCPUCount,
|
||||
NumVCPUs: defaultVCPUCount,
|
||||
DefaultMaxVCPUs: uint32(goruntime.NumCPU()),
|
||||
DefaultMemSz: defaultMemSize,
|
||||
MemorySize: defaultMemSize,
|
||||
DisableBlockDeviceUse: disableBlockDevice,
|
||||
BlockDeviceDriver: defaultBlockDeviceDriver,
|
||||
DefaultBridges: defaultBridgesCount,
|
||||
@ -521,9 +521,9 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
||||
ImagePath: defaultImagePath,
|
||||
InitrdPath: defaultInitrdPath,
|
||||
HypervisorMachineType: defaultMachineType,
|
||||
DefaultVCPUs: defaultVCPUCount,
|
||||
NumVCPUs: defaultVCPUCount,
|
||||
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
||||
DefaultMemSz: defaultMemSize,
|
||||
MemorySize: defaultMemSize,
|
||||
DisableBlockDeviceUse: defaultDisableBlockDeviceUse,
|
||||
DefaultBridges: defaultBridgesCount,
|
||||
Mlock: !defaultEnableSwap,
|
||||
@ -790,13 +790,13 @@ func TestHypervisorDefaults(t *testing.T) {
|
||||
assert.Equal(h.machineType(), machineType, "custom hypervisor machine type wrong")
|
||||
|
||||
// auto inferring
|
||||
h.DefaultVCPUs = -1
|
||||
h.NumVCPUs = -1
|
||||
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")
|
||||
|
||||
h.DefaultVCPUs = int32(numCPUs) + 1
|
||||
h.NumVCPUs = int32(numCPUs) + 1
|
||||
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")
|
||||
|
||||
h.DefaultMaxVCPUs = 2
|
||||
@ -809,7 +809,7 @@ func TestHypervisorDefaults(t *testing.T) {
|
||||
h.DefaultMaxVCPUs = uint32(maxvcpus) + 1
|
||||
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")
|
||||
}
|
||||
|
||||
@ -1207,8 +1207,8 @@ func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
|
||||
tomlConf := tomlConfig{
|
||||
Hypervisor: map[string]hypervisor{
|
||||
qemuHypervisorTableType: {
|
||||
DefaultVCPUs: int32(vcpus),
|
||||
DefaultMemSz: uint32(mem),
|
||||
NumVCPUs: int32(vcpus),
|
||||
MemorySize: uint32(mem),
|
||||
Path: "/",
|
||||
Kernel: "/",
|
||||
Image: "/",
|
||||
@ -1220,7 +1220,7 @@ func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
|
||||
err := updateRuntimeConfig("", tomlConf, &config)
|
||||
assert.NoError(err)
|
||||
|
||||
assert.Equal(expectedVMConfig, config.HypervisorConfig.DefaultMemSz)
|
||||
assert.Equal(expectedVMConfig, config.HypervisorConfig.MemorySize)
|
||||
}
|
||||
|
||||
func TestUpdateRuntimeConfigurationFactoryConfig(t *testing.T) {
|
||||
|
@ -858,8 +858,8 @@ func TestStatusSandboxSuccessfulStateReady(t *testing.T) {
|
||||
KernelPath: filepath.Join(testDir, testKernel),
|
||||
ImagePath: filepath.Join(testDir, testImage),
|
||||
HypervisorPath: filepath.Join(testDir, testHypervisor),
|
||||
DefaultVCPUs: defaultVCPUs,
|
||||
DefaultMemSz: defaultMemSzMiB,
|
||||
NumVCPUs: defaultVCPUs,
|
||||
MemorySize: defaultMemSzMiB,
|
||||
DefaultBridges: defaultBridges,
|
||||
BlockDeviceDriver: defaultBlockDriver,
|
||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||
@ -916,8 +916,8 @@ func TestStatusSandboxSuccessfulStateRunning(t *testing.T) {
|
||||
KernelPath: filepath.Join(testDir, testKernel),
|
||||
ImagePath: filepath.Join(testDir, testImage),
|
||||
HypervisorPath: filepath.Join(testDir, testHypervisor),
|
||||
DefaultVCPUs: defaultVCPUs,
|
||||
DefaultMemSz: defaultMemSzMiB,
|
||||
NumVCPUs: defaultVCPUs,
|
||||
MemorySize: defaultMemSzMiB,
|
||||
DefaultBridges: defaultBridges,
|
||||
BlockDeviceDriver: defaultBlockDriver,
|
||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||
|
@ -154,13 +154,13 @@ type HypervisorConfig struct {
|
||||
// enable debug output where available.
|
||||
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.
|
||||
DefaultVCPUs uint32
|
||||
NumVCPUs uint32
|
||||
|
||||
// DefaultMem specifies default memory size in MiB for the VM.
|
||||
// Sandbox configuration VMConfig.Memory overwrites this.
|
||||
DefaultMemSz uint32
|
||||
MemorySize uint32
|
||||
|
||||
// DefaultBridges specifies default number of bridges for the VM.
|
||||
// Bridges can be used to hot plug devices
|
||||
|
@ -43,7 +43,7 @@ func Example_createAndStartSandbox() {
|
||||
KernelPath: "/usr/share/kata-containers/vmlinux.container",
|
||||
ImagePath: "/usr/share/kata-containers/kata-containers.img",
|
||||
HypervisorPath: "/usr/bin/qemu-system-x86_64",
|
||||
DefaultMemSz: 1024,
|
||||
MemorySize: 1024,
|
||||
}
|
||||
|
||||
// Use hyperstart default values for the agent.
|
||||
|
@ -94,8 +94,8 @@ func (f *factory) log() *logrus.Entry {
|
||||
}
|
||||
|
||||
func resetHypervisorConfig(config *vc.HypervisorConfig) {
|
||||
config.DefaultVCPUs = 0
|
||||
config.DefaultMemSz = 0
|
||||
config.NumVCPUs = 0
|
||||
config.MemorySize = 0
|
||||
config.BootToBeTemplate = false
|
||||
config.BootFromTemplate = false
|
||||
config.MemoryPath = ""
|
||||
@ -175,16 +175,16 @@ func (f *factory) GetVM(ctx context.Context, config vc.VMConfig) (*vc.VM, error)
|
||||
|
||||
online := false
|
||||
baseConfig := f.base.Config().HypervisorConfig
|
||||
if baseConfig.DefaultVCPUs < hypervisorConfig.DefaultVCPUs {
|
||||
err = vm.AddCPUs(hypervisorConfig.DefaultVCPUs - baseConfig.DefaultVCPUs)
|
||||
if baseConfig.NumVCPUs < hypervisorConfig.NumVCPUs {
|
||||
err = vm.AddCPUs(hypervisorConfig.NumVCPUs - baseConfig.NumVCPUs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
online = true
|
||||
}
|
||||
|
||||
if baseConfig.DefaultMemSz < hypervisorConfig.DefaultMemSz {
|
||||
err = vm.AddMemory(hypervisorConfig.DefaultMemSz - baseConfig.DefaultMemSz)
|
||||
if baseConfig.MemorySize < hypervisorConfig.MemorySize {
|
||||
err = vm.AddMemory(hypervisorConfig.MemorySize - baseConfig.MemorySize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -218,12 +218,12 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
|
||||
// CPU hotplug
|
||||
vmConfig.HypervisorConfig.DefaultVCPUs++
|
||||
vmConfig.HypervisorConfig.NumVCPUs++
|
||||
_, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
// Memory hotplug
|
||||
vmConfig.HypervisorConfig.DefaultMemSz += 128
|
||||
vmConfig.HypervisorConfig.MemorySize += 128
|
||||
_, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
|
@ -80,7 +80,7 @@ func (t *template) prepareTemplateFiles() error {
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func buildSandboxConfig(context *cli.Context) (vc.SandboxConfig, error) {
|
||||
KernelPath: kernelPath,
|
||||
ImagePath: "/usr/share/clear-containers/clear-containers.img",
|
||||
HypervisorMachineType: machineType,
|
||||
DefaultMemSz: uint32(vmMemory),
|
||||
MemorySize: uint32(vmMemory),
|
||||
}
|
||||
|
||||
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.
|
||||
customAssets map[assetType]*asset
|
||||
|
||||
// DefaultVCPUs specifies default number of vCPUs for the VM.
|
||||
DefaultVCPUs uint32
|
||||
// NumVCPUs specifies default number of vCPUs for the VM.
|
||||
NumVCPUs uint32
|
||||
|
||||
//DefaultMaxVCPUs specifies the maximum number of vCPUs for the VM.
|
||||
DefaultMaxVCPUs uint32
|
||||
|
||||
// DefaultMem specifies default memory size in MiB for the VM.
|
||||
DefaultMemSz uint32
|
||||
MemorySize uint32
|
||||
|
||||
// DefaultBridges specifies default number of bridges for the VM.
|
||||
// Bridges can be used to hot plug devices
|
||||
@ -273,12 +273,12 @@ func (conf *HypervisorConfig) valid() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if conf.DefaultVCPUs == 0 {
|
||||
conf.DefaultVCPUs = defaultVCPUs
|
||||
if conf.NumVCPUs == 0 {
|
||||
conf.NumVCPUs = defaultVCPUs
|
||||
}
|
||||
|
||||
if conf.DefaultMemSz == 0 {
|
||||
conf.DefaultMemSz = defaultMemSzMiB
|
||||
if conf.MemorySize == 0 {
|
||||
conf.MemorySize = defaultMemSzMiB
|
||||
}
|
||||
|
||||
if conf.DefaultBridges == 0 {
|
||||
|
@ -193,8 +193,8 @@ func TestHypervisorConfigDefaults(t *testing.T) {
|
||||
KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel),
|
||||
ImagePath: fmt.Sprintf("%s/%s", testDir, testImage),
|
||||
HypervisorPath: "",
|
||||
DefaultVCPUs: defaultVCPUs,
|
||||
DefaultMemSz: defaultMemSzMiB,
|
||||
NumVCPUs: defaultVCPUs,
|
||||
MemorySize: defaultMemSzMiB,
|
||||
DefaultBridges: defaultBridges,
|
||||
BlockDeviceDriver: defaultBlockDriver,
|
||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||
|
@ -417,7 +417,7 @@ func updateVMConfig(ocispec CompatOCISpec, config *RuntimeConfig) error {
|
||||
}
|
||||
// Use some math magic to round up to the nearest Mb.
|
||||
// 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
|
||||
|
@ -258,7 +258,7 @@ func TestUpdateVmConfig(t *testing.T) {
|
||||
|
||||
config := RuntimeConfig{
|
||||
HypervisorConfig: vc.HypervisorConfig{
|
||||
DefaultMemSz: 2048,
|
||||
MemorySize: 2048,
|
||||
},
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ func TestUpdateVmConfig(t *testing.T) {
|
||||
|
||||
err := updateVMConfig(ocispec, &config)
|
||||
assert.Nil(err)
|
||||
assert.Equal(config.HypervisorConfig.DefaultMemSz, expectedMem)
|
||||
assert.Equal(config.HypervisorConfig.MemorySize, expectedMem)
|
||||
|
||||
limitBytes = -128 * 1024 * 1024
|
||||
ocispec.Linux.Resources.Memory.Limit = &limitBytes
|
||||
@ -297,7 +297,7 @@ func TestUpdateVmConfig(t *testing.T) {
|
||||
ocispec.Linux.Resources.Memory = &specs.LinuxMemory{Limit: &limitBytes}
|
||||
err = updateVMConfig(ocispec, &config)
|
||||
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) {
|
||||
|
@ -248,7 +248,7 @@ func (q *qemu) init(ctx context.Context, id string, hypervisorConfig *Hypervisor
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -269,7 +269,7 @@ func (q *qemu) memoryTopology() (govmmQemu.Memory, error) {
|
||||
return govmmQemu.Memory{}, err
|
||||
}
|
||||
|
||||
memMb := uint64(q.config.DefaultMemSz)
|
||||
memMb := uint64(q.config.MemorySize)
|
||||
|
||||
return q.arch.memoryTopology(memMb, hostMemMb), nil
|
||||
}
|
||||
@ -1033,12 +1033,12 @@ func (q *qemu) hotplugMemory(memDev *memoryDevice, op operation) error {
|
||||
}
|
||||
|
||||
// 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
|
||||
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",
|
||||
memDev.sizeMB, currentMemory, q.config.DefaultMemSz)
|
||||
memDev.sizeMB, currentMemory, q.config.MemorySize)
|
||||
}
|
||||
|
||||
return q.hotplugAddMemory(memDev)
|
||||
|
@ -24,8 +24,8 @@ func newQemuConfig() HypervisorConfig {
|
||||
ImagePath: testQemuImagePath,
|
||||
InitrdPath: testQemuInitrdPath,
|
||||
HypervisorPath: testQemuPath,
|
||||
DefaultVCPUs: defaultVCPUs,
|
||||
DefaultMemSz: defaultMemSzMiB,
|
||||
NumVCPUs: defaultVCPUs,
|
||||
MemorySize: defaultMemSzMiB,
|
||||
DefaultBridges: defaultBridges,
|
||||
BlockDeviceDriver: defaultBlockDriver,
|
||||
DefaultMaxVCPUs: defaultMaxQemuVCPUs,
|
||||
@ -129,7 +129,7 @@ func TestQemuCPUTopology(t *testing.T) {
|
||||
q := &qemu{
|
||||
arch: &qemuArchBase{},
|
||||
config: HypervisorConfig{
|
||||
DefaultVCPUs: uint32(vcpus),
|
||||
NumVCPUs: uint32(vcpus),
|
||||
DefaultMaxVCPUs: uint32(vcpus),
|
||||
},
|
||||
}
|
||||
@ -150,10 +150,13 @@ func TestQemuCPUTopology(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestQemuMemoryTopology(t *testing.T) {
|
||||
mem := 1000
|
||||
mem := uint32(1000)
|
||||
|
||||
q := &qemu{
|
||||
arch: &qemuArchBase{},
|
||||
config: HypervisorConfig{
|
||||
MemorySize: mem,
|
||||
},
|
||||
}
|
||||
|
||||
hostMemKb, err := getHostMemorySizeKb(procMemInfo)
|
||||
|
@ -111,8 +111,8 @@ func NewVM(ctx context.Context, config VMConfig) (*VM, error) {
|
||||
id: id,
|
||||
hypervisor: hypervisor,
|
||||
agent: agent,
|
||||
cpu: config.HypervisorConfig.DefaultVCPUs,
|
||||
memory: config.HypervisorConfig.DefaultMemSz,
|
||||
cpu: config.HypervisorConfig.NumVCPUs,
|
||||
memory: config.HypervisorConfig.MemorySize,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user