diff mbox

[05/12] virtio-net: Allow qemu_announce_self to trigger virtio announcements

Message ID 1495649128-10529-6-git-send-email-vyasevic@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Vlad Yasevich May 24, 2017, 6:05 p.m. UTC
Expose the virtio-net self annoucement capability and allow
qemu_announce_self() to call it.

Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
---
 hw/net/virtio-net.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

Comments

Jason Wang May 26, 2017, 4:21 a.m. UTC | #1
On 2017年05月25日 02:05, Vladislav Yasevich wrote:
> Expose the virtio-net self annoucement capability and allow
> qemu_announce_self() to call it.
>
> Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
> ---
>   hw/net/virtio-net.c | 32 +++++++++++++++++++++++++++++---
>   1 file changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 1c65825..4adafbd 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -111,14 +111,38 @@ static bool virtio_net_started(VirtIONet *n, uint8_t status)
>           (n->status & VIRTIO_NET_S_LINK_UP) && vdev->vm_running;
>   }
>   
> +static void __virtio_net_announce(VirtIONet *net)
> +{
> +    VirtIODevice *vdev = VIRTIO_DEVICE(net);
> +
> +    net->status |= VIRTIO_NET_S_ANNOUNCE;
> +    virtio_notify_config(vdev);
> +}
> +
>   static void virtio_net_announce_timer(void *opaque)
>   {
>       VirtIONet *n = opaque;
> -    VirtIODevice *vdev = VIRTIO_DEVICE(n);
>   
>       n->announce_timer->round--;
> -    n->status |= VIRTIO_NET_S_ANNOUNCE;
> -    virtio_notify_config(vdev);
> +    __virtio_net_announce(n);
> +}
> +
> +static void virtio_net_announce(NetClientState *nc)
> +{
> +    VirtIONet *n = qemu_get_nic_opaque(nc);
> +    VirtIODevice *vdev = VIRTIO_DEVICE(n);
> +
> +    /* Make sure the virtio migration announcement timer isn't running
> +     * If it is, let it trigger announcement so that we do not cause
> +     * confusion.
> +     */
> +    if (n->announce_timer->round)
> +        return;
> +
> +    if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
> +        virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
> +            __virtio_net_announce(n);
> +    }
>   }
>   
>   static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
> @@ -1834,6 +1858,7 @@ static NetClientInfo net_virtio_info = {
>       .receive = virtio_net_receive,
>       .link_status_changed = virtio_net_set_link_status,
>       .query_rx_filter = virtio_net_query_rxfilter,
> +    .announce = virtio_net_announce,
>   };
>   
>   static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx)
> @@ -1941,6 +1966,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
>       n->status = VIRTIO_NET_S_LINK_UP;
>       n->announce_timer = qemu_announce_timer_new(qemu_get_announce_params(),
>                                                   QEMU_CLOCK_VIRTUAL);
> +    n->announce_timer->round = 0;
>       n->announce_timer->tm = timer_new_ms(QEMU_CLOCK_VIRTUAL,
>                                             virtio_net_announce_timer, n);
>   

Reviewed-by: Jason Wang <jasowang@redhat.com>
diff mbox

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1c65825..4adafbd 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -111,14 +111,38 @@  static bool virtio_net_started(VirtIONet *n, uint8_t status)
         (n->status & VIRTIO_NET_S_LINK_UP) && vdev->vm_running;
 }
 
+static void __virtio_net_announce(VirtIONet *net)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(net);
+
+    net->status |= VIRTIO_NET_S_ANNOUNCE;
+    virtio_notify_config(vdev);
+}
+
 static void virtio_net_announce_timer(void *opaque)
 {
     VirtIONet *n = opaque;
-    VirtIODevice *vdev = VIRTIO_DEVICE(n);
 
     n->announce_timer->round--;
-    n->status |= VIRTIO_NET_S_ANNOUNCE;
-    virtio_notify_config(vdev);
+    __virtio_net_announce(n);
+}
+
+static void virtio_net_announce(NetClientState *nc)
+{
+    VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
+
+    /* Make sure the virtio migration announcement timer isn't running
+     * If it is, let it trigger announcement so that we do not cause
+     * confusion.
+     */
+    if (n->announce_timer->round)
+        return;
+
+    if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
+        virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
+            __virtio_net_announce(n);
+    }
 }
 
 static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
@@ -1834,6 +1858,7 @@  static NetClientInfo net_virtio_info = {
     .receive = virtio_net_receive,
     .link_status_changed = virtio_net_set_link_status,
     .query_rx_filter = virtio_net_query_rxfilter,
+    .announce = virtio_net_announce,
 };
 
 static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx)
@@ -1941,6 +1966,7 @@  static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     n->status = VIRTIO_NET_S_LINK_UP;
     n->announce_timer = qemu_announce_timer_new(qemu_get_announce_params(),
                                                 QEMU_CLOCK_VIRTUAL);
+    n->announce_timer->round = 0;
     n->announce_timer->tm = timer_new_ms(QEMU_CLOCK_VIRTUAL,
                                           virtio_net_announce_timer, n);