Block patches for 1.2-rc2
The following changes since commit 18fec301cd2a38f72a5eeba2656a0c5b4fa69fb7:
tcg/mips: fix broken CONFIG_TCG_PASS_AREG0 code (2012-08-28 20:38:39 +0200)
are available in the git repository at:
http://repo.or.cz/r/qemu/kevin.git for-anthony
Stefan Hajnoczi (3):
qed: refuse unaligned zero writes with a backing file
stream: complete early if end of backing file is reached
qemu-iotests: add backing file smaller than image test case
block/qed.c | 11 +++++++++++ block/stream.c | 6 ++++++ tests/qemu-iotests/030 | 33 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/030.out | 4 ++-- 4 files changed, 52 insertions(+), 2 deletions(-)
PATCH 1/3 qed: refuse unaligned zero writes with a backing file
From: Stefan Hajnoczi <[email protected]>
Zero writes have cluster granularity in QED. Therefore they can only be used to zero entire clusters.
If the zero write request leaves sectors untouched, zeroing the entire cluster would obscure the backing file. Instead return -ENOTSUP, which is handled by block.c:bdrv_co_do_write_zeroes() and falls back to a regular write.
The qemu-iotests 034 test cases covers this scenario.
--- block/qed.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
block/qed.c +11 -0
@@ -1363,10 +1363,21 @@ static int coroutine_fn bdrv_qed_co_write_zeroes(BlockDriverState *bs, int nb_sectors) {BlockDriverAIOCB *blockacb; +BDRVQEDState *s = bs->opaque;QEDWriteZeroesCB cb = { .done = false };QEMUIOVector qiov;struct iovec iov; +/* Refuse if there are untouched backing file sectors */ +if (bs->backing_hd) { +if (qed_offset_into_cluster (s, sector_num *BDRV_SECTOR_SIZE ) !=0 ) { +return -ENOTSUP ; + } +if (qed_offset_into_cluster (s, nb_sectors *BDRV_SECTOR_SIZE ) !=0 ) { +return -ENOTSUP ; + } + } +/* Zero writes start without an I/O buffer. If a buffer becomes necessary * then it will be allocated during request processing. */
Signature · 1 line
1.7.6.5
PATCH 2/3 stream: complete early if end of backing file is reached
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
It is possible to create an image that is larger than its backing file. Reading beyond the end of the backing file produces zeroes if no writes have been made to those sectors in the image file.
This patch finishes streaming early when the end of the backing file is reached. Without this patch the block job hangs and continually tries to stream the first sectors beyond the end of the backing file.
To reproduce the hung block job bug:
$ qemu-img create -f qcow2 backing.qcow2 128M $ qemu-img create -f qcow2 -o backing_file=backing.qcow2 image.qcow2 6G $ qemu -drive if=virtio,cache=none,file=image.qcow2 (qemu) block_stream virtio0 (qemu) info block-jobs
The qemu-iotests 030 streaming test still passes.
--- block/stream.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
block/stream.c +6 -0
@@ -122,6 +122,12 @@ wait:* known-unallocated area [sector_num, sector_num+n). */ ret =bdrv_co_is_allocated_above (bs->backing_hd, base, sector_num, n, &n); + +/* Finish early if end of backing file has been reached */ +if (ret ==0 && n ==0 ) { + n = end - sector_num; + } + copy = (ret ==1 ); }trace_stream_one_iteration (s, sector_num, n, ret);
Signature · 1 line
1.7.6.5
PATCH 3/3 qemu-iotests: add backing file smaller than image test case
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
This new test case checks that streaming completes successfully when the backing file is smaller than the image file.
--- tests/qemu-iotests/030 | 33 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/030.out | 4 ++-- 2 files changed, 35 insertions(+), 2 deletions(-)
tests/qemu-iotests/030 +33 -0
@@ -125,6 +125,39 @@ class TestSingleDrive(ImageStreamingTestCase): result = self.vm.qmp('block-stream', device='nonexistent') self.assert_qmp(result, 'error/class', 'DeviceNotFound') + +class TestSmallerBackingFile(ImageStreamingTestCase): + backing_len = 1 * 1024 * 1024 # MB + image_len = 2 * backing_len + + def setUp(self): + self.create_image(backing_img, self.backing_len) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img, str(self.image_len)) + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + # If this hangs, then you are missing a fix to complete streaming when the + # end of the backing file is reached. + def test_stream(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0') + self.assert_qmp(result, 'return', {}) + + completed = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_COMPLETED': + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() + + class TestStreamStop(ImageStreamingTestCase): image_len = 8 * 1024 * 1024 * 1024 # GB
tests/qemu-iotests/030.out +2 -2
@@ -1,5 +1,5 @@ -...... +....... ---------------------------------------------------------------------- -Ran 6 tests +Ran 7 tests OK
Signature · 1 line
1.7.6.5