All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/4] colo-compare: fix some bugs
@ 2017-02-16  6:00 zhanghailiang
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 1/4] colo-compare: use g_timeout_source_new() to process the stale packets zhanghailiang
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: zhanghailiang @ 2017-02-16  6:00 UTC (permalink / raw)
  To: jasowang, zhangchen.fnst, lizhijian
  Cc: qemu-devel, xuquan8, pss.wulizhen, zhanghailiang

This series includes two parts: codes optimization and bug fix.
patch 1 tries to move timer process into colo compare thread as 
a new coroutine.
patch 2 ~ 4 fixe some bugs of colo compare.

v2:
 - Squash patch 3 of last version into patch 2. (ZhangChen's suggestion)

zhanghailiang (4):
  colo-compare: use g_timeout_source_new() to process the stale packets
  colo-compare: kick compare thread to exit after some cleanup in
    finalization
  char: remove the right fd been watched in qemu_chr_fe_set_handlers()
  colo-compare: Fix removing fds been watched incorrectly in
    finalization

 chardev/char-io.c  |  13 ++++--
 chardev/char-io.h  |   2 +
 chardev/char.c     |   2 +-
 net/colo-compare.c | 115 +++++++++++++++++++++++++++--------------------------
 4 files changed, 71 insertions(+), 61 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v2 1/4] colo-compare: use g_timeout_source_new() to process the stale packets
  2017-02-16  6:00 [Qemu-devel] [PATCH v2 0/4] colo-compare: fix some bugs zhanghailiang
@ 2017-02-16  6:00 ` zhanghailiang
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 2/4] colo-compare: kick compare thread to exit after some cleanup in finalization zhanghailiang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: zhanghailiang @ 2017-02-16  6:00 UTC (permalink / raw)
  To: jasowang, zhangchen.fnst, lizhijian
  Cc: qemu-devel, xuquan8, pss.wulizhen, zhanghailiang

Instead of using qemu timer to process the stale packets,
We re-use the colo compare thread to process these packets
by creating a new timeout coroutine.

Besides, since we process all the same vNIC's net connection/packets
in one thread, it is safe to remove the timer_check_lock.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 net/colo-compare.c | 62 +++++++++++++++++++-----------------------------------
 1 file changed, 22 insertions(+), 40 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 162fd6a..fdde788 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -83,9 +83,6 @@ typedef struct CompareState {
     GHashTable *connection_track_table;
     /* compare thread, a thread for each NIC */
     QemuThread thread;
-    /* Timer used on the primary to find packets that are never matched */
-    QEMUTimer *timer;
-    QemuMutex timer_check_lock;
 } CompareState;
 
 typedef struct CompareClass {
@@ -374,9 +371,7 @@ static void colo_compare_connection(void *opaque, void *user_data)
 
     while (!g_queue_is_empty(&conn->primary_list) &&
            !g_queue_is_empty(&conn->secondary_list)) {
-        qemu_mutex_lock(&s->timer_check_lock);
         pkt = g_queue_pop_tail(&conn->primary_list);
-        qemu_mutex_unlock(&s->timer_check_lock);
         switch (conn->ip_proto) {
         case IPPROTO_TCP:
             result = g_queue_find_custom(&conn->secondary_list,
@@ -411,9 +406,7 @@ static void colo_compare_connection(void *opaque, void *user_data)
              * until next comparison.
              */
             trace_colo_compare_main("packet different");
-            qemu_mutex_lock(&s->timer_check_lock);
             g_queue_push_tail(&conn->primary_list, pkt);
-            qemu_mutex_unlock(&s->timer_check_lock);
             /* TODO: colo_notify_checkpoint();*/
             break;
         }
@@ -486,11 +479,26 @@ static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size)
     }
 }
 
+/*
+ * Check old packet regularly so it can watch for any packets
+ * that the secondary hasn't produced equivalents of.
+ */
+static gboolean check_old_packet_regular(void *opaque)
+{
+    CompareState *s = opaque;
+
+    /* if have old packet we will notify checkpoint */
+    colo_old_packet_check(s);
+
+    return TRUE;
+}
+
 static void *colo_compare_thread(void *opaque)
 {
     GMainContext *worker_context;
     GMainLoop *compare_loop;
     CompareState *s = opaque;
+    GSource *timeout_source;
 
     worker_context = g_main_context_new();
 
@@ -501,8 +509,15 @@ static void *colo_compare_thread(void *opaque)
 
     compare_loop = g_main_loop_new(worker_context, FALSE);
 
+    /* To kick any packets that the secondary doesn't match */
+    timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS);
+    g_source_set_callback(timeout_source,
+                          (GSourceFunc)check_old_packet_regular, s, NULL);
+    g_source_attach(timeout_source, worker_context);
+
     g_main_loop_run(compare_loop);
 
+    g_source_unref(timeout_source);
     g_main_loop_unref(compare_loop);
     g_main_context_unref(worker_context);
     return NULL;
@@ -604,26 +619,6 @@ static int find_and_check_chardev(Chardev **chr,
 }
 
 /*
- * Check old packet regularly so it can watch for any packets
- * that the secondary hasn't produced equivalents of.
- */
-static void check_old_packet_regular(void *opaque)
-{
-    CompareState *s = opaque;
-
-    timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
-              REGULAR_PACKET_CHECK_MS);
-    /* if have old packet we will notify checkpoint */
-    /*
-     * TODO: Make timer handler run in compare thread
-     * like qemu_chr_add_handlers_full.
-     */
-    qemu_mutex_lock(&s->timer_check_lock);
-    colo_old_packet_check(s);
-    qemu_mutex_unlock(&s->timer_check_lock);
-}
-
-/*
  * Called from the main thread on the primary
  * to setup colo-compare.
  */
@@ -665,7 +660,6 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
     net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize);
 
     g_queue_init(&s->conn_list);
-    qemu_mutex_init(&s->timer_check_lock);
 
     s->connection_track_table = g_hash_table_new_full(connection_key_hash,
                                                       connection_key_equal,
@@ -678,12 +672,6 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
                        QEMU_THREAD_JOINABLE);
     compare_id++;
 
-    /* A regular timer to kick any packets that the secondary doesn't match */
-    s->timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, /* Only when guest runs */
-                            check_old_packet_regular, s);
-    timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
-                        REGULAR_PACKET_CHECK_MS);
-
     return;
 }
 
@@ -723,12 +711,6 @@ static void colo_compare_finalize(Object *obj)
         qemu_thread_join(&s->thread);
     }
 
-    if (s->timer) {
-        timer_del(s->timer);
-    }
-
-    qemu_mutex_destroy(&s->timer_check_lock);
-
     g_free(s->pri_indev);
     g_free(s->sec_indev);
     g_free(s->outdev);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v2 2/4] colo-compare: kick compare thread to exit after some cleanup in finalization
  2017-02-16  6:00 [Qemu-devel] [PATCH v2 0/4] colo-compare: fix some bugs zhanghailiang
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 1/4] colo-compare: use g_timeout_source_new() to process the stale packets zhanghailiang
@ 2017-02-16  6:00 ` zhanghailiang
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers() zhanghailiang
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 4/4] colo-compare: Fix removing fds been watched incorrectly in finalization zhanghailiang
  3 siblings, 0 replies; 9+ messages in thread
