diff mbox

[v2,04/11] block: add helper function to find the active layer of any BDS

Message ID 532d4f010624ccf8f70f5447519acdc795c375d9.1401200582.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody May 27, 2014, 2:28 p.m. UTC
This helper function will find the active (top-most) layer of a
specified BDS.  This returns either the active layer, or NULL if
the passed BDS is NULL.

Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 block.c               | 10 ++++++++++
 include/block/block.h |  1 +
 2 files changed, 11 insertions(+)

Comments

Eric Blake May 27, 2014, 3:58 p.m. UTC | #1
On 05/27/2014 08:28 AM, Jeff Cody wrote:
> This helper function will find the active (top-most) layer of a
> specified BDS.  This returns either the active layer, or NULL if
> the passed BDS is NULL.
> 
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  block.c               | 10 ++++++++++
>  include/block/block.h |  1 +
>  2 files changed, 11 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index b72fe4e..577d4f1 100644
--- a/block.c
+++ b/block.c
@@ -4379,6 +4379,16 @@  BlockDriverState *bdrv_find_base(BlockDriverState *bs)
     return curr_bs;
 }
 
+/* Given a BDS, searches for the active layer.  If
+ * active layer cannot be found, returns NULL */
+BlockDriverState *bdrv_find_active(BlockDriverState *bs)
+{
+    while (bs && bs->overlay) {
+        bs = bs->overlay;
+    }
+    return bs;
+}
+
 /**************************************************************/
 /* async I/Os */
 
diff --git a/include/block/block.h b/include/block/block.h
index 4dc68be..a978e0d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -293,6 +293,7 @@  int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
 BlockDriverState *bdrv_find_overlay(BlockDriverState *active,
                                     BlockDriverState *bs);
 BlockDriverState *bdrv_find_base(BlockDriverState *bs);
+BlockDriverState *bdrv_find_active(BlockDriverState *bs);
 
 
 typedef struct BdrvCheckResult {