blob: cb455125069c4047d0183188dcc791327d6d9f66 [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"
Markus Armbruster922a01a2018-02-01 12:18:46 +010019#include "qemu/option.h"
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080020#include "qmp-commands.h"
Marc-André Lureau69b32a62015-10-09 17:17:30 +020021#include "trace.h"
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030022
23typedef struct VhostUserState {
24 NetClientState nc;
Marc-André Lureau5d300162016-10-22 12:52:57 +030025 CharBackend chr; /* only queue index 0 */
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030026 VHostNetState *vhost_net;
Paolo Bonzini6f1de6b2016-06-20 15:02:40 +020027 guint watch;
Marc-André Lureaua4632152016-06-06 18:45:05 +020028 uint64_t acked_features;
Marc-André Lureauc89804d2016-07-27 01:15:19 +040029 bool started;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030030} VhostUserState;
31
32VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
33{
34 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
Eric Blakef394b2e2016-07-13 21:50:23 -060035 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030036 return s->vhost_net;
37}
38
Marc-André Lureaua4632152016-06-06 18:45:05 +020039uint64_t vhost_user_get_acked_features(NetClientState *nc)
40{
41 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
Eric Blakef394b2e2016-07-13 21:50:23 -060042 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Marc-André Lureaua4632152016-06-06 18:45:05 +020043 return s->acked_features;
44}
45
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080046static void vhost_user_stop(int queues, NetClientState *ncs[])
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030047{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080048 VhostUserState *s;
49 int i;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030050
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080051 for (i = 0; i < queues; i++) {
Eric Blakef394b2e2016-07-13 21:50:23 -060052 assert(ncs[i]->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080053
54 s = DO_UPCAST(VhostUserState, nc, ncs[i]);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080055
56 if (s->vhost_net) {
Marc-André Lureaua4632152016-06-06 18:45:05 +020057 /* save acked features */
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040058 uint64_t features = vhost_net_get_acked_features(s->vhost_net);
59 if (features) {
60 s->acked_features = features;
61 }
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080062 vhost_net_cleanup(s->vhost_net);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080063 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030064 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030065}
66
Marc-André Lureau5d300162016-10-22 12:52:57 +030067static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
Nikolay Nikolaevd314f582014-05-27 15:06:29 +030068{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080069 VhostNetOptions options;
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040070 struct vhost_net *net = NULL;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080071 VhostUserState *s;
72 int max_queues;
73 int i;
74
75 options.backend_type = VHOST_BACKEND_TYPE_USER;
76
77 for (i = 0; i < queues; i++) {
Eric Blakef394b2e2016-07-13 21:50:23 -060078 assert(ncs[i]->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080079
80 s = DO_UPCAST(VhostUserState, nc, ncs[i]);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080081
82 options.net_backend = ncs[i];
Marc-André Lureau5d300162016-10-22 12:52:57 +030083 options.opaque = be;
Jason Wang69e87b32016-07-06 09:57:55 +080084 options.busyloop_timeout = 0;
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040085 net = vhost_net_init(&options);
86 if (!net) {
Markus Armbruster9af9e0f2015-12-18 16:35:19 +010087 error_report("failed to init vhost_net for queue %d", i);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080088 goto err;
89 }
90
91 if (i == 0) {
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040092 max_queues = vhost_net_get_max_queues(net);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080093 if (queues > max_queues) {
Markus Armbruster9af9e0f2015-12-18 16:35:19 +010094 error_report("you are asking more queues than supported: %d",
95 max_queues);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +080096 goto err;
97 }
98 }
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +040099
100 if (s->vhost_net) {
101 vhost_net_cleanup(s->vhost_net);
102 g_free(s->vhost_net);
103 }
104 s->vhost_net = net;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300105 }
106
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800107 return 0;
108
109err:
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +0400110 if (net) {
111 vhost_net_cleanup(net);
112 }
113 vhost_user_stop(i, ncs);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800114 return -1;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300115}
116
Thibaut Colletf6f56292015-10-09 17:17:31 +0200117static ssize_t vhost_user_receive(NetClientState *nc, const uint8_t *buf,
118 size_t size)
119{
Thibaut Collet3e866362015-10-09 17:17:32 +0200120 /* In case of RARP (message size is 60) notify backup to send a fake RARP.
121 This fake RARP will be sent by backend only for guest
122 without GUEST_ANNOUNCE capability.
Thibaut Colletf6f56292015-10-09 17:17:31 +0200123 */
Thibaut Collet3e866362015-10-09 17:17:32 +0200124 if (size == 60) {
125 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
126 int r;
127 static int display_rarp_failure = 1;
128 char mac_addr[6];
129
130 /* extract guest mac address from the RARP message */
131 memcpy(mac_addr, &buf[6], 6);
132
133 r = vhost_net_notify_migration_done(s->vhost_net, mac_addr);
134
135 if ((r != 0) && (display_rarp_failure)) {
136 fprintf(stderr,
137 "Vhost user backend fails to broadcast fake RARP\n");
138 fflush(stderr);
139 display_rarp_failure = 0;
140 }
141 }
142
Thibaut Colletf6f56292015-10-09 17:17:31 +0200143 return size;
144}
145
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300146static void vhost_user_cleanup(NetClientState *nc)
147{
148 VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
149
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800150 if (s->vhost_net) {
151 vhost_net_cleanup(s->vhost_net);
Marc-André Lureaue6bcb1b2016-07-27 01:15:12 +0400152 g_free(s->vhost_net);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800153 s->vhost_net = NULL;
154 }
Marc-André Lureauc39860e2016-10-22 12:52:58 +0300155 if (nc->queue_index == 0) {
Yunjian Wang41d4e5e2017-07-28 09:50:53 +0800156 if (s->watch) {
157 g_source_remove(s->watch);
158 s->watch = 0;
159 }
Marc-André Lureau1ce26102017-01-27 00:49:13 +0400160 qemu_chr_fe_deinit(&s->chr, true);
Paolo Bonzini25f0d2a2016-06-29 15:15:33 +0200161 }
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800162
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300163 qemu_purge_queued_packets(nc);
164}
165
166static bool vhost_user_has_vnet_hdr(NetClientState *nc)
167{
Eric Blakef394b2e2016-07-13 21:50:23 -0600168 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300169
170 return true;
171}
172
173static bool vhost_user_has_ufo(NetClientState *nc)
174{
Eric Blakef394b2e2016-07-13 21:50:23 -0600175 assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300176
177 return true;
178}
179
180static NetClientInfo net_vhost_user_info = {
Eric Blakef394b2e2016-07-13 21:50:23 -0600181 .type = NET_CLIENT_DRIVER_VHOST_USER,
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300182 .size = sizeof(VhostUserState),
Thibaut Colletf6f56292015-10-09 17:17:31 +0200183 .receive = vhost_user_receive,
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300184 .cleanup = vhost_user_cleanup,
185 .has_vnet_hdr = vhost_user_has_vnet_hdr,
186 .has_ufo = vhost_user_has_ufo,
187};
188
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200189static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond,
190 void *opaque)
191{
192 VhostUserState *s = opaque;
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200193
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300194 qemu_chr_fe_disconnect(&s->chr);
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200195
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400196 return TRUE;
197}
198
199static void net_vhost_user_event(void *opaque, int event);
200
201static void chr_closed_bh(void *opaque)
202{
203 const char *name = opaque;
204 NetClientState *ncs[MAX_QUEUE_NUM];
205 VhostUserState *s;
206 Error *err = NULL;
207 int queues;
208
209 queues = qemu_find_net_clients_except(name, ncs,
210 NET_CLIENT_DRIVER_NIC,
211 MAX_QUEUE_NUM);
212 assert(queues < MAX_QUEUE_NUM);
213
214 s = DO_UPCAST(VhostUserState, nc, ncs[0]);
215
216 qmp_set_link(name, false, &err);
217 vhost_user_stop(queues, ncs);
218
219 qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, net_vhost_user_event,
Anton Nefedov81517ba2017-07-06 15:08:49 +0300220 NULL, opaque, NULL, true);
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400221
222 if (err) {
223 error_report_err(err);
224 }
Tetsuya Mukawaa6553592016-06-06 18:44:59 +0200225}
226
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300227static void net_vhost_user_event(void *opaque, int event)
228{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800229 const char *name = opaque;
230 NetClientState *ncs[MAX_QUEUE_NUM];
231 VhostUserState *s;
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300232 Chardev *chr;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800233 Error *err = NULL;
234 int queues;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300235
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800236 queues = qemu_find_net_clients_except(name, ncs,
Eric Blakef394b2e2016-07-13 21:50:23 -0600237 NET_CLIENT_DRIVER_NIC,
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800238 MAX_QUEUE_NUM);
Marc-André Lureauc1bf3532016-02-23 19:10:49 +0100239 assert(queues < MAX_QUEUE_NUM);
240
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800241 s = DO_UPCAST(VhostUserState, nc, ncs[0]);
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300242 chr = qemu_chr_fe_get_driver(&s->chr);
243 trace_vhost_user_event(chr->label, event);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300244 switch (event) {
245 case CHR_EVENT_OPENED:
Marc-André Lureau5d300162016-10-22 12:52:57 +0300246 if (vhost_user_start(queues, ncs, &s->chr) < 0) {
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300247 qemu_chr_fe_disconnect(&s->chr);
Marc-André Lureau0d572af2016-06-06 18:45:03 +0200248 return;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800249 }
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400250 s->watch = qemu_chr_fe_add_watch(&s->chr, G_IO_HUP,
251 net_vhost_user_watch, s);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800252 qmp_set_link(name, true, &err);
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400253 s->started = true;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300254 break;
255 case CHR_EVENT_CLOSED:
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400256 /* a close event may happen during a read/write, but vhost
257 * code assumes the vhost_dev remains setup, so delay the
258 * stop & clear to idle.
259 * FIXME: better handle failure in vhost code, remove bh
260 */
261 if (s->watch) {
262 AioContext *ctx = qemu_get_current_aio_context();
263
264 g_source_remove(s->watch);
265 s->watch = 0;
Anton Nefedov81517ba2017-07-06 15:08:49 +0300266 qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, NULL,
Marc-André Lureaue7c83a82017-02-27 14:49:56 +0400267 NULL, NULL, false);
268
269 aio_bh_schedule_oneshot(ctx, chr_closed_bh, opaque);
270 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300271 break;
272 }
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800273
274 if (err) {
275 error_report_err(err);
276 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300277}
278
279static int net_vhost_user_init(NetClientState *peer, const char *device,
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300280 const char *name, Chardev *chr,
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800281 int queues)
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300282{
Marc-André Lureau32a6ebe2016-10-22 12:52:52 +0300283 Error *err = NULL;
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400284 NetClientState *nc, *nc0 = NULL;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300285 VhostUserState *s;
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800286 int i;
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300287
Marc-André Lureauc1bf3532016-02-23 19:10:49 +0100288 assert(name);
289 assert(queues > 0);
290
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800291 for (i = 0; i < queues; i++) {
292 nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800293 snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
294 i, chr->label);
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800295 nc->queue_index = i;
Marc-André Lureau5d300162016-10-22 12:52:57 +0300296 if (!nc0) {
297 nc0 = nc;
298 s = DO_UPCAST(VhostUserState, nc, nc);
299 if (!qemu_chr_fe_init(&s->chr, chr, &err)) {
300 error_report_err(err);
301 return -1;
302 }
Marc-André Lureau32a6ebe2016-10-22 12:52:52 +0300303 }
Marc-André Lureau5d300162016-10-22 12:52:57 +0300304
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800305 }
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300306
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400307 s = DO_UPCAST(VhostUserState, nc, nc0);
308 do {
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300309 if (qemu_chr_fe_wait_connected(&s->chr, &err) < 0) {
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400310 error_report_err(err);
311 return -1;
312 }
Marc-André Lureau5345fdb2016-10-22 12:52:55 +0300313 qemu_chr_fe_set_handlers(&s->chr, NULL, NULL,
Anton Nefedov81517ba2017-07-06 15:08:49 +0300314 net_vhost_user_event, NULL, nc0->name, NULL,
315 true);
Marc-André Lureauc89804d2016-07-27 01:15:19 +0400316 } while (!s->started);
Michael S. Tsirkind345ed22015-07-15 13:47:31 +0300317
Marc-André Lureau1a5b68c2016-07-27 01:15:13 +0400318 assert(s->vhost_net);
319
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300320 return 0;
321}
322
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300323static Chardev *net_vhost_claim_chardev(
Markus Armbruster81904832015-03-13 14:17:16 +0100324 const NetdevVhostUserOptions *opts, Error **errp)
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300325{
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300326 Chardev *chr = qemu_chr_find(opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300327
328 if (chr == NULL) {
Markus Armbruster81904832015-03-13 14:17:16 +0100329 error_setg(errp, "chardev \"%s\" not found", opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300330 return NULL;
331 }
332
Daniel P. Berrange0a733362016-10-07 13:18:34 +0100333 if (!qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE)) {
334 error_setg(errp, "chardev \"%s\" is not reconnectable",
335 opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300336 return NULL;
337 }
Daniel P. Berrange0a733362016-10-07 13:18:34 +0100338 if (!qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_FD_PASS)) {
339 error_setg(errp, "chardev \"%s\" does not support FD passing",
Markus Armbruster81904832015-03-13 14:17:16 +0100340 opts->chardev);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300341 return NULL;
342 }
343
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300344 return chr;
345}
346
Markus Armbruster28d0de72015-03-13 13:35:14 +0100347static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300348{
349 const char *name = opaque;
350 const char *driver, *netdev;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300351
352 driver = qemu_opt_get(opts, "driver");
353 netdev = qemu_opt_get(opts, "netdev");
354
355 if (!driver || !netdev) {
356 return 0;
357 }
358
359 if (strcmp(netdev, name) == 0 &&
Marc-André Lureaud9d26112016-07-27 01:14:56 +0400360 !g_str_has_prefix(driver, "virtio-net-")) {
Markus Armbruster81904832015-03-13 14:17:16 +0100361 error_setg(errp, "vhost-user requires frontend driver virtio-net-*");
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300362 return -1;
363 }
364
365 return 0;
366}
367
Kővágó, Zoltáncebea512016-07-13 21:50:12 -0600368int net_init_vhost_user(const Netdev *netdev, const char *name,
Markus Armbrustera30ecde2015-05-15 13:58:50 +0200369 NetClientState *peer, Error **errp)
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300370{
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800371 int queues;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300372 const NetdevVhostUserOptions *vhost_user_opts;
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300373 Chardev *chr;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300374
Eric Blakef394b2e2016-07-13 21:50:23 -0600375 assert(netdev->type == NET_CLIENT_DRIVER_VHOST_USER);
376 vhost_user_opts = &netdev->u.vhost_user;
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300377
Daniel P. Berrange0a733362016-10-07 13:18:34 +0100378 chr = net_vhost_claim_chardev(vhost_user_opts, errp);
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300379 if (!chr) {
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300380 return -1;
381 }
382
383 /* verify net frontend */
384 if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
Markus Armbruster81904832015-03-13 14:17:16 +0100385 (char *)name, errp)) {
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300386 return -1;
387 }
388
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800389 queues = vhost_user_opts->has_queues ? vhost_user_opts->queues : 1;
Ilya Maximetsfff4e482016-02-24 13:44:34 +0300390 if (queues < 1 || queues > MAX_QUEUE_NUM) {
Victor Kaplansky6f6f9512015-12-01 15:32:26 +0200391 error_setg(errp,
Ilya Maximetsfff4e482016-02-24 13:44:34 +0300392 "vhost-user number of queues must be in range [1, %d]",
393 MAX_QUEUE_NUM);
Victor Kaplansky6f6f9512015-12-01 15:32:26 +0200394 return -1;
395 }
Nikolay Nikolaev03ce5742014-06-10 13:02:16 +0300396
Changchun Ouyangb931bfb2015-09-23 12:20:00 +0800397 return net_vhost_user_init(peer, "vhost_user", name, chr, queues);
Nikolay Nikolaevd314f582014-05-27 15:06:29 +0300398}