From: zhanghailiang @ 2017-02-16  6:00 UTC (permalink / raw)
  To: jasowang, zhangchen.fnst, lizhijian
  Cc: qemu-devel, xuquan8, pss.wulizhen, zhanghailiang

We should call g_main_loop_quit() to notify colo compare thread to
exit, Or it will run in g_main_loop_run() forever.

Besides, the finalizing process can't happen in context of colo thread,
it is reasonable to remove the 'if (qemu_thread_is_self(&s->thread))'
branch.

Before compare thead exits, some cleanup works need to be
done,  All unhandled packets need to be released and connection_track_table
needs to be freed, or there will be memory leak.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 net/colo-compare.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index fdde788..37ce75c 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -83,6 +83,8 @@ typedef struct CompareState {
     GHashTable *connection_track_table;
     /* compare thread, a thread for each NIC */
     QemuThread thread;
+
+    GMainLoop *compare_loop;
 } CompareState;
 
 typedef struct CompareClass {
@@ -496,7 +498,6 @@ static gboolean check_old_packet_regular(void *opaque)
 static void *colo_compare_thread(void *opaque)
 {
     GMainContext *worker_context;
-    GMainLoop *compare_loop;
     CompareState *s = opaque;
     GSource *timeout_source;
 
@@ -507,7 +508,7 @@ static void *colo_compare_thread(void *opaque)
     qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read,
                              compare_sec_chr_in, NULL, s, worker_context, true);
 
-    compare_loop = g_main_loop_new(worker_context, FALSE);
+    s->compare_loop = g_main_loop_new(worker_context, FALSE);
 
     /* To kick any packets that the secondary doesn't match */
     timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS);
@@ -515,10 +516,10 @@ static void *colo_compare_thread(void *opaque)
                           (GSourceFunc)check_old_packet_regular, s, NULL);
     g_source_attach(timeout_source, worker_context);
 
