aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Vivier <lvivier@redhat.com>2025-07-09 10:24:23 +0200
committerJason Wang <jasowang@redhat.com>2025-07-14 13:27:09 +0800
commitba5acc5d6e0bc9ab86619c92cb76493aa197d7a2 (patch)
tree76b6de340e1e03227643eee9ecd3a436883b6d05
parent33b78a30a3e8e1cf16ef423bf2e78caf3d560985 (diff)
downloadqemu-ba5acc5d6e0bc9ab86619c92cb76493aa197d7a2.zip
qemu-ba5acc5d6e0bc9ab86619c92cb76493aa197d7a2.tar.gz
qemu-ba5acc5d6e0bc9ab86619c92cb76493aa197d7a2.tar.bz2
net: Add is_vhost_user flag to vhost_net struct
Introduce a boolean is_vhost_user field to the vhost_net structure. This flag is initialized during vhost_net_init based on whether the backend is vhost-user. This refactoring simplifies checks for vhost-user specific behavior, replacing direct comparisons of 'net->nc->info->type' with the new flag. It improves readability and encapsulates the backend type information directly within the vhost_net instance. Signed-off-by: Laurent Vivier <lvivier@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
-rw-r--r--hw/net/vhost_net.c3
-rw-r--r--hw/net/virtio-net.c8
-rw-r--r--include/hw/virtio/vhost.h1
-rw-r--r--include/net/vhost_net.h1
-rw-r--r--net/tap.c1
-rw-r--r--net/vhost-user.c1
-rw-r--r--net/vhost-vdpa.c1
7 files changed, 13 insertions, 3 deletions
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 74d2e3e..540492b 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -246,6 +246,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
net->feature_bits = options->feature_bits;
net->save_acked_features = options->save_acked_features;
net->max_tx_queue_size = options->max_tx_queue_size;
+ net->is_vhost_user = options->is_vhost_user;
net->dev.max_queues = 1;
net->dev.vqs = net->vqs;
@@ -440,7 +441,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
* because vhost user doesn't interrupt masking/unmasking
* properly.
*/
- if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
+ if (net->is_vhost_user) {
dev->use_guest_notifier_mask = false;
}
}
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 39fc280..00df5fd 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -691,12 +691,14 @@ default_value:
static int peer_attach(VirtIONet *n, int index)
{
NetClientState *nc = qemu_get_subqueue(n->nic, index);
+ struct vhost_net *net;
if (!nc->peer) {
return 0;
}
- if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
+ net = get_vhost_net(nc->peer);
+ if (net && net->is_vhost_user) {
vhost_net_set_vring_enable(nc->peer, 1);
}
@@ -714,12 +716,14 @@ static int peer_attach(VirtIONet *n, int index)
static int peer_detach(VirtIONet *n, int index)
{
NetClientState *nc = qemu_get_subqueue(n->nic, index);
+ struct vhost_net *net;
if (!nc->peer) {
return 0;
}
- if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
+ net = get_vhost_net(nc->peer);
+ if (net && net->is_vhost_user) {
vhost_net_set_vring_enable(nc->peer, 0);
}
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index a62992c..f178cf9 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -147,6 +147,7 @@ struct vhost_net {
const int *feature_bits;
int max_tx_queue_size;
SaveAcketFeatures *save_acked_features;
+ bool is_vhost_user;
NetClientState *nc;
};
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 8f4fddf..879781d 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -17,6 +17,7 @@ typedef struct VhostNetOptions {
unsigned int nvqs;
const int *feature_bits;
int max_tx_queue_size;
+ bool is_vhost_user;
GetAckedFeatures *get_acked_features;
SaveAcketFeatures *save_acked_features;
void *opaque;
diff --git a/net/tap.c b/net/tap.c
index 2f0cb55..23536c0 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -747,6 +747,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
options.get_acked_features = NULL;
options.save_acked_features = NULL;
options.max_tx_queue_size = 0;
+ options.is_vhost_user = false;
s->vhost_net = vhost_net_init(&options);
if (!s->vhost_net) {
diff --git a/net/vhost-user.c b/net/vhost-user.c
index bf89291..1c3b8b3 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -141,6 +141,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[],
options.max_tx_queue_size = VIRTQUEUE_MAX_SIZE;
options.get_acked_features = vhost_user_get_acked_features;
options.save_acked_features = vhost_user_save_acked_features;
+ options.is_vhost_user = true;
net = vhost_net_init(&options);
if (!net) {
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 353392b..943e9c5 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -205,6 +205,7 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be,
options.get_acked_features = NULL;
options.save_acked_features = NULL;
options.max_tx_queue_size = VIRTQUEUE_MAX_SIZE;
+ options.is_vhost_user = false;
net = vhost_net_init(&options);
if (!net) {