[CRIU] [PATCH 2/2] opts: Allo to specify the maximum size of ghost files

Cyrill Gorcunov gorcunov at openvz.org
Mon Aug 10 02:44:03 PDT 2015


For example we hit a case where systemd carries journal
file with 4M in size.

https://jira.sw.ru/browse/PSBM-38571

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Documentation/criu.txt |  6 ++++++
 crtools.c              | 17 +++++++++++++++++
 files-reg.c            |  4 ++--
 include/cr_options.h   |  1 +
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Documentation/criu.txt b/Documentation/criu.txt
index b73a416ef4ff..633ef216537a 100644
--- a/Documentation/criu.txt
+++ b/Documentation/criu.txt
@@ -176,6 +176,12 @@ In other words, do not use it until really needed.
 *--link-remap*::
     Allow one to link unlinked files back when possible (modifies FS till *restore*).
 
+*--ghost-limit* 'size'::
+    Allow one to specify maximum allowed size of deleted file to be carried
+    inside image files. By default up to 1M file is allowed. It is done in
+    a sake to not carry big files inside images. 'size' may be postfixed
+    with 'K', 'M' or 'G' (which stands for kilo, mega and gigabytes accordingly).
+
 *-j*, *--shell-job*::
     Allow one to dump shell jobs. This implies the restored task will inherit session and
     process group ID from the criu itself. Also this option allows one to migrate a
diff --git a/crtools.c b/crtools.c
index 6af60804b321..996eb3b3ce5c 100644
--- a/crtools.c
+++ b/crtools.c
@@ -60,6 +60,7 @@ void init_opts(void)
 	opts.cpu_cap = CPU_CAP_DEFAULT;
 	opts.manage_cgroups = CG_MODE_DEFAULT;
 	opts.ps_socket = -1;
+	opts.ghost_limit = (1 * 1024 * 1024);
 }
 
 static int parse_ns_string(const char *ptr)
@@ -175,6 +176,17 @@ Esyntax:
 	return -1;
 }
 
+static size_t parse_size(char *optarg)
+{
+	if (index(optarg, 'K'))
+		return (size_t)KILO(atol(optarg));
+	else if (index(optarg, 'M'))
+		return (size_t)MEGA(atol(optarg));
+	else if (index(optarg, 'G'))
+		return (size_t)GIGA(atol(optarg));
+	return (size_t)atol(optarg);
+}
+
 int main(int argc, char *argv[], char *envp[])
 {
 	pid_t pid = 0, tree_id = 0;
@@ -235,6 +247,7 @@ int main(int argc, char *argv[], char *envp[])
 		{ "enable-fs",			required_argument,	0, 1065 },
 		{ "enable-external-sharing", 	no_argument, 		0, 1066 },
 		{ "enable-external-masters", 	no_argument, 		0, 1067 },
+		{ "ghost-limit",		required_argument,	0, 1068 },
 		{ },
 	};
 
@@ -465,6 +478,9 @@ int main(int argc, char *argv[], char *envp[])
 		case 1067:
 			opts.enable_external_masters = true;
 			break;
+		case 1068:
+			opts.ghost_limit = parse_size(optarg);
+			break;
 		case 'M':
 			{
 				char *aux;
@@ -687,6 +703,7 @@ usage:
 "                        can optionally append @<bridge-name> to OUT for moving\n"
 "                        the outside veth to the named bridge\n"
 "  --link-remap          allow one to link unlinked files back when possible\n"
+"  --ghost-limit size    specify maximum size of deleted file contents to be carried inside an image file\n"
 "  --action-script FILE  add an external action script\n"
 "  -j|--" OPT_SHELL_JOB "        allow one to dump and restore shell jobs\n"
 "  -l|--" OPT_FILE_LOCKS "       handle file locks, for safety, only used for container\n"
diff --git a/files-reg.c b/files-reg.c
index 5a664494f2d8..16233831bb04 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -423,8 +423,8 @@ static int dump_ghost_remap(char *path, const struct stat *st,
 
 	pr_info("Dumping ghost file for fd %d id %#x\n", lfd, id);
 
-	if (st->st_size > MAX_GHOST_FILE_SIZE) {
-		pr_err("Can't dump ghost file %s of %"PRIu64" size\n",
+	if (st->st_size > opts.ghost_limit) {
+		pr_err("Can't dump ghost file %s of %"PRIu64" size, increase limit\n",
 				path, st->st_size);
 		return -1;
 	}
diff --git a/include/cr_options.h b/include/cr_options.h
index 011349c3e043..74aa0103ddec 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -80,6 +80,7 @@ struct cr_options {
 	bool			enable_external_masters;
 	bool			aufs;		/* auto-deteced, not via cli */
 	bool			overlayfs;
+	size_t			ghost_limit;
 };
 
 extern struct cr_options opts;
-- 
2.4.3



More information about the CRIU mailing list