[libvirt] [RFC PATCH 10/30] qemu: block: Propagate 'legacy' parameter when formatting disk backing

Peter Krempa pkrempa at redhat.com
Thu Apr 19 15:25:07 UTC 2018


The gluster protocol in qemu uses two styles, one of which is legacy and
not covered by the QAPI schema. To allow using of the new style in the
blockdev-add code, add a parameter for
qemuBlockStorageSourceGetBackendProps which will switch between the two
modes.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_block.c   | 11 +++++++----
 src/qemu/qemu_block.h   |  3 ++-
 src/qemu/qemu_command.c |  2 +-
 tests/qemublocktest.c   |  2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 516b006ce9..9057fe4f9a 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -655,13 +655,14 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src)


 static virJSONValuePtr
-qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src)
+qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
+                                      bool legacy)
 {
     virJSONValuePtr servers = NULL;
     virJSONValuePtr props = NULL;
     virJSONValuePtr ret = NULL;

-    if (!(servers = qemuBlockStorageSourceBuildHostsJSONSocketAddress(src, true)))
+    if (!(servers = qemuBlockStorageSourceBuildHostsJSONSocketAddress(src, legacy)))
         return NULL;

      /* { driver:"gluster",
@@ -1014,12 +1015,14 @@ qemuBlockStorageSourceGetVvfatProps(virStorageSourcePtr src)
 /**
  * qemuBlockStorageSourceGetBackendProps:
  * @src: disk source
+ * @legacy: use legacy formatting of attributes (for -drive / old qemus)
  *
  * Creates a JSON object describing the underlying storage or protocol of a
  * storage source. Returns NULL on error and reports an appropriate error message.
  */
 virJSONValuePtr
-qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src)
+qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
+                                      bool legacy)
 {
     int actualType = virStorageSourceGetActualType(src);
     virJSONValuePtr fileprops = NULL;
@@ -1046,7 +1049,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src)
     case VIR_STORAGE_TYPE_NETWORK:
         switch ((virStorageNetProtocol) src->protocol) {
         case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
-            if (!(fileprops = qemuBlockStorageSourceGetGlusterProps(src)))
+            if (!(fileprops = qemuBlockStorageSourceGetGlusterProps(src, legacy)))
                 return NULL;
             break;

diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 45485733fc..0e674437f4 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -58,7 +58,8 @@ bool
 qemuBlockStorageSourceSupportsConcurrentAccess(virStorageSourcePtr src);

 virJSONValuePtr
-qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src);
+qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
+                                      bool legacy);

 virURIPtr
 qemuBlockStorageSourceGetURI(virStorageSourcePtr src);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6de2fc56d5..6ca83b8383 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1450,7 +1450,7 @@ qemuDiskSourceGetProps(virStorageSourcePtr src)
     virJSONValuePtr props;
     virJSONValuePtr ret;

-    if (!(props = qemuBlockStorageSourceGetBackendProps(src)))
+    if (!(props = qemuBlockStorageSourceGetBackendProps(src, true)))
         return NULL;

     if (virJSONValueObjectCreate(&ret, "a:file", &props, NULL) < 0) {
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 99584c759c..bd628295ff 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -62,7 +62,7 @@ testBackingXMLjsonXML(const void *args)
         goto cleanup;
     }

-    if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc))) {
+    if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc, true))) {
         fprintf(stderr, "failed to format disk source json\n");
         goto cleanup;
     }
-- 
2.14.3




More information about the libvir-list mailing list