From patchwork Tue Sep 24 13:35:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 277499 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 213462C00AD for ; Tue, 24 Sep 2013 23:42:20 +1000 (EST) Received: from localhost ([::1]:46126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOSsb-0001ZR-F1 for incoming@patchwork.ozlabs.org; Tue, 24 Sep 2013 09:42:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOSnv-0004MR-Vr for qemu-devel@nongnu.org; Tue, 24 Sep 2013 09:37:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOSnp-0004y0-HB for qemu-devel@nongnu.org; Tue, 24 Sep 2013 09:37:27 -0400 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:43901 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOSno-0004wn-Qe for qemu-devel@nongnu.org; Tue, 24 Sep 2013 09:37:21 -0400 Received: (qmail 13716 invoked by uid 89); 24 Sep 2013 13:37:19 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98/17892. hbedv: 8.2.12.122/7.11.104.28. spamassassin: 3.3.1. Clear:RC:1(82.141.1.145):SA:0(-1.2/5.0):. Processed in 2.133279 secs); 24 Sep 2013 13:37:19 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 24 Sep 2013 13:37:16 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id A4A51206AE; Tue, 24 Sep 2013 15:35:15 +0200 (CEST) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id A83A261461; Tue, 24 Sep 2013 15:35:15 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Tue, 24 Sep 2013 15:35:01 +0200 Message-Id: <1380029714-5239-8-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1380029714-5239-1-git-send-email-pl@kamp.de> References: <1380029714-5239-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, ronniesahlberg@gmail.com, Peter Lieven , stefanha@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com Subject: [Qemu-devel] [PATCHv3 07/20] block: honour BlockLimits in bdrv_co_do_write_zeroes 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 Signed-off-by: Peter Lieven Reviewed-by: Eric Blake --- block.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index ac35cb5..580570a 100644 --- a/block.c +++ b/block.c @@ -2710,32 +2710,65 @@ int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, BDRV_REQ_COPY_ON_READ); } +/* if no limit is specified in the BlockLimits use a default + * of 32768 512-byte sectors (16 MiB) per request. + */ +#define MAX_WRITE_ZEROES_DEFAULT 32768 + static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors, BdrvRequestFlags flags) { BlockDriver *drv = bs->drv; QEMUIOVector qiov; - struct iovec iov; - int ret; + struct iovec iov = {0}; + int ret = 0; - /* TODO Emulate only part of misaligned requests instead of letting block - * drivers return -ENOTSUP and emulate everything */ + int max_write_zeroes = bs->bl.max_write_zeroes ? + bs->bl.max_write_zeroes : MAX_WRITE_ZEROES_DEFAULT; - /* First try the efficient write zeroes operation */ - if (drv->bdrv_co_write_zeroes) { - ret = drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags); - if (ret != -ENOTSUP) { - return ret; + 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) { + num = bs->bl.write_zeroes_alignment; + } + num -= sector_num % bs->bl.write_zeroes_alignment; } - } - /* Fall back to bounce buffer if write zeroes is unsupported */ - iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE; - iov.iov_base = qemu_blockalign(bs, iov.iov_len); - memset(iov.iov_base, 0, iov.iov_len); - qemu_iovec_init_external(&qiov, &iov, 1); + /* limit request size */ + if (num > max_write_zeroes) { + num = max_write_zeroes; + } + + ret = -ENOTSUP; + /* First try the efficient write zeroes operation */ + if (drv->bdrv_co_write_zeroes) { + ret = drv->bdrv_co_write_zeroes(bs, sector_num, num, flags); + } + + if (ret == -ENOTSUP) { + /* 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); + } + qemu_iovec_init_external(&qiov, &iov, 1); - ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, &qiov); + ret = drv->bdrv_co_writev(bs, sector_num, num, &qiov); + } + + sector_num += num; + nb_sectors -= num; + } qemu_vfree(iov.iov_base); return ret;