diff mbox

[v3,11/14] block: Add blk_next_root_bs()

Message ID 1455646106-2047-12-git-send-email-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Max Reitz Feb. 16, 2016, 6:08 p.m. UTC
This function iterates over all BDSs attached to a BB. We are going to
need it when rewriting bdrv_next() so it no longer uses bdrv_states.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/block-backend.c          | 24 ++++++++++++++++++++++++
 include/sysemu/block-backend.h |  1 +
 2 files changed, 25 insertions(+)

Comments

Kevin Wolf Feb. 17, 2016, 4:06 p.m. UTC | #1
Am 16.02.2016 um 19:08 hat Max Reitz geschrieben:
> This function iterates over all BDSs attached to a BB. We are going to
> need it when rewriting bdrv_next() so it no longer uses bdrv_states.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/block-backend.c          | 24 ++++++++++++++++++++++++
>  include/sysemu/block-backend.h |  1 +
>  2 files changed, 25 insertions(+)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index a918c35..d1621ec 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -269,6 +269,30 @@ BlockBackend *blk_next(BlockBackend *blk)
>  }
>  
>  /*
> + * Iterates over all BlockDriverStates which are attached to a BlockBackend.
> + * This function is for use by bdrv_next().
> + *
> + * @bs must be NULL or a BDS that is attached to a BB.
> + */
> +BlockDriverState *blk_next_root_bs(BlockDriverState *bs)
> +{
> +    BlockBackend *blk;
> +
> +    if (bs) {
> +        assert(bs->blk);
> +        blk = bs->blk;

I'm trying to remove bs->blk, and you're adding new instances. :-/

This isn't going to be an easy one to remove. But of course, it wouldn't
be easy for you to avoid it either, so unless you have a good idea,
let's apply this and we'll figure out how to get rid of it again.

> +    } else {
> +        blk = NULL;
> +    }
> +
> +    do {
> +        blk = blk_all_next(blk);
> +    } while (blk && !blk->bs);
> +
> +    return blk ? blk->bs : NULL;
> +}

Kevin
diff mbox

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index a918c35..d1621ec 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -269,6 +269,30 @@  BlockBackend *blk_next(BlockBackend *blk)
 }
 
 /*
+ * Iterates over all BlockDriverStates which are attached to a BlockBackend.
+ * This function is for use by bdrv_next().
+ *
+ * @bs must be NULL or a BDS that is attached to a BB.
+ */
+BlockDriverState *blk_next_root_bs(BlockDriverState *bs)
+{
+    BlockBackend *blk;
+
+    if (bs) {
+        assert(bs->blk);
+        blk = bs->blk;
+    } else {
+        blk = NULL;
+    }
+
+    do {
+        blk = blk_all_next(blk);
+    } while (blk && !blk->bs);
+
+    return blk ? blk->bs : NULL;
+}
+
+/*
  * Add a BlockBackend into the list of backends referenced by the monitor.
  * Strictly for use by blockdev.c.
  */
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 3a47982..5ac9bd2 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -73,6 +73,7 @@  const char *blk_name(BlockBackend *blk);
 BlockBackend *blk_by_name(const char *name);
 bool blk_name_taken(const char *name);
 BlockBackend *blk_next(BlockBackend *blk);
+BlockDriverState *blk_next_root_bs(BlockDriverState *bs);
 void monitor_add_blk(BlockBackend *blk);
 void monitor_remove_blk(BlockBackend *blk);