diff mbox

[02/55] block: Reset device model callbacks on detach

Message ID 1311179069-27882-3-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster July 20, 2011, 4:23 p.m. UTC
BlockDriverState members change_cb and change_opaque are initially
null.  The device model may set them, with bdrv_set_change_cb().  If
the device model gets detached (hot unplug), they're left dangling.
Only safe because device hot unplug automatically destroys the
BlockDriverState.  But that's a questionable feature, best not to rely
on it.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Christoph Hellwig July 25, 2011, 12:27 p.m. UTC | #1
On Wed, Jul 20, 2011 at 06:23:36PM +0200, Markus Armbruster wrote:
> BlockDriverState members change_cb and change_opaque are initially
> null.  The device model may set them, with bdrv_set_change_cb().  If
> the device model gets detached (hot unplug), they're left dangling.
> Only safe because device hot unplug automatically destroys the
> BlockDriverState.  But that's a questionable feature, best not to rely
> on it.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox

Patch

diff --git a/block.c b/block.c
index 24a25d5..c49a825 100644
--- a/block.c
+++ b/block.c
@@ -730,6 +730,8 @@  void bdrv_detach(BlockDriverState *bs, DeviceState *qdev)
 {
     assert(bs->peer == qdev);
     bs->peer = NULL;
+    bs->change_cb = NULL;
+    bs->change_opaque = NULL;
 }
 
 DeviceState *bdrv_get_attached(BlockDriverState *bs)