[CRIU] [PATCH 1/2] libcriu: Introduce the criu_dump_iters() call

Pavel Emelyanov xemul at parallels.com
Thu Jun 26 08:44:46 PDT 2014


Perform dumping but with preliminary iterations. Each
time an iteration ends the ->more callback is called.
The callback's return value is
  - positive -- one more iteration starts
  - zero     -- final dump is performed and call exits
  - negative -- dump is aborted, the value is returned
    back from criu_dump_iters

Inside callback one may (well, should) call criu_set_
function to alter the details of next iterations. In
particluar, then prev and next images directories should
be changed.

The @pi argument is an opaque value that caller may
use to request pre-dump statistics (not yet implemented).

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 lib/criu.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/criu.h | 15 +++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/lib/criu.c b/lib/criu.c
index 76394a8..2d1d5ce 100644
--- a/lib/criu.c
+++ b/lib/criu.c
@@ -476,6 +476,70 @@ exit:
 	return ret;
 }
 
+int criu_dump_iters(int (*more)(criu_predump_info pi))
+{
+	int ret = -1, fd = -1, uret;
+	CriuReq req	= CRIU_REQ__INIT;
+	CriuResp *resp	= NULL;
+
+	saved_errno = 0;
+
+	req.type	= CRIU_REQ_TYPE__PRE_DUMP;
+	req.opts	= opts;
+
+	ret = -EINVAL;
+	/*
+	 * Self-dump in iterable manner is tricky and
+	 * not supported for the moment.
+	 *
+	 * Calls w/o iteration callback is, well, not
+	 * allowed either.
+	 */
+	if (!opts->has_pid || !more)
+		goto exit;
+
+	ret = -ECONNREFUSED;
+	fd = criu_connect();
+	if (fd < 0)
+		goto exit;
+
+	while (1) {
+		ret = send_req_and_recv_resp_sk(fd, &req, &resp);
+		if (ret)
+			goto exit;
+
+		if (!resp->success) {
+			ret = -EBADE;
+			goto exit;
+		}
+
+		uret = more(NULL);
+		if (uret < 0) {
+			ret = uret;
+			goto exit;
+		}
+
+		criu_resp__free_unpacked(resp, NULL);
+
+		if (uret == 0)
+			break;
+	}
+
+	req.type = CRIU_REQ_TYPE__DUMP;
+	ret = send_req_and_recv_resp_sk(fd, &req, &resp);
+	if (!ret)
+		ret = (resp->success ? 0 : -EBADE);
+exit:
+	if (fd >= 0)
+		close(fd);
+	if (resp)
+		criu_resp__free_unpacked(resp, NULL);
+
+	errno = saved_errno;
+
+	return ret;
+}
+
 int criu_restore(void)
 {
 	int ret = -1;
diff --git a/lib/criu.h b/lib/criu.h
index 4591519..18faaef 100644
--- a/lib/criu.h
+++ b/lib/criu.h
@@ -91,4 +91,19 @@ int criu_dump(void);
 int criu_restore(void);
 int criu_restore_child(void);
 
+/*
+ * Perform dumping but with preliminary iterations. Each
+ * time an iteration ends the ->more callback is called.
+ * The callback's return value is
+ *   - positive -- one more iteration starts
+ *   - zero     -- final dump is performed and call exits
+ *   - negative -- dump is aborted, the value is returned
+ *     back from criu_dump_iters
+ *
+ * The @pi argument is an opaque value that caller may
+ * use to request pre-dump statistics (not yet implemented).
+ */
+typedef void *criu_predump_info;
+int criu_dump_iters(int (*more)(criu_predump_info pi));
+
 #endif /* __CRIU_LIB_H__ */
-- 
1.8.4.2




More information about the CRIU mailing list