LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Nathaniel Yazdani <n1ght.4nd.d4y@gmail.com>
To: viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nathaniel Yazdani <n1ght.4nd.d4y@gmail.com>
Subject: [RFC PATCH for-next 4/4] epoll: epoll() syscall definition
Date: Sun, 23 Feb 2014 17:42:42 -0800
Message-ID: <1393206162-18151-5-git-send-email-n1ght.4nd.d4y@gmail.com> (raw)
In-Reply-To: <1393206162-18151-1-git-send-email-n1ght.4nd.d4y@gmail.com>

This new system call combines eventpoll entry addition, modification,
deletion, and retrieval into a single call, much like the BSDs' kevent().
Eventpoll entries are described using struct epoll, whose definition
and implementation can be found in prior patches. Its operation is fairly
straightforward: for every input eventpoll entry, add/modify it if the
I/O events bitmask is nonzero (otherwise remove the untriggerable entry),
updating the final event mask in userspace, then retrieve as many ready
eventpoll entries as will fit into the output buffer. It returns the
number of successfully

Signed-off-by: Nathaniel Yazdani <n1ght.4nd.d4y@gmail.com>
---
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index af90312..13451a2 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1816,6 +1981,66 @@ SYSCALL_DEFINE1(epoll_create, int, size)
 }
 
 /*
+ * This behaves like sys_epoll_ctl() and sys_epoll_wait() combined into one;
+ * it creates, modifies, or deletes eventpoll entries from the 'in' array and
+ * stores triggered eventpoll entries in the 'out' array. The input array is
+ * _not_ read-only, because the resulting event mask gets written back to each
+ * entry's ->ep_events field. When successful, this will be the same as before
+ * (plus EPOLLERR & EPOLLHUP). If ->ep_events gets cleared, then it is reasonable
+ * to infer that the entry's ->ep_fildes was a bad file descriptor.
+ */
+SYSCALL_DEFINE6(epoll, int, ep, struct epoll __user *, in,
+		unsigned int, inc, struct epoll __user *, out,
+		unsigned int, outc, int, timeout)
+{
+	struct file *file = fget(ep);
+	unsigned int i;
+	int ret;
+
+	ret = -EBADF;
+	if (!file || !is_file_epoll(file))
+		goto out;
+
+input:
+	/* process input eventpoll entries */
+	if (!in || !inc)
+		goto output;
+
+	ret = -EFAULT;
+	if (!access_ok(VERIFY_WRITE, in, inc * sizeof(struct epoll)))
+		goto out;
+	for (i = 0; i < inc; ++i) {
+		int fd, io;
+		long long id;
+
+		ret = -EFAULT;
+		if (__get_user(fd, &in[i].ep_fildes) ||
+		    __get_user(io, &in[i].ep_events) ||
+		    __get_user(id, &in[i].ep_ident))
+			goto out;
+
+		ep_control(file->private_data, fd, &io, id, 0);
+		ret = -EFAULT;
+		if (__put_user(io, &in[i].ep_events))
+			goto out;
+	}
+
+output:
+	/* produce output eventpoll entries */
+	if (!out || !outc)
+		goto out;
+
+	ret = -EFAULT;
+	if (!access_ok(VERIFY_WRITE, out, outc * sizeof(struct epoll)))
+		goto out;
+	ret = ep_poll(file->private_data, out, outc * sizeof(struct epoll),
+		      timeout, ep_send_entries);
+out:
+	fput(file);
+	return ret;
+}
+
+/*
  * The following function implements the controller interface for
  * the eventpoll file that enables the insertion/removal/change of
  * file descriptors inside the interest set.

  parent reply index

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-24  1:42 [RFC PATCH for-next 0/4] epoll: combined control/wait syscall Nathaniel Yazdani
2014-02-24  1:42 ` [RFC PATCH for-next 1/4] epoll: struct epoll userspace definiton Nathaniel Yazdani
2014-02-24  5:29   ` Eric Wong
     [not found]     ` <CAJ3m7Bq1y+MLn=HFY3AADnVc2HK31+WANahiYLUcdBw=hh_2pg@mail.gmail.com>
     [not found]       ` <20140225101527.GA9963@dcvr.yhbt.net>
2014-02-26  0:13         ` Nathaniel Yazdani
2014-02-24  1:42 ` [RFC PATCH for-next 2/4] epoll: epoll() syscall declaration Nathaniel Yazdani
2014-02-24  5:32   ` Eric Wong
2014-02-24  5:44     ` Nathaniel Yazdani
2014-02-25 10:30       ` Eric Wong
2014-02-25 23:44         ` Nathaniel Yazdani
2014-02-24  1:42 ` [RFC PATCH for-next 3/4] epoll: struct epoll support Nathaniel Yazdani
2014-02-24 18:59   ` Jonathan Corbet
2014-02-24 19:24     ` Nathaniel Yazdani
2014-02-24  1:42 ` Nathaniel Yazdani [this message]
2014-02-25 10:21   ` [RFC PATCH for-next 4/4] epoll: epoll() syscall definition Eric Wong
2014-02-25 23:46     ` Nathaniel Yazdani

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=1393206162-18151-5-git-send-email-n1ght.4nd.d4y@gmail.com \
    --to=n1ght.4nd.d4y@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git