[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/48] block: make bdrv_co_do_write_zeroes stricter i
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 09/48] block: make bdrv_co_do_write_zeroes stricter in producing aligned requests |
Date: |
Fri, 6 Dec 2013 17:36:08 +0100 |
From: Paolo Bonzini <address@hidden>
Right now, bdrv_co_do_write_zeroes will only try to align the
beginning of the request. However, it is simpler for many
formats to expect the block layer to separate both the head *and*
the tail. This makes sure that the format's bdrv_co_write_zeroes
function will be called with aligned sector_num and nb_sectors for
the bulk of the request.
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Peter Lieven <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/block.c b/block.c
index 9818052..831c150 100644
--- a/block.c
+++ b/block.c
@@ -2771,14 +2771,21 @@ static int coroutine_fn
bdrv_co_do_write_zeroes(BlockDriverState *bs,
while (nb_sectors > 0 && !ret) {
int num = nb_sectors;
- /* align request */
- if (bs->bl.write_zeroes_alignment &&
- num >= bs->bl.write_zeroes_alignment &&
- sector_num % bs->bl.write_zeroes_alignment) {
- if (num > bs->bl.write_zeroes_alignment) {
+ /* Align request. Block drivers can expect the "bulk" of the request
+ * to be aligned.
+ */
+ if (bs->bl.write_zeroes_alignment
+ && num > bs->bl.write_zeroes_alignment) {
+ if (sector_num % bs->bl.write_zeroes_alignment != 0) {
+ /* Make a small request up to the first aligned sector. */
num = bs->bl.write_zeroes_alignment;
+ num -= sector_num % bs->bl.write_zeroes_alignment;
+ } else if ((sector_num + num) % bs->bl.write_zeroes_alignment !=
0) {
+ /* Shorten the request to the last aligned sector. num cannot
+ * underflow because num > bs->bl.write_zeroes_alignment.
+ */
+ num -= (sector_num + num) % bs->bl.write_zeroes_alignment;
}
- num -= sector_num % bs->bl.write_zeroes_alignment;
}
/* limit request size */
@@ -2796,16 +2803,20 @@ static int coroutine_fn
bdrv_co_do_write_zeroes(BlockDriverState *bs,
/* Fall back to bounce buffer if write zeroes is unsupported */
iov.iov_len = num * BDRV_SECTOR_SIZE;
if (iov.iov_base == NULL) {
- /* allocate bounce buffer only once and ensure that it
- * is big enough for this and all future requests.
- */
- size_t bufsize = num <= nb_sectors ? num : max_write_zeroes;
- iov.iov_base = qemu_blockalign(bs, bufsize * BDRV_SECTOR_SIZE);
- memset(iov.iov_base, 0, bufsize * BDRV_SECTOR_SIZE);
+ iov.iov_base = qemu_blockalign(bs, num * BDRV_SECTOR_SIZE);
+ memset(iov.iov_base, 0, num * BDRV_SECTOR_SIZE);
}
qemu_iovec_init_external(&qiov, &iov, 1);
ret = drv->bdrv_co_writev(bs, sector_num, num, &qiov);
+
+ /* Keep bounce buffer around if it is big enough for all
+ * all future requests.
+ */
+ if (num < max_write_zeroes) {
+ qemu_vfree(iov.iov_base);
+ iov.iov_base = NULL;
+ }
}
sector_num += num;
--
1.8.4.2
- [Qemu-devel] [PULL 00/48] Block patches, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 04/48] block: generalize BlockLimits handling to cover bdrv_aio_discard too, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 02/48] coroutine: remove unused CoQueue AioContext, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 03/48] vmdk: Fix creating big description file, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 01/48] coroutine: remove qemu_co_queue_wait_insert_head, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 05/48] block: add flags to BlockRequest, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 06/48] block: add flags argument to bdrv_co_write_zeroes tracepoint, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 07/48] block: add bdrv_aio_write_zeroes, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 08/48] block: handle ENOTSUP from discard in generic code, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 09/48] block: make bdrv_co_do_write_zeroes stricter in producing aligned requests,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 10/48] vpc, vhdx: add get_info, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 11/48] block drivers: add discard/write_zeroes properties to bdrv_get_info implementation, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 12/48] block drivers: expose requirement for write same alignment from formats, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 15/48] block/iscsi: check WRITE SAME support differently depending on MAY_UNMAP, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 13/48] block/iscsi: remove .bdrv_has_zero_init, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 14/48] block/iscsi: updated copyright, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 16/48] raw-posix: implement write_zeroes with MAY_UNMAP for files, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 17/48] raw-posix: implement write_zeroes with MAY_UNMAP for block devices, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 18/48] raw-posix: add support for write_zeroes on XFS and block devices, Stefan Hajnoczi, 2013/12/06
- [Qemu-devel] [PULL 19/48] qemu-iotests: 033 is fast, Stefan Hajnoczi, 2013/12/06