diff mbox

[1/5] block: add bdrv_find_backing_image

Message ID 20111230100503.173568803@redhat.com
State New
Headers show

Commit Message

Marcelo Tosatti Dec. 30, 2011, 10:03 a.m. UTC
Add bdrv_find_backing_image: given a BlockDriverState pointer, and an id,
traverse the backing image chain to locate the id.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
diff mbox

Patch

Index: stefanha/block.c
===================================================================
--- stefanha.orig/block.c
+++ stefanha/block.c
@@ -2580,6 +2580,23 @@  int bdrv_snapshot_load_tmp(BlockDriverSt
     return -ENOTSUP;
 }
 
+/*
+ * Return the BlockDriverState pointer for a backing image
+ * with 'id'.
+ */
+BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
+                                          const char *id)
+{
+    BlockDriver *drv = bs->drv;
+    if (!drv) {
+        return NULL;
+    }
+    if (drv->bdrv_find_backing_image) {
+            return drv->bdrv_find_backing_image(bs, id);
+    }
+    return NULL;
+}
+
 #define NB_SUFFIXES 4
 
 char *get_human_readable_size(char *buf, int buf_size, int64_t size)
Index: stefanha/block.h
===================================================================
--- stefanha.orig/block.h
+++ stefanha/block.h
@@ -146,6 +146,7 @@  int coroutine_fn bdrv_co_writev(BlockDri
     int nb_sectors, QEMUIOVector *qiov);
 int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num,
     int nb_sectors, int *pnum);
+BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *id);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
 int64_t bdrv_getlength(BlockDriverState *bs);
 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
Index: stefanha/block_int.h
===================================================================
--- stefanha.orig/block_int.h
+++ stefanha/block_int.h
@@ -136,6 +136,9 @@  struct BlockDriver {
     int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs,
         int64_t sector_num, int nb_sectors, int *pnum);
 
+    BlockDriverState *(*bdrv_find_backing_image)(BlockDriverState *bs,
+        const char *id);
+
     /*
      * Invalidate any cached meta-data.
      */