From: Andrew Morton <akpm@linux-foundation.org>
To: Eric Paris <eparis@redhat.com>
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
hch@infradead.org, alan@lxorguk.ukuu.org.uk,
sfr@canb.auug.org.au, john@johnmccutchan.com, rlove@rlove.org
Subject: Re: [PATCH -V2 07/13] fsnotify: generic notification queue and waitq
Date: Tue, 7 Apr 2009 16:06:26 -0700 [thread overview]
Message-ID: <20090407160626.1ff81b1e.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090327200543.32007.98060.stgit@paris.rdu.redhat.com>
On Fri, 27 Mar 2009 16:05:43 -0400
Eric Paris <eparis@redhat.com> wrote:
> inotify needs to do asyc notification in which event information is stored
> on a queue until the listener is ready to receive it. This patch
> implements a generic notification queue for inotify (and later fanotify) to
> store events to be sent at a later time.
>
>
> ...
>
> +/* return 1 if something is available, return 0 otherwise */
> +int fsnotify_check_notif_queue(struct fsnotify_group *group)
> +{
> + BUG_ON(!mutex_is_locked(&group->notification_mutex));
> + return !list_empty(&group->notification_list);
> +}
It's a poorly named function, because the name ("check") doesn't convey
information about the return value.
Better would be
bool fsnotify_notif_queue_nonempty(...)
or
bool fsnotify_notif_queue_empty(...)
(and invert test in callers)
and the abbreviation of "notify" to "notif" just makes it harder to
remember its name.
best is
bool fsnotify_notify_queue_is_empty(...)
> void fsnotify_get_event(struct fsnotify_event *event)
> {
> @@ -45,26 +60,180 @@ void fsnotify_put_event(struct fsnotify_event *event)
> return;
>
> if (atomic_dec_and_test(&event->refcnt)) {
> - if (event->data_type == FSNOTIFY_EVENT_PATH) {
> + if (event->data_type == FSNOTIFY_EVENT_PATH)
> path_put(&event->path);
> - event->path.dentry = NULL;
> - event->path.mnt = NULL;
> - }
> + kmem_cache_free(event_kmem_cache, event);
> + }
> +}
>
> - event->mask = 0;
> +struct fsnotify_event_holder *alloc_event_holder(void)
> +{
> + return kmem_cache_alloc(event_holder_kmem_cache, GFP_KERNEL);
> +}
That's a pretty generic-sounding name for a global symbol.
> - kmem_cache_free(event_kmem_cache, event);
> +void fsnotify_destroy_event_holder(struct fsnotify_event_holder *holder)
> +{
> + kmem_cache_free(event_holder_kmem_cache, holder);
> +}
That one's better.
> +/*
> + * check if 2 events contain the same information.
> + */
> +static inline int event_compare(struct fsnotify_event *old, struct fsnotify_event *new)
> +{
> + if ((old->mask == new->mask) &&
> + (old->to_tell == new->to_tell) &&
> + (old->data_type == new->data_type)) {
> + switch (old->data_type) {
> + case (FSNOTIFY_EVENT_INODE):
> + if (old->inode == new->inode)
> + return 1;
> + break;
> + case (FSNOTIFY_EVENT_PATH):
> + if ((old->path.mnt == new->path.mnt) &&
> + (old->path.dentry == new->path.dentry))
> + return 1;
> + case (FSNOTIFY_EVENT_NONE):
> + return 1;
> + };
> }
> + return 0;
> }
The compiler would have inlined this.
> -struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask, void *data, int data_type)
> +/*
> + * Add an event to the group notification queue. The group can later pull this
> + * event off the queue to deal with.
> + */
> +int fsnotify_add_notif_event(struct fsnotify_group *group, struct fsnotify_event *event)
s/notif/notify/
> +{
> + struct fsnotify_event_holder *holder = NULL;
> + struct list_head *list = &group->notification_list;
> + struct fsnotify_event_holder *last_holder;
> + struct fsnotify_event *last_event;
> +
> + /*
> + * Check if we expect to be able to use the in event holder. If not alloc
> + * a new holder.
> + * For the overflow event it's possible that something will use the in
> + * event holder before we get the lock so we may need to jump back and
> + * alloc a new holder.
> + */
The term "in event" is unclear to this reader.
> + if (!list_empty(&event->holder.event_list)) {
> +alloc_holder:
> + holder = alloc_event_holder();
> + if (!holder)
> + return -ENOMEM;
> + }
> +
> + mutex_lock(&group->notification_mutex);
> +
> + if (group->q_len >= group->max_events)
> + event = &q_overflow_event;
> +
> + spin_lock(&event->lock);
> +
> + if (list_empty(&event->holder.event_list)) {
> + if (unlikely(holder))
> + fsnotify_destroy_event_holder(holder);
> + holder = &event->holder;
> + } else if (unlikely(!holder)) {
> + /* between the time we checked above and got the lock the in
> + * event holder was used, go back and get a new one */
> + spin_unlock(&event->lock);
> + mutex_unlock(&group->notification_mutex);
> + goto alloc_holder;
> + }
> +
> + if (!list_empty(list)) {
> + last_holder = list_entry(list->prev, struct fsnotify_event_holder, event_list);
> + last_event = last_holder->event;
> + if (event_compare(last_event, event)) {
> + spin_unlock(&event->lock);
> + mutex_unlock(&group->notification_mutex);
> + if (holder != &event->holder)
> + fsnotify_destroy_event_holder(holder);
> + return 0;
> + }
> + }
> +
> + group->q_len++;
> + holder->event = event;
> +
> + fsnotify_get_event(event);
> + list_add_tail(&holder->event_list, list);
> + spin_unlock(&event->lock);
> + mutex_unlock(&group->notification_mutex);
> +
> + wake_up(&group->notification_waitq);
> + return 0;
> +}
> +
>
> ...
>
next prev parent reply other threads:[~2009-04-07 23:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-27 20:05 [PATCH -V2 01/13] mutex: add atomic_dec_and_mutex_lock Eric Paris
2009-03-27 20:05 ` [PATCH -V2 02/13] fsnotify: unified filesystem notification backend Eric Paris
2009-04-07 23:05 ` Andrew Morton
2009-04-08 0:37 ` Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-03-27 20:05 ` [PATCH -V2 03/13] fsnotify: add group priorities Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-03-27 20:05 ` [PATCH -V2 04/13] fsnotify: add in inode fsnotify markings Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-03-27 20:05 ` [PATCH -V2 05/13] fsnotify: parent event notification Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-03-27 20:05 ` [PATCH -V2 06/13] dnotify: reimplement dnotify using fsnotify Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-03-27 20:05 ` [PATCH -V2 07/13] fsnotify: generic notification queue and waitq Eric Paris
2009-04-07 23:06 ` Andrew Morton [this message]
2009-03-27 20:05 ` [PATCH -V2 08/13] fsnotify: include pathnames with entries when possible Eric Paris
2009-03-27 20:05 ` [PATCH -V2 09/13] fsnotify: add correlations between events Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-03-27 20:06 ` [PATCH -V2 10/13] fsnotify: allow groups to add private data to events Eric Paris
2009-03-27 20:06 ` [PATCH -V2 11/13] fsnotify: fsnotify marks on inodes pin them in core Eric Paris
2009-03-27 20:06 ` [PATCH -V2 12/13] fsnotify: handle filesystem unmounts with fsnotify marks Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-03-27 20:06 ` [PATCH -V2 13/13] inotify: reimplement inotify using fsnotify Eric Paris
2009-04-07 23:06 ` Andrew Morton
2009-04-07 23:06 ` [PATCH -V2 01/13] mutex: add atomic_dec_and_mutex_lock Andrew Morton
2009-04-28 20:08 ` Andrew Morton
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=20090407160626.1ff81b1e.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=eparis@redhat.com \
--cc=hch@infradead.org \
--cc=john@johnmccutchan.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rlove@rlove.org \
--cc=sfr@canb.auug.org.au \
--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
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.