[2/6] ext: Sweep external resources code into separate files.

Submitted by Pavel Emelianov on Sept. 20, 2016, 1:26 p.m.

Details

Message ID 57E138F7.3070002@virtuozzo.com
State Accepted
Series "Unify external resources in CLI"
Commit b4d1158732ce2f133196b0c58ee120f802e02add
Headers show

Commit Message

Pavel Emelianov Sept. 20, 2016, 1:26 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/Makefile.crtools     |  1 +
 criu/cr-service.c         |  1 +
 criu/crtools.c            | 14 +-------------
 criu/external.c           | 42 ++++++++++++++++++++++++++++++++++++++++++
 criu/files-reg.c          |  1 +
 criu/files.c              | 24 ------------------------
 criu/include/cr_options.h |  7 -------
 criu/include/external.h   | 11 +++++++++++
 criu/include/files.h      |  2 --
 criu/mount.c              |  1 +
 criu/tty.c                |  1 +
 11 files changed, 59 insertions(+), 46 deletions(-)
 create mode 100644 criu/external.c
 create mode 100644 criu/include/external.h

Patch hide | download patch | download mbox

diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools
index 52c00ec..98d9764 100644
--- a/criu/Makefile.crtools
+++ b/criu/Makefile.crtools
@@ -1,5 +1,6 @@ 
 ccflags-y		+= -iquote criu/$(ARCH)
 obj-y			+= action-scripts.o
+obj-y			+= external.o
 obj-y			+= aio.o
 obj-y			+= bfd.o
 obj-y			+= bitmap.o
diff --git a/criu/cr-service.c b/criu/cr-service.c
index 2cb6f83..460680b 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -17,6 +17,7 @@ 
 
 #include "crtools.h"
 #include "cr_options.h"
+#include "external.h"
 #include "util.h"
 #include "log.h"
 #include "cpu.h"
diff --git a/criu/crtools.c b/criu/crtools.c
index fe3c5a0..6c3c3b5 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -24,6 +24,7 @@ 
 #include "compiler.h"
 #include "crtools.h"
 #include "cr_options.h"
+#include "external.h"
 #include "sockets.h"
 #include "files.h"
 #include "sk-inet.h"
@@ -193,19 +194,6 @@  static size_t parse_size(char *optarg)
 	return (size_t)atol(optarg);
 }
 
-int add_external(char *key)
-{
-	struct external *ext;
-
-	ext = xmalloc(sizeof(*ext));
-	if (!ext)
-		return -1;
-	ext->id = key;
-	list_add(&ext->node, &opts.external);
-
-	return 0;
-}
-
 bool deprecated_ok(char *what)
 {
 	if (opts.deprecated_ok)
diff --git a/criu/external.c b/criu/external.c
new file mode 100644
index 0000000..bb7ef06
--- /dev/null
+++ b/criu/external.c
@@ -0,0 +1,42 @@ 
+#include "list.h"
+#include "cr_options.h"
+#include "xmalloc.h"
+#include "external.h"
+
+int add_external(char *key)
+{
+	struct external *ext;
+
+	ext = xmalloc(sizeof(*ext));
+	if (!ext)
+		return -1;
+	ext->id = key;
+	list_add(&ext->node, &opts.external);
+
+	return 0;
+}
+
+bool external_lookup_id(char *id)
+{
+	struct external *ext;
+
+	list_for_each_entry(ext, &opts.external, node)
+		if (!strcmp(ext->id, id))
+			return true;
+	return false;
+}
+
+char *external_lookup_by_key(char *key)
+{
+	struct external *ext;
+	int len = strlen(key);
+
+	list_for_each_entry(ext, &opts.external, node) {
+		if (strncmp(ext->id, key, len))
+			continue;
+		if (ext->id[len] == ':')
+			return ext->id + len + 1;
+	}
+	return NULL;
+}
+
diff --git a/criu/files-reg.c b/criu/files-reg.c
index b91a2c3..7817fb4 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -28,6 +28,7 @@ 
 #include "proc_parse.h"
 #include "pstree.h"
 #include "fault-injection.h"
+#include "external.h"
 
 #include "protobuf.h"
 #include "images/regfile.pb-c.h"
diff --git a/criu/files.c b/criu/files.c
index 7e7e3a5..2dbbf5a 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -1649,30 +1649,6 @@  int inherit_fd_fini()
 	return 0;
 }
 
-bool external_lookup_id(char *id)
-{
-	struct external *ext;
-
-	list_for_each_entry(ext, &opts.external, node)
-		if (!strcmp(ext->id, id))
-			return true;
-	return false;
-}
-
-char *external_lookup_by_key(char *key)
-{
-	struct external *ext;
-	int len = strlen(key);
-
-	list_for_each_entry(ext, &opts.external, node) {
-		if (strncmp(ext->id, key, len))
-			continue;
-		if (ext->id[len] == ':')
-			return ext->id + len + 1;
-	}
-	return NULL;
-}
-
 int open_transport_socket()
 {
 	int sock;
diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
index ba5c23f..7711a7a 100644
--- a/criu/include/cr_options.h
+++ b/criu/include/cr_options.h
@@ -47,11 +47,6 @@  struct irmap_path_opt {
 	struct irmap *ir;
 };
 
-struct external {
-	struct list_head node;
-	char *id;
-};
-
 struct cr_options {
 	int			final_state;
 	char			*show_dump_file;
@@ -127,6 +122,4 @@  extern struct cr_options opts;
 
 extern void init_opts(void);
 
-extern int add_external(char *key);
-
 #endif /* __CR_OPTIONS_H__ */
diff --git a/criu/include/external.h b/criu/include/external.h
new file mode 100644
index 0000000..d343732
--- /dev/null
+++ b/criu/include/external.h
@@ -0,0 +1,11 @@ 
+#ifndef __CR_EXTERNAL_H__
+#define __CR_EXTERNAL_H__
+struct external {
+	struct list_head node;
+	char *id;
+};
+
+extern int add_external(char *key);
+extern bool external_lookup_id(char *id);
+extern char *external_lookup_by_key(char *id);
+#endif
diff --git a/criu/include/files.h b/criu/include/files.h
index 7513b21..c073c03 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -191,9 +191,7 @@  extern void inherit_fd_log(void);
 extern int inherit_fd_resolve_clash(int fd);
 extern int inherit_fd_fini(void);
 
-extern bool external_lookup_id(char *id);
 extern int inherit_fd_lookup_id(char *id);
-extern char *external_lookup_by_key(char *id);
 
 extern bool inherited_fd(struct file_desc *, int *fdp);
 
diff --git a/criu/mount.c b/criu/mount.c
index 615a71a..6e98f1e 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -30,6 +30,7 @@ 
 #include "path.h"
 #include "autofs.h"
 #include "files-reg.h"
+#include "external.h"
 
 #include "images/mnt.pb-c.h"
 #include "images/binfmt-misc.pb-c.h"
diff --git a/criu/tty.c b/criu/tty.c
index 8090e22..d1fc671 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -28,6 +28,7 @@ 
 #include "file-ids.h"
 #include "files-reg.h"
 #include "namespaces.h"
+#include "external.h"
 
 #include "protobuf.h"
 #include "images/tty.pb-c.h"