[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [patch 2/5] block: implement bdrv_find_backing_image in
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [patch 2/5] block: implement bdrv_find_backing_image in qcow2 |
Date: |
Tue, 3 Jan 2012 13:44:19 +0000 |
On Fri, Dec 30, 2011 at 10:03 AM, Marcelo Tosatti <address@hidden> wrote:
> Signed-off-by: Marcelo Tosatti <address@hidden>
>
> Index: stefanha/block/qcow2.c
> ===================================================================
> --- stefanha.orig/block/qcow2.c
> +++ stefanha/block/qcow2.c
> @@ -767,6 +767,20 @@ static int qcow2_change_backing_file(Blo
> return qcow2_update_ext_header(bs, backing_file, backing_fmt);
> }
>
> +static BlockDriverState *qcow2_find_backing_image(BlockDriverState *bs,
> + const char *id)
> +{
> +
> + do {
> + if (!strncmp(bs->backing_file, id, sizeof(bs->backing_file)))
> + return bs->backing_hd;
Coding style uses {} always.
> +
> + bs = bs->backing_hd;
> + } while (bs);
> +
> + return NULL;
> +}
The backing file may not be qcow2, so we cannot loop over
bs->backing_hd. We need to recurse instead.
That said, any image format which uses bs->backing_file will use
bs->backing_hd. For example, QED could use the exact same
.bdrv_find_backing_file() implementation.
Perhaps instead we need a generic implementation which does something like:
BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *id)
{
if (!bs->drv) {
return NULL;
}
if (bs->backing_hd) {
if (strcmp(id, bs->backing_file) == 0) {
return bs->backing_hd;
} else {
return bdrv_find_backing_file(bs->backing_hd, id);
}
}
if (bs->drv->bdrv_find_backing_file) {
return bs->drv->bdrv_find_backing_file(bs, id);
}
return NULL;
}
Stefan
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Qemu-devel] [patch 2/5] block: implement bdrv_find_backing_image in qcow2,
Stefan Hajnoczi <=