Commit 9fee3dc8 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Pavel Emelyanov

pass "bool for_dump" argument down to collect_mntinfo() and parse_mountinfo()

Preparation.

1. Add the new "bool for_dump" arg to collect/parse_mntinfo().

2. Introduce "struct collect_mntns_arg" to pass the additional
   "bool for_dump" field to collect_mntinfo() and change it to
   pass this boolean to collect_mntinfo()->parse_mountinfo() path.

3. Change other callers of collect_mntinfo() to pass "false".
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4fd669fc
...@@ -692,7 +692,7 @@ int cr_check(void) ...@@ -692,7 +692,7 @@ int cr_check(void)
ns.id = root_item->ids->mnt_ns_id; ns.id = root_item->ids->mnt_ns_id;
mntinfo = collect_mntinfo(&ns); mntinfo = collect_mntinfo(&ns, false);
if (mntinfo == NULL) if (mntinfo == NULL)
return -1; return -1;
......
...@@ -15,7 +15,7 @@ extern int open_mount(unsigned int s_dev); ...@@ -15,7 +15,7 @@ extern int open_mount(unsigned int s_dev);
extern struct fstype *find_fstype_by_name(char *fst); extern struct fstype *find_fstype_by_name(char *fst);
struct cr_imgset; struct cr_imgset;
extern struct mount_info * collect_mntinfo(struct ns_id *ns); extern struct mount_info * collect_mntinfo(struct ns_id *ns, bool for_dump);
extern int prepare_mnt_ns(void); extern int prepare_mnt_ns(void);
extern int pivot_root(const char *new_root, const char *put_old); extern int pivot_root(const char *new_root, const char *put_old);
......
...@@ -153,7 +153,7 @@ extern void mnt_entry_free(struct mount_info *mi); ...@@ -153,7 +153,7 @@ extern void mnt_entry_free(struct mount_info *mi);
struct vm_area_list; struct vm_area_list;
extern struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid); extern struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump);
extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s); extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list); extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list);
extern int parse_self_maps_lite(struct vm_area_list *vms); extern int parse_self_maps_lite(struct vm_area_list *vms);
......
...@@ -1193,11 +1193,11 @@ static void free_mntinfo(struct mount_info *pms) ...@@ -1193,11 +1193,11 @@ static void free_mntinfo(struct mount_info *pms)
} }
} }
struct mount_info *collect_mntinfo(struct ns_id *ns) struct mount_info *collect_mntinfo(struct ns_id *ns, bool for_dump)
{ {
struct mount_info *pm; struct mount_info *pm;
ns->mnt.mntinfo_list = pm = parse_mountinfo(ns->pid, ns); ns->mnt.mntinfo_list = pm = parse_mountinfo(ns->pid, ns, for_dump);
if (!pm) { if (!pm) {
pr_err("Can't parse %d's mountinfo\n", ns->pid); pr_err("Can't parse %d's mountinfo\n", ns->pid);
return NULL; return NULL;
...@@ -1809,7 +1809,7 @@ static int rst_collect_local_mntns(void) ...@@ -1809,7 +1809,7 @@ static int rst_collect_local_mntns(void)
if (!nsid) if (!nsid)
return -1; return -1;
mntinfo = collect_mntinfo(nsid); mntinfo = collect_mntinfo(nsid, false);
if (!mntinfo) if (!mntinfo)
return -1; return -1;
...@@ -2147,7 +2147,7 @@ int prepare_mnt_ns(void) ...@@ -2147,7 +2147,7 @@ int prepare_mnt_ns(void)
pr_info("Restoring mount namespace\n"); pr_info("Restoring mount namespace\n");
old = collect_mntinfo(&ns); old = collect_mntinfo(&ns, false);
if (old == NULL) if (old == NULL)
return -1; return -1;
...@@ -2321,16 +2321,22 @@ int mntns_get_root_by_mnt_id(int mnt_id) ...@@ -2321,16 +2321,22 @@ int mntns_get_root_by_mnt_id(int mnt_id)
return mntns_get_root_fd(mntns); return mntns_get_root_fd(mntns);
} }
static int collect_mntns(struct ns_id *ns, void *oarg) struct collect_mntns_arg {
bool need_to_validate;
bool for_dump;
};
static int collect_mntns(struct ns_id *ns, void *__arg)
{ {
struct collect_mntns_arg *arg = __arg;
struct mount_info *pms; struct mount_info *pms;
pms = collect_mntinfo(ns); pms = collect_mntinfo(ns, arg->for_dump);
if (!pms) if (!pms)
return -1; return -1;
if (ns->pid != getpid()) if (arg->for_dump && ns->pid != getpid())
*(int *)oarg = 1; arg->need_to_validate = true;
mntinfo_add_list(pms); mntinfo_add_list(pms);
return 0; return 0;
...@@ -2338,13 +2344,17 @@ static int collect_mntns(struct ns_id *ns, void *oarg) ...@@ -2338,13 +2344,17 @@ static int collect_mntns(struct ns_id *ns, void *oarg)
int collect_mnt_namespaces(bool for_dump) int collect_mnt_namespaces(bool for_dump)
{ {
int need_to_validate = 0, ret; struct collect_mntns_arg arg;
int ret;
arg.for_dump = for_dump;
arg.need_to_validate = false;
ret = walk_namespaces(&mnt_ns_desc, collect_mntns, &need_to_validate); ret = walk_namespaces(&mnt_ns_desc, collect_mntns, &arg);
if (ret) if (ret)
goto err; goto err;
if (for_dump && need_to_validate) { if (arg.need_to_validate) {
ret = -1; ret = -1;
if (collect_shared(mntinfo)) if (collect_shared(mntinfo))
......
...@@ -1000,7 +1000,7 @@ err: ...@@ -1000,7 +1000,7 @@ err:
goto ret; goto ret;
} }
struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid) struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump)
{ {
struct mount_info *list = NULL; struct mount_info *list = NULL;
FILE *f; FILE *f;
......
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