qemu: Move bootindex usage logic into qemuBuildDiskDeviceStr

We can skip the formatting of the bootindex for floppies directly at the
place where it's being formatted.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Peter Krempa 2021-04-30 16:09:09 +02:00
parent 2976b6aaeb
commit 4130cc1f7b
3 changed files with 9 additions and 17 deletions

View File

@ -1659,9 +1659,9 @@ qemuBuildDriveDevCacheStr(virDomainDiskDef *disk,
char * char *
qemuBuildDiskDeviceStr(const virDomainDef *def, qemuBuildDiskDeviceStr(const virDomainDef *def,
virDomainDiskDef *disk, virDomainDiskDef *disk,
unsigned int bootindex,
virQEMUCaps *qemuCaps) virQEMUCaps *qemuCaps)
{ {
qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
const char *contAlias; const char *contAlias;
g_autofree char *backendAlias = NULL; g_autofree char *backendAlias = NULL;
@ -1876,8 +1876,10 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
} }
virBufferAsprintf(&opt, ",id=%s", disk->info.alias); virBufferAsprintf(&opt, ",id=%s", disk->info.alias);
if (bootindex) /* bootindex for floppies is configured via the fdc controller */
virBufferAsprintf(&opt, ",bootindex=%u", bootindex); if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
diskPriv->effectiveBootindex > 0)
virBufferAsprintf(&opt, ",bootindex=%u", diskPriv->effectiveBootindex);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKIO)) { if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKIO)) {
if (disk->blockio.logical_block_size > 0) if (disk->blockio.logical_block_size > 0)
virBufferAsprintf(&opt, ",logical_block_size=%u", virBufferAsprintf(&opt, ",logical_block_size=%u",
@ -2164,8 +2166,7 @@ static int
qemuBuildDiskCommandLine(virCommand *cmd, qemuBuildDiskCommandLine(virCommand *cmd,
const virDomainDef *def, const virDomainDef *def,
virDomainDiskDef *disk, virDomainDiskDef *disk,
virQEMUCaps *qemuCaps, virQEMUCaps *qemuCaps)
unsigned int bootindex)
{ {
g_autofree char *optstr = NULL; g_autofree char *optstr = NULL;
@ -2188,8 +2189,7 @@ qemuBuildDiskCommandLine(virCommand *cmd,
virCommandAddArg(cmd, "-device"); virCommandAddArg(cmd, "-device");
if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex, if (!(optstr = qemuBuildDiskDeviceStr(def, disk, qemuCaps)))
qemuCaps)))
return -1; return -1;
virCommandAddArg(cmd, optstr); virCommandAddArg(cmd, optstr);
@ -2213,15 +2213,8 @@ qemuBuildDisksCommandLine(virCommand *cmd,
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
virDomainDiskDef *disk = def->disks[i]; virDomainDiskDef *disk = def->disks[i];
qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
unsigned int bootindex = 0;
/* The floppy device itself does not support the bootindex property if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps) < 0)
* so we need to set it up for the controller */
if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY)
bootindex = diskPriv->effectiveBootindex;
if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps, bootindex) < 0)
return -1; return -1;
} }

View File

@ -146,7 +146,6 @@ qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSource *top,
char char
*qemuBuildDiskDeviceStr(const virDomainDef *def, *qemuBuildDiskDeviceStr(const virDomainDef *def,
virDomainDiskDef *disk, virDomainDiskDef *disk,
unsigned int bootindex,
virQEMUCaps *qemuCaps); virQEMUCaps *qemuCaps);
/* Current, best practice */ /* Current, best practice */

View File

@ -734,7 +734,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriver *driver,
goto cleanup; goto cleanup;
} }
if (!(devstr = qemuBuildDiskDeviceStr(vm->def, disk, 0, priv->qemuCaps))) if (!(devstr = qemuBuildDiskDeviceStr(vm->def, disk, priv->qemuCaps)))
goto cleanup; goto cleanup;
VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1); VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1);