Commit 7a2698cf authored by Pavel Emelyanov's avatar Pavel Emelyanov

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: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 7aee2619
......@@ -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;
......
......@@ -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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment