[CRIU] [PATCH] image: Add O_OPT when trying to open optional image files

Cyrill Gorcunov gorcunov at openvz.org
Fri Mar 14 06:38:28 PDT 2014


During the time some files become obsolete and might be missing
in checkpoint image set, but to keep backward compatibility we
still trying to open them, which might print out error like

 | Unable to open 'path-to-file'

and confuse a reader why criu prints error but continue working.

To eliminate this problem O_OPT flag has been introduced in
commit 16b5692061e2, which suppress error message priting
if the flag is set.

Now start using O_OPT in the following functions

 - open_irmap_cache: irmap cache is relatively new optional feature

 - prepare_rlimits, open_signal_image, restore_file_locks,
   prepare_fd_pid, prepare_mm_pid, collect_image: all these
   helpers are trying to open image files which can be missing.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-restore.c | 8 ++++----
 file-lock.c  | 4 ++--
 files.c      | 4 ++--
 irmap.c      | 6 +++---
 mem.c        | 4 ++--
 protobuf.c   | 5 +++--
 6 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index f7fea99b8c29..df270760b0b9 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -2070,9 +2070,9 @@ static int prepare_rlimits(int pid, CoreEntry *core)
 	/*
 	 * Old image -- read from the file.
 	 */
-	fd = open_image(CR_FD_RLIMIT, O_RSTR, pid);
+	fd = open_image(CR_FD_RLIMIT, O_RSTR | O_OPT, pid);
 	if (fd < 0) {
-		if (errno == ENOENT) {
+		if (fd == -ENOENT) {
 			pr_info("Skip rlimits for %d\n", pid);
 			return 0;
 		}
@@ -2116,9 +2116,9 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr)
 {
 	int fd, ret;
 
-	fd = open_image(type, O_RSTR, pid);
+	fd = open_image(type, O_RSTR | O_OPT, pid);
 	if (fd < 0) {
-		if (errno == ENOENT) /* backward compatibility */
+		if (fd == -ENOENT) /* backward compatibility */
 			return 0;
 		else
 			return -1;
diff --git a/file-lock.c b/file-lock.c
index de9dc227cfe3..5276d2ea5d6d 100644
--- a/file-lock.c
+++ b/file-lock.c
@@ -226,9 +226,9 @@ static int restore_file_locks(int pid)
 	int fd, ret = -1;
 	FileLockEntry *fle;
 
-	fd = open_image(CR_FD_FILE_LOCKS, O_RSTR, pid);
+	fd = open_image(CR_FD_FILE_LOCKS, O_RSTR | O_OPT, pid);
 	if (fd < 0) {
-		if (errno == ENOENT)
+		if (fd == -ENOENT)
 			return 0;
 		else
 			return -1;
diff --git a/files.c b/files.c
index e6a32ee58353..3cf5e470c5c0 100644
--- a/files.c
+++ b/files.c
@@ -601,9 +601,9 @@ int prepare_fd_pid(struct pstree_item *item)
 	INIT_LIST_HEAD(&rst_info->tty_slaves);
 
 	if (!fdinfo_per_id) {
-		fdinfo_fd = open_image(CR_FD_FDINFO, O_RSTR, pid);
+		fdinfo_fd = open_image(CR_FD_FDINFO, O_RSTR | O_OPT, pid);
 		if (fdinfo_fd < 0) {
-			if (errno == ENOENT)
+			if (fdinfo_fd == -ENOENT)
 				return 0;
 			return -1;
 		}
diff --git a/irmap.c b/irmap.c
index 2b75f844f5b7..1af4a95568e5 100644
--- a/irmap.c
+++ b/irmap.c
@@ -360,7 +360,7 @@ static int open_irmap_cache(int *fd)
 
 	pr_info("Searching irmap cache in work dir\n");
 in:
-	*fd = open_image_at(dir, CR_FD_IRMAP_CACHE, O_RSTR);
+	*fd = open_image_at(dir, CR_FD_IRMAP_CACHE, O_RSTR | O_OPT);
 	if (dir != AT_FDCWD)
 		close(dir);
 
@@ -369,14 +369,14 @@ in:
 		return 1;
 	}
 
-	if (errno == ENOENT && dir == AT_FDCWD) {
+	if (*fd == -ENOENT && dir == AT_FDCWD) {
 		pr_info("Searching irmap cache in parent\n");
 		dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
 		if (dir >= 0)
 			goto in;
 	}
 
-	if (errno != ENOENT)
+	if (*fd != -ENOENT)
 		return -1;
 
 	pr_info("No irmap cache\n");
diff --git a/mem.c b/mem.c
index b6681d161e5f..ef1d0106651d 100644
--- a/mem.c
+++ b/mem.c
@@ -376,9 +376,9 @@ int prepare_mm_pid(struct pstree_item *i)
 	int fd, ret = -1, vn = 0;
 	struct rst_info *ri = i->rst;
 
-	fd = open_image(CR_FD_MM, O_RSTR, pid);
+	fd = open_image(CR_FD_MM, O_RSTR | O_OPT, pid);
 	if (fd < 0) {
-		if (errno == ENOENT)
+		if (fd == -ENOENT)
 			return 0;
 		return -1;
 	}
diff --git a/protobuf.c b/protobuf.c
index e6abe942061b..fe09d6ab5c08 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -654,6 +654,7 @@ err:
 
 int collect_image(struct collect_image_info *cinfo)
 {
+	bool optional = !!(cinfo->flags & COLLECT_OPTIONAL);
 	int fd, ret;
 	void *(*o_alloc)(size_t size) = malloc;
 	void (*o_free)(void *ptr) = free;
@@ -661,9 +662,9 @@ int collect_image(struct collect_image_info *cinfo)
 	pr_info("Collecting %d/%d (flags %x)\n",
 			cinfo->fd_type, cinfo->pb_type, cinfo->flags);
 
-	fd = open_image(cinfo->fd_type, O_RSTR);
+	fd = open_image(cinfo->fd_type, O_RSTR | optional ? O_OPT : 0);
 	if (fd < 0) {
-		if ((cinfo->flags & COLLECT_OPTIONAL) && (errno == ENOENT))
+		if (optional && fd == -ENOENT)
 			return 0;
 		else
 			return -1;
-- 
1.8.3.1



More information about the CRIU mailing list