mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
service: add ability to set inherit file descriptors (v3)
This is required to use criu swrk in libcontainer.
v2: remove useless function declaration
allow to set inherit_fd only for swrk
v3: check swrk out of loop
Cc: Saied Kazemi <saied@google.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
4620eab51c
commit
4e37d72e90
5 changed files with 29 additions and 6 deletions
10
cr-service.c
10
cr-service.c
|
|
@ -18,6 +18,7 @@
|
|||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "cpu.h"
|
||||
#include "files.h"
|
||||
#include "pstree.h"
|
||||
#include "cr-service.h"
|
||||
#include "cr-service-const.h"
|
||||
|
|
@ -344,6 +345,15 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
|
|||
goto err;
|
||||
}
|
||||
|
||||
if (req->n_inherit_fd && !opts.swrk_restore) {
|
||||
pr_err("inherit_fd is not allowed in standalone service\n");
|
||||
goto err;
|
||||
}
|
||||
for (i = 0; i < req->n_inherit_fd; i++) {
|
||||
if (inherit_fd_add(req->inherit_fd[i]->fd, req->inherit_fd[i]->key))
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i = 0; i < req->n_cg_root; i++) {
|
||||
if (new_cg_root_add(req->cg_root[i]->ctrl,
|
||||
req->cg_root[i]->path))
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ int main(int argc, char *argv[], char *envp[])
|
|||
}
|
||||
break;
|
||||
case 1062:
|
||||
if (inherit_fd_add(optarg) < 0)
|
||||
if (inherit_fd_parse(optarg) < 0)
|
||||
return 1;
|
||||
break;
|
||||
case 1063:
|
||||
|
|
|
|||
14
files.c
14
files.c
|
|
@ -1266,14 +1266,12 @@ static int inherit_fd_reused(struct inherit_fd *inh)
|
|||
* We can't print diagnostics messages in this function because the
|
||||
* log file isn't initialized yet.
|
||||
*/
|
||||
int inherit_fd_add(char *optarg)
|
||||
int inherit_fd_parse(char *optarg)
|
||||
{
|
||||
char *cp = NULL;
|
||||
int n = -1;
|
||||
int fd = -1;
|
||||
int dbg = 0;
|
||||
struct stat sbuf;
|
||||
struct inherit_fd *inh;
|
||||
|
||||
/*
|
||||
* Parse the argument.
|
||||
|
|
@ -1308,6 +1306,14 @@ int inherit_fd_add(char *optarg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
return inherit_fd_add(fd, cp);
|
||||
}
|
||||
|
||||
int inherit_fd_add(int fd, char *key)
|
||||
{
|
||||
struct inherit_fd *inh;
|
||||
struct stat sbuf;
|
||||
|
||||
if (fstat(fd, &sbuf) == -1) {
|
||||
pr_perror("Can't fstat inherit fd %d", fd);
|
||||
return -1;
|
||||
|
|
@ -1317,7 +1323,7 @@ int inherit_fd_add(char *optarg)
|
|||
if (inh == NULL)
|
||||
return -1;
|
||||
|
||||
inh->inh_id = cp;
|
||||
inh->inh_id = key;
|
||||
inh->inh_fd = fd;
|
||||
inh->inh_dev = sbuf.st_dev;
|
||||
inh->inh_ino = sbuf.st_ino;
|
||||
|
|
|
|||
|
|
@ -169,7 +169,8 @@ extern struct collect_image_info ext_file_cinfo;
|
|||
extern int dump_unsupp_fd(struct fd_parms *p, int lfd,
|
||||
struct cr_img *, char *more, char *info);
|
||||
|
||||
extern int inherit_fd_add(char *optarg);
|
||||
extern int inherit_fd_parse(char *optarg);
|
||||
extern int inherit_fd_add(int fd, char *key);
|
||||
extern void inherit_fd_log(void);
|
||||
extern int inherit_fd_resolve_clash(int fd);
|
||||
extern int inherit_fd_fini(void);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ message ext_mount_map {
|
|||
required string val = 2;
|
||||
};
|
||||
|
||||
message inherit_fd {
|
||||
required string key = 1;
|
||||
required int32 fd = 2;
|
||||
};
|
||||
|
||||
message cgroup_root {
|
||||
optional string ctrl = 1;
|
||||
required string path = 2;
|
||||
|
|
@ -55,6 +60,7 @@ message criu_opts {
|
|||
repeated cgroup_root cg_root = 25;
|
||||
|
||||
optional bool rst_sibling = 26; /* swrk only */
|
||||
repeated inherit_fd inherit_fd = 27; /* swrk only */
|
||||
}
|
||||
|
||||
message criu_dump_resp {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue