[PATCH 5/7] qemu: Support update net's bootindex

Jiang Jiacheng jiangjiacheng at huawei.com
Thu Nov 17 02:05:31 UTC 2022


Support to update the net's bootindex using 'virsh update-device'.
Using flag --config or --persistent to change the boot index and the
change will be affected after reboot. With --persistent, we can get
the result of change immediently, but it still takes effect after reboot.

Signed-off-by: Jiang Jiacheng <jiangjiacheng at huawei.com>
---
 src/qemu/qemu_driver.c  |  4 ++++
 src/qemu/qemu_hotplug.c | 17 ++++++++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 65abc04998..863b779514 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7568,6 +7568,10 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef,
                                          false) < 0)
             return -1;
 
+        if (qemuCheckBootIndex(&vmdef->nets[pos]->info,
+                               net->info.bootIndex) < 0)
+            return -1;
+
         if (virDomainNetUpdate(vmdef, pos, net))
             return -1;
 
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index da92ced2f4..5d1913d0c7 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3468,6 +3468,7 @@ qemuDomainChangeNet(virQEMUDriver *driver,
     bool needCoalesceChange = false;
     bool needVlanUpdate = false;
     bool needIsolatedPortChange = false;
+    int needChangeIndex = 0;
     int ret = -1;
     int changeidx = -1;
     g_autoptr(virConnect) conn = NULL;
@@ -3633,11 +3634,8 @@ qemuDomainChangeNet(virQEMUDriver *driver,
         goto cleanup;
     }
 
-    if (newdev->info.bootIndex == 0)
-        newdev->info.bootIndex = olddev->info.bootIndex;
-    if (olddev->info.bootIndex != newdev->info.bootIndex) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("cannot modify network device boot index setting"));
+    if ((needChangeIndex = qemuCheckBootIndex(&olddev->info,
+                                              newdev->info.bootIndex)) < 0) {
         goto cleanup;
     }
 
@@ -3918,6 +3916,15 @@ qemuDomainChangeNet(virQEMUDriver *driver,
         needReplaceDevDef = true;
     }
 
+    if (needChangeIndex) {
+        if (qemuDomainChangeBootIndex(vm, &olddev->info, newdev->info.bootIndex) < 0)
+            goto cleanup;
+        /* we successfully switched to the new boot index, and we've
+         * determined that the rest of newdev is equivalent to olddev,
+         * so move newdev into place */
+        needReplaceDevDef = true;
+    }
+
     if (needReplaceDevDef) {
         /* the changes above warrant replacing olddev with newdev in
          * the domain's nets list.
-- 
2.33.0



More information about the libvir-list mailing list