Skip to content

Commit ee8a1c6

Browse files
committed
net/vhost-vdpa: Fix device compatibility check
vhost-vdpa 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 5c485d5 commit ee8a1c6

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

net/vhost-vdpa.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,26 @@ static bool vhost_vdpa_has_ufo(NetClientState *nc)
147147

148148
}
149149

150+
static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc,
151+
Error **errp)
152+
{
153+
const char *driver = object_class_get_name(oc);
154+
155+
if (!g_str_has_prefix(driver, "virtio-net-")) {
156+
error_setg(errp, "vhost-vdpa requires frontend driver virtio-net-*");
157+
return false;
158+
}
159+
160+
return true;
161+
}
162+
150163
static NetClientInfo net_vhost_vdpa_info = {
151164
.type = NET_CLIENT_DRIVER_VHOST_VDPA,
152165
.size = sizeof(VhostVDPAState),
153166
.cleanup = vhost_vdpa_cleanup,
154167
.has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
155168
.has_ufo = vhost_vdpa_has_ufo,
169+
.check_peer_type = vhost_vdpa_check_peer_type,
156170
};
157171

158172
static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
@@ -179,35 +193,12 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
179193
return ret;
180194
}
181195

182-
static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
183-
{
184-
const char *name = opaque;
185-
const char *driver, *netdev;
186-
187-
driver = qemu_opt_get(opts, "driver");
188-
netdev = qemu_opt_get(opts, "netdev");
189-
if (!driver || !netdev) {
190-
return 0;
191-
}
192-
if (strcmp(netdev, name) == 0 &&
193-
!g_str_has_prefix(driver, "virtio-net-")) {
194-
error_setg(errp, "vhost-vdpa requires frontend driver virtio-net-*");
195-
return -1;
196-
}
197-
return 0;
198-
}
199-
200196
int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
201197
NetClientState *peer, Error **errp)
202198
{
203199
const NetdevVhostVDPAOptions *opts;
204200

205201
assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
206202
opts = &netdev->u.vhost_vdpa;
207-
/* verify net frontend */
208-
if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
209-
(char *)name, errp)) {
210-
return -1;
211-
}
212203
return net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, opts->vhostdev);
213204
}

0 commit comments

Comments
 (0)