]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move 'bootindex' handling for disks out of command line formatter
authorPeter Krempa <pkrempa@redhat.com>
Fri, 30 Apr 2021 06:58:45 +0000 (08:58 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 24 May 2021 18:38:07 +0000 (20:38 +0200)
The logic assigning the bootindices from the legacy boot order
configuration was spread through the command line formatters for the
disk device and for the floppy controller.

This patch adds 'effectiveBootindex' property to the disk private data
which holds the calculated boot index and moves the logic of determining
the boot index into 'qemuProcessPrepareDomainDiskBootorder' called from
'qemuProcessPrepareDomainStorage'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_command.c
src/qemu/qemu_domain.h
src/qemu/qemu_process.c

index 19c1502ee02da1a2d8375d4e4cd355332058edbe..453f24174f01df141e0befb59bdbcb25d2bbaecf 100644 (file)
@@ -1976,13 +1976,11 @@ qemuCommandAddExtDevice(virCommand *cmd,
 static int
 qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd,
                                             const virDomainDef *def,
-                                            virQEMUCaps *qemuCaps,
-                                            unsigned int bootFloppy)
+                                            virQEMUCaps *qemuCaps)
 {
     g_auto(virBuffer) fdc_opts = VIR_BUFFER_INITIALIZER;
     bool explicitfdc = qemuDomainNeedsFDC(def);
     bool hasfloppy = false;
-    unsigned int bootindex;
     char driveLetter;
     size_t i;
 
@@ -1993,26 +1991,21 @@ qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd,
         g_autofree char *backendStr = NULL;
         g_autofree char *bootindexStr = NULL;
         virDomainDiskDef *disk = def->disks[i];
+        qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
 
         if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC)
             continue;
 
         hasfloppy = true;
 
-        if (disk->info.bootIndex) {
-            bootindex = disk->info.bootIndex;
-        } else {
-            bootindex = bootFloppy;
-            bootFloppy = 0;
-        }
-
         if (disk->info.addr.drive.unit)
             driveLetter = 'B';
         else
             driveLetter = 'A';
 
-        if (bootindex)
-            bootindexStr = g_strdup_printf("bootindex%c=%u", driveLetter, bootindex);
+        if (diskPriv->effectiveBootindex > 0)
+            bootindexStr = g_strdup_printf("bootindex%c=%u", driveLetter,
+                                           diskPriv->effectiveBootindex);
 
         /* with -blockdev we setup the floppy device and it's backend with -device */
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
@@ -2210,66 +2203,30 @@ qemuBuildDisksCommandLine(virCommand *cmd,
                           virQEMUCaps *qemuCaps)
 {
     size_t i;
-    unsigned int bootCD = 0;
-    unsigned int bootFloppy = 0;
-    unsigned int bootDisk = 0;
     bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV);
 
-    for (i = 0; i < def->os.nBootDevs; i++) {
-        switch (def->os.bootDevs[i]) {
-        case VIR_DOMAIN_BOOT_CDROM:
-            bootCD = i + 1;
-            break;
-        case VIR_DOMAIN_BOOT_FLOPPY:
-            bootFloppy = i + 1;
-            break;
-        case VIR_DOMAIN_BOOT_DISK:
-            bootDisk = i + 1;
-            break;
-        }
-    }
-
     /* If we want to express the floppy drives via -device, the controller needs
      * to be instantiated prior to that */
     if (blockdev &&
-        qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, bootFloppy) < 0)
+        qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps) < 0)
         return -1;
 
     for (i = 0; i < def->ndisks; i++) {
         virDomainDiskDef *disk = def->disks[i];
+        qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
         unsigned int bootindex = 0;
 
-        if (disk->info.bootIndex) {
-            bootindex = disk->info.bootIndex;
-        } else {
-            switch (disk->device) {
-            case VIR_DOMAIN_DISK_DEVICE_CDROM:
-                bootindex = bootCD;
-                bootCD = 0;
-                break;
-            case VIR_DOMAIN_DISK_DEVICE_DISK:
-            case VIR_DOMAIN_DISK_DEVICE_LUN:
-                bootindex = bootDisk;
-                bootDisk = 0;
-                break;
-            case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
-            case VIR_DOMAIN_DISK_DEVICE_LAST:
-            default:
-                break;
-            }
-        }
-
         /* The floppy device itself does not support the bootindex property
          * so we need to set it up for the controller */
-        if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
-            bootindex = 0;
+        if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+            bootindex = diskPriv->effectiveBootindex;
 
         if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps, bootindex) < 0)
             return -1;
     }
 
     if (!blockdev &&
-        qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, bootFloppy) < 0)
+        qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps) < 0)
         return -1;
 
     return 0;
