[CRIU] [PATCH] files-reg: Adjust file position for /dev/kmsg

Cyrill Gorcunov gorcunov at gmail.com
Mon Jul 20 09:57:04 PDT 2015


On Mon, Jul 20, 2015 at 07:49:31PM +0300, Pavel Emelyanov wrote:
> 
> && rfe->pos == 0, we don't want to screw up somehow changed pos, do we?

yeah, thanks! updated
-------------- next part --------------
>From 610d345c26bcaa1f4790c08dcacd379d50c64c72 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon, 20 Jul 2015 12:40:16 +0300
Subject: [PATCH] files-reg: Adjust file position for /dev/kmsg

The kernel doesnt allow to call lseek on /dev/kmsg
if it has been opened with O_WRONLY mode so our
restore procedure fails.

Add adjust_file_pos() helper which would handle
this problem on dump.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 files-reg.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/files-reg.c b/files-reg.c
index 2a6269b2a550..cacd46c14839 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -9,6 +9,8 @@
 #include <sys/vfs.h>
 #include <ctype.h>
 
+#include <linux/major.h>
+
 /* Stolen from kernel/fs/nfs/unlink.c */
 #define SILLYNAME_PREF ".nfs"
 #define SILLYNAME_SUFF_LEN (((unsigned)sizeof(u64) << 1) + ((unsigned)sizeof(unsigned int) << 1))
@@ -801,6 +803,21 @@ static bool should_check_size(int flags)
 	return true;
 }
 
+static void adjust_file_pos(const struct fd_parms *p, RegFileEntry *rfe)
+{
+	int maj = major(p->stat.st_rdev);
+	int min = minor(p->stat.st_rdev);
+
+	/*
+	 * If /dev/kmsg is opened in write-only mode the file position
+	 * should not be set up upon restore, kernel doesn't allow that.
+	 */
+	if (maj == MEM_MAJOR && min == 11) {
+		if ((rfe->flags & O_ACCMODE) == O_WRONLY && rfe->pos == 0)
+			rfe->pos = -1ULL;
+	}
+}
+
 int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 {
 	struct fd_link _link, *link;
@@ -853,6 +870,8 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 		rfe.size = p->stat.st_size;
 	}
 
+	adjust_file_pos(p, &rfe);
+
 	rimg = img_from_set(glob_imgset, CR_FD_REG_FILES);
 	return pb_write_one(rimg, &rfe, PB_REG_FILE);
 }
-- 
2.4.3



More information about the CRIU mailing list