From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THeoi-0003Fr-J3 for qemu-devel@nongnu.org; Fri, 28 Sep 2012 13:57:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THeog-0007fF-Pp for qemu-devel@nongnu.org; Fri, 28 Sep 2012 13:57:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41944) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THeog-0007em-Hf for qemu-devel@nongnu.org; Fri, 28 Sep 2012 13:57:34 -0400 From: Kevin Wolf Date: Fri, 28 Sep 2012 19:56:54 +0200 Message-Id: <1348855033-17174-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1348855033-17174-1-git-send-email-kwolf@redhat.com> References: <1348855033-17174-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 11/30] block: helper function, to find the base image of a chain List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Jeff Cody This is a simple helper function, that will return the base image of a given image chain. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block.c | 16 ++++++++++++++++ block.h | 1 + 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 54209a5..d7a6d14 100644 --- a/block.c +++ b/block.c @@ -3117,6 +3117,22 @@ int bdrv_get_backing_file_depth(BlockDriverState *bs) return 1 + bdrv_get_backing_file_depth(bs->backing_hd); } +BlockDriverState *bdrv_find_base(BlockDriverState *bs) +{ + BlockDriverState *curr_bs = NULL; + + if (!bs) { + return NULL; + } + + curr_bs = bs; + + while (curr_bs->backing_hd) { + curr_bs = curr_bs->backing_hd; + } + return curr_bs; +} + #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 8c9b424..e9249c4 100644 --- a/block.h +++ b/block.h @@ -207,6 +207,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, BlockDriverState *base); BlockDriverState *bdrv_find_overlay(BlockDriverState *active, BlockDriverState *bs); +BlockDriverState *bdrv_find_base(BlockDriverState *bs); typedef struct BdrvCheckResult { -- 1.7.6.5