conf: use virDomainNetTeamingInfoPtr instead of virDomainNetTeamingInfo

To make it easier to split out the parsing/formatting of the <teaming>
element into separate functions (so we can more easily add the
<teaming> element to <hostdev>, change its virDomainNetDef so that it
points to a virDomainNetTeamingInfo rather than containing one.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Laine Stump 2021-02-10 21:09:58 -05:00
parent 5d74e2f168
commit 13be68094d
7 changed files with 63 additions and 54 deletions

View File

@ -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, "</tune>\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='%s'",
virDomainNetTeamingTypeToString(def->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) {

View File

@ -1038,7 +1038,7 @@ struct _virDomainNetDef {
char *tap;
char *vhost;
} backend;
virDomainNetTeamingInfo teaming;
virDomainNetTeamingInfoPtr teaming;
union {
virDomainChrSourceDefPtr vhostuser;
struct {

View File

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

View File

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

View File

@ -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'"),

View File

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

View File

@ -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 <model type='virtio'/>, 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 <model type='virtio'/>, 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)) {