[CRIU] [PATCH 14/15] crtools: split crtools.h

Andrey Vagin avagin at openvz.org
Mon Nov 4 22:00:36 PST 2013


crtools.h includes too many headers to be a general header,
so lets split it on two parts. The first one "common" will be included
in many other files. crtools.h is a header for tool, which will be
included in crtools.c, cr-service.c, etc

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-service.c               |   1 +
 include/common.h           | 100 +++++++++++++++++++++++++++++++++++++++++++++
 include/crtools.h          |  77 ----------------------------------
 include/file-lock.h        |   2 +-
 include/files.h            |   2 +-
 include/page-xfer.h        |   2 +
 include/parasite-syscall.h |   2 +-
 include/pstree.h           |   2 +-
 include/types.h            |  19 ---------
 log.c                      |   2 +-
 page-xfer.c                |   2 +-
 shmem.c                    |   2 +-
 sk-queue.c                 |   2 +-
 util.c                     |   2 +-
 14 files changed, 112 insertions(+), 105 deletions(-)
 create mode 100644 include/common.h
 delete mode 100644 include/types.h

diff --git a/cr-service.c b/cr-service.c
index 0bf5732..f7c9805 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -14,6 +14,7 @@
 #include <sys/stat.h>
 
 #include "crtools.h"
+#include "common.h"
 #include "util-pie.h"
 #include "image.h"
 #include "log.h"
diff --git a/include/common.h b/include/common.h
new file mode 100644
index 0000000..6efca6b
--- /dev/null
+++ b/include/common.h
@@ -0,0 +1,100 @@
+#ifndef __CR_COMMON_H__
+#define __CR_COMMON_H__
+
+#include <stdbool.h>
+
+#include "bug.h"
+#include "list.h"
+
+struct pid {
+	/*
+	 * The @real pid is used to fetch tasks during dumping stage,
+	 * This is a global pid seen from the context where the dumping
+	 * is running.
+	 */
+	pid_t real;
+
+	/*
+	 * The @virt pid is one which used in the image itself and keeps
+	 * the pid value to be restored. This pid fetched from the
+	 * dumpee context, because the dumpee might have own pid namespace.
+	 */
+	pid_t virt;
+};
+
+/*
+ * When we have to restore a shared resource, we mush select which
+ * task should do it, and make other(s) wait for it. In order to
+ * avoid deadlocks, always make task with lower pid be the restorer.
+ */
+static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b)
+{
+	return pid_a < pid_b;
+}
+
+struct cr_fdset {
+	int fd_off;
+	int fd_nr;
+	int *_fds;
+};
+
+static inline int fdset_fd(const struct cr_fdset *fdset, int type)
+{
+	int idx;
+
+	idx = type - fdset->fd_off;
+	BUG_ON(idx > fdset->fd_nr);
+
+	return fdset->_fds[idx];
+}
+
+extern struct cr_fdset *glob_fdset;
+
+struct cr_fdset *cr_task_fdset_open(int pid, int mode);
+struct cr_fdset *cr_fdset_open_range(int pid, int from, int to,
+			       unsigned long flags);
+#define cr_fdset_open(pid, type, flags) cr_fdset_open_range(pid, \
+		_CR_FD_##type##_FROM, _CR_FD_##type##_TO, flags)
+struct cr_fdset *cr_glob_fdset_open(int mode);
+
+void close_cr_fdset(struct cr_fdset **cr_fdset);
+
+extern void print_data(unsigned long addr, unsigned char *data, size_t size);
+extern void print_image_data(int fd, unsigned int length, int show);
+
+struct cr_options {
+	int			final_state;
+	char			*show_dump_file;
+	bool			check_ms_kernel;
+	bool			show_pages_content;
+	bool			restore_detach;
+	bool			ext_unix_sk;
+	bool			shell_job;
+	bool			handle_file_locks;
+	bool			tcp_established_ok;
+	bool			evasive_devices;
+	bool			link_remap_ok;
+	unsigned int		rst_namespaces_flags;
+	bool			log_file_per_pid;
+	char			*output;
+	char			*root;
+	char			*pidfile;
+	struct list_head	veth_pairs;
+	struct list_head	scripts;
+	bool			use_page_server;
+	unsigned short		ps_port;
+	char			*addr;
+	bool			track_mem;
+	char			*img_parent;
+};
+
+extern struct cr_options opts;
+
+extern void init_opts(void);
+
+struct script {
+	struct list_head node;
+	char *path;
+};
+
+#endif
diff --git a/include/crtools.h b/include/crtools.h
index 944d73d..751b4d8 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -14,73 +14,15 @@
 
 #define CR_FD_PERM		(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
 
-struct script {
-	struct list_head node;
-	char *path;
-};
-
-struct cr_options {
-	int			final_state;
-	char			*show_dump_file;
-	bool			check_ms_kernel;
-	bool			show_pages_content;
-	bool			restore_detach;
-	bool			ext_unix_sk;
-	bool			shell_job;
-	bool			handle_file_locks;
-	bool			tcp_established_ok;
-	bool			evasive_devices;
-	bool			link_remap_ok;
-	unsigned int		rst_namespaces_flags;
-	bool			log_file_per_pid;
-	char			*output;
-	char			*root;
-	char			*pidfile;
-	struct list_head	veth_pairs;
-	struct list_head	scripts;
-	bool			use_page_server;
-	unsigned short		ps_port;
-	char			*addr;
-	bool			track_mem;
-	char			*img_parent;
-};
-
-extern struct cr_options opts;
-
-extern void init_opts(void);
-
 int check_img_inventory(void);
 int write_img_inventory(void);
 void kill_inventory(void);
 
-extern void print_data(unsigned long addr, unsigned char *data, size_t size);
-extern void print_image_data(int fd, unsigned int length, int show);
-
 extern int open_image_dir(void);
 extern void close_image_dir(void);
 
-void up_page_ids_base(void);
-
 #define LAST_PID_PATH		"/proc/sys/kernel/ns_last_pid"
 
-struct cr_fdset {
-	int fd_off;
-	int fd_nr;
-	int *_fds;
-};
-
-static inline int fdset_fd(const struct cr_fdset *fdset, int type)
-{
-	int idx;
-
-	idx = type - fdset->fd_off;
-	BUG_ON(idx > fdset->fd_nr);
-
-	return fdset->_fds[idx];
-}
-
-extern struct cr_fdset *glob_fdset;
-
 int cr_dump_tasks(pid_t pid);
 int cr_pre_dump_tasks(pid_t pid);
 int cr_restore_tasks(void);
@@ -89,15 +31,6 @@ int convert_to_elf(char *elf_path, int fd_core);
 int cr_check(void);
 int cr_exec(int pid, char **opts);
 
-struct cr_fdset *cr_task_fdset_open(int pid, int mode);
-struct cr_fdset *cr_fdset_open_range(int pid, int from, int to,
-			       unsigned long flags);
-#define cr_fdset_open(pid, type, flags) cr_fdset_open_range(pid, \
-		_CR_FD_##type##_FROM, _CR_FD_##type##_TO, flags)
-struct cr_fdset *cr_glob_fdset_open(int mode);
-
-void close_cr_fdset(struct cr_fdset **cr_fdset);
-
 struct fdt {
 	int			nr;		/* How many tasks share this fd table */
 	pid_t			pid;		/* Who should restore this fd table */
@@ -108,16 +41,6 @@ struct fdt {
 	futex_t			fdt_lock;
 };
 
-/*
- * When we have to restore a shared resource, we mush select which
- * task should do it, and make other(s) wait for it. In order to
- * avoid deadlocks, always make task with lower pid be the restorer.
- */
-static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b)
-{
-	return pid_a < pid_b;
-}
-
 void restrict_uid(unsigned int uid, unsigned int gid);
 struct proc_status_creds;
 bool may_dump(struct proc_status_creds *);
diff --git a/include/file-lock.h b/include/file-lock.h
index 084cc2c..3a1be82 100644
--- a/include/file-lock.h
+++ b/include/file-lock.h
@@ -1,7 +1,7 @@
 #ifndef __FILE_LOCK_H__
 #define __FILE_LOCK_H__
 
-#include "crtools.h"
+#include "common.h"
 #include "protobuf.h"
 #include "protobuf/file-lock.pb-c.h"
 
