[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/38] vhost-user: only initialize queue 0 CharBacke
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH 17/38] vhost-user: only initialize queue 0 CharBackend |
Date: |
Sat, 22 Oct 2016 12:52:57 +0300 |
All the queues share the same chardev. Initialize only the first queue
CharBackend, and pass it to other queues. This will allow to claim the
chardev only once in a later change.
Signed-off-by: Marc-André Lureau <address@hidden>
---
net/vhost-user.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 8b7e98d..357b500 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -20,7 +20,7 @@
typedef struct VhostUserState {
NetClientState nc;
- CharBackend chr;
+ CharBackend chr; /* only queue index 0 */
VHostNetState *vhost_net;
guint watch;
uint64_t acked_features;
@@ -62,7 +62,7 @@ static void vhost_user_stop(int queues, NetClientState *ncs[])
}
}
-static int vhost_user_start(int queues, NetClientState *ncs[])
+static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
{
VhostNetOptions options;
struct vhost_net *net = NULL;
@@ -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 = be;
options.busyloop_timeout = 0;
net = vhost_net_init(&options);
if (!net) {
@@ -150,7 +150,7 @@ static void vhost_user_cleanup(NetClientState *nc)
g_free(s->vhost_net);
s->vhost_net = NULL;
}
- if (s->chr.chr) {
+ if (nc->queue_index == 0 && s->chr.chr) {
qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, NULL, NULL);
qemu_chr_fe_release(s->chr.chr);
s->chr.chr = NULL;
@@ -213,7 +213,7 @@ static void net_vhost_user_event(void *opaque, int event)
case CHR_EVENT_OPENED:
s->watch = qemu_chr_fe_add_watch(&s->chr, G_IO_HUP,
net_vhost_user_watch, s);
- if (vhost_user_start(queues, ncs) < 0) {
+ if (vhost_user_start(queues, ncs, &s->chr) < 0) {
qemu_chr_fe_disconnect(&s->chr);
return;
}
@@ -247,21 +247,18 @@ static int net_vhost_user_init(NetClientState *peer,
const char *device,
for (i = 0; i < queues; i++) {
nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
- if (!nc0) {
- nc0 = nc;
- }
-
snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
i, chr->label);
-
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;
+ if (!nc0) {
+ nc0 = nc;
+ s = DO_UPCAST(VhostUserState, nc, nc);
+ if (!qemu_chr_fe_init(&s->chr, chr, &err)) {
+ error_report_err(err);
+ return -1;
+ }
}
+
}
s = DO_UPCAST(VhostUserState, nc, nc0);
--
2.10.0
- [Qemu-devel] [PATCH 08/38] mux: split mux_chr_update_read_handler(), (continued)
- [Qemu-devel] [PATCH 08/38] mux: split mux_chr_update_read_handler(), Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 10/38] char: start converting mux driver to use CharBackend, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 09/38] char: introduce CharBackend, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 11/38] char: replace PROP_CHR with CharBackend, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 14/38] colo: claim in find_and_check_chardev, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 12/38] char: remaining switch to CharBackend in frontend, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 13/38] char: rename some frontend functions, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 16/38] char: fold qemu_chr_set_handlers in qemu_chr_fe_set_handlers, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 17/38] vhost-user: only initialize queue 0 CharBackend,
Marc-André Lureau <=
- [Qemu-devel] [PATCH 15/38] char: use qemu_chr_fe* functions with CharBackend argument, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 18/38] char: replace qemu_chr_claim/release with qemu_chr_fe_init/deinit, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 19/38] char: make some qemu_chr_fe skip if no driver, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 20/38] tests: start chardev unit tests, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 21/38] char: move front end handlers in CharBackend, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 22/38] char: rename chr_close/chr_free, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 23/38] char: remove explicit_fe_open, use a set_handlers argument, Marc-André Lureau, 2016/10/22
- [Qemu-devel] [PATCH 24/38] char: move fe_open in CharBackend, Marc-André Lureau, 2016/10/22