Received: from eggs.gnu.org ([2001:4830:134:3::10]:46972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byfc5-0004Ut-PH for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byfc4-0006bq-Km for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:48:29 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36065) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byfc4-0006bf-EF for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:48:28 -0400 Received: by mail-wm0-x243.google.com with SMTP id f193so9919042wmg.3 for ; Mon, 24 Oct 2016 06:48:28 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 24 Oct 2016 15:47:21 +0200 Message-Id: <1477316855-42218-37-git-send-email-pbonzini@redhat.com> In-Reply-To: <1477316855-42218-1-git-send-email-pbonzini@redhat.com> References: <1477316855-42218-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PULL 36/50] vhost-user: only initialize queue 0 CharBackend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau 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 Message-Id: <20161022095318.17775-18-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- 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); -- 1.8.3.1