On Fri, Dec 30, 2011 at 10:03 AM, Marcelo Tosatti <mtosa...@redhat.com> wrote: > Signed-off-by: Marcelo Tosatti <mtosa...@redhat.com> > > 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