]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: Assign device alias early
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 23 Oct 2025 13:53:20 +0000 (15:53 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Nov 2025 12:16:12 +0000 (13:16 +0100)
Assigning device should happen from ch_hotplug.c (just like it's
done for disks currently) not in ch_process.c. Move alias
assignment out of chProcessAddNetworkDevice(). And while at it,
mimic what's done with disks and have net hotplug handling done
from a function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/ch/ch_hotplug.c
src/ch/ch_process.c

index fabca2a73a8364f72ee8bf62b926fe1cadd1fb97..b296fd11b1e55241f405cc49419b60926de78e27 100644 (file)
@@ -53,6 +53,25 @@ chDomainAddDisk(virCHMonitor *mon,
     return 0;
 }
 
+
+static int
+chDomainAddNet(virCHDriver *driver,
+               virCHMonitor *mon,
+               virDomainObj *vm,
+               virDomainNetDef *net)
+{
+    chAssignDeviceNetAlias(vm->def, net);
+
+    if (chProcessAddNetworkDevice(driver, mon, vm->def, net, NULL, NULL) < 0) {
+        return -1;
+    }
+
+    virDomainNetInsert(vm->def, net);
+
+    return 0;
+}
+
+
 static int
 chDomainAttachDeviceLive(virCHDriver *driver,
                          virDomainObj *vm,
@@ -75,12 +94,10 @@ chDomainAttachDeviceLive(virCHDriver *driver,
         break;
 
     case VIR_DOMAIN_DEVICE_NET:
-        if (chProcessAddNetworkDevice(driver, mon, vm->def, dev->data.net,
-                                      NULL, NULL) < 0) {
+        if (chDomainAddNet(driver, mon, vm, dev->data.net) < 0) {
             break;
         }
 
-        virDomainNetInsert(vm->def, dev->data.net);
         alias = dev->data.net->info.alias;
         dev->data.net = NULL;
         ret = 0;
index f16f2b3916cfec5412f66de2396b0f95ea331f38..29db853a7f646442d436948d192d5b7503b98e29 100644 (file)
@@ -685,7 +685,6 @@ chProcessAddNetworkDevice(virCHDriver *driver,
         return -1;
     }
 
-    chAssignDeviceNetAlias(vmdef, net);
     if (virCHMonitorBuildNetJson(net, &netJSONPayload) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                         _("Failed to build net json"));