From 32a6ebecd2ffe82ffade5edf9e054e20cb48f281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sat, 22 Oct 2016 12:52:52 +0300 Subject: char: remaining switch to CharBackend in frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to previous change, for the remaining CharDriverState front ends users. Signed-off-by: Marc-André Lureau Message-Id: <20161022095318.17775-13-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- net/colo-compare.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'net/colo-compare.c') diff --git a/net/colo-compare.c b/net/colo-compare.c index 47703c5..efcd15e 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -68,9 +68,9 @@ typedef struct CompareState { char *pri_indev; char *sec_indev; char *outdev; - CharDriverState *chr_pri_in; - CharDriverState *chr_sec_in; - CharDriverState *chr_out; + CharBackend chr_pri_in; + CharBackend chr_sec_in; + CharBackend chr_out; SocketReadState pri_rs; SocketReadState sec_rs; @@ -385,7 +385,7 @@ static void colo_compare_connection(void *opaque, void *user_data) } if (result) { - ret = compare_chr_send(s->chr_out, pkt->data, pkt->size); + ret = compare_chr_send(s->chr_out.chr, pkt->data, pkt->size); if (ret < 0) { error_report("colo_send_primary_packet failed"); } @@ -451,7 +451,7 @@ static void compare_pri_chr_in(void *opaque, const uint8_t *buf, int size) ret = net_fill_rstate(&s->pri_rs, buf, size); if (ret == -1) { - qemu_chr_add_handlers(s->chr_pri_in, NULL, NULL, NULL, NULL); + qemu_chr_add_handlers(s->chr_pri_in.chr, NULL, NULL, NULL, NULL); error_report("colo-compare primary_in error"); } } @@ -467,7 +467,7 @@ static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size) ret = net_fill_rstate(&s->sec_rs, buf, size); if (ret == -1) { - qemu_chr_add_handlers(s->chr_sec_in, NULL, NULL, NULL, NULL); + qemu_chr_add_handlers(s->chr_sec_in.chr, NULL, NULL, NULL, NULL); error_report("colo-compare secondary_in error"); } } @@ -480,9 +480,9 @@ static void *colo_compare_thread(void *opaque) worker_context = g_main_context_new(); - qemu_chr_add_handlers_full(s->chr_pri_in, compare_chr_can_read, + qemu_chr_add_handlers_full(s->chr_pri_in.chr, compare_chr_can_read, compare_pri_chr_in, NULL, s, worker_context); - qemu_chr_add_handlers_full(s->chr_sec_in, compare_chr_can_read, + qemu_chr_add_handlers_full(s->chr_sec_in.chr, compare_chr_can_read, compare_sec_chr_in, NULL, s, worker_context); compare_loop = g_main_loop_new(worker_context, FALSE); @@ -545,7 +545,7 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) if (packet_enqueue(s, PRIMARY_IN)) { trace_colo_compare_main("primary: unsupported packet in"); - compare_chr_send(s->chr_out, pri_rs->buf, pri_rs->packet_len); + compare_chr_send(s->chr_out.chr, pri_rs->buf, pri_rs->packet_len); } else { /* compare connection */ g_queue_foreach(&s->conn_list, colo_compare_connection, s); @@ -634,23 +634,23 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } - if (find_and_check_chardev(&s->chr_pri_in, s->pri_indev, errp)) { + if (find_and_check_chardev(&s->chr_pri_in.chr, s->pri_indev, errp)) { return; } - if (find_and_check_chardev(&s->chr_sec_in, s->sec_indev, errp)) { + if (find_and_check_chardev(&s->chr_sec_in.chr, s->sec_indev, errp)) { return; } - if (find_and_check_chardev(&s->chr_out, s->outdev, errp)) { + if (find_and_check_chardev(&s->chr_out.chr, s->outdev, errp)) { return; } - qemu_chr_fe_claim_no_fail(s->chr_pri_in); + qemu_chr_fe_claim_no_fail(s->chr_pri_in.chr); - qemu_chr_fe_claim_no_fail(s->chr_sec_in); + qemu_chr_fe_claim_no_fail(s->chr_sec_in.chr); - qemu_chr_fe_claim_no_fail(s->chr_out); + qemu_chr_fe_claim_no_fail(s->chr_out.chr); net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize); net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); @@ -702,16 +702,16 @@ static void colo_compare_finalize(Object *obj) { CompareState *s = COLO_COMPARE(obj); - if (s->chr_pri_in) { - qemu_chr_add_handlers(s->chr_pri_in, NULL, NULL, NULL, NULL); - qemu_chr_fe_release(s->chr_pri_in); + if (s->chr_pri_in.chr) { + qemu_chr_add_handlers(s->chr_pri_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_release(s->chr_pri_in.chr); } - if (s->chr_sec_in) { - qemu_chr_add_handlers(s->chr_sec_in, NULL, NULL, NULL, NULL); - qemu_chr_fe_release(s->chr_sec_in); + if (s->chr_sec_in.chr) { + qemu_chr_add_handlers(s->chr_sec_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_release(s->chr_sec_in.chr); } - if (s->chr_out) { - qemu_chr_fe_release(s->chr_out); + if (s->chr_out.chr) { + qemu_chr_fe_release(s->chr_out.chr); } g_queue_free(&s->conn_list); -- cgit v1.1 From fbf3cc3a67a7131e258764aa1f19d5324e9e9f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sat, 22 Oct 2016 12:52:54 +0300 Subject: colo: claim in find_and_check_chardev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This factors out claiming of chardev, and changes the call to non-fatal to return an error like the rest of the chardev checks. Signed-off-by: Marc-André Lureau Message-Id: <20161022095318.17775-15-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- net/colo-compare.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'net/colo-compare.c') diff --git a/net/colo-compare.c b/net/colo-compare.c index efcd15e..b115465 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -589,6 +589,13 @@ static int find_and_check_chardev(CharDriverState **chr, chr_name); return 1; } + + if (qemu_chr_fe_claim(*chr) < 0) { + error_setg(errp, "chardev \"%s\" cannot be claimed", + chr_name); + return 1; + } + return 0; } @@ -646,12 +653,6 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } - qemu_chr_fe_claim_no_fail(s->chr_pri_in.chr); - - qemu_chr_fe_claim_no_fail(s->chr_sec_in.chr); - - qemu_chr_fe_claim_no_fail(s->chr_out.chr); - net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize); net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); -- cgit v1.1 From 5345fdb4467816c44f6752b3a1f4e73aa25919f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sat, 22 Oct 2016 12:52:55 +0300 Subject: char: use qemu_chr_fe* functions with CharBackend argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also switches from qemu_chr_add_handlers() to qemu_chr_fe_set_handlers(). Note that qemu_chr_fe_set_handlers() now takes the focus when fe_open (qemu_chr_add_handlers() did take the focus) Signed-off-by: Marc-André Lureau Message-Id: <20161022095318.17775-16-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- net/colo-compare.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'net/colo-compare.c') diff --git a/net/colo-compare.c b/net/colo-compare.c index b115465..63d92cb 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -101,7 +101,7 @@ enum { SECONDARY_IN, }; -static int compare_chr_send(CharDriverState *out, +static int compare_chr_send(CharBackend *out, const uint8_t *buf, uint32_t size); @@ -385,7 +385,7 @@ static void colo_compare_connection(void *opaque, void *user_data) } if (result) { - ret = compare_chr_send(s->chr_out.chr, pkt->data, pkt->size); + ret = compare_chr_send(&s->chr_out, pkt->data, pkt->size); if (ret < 0) { error_report("colo_send_primary_packet failed"); } @@ -408,7 +408,7 @@ static void colo_compare_connection(void *opaque, void *user_data) } } -static int compare_chr_send(CharDriverState *out, +static int compare_chr_send(CharBackend *out, const uint8_t *buf, uint32_t size) { @@ -451,7 +451,7 @@ static void compare_pri_chr_in(void *opaque, const uint8_t *buf, int size) ret = net_fill_rstate(&s->pri_rs, buf, size); if (ret == -1) { - qemu_chr_add_handlers(s->chr_pri_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, NULL); error_report("colo-compare primary_in error"); } } @@ -467,7 +467,7 @@ static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size) ret = net_fill_rstate(&s->sec_rs, buf, size); if (ret == -1) { - qemu_chr_add_handlers(s->chr_sec_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, NULL); error_report("colo-compare secondary_in error"); } } @@ -480,10 +480,10 @@ static void *colo_compare_thread(void *opaque) worker_context = g_main_context_new(); - qemu_chr_add_handlers_full(s->chr_pri_in.chr, compare_chr_can_read, - compare_pri_chr_in, NULL, s, worker_context); - qemu_chr_add_handlers_full(s->chr_sec_in.chr, compare_chr_can_read, - compare_sec_chr_in, NULL, s, worker_context); + qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, + compare_pri_chr_in, NULL, s, worker_context); + qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read, + compare_sec_chr_in, NULL, s, worker_context); compare_loop = g_main_loop_new(worker_context, FALSE); @@ -545,7 +545,7 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) if (packet_enqueue(s, PRIMARY_IN)) { trace_colo_compare_main("primary: unsupported packet in"); - compare_chr_send(s->chr_out.chr, pri_rs->buf, pri_rs->packet_len); + compare_chr_send(&s->chr_out, pri_rs->buf, pri_rs->packet_len); } else { /* compare connection */ g_queue_foreach(&s->conn_list, colo_compare_connection, s); @@ -626,6 +626,7 @@ static void check_old_packet_regular(void *opaque) static void colo_compare_complete(UserCreatable *uc, Error **errp) { CompareState *s = COLO_COMPARE(uc); + CharDriverState *chr; char thread_name[64]; static int compare_id; @@ -641,15 +642,18 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } - if (find_and_check_chardev(&s->chr_pri_in.chr, s->pri_indev, errp)) { + if (find_and_check_chardev(&chr, s->pri_indev, errp) || + !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) { return; } - if (find_and_check_chardev(&s->chr_sec_in.chr, s->sec_indev, errp)) { + if (find_and_check_chardev(&chr, s->sec_indev, errp) || + !qemu_chr_fe_init(&s->chr_sec_in, chr, errp)) { return; } - if (find_and_check_chardev(&s->chr_out.chr, s->outdev, errp)) { + if (find_and_check_chardev(&chr, s->outdev, errp) || + !qemu_chr_fe_init(&s->chr_out, chr, errp)) { return; } @@ -704,11 +708,11 @@ static void colo_compare_finalize(Object *obj) CompareState *s = COLO_COMPARE(obj); if (s->chr_pri_in.chr) { - qemu_chr_add_handlers(s->chr_pri_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, NULL); qemu_chr_fe_release(s->chr_pri_in.chr); } if (s->chr_sec_in.chr) { - qemu_chr_add_handlers(s->chr_sec_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, NULL); qemu_chr_fe_release(s->chr_sec_in.chr); } if (s->chr_out.chr) { -- cgit v1.1 From c39860e6dc90f6ee2e82ee078f978c5d7f3df86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sat, 22 Oct 2016 12:52:58 +0300 Subject: char: replace qemu_chr_claim/release with qemu_chr_fe_init/deinit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that all front end use qemu_chr_fe_init(), we can move chardev claiming in init(), and add a function deinit() to release the chardev and cleanup handlers. The qemu_chr_fe_claim_no_fail() for property are gone, since the property will raise an error instead. In other cases, where there is already an error path, an error is raised instead. Finally, other cases are handled by &error_abort in qemu_chr_fe_init(). Signed-off-by: Marc-André Lureau Message-Id: <20161022095318.17775-19-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- net/colo-compare.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'net/colo-compare.c') diff --git a/net/colo-compare.c b/net/colo-compare.c index 63d92cb..3083681 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -590,12 +590,6 @@ static int find_and_check_chardev(CharDriverState **chr, return 1; } - if (qemu_chr_fe_claim(*chr) < 0) { - error_setg(errp, "chardev \"%s\" cannot be claimed", - chr_name); - return 1; - } - return 0; } @@ -707,17 +701,9 @@ static void colo_compare_finalize(Object *obj) { CompareState *s = COLO_COMPARE(obj); - if (s->chr_pri_in.chr) { - qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, NULL); - qemu_chr_fe_release(s->chr_pri_in.chr); - } - if (s->chr_sec_in.chr) { - qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, NULL); - qemu_chr_fe_release(s->chr_sec_in.chr); - } - if (s->chr_out.chr) { - qemu_chr_fe_release(s->chr_out.chr); - } + qemu_chr_fe_deinit(&s->chr_pri_in); + qemu_chr_fe_deinit(&s->chr_sec_in); + qemu_chr_fe_deinit(&s->chr_out); g_queue_free(&s->conn_list); -- cgit v1.1 From 39ab61c6d0757ed95badc9315857effdb64e4aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sat, 22 Oct 2016 12:53:03 +0300 Subject: char: remove explicit_fe_open, use a set_handlers argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to keep explicit_fe_open around if it affects only a qemu_chr_fe_set_handlers(). Use an additional argument instead. Signed-off-by: Marc-André Lureau Message-Id: <20161022095318.17775-24-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- net/colo-compare.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'net/colo-compare.c') diff --git a/net/colo-compare.c b/net/colo-compare.c index 3083681..109990f 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -451,7 +451,8 @@ static void compare_pri_chr_in(void *opaque, const uint8_t *buf, int size) ret = net_fill_rstate(&s->pri_rs, buf, size); if (ret == -1) { - qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, + NULL, NULL, true); error_report("colo-compare primary_in error"); } } @@ -467,7 +468,8 @@ static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size) ret = net_fill_rstate(&s->sec_rs, buf, size); if (ret == -1) { - qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, + NULL, NULL, true); error_report("colo-compare secondary_in error"); } } @@ -481,9 +483,9 @@ static void *colo_compare_thread(void *opaque) 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); + compare_pri_chr_in, NULL, 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); + compare_sec_chr_in, NULL, s, worker_context, true); compare_loop = g_main_loop_new(worker_context, FALSE); -- cgit v1.1