From patchwork Mon Jul 23 14:56:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benoit Canet X-Patchwork-Id: 172700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3D8882C035D for ; Tue, 24 Jul 2012 00:57:26 +1000 (EST) Received: from localhost ([::1]:54341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StK4a-00009g-0V for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 10:57:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StK4I-0008Lh-HW for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:57:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StK4D-0007yW-Oq for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:57:06 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:40694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StK4D-0007yF-If for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:57:01 -0400 Received: by mail-bk0-f45.google.com with SMTP id ji1so4546193bkc.4 for ; Mon, 23 Jul 2012 07:57:01 -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:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=jnukCHeu3Zk9IOdwqvQsNIAqFGs9hlH+MseSxMXpBXU=; b=tkdzDrQfHS3+I8VMurKx2y8o3+ucCRLsxRsvdF1ULE+8BgkZ3Qn5y+W09s1/cJ6hZz gANRRHsG0Vo/sHOTNrA90ZsOev5n9AOOlRJ3SYNYP0J741Wq1MiNO5jOTvCKcxW1pXBj 8VWE1KLnzsVDWKV48X4RS837vp2RXdX2A+05c3qbyLdl8dZfC0dE1SQpMNHLXF9eeUFO m6EQkGjfN0qtAVOwE9zokb8p/Nw4hvaRNhwBC00p+MNDLyDpvXIkcGrgSXPT83dTtuXz gZH0FnvArRqzizYlh+x23hJEtkt4ppp9Yd0Xs26gDh1kSkQxWjqDrWpQul4qJ8UoNJ4k Sdrw== Received: by 10.205.127.131 with SMTP id ha3mr8114466bkc.123.1343055421019; Mon, 23 Jul 2012 07:57:01 -0700 (PDT) Received: from Laure.box.in.irqsave.net (paradis.irqsave.net. [109.190.18.76]) by mx.google.com with ESMTPS id y20sm7870384bkv.11.2012.07.23.07.56.59 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jul 2012 07:57:00 -0700 (PDT) From: benoit.canet@gmail.com To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2012 16:56:53 +0200 Message-Id: <1343055415-24767-2-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1343055415-24767-1-git-send-email-benoit@irqsave.net> References: <1343055415-24767-1-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.45 Cc: kwolf@redhat.com, stefanha@gmail.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@linux.vnet.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 1/3] block: create bdrv_get_file_ancestors_count() 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: BenoƮt Canet Create bdrv_get_file_ancestors_count() in order to be able to show in QMP and HMP how many ancestors backing an image a block device have. Signed-off-by: Benoit Canet --- block.c | 13 +++++++++++++ block.h | 1 + 2 files changed, 14 insertions(+) diff --git a/block.c b/block.c index ce7eb8f..1128356 100644 --- a/block.c +++ b/block.c @@ -2754,6 +2754,19 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, return NULL; } +int bdrv_get_file_ancestors_count(BlockDriverState *bs) +{ + if (!bs->drv) { + return 0; + } + + if (!bs->backing_hd) { + return 0; + } + + return 1 + bdrv_get_file_ancestors_count(bs->backing_hd); +} + #define NB_SUFFIXES 4 char *get_human_readable_size(char *buf, int buf_size, int64_t size) diff --git a/block.h b/block.h index c89590d..8114ed0 100644 --- a/block.h +++ b/block.h @@ -174,6 +174,7 @@ int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, int nb_sectors, int *pnum); BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *backing_file); +int bdrv_get_file_ancestors_count(BlockDriverState *bs); int bdrv_truncate(BlockDriverState *bs, int64_t offset); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);