mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 04/13] fsnotify: add in inode fsnotify markings
Date: Tue, 7 Apr 2009 16:06:15 -0700	[thread overview]
Message-ID: <20090407160615.0815aadd.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090327200526.32007.29489.stgit@paris.rdu.redhat.com>

On Fri, 27 Mar 2009 16:05:26 -0400
Eric Paris <eparis@redhat.com> wrote:

> This patch creates in inode fsnotify markings.  dnotify will make use of in
> inode markings to mark which inodes it wishes to send events for.

The text appears to be using the term "in inode" as a term-of-art.  But
it's a new one to me.

>  fanotify
> will use this to mark which inodes it does not wish to send events for.
> 

<but i dont know what fanotify is>

> ---
> 
>  Documentation/filesystems/fsnotify.txt |  180 +++++++++++++++++++++++++
>  fs/inode.c                             |    9 +
>  fs/notify/Makefile                     |    2 
>  fs/notify/fsnotify.c                   |   10 +
>  fs/notify/fsnotify.h                   |    3 
>  fs/notify/group.c                      |   33 ++++-
>  fs/notify/inode_mark.c                 |  229 ++++++++++++++++++++++++++++++++
>  include/linux/fs.h                     |    5 +
>  include/linux/fsnotify.h               |    9 +
>  include/linux/fsnotify_backend.h       |   58 ++++++++
>  10 files changed, 535 insertions(+), 3 deletions(-)
>  create mode 100644 Documentation/filesystems/fsnotify.txt
>  create mode 100644 fs/notify/inode_mark.c
> 
> diff --git a/Documentation/filesystems/fsnotify.txt b/Documentation/filesystems/fsnotify.txt
> new file mode 100644
> index 0000000..e1c90f5
> --- /dev/null
> +++ b/Documentation/filesystems/fsnotify.txt
> @@ -0,0 +1,180 @@
> +fsnotify inode mark locking/lifetime/and refcnting
> +
> +struct fsnotify_mark_entry {
> +        __u32 mask;                     /* mask this mark entry is for */
> +        /* we hold ref for each i_list and g_list.  also one ref for each 'thing'
> +         * in kernel that found and may be using this mark. */
> +        atomic_t refcnt;                /* active things looking at this mark */
> +        struct inode *inode;            /* inode this entry is associated with */
> +        struct fsnotify_group *group;   /* group this mark entry is for */
> +        struct hlist_node i_list;       /* list of mark_entries by inode->i_fsnotify_mark_entries */
> +        struct list_head g_list;        /* list of mark_entries by group->i_fsnotify_mark_entries */
> +        spinlock_t lock;                /* protect group, inode, and killme */
> +        struct list_head free_i_list;   /* tmp list used when freeing this mark */
> +        struct list_head free_g_list;   /* tmp list used when freeing this mark */
> +        void (*free_mark)(struct fsnotify_mark_entry *entry); /* called on final put+free */
> +};
> +
> +REFCNT:
> +The mark->refcnt tells how many "things" in the kernel currectly are

"currently"

>
> ...
>
> +The inode mark can be cleared for a number of different reasons including:
> +- The inode is unlinked for the last time.  (fsnotify_inoderemove)
> +- The inode is being evicted from cache. (fsnotify_inode_delete)
> +- The fs the inode is on is unmounted.  (fsnotify_inode_delete/fsnotify_unmount_inodes)

So it did want to be called fsnotify_inode_remove.

