mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-29 21:12:07 -06:00
Refactor virtio-net to use generic get_vhost_net
This decouples virtio-net from the TAP netdev backend and allows support for other backends to be implemented. Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com> Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
212d69f25e
commit
ed8b4afe5f
3 changed files with 36 additions and 24 deletions
|
@ -233,7 +233,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < total_queues; i++) {
|
for (i = 0; i < total_queues; i++) {
|
||||||
r = vhost_net_start_one(tap_get_vhost_net(ncs[i].peer), dev, i * 2);
|
r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev, i * 2);
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -250,7 +250,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
|
||||||
|
|
||||||
err:
|
err:
|
||||||
while (--i >= 0) {
|
while (--i >= 0) {
|
||||||
vhost_net_stop_one(tap_get_vhost_net(ncs[i].peer), dev);
|
vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
|
|
||||||
for (i = 0; i < total_queues; i++) {
|
for (i = 0; i < total_queues; i++) {
|
||||||
vhost_net_stop_one(tap_get_vhost_net(ncs[i].peer), dev);
|
vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,6 +291,25 @@ void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
|
||||||
{
|
{
|
||||||
vhost_virtqueue_mask(&net->dev, dev, idx, mask);
|
vhost_virtqueue_mask(&net->dev, dev, idx, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VHostNetState *get_vhost_net(NetClientState *nc)
|
||||||
|
{
|
||||||
|
VHostNetState *vhost_net = 0;
|
||||||
|
|
||||||
|
if (!nc) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (nc->info->type) {
|
||||||
|
case NET_CLIENT_OPTIONS_KIND_TAP:
|
||||||
|
vhost_net = tap_get_vhost_net(nc);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vhost_net;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
|
struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
|
||||||
bool force)
|
bool force)
|
||||||
|
@ -337,4 +356,9 @@ void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
|
||||||
int idx, bool mask)
|
int idx, bool mask)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VHostNetState *get_vhost_net(NetClientState *nc)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -115,14 +115,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
|
||||||
NetClientState *nc = qemu_get_queue(n->nic);
|
NetClientState *nc = qemu_get_queue(n->nic);
|
||||||
int queues = n->multiqueue ? n->max_queues : 1;
|
int queues = n->multiqueue ? n->max_queues : 1;
|
||||||
|
|
||||||
if (!nc->peer) {
|
if (!get_vhost_net(nc->peer)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tap_get_vhost_net(nc->peer)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +125,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
|
||||||
}
|
}
|
||||||
if (!n->vhost_started) {
|
if (!n->vhost_started) {
|
||||||
int r;
|
int r;
|
||||||
if (!vhost_net_query(tap_get_vhost_net(nc->peer), vdev)) {
|
if (!vhost_net_query(get_vhost_net(nc->peer), vdev)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
n->vhost_started = 1;
|
n->vhost_started = 1;
|
||||||
|
@ -465,13 +458,10 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)
|
||||||
features &= ~(0x1 << VIRTIO_NET_F_HOST_UFO);
|
features &= ~(0x1 << VIRTIO_NET_F_HOST_UFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nc->peer || nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
|
if (!get_vhost_net(nc->peer)) {
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
if (!tap_get_vhost_net(nc->peer)) {
|
return vhost_net_get_features(get_vhost_net(nc->peer), features);
|
||||||
return features;
|
|
||||||
}
|
|
||||||
return vhost_net_get_features(tap_get_vhost_net(nc->peer), features);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t virtio_net_bad_features(VirtIODevice *vdev)
|
static uint32_t virtio_net_bad_features(VirtIODevice *vdev)
|
||||||
|
@ -535,13 +525,10 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
|
||||||
for (i = 0; i < n->max_queues; i++) {
|
for (i = 0; i < n->max_queues; i++) {
|
||||||
NetClientState *nc = qemu_get_subqueue(n->nic, i);
|
NetClientState *nc = qemu_get_subqueue(n->nic, i);
|
||||||
|
|
||||||
if (!nc->peer || nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
|
if (!get_vhost_net(nc->peer)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!tap_get_vhost_net(nc->peer)) {
|
vhost_net_ack_features(get_vhost_net(nc->peer), features);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
vhost_net_ack_features(tap_get_vhost_net(nc->peer), features);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((1 << VIRTIO_NET_F_CTRL_VLAN) & features) {
|
if ((1 << VIRTIO_NET_F_CTRL_VLAN) & features) {
|
||||||
|
@ -1514,7 +1501,7 @@ static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx)
|
||||||
VirtIONet *n = VIRTIO_NET(vdev);
|
VirtIONet *n = VIRTIO_NET(vdev);
|
||||||
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
|
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
|
||||||
assert(n->vhost_started);
|
assert(n->vhost_started);
|
||||||
return vhost_net_virtqueue_pending(tap_get_vhost_net(nc->peer), idx);
|
return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
|
static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
|
||||||
|
@ -1523,7 +1510,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
|
||||||
VirtIONet *n = VIRTIO_NET(vdev);
|
VirtIONet *n = VIRTIO_NET(vdev);
|
||||||
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
|
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
|
||||||
assert(n->vhost_started);
|
assert(n->vhost_started);
|
||||||
vhost_net_virtqueue_mask(tap_get_vhost_net(nc->peer),
|
vhost_net_virtqueue_mask(get_vhost_net(nc->peer),
|
||||||
vdev, idx, mask);
|
vdev, idx, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,4 +20,5 @@ void vhost_net_ack_features(VHostNetState *net, unsigned features);
|
||||||
bool vhost_net_virtqueue_pending(VHostNetState *net, int n);
|
bool vhost_net_virtqueue_pending(VHostNetState *net, int n);
|
||||||
void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
|
void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
|
||||||
int idx, bool mask);
|
int idx, bool mask);
|
||||||
|
VHostNetState *get_vhost_net(NetClientState *nc);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue