From: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
To: Jeff Garzik <jeff@garzik.org>
Cc: David Miller <davem@davemloft.net>,
Ulrich Drepper <drepper@redhat.com>,
Andrew Morton <akpm@osdl.org>, netdev <netdev@vger.kernel.org>,
Zach Brown <zach.brown@oracle.com>,
Christoph Hellwig <hch@infradead.org>,
Chase Venters <chase.venters@clientec.com>,
Johann Borck <johann.borck@densedata.com>,
linux-kernel@vger.kernel.org, Jamal Hadi Salim <hadi@cyberus.ca>,
Ingo Molnar <mingo@elte.hu>,
linux-fsdevel@vger.kernel.org
Subject: Kevent bonus: epoll implementaion over kevent.
Date: Wed, 10 Jan 2007 15:18:06 +0300 [thread overview]
Message-ID: <20070110121806.GB28862@2ka.mipt.ru> (raw)
In-Reply-To: <20070110113051.GA4950@2ka.mipt.ru>
As a usage scenario, compile-tested only.
Replace fs/eventpoll.c with this code and see,
how your kernel crashes. Or works.
:)
Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/kevent.h>
#include <linux/ukevent.h>
#include <linux/syscalls.h>
#include <asm/poll.h>
#include <asm/uaccess.h>
#include <linux/eventpoll.h>
asmlinkage long sys_epoll_create(int size)
{
return sys_kevent_init(NULL, 0, 0);
}
#define EP_PRIVATE_BITS (EPOLLONESHOT | EPOLLET)
asmlinkage long sys_epoll_ctl(int epfd, int op, int fd, struct epoll_event __user *event)
{
struct epoll_event epds;
struct ukevent uk;
int cmd, err;
switch (op) {
case EPOLL_CTL_DEL:
cmd = KEVENT_CTL_REMOVE;
break;
case EPOLL_CTL_ADD:
cmd = KEVENT_CTL_ADD;
break;
case EPOLL_CTL_MOD:
cmd = KEVENT_CTL_MODIFY;
break;
default:
err = -EINVAL;
goto err_out_exit;
}
if (copy_from_user(&epds, event, sizeof(struct epoll_event))) {
err = -EFAULT;
goto err_out_exit;
}
memset(&uk, 0, sizeof(struct ukevent));
uk.id.raw[0] = fd;
memcpy(uk.user, &epds.data, sizeof(u64));
uk.type = KEVENT_POLL;
uk.event = (epds.events & ~EP_PRIVATE_BITS)| POLLERR | POLLHUP;
uk.req_flags = KEVENT_REQ_ALWAYS_QUEUE | KEVENT_REQ_LAST_CHECK;
if (epds.events & EPOLLONESHOT)
uk.req_flags |= KEVENT_REQ_ONESHOT;
if (epds.events & EPOLLET)
uk.req_flags |= KEVENT_REQ_ET;
return sys_kevent_ctl(epfd, cmd, 1, &uk);
err_out_exit:
return err;
}
asmlinkage long sys_epoll_wait(int epfd, struct epoll_event __user *events,
int maxevents, int timeout)
{
struct ukevent uk[3];
struct timespec ts;
long num, i;
int err;
if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) {
err = -EFAULT;
goto err_out_exit;
}
memset(uk, 0, sizeof(uk));
ts.tv_sec = timeout/1000;
ts.tv_nsec = (timeout - ts.tv_sec*1000)*1000;
num = sys_kevent_get_events(epfd, 1, min(3, maxevents), ts, uk, 0);
if (num <= 0)
return num;
for (i=0; i<num; ++i) {
__u64 data;
memcpy(&data, &uk[i].user, sizeof(u64));
if (__put_user(uk[i].ret_data[0], &events[i].events) ||
__put_user(data, &events[i].data))
return -EFAULT;
}
return num;
err_out_exit:
return err;
}
--
Evgeniy Polyakov
prev parent reply other threads:[~2007-01-10 12:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <315adqaa0591036@2ka.mipt.ru>
2007-01-10 8:16 ` [take32 0/10] kevent: Generic event handling mechanism Evgeniy Polyakov
2007-01-10 8:16 ` [take32 1/10] kevent: Description Evgeniy Polyakov
2007-01-10 8:16 ` [take32 2/10] kevent: Core files Evgeniy Polyakov
2007-01-10 8:16 ` [take32 3/10] kevent: poll/select() notifications Evgeniy Polyakov
2007-01-10 8:16 ` [take32 4/10] kevent: Socket notifications Evgeniy Polyakov
2007-01-10 8:16 ` [take32 5/10] kevent: Timer notifications Evgeniy Polyakov
2007-01-10 8:16 ` [take32 6/10] kevent: Pipe notifications Evgeniy Polyakov
2007-01-10 8:16 ` [take32 7/10] kevent: Signal notifications Evgeniy Polyakov
2007-01-10 8:16 ` [take32 8/10] kevent: Kevent posix timer notifications Evgeniy Polyakov
2007-01-10 8:16 ` [take32 9/10] kevent: Private userspace notifications Evgeniy Polyakov
2007-01-10 8:16 ` [take32 10/10] kevent: Kevent based AIO (aio_sendfile()) Evgeniy Polyakov
2007-01-10 11:11 ` [take32 0/10] kevent: Generic event handling mechanism Jeff Garzik
2007-01-10 11:30 ` Evgeniy Polyakov
2007-01-10 11:56 ` Jeff Garzik
2007-01-10 12:14 ` Evgeniy Polyakov
2007-01-10 12:18 ` Evgeniy Polyakov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070110121806.GB28862@2ka.mipt.ru \
--to=johnpol@2ka.mipt.ru \
--cc=akpm@osdl.org \
--cc=chase.venters@clientec.com \
--cc=davem@davemloft.net \
--cc=drepper@redhat.com \
--cc=hadi@cyberus.ca \
--cc=hch@infradead.org \
--cc=jeff@garzik.org \
--cc=johann.borck@densedata.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=netdev@vger.kernel.org \
--cc=zach.brown@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).