> +- Something explicitly requests that it be removed.  (fsnotify_destroy_mark_by_entry)
> +- The fsnotify_group associated with the mark is going away and all such marks
> +  need to be cleaned up. (fsnotify_clear_marks_by_group)
> +
> +Worst case we are given an inode and need to clean up all the marks on that
> +inode.  We take i_lock and walk the i_fsnotify_mark_entries safely.  For each
> +mark on the list we take a reference (so the mark can't disappear under us).
> +We remove that mark form the inode's list of marks and we add this mark to a
> +private list anchored on the stack using i_free_list;  At this point we no
> +longer fear anything finding the mark using the inode's list of marks.

damn, I wish this was all written in the C files instead.

>
> ...
>
> +void fsnotify_recalc_group_mask(struct fsnotify_group *group)
> +{
> +	__u32 mask = 0;
> +	__u32 old_mask = group->mask;
> +	struct fsnotify_mark_entry *entry;
> +
> +	spin_lock(&group->mark_lock);
> +	list_for_each_entry(entry, &group->mark_entries, g_list) {
> +		mask |= entry->mask;
> +	}

unneeded {}  (numerous places)

> +	spin_unlock(&group->mark_lock);
> +
> +	group->mask = mask;
> +
> +	if (old_mask != mask)
> +		fsnotify_recalc_global_mask();
> +}
> +
>  static void fsnotify_add_group(struct fsnotify_group *group)
>  {
>  	int priority = group->priority;
> @@ -71,13 +89,22 @@ static void fsnotify_get_group(struct fsnotify_group *group)
>  	atomic_inc(&group->refcnt);
>  }
>  
> -static void fsnotify_destroy_group(struct fsnotify_group *group)
> +void fsnotify_final_destroy_group(struct fsnotify_group *group)
>  {
>  	if (group->ops->free_group_priv)
>  		group->ops->free_group_priv(group);
>  
>  	kfree(group);
>  }

missing newline

> +static void fsnotify_destroy_group(struct fsnotify_group *group)
> +{
> +	/* clear all inode mark entries for this group */
> +	fsnotify_clear_marks_by_group(group);
> +
> +	/* past the point of no return, matches the initial value of 1 */
> +	if (atomic_dec_and_test(&group->num_marks))
> +		fsnotify_final_destroy_group(group);
> +}
>  
>
> ...
>
> +void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry)
> +{
> +	struct fsnotify_group *group;
> +	struct inode *inode;
> +
> +	spin_lock(&entry->lock);
> +
> +	group = entry->group;
> +	inode = entry->inode;
> +
> +	BUG_ON(group && !inode);
> +	BUG_ON(!group && inode);
> +
> +	/* if !group something else already marked this to die */
> +	if (!group) {
> +		spin_unlock(&entry->lock);
> +		return;
> +	}
> +
> +	/* this just tests that the caller held a reference */
> +	if (unlikely(atomic_read(&entry->refcnt) < 3))
> +		BUG();

BUG_ON()

> +	spin_lock(&group->mark_lock);
> +	spin_lock(&inode->i_lock);
> +
> +	hlist_del_init(&entry->i_list);
> +	entry->inode = NULL;
> +	fsnotify_put_mark(entry); /* for i_list */
> +
> +	list_del_init(&entry->g_list);
> +	entry->group = NULL;
> +	fsnotify_put_mark(entry); /* for g_list */
> +
> +	fsnotify_recalc_inode_mask_locked(inode);
> +
> +	spin_unlock(&inode->i_lock);
> +	spin_unlock(&group->mark_lock);
> +	spin_unlock(&entry->lock);
> +
> +	group->ops->freeing_mark(entry, group);
> +
> +	if (atomic_dec_and_test(&group->num_marks))
> +		fsnotify_final_destroy_group(group);
> +}
> +
>
> ...
>
> +void fsnotify_init_mark(struct fsnotify_mark_entry *entry, void (*free_mark)(struct fsnotify_mark_entry *entry))

you must have a wide monitor.

> +
> +{
> +	spin_lock_init(&entry->lock);
> +	atomic_set(&entry->refcnt, 1);
> +	INIT_HLIST_NODE(&entry->i_list);
> +	entry->group = NULL;
> +	entry->mask = 0;
> +	entry->inode = NULL;
> +	entry->free_mark = free_mark;
> +}
> +
>
> ...
>


  reply	other threads:[~2009-04-07 23:16 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 [this message]
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
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=20090407160615.0815aadd.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome