mnt: Factor out mntns nsid creation on restore

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov 2014-04-23 13:22:12 +04:00
parent aca33ac402
commit 8d5822d9cb
3 changed files with 24 additions and 24 deletions

View file

@ -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 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 struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);

17
mount.c
View file

@ -1423,24 +1423,15 @@ static int rst_collect_local_mntns(void)
{
struct ns_id *nsid;
nsid = shmalloc(sizeof(struct ns_id));
if (nsid == NULL)
nsid = rst_new_ns_id(0, getpid(), &mnt_ns_desc);
if (!nsid)
return -1;
nsid->nd = &mnt_ns_desc;
nsid->id = 0;
nsid->pid = getpid();
futex_set(&nsid->created, 1);
mntinfo = collect_mntinfo(nsid);
if (mntinfo == NULL)
if (!mntinfo)
return -1;
nsid->next = ns_ids;
ns_ids = nsid;
pr_info("Add namespace %d pid %d\n", nsid->id, nsid->pid);
futex_set(&nsid->created, 1);
return 0;
}

View file

@ -117,6 +117,24 @@ struct ns_id *ns_ids = NULL;
static unsigned int ns_next_id = 1;
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)
{
struct ns_id *nsid;
@ -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 (nsid == NULL)
if (rst_new_ns_id(id, pid, nd) == NULL)
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);
return 0;
}