提交 6427bfc8 编写于 作者: C Cole Robinson

qemu: Move <memballoon> validation out of qemu_command.c

If we validate that memballoon is NONE|VIRTIO at parse time,
we can drop similar checks elsewhere in the qemu driver
Reviewed-by: NAndrea Bolognani <abologna@redhat.com>
Signed-off-by: NCole Robinson <crobinso@redhat.com>
上级 ea72bc65
...@@ -4046,20 +4046,9 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd, ...@@ -4046,20 +4046,9 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd,
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (STRPREFIX(def->os.machine, "s390-virtio") &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon)
def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
if (!virDomainDefHasMemballoon(def)) if (!virDomainDefHasMemballoon(def))
return 0; return 0;
if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Memory balloon device type '%s' is not supported by this version of qemu"),
virDomainMemballoonModelTypeToString(def->memballoon->model));
return -1;
}
if (qemuBuildVirtioDevStr(&buf, "virtio-balloon", if (qemuBuildVirtioDevStr(&buf, "virtio-balloon",
def->memballoon->info.type) < 0) { def->memballoon->info.type) < 0) {
goto error; goto error;
...@@ -4070,12 +4059,6 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd, ...@@ -4070,12 +4059,6 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd,
goto error; goto error;
if (def->memballoon->autodeflate != VIR_TRISTATE_SWITCH_ABSENT) { if (def->memballoon->autodeflate != VIR_TRISTATE_SWITCH_ABSENT) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("deflate-on-oom is not supported by this QEMU binary"));
goto error;
}
virBufferAsprintf(&buf, ",deflate-on-oom=%s", virBufferAsprintf(&buf, ",deflate-on-oom=%s",
virTristateSwitchTypeToString(def->memballoon->autodeflate)); virTristateSwitchTypeToString(def->memballoon->autodeflate));
} }
......
...@@ -3481,6 +3481,10 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, ...@@ -3481,6 +3481,10 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def,
def->memballoon = memballoon; def->memballoon = memballoon;
} }
if (STRPREFIX(def->os.machine, "s390-virtio") &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon)
def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
if (addDefaultUSBKBD && if (addDefaultUSBKBD &&
def->ngraphics > 0 && def->ngraphics > 0 &&
virDomainDefMaybeAddInput(def, virDomainDefMaybeAddInput(def,
...@@ -5980,6 +5984,33 @@ qemuDomainDeviceDefValidateInput(const virDomainInputDef *input, ...@@ -5980,6 +5984,33 @@ qemuDomainDeviceDefValidateInput(const virDomainInputDef *input,
} }
static int
qemuDomainDeviceDefValidateMemballoon(const virDomainMemballoonDef *memballoon,
virQEMUCapsPtr qemuCaps)
{
if (!memballoon ||
memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
return 0;
}
if (memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Memory balloon device type '%s' is not supported by this version of qemu"),
virDomainMemballoonModelTypeToString(memballoon->model));
return -1;
}
if (memballoon->autodeflate != VIR_TRISTATE_SWITCH_ABSENT &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("deflate-on-oom is not supported by this QEMU binary"));
return -1;
}
return 0;
}
static int static int
qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info, qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
...@@ -6088,11 +6119,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, ...@@ -6088,11 +6119,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
ret = qemuDomainDeviceDefValidateInput(dev->data.input, def, qemuCaps); ret = qemuDomainDeviceDefValidateInput(dev->data.input, def, qemuCaps);
break; break;
case VIR_DOMAIN_DEVICE_MEMBALLOON:
ret = qemuDomainDeviceDefValidateMemballoon(dev->data.memballoon, qemuCaps);
break;
case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_HUB: case VIR_DOMAIN_DEVICE_HUB:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_NVRAM:
case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_MEMORY:
......
...@@ -358,8 +358,8 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def, ...@@ -358,8 +358,8 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,
def->hostdevs[i]->info->type = type; def->hostdevs[i]->info->type = type;
} }
if (def->memballoon && /* All memballoon devices accepted by the qemu driver are virtio */
def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO && if (virDomainDefHasMemballoon(def) &&
def->memballoon->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) def->memballoon->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
def->memballoon->info.type = type; def->memballoon->info.type = type;
...@@ -2268,11 +2268,9 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, ...@@ -2268,11 +2268,9 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
goto error; goto error;
} }
/* VirtIO balloon */ /* memballoon. the qemu driver only accepts virtio memballoon devices */
if (def->memballoon && if (virDomainDefHasMemballoon(def) &&
def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO &&
virDeviceInfoPCIAddressIsWanted(&def->memballoon->info)) { virDeviceInfoPCIAddressIsWanted(&def->memballoon->info)) {
if (qemuDomainPCIAddressReserveNextAddr(addrs, if (qemuDomainPCIAddressReserveNextAddr(addrs,
&def->memballoon->info) < 0) &def->memballoon->info) < 0)
goto error; goto error;
......
...@@ -2439,11 +2439,10 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, ...@@ -2439,11 +2439,10 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period,
priv = vm->privateData; priv = vm->privateData;
if (def) { if (def) {
if (!def->memballoon || if (!virDomainDefHasMemballoon(def)) {
def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Memory balloon model must be virtio to set the" _("No memory balloon device configured, "
" collection period")); "can not set the collection period"));
goto endjob; goto endjob;
} }
...@@ -2463,11 +2462,10 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, ...@@ -2463,11 +2462,10 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period,
} }
if (persistentDef) { if (persistentDef) {
if (!persistentDef->memballoon || if (!virDomainDefHasMemballoon(persistentDef)) {
persistentDef->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Memory balloon model must be virtio to set the" _("No memory balloon device configured, "
" collection period")); "can not set the collection period"));
goto endjob; goto endjob;
} }
persistentDef->memballoon->period = period; persistentDef->memballoon->period = period;
...@@ -11964,8 +11962,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriverPtr driver, ...@@ -11964,8 +11962,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriverPtr driver,
if (virDomainObjCheckActive(vm) < 0) if (virDomainObjCheckActive(vm) < 0)
return -1; return -1;
if (vm->def->memballoon && if (virDomainDefHasMemballoon(vm->def)) {
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm), ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm),
vm->def->memballoon, stats, nr_stats); vm->def->memballoon, stats, nr_stats);
......
...@@ -7593,8 +7593,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -7593,8 +7593,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
if (running) { if (running) {
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
VIR_DOMAIN_RUNNING_UNPAUSED); VIR_DOMAIN_RUNNING_UNPAUSED);
if (vm->def->memballoon && if (virDomainDefHasMemballoon(vm->def) &&
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO &&
vm->def->memballoon->period) { vm->def->memballoon->period) {
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon, qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册