diff options
author | Laurent Vivier <lvivier@redhat.com> | 2025-07-09 10:24:18 +0200 |
---|---|---|
committer | Jason Wang <jasowang@redhat.com> | 2025-07-14 13:27:09 +0800 |
commit | 8f6e5c620a5b21c070eed93721236cad48b6f9d7 (patch) | |
tree | 6665b71774b42435e4fa95d6c3cb7716d6c4765c /include | |
parent | 7136352b40631b058dd0fe731a0d404e761e799f (diff) | |
download | qemu-8f6e5c620a5b21c070eed93721236cad48b6f9d7.zip qemu-8f6e5c620a5b21c070eed93721236cad48b6f9d7.tar.gz qemu-8f6e5c620a5b21c070eed93721236cad48b6f9d7.tar.bz2 |
net: Add get_vhost_net callback to NetClientInfo
The get_vhost_net() function previously contained a large switch
statement to find the VHostNetState pointer based on the net
client's type. This created a tight coupling, requiring the generic
vhost layer to be aware of every specific backend that supported
vhost, such as tap, vhost-user, and vhost-vdpa.
This approach is not scalable and requires modifying a central function
for any new backend. It also forced each backend to expose its internal
getter function in a public header file.
This patch refactors the logic by introducing a new get_vhost_net
function pointer to the NetClientInfo struct. The central
get_vhost_net() function is now a simple, generic dispatcher that
invokes the callback provided by the net client.
Each backend now implements its own private getter and registers it in
its NetClientInfo.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/net/net.h | 2 | ||||
-rw-r--r-- | include/net/tap.h | 3 | ||||
-rw-r--r-- | include/net/vhost-user.h | 1 | ||||
-rw-r--r-- | include/net/vhost-vdpa.h | 2 |
4 files changed, 2 insertions, 6 deletions
diff --git a/include/net/net.h b/include/net/net.h index ac59b59..e67b375 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -67,6 +67,7 @@ typedef void (SocketReadStateFinalize)(SocketReadState *rs); typedef void (NetAnnounce)(NetClientState *); typedef bool (SetSteeringEBPF)(NetClientState *, int); typedef bool (NetCheckPeerType)(NetClientState *, ObjectClass *, Error **); +typedef struct vhost_net *(GetVHostNet)(NetClientState *nc); typedef struct NetClientInfo { NetClientDriver type; @@ -92,6 +93,7 @@ typedef struct NetClientInfo { NetAnnounce *announce; SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; + GetVHostNet *get_vhost_net; } NetClientInfo; struct NetClientState { diff --git a/include/net/tap.h b/include/net/tap.h index 5d58551..6f34f13 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -33,7 +33,4 @@ int tap_disable(NetClientState *nc); int tap_get_fd(NetClientState *nc); -struct vhost_net; -struct vhost_net *tap_get_vhost_net(NetClientState *nc); - #endif /* QEMU_NET_TAP_H */ diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h index 35bf619..0b233a2 100644 --- a/include/net/vhost-user.h +++ b/include/net/vhost-user.h @@ -12,7 +12,6 @@ #define VHOST_USER_H struct vhost_net; -struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); uint64_t vhost_user_get_acked_features(NetClientState *nc); void vhost_user_save_acked_features(NetClientState *nc); diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h index b81f9a6..916ead3 100644 --- a/include/net/vhost-vdpa.h +++ b/include/net/vhost-vdpa.h @@ -14,8 +14,6 @@ #define TYPE_VHOST_VDPA "vhost-vdpa" -struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); - extern const int vdpa_feature_bits[]; #endif /* VHOST_VDPA_H */ |