-    g_main_loop_run(compare_loop);
+    g_main_loop_run(s->compare_loop);
 
     g_source_unref(timeout_source);
-    g_main_loop_unref(compare_loop);
+    g_main_loop_unref(s->compare_loop);
     g_main_context_unref(worker_context);
     return NULL;
 }
@@ -675,6 +676,23 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
     return;
 }
 
+static void colo_flush_packets(void *opaque, void *user_data)
+{
+    CompareState *s = user_data;
+    Connection *conn = opaque;
+    Packet *pkt = NULL;
+
+    while (!g_queue_is_empty(&conn->primary_list)) {
+        pkt = g_queue_pop_head(&conn->primary_list);
+        compare_chr_send(&s->chr_out, pkt->data, pkt->size);
+        packet_destroy(pkt, NULL);
+    }
+    while (!g_queue_is_empty(&conn->secondary_list)) {
+        pkt = g_queue_pop_head(&conn->secondary_list);
+        packet_destroy(pkt, NULL);
+    }
+}
+
 static void colo_compare_class_init(ObjectClass *oc, void *data)
 {
     UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
@@ -703,14 +721,15 @@ static void colo_compare_finalize(Object *obj)
     qemu_chr_fe_deinit(&s->chr_sec_in);
     qemu_chr_fe_deinit(&s->chr_out);
 
-    g_queue_free(&s->conn_list);
+    g_main_loop_quit(s->compare_loop);
+    qemu_thread_join(&s->thread);
 
-    if (qemu_thread_is_self(&s->thread)) {
-        /* compare connection */
-        g_queue_foreach(&s->conn_list, colo_compare_connection, s);
-        qemu_thread_join(&s->thread);
-    }
+    /* Release all unhandled packets after compare thead exited */
+    g_queue_foreach(&s->conn_list, colo_flush_packets, s);
+
+    g_queue_free(&s->conn_list);
 
+    g_hash_table_destroy(s->connection_track_table);
     g_free(s->pri_indev);
     g_free(s->sec_indev);
     g_free(s->outdev);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers()
  2017-02-16  6:00 [Qemu-devel] [PATCH v2 0/4] colo-compare: fix some bugs zhanghailiang
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 1/4] colo-compare: use g_timeout_source_new() to process the stale packets zhanghailiang
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 2/4] colo-compare: kick compare thread to exit after some cleanup in finalization zhanghailiang
@ 2017-02-16  6:00 ` zhanghailiang
  2017-02-16 10:40   ` Marc-André Lureau
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 4/4] colo-compare: Fix removing fds been watched incorrectly in finalization zhanghailiang
  3 siblings, 1 reply; 9+ messages in thread
From: zhanghailiang @ 2017-02-16  6:00 UTC (permalink / raw)
  To: jasowang, zhangchen.fnst, lizhijian
  Cc: qemu-devel, xuquan8, pss.wulizhen, zhanghailiang, Paolo Bonzini,
	Marc-André Lureau

We can call qemu_chr_fe_set_handlers() to add/remove fd been watched
in 'context' which can be either default main context or other explicit
context. But the original logic is not correct, we didn't remove
the right fd because we call g_main_context_find_source_by_id(NULL, tag)
which always try to find the Gsource from default context.

Fix it by passing the right context to g_main_context_find_source_by_id().

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 chardev/char-io.c | 13 +++++++++----
 chardev/char-io.h |  2 ++
 chardev/char.c    |  2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/chardev/char-io.c b/chardev/char-io.c
index 7dfc3f2..a69cc61 100644
--- a/chardev/char-io.c
+++ b/chardev/char-io.c
@@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr,
     return tag;
 }
 
-static void io_remove_watch_poll(guint tag)
+static void io_remove_watch_poll(guint tag, GMainContext *context)
 {
     GSource *source;
     IOWatchPoll *iwp;
 
     g_return_if_fail(tag > 0);
 
-    source = g_main_context_find_source_by_id(NULL, tag);
+    source = g_main_context_find_source_by_id(context, tag);
     g_return_if_fail(source != NULL);
 
     iwp = io_watch_poll_from_source(source);
@@ -146,14 +146,19 @@ static void io_remove_watch_poll(guint tag)
     g_source_destroy(&iwp->parent);
 }
 
-void remove_fd_in_watch(Chardev *chr)
+void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context)
 {
     if (chr->fd_in_tag) {
-        io_remove_watch_poll(chr->fd_in_tag);
+        io_remove_watch_poll(chr->fd_in_tag, context);
         chr->fd_in_tag = 0;
     }
 }
 
