From patchwork Mon Sep 22 15:23:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 392014 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 079BD14011D for ; Tue, 23 Sep 2014 01:24:37 +1000 (EST) Received: from localhost ([::1]:47186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW5Te-0005nm-Qf for incoming@patchwork.ozlabs.org; Mon, 22 Sep 2014 11:24:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW5TG-0005LF-Qs for qemu-devel@nongnu.org; Mon, 22 Sep 2014 11:24:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XW5T7-0005Em-S8 for qemu-devel@nongnu.org; Mon, 22 Sep 2014 11:24:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW5T7-0005E5-Li for qemu-devel@nongnu.org; Mon, 22 Sep 2014 11:24:01 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8MFNt5l004088 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 22 Sep 2014 11:23:56 -0400 Received: from localhost (ovpn-116-110.ams2.redhat.com [10.36.116.110]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8MFNqui013094 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 22 Sep 2014 11:23:55 -0400 From: Max Reitz To: qemu-devel@nongnu.org Date: Mon, 22 Sep 2014 17:23:45 +0200 Message-Id: <1411399425-23430-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1411399425-23430-1-git-send-email-mreitz@redhat.com> References: <1411399425-23430-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH 2/2] raw-posix: raw_co_get_block_status() return value 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 Instead of generating the full return value thrice in try_fiemap(), try_seek_hole() and as a fall-back in raw_co_get_block_status() itself, generate the value only in raw_co_get_block_status(). Suggested-by: Kevin Wolf Signed-off-by: Max Reitz --- block/raw-posix.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index de4e3f3..7e1cc02 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1455,12 +1455,12 @@ out: return result; } -static int64_t try_fiemap(BlockDriverState *bs, off_t start, off_t *data, +static int try_fiemap(BlockDriverState *bs, off_t start, off_t *data, off_t *hole, int nb_sectors, int *pnum) { #ifdef CONFIG_FIEMAP BDRVRawState *s = bs->opaque; - int64_t ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + int ret = 0; struct { struct fiemap fm; struct fiemap_extent fe; @@ -1501,7 +1501,7 @@ static int64_t try_fiemap(BlockDriverState *bs, off_t start, off_t *data, #endif } -static int64_t try_seek_hole(BlockDriverState *bs, off_t start, off_t *data, +static int try_seek_hole(BlockDriverState *bs, off_t start, off_t *data, off_t *hole, int *pnum) { #if defined SEEK_HOLE && defined SEEK_DATA @@ -1526,7 +1526,7 @@ static int64_t try_seek_hole(BlockDriverState *bs, off_t start, off_t *data, } } - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + return 0; #else return -ENOTSUP; #endif @@ -1552,7 +1552,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, int nb_sectors, int *pnum) { off_t start, data = 0, hole = 0; - int64_t ret; + int ret; ret = fd_open(bs); if (ret < 0) { @@ -1572,21 +1572,21 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, /* Assume everything is allocated. */ data = 0; hole = start + nb_sectors * BDRV_SECTOR_SIZE; - ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + ret = 0; } } + assert(ret >= 0); + if (data <= start) { /* On a data extent, compute sectors to the end of the extent. */ *pnum = MIN(nb_sectors, (hole - start) / BDRV_SECTOR_SIZE); + return ret | BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; } else { /* On a hole, compute sectors to the beginning of the next extent. */ *pnum = MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE); - ret &= ~BDRV_BLOCK_DATA; - ret |= BDRV_BLOCK_ZERO; + return ret | BDRV_BLOCK_ZERO | BDRV_BLOCK_OFFSET_VALID | start; } - - return ret; } static coroutine_fn BlockDriverAIOCB *raw_aio_discard(BlockDriverState *bs,