diff mbox

[v2,4/7] block: helper function, to find the base image of a chain

Message ID 26a2d4bf59b66b5b898ad5cbc2ac939cbd5ec255.1348589526.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody Sept. 25, 2012, 4:29 p.m. UTC
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>
---
 block.c | 16 ++++++++++++++++
 block.h |  1 +
 2 files changed, 17 insertions(+)

Comments

Eric Blake Sept. 25, 2012, 7:13 p.m. UTC | #1
On 09/25/2012 10:29 AM, Jeff Cody wrote:
> 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>
> ---
>  block.c | 16 ++++++++++++++++
>  block.h |  1 +
>  2 files changed, 17 insertions(+)

Bikeshed question: Any reason patch 1/7 adds two helper functions, and
patch 4/7 adds a third?  Perhaps it would be worth squashing all three
into one commit, or else having three commits, one per helper?  But
there's no point in repainting things now, so:

Reviewed-by: Eric Blake <eblake@redhat.com>
Jeff Cody Sept. 25, 2012, 7:45 p.m. UTC | #2
On 09/25/2012 03:13 PM, Eric Blake wrote:
> On 09/25/2012 10:29 AM, Jeff Cody wrote:
>> 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>
>> ---
>>  block.c | 16 ++++++++++++++++
>>  block.h |  1 +
>>  2 files changed, 17 insertions(+)
> 
> Bikeshed question: Any reason patch 1/7 adds two helper functions, and
> patch 4/7 adds a third?  Perhaps it would be worth squashing all three
> into one commit, or else having three commits, one per helper?  But
> there's no point in repainting things now, so:
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 

The reasoning was the helper functions in 1/7 were to support block
commit (patch 2/7), and the helper function in 4/7 was to support the
block commit QMP command (patch 5/7), so it seemed logical to split
them.
diff mbox

Patch

diff --git a/block.c b/block.c
index d044529..4a9bdc1 100644
--- a/block.c
+++ b/block.c
@@ -3124,6 +3124,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 {