[CRIU] [PATCH 3/7] eventpoll: Rework parse_fdinfo not to use callback

Pavel Emelyanov xemul at virtuozzo.com
Thu Jun 22 20:39:08 MSK 2017


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-check.c       | 19 ++++++-------------
 criu/eventpoll.c      | 39 +++++++--------------------------------
 criu/include/fdinfo.h |  7 -------
 criu/proc_parse.c     | 23 +++++++++++------------
 4 files changed, 24 insertions(+), 64 deletions(-)

diff --git a/criu/cr-check.c b/criu/cr-check.c
index b626b1b..8c4a50c 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -345,17 +345,11 @@ static int check_fdinfo_signalfd(void)
 	return 0;
 }
 
-static int check_one_epoll(union fdinfo_entries *e, void *arg)
-{
-	*(int *)arg = e->epl.e.tfd;
-	free_event_poll_entry(e);
-	return 0;
-}
-
 static int check_fdinfo_eventpoll(void)
 {
-	int efd, pfd[2], proc_fd = 0, ret = -1;
+	int efd, pfd[2], ret = -1;
 	struct epoll_event ev;
+	EventpollFileEntry efe = EVENTPOLL_FILE_ENTRY__INIT;
 
 	if (pipe(pfd)) {
 		pr_perror("Can't make pipe to watch");
@@ -376,20 +370,19 @@ static int check_fdinfo_eventpoll(void)
 		goto epoll_err;
 	}
 
-	ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, check_one_epoll, &proc_fd);
+	ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, NULL, &efe);
 	if (ret) {
 		pr_err("Error parsing proc fdinfo\n");
 		goto epoll_err;
 	}
 
-	if (pfd[0] != proc_fd) {
-		pr_err("TFD mismatch (or not met) %d want %d\n",
-				proc_fd, pfd[0]);
+	if (efe.n_tfd != 1 || efe.tfd[0]->tfd != pfd[0]) {
+		pr_err("TFD mismatch (or not met)\n");
 		ret = -1;
 		goto epoll_err;
 	}
 
-	pr_info("Epoll fdinfo works OK (%d vs %d)\n", pfd[0], proc_fd);
+	pr_info("Epoll fdinfo works OK\n");
 
 epoll_err:
 	close(efd);
diff --git a/criu/eventpoll.c b/criu/eventpoll.c
index 1253f23..87e2457 100644
--- a/criu/eventpoll.c
+++ b/criu/eventpoll.c
@@ -51,53 +51,28 @@ static void pr_info_eventpoll(char *action, EventpollFileEntry *e)
 	pr_info("%seventpoll: id %#08x flags %#04x\n", action, e->id, e->flags);
 }
 
-struct eventpoll_list {
-	struct list_head list;
-	int n;
-};
-
-static int dump_eventpoll_entry(union fdinfo_entries *e, void *arg)
-{
-	struct eventpoll_list *ep_list = (struct eventpoll_list *) arg;
-	EventpollTfdEntry *efd = &e->epl.e;
-
-	pr_info_eventpoll_tfd("Dumping: ", efd);
-
-	list_add_tail(&e->epl.node, &ep_list->list);
-	ep_list->n++;
-
-	return 0;
-}
-
 static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
 {
 	EventpollFileEntry e = EVENTPOLL_FILE_ENTRY__INIT;
-	struct eventpoll_list ep_list = {LIST_HEAD_INIT(ep_list.list), 0};
-	union fdinfo_entries *te, *tmp;
 	int i, ret = -1;
 
 	e.id = id;
 	e.flags = p->flags;
 	e.fown = (FownEntry *)&p->fown;
 
-	if (parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, dump_eventpoll_entry, &ep_list))
-		goto out;
-
-	e.tfd = xmalloc(sizeof(struct EventpollTfdEntry *) * ep_list.n);
-	if (!e.tfd)
+	if (parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, NULL, &e))
 		goto out;
 
-	i = 0;
-	list_for_each_entry(te, &ep_list.list, epl.node)
-		e.tfd[i++] = &te->epl.e;
-	e.n_tfd = ep_list.n;
-
 	pr_info_eventpoll("Dumping ", &e);
 	ret = pb_write_one(img_from_set(glob_imgset, CR_FD_EVENTPOLL_FILE),
 		     &e, PB_EVENTPOLL_FILE);
 out:
-	list_for_each_entry_safe(te, tmp, &ep_list.list, epl.node)
-		free_event_poll_entry(te);
+	for (i = 0; i < e.n_tfd; i++) {
+		if (!ret)
+			pr_info_eventpoll_tfd("Dumping: ", e.tfd[i]);
+		eventpoll_tfd_entry__free_unpacked(e.tfd[i], NULL);
+	}
+	xfree(e.tfd);
 
 	return ret;
 }
diff --git a/criu/include/fdinfo.h b/criu/include/fdinfo.h
index 18e85ed..45f5746 100644
--- a/criu/include/fdinfo.h
+++ b/criu/include/fdinfo.h
@@ -25,21 +25,14 @@ struct fanotify_mark_entry {
 	};
 };
 
-struct eventpoll_tfd_entry {
-	EventpollTfdEntry e;
-	struct list_head node;
-};
-
 union fdinfo_entries {
 	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/criu/proc_parse.c b/criu/proc_parse.c
index e00b0da..813614d 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1619,11 +1619,6 @@ 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;
@@ -1815,27 +1810,31 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
 			continue;
 		}
 		if (fdinfo_field(str, "tfd")) {
-			union fdinfo_entries *e;
+			EventpollFileEntry *epfe = arg;
+			EventpollTfdEntry *e;
+			int i;
 
 			if (type != FD_TYPES__EVENTPOLL)
 				goto parse_err;
 
-			e = xmalloc(sizeof(union fdinfo_entries));
+			e = xmalloc(sizeof(EventpollTfdEntry));
 			if (!e)
 				goto out;
 
-			eventpoll_tfd_entry__init(&e->epl.e);
+			eventpoll_tfd_entry__init(e);
 
 			ret = sscanf(str, "tfd: %d events: %x data: %"PRIx64,
-					&e->epl.e.tfd, &e->epl.e.events, &e->epl.e.data);
+					&e->tfd, &e->events, &e->data);
 			if (ret != 3) {
-				free_event_poll_entry(e);
+				eventpoll_tfd_entry__free_unpacked(e, NULL);
 				goto parse_err;
 			}
-			ret = cb(e, arg);
-			if (ret)
+
+			i = epfe->n_tfd++;
+			if (xrealloc_safe(&epfe->tfd, epfe->n_tfd * sizeof(EventpollTfdEntry *)))
 				goto out;
 
+			epfe->tfd[i] = e;
 			entry_met = true;
 			continue;
 		}
-- 
2.1.4



More information about the CRIU mailing list