+void remove_fd_in_watch(Chardev *chr)
+{
+    qemu_remove_fd_in_watch(chr, NULL);
+}
+
 int io_channel_send_full(QIOChannel *ioc,
                          const void *buf, size_t len,
                          int *fds, size_t nfds)
diff --git a/chardev/char-io.h b/chardev/char-io.h
index d7ae5f1..117c888 100644
--- a/chardev/char-io.h
+++ b/chardev/char-io.h
@@ -38,6 +38,8 @@ guint io_add_watch_poll(Chardev *chr,
 
 void remove_fd_in_watch(Chardev *chr);
 
+void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context);
+
 int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
 
 int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len,
diff --git a/chardev/char.c b/chardev/char.c
index abd525f..5563375 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
     cc = CHARDEV_GET_CLASS(s);
     if (!opaque && !fd_can_read && !fd_read && !fd_event) {
         fe_open = 0;
-        remove_fd_in_watch(s);
+        qemu_remove_fd_in_watch(s, context);
     } else {
         fe_open = 1;
     }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v2 4/4] colo-compare: Fix removing fds been watched incorrectly in finalization
  2017-02-16  6:00 [Qemu-devel] [PATCH v2 0/4] colo-compare: fix some bugs zhanghailiang
                   ` (2 preceding siblings ...)
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers() zhanghailiang
@ 2017-02-16  6:00 ` zhanghailiang
  3 siblings, 0 replies; 9+ messages in thread
From: zhanghailiang @ 2017-02-16  6:00 UTC (permalink / raw)
  To: jasowang, zhangchen.fnst, lizhijian
  Cc: qemu-devel, xuquan8, pss.wulizhen, zhanghailiang

