From 4dc08d8193c4f265039e661dca3b88339f735469 Mon Sep 17 00:00:00 2001
Message-Id: <4dc08d8193c4f265039e661dca3b88339f735469.1350493760.git.minovotn@redhat.com>
In-Reply-To: <c93188b6c6973932d2adaa52e6a4920db13b4e62.1350493760.git.minovotn@redhat.com>
References: <c93188b6c6973932d2adaa52e6a4920db13b4e62.1350493760.git.minovotn@redhat.com>
From: Jeffrey Cody <jcody@redhat.com>
Date: Wed, 17 Oct 2012 05:59:45 +0200
Subject: [PATCH 32/35] block: helper function, to find the base image of a
 chain

RH-Author: Jeffrey Cody <jcody@redhat.com>
Message-id: <260660a9583b71469acc318553eabcd30dc75bde.1350447475.git.jcody@redhat.com>
Patchwork-id: 43290
O-Subject: [RHEL6.4 qemu-kvm PATCH v4 32/35] block: helper function, to find the base image of a chain
Bugzilla: 767233
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Eric Blake <eblake@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

This is a simple helper function, that will return the base image
of a given image chain.

Signed-off-by: Jeff Cody <jcody@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 79fac5680d3680c9fb43d14a8d4e39ced25530f8)

Conflicts:
	block.c
---
 block.c | 16 ++++++++++++++++
 block.h |  1 +
 2 files changed, 17 insertions(+)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 block.c | 16 ++++++++++++++++
 block.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/block.c b/block.c
index 9fbdc8f..dfdf078 100644
--- a/block.c
+++ b/block.c
@@ -2968,6 +2968,22 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
     return NULL;
 }
 
+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 caf41a9..1de99f0 100644
--- a/block.h
+++ b/block.h
@@ -197,6 +197,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.11.7

