[PATCH 7/7] qemu: Reserve bootIndexSpecified when update device

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


If the 'boot order' is not specified in the xml, we cancel its
bootindex setting and set it to '0'. However, the bootIndexSpecified
will be set to false because we cannot parse boot order from XML,
so copy bootIndexSpecified from origin device when updating it.

Signed-off-by: Jiang Jiacheng <jiangjiacheng at huawei.com>
---
 src/qemu/qemu_conf.c   | 33 +++++++++++++++++++++++++++++++++
 src/qemu/qemu_conf.h   |  4 ++++
 src/qemu/qemu_driver.c |  3 +++
 3 files changed, 40 insertions(+)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 9a7992db01..517fc813f2 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1748,3 +1748,36 @@ qemuChangeDiskBootIndex(virDomainObj *vm,
     }
     return 0;
 }
+
+/**
+ * qemuDomainDefCopyBootState:
+ * @dev: pointer to device parsed from xml
+ * @vmdef: pointer to vm definition structure
+ *
+ * copy the bootIndexSpecified from vmDef's device info
+ *
+ * Returns: 0 on success or no need to copy
+ *          -1 on fail to find the device
+ */
+int
+qemuDomainDefCopyBootState(virDomainDeviceDef *dev, virDomainDef *vmDef)
+{
+    int idx = -1;
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
+        if ((idx = virDomainDiskIndexByName(vmDef, dev->data.disk->dst, false)) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("target %s doesn't exist."), dev->data.disk->info.alias);
+            return -1;
+        }
+        dev->data.disk->info.bootIndexSpecified = vmDef->disks[idx]->info.bootIndexSpecified;
+    }
+    if (dev->type == VIR_DOMAIN_DEVICE_NET) {
+        if ((idx = virDomainNetFindIdx(vmDef, dev->data.net)) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("target %s doesn't exist."), dev->data.net->info.alias);
+            return -1;
+        }
+        dev->data.net->info.bootIndexSpecified = vmDef->nets[idx]->info.bootIndexSpecified;
+    }
+    return 0;
+}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 5b05a7392b..c1e9a2120f 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -387,3 +387,7 @@ int qemuCheckBootIndex(virDomainDeviceInfo *devInfo,
 int qemuChangeDiskBootIndex(virDomainObj *vm,
                             virDomainDiskDef *orig_disk,
                             virDomainDiskDef *disk);
+
+
+int qemuDomainDefCopyBootState(virDomainDeviceDef *dev,
+                               virDomainDef *vmDef);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 863b779514..3dbf95041e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7841,6 +7841,9 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
     if (dev == NULL)
         goto endjob;
 
+    if (qemuDomainDefCopyBootState(dev, vm->def) < 0)
+        goto endjob;
+
     if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
         flags & VIR_DOMAIN_AFFECT_LIVE) {
         /* If we are affecting both CONFIG and LIVE
-- 
2.33.0



More information about the libvir-list mailing list