[PATCH V3 6/7] qemu: Support set bootindex to 0 to cancel bootindex setting

Jiang Jiacheng jiangjiacheng at huawei.com
Sat Dec 24 14:09:23 UTC 2022


Support set bootindex to 0, which means cancel the previous
bootindex setting. We get bootindex = 0 if the bootindex isn't
set or specified to 0 in the device's xml, and is used with
'bootIndexSpecified'.
Support format <boot order = '0'\> into xml when bootIndexSpecified
is true wo keep the bootindex still changeble.
Support set multiple bootindex = 0, and boot in a Qemu's default
sequence 'disk->cdrom->net' if all devices' bootindex is set to 0;

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

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7f045b0d4a..90881f7dfe 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5146,7 +5146,11 @@ 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)
@@ -5308,8 +5312,7 @@ 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;
 
diff --git a/src/conf/domain_postparse.c b/src/conf/domain_postparse.c
index 9a3e8f494c..2ba3186561 100644
--- a/src/conf/domain_postparse.c
+++ b/src/conf/domain_postparse.c
@@ -1031,7 +1031,7 @@ virDomainDefCollectBootOrder(virDomainDef *def G_GNUC_UNUSED,
     GHashTable *bootHash = data;
     g_autofree char *order = NULL;
 
-    if (info->bootIndex == 0)
+    if (info->bootIndex == 0 && !info->bootIndexSpecified)
         return 0;
 
     if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
@@ -1045,6 +1045,12 @@ virDomainDefCollectBootOrder(virDomainDef *def G_GNUC_UNUSED,
     order = g_strdup_printf("%u", info->bootIndex);
 
     if (virHashLookup(bootHash, order)) {
+        /* 0 in the bootHash means cancel the bootIndex specified in
+         * XML, so it allowed to make more than one device use 0 with
+         * its bootIndexSpecified = true.
+         */
+        if (info->bootIndex == 0)
+            return 0;
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("boot order '%s' used for more than one device"),
                        order);
-- 
2.33.0



More information about the libvir-list mailing list