From: Laine Stump Date: Wed, 23 Sep 2020 01:19:38 +0000 (-0400) Subject: qemu: eliminate use of virDomainNetDefClear() in qemuConnectDomainXMLToNative() X-Git-Tag: v6.9.0-rc1~423 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bbf2fa7afc897af555f78083d0e9af625f56d1b;p=thirdparty%2Flibvirt.git 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 --- 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); + 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,