From patchwork Fri Dec 26 12:35:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 424111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 861A014009B for ; Fri, 26 Dec 2014 23:35:59 +1100 (AEDT) Received: from localhost ([::1]:53162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4U7Z-0002AU-Lz for incoming@patchwork.ozlabs.org; Fri, 26 Dec 2014 07:35:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4U6u-0001Hu-AT for qemu-devel@nongnu.org; Fri, 26 Dec 2014 07:35:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y4U6p-0001qU-Gh for qemu-devel@nongnu.org; Fri, 26 Dec 2014 07:35:16 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:12242 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4U6p-0001nd-49 for qemu-devel@nongnu.org; Fri, 26 Dec 2014 07:35:11 -0500 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id sBQCZ0YX026257; Fri, 26 Dec 2014 15:35:03 +0300 (MSK) From: "Denis V. Lunev" To: Date: Fri, 26 Dec 2014 15:35:07 +0300 Message-Id: <1419597313-20514-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1419597313-20514-1-git-send-email-den@openvz.org> References: <1419597313-20514-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Kevin Wolf , Peter Lieven , qemu-devel@nongnu.org, Stefan Hajnoczi , "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 1/7] block: fix maximum length sent to bdrv_co_do_write_zeroes callback in bs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The check for maximum length was added by commit c31cb70728d2c0c8900b35a66784baa446fd5147 Author: Peter Lieven Date: Thu Oct 24 12:06:58 2013 +0200 block: honour BlockLimits in bdrv_co_do_write_zeroes but actually if driver provides .bdrv_co_write_zeroes callback, there is no need to limit the size to 32 MB. Callback should provide effective implementation which normally should not write any zeroes in comparable amount. Correct check should be as follows to honour BlockLimits for slow writes: - if bs->bl.max_write_zeroes is specified, it should be applied to all paths (fast and slow) - MAX_WRITE_ZEROES_DEFAULT should be applied for slow path only Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Peter Lieven CC: Kevin Wolf CC: Stefan Hajnoczi --- block.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 4165d42..0ec8b15 100644 --- a/block.c +++ b/block.c @@ -3182,8 +3182,12 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, struct iovec iov = {0}; int ret = 0; - int max_write_zeroes = bs->bl.max_write_zeroes ? - bs->bl.max_write_zeroes : MAX_WRITE_ZEROES_DEFAULT; + int max_fast_write_size = nb_sectors; + int max_slow_write_size = MAX_WRITE_ZEROES_DEFAULT; + if (bs->bl.max_write_zeroes != 0) { + max_fast_write_size = bs->bl.max_write_zeroes; + max_slow_write_size = bs->bl.max_write_zeroes; + } while (nb_sectors > 0 && !ret) { int num = nb_sectors; @@ -3205,9 +3209,9 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, } } - /* limit request size */ - if (num > max_write_zeroes) { - num = max_write_zeroes; + /* limit request size for fast path */ + if (num > max_fast_write_size) { + num = max_fast_write_size; } ret = -ENOTSUP; @@ -3217,6 +3221,11 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, } if (ret == -ENOTSUP) { + /* limit request size further for slow path */ + if (num > max_slow_write_size) { + num = max_slow_write_size; + } + /* Fall back to bounce buffer if write zeroes is unsupported */ iov.iov_len = num * BDRV_SECTOR_SIZE; if (iov.iov_base == NULL) { @@ -3234,7 +3243,7 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, /* Keep bounce buffer around if it is big enough for all * all future requests. */ - if (num < max_write_zeroes) { + if (num < max_slow_write_size) { qemu_vfree(iov.iov_base); iov.iov_base = NULL; }