]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: command: Add infrastructure for object specified disk sources
authorPeter Krempa <pkrempa@redhat.com>
Mon, 25 Jul 2016 17:51:18 +0000 (19:51 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 27 Jul 2016 11:33:10 +0000 (13:33 +0200)
To allow richer definitions of disk sources add infrastructure that will
allow to register functionst generating a JSON object based definition.

This infrastructure will then convert the definition to the proper
command line syntax and use it in cases where it's necessary. This will
allow to keep legacy definitions for back-compat when possible and use
the new definitions for the configurations requiring them.

src/libvirt_private.syms
src/qemu/qemu_command.c
src/util/virqemu.c
src/util/virqemu.h

index f49a3b237754b166a433a59fcb323b29d2373793..56ceac8958783d42fdec9ef3dae7ab422b6b2bb1 100644 (file)
@@ -2207,6 +2207,7 @@ virQEMUBuildBufferEscapeComma;
 virQEMUBuildCommandLineJSON;
 virQEMUBuildCommandLineJSONArrayBitmap;
 virQEMUBuildCommandLineJSONArrayNumbered;
+virQEMUBuildDriveCommandlineFromJSON;
 virQEMUBuildLuksOpts;
 virQEMUBuildObjectCommandlineFromJSON;
 
index 2fe07edfdc17c6beb47b6ba6cac33cb2a2422035..d90571eb43b11f9cfb2868ac5b8cea8e28f03fab 100644 (file)
@@ -916,6 +916,34 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
 }
 
 
+static int
+qemuGetDriveSourceProps(virStorageSourcePtr src,
+                        virJSONValuePtr *props)
+{
+    int actualType = virStorageSourceGetActualType(src);
+    virJSONValuePtr fileprops = NULL;
+
+    *props = NULL;
+
+    switch ((virStorageType) actualType) {
+    case VIR_STORAGE_TYPE_BLOCK:
+    case VIR_STORAGE_TYPE_FILE:
+    case VIR_STORAGE_TYPE_DIR:
+    case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
+    case VIR_STORAGE_TYPE_LAST:
+    case VIR_STORAGE_TYPE_NETWORK:
+        break;
+    }
+
+    if (fileprops &&
+        virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 int
 qemuGetDriveSourceString(virStorageSourcePtr src,
                          qemuDomainSecretInfoPtr secinfo,
@@ -1101,14 +1129,19 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
     qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
     qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
     qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
+    virJSONValuePtr srcprops = NULL;
     char *source = NULL;
     int ret = -1;
 
-    if (qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
+    if (qemuGetDriveSourceProps(disk->src, &srcprops) < 0)
+        goto cleanup;
+
+    if (!srcprops &&
+        qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
         goto cleanup;
 
     /* nothing to format if the drive is empty */
-    if (!source ||
+    if (!(source || srcprops) ||
         ((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
           disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
          disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
@@ -1125,31 +1158,38 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
         goto cleanup;
     }
 
-    virBufferAddLit(buf, "file=");
+    if (source) {
+        virBufferAddLit(buf, "file=");
 
-    /* for now the DIR based storage is handled by the magic FAT format */
-    if (actualType == VIR_STORAGE_TYPE_DIR) {
-        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;
-        }
+        /* for now the DIR based storage is handled by the magic FAT format */
+        if (actualType == VIR_STORAGE_TYPE_DIR) {
+            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;
+            if (!disk->src->readonly) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("cannot create virtual FAT disks in read-write mode"));
+                goto cleanup;
+            }
+
+            virBufferAddLit(buf, "fat:");
+
+            if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+                virBufferAddLit(buf, "floppy:");
         }
 
-        virBufferAddLit(buf, "fat:");
+        virQEMUBuildBufferEscapeComma(buf, source);
+    } else {
+        if (!(source = virQEMUBuildDriveCommandlineFromJSON(srcprops)))
+            goto cleanup;
 
-        if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
-            virBufferAddLit(buf, "floppy:");
+        virBufferAdd(buf, source, -1);
     }
-
-    virQEMUBuildBufferEscapeComma(buf, source);
     virBufferAddLit(buf, ",");
 
     if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
@@ -1170,6 +1210,7 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
 
  cleanup:
     VIR_FREE(source);
+    virJSONValueFree(srcprops);
     return ret;
 }
 
index 20410f70ea2d6a7994ef2278fa8c4d477576bbda..a1ba562ad21ce525ac384828786f30d19b4d231b 100644 (file)
@@ -264,6 +264,27 @@ virQEMUBuildObjectCommandlineFromJSON(const char *type,
 }
 
 
+char *
+virQEMUBuildDriveCommandlineFromJSON(const virJSONValue *srcdef)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *ret = NULL;
+
+    if (virQEMUBuildCommandLineJSON(srcdef, &buf,
+                                    virQEMUBuildCommandLineJSONArrayNumbered) < 0)
+        goto cleanup;
+
+    if (virBufferCheckError(&buf) < 0)
+        goto cleanup;
+
+    ret = virBufferContentAndReset(&buf);
+
+ cleanup:
+    virBufferFreeAndReset(&buf);
+    return ret;
+}
+
+
 /**
  * virQEMUBuildBufferEscapeComma:
  * @buf: buffer to append the escaped string
index 40cd9b8046ad7edf30c17bc9d1594dd788b35e60..f3c2b69565a9db2265482b597a3678a6a749337f 100644 (file)
@@ -47,6 +47,8 @@ char *virQEMUBuildObjectCommandlineFromJSON(const char *type,
                                             const char *alias,
                                             virJSONValuePtr props);
 
+char *virQEMUBuildDriveCommandlineFromJSON(const virJSONValue *src);
+
 void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);
 void virQEMUBuildLuksOpts(virBufferPtr buf,
                           virStorageEncryptionInfoDefPtr enc,