[CRIU] [PATCH 1/7] eventfd: Rework parse_fdinfo not to use callback

Pavel Emelyanov xemul at virtuozzo.com
Thu Jun 22 20:38:36 MSK 2017


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-check.c       | 17 ++++++-----------
 criu/eventfd.c        | 31 ++++++++-----------------------
 criu/include/fdinfo.h |  1 -
 criu/proc_parse.c     |  7 ++-----
 4 files changed, 16 insertions(+), 40 deletions(-)

diff --git a/criu/cr-check.c b/criu/cr-check.c
index de81ec3..92de4bf 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -273,16 +273,11 @@ static int check_proc_stat(void)
 	return 0;
 }
 
-static int check_one_fdinfo(union fdinfo_entries *e, void *arg)
-{
-	*(int *)arg = (int)e->efd.counter;
-	return 0;
-}
-
 static int check_fdinfo_eventfd(void)
 {
 	int fd, ret;
-	int cnt = 13, proc_cnt = 0;
+	int cnt = 13;
+	EventfdFileEntry fe = EVENTFD_FILE_ENTRY__INIT;
 
 	fd = eventfd(cnt, 0);
 	if (fd < 0) {
@@ -290,7 +285,7 @@ static int check_fdinfo_eventfd(void)
 		return -1;
 	}
 
-	ret = parse_fdinfo(fd, FD_TYPES__EVENTFD, check_one_fdinfo, &proc_cnt);
+	ret = parse_fdinfo(fd, FD_TYPES__EVENTFD, NULL, &fe);
 	close(fd);
 
 	if (ret) {
@@ -298,13 +293,13 @@ static int check_fdinfo_eventfd(void)
 		return -1;
 	}
 
-	if (proc_cnt != cnt) {
+	if (fe.counter != cnt) {
 		pr_err("Counter mismatch (or not met) %d want %d\n",
-				proc_cnt, cnt);
+				(int)fe.counter, cnt);
 		return -1;
 	}
 
-	pr_info("Eventfd fdinfo works OK (%d vs %d)\n", cnt, proc_cnt);
+	pr_info("Eventfd fdinfo works OK (%d vs %d)\n", cnt, (int)fe.counter);
 	return 0;
 }
 
diff --git a/criu/eventfd.c b/criu/eventfd.c
index 68edb1c..7212ad4 100644
--- a/criu/eventfd.c
+++ b/criu/eventfd.c
@@ -43,35 +43,20 @@ static void pr_info_eventfd(char *action, EventfdFileEntry *efe)
 		action, efe->id, efe->flags, efe->counter);
 }
 
-struct eventfd_dump_arg {
-	u32 id;
-	const struct fd_parms *p;
-	bool dumped;
-};
-
-static int dump_eventfd_entry(union fdinfo_entries *e, void *arg)
+static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
 {
-	struct eventfd_dump_arg *da = arg;
+	EventfdFileEntry efd = EVENTFD_FILE_ENTRY__INIT;
 
-	if (da->dumped) {
-		pr_err("Several counters in a file?\n");
+	if (parse_fdinfo(lfd, FD_TYPES__EVENTFD, NULL, &efd))
 		return -1;
-	}
 
-	da->dumped = true;
-	e->efd.id = da->id;
-	e->efd.flags = da->p->flags;
-	e->efd.fown = (FownEntry *)&da->p->fown;
+	efd.id = id;
+	efd.flags = p->flags;
+	efd.fown = (FownEntry *)&p->fown;
 
-	pr_info_eventfd("Dumping ", &e->efd);
+	pr_info_eventfd("Dumping ", &efd);
 	return pb_write_one(img_from_set(glob_imgset, CR_FD_EVENTFD_FILE),
-			&e->efd, PB_EVENTFD_FILE);
-}
-
-static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
-{
-	struct eventfd_dump_arg da = { .id = id, .p = p, };
-	return parse_fdinfo(lfd, FD_TYPES__EVENTFD, dump_eventfd_entry, &da);
+			&efd, PB_EVENTFD_FILE);
 }
 
 const struct fdtype_ops eventfd_dump_ops = {
diff --git a/criu/include/fdinfo.h b/criu/include/fdinfo.h
index a36e913..830b3fc 100644
--- a/criu/include/fdinfo.h
+++ b/criu/include/fdinfo.h
@@ -31,7 +31,6 @@ struct eventpoll_tfd_entry {
 };
 
 union fdinfo_entries {
-	EventfdFileEntry efd;
 	SignalfdEntry sfd;
 	struct inotify_wd_entry ify;
 	struct fanotify_mark_entry ffy;
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 041d451..54f5931 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1787,17 +1787,14 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
 			continue;
 
 		if (fdinfo_field(str, "eventfd-count")) {
-			eventfd_file_entry__init(&entry.efd);
+			EventfdFileEntry *efd = arg;
 
 			if (type != FD_TYPES__EVENTFD)
 				goto parse_err;
 			ret = sscanf(str, "eventfd-count: %"PRIx64,
-					&entry.efd.counter);
+					&efd->counter);
 			if (ret != 1)
 				goto parse_err;
-			ret = cb(&entry, arg);
-			if (ret)
-				goto out;
 
 			entry_met = true;
 			continue;
-- 
2.1.4



More information about the CRIU mailing list