The logic assigning the bootindices from the legacy boot orded
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(a)redhat.com>
---
src/qemu/qemu_command.c | 63 +++++++--------------------------------
src/qemu/qemu_domain.h | 4 +++
src/qemu/qemu_process.c | 66 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+), 53 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index dcc060bde9..b01421f61b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 2626f5dcaa..4fc1969d9e 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -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) \
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d743a581b3..7fe051505b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6290,6 +6290,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,
@@ -6316,6 +6380,8 @@ qemuProcessPrepareDomainStorage(virQEMUDriver *driver,
return -1;
}
+ qemuProcessPrepareDomainDiskBootorder(vm->def);
+
return 0;
}
--
2.31.1