From 5f8d3f29a30c6b872780dd8cbba5b0d74a5b9c57 Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Wed, 21 Mar 2012 21:55:12 +0100 Subject: [PATCH 45/55] block: add bdrv_find_backing_image RH-Author: Jeffrey Cody Message-id: <55db0a71e895d5f0ef6106c4108d8c151cb37202.1332362400.git.jcody@redhat.com> Patchwork-id: 38895 O-Subject: [RHEL6.3 qemu-kvm PATCH v8 45/54] block: add bdrv_find_backing_image Bugzilla: 582475 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Kevin Wolf 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 Signed-off-by: Kevin Wolf (cherry picked from commit e8a6bb9caa5379b0fcaca4e0a12aa6d2913961f3) Signed-off-by: Stefan Hajnoczi Signed-off-by: Anthony Liguori Signed-off-by: Jeff Cody --- block.c | 18 ++++++++++++++++++ block.h | 2 ++ 2 files changed, 20 insertions(+), 0 deletions(-) Signed-off-by: Michal Novotny --- block.c | 18 ++++++++++++++++++ block.h | 2 ++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index f74f84b..0aaab0b 100644 --- a/block.c +++ b/block.c @@ -2468,6 +2468,24 @@ int bdrv_snapshot_list(BlockDriverState *bs, return drv->bdrv_snapshot_list(bs, psn_info); } +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 5567d7c..c682ea7 100644 --- a/block.h +++ b/block.h @@ -152,6 +152,8 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, 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 *backing_file); int bdrv_truncate(BlockDriverState *bs, int64_t offset); int64_t bdrv_getlength(BlockDriverState *bs); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); -- 1.7.7.6