linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
	Matthew Bobrowski <mbobrowski@mbobrowski.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v4 01/15] fsnotify: annotate directory entry modification events
Date: Thu, 3 Jan 2019 16:41:37 +0100	[thread overview]
Message-ID: <20190103154137.GA22409@quack2.suse.cz> (raw)
In-Reply-To: <20181202113826.32133-2-amir73il@gmail.com>

On Sun 02-12-18 13:38:12, Amir Goldstein wrote:
> "dirent" events are referring to events that modify directory entries,
> such as create,delete,rename. Those events should always be reported
> on a watched directory, regardless if FS_EVENT_ON_CHILD is set
> on the watch mask.
> 
> fsnotify_nameremove() and fsnotify_move() were modified to no longer
> set the FS_EVENT_ON_CHILD event bit. This is a semantic change to
> align with the "dirent" event definition. It has no effect on any
> existing backend, because dnotify, inotify and audit always requets the
> child events and fanotify does not get the delete,rename events.
> 
> The fsnotify_dirent() helper is used instead of fsnotify_parent() to
> report a dirent event to dentry->d_parent without FS_EVENT_ON_CHILD
> and regardless if parent has the FS_EVENT_ON_CHILD bit set.
> 
> ALL_FSNOTIFY_DIRENT_EVENTS defines all the dirent event types and
> those event types have been extracted out of FS_EVENTS_POSS_ON_CHILD.
> 
> That means for a directory with an inotify watch and only dirent
> events in the mask (i.e. create,delete,move), all children dentries
> will no longer have the DCACHE_FSNOTIFY_PARENT_WATCHED flag set.
> This will allow all events that happen on children to be optimized
> away in __fsnotify_parent() without the need to dereference
> child->d_parent->d_inode->i_fsnotify_mask.
> 
> Since the dirent events are never repoted via __fsnotify_parent(),
> this results in no change of logic, but only an optimization.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  include/linux/fsnotify.h         | 42 +++++++++++++++++++++++++-------
>  include/linux/fsnotify_backend.h | 36 +++++++++++++++------------
>  2 files changed, 54 insertions(+), 24 deletions(-)
> 
> diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
> index 2ccb08cb5d6a..8de8f390cce2 100644
> --- a/include/linux/fsnotify.h
> +++ b/include/linux/fsnotify.h
> @@ -17,8 +17,35 @@
>  #include <linux/slab.h>
>  #include <linux/bug.h>
>  
> +/*
> + * Notify this @dir inode about a change in the directory entry @dentry.
> + *
> + * Unlike fsnotify_parent(), the event will be reported regardless of the
> + * FS_EVENT_ON_CHILD mask on the parent inode.
> + *
> + * When called with NULL @dir (from fsnotify_nameremove()), the dentry parent
> + * inode is used as the inode to report the event to.
> + */
> +static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry,
> +				  __u32 mask)
> +{
> +	if (!dir)
> +		dir = d_inode(dentry->d_parent);

Just a small nit: This !dir handling is only used for
fsnotify_nameremove(). So why not move that d_parent logic to that single
call site? That would make the function easier to argue about.

Otherwise I like the patch.

								Honza

> +
> +	/*
> +	 * This helper assumes d_parent and d_name are stable. It must be true
> +	 * when called from fsnotify_create()/fsnotify_mkdir(). Less sure about
> +	 * all callers that get here from d_delete() => fsnotify_nameremove().
> +	 */
> +	WARN_ON(!inode_is_locked(dir));
> +
> +	return fsnotify(dir, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
> +			dentry->d_name.name, 0);
> +}
> +
>  /* Notify this dentry's parent about a child's events. */
> -static inline int fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask)
> +static inline int fsnotify_parent(const struct path *path,
> +				  struct dentry *dentry, __u32 mask)
>  {
>  	if (!dentry)
>  		dentry = path->dentry;
> @@ -85,8 +112,8 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
>  {
>  	struct inode *source = moved->d_inode;
>  	u32 fs_cookie = fsnotify_get_cookie();
> -	__u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
> -	__u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
> +	__u32 old_dir_mask = FS_MOVED_FROM;
> +	__u32 new_dir_mask = FS_MOVED_TO;
>  	const unsigned char *new_name = moved->d_name.name;
>  
>  	if (old_dir == new_dir)
> @@ -136,7 +163,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
>  	if (isdir)
>  		mask |= FS_ISDIR;
>  
> -	fsnotify_parent(NULL, dentry, mask);
> +	fsnotify_dirent(NULL, dentry, mask);
>  }
>  
>  /*
> @@ -155,7 +182,7 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
>  {
>  	audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
>  
> -	fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
> +	fsnotify_dirent(inode, dentry, FS_CREATE);
>  }
>  
>  /*
> @@ -176,12 +203,9 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct
>   */
>  static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
>  {
> -	__u32 mask = (FS_CREATE | FS_ISDIR);
> -	struct inode *d_inode = dentry->d_inode;
> -
>  	audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
>  
> -	fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
> +	fsnotify_dirent(inode, dentry, FS_CREATE | FS_ISDIR);
>  }
>  
>  /*
> diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
> index 7639774e7475..7f195d43efaf 100644
> --- a/include/linux/fsnotify_backend.h
> +++ b/include/linux/fsnotify_backend.h
> @@ -59,27 +59,33 @@
>   * dnotify and inotify. */
>  #define FS_EVENT_ON_CHILD	0x08000000
>  
> -/* This is a list of all events that may get sent to a parernt based on fs event
> - * happening to inodes inside that directory */
> -#define FS_EVENTS_POSS_ON_CHILD   (FS_ACCESS | FS_MODIFY | FS_ATTRIB |\
> -				   FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN |\
> -				   FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE |\
> -				   FS_DELETE | FS_OPEN_PERM | FS_ACCESS_PERM | \
> -				   FS_OPEN_EXEC | FS_OPEN_EXEC_PERM)
> -
>  #define FS_MOVE			(FS_MOVED_FROM | FS_MOVED_TO)
>  
> +/*
> + * Directory entry modification events - reported only to directory
> + * where entry is modified and not to a watching parent.
> + * The watching parent may get an FS_ATTRIB|FS_EVENT_ON_CHILD event
> + * when a directory entry inside a child subdir changes.
> + */
> +#define ALL_FSNOTIFY_DIRENT_EVENTS	(FS_CREATE | FS_DELETE | FS_MOVE)
> +
>  #define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \
>  				  FS_OPEN_EXEC_PERM)
>  
> +/*
> + * This is a list of all events that may get sent to a parent based on fs event
> + * happening to inodes inside that directory.
> + */
> +#define FS_EVENTS_POSS_ON_CHILD   (ALL_FSNOTIFY_PERM_EVENTS | \
> +				   FS_ACCESS | FS_MODIFY | FS_ATTRIB | \
> +				   FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | \
> +				   FS_OPEN | FS_OPEN_EXEC)
> +
>  /* Events that can be reported to backends */
> -#define ALL_FSNOTIFY_EVENTS (FS_ACCESS | FS_MODIFY | FS_ATTRIB | \
> -			     FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN | \
> -			     FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE | \
> -			     FS_DELETE | FS_DELETE_SELF | FS_MOVE_SELF | \
> -			     FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED | \
> -			     FS_OPEN_PERM | FS_ACCESS_PERM | FS_DN_RENAME | \
> -			     FS_OPEN_EXEC | FS_OPEN_EXEC_PERM)
> +#define ALL_FSNOTIFY_EVENTS (ALL_FSNOTIFY_DIRENT_EVENTS | \
> +			     FS_EVENTS_POSS_ON_CHILD | \
> +			     FS_DELETE_SELF | FS_MOVE_SELF | FS_DN_RENAME | \
> +			     FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED)
>  
>  /* Extra flags that may be reported with event or control handling of events */
>  #define ALL_FSNOTIFY_FLAGS  (FS_EXCL_UNLINK | FS_ISDIR | FS_IN_ONESHOT | \
> -- 
> 2.17.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2019-01-03 15:41 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-02 11:38 [PATCH v4 00/15] fanotify: add support for more event types Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 01/15] fsnotify: annotate directory entry modification events Amir Goldstein
2019-01-03 15:41   ` Jan Kara [this message]
2019-01-03 16:31     ` Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 02/15] fsnotify: send all event types to super block marks Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 03/15] fsnotify: move mask out of struct fsnotify_event Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 04/15] fanotify: rename struct fanotify_{,perm_}event_info Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 05/15] fanotify: open code fill_event_metadata() Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 06/15] fanotify: encode file identifier for FAN_REPORT_FID Amir Goldstein
2019-01-03 16:18   ` Jan Kara
2018-12-02 11:38 ` [PATCH v4 07/15] fanotify: copy event fid info to user Amir Goldstein
2019-01-03 17:13   ` Jan Kara
2019-01-04  3:58     ` Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 08/15] fanotify: enable FAN_REPORT_FID init flag Amir Goldstein
2018-12-08  9:26   ` Amir Goldstein
2018-12-10 16:20     ` Jan Kara
2018-12-11  6:12       ` Matthew Bobrowski
2018-12-11  6:58         ` Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 09/15] fanotify: cache fsid in fsnotify_mark_connector Amir Goldstein
2019-01-04  9:38   ` Jan Kara
2019-01-04  9:54     ` Jan Kara
2018-12-02 11:38 ` [PATCH v4 10/15] vfs: add vfs_get_fsid() helper Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 11/15] fanotify: use vfs_get_fsid() helper instead of vfs_statfs() Amir Goldstein
2019-01-04  9:55   ` Jan Kara
2018-12-02 11:38 ` [PATCH v4 12/15] fanotify: check FS_ISDIR flag instead of d_is_dir() Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 13/15] fanotify: support events with data type FSNOTIFY_EVENT_INODE Amir Goldstein
2019-01-04 10:17   ` Jan Kara
2019-01-04 11:12     ` Amir Goldstein
2018-12-02 11:38 ` [PATCH v4 14/15] fanotify: add support for create/attrib/move/delete events Amir Goldstein
2019-01-04 10:26   ` Jan Kara
2018-12-02 11:38 ` [PATCH v4 15/15] fanotify: report FAN_ONDIR to listener with FAN_REPORT_FID Amir Goldstein
2019-01-04 10:57   ` Jan Kara
2019-01-04 11:42     ` Amir Goldstein
2019-01-04 12:18       ` Jan Kara
2019-01-04 12:39         ` Amir Goldstein
2019-01-05  0:34           ` Matthew Bobrowski
2019-01-05  8:18             ` Amir Goldstein
2019-01-07  7:40         ` Amir Goldstein
2019-01-04 12:19       ` Jan Kara
2019-01-04 23:46       ` Matthew Bobrowski
2019-01-05  7:59         ` Amir Goldstein
2019-01-05  9:49           ` Matthew Bobrowski
2019-01-07  7:37             ` Amir Goldstein
2019-01-04 11:00 ` [PATCH v4 00/15] fanotify: add support for more event types Jan Kara
2019-01-07  7:46   ` Amir Goldstein
2019-01-09 14:02     ` Jan Kara
2019-01-09 15:34       ` Amir Goldstein
2019-01-10  7:49         ` Amir Goldstein
2019-01-10  9:22           ` Jan Kara
2019-01-10  9:50             ` Amir Goldstein
2019-01-10 11:43               ` Jan Kara
2019-01-10 11:55                 ` Amir Goldstein
2019-01-10  8:53         ` Jan Kara
2019-01-10 10:10           ` Amir Goldstein

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=20190103154137.GA22409@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mbobrowski@mbobrowski.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 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).