We will catch the bellow error report while try to delete compare object
by qmp command:
chardev/char-io.c:91: io_watch_poll_finalize: Assertion `iwp->src == ((void *)0)' failed.

This is caused by failing to remove the right fd been watched while
call qemu_chr_fe_set_handlers();

Fix it by pass the worker_context parameter to qemu_chr_fe_set_handlers().

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 net/colo-compare.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 37ce75c..a6fc2ff 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -84,6 +84,7 @@ typedef struct CompareState {
     /* compare thread, a thread for each NIC */
     QemuThread thread;
 
+    GMainContext *worker_context;
     GMainLoop *compare_loop;
 } CompareState;
 
@@ -497,30 +498,29 @@ static gboolean check_old_packet_regular(void *opaque)
 
 static void *colo_compare_thread(void *opaque)
 {
-    GMainContext *worker_context;
     CompareState *s = opaque;
     GSource *timeout_source;
 
-    worker_context = g_main_context_new();
+    s->worker_context = g_main_context_new();
 
     qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read,
-                             compare_pri_chr_in, NULL, s, worker_context, true);
+                          compare_pri_chr_in, NULL, s, s->worker_context, true);
     qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read,
-                             compare_sec_chr_in, NULL, s, worker_context, true);
+                          compare_sec_chr_in, NULL, s, s->worker_context, true);
 
-    s->compare_loop = g_main_loop_new(worker_context, FALSE);
+    s->compare_loop = g_main_loop_new(s->worker_context, FALSE);
 
     /* To kick any packets that the secondary doesn't match */
     timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS);
     g_source_set_callback(timeout_source,
                           (GSourceFunc)check_old_packet_regular, s, NULL);
-    g_source_attach(timeout_source, worker_context);
+    g_source_attach(timeout_source, s->worker_context);
 
     g_main_loop_run(s->compare_loop);
 
     g_source_unref(timeout_source);
     g_main_loop_unref(s->compare_loop);
-    g_main_context_unref(worker_context);
+    g_main_context_unref(s->worker_context);
     return NULL;
 }
 
@@ -717,8 +717,10 @@ static void colo_compare_finalize(Object *obj)
 {
     CompareState *s = COLO_COMPARE(obj);
 
-    qemu_chr_fe_deinit(&s->chr_pri_in);
-    qemu_chr_fe_deinit(&s->chr_sec_in);
+    qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL,
+                             s->worker_context, true);
+    qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL,
+                             s->worker_context, true);
     qemu_chr_fe_deinit(&s->chr_out);
 
     g_main_loop_quit(s->compare_loop);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers()
  2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers() zhanghailiang
@ 2017-02-16 10:40   ` Marc-André Lureau
  2017-02-16 12:49     ` Hailiang Zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Marc-André Lureau @ 2017-02-16 10:40 UTC (permalink / raw)
  To: zhanghailiang, jasowang, zhangchen.fnst, lizhijian
  Cc: xuquan8, qemu-devel, pss.wulizhen, Paolo Bonzini

Hi

On Thu, Feb 16, 2017 at 10:08 AM zhanghailiang <
zhang.zhanghailiang@huawei.com> wrote:

> We can call qemu_chr_fe_set_handlers() to add/remove fd been watched
> in 'context' which can be either default main context or other explicit
> context. But the original logic is not correct, we didn't remove
> the right fd because we call g_main_context_find_source_by_id(NULL, tag)
> which always try to find the Gsource from default context.
>
> Fix it by passing the right context to g_main_context_find_source_by_id().
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>  chardev/char-io.c | 13 +++++++++----
>  chardev/char-io.h |  2 ++
>  chardev/char.c    |  2 +-
>  3 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/chardev/char-io.c b/chardev/char-io.c
> index 7dfc3f2..a69cc61 100644
> --- a/chardev/char-io.c
> +++ b/chardev/char-io.c
> @@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr,
>      return tag;
>  }
>
> -static void io_remove_watch_poll(guint tag)
> +static void io_remove_watch_poll(guint tag, GMainContext *context)
>  {
>      GSource *source;
>      IOWatchPoll *iwp;
>
>      g_return_if_fail(tag > 0);
>
> -    source = g_main_context_find_source_by_id(NULL, tag);
> +    source = g_main_context_find_source_by_id(context, tag);
>      g_return_if_fail(source != NULL);
>
>      iwp = io_watch_poll_from_source(source);
> @@ -146,14 +146,19 @@ static void io_remove_watch_poll(guint tag)
>      g_source_destroy(&iwp->parent);
>  }
>
> -void remove_fd_in_watch(Chardev *chr)
> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context)
>  {
>      if (chr->fd_in_tag) {
> -        io_remove_watch_poll(chr->fd_in_tag);
> +        io_remove_watch_poll(chr->fd_in_tag, context);
>          chr->fd_in_tag = 0;
>      }
>  }
>
> +void remove_fd_in_watch(Chardev *chr)
> +{
> +    qemu_remove_fd_in_watch(chr, NULL);
> +}
> +
>

I would just change the signature of remove_fd_in_watch() instead of
introducing a function.

 int io_channel_send_full(QIOChannel *ioc,
>                           const void *buf, size_t len,
>                           int *fds, size_t nfds)
> diff --git a/chardev/char-io.h b/chardev/char-io.h
> index d7ae5f1..117c888 100644
> --- a/chardev/char-io.h
> +++ b/chardev/char-io.h
> @@ -38,6 +38,8 @@ guint io_add_watch_poll(Chardev *chr,
>
>  void remove_fd_in_watch(Chardev *chr);
>
> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context);
> +
>  int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
>
>  int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len,
> diff --git a/chardev/char.c b/chardev/char.c
> index abd525f..5563375 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
>      cc = CHARDEV_GET_CLASS(s);
>      if (!opaque && !fd_can_read && !fd_read && !fd_event) {
>          fe_open = 0;
> -        remove_fd_in_watch(s);
> +        qemu_remove_fd_in_watch(s, context);
>      } else {
>          fe_open = 1;
>      }
> --
> 1.8.3.1
>
>
>
otherwise, looks good to me

-- 
Marc-André Lureau

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers()
  2017-02-16 10:40   ` Marc-André Lureau
@ 2017-02-16 12:49     ` Hailiang Zhang
  2017-02-16 13:04       ` Marc-André Lureau
  0 siblings, 1 reply; 9+ messages in thread
From: Hailiang Zhang @ 2017-02-16 12:49 UTC (permalink / raw)
  To: Marc-André Lureau, jasowang, zhangchen.fnst, lizhijian
  Cc: xuquan8, qemu-devel, pss.wulizhen, Paolo Bonzini

Hi,

