[CRIU] [PATCH v3 02/11] gc: mock implementation of new gc command

Eugene Batalov eabatalov89 at gmail.com
Wed Aug 10 12:12:46 PDT 2016


From: Maxim Kuzmin <maxriderg at gmail.com>

gc is a new CRIU command. Its aim is to remove helper objects
needed for restore that were left in the system after dump was performed.
Its main use case is to cleanup on node where dump was
performed but restore isn't planned.
Dumped ps tree should be dead on criu gc invocation.

CRIU gc accepts dump dir path as an input and removes:
1. Link remaps created for ps tree
2. Netfilter rules that drop ps tree tcp packets
Currently this is all that CRIU dump leaves in the system

--show option changes gc command behavior. It only
shows what was left in the system without objects removal.

Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 criu/Makefile.crtools     |  1 +
 criu/cr-gc.c              |  6 ++++++
 criu/crtools.c            | 13 +++++++++++++
 criu/include/cr_options.h |  1 +
 criu/include/crtools.h    |  1 +
 5 files changed, 22 insertions(+)
 create mode 100644 criu/cr-gc.c

diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools
index 52c00ec..bb13459 100644
--- a/criu/Makefile.crtools
+++ b/criu/Makefile.crtools
@@ -6,6 +6,7 @@ obj-y			+= bitmap.o
 obj-y			+= cgroup.o
 obj-y			+= cgroup-props.o
 obj-y			+= cr-check.o
+obj-y			+= cr-gc.o
 obj-y			+= cr-dedup.o
 obj-y			+= cr-dump.o
 obj-y			+= cr-errno.o
diff --git a/criu/cr-gc.c b/criu/cr-gc.c
new file mode 100644
index 0000000..bdd3723
--- /dev/null
+++ b/criu/cr-gc.c
@@ -0,0 +1,6 @@
+#include "crtools.h"
+
+int cr_gc(void)
+{
+	return 0;
+}
diff --git a/criu/crtools.c b/criu/crtools.c
index 7e11c22..bbbed67 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -324,6 +324,7 @@ int main(int argc, char *argv[], char *envp[])
 		{ "cgroup-props-file",		required_argument,	0, 1081	},
 		{ "cgroup-dump-controller",	required_argument,	0, 1082	},
 		{ SK_INFLIGHT_PARAM,		no_argument,		0, 1083	},
+		{ "show",			no_argument,		0, 1084	},
 		{ },
 	};
 
@@ -639,6 +640,9 @@ int main(int argc, char *argv[], char *envp[])
 			pr_msg("Will skip in-flight TCP connections\n");
 			opts.tcp_skip_in_flight = true;
 			break;
+		case 1084:
+			opts.show = true;
+			break;
 		case 'V':
 			pr_msg("Version: %s\n", CRIU_VERSION);
 			if (strcmp(CRIU_GITID, "0"))
@@ -809,6 +813,9 @@ int main(int argc, char *argv[], char *envp[])
 			return cpuinfo_check();
 	}
 
+	if (!strcmp(argv[optind], "gc"))
+		return cr_gc();
+
 	pr_msg("Error: unknown command: %s\n", argv[optind]);
 usage:
 	pr_msg("\n"
@@ -821,6 +828,7 @@ usage:
 "  criu service [<options>]\n"
 "  criu dedup\n"
 "  criu lazy-pages -D DIR [<options>]\n"
+"  criu gc -D DIR [<options>]\n"
 "\n"
 "Commands:\n"
 "  dump           checkpoint a process/tree identified by pid\n"
@@ -833,6 +841,8 @@ usage:
 "  dedup          remove duplicates in memory dump\n"
 "  cpuinfo dump   writes cpu information into image file\n"
 "  cpuinfo check  validates cpu information read from image file\n"
+"  gc             deletes helper objects needed for restore that were left\n"
+"                 in the system after dump. Makes dump not restorable\n"
 	);
 
 	if (usage_error) {
@@ -976,6 +986,9 @@ usage:
 "  --port PORT           port of page server\n"
 "  -d|--daemon           run in the background after creating socket\n"
 "\n"
+"Garbage collection options:\n"
+"  --show                show what will be deleted without actual deletion\n"
+"\n"
 "Other options:\n"
 "  -h|--help             show this text\n"
 "  -V|--version          show version\n"
diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
index 35c1ace..5d6a03d 100644
--- a/criu/include/cr_options.h
+++ b/criu/include/cr_options.h
@@ -113,6 +113,7 @@ struct cr_options {
 	bool			lazy_pages;
 	bool			tcp_skip_in_flight;
 	char			*work_dir;
+	bool			show;
 };
 
 extern struct cr_options opts;
diff --git a/criu/include/crtools.h b/criu/include/crtools.h
index f3c9f7f..8f961f0 100644
--- a/criu/include/crtools.h
+++ b/criu/include/crtools.h
@@ -24,6 +24,7 @@ extern int cr_check(void);
 extern int cr_exec(int pid, char **opts);
 extern int cr_dedup(void);
 extern int cr_lazy_pages(void);
+extern int cr_gc(void);
 
 extern int check_add_feature(char *arg);
 
-- 
1.9.1



More information about the CRIU mailing list