From 524655eea2500196a98af20be3edfa198f870e85 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Mon, 18 Jul 2011 18:44:38 -0400 Subject: [PATCH] conf: virDomainNetDef points to (rather than contains) virtPortProfile The virtPortProfile in the domain interface struct is now a separately allocated object *pointed to by* (rather than contained in) the main virDomainNetDef object. This is done to make it easier to figure out when a virtualPortProfile has/hasn't been specified in a particular config. --- src/conf/domain_conf.c | 17 ++++++++--------- src/conf/domain_conf.h | 2 +- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_migration.c | 4 ++-- src/qemu/qemu_process.c | 2 +- src/util/network.c | 15 ++++++++++++--- src/util/network.h | 2 +- 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2373e97f1c..039b47897c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -770,6 +770,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def) case VIR_DOMAIN_NET_TYPE_DIRECT: VIR_FREE(def->data.direct.linkdev); + VIR_FREE(def->data.direct.virtPortProfile); break; case VIR_DOMAIN_NET_TYPE_USER: @@ -2617,8 +2618,7 @@ virDomainNetDefParseXML(virCapsPtr caps, char *devaddr = NULL; char *mode = NULL; virNWFilterHashTablePtr filterparams = NULL; - virVirtualPortProfileParams virtPort; - bool virtPortParsed = false; + virVirtualPortProfileParamsPtr virtPort = NULL; xmlNodePtr oldnode = ctxt->node; int ret; @@ -2664,12 +2664,11 @@ virDomainNetDefParseXML(virCapsPtr caps, xmlStrEqual(cur->name, BAD_CAST "source")) { dev = virXMLPropString(cur, "dev"); mode = virXMLPropString(cur, "mode"); - } else if (!virtPortParsed && + } else if ((virtPort == NULL) && (def->type == VIR_DOMAIN_NET_TYPE_DIRECT) && xmlStrEqual(cur->name, BAD_CAST "virtualport")) { - if (virVirtualPortProfileParseXML(cur, &virtPort)) + if (virVirtualPortProfileParseXML(cur, &virtPort) < 0) goto error; - virtPortParsed = true; } else if ((network == NULL) && ((def->type == VIR_DOMAIN_NET_TYPE_SERVER) || (def->type == VIR_DOMAIN_NET_TYPE_CLIENT) || @@ -2853,9 +2852,8 @@ virDomainNetDefParseXML(virCapsPtr caps, } else def->data.direct.mode = VIR_MACVTAP_MODE_VEPA; - if (virtPortParsed) - def->data.direct.virtPortProfile = virtPort; - + def->data.direct.virtPortProfile = virtPort; + virtPort = NULL; def->data.direct.linkdev = dev; dev = NULL; @@ -2962,6 +2960,7 @@ cleanup: VIR_FREE(port); VIR_FREE(ifname); VIR_FREE(dev); + VIR_FREE(virtPort); VIR_FREE(script); VIR_FREE(bridge); VIR_FREE(model); @@ -8609,7 +8608,7 @@ virDomainNetDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " mode='%s'", virMacvtapModeTypeToString(def->data.direct.mode)); virBufferAddLit(buf, "/>\n"); - virVirtualPortProfileFormat(buf, &def->data.direct.virtPortProfile, + virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile, " "); break; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fc7668dd1a..0e6354bfce 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -381,7 +381,7 @@ struct _virDomainNetDef { struct { char *linkdev; int mode; /* enum virMacvtapMode from util/macvtap.h */ - virVirtualPortProfileParams virtPortProfile; + virVirtualPortProfileParamsPtr virtPortProfile; } direct; } data; struct { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 938f113998..5badf75c4c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -127,7 +127,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def, rc = openMacvtapTap(net->ifname, net->mac, net->data.direct.linkdev, net->data.direct.mode, vnet_hdr, def->uuid, - &net->data.direct.virtPortProfile, &res_ifname, + net->data.direct.virtPortProfile, &res_ifname, vmop, driver->stateDir); if (rc >= 0) { virDomainAuditNetDevice(def, net, res_ifname, true); @@ -150,7 +150,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def, VIR_FORCE_CLOSE(rc); delMacvtap(net->ifname, net->mac, net->data.direct.linkdev, net->data.direct.mode, - &net->data.direct.virtPortProfile, + net->data.direct.virtPortProfile, driver->stateDir); VIR_FREE(net->ifname); } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 20f0dafa02..43914db33c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1616,7 +1616,7 @@ int qemuDomainDetachNetDevice(struct qemud_driver *driver, if (detach->type == VIR_DOMAIN_NET_TYPE_DIRECT) { delMacvtap(detach->ifname, detach->mac, detach->data.direct.linkdev, detach->data.direct.mode, - &detach->data.direct.virtPortProfile, + detach->data.direct.virtPortProfile, driver->stateDir); VIR_FREE(detach->ifname); } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 3282271816..5bfcaba812 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2347,7 +2347,7 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) { if (vpAssociatePortProfileId(net->ifname, net->mac, net->data.direct.linkdev, - &net->data.direct.virtPortProfile, + net->data.direct.virtPortProfile, def->uuid, VIR_VM_OP_MIGRATE_IN_FINISH) != 0) goto err_exit; @@ -2364,7 +2364,7 @@ err_exit: vpDisassociatePortProfileId(net->ifname, net->mac, net->data.direct.linkdev, - &net->data.direct.virtPortProfile, + net->data.direct.virtPortProfile, VIR_VM_OP_MIGRATE_IN_FINISH); } } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4c6081bb76..98455c5f73 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3021,7 +3021,7 @@ void qemuProcessStop(struct qemud_driver *driver, if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) { delMacvtap(net->ifname, net->mac, net->data.direct.linkdev, net->data.direct.mode, - &net->data.direct.virtPortProfile, driver->stateDir); + net->data.direct.virtPortProfile, driver->stateDir); VIR_FREE(net->ifname); } } diff --git a/src/util/network.c b/src/util/network.c index c7b8fb3c36..64f5645a91 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -685,7 +685,7 @@ VIR_ENUM_IMPL(virVirtualPort, VIR_VIRTUALPORT_TYPE_LAST, int virVirtualPortProfileParseXML(xmlNodePtr node, - virVirtualPortProfileParamsPtr virtPort) + virVirtualPortProfileParamsPtr *def) { int ret = -1; char *virtPortType; @@ -694,8 +694,14 @@ virVirtualPortProfileParseXML(xmlNodePtr node, char *virtPortTypeIDVersion = NULL; char *virtPortInstanceID = NULL; char *virtPortProfileID = NULL; + virVirtualPortProfileParamsPtr virtPort = NULL; xmlNodePtr cur = node->children; + if (VIR_ALLOC(virtPort) < 0) { + virReportOOMError(); + return -1; + } + virtPortType = virXMLPropString(node, "type"); if (!virtPortType) { virSocketError(VIR_ERR_XML_ERROR, "%s", @@ -785,7 +791,7 @@ virVirtualPortProfileParseXML(xmlNodePtr node, } virtPort->virtPortType = VIR_VIRTUALPORT_8021QBG; - ret = 0; + } else { virSocketError(VIR_ERR_XML_ERROR, "%s", _("a parameter is missing for 802.1Qbg description")); @@ -798,7 +804,6 @@ virVirtualPortProfileParseXML(xmlNodePtr node, if (virStrcpyStatic(virtPort->u.virtPort8021Qbh.profileID, virtPortProfileID) != NULL) { virtPort->virtPortType = VIR_VIRTUALPORT_8021QBH; - ret = 0; } else { virSocketError(VIR_ERR_XML_ERROR, "%s", _("profileid parameter too long")); @@ -821,7 +826,11 @@ virVirtualPortProfileParseXML(xmlNodePtr node, break; } + ret = 0; + *def = virtPort; + virtPort = NULL; error: + VIR_FREE(virtPort); VIR_FREE(virtPortManagerID); VIR_FREE(virtPortTypeID); VIR_FREE(virtPortTypeIDVersion); diff --git a/src/util/network.h b/src/util/network.h index 0fda3c1fa1..27347f8e69 100644 --- a/src/util/network.h +++ b/src/util/network.h @@ -130,7 +130,7 @@ struct _virVirtualPortProfileParams { int virVirtualPortProfileParseXML(xmlNodePtr node, - virVirtualPortProfileParamsPtr virtPort); + virVirtualPortProfileParamsPtr *virtPort); void virVirtualPortProfileFormat(virBufferPtr buf, virVirtualPortProfileParamsPtr virtPort,