On 2017/2/16 18:40, Marc-André Lureau wrote:
> Hi
>
> On Thu, Feb 16, 2017 at 10:08 AM zhanghailiang <
> zhang.zhanghailiang@huawei.com> wrote:
>
>> We can call qemu_chr_fe_set_handlers() to add/remove fd been watched
>> in 'context' which can be either default main context or other explicit
>> context. But the original logic is not correct, we didn't remove
>> the right fd because we call g_main_context_find_source_by_id(NULL, tag)
>> which always try to find the Gsource from default context.
>>
>> Fix it by passing the right context to g_main_context_find_source_by_id().
>>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> ---
>>   chardev/char-io.c | 13 +++++++++----
>>   chardev/char-io.h |  2 ++
>>   chardev/char.c    |  2 +-
>>   3 files changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/chardev/char-io.c b/chardev/char-io.c
>> index 7dfc3f2..a69cc61 100644
>> --- a/chardev/char-io.c
>> +++ b/chardev/char-io.c
>> @@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr,
>>       return tag;
>>   }
>>
>> -static void io_remove_watch_poll(guint tag)
>> +static void io_remove_watch_poll(guint tag, GMainContext *context)
>>   {
>>       GSource *source;
>>       IOWatchPoll *iwp;
>>
>>       g_return_if_fail(tag > 0);
>>
>> -    source = g_main_context_find_source_by_id(NULL, tag);
>> +    source = g_main_context_find_source_by_id(context, tag);
>>       g_return_if_fail(source != NULL);
>>
>>       iwp = io_watch_poll_from_source(source);
>> @@ -146,14 +146,19 @@ static void io_remove_watch_poll(guint tag)
>>       g_source_destroy(&iwp->parent);
>>   }
>>
>> -void remove_fd_in_watch(Chardev *chr)
>> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context)
>>   {
>>       if (chr->fd_in_tag) {
>> -        io_remove_watch_poll(chr->fd_in_tag);
>> +        io_remove_watch_poll(chr->fd_in_tag, context);
>>           chr->fd_in_tag = 0;
>>       }
>>   }
>>
>> +void remove_fd_in_watch(Chardev *chr)
>> +{
>> +    qemu_remove_fd_in_watch(chr, NULL);
>> +}
>> +
>>
>
> I would just change the signature of remove_fd_in_watch() instead of
> introducing a function.
>

In that case, i have to modify all the places call this helper,
About eleven places in six files,is it acceptable ?

Thanks.

