mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 22:05:36 +00:00
ns: Pack functionality of storing ns fd to store_self_ns()
Move the code to simplify it and to allow to use this function others. Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
committed by
Andrei Vagin
parent
47170c462d
commit
7af38c85cf
@@ -193,6 +193,7 @@ extern int predump_task_ns_ids(struct pstree_item *);
|
|||||||
extern struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd, enum ns_type t);
|
extern struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd, enum ns_type t);
|
||||||
extern int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
|
extern int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
|
||||||
extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
|
extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
|
||||||
|
extern int store_self_ns(struct ns_id *ns);
|
||||||
|
|
||||||
extern int collect_user_namespaces(bool for_dump);
|
extern int collect_user_namespaces(bool for_dump);
|
||||||
extern int prepare_userns(pid_t real_pid, UsernsEntry *e);
|
extern int prepare_userns(pid_t real_pid, UsernsEntry *e);
|
||||||
|
@@ -2165,6 +2165,20 @@ err_out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int store_self_ns(struct ns_id *ns)
|
||||||
|
{
|
||||||
|
int fd, id;
|
||||||
|
|
||||||
|
/* Pin one with a file descriptor */
|
||||||
|
fd = open_proc(PROC_SELF, "ns/%s", ns->nd->str);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
id = fdstore_add(fd);
|
||||||
|
close(fd);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NS__CREATED = 1,
|
NS__CREATED = 1,
|
||||||
NS__MAPS_POPULATED,
|
NS__MAPS_POPULATED,
|
||||||
@@ -2185,7 +2199,7 @@ static int create_user_ns_hierarhy_fn(void *in_arg)
|
|||||||
futex_t *p_futex = NULL, *futex = NULL;
|
futex_t *p_futex = NULL, *futex = NULL;
|
||||||
size_t map_size = 2 * 1024 * 1024;
|
size_t map_size = 2 * 1024 * 1024;
|
||||||
void *map = MAP_FAILED, *stack;
|
void *map = MAP_FAILED, *stack;
|
||||||
int status, fd, ret = -1;
|
int status, ret = -1;
|
||||||
struct ns_id *me, *child;
|
struct ns_id *me, *child;
|
||||||
pid_t pid = -1;
|
pid_t pid = -1;
|
||||||
|
|
||||||
@@ -2197,17 +2211,7 @@ static int create_user_ns_hierarhy_fn(void *in_arg)
|
|||||||
/* Set self pid to allow parent restore user_ns maps */
|
/* Set self pid to allow parent restore user_ns maps */
|
||||||
p_arg->pid = get_self_real_pid();
|
p_arg->pid = get_self_real_pid();
|
||||||
futex_set_and_wake(p_futex, NS__CREATED);
|
futex_set_and_wake(p_futex, NS__CREATED);
|
||||||
/*
|
me->user.nsfd_id = store_self_ns(me);
|
||||||
* Note we can't use open_proc() here after
|
|
||||||
* clone() with CLONE_FILES but no CLONE_VM.
|
|
||||||
*/
|
|
||||||
fd = open("/proc/self/ns/user", O_RDONLY);
|
|
||||||
if (fd < 0) {
|
|
||||||
pr_perror("Can't get self user ns");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
me->user.nsfd_id = fdstore_add(fd);
|
|
||||||
close(fd);
|
|
||||||
if (me->user.nsfd_id < 0) {
|
if (me->user.nsfd_id < 0) {
|
||||||
pr_err("Can't add fd to fdstore\n");
|
pr_err("Can't add fd to fdstore\n");
|
||||||
goto out;
|
goto out;
|
||||||
|
Reference in New Issue
Block a user