[CRIU] [PATCH] reg-files: skip size for O_APPEND|O_WRONLY files, v2

Ruslan Kuprieiev kupruser at gmail.com
Thu Mar 19 10:25:57 PDT 2015


From: Ruslan Kuprieiev <rkuprieiev at cloudlinux.com>

This is common for log files, when a number of processes
are writing something into one file. Currently, if someone
wrote something to log since dump happened, on restore criu
will complain about "File has bad size" and refuse to restore.

If file is opened with O_APPEND|O_WRONLY flags it is going to
jump to the EOF anyway.

v2, use O_ACCMODE and separate helper

Signed-off-by: Ruslan Kuprieiev <rkuprieiev at cloudlinux.com>
---
 files-reg.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/files-reg.c b/files-reg.c
index a716a69..88c6cc1 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -791,6 +791,16 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms,
 	return 0;
 }
 
+static bool should_check_size(int flags)
+{
+	/* Skip size if file has O_APPEND and O_WRONLY flags(i.e. log file). */
+	if (((flags & O_ACCMODE) == O_WRONLY) &&
+	    (flags & O_APPEND))
+		return false;
+
+	return true;
+}
+
 int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 {
 	struct fd_link _link, *link;
@@ -837,7 +847,7 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 	rfe.fown	= (FownEntry *)&p->fown;
 	rfe.name	= &link->name[1];
 
-	if (S_ISREG(p->stat.st_mode)) {
+	if (S_ISREG(p->stat.st_mode) && should_check_size(rfe.flags)) {
 		rfe.has_size = true;
 		rfe.size = p->stat.st_size;
 	}
-- 
2.1.0



More information about the CRIU mailing list