]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: eliminate use of virDomainNetDefClear() in qemuConnectDomainXMLToNative()
authorLaine Stump <laine@redhat.com>
Wed, 23 Sep 2020 01:19:38 +0000 (21:19 -0400)
committerLaine Stump <laine@redhat.com>
Thu, 1 Oct 2020 18:02:33 +0000 (14:02 -0400)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_driver.c

index e158cf85a9061a931f2fe9cec6d12e6e7f3dc97e..85b6a6a321779eccadea7eb79ea8565ebbc23fa5 100644 (file)
@@ -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,