[CRIU] [PATCH CRIU v2] cpt/rst: access and modification time of ghost files

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Dec 22 07:22:57 PST 2015


Modification time changes after cpt/rst file_attr test in VZ7CT:
CT-102 criu# cat test/zdtm/live/static/file_attr.out
15:05:05.315:   146: FAIL: file_attr.c:101: modification time has
changed (errno = 11 (Resource temporarily unavailable))

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

v2: add timeval message, test seem to pass now - remove noauto
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 files-reg.c                          | 20 ++++++++++++++++++++
 protobuf/Makefile                    |  1 +
 protobuf/ghost-file.proto            |  3 +++
 protobuf/time.proto                  |  4 ++++
 test/zdtm/live/static/file_attr.desc |  1 -
 5 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 protobuf/time.proto
 delete mode 100644 test/zdtm/live/static/file_attr.desc

diff --git a/files-reg.c b/files-reg.c
index 9aa2481..0f89be5 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -99,6 +99,7 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_im
 {
 	int gfd, ghost_flags, ret;
 	char path[PATH_MAX];
+	struct timeval tv[2];
 
 	ret = rst_get_mnt_root(gf->remap.rmnt_id, path, sizeof(path));
 	if (ret < 0) {
@@ -156,6 +157,17 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_im
 		goto err_c;
 	}
 
+	if (gfe->atim) {
+		tv[0].tv_sec = gfe->atim->tv_sec;
+		tv[0].tv_usec = gfe->atim->tv_usec;
+		tv[1].tv_sec = gfe->mtim->tv_sec;
+		tv[1].tv_usec = gfe->mtim->tv_usec;
+		if (futimes(gfd, tv)) {
+			pr_perror("Can't set access and modufication times on ghost %s", path);
+			goto err_c;
+		}
+	}
+
 	ret = 0;
 err_c:
 	close(gfd);
@@ -518,6 +530,7 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st, dev_t phys_de
 {
 	struct cr_img *img;
 	GhostFileEntry gfe = GHOST_FILE_ENTRY__INIT;
+	Timeval atim = TIMEVAL__INIT, mtim = TIMEVAL__INIT;
 
 	pr_info("Dumping ghost file contents (id %#x)\n", id);
 
@@ -529,6 +542,13 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st, dev_t phys_de gfe.gid = userns_gid(st->st_gid); gfe.mode = st->st_mode;
 
+	gfe.atim = &atim;
+	gfe.mtim = &mtim;
+	gfe.atim->tv_sec = st->st_atim.tv_sec;
+	gfe.atim->tv_usec = st->st_atim.tv_nsec / 1000;
+	gfe.mtim->tv_sec = st->st_mtim.tv_sec;
+	gfe.mtim->tv_usec = st->st_mtim.tv_nsec / 1000;
+
 	gfe.has_dev = gfe.has_ino = true;
 	gfe.dev = phys_dev;
 	gfe.ino = st->st_ino;
diff --git a/protobuf/Makefile b/protobuf/Makefile
index 4b43eca..12089a2 100644
--- a/protobuf/Makefile
+++ b/protobuf/Makefile
@@ -57,6 +57,7 @@ proto-obj-y	+= google/protobuf/descriptor.o # To make protoc-c happy and compile
 proto-obj-y	+= opts.o
 proto-obj-y	+= seccomp.o
 proto-obj-y	+= binfmt-misc.o
+proto-obj-y	+= time.o
 
 CFLAGS		+= -I$(obj)/
 
diff --git a/protobuf/ghost-file.proto b/protobuf/ghost-file.proto
index a600a43..db056db 100644
--- a/protobuf/ghost-file.proto
+++ b/protobuf/ghost-file.proto
@@ -1,4 +1,5 @@
 import "opts.proto";
+import "time.proto";
 
 message ghost_file_entry {
 	required uint32		uid		= 1;
@@ -8,4 +9,6 @@ message ghost_file_entry {
 	optional uint32		dev		= 4 [(criu).dev = true];
 	optional uint64		ino		= 5;
 	optional uint32		rdev		= 6 [(criu).dev = true, (criu).odev = true];
+	optional timeval	atim		= 7;
+	optional timeval	mtim		= 8;
 }
diff --git a/protobuf/time.proto b/protobuf/time.proto
new file mode 100644
index 0000000..09cdf42
--- /dev/null
+++ b/protobuf/time.proto
@@ -0,0 +1,4 @@
+message timeval {
+	required uint64		tv_sec	= 1;
+	required uint64		tv_usec	= 2;
+}
diff --git a/test/zdtm/live/static/file_attr.desc b/test/zdtm/live/static/file_attr.desc
deleted file mode 100644
index 95c58b4..0000000
--- a/test/zdtm/live/static/file_attr.desc
+++ /dev/null
@@ -1 +0,0 @@
-{'flags': 'noauto'}
-- 
1.9.3



More information about the CRIU mailing list