diff mbox

[04/13] block: New bdrv_next()

Message ID 1275497729-13120-5-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster June 2, 2010, 4:55 p.m. UTC
This is a more flexible alternative to bdrv_iterate().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c |    8 ++++++++
 block.h |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/block.c b/block.c
index 1bef649..f42960c 100644
--- a/block.c
+++ b/block.c
@@ -1330,6 +1330,14 @@  BlockDriverState *bdrv_find(const char *name)
     return NULL;
 }
 
+BlockDriverState *bdrv_next(BlockDriverState *bs)
+{
+    if (!bs) {
+        return QTAILQ_FIRST(&bdrv_states);
+    }
+    return QTAILQ_NEXT(bs, list);
+}
+
 void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void *opaque)
 {
     BlockDriverState *bs;
diff --git a/block.h b/block.h
index 49e3dcf..29993d1 100644
--- a/block.h
+++ b/block.h
@@ -168,6 +168,7 @@  void bdrv_set_change_cb(BlockDriverState *bs,
                         void (*change_cb)(void *opaque), void *opaque);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
 BlockDriverState *bdrv_find(const char *name);
+BlockDriverState *bdrv_next(BlockDriverState *bs);
 void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
                   void *opaque);
 int bdrv_is_encrypted(BlockDriverState *bs);