[PATCH 02/18] qemuBlockStorageSourceGetBackendProps: Allow skipping "discard":"unmap"

Peter Krempa pkrempa at redhat.com
Fri Jul 10 14:33:23 UTC 2020


It doesn't make sense to format "discard" when doing a -blockdev backend
of scsi-generic used with SCSI hostdevs. Add a way to skip it.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_block.c | 8 ++++++++
 src/qemu/qemu_block.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 10ddf53b3b..bdd07d9925 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1061,6 +1061,9 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSourcePtr src,
  *      omit any data which does not identify the image itself
  *  QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY:
  *      use the auto-read-only feature of qemu
+ *  QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP:
+ *      don't enable 'discard:unmap' option for passing through dicards
+ *      (note that this is disabled also for _LEGACY and _TARGET_ONLY options)
  *
  * Creates a JSON object describing the underlying storage or protocol of a
  * storage source. Returns NULL on error and reports an appropriate error message.
@@ -1202,6 +1205,11 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
             if (virJSONValueObjectAdd(fileprops,
                                       "T:read-only", ro,
                                       "T:auto-read-only", aro,
+                                      NULL) < 0)
+                return NULL;
+
+            if (!(flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP) &&
+                virJSONValueObjectAdd(fileprops,
                                       "s:discard", "unmap",
                                       NULL) < 0)
                 return NULL;
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 715739e59c..0701fc18d1 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -60,6 +60,7 @@ typedef enum {
     QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_LEGACY = 1 << 0,
     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,
 } qemuBlockStorageSourceBackendPropsFlags;

 virJSONValuePtr
-- 
2.26.2




More information about the libvir-list mailing list