|
|
6ae9ed |
From 74ff94fbfdf3ab656fa5a124dd4c7254167cf181 Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <74ff94fbfdf3ab656fa5a124dd4c7254167cf181@dist-git>
|
|
|
6ae9ed |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
6ae9ed |
Date: Tue, 2 Aug 2016 13:41:59 +0200
|
|
|
6ae9ed |
Subject: [PATCH] qemu: command: Extract drive source command line formatter
|
|
|
6ae9ed |
|
|
|
6ae9ed |
The disk source formatting code grew rather ugly and complex and it will
|
|
|
6ae9ed |
get worse. Extract it into a separated function to contain the mess.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
(cherry picked from commit 3678d42705b76e8e47012cf0b8e23053598a2f5e)
|
|
|
6ae9ed |
https://bugzilla.redhat.com/show_bug.cgi?id=1247521 [gluster multi-host]
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
src/qemu/qemu_command.c | 159 ++++++++++++++++++++++++++----------------------
|
|
|
6ae9ed |
1 file changed, 87 insertions(+), 72 deletions(-)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
index 32f8384..bb40832 100644
|
|
|
6ae9ed |
--- a/src/qemu/qemu_command.c
|
|
|
6ae9ed |
+++ b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
@@ -1093,6 +1093,92 @@ qemuDiskBusNeedsDeviceArg(int bus)
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
|
|
|
6ae9ed |
+static int
|
|
|
6ae9ed |
+qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
+ virBufferPtr buf)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ int actualType = virStorageSourceGetActualType(disk->src);
|
|
|
6ae9ed |
+ qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
|
|
6ae9ed |
+ qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
|
|
|
6ae9ed |
+ qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
|
|
|
6ae9ed |
+ char *source = NULL;
|
|
|
6ae9ed |
+ int ret = -1;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (source &&
|
|
|
6ae9ed |
+ !((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
|
|
|
6ae9ed |
+ disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
|
|
|
6ae9ed |
+ disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ virBufferAddLit(buf, "file=");
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ switch (actualType) {
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_DIR:
|
|
|
6ae9ed |
+ /* QEMU only supports magic FAT format for now */
|
|
|
6ae9ed |
+ if (disk->src->format > 0 &&
|
|
|
6ae9ed |
+ disk->src->format != VIR_STORAGE_FILE_FAT) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
6ae9ed |
+ _("unsupported disk driver type for '%s'"),
|
|
|
6ae9ed |
+ virStorageFileFormatTypeToString(disk->src->format));
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (!disk->src->readonly) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
6ae9ed |
+ _("cannot create virtual FAT disks in read-write mode"));
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ virBufferAddLit(buf, "fat:");
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
|
|
|
6ae9ed |
+ virBufferAddLit(buf, "floppy:");
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_BLOCK:
|
|
|
6ae9ed |
+ if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
6ae9ed |
+ disk->src->type == VIR_STORAGE_TYPE_VOLUME ?
|
|
|
6ae9ed |
+ _("tray status 'open' is invalid for block type volume") :
|
|
|
6ae9ed |
+ _("tray status 'open' is invalid for block type disk"));
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ default:
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ virQEMUBuildBufferEscapeComma(buf, source);
|
|
|
6ae9ed |
+ virBufferAddLit(buf, ",");
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
|
|
|
6ae9ed |
+ virBufferAsprintf(buf, "password-secret=%s,",
|
|
|
6ae9ed |
+ secinfo->s.aes.alias);
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (encinfo)
|
|
|
6ae9ed |
+ virQEMUBuildLuksOpts(buf, &disk->src->encryption->encinfo,
|
|
|
6ae9ed |
+ encinfo->s.aes.alias);
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (disk->src->format > 0 &&
|
|
|
6ae9ed |
+ disk->src->type != VIR_STORAGE_TYPE_DIR)
|
|
|
6ae9ed |
+ virBufferAsprintf(buf, "format=%s,",
|
|
|
6ae9ed |
+ virStorageFileFormatTypeToString(disk->src->format));
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ ret = 0;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ cleanup:
|
|
|
6ae9ed |
+ VIR_FREE(source);
|
|
|
6ae9ed |
+ return ret;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
char *
|
|
|
6ae9ed |
qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
bool bootable,
|
|
|
6ae9ed |
@@ -1104,11 +1190,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
virDomainDiskGeometryTransTypeToString(disk->geometry.trans);
|
|
|
6ae9ed |
int idx = virDiskNameToIndex(disk->dst);
|
|
|
6ae9ed |
int busid = -1, unitid = -1;
|
|
|
6ae9ed |
- char *source = NULL;
|
|
|
6ae9ed |
- int actualType = virStorageSourceGetActualType(disk->src);
|
|
|
6ae9ed |
- qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
|
|
6ae9ed |
- qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
|
|
|
6ae9ed |
- qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
|
|
|
6ae9ed |
bool emitDeviceSyntax = qemuDiskBusNeedsDeviceArg(disk->bus);
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (idx < 0) {
|
|
|
6ae9ed |
@@ -1191,74 +1272,9 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
break;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- if (qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
|
|
|
6ae9ed |
+ if (qemuBuildDriveSourceStr(disk, &opt) < 0)
|
|
|
6ae9ed |
goto error;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- if (source &&
|
|
|
6ae9ed |
- !((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
|
|
|
6ae9ed |
- disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
|
|
|
6ae9ed |
- disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- virBufferAddLit(&opt, "file=");
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- switch (actualType) {
|
|
|
6ae9ed |
- case VIR_STORAGE_TYPE_DIR:
|
|
|
6ae9ed |
- /* QEMU only supports magic FAT format for now */
|
|
|
6ae9ed |
- if (disk->src->format > 0 &&
|
|
|
6ae9ed |
- disk->src->format != VIR_STORAGE_FILE_FAT) {
|
|
|
6ae9ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
6ae9ed |
- _("unsupported disk driver type for '%s'"),
|
|
|
6ae9ed |
- virStorageFileFormatTypeToString(disk->src->format));
|
|
|
6ae9ed |
- goto error;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (!disk->src->readonly) {
|
|
|
6ae9ed |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
6ae9ed |
- _("cannot create virtual FAT disks in read-write mode"));
|
|
|
6ae9ed |
- goto error;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- virBufferAddLit(&opt, "fat:");
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
|
|
|
6ae9ed |
- virBufferAddLit(&opt, "floppy:");
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- break;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- case VIR_STORAGE_TYPE_BLOCK:
|
|
|
6ae9ed |
- if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) {
|
|
|
6ae9ed |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
6ae9ed |
- disk->src->type == VIR_STORAGE_TYPE_VOLUME ?
|
|
|
6ae9ed |
- _("tray status 'open' is invalid for block type volume") :
|
|
|
6ae9ed |
- _("tray status 'open' is invalid for block type disk"));
|
|
|
6ae9ed |
- goto error;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- break;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- default:
|
|
|
6ae9ed |
- break;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- virQEMUBuildBufferEscapeComma(&opt, source);
|
|
|
6ae9ed |
- virBufferAddLit(&opt, ",");
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
|
|
|
6ae9ed |
- virBufferAsprintf(&opt, "password-secret=%s,",
|
|
|
6ae9ed |
- secinfo->s.aes.alias);
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (encinfo)
|
|
|
6ae9ed |
- virQEMUBuildLuksOpts(&opt, &disk->src->encryption->encinfo,
|
|
|
6ae9ed |
- encinfo->s.aes.alias);
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (disk->src->format > 0 &&
|
|
|
6ae9ed |
- disk->src->type != VIR_STORAGE_TYPE_DIR)
|
|
|
6ae9ed |
- virBufferAsprintf(&opt, "format=%s,",
|
|
|
6ae9ed |
- virStorageFileFormatTypeToString(disk->src->format));
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
- VIR_FREE(source);
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
if (emitDeviceSyntax)
|
|
|
6ae9ed |
virBufferAddLit(&opt, "if=none");
|
|
|
6ae9ed |
else
|
|
|
6ae9ed |
@@ -1581,7 +1597,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
return virBufferContentAndReset(&opt;;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
error:
|
|
|
6ae9ed |
- VIR_FREE(source);
|
|
|
6ae9ed |
virBufferFreeAndReset(&opt;;
|
|
|
6ae9ed |
return NULL;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|