From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
To: qemu devel <qemu-devel@nongnu.org>,
Jason Wang <jasowang@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Cc: Li Zhijian <lizhijian@cn.fujitsu.com>,
Gui jianfeng <guijianfeng@cn.fujitsu.com>,
"eddie.dong" <eddie.dong@intel.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Huang peng <peter.huangpeng@huawei.com>,
Gong lei <arei.gonglei@huawei.com>,
jan.kiszka@siemens.com,
Zhang Chen <zhangchen.fnst@cn.fujitsu.com>,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: [Qemu-devel] [RFC PATCH 5/9] net/colo-proxy: add colo packet handler
Date: Fri, 27 Nov 2015 20:27:27 +0800 [thread overview]
Message-ID: <1448627251-11186-6-git-send-email-zhangchen.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1448627251-11186-1-git-send-email-zhangchen.fnst@cn.fujitsu.com>
From: zhangchen <zhangchen.fnst@cn.fujitsu.com>
add primary and secondary handler
Signed-off-by: zhangchen <zhangchen.fnst@cn.fujitsu.com>
---
net/colo-proxy.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 103 insertions(+), 2 deletions(-)
diff --git a/net/colo-proxy.c b/net/colo-proxy.c
index 89d9616..ece5661 100644
--- a/net/colo-proxy.c
+++ b/net/colo-proxy.c
@@ -25,6 +25,101 @@
static char *mode;
static bool colo_do_checkpoint;
+/*
+ * colo primary handle host's normal send and
+ * recv packets to primary guest
+ * return: >= 0 success
+ * < 0 failed
+ */
+static ssize_t colo_proxy_primary_handler(NetFilterState *nf,
+ NetClientState *sender,
+ unsigned flags,
+ const struct iovec *iov,
+ int iovcnt,
+ NetPacketSent *sent_cb)
+{
+ ssize_t ret = 0;
+ int direction;
+
+ if (sender == nf->netdev) {
+ /* This packet is sent by netdev itself */
+ direction = NET_FILTER_DIRECTION_TX;
+ } else {
+ direction = NET_FILTER_DIRECTION_RX;
+ }
+ /*
+ * if packet's direction=rx
+ * enqueue packets to primary queue
+ * and wait secondary queue to compare
+ * if packet's direction=tx
+ * enqueue packets then send packets to
+ * secondary and flush queued packets
+ */
+
+ if (colo_do_checkpoint) {
+ colo_proxy_do_checkpoint(nf);
+ }
+
+ if (direction == NET_FILTER_DIRECTION_RX) {
+ /* TODO: enqueue_primary_packet */
+ } else {
+ /* TODO: forward packets to another */
+ }
+
+ return ret;
+}
+
+/*
+ * colo secondary handle host's normal send and
+ * recv packets to secondary guest
+ * return: >= 0 success
+ * < 0 failed
+ */
+static ssize_t colo_proxy_secondary_handler(NetFilterState *nf,
+ NetClientState *sender,
+ unsigned flags,
+ const struct iovec *iov,
+ int iovcnt,
+ NetPacketSent *sent_cb)
+{
+ ColoProxyState *s = FILTER_COLO_PROXY(nf);
+ int direction;
+ ssize_t ret = 0;
+
+ if (sender == nf->netdev) {
+ /* This packet is sent by netdev itself */
+ direction = NET_FILTER_DIRECTION_TX;
+ } else {
+ direction = NET_FILTER_DIRECTION_RX;
+ }
+ /*
+ * if packet's direction=rx
+ * enqueue packets and send to
+ * primary QEMU
+ * if packet's direction=tx
+ * record PVM's packet inital seq & adjust
+ * client's ack,send adjusted packets to SVM(next version will be do)
+ */
+
+ if (direction == NET_FILTER_DIRECTION_RX) {
+ if (colo_has_failover(nf)) {
+ qemu_net_queue_send_iov(s->incoming_queue, sender, flags, iov,
+ iovcnt, NULL);
+ return 1;
+ } else {
+ /* TODO: forward packets to another */
+ }
+
+ } else {
+ if (colo_has_failover(nf)) {
+ qemu_net_queue_send_iov(s->incoming_queue, sender, flags, iov,
+ iovcnt, NULL);
+ }
+ return 1;
+ }
+ return ret;
+}
+
static ssize_t colo_proxy_receive_iov(NetFilterState *nf,
NetClientState *sender,
unsigned flags,
@@ -38,10 +133,16 @@ static ssize_t colo_proxy_receive_iov(NetFilterState *nf,
*
*/
ColoProxyState *s = FILTER_COLO_PROXY(nf);
+ ssize_t ret = 0;
if (s->colo_mode == COLO_PRIMARY_MODE) {
- /* colo_proxy_primary_handler */
+ ret = colo_proxy_primary_handler(nf, sender, flags,
+ iov, iovcnt, sent_cb);
} else {
- /* colo_proxy_primary_handler */
+ ret = colo_proxy_secondary_handler(nf, sender, flags,
+ iov, iovcnt, sent_cb);
+ }
+ if (ret < 0) {
+ DEBUG("colo_proxy_receive_iov running failed\n");
}
return iov_size(iov, iovcnt);
}
--
1.9.1
next prev parent reply other threads:[~2015-11-27 12:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-27 12:27 [Qemu-devel] [RFC PATCH 0/9] Add colo-proxy based on netfilter Zhang Chen
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 1/9] Init colo-proxy object " Zhang Chen
2015-11-30 2:50 ` Wen Congyang
2015-11-30 5:38 ` Zhang Chen
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 2/9] jhash: add linux kernel jhashtable in qemu Zhang Chen
2015-12-01 11:23 ` Dr. David Alan Gilbert
2015-12-03 3:40 ` Zhang Chen
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 3/9] colo-proxy: add colo-proxy framework Zhang Chen
2015-11-28 2:46 ` Hailiang Zhang
2015-11-30 2:25 ` Zhang Chen
2015-11-30 3:10 ` Wen Congyang
2015-11-30 5:44 ` Zhang Chen
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 4/9] colo-proxy: add colo-proxy setup work Zhang Chen
2015-11-28 3:02 ` Hailiang Zhang
2015-11-30 2:35 ` Zhang Chen
2015-12-01 15:35 ` Dr. David Alan Gilbert
2015-12-03 3:49 ` Zhang Chen
2015-11-27 12:27 ` Zhang Chen [this message]
2015-11-28 3:17 ` [Qemu-devel] [RFC PATCH 5/9] net/colo-proxy: add colo packet handler Hailiang Zhang
2015-11-30 5:37 ` Zhang Chen
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 6/9] net/colo-proxy: add packet forward function Zhang Chen
2015-12-01 15:50 ` Dr. David Alan Gilbert
2015-12-03 6:17 ` Zhang Chen
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 7/9] net/colo-proxy: add packet enqueue and handle function Zhang Chen
2015-12-01 16:12 ` Dr. David Alan Gilbert
2015-12-03 6:35 ` Zhang Chen
2015-12-03 9:09 ` Dr. David Alan Gilbert
2015-12-04 3:21 ` Zhang Chen
2015-12-04 9:14 ` Dr. David Alan Gilbert
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 8/9] net/colo-proxy: enqueue primary and secondary packet Zhang Chen
2015-11-27 12:27 ` [Qemu-devel] [RFC PATCH 9/9] net/colo-proxy: add packet compare and notify checkpoint Zhang Chen
2015-12-01 16:37 ` Dr. David Alan Gilbert
2015-12-03 7:10 ` Zhang Chen
2015-12-01 16:44 ` [Qemu-devel] [RFC PATCH 0/9] Add colo-proxy based on netfilter Dr. David Alan Gilbert
2015-12-03 7:33 ` Zhang Chen
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=1448627251-11186-6-git-send-email-zhangchen.fnst@cn.fujitsu.com \
--to=zhangchen.fnst@cn.fujitsu.com \
--cc=arei.gonglei@huawei.com \
--cc=dgilbert@redhat.com \
--cc=eddie.dong@intel.com \
--cc=guijianfeng@cn.fujitsu.com \
--cc=jan.kiszka@siemens.com \
--cc=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=peter.huangpeng@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=zhang.zhanghailiang@huawei.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).