[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 16/25] filter-rewriter: handle checkpoint and failove
From: |
Jason Wang |
Subject: |
[Qemu-devel] [PULL 16/25] filter-rewriter: handle checkpoint and failover event |
Date: |
Wed, 26 Sep 2018 11:16:41 +0800 |
From: Zhang Chen <address@hidden>
After one round of checkpoint, the states between PVM and SVM
become consistent, so it is unnecessary to adjust the sequence
of net packets for old connections, besides, while failover
happens, filter-rewriter will into failover mode that needn't
handle the new TCP connection.
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Zhang Chen <address@hidden>
Signed-off-by: Zhang Chen <address@hidden>
Signed-off-by: Jason Wang <address@hidden>
---
net/colo-compare.c | 12 ++++-----
net/colo.c | 8 ++++++
net/colo.h | 2 ++
net/filter-rewriter.c | 57 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/net/colo-compare.c b/net/colo-compare.c
index 3f7e240590..a39191d522 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -116,6 +116,12 @@ enum {
SECONDARY_IN,
};
+static void colo_compare_inconsistency_notify(void)
+{
+ notifier_list_notify(&colo_compare_notifiers,
+ migrate_get_current());
+}
+
static int compare_chr_send(CompareState *s,
const uint8_t *buf,
uint32_t size,
@@ -330,12 +336,6 @@ static bool colo_mark_tcp_pkt(Packet *ppkt, Packet *spkt,
return false;
}
-static void colo_compare_inconsistency_notify(void)
-{
- notifier_list_notify(&colo_compare_notifiers,
- migrate_get_current());
-}
-
static void colo_compare_tcp(CompareState *s, Connection *conn)
{
Packet *ppkt = NULL, *spkt = NULL;
diff --git a/net/colo.c b/net/colo.c
index 97c8fc928f..49176bf07b 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -221,3 +221,11 @@ Connection *connection_get(GHashTable
*connection_track_table,
return conn;
}
+
+bool connection_has_tracked(GHashTable *connection_track_table,
+ ConnectionKey *key)
+{
+ Connection *conn = g_hash_table_lookup(connection_track_table, key);
+
+ return conn ? true : false;
+}
diff --git a/net/colo.h b/net/colo.h
index 0277e0e9ba..11c5226488 100644
--- a/net/colo.h
+++ b/net/colo.h
@@ -98,6 +98,8 @@ void connection_destroy(void *opaque);
Connection *connection_get(GHashTable *connection_track_table,
ConnectionKey *key,
GQueue *conn_list);
+bool connection_has_tracked(GHashTable *connection_track_table,
+ ConnectionKey *key);
void connection_hashtable_reset(GHashTable *connection_track_table);
Packet *packet_new(const void *data, int size, int vnet_hdr_len);
void packet_destroy(void *opaque, void *user_data);
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index dd323faf61..bb8f4d93b1 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -20,11 +20,15 @@
#include "qemu/main-loop.h"
#include "qemu/iov.h"
#include "net/checksum.h"
+#include "net/colo.h"
+#include "migration/colo.h"
#define FILTER_COLO_REWRITER(obj) \
OBJECT_CHECK(RewriterState, (obj), TYPE_FILTER_REWRITER)
#define TYPE_FILTER_REWRITER "filter-rewriter"
+#define FAILOVER_MODE_ON true
+#define FAILOVER_MODE_OFF false
typedef struct RewriterState {
NetFilterState parent_obj;
@@ -32,8 +36,14 @@ typedef struct RewriterState {
/* hashtable to save connection */
GHashTable *connection_track_table;
bool vnet_hdr;
+ bool failover_mode;
} RewriterState;
+static void filter_rewriter_failover_mode(RewriterState *s)
+{
+ s->failover_mode = FAILOVER_MODE_ON;
+}
+
static void filter_rewriter_flush(NetFilterState *nf)
{
RewriterState *s = FILTER_COLO_REWRITER(nf);
@@ -273,6 +283,13 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState
*nf,
*/
reverse_connection_key(&key);
}
+
+ /* After failover we needn't change new TCP packet */
+ if (s->failover_mode &&
+ !connection_has_tracked(s->connection_track_table, &key)) {
+ goto out;
+ }
+
conn = connection_get(s->connection_track_table,
&key,
NULL);
@@ -306,11 +323,49 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState
*nf,
}
}
+out:
packet_destroy(pkt, NULL);
pkt = NULL;
return 0;
}
+static void reset_seq_offset(gpointer key, gpointer value, gpointer user_data)
+{
+ Connection *conn = (Connection *)value;
+
+ conn->offset = 0;
+}
+
+static gboolean offset_is_nonzero(gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ Connection *conn = (Connection *)value;
+
+ return conn->offset ? true : false;
+}
+
+static void colo_rewriter_handle_event(NetFilterState *nf, int event,
+ Error **errp)
+{
+ RewriterState *rs = FILTER_COLO_REWRITER(nf);
+
+ switch (event) {
+ case COLO_EVENT_CHECKPOINT:
+ g_hash_table_foreach(rs->connection_track_table,
+ reset_seq_offset, NULL);
+ break;
+ case COLO_EVENT_FAILOVER:
+ if (!g_hash_table_find(rs->connection_track_table,
+ offset_is_nonzero, NULL)) {
+ filter_rewriter_failover_mode(rs);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
static void colo_rewriter_cleanup(NetFilterState *nf)
{
RewriterState *s = FILTER_COLO_REWRITER(nf);
@@ -354,6 +409,7 @@ static void filter_rewriter_init(Object *obj)
RewriterState *s = FILTER_COLO_REWRITER(obj);
s->vnet_hdr = false;
+ s->failover_mode = FAILOVER_MODE_OFF;
object_property_add_bool(obj, "vnet_hdr_support",
filter_rewriter_get_vnet_hdr,
filter_rewriter_set_vnet_hdr, NULL);
@@ -366,6 +422,7 @@ static void colo_rewriter_class_init(ObjectClass *oc, void
*data)
nfc->setup = colo_rewriter_setup;
nfc->cleanup = colo_rewriter_cleanup;
nfc->receive_iov = colo_rewriter_receive_iov;
+ nfc->handle_event = colo_rewriter_handle_event;
}
static const TypeInfo colo_rewriter_info = {
--
2.17.1
- [Qemu-devel] [PULL 20/25] clean up callback when del virtqueue, (continued)
- [Qemu-devel] [PULL 20/25] clean up callback when del virtqueue, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 14/25] COLO: flush host dirty ram from cache, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 21/25] ne2000: fix possible out of bound access in ne2000_receive, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 17/25] COLO: notify net filters about checkpoint/failover event, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 18/25] COLO: quick failover process by kick COLO thread, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 13/25] savevm: split the process of different stages for loadvm/savevm, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 15/25] filter: Add handle_event method for NetFilterClass, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 11/25] qapi/migration.json: Rename COLO unknown mode to none mode., Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 05/25] COLO: Add block replication into colo process, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 07/25] COLO: Load dirty pages into SVM's RAM cache firstly, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 16/25] filter-rewriter: handle checkpoint and failover event,
Jason Wang <=
- [Qemu-devel] [PULL 12/25] qapi: Add new command to query colo status, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 10/25] qmp event: Add COLO_EXIT event to notify users while exited COLO, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 09/25] COLO: Flush memory data from ram cache, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 08/25] ram/COLO: Record the dirty pages that SVM received, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 01/25] filter-rewriter: Add TCP state machine and fix memory leak in connection_track_table, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 04/25] COLO: integrate colo compare with colo frame, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 03/25] colo-compare: use notifier to notify packets comparing result, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 02/25] colo-compare: implement the process of checkpoint, Jason Wang, 2018/09/25
- [Qemu-devel] [PULL 06/25] COLO: Remove colo_state migration struct, Jason Wang, 2018/09/25