[CRIU] [PATCH 3/7] mount: Move mount_info and ext_mount to mount.h

Cyrill Gorcunov gorcunov at openvz.org
Tue Aug 11 07:18:07 PDT 2015


It's quite unclean while this structure lives
in proc_parse.h, which only have to fill this
structure on procfs read, but real handling
is inside mount.c. Move it as appropriate.

Same time ext_mount structure should be moved
into a header as well with sane @list name
used instead of @l.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/mount.h      | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 include/proc_parse.h | 59 +------------------------------------
 mount.c              | 23 ++-------------
 3 files changed, 83 insertions(+), 81 deletions(-)

diff --git a/include/mount.h b/include/mount.h
index a7fa93821b4c..1307e277419b 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -1,15 +1,93 @@
 #ifndef __CR_MOUNT_H__
 #define __CR_MOUNT_H__
 
+#include <sys/types.h>
+
+#include "asm/types.h"
+#include "list.h"
+
 struct proc_mountinfo;
 struct pstree_item;
-struct mount_info;
-struct cr_imgset;
+struct fstype;
 struct ns_id;
 
+/*
+ * Structure to keep external mount points resolving info.
+ *
+ * On dump the key is the mountpoint as seen from the mount
+ * namespace, the val is some name that will be put into image
+ * instead of the mount point's root path.
+ *
+ * On restore the key is the name from the image (the one
+ * mentioned above) and the val is the path in criu's mount
+ * namespace that will become the mount point's root, i.e. --
+ * be bind mounted to the respective mountpoint.
+ */
+struct ext_mount {
+	struct list_head	list;
+	char			*key;
+	char			*val;
+};
+
+struct mount_info {
+	int			mnt_id;
+	int			parent_mnt_id;
+	unsigned int		s_dev;
+	char			*root;
+	/*
+	 * During dump mountpoint contains path with dot at the
+	 * beginning. It allows to use openat, statat, etc without
+	 * creating a temporary copy of the path.
+	 *
+	 * On restore mountpoint is prepended with so called ns
+	 * root path -- it's a place in fs where the namespace
+	 * mount tree is constructed. Check mnt_roots for details.
+	 * The ns_mountpoint contains path w/o this prefix.
+	 */
+	char			*mountpoint;
+	char			*ns_mountpoint;
+	unsigned		flags;
+	int			master_id;
+	int			shared_id;
+	struct fstype		*fstype;
+	char			*source;
+	char			*options;
+	union {
+		bool		mounted;
+		bool		dumped;
+	};
+	bool			need_plugin;
+	int			is_file;
+	bool			is_ns_root;
+	struct mount_info	*next;
+	struct ns_id		*nsid;
+
+	struct ext_mount	*external;
+	bool			internal_sharing;
+
+	/* tree linkage */
+	struct mount_info	*parent;
+	struct mount_info	*bind;
+	struct list_head	children;
+	struct list_head	siblings;
+
+	struct list_head	mnt_bind;	/* circular list of derivatives of one real mount */
+	struct list_head	mnt_share;	/* circular list of shared mounts */
+	struct list_head	mnt_slave_list;	/* list of slave mounts */
+	struct list_head	mnt_slave;	/* slave list entry */
+	struct mount_info	*mnt_master;	/* slave is on master->mnt_slave_list */
+
+	struct list_head	postpone;
+
+	void			*private;	/* associated filesystem data */
+};
+
 extern struct mount_info *mntinfo;
 extern struct ns_desc mnt_ns_desc;
 
+extern struct mount_info *mnt_entry_alloc();
+extern void mnt_entry_free(struct mount_info *mi);
+
 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);
diff --git a/include/proc_parse.h b/include/proc_parse.h
index 6dc3a094706a..b4fb57d11c83 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -6,6 +6,7 @@
 #include "image.h"
 #include "list.h"
 #include "cgroup.h"
+#include "mount.h"
 
 #include "protobuf/eventfd.pb-c.h"
 #include "protobuf/eventpoll.pb-c.h"
