diff mbox series

[v2,2/2] qcow2: don't allow discard-no-unref when discard is not enabled

Message ID 20240605132539.3668497-3-jean-louis@dupond.be (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] qcow2: handle discard-no-unref in measure | expand

Commit Message

Jean-Louis Dupond June 5, 2024, 1:25 p.m. UTC
When discard is not set to unmap/on, we should not allow setting
discard-no-unref.

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

Comments

Hanna Czenczek July 10, 2024, 1 p.m. UTC | #1
On 05.06.24 15:25, Jean-Louis Dupond wrote:
> When discard is not set to unmap/on, we should not allow setting
> discard-no-unref.

Is this important?  Technically, it’s an incompatible change, and would 
require a deprecation warning first.

(I can imagine people setting this option indiscriminately on all image, 
whether discard actually plays a role or not.  It may make sense for them.)

Hanna

> Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
> ---
>   block/qcow2.c | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 50354e5b98..cead5479e4 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:
diff mbox series

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index 50354e5b98..cead5479e4 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: