Instead of saving the interesting pieces of each existing NetDef,
clearing it, and then copying back the saved pieces after setting the
type to ethernet, just create a new NetDef, copy in the interesting
bits, and replace the old one. (The end game is to eliminate
virDomainNetDefClear() completely, since this is the only real use)
Signed-off-by: Laine Stump <laine(a)redhat.com>
---
src/qemu/qemu_driver.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b27f05992b..19e2aff3e4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6456,24 +6456,20 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
*/
for (i = 0; i < vm->def->nnets; i++) {
virDomainNetDefPtr net = vm->def->nets[i];
- unsigned int bootIndex = net->info.bootIndex;
- g_autofree char *model = NULL;
- virMacAddr mac = net->mac;
- char *script = net->script;
+ virDomainNetDefPtr newNet = virDomainNetDefNew(driver->xmlopt);
- model = g_strdup(virDomainNetGetModelString(net));
-
- net->script = NULL;
-
- virDomainNetDefClear(net);
+ if (!newNet)
+ goto cleanup;
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->info.bootIndex = bootIndex;
- net->mac = mac;
- net->script = script;
+ newNet->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
+ newNet->info.bootIndex = net->info.bootIndex;
+ newNet->model = net->model;
+ newNet->modelstr = g_steal_pointer(&net->modelstr);
+ newNet->mac = net->mac;
+ newNet->script = g_steal_pointer(&net->script);
- if (virDomainNetSetModelString(net, model) < 0)
- goto cleanup;
+ virDomainNetDefFree(net);
+ vm->def->nets[i] = newNet;
}
if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,
--
2.26.2