aboutsummaryrefslogtreecommitdiff
path: root/net/vhost-user.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/vhost-user.c')
-rw-r--r--net/vhost-user.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 5b94c84541..7aff77ee4a 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -20,7 +20,7 @@
typedef struct VhostUserState {
NetClientState nc;
- CharDriverState *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,10 +150,8 @@ 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 (nc->queue_index == 0) {
+ qemu_chr_fe_deinit(&s->chr);
}
qemu_purge_queued_packets(nc);
@@ -187,7 +185,7 @@ static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond,
{
VhostUserState *s = opaque;
- qemu_chr_disconnect(s->chr);
+ qemu_chr_fe_disconnect(&s->chr);
return FALSE;
}
@@ -197,6 +195,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 +205,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->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, 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_disconnect(s->chr);
+ if (vhost_user_start(queues, ncs, &s->chr) < 0) {
+ qemu_chr_fe_disconnect(&s->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;
@@ -244,28 +245,28 @@ 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;
+ 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, nc);
- s->chr = chr;
}
s = DO_UPCAST(VhostUserState, nc, nc0);
do {
- Error *err = NULL;
- 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, true);
} while (!s->started);
assert(s->vhost_net);
@@ -294,8 +295,6 @@ static CharDriverState *net_vhost_claim_chardev(
return NULL;
}
- qemu_chr_fe_claim_no_fail(chr);
-
return chr;
}