[CRIU] [PATCH] lib: Add start page-server support
Radostin Stoyanov
rstoyanov1 at gmail.com
Wed Feb 7 00:47:29 MSK 2018
Starting a page-server is already present in rpc, so lets add it to
libcriu too.
Usage Example:
#include <stdio.h>
#include <fcntl.h>
#include <criu/criu.h>
int main( void )
{
int dir_fd;
if ((dir_fd = open("/tmp/dump", O_DIRECTORY)) < 0) {
printf("Can't open images dir");
return -1;
}
criu_init_opts();
criu_set_images_dir_fd(dir_fd);
criu_start_page_server("0.0.0.0", 1234);
return 0;
}
Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
lib/c/criu.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
lib/c/criu.h | 2 ++
2 files changed, 49 insertions(+)
diff --git a/lib/c/criu.c b/lib/c/criu.c
index 08806c6e..e2ed8d2b 100644
--- a/lib/c/criu.c
+++ b/lib/c/criu.c
@@ -1396,3 +1396,50 @@ int criu_restore_child(void)
{
return criu_local_restore_child(global_opts);
}
+
+int criu_local_start_page_server(criu_opts *opts, char *address, int port)
+{
+ int ret = -1;
+ CriuReq req = CRIU_REQ__INIT;
+ CriuResp *resp = NULL;
+
+ req.type = CRIU_REQ_TYPE__PAGE_SERVER;
+ req.opts = opts->rpc;
+
+ req.opts->ps = malloc(sizeof(CriuPageServerInfo));
+ if (req.opts->ps == NULL) {
+ perror("Can't allocate memory for criu RPC page-server opts");
+ goto exit;
+ }
+ criu_page_server_info__init(req.opts->ps);
+
+ req.opts->ps->has_port = true;
+ req.opts->ps->port = port;
+ req.opts->ps->address = strdup(address);
+
+ ret = send_req_and_recv_resp(opts, &req, &resp);
+ if (ret)
+ goto exit;
+
+ if (resp->type != req.type)
+ ret = -EBADMSG;
+ else if (resp->success)
+ ret = resp->ps->pid;
+ else
+ ret = -EBADE;
+
+exit:
+ if (resp)
+ criu_resp__free_unpacked(resp, NULL);
+
+ swrk_wait(opts);
+
+ errno = saved_errno;
+
+ return ret;
+}
+
+int criu_start_page_server(char *address, int port)
+{
+ return criu_local_start_page_server(global_opts, address, port);
+}
diff --git a/lib/c/criu.h b/lib/c/criu.h
index 5d0b5b6c..8a08841b 100644
--- a/lib/c/criu.h
+++ b/lib/c/criu.h
@@ -135,6 +135,7 @@ int criu_check(void);
int criu_dump(void);
int criu_restore(void);
int criu_restore_child(void);
+int criu_start_page_server(char *address, int port);
/*
* Perform dumping but with preliminary iterations. Each
@@ -214,6 +215,7 @@ int criu_local_dump(criu_opts *opts);
int criu_local_restore(criu_opts *opts);
int criu_local_restore_child(criu_opts *opts);
int criu_local_dump_iters(criu_opts *opts, int (*more)(criu_predump_info pi));
+int criu_local_start_page_server(criu_opts *opts, char *address, int port);
#ifdef __GNUG__
}
--
2.14.3
More information about the CRIU
mailing list