diff mbox

[v4,11/15] block: add bdrv_find_backing_image

Message ID 1325858501-25741-12-git-send-email-stefanha@linux.vnet.ibm.com
State New
Headers show

Commit Message

Stefan Hajnoczi Jan. 6, 2012, 2:01 p.m. UTC
From: Marcelo Tosatti <mtosatti@redhat.com>

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>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block.c |   17 +++++++++++++++++
 block.h |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)

Comments

Kevin Wolf Jan. 12, 2012, 12:17 p.m. UTC | #1
Am 06.01.2012 15:01, schrieb Stefan Hajnoczi:
> From: Marcelo Tosatti <mtosatti@redhat.com>
> 
> 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>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  block.c |   17 +++++++++++++++++
>  block.h |    1 +
>  2 files changed, 18 insertions(+), 0 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 5bfaa3a..9b688a0 100644
> --- a/block.c
> +++ b/block.c
> @@ -2614,6 +2614,23 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs,
>      return -ENOTSUP;
>  }
>  
> +BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *id)
> +{
> +    if (!bs->drv) {
> +        return NULL;
> +    }
> +
> +    if (bs->backing_hd) {
> +        if (strcmp(bs->backing_file, id) == 0) {
> +            return bs->backing_hd;

So it's not really just some id, but the backing file name? I would find
it clearer to reflect that in the parameter name and the QMP error in
the next patch.

Kevin
Stefan Hajnoczi Jan. 12, 2012, 1:01 p.m. UTC | #2
On Thu, Jan 12, 2012 at 12:17 PM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 06.01.2012 15:01, schrieb Stefan Hajnoczi:
>> +BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *id)
>> +{
>> +    if (!bs->drv) {
>> +        return NULL;
>> +    }
>> +
>> +    if (bs->backing_hd) {
>> +        if (strcmp(bs->backing_file, id) == 0) {
>> +            return bs->backing_hd;
>
> So it's not really just some id, but the backing file name? I would find
> it clearer to reflect that in the parameter name and the QMP error in
> the next patch.

Okay, thanks.
diff mbox

Patch

diff --git a/block.c b/block.c
index 5bfaa3a..9b688a0 100644
--- a/block.c
+++ b/block.c
@@ -2614,6 +2614,23 @@  int bdrv_snapshot_load_tmp(BlockDriverState *bs,
     return -ENOTSUP;
 }
 
+BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *id)
+{
+    if (!bs->drv) {
+        return NULL;
+    }
+
+    if (bs->backing_hd) {
+        if (strcmp(bs->backing_file, id) == 0) {
+            return bs->backing_hd;
+        } else {
+            return bdrv_find_backing_image(bs->backing_hd, id);
+        }
+    }
+
+    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..a1d9b56 100644
--- a/block.h
+++ b/block.h
@@ -153,6 +153,7 @@  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 *id);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
 int64_t bdrv_getlength(BlockDriverState *bs);
 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);