提交 e9949a58 编写于 作者: L Laine Stump

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*.
上级 03caa988
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册