[PATCH 2/7] qemu: Add bootIndexSpecified and support set bootIndex to '0'

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


Add a bool bootIndexSpecified into _virDomainDeviceInfo, which means whether
the bootindex could be update or not. BootIndexSpecified will be set to
true if bootindex is set in XML.
Support set bootindex to 0, which means cancel the previous bootindex setting,
and format boot order = '0' into XML when its bootIndexSpecified is true to
keep its bootindex changeble.

Signed-off-by: Jiang Jiacheng <jiangjiacheng at huawei.com>
---
 src/conf/device_conf.h | 3 +++
 src/conf/domain_conf.c | 9 ++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f2907dc596..5259e25c10 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -144,6 +144,9 @@ struct _virDomainDeviceInfo {
      * not formatted back. This allows HV drivers to update it if <os><boot ..
      * is present. */
     unsigned int effectiveBootIndex;
+    /* bootIndexSpecified is set to true when device's bootIndex is provided in
+     * the XML. This allows changing bootIndex online of some devices. */
+    bool bootIndexSpecified;
     /* Valid for any PCI device. Can be used for NIC to get
      * stable numbering in Linux */
     unsigned int acpiIndex;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3790121cf7..dcd9696a93 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5142,7 +5142,10 @@ virDomainDeviceInfoFormat(virBuffer *buf,
     g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
     g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
 
-    if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) {
+    if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && (info->bootIndex || info->bootIndexSpecified)) {
+        /* format the boot order = 0 in XML when its bootIndexSpecified is true,
+         * which means the boot order could be changed by virsh update-device.
+         */
         virBufferAsprintf(buf, "<boot order='%u'", info->bootIndex);
 
         if (info->loadparm)
@@ -5304,12 +5307,12 @@ virDomainDeviceBootParseXML(xmlNodePtr node,
 {
     g_autofree char *loadparm = NULL;
 
-    if (virXMLPropUInt(node, "order", 10,
-                       VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+    if (virXMLPropUInt(node, "order", 10, VIR_XML_PROP_REQUIRED,
                        &info->bootIndex) < 0)
         return -1;
 
     info->effectiveBootIndex = info->bootIndex;
+    info->bootIndexSpecified = true;
 
     loadparm = virXMLPropString(node, "loadparm");
     if (loadparm) {
-- 
2.33.0



More information about the libvir-list mailing list