]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuBlockStorageSourceGetBackendProps: Introduce QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PR...
authorPeter Krempa <pkrempa@redhat.com>
Thu, 19 Oct 2023 14:12:38 +0000 (16:12 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 2 Nov 2023 14:31:51 +0000 (15:31 +0100)
Introduce a mode where the protocol layer -blockdev will be formatted
so that it can be used as the effective node (used to access data from
the device). For this new mode we'll use
qemuBlockStorageSourceAddBlockdevCommonProps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_block.c
src/qemu/qemu_block.h

index 54aa847dff61105111ca97337e88a96960cc4e4d..79671b9222fa0fa8ef57fb54a4300c674114f65d 100644 (file)
@@ -1031,6 +1031,8 @@ qemuBlockStorageSourceAddBlockdevCommonProps(virJSONValue **props,
  *  QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP:
  *      don't enable 'discard:unmap' option for passing through discards
  *      (note that this is disabled also for _LEGACY and _TARGET_ONLY options)
+ *  QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE:
+ *      the 'protocol' node is used as the effective/top node of a virStorageSource
  *
  * Creates a JSON object describing the underlying storage or protocol of a
  * storage source. Returns NULL on error and reports an appropriate error message.
@@ -1183,27 +1185,33 @@ qemuBlockStorageSourceGetBackendProps(virStorageSource *src,
         return NULL;
 
     if (!onlytarget && !legacy) {
-        g_autoptr(virJSONValue) cache = NULL;
-        const char *discardstr = "unmap";
         const char *nodename = qemuBlockStorageSourceGetStorageNodename(src);
 
-        if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP)
-            discardstr = NULL;
+        if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE) {
+            if (qemuBlockStorageSourceAddBlockdevCommonProps(&fileprops, src, nodename, true) < 0)
+                return NULL;
+        } else {
+            g_autoptr(virJSONValue) cache = NULL;
+            const char *discardstr = "unmap";
 
-        if (qemuBlockNodeNameValidate(nodename) < 0)
-            return NULL;
+            if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP)
+                discardstr = NULL;
 
-        if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
-            return NULL;
+            if (qemuBlockNodeNameValidate(nodename) < 0)
+                return NULL;
 
-        if (virJSONValueObjectAdd(&fileprops,
-                                  "s:node-name", nodename,
-                                  "T:read-only", ro,
-                                  "T:auto-read-only", aro,
-                                  "S:discard", discardstr,
-                                  "A:cache", &cache,
-                                  NULL) < 0)
-            return NULL;
+            if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
+                return NULL;
+
+            if (virJSONValueObjectAdd(&fileprops,
+                                      "s:node-name", nodename,
+                                      "T:read-only", ro,
+                                      "T:auto-read-only", aro,
+                                      "S:discard", discardstr,
+                                      "A:cache", &cache,
+                                      NULL) < 0)
+                return NULL;
+        }
     }
 
     return g_steal_pointer(&fileprops);
index 7bb83d8d44dccd2d4bb2fc2f34f499a3a431f784..9757108501179e8de4230deaab8ef856d0823a62 100644 (file)
@@ -68,6 +68,7 @@ typedef enum {
     QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY = 1 << 1,
     QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY = 1 << 2,
     QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP = 1 << 3,
+    QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE = 1 << 4,
 } qemuBlockStorageSourceBackendPropsFlags;
 
 virJSONValue *