From 7f30c5668d4b1e41daad07357f3dc1ed7cff8a71 Mon Sep 17 00:00:00 2001 Message-Id: <7f30c5668d4b1e41daad07357f3dc1ed7cff8a71@dist-git> From: Peter Krempa Date: Wed, 24 Aug 2016 16:10:50 -0400 Subject: [PATCH] qemu: domain: Extract formating and parsing of vCPU thread ids https://bugzilla.redhat.com/show_bug.cgi?id=1097930 https://bugzilla.redhat.com/show_bug.cgi?id=1224341 Further patches will be adding index and modifying the source variables so this will make it more clear. (cherry picked from commit b91335afe48a406223caf15a0598b95ec29a26b5) --- src/qemu/qemu_domain.c | 82 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index c213a9f..01f0d6a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1354,6 +1354,27 @@ qemuDomainObjPrivateFree(void *data) } +static void +qemuDomainObjPrivateXMLFormatVcpus(virBufferPtr buf, + int *vcpupids, + int nvcpupids) +{ + size_t i; + + if (!nvcpupids) + return; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + for (i = 0; i < nvcpupids; i++) + virBufferAsprintf(buf, "\n", vcpupids[i]); + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); +} + + static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, virDomainObjPtr vm) @@ -1381,16 +1402,7 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, virDomainChrTypeToString(priv->monConfig->type)); } - - if (priv->nvcpupids) { - size_t i; - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - for (i = 0; i < priv->nvcpupids; i++) - virBufferAsprintf(buf, "\n", priv->vcpupids[i]); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } + qemuDomainObjPrivateXMLFormatVcpus(buf, priv->vcpupids, priv->nvcpupids); if (priv->qemuCaps) { size_t i; @@ -1479,6 +1491,29 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, return 0; } + +static int +qemuDomainObjPrivateXMLParseVcpu(xmlNodePtr node, + unsigned int idx, + qemuDomainObjPrivatePtr priv) +{ + char *pidstr; + int ret = -1; + + if (!(pidstr = virXMLPropString(node, "pid"))) + goto cleanup; + + if (virStrToLong_i(pidstr, NULL, 10, &(priv->vcpupids[idx])) < 0) + goto cleanup; + + ret = 0; + + cleanup: + VIR_FREE(pidstr); + return ret; +} + + static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, virDomainObjPtr vm, @@ -1529,27 +1564,18 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, goto error; } - n = virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes); - if (n < 0) + if ((n = virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0) goto error; - if (n) { - priv->nvcpupids = n; - if (VIR_REALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) + + priv->nvcpupids = n; + if (VIR_REALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) + goto error; + + for (i = 0; i < n; i++) { + if (qemuDomainObjPrivateXMLParseVcpu(nodes[i], i, priv) < 0) goto error; - - for (i = 0; i < n; i++) { - char *pidstr = virXMLPropString(nodes[i], "pid"); - if (!pidstr) - goto error; - - if (virStrToLong_i(pidstr, NULL, 10, &(priv->vcpupids[i])) < 0) { - VIR_FREE(pidstr); - goto error; - } - VIR_FREE(pidstr); - } - VIR_FREE(nodes); } + VIR_FREE(nodes); if ((n = virXPathNodeSet("./qemuCaps/flag", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 2.10.0