[CRIU] [PATCH 5/6] eventpoll: parse_fdinfo_pid_s() returns allocated object for eventpol tfd

Andrey Vagin avagin at openvz.org
Mon Aug 25 12:19:58 PDT 2014


We are going to collect all objects in a list and write them into
the eventpoll image. The eventpoll tfd image will be depricated.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-check.c           |  3 ++-
 eventpoll.c          |  8 ++++++--
 include/proc_parse.h |  8 +++++++-
 proc_parse.c         | 21 +++++++++++++++++----
 4 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/cr-check.c b/cr-check.c
index fe7d03c..7647cac 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -299,7 +299,8 @@ static int check_fdinfo_signalfd(void)
 
 static int check_one_epoll(union fdinfo_entries *e, void *arg)
 {
-	*(int *)arg = e->epl.tfd;
+	*(int *)arg = e->epl.e.tfd;
+	free_event_poll_entry(e);
 	return 0;
 }
 
diff --git a/eventpoll.c b/eventpoll.c
index 88b331f..da40e92 100644
--- a/eventpoll.c
+++ b/eventpoll.c
@@ -59,12 +59,16 @@ static void pr_info_eventpoll(char *action, EventpollFileEntry *e)
 
 static int dump_eventpoll_entry(union fdinfo_entries *e, void *arg)
 {
-	EventpollTfdEntry *efd = &e->epl;
+	EventpollTfdEntry *efd = &e->epl.e;
+	int ret;
 
 	efd->id = *(u32 *)arg;
 	pr_info_eventpoll_tfd("Dumping: ", efd);
-	return pb_write_one(fdset_fd(glob_fdset, CR_FD_EVENTPOLL_TFD),
+	ret = pb_write_one(fdset_fd(glob_fdset, CR_FD_EVENTPOLL_TFD),
 			efd, PB_EVENTPOLL_TFD);
+
+	free_event_poll_entry(e);
+	return ret;
 }
 
 static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
diff --git a/include/proc_parse.h b/include/proc_parse.h
index f7e4738..4607492 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -182,17 +182,23 @@ struct fanotify_mark_entry {
 	};
 };
 
+struct eventpoll_tfd_entry {
+	EventpollTfdEntry e;
+	struct list_head node;
+};
+
 union fdinfo_entries {
 	EventfdFileEntry efd;
-	EventpollTfdEntry epl;
 	SignalfdEntry sfd;
 	struct inotify_wd_entry ify;
 	struct fanotify_mark_entry ffy;
+	struct eventpoll_tfd_entry epl;
 	TimerfdEntry tfy;
 };
 
 extern void free_inotify_wd_entry(union fdinfo_entries *e);
 extern void free_fanotify_mark_entry(union fdinfo_entries *e);
+extern void free_event_poll_entry(union fdinfo_entries *e);
 
 struct fdinfo_common {
 	off64_t pos;
diff --git a/proc_parse.c b/proc_parse.c
index fbc8764..42c95cb 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -1032,6 +1032,10 @@ void free_fanotify_mark_entry(union fdinfo_entries *e) {
 	xfree(e);
 }
 
+void free_event_poll_entry(union fdinfo_entries *e) {
+	xfree(e);
+}
+
 static void parse_fhandle_encoded(char *tok, FhEntry *fh)
 {
 	char *d = (char *)fh->handle;
@@ -1176,15 +1180,24 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type,
 			continue;
 		}
 		if (fdinfo_field(str, "tfd")) {
-			eventpoll_tfd_entry__init(&entry.epl);
+			union fdinfo_entries *e;
 
 			if (type != FD_TYPES__EVENTPOLL)
 				goto parse_err;
+
+			e = xmalloc(sizeof(union fdinfo_entries));
+			if (!e)
+				goto out;
+
+			eventpoll_tfd_entry__init(&e->epl.e);
+
 			ret = sscanf(str, "tfd: %d events: %x data: %"PRIx64,
-					&entry.epl.tfd, &entry.epl.events, &entry.epl.data);
-			if (ret != 3)
+					&e->epl.e.tfd, &e->epl.e.events, &e->epl.e.data);
+			if (ret != 3) {
+				free_event_poll_entry(e);
 				goto parse_err;
-			ret = cb(&entry, arg);
+			}
+			ret = cb(e, arg);
 			if (ret)
 				goto out;
 
-- 
1.9.3



More information about the CRIU mailing list