Skip to content

Commit

Permalink
qemu: command: Extract formatting of floppy related stuff into a helper
Browse files Browse the repository at this point in the history
The floppy command formatting is special-cased since it does not
directly translate to a single '-device' argument.

Move the code from qemuBuildDiskDriveCommandLine to a new helper
function so that all the related code is together.

Signed-off-by: Peter Krempa <[email protected]>
  • Loading branch information
pipo committed Feb 12, 2018
1 parent 60a95e5 commit 42fd5a5
Showing 1 changed file with 54 additions and 37 deletions.
91 changes: 54 additions & 37 deletions src/qemu/qemu_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,58 @@ qemuBuildDriveDevStr(const virDomainDef *def,
}


static int
qemuBulildFloppyCommandLineOptions(virCommandPtr cmd,
const virDomainDef *def,
virDomainDiskDefPtr disk,
unsigned int bootindex)

{
virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
char *fdc_opts_str = NULL;
char *optstr;

if (virAsprintf(&optstr, "drive%c=drive-%s",
disk->info.addr.drive.unit ? 'B' : 'A',
disk->info.alias) < 0)
return -1;

if (!qemuDomainNeedsFDC(def)) {
virCommandAddArg(cmd, "-global");
virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
} else {
virBufferAsprintf(&fdc_opts, "%s,", optstr);
}
VIR_FREE(optstr);

if (bootindex) {
if (virAsprintf(&optstr, "bootindex%c=%u",
disk->info.addr.drive.unit
? 'B' : 'A',
bootindex) < 0)
return -1;

if (!qemuDomainNeedsFDC(def)) {
virCommandAddArg(cmd, "-global");
virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
} else {
virBufferAsprintf(&fdc_opts, "%s,", optstr);
}
VIR_FREE(optstr);
}

/* Newer Q35 machine types require an explicit FDC controller */
virBufferTrim(&fdc_opts, ",", -1);
if ((fdc_opts_str = virBufferContentAndReset(&fdc_opts))) {
virCommandAddArg(cmd, "-device");
virCommandAddArgFormat(cmd, "isa-fdc,%s", fdc_opts_str);
VIR_FREE(fdc_opts_str);
}

return 0;
}


static int
qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
const virDomainDef *def,
Expand All @@ -2219,8 +2271,6 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
unsigned int bootCD = 0;
unsigned int bootFloppy = 0;
unsigned int bootDisk = 0;
virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
char *fdc_opts_str = NULL;

if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_BOOT) ||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX)) {
Expand Down Expand Up @@ -2299,34 +2349,9 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,

if (qemuDiskBusNeedsDeviceArg(disk->bus)) {
if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC) {
if (virAsprintf(&optstr, "drive%c=drive-%s",
disk->info.addr.drive.unit ? 'B' : 'A',
disk->info.alias) < 0)
if (qemuBulildFloppyCommandLineOptions(cmd, def, disk,
bootindex) < 0)
return -1;

if (!qemuDomainNeedsFDC(def)) {
virCommandAddArg(cmd, "-global");
virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
} else {
virBufferAsprintf(&fdc_opts, "%s,", optstr);
}
VIR_FREE(optstr);

if (bootindex) {
if (virAsprintf(&optstr, "bootindex%c=%u",
disk->info.addr.drive.unit
? 'B' : 'A',
bootindex) < 0)
return -1;

if (!qemuDomainNeedsFDC(def)) {
virCommandAddArg(cmd, "-global");
virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
} else {
virBufferAsprintf(&fdc_opts, "%s,", optstr);
}
VIR_FREE(optstr);
}
} else {
virCommandAddArg(cmd, "-device");

Expand All @@ -2338,14 +2363,6 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
}
}
}
/* Newer Q35 machine types require an explicit FDC controller */
virBufferTrim(&fdc_opts, ",", -1);
if ((fdc_opts_str = virBufferContentAndReset(&fdc_opts))) {
virCommandAddArg(cmd, "-device");
virCommandAddArgFormat(cmd, "isa-fdc,%s", fdc_opts_str);
VIR_FREE(fdc_opts_str);
}

return 0;
}

Expand Down

0 comments on commit 42fd5a5

Please sign in to comment.