[CRIU] [PATCH 06/11] mount: add helper mntns_get_root_by_mnt_id

Andrey Vagin avagin at openvz.org
Sun Aug 3 11:31:20 PDT 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 files-reg.c     |  8 +-------
 include/mount.h |  1 +
 mount.c         | 10 ++++++++++
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/files-reg.c b/files-reg.c
index 5a69fef..d8875d6 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -676,7 +676,6 @@ int open_path(struct file_desc *d,
 		int(*open_cb)(int mntns_root, struct reg_file_info *, void *), void *arg)
 {
 	struct reg_file_info *rfi;
-	struct ns_id *ns;
 	int tmp, mntns_root;
 	char *orig_path = NULL;
 
@@ -722,12 +721,7 @@ int open_path(struct file_desc *d,
 		}
 	}
 
-	ns = lookup_nsid_by_mnt_id(rfi->rfe->mnt_id);
-	if (ns == NULL)
-		return -1;
-
-	mntns_root = mntns_get_root_fd(ns);
-
+	mntns_root = mntns_get_root_by_mnt_id(rfi->rfe->mnt_id);
 	tmp = open_cb(mntns_root, rfi, arg);
 	if (tmp < 0) {
 		pr_perror("Can't open file %s", rfi->path);
diff --git a/include/mount.h b/include/mount.h
index 670e779..98bc397 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -6,6 +6,7 @@ extern struct mount_info *mntinfo;
 struct ns_id;
 extern int __mntns_get_root_fd(pid_t pid);
 extern int mntns_get_root_fd(struct ns_id *ns);
+extern int mntns_get_root_by_mnt_id(int mnt_id);
 extern struct ns_id *lookup_nsid_by_mnt_id(int mnt_id);
 
 struct proc_mountinfo;
diff --git a/mount.c b/mount.c
index 544a840..c5399ea 100644
--- a/mount.c
+++ b/mount.c
@@ -2077,6 +2077,16 @@ struct ns_id *lookup_nsid_by_mnt_id(int mnt_id)
 	return mi->nsid;
 }
 
+int mntns_get_root_by_mnt_id(int mnt_id)
+{
+	struct ns_id *mntns;
+
+	mntns = lookup_nsid_by_mnt_id(mnt_id);
+	BUG_ON(mntns == NULL);
+
+	return mntns_get_root_fd(mntns);
+}
+
 static int walk_mnt_ns(int (*cb)(struct ns_id *, struct mount_info *, void *), void *arg)
 {
 	struct mount_info *pms;
-- 
1.8.5.3



More information about the CRIU mailing list