[CRIU] [PATCH RFC 1/2] mountinfo: hash introduced

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Thu Mar 17 05:54:02 PDT 2016


Search over all mount point objects by mount ID (which are unique) is called
in several places along the code base.
It's reasonable to introduced hash by mnt_id as a key, to
store mount points object.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 criu/include/mount.h |    5 +++++
 criu/mount.c         |   19 +++++++++++++++++++
 criu/proc_parse.c    |    2 ++
 3 files changed, 26 insertions(+)

diff --git a/criu/include/mount.h b/criu/include/mount.h
index b3bbdce..58dc3b7 100644
--- a/criu/include/mount.h
+++ b/criu/include/mount.h
@@ -83,6 +83,8 @@ struct mount_info {
 
 	struct list_head	postpone;
 
+	struct hlist_node	hash;
+
 	void			*private;	/* associated filesystem data */
 };
 
@@ -92,6 +94,9 @@ 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 mountinfo_hash_init(void);
+extern void mountinfo_hash_add(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/criu/mount.c b/criu/mount.c
index f5e3107..ac784a2 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -39,6 +39,24 @@
 #undef	LOG_PREFIX
 #define LOG_PREFIX "mnt: "
 
+#define MOUNTINFO_HASH_SIZE	32
+static struct hlist_head mountinfo_hash[MOUNTINFO_HASH_SIZE];
+
+int mountinfo_hash_init(void)
+{
+	int c;
+
+	for (c = 0; c < MOUNTINFO_HASH_SIZE; c++)
+		INIT_HLIST_HEAD(&mountinfo_hash[c]);
+
+	return 0;
+}
+
+void mountinfo_hash_add(struct mount_info *mi)
+{
+	hlist_add_head(&mi->hash, &mountinfo_hash[mi->mnt_id % MOUNTINFO_HASH_SIZE]);
+}
+
 int ext_mount_add(char *key, char *val)
 {
 	struct ext_mount *em;
@@ -2674,6 +2692,7 @@ struct mount_info *mnt_entry_alloc()
 		INIT_LIST_HEAD(&new->mnt_share);
 		INIT_LIST_HEAD(&new->mnt_bind);
 		INIT_LIST_HEAD(&new->postpone);
+		INIT_HLIST_NODE(&new->hash);
 	}
 	return new;
 }
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 24a9154..a879c15 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1398,6 +1398,8 @@ end:
 			list = new;
 		}
 
+		mountinfo_hash_add(new);
+
 		if (ret)
 			goto err;
 	}



More information about the CRIU mailing list