From e9949a586a9a2e6642d6394f85bd58955740b69d Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Wed, 20 Jul 2011 00:06:45 -0400 Subject: [PATCH] qemu: use virDomainNetGetActual*() in qemuDomainXMLToNative 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 | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0106824696..6626057bbe 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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); -- GitLab