qemu: domain: Store capability overrides in NULL-terminated string list

We always process the full list so there's no value in storing the count
separately.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-06-21 14:54:24 +02:00
parent b7b8ea965b
commit d1aa253730
3 changed files with 20 additions and 23 deletions

View File

@ -3331,8 +3331,8 @@ qemuDomainXmlNsDefFree(qemuDomainXmlNsDef *def)
g_free(def->env);
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);
@ -3448,10 +3448,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;
@ -3460,10 +3460,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;
@ -3492,7 +3492,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);
@ -3534,19 +3534,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");
@ -6617,7 +6617,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;
}

View File

@ -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

View File

@ -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;
}