Skip to contentSkip to conversation

Block layer patches for 5.1.0-rc1

GIT PULL Applied Kevin Wolf 2 participants 5 messages Jul 21, 2020 Block layer

lore
Share & tools
lore
author
#1 lore raw

[PULL 1/3] file-posix: Handle `EINVAL` fallocate return value

In reply to Kevin Wolf

From: Antoine Damhet <[email protected]>

The detect-zeroes=unmap option may issue unaligned FALLOC_FL_PUNCH_HOLE requests, raw block devices can (and will) return EINVAL, qemu should then write the zeroes to the blockdev instead of issuing an IO_ERROR.

The problem can be reprodced like this:

$ qemu-io -c 'write -P 0 42 1234' --image-opts driver=host_device,filename=/dev/loop0,detect-zeroes=unmap
write failed: Invalid argument

Message-Id: <[email protected]>

---
 block/file-posix.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
block/file-posix.c +5 -1
index 8cc39a1ef6..9a00d4190a 100644
@@ -1698,7 +1698,11 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
 #ifdef CONFIG_FALLOCATE_PUNCH_HOLE
     int ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                            aiocb->aio_offset, aiocb->aio_nbytes);
-    if (ret != -ENOTSUP) {
+    switch (ret) {
+    case -ENOTSUP:
+    case -EINVAL:
+        break;
+    default:
         return ret;
     }
 #endif
Signature · 1 line
2.25.4
author
#2 lore raw

[PULL 2/3] qcow2: Implement v2 zero writes with discard if possible

In reply to Kevin Wolf

qcow2 version 2 images don't support the zero flag for clusters, so for write_zeroes requests, we return -ENOTSUP and get explicit zero buffer writes. If the image doesn't have a backing file, we can do better: Just discard the respective clusters.

This is relevant for 'qemu-img convert -O qcow2 -n', where qemu-img has to assume that the existing target image may contain any data, so it has to write zeroes. Without this patch, this results in a fully allocated target image, even if the source image was empty.

Message-Id: <[email protected]>

---
 block/qcow2-cluster.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
block/qcow2-cluster.c +8 -1
index 4b5fc8c4a7..a677ba9f5c 100644
@@ -1797,8 +1797,15 @@ int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
     assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
            end_offset >= bs->total_sectors << BDRV_SECTOR_BITS);
 
-    /* The zero flag is only supported by version 3 and newer */
+    /*
+     * The zero flag is only supported by version 3 and newer. However, if we
+     * have no backing file, we can resort to discard in version 2.
+     */
     if (s->qcow_version < 3) {
+        if (!bs->backing) {
+            return qcow2_cluster_discard(bs, offset, bytes,
+                                         QCOW2_DISCARD_REQUEST, false);
+        }
         return -ENOTSUP;
     }
 
Signature · 1 line
2.25.4

Kevin Wolf

author
#0 lore raw

The following changes since commit 90218a9a393c7925f330e7dcc08658e2a01d3bd4:

Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-07-21' into staging (2020-07-21 10:24:38 +0100)

are available in the Git repository at:

git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 4a01e27ddcb5921efd68820d05d85ba71293fea6:

iotests: Test sparseness for qemu-img convert -n (2020-07-21 17:44:35 +0200)

----------------------------------------------------------------
Block layer patches:

- file-posix: Handle EINVAL fallocate return value
- qemu-img convert -n: Keep qcow2 v2 target sparse

----------------------------------------------------------------
Antoine Damhet (1):
file-posix: Handle EINVAL fallocate return value

Kevin Wolf (2):
qcow2: Implement v2 zero writes with discard if possible
iotests: Test sparseness for qemu-img convert -n

 block/file-posix.c         |  6 +++++-
 block/qcow2-cluster.c      |  9 ++++++++-
 tests/qemu-iotests/122     | 30 ++++++++++++++++++++++++++++++
 tests/qemu-iotests/122.out | 17 +++++++++++++++++
 4 files changed, 60 insertions(+), 2 deletions(-)
author
#3 lore raw

[PULL 3/3] iotests: Test sparseness for qemu-img convert -n

Message-Id: <[email protected]>

---
 tests/qemu-iotests/122     | 30 ++++++++++++++++++++++++++++++
 tests/qemu-iotests/122.out | 17 +++++++++++++++++
 2 files changed, 47 insertions(+)
tests/qemu-iotests/122 +30 -0
index dfd1cd05d6..0f3d4ca851 100755
@@ -281,6 +281,36 @@ $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG".orig
 
 $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG".orig
 
+echo
+echo '=== -n to an empty image ==='
+echo
+
+TEST_IMG="$TEST_IMG".orig _make_test_img 64M
+
+# Convert with -n, which should not result in a fully allocated image, not even
+# with compat=0.10 (because the target doesn't have a backing file)
+for compat in "1.1" "0.10"; do
+    IMGOPTS="compat=$compat" _make_test_img 64M
+    $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG".orig "$TEST_IMG"
+    $QEMU_IMG map --output=json "$TEST_IMG"
+done
+
+echo
+echo '=== -n to an empty image with a backing file ==='
+echo
+
+TEST_IMG="$TEST_IMG".orig _make_test_img 64M
+TEST_IMG="$TEST_IMG".base _make_test_img 64M
+
+# Convert with -n, which should still not result in a fully allocated image for
+# compat=1.1 (because it can use zero clusters), but it should be fully
+# allocated with compat=0.10
+for compat in "1.1" "0.10"; do
+    IMGOPTS="compat=$compat" _make_test_img -b "$TEST_IMG".base -F $IMGFMT 64M
+    $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG".orig "$TEST_IMG"
+    $QEMU_IMG map --output=json "$TEST_IMG"
+done
+
 echo
 echo '=== -n -B to an image without a backing file ==='
 echo
tests/qemu-iotests/122.out +17 -0
index f1f195ed77..3a3e121d57 100644
@@ -229,6 +229,23 @@ wrote 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 Images are identical.
 
+=== -n to an empty image ===
+
+Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=67108864
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
+
+=== -n to an empty image with a backing file ===
+
+Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=67108864
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
+
 === -n -B to an image without a backing file ===
 
 Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
Signature · 1 line
2.25.4
#4 lore raw
In reply to Kevin Wolf
Quoted 19 lines · Kevin Wolf

The following changes since commit 90218a9a393c7925f330e7dcc08658e2a01d3bd4:

Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-07-21' into staging (2020-07-21 10:24:38 +0100)

are available in the Git repository at:

git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 4a01e27ddcb5921efd68820d05d85ba71293fea6:

iotests: Test sparseness for qemu-img convert -n (2020-07-21 17:44:35 +0200)

----------------------------------------------------------------
Block layer patches:

- file-posix: Handle EINVAL fallocate return value
- qemu-img convert -n: Keep qcow2 v2 target sparse

Quoted 7 lines

----------------------------------------------------------------
Antoine Damhet (1):
file-posix: Handle EINVAL fallocate return value

Kevin Wolf (2):
qcow2: Implement v2 zero writes with discard if possible
iotests: Test sparseness for qemu-img convert -n

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM