From patchwork Mon Jan 12 16:39:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 427860 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 C20D2140140 for ; Tue, 13 Jan 2015 04:24:58 +1100 (AEDT) Received: from localhost ([::1]:35623 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAijY-0006Oo-OH for incoming@patchwork.ozlabs.org; Mon, 12 Jan 2015 12:24:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAij9-0005og-Hj for qemu-devel@nongnu.org; Mon, 12 Jan 2015 12:24:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YAij8-000155-Lm for qemu-devel@nongnu.org; Mon, 12 Jan 2015 12:24:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58931) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAij8-00014v-D3 for qemu-devel@nongnu.org; Mon, 12 Jan 2015 12:24:30 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0CGeinC024860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Jan 2015 11:40:44 -0500 Received: from localhost (ovpn-112-78.ams2.redhat.com [10.36.112.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0CGeh35027440; Mon, 12 Jan 2015 11:40:43 -0500 From: Stefan Hajnoczi To: Date: Mon, 12 Jan 2015 16:39:54 +0000 Message-Id: <1421080834-14724-5-git-send-email-stefanha@redhat.com> In-Reply-To: <1421080834-14724-1-git-send-email-stefanha@redhat.com> References: <1421080834-14724-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Peter Maydell , Paolo Bonzini Subject: [Qemu-devel] [PULL v2 04/44] block: do not allocate an iovec per read of a growable/zero_after_eof BDS 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 From: Paolo Bonzini Most reads do not go past the end of the file, and they can use the input QEMUIOVector instead of creating one. This removes the qemu_iovec_* functions from the profile. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- block.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 4165d42..58f8042 100644 --- a/block.c +++ b/block.c @@ -3034,18 +3034,16 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, max_nb_sectors = ROUND_UP(MAX(0, total_sectors - sector_num), align >> BDRV_SECTOR_BITS); - if (max_nb_sectors > 0) { + if (nb_sectors < max_nb_sectors) { + ret = drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov); + } else if (max_nb_sectors > 0) { QEMUIOVector local_qiov; - size_t local_sectors; - - max_nb_sectors = MIN(max_nb_sectors, SIZE_MAX / BDRV_SECTOR_BITS); - local_sectors = MIN(max_nb_sectors, nb_sectors); qemu_iovec_init(&local_qiov, qiov->niov); qemu_iovec_concat(&local_qiov, qiov, 0, - local_sectors * BDRV_SECTOR_SIZE); + max_nb_sectors * BDRV_SECTOR_SIZE); - ret = drv->bdrv_co_readv(bs, sector_num, local_sectors, + ret = drv->bdrv_co_readv(bs, sector_num, max_nb_sectors, &local_qiov); qemu_iovec_destroy(&local_qiov);