From patchwork Thu Aug 29 14:00:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 270845 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 5088B2C0089 for ; Fri, 30 Aug 2013 00:10:05 +1000 (EST) Received: from localhost ([::1]:43672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2vD-0002Hn-12 for incoming@patchwork.ozlabs.org; Thu, 29 Aug 2013 10:10:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2mo-0007QE-Im for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VF2me-0008DV-2P for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:22 -0400 Received: from mail-ee0-x22d.google.com ([2a00:1450:4013:c00::22d]:36035) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2md-0008DI-Sm for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:12 -0400 Received: by mail-ee0-f45.google.com with SMTP id c50so266912eek.32 for ; Thu, 29 Aug 2013 07:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+6BvRkANk40AV/WV3fL0QAsApF6tSHeMQaxkjxBriyM=; b=IbV+lf7N+RiwtKJasZK6WaLlM4s54wxRVO09PLV833cXbLgkP4en8xvcwJ5BouuVFU PydrTJwhxLV6F8MqZk87Eo49xa7b7PoNuOTPrNX+1CJKW1BZ/Tdvix/EJWKtWLU3L7gH CuNLJ2G/fl+pc4V15xA7PB0s2vTa5Tlj4t6qKxmlKXmMOIK4Siu7jgqZxjuQRHS58C02 2OyPkdZV7S6plkTwto2kvWmH1eOyiw25yg3+k+wsQY6dPKznrMoA4ek9teB5UJ24dK9K FAXAd3EFl4RutiTxnQdtB/Q8Gl4HD3tFCoFtYRl/e782jt2bID5nYJU3ISpOn7LcRk5B yrkA== X-Received: by 10.14.194.131 with SMTP id m3mr4648236een.45.1377784870948; Thu, 29 Aug 2013 07:01:10 -0700 (PDT) Received: from yakj.usersys.redhat.com (nat-pool-mxp-t.redhat.com. [209.132.186.18]) by mx.google.com with ESMTPSA id p5sm46359028eeg.5.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 29 Aug 2013 07:01:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2013 16:00:18 +0200 Message-Id: <1377784821-29561-19-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> References: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::22d Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v4 18/21] raw-posix: return get_block_status data and flags 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 Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- block/raw-posix.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index dbc65b0..d011cfd 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1089,7 +1089,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, int nb_sectors, int *pnum) { off_t start, data, hole; - int ret; + int64_t ret; ret = fd_open(bs); if (ret < 0) { @@ -1097,6 +1097,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, } start = sector_num * BDRV_SECTOR_SIZE; + ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; #ifdef CONFIG_FIEMAP @@ -1114,7 +1115,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, if (ioctl(s->fd, FS_IOC_FIEMAP, &f) == -1) { /* Assume everything is allocated. */ *pnum = nb_sectors; - return 1; + return ret; } if (f.fm.fm_mapped_extents == 0) { @@ -1141,7 +1142,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, /* Most likely EINVAL. Assume everything is allocated. */ *pnum = nb_sectors; - return 1; + return ret; } if (hole > start) { @@ -1154,19 +1155,21 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, } } #else - *pnum = nb_sectors; - return 1; + data = 0; + hole = start + nb_sectors * BDRV_SECTOR_SIZE; #endif 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 1; } else { /* On a hole, compute sectors to the beginning of the next extent. */ *pnum = MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE); - return 0; + ret &= ~BDRV_BLOCK_DATA; + ret |= BDRV_BLOCK_ZERO; } + + return ret; } static coroutine_fn BlockDriverAIOCB *raw_aio_discard(BlockDriverState *bs,