On Mon, Jul 25, 2016 at 08:12:06PM +0200, Peter Krempa wrote:
Avoid a large block by tweaking the condition skipping empty drives
and
split up the switch containing two branches having different purpose.
---
src/qemu/qemu_command.c | 99 +++++++++++++++++++++++--------------------------
1 file changed, 46 insertions(+), 53 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ee7329c..3b42b73 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1107,70 +1107,63 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
if (qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
goto cleanup;
- if (source &&
- !((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
- disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
- disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
-
- virBufferAddLit(buf, "file=");
-
- switch (actualType) {
- case VIR_STORAGE_TYPE_DIR:
- /* QEMU only supports magic FAT format for now */
- if (disk->src->format > 0 &&
- disk->src->format != VIR_STORAGE_FILE_FAT) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unsupported disk driver type for
'%s'"),
-
virStorageFileFormatTypeToString(disk->src->format));
- goto cleanup;
- }
-
- if (!disk->src->readonly) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("cannot create virtual FAT disks in read-write
mode"));
- goto cleanup;
- }
-
- virBufferAddLit(buf, "fat:");
+ /* nothing to format if the drive is empty */
+ if (!source ||
+ ((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
+ disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
+ disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN))
+ return 0;
Looks like this would leak source if it's non-NULL.
Jan