From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T79mh-0005sv-9o for qemu-devel@nongnu.org; Thu, 30 Aug 2012 14:48:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T79mf-0005NI-75 for qemu-devel@nongnu.org; Thu, 30 Aug 2012 14:48:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T79me-0005N1-W4 for qemu-devel@nongnu.org; Thu, 30 Aug 2012 14:48:05 -0400 From: Jeff Cody Date: Thu, 30 Aug 2012 14:47:43 -0400 Message-Id: <119e6ad34ce86318a8e07cf84bb7de4b2a750cee.1346351079.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [RFC v2 PATCH 5/6] block: helper function, to find the base image of a chain List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@gmail.com, eblake@redhat.com, supriyak@linux.vnet.ibm.com This is a simple helper function, that will return the base image of a given image chain. Signed-off-by: Jeff Cody --- block.c | 16 ++++++++++++++++ block.h | 1 + 2 files changed, 17 insertions(+) diff --git a/block.c b/block.c index 11e275c..5f58600 100644 --- a/block.c +++ b/block.c @@ -3137,6 +3137,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 ee76869..376cc50 100644 --- a/block.h +++ b/block.h @@ -201,6 +201,7 @@ int bdrv_commit_all(void); int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt); void bdrv_register(BlockDriver *bdrv); +BlockDriverState *bdrv_find_base(BlockDriverState *bs); int bdrv_delete_intermediate(BlockDriverState *active, BlockDriverState *top, BlockDriverState *base); BlockDriverState *bdrv_find_child(BlockDriverState *active, -- 1.7.11.2