qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, quintela@redhat.com, jasowang@redhat.com,
	mst@redhat.com, eblake@redhat.com, armbru@redhat.com,
	berrange@redhat.com
Subject: [Qemu-devel] [PATCH 1/9] net: Introduce announce timer
Date: Mon, 28 Jan 2019 17:03:13 +0000	[thread overview]
Message-ID: <20190128170321.16936-2-dgilbert@redhat.com> (raw)
In-Reply-To: <20190128170321.16936-1-dgilbert@redhat.com>

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

The 'announce timer' will be used by migration, and explicit
requests for qemu to perform network announces.

Based on the work by Germano Veit Michel <germano@redhat.com>
 and Vlad Yasevich <vyasevic@redhat.com>

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 include/net/announce.h  | 39 ++++++++++++++++++++++++++
 include/qemu/typedefs.h |  1 +
 migration/migration.c   |  1 +
 net/Makefile.objs       |  1 +
 net/announce.c          | 61 +++++++++++++++++++++++++++++++++++++++++
 qapi/net.json           | 23 ++++++++++++++++
 6 files changed, 126 insertions(+)
 create mode 100644 include/net/announce.h
 create mode 100644 net/announce.c

diff --git a/include/net/announce.h b/include/net/announce.h
new file mode 100644
index 0000000000..b89f1c28b5
--- /dev/null
+++ b/include/net/announce.h
@@ -0,0 +1,39 @@
+/*
+ *  Self-announce facility
+ *  (c) 2017-2019 Red Hat, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_NET_ANNOUNCE_H
+#define QEMU_NET_ANNOUNCE_H
+
+#include "qemu-common.h"
+#include "qapi/qapi-types-net.h"
+#include "qemu/timer.h"
+
+struct AnnounceTimer {
+    QEMUTimer *tm;
+    AnnounceParameters params;
+    QEMUClockType type;
+    int round;
+};
+
+/* Returns: update the timer to the next time point */
+int64_t qemu_announce_timer_step(AnnounceTimer *timer);
+
+/* Delete the underlying timer */
+void qemu_announce_timer_del(AnnounceTimer *timer);
+
+/*
+ * Under BQL/main thread
+ * Reset the timer to the given parameters/type/notifier.
+ */
+void qemu_announce_timer_reset(AnnounceTimer *timer,
+                               AnnounceParameters *params,
+                               QEMUClockType type,
+                               QEMUTimerCB *cb,
+                               void *opaque);
+
+#endif
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 5d1a2d8329..e4a0a656d1 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -8,6 +8,7 @@
 typedef struct AdapterInfo AdapterInfo;
 typedef struct AddressSpace AddressSpace;
 typedef struct AioContext AioContext;
+typedef struct AnnounceTimer AnnounceTimer;
 typedef struct BdrvDirtyBitmap BdrvDirtyBitmap;
 typedef struct BdrvDirtyBitmapIter BdrvDirtyBitmapIter;
 typedef struct BlockBackend BlockBackend;
diff --git a/migration/migration.c b/migration/migration.c
index 37e06b76dc..a9c4c6f01d 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -45,6 +45,7 @@
 #include "migration/colo.h"
 #include "hw/boards.h"
 #include "monitor/monitor.h"
+#include "net/announce.h"
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration transfer speed throttling */
 
diff --git a/net/Makefile.objs b/net/Makefile.objs
index b2bf88a0ef..b363fe92d9 100644
--- a/net/Makefile.objs
+++ b/net/Makefile.objs
@@ -2,6 +2,7 @@ common-obj-y = net.o queue.o checksum.o util.o hub.o
 common-obj-y += socket.o
 common-obj-y += dump.o
 common-obj-y += eth.o
+common-obj-y += announce.o
 common-obj-$(CONFIG_L2TPV3) += l2tpv3.o
 common-obj-$(CONFIG_POSIX) += vhost-user.o
 common-obj-$(CONFIG_SLIRP) += slirp.o
