From patchwork Fri Jun 3 23:13:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9154267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A469E60221 for ; Fri, 3 Jun 2016 23:13:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95DA7266F3 for ; Fri, 3 Jun 2016 23:13:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A85328345; Fri, 3 Jun 2016 23:13:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F386D266F3 for ; Fri, 3 Jun 2016 23:13:57 +0000 (UTC) Received: from localhost ([::1]:58118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8yHs-0007dc-DI for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 19:13:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8yHa-0007dL-Up for qemu-devel@nongnu.org; Fri, 03 Jun 2016 19:13:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8yHW-0005mL-NV for qemu-devel@nongnu.org; Fri, 03 Jun 2016 19:13:37 -0400 Received: from resqmta-po-03v.sys.comcast.net ([2001:558:fe16:19:96:114:154:162]:56874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8yHW-0005lf-Ik for qemu-devel@nongnu.org; Fri, 03 Jun 2016 19:13:34 -0400 Received: from resomta-po-12v.sys.comcast.net ([96.114.154.236]) by comcast with SMTP id 8yHLbswWkYPZX8yHVbygPe; Fri, 03 Jun 2016 23:13:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1464995613; bh=QT+SI63spk316pRivtNOxcNpF+nCbZNgrcDPMarnYd8=; h=Received:Received:From:To:Subject:Date:Message-Id; b=PlkyUHtmnJEQHypSaMZS+gCLJ+Xp7ZKtssHfUuHutSArhpaHxs4uzP96yYKYCETzw ptD7EonXEub5WEP16IIiQkn1GqHt4lk8RKYYwtozKVnhcMq0CIBRAJTnFzt83eXk94 Ahi5inEtmYaTh0DQA8udLlduk4/IAGAcif0fZu4VTwN6V7uTV05vzoPhj53+TEpiDE 4CGapSVKyobZWHzjAFd+ncvAOZ+VsNmwQVKG8U/qeN/+6hZ0VZvPi6AX58tmVS8eZz VW7nVHOyX2wln1cGkI5cq1+ZF+dxwhxqYhpHMBFkGwfaCTRNCQHSrvKrutQKZWns2Z reKHg2qzF5uiw== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-12v.sys.comcast.net with comcast id 2PDW1t00F2fD5rL01PDYJp; Fri, 03 Jun 2016 23:13:33 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2016 17:13:28 -0600 Message-Id: <1464995608-15264-1-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464973388-15821-1-git-send-email-eblake@redhat.com> References: <1464973388-15821-1-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:162 Subject: [Qemu-devel] [PATCH 7/5] block: Refactor zero_beyond_eof hack in bdrv_aligned_preadv() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reindent code so that later removal of zero_beyond_eof doesn't interfere as much with upcoming changes to the normal path. Patch viewed best with 'git diff -b'. Signed-off-by: Eric Blake --- block/io.c | 74 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/block/io.c b/block/io.c index c8b323e..243d18a 100644 --- a/block/io.c +++ b/block/io.c @@ -944,6 +944,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, { int ret; + int64_t total_sectors, max_nb_sectors; int64_t sector_num = offset >> BDRV_SECTOR_BITS; unsigned int nb_sectors = bytes >> BDRV_SECTOR_BITS; @@ -981,46 +982,45 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, } } - /* Forward the request to the BlockDriver */ + /* Hack for stashing vmstate beyond guest visibility */ if (!bs->zero_beyond_eof) { ret = bdrv_driver_preadv(bs, offset, bytes, qiov, flags); + goto out; + } + + /* Forward the request to the BlockDriver */ + total_sectors = bdrv_nb_sectors(bs); + if (total_sectors < 0) { + ret = total_sectors; + goto out; + } + + max_nb_sectors = ROUND_UP(MAX(0, total_sectors - sector_num), + align >> BDRV_SECTOR_BITS); + if (nb_sectors <= max_nb_sectors) { + ret = bdrv_driver_preadv(bs, offset, bytes, qiov, flags); + } else if (max_nb_sectors > 0) { + QEMUIOVector local_qiov; + + qemu_iovec_init(&local_qiov, qiov->niov); + qemu_iovec_concat(&local_qiov, qiov, 0, + max_nb_sectors * BDRV_SECTOR_SIZE); + + ret = bdrv_driver_preadv(bs, offset, + max_nb_sectors * BDRV_SECTOR_SIZE, + &local_qiov, flags); + + qemu_iovec_destroy(&local_qiov); } else { - /* Read zeros after EOF */ - int64_t total_sectors, max_nb_sectors; - - total_sectors = bdrv_nb_sectors(bs); - if (total_sectors < 0) { - ret = total_sectors; - goto out; - } - - max_nb_sectors = ROUND_UP(MAX(0, total_sectors - sector_num), - align >> BDRV_SECTOR_BITS); - if (nb_sectors <= max_nb_sectors) { - ret = bdrv_driver_preadv(bs, offset, bytes, qiov, flags); - } else if (max_nb_sectors > 0) { - QEMUIOVector local_qiov; - - qemu_iovec_init(&local_qiov, qiov->niov); - qemu_iovec_concat(&local_qiov, qiov, 0, - max_nb_sectors * BDRV_SECTOR_SIZE); - - ret = bdrv_driver_preadv(bs, offset, - max_nb_sectors * BDRV_SECTOR_SIZE, - &local_qiov, flags); - - qemu_iovec_destroy(&local_qiov); - } else { - ret = 0; - } - - /* Reading beyond end of file is supposed to produce zeroes */ - if (ret == 0 && total_sectors < sector_num + nb_sectors) { - uint64_t offset = MAX(0, total_sectors - sector_num); - uint64_t bytes = (sector_num + nb_sectors - offset) * - BDRV_SECTOR_SIZE; - qemu_iovec_memset(qiov, offset * BDRV_SECTOR_SIZE, 0, bytes); - } + ret = 0; + } + + /* Reading beyond end of file is supposed to produce zeroes */ + if (ret == 0 && total_sectors < sector_num + nb_sectors) { + uint64_t offset = MAX(0, total_sectors - sector_num); + uint64_t bytes = (sector_num + nb_sectors - offset) * + BDRV_SECTOR_SIZE; + qemu_iovec_memset(qiov, offset * BDRV_SECTOR_SIZE, 0, bytes); } out: