From: Zach Brown <zab@zabbo.net>
To: Robert Love <rml@novell.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>,
linux-kernel@vger.kernel.org,
John McCutchan <ttb@tentacle.dhs.org>
Subject: Re: [patch] inotify, improved.
Date: Fri, 17 Jun 2005 10:20:20 -0700 [thread overview]
Message-ID: <42B30654.4030307@zabbo.net> (raw)
In-Reply-To: <1119021336.3949.104.camel@betsy>
[-- Attachment #1: Type: text/plain, Size: 646 bytes --]
> + schedule();
Here's a stab at getting rid of that raw schedule() in inotify_read().
It maintains the behaviour where it returns when an event doesn't fit
and returns after events have been copied instead of sleeping. It
changes behaviour in that it returns partial reads that suceeded instead
of the error that stopped processing. It also lets threads who race out
of a wakeup to find an empty list go back to sleep instead of returning
0. Dunno if that's behaviour you'd prefer but it seemed reasonable. I
hope that lockless list_empty() is OK, I didn't think very hard about it.
Compiles but totally untested. Check my work :)
- z
[-- Attachment #2: inotify-use-w-e-i-0.patch --]
[-- Type: text/x-patch, Size: 1868 bytes --]
Index: 2.6-mm-inotify-throwaway/fs/inotify.c
===================================================================
--- 2.6-mm-inotify-throwaway.orig/fs/inotify.c 2005-06-17 09:32:52.000000000 -0700
+++ 2.6-mm-inotify-throwaway/fs/inotify.c 2005-06-17 10:16:11.000000000 -0700
@@ -639,52 +639,32 @@
static ssize_t inotify_read(struct file *file, char __user *buf,
size_t count, loff_t *pos)
{
- size_t event_size = sizeof (struct inotify_event);
- struct inotify_device *dev;
- char __user *start;
- int ret;
- DEFINE_WAIT(wait);
-
- start = buf;
- dev = file->private_data;
-
- while (1) {
- int events;
-
- prepare_to_wait(&dev->wq, &wait, TASK_INTERRUPTIBLE);
-
- down(&dev->sem);
- events = !list_empty(&dev->events);
- up(&dev->sem);
- if (events) {
- ret = 0;
- break;
- }
-
- if (file->f_flags & O_NONBLOCK) {
- ret = -EAGAIN;
- break;
- }
-
- if (signal_pending(current)) {
- ret = -EINTR;
- break;
- }
-
- schedule();
- }
-
- finish_wait(&dev->wq, &wait);
- if (ret)
- return ret;
+ struct inotify_device *dev = file->private_data;
+ char __user *start = buf;
+ int ret = 0;
down(&dev->sem);
while (1) {
struct inotify_kernel_event *kevent;
+ static size_t event_size = sizeof (struct inotify_event);
- ret = buf - start;
- if (list_empty(&dev->events))
- break;
+ if (list_empty(&dev->events)) {
+ /* return partial instead of sleeping */
+ if (buf > start)
+ break;
+ if (file->f_flags & O_NONBLOCK) {
+ ret = -EAGAIN;
+ break;
+ }
+ up(&dev->sem);
+ ret = wait_event_interruptible(dev->wq,
+ !list_empty(&dev->events));
+ down(&dev->sem);
+ if (ret)
+ break;
+ continue;
+
+ }
kevent = inotify_dev_get_event(dev);
if (event_size + kevent->event.len > count)
@@ -710,6 +690,9 @@
}
up(&dev->sem);
+ if (buf > start)
+ ret = buf - start;
+
return ret;
}
next prev parent reply other threads:[~2005-06-17 17:20 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-15 17:18 [patch] inotify Robert Love
2005-06-16 17:52 ` Zach Brown
2005-06-16 18:25 ` Robert Love
2005-06-17 1:30 ` Nick Piggin
2005-06-17 1:35 ` Robert Love
2005-06-17 15:15 ` [patch] inotify, improved Robert Love
2005-06-17 15:37 ` Chris Friesen
2005-06-17 15:44 ` Robert Love
2005-06-17 16:11 ` Valdis.Kletnieks
2005-06-17 16:29 ` Robert Love
2005-06-17 16:36 ` Chris Friesen
2005-06-17 16:43 ` Chris Wright
2005-06-17 16:46 ` Muli Ben-Yehuda
2005-06-17 16:40 ` Chris Friesen
2005-06-17 17:57 ` John McCutchan
2005-06-17 17:20 ` Zach Brown [this message]
2005-06-17 17:54 ` John McCutchan
2005-06-17 17:56 ` Zach Brown
2005-06-17 18:15 ` John McCutchan
2005-06-17 18:17 ` Zach Brown
2005-06-17 17:07 ` [patch] inotify Arnd Bergmann
2005-06-17 17:54 ` Christoph Hellwig
2005-06-17 18:12 ` John McCutchan
2005-06-17 18:16 ` Robert Love
2005-06-17 18:28 ` Christoph Hellwig
2005-06-17 18:38 ` Robert Love
2005-06-17 18:45 ` Christoph Hellwig
2005-06-17 18:54 ` Robert Love
2005-06-17 17:56 ` John McCutchan
2005-06-17 21:33 ` Andrew Morton
2005-06-17 21:40 ` Robert Love
2005-06-17 23:52 ` Robert Love
2005-06-21 0:51 ` Neil Brown
2005-06-21 2:15 ` John McCutchan
2005-06-21 2:29 ` Neil Brown
2005-06-21 2:43 ` John McCutchan
2005-06-21 15:55 ` Robert Love
2005-07-14 0:25 ` Neil Brown
2005-07-14 4:11 ` John McCutchan
2005-06-18 0:05 ` Arnd Bergmann
2005-06-18 0:57 ` Robert Love
2005-06-18 1:51 ` Chris Wedgwood
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=42B30654.4030307@zabbo.net \
--to=zab@zabbo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=nickpiggin@yahoo.com.au \
--cc=rml@novell.com \
--cc=ttb@tentacle.dhs.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.