Commit b23268e4 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

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: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 54d0f241
......@@ -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:
......
......@@ -1253,14 +1253,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.
......@@ -1295,6 +1293,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;
......@@ -1304,7 +1310,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 {
......
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