[CRIU] [PATCH 1/3] shmem: Move some code to shmem.c file

Pavel Emelyanov xemul at parallels.com
Tue Dec 30 07:41:39 PST 2014


The struct and find routine used to be use by restorer code. Now
the former fully uses vmas and fd opened, so we can move the code
into .c file not to spoil global namespace.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 include/shmem.h | 46 ----------------------------------------------
 shmem.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 46 deletions(-)

diff --git a/include/shmem.h b/include/shmem.h
index 86a8264..1cef7da 100644
--- a/include/shmem.h
+++ b/include/shmem.h
@@ -2,41 +2,8 @@
 #define __CR_SHMEM_H__
 
 #include "lock.h"
-
 #include "protobuf/vma.pb-c.h"
 
-/*
- * pid is a pid of a creater
- * start, end are used for open mapping
- * fd is a file discriptor, which is valid for creater,
- * it's opened in cr-restor, because pgoff may be non zero
- */
-struct shmem_info {
-	unsigned long	shmid;
-	unsigned long	start;
-	unsigned long	end;
-	unsigned long	size;
-	int		pid;
-	int		fd;
-
-	/*
-	 * 0. lock is initilized to zero
-	 * 1. the master opens a descriptor and set lock to 1
-	 * 2. slaves open their descriptors and increment lock
-	 * 3. the master waits all slaves on lock. After that
-	 *    it can close the descriptor.
-	 */
-	futex_t		lock;
-
-	/*
-	 * Here is a problem, that we don't know, which process will restore
-	 * an region. Each time when we	found a process with a smaller pid,
-	 * we reset self_count, so we can't have only one counter.
-	 */
-	int		count;		/* the number of regions */
-	int		self_count;	/* the number of regions, which belongs to "pid" */
-};
-
 struct _VmaEntry;
 extern int collect_shmem(int pid, struct _VmaEntry *vi);
 extern int prepare_shmem_restore(void);
@@ -49,17 +16,4 @@ extern unsigned long rst_shmems;
 extern int cr_dump_shmem(void);
 extern int add_shmem_area(pid_t pid, VmaEntry *vma);
 
-static always_inline struct shmem_info *
-find_shmem(struct shmem_info *shmems, int nr, unsigned long shmid)
-{
-	struct shmem_info *si;
-	int i;
-
-	for (i = 0, si = shmems; i < nr; i++, si++)
-		if (si->shmid == shmid)
-			return si;
-
-	return NULL;
-}
-
 #endif /* __CR_SHMEM_H__ */
diff --git a/shmem.c b/shmem.c
index 865db27..bd1a2e5 100644
--- a/shmem.c
+++ b/shmem.c
@@ -16,6 +16,38 @@
 #include "protobuf.h"
 #include "protobuf/pagemap.pb-c.h"
 
+/*
+ * pid is a pid of a creater
+ * start, end are used for open mapping
+ * fd is a file discriptor, which is valid for creater,
+ * it's opened in cr-restor, because pgoff may be non zero
+ */
+struct shmem_info {
+	unsigned long	shmid;
+	unsigned long	start;
+	unsigned long	end;
+	unsigned long	size;
+	int		pid;
+	int		fd;
+
+	/*
+	 * 0. lock is initilized to zero
+	 * 1. the master opens a descriptor and set lock to 1
+	 * 2. slaves open their descriptors and increment lock
+	 * 3. the master waits all slaves on lock. After that
+	 *    it can close the descriptor.
+	 */
+	futex_t		lock;
+
+	/*
+	 * Here is a problem, that we don't know, which process will restore
+	 * an region. Each time when we	found a process with a smaller pid,
+	 * we reset self_count, so we can't have only one counter.
+	 */
+	int		count;		/* the number of regions */
+	int		self_count;	/* the number of regions, which belongs to "pid" */
+};
+
 unsigned long nr_shmems;
 unsigned long rst_shmems;
 
@@ -37,6 +69,19 @@ void show_saved_shmems(void)
 				si->start, si->shmid, si->pid);
 }
 
+static struct shmem_info *find_shmem(struct shmem_info *shmems,
+		int nr, unsigned long shmid)
+{
+	struct shmem_info *si;
+	int i;
+
+	for (i = 0, si = shmems; i < nr; i++, si++)
+		if (si->shmid == shmid)
+			return si;
+
+	return NULL;
+}
+
 
 static struct shmem_info *find_shmem_by_id(unsigned long id)
 {
-- 
1.8.4.2




More information about the CRIU mailing list