From 13be68094d47693fd5346d45612d05de425e2529 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Wed, 10 Feb 2021 21:09:58 -0500 Subject: [PATCH] conf: use virDomainNetTeamingInfoPtr instead of virDomainNetTeamingInfo To make it easier to split out the parsing/formatting of the element into separate functions (so we can more easily add the element to , change its virDomainNetDef so that it points to a virDomainNetTeamingInfo rather than containing one. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 31 ++++++++++++++++------------ src/conf/domain_conf.h | 2 +- src/conf/domain_validate.c | 26 ++++++++++++----------- src/qemu/qemu_command.c | 10 ++++----- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_migration.c | 4 ++-- src/qemu/qemu_validate.c | 42 ++++++++++++++++++++------------------ 7 files changed, 63 insertions(+), 54 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7d7acb940a..bbf54c90ba 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2542,7 +2542,7 @@ virDomainNetDefFree(virDomainNetDefPtr def) g_free(def->backend.tap); g_free(def->backend.vhost); - g_free(def->teaming.persistent); + virDomainNetTeamingInfoFree(def->teaming); g_free(def->virtPortProfile); g_free(def->script); g_free(def->downscript); @@ -11447,18 +11447,23 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, } } - if (teamingType) { - int tmpTeaming; + if (teamingType || teamingPersistent) { + def->teaming = g_new0(virDomainNetTeamingInfo, 1); - if ((tmpTeaming = virDomainNetTeamingTypeFromString(teamingType)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown teaming type '%s'"), - teamingType); - goto error; + if (teamingType) { + int tmpTeaming; + + if ((tmpTeaming = virDomainNetTeamingTypeFromString(teamingType)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown teaming type '%s'"), + teamingType); + goto error; + } + def->teaming->type = tmpTeaming; } - def->teaming.type = tmpTeaming; + + def->teaming->persistent = g_steal_pointer(&teamingPersistent); } - def->teaming.persistent = g_steal_pointer(&teamingPersistent); rv = virXPathULong("string(./tune/sndbuf)", ctxt, &def->tune.sndbuf); if (rv >= 0) { @@ -25825,10 +25830,10 @@ virDomainNetDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); } - if (def->teaming.type != VIR_DOMAIN_NET_TEAMING_TYPE_NONE) { + if (def->teaming && def->teaming->type != VIR_DOMAIN_NET_TEAMING_TYPE_NONE) { virBufferAsprintf(buf, "teaming.type)); - virBufferEscapeString(buf, " persistent='%s'", def->teaming.persistent); + virDomainNetTeamingTypeToString(def->teaming->type)); + virBufferEscapeString(buf, " persistent='%s'", def->teaming->persistent); virBufferAddLit(buf, "/>\n"); } if (def->linkstate) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 92fe588b3f..fb695a212b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1038,7 +1038,7 @@ struct _virDomainNetDef { char *tap; char *vhost; } backend; - virDomainNetTeamingInfo teaming; + virDomainNetTeamingInfoPtr teaming; union { virDomainChrSourceDefPtr vhostuser; struct { diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index b6f53886cd..703946b3e5 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1507,18 +1507,20 @@ virDomainNetDefValidate(const virDomainNetDef *net) return -1; } - if (net->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT) { - if (!net->teaming.persistent) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("teaming persistent attribute must be set if teaming type is 'transient'")); - return -1; - } - } else { - if (net->teaming.persistent) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("teaming persistent attribute not allowed if teaming type is '%s'"), - virDomainNetTeamingTypeToString(net->teaming.type)); - return -1; + if (net->teaming) { + if (net->teaming->type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT) { + if (!net->teaming->persistent) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("teaming persistent attribute must be set if teaming type is 'transient'")); + return -1; + } + } else { + if (net->teaming->persistent) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("teaming persistent attribute not allowed if teaming type is '%s'"), + virDomainNetTeamingTypeToString(net->teaming->type)); + return -1; + } } } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5fe4e618fe..455430c95b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3536,7 +3536,7 @@ qemuBuildNicDevStr(virDomainDefPtr def, if (net->mtu) virBufferAsprintf(&buf, ",host_mtu=%u", net->mtu); - if (net->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_PERSISTENT) + if (net->teaming && net->teaming->type == VIR_DOMAIN_NET_TEAMING_TYPE_PERSISTENT) virBufferAddLit(&buf, ",failover=on"); } @@ -4461,11 +4461,11 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def, if (qemuBuildRomStr(&buf, dev->info) < 0) return NULL; - if (dev->parentnet && - dev->parentnet->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT && - dev->parentnet->teaming.persistent) { + if (dev->parentnet && dev->parentnet->teaming && + dev->parentnet->teaming->type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT && + dev->parentnet->teaming->persistent) { virBufferAsprintf(&buf, ",failover_pair_id=%s", - dev->parentnet->teaming.persistent); + dev->parentnet->teaming->persistent); } return virBufferContentAndReset(&buf); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6243bf853f..14d05cfe3b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4458,7 +4458,7 @@ qemuDomainValidateActualNetDef(const virDomainNetDef *net, return -1; } - if (net->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT && + if (net->teaming && net->teaming->type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT && actualType != VIR_DOMAIN_NET_TYPE_HOSTDEV) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("interface %s - teaming transient device must be type='hostdev', not '%s'"), diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 1bb4a9608e..f4826707c5 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1223,8 +1223,8 @@ qemuMigrationSrcIsAllowedHostdev(const virDomainDef *def) * the device will be auto-unplugged by QEMU during * migration. */ - if (hostdev->parentnet && - hostdev->parentnet->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT) { + if (hostdev->parentnet && hostdev->parentnet->teaming && + hostdev->parentnet->teaming->type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT) { continue; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index bf4901bf89..2541ae856a 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1588,26 +1588,28 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net, return -1; } - if (net->teaming.type != VIR_DOMAIN_NET_TEAMING_TYPE_NONE && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_FAILOVER)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtio-net failover (teaming) is not supported with this QEMU binary")); - return -1; - } - if (net->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_PERSISTENT - && !virDomainNetIsVirtioModel(net)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("virtio-net teaming persistent interface must be , not '%s'"), - virDomainNetGetModelString(net)); - return -1; - } - if (net->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT && - net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && - net->type != VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("virtio-net teaming transient interface must be type='hostdev', not '%s'"), - virDomainNetTypeToString(net->type)); - return -1; + if (net->teaming) { + if (net->teaming->type != VIR_DOMAIN_NET_TEAMING_TYPE_NONE && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_FAILOVER)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio-net failover (teaming) is not supported with this QEMU binary")); + return -1; + } + if (net->teaming->type == VIR_DOMAIN_NET_TEAMING_TYPE_PERSISTENT + && !virDomainNetIsVirtioModel(net)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("virtio-net teaming persistent interface must be , not '%s'"), + virDomainNetGetModelString(net)); + return -1; + } + if (net->teaming->type == VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT && + net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && + net->type != VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("virtio-net teaming transient interface must be type='hostdev', not '%s'"), + virDomainNetTypeToString(net->type)); + return -1; + } } if (net->coalesce && !qemuValidateNetSupportsCoalesce(net->type)) {