[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/51] block: Use blk_make_empty() after commits
From: |
Kevin Wolf |
Subject: |
[PULL 10/51] block: Use blk_make_empty() after commits |
Date: |
Fri, 15 May 2020 14:44:40 +0200 |
From: Max Reitz <address@hidden>
bdrv_commit() already has a BlockBackend pointing to the BDS that we
want to empty, it just has the wrong permissions.
qemu-img commit has no BlockBackend pointing to the old backing file
yet, but introducing one is simple.
After this commit, bdrv_make_empty() is the only remaining caller of
BlockDriver.bdrv_make_empty().
Signed-off-by: Max Reitz <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
[kwolf: Fixed up reference output for 098]
Signed-off-by: Kevin Wolf <address@hidden>
---
block/commit.c | 16 +++++++++-------
qemu-img.c | 19 ++++++++++++++-----
tests/qemu-iotests/098.out | 8 ++++----
3 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/block/commit.c b/block/commit.c
index 87f6096d90..ba60fb7955 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -414,7 +414,9 @@ int bdrv_commit(BlockDriverState *bs)
}
ctx = bdrv_get_aio_context(bs);
- src = blk_new(ctx, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL);
+ /* WRITE_UNCHANGED is required for bdrv_make_empty() */
+ src = blk_new(ctx, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED,
+ BLK_PERM_ALL);
backing = blk_new(ctx, BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL);
ret = blk_insert_bs(src, bs, &local_err);
@@ -492,14 +494,14 @@ int bdrv_commit(BlockDriverState *bs)
}
}
- if (drv->bdrv_make_empty) {
- ret = drv->bdrv_make_empty(bs);
- if (ret < 0) {
- goto ro_cleanup;
- }
- blk_flush(src);
+ ret = blk_make_empty(src, NULL);
+ /* Ignore -ENOTSUP */
+ if (ret < 0 && ret != -ENOTSUP) {
+ goto ro_cleanup;
}
+ blk_flush(src);
+
/*
* Make sure all data we wrote to the backing device is actually
* stable on disk.
diff --git a/qemu-img.c b/qemu-img.c
index 6a4327aaba..f1795c788c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1104,11 +1104,20 @@ static int img_commit(int argc, char **argv)
goto unref_backing;
}
- if (!drop && bs->drv->bdrv_make_empty) {
- ret = bs->drv->bdrv_make_empty(bs);
- if (ret) {
- error_setg_errno(&local_err, -ret, "Could not empty %s",
- filename);
+ if (!drop) {
+ BlockBackend *old_backing_blk;
+
+ old_backing_blk = blk_new_with_bs(bs, BLK_PERM_WRITE, BLK_PERM_ALL,
+ &local_err);
+ if (!old_backing_blk) {
+ goto unref_backing;
+ }
+ ret = blk_make_empty(old_backing_blk, &local_err);
+ blk_unref(old_backing_blk);
+ if (ret == -ENOTSUP) {
+ error_free(local_err);
+ local_err = NULL;
+ } else if (ret < 0) {
goto unref_backing;
}
}
diff --git a/tests/qemu-iotests/098.out b/tests/qemu-iotests/098.out
index 7634d0e8b0..23cf371f53 100644
--- a/tests/qemu-iotests/098.out
+++ b/tests/qemu-iotests/098.out
@@ -6,7 +6,7 @@ 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
wrote 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
+qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
No errors were found on the image.
=== empty_image_prepare ===
@@ -15,7 +15,7 @@ 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
wrote 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
+qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
Leaked cluster 4 refcount=1 reference=0
Leaked cluster 5 refcount=1 reference=0
Repairing cluster 4 refcount=1 reference=0
@@ -28,7 +28,7 @@ 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
wrote 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
+qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
ERROR cluster 0 refcount=0 reference=1
ERROR cluster 1 refcount=0 reference=1
ERROR cluster 3 refcount=0 reference=1
@@ -42,7 +42,7 @@ 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
wrote 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
+qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT:
Input/output error
ERROR cluster 0 refcount=0 reference=1
ERROR cluster 1 refcount=0 reference=1
ERROR cluster 3 refcount=0 reference=1
--
2.25.4
- [PULL 00/51] Block layer patches, Kevin Wolf, 2020/05/15
- [PULL 01/51] iotests/109: Don't mirror with mismatched size, Kevin Wolf, 2020/05/15
- [PULL 02/51] iotests/229: Use blkdebug to inject an error, Kevin Wolf, 2020/05/15
- [PULL 03/51] mirror: Make sure that source and target size match, Kevin Wolf, 2020/05/15
- [PULL 05/51] block/replication.c: Avoid cancelling the job twice, Kevin Wolf, 2020/05/15
- [PULL 04/51] iotests: Mirror with different source/target size, Kevin Wolf, 2020/05/15
- [PULL 06/51] iotests: Fix incomplete type declarations, Kevin Wolf, 2020/05/15
- [PULL 08/51] block: Add bdrv_make_empty(), Kevin Wolf, 2020/05/15
- [PULL 09/51] block: Add blk_make_empty(), Kevin Wolf, 2020/05/15
- [PULL 10/51] block: Use blk_make_empty() after commits,
Kevin Wolf <=
- [PULL 12/51] block: Use bdrv_make_empty() where possible, Kevin Wolf, 2020/05/15
- [PULL 07/51] iotests: Run pylint and mypy in a testcase, Kevin Wolf, 2020/05/15
- [PULL 11/51] replication: Avoid blk_make_empty() on read-only child, Kevin Wolf, 2020/05/15
- [PULL 13/51] block: Mark commit, mirror, blkreplay as filters, Kevin Wolf, 2020/05/15
- [PULL 15/51] block: Rename BdrvChildRole to BdrvChildClass, Kevin Wolf, 2020/05/15
- [PULL 16/51] block: Add BdrvChildRole and BdrvChildRoleBits, Kevin Wolf, 2020/05/15
- [PULL 17/51] block: Add BdrvChildRole to BdrvChild, Kevin Wolf, 2020/05/15
- [PULL 19/51] block: Pass BdrvChildRole to .inherit_options(), Kevin Wolf, 2020/05/15
- [PULL 14/51] block: Add BlockDriver.is_format, Kevin Wolf, 2020/05/15
- [PULL 22/51] block: Add generic bdrv_inherited_options(), Kevin Wolf, 2020/05/15