qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

block: Use blk_make_empty() after commits

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 <mreitz@redhat.com>
Message-Id: <20200429141126.85159-5-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[kwolf: Fixed up reference output for 098]
Signed-off-by: Kevin Wolf <kwolf@redhat.com>

authored by

Max Reitz and committed by
Kevin Wolf
2d97fde4 2b7bbdbd

+27 -16
+9 -7
block/commit.c
··· 414 414 } 415 415 416 416 ctx = bdrv_get_aio_context(bs); 417 - src = blk_new(ctx, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); 417 + /* WRITE_UNCHANGED is required for bdrv_make_empty() */ 418 + src = blk_new(ctx, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED, 419 + BLK_PERM_ALL); 418 420 backing = blk_new(ctx, BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL); 419 421 420 422 ret = blk_insert_bs(src, bs, &local_err); ··· 492 494 } 493 495 } 494 496 495 - if (drv->bdrv_make_empty) { 496 - ret = drv->bdrv_make_empty(bs); 497 - if (ret < 0) { 498 - goto ro_cleanup; 499 - } 500 - blk_flush(src); 497 + ret = blk_make_empty(src, NULL); 498 + /* Ignore -ENOTSUP */ 499 + if (ret < 0 && ret != -ENOTSUP) { 500 + goto ro_cleanup; 501 501 } 502 + 503 + blk_flush(src); 502 504 503 505 /* 504 506 * Make sure all data we wrote to the backing device is actually
+14 -5
qemu-img.c
··· 1104 1104 goto unref_backing; 1105 1105 } 1106 1106 1107 - if (!drop && bs->drv->bdrv_make_empty) { 1108 - ret = bs->drv->bdrv_make_empty(bs); 1109 - if (ret) { 1110 - error_setg_errno(&local_err, -ret, "Could not empty %s", 1111 - filename); 1107 + if (!drop) { 1108 + BlockBackend *old_backing_blk; 1109 + 1110 + old_backing_blk = blk_new_with_bs(bs, BLK_PERM_WRITE, BLK_PERM_ALL, 1111 + &local_err); 1112 + if (!old_backing_blk) { 1113 + goto unref_backing; 1114 + } 1115 + ret = blk_make_empty(old_backing_blk, &local_err); 1116 + blk_unref(old_backing_blk); 1117 + if (ret == -ENOTSUP) { 1118 + error_free(local_err); 1119 + local_err = NULL; 1120 + } else if (ret < 0) { 1112 1121 goto unref_backing; 1113 1122 } 1114 1123 }
+4 -4
tests/qemu-iotests/098.out
··· 6 6 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base 7 7 wrote 65536/65536 bytes at offset 0 8 8 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 9 - qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 9 + qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 10 10 No errors were found on the image. 11 11 12 12 === empty_image_prepare === ··· 15 15 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base 16 16 wrote 65536/65536 bytes at offset 0 17 17 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 18 - qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 18 + qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 19 19 Leaked cluster 4 refcount=1 reference=0 20 20 Leaked cluster 5 refcount=1 reference=0 21 21 Repairing cluster 4 refcount=1 reference=0 ··· 28 28 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base 29 29 wrote 65536/65536 bytes at offset 0 30 30 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 31 - qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 31 + qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 32 32 ERROR cluster 0 refcount=0 reference=1 33 33 ERROR cluster 1 refcount=0 reference=1 34 34 ERROR cluster 3 refcount=0 reference=1 ··· 42 42 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base 43 43 wrote 65536/65536 bytes at offset 0 44 44 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 45 - qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 45 + qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error 46 46 ERROR cluster 0 refcount=0 reference=1 47 47 ERROR cluster 1 refcount=0 reference=1 48 48 ERROR cluster 3 refcount=0 reference=1