From: Yang Hongyang Subject: [PATCH V9 08/12] remus: implement the API to buffer/release packages Date: Tue, 15 Apr 2014 13:38:16 +0800 Message-ID: <1397540297-32184-9-git-send-email-yanghy@cn.fujitsu.com> References: <1397540297-32184-1-git-send-email-yanghy@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1397540297-32184-1-git-send-email-yanghy@cn.fujitsu.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: ian.campbell@citrix.com, wency@cn.fujitsu.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, yunhong.jiang@intel.com, ian.jackson@eu.citrix.com, eddie.dong@intel.com, rshriram@cs.ubc.ca, roger.pau@citrix.com, laijs@cn.fujitsu.com List-Id: xen-devel@lists.xenproject.org From: Shriram Rajagopalan This patch implements two APIs: 1. netbuf_start_new_epoch() It marks a new epoch. The packages before this epoch will be flushed, and the packages after this epoch will be buffered. It will be called after the guest is suspended. 2. netbuf_release_prev_epoch() It flushes the buffered packages to client, and it will be called when a checkpoint finishes. Signed-off-by: Shriram Rajagopalan Signed-off-by: Lai Jiangshan Reviewed-by: Wen Congyang --- tools/libxl/libxl_netbuffer.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tools/libxl/libxl_netbuffer.c b/tools/libxl/libxl_netbuffer.c index a5f2b9a..4b4bc9d 100644 --- a/tools/libxl/libxl_netbuffer.c +++ b/tools/libxl/libxl_netbuffer.c @@ -416,9 +416,66 @@ static int nic_teardown(libxl__remus_device *remus_dev, return REMUS_INPROGRESS; } +/* The buffer_op's value, not the value passed to kernel */ +enum { + tc_buffer_start, + tc_buffer_release +}; + +static int remus_netbuf_op(libxl__remus_device_nic *remus_nic, + libxl__remus_netbuf_state *netbuf_state, + int buffer_op) +{ + int ret; + + STATE_AO_GC(netbuf_state->ao); + + if (buffer_op == tc_buffer_start) + ret = rtnl_qdisc_plug_buffer(remus_nic->qdisc); + else + ret = rtnl_qdisc_plug_release_one(remus_nic->qdisc); + + if (!ret) { + ret = rtnl_qdisc_add(netbuf_state->nlsock, + remus_nic->qdisc, + NLM_F_REQUEST); + if (ret) + goto out; + } + + return REMUS_OK; + +out: + LOG(ERROR, "Remus: cannot do netbuf op %s on %s:%s", + ((buffer_op == tc_buffer_start) ? + "start_new_epoch" : "release_prev_epoch"), + remus_nic->ifb, nl_geterror(ret)); + return REMUS_FAIL; +} + +static int netbuf_start_new_epoch(libxl__remus_device *remus_dev) +{ + libxl__remus_device_nic *remus_nic = + CONTAINER_OF(remus_dev, *remus_nic, remus_dev); + libxl__remus_netbuf_state *netbuf_state = remus_dev->dev_type->data; + + return remus_netbuf_op(remus_nic, netbuf_state, tc_buffer_start); +} + +static int netbuf_release_prev_epoch(libxl__remus_device *remus_dev) +{ + libxl__remus_device_nic *remus_nic = + CONTAINER_OF(remus_dev, *remus_nic, remus_dev); + libxl__remus_netbuf_state *netbuf_state = remus_dev->dev_type->data; + + return remus_netbuf_op(remus_nic, netbuf_state, tc_buffer_release); +} + libxl__remus_device_type remus_device_nic = { .init = nic_init, .destroy = nic_destroy, + .postsuspend = netbuf_start_new_epoch, + .commit = netbuf_release_prev_epoch, .match = nic_match, .setup = nic_setup, .teardown = nic_teardown, -- 1.8.3.2