[CRIU] [PATCH 1/3] img: Remove O_OPT and COLLECT_OPTIONAL

Pavel Emelyanov xemul at parallels.com
Fri Mar 6 07:01:54 PST 2015


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 <xemul at parallels.com>
---
 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 9fcba7c..d703e68 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 f5da3ed..f20d6c3 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 e30d5a6..c5d3a7f 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -2406,7 +2406,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);
@@ -2498,7 +2498,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 5b2143d..d39029b 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 3312938..c414c35 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 210e67c..03189b2 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 6274982..7c94951 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 f84252b..f4222d9 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 e60cda7..5e13bd3 100644
--- a/image.c
+++ b/image.c
@@ -215,7 +215,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);
@@ -223,12 +223,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 7c79b99..43cd691 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_RDWR | O_CREAT | O_TRUNC)
diff --git a/include/protobuf.h b/include/protobuf.h
index 83b24c6..3d76b13 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 e099603..e671bb5 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 e6af5a8..f049cc3 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 eab4d17..9fdd9b3 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 b5f5975..be80f27 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 8281c72..6d686d4 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 651ce05..a98b26d 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 d4ca77d..b79a8ec 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 edf917a..cd15c09 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 072f379..c2d81e0 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 0f860a9..e4c9bb6 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)
-- 
1.8.4.2



More information about the CRIU mailing list