Skip to content

Commit 5c485d5

Browse files
committed
net/vhost-user: Fix device compatibility check
vhost-user works only with specific devices. At startup, it second guesses what the command line option handling will do and error out if it thinks a non-virtio device will attach to them. This second guessing is not only ugly, it can lead to wrong error messages ('-device floppy,netdev=foo' should complain about an unknown property, not about the wrong kind of network device being attached) and completely ignores hotplugging. Drop the old checks and implement .check_peer_type() instead to fix this. As a nice side effect, it also removes one more dependency on the legacy QemuOpts infrastructure and even reduces the code size. Signed-off-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Reviewed-by: Damien Hedde <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Tested-by: Peter Krempa <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent e287bf7 commit 5c485d5

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

net/vhost-user.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ static bool vhost_user_has_ufo(NetClientState *nc)
198198
return true;
199199
}
200200

201+
static bool vhost_user_check_peer_type(NetClientState *nc, ObjectClass *oc,
202+
Error **errp)
203+
{
204+
const char *driver = object_class_get_name(oc);
205+
206+
if (!g_str_has_prefix(driver, "virtio-net-")) {
207+
error_setg(errp, "vhost-user requires frontend driver virtio-net-*");
208+
return false;
209+
}
210+
211+
return true;
212+
}
213+
201214
static NetClientInfo net_vhost_user_info = {
202215
.type = NET_CLIENT_DRIVER_VHOST_USER,
203216
.size = sizeof(NetVhostUserState),
@@ -207,6 +220,7 @@ static NetClientInfo net_vhost_user_info = {
207220
.has_ufo = vhost_user_has_ufo,
208221
.set_vnet_be = vhost_user_set_vnet_endianness,
209222
.set_vnet_le = vhost_user_set_vnet_endianness,
223+
.check_peer_type = vhost_user_check_peer_type,
210224
};
211225

212226
static gboolean net_vhost_user_watch(void *do_not_use, GIOCondition cond,
@@ -397,27 +411,6 @@ static Chardev *net_vhost_claim_chardev(
397411
return chr;
398412
}
399413

400-
static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
401-
{
402-
const char *name = opaque;
403-
const char *driver, *netdev;
404-
405-
driver = qemu_opt_get(opts, "driver");
406-
netdev = qemu_opt_get(opts, "netdev");
407-
408-
if (!driver || !netdev) {
409-
return 0;
410-
}
411-
412-
if (strcmp(netdev, name) == 0 &&
413-
!g_str_has_prefix(driver, "virtio-net-")) {
414-
error_setg(errp, "vhost-user requires frontend driver virtio-net-*");
415-
return -1;
416-
}
417-
418-
return 0;
419-
}
420-
421414
int net_init_vhost_user(const Netdev *netdev, const char *name,
422415
NetClientState *peer, Error **errp)
423416
{
@@ -433,12 +426,6 @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
433426
return -1;
434427
}
435428

436-
/* verify net frontend */
437-
if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
438-
(char *)name, errp)) {
439-
return -1;
440-
}
441-
442429
queues = vhost_user_opts->has_queues ? vhost_user_opts->queues : 1;
443430
if (queues < 1 || queues > MAX_QUEUE_NUM) {
444431
error_setg(errp,

0 commit comments

Comments
 (0)