All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Chen <zhangckid@gmail.com>
To: qemu-devel <qemu-devel@nongnu.org>,
	"Dr . David Alan Gilbert" <dave@treblig.org>,
	"Eric Blake" <eblake@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>, "Fam Zheng" <fam@euphon.net>,
	"Daniel P . Berrangé" <berrange@redhat.com>
Cc: Zhang Chen <zhangckid@gmail.com>
Subject: [PATCH V10 09/15] net/colo: track IOThread references using path-based holder
Date: Thu, 16 Jul 2026 22:40:34 +0800	[thread overview]
Message-ID: <20260716144043.76414-10-zhangckid@gmail.com> (raw)
In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com>

Convert colo-compare to use the iothread_ref_and_get_aio_context()
and iothread_put_aio_context() APIs. This ensures that IOThread
references are tracked using the COLO object's canonical QOM path
as the holder ID.

This refactoring improves IOThread lifecycle traceability and aligns
the code with modern QEMU iothread reference management patterns.

Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
 net/colo-compare.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 5986fb1e88..a7bbb1056d 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -130,6 +130,7 @@ struct CompareState {
     GHashTable *connection_track_table;
 
     IOThread *iothread;
+    AioContext *iothread_ctx;
     GMainContext *worker_context;
     QEMUTimer *packet_check_timer;
 
@@ -922,9 +923,7 @@ void colo_notify_compares_event(void *opaque, int event, Error **errp)
 
 static void colo_compare_timer_init(CompareState *s)
 {
-    AioContext *ctx = iothread_get_aio_context(s->iothread);
-
-    s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_HOST,
+    s->packet_check_timer = aio_timer_new(s->iothread_ctx, QEMU_CLOCK_HOST,
                                 SCALE_MS, check_old_packet_regular,
                                 s);
     timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
@@ -964,8 +963,15 @@ static void colo_compare_handle_event(void *opaque)
 
 static void colo_compare_iothread(CompareState *s)
 {
-    AioContext *ctx = iothread_get_aio_context(s->iothread);
-    object_ref(OBJECT(s->iothread));
+    g_autofree char *path = object_get_canonical_path(OBJECT(s));
+    IOThreadHolder io_holder = {
+        .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT,
+        .u.qom_object.qom_path = (char *)path,
+    };
+
+    AioContext *ctx = iothread_ref_and_get_aio_context(s->iothread, &io_holder);
+
+    s->iothread_ctx = ctx;
     s->worker_context = iothread_get_g_main_context(s->iothread);
 
     qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read,
@@ -1404,6 +1410,7 @@ static void colo_compare_finalize(Object *obj)
 {
     CompareState *s = COLO_COMPARE(obj);
     CompareState *tmp;
+    g_autofree char *path = object_get_canonical_path(OBJECT(s));
 
     qemu_mutex_lock(&colo_compare_mutex);
     QTAILQ_FOREACH(tmp, &net_compares, next) {
@@ -1430,18 +1437,20 @@ static void colo_compare_finalize(Object *obj)
     g_clear_pointer(&s->event_bh, qemu_bh_delete);
 
     if (s->iothread) {
-        AioContext *ctx = iothread_get_aio_context(s->iothread);
-
-        AIO_WAIT_WHILE(ctx, !s->out_sendco.done);
+        AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done);
         if (s->notify_dev) {
-            AIO_WAIT_WHILE(ctx, !s->notify_sendco.done);
+            AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done);
         }
 
         /* Release all unhandled packets after compare thread exited */
         g_queue_foreach(&s->conn_list, colo_flush_packets, s);
         AIO_WAIT_WHILE(NULL, !s->out_sendco.done);
 
-        object_unref(OBJECT(s->iothread));
+        IOThreadHolder io_holder = {
+            .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT,
+            .u.qom_object.qom_path = (char *)path,
+        };
+        iothread_put_aio_context(s->iothread, &io_holder);
     }
 
     g_queue_clear(&s->conn_list);
-- 
2.49.0



  parent reply	other threads:[~2026-07-16 14:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 14:40 [PATCH V10 00/15] iothread: Support tracking and querying IOThread holders Zhang Chen
2026-07-16 14:40 ` [PATCH V10 01/15] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-07-16 14:40 ` [PATCH V10 02/15] iothread: introduce iothread_ref/unref to track attached devices Zhang Chen
2026-07-16 14:40 ` [PATCH V10 03/15] iothread: tracking iothread users with holder name Zhang Chen
2026-07-16 14:40 ` [PATCH V10 04/15] iothread: introduce iothread_unsafe_get_aio_context() Zhang Chen
2026-07-16 14:40 ` [PATCH V10 05/15] block/export: track IOThread reference in BlockExport Zhang Chen
2026-07-16 14:40 ` [PATCH V10 06/15] monitor: Update tracking iothread users with holder Zhang Chen
2026-07-16 15:11   ` Daniel P. Berrangé
2026-07-16 16:18     ` Zhang Chen
2026-07-16 14:40 ` [PATCH V10 07/15] virtio-vq-mapping: track iothread-vq-mapping references using device path Zhang Chen
2026-07-16 14:40 ` [PATCH V10 08/15] virtio: use iothread_get/put_aio_context for thread pinning Zhang Chen
2026-07-16 14:40 ` Zhang Chen [this message]
2026-07-16 14:40 ` [PATCH V10 10/15] virtio-balloon: Update tracking iothread users with holder Zhang Chen
2026-07-16 14:40 ` [PATCH V10 11/15] vfio-user/proxy: Update tracking iothread users with holder name Zhang Chen
2026-07-16 14:40 ` [PATCH V10 12/15] xen-block: " Zhang Chen
2026-07-16 14:40 ` [PATCH V10 13/15] monitor/hmp: Add holders support for hmp_info_iothreads Zhang Chen
2026-07-16 14:40 ` [PATCH V10 14/15] iothread: simplify API by merging iothread_get_aio_context variants Zhang Chen
2026-07-16 14:40 ` [PATCH V10 15/15] tests/unit/iothread: Update the iothread_get_aio_context Zhang Chen

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=20260716144043.76414-10-zhangckid@gmail.com \
    --to=zhangckid@gmail.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dave@treblig.org \
    --cc=eblake@redhat.com \
    --cc=fam@euphon.net \
    --cc=jasowang@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.