From e29c9daec271614a06bf2f5fb8ed77cbd72ae1a6 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 6 Mar 2015 18:01:54 +0300 Subject: [PATCH] img: Remove O_OPT and COLLECT_OPTIONAL Current code doesn't make any difference between OPT and no-OPT except for the message is printed or not in the open_image(). So this particular change changes nothing but the availability of this message. In the next patches I wil introduce "empty images" to deal with the ENOENT situation in a more graceful manner. Signed-off-by: Pavel Emelyanov --- arch/x86/cpu.c | 2 +- cgroup.c | 2 +- cr-restore.c | 4 ++-- cr-show.c | 2 +- eventpoll.c | 1 - file-lock.c | 3 +-- files.c | 4 ++-- fsnotify.c | 4 ---- image.c | 12 +++++------- include/image.h | 1 - include/protobuf.h | 1 - irmap.c | 2 +- mem.c | 2 +- namespaces.c | 1 - protobuf.c | 5 ++--- signalfd.c | 1 - sk-netlink.c | 1 - sk-packet.c | 1 - timerfd.c | 1 - tty.c | 2 -- tun.c | 1 - 21 files changed, 17 insertions(+), 36 deletions(-) diff --git a/arch/x86/cpu.c b/arch/x86/cpu.c index 9fcba7c4f..d703e68e3 100644 --- a/arch/x86/cpu.c +++ b/arch/x86/cpu.c @@ -428,7 +428,7 @@ int cpu_validate_cpuinfo(void) struct cr_img *img; int ret = -1; - img = open_image(CR_FD_CPUINFO, O_RSTR | O_OPT); + img = open_image(CR_FD_CPUINFO, O_RSTR); if (!img) return -1; diff --git a/cgroup.c b/cgroup.c index f5da3edfa..f20d6c3ce 100644 --- a/cgroup.c +++ b/cgroup.c @@ -1291,7 +1291,7 @@ int prepare_cgroup(void) struct cr_img *img; CgroupEntry *ce; - img = open_image(CR_FD_CGROUP, O_RSTR | O_OPT); + img = open_image(CR_FD_CGROUP, O_RSTR); if (!img) { if (errno == ENOENT) /* backward compatibility */ return 0; diff --git a/cr-restore.c b/cr-restore.c index 58a59d4d1..42667f00b 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -2419,7 +2419,7 @@ static int prepare_rlimits_from_fd(int pid) /* * Old image -- read from the file. */ - img = open_image(CR_FD_RLIMIT, O_RSTR | O_OPT, pid); + img = open_image(CR_FD_RLIMIT, O_RSTR, pid); if (!img) { if (errno == ENOENT) { pr_info("Skip rlimits for %d\n", pid); @@ -2511,7 +2511,7 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr) int ret; struct cr_img *img; - img = open_image(type, O_RSTR | O_OPT, pid); + img = open_image(type, O_RSTR, pid); if (!img) { if (errno == ENOENT) /* backward compatibility */ return 0; diff --git a/cr-show.c b/cr-show.c index 5b2143d86..d39029b57 100644 --- a/cr-show.c +++ b/cr-show.c @@ -454,7 +454,7 @@ static int cr_show_pstree_item(struct pstree_item *item) cr_parse_fd(img_from_set(cr_imgset, i), imgset_template[i].magic); } - img = open_image(CR_FD_RLIMIT, O_SHOW | O_OPT, item->pid.virt); + img = open_image(CR_FD_RLIMIT, O_SHOW, item->pid.virt); if (img) { pr_msg("* "); pr_msg(imgset_template[CR_FD_RLIMIT].fmt, item->pid.virt); diff --git a/eventpoll.c b/eventpoll.c index 331293806..c414c35b9 100644 --- a/eventpoll.c +++ b/eventpoll.c @@ -210,7 +210,6 @@ struct collect_image_info epoll_tfd_cinfo = { .pb_type = PB_EVENTPOLL_TFD, .priv_size = sizeof(struct eventpoll_tfd_file_info), .collect = collect_one_epoll_tfd, - .flags = COLLECT_OPTIONAL, }; static int collect_one_epoll(void *o, ProtobufCMessage *msg) diff --git a/file-lock.c b/file-lock.c index 210e67cd9..03189b281 100644 --- a/file-lock.c +++ b/file-lock.c @@ -40,7 +40,6 @@ struct collect_image_info file_locks_cinfo = { .pb_type = PB_FILE_LOCK, .priv_size = sizeof(struct file_lock_rst), .collect = collect_one_file_lock, - .flags = COLLECT_OPTIONAL, }; struct file_lock *alloc_file_lock(void) @@ -342,7 +341,7 @@ static int restore_file_locks_legacy(int pid) struct cr_img *img; FileLockEntry *fle; - img = open_image(CR_FD_FILE_LOCKS_PID, O_RSTR | O_OPT, pid); + img = open_image(CR_FD_FILE_LOCKS_PID, O_RSTR, pid); if (!img) { if (errno == ENOENT) return 0; diff --git a/files.c b/files.c index 62749821b..7c9495114 100644 --- a/files.c +++ b/files.c @@ -609,7 +609,7 @@ int prepare_fd_pid(struct pstree_item *item) INIT_LIST_HEAD(&rst_info->tty_slaves); if (!fdinfo_per_id) { - img = open_image(CR_FD_FDINFO, O_RSTR | O_OPT, pid); + img = open_image(CR_FD_FDINFO, O_RSTR, pid); if (!img) { if (errno == ENOENT) return 0; @@ -1116,7 +1116,7 @@ int prepare_fs_pid(struct pstree_item *item) struct cr_img *img; FsEntry *fe; - img = open_image(CR_FD_FS, O_RSTR | O_OPT, pid); + img = open_image(CR_FD_FS, O_RSTR, pid); if (!img) { if (errno == ENOENT) goto ok; diff --git a/fsnotify.c b/fsnotify.c index f84252ba4..f4222d9a5 100644 --- a/fsnotify.c +++ b/fsnotify.c @@ -756,7 +756,6 @@ struct collect_image_info inotify_cinfo = { .pb_type = PB_INOTIFY_FILE, .priv_size = sizeof(struct fsnotify_file_info), .collect = collect_one_inotify, - .flags = COLLECT_OPTIONAL, }; static int collect_one_fanotify(void *o, ProtobufCMessage *msg) @@ -792,7 +791,6 @@ struct collect_image_info fanotify_cinfo = { .pb_type = PB_FANOTIFY_FILE, .priv_size = sizeof(struct fsnotify_file_info), .collect = collect_one_fanotify, - .flags = COLLECT_OPTIONAL, }; static int collect_one_inotify_mark(void *o, ProtobufCMessage *msg) @@ -811,7 +809,6 @@ struct collect_image_info inotify_mark_cinfo = { .pb_type = PB_INOTIFY_WD, .priv_size = sizeof(struct fsnotify_mark_info), .collect = collect_one_inotify_mark, - .flags = COLLECT_OPTIONAL, }; static int collect_one_fanotify_mark(void *o, ProtobufCMessage *msg) @@ -830,5 +827,4 @@ struct collect_image_info fanotify_mark_cinfo = { .pb_type = PB_FANOTIFY_MARK, .priv_size = sizeof(struct fsnotify_mark_info), .collect = collect_one_fanotify_mark, - .flags = COLLECT_OPTIONAL, }; diff --git a/image.c b/image.c index 4f8a31b78..ae63a37f6 100644 --- a/image.c +++ b/image.c @@ -218,7 +218,7 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...) goto errn; oflags |= imgset_template[type].oflags; - flags &= ~(O_OPT | O_NOBUF); + flags &= ~(O_NOBUF); va_start(args, flags); vsnprintf(path, PATH_MAX, imgset_template[type].fmt, args); @@ -226,12 +226,10 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...) ret = openat(dfd, path, flags, CR_FD_PERM); if (ret < 0) { - if ((oflags & O_OPT) && errno == ENOENT) { - xfree(img); - return NULL; - } - - pr_perror("Unable to open %s", path); + if (errno == ENOENT) + pr_info("No %s image\n", path); + else + pr_perror("Unable to open %s", path); goto err; } diff --git a/include/image.h b/include/image.h index 7ab0bfacf..8e2da451a 100644 --- a/include/image.h +++ b/include/image.h @@ -117,7 +117,6 @@ extern bool fdinfo_per_id; extern bool ns_per_id; -#define O_OPT (O_PATH) #define O_NOBUF (O_DIRECT) #define O_DUMP (O_WRONLY | O_CREAT | O_TRUNC) diff --git a/include/protobuf.h b/include/protobuf.h index 83b24c65f..3d76b13ed 100644 --- a/include/protobuf.h +++ b/include/protobuf.h @@ -50,7 +50,6 @@ struct collect_image_info { }; #define COLLECT_SHARED 0x1 /* use shared memory for obj-s */ -#define COLLECT_OPTIONAL 0x2 /* image file may be missing */ #define COLLECT_HAPPENED 0x4 /* image was opened and collected */ extern int collect_image(struct collect_image_info *); diff --git a/irmap.c b/irmap.c index e099603e5..e671bb546 100644 --- a/irmap.c +++ b/irmap.c @@ -399,7 +399,7 @@ static int open_irmap_cache(struct cr_img **img) pr_info("Searching irmap cache in work dir\n"); in: - *img = open_image_at(dir, CR_FD_IRMAP_CACHE, O_RSTR | O_OPT); + *img = open_image_at(dir, CR_FD_IRMAP_CACHE, O_RSTR); if (dir != AT_FDCWD) close(dir); diff --git a/mem.c b/mem.c index e6af5a8d8..f049cc3c0 100644 --- a/mem.c +++ b/mem.c @@ -395,7 +395,7 @@ int prepare_mm_pid(struct pstree_item *i) struct cr_img *img; struct rst_info *ri = rsti(i); - img = open_image(CR_FD_MM, O_RSTR | O_OPT, pid); + img = open_image(CR_FD_MM, O_RSTR, pid); if (!img) { if (errno == ENOENT) return 0; diff --git a/namespaces.c b/namespaces.c index eab4d1798..9fdd9b30c 100644 --- a/namespaces.c +++ b/namespaces.c @@ -408,7 +408,6 @@ struct collect_image_info nsfile_cinfo = { .pb_type = PB_NS_FILE, .priv_size = sizeof(struct ns_file_info), .collect = collect_one_nsfile, - .flags = COLLECT_OPTIONAL, }; /* diff --git a/protobuf.c b/protobuf.c index b5f597533..be80f278e 100644 --- a/protobuf.c +++ b/protobuf.c @@ -633,7 +633,6 @@ err: int collect_image(struct collect_image_info *cinfo) { - bool optional = !!(cinfo->flags & COLLECT_OPTIONAL); int ret; struct cr_img *img; void *(*o_alloc)(size_t size) = malloc; @@ -642,9 +641,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); - img = open_image(cinfo->fd_type, O_RSTR | (optional ? O_OPT : 0)); + img = open_image(cinfo->fd_type, O_RSTR); if (!img) { - if (optional && errno == ENOENT) + if (errno == ENOENT) return 0; else return -1; diff --git a/signalfd.c b/signalfd.c index 8281c7215..6d686d44c 100644 --- a/signalfd.c +++ b/signalfd.c @@ -120,5 +120,4 @@ struct collect_image_info signalfd_cinfo = { .pb_type = PB_SIGNALFD, .priv_size = sizeof(struct signalfd_info), .collect = collect_one_sigfd, - .flags = COLLECT_OPTIONAL, }; diff --git a/sk-netlink.c b/sk-netlink.c index 651ce05a7..a98b26dc8 100644 --- a/sk-netlink.c +++ b/sk-netlink.c @@ -230,5 +230,4 @@ struct collect_image_info netlink_sk_cinfo = { .pb_type = PB_NETLINK_SK, .priv_size = sizeof(struct netlink_sock_info), .collect = collect_one_netlink_sk, - .flags = COLLECT_OPTIONAL, }; diff --git a/sk-packet.c b/sk-packet.c index d4ca77dbe..b79a8ec00 100644 --- a/sk-packet.c +++ b/sk-packet.c @@ -500,5 +500,4 @@ struct collect_image_info packet_sk_cinfo = { .pb_type = PB_PACKET_SOCK, .priv_size = sizeof(struct packet_sock_info), .collect = collect_one_packet_sk, - .flags = COLLECT_OPTIONAL, }; diff --git a/timerfd.c b/timerfd.c index edf917ad8..cd15c0963 100644 --- a/timerfd.c +++ b/timerfd.c @@ -194,5 +194,4 @@ struct collect_image_info timerfd_cinfo = { .pb_type = PB_TIMERFD, .priv_size = sizeof(struct timerfd_info), .collect = collect_one_timerfd, - .flags = COLLECT_OPTIONAL, }; diff --git a/tty.c b/tty.c index e4976a02e..5af40c929 100644 --- a/tty.c +++ b/tty.c @@ -1274,7 +1274,6 @@ struct collect_image_info tty_info_cinfo = { .pb_type = PB_TTY_INFO, .priv_size = sizeof(struct tty_info_entry), .collect = collect_one_tty_info_entry, - .flags = COLLECT_OPTIONAL, }; static int collect_one_tty(void *obj, ProtobufCMessage *msg) @@ -1339,7 +1338,6 @@ struct collect_image_info tty_cinfo = { .pb_type = PB_TTY_FILE, .priv_size = sizeof(struct tty_info), .collect = collect_one_tty, - .flags = COLLECT_OPTIONAL, }; /* Make sure the ttys we're dumping do belong our process tree */ diff --git a/tun.c b/tun.c index 0f860a9fd..e4c9bb6b7 100644 --- a/tun.c +++ b/tun.c @@ -400,7 +400,6 @@ struct collect_image_info tunfile_cinfo = { .pb_type = PB_TUNFILE, .priv_size = sizeof(struct tunfile_info), .collect = collect_one_tunfile, - .flags = COLLECT_OPTIONAL, }; int dump_tun_link(NetDeviceEntry *nde, struct cr_imgset *fds)