diff mbox

[v11,23/27] COLO proxy: preresume, postresume and checkpoint

Message ID 1457080891-26054-24-git-send-email-xiecl.fnst@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Changlong Xie March 4, 2016, 8:41 a.m. UTC
From: Wen Congyang <wency@cn.fujitsu.com>

preresume, postresume and checkpoint

Signed-off-by: Yang Hongyang <hongyang.yang@easystack.cn>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
---
 tools/libxl/libxl_colo.h       |  4 +++
 tools/libxl/libxl_colo_proxy.c | 62 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

Comments

Ian Jackson March 4, 2016, 6:01 p.m. UTC | #1
Changlong Xie writes ("[PATCH v11 23/27] COLO proxy: preresume, postresume and checkpoint"):
> From: Wen Congyang <wency@cn.fujitsu.com>
> 
> preresume, postresume and checkpoint

I think maybe this needs to be combined with the previous patch ?

I don't think I quite understand the structure of the patch series at
this point.

Ian.
Changlong Xie March 18, 2016, 8:20 a.m. UTC | #2
On 03/05/2016 02:01 AM, Ian Jackson wrote:
> Changlong Xie writes ("[PATCH v11 23/27] COLO proxy: preresume, postresume and checkpoint"):
>> From: Wen Congyang <wency@cn.fujitsu.com>
>>
>> preresume, postresume and checkpoint
>
> I think maybe this needs to be combined with the previous patch ?
>

Surely

Thanks
	-Xie

> I don't think I quite understand the structure of the patch series at
> this point.
>
> Ian.
>
>
> .
>
diff mbox

Patch

diff --git a/tools/libxl/libxl_colo.h b/tools/libxl/libxl_colo.h
index 9e7f99c..736927e 100644
--- a/tools/libxl/libxl_colo.h
+++ b/tools/libxl/libxl_colo.h
@@ -99,5 +99,9 @@  extern void libxl__colo_save_teardown(struct libxl__egc *egc,
                                       int rc);
 extern int colo_proxy_setup(libxl__colo_proxy_state *cps);
 extern void colo_proxy_teardown(libxl__colo_proxy_state *cps);
+extern void colo_proxy_preresume(libxl__colo_proxy_state *cps);
+extern void colo_proxy_postresume(libxl__colo_proxy_state *cps);
+extern int colo_proxy_checkpoint(libxl__colo_proxy_state *cps,
+                                 unsigned int timeout_us);
 
 #endif
diff --git a/tools/libxl/libxl_colo_proxy.c b/tools/libxl/libxl_colo_proxy.c
index 2b3baa3..1b1dd40 100644
--- a/tools/libxl/libxl_colo_proxy.c
+++ b/tools/libxl/libxl_colo_proxy.c
@@ -216,3 +216,65 @@  void colo_proxy_teardown(libxl__colo_proxy_state *cps)
         cps->sock_fd = -1;
     }
 }
+
+/* ========= colo-proxy: preresume, postresume and checkpoint ========== */
+
+void colo_proxy_preresume(libxl__colo_proxy_state *cps)
+{
+    colo_proxy_send(cps, NULL, 0, COLO_CHECKPOINT);
+    /* TODO: need to handle if the call fails... */
+}
+
+void colo_proxy_postresume(libxl__colo_proxy_state *cps)
+{
+    /* nothing to do... */
+}
+
+typedef struct colo_msg {
+    bool is_checkpoint;
+} colo_msg;
+
+/*
+ * Return value:
+ * -1: error
+ *  0: no checkpoint event is received before timeout
+ *  1: do checkpoint
+ */
+int colo_proxy_checkpoint(libxl__colo_proxy_state *cps,
+                          unsigned int timeout_us)
+{
+    uint8_t *buff;
+    int64_t size;
+    struct nlmsghdr *h;
+    struct colo_msg *m;
+    int ret = -1;
+
+    STATE_AO_GC(cps->ao);
+
+    size = colo_proxy_recv(cps, &buff, timeout_us);
+
+    /* timeout, return no checkpoint message. */
+    if (size <= 0) {
+        return 0;
+    }
+
+    h = (struct nlmsghdr *) buff;
+
+    if (h->nlmsg_type == NLMSG_ERROR) {
+        LOG(ERROR, "receive NLMSG_ERROR");
+        goto out;
+    }
+
+    if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*m))) {
+        LOG(ERROR, "NLMSG_LENGTH is too short");
+        goto out;
+    }
+
+    m = NLMSG_DATA(h);
+
+    ret = m->is_checkpoint ? 1 : 0;
+
+out:
+    free(buff);
+    return ret;
+}