Replace raw object_ref/unref calls with iothread_get/put_aio_context.
Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
hw/virtio/virtio-balloon.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 4c5f486ba2..8a4494905a 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -892,14 +892,16 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
+
s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
virtio_balloon_handle_free_page_vq);
precopy_add_notifier(&s->free_page_hint_notify);
- object_ref(OBJECT(s->iothread));
- s->free_page_bh = aio_bh_new_guarded(iothread_get_aio_context(s->iothread),
- virtio_ballloon_get_free_page_hints, s,
- &dev->mem_reentrancy_guard);
+ s->free_page_bh = aio_bh_new_guarded(
+ iothread_ref_and_get_aio_context(s->iothread, path),
+ virtio_ballloon_get_free_page_hints, s,
+ &dev->mem_reentrancy_guard);
}
if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) {
@@ -919,9 +921,11 @@ static void virtio_balloon_device_unrealize(DeviceState *dev)
qemu_unregister_resettable(OBJECT(dev));
if (s->free_page_bh) {
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
+
qemu_bh_delete(s->free_page_bh);
- object_unref(OBJECT(s->iothread));
virtio_balloon_free_page_stop(s);
+ iothread_put_aio_context(s->iothread, path);
precopy_remove_notifier(&s->free_page_hint_notify);
}
balloon_stats_destroy_timer(s);
--
2.49.0