diff --git a/net/announce.c b/net/announce.c
new file mode 100644
index 0000000000..a37089bf27
--- /dev/null
+++ b/net/announce.c
@@ -0,0 +1,61 @@
+/*
+ *  Self-announce
+ *  (c) 2017-2019 Red Hat, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "net/announce.h"
+#include "qapi/clone-visitor.h"
+#include "qapi/qapi-visit-net.h"
+
+int64_t qemu_announce_timer_step(AnnounceTimer *timer)
+{
+    int64_t step;
+
+    step =  timer->params.initial +
+            (timer->params.rounds - timer->round - 1) *
+            timer->params.step;
+
+    if (step < 0 || step > timer->params.max) {
+        step = timer->params.max;
+    }
+    timer_mod(timer->tm, qemu_clock_get_ms(timer->type) + step);
+
+    return step;
+}
+
+void qemu_announce_timer_del(AnnounceTimer *timer)
+{
+    if (timer->tm) {
+        timer_del(timer->tm);
+        timer_free(timer->tm);
+        timer->tm = NULL;
+    }
+}
+
+/*
+ * Under BQL/main thread
+ * Reset the timer to the given parameters/type/notifier.
+ */
+void qemu_announce_timer_reset(AnnounceTimer *timer,
+                               AnnounceParameters *params,
+                               QEMUClockType type,
+                               QEMUTimerCB *cb,
+                               void *opaque)
+{
+    /*
+     * We're under the BQL, so the current timer can't
+     * be firing, so we should be able to delete it.
+     */
+    qemu_announce_timer_del(timer);
+
+    QAPI_CLONE_MEMBERS(AnnounceParameters, &timer->params, params);
+    timer->round = params->rounds;
+    timer->type = type;
+    timer->tm = timer_new_ms(type, cb, opaque);
+}
+
diff --git a/qapi/net.json b/qapi/net.json
index a1a0f39f74..b9ff7617bd 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -684,3 +684,26 @@
 ##
 { 'event': 'NIC_RX_FILTER_CHANGED',
   'data': { '*name': 'str', 'path': 'str' } }
+
+##
+# @AnnounceParameters:
+#
+# Parameters for self-announce timers
+#
+# @initial: Initial delay (in ms) before sending the first GARP/RARP
+#       announcement
+#
+# @max: Maximum delay (in ms) to between GARP/RARP announcement packets
+#
+# @rounds: Number of self-announcement attempts
+#
+# @step: Delay increase (in ms) after each self-announcement attempt
+#
+# Since: 4.0
+##
+
+{ 'struct': 'AnnounceParameters',
+  'data': { 'initial': 'int',
+            'max': 'int',
+            'rounds': 'int',
+            'step': 'int' } }
-- 
2.20.1

  reply	other threads:[~2019-01-28 17:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28 17:03 [Qemu-devel] [PATCH 0/9] Network announce changes Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` Dr. David Alan Gilbert (git) [this message]
2019-01-28 17:42   ` [Qemu-devel] [PATCH 1/9] net: Introduce announce timer Eric Blake
2019-01-29 11:27     ` Dr. David Alan Gilbert
2019-01-28 17:03 ` [Qemu-devel] [PATCH 2/9] migration: Add announce parameters Dr. David Alan Gilbert (git)
2019-01-28 17:45   ` Eric Blake
2019-01-29 11:34     ` Dr. David Alan Gilbert
2019-02-01 18:17   ` Markus Armbruster
2019-02-04 11:48     ` Dr. David Alan Gilbert
2019-01-28 17:03 ` [Qemu-devel] [PATCH 3/9] virtio-net: Switch to using announce timer Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 4/9] migration: " Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 5/9] net: Add a network device specific self-announcement ability Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 6/9] virtio-net: Allow qemu_announce_self to trigger virtio announcements Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 7/9] qmp: Add announce-self command Dr. David Alan Gilbert (git)
2019-01-28 17:47   ` Eric Blake
2019-01-29 11:42     ` Dr. David Alan Gilbert
2019-01-28 17:03 ` [Qemu-devel] [PATCH 8/9] hmp: Add hmp_announce_self Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 9/9] tests: Add a test for qemu self announcments Dr. David Alan Gilbert (git)
2019-01-28 17:05   ` Michael S. Tsirkin
2019-01-29 10:45     ` Dr. David Alan Gilbert
2019-01-28 17:12 ` [Qemu-devel] [PATCH 0/9] Network announce changes Michael S. Tsirkin
2019-01-28 17:25   ` Dr. David Alan Gilbert
2019-02-01 18:07 ` Markus Armbruster
2019-02-04 11:19   ` Dr. David Alan Gilbert
2019-02-03 15:52 ` no-reply

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=20190128170321.16936-2-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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).