[CRIU] [PATCH 1/2] reg-files: Allow to skip file size checking via --skip-fsize-path option

Cyrill Gorcunov gorcunov at openvz.org
Thu Mar 23 08:20:16 PDT 2017


Some files may be updated by kernel with acct() syscall so
the size kept inside image won't match one upon task exit.

Because there is no way to fetch this setting from the
kernel without its modifucation (or moreover because
we have to be able to work with older images) lets
rather allow a user to specify file path to skip size
check on.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/crtools.c            | 18 ++++++++++++++++++
 criu/files-reg.c          | 28 +++++++++++++++++++++++++---
 criu/include/cr_options.h |  2 ++
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/criu/crtools.c b/criu/crtools.c
index 927ca8e5db71..d82056bf9b06 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -291,6 +291,7 @@ int main(int argc, char *argv[], char *envp[])
 		{ "weak-sysctls",		no_argument,		0, 1087 },
 		{ "status-fd",			required_argument,	0, 1088 },
 		{ "remote",			no_argument,		0, 1089 },
+		{ "skip-fsize-path",		required_argument,	0, 1090 },
 		{ },
 	};
 
@@ -625,6 +626,20 @@ int main(int argc, char *argv[], char *envp[])
 		case 1089:
 			opts.remote = true;
 			break;
+		case 1090:
+			if (xrealloc_safe(&opts.skip_fsize_paths,
+					  sizeof(opts.skip_fsize_paths) *
+					  (opts.nr_skip_fsize_paths + 1))) {
+				pr_err("Can't setup path to skip size on\n");
+				return 1;
+			} else {
+				/*
+				 * We don't release this memory
+				 * explicitly, OS will do upon exit.
+				 */
+				opts.skip_fsize_paths[opts.nr_skip_fsize_paths++] = optarg;
+			}
+			break;
 		case 'V':
 			pr_msg("Version: %s\n", CRIU_VERSION);
 			if (strcmp(CRIU_GITID, "0"))
@@ -926,6 +941,9 @@ usage:
 "                        define cgroup controller to be dumped\n"
 "                        and skip anything else present in system\n"
 "  --skip-mnt PATH       ignore this mountpoint when dumping the mount namespace\n"
+"  --skip-fsize-path PATH\n"
+"                        ignore this relative PATH when checking for file size on both\n"
+"                        during checkpoing and restore\n"
 "  --enable-fs FSNAMES   a comma separated list of filesystem names or \"all\"\n"
 "                        force criu to (try to) dump/restore these filesystem's\n"
 "                        mountpoints even if fs is not supported\n"
diff --git a/criu/files-reg.c b/criu/files-reg.c
index 3b93bb9e445d..213a6971510f 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -1089,8 +1089,28 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms,
 	return 0;
 }
 
-static bool should_check_size(int flags)
+static bool in_skip_fsize_list(const char *name)
 {
+	size_t i;
+
+	/*
+	 * If been explicitly requested, don't check for
+	 * size, for example on files which are updated
+	 * by kernel itself with acct() syscall.
+	 */
+	for (i = 0; i < opts.nr_skip_fsize_paths; i++) {
+		if (!strcmp(opts.skip_fsize_paths[i], name))
+			return true;
+	}
+
+	return false;
+}
+
+static bool should_check_size(char *name, int flags)
+{
+	if (in_skip_fsize_list(name))
+		return false;
+
 	/* Skip size if file has O_APPEND and O_WRONLY flags (e.g. log file). */
 	if (((flags & O_ACCMODE) == O_WRONLY) &&
 			(flags & O_APPEND))
@@ -1160,7 +1180,7 @@ ext:
 	rfe.has_mode	= true;
 	rfe.mode	= p->stat.st_mode;
 
-	if (S_ISREG(p->stat.st_mode) && should_check_size(rfe.flags)) {
+	if (S_ISREG(p->stat.st_mode) && should_check_size(&link->name[1], rfe.flags)) {
 		rfe.has_size = true;
 		rfe.size = p->stat.st_size;
 	}
@@ -1514,7 +1534,9 @@ ext:
 			return -1;
 		}
 
-		if (rfi->rfe->has_size && (st.st_size != rfi->rfe->size)) {
+		if (rfi->rfe->has_size &&
+		    !in_skip_fsize_list(rfi->path) &&
+		    (st.st_size != rfi->rfe->size)) {
 			pr_err("File %s has bad size %"PRIu64" (expect %"PRIu64")\n",
 					rfi->path, st.st_size,
 					rfi->rfe->size);
diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
index 518d2a342922..90d12671f5e5 100644
--- a/criu/include/cr_options.h
+++ b/criu/include/cr_options.h
@@ -122,6 +122,8 @@ struct cr_options {
 	bool			orphan_pts_master;
 	bool			check_only;
 	bool			remote;
+	size_t			nr_skip_fsize_paths;
+	char			**skip_fsize_paths;
 };
 
 extern struct cr_options opts;
-- 
2.7.4



More information about the CRIU mailing list