提交 500d76a0 编写于 作者: P Peter Maydell

Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging

# gpg: Signature made Fri Mar 27 10:13:35 2015 GMT using RSA key ID 81AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>"

* remotes/stefanha/tags/block-pull-request:
  block: Document blockdev-add's immaturity
  qemu-iotests: Test unaligned 4k zero write
  block: Fix unaligned zero write
  nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
...@@ -3118,6 +3118,19 @@ out: ...@@ -3118,6 +3118,19 @@ out:
return ret; return ret;
} }
static inline uint64_t bdrv_get_align(BlockDriverState *bs)
{
/* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */
return MAX(BDRV_SECTOR_SIZE, bs->request_alignment);
}
static inline bool bdrv_req_is_aligned(BlockDriverState *bs,
int64_t offset, size_t bytes)
{
int64_t align = bdrv_get_align(bs);
return !(offset & (align - 1) || (bytes & (align - 1)));
}
/* /*
* Handle a read request in coroutine context * Handle a read request in coroutine context
*/ */
...@@ -3128,8 +3141,7 @@ static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs, ...@@ -3128,8 +3141,7 @@ static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs,
BlockDriver *drv = bs->drv; BlockDriver *drv = bs->drv;
BdrvTrackedRequest req; BdrvTrackedRequest req;
/* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */ uint64_t align = bdrv_get_align(bs);
uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment);
uint8_t *head_buf = NULL; uint8_t *head_buf = NULL;
uint8_t *tail_buf = NULL; uint8_t *tail_buf = NULL;
QEMUIOVector local_qiov; QEMUIOVector local_qiov;
...@@ -3371,8 +3383,7 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, ...@@ -3371,8 +3383,7 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
BdrvRequestFlags flags) BdrvRequestFlags flags)
{ {
BdrvTrackedRequest req; BdrvTrackedRequest req;
/* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */ uint64_t align = bdrv_get_align(bs);
uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment);
uint8_t *head_buf = NULL; uint8_t *head_buf = NULL;
uint8_t *tail_buf = NULL; uint8_t *tail_buf = NULL;
QEMUIOVector local_qiov; QEMUIOVector local_qiov;
...@@ -3471,6 +3482,10 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, ...@@ -3471,6 +3482,10 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
bytes = ROUND_UP(bytes, align); bytes = ROUND_UP(bytes, align);
} }
if (use_local_qiov) {
/* Local buffer may have non-zero data. */
flags &= ~BDRV_REQ_ZERO_WRITE;
}
ret = bdrv_aligned_pwritev(bs, &req, offset, bytes, ret = bdrv_aligned_pwritev(bs, &req, offset, bytes,
use_local_qiov ? &local_qiov : qiov, use_local_qiov ? &local_qiov : qiov,
flags); flags);
...@@ -3511,14 +3526,32 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, ...@@ -3511,14 +3526,32 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, int64_t sector_num, int nb_sectors,
BdrvRequestFlags flags) BdrvRequestFlags flags)
{ {
int ret;
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags); trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags);
if (!(bs->open_flags & BDRV_O_UNMAP)) { if (!(bs->open_flags & BDRV_O_UNMAP)) {
flags &= ~BDRV_REQ_MAY_UNMAP; flags &= ~BDRV_REQ_MAY_UNMAP;
} }
if (bdrv_req_is_aligned(bs, sector_num << BDRV_SECTOR_BITS,
nb_sectors << BDRV_SECTOR_BITS)) {
ret = bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
BDRV_REQ_ZERO_WRITE | flags);
} else {
uint8_t *buf;
QEMUIOVector local_qiov;
size_t bytes = nb_sectors << BDRV_SECTOR_BITS;
buf = qemu_memalign(bdrv_opt_mem_align(bs), bytes);
memset(buf, 0, bytes);
qemu_iovec_init(&local_qiov, 1);
qemu_iovec_add(&local_qiov, buf, bytes);
return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL, ret = bdrv_co_do_writev(bs, sector_num, nb_sectors, &local_qiov,
BDRV_REQ_ZERO_WRITE | flags); BDRV_REQ_ZERO_WRITE | flags);
qemu_vfree(buf);
}
return ret;
} }
/** /**
......
...@@ -222,7 +222,7 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd, ...@@ -222,7 +222,7 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas); uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds; uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
uint64_t data_size = nlb << data_shift; uint64_t data_size = (uint64_t)nlb << data_shift;
uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS); uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS);
int is_write = rw->opcode == NVME_CMD_WRITE ? 1 : 0; int is_write = rw->opcode == NVME_CMD_WRITE ? 1 : 0;
......
...@@ -1721,6 +1721,10 @@ ...@@ -1721,6 +1721,10 @@
# #
# Creates a new block device. # Creates a new block device.
# #
# This command is still a work in progress. It doesn't support all
# block drivers, it lacks a matching blockdev-del, and more. Stay
# away from it unless you want to help with its development.
#
# @options: block device options for the new device # @options: block device options for the new device
# #
# Since: 1.7 # Since: 1.7
......
...@@ -3636,6 +3636,10 @@ blockdev-add ...@@ -3636,6 +3636,10 @@ blockdev-add
Add a block device. Add a block device.
This command is still a work in progress. It doesn't support all
block drivers, it lacks a matching blockdev-del, and more. Stay away
from it unless you want to help with its development.
Arguments: Arguments:
- "options": block driver options - "options": block driver options
......
...@@ -46,26 +46,39 @@ _supported_os Linux ...@@ -46,26 +46,39 @@ _supported_os Linux
size=128M size=128M
_make_test_img $size _make_test_img $size
echo do_test()
echo "== preparing image ==" {
$QEMU_IO -c "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io local align=$1
$QEMU_IO -c "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io local iocmd=$2
$QEMU_IO -c "write -z 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io local img=$3
{
echo "open -o driver=$IMGFMT,file.align=$align blkdebug::$img"
echo $iocmd
} | $QEMU_IO
}
for align in 512 4k; do
echo
echo "== preparing image =="
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 -z 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
echo echo
echo "== verifying patterns (1) ==" echo "== verifying patterns (1) =="
$QEMU_IO -c "read -P 0xa 0x200 0x200" "$TEST_IMG" | _filter_qemu_io do_test $align "read -P 0xa 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
$QEMU_IO -c "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
$QEMU_IO -c "read -P 0xa 0x20400 0x200" "$TEST_IMG" | _filter_qemu_io do_test $align "read -P 0xa 0x20400 0x200" "$TEST_IMG" | _filter_qemu_io
echo echo
echo "== rewriting zeroes ==" echo "== rewriting zeroes =="
$QEMU_IO -c "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io do_test $align "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
$QEMU_IO -c "write -z 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io do_test $align "write -z 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
echo echo
echo "== verifying patterns (2) ==" echo "== verifying patterns (2) =="
$QEMU_IO -c "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
done
# success, all done # success, all done
echo "*** done" echo "*** done"
......
...@@ -23,6 +23,32 @@ wrote 65536/65536 bytes at offset 65536 ...@@ -23,6 +23,32 @@ wrote 65536/65536 bytes at offset 65536
wrote 65536/65536 bytes at offset 65536 wrote 65536/65536 bytes at offset 65536
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 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)
== 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) == == verifying patterns (2) ==
read 131072/131072 bytes at offset 1024 read 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 128 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.
先完成此消息的编辑!
想要评论请 注册