|
|
6ae9ed |
From e1b18fb8e327e01dbc062f86d7e23e288f441228 Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <e1b18fb8e327e01dbc062f86d7e23e288f441228@dist-git>
|
|
|
6ae9ed |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
6ae9ed |
Date: Tue, 2 Aug 2016 13:42:03 +0200
|
|
|
6ae9ed |
Subject: [PATCH] qemu: command: Add infrastructure for object specified disk
|
|
|
6ae9ed |
sources
|
|
|
6ae9ed |
|
|
|
6ae9ed |
To allow richer definitions of disk sources add infrastructure that will
|
|
|
6ae9ed |
allow to register functionst generating a JSON object based definition.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
This infrastructure will then convert the definition to the proper
|
|
|
6ae9ed |
command line syntax and use it in cases where it's necessary. This will
|
|
|
6ae9ed |
allow to keep legacy definitions for back-compat when possible and use
|
|
|
6ae9ed |
the new definitions for the configurations requiring them.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
(cherry picked from commit f444101729db35979857f317f46908bea3750488)
|
|
|
6ae9ed |
https://bugzilla.redhat.com/show_bug.cgi?id=1247521 [gluster multi-host]
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
src/libvirt_private.syms | 1 +
|
|
|
6ae9ed |
src/qemu/qemu_command.c | 83 ++++++++++++++++++++++++++++++++++++------------
|
|
|
6ae9ed |
src/util/virqemu.c | 21 ++++++++++++
|
|
|
6ae9ed |
src/util/virqemu.h | 2 ++
|
|
|
6ae9ed |
4 files changed, 86 insertions(+), 21 deletions(-)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
6ae9ed |
index 533cf55..b7a1663 100644
|
|
|
6ae9ed |
--- a/src/libvirt_private.syms
|
|
|
6ae9ed |
+++ b/src/libvirt_private.syms
|
|
|
6ae9ed |
@@ -2196,6 +2196,7 @@ virQEMUBuildBufferEscapeComma;
|
|
|
6ae9ed |
virQEMUBuildCommandLineJSON;
|
|
|
6ae9ed |
virQEMUBuildCommandLineJSONArrayBitmap;
|
|
|
6ae9ed |
virQEMUBuildCommandLineJSONArrayNumbered;
|
|
|
6ae9ed |
+virQEMUBuildDriveCommandlineFromJSON;
|
|
|
6ae9ed |
virQEMUBuildLuksOpts;
|
|
|
6ae9ed |
virQEMUBuildObjectCommandlineFromJSON;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
index a3e838c..b33c39c 100644
|
|
|
6ae9ed |
--- a/src/qemu/qemu_command.c
|
|
|
6ae9ed |
+++ b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
@@ -916,6 +916,34 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
|
|
|
6ae9ed |
+static int
|
|
|
6ae9ed |
+qemuGetDriveSourceProps(virStorageSourcePtr src,
|
|
|
6ae9ed |
+ virJSONValuePtr *props)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ int actualType = virStorageSourceGetActualType(src);
|
|
|
6ae9ed |
+ virJSONValuePtr fileprops = NULL;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ *props = NULL;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ switch ((virStorageType) actualType) {
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_BLOCK:
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_FILE:
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_DIR:
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_VOLUME:
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_NONE:
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_LAST:
|
|
|
6ae9ed |
+ case VIR_STORAGE_TYPE_NETWORK:
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (fileprops &&
|
|
|
6ae9ed |
+ virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ return 0;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
int
|
|
|
6ae9ed |
qemuGetDriveSourceString(virStorageSourcePtr src,
|
|
|
6ae9ed |
qemuDomainSecretInfoPtr secinfo,
|
|
|
6ae9ed |
@@ -1101,14 +1129,19 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
|
|
6ae9ed |
qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
|
|
|
6ae9ed |
qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
|
|
|
6ae9ed |
+ virJSONValuePtr srcprops = NULL;
|
|
|
6ae9ed |
char *source = NULL;
|
|
|
6ae9ed |
int ret = -1;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- if (qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
|
|
|
6ae9ed |
+ if (qemuGetDriveSourceProps(disk->src, &srcprops) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (!srcprops &&
|
|
|
6ae9ed |
+ qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
/* nothing to format if the drive is empty */
|
|
|
6ae9ed |
- if (!source ||
|
|
|
6ae9ed |
+ if (!(source || srcprops) ||
|
|
|
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 |
@@ -1125,31 +1158,38 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- virBufferAddLit(buf, "file=");
|
|
|
6ae9ed |
+ if (source) {
|
|
|
6ae9ed |
+ virBufferAddLit(buf, "file=");
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- /* for now the DIR based storage is handled by the magic FAT format */
|
|
|
6ae9ed |
- if (actualType == VIR_STORAGE_TYPE_DIR) {
|
|
|
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 |
+ /* for now the DIR based storage is handled by the magic FAT format */
|
|
|
6ae9ed |
+ if (actualType == VIR_STORAGE_TYPE_DIR) {
|
|
|
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 |
|
|
|
6ae9ed |
- if (!disk->src->readonly) {
|
|
|
6ae9ed |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
6ae9ed |
- _("cannot create virtual FAT disks in read-write mode"));
|
|
|
6ae9ed |
+ virQEMUBuildBufferEscapeComma(buf, source);
|
|
|
6ae9ed |
+ } else {
|
|
|
6ae9ed |
+ if (!(source = virQEMUBuildDriveCommandlineFromJSON(srcprops)))
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- virBufferAddLit(buf, "fat:");
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
|
|
|
6ae9ed |
- virBufferAddLit(buf, "floppy:");
|
|
|
6ae9ed |
+ virBufferAdd(buf, source, -1);
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- virQEMUBuildBufferEscapeComma(buf, source);
|
|
|
6ae9ed |
virBufferAddLit(buf, ",");
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
|
|
|
6ae9ed |
@@ -1170,6 +1210,7 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
|
|
6ae9ed |
|
|
|
6ae9ed |
cleanup:
|
|
|
6ae9ed |
VIR_FREE(source);
|
|
|
6ae9ed |
+ virJSONValueFree(srcprops);
|
|
|
6ae9ed |
return ret;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/util/virqemu.c b/src/util/virqemu.c
|
|
|
6ae9ed |
index 20410f7..a1ba562 100644
|
|
|
6ae9ed |
--- a/src/util/virqemu.c
|
|
|
6ae9ed |
+++ b/src/util/virqemu.c
|
|
|
6ae9ed |
@@ -264,6 +264,27 @@ virQEMUBuildObjectCommandlineFromJSON(const char *type,
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
|
|
|
6ae9ed |
+char *
|
|
|
6ae9ed |
+virQEMUBuildDriveCommandlineFromJSON(const virJSONValue *srcdef)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
6ae9ed |
+ char *ret = NULL;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (virQEMUBuildCommandLineJSON(srcdef, &buf,
|
|
|
6ae9ed |
+ virQEMUBuildCommandLineJSONArrayNumbered) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (virBufferCheckError(&buf) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ ret = virBufferContentAndReset(&buf;;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ cleanup:
|
|
|
6ae9ed |
+ virBufferFreeAndReset(&buf;;
|
|
|
6ae9ed |
+ return ret;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
/**
|
|
|
6ae9ed |
* virQEMUBuildBufferEscapeComma:
|
|
|
6ae9ed |
* @buf: buffer to append the escaped string
|
|
|
6ae9ed |
diff --git a/src/util/virqemu.h b/src/util/virqemu.h
|
|
|
6ae9ed |
index 40cd9b8..f3c2b69 100644
|
|
|
6ae9ed |
--- a/src/util/virqemu.h
|
|
|
6ae9ed |
+++ b/src/util/virqemu.h
|
|
|
6ae9ed |
@@ -47,6 +47,8 @@ char *virQEMUBuildObjectCommandlineFromJSON(const char *type,
|
|
|
6ae9ed |
const char *alias,
|
|
|
6ae9ed |
virJSONValuePtr props);
|
|
|
6ae9ed |
|
|
|
6ae9ed |
+char *virQEMUBuildDriveCommandlineFromJSON(const virJSONValue *src);
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);
|
|
|
6ae9ed |
void virQEMUBuildLuksOpts(virBufferPtr buf,
|
|
|
6ae9ed |
virStorageEncryptionInfoDefPtr enc,
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|