On Wed, Jul 17, 2013 at 05:42:09PM +0800, Fam Zheng wrote: > Signed-off-by: Fam Zheng <f...@redhat.com> > --- > block.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/block.c b/block.c > index 7b46669..57a3876 100644 > --- a/block.c > +++ b/block.c > @@ -1622,6 +1622,7 @@ int bdrv_attach_dev(BlockDriverState *bs, void *dev) > return -EBUSY; > } > bs->dev = dev; > + bdrv_ref(bs, false); > bdrv_iostatus_reset(bs); > return 0; > } > @@ -1639,6 +1640,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev) > { > assert(bs->dev == dev); > bs->dev = NULL; > + bdrv_unref(bs, false); > bs->dev_ops = NULL; > bs->dev_opaque = NULL; > bs->buffer_alignment = 512;
I'm not 100% sure about this. sd_init() and ide_init2_with_non_qdev_drives() call bdrv_attach_dev_nofail() but I don't see a bdrv_detach_dev() call. It may be necessary to audit the lifecycle of emulated storage controllers more closely before the refcounts work correctly.