We always process the full list so there's no value in storing the count
separately.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_domain.c | 28 ++++++++++++++--------------
src/qemu/qemu_domain.h | 2 --
src/qemu/qemu_process.c | 13 ++++++-------
3 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 21668cae4c..b2cbd3d6ba 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3330,8 +3330,8 @@ qemuDomainXmlNsDefFree(qemuDomainXmlNsDef *def)
}
virStringListFreeCount(def->args, def->num_args);
- virStringListFreeCount(def->capsadd, def->ncapsadd);
- virStringListFreeCount(def->capsdel, def->ncapsdel);
+ g_strfreev(def->capsadd);
+ g_strfreev(def->capsdel);
g_free(def->deprecationBehavior);
@@ -3447,10 +3447,10 @@ qemuDomainDefNamespaceParseCaps(qemuDomainXmlNsDef *nsdef,
return -1;
if (nnodesadd > 0) {
- nsdef->capsadd = g_new0(char *, nnodesadd);
+ nsdef->capsadd = g_new0(char *, nnodesadd + 1);
for (i = 0; i < nnodesadd; i++) {
- if (!(nsdef->capsadd[nsdef->ncapsadd++] = virXMLPropString(nodesadd[i],
"capability"))) {
+ if (!(nsdef->capsadd[i] = virXMLPropString(nodesadd[i],
"capability"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing capability name"));
return -1;
@@ -3459,10 +3459,10 @@ qemuDomainDefNamespaceParseCaps(qemuDomainXmlNsDef *nsdef,
}
if (nnodesdel > 0) {
- nsdef->capsdel = g_new0(char *, nnodesdel);
+ nsdef->capsdel = g_new0(char *, nnodesdel + 1);
for (i = 0; i < nnodesdel; i++) {
- if (!(nsdef->capsdel[nsdef->ncapsdel++] = virXMLPropString(nodesdel[i],
"capability"))) {
+ if (!(nsdef->capsdel[i] = virXMLPropString(nodesdel[i],
"capability"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing capability name"));
return -1;
@@ -3491,7 +3491,7 @@ qemuDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
nsdata->deprecationBehavior =
virXPathString("string(./qemu:deprecation/@behavior)", ctxt);
if (nsdata->num_args > 0 || nsdata->num_env > 0 ||
- nsdata->ncapsadd > 0 || nsdata->ncapsdel > 0 ||
+ nsdata->capsadd || nsdata->capsdel ||
nsdata->deprecationBehavior)
*data = g_steal_pointer(&nsdata);
@@ -3533,19 +3533,19 @@ static void
qemuDomainDefNamespaceFormatXMLCaps(virBuffer *buf,
qemuDomainXmlNsDef *xmlns)
{
- size_t i;
+ GStrv n;
- if (!xmlns->ncapsadd && !xmlns->ncapsdel)
+ if (!xmlns->capsadd && !xmlns->capsdel)
return;
virBufferAddLit(buf, "<qemu:capabilities>\n");
virBufferAdjustIndent(buf, 2);
- for (i = 0; i < xmlns->ncapsadd; i++)
- virBufferEscapeString(buf, "<qemu:add
capability='%s'/>\n", xmlns->capsadd[i]);
+ for (n = xmlns->capsadd; n && *n; n++)
+ virBufferEscapeString(buf, "<qemu:add
capability='%s'/>\n", *n);
- for (i = 0; i < xmlns->ncapsdel; i++)
- virBufferEscapeString(buf, "<qemu:del
capability='%s'/>\n", xmlns->capsdel[i]);
+ for (n = xmlns->capsdel; n && *n; n++)
+ virBufferEscapeString(buf, "<qemu:del
capability='%s'/>\n", *n);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</qemu:capabilities>\n");
@@ -6616,7 +6616,7 @@ void qemuDomainObjCheckTaint(virQEMUDriver *driver,
qemuDomainXmlNsDef *qemuxmlns = obj->def->namespaceData;
if (qemuxmlns->num_args || qemuxmlns->num_env)
qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_CUSTOM_ARGV, logCtxt);
- if (qemuxmlns->ncapsadd > 0 || qemuxmlns->ncapsdel > 0)
+ if (qemuxmlns->capsadd || qemuxmlns->capsdel)
custom_hypervisor_feat = true;
}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 5f2814271d..aa3ed78094 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -471,10 +471,8 @@ struct _qemuDomainXmlNsDef {
unsigned int num_env;
qemuDomainXmlNsEnvTuple *env;
- size_t ncapsadd;
char **capsadd;
- size_t ncapsdel;
char **capsdel;
/* We deliberately keep this as a string so that it's parsed only when
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 81af4f1a44..4264191a9a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5484,7 +5484,6 @@ qemuProcessStartUpdateCustomCaps(virDomainObj *vm)
qemuDomainXmlNsDef *nsdef = vm->def->namespaceData;
char **next;
int tmp;
- size_t i;
if (cfg->capabilityfilters) {
for (next = cfg->capabilityfilters; *next; next++) {
@@ -5500,22 +5499,22 @@ qemuProcessStartUpdateCustomCaps(virDomainObj *vm)
}
if (nsdef) {
- for (i = 0; i < nsdef->ncapsadd; i++) {
- if ((tmp = virQEMUCapsTypeFromString(nsdef->capsadd[i])) < 0) {
+ for (next = nsdef->capsadd; next && *next; next++) {
+ if ((tmp = virQEMUCapsTypeFromString(*next)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid qemu namespace capability
'%s'"),
- nsdef->capsadd[i]);
+ *next);
return -1;
}
virQEMUCapsSet(priv->qemuCaps, tmp);
}
- for (i = 0; i < nsdef->ncapsdel; i++) {
- if ((tmp = virQEMUCapsTypeFromString(nsdef->capsdel[i])) < 0) {
+ for (next = nsdef->capsdel; next && *next; next++) {
+ if ((tmp = virQEMUCapsTypeFromString(*next)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid qemu namespace capability
'%s'"),
- nsdef->capsdel[i]);
+ *next);
return -1;
}
--
2.31.1