When discard is not set to unmap/on, we should not allow setting
discard-no-unref.

Signed-off-by: Jean-Louis Dupond <jean-lo...@dupond.be>
---
 block/qcow2.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/block/qcow2.c b/block/qcow2.c
index 1ce7ebbab4..54c6b041b1 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1156,6 +1156,12 @@ qcow2_update_options_prepare(BlockDriverState *bs, 
Qcow2ReopenState *r,
         ret = -EINVAL;
         goto fail;
     }
+    if (r->discard_no_unref && !(flags & BDRV_O_UNMAP)) {
+        error_setg(errp,
+                   "discard-no-unref is only valid with discard=unmap/on");
+        ret = -EINVAL;
+        goto fail;
+    }
 
     switch (s->crypt_method_header) {
     case QCOW_CRYPT_NONE:
-- 
2.45.2


Reply via email to