diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-10-22 12:52:52 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-10-24 15:27:20 +0200 |
commit | 32a6ebecd2ffe82ffade5edf9e054e20cb48f281 (patch) | |
tree | b1e82e3f6eb4a28c65098015dd8114e190a064bf /net | |
parent | becdfa00cfa2995e859ccefa4b7d72a72eb96581 (diff) |
char: remaining switch to CharBackend in frontend
Similar to previous change, for the remaining CharDriverState front ends
users.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20161022095318.17775-13-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/colo-compare.c | 46 | ||||
-rw-r--r-- | net/filter-mirror.c | 58 | ||||
-rw-r--r-- | net/slirp.c | 23 | ||||
-rw-r--r-- | net/vhost-user.c | 27 |
4 files changed, 88 insertions, 66 deletions
diff --git a/net/colo-compare.c b/net/colo-compare.c index 47703c59bc..efcd15e9ae 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); diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 0ee58d905e..425e146e9e 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -38,8 +38,8 @@ typedef struct MirrorState { NetFilterState parent_obj; char *indev; char *outdev; - CharDriverState *chr_in; - CharDriverState *chr_out; + CharBackend chr_in; + CharBackend chr_out; SocketReadState rs; } MirrorState; @@ -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, NULL, NULL, NULL, NULL); + qemu_chr_add_handlers(s->chr_in.chr, 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, NULL, NULL, NULL, NULL); + qemu_chr_add_handlers(s->chr_in.chr, 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, iov, iovcnt); + ret = filter_mirror_send(s->chr_out.chr, 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) { - ret = filter_mirror_send(s->chr_out, iov, iovcnt); + if (s->chr_out.chr) { + ret = filter_mirror_send(s->chr_out.chr, iov, iovcnt); if (ret) { error_report("filter_mirror_send failed(%s)", strerror(-ret)); } @@ -175,8 +175,8 @@ static void filter_mirror_cleanup(NetFilterState *nf) { MirrorState *s = FILTER_MIRROR(nf); - if (s->chr_out) { - qemu_chr_fe_release(s->chr_out); + if (s->chr_out.chr) { + qemu_chr_fe_release(s->chr_out.chr); } } @@ -184,18 +184,19 @@ static void filter_redirector_cleanup(NetFilterState *nf) { MirrorState *s = FILTER_REDIRECTOR(nf); - if (s->chr_in) { - qemu_chr_add_handlers(s->chr_in, NULL, NULL, NULL, NULL); - qemu_chr_fe_release(s->chr_in); + if (s->chr_in.chr) { + qemu_chr_add_handlers(s->chr_in.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_release(s->chr_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); } } static void filter_mirror_setup(NetFilterState *nf, Error **errp) { MirrorState *s = FILTER_MIRROR(nf); + CharDriverState *chr; if (!s->outdev) { error_setg(errp, "filter mirror needs 'outdev' " @@ -203,17 +204,19 @@ static void filter_mirror_setup(NetFilterState *nf, Error **errp) return; } - s->chr_out = qemu_chr_find(s->outdev); - if (s->chr_out == NULL) { + chr = qemu_chr_find(s->outdev); + if (chr == NULL) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", s->outdev); return; } - if (qemu_chr_fe_claim(s->chr_out) != 0) { + if (qemu_chr_fe_claim(chr) != 0) { error_setg(errp, QERR_DEVICE_IN_USE, s->outdev); return; } + + qemu_chr_fe_init(&s->chr_out, chr, errp); } static void redirector_rs_finalize(SocketReadState *rs) @@ -227,6 +230,7 @@ static void redirector_rs_finalize(SocketReadState *rs) static void filter_redirector_setup(NetFilterState *nf, Error **errp) { MirrorState *s = FILTER_REDIRECTOR(nf); + CharDriverState *chr; if (!s->indev && !s->outdev) { error_setg(errp, "filter redirector needs 'indev' or " @@ -243,26 +247,32 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) net_socket_rs_init(&s->rs, redirector_rs_finalize); if (s->indev) { - s->chr_in = qemu_chr_find(s->indev); - if (s->chr_in == NULL) { + chr = qemu_chr_find(s->indev); + if (chr == NULL) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "IN Device '%s' not found", s->indev); return; } - qemu_chr_fe_claim_no_fail(s->chr_in); - qemu_chr_add_handlers(s->chr_in, redirector_chr_can_read, + qemu_chr_fe_claim_no_fail(chr); + 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); } if (s->outdev) { - s->chr_out = qemu_chr_find(s->outdev); - if (s->chr_out == NULL) { + chr = qemu_chr_find(s->outdev); + if (chr == NULL) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "OUT Device '%s' not found", s->outdev); return; } - qemu_chr_fe_claim_no_fail(s->chr_out); + qemu_chr_fe_claim_no_fail(chr); + if (!qemu_chr_fe_init(&s->chr_out, chr, errp)) { + return; + } } } diff --git a/net/slirp.c b/net/slirp.c index f9fdff5fb9..407e8aa704 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -40,6 +40,7 @@ #include "sysemu/char.h" #include "sysemu/sysemu.h" #include "qemu/cutils.h" +#include "qapi/error.h" static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) { @@ -682,7 +683,7 @@ int net_slirp_smb(const char *exported_dir) #endif /* !defined(_WIN32) */ struct GuestFwd { - CharDriverState *hd; + CharBackend hd; struct in_addr server; int port; Slirp *slirp; @@ -746,15 +747,23 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, return -1; } } else { - fwd = g_new(struct GuestFwd, 1); - fwd->hd = qemu_chr_new(buf, p); - if (!fwd->hd) { + Error *err = NULL; + CharDriverState *chr = qemu_chr_new(buf, p); + + if (!chr) { error_report("could not open guest forwarding device '%s'", buf); + return -1; + } + + fwd = g_new(struct GuestFwd, 1); + qemu_chr_fe_init(&fwd->hd, chr, &err); + if (err) { + error_report_err(err); g_free(fwd); return -1; } - if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) { + if (slirp_add_exec(s->slirp, 3, fwd->hd.chr, &server, port) < 0) { error_report("conflicting/invalid host:port in guest forwarding " "rule '%s'", config_str); g_free(fwd); @@ -764,8 +773,8 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, fwd->port = port; fwd->slirp = s->slirp; - qemu_chr_fe_claim_no_fail(fwd->hd); - qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read, + qemu_chr_fe_claim_no_fail(fwd->hd.chr); + qemu_chr_add_handlers(fwd->hd.chr, guestfwd_can_read, guestfwd_read, NULL, fwd); } return 0; diff --git a/net/vhost-user.c b/net/vhost-user.c index 5b94c84541..957459f493 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -20,7 +20,7 @@ typedef struct VhostUserState { NetClientState nc; - CharDriverState *chr; + CharBackend chr; VHostNetState *vhost_net; guint watch; uint64_t acked_features; @@ -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; + options.opaque = s->chr.chr; options.busyloop_timeout = 0; net = vhost_net_init(&options); if (!net) { @@ -150,10 +150,10 @@ static void vhost_user_cleanup(NetClientState *nc) g_free(s->vhost_net); s->vhost_net = NULL; } - if (s->chr) { - qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, NULL); - qemu_chr_fe_release(s->chr); - s->chr = NULL; + if (s->chr.chr) { + qemu_chr_add_handlers(s->chr.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_release(s->chr.chr); + s->chr.chr = NULL; } qemu_purge_queued_packets(nc); @@ -187,7 +187,7 @@ static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond, { VhostUserState *s = opaque; - qemu_chr_disconnect(s->chr); + qemu_chr_disconnect(s->chr.chr); return FALSE; } @@ -206,13 +206,13 @@ 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->label, event); + trace_vhost_user_event(s->chr.chr->label, event); switch (event) { case CHR_EVENT_OPENED: - s->watch = qemu_chr_fe_add_watch(s->chr, G_IO_HUP, + s->watch = qemu_chr_fe_add_watch(s->chr.chr, G_IO_HUP, net_vhost_user_watch, s); if (vhost_user_start(queues, ncs) < 0) { - qemu_chr_disconnect(s->chr); + qemu_chr_disconnect(s->chr.chr); return; } qmp_set_link(name, true, &err); @@ -235,6 +235,7 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, const char *name, CharDriverState *chr, int queues) { + Error *err = NULL; NetClientState *nc, *nc0 = NULL; VhostUserState *s; int i; @@ -254,12 +255,14 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, nc->queue_index = i; s = DO_UPCAST(VhostUserState, nc, nc); - s->chr = chr; + if (!qemu_chr_fe_init(&s->chr, chr, &err)) { + error_report_err(err); + return -1; + } } s = DO_UPCAST(VhostUserState, nc, nc0); do { - Error *err = NULL; if (qemu_chr_wait_connected(chr, &err) < 0) { error_report_err(err); return -1; |