From patchwork Wed Aug 7 08:59:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Yuan X-Patchwork-Id: 265414 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 1D1D02C0127 for ; Wed, 7 Aug 2013 19:00:30 +1000 (EST) Received: from localhost ([::1]:33933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6zbX-0002uA-WE for incoming@patchwork.ozlabs.org; Wed, 07 Aug 2013 05:00:28 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ZwBkxb8bpS3TOJ/XHZrnq/ZoMF65rBdAvTMRb4k4RMw=; b=KzE+Rr4mJyz/THwN3zIyMuy49kIYKiuuco4ecBHWpyzPZuVP1Wd0DfHRtrFkw65EWz NljaiNflDQ80F80BGT8nMQtNG8pXoftZCoe6KMmQxd0KDhLckAvzHPYqSfLu9NAns/8J 1mlsoiSMMc+JPAA4aMRTwD6HaeXNFOFZJaRWwwiNoldHKZHeKwuf7a8/UaikWztjGdpl HFq3KstLU5Jnjz14zeF+NGEYZ3Siiv25G1VqhIRIGJ8ZfEuLyieFTenDET8X54RymFyt ups+D1m+GQ50zIkwY+ODFBYVyEPz7ok+f6AE2DeDzwrmoUKZiwYBVHOEzfysYIJsASLN WuWQ== X-Received: by 10.66.186.204 with SMTP id fm12mr3085875pac.189.1375866000684; Wed, 07 Aug 2013 02:00:00 -0700 (PDT) Received: from ubuntu-precise.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPSA id bg3sm6950527pbb.44.2013.08.07.01.59.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 Aug 2013 01:59:59 -0700 (PDT) From: Liu Yuan To: qemu-devel@nongnu.org Date: Wed, 7 Aug 2013 16:59:53 +0800 Message-Id: <1375865993-6715-1-git-send-email-namei.unix@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22f Cc: Kevin Wolf , sheepdog@lists.wpkg.org, MORITA Kazutaka , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] 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 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 --- 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,