From c94d0cacb44c38e392de13d901212e0184c0c140 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 22 Jun 2017 20:38:36 +0300 Subject: [PATCH] eventfd: Rework parse_fdinfo not to use callback Signed-off-by: Pavel Emelyanov Signed-off-by: Andrei Vagin --- criu/cr-check.c | 17 ++++++----------- criu/eventfd.c | 39 ++++++++++++--------------------------- criu/include/fdinfo.h | 1 - criu/proc_parse.c | 7 ++----- 4 files changed, 20 insertions(+), 44 deletions(-) diff --git a/criu/cr-check.c b/criu/cr-check.c index cd23f7863..cd989fb03 100644 --- a/criu/cr-check.c +++ b/criu/cr-check.c @@ -272,16 +272,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) { @@ -289,7 +284,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) { @@ -297,13 +292,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 68edb1c56..7212ad4c4 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) -{ - struct eventfd_dump_arg *da = arg; - - if (da->dumped) { - pr_err("Several counters in a file?\n"); - return -1; - } - - da->dumped = true; - e->efd.id = da->id; - e->efd.flags = da->p->flags; - e->efd.fown = (FownEntry *)&da->p->fown; - - pr_info_eventfd("Dumping ", &e->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); + EventfdFileEntry efd = EVENTFD_FILE_ENTRY__INIT; + + if (parse_fdinfo(lfd, FD_TYPES__EVENTFD, NULL, &efd)) + return -1; + + efd.id = id; + efd.flags = p->flags; + efd.fown = (FownEntry *)&p->fown; + + pr_info_eventfd("Dumping ", &efd); + return pb_write_one(img_from_set(glob_imgset, CR_FD_EVENTFD_FILE), + &efd, PB_EVENTFD_FILE); } const struct fdtype_ops eventfd_dump_ops = { diff --git a/criu/include/fdinfo.h b/criu/include/fdinfo.h index a36e9138b..830b3fcf0 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 5e36db540..9d36fb2fe 100644 --- a/criu/proc_parse.c +++ b/criu/proc_parse.c @@ -1715,17 +1715,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;