From patchwork Fri Nov 29 16:45:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 295489 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 DE71B2C00C7 for ; Sat, 30 Nov 2013 04:34:48 +1100 (EST) Received: from localhost ([::1]:48370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRNZ-0004UV-SS for incoming@patchwork.ozlabs.org; Fri, 29 Nov 2013 11:57:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRDT-0004Hy-8X for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:47:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmRDO-0002uV-89 for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:46:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35386) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRDN-0002uI-Ti for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:46:50 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rATGkmFc015488 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Nov 2013 11:46:48 -0500 Received: from dhcp-200-207.str.redhat.com (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rATGkEqk019151; Fri, 29 Nov 2013 11:46:47 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 29 Nov 2013 17:45:35 +0100 Message-Id: <1385743555-27888-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1385743555-27888-1-git-send-email-kwolf@redhat.com> References: <1385743555-27888-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 20/41] sheepdog: implement .bdrv_get_allocated_file_size 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: Liu Yuan With this patch, qemu-img info sheepdog:image will show disk size for sheepdog images. Cc: Kevin Wolf Cc: Stefan Hajnoczi Cc: MORITA Kazutaka Signed-off-by: Liu Yuan Reviewed-by: MORITA Kazutaka Signed-off-by: Kevin Wolf --- block/sheepdog.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/sheepdog.c b/block/sheepdog.c index ef387de..252d7ad 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2407,6 +2407,22 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, return ret; } +static int64_t sd_get_allocated_file_size(BlockDriverState *bs) +{ + BDRVSheepdogState *s = bs->opaque; + SheepdogInode *inode = &s->inode; + unsigned long i, last = DIV_ROUND_UP(inode->vdi_size, SD_DATA_OBJ_SIZE); + uint64_t size = 0; + + for (i = 0; i < last; i++) { + if (inode->data_vdi_id[i] == 0) { + continue; + } + size += SD_DATA_OBJ_SIZE; + } + return size; +} + static QEMUOptionParameter sd_create_options[] = { { .name = BLOCK_OPT_SIZE, @@ -2436,6 +2452,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, + .bdrv_get_allocated_file_size = sd_get_allocated_file_size, .bdrv_truncate = sd_truncate, .bdrv_co_readv = sd_co_readv, @@ -2465,6 +2482,7 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, + .bdrv_get_allocated_file_size = sd_get_allocated_file_size, .bdrv_truncate = sd_truncate, .bdrv_co_readv = sd_co_readv, @@ -2494,6 +2512,7 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, + .bdrv_get_allocated_file_size = sd_get_allocated_file_size, .bdrv_truncate = sd_truncate, .bdrv_co_readv = sd_co_readv,