aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorDenis V. Lunev <den@openvz.org>2016-05-25 21:48:45 -0600
committerKevin Wolf <kwolf@redhat.com>2016-06-08 10:21:08 +0200
commit443668ca408cdb7f01e1a70a58518bb100c3e9d1 (patch)
tree668a5dad129a866dcba61c066a193f42e5bdabd9 /block
parent6ed5546fa7bf12c5b87ef76bafb86e1d77ed6e85 (diff)
block: split write_zeroes always
We should split requests even if they are less than write_zeroes_alignment. For example we can have the following request: offset 62k size 4k write_zeroes_alignment 64k The original code sent 1 request covering 2 qcow2 clusters, and resulted in both clusters being allocated. But by splitting the request, we can cater to the case where one of the two clusters can be zeroed as a whole, for only 1 cluster allocated after the operation. Signed-off-by: Denis V. Lunev <den@openvz.org> CC: Eric Blake <eblake@redhat.com> CC: Kevin Wolf <kwolf@redhat.com> Message-Id: <1463476543-3087-2-git-send-email-den@openvz.org> [eblake: Avoid exceeding nb_sectors, hoist alignment checks out of loop, and update testsuite to show that patch works] Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/io.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/block/io.c b/block/io.c
index 6070e773b7..c73be55f86 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1118,28 +1118,32 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
struct iovec iov = {0};
int ret = 0;
bool need_flush = false;
+ int head = 0;
+ int tail = 0;
int max_write_zeroes = MIN_NON_ZERO(bs->bl.max_write_zeroes,
BDRV_REQUEST_MAX_SECTORS);
+ if (bs->bl.write_zeroes_alignment) {
+ assert(is_power_of_2(bs->bl.write_zeroes_alignment));
+ head = sector_num & (bs->bl.write_zeroes_alignment - 1);
+ tail = (sector_num + nb_sectors) & (bs->bl.write_zeroes_alignment - 1);
+ max_write_zeroes &= ~(bs->bl.write_zeroes_alignment - 1);
+ }
while (nb_sectors > 0 && !ret) {
int num = nb_sectors;
/* Align request. Block drivers can expect the "bulk" of the request
- * to be aligned.
+ * to be aligned, and that unaligned requests do not cross cluster
+ * boundaries.
*/
- 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;
- }
+ if (head) {
+ /* Make a small request up to the first aligned sector. */
+ num = MIN(nb_sectors, bs->bl.write_zeroes_alignment - head);
+ head = 0;
+ } else if (tail && num > bs->bl.write_zeroes_alignment) {
+ /* Shorten the request to the last aligned sector. */
+ num -= tail;
}
/* limit request size */