@@ -90,7 +91,6 @@ struct proc_status_creds {
 
 bool proc_status_creds_eq(struct proc_status_creds *o1, struct proc_status_creds *o2);
 
-struct mount_info;
 struct fstype {
 	char *name;
 	int code;
@@ -99,63 +99,6 @@ struct fstype {
 	int (*parse)(struct mount_info *pm);
 };
 
-struct ext_mount;
-struct mount_info {
-	int			mnt_id;
-	int			parent_mnt_id;
-	unsigned int		s_dev;
-	char			*root;
-	/*
-	 * During dump mountpoint contains path with dot at the 
-	 * beginning. It allows to use openat, statat, etc without 
-	 * creating a temporary copy of the path.
-	 *
-	 * On restore mountpoint is prepended with so called ns
-	 * root path -- it's a place in fs where the namespace
-	 * mount tree is constructed. Check mnt_roots for details.
-	 * The ns_mountpoint contains path w/o this prefix.
-	 */
-	char			*mountpoint;
-	char			*ns_mountpoint;
-	unsigned		flags;
-	int			master_id;
-	int			shared_id;
-	struct fstype		*fstype;
-	char			*source;
-	char			*options;
-	union {
-		bool		mounted;
-		bool		dumped;
-	};
-	bool			need_plugin;
-	int			is_file;
-	bool			is_ns_root;
-	struct mount_info	*next;
-	struct ns_id		*nsid;
-
-	struct ext_mount	*external;
-	bool			internal_sharing;
-
-	/* tree linkage */
-	struct mount_info	*parent;
-	struct mount_info	*bind;
-	struct list_head	children;
-	struct list_head	siblings;
-
-	struct list_head	mnt_bind;	/* circular list of derivatives of one real mount */
-	struct list_head	mnt_share;	/* circular list of shared mounts */
-	struct list_head	mnt_slave_list;	/* list of slave mounts */
-	struct list_head	mnt_slave;	/* slave list entry */
-	struct mount_info	*mnt_master;	/* slave is on master->mnt_slave_list */
-
-	struct list_head	postpone;
-
-	void			*private;	/* associated filesystem data */
-};
-
-extern struct mount_info *mnt_entry_alloc();
-extern void mnt_entry_free(struct mount_info *mi);
-
 struct vm_area_list;
 
 extern bool add_skip_mount(const char *mountpoint);
diff --git a/mount.c b/mount.c
index 344d64622a71..f70875a72893 100644
--- a/mount.c
+++ b/mount.c
@@ -32,25 +32,6 @@
 
 #define AUTODETECTED_MOUNT "CRIU:AUTOGENERATED"
 
-/*
- * Structure to keep external mount points resolving info.
- *
- * On dump the key is the mountpoint as seen from the mount
- * namespace, the val is some name that will be put into image
- * instead of the mount point's root path.
- *
- * On restore the key is the name from the image (the one 
- * mentioned above) and the val is the path in criu's mount 
- * namespace that will become the mount point's root, i.e. -- 
- * be bind mounted to the respective mountpoint.
- */
-
-struct ext_mount {
-	char *key;
-	char *val;
-	struct list_head l;
-};
-
 int ext_mount_add(char *key, char *val)
 {
 	struct ext_mount *em;
@@ -61,7 +42,7 @@ int ext_mount_add(char *key, char *val)
 
 	em->key = key;
 	em->val = val;
-	list_add_tail(&em->l, &opts.ext_mounts);
+	list_add_tail(&em->list, &opts.ext_mounts);
 	pr_info("Added %s:%s ext mount mapping\n", key, val);
 	return 0;
 }
@@ -71,7 +52,7 @@ static struct ext_mount *ext_mount_lookup(char *key)
 {
 	struct ext_mount *em;
 
-	list_for_each_entry(em, &opts.ext_mounts, l)
+	list_for_each_entry(em, &opts.ext_mounts, list)
 		if (!strcmp(em->key, key))
 			return em;
 
-- 
2.4.3



More information about the CRIU mailing list