qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Andreas Faerber <afaerber@suse.de>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	fred.konrad@greensocs.com
Subject: [Qemu-devel] [RFC 5/5] virtio: fix virtio-blk child refcount in transports
Date: Wed, 19 Mar 2014 16:48:58 +0100	[thread overview]
Message-ID: <1395244138-8834-6-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1395244138-8834-1-git-send-email-stefanha@redhat.com>

object_initialize() leaves the object with a refcount of 1.
object_property_add_child() adds its own reference which is dropped
again when the property is deleted.

The upshot of this is that we always have a refcount >= 1.  Upon hot
unplug the virtio-blk child is not finalized!

Drop our reference after the child property has been added to the
parent.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/s390x/s390-virtio-bus.c | 1 +
 hw/s390x/virtio-ccw.c      | 1 +
 hw/virtio/virtio-pci.c     | 1 +
 3 files changed, 3 insertions(+)

diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index 064947b..1996c53 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -191,6 +191,7 @@ static void s390_virtio_blk_instance_init(Object *obj)
     VirtIOBlkS390 *dev = VIRTIO_BLK_S390(obj);
     object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BLK);
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+    object_unref(OBJECT(&dev->vdev));
 }
 
 static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index ba62dad..b80deb6 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -739,6 +739,7 @@ static void virtio_ccw_blk_instance_init(Object *obj)
     VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj);
     object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BLK);
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+    object_unref(OBJECT(&dev->vdev));
 }
 
 static int virtio_ccw_serial_init(VirtioCcwDevice *ccw_dev)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index ba86e1c..44421c8 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1106,6 +1106,7 @@ static void virtio_blk_pci_instance_init(Object *obj)
     VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(obj);
     object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BLK);
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+    object_unref(OBJECT(&dev->vdev));
 }
 
 static const TypeInfo virtio_blk_pci_info = {
-- 
1.8.5.3

  parent reply	other threads:[~2014-03-19 15:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-19 15:48 [Qemu-devel] [RFC 0/5] virtio: use alias properties in transport devices Stefan Hajnoczi
2014-03-19 15:48 ` [Qemu-devel] [RFC 1/5] qdev: add child alias properties Stefan Hajnoczi
2014-05-14 13:27   ` Andreas Färber
2014-05-14 13:31     ` Paolo Bonzini
2014-05-14 14:13   ` Peter Crosthwaite
2014-05-14 14:17     ` Andreas Färber
2014-05-14 14:26       ` Peter Crosthwaite
2014-03-19 15:48 ` [Qemu-devel] [RFC 2/5] virtio: add child alias properties for virtio-blk Stefan Hajnoczi
2014-05-14 14:04   ` Peter Crosthwaite
2014-05-14 14:33     ` Stefan Hajnoczi
2014-05-14 14:38       ` Peter Crosthwaite
2014-03-19 15:48 ` [Qemu-devel] [RFC 3/5] virtio: use child aliases for virtio-blk transport properties Stefan Hajnoczi
2014-03-19 15:48 ` [Qemu-devel] [RFC 4/5] virtio-blk: drop virtio_blk_set_conf() Stefan Hajnoczi
2014-03-19 15:48 ` Stefan Hajnoczi [this message]
2014-05-14 13:21 ` [Qemu-devel] [RFC 0/5] virtio: use alias properties in transport devices Stefan Hajnoczi
2014-05-16 15:08 ` Frederic Konrad
2014-05-19 14:21   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1395244138-8834-6-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=afaerber@suse.de \
    --cc=fred.konrad@greensocs.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).