qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] block/file-posix: Consider discard flag when opening


From: Nir Soffer
Subject: [PATCH] block/file-posix: Consider discard flag when opening
Date: Wed, 19 Jun 2024 00:24:57 +0300

Set has_discard only when BDRV_O_UNMAP is not set. With this users that
want to keep their images fully allocated can disable hole punching
when writing zeros or discarding using:

   -drive file=thick.img,discard=off

This change is not entirely correct since it changes the default discard
behavior.  Previously we always allowed punching holes, but now you have
must use discard=unmap|on to enable it. We probably need to add the
BDDR_O_UNMAP flag by default.

make check still works, so maybe we don't have tests for sparsifying
images, or maybe you need to run special tests that do not run by
default. We needs tests for keeping images non-sparse.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
 block/file-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/file-posix.c b/block/file-posix.c
index be25e35ff6..acac2abadc 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -738,11 +738,11 @@ static int raw_open_common(BlockDriverState *bs, QDict 
*options,
         ret = -EINVAL;
         goto fail;
     }
 #endif /* !defined(CONFIG_LINUX_IO_URING) */
 
-    s->has_discard = true;
+    s->has_discard = !!(bdrv_flags & BDRV_O_UNMAP);
     s->has_write_zeroes = true;
 
     if (fstat(s->fd, &st) < 0) {
         ret = -errno;
         error_setg_errno(errp, errno, "Could not stat file");
-- 
2.45.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]