conf: Introduce 'effectiveBootIndex' into 'virDomainDeviceInfo'

'effectiveBootIndex' is a copy of 'bootIndex' if '<boot order=' was
present and left unassigned if not. This allows hypervisor drivers to
reinterpret <os><boot> without being visible in the XML.

QEMU driver had a internal implementation for disks, which is now
replaced. Additionally this will simplify a refactor of network boot
assignment.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-10-01 15:16:57 +02:00
parent 1419044940
commit aee82fe616
5 changed files with 16 additions and 19 deletions

View File

@ -149,6 +149,10 @@ struct _virDomainDeviceInfo {
/* bootIndex is only used for disk, network interface, hostdev
* and redirdev devices */
unsigned int bootIndex;
/* 'effectiveBootIndex' is same as 'bootIndex' (if provided in the XML) but
* not formatted back. This allows HV drivers to update it if <os><boot ..
* is present. */
unsigned int effectiveBootIndex;
/* Valid for any PCI device. Can be used for NIC to get
* stable numbering in Linux */
unsigned int acpiIndex;

View File

@ -6498,6 +6498,8 @@ virDomainDeviceBootParseXML(xmlNodePtr node,
&info->bootIndex) < 0)
return -1;
info->effectiveBootIndex = info->bootIndex;
loadparm = virXMLPropString(node, "loadparm");
if (loadparm) {
if (virStringToUpper(&info->loadparm, loadparm) != 1) {

View File

@ -1869,7 +1869,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
virDomainDiskDef *disk,
virQEMUCaps *qemuCaps)
{
qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
const char *contAlias;
g_autofree char *backendAlias = NULL;
@ -2072,8 +2071,8 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
virBufferAsprintf(&opt, ",id=%s", disk->info.alias);
/* bootindex for floppies is configured via the fdc controller */
if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
diskPriv->effectiveBootindex > 0)
virBufferAsprintf(&opt, ",bootindex=%u", diskPriv->effectiveBootindex);
disk->info.effectiveBootIndex > 0)
virBufferAsprintf(&opt, ",bootindex=%u", disk->info.effectiveBootIndex);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKIO)) {
if (disk->blockio.logical_block_size > 0)
virBufferAsprintf(&opt, ",logical_block_size=%u",
@ -2187,7 +2186,6 @@ 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;
@ -2199,9 +2197,9 @@ qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd,
else
driveLetter = 'A';
if (diskPriv->effectiveBootindex > 0)
if (disk->info.effectiveBootIndex > 0)
bootindexStr = g_strdup_printf("bootindex%c=%u", driveLetter,
diskPriv->effectiveBootindex);
disk->info.effectiveBootIndex);
/* with -blockdev we setup the floppy device and it's backend with -device */
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {

View File

@ -270,10 +270,6 @@ 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 */
bool transientOverlayCreated; /* the overlay image of a transient disk was
created and the definition was updated */
};

View File

@ -6271,6 +6271,9 @@ qemuProcessPrepareDomainDiskBootorder(virDomainDef *def)
unsigned int bootFloppy = 0;
unsigned int bootDisk = 0;
if (def->os.nBootDevs == 0)
return;
for (i = 0; i < def->os.nBootDevs; i++) {
switch ((virDomainBootOrder) def->os.bootDevs[i]) {
case VIR_DOMAIN_BOOT_CDROM:
@ -6295,27 +6298,21 @@ qemuProcessPrepareDomainDiskBootorder(virDomainDef *def)
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;
disk->info.effectiveBootIndex = bootCD;
bootCD = 0;
break;
case VIR_DOMAIN_DISK_DEVICE_DISK:
case VIR_DOMAIN_DISK_DEVICE_LUN:
diskPriv->effectiveBootindex = bootDisk;
disk->info.effectiveBootIndex = bootDisk;
bootDisk = 0;
break;
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
diskPriv->effectiveBootindex = bootFloppy;
disk->info.effectiveBootIndex = bootFloppy;
bootFloppy = 0;
break;