From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6zbE-0002b8-57 for qemu-devel@nongnu.org; Wed, 07 Aug 2013 05:00:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V6zb8-00043O-6P for qemu-devel@nongnu.org; Wed, 07 Aug 2013 05:00:08 -0400 Received: from mail-pb0-x22f.google.com ([2607:f8b0:400e:c01::22f]:58082) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6zb8-0003zn-1E for qemu-devel@nongnu.org; Wed, 07 Aug 2013 05:00:02 -0400 Received: by mail-pb0-f47.google.com with SMTP id rr4so1643024pbb.6 for ; Wed, 07 Aug 2013 02:00:00 -0700 (PDT) From: Liu Yuan Date: Wed, 7 Aug 2013 16:59:53 +0800 Message-Id: <1375865993-6715-1-git-send-email-namei.unix@gmail.com> Subject: [Qemu-devel] [PATCH] sheepdog: implement .bdrv_get_allocated_file_size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , sheepdog@lists.wpkg.org, MORITA Kazutaka , Stefan Hajnoczi 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 --- block/sheepdog.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/sheepdog.c b/block/sheepdog.c index afe0533..7699aad 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2321,6 +2321,22 @@ sd_co_is_allocated(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, @@ -2349,6 +2365,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, @@ -2377,6 +2394,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, @@ -2405,6 +2423,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, -- 1.7.9.5