From patchwork Fri Sep 14 13:41:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 183935 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 25DB72C0082 for ; Fri, 14 Sep 2012 23:43:48 +1000 (EST) Received: from localhost ([::1]:46705 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCWBO-0002HY-9n for incoming@patchwork.ozlabs.org; Fri, 14 Sep 2012 09:43:46 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCWBA-0002G6-IZ for qemu-devel@nongnu.org; Fri, 14 Sep 2012 09:43:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCWB6-0003PF-2i for qemu-devel@nongnu.org; Fri, 14 Sep 2012 09:43:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22144) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCWB5-0003OA-Rk for qemu-devel@nongnu.org; Fri, 14 Sep 2012 09:43:28 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8EDff0W027773 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 14 Sep 2012 09:41:41 -0400 Received: from localhost ([10.3.112.18]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8EDfcFl010130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 14 Sep 2012 09:41:40 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Fri, 14 Sep 2012 09:41:10 -0400 Message-Id: <4439048aa3fbeb117201a868636f3221d2a6fea6.1347629357.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@gmail.com, eblake@redhat.com, supriyak@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 5/8] block: helper function, to find the base image of a chain 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 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 9549eca..f19c1dd 100644 --- a/block.c +++ b/block.c @@ -3113,6 +3113,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 54a074d..c256211 100644 --- a/block.h +++ b/block.h @@ -213,6 +213,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 { int corruptions;