From: zhanghailiang <zhang.zhanghailiang@huawei.com>
To: qemu-devel@nongnu.org, dgilbert@redhat.com
Cc: quintela@redhat.com, zhangchen.fnst@cn.fujitsu.com,
zhanghailiang <zhang.zhanghailiang@huawei.com>,
Jason Wang <jasowang@redhat.com>,
Li Zhijian <lizhijian@cn.fujitsu.com>
Subject: [Qemu-devel] [PATCH RESEND v2 01/18] net/colo: Add notifier/callback related helpers for filter
Date: Sat, 22 Apr 2017 16:35:11 +0800 [thread overview]
Message-ID: <1492850128-17472-2-git-send-email-zhang.zhanghailiang@huawei.com> (raw)
In-Reply-To: <1492850128-17472-1-git-send-email-zhang.zhanghailiang@huawei.com>
We will use this notifier to help COLO to notify filter object
to do something, like do checkpoint, or process failover event.
Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
net/colo.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
net/colo.h | 19 +++++++++++
2 files changed, 124 insertions(+)
diff --git a/net/colo.c b/net/colo.c
index 8cc166b..8aef670 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -15,6 +15,7 @@
#include "qemu/osdep.h"
#include "trace.h"
#include "net/colo.h"
+#include "qapi/error.h"
uint32_t connection_key_hash(const void *opaque)
{
@@ -209,3 +210,107 @@ Connection *connection_get(GHashTable *connection_track_table,
return conn;
}
+
+static gboolean
+filter_notify_prepare(GSource *source, gint *timeout)
+{
+ *timeout = -1;
+
+ return FALSE;
+}
+
+static gboolean
+filter_notify_check(GSource *source)
+{
+ FilterNotifier *notify = (FilterNotifier *)source;
+
+ return notify->pfd.revents & (G_IO_IN | G_IO_HUP | G_IO_ERR);
+}
+
+static gboolean
+filter_notify_dispatch(GSource *source,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ FilterNotifier *notify = (FilterNotifier *)source;
+ int revents;
+ uint64_t value;
+ int ret;
+
+ revents = notify->pfd.revents & notify->pfd.events;
+ if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) {
+ ret = filter_notifier_get(notify, &value);
+ if (notify->cb && !ret) {
+ notify->cb(notify, value);
+ }
+ }
+ return TRUE;
+}
+
+static void
+filter_notify_finalize(GSource *source)
+{
+ FilterNotifier *notify = (FilterNotifier *)source;
+
+ event_notifier_cleanup(¬ify->event);
+}
+
+static GSourceFuncs notifier_source_funcs = {
+ filter_notify_prepare,
+ filter_notify_check,
+ filter_notify_dispatch,
+ filter_notify_finalize,
+};
+
+FilterNotifier *filter_notifier_new(FilterNotifierCallback *cb,
+ void *opaque, Error **errp)
+{
+ FilterNotifier *notify;
+ int ret;
+
+ notify = (FilterNotifier *)g_source_new(¬ifier_source_funcs,
+ sizeof(FilterNotifier));
+ ret = event_notifier_init(¬ify->event, false);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Failed to initialize event notifier");
+ goto fail;
+ }
+ notify->pfd.fd = event_notifier_get_fd(¬ify->event);
+ notify->pfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
+ notify->cb = cb;
+ notify->opaque = opaque;
+ g_source_add_poll(¬ify->source, ¬ify->pfd);
+
+ return notify;
+
+fail:
+ g_source_destroy(¬ify->source);
+ return NULL;
+}
+
+int filter_notifier_set(FilterNotifier *notify, uint64_t value)
+{
+ ssize_t ret;
+
+ do {
+ ret = write(notify->event.wfd, &value, sizeof(value));
+ } while (ret < 0 && errno == EINTR);
+
+ /* EAGAIN is fine, a read must be pending. */
+ if (ret < 0 && errno != EAGAIN) {
+ return -errno;
+ }
+ return 0;
+}
+
+int filter_notifier_get(FilterNotifier *notify, uint64_t *value)
+{
+ ssize_t len;
+
+ /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
+ do {
+ len = read(notify->event.rfd, value, sizeof(*value));
+ } while ((len == -1 && errno == EINTR));
+
+ return len != sizeof(*value) ? -1 : 0;
+}
diff --git a/net/colo.h b/net/colo.h
index cd9027f..b586db3 100644
--- a/net/colo.h
+++ b/net/colo.h
@@ -19,6 +19,7 @@
#include "qemu/jhash.h"
#include "qemu/timer.h"
#include "slirp/tcp.h"
+#include "qemu/event_notifier.h"
#define HASHTABLE_MAX_SIZE 16384
@@ -89,4 +90,22 @@ void connection_hashtable_reset(GHashTable *connection_track_table);
Packet *packet_new(const void *data, int size);
void packet_destroy(void *opaque, void *user_data);
+typedef void FilterNotifierCallback(void *opaque, int value);
+typedef struct FilterNotifier {
+ GSource source;
+ EventNotifier event;
+ GPollFD pfd;
+ FilterNotifierCallback *cb;
+ void *opaque;
+} FilterNotifier;
+
+FilterNotifier *filter_notifier_new(FilterNotifierCallback *cb,
+ void *opaque, Error **errp);
+int filter_notifier_set(FilterNotifier *notify, uint64_t value);
+int filter_notifier_get(FilterNotifier *notify, uint64_t *value);
+
+enum {
+ COLO_CHECKPOINT = 2,
+ COLO_FAILOVER,
+};
#endif /* QEMU_COLO_PROXY_H */
--
1.8.3.1
next prev parent reply other threads:[~2017-04-22 8:36 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-22 8:35 [Qemu-devel] [PATCH RESEND v2 00/18] COLO: integrate colo frame with block replication and net compare zhanghailiang
2017-04-22 8:35 ` zhanghailiang [this message]
2017-04-25 11:40 ` [Qemu-devel] [PATCH RESEND v2 01/18] net/colo: Add notifier/callback related helpers for filter Jason Wang
2017-04-26 8:14 ` Hailiang Zhang
2017-04-26 9:14 ` Jason Wang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 02/18] colo-compare: implement the process of checkpoint zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 03/18] colo-compare: use notifier to notify packets comparing result zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 04/18] COLO: integrate colo compare with colo frame zhanghailiang
2017-04-24 18:18 ` Juan Quintela
2017-04-25 11:03 ` Hailiang Zhang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 05/18] COLO: Handle shutdown command for VM in COLO state zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 06/18] COLO: Add block replication into colo process zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 07/18] COLO: Load dirty pages into SVM's RAM cache firstly zhanghailiang
2017-04-24 18:27 ` Juan Quintela
2017-04-25 11:06 ` Hailiang Zhang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 08/18] ram/COLO: Record the dirty pages that SVM received zhanghailiang
2017-04-24 18:29 ` Juan Quintela
2017-04-25 11:19 ` Hailiang Zhang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 09/18] COLO: Flush memory data from ram cache zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 10/18] qmp event: Add COLO_EXIT event to notify users while exited COLO zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 11/18] savevm: split save/find loadvm_handlers entry into two helper functions zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 12/18] savevm: split the process of different stages for loadvm/savevm zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 13/18] COLO: Separate the process of saving/loading ram and device state zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 14/18] COLO: Split qemu_savevm_state_begin out of checkpoint process zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 15/18] COLO: flush host dirty ram from cache zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 16/18] filter: Add handle_event method for NetFilterClass zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 17/18] filter-rewriter: handle checkpoint and failover event zhanghailiang
2017-04-22 8:35 ` [Qemu-devel] [PATCH RESEND v2 18/18] COLO: notify net filters about checkpoint/failover event zhanghailiang
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=1492850128-17472-2-git-send-email-zhang.zhanghailiang@huawei.com \
--to=zhang.zhanghailiang@huawei.com \
--cc=dgilbert@redhat.com \
--cc=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=zhangchen.fnst@cn.fujitsu.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).