>   int io_channel_send_full(QIOChannel *ioc,
>>                            const void *buf, size_t len,
>>                            int *fds, size_t nfds)
>> diff --git a/chardev/char-io.h b/chardev/char-io.h
>> index d7ae5f1..117c888 100644
>> --- a/chardev/char-io.h
>> +++ b/chardev/char-io.h
>> @@ -38,6 +38,8 @@ guint io_add_watch_poll(Chardev *chr,
>>
>>   void remove_fd_in_watch(Chardev *chr);
>>
>> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context);
>> +
>>   int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
>>
>>   int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len,
>> diff --git a/chardev/char.c b/chardev/char.c
>> index abd525f..5563375 100644
>> --- a/chardev/char.c
>> +++ b/chardev/char.c
>> @@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
>>       cc = CHARDEV_GET_CLASS(s);
>>       if (!opaque && !fd_can_read && !fd_read && !fd_event) {
>>           fe_open = 0;
>> -        remove_fd_in_watch(s);
>> +        qemu_remove_fd_in_watch(s, context);
>>       } else {
>>           fe_open = 1;
>>       }
>> --
>> 1.8.3.1
>>
>>
>>
> otherwise, looks good to me
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers()
  2017-02-16 12:49     ` Hailiang Zhang
@ 2017-02-16 13:04       ` Marc-André Lureau
  2017-02-16 13:09         ` Hailiang Zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Marc-André Lureau @ 2017-02-16 13:04 UTC (permalink / raw)
  To: Hailiang Zhang, jasowang, zhangchen.fnst, lizhijian
  Cc: xuquan8, qemu-devel, pss.wulizhen, Paolo Bonzini

Hi

On Thu, Feb 16, 2017 at 4:49 PM Hailiang Zhang <
zhang.zhanghailiang@huawei.com> wrote:

> Hi,
>
> On 2017/2/16 18:40, Marc-André Lureau wrote:
> > Hi
> >
> > On Thu, Feb 16, 2017 at 10:08 AM zhanghailiang <
> > zhang.zhanghailiang@huawei.com> wrote:
> >
> >> We can call qemu_chr_fe_set_handlers() to add/remove fd been watched
> >> in 'context' which can be either default main context or other explicit
> >> context. But the original logic is not correct, we didn't remove
> >> the right fd because we call g_main_context_find_source_by_id(NULL, tag)
> >> which always try to find the Gsource from default context.
> >>
> >> Fix it by passing the right context to
> g_main_context_find_source_by_id().
> >>
> >> Cc: Paolo Bonzini <pbonzini@redhat.com>
> >> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> >> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> >> ---
> >>   chardev/char-io.c | 13 +++++++++----
> >>   chardev/char-io.h |  2 ++
> >>   chardev/char.c    |  2 +-
> >>   3 files changed, 12 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/chardev/char-io.c b/chardev/char-io.c
> >> index 7dfc3f2..a69cc61 100644
> >> --- a/chardev/char-io.c
> >> +++ b/chardev/char-io.c
> >> @@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr,
> >>       return tag;
> >>   }
> >>
> >> -static void io_remove_watch_poll(guint tag)
> >> +static void io_remove_watch_poll(guint tag, GMainContext *context)
> >>   {
> >>       GSource *source;
> >>       IOWatchPoll *iwp;
> >>
> >>       g_return_if_fail(tag > 0);
> >>
> >> -    source = g_main_context_find_source_by_id(NULL, tag);
> >> +    source = g_main_context_find_source_by_id(context, tag);
> >>       g_return_if_fail(source != NULL);
> >>
> >>       iwp = io_watch_poll_from_source(source);
> >> @@ -146,14 +146,19 @@ static void io_remove_watch_poll(guint tag)
> >>       g_source_destroy(&iwp->parent);
> >>   }
> >>
> >> -void remove_fd_in_watch(Chardev *chr)
> >> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context)
> >>   {
> >>       if (chr->fd_in_tag) {
> >> -        io_remove_watch_poll(chr->fd_in_tag);
> >> +        io_remove_watch_poll(chr->fd_in_tag, context);
> >>           chr->fd_in_tag = 0;
> >>       }
> >>   }
> >>
> >> +void remove_fd_in_watch(Chardev *chr)
> >> +{
> >> +    qemu_remove_fd_in_watch(chr, NULL);
> >> +}
> >> +
> >>
> >
> > I would just change the signature of remove_fd_in_watch() instead of
> > introducing a function.
> >
>
> In that case, i have to modify all the places call this helper,
> About eleven places in six files,is it acceptable ?
>

Yes, that's fine.

>
> Thanks.
>
> >   int io_channel_send_full(QIOChannel *ioc,
> >>                            const void *buf, size_t len,
> >>                            int *fds, size_t nfds)
> >> diff --git a/chardev/char-io.h b/chardev/char-io.h
> >> index d7ae5f1..117c888 100644
> >> --- a/chardev/char-io.h
> >> +++ b/chardev/char-io.h
> >> @@ -38,6 +38,8 @@ guint io_add_watch_poll(Chardev *chr,
> >>
> >>   void remove_fd_in_watch(Chardev *chr);
> >>
> >> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context);
> >> +
> >>   int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
> >>
> >>   int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len,
> >> diff --git a/chardev/char.c b/chardev/char.c
> >> index abd525f..5563375 100644
> >> --- a/chardev/char.c
> >> +++ b/chardev/char.c
> >> @@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
> >>       cc = CHARDEV_GET_CLASS(s);
> >>       if (!opaque && !fd_can_read && !fd_read && !fd_event) {
> >>           fe_open = 0;
> >> -        remove_fd_in_watch(s);
> >> +        qemu_remove_fd_in_watch(s, context);
> >>       } else {
> >>           fe_open = 1;
> >>       }
> >> --
> >> 1.8.3.1
> >>
> >>
> >>
> > otherwise, looks good to me
> >
>
> --
Marc-André Lureau

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers()
  2017-02-16 13:04       ` Marc-André Lureau
@ 2017-02-16 13:09         ` Hailiang Zhang
  0 siblings, 0 replies; 9+ messages in thread
From: Hailiang Zhang @ 2017-02-16 13:09 UTC (permalink / raw)
  To: Marc-André Lureau, jasowang, zhangchen.fnst, lizhijian
  Cc: xuquan8, qemu-devel, pss.wulizhen, Paolo Bonzini

On 2017/2/16 21:04, Marc-André Lureau wrote:
> Hi
>
> On Thu, Feb 16, 2017 at 4:49 PM Hailiang Zhang <
> zhang.zhanghailiang@huawei.com> wrote:
>
>> Hi,
>>
>> On 2017/2/16 18:40, Marc-André Lureau wrote:
>>> Hi
>>>
>>> On Thu, Feb 16, 2017 at 10:08 AM zhanghailiang <
>>> zhang.zhanghailiang@huawei.com> wrote:
>>>
>>>> We can call qemu_chr_fe_set_handlers() to add/remove fd been watched
>>>> in 'context' which can be either default main context or other explicit
>>>> context. But the original logic is not correct, we didn't remove
>>>> the right fd because we call g_main_context_find_source_by_id(NULL, tag)
>>>> which always try to find the Gsource from default context.
>>>>
>>>> Fix it by passing the right context to
>> g_main_context_find_source_by_id().
>>>>
>>>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>>>> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
>>>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>>>> ---
>>>>    chardev/char-io.c | 13 +++++++++----
>>>>    chardev/char-io.h |  2 ++
>>>>    chardev/char.c    |  2 +-
>>>>    3 files changed, 12 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/chardev/char-io.c b/chardev/char-io.c
>>>> index 7dfc3f2..a69cc61 100644
>>>> --- a/chardev/char-io.c
>>>> +++ b/chardev/char-io.c
>>>> @@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr,
>>>>        return tag;
>>>>    }
>>>>
>>>> -static void io_remove_watch_poll(guint tag)
>>>> +static void io_remove_watch_poll(guint tag, GMainContext *context)
>>>>    {
>>>>        GSource *source;
>>>>        IOWatchPoll *iwp;
>>>>
>>>>        g_return_if_fail(tag > 0);
>>>>
>>>> -    source = g_main_context_find_source_by_id(NULL, tag);
>>>> +    source = g_main_context_find_source_by_id(context, tag);
>>>>        g_return_if_fail(source != NULL);
>>>>
>>>>        iwp = io_watch_poll_from_source(source);
>>>> @@ -146,14 +146,19 @@ static void io_remove_watch_poll(guint tag)
>>>>        g_source_destroy(&iwp->parent);
>>>>    }
>>>>
>>>> -void remove_fd_in_watch(Chardev *chr)
>>>> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context)
>>>>    {
>>>>        if (chr->fd_in_tag) {
>>>> -        io_remove_watch_poll(chr->fd_in_tag);
>>>> +        io_remove_watch_poll(chr->fd_in_tag, context);
>>>>            chr->fd_in_tag = 0;
>>>>        }
>>>>    }
>>>>
>>>> +void remove_fd_in_watch(Chardev *chr)
>>>> +{
>>>> +    qemu_remove_fd_in_watch(chr, NULL);
>>>> +}
>>>> +
>>>>
>>>
>>> I would just change the signature of remove_fd_in_watch() instead of
>>> introducing a function.
>>>
>>
>> In that case, i have to modify all the places call this helper,
>> About eleven places in six files,is it acceptable ?
>>
>
> Yes, that's fine.
>

OK, will fix it in v3, thanks.

>>
>> Thanks.
>>
>>>    int io_channel_send_full(QIOChannel *ioc,
>>>>                             const void *buf, size_t len,
>>>>                             int *fds, size_t nfds)
>>>> diff --git a/chardev/char-io.h b/chardev/char-io.h
>>>> index d7ae5f1..117c888 100644
>>>> --- a/chardev/char-io.h
>>>> +++ b/chardev/char-io.h
>>>> @@ -38,6 +38,8 @@ guint io_add_watch_poll(Chardev *chr,
>>>>
>>>>    void remove_fd_in_watch(Chardev *chr);
>>>>
>>>> +void qemu_remove_fd_in_watch(Chardev *chr, GMainContext *context);
>>>> +
>>>>    int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
>>>>
>>>>    int io_channel_send_full(QIOChannel *ioc, const void *buf, size_t len,
>>>> diff --git a/chardev/char.c b/chardev/char.c
>>>> index abd525f..5563375 100644
>>>> --- a/chardev/char.c
>>>> +++ b/chardev/char.c
>>>> @@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
>>>>        cc = CHARDEV_GET_CLASS(s);
>>>>        if (!opaque && !fd_can_read && !fd_read && !fd_event) {
>>>>            fe_open = 0;
>>>> -        remove_fd_in_watch(s);
>>>> +        qemu_remove_fd_in_watch(s, context);
>>>>        } else {
>>>>            fe_open = 1;
>>>>        }
>>>> --
>>>> 1.8.3.1
>>>>
>>>>
>>>>
>>> otherwise, looks good to me
>>>
>>
>> --
> Marc-André Lureau
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-02-16 13:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-16  6:00 [Qemu-devel] [PATCH v2 0/4] colo-compare: fix some bugs zhanghailiang
2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 1/4] colo-compare: use g_timeout_source_new() to process the stale packets zhanghailiang
2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 2/4] colo-compare: kick compare thread to exit after some cleanup in finalization zhanghailiang
2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers() zhanghailiang
2017-02-16 10:40   ` Marc-André Lureau
2017-02-16 12:49     ` Hailiang Zhang
2017-02-16 13:04       ` Marc-André Lureau
2017-02-16 13:09         ` Hailiang Zhang
2017-02-16  6:00 ` [Qemu-devel] [PATCH v2 4/4] colo-compare: Fix removing fds been watched incorrectly in finalization zhanghailiang

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.