提交 33b9598c 编写于 作者: P Peter Krempa

qemu: command: Refactor memballoon command line formatting

Now that there is just one format of the memory balloon command line
used the code can be merged into a single function.

Additionally with some tweaks to the control flow the code is easier to
read.
上级 388b356e
...@@ -3470,14 +3470,29 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd, ...@@ -3470,14 +3470,29 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd,
} }
char * static int
qemuBuildMemballoonDevStr(const virDomainDef *def, qemuBuildMemballoonCommandLine(virCommandPtr cmd,
virDomainMemballoonDefPtr dev, const virDomainDef *def,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
switch (dev->info.type) { if (STREQLEN(def->os.machine, "s390-virtio", 10) &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon)
def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
if (!def->memballoon ||
def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE)
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;
}
switch (def->memballoon->info.type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
virBufferAddLit(&buf, "virtio-balloon-pci"); virBufferAddLit(&buf, "virtio-balloon-pci");
break; break;
...@@ -3490,15 +3505,15 @@ qemuBuildMemballoonDevStr(const virDomainDef *def, ...@@ -3490,15 +3505,15 @@ qemuBuildMemballoonDevStr(const virDomainDef *def,
default: default:
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("memballoon unsupported with address type '%s'"), _("memballoon unsupported with address type '%s'"),
virDomainDeviceAddressTypeToString(dev->info.type)); virDomainDeviceAddressTypeToString(def->memballoon->info.type));
goto error; goto error;
} }
virBufferAsprintf(&buf, ",id=%s", dev->info.alias); virBufferAsprintf(&buf, ",id=%s", def->memballoon->info.alias);
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &def->memballoon->info, qemuCaps) < 0)
goto error; goto error;
if (dev->autodeflate != VIR_TRISTATE_SWITCH_ABSENT) { if (def->memballoon->autodeflate != VIR_TRISTATE_SWITCH_ABSENT) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("deflate-on-oom is not supported by this QEMU binary")); _("deflate-on-oom is not supported by this QEMU binary"));
...@@ -3506,49 +3521,16 @@ qemuBuildMemballoonDevStr(const virDomainDef *def, ...@@ -3506,49 +3521,16 @@ qemuBuildMemballoonDevStr(const virDomainDef *def,
} }
virBufferAsprintf(&buf, ",deflate-on-oom=%s", virBufferAsprintf(&buf, ",deflate-on-oom=%s",
virTristateSwitchTypeToString(dev->autodeflate)); virTristateSwitchTypeToString(def->memballoon->autodeflate));
} }
if (virBufferCheckError(&buf) < 0) virCommandAddArg(cmd, "-device");
goto error; virCommandAddArgBuffer(cmd, &buf);
return 0;
return virBufferContentAndReset(&buf);
error: error:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL;
}
static int
qemuBuildMemballoonCommandLine(virCommandPtr cmd,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
char *optstr;
if (STREQLEN(def->os.machine, "s390-virtio", 10) &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon)
def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
if (def->memballoon &&
def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
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;
}
virCommandAddArg(cmd, "-device");
optstr = qemuBuildMemballoonDevStr(def, def->memballoon, qemuCaps);
if (!optstr)
return -1; return -1;
virCommandAddArg(cmd, optstr);
VIR_FREE(optstr);
}
return 0;
} }
......
...@@ -117,10 +117,6 @@ char *qemuBuildControllerDevStr(const virDomainDef *domainDef, ...@@ -117,10 +117,6 @@ char *qemuBuildControllerDevStr(const virDomainDef *domainDef,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
int *nusbcontroller); int *nusbcontroller);
char *qemuBuildMemballoonDevStr(const virDomainDef *domainDef,
virDomainMemballoonDefPtr dev,
virQEMUCapsPtr qemuCaps);
int qemuBuildMemoryBackendStr(unsigned long long size, int qemuBuildMemoryBackendStr(unsigned long long size,
unsigned long long pagesize, unsigned long long pagesize,
int guestNode, int guestNode,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册