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(a)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 d5fa9c022c..633abdcbca 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7596,6 +7596,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 6e300f547c..af0cec3c46 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