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

Jiang Jiacheng posted 7 patches 3 years, 2 months ago
There is a newer version of this series
[PATCH 7/7] qemu: Reserve bootIndexSpecified when update device
Posted by Jiang Jiacheng 3 years, 2 months ago
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@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
Re: [PATCH 7/7] qemu: Reserve bootIndexSpecified when update device
Posted by Peter Krempa 3 years, 2 months ago
On Thu, Nov 17, 2022 at 10:05:33 +0800, Jiang Jiacheng wrote:
> 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@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(+)

Rather than doing this qemuDomainUpdateDeviceFlags can parse the XML
twice as it's acutally less work than invoking the copy function (Which
re-formats the XML and parses it again). I'll post patches to adress
that in qemuDomainUpdateDeviceFlags. You can drop this patch.
Re: [PATCH 7/7] qemu: Reserve bootIndexSpecified when update device
Posted by Jiang Jiacheng 3 years, 2 months ago

On 2022/11/22 23:53, Peter Krempa wrote:
> On Thu, Nov 17, 2022 at 10:05:33 +0800, Jiang Jiacheng wrote:
>> 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@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(+)
> 
> Rather than doing this qemuDomainUpdateDeviceFlags can parse the XML
> twice as it's acutally less work than invoking the copy function (Which
> re-formats the XML and parses it again). I'll post patches to adress
> that in qemuDomainUpdateDeviceFlags. You can drop this patch.
> 
Thanks for your review and suggetions, I will improve my patches in next
version.