diff mbox

[10/21] block: Add blk_next_inserted()

Message ID 1422300468-16216-11-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Jan. 26, 2015, 7:27 p.m. UTC
This function skips to the next BlockBackend for which blk_is_inserted()
is true.

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

Comments

Eric Blake Jan. 29, 2015, 11:52 p.m. UTC | #1
On 01/26/2015 12:27 PM, Max Reitz wrote:
> This function skips to the next BlockBackend for which blk_is_inserted()
> is true.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/block-backend.c          | 15 +++++++++++++++
>  include/sysemu/block-backend.h |  1 +
>  2 files changed, 16 insertions(+)
> 

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

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index 4467a8c..3ff6679 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -232,6 +232,21 @@  BlockBackend *blk_next(BlockBackend *blk)
 }
 
 /*
+ * Like blk_next(), but skips all non-inserted BlockBackends (that is,
+ * BlockBackends for which blk_is_inserted() returns false)
+ */
+BlockBackend *blk_next_inserted(BlockBackend *blk)
+{
+    while ((blk = blk_next(blk)) != NULL) {
+        if (blk_is_inserted(blk)) {
+            break;
+        }
+    }
+
+    return blk;
+}
+
+/*
  * Return @blk's name, a non-null string.
  * Wart: the name is empty iff @blk has been hidden with
  * blk_hide_on_behalf_of_do_drive_del().
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 7322db6..e1645ae 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -74,6 +74,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);
+BlockBackend *blk_next_inserted(BlockBackend *blk);
 
 BlockDriverState *blk_bs(BlockBackend *blk);
 void blk_remove_bs(BlockBackend *blk);