block: A few more copy offloading fixes
cover block: A few more copy offloading fixes
These are unfortunately more serious than the previous two fixes but the patches are not complicated.
Fam Zheng (3):
qcow2: Fix src_offset in copy offloading
iscsi: Don't blindly use designator length in response for memcpy
file-posix: Fix EINTR handling
block/file-posix.c | 17 +++++++++-------- block/iscsi.c | 2 +- block/qcow2.c | 1 + tests/qemu-iotests/063 | 9 +++++++++ tests/qemu-iotests/063.out | 12 ++++++++++++ 5 files changed, 32 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 qcow2: Fix src_offset in copy offloading
Not updating src_offset will result in wrong data being written to dst image.
--- block/qcow2.c | 1 + tests/qemu-iotests/063 | 9 +++++++++ tests/qemu-iotests/063.out | 12 ++++++++++++ 3 files changed, 22 insertions(+)
block/qcow2.c +1 -0
@@ -3422,6 +3422,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, } bytes -= cur_bytes; + src_offset += cur_bytes; dst_offset += cur_bytes; } ret =0 ;
tests/qemu-iotests/063 +9 -0
@@ -91,6 +91,15 @@ if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG.orig" "$TEST_IMG" >/dev exit 1 fi +echo "== Regression testing for copy offloading bug ==" + +_make_test_img 1M +TEST_IMG="$TEST_IMG.target" _make_test_img 1M +$QEMU_IO -c 'write -P 1 0 512k' -c 'write -P 2 512k 512k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c 'write -P 4 512k 512k' -c 'write -P 3 0 512k' "$TEST_IMG.target" | _filter_qemu_io +$QEMU_IMG convert -n -O $IMGFMT "$TEST_IMG" "$TEST_IMG.target" +$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.target" + echo "*** done" rm -f $seq.full status=0
tests/qemu-iotests/063.out +12 -0
@@ -7,4 +7,16 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304 No errors were found on the image. == Testing conversion to a smaller file fails == Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2097152 +== Regression testing for copy offloading bug == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +Formatting 'TEST_DIR/t.IMGFMT.target', fmt=IMGFMT size=1048576 +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 524288 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 524288 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Images are identical. *** done
Signature · 1 line
2.17.1
PATCH 2/3 iscsi: Don't blindly use designator length in response for memcpy
In reply to Fam ZhengPer SCSI definition the designator_length we receive from INQUIRY is 8, 12 or at most 16, but we should be careful because the remote iscsi target may misbehave, otherwise we could have a buffer overflow.
--- block/iscsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +1 -1
@@ -2226,7 +2226,7 @@ static void iscsi_populate_target_desc(unsigned char *desc, IscsiLun *lun) desc[5 ] = (dd->designator_type &0xF ) | ((dd->association &3 ) <<4 ); desc[7 ] = dd->designator_length; -memcpy (desc +8 , dd->designator, dd->designator_length); +memcpy (desc +8 , dd->designator,MIN (dd->designator_length,20 )); desc[28 ] =0 ; desc[29 ] = (lun->block_size >>16 ) &0xFF ;
Signature · 1 line
2.17.1
PATCH 3/3 file-posix: Fix EINTR handling
In reply to Fam ZhengEINTR should be checked against errno, not ret. While fixing the bug, collect the branches with a switch block.
Also, change the return value from -ENOSTUP to -ENOSPC when the actual issue is request range passes EOF, which should be distinguishable from the case of error == ENOSYS by the caller, so that it could still retry with other byte ranges, whereas it shouldn't retry anymore upon ENOSYS.
--- block/file-posix.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
block/file-posix.c +9 -8
@@ -1474,20 +1474,21 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIOData *aiocb)ssize_t ret =copy_file_range (aiocb->aio_fildes, &in_off, aiocb->aio_fd2, &out_off, bytes,0 ); -if (ret == -EINTR ) { -continue ; +if (ret ==0 ) { +/* No progress (e.g. when beyond EOF), let the caller fall back to +* buffer I/O. */ +return -ENOSPC ; }if (ret <0 ) { -if (errno ==ENOSYS ) { +switch (errno) { +case ENOSYS :return -ENOTSUP ; - }else { +case EINTR : +continue ; +default :return -errno; } } -if (!ret) { -/* No progress (e.g. when beyond EOF), fall back to buffer I/O. */ -return -ENOTSUP ; - } bytes -= ret; }return 0 ;
Signature · 1 line
2.17.1
Kevin Wolf
AppliedAm 29.06.2018 um 08:03 hat Fam Zheng geschrieben:
Quoted 2 lines
These are unfortunately more serious than the previous two fixes but the patches are not complicated.
Thanks, applied to the block branch.
Kevin