mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
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*.
This commit is contained in:
parent
03caa988a6
commit
e9949a586a
@ -4052,9 +4052,44 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
|
|||||||
for (i = 0 ; i < def->nnets ; i++) {
|
for (i = 0 ; i < def->nnets ; i++) {
|
||||||
virDomainNetDefPtr net = def->nets[i];
|
virDomainNetDefPtr net = def->nets[i];
|
||||||
int bootIndex = net->bootIndex;
|
int bootIndex = net->bootIndex;
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||||
net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
int actualType = virDomainNetGetActualType(net);
|
||||||
|
const char *brname;
|
||||||
|
|
||||||
VIR_FREE(net->data.network.name);
|
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);
|
memset(net, 0, sizeof *net);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user