mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 19:14:58 -06:00
vhost-user: only initialize queue 0 CharBackend
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 <marcandre.lureau@redhat.com> Message-Id: <20161022095318.17775-18-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
386f07d1fc
commit
5d300164d0
1 changed files with 13 additions and 16 deletions
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
typedef struct VhostUserState {
|
typedef struct VhostUserState {
|
||||||
NetClientState nc;
|
NetClientState nc;
|
||||||
CharBackend chr;
|
CharBackend chr; /* only queue index 0 */
|
||||||
VHostNetState *vhost_net;
|
VHostNetState *vhost_net;
|
||||||
guint watch;
|
guint watch;
|
||||||
uint64_t acked_features;
|
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;
|
VhostNetOptions options;
|
||||||
struct vhost_net *net = NULL;
|
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]);
|
s = DO_UPCAST(VhostUserState, nc, ncs[i]);
|
||||||
|
|
||||||
options.net_backend = ncs[i];
|
options.net_backend = ncs[i];
|
||||||
options.opaque = &s->chr;
|
options.opaque = be;
|
||||||
options.busyloop_timeout = 0;
|
options.busyloop_timeout = 0;
|
||||||
net = vhost_net_init(&options);
|
net = vhost_net_init(&options);
|
||||||
if (!net) {
|
if (!net) {
|
||||||
|
@ -150,7 +150,7 @@ static void vhost_user_cleanup(NetClientState *nc)
|
||||||
g_free(s->vhost_net);
|
g_free(s->vhost_net);
|
||||||
s->vhost_net = NULL;
|
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_set_handlers(&s->chr, NULL, NULL, NULL, NULL, NULL);
|
||||||
qemu_chr_fe_release(s->chr.chr);
|
qemu_chr_fe_release(s->chr.chr);
|
||||||
s->chr.chr = NULL;
|
s->chr.chr = NULL;
|
||||||
|
@ -213,7 +213,7 @@ static void net_vhost_user_event(void *opaque, int event)
|
||||||
case CHR_EVENT_OPENED:
|
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, G_IO_HUP,
|
||||||
net_vhost_user_watch, s);
|
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);
|
qemu_chr_fe_disconnect(&s->chr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -247,21 +247,18 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
|
||||||
|
|
||||||
for (i = 0; i < queues; i++) {
|
for (i = 0; i < queues; i++) {
|
||||||
nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
|
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",
|
snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
|
||||||
i, chr->label);
|
i, chr->label);
|
||||||
|
|
||||||
nc->queue_index = i;
|
nc->queue_index = i;
|
||||||
|
if (!nc0) {
|
||||||
s = DO_UPCAST(VhostUserState, nc, nc);
|
nc0 = nc;
|
||||||
|
s = DO_UPCAST(VhostUserState, nc, nc);
|
||||||
if (!qemu_chr_fe_init(&s->chr, chr, &err)) {
|
if (!qemu_chr_fe_init(&s->chr, chr, &err)) {
|
||||||
error_report_err(err);
|
error_report_err(err);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s = DO_UPCAST(VhostUserState, nc, nc0);
|
s = DO_UPCAST(VhostUserState, nc, nc0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue