From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGS0-0002c3-VV for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHGRr-00063b-Cm for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:04 -0400 Received: from mail-qa0-x229.google.com ([2607:f8b0:400d:c00::229]:45645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGRr-00063W-8G for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:00:55 -0400 Received: by mail-qa0-f41.google.com with SMTP id hu16so2153880qab.0 for ; Wed, 04 Sep 2013 10:00:54 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Sep 2013 19:00:21 +0200 Message-Id: <1378314038-15525-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> References: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v5 04/21] block: keep bs->total_sectors up to date even for growable block devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@redhat.com If a BlockDriverState is growable, after every write we need to check if bs->total_sectors might have changed. With this change, bdrv_getlength does not need anymore a system call. Signed-off-by: Paolo Bonzini --- block.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 26639e8..d5800fc 100644 --- a/block.c +++ b/block.c @@ -2711,6 +2711,9 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs, if (bs->wr_highest_sector < sector_num + nb_sectors - 1) { bs->wr_highest_sector = sector_num + nb_sectors - 1; } + if (bs->growable && ret >= 0) { + bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors); + } tracked_request_end(&req); @@ -2785,7 +2788,7 @@ int64_t bdrv_getlength(BlockDriverState *bs) if (!drv) return -ENOMEDIUM; - if (bs->growable || bdrv_dev_has_removable_media(bs)) { + if (bdrv_dev_has_removable_media(bs)) { if (drv->bdrv_getlength) { return drv->bdrv_getlength(bs); } -- 1.8.3.1