Commit 8d5822d9 authored by Pavel Emelyanov's avatar Pavel Emelyanov

mnt: Factor out mntns nsid creation on restore

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent aca33ac4
...@@ -50,6 +50,7 @@ extern int switch_ns(int pid, struct ns_desc *nd, int *rst); ...@@ -50,6 +50,7 @@ extern int switch_ns(int pid, struct ns_desc *nd, int *rst);
extern int restore_ns(int rst, struct ns_desc *nd); extern int restore_ns(int rst, struct ns_desc *nd);
extern int dump_task_ns_ids(struct pstree_item *); extern int dump_task_ns_ids(struct pstree_item *);
extern struct ns_id *rst_new_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 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);
......
...@@ -1423,24 +1423,15 @@ static int rst_collect_local_mntns(void) ...@@ -1423,24 +1423,15 @@ static int rst_collect_local_mntns(void)
{ {
struct ns_id *nsid; struct ns_id *nsid;
nsid = shmalloc(sizeof(struct ns_id)); nsid = rst_new_ns_id(0, getpid(), &mnt_ns_desc);
if (nsid == NULL) if (!nsid)
return -1; return -1;
nsid->nd = &mnt_ns_desc;
nsid->id = 0;
nsid->pid = getpid();
futex_set(&nsid->created, 1);
mntinfo = collect_mntinfo(nsid); mntinfo = collect_mntinfo(nsid);
if (mntinfo == NULL) if (!mntinfo)
return -1; return -1;
nsid->next = ns_ids; futex_set(&nsid->created, 1);
ns_ids = nsid;
pr_info("Add namespace %d pid %d\n", nsid->id, nsid->pid);
return 0; return 0;
} }
......
...@@ -117,6 +117,24 @@ struct ns_id *ns_ids = NULL; ...@@ -117,6 +117,24 @@ struct ns_id *ns_ids = NULL;
static unsigned int ns_next_id = 1; static unsigned int ns_next_id = 1;
unsigned long root_ns_mask = 0; unsigned long root_ns_mask = 0;
struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
{
struct ns_id *nsid;
nsid = shmalloc(sizeof(*nsid));
if (nsid) {
nsid->nd = nd;
nsid->id = id;
nsid->pid = pid;
futex_set(&nsid->created, 0);
nsid->next = ns_ids;
ns_ids = nsid;
}
return nsid;
}
int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd) int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
{ {
struct ns_id *nsid; struct ns_id *nsid;
...@@ -129,20 +147,10 @@ int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd) ...@@ -129,20 +147,10 @@ int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
} }
} }
nsid = shmalloc(sizeof(struct ns_id)); if (rst_new_ns_id(id, pid, nd) == NULL)
if (nsid == NULL)
return -1; return -1;
nsid->nd = nd;
nsid->id = id;
nsid->pid = pid;
futex_set(&nsid->created, 0);
nsid->next = ns_ids;
ns_ids = nsid;
pr_info("Add namespace %d pid %d\n", nsid->id, nsid->pid); pr_info("Add namespace %d pid %d\n", nsid->id, nsid->pid);
return 0; return 0;
} }
......
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