diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/colo-compare.c | 34 | ||||
-rw-r--r-- | net/filter-mirror.c | 20 | ||||
-rw-r--r-- | net/slirp.c | 7 | ||||
-rw-r--r-- | net/vhost-user.c | 21 |
4 files changed, 46 insertions, 36 deletions
diff --git a/net/colo-compare.c b/net/colo-compare.c index b11546520b..63d92cb9da 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) { diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 425e146e9e..12d79cd987 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -43,7 +43,7 @@ typedef struct MirrorState { SocketReadState rs; } MirrorState; -static int filter_mirror_send(CharDriverState *chr_out, +static int filter_mirror_send(CharBackend *chr_out, const struct iovec *iov, int iovcnt) { @@ -110,7 +110,7 @@ static void redirector_chr_read(void *opaque, const uint8_t *buf, int size) ret = net_fill_rstate(&s->rs, buf, size); if (ret == -1) { - qemu_chr_add_handlers(s->chr_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, NULL, NULL); } } @@ -121,7 +121,7 @@ static void redirector_chr_event(void *opaque, int event) switch (event) { case CHR_EVENT_CLOSED: - qemu_chr_add_handlers(s->chr_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, NULL, NULL); break; default: break; @@ -138,7 +138,7 @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf, MirrorState *s = FILTER_MIRROR(nf); int ret; - ret = filter_mirror_send(s->chr_out.chr, iov, iovcnt); + ret = filter_mirror_send(&s->chr_out, iov, iovcnt); if (ret) { error_report("filter_mirror_send failed(%s)", strerror(-ret)); } @@ -160,8 +160,8 @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf, MirrorState *s = FILTER_REDIRECTOR(nf); int ret; - if (s->chr_out.chr) { - ret = filter_mirror_send(s->chr_out.chr, iov, iovcnt); + if (qemu_chr_fe_get_driver(&s->chr_out)) { + ret = filter_mirror_send(&s->chr_out, iov, iovcnt); if (ret) { error_report("filter_mirror_send failed(%s)", strerror(-ret)); } @@ -185,7 +185,7 @@ static void filter_redirector_cleanup(NetFilterState *nf) MirrorState *s = FILTER_REDIRECTOR(nf); if (s->chr_in.chr) { - qemu_chr_add_handlers(s->chr_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, NULL, NULL); qemu_chr_fe_release(s->chr_in.chr); } if (s->chr_out.chr) { @@ -258,8 +258,10 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) if (!qemu_chr_fe_init(&s->chr_in, chr, errp)) { return; } - qemu_chr_add_handlers(s->chr_in.chr, redirector_chr_can_read, - redirector_chr_read, redirector_chr_event, nf); + + qemu_chr_fe_set_handlers(&s->chr_in, redirector_chr_can_read, + redirector_chr_read, redirector_chr_event, + nf, NULL); } if (s->outdev) { diff --git a/net/slirp.c b/net/slirp.c index 407e8aa704..f9f6fc6b0b 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -763,7 +763,8 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, return -1; } - if (slirp_add_exec(s->slirp, 3, fwd->hd.chr, &server, port) < 0) { + if (slirp_add_exec(s->slirp, 3, qemu_chr_fe_get_driver(&fwd->hd), + &server, port) < 0) { error_report("conflicting/invalid host:port in guest forwarding " "rule '%s'", config_str); g_free(fwd); @@ -774,8 +775,8 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, fwd->slirp = s->slirp; qemu_chr_fe_claim_no_fail(fwd->hd.chr); - qemu_chr_add_handlers(fwd->hd.chr, guestfwd_can_read, guestfwd_read, - NULL, fwd); + qemu_chr_fe_set_handlers(&fwd->hd, guestfwd_can_read, guestfwd_read, + NULL, fwd, NULL); } return 0; diff --git a/net/vhost-user.c b/net/vhost-user.c index 45782470e8..8b7e98d5b9 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -78,7 +78,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[]) s = DO_UPCAST(VhostUserState, nc, ncs[i]); options.net_backend = ncs[i]; - options.opaque = s->chr.chr; + options.opaque = &s->chr; options.busyloop_timeout = 0; net = vhost_net_init(&options); if (!net) { @@ -151,7 +151,7 @@ static void vhost_user_cleanup(NetClientState *nc) s->vhost_net = NULL; } if (s->chr.chr) { - qemu_chr_add_handlers(s->chr.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, NULL, NULL); qemu_chr_fe_release(s->chr.chr); s->chr.chr = NULL; } @@ -187,7 +187,7 @@ static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond, { VhostUserState *s = opaque; - qemu_chr_fe_disconnect(s->chr.chr); + qemu_chr_fe_disconnect(&s->chr); return FALSE; } @@ -197,6 +197,7 @@ static void net_vhost_user_event(void *opaque, int event) const char *name = opaque; NetClientState *ncs[MAX_QUEUE_NUM]; VhostUserState *s; + CharDriverState *chr; Error *err = NULL; int queues; @@ -206,13 +207,14 @@ static void net_vhost_user_event(void *opaque, int event) assert(queues < MAX_QUEUE_NUM); s = DO_UPCAST(VhostUserState, nc, ncs[0]); - trace_vhost_user_event(s->chr.chr->label, event); + chr = qemu_chr_fe_get_driver(&s->chr); + trace_vhost_user_event(chr->label, event); switch (event) { case CHR_EVENT_OPENED: - s->watch = qemu_chr_fe_add_watch(s->chr.chr, G_IO_HUP, + s->watch = qemu_chr_fe_add_watch(&s->chr, G_IO_HUP, net_vhost_user_watch, s); if (vhost_user_start(queues, ncs) < 0) { - qemu_chr_fe_disconnect(s->chr.chr); + qemu_chr_fe_disconnect(&s->chr); return; } qmp_set_link(name, true, &err); @@ -255,6 +257,7 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, nc->queue_index = i; s = DO_UPCAST(VhostUserState, nc, nc); + if (!qemu_chr_fe_init(&s->chr, chr, &err)) { error_report_err(err); return -1; @@ -263,12 +266,12 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, s = DO_UPCAST(VhostUserState, nc, nc0); do { - if (qemu_chr_wait_connected(chr, &err) < 0) { + if (qemu_chr_fe_wait_connected(&s->chr, &err) < 0) { error_report_err(err); return -1; } - qemu_chr_add_handlers(chr, NULL, NULL, - net_vhost_user_event, nc0->name); + qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, + net_vhost_user_event, nc0->name, NULL); } while (!s->started); assert(s->vhost_net); |