Block layer patches
Subsystems (2)
The following changes since commit 1e3ee834083227f552179f6e43902cba5a866e6b:
Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging (2017-09-25 20:31:24 +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 b156d51b62e6970753e1f9f36f7c4d5fdbf4c619:
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-09-26' into queue-block (2017-09-26 15:03:02 +0200)
----------------------------------------------------------------
Block layer patches
----------------------------------------------------------------
Alberto Garcia (1):
throttle: Assert that bkt->max is valid in throttle_compute_wait()
Cornelia Huck (3):
iotests: use -ccw on s390x for 040, 139, and 182
iotests: use -ccw on s390x for 051
iotests: use virtio aliases for 067Fam Zheng (3):
qemu-img: Clarify about relative backing file options
file-posix: Clear out first sector in hdev_create
iotests: Print full path of bad output if mismatch
Kevin Wolf (9):
qemu-iotests: Add missing -machine accel=qtest
qemu-io: Drop write permissions before read-only reopen
block: Add reopen_queue to bdrv_child_perm()
block: Add reopen queue to bdrv_check_perm()
block: Base permissions on rw state after reopen
block: reopen: Queue children after their parents
block: Fix permissions after bdrv_reopen()
qemu-iotests: Test change-backing-file command
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-09-26' into queue-block
Manos Pitsidianakis (1):
block/throttle-groups.c: allocate RestartData on the heap
Pavel Butsykin (4):
qemu-img: add --shrink flag for resize
qcow2: add qcow2_cache_discard
qcow2: add shrink image support
qemu-iotests: add shrinking image test
Stefan Hajnoczi (1):
docs: add qemu-block-drivers(7) man page
Thomas Huth (1):
block: Clean up some bad code in the vvfat driver
Vladimir Sementsov-Ogievskiy (2):
iotests: fix 181: enable postcopy-ram capability on target block/qcow2-bitmap: fix use of uninitialized pointer
qapi/block-core.json | 8 +- block/qcow2.h | 17 + include/block/block.h | 2 +- include/block/block_int.h | 7 + block.c | 191 +++++++--- block/commit.c | 1 + block/file-posix.c | 10 + block/mirror.c | 1 + block/qcow2-bitmap.c | 2 +- block/qcow2-cache.c | 26 ++ block/qcow2-cluster.c | 50 +++ block/qcow2-refcount.c | 140 +++++++- block/qcow2.c | 43 ++- block/replication.c | 1 + block/throttle-groups.c | 12 +- block/vvfat.c | 27 +- qemu-img.c | 23 ++ qemu-io-cmds.c | 12 + util/throttle.c | 1 + Makefile | 6 +- docs/qemu-block-drivers.texi | 804 ++++++++++++++++++++++++++++++++++++++++++ qemu-doc.texi | 781 +--------------------------------------- qemu-img-cmds.hx | 4 +- qemu-img.texi | 15 +- tests/qemu-iotests/040 | 6 +- tests/qemu-iotests/051 | 12 +- tests/qemu-iotests/051.out | 2 +- tests/qemu-iotests/051.pc.out | 2 +- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 2 +- tests/qemu-iotests/102 | 4 +- tests/qemu-iotests/106 | 2 +- tests/qemu-iotests/139 | 12 +- tests/qemu-iotests/163 | 170 +++++++++ tests/qemu-iotests/163.out | 5 + tests/qemu-iotests/172 | 2 +- tests/qemu-iotests/181 | 2 + tests/qemu-iotests/181.out | 1 - tests/qemu-iotests/182 | 13 +- tests/qemu-iotests/186 | 6 +- tests/qemu-iotests/187.out | 2 +- tests/qemu-iotests/195 | 92 +++++ tests/qemu-iotests/195.out | 78 ++++ tests/qemu-iotests/check | 2 +- tests/qemu-iotests/group | 2 + 45 files changed, 1708 insertions(+), 895 deletions(-) create mode 100644 docs/qemu-block-drivers.texi create mode 100644 tests/qemu-iotests/163 create mode 100644 tests/qemu-iotests/163.out create mode 100755 tests/qemu-iotests/195 create mode 100644 tests/qemu-iotests/195.out
[Qemu-devel] [PULL 01/24] qemu-iotests: Add missing -machine accel=qtest
A basic set of qemu options is initialised in ./common:
export QEMU_OPTIONS="-nodefaults -machine accel=qtest"
However, two test cases (172 and 186) overwrite QEMU_OPTIONS and neglect to manually set '-machine accel=qtest'. Add the missing option for 172. 186 probably only copied the code from 172, it doesn't actually need to overwrite QEMU_OPTIONS, so remove that in 186.
--- tests/qemu-iotests/172 | 2 +- tests/qemu-iotests/186 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
tests/qemu-iotests/172 +1 -1
@@ -56,7 +56,7 @@ function do_run_qemu() done fi echo quit - ) | $QEMU -nographic -monitor stdio -serial none "$@" + ) | $QEMU -machine accel=qtest -nographic -monitor stdio -serial none "$@" echo }
tests/qemu-iotests/186 +3 -3
@@ -56,15 +56,15 @@ function do_run_qemu() done fi echo quit - ) | $QEMU -S -nodefaults -display none -device virtio-scsi-pci -monitor stdio "$@" 2>&1 + ) | $QEMU -S -display none -device virtio-scsi-pci -monitor stdio "$@" 2>&1 echo } function check_info_block() { echo "info block" | - QEMU_OPTIONS="" do_run_qemu "$@" | _filter_win32 | _filter_hmp | - _filter_qemu | _filter_generated_node_ids + do_run_qemu "$@" | _filter_win32 | _filter_hmp | _filter_qemu | + _filter_generated_node_ids }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 02/24] qemu-img: Clarify about relative backing file options
In reply to Kevin WolfFrom: Fam Zheng <[email protected]>
It's not too surprising when a user specifies the backing file relative to the current working directory instead of the top layer image. This causes error when they differ. Though the error message has enough information to infer the fact about the misunderstanding, it is better if we document this explicitly, so that users don't have to learn from mistakes.
--- qemu-img.texi | 9 +++++++++ 1 file changed, 9 insertions(+)
qemu-img.texi +9 -0
@@ -244,6 +244,9 @@ only the differences from @var{backing_file}. No size needs to be specified in this case. @var{backing_file} will never be modified unless you use the @code{commit} monitor command (or qemu-img commit). +If a relative path name is given, the backing file is looked up relative to +the directory containing @var{filename}. + Note that a given backing file will be opened to check that it is valid. Use the @code{-u} option to enable unsafe backing file mode, which means that the image will be created even if the associated backing file cannot be opened. A
@@ -343,6 +346,9 @@ created as a copy on write image of the specified base image; the @var{backing_file} should have the same content as the input's base image, however the path, image format, etc may differ. +If a relative path name is given, the backing file is looked up relative to +the directory containing @var{output_filename}. + If the @code{-n} option is specified, the target volume creation will be skipped. This is useful for formats such as @code{rbd} if the target volume has already been created with site specific options that cannot
@@ -490,6 +496,9 @@ The backing file is changed to @var{backing_file} and (if the image format of string), then the image is rebased onto no backing file (i.e. it will exist independently of any backing file). +If a relative path name is given, the backing file is looked up relative to +the directory containing @var{filename}. + @var{cache} specifies the cache mode to be used for @var{filename}, whereas @var{src_cache} specifies the cache mode for reading backing files.
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 08/24] iotests: Print full path of bad output if mismatch
In reply to Kevin WolfFrom: Fam Zheng <[email protected]>
So it is easier to copy paste the path.
--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/check +1 -1
@@ -353,7 +353,7 @@ do else echo " - output mismatch (see $seq.out.bad)" mv $tmp.out $seq.out.bad - $diff -w "$reference" $seq.out.bad + $diff -w "$reference" $(realpath $seq.out.bad) err=true fi fi
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PULL 08/24] iotests: Print full path of bad output if mismatch
Quoted 15 lines · Kevin Wolf
From: Fam Zheng <[email protected]>
So it is easier to copy paste the path.
Signed-off-by Fam Zheng <[email protected]>Signed-off-by Kevin Wolf <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qemu-iotests/check +0
-0
tests/qemu-iotests/check do · line 356
Quoted 5 lines
tests/qemu-iotests/check +1
-1@@ -353,7 +353,7 @@ do else echo " - output mismatch (see $seq.out.bad)" mv $tmp.out $seq.out.bad - $diff -w "$reference" $seq.out.bad + $diff -w "$reference" $(realpath $seq.out.bad)
This missed my review comments about being unsafe if $PWD contains spaces:
https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg04241.html
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PULL 08/24] iotests: Print full path of bad output if mismatch
Am 26.09.2017 um 16:56 hat Eric Blake geschrieben:
Quoted 11 lines · Kevin Wolf
Quoted 10 lines
From: Fam Zheng <[email protected]>
So it is easier to copy paste the path.
Signed-off-by Fam Zheng <[email protected]>Signed-off-by Kevin Wolf <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
tests/qemu-iotests/check do · line 356
Quoted 10 lines
tests/qemu-iotests/check +1
-1@@ -353,7 +353,7 @@ do else echo " - output mismatch (see $seq.out.bad)" mv $tmp.out $seq.out.bad - $diff -w "$reference" $seq.out.bad + $diff -w "$reference" $(realpath $seq.out.bad)This missed my review comments about being unsafe if $PWD contains spaces:
https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg04241.html
Sorry for missing this. Please send a follow-up patch to fix it.
Kevin
[Qemu-devel] [PULL 06/24] iotests: use -ccw on s390x for 051
In reply to Kevin WolfFrom: Cornelia Huck <[email protected]>
The default cpu model on s390x does not provide zPCI, which is not yet wired up on tcg. Moreover, virtio-ccw is the standard on s390x, so use the -ccw instead of the -pci versions of virtio devices on s390x.
--- tests/qemu-iotests/051 | 12 +++++++++++- tests/qemu-iotests/051.out | 2 +- tests/qemu-iotests/051.pc.out | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-)
tests/qemu-iotests/051 +11 -1
@@ -103,7 +103,17 @@ echo echo === Device without drive === echo -run_qemu -device virtio-scsi-pci -device scsi-hd +case "$QEMU_DEFAULT_MACHINE" in + s390-ccw-virtio) + virtio_scsi=virtio-scsi-ccw + ;; + *) + virtio_scsi=virtio-scsi-pci + ;; +esac + +run_qemu -device $virtio_scsi -device scsi-hd | + sed -e "s/$virtio_scsi/VIRTIO_SCSI/" echo echo === Overriding backing file ===
tests/qemu-iotests/051.out +1 -1
@@ -49,7 +49,7 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specif === Device without drive === -Testing: -device virtio-scsi-pci -device scsi-hd +Testing: -device VIRTIO_SCSI -device scsi-hd QEMU X.Y.Z monitor - type 'help' for more information (qemu) QEMU_PROG: -device scsi-hd: drive property not set
tests/qemu-iotests/051.pc.out +1 -1
@@ -49,7 +49,7 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specif === Device without drive === -Testing: -device virtio-scsi-pci -device scsi-hd +Testing: -device VIRTIO_SCSI -device scsi-hd QEMU X.Y.Z monitor - type 'help' for more information (qemu) QEMU_PROG: -device scsi-hd: drive property not set
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 05/24] iotests: use -ccw on s390x for 040, 139, and 182
In reply to Kevin WolfFrom: Cornelia Huck <[email protected]>
The default cpu model on s390x does not provide zPCI, which is not yet wired up on tcg. Moreover, virtio-ccw is the standard on s390x, so use the -ccw instead of the -pci versions of virtio devices on s390x.
--- tests/qemu-iotests/040 | 6 +++++- tests/qemu-iotests/139 | 12 ++++++++++-- tests/qemu-iotests/182 | 13 +++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-)
tests/qemu-iotests/040 +5 -1
@@ -82,7 +82,11 @@ class TestSingleDrive(ImageCommitTestCase): qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) self.vm = iotests.VM().add_drive(test_img, "node-name=top,backing.node-name=mid,backing.backing.node-name=base", interface="none") - self.vm.add_device("virtio-scsi-pci") + if iotests.qemu_default_machine == 's390-ccw-virtio': + self.vm.add_device("virtio-scsi-ccw") + else: + self.vm.add_device("virtio-scsi-pci") + self.vm.add_device("scsi-hd,id=scsi0,drive=drive0") self.vm.launch()
tests/qemu-iotests/139 +10 -2
@@ -25,13 +25,21 @@ import time base_img = os.path.join(iotests.test_dir, 'base.img') new_img = os.path.join(iotests.test_dir, 'new.img') +if iotests.qemu_default_machine == 's390-ccw-virtio': + default_virtio_blk = 'virtio-blk-ccw' +else: + default_virtio_blk = 'virtio-blk-pci' class TestBlockdevDel(iotests.QMPTestCase): def setUp(self): iotests.qemu_img('create', '-f', iotests.imgfmt, base_img, '1M') self.vm = iotests.VM() - self.vm.add_device("virtio-scsi-pci,id=virtio-scsi") + if iotests.qemu_default_machine == 's390-ccw-virtio': + self.vm.add_device("virtio-scsi-ccw,id=virtio-scsi") + else: + self.vm.add_device("virtio-scsi-pci,id=virtio-scsi") + self.vm.launch() def tearDown(self):
@@ -87,7 +95,7 @@ class TestBlockdevDel(iotests.QMPTestCase): self.checkBlockDriverState(node, expect_error) # Add a device model - def addDeviceModel(self, device, backend, driver = 'virtio-blk-pci'): + def addDeviceModel(self, device, backend, driver = default_virtio_blk): result = self.vm.qmp('device_add', id = device, driver = driver, drive = backend) self.assert_qmp(result, 'return', {})
tests/qemu-iotests/182 +11 -2
@@ -45,17 +45,26 @@ _supported_os Linux size=32M +case "$QEMU_DEFAULT_MACHINE" in + s390-ccw-virtio) + virtioblk=virtio-blk-ccw + ;; + *) + virtioblk=virtio-blk-pci + ;; +esac + _make_test_img $size echo "Starting QEMU" _launch_qemu -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \ - -device virtio-blk-pci,drive=drive0 + -device $virtioblk,drive=drive0 echo echo "Starting a second QEMU using the same image should fail" echo 'quit' | $QEMU -monitor stdio \ -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \ - -device virtio-blk-pci,drive=drive0 2>&1 | _filter_testdir 2>&1 | + -device $virtioblk,drive=drive0 2>&1 | _filter_testdir 2>&1 | _filter_qemu | sed -e '/falling back to POSIX file/d' \ -e '/locks can be lost unexpectedly/d'
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 10/24] block/throttle-groups.c: allocate RestartData on the heap
In reply to Kevin WolfFrom: Manos Pitsidianakis <[email protected]>
RestartData is the opaque data of the throttle_group_restart_queue_entry coroutine. By being stack allocated, it isn't available anymore if aio_co_enter schedules the coroutine with a bottom half and runs after throttle_group_restart_queue returns.
--- block/throttle-groups.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
block/throttle-groups.c +7 -5
@@ -403,17 +403,19 @@ static void coroutine_fn throttle_group_restart_queue_entry(void *opaque)schedule_next_request (tgm, is_write);qemu_mutex_unlock (&tg->lock); } + +g_free (data); }static void throttle_group_restart_queue (ThrottleGroupMember *tgm,bool is_write) {Coroutine *co; -RestartData rd = { - .tgm = tgm, - .is_write = is_write - }; +RestartData *rd =g_new0 (RestartData,1 ); + + rd->tgm = tgm; + rd->is_write = is_write; - co =qemu_coroutine_create (throttle_group_restart_queue_entry, &rd); + co =qemu_coroutine_create (throttle_group_restart_queue_entry, rd);aio_co_enter (tgm->aio_context, co); }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 03/24] file-posix: Clear out first sector in hdev_create
In reply to Kevin WolfFrom: Fam Zheng <[email protected]>
People get surprised when, after "qemu-img create -f raw /dev/sdX", they still see qcow2 with "qemu-img info", if previously the bdev had a qcow2 header. While this is natural because raw doesn't need to write any magic bytes during creation, hdev_create is free to clear out the first sector to make sure the stale qcow2 header doesn't cause such confusion.
--- block/file-posix.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
block/file-posix.c +10 -0
@@ -2730,6 +2730,16 @@ static int hdev_create(const char *filename, QemuOpts *opts, ret = -ENOSPC ; } +if (!ret && total_size) { +uint8_t buf[BDRV_SECTOR_SIZE ] = {0 }; +int64_t zero_size =MIN (BDRV_SECTOR_SIZE , total_size); +if (lseek (fd,0 ,SEEK_SET ) ==-1 ) { + ret = -errno; + }else { + ret =qemu_write_full (fd, buf, zero_size); + ret = ret == zero_size ?0 : -errno; + } + }qemu_close (fd);return ret; }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 12/24] qemu-io: Drop write permissions before read-only reopen
In reply to Kevin Wolfqemu-io provides a 'reopen' command that allows switching from writable to read-only access. We need to make sure that we don't try to keep write permissions to a BlockBackend that becomes read-only, otherwise things are going to fail.
This requires a bdrv_drain() call because otherwise in-flight AIO write requests could issue new internal requests while the permission has already gone away, which would cause assertion failures. Draining the queue doesn't break AIO requests in any new way, bdrv_reopen() would drain it anyway only a few lines later.
--- qemu-io-cmds.c | 12 ++++++++++++ tests/qemu-iotests/187.out | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)
qemu-io-cmds.c +12 -0
@@ -2010,6 +2010,18 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv)return 0 ; } +if (!(flags &BDRV_O_RDWR )) { +uint64_t orig_perm, orig_shared_perm; + +bdrv_drain (bs); + +blk_get_perm (blk, &orig_perm, &orig_shared_perm); +blk_set_perm (blk, + orig_perm & ~(BLK_PERM_WRITE |BLK_PERM_WRITE_UNCHANGED ), + orig_shared_perm, + &error_abort); + } + qopts =qemu_opts_find (&reopen_opts,NULL ); opts = qopts ?qemu_opts_to_qdict (qopts,NULL ) :NULL ;qemu_opts_reset (&reopen_opts);
tests/qemu-iotests/187.out +1 -1
@@ -12,7 +12,7 @@ Start from read-write wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -write failed: Operation not permitted +Block node is read-only wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 09/24] throttle: Assert that bkt->max is valid in throttle_compute_wait()
In reply to Kevin WolfFrom: Alberto Garcia <[email protected]>
If bkt->max == 0 and bkt->burst_length > 1 then we could have a division by 0 in throttle_do_compute_wait(). That configuration is however not permitted and is already detected by throttle_is_valid(), but let's assert it in throttle_compute_wait() to make it explicit.
Found by Coverity (CID: 1381016).
--- util/throttle.c | 1 + 1 file changed, 1 insertion(+)
util/throttle.c +1 -0
@@ -124,6 +124,7 @@ int64_t throttle_compute_wait(LeakyBucket *bkt)/* If the main bucket is not full yet we still have to check the * burst bucket in order to enforce the burst limit */ if (bkt->burst_length >1 ) { +assert (bkt->max >0 );/* see throttle_is_valid() */ extra = bkt->burst_level - burst_bucket_size;if (extra >0 ) {return throttle_do_compute_wait (bkt->max, extra);
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 13/24] block: Add reopen_queue to bdrv_child_perm()
In reply to Kevin WolfIn the context of bdrv_reopen(), we'll have to look at the state of the graph as it will be after the reopen. This interface addition is in preparation for the change.
--- include/block/block_int.h | 7 +++++++ block.c | 19 ++++++++++++------- block/commit.c | 1 + block/mirror.c | 1 + block/replication.c | 1 + block/vvfat.c | 1 + 6 files changed, 23 insertions(+), 7 deletions(-)
include/block/block_int.h +7 -0
@@ -411,9 +411,14 @@ struct BlockDriver {* * If @c is NULL, return the permissions for attaching a new child for the * given @role. +* +* If @reopen_queue is non-NULL, don't return the currently needed +* permissions, but those that will be needed after applying the +* @reopen_queue. */ void (*bdrv_child_perm)(BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t parent_perm,uint64_t parent_shared,uint64_t *nperm,uint64_t *nshared);
@@ -983,6 +988,7 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,* all children */ void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared);
@@ -992,6 +998,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,* CONSISTENT_READ and doesn't share WRITE. */ void bdrv_format_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared);
block.c +12 -7
@@ -1537,16 +1537,17 @@ static void bdrv_child_abort_perm_update(BdrvChild *c);static void bdrv_child_set_perm (BdrvChild *c,uint64_t perm,uint64_t shared);static void bdrv_child_perm (BlockDriverState *bs,BlockDriverState *child_bs, -BdrvChild *c, -const BdrvChildRole *role, +BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t parent_perm,uint64_t parent_shared,uint64_t *nperm,uint64_t *nshared) {if (bs->drv && bs->drv->bdrv_child_perm) { - bs->drv->bdrv_child_perm (bs, c, role, + bs->drv->bdrv_child_perm (bs, c, role, reopen_queue, parent_perm, parent_shared, nperm, nshared); } +/* TODO Take force_share from reopen_queue */ if (child_bs && child_bs->force_share) { *nshared =BLK_PERM_ALL ; }
@@ -1596,7 +1597,7 @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,/* Check all children */ QLIST_FOREACH(c, &bs->children, next) {uint64_t cur_perm, cur_shared; -bdrv_child_perm (bs, c->bs, c, c->role, +bdrv_child_perm (bs, c->bs, c, c->role,NULL , cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, cur_perm, cur_shared, ignore_children,
@@ -1658,7 +1659,7 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,/* Update all children */ QLIST_FOREACH(c, &bs->children, next) {uint64_t cur_perm, cur_shared; -bdrv_child_perm (bs, c->bs, c, c->role, +bdrv_child_perm (bs, c->bs, c, c->role,NULL , cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared);bdrv_child_set_perm (c, cur_perm, cur_shared);
@@ -1827,6 +1828,7 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {
@@ -1844,6 +1846,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,void bdrv_format_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {
@@ -1853,9 +1856,11 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,if (!backing) {/* Apart from the modifications below, the same permissions are * forwarded and left alone as for filters */ -bdrv_filter_default_perms (bs, c, role, perm, shared, &perm, &shared); +bdrv_filter_default_perms (bs, c, role, reopen_queue, perm, shared, + &perm, &shared);/* Format drivers may touch metadata even if the guest doesn't write */ +/* TODO Take flags from reopen_queue */ if (bdrv_is_writable (bs)) { perm |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; }
@@ -1999,7 +2004,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,assert (parent_bs->drv);assert (bdrv_get_aio_context (parent_bs) ==bdrv_get_aio_context (child_bs)); -bdrv_child_perm (parent_bs, child_bs,NULL , child_role, +bdrv_child_perm (parent_bs, child_bs,NULL , child_role,NULL , perm, shared_perm, &perm, &shared_perm); child = bdrv_root_attach_child(child_bs, child_name, child_role,
block/commit.c +1 -0
@@ -257,6 +257,7 @@ static void bdrv_commit_top_close(BlockDriverState *bs)static void bdrv_commit_top_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {
block/mirror.c +1 -0
@@ -1084,6 +1084,7 @@ static void bdrv_mirror_top_close(BlockDriverState *bs)static void bdrv_mirror_top_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {
block/replication.c +1 -0
@@ -157,6 +157,7 @@ static void replication_close(BlockDriverState *bs)static void replication_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {
block/vvfat.c +1 -0
@@ -3202,6 +3202,7 @@ err:static void vvfat_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildRole *role, +BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 07/24] iotests: use virtio aliases for 067
In reply to Kevin WolfFrom: Cornelia Huck <[email protected]>
The default cpu model on s390x does not provide zPCI, which is not yet wired up on tcg. Moreover, virtio-ccw is the standard on s390x.
Using virtio-scsi will implicitly pick the right device, so just switch to that for simplicity.
--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tests/qemu-iotests/067 +1 -1
@@ -141,7 +141,7 @@ echo echo === Empty drive with -device and device_del === echo -run_qemu -device virtio-scsi-pci -device scsi-cd,id=cd0 <<EOF +run_qemu -device virtio-scsi -device scsi-cd,id=cd0 <<EOF { "execute": "qmp_capabilities" } { "execute": "query-block" } { "execute": "device_del", "arguments": { "id": "cd0" } }
tests/qemu-iotests/067.out +1 -1
@@ -419,7 +419,7 @@ Testing: === Empty drive with -device and device_del === -Testing: -device virtio-scsi-pci -device scsi-cd,id=cd0 +Testing: -device virtio-scsi -device scsi-cd,id=cd0 { QMP_VERSION }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 17/24] block: Fix permissions after bdrv_reopen()
In reply to Kevin WolfIf we switch between read-only and read-write, the permissions that image format drivers need on bs->file change, too. Make sure to update the permissions during bdrv_reopen().
--- include/block/block.h | 1 + block.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
include/block/block.h +1 -0
@@ -166,6 +166,7 @@ typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue; typedef struct BDRVReopenState { BlockDriverState *bs; int flags; + uint64_t perm, shared_perm; QDict *options; QDict *explicit_options; void *opaque;
block.c +64 -0
100 lines not on this page · raw message
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 18/24] qemu-iotests: Test change-backing-file command
In reply to Kevin WolfThis involves a temporary read-write reopen if the backing file link in the middle of a backing file chain should be changed and is therefore a good test for the latest bdrv_reopen() vs. op blockers fixes.
--- tests/qemu-iotests/195 | 92 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/195.out | 78 +++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 171 insertions(+) create mode 100755 tests/qemu-iotests/195 create mode 100644 tests/qemu-iotests/195.out
tests/qemu-iotests/195 new file +92 -0
@@ -0,0 +1,92 @@ +#!/bin/bash +# +# Test change-backing-file command +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.mid" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +function do_run_qemu() +{ + echo Testing: "$@" | _filter_imgfmt + $QEMU -nographic -qmp-pretty stdio -serial none "$@" + echo +} + +function run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp \ + | _filter_qemu_io | _filter_generated_node_ids +} + +size=64M +TEST_IMG="$TEST_IMG.base" _make_test_img $size +TEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" +_make_test_img -b "$TEST_IMG.mid" + +echo +echo "Change backing file of mid (opened read-only)" +echo + +run_qemu -drive if=none,file="$TEST_IMG",backing.node-name=mid <<EOF +{"execute":"qmp_capabilities"} +{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"mid","backing-file":"/dev/null"}} +{"execute":"quit"} +EOF + +TEST_IMG="$TEST_IMG.mid" _img_info + +echo +echo "Change backing file of top (opened writable)" +echo + +TEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" + +run_qemu -drive if=none,file="$TEST_IMG",node-name=top <<EOF +{"execute":"qmp_capabilities"} +{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"top","backing-file":"/dev/null"}} +{"execute":"quit"} +EOF + +_img_info + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/195.out new file +78 -0
78 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -189,3 +189,4 @@ 190 rw auto quick 192 rw auto quick 194 rw auto migration quick +195 rw auto quick
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 04/24] docs: add qemu-block-drivers(7) man page
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
Block driver documentation is available in qemu-doc.html. It would be convenient to have documentation for formats, protocols, and filter drivers in a man page.
Extract the relevant part of qemu-doc.html into a new file called docs/qemu-block-drivers.texi. This file can also be built as a stand-alone document (man, html, etc).
--- Makefile | 6 +- docs/qemu-block-drivers.texi | 804 +++++++++++++++++++++++++++++++++++++++++++ qemu-doc.texi | 781 +---------------------------------------- 3 files changed, 810 insertions(+), 781 deletions(-) create mode 100644 docs/qemu-block-drivers.texi
Makefile +5 -1
@@ -209,6 +209,7 @@ ifdef BUILD_DOCS DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8 DOCS+=docs/interop/qemu-qmp-ref.html docs/interop/qemu-qmp-ref.txt docs/interop/qemu-qmp-ref.7 DOCS+=docs/interop/qemu-ga-ref.html docs/interop/qemu-ga-ref.txt docs/interop/qemu-ga-ref.7 +DOCS+=docs/qemu-block-drivers.7 ifdef CONFIG_VIRTFS DOCS+=fsdev/virtfs-proxy-helper.1 endif
@@ -532,6 +533,7 @@ distclean: clean rm -f docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt rm -f docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf rm -f docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html + rm -f docs/qemu-block-drivers.7 for d in $(TARGET_DIRS); do \ rm -rf $$d || exit 1 ; \ done
@@ -576,6 +578,7 @@ ifdef CONFIG_POSIX $(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1" $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man7" $(INSTALL_DATA) docs/interop/qemu-qmp-ref.7 "$(DESTDIR)$(mandir)/man7" + $(INSTALL_DATA) docs/qemu-block-drivers.7 "$(DESTDIR)$(mandir)/man7" ifneq ($(TOOLS),) $(INSTALL_DATA) qemu-img.1 "$(DESTDIR)$(mandir)/man1" $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
@@ -721,6 +724,7 @@ qemu-img.1: qemu-img.texi qemu-option-trace.texi qemu-img-cmds.texi fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi qemu-nbd.8: qemu-nbd.texi qemu-option-trace.texi qemu-ga.8: qemu-ga.texi +docs/qemu-block-drivers.7: docs/qemu-block-drivers.texi html: qemu-doc.html docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html info: qemu-doc.info docs/interop/qemu-qmp-ref.info docs/interop/qemu-ga-ref.info
@@ -730,7 +734,7 @@ txt: qemu-doc.txt docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt qemu-doc.html qemu-doc.info qemu-doc.pdf qemu-doc.txt: \ qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \ qemu-monitor.texi qemu-img-cmds.texi qemu-ga.texi \ - qemu-monitor-info.texi + qemu-monitor-info.texi docs/qemu-block-drivers.texi docs/interop/qemu-ga-ref.dvi docs/interop/qemu-ga-ref.html \ docs/interop/qemu-ga-ref.info docs/interop/qemu-ga-ref.pdf \
docs/qemu-block-drivers.texi new file +804 -0
804 lines not on this page · raw message
qemu-doc.texi +1 -780
787 lines not on this page · raw message
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 15/24] block: Base permissions on rw state after reopen
In reply to Kevin WolfWhen new permissions are calculated during bdrv_reopen(), they need to be based on the state of the graph as it will be after the reopen has completed, not on the current state of the involved nodes.
This patch makes bdrv_is_writable() optionally accept a BlockReopenQueue from which the new flags are taken. This is then used for determining the new bs->file permissions of format drivers as soon as we add the code to actually pass a non-NULL reopen queue to the .bdrv_child_perm callbacks.
While moving bdrv_is_writable(), make it static. It isn't used outside block.c.
--- include/block/block.h | 1 - block.c | 52 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 16 deletions(-)
include/block/block.h +0 -1
@@ -435,7 +435,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum);bool bdrv_is_read_only (BlockDriverState *bs); -bool bdrv_is_writable (BlockDriverState *bs);int bdrv_can_set_read_only (BlockDriverState *bs,bool read_only,bool ignore_allow_rdw,Error **errp);int bdrv_set_read_only (BlockDriverState *bs,bool read_only,Error **errp);
block.c +37 -15
82 lines not on this page · raw message
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 11/24] block: Clean up some bad code in the vvfat driver
In reply to Kevin WolfFrom: Thomas Huth <[email protected]>
Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.
--- block/vvfat.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-)
block/vvfat.c +2 -24
@@ -57,15 +57,6 @@static void checkpoint (void ); -#ifdef __MINGW32__ -void nonono (const char * file,int line,const char * msg) { -fprintf (stderr,"Nonono! %s:%d %s\n" , file, line, msg); -exit (-5 ); -} -#undef assert -#define assert (a) do {if (!(a)) nonono(__FILE__, __LINE__, #a);}while(0) -#endif -#else #define DLOG (a)
@@ -3270,24 +3261,11 @@ static void bdrv_vvfat_init(void)block_init (bdrv_vvfat_init);#ifdef DEBUG -static void checkpoint (void ) { +static void checkpoint (void ) +{assert (((mapping_t *)array_get (&(vvv->mapping),0 ))->end ==2 );check1 (vvv);check2 (vvv);assert (!vvv->current_mapping || vvv->current_fd || (vvv->current_mapping->mode &MODE_DIRECTORY )); -#if 0 -if (((direntry_t *)vvv->directory.pointer)[1 ].attributes !=0xf ) -fprintf (stderr,"Nonono!\n" ); -mapping_t * mapping; -direntry_t * direntry; -assert (vvv->mapping.size >= vvv->mapping.item_size * vvv->mapping.next); -assert (vvv->directory.size >= vvv->directory.item_size * vvv->directory.next); -if (vvv->mapping.next<47 ) -return ; -assert ((mapping =array_get (&(vvv->mapping),47 ))); -assert (mapping->dir_index < vvv->directory.next); - direntry =array_get (&(vvv->directory), mapping->dir_index); -assert (!memcmp (direntry->name,"USB H " ,11 ) || direntry->name[0 ]==0 ); -#endif }#endif
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 19/24] iotests: fix 181: enable postcopy-ram capability on target
In reply to Kevin WolfFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Migration capabilities should be enabled on both source and destination qemu processes.
--- tests/qemu-iotests/181 | 2 ++ tests/qemu-iotests/181.out | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
tests/qemu-iotests/181 +2 -0
@@ -93,7 +93,9 @@ echo # Slow down migration so much that it definitely won't finish before we can # switch to postcopy +# Enable postcopy-ram capability both on source and destination silent=yes +_send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)" _send_qemu_cmd $src 'migrate_set_speed 4k' "(qemu)" _send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)" _send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)"
tests/qemu-iotests/181.out +0 -1
@@ -20,7 +20,6 @@ read 65536/65536 bytes at offset 0 === Do some I/O on the destination === -QEMU X.Y.Z monitor - type 'help' for more information (qemu) qemu-io disk "read -P 0x55 0 64k" read 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 14/24] block: Add reopen queue to bdrv_check_perm()
In reply to Kevin WolfIn the context of bdrv_reopen(), we'll have to look at the state of the graph as it will be after the reopen. This interface addition is in preparation for the change.
--- block.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
block.c +19 -15
@@ -1531,7 +1531,8 @@ static int bdrv_fill_options(QDict **options, const char *filename,return 0 ; } -static int bdrv_child_check_perm (BdrvChild *c,uint64_t perm,uint64_t shared, +static int bdrv_child_check_perm (BdrvChild *c,BlockReopenQueue *q, +uint64_t perm,uint64_t shared,GSList *ignore_children,Error **errp);static void bdrv_child_abort_perm_update (BdrvChild *c);static void bdrv_child_set_perm (BdrvChild *c,uint64_t perm,uint64_t shared);
@@ -1562,7 +1563,8 @@ static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,* A call to this function must always be followed by a call to bdrv_set_perm() * or bdrv_abort_perm_update(). */ -static int bdrv_check_perm (BlockDriverState *bs,uint64_t cumulative_perms, +static int bdrv_check_perm (BlockDriverState *bs,BlockReopenQueue *q, +uint64_t cumulative_perms,uint64_t cumulative_shared_perms,GSList *ignore_children,Error **errp) {
@@ -1597,11 +1599,11 @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,/* Check all children */ QLIST_FOREACH(c, &bs->children, next) {uint64_t cur_perm, cur_shared; -bdrv_child_perm (bs, c->bs, c, c->role,NULL , +bdrv_child_perm (bs, c->bs, c, c->role, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); - ret =bdrv_child_check_perm (c, cur_perm, cur_shared, ignore_children, - errp); + ret =bdrv_child_check_perm (c, q, cur_perm, cur_shared, + ignore_children, errp);if (ret <0 ) {return ret; }
@@ -1727,7 +1729,8 @@ char *bdrv_perm_names(uint64_t perm)* * Needs to be followed by a call to either bdrv_set_perm() or * bdrv_abort_perm_update(). */ -static int bdrv_check_update_perm (BlockDriverState *bs,uint64_t new_used_perm, +static int bdrv_check_update_perm (BlockDriverState *bs,BlockReopenQueue *q, +uint64_t new_used_perm,uint64_t new_shared_perm,GSList *ignore_children,Error **errp) {
@@ -1769,19 +1772,20 @@ static int bdrv_check_update_perm(BlockDriverState *bs, uint64_t new_used_perm, cumulative_shared_perms &= c->shared_perm; } -return bdrv_check_perm (bs, cumulative_perms, cumulative_shared_perms, +return bdrv_check_perm (bs, q, cumulative_perms, cumulative_shared_perms, ignore_children, errp); }/* Needs to be followed by a call to either bdrv_child_set_perm() or * bdrv_child_abort_perm_update(). */ -static int bdrv_child_check_perm (BdrvChild *c,uint64_t perm,uint64_t shared, +static int bdrv_child_check_perm (BdrvChild *c,BlockReopenQueue *q, +uint64_t perm,uint64_t shared,GSList *ignore_children,Error **errp) {int ret; ignore_children =g_slist_prepend (g_slist_copy (ignore_children), c); - ret =bdrv_check_update_perm (c->bs, perm, shared, ignore_children, errp); + ret =bdrv_check_update_perm (c->bs, q, perm, shared, ignore_children, errp);g_slist_free (ignore_children);return ret;
@@ -1809,7 +1813,7 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, {int ret; - ret =bdrv_child_check_perm (c, perm, shared,NULL , errp); + ret =bdrv_child_check_perm (c,NULL , perm, shared,NULL , errp);if (ret <0 ) {bdrv_child_abort_perm_update (c);return ret;
@@ -1950,7 +1954,7 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs)* because we're just taking a parent away, so we're loosening * restrictions. */ bdrv_get_cumulative_perm (old_bs, &perm, &shared_perm); -bdrv_check_perm (old_bs, perm, shared_perm,NULL , &error_abort); +bdrv_check_perm (old_bs,NULL , perm, shared_perm,NULL , &error_abort);bdrv_set_perm (old_bs, perm, shared_perm); }
@@ -1969,7 +1973,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,BdrvChild *child;int ret; - ret =bdrv_check_update_perm (child_bs, perm, shared_perm,NULL , errp); + ret =bdrv_check_update_perm (child_bs,NULL , perm, shared_perm,NULL , errp);if (ret <0 ) {bdrv_abort_perm_update (child_bs);return NULL ;
@@ -3184,7 +3188,7 @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,/* Check whether the required permissions can be granted on @to, ignoring * all BdrvChild in @list so that they can't block themselves. */ - ret =bdrv_check_update_perm (to, perm, shared, list, errp); + ret =bdrv_check_update_perm (to,NULL , perm, shared, list, errp);if (ret <0 ) {bdrv_abort_perm_update (to); goto out;
@@ -4054,7 +4058,7 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)/* Update permissions, they may differ for inactive nodes */ bdrv_get_cumulative_perm (bs, &perm, &shared_perm); - ret =bdrv_check_perm (bs, perm, shared_perm,NULL , &local_err); + ret =bdrv_check_perm (bs,NULL , perm, shared_perm,NULL , &local_err);if (ret <0 ) { bs->open_flags |=BDRV_O_INACTIVE ;error_propagate (errp, local_err);
@@ -4121,7 +4125,7 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,/* Update permissions, they may differ for inactive nodes */ bdrv_get_cumulative_perm (bs, &perm, &shared_perm); -bdrv_check_perm (bs, perm, shared_perm,NULL , &error_abort); +bdrv_check_perm (bs,NULL , perm, shared_perm,NULL , &error_abort);bdrv_set_perm (bs, perm, shared_perm); }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 16/24] block: reopen: Queue children after their parents
In reply to Kevin WolfWe will calculate the required new permissions in the prepare stage of a reopen. Required permissions of children can be influenced by the changes made to their parents, but parents are independent from their children. This means that permissions need to be calculated top-down. In order to achieve this, queue parents before their children rather than queuing the children first.
--- block.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
block.c +13 -13
@@ -2768,6 +2768,19 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, flags |=BDRV_O_ALLOW_RDWR ; } +if (!bs_entry) { + bs_entry =g_new0 (BlockReopenQueueEntry,1 ); +QSIMPLEQ_INSERT_TAIL (bs_queue, bs_entry, entry); + }else { +QDECREF (bs_entry->state.options); +QDECREF (bs_entry->state.explicit_options); + } + + bs_entry->state.bs = bs; + bs_entry->state.options = options; + bs_entry->state.explicit_options = explicit_options; + bs_entry->state.flags = flags; + QLIST_FOREACH(child, &bs->children, next) {QDict *new_child_options;char *child_key_dot;
@@ -2787,19 +2800,6 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, child->role, options, flags); } -if (!bs_entry) { - bs_entry =g_new0 (BlockReopenQueueEntry,1 ); -QSIMPLEQ_INSERT_TAIL (bs_queue, bs_entry, entry); - }else { -QDECREF (bs_entry->state.options); -QDECREF (bs_entry->state.explicit_options); - } - - bs_entry->state.bs = bs; - bs_entry->state.options = options; - bs_entry->state.explicit_options = explicit_options; - bs_entry->state.flags = flags; -return bs_queue; }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 22/24] qcow2: add shrink image support
In reply to Kevin WolfFrom: Pavel Butsykin <[email protected]>
This patch add shrinking of the image file for qcow2. As a result, this allows us to reduce the virtual image size and free up space on the disk without copying the image. Image can be fragmented and shrink is done by punching holes in the image file.
Message-id: [email protected]
--- qapi/block-core.json | 8 +++- block/qcow2.h | 14 ++++++ block/qcow2-cluster.c | 50 +++++++++++++++++++++ block/qcow2-refcount.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 43 ++++++++++++++---- 5 files changed, 225 insertions(+), 10 deletions(-)
qapi/block-core.json +7 -1
@@ -2533,6 +2533,11 @@ # # Trigger events supported by blkdebug. # +# @l1_shrink_write_table: write zeros to the l1 table to shrink image. +# (since 2.11) +# +# @l1_shrink_free_l2_clusters: discard the l2 tables. (since 2.11) +# # Since: 2.9 ## { 'enum': 'BlkdebugEvent', 'prefix': 'BLKDBG',
@@ -2549,7 +2554,8 @@ 'cluster_alloc_bytes', 'cluster_free', 'flush_to_os', 'flush_to_disk', 'pwritev_rmw_head', 'pwritev_rmw_after_head', 'pwritev_rmw_tail', 'pwritev_rmw_after_tail', 'pwritev', - 'pwritev_zero', 'pwritev_done', 'empty_image_prepare' ] } + 'pwritev_zero', 'pwritev_done', 'empty_image_prepare', + 'l1_shrink_write_table', 'l1_shrink_free_l2_clusters' ] } ## # @BlkdebugInjectErrorOptions:
block/qcow2.h +14 -0
@@ -521,6 +521,18 @@ static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)return r1 > r2 ? r1 - r2 : r2 - r1; } +static inline +uint32_t offset_to_reftable_index (BDRVQcow2State *s,uint64_t offset) +{ +return offset >> (s->refcount_block_bits + s->cluster_bits); +} + +static inline uint64_t get_refblock_offset (BDRVQcow2State *s,uint64_t offset) +{ +uint32_t index =offset_to_reftable_index (s, offset); +return s->refcount_table[index] &REFT_OFFSET_MASK ; +} +/* qcow2.c functions */ int qcow2_backing_read1 (BlockDriverState *bs,QEMUIOVector *qiov,int64_t sector_num,int nb_sectors);
@@ -584,10 +596,12 @@ int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,int qcow2_change_refcount_order (BlockDriverState *bs,int refcount_order,BlockDriverAmendStatusCB *status_cb,void *cb_opaque,Error **errp); +int qcow2_shrink_reftable (BlockDriverState *bs);/* qcow2-cluster.c functions */ int qcow2_grow_l1_table (BlockDriverState *bs,uint64_t min_size,bool exact_size); +int qcow2_shrink_l1_table (BlockDriverState *bs,uint64_t max_size);int qcow2_write_l1_entry (BlockDriverState *bs,int l1_index);int qcow2_decompress_cluster (BlockDriverState *bs,uint64_t cluster_offset); int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
block/qcow2-cluster.c +50 -0
56 lines not on this page · raw message
block/qcow2-refcount.c +120 -0
129 lines not on this page · raw message
block/qcow2.c +34 -9
52 lines not on this page · raw message
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 21/24] qcow2: add qcow2_cache_discard
In reply to Kevin WolfFrom: Pavel Butsykin <[email protected]>
Whenever l2/refcount table clusters are discarded from the file we can automatically drop unnecessary content of the cache tables. This reduces the chance of eviction useful cache data and eliminates inconsistent data in the cache with the data in the file.
Message-id: [email protected]
--- block/qcow2.h | 3 +++ block/qcow2-cache.c | 26 ++++++++++++++++++++++++++ block/qcow2-refcount.c | 20 ++++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-)
block/qcow2.h +3 -0
@@ -649,6 +649,9 @@ int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,int qcow2_cache_get_empty (BlockDriverState *bs,Qcow2Cache *c,uint64_t offset,void **table);void qcow2_cache_put (BlockDriverState *bs,Qcow2Cache *c,void **table); +void *qcow2_cache_is_table_offset (BlockDriverState *bs,Qcow2Cache *c, +uint64_t offset); +void qcow2_cache_discard (BlockDriverState *bs,Qcow2Cache *c,void *table);/* qcow2-bitmap.c functions */ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
block/qcow2-cache.c +26 -0
@@ -411,3 +411,29 @@ void qcow2_cache_entry_mark_dirty(BlockDriverState *bs, Qcow2Cache *c,assert (c->entries[i].offset !=0 ); c->entries[i].dirty = true; } + +void *qcow2_cache_is_table_offset (BlockDriverState *bs,Qcow2Cache *c, +uint64_t offset) +{ +int i; + +for (i =0 ; i < c->size; i++) { +if (c->entries[i].offset == offset) { +return qcow2_cache_get_table_addr (bs, c, i); + } + } +return NULL ; +} + +void qcow2_cache_discard (BlockDriverState *bs,Qcow2Cache *c,void *table) +{ +int i =qcow2_cache_get_table_idx (bs, c, table); + +assert (c->entries[i].ref ==0 ); + + c->entries[i].offset =0 ; + c->entries[i].lru_counter =0 ; + c->entries[i].dirty = false; + +qcow2_cache_table_release (bs, c, i,1 ); +}
block/qcow2-refcount.c +18 -2
@@ -861,8 +861,24 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, } s->set_refcount (refcount_block, block_index, refcount); -if (refcount ==0 && s->discard_passthrough[type]) { -update_refcount_discard (bs, cluster_offset, s->cluster_size); +if (refcount ==0 ) { +void *table; + + table =qcow2_cache_is_table_offset (bs, s->refcount_block_cache, + offset); +if (table !=NULL ) { +qcow2_cache_put (bs, s->refcount_block_cache, &refcount_block); +qcow2_cache_discard (bs, s->refcount_block_cache, table); + } + + table =qcow2_cache_is_table_offset (bs, s->l2_table_cache, offset); +if (table !=NULL ) { +qcow2_cache_discard (bs, s->l2_table_cache, table); + } + +if (s->discard_passthrough[type]) { +update_refcount_discard (bs, cluster_offset, s->cluster_size); + } } }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 23/24] qemu-iotests: add shrinking image test
In reply to Kevin WolfFrom: Pavel Butsykin <[email protected]>
Message-id: [email protected]
--- tests/qemu-iotests/163 | 170 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/163.out | 5 ++ tests/qemu-iotests/group | 1 + 3 files changed, 176 insertions(+) create mode 100644 tests/qemu-iotests/163 create mode 100644 tests/qemu-iotests/163.out
tests/qemu-iotests/163 new file +170 -0
@@ -0,0 +1,170 @@ +#!/usr/bin/env python +# +# Tests for shrinking images +# +# Copyright (c) 2016-2017 Parallels International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import os, random, iotests, struct, qcow2 +from iotests import qemu_img, qemu_io, image_size + +test_img = os.path.join(iotests.test_dir, 'test.img') +check_img = os.path.join(iotests.test_dir, 'check.img') + +def size_to_int(str): + suff = ['B', 'K', 'M', 'G', 'T'] + return int(str[:-1]) * 1024**suff.index(str[-1:]) + +class ShrinkBaseClass(iotests.QMPTestCase): + image_len = '128M' + shrink_size = '10M' + chunk_size = '16M' + refcount_bits = '16' + + def __qcow2_check(self, filename): + entry_bits = 3 + entry_size = 1 << entry_bits + l1_mask = 0x00fffffffffffe00 + div_roundup = lambda n, d: (n + d - 1) / d + + def split_by_n(data, n): + for x in xrange(0, len(data), n): + yield struct.unpack('>Q', data[x:x + n])[0] & l1_mask + + def check_l1_table(h, l1_data): + l1_list = list(split_by_n(l1_data, entry_size)) + real_l1_size = div_roundup(h.size, + 1 << (h.cluster_bits*2 - entry_size)) + used, unused = l1_list[:real_l1_size], l1_list[real_l1_size:] + + self.assertTrue(len(used) != 0, "Verifying l1 table content") + self.assertFalse(any(unused), "Verifying l1 table content") + + def check_reftable(fd, h, reftable): + for offset in split_by_n(reftable, entry_size): + if offset != 0: + fd.seek(offset) + cluster = fd.read(1 << h.cluster_bits) + self.assertTrue(any(cluster), "Verifying reftable content") + + with open(filename, "rb") as fd: + h = qcow2.QcowHeader(fd) + + fd.seek(h.l1_table_offset) + l1_table = fd.read(h.l1_size << entry_bits) + + fd.seek(h.refcount_table_offset) + reftable = fd.read(h.refcount_table_clusters << h.cluster_bits) + + check_l1_table(h, l1_table) + check_reftable(fd, h, reftable) + + def __raw_check(self, filename): + pass + + image_check = { + 'qcow2' : __qcow2_check, + 'raw' : __raw_check + } + + def setUp(self): + if iotests.imgfmt == 'raw': + qemu_img('create', '-f', iotests.imgfmt, test_img, self.image_len) + qemu_img('create', '-f', iotests.imgfmt, check_img, + self.shrink_size) + else: + qemu_img('create', '-f', iotests.imgfmt, + '-o', 'cluster_size=' + self.cluster_size + + ',refcount_bits=' + self.refcount_bits, + test_img, self.image_len) + qemu_img('create', '-f', iotests.imgfmt, + '-o', 'cluster_size=%s'% self.cluster_size, + check_img, self.shrink_size) + qemu_io('-c', 'write -P 0xff 0 ' + self.shrink_size, check_img) + + def tearDown(self): + os.remove(test_img) + os.remove(check_img) + + def image_verify(self): + self.assertEqual(image_size(test_img), image_size(check_img), + "Verifying image size") + self.image_check[iotests.imgfmt](self, test_img) + + if iotests.imgfmt == 'raw': + return + self.assertEqual(qemu_img('check', test_img), 0, + "Verifying image corruption") + + def test_empty_image(self): + qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, + self.shrink_size) + + self.assertEqual( + qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, test_img), + qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, check_img), + "Verifying image content") + + self.image_verify() + + def test_sequential_write(self): + for offs in range(0, size_to_int(self.image_len), + size_to_int(self.chunk_size)): + qemu_io('-c', 'write -P 0xff %d %s' % (offs, self.chunk_size), + test_img) + + qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, + self.shrink_size) + + self.assertEqual(qemu_img("compare", test_img, check_img), 0, + "Verifying image content") + + self.image_verify() + + def test_random_write(self): + offs_list = range(0, size_to_int(self.image_len), + size_to_int(self.chunk_size)) + random.shuffle(offs_list) + for offs in offs_list: + qemu_io('-c', 'write -P 0xff %d %s' % (offs, self.chunk_size), + test_img) + + qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, + self.shrink_size) + + self.assertEqual(qemu_img("compare", test_img, check_img), 0, + "Verifying image content") + + self.image_verify() + +class TestShrink512(ShrinkBaseClass): + image_len = '3M' + shrink_size = '1M' + chunk_size = '256K' + cluster_size = '512' + refcount_bits = '64' + +class TestShrink64K(ShrinkBaseClass): + cluster_size = '64K' + +class TestShrink1M(ShrinkBaseClass): + cluster_size = '1M' + refcount_bits = '1' + +ShrinkBaseClass = None + +if __name__ == '__main__': + iotests.main(supported_fmts=['raw', 'qcow2'])
tests/qemu-iotests/163.out new file +5 -0
@@ -0,0 +1,5 @@ +......... +---------------------------------------------------------------------- +Ran 9 tests + +OK
tests/qemu-iotests/group +1 -0
@@ -166,6 +166,7 @@ 159 rw auto quick 160 rw auto quick 162 auto quick +163 rw auto quick 165 rw auto quick 170 rw auto quick 171 rw auto quick
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 20/24] qemu-img: add --shrink flag for resize
In reply to Kevin WolfFrom: Pavel Butsykin <[email protected]>
The flag is additional precaution against data loss. Perhaps in the future the operation shrink without this flag will be blocked for all formats, but for now we need to maintain compatibility with raw.
Message-id: [email protected]
--- qemu-img.c | 23 +++++++++++++++++++++++ qemu-img-cmds.hx | 4 ++-- qemu-img.texi | 6 +++++- tests/qemu-iotests/102 | 4 ++-- tests/qemu-iotests/106 | 2 +- 5 files changed, 33 insertions(+), 6 deletions(-)
qemu-img.c +23 -0
@@ -64,6 +64,7 @@ enum {OPTION_TARGET_IMAGE_OPTS =263 ,OPTION_SIZE =264 ,OPTION_PREALLOCATION =265 , + OPTION_SHRINK = 266, }; typedef enum OutputFormat {
@@ -3436,6 +3437,7 @@ static int img_resize(int argc, char **argv) }, };bool image_opts = false; +bool shrink = false;/* Remove size from argv manually so that negative numbers are not treated * as options by getopt. */
@@ -3454,6 +3456,7 @@ static int img_resize(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"preallocation", required_argument, 0, OPTION_PREALLOCATION}, + {"shrink", no_argument, 0, OPTION_SHRINK}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":f:hq",
@@ -3496,6 +3499,9 @@ static int img_resize(int argc, char **argv)return 1 ; }break ; +case OPTION_SHRINK : + shrink = true; +break ; } }if (optind != argc -1 ) {
@@ -3569,6 +3575,23 @@ static int img_resize(int argc, char **argv) goto out; } +if (total_size < current_size && !shrink) { +warn_report ("Shrinking an image will delete all data beyond the " +"shrunken image's end. Before performing such an " +"operation, make sure there is no important data there." ); + +if (g_strcmp0 (bdrv_get_format_name (blk_bs (blk)),"raw" ) !=0 ) { +error_report ( +"Use the --shrink option to perform a shrink operation." ); + ret =-1 ; + goto out; + }else { +warn_report ("Using the --shrink option will suppress this message. " +"Note that future versions of qemu-img may refuse to " +"shrink images without this option." ); + } + } + ret =blk_truncate (blk, total_size, prealloc, &err);if (!ret) {qprintf (quiet,"Image resized.\n" );
qemu-img-cmds.hx +2 -2
@@ -89,9 +89,9 @@ STEXI ETEXI DEF("resize", img_resize, - "resize [--object objectdef] [--image-opts] [-q] filename [+ | -]size") + "resize [--object objectdef] [--image-opts] [-q] [--shrink] filename [+ | -]size") STEXI -@item resize [--object @var{objectdef}] [--image-opts] [-q] @var{filename} [+ | -]@var{size} +@item resize [--object @var{objectdef}] [--image-opts] [-q] [--shrink] @var{filename} [+ | -]@var{size} ETEXI STEXI
qemu-img.texi +5 -1
@@ -545,7 +545,7 @@ qemu-img rebase -b base.img diff.qcow2 At this point, @code{modified.img} can be discarded, since @code{base.img + diff.qcow2} contains the same information. -@item resize [--preallocation=@var{prealloc}] @var{filename} [+ | -]@var{size} +@item resize [--shrink] [--preallocation=@var{prealloc}] @var{filename} [+ | -]@var{size} Change the disk image as if it had been created with @var{size}.
@@ -553,6 +553,10 @@ Before using this command to shrink a disk image, you MUST use file system and partitioning tools inside the VM to reduce allocated file systems and partition sizes accordingly. Failure to do so will result in data loss! +When shrinking images, the @code{--shrink} option must be given. This informs +qemu-img that the user acknowledges all loss of data beyond the truncated +image's end. + After using this command to grow a disk image, you must use file system and partitioning tools inside the VM to actually begin using the new space on the device.
tests/qemu-iotests/102 +2 -2
@@ -54,7 +54,7 @@ _make_test_img $IMG_SIZE $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io # Remove data cluster from image (first cluster: image header, second: reftable, # third: refblock, fourth: L1 table, fifth: L2 table) -$QEMU_IMG resize -f raw "$TEST_IMG" $((5 * 64 * 1024)) +$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024)) $QEMU_IO -c map "$TEST_IMG" $QEMU_IMG map "$TEST_IMG"
@@ -69,7 +69,7 @@ $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io qemu_comm_method=monitor _launch_qemu -drive if=none,file="$TEST_IMG",id=drv0 -$QEMU_IMG resize -f raw "$TEST_IMG" $((5 * 64 * 1024)) +$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024)) _send_qemu_cmd $QEMU_HANDLE 'qemu-io drv0 map' 'allocated' \ | sed -e 's/^(qemu).*qemu-io drv0 map...$/(qemu) qemu-io drv0 map/'
tests/qemu-iotests/106 +1 -1
@@ -83,7 +83,7 @@ echo '=== Testing image shrinking ===' for growth_mode in falloc full off; do echo echo "--- growth_mode=$growth_mode ---" - $QEMU_IMG resize -f "$IMGFMT" --preallocation=$growth_mode "$TEST_IMG" -${GROWTH_SIZE}K + $QEMU_IMG resize -f "$IMGFMT" --shrink --preallocation=$growth_mode "$TEST_IMG" -${GROWTH_SIZE}K done # success, all done
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 24/24] block/qcow2-bitmap: fix use of uninitialized pointer
In reply to Kevin WolfFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Without initialization to zero dirty_bitmap field may be not zero for a bitmap which should not be stored and qcow2_store_persistent_dirty_bitmaps will erroneously call store_bitmap for it which leads to SIGSEGV on bdrv_dirty_bitmap_name.
Message-id: [email protected]
--- block/qcow2-bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/qcow2-bitmap.c +1 -1
@@ -602,7 +602,7 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t offset, goto fail; } - bm =g_new (Qcow2Bitmap,1 ); + bm =g_new0 (Qcow2Bitmap,1 ); bm->table.offset = e->bitmap_table_offset; bm->table.size = e->bitmap_table_size; bm->flags = e->flags;
Signature · 1 line
2.13.5
Peter Maydell
AppliedQuoted 8 lines · Kevin Wolf
The following changes since commit
1e3ee834083227f552179f6e43902cba5a866e6b:Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging (2017-09-25 20:31:24 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.gittags/for-upstream
Quoted 8 lines
for you to fetch changes up to
b156d51b62e6970753e1f9f36f7c4d5fdbf4c619:Merge remote-tracking branch 'mreitz/tags/pull-block-2017-09-26' into queue-block (2017-09-26 15:03:02 +0200)
----------------------------------------------------------------
Block layer patches----------------------------------------------------------------
Applied, thanks.
-- PMM