diff --git a/include/files.h b/include/files.h
index 5b65bd7..6d4aaf9 100644
--- a/include/files.h
+++ b/include/files.h
@@ -6,7 +6,7 @@
 #include "lock.h"
 #include "list.h"
 #include "image.h"
-#include "crtools.h"
+#include "common.h"
 
 #include "protobuf/fdinfo.pb-c.h"
 #include "protobuf/fown.pb-c.h"
diff --git a/include/page-xfer.h b/include/page-xfer.h
index 7d2284a..eaa2166 100644
--- a/include/page-xfer.h
+++ b/include/page-xfer.h
@@ -25,6 +25,8 @@ struct page_xfer {
 	};
 };
 
+void up_page_ids_base(void);
+
 int open_page_xfer(struct page_xfer *xfer, int fd_type, long id);
 struct page_pipe;
 int page_xfer_dump_pages(struct page_xfer *, struct page_pipe *,
diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index a31e51d..3bb2d8c 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -1,7 +1,7 @@
 #ifndef __CR_PARASITE_SYSCALL_H__
 #define __CR_PARASITE_SYSCALL_H__
 
-#include "types.h"
+#include "common.h"
 #include "list.h"
 
 #define BUILTIN_SYSCALL_SIZE	8
diff --git a/include/pstree.h b/include/pstree.h
index 53b0520..3cd0da6 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -2,7 +2,7 @@
 #define __CR_PSTREE_H__
 
 #include "list.h"
-#include "types.h"
+#include "common.h"
 #include "image.h"
 #include "lock.h"
 #include "protobuf/core.pb-c.h"
diff --git a/include/types.h b/include/types.h
deleted file mode 100644
index 5ea5cef..0000000
--- a/include/types.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef __CR_TYPES_H__
-#define __CR_TYPES_H__
-struct pid {
-	/*
-	 * The @real pid is used to fetch tasks during dumping stage,
-	 * This is a global pid seen from the context where the dumping
-	 * is running.
-	 */
-	pid_t real;
-
-	/*
-	 * The @virt pid is one which used in the image itself and keeps
-	 * the pid value to be restored. This pid fetched from the
-	 * dumpee context, because the dumpee might have own pid namespace.
-	 */
-	pid_t virt;
-};
-
-#endif
diff --git a/log.c b/log.c
index 34f69e7..d7997e2 100644
--- a/log.c
+++ b/log.c
@@ -15,7 +15,7 @@
 #include "compiler.h"
 #include "asm/types.h"
 #include "util.h"
-#include "crtools.h"
+#include "common.h"
 #include "servicefd.h"
 
 #define DEFAULT_LOGFD		STDERR_FILENO
diff --git a/page-xfer.c b/page-xfer.c
index c16d749..e4ab2c1 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -4,7 +4,7 @@
 #include <unistd.h>
 
 #include "image.h"
-#include "crtools.h"
+#include "common.h"
 #include "page-xfer.h"
 #include "page-pipe.h"
 
diff --git a/shmem.c b/shmem.c
index eb24203..863d24f 100644
--- a/shmem.c
+++ b/shmem.c
@@ -4,7 +4,7 @@
 
 #include "shmem.h"
 #include "image.h"
-#include "crtools.h"
+#include "common.h"
 #include "page-pipe.h"
 #include "page-xfer.h"
 #include "vma.h"
diff --git a/sk-queue.c b/sk-queue.c
index 5896e97..5527a4f 100644
--- a/sk-queue.c
+++ b/sk-queue.c
@@ -13,7 +13,7 @@
 #include "asm/types.h"
 #include "list.h"
 #include "image.h"
-#include "crtools.h"
+#include "common.h"
 #include "util.h"
 #include "util-pie.h"
 #include "sockets.h"
diff --git a/util.c b/util.c
index 9b0792d..de32a4b 100644
--- a/util.c
+++ b/util.c
@@ -38,7 +38,7 @@
 #include "image.h"
 #include "vma.h"
 
-#include "crtools.h"
+#include "common.h"
 #include "servicefd.h"
 
 #define VMA_OPT_LEN	128
-- 
1.8.3.1



More information about the CRIU mailing list