Commit 1153f225 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

image: Add O_OPT when trying to open optional image files

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 16b56920, 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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 5f433a6e
...@@ -2070,9 +2070,9 @@ static int prepare_rlimits(int pid, CoreEntry *core) ...@@ -2070,9 +2070,9 @@ static int prepare_rlimits(int pid, CoreEntry *core)
/* /*
* Old image -- read from the file. * 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 (fd < 0) {
if (errno == ENOENT) { if (fd == -ENOENT) {
pr_info("Skip rlimits for %d\n", pid); pr_info("Skip rlimits for %d\n", pid);
return 0; return 0;
} }
...@@ -2116,9 +2116,9 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr) ...@@ -2116,9 +2116,9 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr)
{ {
int fd, ret; int fd, ret;
fd = open_image(type, O_RSTR, pid); fd = open_image(type, O_RSTR | O_OPT, pid);
if (fd < 0) { if (fd < 0) {
if (errno == ENOENT) /* backward compatibility */ if (fd == -ENOENT) /* backward compatibility */
return 0; return 0;
else else
return -1; return -1;
......
...@@ -226,9 +226,9 @@ static int restore_file_locks(int pid) ...@@ -226,9 +226,9 @@ static int restore_file_locks(int pid)
int fd, ret = -1; int fd, ret = -1;
FileLockEntry *fle; 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 (fd < 0) {
if (errno == ENOENT) if (fd == -ENOENT)
return 0; return 0;
else else
return -1; return -1;
......
...@@ -601,9 +601,9 @@ int prepare_fd_pid(struct pstree_item *item) ...@@ -601,9 +601,9 @@ int prepare_fd_pid(struct pstree_item *item)
INIT_LIST_HEAD(&rst_info->tty_slaves); INIT_LIST_HEAD(&rst_info->tty_slaves);
if (!fdinfo_per_id) { 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 (fdinfo_fd < 0) {
if (errno == ENOENT) if (fdinfo_fd == -ENOENT)
return 0; return 0;
return -1; return -1;
} }
......
...@@ -360,7 +360,7 @@ static int open_irmap_cache(int *fd) ...@@ -360,7 +360,7 @@ static int open_irmap_cache(int *fd)
pr_info("Searching irmap cache in work dir\n"); pr_info("Searching irmap cache in work dir\n");
in: 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) if (dir != AT_FDCWD)
close(dir); close(dir);
...@@ -369,14 +369,14 @@ in: ...@@ -369,14 +369,14 @@ in:
return 1; return 1;
} }
if (errno == ENOENT && dir == AT_FDCWD) { if (*fd == -ENOENT && dir == AT_FDCWD) {
pr_info("Searching irmap cache in parent\n"); pr_info("Searching irmap cache in parent\n");
dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY); dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
if (dir >= 0) if (dir >= 0)
goto in; goto in;
} }
if (errno != ENOENT) if (*fd != -ENOENT)
return -1; return -1;
pr_info("No irmap cache\n"); pr_info("No irmap cache\n");
......
...@@ -376,9 +376,9 @@ int prepare_mm_pid(struct pstree_item *i) ...@@ -376,9 +376,9 @@ int prepare_mm_pid(struct pstree_item *i)
int fd, ret = -1, vn = 0; int fd, ret = -1, vn = 0;
struct rst_info *ri = i->rst; 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 (fd < 0) {
if (errno == ENOENT) if (fd == -ENOENT)
return 0; return 0;
return -1; return -1;
} }
......
...@@ -654,6 +654,7 @@ err: ...@@ -654,6 +654,7 @@ err:
int collect_image(struct collect_image_info *cinfo) int collect_image(struct collect_image_info *cinfo)
{ {
bool optional = !!(cinfo->flags & COLLECT_OPTIONAL);
int fd, ret; int fd, ret;
void *(*o_alloc)(size_t size) = malloc; void *(*o_alloc)(size_t size) = malloc;
void (*o_free)(void *ptr) = free; void (*o_free)(void *ptr) = free;
...@@ -661,9 +662,9 @@ int collect_image(struct collect_image_info *cinfo) ...@@ -661,9 +662,9 @@ int collect_image(struct collect_image_info *cinfo)
pr_info("Collecting %d/%d (flags %x)\n", pr_info("Collecting %d/%d (flags %x)\n",
cinfo->fd_type, cinfo->pb_type, cinfo->flags); 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 (fd < 0) {
if ((cinfo->flags & COLLECT_OPTIONAL) && (errno == ENOENT)) if (optional && fd == -ENOENT)
return 0; return 0;
else else
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment