2012-05-04 13:38:00 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/statfs.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/epoll.h>
|
|
|
|
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "eventpoll.h"
|
2012-07-11 09:22:38 +04:00
|
|
|
#include "proc_parse.h"
|
2012-05-04 13:38:00 +04:00
|
|
|
#include "crtools.h"
|
|
|
|
#include "image.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
2012-07-17 07:25:40 +04:00
|
|
|
#include "protobuf.h"
|
|
|
|
#include "protobuf/eventpoll.pb-c.h"
|
|
|
|
|
2012-08-20 15:14:49 +04:00
|
|
|
#undef LOG_PREFIX
|
|
|
|
#define LOG_PREFIX "epoll: "
|
|
|
|
|
2012-05-04 13:38:00 +04:00
|
|
|
struct eventpoll_file_info {
|
2012-07-17 07:25:40 +04:00
|
|
|
EventpollFileEntry *efe;
|
2012-05-04 13:38:00 +04:00
|
|
|
struct file_desc d;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct eventpoll_tfd_file_info {
|
2012-07-17 07:25:40 +04:00
|
|
|
EventpollTfdEntry *tdefe;
|
2012-05-04 13:38:00 +04:00
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(eventpoll_tfds);
|
|
|
|
|
|
|
|
/* Checks if file desciptor @lfd is eventfd */
|
|
|
|
int is_eventpoll_link(int lfd)
|
|
|
|
{
|
2012-05-04 14:22:18 +04:00
|
|
|
return is_anon_link_type(lfd, "[eventpoll]");
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 07:25:40 +04:00
|
|
|
static void pr_info_eventpoll_tfd(char *action, EventpollTfdEntry *e)
|
2012-05-04 13:38:00 +04:00
|
|
|
{
|
|
|
|
pr_info("%seventpoll-tfd: id %#08x tfd %#08x events %#08x data %#016lx\n",
|
|
|
|
action, e->id, e->tfd, e->events, e->data);
|
|
|
|
}
|
|
|
|
|
2012-07-17 07:25:40 +04:00
|
|
|
static void pr_info_eventpoll(char *action, EventpollFileEntry *e)
|
2012-05-04 13:38:00 +04:00
|
|
|
{
|
|
|
|
pr_info("%seventpoll: id %#08x flags %#04x\n", action, e->id, e->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_eventpoll_tfd(int fd, struct cr_options *o)
|
|
|
|
{
|
2012-08-07 02:51:34 +04:00
|
|
|
pb_show_plain(fd, PB_EVENTPOLL_TFD);
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_eventpoll(int fd, struct cr_options *o)
|
|
|
|
{
|
2012-08-07 02:51:34 +04:00
|
|
|
pb_show_plain(fd, PB_EVENTPOLL);
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|
|
|
|
|
2012-07-11 09:22:38 +04:00
|
|
|
static int dump_eventpoll_entry(union fdinfo_entries *e, void *arg)
|
|
|
|
{
|
2012-07-17 07:25:40 +04:00
|
|
|
EventpollTfdEntry *efd = &e->epl;
|
2012-07-11 09:22:38 +04:00
|
|
|
|
|
|
|
efd->id = *(u32 *)arg;
|
|
|
|
pr_info_eventpoll_tfd("Dumping: ", efd);
|
2012-08-07 02:26:50 +04:00
|
|
|
return pb_write_one(fdset_fd(glob_fdset, CR_FD_EVENTPOLL_TFD),
|
|
|
|
efd, PB_EVENTPOLL_TFD);
|
2012-07-11 09:22:38 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 15:34:55 +04:00
|
|
|
static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
|
2012-05-04 13:38:00 +04:00
|
|
|
{
|
2012-07-17 07:25:40 +04:00
|
|
|
EventpollFileEntry e = EVENTPOLL_FILE_ENTRY__INIT;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-07-11 09:22:38 +04:00
|
|
|
e.id = id;
|
|
|
|
e.flags = p->flags;
|
2012-07-19 09:39:00 +04:00
|
|
|
e.fown = (FownEntry *)&p->fown;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
|
|
|
pr_info_eventpoll("Dumping ", &e);
|
2012-08-07 02:26:50 +04:00
|
|
|
if (pb_write_one(fdset_fd(glob_fdset, CR_FD_EVENTPOLL),
|
|
|
|
&e, PB_EVENTPOLL))
|
2012-05-04 13:38:00 +04:00
|
|
|
return -1;
|
|
|
|
|
2012-07-19 10:18:37 +04:00
|
|
|
return parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, dump_eventpoll_entry, &id);
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 15:34:55 +04:00
|
|
|
static const struct fdtype_ops eventpoll_ops = {
|
2012-07-19 10:18:37 +04:00
|
|
|
.type = FD_TYPES__EVENTPOLL,
|
2012-05-04 15:34:55 +04:00
|
|
|
.dump = dump_one_eventpoll,
|
|
|
|
};
|
|
|
|
|
|
|
|
int dump_eventpoll(struct fd_parms *p, int lfd, const struct cr_fdset *set)
|
|
|
|
{
|
|
|
|
return do_dump_gen_file(p, lfd, &eventpoll_ops, set);
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:38:00 +04:00
|
|
|
static int eventpoll_open(struct file_desc *d)
|
|
|
|
{
|
|
|
|
struct eventpoll_tfd_file_info *td_info;
|
|
|
|
struct eventpoll_file_info *info;
|
|
|
|
int tmp, ret;
|
|
|
|
|
|
|
|
info = container_of(d, struct eventpoll_file_info, d);
|
|
|
|
|
|
|
|
tmp = epoll_create(1);
|
|
|
|
if (tmp < 0) {
|
|
|
|
pr_perror("Can't create epoll %#08x",
|
2012-07-10 02:49:00 +04:00
|
|
|
info->efe->id);
|
2012-05-04 13:38:00 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-19 09:39:00 +04:00
|
|
|
if (rst_file_params(tmp, info->efe->fown, info->efe->flags)) {
|
2012-05-04 13:38:00 +04:00
|
|
|
pr_perror("Can't restore file params on epoll %#08x",
|
2012-07-10 02:49:00 +04:00
|
|
|
info->efe->id);
|
2012-05-04 13:38:00 +04:00
|
|
|
goto err_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(td_info, &eventpoll_tfds, list) {
|
|
|
|
struct epoll_event event;
|
|
|
|
|
2012-07-10 02:49:00 +04:00
|
|
|
if (td_info->tdefe->id != info->efe->id)
|
2012-05-04 13:38:00 +04:00
|
|
|
continue;
|
|
|
|
|
2012-07-10 02:49:00 +04:00
|
|
|
event.events = td_info->tdefe->events;
|
|
|
|
event.data.u64 = td_info->tdefe->data;
|
|
|
|
ret = epoll_ctl(tmp, EPOLL_CTL_ADD, td_info->tdefe->tfd, &event);
|
2012-05-04 13:38:00 +04:00
|
|
|
if (ret) {
|
2012-07-10 02:49:00 +04:00
|
|
|
pr_perror("Can't add event on %#08x", info->efe->id);
|
2012-05-04 13:38:00 +04:00
|
|
|
goto err_close;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
|
|
|
err_close:
|
|
|
|
close(tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_desc_ops desc_ops = {
|
2012-07-19 10:18:37 +04:00
|
|
|
.type = FD_TYPES__EVENTPOLL,
|
2012-05-04 13:38:00 +04:00
|
|
|
.open = eventpoll_open,
|
|
|
|
};
|
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
static int collect_one_epoll_tfd(void *o, ProtobufCMessage *msg)
|
2012-05-04 13:38:00 +04:00
|
|
|
{
|
2012-08-09 13:16:46 +04:00
|
|
|
struct eventpoll_tfd_file_info *info = o;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
info->tdefe = pb_msg(msg, EventpollTfdEntry);
|
|
|
|
list_add(&info->list, &eventpoll_tfds);
|
|
|
|
pr_info_eventpoll_tfd("Collected ", info->tdefe);
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
static int collect_one_epoll(void *o, ProtobufCMessage *msg)
|
|
|
|
{
|
|
|
|
struct eventpoll_file_info *info = o;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
info->efe = pb_msg(msg, EventpollFileEntry);
|
|
|
|
file_desc_add(&info->d, info->efe->id, &desc_ops);
|
|
|
|
pr_info_eventpoll("Collected ", info->efe);
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
int collect_eventpoll(void)
|
|
|
|
{
|
|
|
|
int ret;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
ret = collect_image(CR_FD_EVENTPOLL_TFD, PB_EVENTPOLL_TFD,
|
|
|
|
sizeof(struct eventpoll_tfd_file_info),
|
|
|
|
collect_one_epoll_tfd);
|
|
|
|
if (!ret)
|
|
|
|
ret = collect_image(CR_FD_EVENTPOLL, PB_EVENTPOLL,
|
|
|
|
sizeof(struct eventpoll_file_info),
|
|
|
|
collect_one_epoll);
|
2012-05-04 13:38:00 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|