2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

libcriu: Introduce the criu_dump_iters() call

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@parallels.com>
This commit is contained in:
Pavel Emelyanov
2014-06-26 18:52:34 +04:00
parent 7aee2619c6
commit 7a2698cfe8
2 changed files with 79 additions and 0 deletions

View File

@@ -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;