diff mbox

[v2,04/11] block: use refcnt for device attach/detach

Message ID 1374054136-28741-5-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng July 17, 2013, 9:42 a.m. UTC
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Stefan Hajnoczi July 23, 2013, 9:44 a.m. UTC | #1
On Wed, Jul 17, 2013 at 05:42:09PM +0800, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@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.
diff mbox

Patch

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;