[CRIU] [PATCH 02/14] mount: save mount tree for each namespace
Andrey Vagin
avagin at openvz.org
Thu Apr 17 12:23:56 PDT 2014
We are going to support nested mount namespaces and each NS has own
tree. The mount tree is used for checking that a file is reachable.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
include/mount.h | 4 ++--
include/namespaces.h | 5 +++++
mount.c | 8 +++++---
namespaces.c | 2 +-
4 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/mount.h b/include/mount.h
index 86836ea..1d51910 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -10,7 +10,8 @@ extern int collect_mount_info(pid_t pid);
extern struct fstype *find_fstype_by_name(char *fst);
struct cr_fdset;
-extern int dump_mnt_ns(int pid, int ns_id);
+struct ns_id;
+extern int dump_mnt_ns(struct ns_id *ns);
extern int prepare_mnt_ns(int pid);
extern int pivot_root(const char *new_root, const char *put_old);
@@ -24,7 +25,6 @@ extern struct ns_desc mnt_ns_desc;
extern dev_t phys_stat_resolve_dev(dev_t st_dev, const char *path);
extern bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev, const char *path);
-struct ns_id;
extern int restore_task_mnt_ns(struct ns_id *nsid, pid_t pid);
extern int fini_mnt_ns(void);
diff --git a/include/namespaces.h b/include/namespaces.h
index fcbe17c..55cf37a 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -16,6 +16,11 @@ struct ns_id {
struct ns_desc *nd;
struct ns_id *next;
futex_t created; /* boolean */
+ union {
+ struct {
+ struct mount_info *mntinfo_tree;
+ } mnt;
+ };
};
extern struct ns_id *ns_ids;
diff --git a/mount.c b/mount.c
index defafb1..cb6b963 100644
--- a/mount.c
+++ b/mount.c
@@ -824,10 +824,12 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
return 0;
}
-int dump_mnt_ns(int ns_pid, int ns_id)
+int dump_mnt_ns(struct ns_id *ns)
{
struct mount_info *pm;
int img_fd, ret = -1;
+ int ns_pid = ns->pid;
+ int ns_id = ns->id;
img_fd = open_image(CR_FD_MNTS, O_DUMP, ns_id);
if (img_fd < 0)
@@ -842,7 +844,8 @@ int dump_mnt_ns(int ns_pid, int ns_id)
goto err;
}
- if (mnt_build_tree(pm) == NULL)
+ ns->mnt.mntinfo_tree = mnt_build_tree(pm);
+ if (ns->mnt.mntinfo_tree == NULL)
goto err;
if (validate_mounts(pm, true))
@@ -856,7 +859,6 @@ int dump_mnt_ns(int ns_pid, int ns_id)
if (dump_one_mountpoint(pm, img_fd))
goto err;
- xfree(pm);
pm = n;
} while (pm);
diff --git a/namespaces.c b/namespaces.c
index 77920f0..1332a66 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -461,7 +461,7 @@ int dump_mnt_namespaces(void)
pr_info("Dump MNT namespace (mountpoints) %d via %d\n",
ns->id, ns->pid);
- ret = dump_mnt_ns(ns->pid, ns->id);
+ ret = dump_mnt_ns(ns);
if (ret)
break;
}
--
1.8.5.3
More information about the CRIU
mailing list