提交 7fa84cd8 编写于 作者: K Kevin Wolf

block: Fix blk_aio_write_zeroes()

Commit 57d6a428 broke blk_aio_write_zeroes() because in some write
functions in the call path don't have an explicit length argument but
reuse qiov->size instead. Which is great, except that write_zeroes
doesn't have a qiov, which this commit interprets as 0 bytes.
Consequently, blk_aio_write_zeroes() didn't effectively do anything.

This patch introduces an explicit acb->bytes in BlkAioEmAIOCB and uses
that instead of acb->rwco.size.

The synchronous version of the function is okay because it does pass a
qiov (with the right size and a NULL pointer as its base).
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Reviewed-by: NMax Reitz <mreitz@redhat.com>
上级 5ceb7765
...@@ -852,6 +852,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, ...@@ -852,6 +852,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
typedef struct BlkAioEmAIOCB { typedef struct BlkAioEmAIOCB {
BlockAIOCB common; BlockAIOCB common;
BlkRwCo rwco; BlkRwCo rwco;
int bytes;
bool has_returned; bool has_returned;
QEMUBH* bh; QEMUBH* bh;
} BlkAioEmAIOCB; } BlkAioEmAIOCB;
...@@ -877,7 +878,7 @@ static void blk_aio_complete_bh(void *opaque) ...@@ -877,7 +878,7 @@ static void blk_aio_complete_bh(void *opaque)
blk_aio_complete(opaque); blk_aio_complete(opaque);
} }
static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes,
QEMUIOVector *qiov, CoroutineEntry co_entry, QEMUIOVector *qiov, CoroutineEntry co_entry,
BdrvRequestFlags flags, BdrvRequestFlags flags,
BlockCompletionFunc *cb, void *opaque) BlockCompletionFunc *cb, void *opaque)
...@@ -893,6 +894,7 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, ...@@ -893,6 +894,7 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset,
.flags = flags, .flags = flags,
.ret = NOT_DONE, .ret = NOT_DONE,
}; };
acb->bytes = bytes;
acb->bh = NULL; acb->bh = NULL;
acb->has_returned = false; acb->has_returned = false;
...@@ -913,7 +915,8 @@ static void blk_aio_read_entry(void *opaque) ...@@ -913,7 +915,8 @@ static void blk_aio_read_entry(void *opaque)
BlkAioEmAIOCB *acb = opaque; BlkAioEmAIOCB *acb = opaque;
BlkRwCo *rwco = &acb->rwco; BlkRwCo *rwco = &acb->rwco;
rwco->ret = blk_co_preadv(rwco->blk, rwco->offset, rwco->qiov->size, assert(rwco->qiov->size == acb->bytes);
rwco->ret = blk_co_preadv(rwco->blk, rwco->offset, acb->bytes,
rwco->qiov, rwco->flags); rwco->qiov, rwco->flags);
blk_aio_complete(acb); blk_aio_complete(acb);
} }
...@@ -923,8 +926,8 @@ static void blk_aio_write_entry(void *opaque) ...@@ -923,8 +926,8 @@ static void blk_aio_write_entry(void *opaque)
BlkAioEmAIOCB *acb = opaque; BlkAioEmAIOCB *acb = opaque;
BlkRwCo *rwco = &acb->rwco; BlkRwCo *rwco = &acb->rwco;
rwco->ret = blk_co_pwritev(rwco->blk, rwco->offset, assert(!rwco->qiov || rwco->qiov->size == acb->bytes);
rwco->qiov ? rwco->qiov->size : 0, rwco->ret = blk_co_pwritev(rwco->blk, rwco->offset, acb->bytes,
rwco->qiov, rwco->flags); rwco->qiov, rwco->flags);
blk_aio_complete(acb); blk_aio_complete(acb);
} }
...@@ -937,7 +940,8 @@ BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num, ...@@ -937,7 +940,8 @@ BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
return blk_abort_aio_request(blk, cb, opaque, -EINVAL); return blk_abort_aio_request(blk, cb, opaque, -EINVAL);
} }
return blk_aio_prwv(blk, sector_num << BDRV_SECTOR_BITS, NULL, return blk_aio_prwv(blk, sector_num << BDRV_SECTOR_BITS,
nb_sectors << BDRV_SECTOR_BITS, NULL,
blk_aio_write_entry, BDRV_REQ_ZERO_WRITE, cb, opaque); blk_aio_write_entry, BDRV_REQ_ZERO_WRITE, cb, opaque);
} }
...@@ -994,7 +998,8 @@ BlockAIOCB *blk_aio_readv(BlockBackend *blk, int64_t sector_num, ...@@ -994,7 +998,8 @@ BlockAIOCB *blk_aio_readv(BlockBackend *blk, int64_t sector_num,
return blk_abort_aio_request(blk, cb, opaque, -EINVAL); return blk_abort_aio_request(blk, cb, opaque, -EINVAL);
} }
return blk_aio_prwv(blk, sector_num << BDRV_SECTOR_BITS, iov, assert(nb_sectors << BDRV_SECTOR_BITS == iov->size);
return blk_aio_prwv(blk, sector_num << BDRV_SECTOR_BITS, iov->size, iov,
blk_aio_read_entry, 0, cb, opaque); blk_aio_read_entry, 0, cb, opaque);
} }
...@@ -1006,7 +1011,8 @@ BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num, ...@@ -1006,7 +1011,8 @@ BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num,
return blk_abort_aio_request(blk, cb, opaque, -EINVAL); return blk_abort_aio_request(blk, cb, opaque, -EINVAL);
} }
return blk_aio_prwv(blk, sector_num << BDRV_SECTOR_BITS, iov, assert(nb_sectors << BDRV_SECTOR_BITS == iov->size);
return blk_aio_prwv(blk, sector_num << BDRV_SECTOR_BITS, iov->size, iov,
blk_aio_write_entry, 0, cb, opaque); blk_aio_write_entry, 0, cb, opaque);
} }
......
...@@ -57,12 +57,13 @@ do_test() ...@@ -57,12 +57,13 @@ do_test()
} | $QEMU_IO } | $QEMU_IO
} }
for write_zero_cmd in "write -z" "aio_write -z"; do
for align in 512 4k; do for align in 512 4k; do
echo echo
echo "== preparing image ==" echo "== preparing image =="
do_test $align "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io do_test $align "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io
do_test $align "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io do_test $align "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io
do_test $align "write -z 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io do_test $align "$write_zero_cmd 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
echo echo
echo "== verifying patterns (1) ==" echo "== verifying patterns (1) =="
...@@ -73,7 +74,7 @@ for align in 512 4k; do ...@@ -73,7 +74,7 @@ for align in 512 4k; do
echo echo
echo "== rewriting zeroes ==" echo "== rewriting zeroes =="
do_test $align "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io do_test $align "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
do_test $align "write -z 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io do_test $align "$write_zero_cmd 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
echo echo
echo "== verifying patterns (2) ==" echo "== verifying patterns (2) =="
...@@ -82,7 +83,7 @@ for align in 512 4k; do ...@@ -82,7 +83,7 @@ for align in 512 4k; do
echo echo
echo "== rewriting unaligned zeroes ==" echo "== rewriting unaligned zeroes =="
do_test $align "write -P 0xb 0x0 0x1000" "$TEST_IMG" | _filter_qemu_io do_test $align "write -P 0xb 0x0 0x1000" "$TEST_IMG" | _filter_qemu_io
do_test $align "write -z 0x200 0x200" "$TEST_IMG" | _filter_qemu_io do_test $align "$write_zero_cmd 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
echo echo
echo "== verifying patterns (3) ==" echo "== verifying patterns (3) =="
...@@ -92,6 +93,7 @@ for align in 512 4k; do ...@@ -92,6 +93,7 @@ for align in 512 4k; do
echo echo
done done
done
# success, all done # success, all done
echo "*** done" echo "*** done"
......
...@@ -42,6 +42,88 @@ read 3072/3072 bytes at offset 1024 ...@@ -42,6 +42,88 @@ read 3072/3072 bytes at offset 1024
3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== preparing image ==
wrote 1024/1024 bytes at offset 512
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 1536/1536 bytes at offset 131072
1.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== verifying patterns (1) ==
read 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 512/512 bytes at offset 132096
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== rewriting zeroes ==
wrote 65536/65536 bytes at offset 65536
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 65536/65536 bytes at offset 65536
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== verifying patterns (2) ==
read 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== rewriting unaligned zeroes ==
wrote 4096/4096 bytes at offset 0
4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== verifying patterns (3) ==
read 512/512 bytes at offset 0
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 3072/3072 bytes at offset 1024
3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== preparing image ==
wrote 1024/1024 bytes at offset 512
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 1536/1536 bytes at offset 131072
1.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== verifying patterns (1) ==
read 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 512/512 bytes at offset 132096
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== rewriting zeroes ==
wrote 65536/65536 bytes at offset 65536
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 65536/65536 bytes at offset 65536
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== verifying patterns (2) ==
read 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== rewriting unaligned zeroes ==
wrote 4096/4096 bytes at offset 0
4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== verifying patterns (3) ==
read 512/512 bytes at offset 0
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 3072/3072 bytes at offset 1024
3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== preparing image == == preparing image ==
wrote 1024/1024 bytes at offset 512 wrote 1024/1024 bytes at offset 512
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册