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/eventfd.h>
|
|
|
|
|
|
|
|
#include "compiler.h"
|
2013-01-09 17:02:47 +04:00
|
|
|
#include "asm/types.h"
|
2012-05-04 13:38:00 +04:00
|
|
|
#include "eventfd.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:24:54 +04:00
|
|
|
#include "protobuf.h"
|
|
|
|
#include "protobuf/eventfd.pb-c.h"
|
|
|
|
|
2012-08-20 15:14:43 +04:00
|
|
|
#undef LOG_PREFIX
|
|
|
|
#define LOG_PREFIX "eventfd: "
|
|
|
|
|
2012-05-04 13:38:00 +04:00
|
|
|
struct eventfd_file_info {
|
2012-07-17 07:24:54 +04:00
|
|
|
EventfdFileEntry *efe;
|
2012-05-04 13:38:00 +04:00
|
|
|
struct file_desc d;
|
|
|
|
};
|
|
|
|
|
2013-04-12 13:00:06 -07:00
|
|
|
/* Checks if file descriptor @lfd is eventfd */
|
2012-05-04 13:38:00 +04:00
|
|
|
int is_eventfd_link(int lfd)
|
|
|
|
{
|
2012-05-04 14:22:18 +04:00
|
|
|
return is_anon_link_type(lfd, "[eventfd]");
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 07:24:54 +04:00
|
|
|
static void pr_info_eventfd(char *action, EventfdFileEntry *efe)
|
2012-05-04 13:38:00 +04:00
|
|
|
{
|
2013-01-16 19:20:08 +04:00
|
|
|
pr_info("%s: id %#08x flags %#04x counter %#016"PRIx64"\n",
|
2012-05-04 13:38:00 +04:00
|
|
|
action, efe->id, efe->flags, efe->counter);
|
|
|
|
}
|
|
|
|
|
2013-05-08 00:23:42 +04:00
|
|
|
void show_eventfds(int fd)
|
2012-05-04 13:38:00 +04:00
|
|
|
{
|
2012-08-07 02:51:34 +04:00
|
|
|
pb_show_plain(fd, PB_EVENTFD);
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|
|
|
|
|
2012-07-11 09:22:38 +04:00
|
|
|
struct eventfd_dump_arg {
|
|
|
|
u32 id;
|
|
|
|
const struct fd_parms *p;
|
|
|
|
bool dumped;
|
|
|
|
};
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-07-11 09:22:38 +04:00
|
|
|
static int dump_eventfd_entry(union fdinfo_entries *e, void *arg)
|
|
|
|
{
|
|
|
|
struct eventfd_dump_arg *da = arg;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-07-11 09:22:38 +04:00
|
|
|
if (da->dumped) {
|
|
|
|
pr_err("Several counters in a file?\n");
|
2012-05-04 13:38:00 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-17 07:24:54 +04:00
|
|
|
da->dumped = true;
|
|
|
|
e->efd.id = da->id;
|
|
|
|
e->efd.flags = da->p->flags;
|
2012-07-19 09:39:00 +04:00
|
|
|
e->efd.fown = (FownEntry *)&da->p->fown;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-07-17 07:24:54 +04:00
|
|
|
pr_info_eventfd("Dumping ", &e->efd);
|
2012-08-07 02:26:50 +04:00
|
|
|
return pb_write_one(fdset_fd(glob_fdset, CR_FD_EVENTFD),
|
|
|
|
&e->efd, PB_EVENTFD);
|
2012-07-11 09:22:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
|
|
|
|
{
|
|
|
|
struct eventfd_dump_arg da = { .id = id, .p = p, };
|
2012-07-19 10:18:37 +04:00
|
|
|
return parse_fdinfo(lfd, FD_TYPES__EVENTFD, dump_eventfd_entry, &da);
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|
|
|
|
|
2013-06-14 00:11:08 +04:00
|
|
|
const struct fdtype_ops eventfd_dump_ops = {
|
2012-07-19 10:18:37 +04:00
|
|
|
.type = FD_TYPES__EVENTFD,
|
2012-05-04 15:34:55 +04:00
|
|
|
.dump = dump_one_eventfd,
|
|
|
|
};
|
|
|
|
|
2012-05-04 13:38:00 +04:00
|
|
|
static int eventfd_open(struct file_desc *d)
|
|
|
|
{
|
|
|
|
struct eventfd_file_info *info;
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
info = container_of(d, struct eventfd_file_info, d);
|
|
|
|
|
2012-07-10 02:49:00 +04:00
|
|
|
tmp = eventfd(info->efe->counter, 0);
|
2012-05-04 13:38:00 +04:00
|
|
|
if (tmp < 0) {
|
|
|
|
pr_perror("Can't create eventfd %#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 params on eventfd %#08x",
|
2012-07-10 02:49:00 +04:00
|
|
|
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 eventfd_desc_ops = {
|
2012-07-19 10:18:37 +04:00
|
|
|
.type = FD_TYPES__EVENTFD,
|
2012-05-04 13:38:00 +04:00
|
|
|
.open = eventfd_open,
|
|
|
|
};
|
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
static int collect_one_efd(void *obj, ProtobufCMessage *msg)
|
2012-05-04 13:38:00 +04:00
|
|
|
{
|
2012-08-09 13:16:46 +04:00
|
|
|
struct eventfd_file_info *info = obj;
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
info->efe = pb_msg(msg, EventfdFileEntry);
|
|
|
|
pr_info_eventfd("Collected ", info->efe);
|
2013-08-21 01:06:58 +04:00
|
|
|
return file_desc_add(&info->d, info->efe->id, &eventfd_desc_ops);
|
2012-08-09 13:16:46 +04:00
|
|
|
}
|
2012-05-04 13:38:00 +04:00
|
|
|
|
2012-08-09 13:16:46 +04:00
|
|
|
int collect_eventfd(void)
|
|
|
|
{
|
|
|
|
return collect_image(CR_FD_EVENTFD, PB_EVENTFD,
|
|
|
|
sizeof(struct eventfd_file_info), collect_one_efd);
|
2012-05-04 13:38:00 +04:00
|
|
|
}
|