blob: fd766504ab43008eb6afe8eb6b17762ac6a5ea01 [file] [log] [blame]
Nikolay Nikolaevd314f582014-05-27 15:06:29 +03001/*
2 * vhost-user.c
3 *
4 * Copyright (c) 2013 Virtual Open Systems Sarl.
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 *
9 */
10
Peter Maydell2744d922016-01-29 17:50:00 +000011#include "qemu/osdep.h"
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030012#include "clients.h"
13#include "net/vhost_net.h"
14#include "net/vhost-user.h"
Marc-André Lureau4d43a602017-01-26 18:26:44 +040015#include "chardev/char-fe.h"
Markus Armbrustere688df62018-02-01 12:18:31 +010016#include "qapi/error.h"
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +030017#include "qemu/config-file.h"
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030018#include "qemu/error-report.h"
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080019#include "qmp-commands.h"
Marc-André Lureau69b32a62015-10-09 17:17:30 +020020#include "trace.h"
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030021
22typedef struct VhostUserState {
23 NetClientState nc;
Marc-André Lureau5d300162016-10-22 12:52:57 +030024 CharBackend chr; /* only queue index 0 */
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030025 VHostNetState *vhost_net;
Paolo Bonzini6f1de6b2016-06-20 15:02:40 +020026 guint watch;
Marc-André Lureaua4632152016-06-06 18:45:05 +020027 uint64_t acked_features;
Marc-André Lureauc89804d2016-07-27 01:15:19 +040028 bool started;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030029} VhostUserState;
30
31VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
32{
33 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
Eric Blakef394b2e2016-07-13 21:50:23 -060034 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030035 return s->vhost_net;
36}
37
Marc-André Lureaua4632152016-06-06 18:45:05 +020038uint64_t vhost_user_get_acked_features(NetClientState *nc)
39{
40 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
Eric Blakef394b2e2016-07-13 21:50:23 -060041 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Marc-André Lureaua4632152016-06-06 18:45:05 +020042 return s->acked_features;
43}
44
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080045static void vhost_user_stop(int queues, NetClientState *ncs[])
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030046{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080047 VhostUserState *s;
48 int i;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030049
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080050 for (i = 0; i < queues; i++) {
Eric Blakef394b2e2016-07-13 21:50:23 -060051 assert(ncs[i]->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080052
53 s = DO_UPCAST(VhostUserState, nc, ncs[i]);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080054
55 if (s->vhost_net) {
Marc-André Lureaua4632152016-06-06 18:45:05 +020056 /* save acked features */
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040057 uint64_t features = vhost_net_get_acked_features(s->vhost_net);
58 if (features) {
59 s->acked_features = features;
60 }
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080061 vhost_net_cleanup(s->vhost_net);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080062 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030063 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030064}
65
Marc-André Lureau5d300162016-10-22 12:52:57 +030066static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030067{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080068 VhostNetOptions options;
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040069 struct vhost_net *net = NULL;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080070 VhostUserState *s;
71 int max_queues;
72 int i;
73
74 options.backend_type = VHOST_BACKEND_TYPE_USER;
75
76 for (i = 0; i < queues; i++) {
Eric Blakef394b2e2016-07-13 21:50:23 -060077 assert(ncs[i]->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080078
79 s = DO_UPCAST(VhostUserState, nc, ncs[i]);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080080
81 options.net_backend = ncs[i];
Marc-André Lureau5d300162016-10-22 12:52:57 +030082 options.opaque = be;
Jason Wang69e87b32016-07-06 09:57:55 +080083 options.busyloop_timeout = 0;
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040084 net = vhost_net_init(&options);
85 if (!net) {
Markus Armbruster9af9e0f2015-12-18 16:35:19 +010086 error_report("failed to init vhost_net for queue %d", i);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080087 goto err;
88 }
89
90 if (i == 0) {
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040091 max_queues = vhost_net_get_max_queues(net);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080092 if (queues > max_queues) {
Markus Armbruster9af9e0f2015-12-18 16:35:19 +010093 error_report("you are asking more queues than supported: %d",
94 max_queues);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080095 goto err;
96 }
97 }
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040098
99 if (s->vhost_net) {
100 vhost_net_cleanup(s->vhost_net);
101 g_free(s->vhost_net);
102 }
103 s->vhost_net = net;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300104 }
105
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800106 return 0;
107
108err:
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +0400109 if (net) {
110 vhost_net_cleanup(net);
111 }
112 vhost_user_stop(i, ncs);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800113 return -1;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300114}
115
Thibaut Colletf6f56292015-10-09 17:17:31 +0200116static ssize_t vhost_user_receive(NetClientState *nc, const uint8_t *buf,
117 size_t size)
118{
Thibaut Collet3e866362015-10-09 17:17:32 +0200119 /* In case of RARP (message size is 60) notify backup to send a fake RARP.
120 This fake RARP will be sent by backend only for guest
121 without GUEST_ANNOUNCE capability.
Thibaut Colletf6f56292015-10-09 17:17:31 +0200122 */
Thibaut Collet3e866362015-10-09 17:17:32 +0200123 if (size == 60) {
124 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
125 int r;
126 static int display_rarp_failure = 1;
127 char mac_addr[6];
128
129 /* extract guest mac address from the RARP message */
130 memcpy(mac_addr, &buf[6], 6);
131
132 r = vhost_net_notify_migration_done(s->vhost_net, mac_addr);
133
134 if ((r != 0) && (display_rarp_failure)) {
135 fprintf(stderr,
136 "Vhost user backend fails to broadcast fake RARP\n");
137 fflush(stderr);
138 display_rarp_failure = 0;
139 }
140 }
141
Thibaut Colletf6f56292015-10-09 17:17:31 +0200142 return size;
143}
144
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300145static void vhost_user_cleanup(NetClientState *nc)
146{
147 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
148
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800149 if (s->vhost_net) {
150 vhost_net_cleanup(s->vhost_net);
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +0400151 g_free(s->vhost_net);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800152 s->vhost_net = NULL;
153 }
Marc-André Lureauc39860e2016-10-22 12:52:58 +0300154 if (nc->queue_index == 0) {
Yunjian Wang41d4e5e2017-07-28 09:50:53 +0800155 if (s->watch) {
156 g_source_remove(s->watch);
157 s->watch = 0;
158 }
Marc-André Lureau1ce26102017-01-27 00:49:13 +0400159 qemu_chr_fe_deinit(&s->chr, true);
Paolo Bonzini25f0d2a2016-06-29 15:15:33 +0200160 }
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800161
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300162 qemu_purge_queued_packets(nc);
163}
164
165static bool vhost_user_has_vnet_hdr(NetClientState *nc)
166{
Eric Blakef394b2e2016-07-13 21:50:23 -0600167 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300168
169 return true;
170}
171
172static bool vhost_user_has_ufo(NetClientState *nc)
173{
Eric Blakef394b2e2016-07-13 21:50:23 -0600174 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300175
176 return true;
177}
178
179static NetClientInfo net_vhost_user_info = {
Eric Blakef394b2e2016-07-13 21:50:23 -0600180 .type = NET_CLIENT_DRIVER_VHOST_USER,
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300181 .size = sizeof(VhostUserState),
Thibaut Colletf6f56292015-10-09 17:17:31 +0200182 .receive = vhost_user_receive,
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300183 .cleanup = vhost_user_cleanup,
184 .has_vnet_hdr = vhost_user_has_vnet_hdr,
185 .has_ufo = vhost_user_has_ufo,
186};
187
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200188static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond,
189 void *opaque)
190{
191 VhostUserState *s = opaque;
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200192
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300193 qemu_chr_fe_disconnect(&s->chr);
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200194
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400195 return TRUE;
196}
197
198static void net_vhost_user_event(void *opaque, int event);
199
200static void chr_closed_bh(void *opaque)
201{
202 const char *name = opaque;
203 NetClientState *ncs[MAX_QUEUE_NUM];
204 VhostUserState *s;
205 Error *err = NULL;
206 int queues;
207
208 queues = qemu_find_net_clients_except(name, ncs,
209 NET_CLIENT_DRIVER_NIC,
210 MAX_QUEUE_NUM);
211 assert(queues < MAX_QUEUE_NUM);
212
213 s = DO_UPCAST(VhostUserState, nc, ncs[0]);
214
215 qmp_set_link(name, false, &err);
216 vhost_user_stop(queues, ncs);
217
218 qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, net_vhost_user_event,
Anton Nefedov81517ba2017-07-06 15:08:49 +0300219 NULL, opaque, NULL, true);
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400220
221 if (err) {
222 error_report_err(err);
223 }
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200224}
225
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300226static void net_vhost_user_event(void *opaque, int event)
227{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800228 const char *name = opaque;
229 NetClientState *ncs[MAX_QUEUE_NUM];
230 VhostUserState *s;
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300231 Chardev *chr;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800232 Error *err = NULL;
233 int queues;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300234
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800235 queues = qemu_find_net_clients_except(name, ncs,
Eric Blakef394b2e2016-07-13 21:50:23 -0600236 NET_CLIENT_DRIVER_NIC,
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800237 MAX_QUEUE_NUM);
Marc-André Lureauc1bf3532016-02-23 19:10:49 +0100238 assert(queues < MAX_QUEUE_NUM);
239
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800240 s = DO_UPCAST(VhostUserState, nc, ncs[0]);
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300241 chr = qemu_chr_fe_get_driver(&s->chr);
242 trace_vhost_user_event(chr->label, event);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300243 switch (event) {
244 case CHR_EVENT_OPENED:
Marc-André Lureau5d300162016-10-22 12:52:57 +0300245 if (vhost_user_start(queues, ncs, &s->chr) < 0) {
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300246 qemu_chr_fe_disconnect(&s->chr);
Marc-André Lureau0d572af2016-06-06 18:45:03 +0200247 return;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800248 }
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400249 s->watch = qemu_chr_fe_add_watch(&s->chr, G_IO_HUP,
250 net_vhost_user_watch, s);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800251 qmp_set_link(name, true, &err);
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400252 s->started = true;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300253 break;
254 case CHR_EVENT_CLOSED:
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400255 /* a close event may happen during a read/write, but vhost
256 * code assumes the vhost_dev remains setup, so delay the
257 * stop & clear to idle.
258 * FIXME: better handle failure in vhost code, remove bh
259 */
260 if (s->watch) {
261 AioContext *ctx = qemu_get_current_aio_context();
262
263 g_source_remove(s->watch);
264 s->watch = 0;
Anton Nefedov81517ba2017-07-06 15:08:49 +0300265 qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, NULL,
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400266 NULL, NULL, false);
267
268 aio_bh_schedule_oneshot(ctx, chr_closed_bh, opaque);
269 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300270 break;
271 }
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800272
273 if (err) {
274 error_report_err(err);
275 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300276}
277
278static int net_vhost_user_init(NetClientState *peer, const char *device,
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300279 const char *name, Chardev *chr,
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800280 int queues)
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300281{
Marc-André Lureau32a6ebe2016-10-22 12:52:52 +0300282 Error *err = NULL;
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400283 NetClientState *nc, *nc0 = NULL;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300284 VhostUserState *s;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800285 int i;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300286
Marc-André Lureauc1bf3532016-02-23 19:10:49 +0100287 assert(name);
288 assert(queues > 0);
289
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800290 for (i = 0; i < queues; i++) {
291 nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800292 snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
293 i, chr->label);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800294 nc->queue_index = i;
Marc-André Lureau5d300162016-10-22 12:52:57 +0300295 if (!nc0) {
296 nc0 = nc;
297 s = DO_UPCAST(VhostUserState, nc, nc);
298 if (!qemu_chr_fe_init(&s->chr, chr, &err)) {
299 error_report_err(err);
300 return -1;
301 }
Marc-André Lureau32a6ebe2016-10-22 12:52:52 +0300302 }
Marc-André Lureau5d300162016-10-22 12:52:57 +0300303
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800304 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300305
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400306 s = DO_UPCAST(VhostUserState, nc, nc0);
307 do {
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300308 if (qemu_chr_fe_wait_connected(&s->chr, &err) < 0) {
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400309 error_report_err(err);
310 return -1;
311 }
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300312 qemu_chr_fe_set_handlers(&s->chr, NULL, NULL,
Anton Nefedov81517ba2017-07-06 15:08:49 +0300313 net_vhost_user_event, NULL, nc0->name, NULL,
314 true);
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400315 } while (!s->started);
Michael S. Tsirkind345ed22015-07-15 13:47:31 +0300316
Marc-André Lureau1a5b68c2016-07-27 01:15:13 +0400317 assert(s->vhost_net);
318
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300319 return 0;
320}
321
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300322static Chardev *net_vhost_claim_chardev(
Markus Armbruster81904832015-03-13 14:17:16 +0100323 const NetdevVhostUserOptions *opts, Error **errp)
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300324{
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300325 Chardev *chr = qemu_chr_find(opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300326
327 if (chr == NULL) {
Markus Armbruster81904832015-03-13 14:17:16 +0100328 error_setg(errp, "chardev \"%s\" not found", opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300329 return NULL;
330 }
331
Daniel P. Berrange0a733362016-10-07 13:18:34 +0100332 if (!qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE)) {
333 error_setg(errp, "chardev \"%s\" is not reconnectable",
334 opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300335 return NULL;
336 }
Daniel P. Berrange0a733362016-10-07 13:18:34 +0100337 if (!qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_FD_PASS)) {
338 error_setg(errp, "chardev \"%s\" does not support FD passing",
Markus Armbruster81904832015-03-13 14:17:16 +0100339 opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300340 return NULL;
341 }
342
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300343 return chr;
344}
345
Markus Armbruster28d0de72015-03-13 13:35:14 +0100346static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300347{
348 const char *name = opaque;
349 const char *driver, *netdev;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300350
351 driver = qemu_opt_get(opts, "driver");
352 netdev = qemu_opt_get(opts, "netdev");
353
354 if (!driver || !netdev) {
355 return 0;
356 }
357
358 if (strcmp(netdev, name) == 0 &&
Marc-André Lureaud9d26112016-07-27 01:14:56 +0400359 !g_str_has_prefix(driver, "virtio-net-")) {
Markus Armbruster81904832015-03-13 14:17:16 +0100360 error_setg(errp, "vhost-user requires frontend driver virtio-net-*");
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300361 return -1;
362 }
363
364 return 0;
365}
366
Kővágó, Zoltáncebea512016-07-13 21:50:12 -0600367int net_init_vhost_user(const Netdev *netdev, const char *name,
Markus Armbrustera30ecde2015-05-15 13:58:50 +0200368 NetClientState *peer, Error **errp)
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300369{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800370 int queues;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300371 const NetdevVhostUserOptions *vhost_user_opts;
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300372 Chardev *chr;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300373
Eric Blakef394b2e2016-07-13 21:50:23 -0600374 assert(netdev->type == NET_CLIENT_DRIVER_VHOST_USER);
375 vhost_user_opts = &netdev->u.vhost_user;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300376
Daniel P. Berrange0a733362016-10-07 13:18:34 +0100377 chr = net_vhost_claim_chardev(vhost_user_opts, errp);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300378 if (!chr) {
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300379 return -1;
380 }
381
382 /* verify net frontend */
383 if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
Markus Armbruster81904832015-03-13 14:17:16 +0100384 (char *)name, errp)) {
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300385 return -1;
386 }
387
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800388 queues = vhost_user_opts->has_queues ? vhost_user_opts->queues : 1;
Ilya Maximetsfff4e482016-02-24 13:44:34 +0300389 if (queues < 1 || queues > MAX_QUEUE_NUM) {
Victor Kaplansky6f6f9512015-12-01 15:32:26 +0200390 error_setg(errp,
Ilya Maximetsfff4e482016-02-24 13:44:34 +0300391 "vhost-user number of queues must be in range [1, %d]",
392 MAX_QUEUE_NUM);
Victor Kaplansky6f6f9512015-12-01 15:32:26 +0200393 return -1;
394 }
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300395
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800396 return net_vhost_user_init(peer, "vhost_user", name, chr, queues);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300397}