Skip to contentSkip to conversation

Block patches

GIT PULL Applied Stefan Hajnoczi 2 participants 4 messages Jul 11, 2024 Block layer

lore
Share & tools
lore
#0 lore raw

The following changes since commit 59084feb256c617063e0dbe7e64821ae8852d7cf:

Merge tag 'pull-aspeed-20240709' of https://github.com/legoater/qemu into staging (2024-07-09 07:13:55 -0700)

are available in the Git repository at:

https://gitlab.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to d05ae948cc887054495977855b0859d0d4ab2613:

Consider discard option when writing zeros (2024-07-11 11:06:36 +0200)

----------------------------------------------------------------
Pull request

A discard fix from Nir Soffer.

----------------------------------------------------------------

Nir Soffer (2):
qemu-iotest/245: Add missing discard=unmap
Consider discard option when writing zeros

 block/io.c                                    |   9 +-
 tests/qemu-iotests/245                        |   2 +-
 tests/qemu-iotests/tests/write-zeroes-unmap   | 127 ++++++++++++++++++
 .../qemu-iotests/tests/write-zeroes-unmap.out |  81 +++++++++++
 4 files changed, 214 insertions(+), 5 deletions(-)
 create mode 100755 tests/qemu-iotests/tests/write-zeroes-unmap
 create mode 100644 tests/qemu-iotests/tests/write-zeroes-unmap.out
Signature · 1 line
2.45.2
#1 lore raw

[PULL 1/2] qemu-iotest/245: Add missing discard=unmap

From: Nir Soffer <[email protected]>

The test works since we punch holes by default even when opening the image without discard=on or discard=unmap. Fix the test to enable discard.

---
 tests/qemu-iotests/245 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/245 +1 -1
index a934c9d1e6..f96610f510 100755
@@ -592,7 +592,7 @@ class TestBlockdevReopen(iotests.QMPTestCase):
     @iotests.skip_if_unsupported(['compress'])
     def test_insert_compress_filter(self):
         # Add an image to the VM: hd (raw) -> hd0 (qcow2) -> hd0-file (file)
-        opts = {'driver': 'raw', 'node-name': 'hd', 'file': hd_opts(0)}
+        opts = {'driver': 'raw', 'node-name': 'hd', 'file': hd_opts(0), 'discard': 'unmap'}
         self.vm.cmd('blockdev-add', conv_keys = False, **opts)
 
         # Add a 'compress' filter
Signature · 1 line
2.45.2
#2 lore raw

[PULL 2/2] Consider discard option when writing zeros

In reply to Stefan Hajnoczi

From: Nir Soffer <[email protected]>

When opening an image with discard=off, we punch hole in the image when writing zeroes, making the image sparse. This breaks users that want to ensure that writes cannot fail with ENOSPACE by using fully allocated images[1].

bdrv_co_pwrite_zeroes() correctly disables BDRV_REQ_MAY_UNMAP if we opened the child without discard=unmap or discard=on. But we don't go through this function when accessing the top node. Move the check down to bdrv_co_do_pwrite_zeroes() which seems to be used in all code paths.

This change implements the documented behavior, punching holes only when opening the image with discard=on or discard=unmap. This may not be the best default but can improve it later.

The test depends on a file system supporting discard, deallocating the entire file when punching hole with the length of the entire file. Tested with xfs, ext4, and tmpfs.

[1] https://lists.nongnu.org/archive/html/qemu-discuss/2024-06/msg00003.html

Message-id: [email protected]

---
 block/io.c                                    |   9 +-
 tests/qemu-iotests/tests/write-zeroes-unmap   | 127 ++++++++++++++++++
 .../qemu-iotests/tests/write-zeroes-unmap.out |  81 +++++++++++
 3 files changed, 213 insertions(+), 4 deletions(-)
 create mode 100755 tests/qemu-iotests/tests/write-zeroes-unmap
 create mode 100644 tests/qemu-iotests/tests/write-zeroes-unmap.out
block/io.c +5 -4
index 7217cf811b..301514c880 100644
@@ -1862,6 +1862,11 @@ bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes,
         return -EINVAL;
     }
 
+    /* If opened with discard=off we should never unmap. */
+    if (!(bs->open_flags & BDRV_O_UNMAP)) {
+        flags &= ~BDRV_REQ_MAY_UNMAP;
+    }
+
     /* Invalidate the cached block-status data range if this write overlaps */
     bdrv_bsc_invalidate_range(bs, offset, bytes);
 
@@ -2315,10 +2320,6 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,
     trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags);
     assert_bdrv_graph_readable();
 
-    if (!(child->bs->open_flags & BDRV_O_UNMAP)) {
-        flags &= ~BDRV_REQ_MAY_UNMAP;
-    }
-
     return bdrv_co_pwritev(child, offset, bytes, NULL,
                            BDRV_REQ_ZERO_WRITE | flags);
 }
tests/qemu-iotests/tests/write-zeroes-unmap new file +127 -0

127 lines not on this page · raw message

tests/qemu-iotests/tests/write-zeroes-unmap.out new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
2.45.2
#3 lore raw
In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi

The following changes since commit 59084feb256c617063e0dbe7e64821ae8852d7cf:

   Merge tag 'pull-aspeed-20240709' ofhttps://github.com/legoater/qemu  into staging (2024-07-09 07:13:55 -0700)

are available in the Git repository at:

https://gitlab.com/stefanha/qemu.git tags/block-pull-request

Quoted 8 lines

for you to fetch changes up to d05ae948cc887054495977855b0859d0d4ab2613:

Consider discard option when writing zeros (2024-07-11 11:06:36 +0200)

----------------------------------------------------------------
Pull request

A discard fix from Nir Soffer.

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/9.1 as appropriate.

r~