]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: use virDomainNetGetActual*() in qemuDomainXMLToNative
authorLaine Stump <laine@laine.org>
Wed, 20 Jul 2011 04:06:45 +0000 (00:06 -0400)
committerLaine Stump <laine@laine.org>
Thu, 21 Jul 2011 18:47:11 +0000 (14:47 -0400)
This is the one function outside of domain_conf.c that plays around
with (even modifying) the internals of the virDomainNetDef, and thus
can't be fixed up simply by replacing direct accesses to the fields of
the struct with the GetActual*() access functions.

In this case, we need to check if the defined type is "network", and
if it is *then* check the actual type; if the actual type is "bridge",
then we can at least put the bridgename in a place where it can be
used; otherwise (if type isn't "bridge"), we behave exactly as we used
to - just null out *everything*.

src/qemu/qemu_driver.c

index 010682469633d6a902df13b7010e69bc5a204b20..6626057bbe39c29f8e7c21981a91d10d27d85b06 100644 (file)
@@ -4052,9 +4052,44 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
     for (i = 0 ; i < def->nnets ; i++) {
         virDomainNetDefPtr net = def->nets[i];
         int bootIndex = net->bootIndex;
-        if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
-            net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
+        if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+            int actualType = virDomainNetGetActualType(net);
+            const char *brname;
+
             VIR_FREE(net->data.network.name);
+            VIR_FREE(net->data.network.portgroup);
+            if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
+                (brname = virDomainNetGetActualBridgeName(net))) {
+
+                char *brnamecopy = strdup(brname);
+                if (!brnamecopy) {
+                    virReportOOMError();
+                    goto cleanup;
+                }
+
+                virDomainActualNetDefFree(net->data.network.actual);
+
+                memset(net, 0, sizeof *net);
+
+                net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
+                net->data.ethernet.dev = brnamecopy;
+                net->data.ethernet.script = NULL;
+                net->data.ethernet.ipaddr = NULL;
+            } else {
+                /* actualType is either NETWORK or DIRECT. In either
+                 * case, the best we can do is NULL everything out.
+                 */
+                virDomainActualNetDefFree(net->data.network.actual);
+                memset(net, 0, sizeof *net);
+
+                net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
+                net->data.ethernet.dev = NULL;
+                net->data.ethernet.script = NULL;
+                net->data.ethernet.ipaddr = NULL;
+            }
+        } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
+            VIR_FREE(net->data.direct.linkdev);
+            VIR_FREE(net->data.direct.virtPortProfile);
 
             memset(net, 0, sizeof *net);