drive-mirror: limit niov to MAX_IOV
cover drive-mirror: limit niov to MAX_IOV
e5b43573 caused a regression in the preparation of our IO vectors, such that if a small granularity but a large buffer size is chosen, we may accidentally exceed MAX_IOV and the request will fail.
This has been fixed before in cae98cb8, and now we'll fix it again. To keep it fixed, we'll add an iotest this time.
[Thanks to Max for finding the root cause.]
John Snow (3):
mirror: clarify mirror_do_read return code
mirror: limit niov to IOV_MAX elements, again
iotests: add small-granularity mirror test
block/mirror.c | 10 ++++++++-- tests/qemu-iotests/041 | 30 ++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 3 files changed, 40 insertions(+), 4 deletions(-)
Signature · 1 line
2.4.11
PATCH 1/3 mirror: clarify mirror_do_read return code
mirror_do_read intends to return the number of sectors processed after the starting sector, without regard to how many sectors were processed before the starting sector due to alignment.
Clean up the comments and code to hopefully illustrate this more clearly.
This also fixes an issue in initialization where if the mirror buffer size is initialized to smaller than the number of sectors being requested for transfer, we report back an incorrectly large number to the caller.
--- block/mirror.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
block/mirror.c +5 -2
@@ -218,7 +218,9 @@ static inline void mirror_wait_for_io(MirrorBlockJob *s) }/* Submit async read while handling COW. -* Returns: nb_sectors if no alignment is necessary, or +* Returns: The number of sectors copied after and including sector_num, +* excluding any sectors copied prior to sector_num due to alignment. +* This will be nb_sectors if no alignment is necessary, or * (new_end - sector_num) if tail is rounded up or down due to * alignment or buffer limit. */
@@ -227,7 +229,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num, {BlockBackend *source = s->common.blk;int sectors_per_chunk, nb_chunks; -int ret = nb_sectors; +int ret;MirrorOp *op; sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;
@@ -235,6 +237,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,/* We can only handle as much as buf_size at a time. */ nb_sectors =MIN (s->buf_size >>BDRV_SECTOR_BITS , nb_sectors);assert (nb_sectors); + ret = nb_sectors;if (s->cow_bitmap) { ret +=mirror_cow_align (s, §or_num, &nb_sectors);
Signature · 1 line
2.4.11
PATCH 3/3 iotests: add small-granularity mirror test
In reply to John Snow--- tests/qemu-iotests/041 | 30 ++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-)
tests/qemu-iotests/041 +30 -0
@@ -727,6 +727,36 @@ class TestUnbackedSource(iotests.QMPTestCase): self.complete_and_wait() self.assert_no_active_block_jobs() +class TestGranularity(iotests.QMPTestCase): + image_len = 10 * 1024 * 1024 # MB + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, + str(TestGranularity.image_len)) + qemu_io('-c', 'write 0 %d' % (self.image_len), + test_img) + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirroring') + os.remove(test_img) + os.remove(target_img) + + def test_granularity(self): + self.assert_no_active_block_jobs() + result = self.vm.qmp('drive-mirror', device='drive0', + sync='full', target=target_img, + mode='absolute-paths', granularity=8192) + self.assert_qmp(result, 'return', {}) + event = self.vm.get_qmp_event(wait=60.0) + # Failures will manifest as COMPLETED/ERROR. + self.assert_qmp(event, 'event', 'BLOCK_JOB_READY') + self.complete_and_wait(drive='drive0', wait_ready=False) + self.assert_no_active_block_jobs() + class TestRepairQuorum(iotests.QMPTestCase): """ This class test quorum file repair using drive-mirror. It's mostly a fork of TestSingleDrive """
tests/qemu-iotests/041.out +2 -2
@@ -1,5 +1,5 @@ -........................................................................... +............................................................................ ---------------------------------------------------------------------- -Ran 75 tests +Ran 76 tests OK
Signature · 1 line
2.4.11
PATCH 2/3 mirror: limit niov to IOV_MAX elements, again
In reply to John SnowDuring the refactor of mirror_iteration in e5b43573, we regressed the fix introduced in cae98cb8.
This patch re-adds IOV_MAX checking to cases where we aren't checking alignment (and size) already.
--- block/mirror.c | 3 +++ 1 file changed, 3 insertions(+)
block/mirror.c +3 -0
@@ -231,11 +231,14 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,int sectors_per_chunk, nb_chunks;int ret;MirrorOp *op; +int max_sectors; sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ; + max_sectors = sectors_per_chunk * s->max_iov;/* We can only handle as much as buf_size at a time. */ nb_sectors =MIN (s->buf_size >>BDRV_SECTOR_BITS , nb_sectors); + nb_sectors =MIN (max_sectors, nb_sectors);assert (nb_sectors); ret = nb_sectors;
Signature · 1 line
2.4.11
Re: [Qemu-devel] [PATCH 1/3] mirror: clarify mirror_do_read return code
In reply to John SnowQuoted 4 lines · John Snow
mirror_do_readintends to return the number of sectors processed after the starting sector, without regard to how many sectors were processed before the starting sector due to alignment.
Eventually, we may want this to be in terms of bytes instead of sectors; but for now the new wording is an improvement.
Quoted 11 lines
Clean up the comments and code to hopefully illustrate this more clearly.
This also fixes an issue in initialization where if the mirror buffer size is initialized to smaller than the number of sectors being requested for transfer, we report back an incorrectly large number to the caller.
Signed-off-by John Snow <[email protected]>--- block/mirror.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/3] mirror: limit niov to IOV_MAX elements, again
In reply to John SnowQuoted 10 lines · John Snow
During the refactor of
mirror_iterationine5b43573, we regressed the fix introduced incae98cb8.This patch re-adds
IOV_MAXchecking to cases where we aren't checking alignment (and size) already.Signed-off-by John Snow <[email protected]>--- block/mirror.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 21 lines
block/mirror.c +3
-0@@ -231,11 +231,14 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,int sectors_per_chunk, nb_chunks;int ret;MirrorOp *op; +int max_sectors; sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ; + max_sectors = sectors_per_chunk * s->max_iov;/* We can only handle as much as buf_size at a time. */ nb_sectors =MIN (s->buf_size >>BDRV_SECTOR_BITS , nb_sectors); + nb_sectors =MIN (max_sectors, nb_sectors);assert (nb_sectors); ret = nb_sectors;
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] iotests: add small-granularity mirror test
In reply to John SnowQuoted 6 lines · John Snow
Signed-off-by John Snow <[email protected]>--- tests/qemu-iotests/041 | 30 ++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/3] mirror: clarify mirror_do_read return code
In reply to John SnowQuoted 9 lines · John Snow
mirror_do_readintends to return the number of sectors processed after the starting sector, without regard to how many sectors were processed before the starting sector due to alignment.Clean up the comments and code to hopefully illustrate this more clearly.
This also fixes an issue in initialization where if the mirror buffer size is initialized to smaller than the number of sectors being requested for transfer, we report back an incorrectly large number to the caller.
Good catch!
Quoted 41 lines
Signed-off-by John Snow <[email protected]>--- block/mirror.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)block/mirror.c +5
-2@@ -218,7 +218,9 @@ static inline void mirror_wait_for_io(MirrorBlockJob *s) }/* Submit async read while handling COW. -* Returns: nb_sectors if no alignment is necessary, or +* Returns: The number of sectors copied after and including sector_num, +* excluding any sectors copied prior to sector_num due to alignment. +* This will be nb_sectors if no alignment is necessary, or * (new_end - sector_num) if tail is rounded up or down due to * alignment or buffer limit. */ @@ -227,7 +229,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num, {BlockBackend *source = s->common.blk;int sectors_per_chunk, nb_chunks; -int ret = nb_sectors; +int ret;MirrorOp *op; sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;@@ -235,6 +237,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,/* We can only handle as much as buf_size at a time. */ nb_sectors =MIN (s->buf_size >>BDRV_SECTOR_BITS , nb_sectors);assert (nb_sectors); + ret = nb_sectors;if (s->cow_bitmap) { ret +=mirror_cow_align (s, §or_num, &nb_sectors);Signature · 1 line
2.4.11
Re: [Qemu-devel] [PATCH 2/3] mirror: limit niov to IOV_MAX elements, again
In reply to John SnowQuoted 33 lines · John Snow
During the refactor of
mirror_iterationine5b43573, we regressed the fix introduced incae98cb8.This patch re-adds
IOV_MAXchecking to cases where we aren't checking alignment (and size) already.Signed-off-by John Snow <[email protected]>--- block/mirror.c | 3 +++ 1 file changed, 3 insertions(+)block/mirror.c +3
-0@@ -231,11 +231,14 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,int sectors_per_chunk, nb_chunks;int ret;MirrorOp *op; +int max_sectors; sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ; + max_sectors = sectors_per_chunk * s->max_iov;/* We can only handle as much as buf_size at a time. */ nb_sectors =MIN (s->buf_size >>BDRV_SECTOR_BITS , nb_sectors); + nb_sectors =MIN (max_sectors, nb_sectors);assert (nb_sectors); ret = nb_sectors;Signature · 1 line
2.4.11
Re: [Qemu-devel] [PATCH 3/3] iotests: add small-granularity mirror test
In reply to John SnowQuoted 5 lines · John Snow
Signed-off-by John Snow <[email protected]>--- tests/qemu-iotests/041 | 30 ++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-)
Ping, all good?
Jeff Cody, I think this is yours?
Quoted 19 lines · John Snow
e5b43573caused a regression in the preparation of our IO vectors, such that if a small granularity but a large buffer size is chosen, we may accidentally exceedMAX_IOVand the request will fail.This has been fixed before in
cae98cb8, and now we'll fix it again. To keep it fixed, we'll add an iotest this time.[Thanks to Max for finding the root cause.]
John Snow (3):
mirror: clarifymirror_do_readreturn code
mirror: limit niov toIOV_MAXelements, again
iotests: add small-granularity mirror testblock/mirror.c | 10 ++++++++-- tests/qemu-iotests/041 | 30 ++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 3 files changed, 40 insertions(+), 4 deletions(-)
Jeff Cody
AppliedQuoted 14 lines · John Snow
e5b43573caused a regression in the preparation of our IO vectors, such that if a small granularity but a large buffer size is chosen, we may accidentally exceedMAX_IOVand the request will fail.This has been fixed before in
cae98cb8, and now we'll fix it again. To keep it fixed, we'll add an iotest this time.[Thanks to Max for finding the root cause.]
John Snow (3):
mirror: clarifymirror_do_readreturn code
mirror: limit niov toIOV_MAXelements, again
iotests: add small-granularity mirror test
Quoted 8 lines
block/mirror.c | 10 ++++++++-- tests/qemu-iotests/041 | 30 ++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 3 files changed, 40 insertions(+), 4 deletions(-)Signature · 1 line
2.4.11
Thanks,
Applied to my block branch:
git://github.com/codyprime/qemu-kvm-jtc.git block
-Jeff