From patchwork Fri Jan 13 13:14:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v5,11/15] block: add bdrv_find_backing_image From: Stefan Hajnoczi X-Patchwork-Id: 135840 Message-Id: <1326460457-19446-12-git-send-email-stefanha@linux.vnet.ibm.com> To: Cc: Kevin Wolf , Marcelo Tosatti , Stefan Hajnoczi , Luiz Capitulino Date: Fri, 13 Jan 2012 13:14:13 +0000 From: Marcelo Tosatti 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 Signed-off-by: Stefan Hajnoczi --- block.c | 18 ++++++++++++++++++ block.h | 2 ++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index d588ee8..d8ae716 100644 --- a/block.c +++ b/block.c @@ -2614,6 +2614,24 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs, return -ENOTSUP; } +BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, + const char *backing_file) +{ + if (!bs->drv) { + return NULL; + } + + if (bs->backing_hd) { + if (strcmp(bs->backing_file, backing_file) == 0) { + return bs->backing_hd; + } else { + return bdrv_find_backing_image(bs->backing_hd, backing_file); + } + } + + return NULL; +} + #define NB_SUFFIXES 4 char *get_human_readable_size(char *buf, int buf_size, int64_t size) diff --git a/block.h b/block.h index 51b90c7..05c8c83 100644 --- a/block.h +++ b/block.h @@ -153,6 +153,8 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors); 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 *backing_file); int bdrv_truncate(BlockDriverState *bs, int64_t offset); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);