From 5bbf2fa7afc897af555f78083d0e9af625f56d1b Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Tue, 22 Sep 2020 21:19:38 -0400 Subject: [PATCH] qemu: eliminate use of virDomainNetDefClear() in qemuConnectDomainXMLToNative() 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 Reviewed-by: Michal Privoznik --- src/qemu/qemu_driver.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e158cf85a9..85b6a6a321 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); - - net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; - net->info.bootIndex = bootIndex; - net->mac = mac; - net->script = script; - - if (virDomainNetSetModelString(net, model) < 0) + if (!newNet) goto cleanup; + + 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); + + virDomainNetDefFree(net); + vm->def->nets[i] = newNet; } if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,