qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Vladislav Yasevich <vyasevic@redhat.com>,
	Jason Wang <jasowang@redhat.com>
Subject: [Qemu-devel] [PULL V2 10/13] virtio-net: Allow qemu_announce_self to trigger virtio announcements
Date: Tue,  5 Mar 2019 15:12:17 +0800	[thread overview]
Message-ID: <1551769940-22739-11-git-send-email-jasowang@redhat.com> (raw)
In-Reply-To: <1551769940-22739-1-git-send-email-jasowang@redhat.com>

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Expose the virtio-net self announcement capability and allow
qemu_announce_self() to call it.

These announces are caused by something external (i.e. the
announce-self command); they won't trigger if the migration
counter is triggering announces at the same time.

Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/net/trace-events |  1 +
 hw/net/virtio-net.c | 35 ++++++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/hw/net/trace-events b/hw/net/trace-events
index b237d90..3a86004 100644
--- a/hw/net/trace-events
+++ b/hw/net/trace-events
@@ -361,6 +361,7 @@ sunhme_rx_desc(uint32_t addr, int offset, uint32_t status, int len, int cr, int
 sunhme_rx_xsum_calc(uint16_t xsum) "calculated incoming xsum as 0x%x"
 
 # hw/net/virtio-net.c
+virtio_net_announce_notify(void) ""
 virtio_net_announce_timer(int round) "%d"
 virtio_net_handle_announce(int round) "%d"
 virtio_net_post_load_device(void)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 38b8974..7e2c2a6 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -150,15 +150,42 @@ 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_notify(VirtIONet *net)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(net);
+    trace_virtio_net_announce_notify();
+
+    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);
     trace_virtio_net_announce_timer(n->announce_timer.round);
 
     n->announce_timer.round--;
-    n->status |= VIRTIO_NET_S_ANNOUNCE;
-    virtio_notify_config(vdev);
+    virtio_net_announce_notify(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_notify(n);
+    }
 }
 
 static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
@@ -2556,6 +2583,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)
@@ -2692,6 +2720,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     qemu_announce_timer_reset(&n->announce_timer, migrate_announce_params(),
                               QEMU_CLOCK_VIRTUAL,
                               virtio_net_announce_timer, n);
+    n->announce_timer.round = 0;
 
     if (n->netclient_type) {
         /*
-- 
2.5.0

  parent reply	other threads:[~2019-03-05  7:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05  7:12 [Qemu-devel] [PULL V2 00/13] Net patches Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 01/13] net/colo-compare.c: Remove duplicated code Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 02/13] net: netmap: small improvements netmap_send() Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 03/13] net: netmap: simplify netmap_receive() Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 04/13] net: netmap: improve netmap_receive_iov() Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 05/13] net: Introduce announce timer Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 06/13] migration: Add announce parameters Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 07/13] virtio-net: Switch to using announce timer Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 08/13] migration: " Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 09/13] net: Add a network device specific self-announcement ability Jason Wang
2019-03-05  7:12 ` Jason Wang [this message]
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 11/13] qmp: Add announce-self command Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 12/13] hmp: Add hmp_announce_self Jason Wang
2019-03-05  7:12 ` [Qemu-devel] [PULL V2 13/13] tests: Add a test for qemu self announcements Jason Wang
2019-03-05 11:21 ` [Qemu-devel] [PULL V2 00/13] Net patches Peter Maydell
2019-03-06  6:08   ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1551769940-22739-11-git-send-email-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vyasevic@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).