mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 10:35:20 +00:00
qemuBuildFloppyCommandLineControllerOptions: Extract formatting of implicit/explicit fdc
qemuBuildFloppyCommandLineControllerOptions was generating config for both the implicit and explicit fdc. The explicit FDC is using '-device' and thus will need to be converted to JSON. Split up the lookup of the floppy drive configs from the actual command generation. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
9e359909d5
commit
245e8a12fd
@ -2153,23 +2153,79 @@ qemuCommandAddExtDevice(virCommand *cmd,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
qemuBuildFloppyCommandLineControllerOptionsImplicit(virCommand *cmd,
|
||||||
|
unsigned int bootindexA,
|
||||||
|
unsigned int bootindexB,
|
||||||
|
const char *backendA,
|
||||||
|
const char *backendB)
|
||||||
|
{
|
||||||
|
if (backendA) {
|
||||||
|
virCommandAddArg(cmd, "-global");
|
||||||
|
virCommandAddArgFormat(cmd, "isa-fdc.driveA=%s", backendA);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bootindexA > 0) {
|
||||||
|
virCommandAddArg(cmd, "-global");
|
||||||
|
virCommandAddArgFormat(cmd, "isa-fdc.bootindexA=%u", bootindexA);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backendB) {
|
||||||
|
virCommandAddArg(cmd, "-global");
|
||||||
|
virCommandAddArgFormat(cmd, "isa-fdc.driveB=%s", backendB);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bootindexB > 0) {
|
||||||
|
virCommandAddArg(cmd, "-global");
|
||||||
|
virCommandAddArgFormat(cmd, "isa-fdc.bootindexB=%u", bootindexB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
qemuBuildFloppyCommandLineControllerOptionsExplicit(virCommand *cmd,
|
||||||
|
unsigned int bootindexA,
|
||||||
|
unsigned int bootindexB,
|
||||||
|
const char *backendA,
|
||||||
|
const char *backendB)
|
||||||
|
{
|
||||||
|
g_auto(virBuffer) fdc_opts = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
|
virBufferAddLit(&fdc_opts, "isa-fdc,");
|
||||||
|
|
||||||
|
if (backendA)
|
||||||
|
virBufferAsprintf(&fdc_opts, "driveA=%s,", backendA);
|
||||||
|
|
||||||
|
if (bootindexA > 0)
|
||||||
|
virBufferAsprintf(&fdc_opts, "bootindexA=%u,", bootindexA);
|
||||||
|
|
||||||
|
if (backendB)
|
||||||
|
virBufferAsprintf(&fdc_opts, "driveB=%s,", backendB);
|
||||||
|
|
||||||
|
if (bootindexB > 0)
|
||||||
|
virBufferAsprintf(&fdc_opts, "bootindexB=%u,", bootindexB);
|
||||||
|
|
||||||
|
virBufferTrim(&fdc_opts, ",");
|
||||||
|
virCommandAddArg(cmd, "-device");
|
||||||
|
virCommandAddArgBuffer(cmd, &fdc_opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd,
|
qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd,
|
||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
virQEMUCaps *qemuCaps)
|
virQEMUCaps *qemuCaps)
|
||||||
{
|
{
|
||||||
g_auto(virBuffer) fdc_opts = VIR_BUFFER_INITIALIZER;
|
unsigned int bootindexA = 0;
|
||||||
bool explicitfdc = qemuDomainNeedsFDC(def);
|
unsigned int bootindexB = 0;
|
||||||
|
g_autofree char *backendA = NULL;
|
||||||
|
g_autofree char *backendB = NULL;
|
||||||
bool hasfloppy = false;
|
bool hasfloppy = false;
|
||||||
char driveLetter;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
virBufferAddLit(&fdc_opts, "isa-fdc,");
|
|
||||||
|
|
||||||
for (i = 0; i < def->ndisks; i++) {
|
for (i = 0; i < def->ndisks; i++) {
|
||||||
g_autofree char *backendAlias = NULL;
|
g_autofree char *backendAlias = NULL;
|
||||||
g_autofree char *backendStr = NULL;
|
|
||||||
g_autofree char *bootindexStr = NULL;
|
|
||||||
virDomainDiskDef *disk = def->disks[i];
|
virDomainDiskDef *disk = def->disks[i];
|
||||||
|
|
||||||
if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC)
|
if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC)
|
||||||
@ -2177,45 +2233,35 @@ qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd,
|
|||||||
|
|
||||||
hasfloppy = true;
|
hasfloppy = true;
|
||||||
|
|
||||||
if (disk->info.addr.drive.unit)
|
|
||||||
driveLetter = 'B';
|
|
||||||
else
|
|
||||||
driveLetter = 'A';
|
|
||||||
|
|
||||||
if (disk->info.effectiveBootIndex > 0)
|
|
||||||
bootindexStr = g_strdup_printf("bootindex%c=%u", driveLetter,
|
|
||||||
disk->info.effectiveBootIndex);
|
|
||||||
|
|
||||||
/* with -blockdev we setup the floppy device and it's backend with -device */
|
/* with -blockdev we setup the floppy device and it's backend with -device */
|
||||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
|
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) &&
|
||||||
if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlias) < 0)
|
qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlias) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (backendAlias)
|
if (disk->info.addr.drive.unit) {
|
||||||
backendStr = g_strdup_printf("drive%c=%s", driveLetter, backendAlias);
|
bootindexB = disk->info.effectiveBootIndex;
|
||||||
}
|
backendB = g_steal_pointer(&backendAlias);
|
||||||
|
|
||||||
if (!explicitfdc) {
|
|
||||||
if (backendStr) {
|
|
||||||
virCommandAddArg(cmd, "-global");
|
|
||||||
virCommandAddArgFormat(cmd, "isa-fdc.%s", backendStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bootindexStr) {
|
|
||||||
virCommandAddArg(cmd, "-global");
|
|
||||||
virCommandAddArgFormat(cmd, "isa-fdc.%s", bootindexStr);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
virBufferStrcat(&fdc_opts, backendStr, ",", NULL);
|
bootindexA = disk->info.effectiveBootIndex;
|
||||||
virBufferStrcat(&fdc_opts, bootindexStr, ",", NULL);
|
backendA = g_steal_pointer(&backendAlias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (explicitfdc && hasfloppy) {
|
if (!hasfloppy)
|
||||||
/* Newer Q35 machine types require an explicit FDC controller */
|
return 0;
|
||||||
virBufferTrim(&fdc_opts, ",");
|
|
||||||
virCommandAddArg(cmd, "-device");
|
if (qemuDomainNeedsFDC(def)) {
|
||||||
virCommandAddArgBuffer(cmd, &fdc_opts);
|
qemuBuildFloppyCommandLineControllerOptionsExplicit(cmd,
|
||||||
|
bootindexA,
|
||||||
|
bootindexB,
|
||||||
|
backendA,
|
||||||
|
backendB);
|
||||||
|
} else {
|
||||||
|
qemuBuildFloppyCommandLineControllerOptionsImplicit(cmd,
|
||||||
|
bootindexA,
|
||||||
|
bootindexB,
|
||||||
|
backendA,
|
||||||
|
backendB);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user