index 2626f5dcaa6ab03e6fcef00f59be2150b4965ddb..4fc1969d9ee4b635d7d5fff9ef0c1239ec235abd 100644 (file)
@@ -288,6 +288,10 @@ struct _qemuDomainDiskPrivate {
 
     char *qomName; /* QOM path of the disk (also refers to the block backend) */
     char *nodeCopyOnRead; /* nodename of the disk-wide copy-on-read blockdev layer */
+
+    unsigned int effectiveBootindex; /* boot index of the disk based on one
+                                        of the two ways we use to select a boot
+                                        device */
 };
 
 #define QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src) \
index 09202a382fd49bcb55f83de867a18eed07a8e6ac..411d55fbee695641683bfd5cb07e003fae6384ce 100644 (file)
@@ -6289,6 +6289,70 @@ qemuProcessPrepareDomainNUMAPlacement(virDomainObj *vm)
 }
 
 
+static void
+qemuProcessPrepareDomainDiskBootorder(virDomainDef *def)
+{
+    size_t i;
+    unsigned int bootCD = 0;
+    unsigned int bootFloppy = 0;
+    unsigned int bootDisk = 0;
+
+    for (i = 0; i < def->os.nBootDevs; i++) {
+        switch ((virDomainBootOrder) def->os.bootDevs[i]) {
+        case VIR_DOMAIN_BOOT_CDROM:
+            bootCD = i + 1;
+            break;
+
+        case VIR_DOMAIN_BOOT_FLOPPY:
+            bootFloppy = i + 1;
+            break;
+
+        case VIR_DOMAIN_BOOT_DISK:
+            bootDisk = i + 1;
+            break;
+
+        case VIR_DOMAIN_BOOT_NET:
+            /* network boot is handled in network device formatting code */
+        case VIR_DOMAIN_BOOT_LAST:
+        default:
+            break;
+        }
+    }
+
+    for (i = 0; i < def->ndisks; i++) {
+        virDomainDiskDef *disk = def->disks[i];
+        qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
+        if (disk->info.bootIndex > 0) {
+            diskPriv->effectiveBootindex = disk->info.bootIndex;
+            continue;
+        }
+
+        switch (disk->device) {
+        case VIR_DOMAIN_DISK_DEVICE_CDROM:
+            diskPriv->effectiveBootindex = bootCD;
+            bootCD = 0;
+            break;
+
+        case VIR_DOMAIN_DISK_DEVICE_DISK:
+        case VIR_DOMAIN_DISK_DEVICE_LUN:
+            diskPriv->effectiveBootindex = bootDisk;
+            bootDisk = 0;
+            break;
+
+        case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+            diskPriv->effectiveBootindex = bootFloppy;
+            bootFloppy = 0;
+            break;
+
+        case VIR_DOMAIN_DISK_DEVICE_LAST:
+        default:
+            break;
+        }
+    }
+}
+
+
 static int
 qemuProcessPrepareDomainStorage(virQEMUDriver *driver,
                                 virDomainObj *vm,
@@ -6315,6 +6379,8 @@ qemuProcessPrepareDomainStorage(virQEMUDriver *driver,
             return -1;
     }
 
+    qemuProcessPrepareDomainDiskBootorder(vm->def);
+
     return 0;
 }