Skip to content

Commit e287bf7

Browse files
committed
net: Introduce NetClientInfo.check_peer_type()
Some network backends (vhost-user and vhost-vdpa) work only with specific devices. At startup, they second guess what the command line option handling will do and error out if they think 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. Add a callback where backends can check compatibility with a device when it actually tries to attach, even on hotplug. 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 4d1a525 commit e287bf7

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

hw/core/qdev-properties-system.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
431431
goto out;
432432
}
433433

434+
if (peers[i]->info->check_peer_type) {
435+
if (!peers[i]->info->check_peer_type(peers[i], obj->class, errp)) {
436+
goto out;
437+
}
438+
}
439+
434440
ncs[i] = peers[i];
435441
ncs[i]->queue_index = i;
436442
}

include/net/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef struct SocketReadState SocketReadState;
6262
typedef void (SocketReadStateFinalize)(SocketReadState *rs);
6363
typedef void (NetAnnounce)(NetClientState *);
6464
typedef bool (SetSteeringEBPF)(NetClientState *, int);
65+
typedef bool (NetCheckPeerType)(NetClientState *, ObjectClass *, Error **);
6566

6667
typedef struct NetClientInfo {
6768
NetClientDriver type;
@@ -84,6 +85,7 @@ typedef struct NetClientInfo {
8485
SetVnetBE *set_vnet_be;
8586
NetAnnounce *announce;
8687
SetSteeringEBPF *set_steering_ebpf;
88+
NetCheckPeerType *check_peer_type;
8789
} NetClientInfo;
8890

8991
struct NetClientState {

0 commit comments

Comments
 (0)