diff mbox series

[v3,03/15] fanotify: Split fsid check from other fid mode checks

Message ID 20210629191035.681913-4-krisman@collabora.com
State Superseded
Headers show
Series File system wide monitoring | expand

Commit Message

Gabriel Krisman Bertazi June 29, 2021, 7:10 p.m. UTC
FAN_FS_ERROR will require fsid, but not necessarily require the
filesystem to expose a file handle.  Split those checks into different
functions, so they can be used separately when setting up an event.

While there, update a comment about tmpfs having 0 fsid, which is no
longer true.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>

---
Changes since v2:
  - FAN_ERROR -> FAN_FS_ERROR (Amir)
  - Update comment (Amir)

Changes since v1:
  (Amir)
  - Sort hunks to simplify diff.
Changes since RFC:
  (Amir)
  - Rename fanotify_check_path_fsid -> fanotify_test_fsid.
  - Use dentry directly instead of path.
---
 fs/notify/fanotify/fanotify_user.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

Comments

Amir Goldstein June 30, 2021, 3:14 a.m. UTC | #1
On Tue, Jun 29, 2021 at 10:12 PM Gabriel Krisman Bertazi
<krisman@collabora.com> wrote:
>
> FAN_FS_ERROR will require fsid, but not necessarily require the
> filesystem to expose a file handle.  Split those checks into different
> functions, so they can be used separately when setting up an event.
>
> While there, update a comment about tmpfs having 0 fsid, which is no
> longer true.
>
> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>

> ---
> Changes since v2:
>   - FAN_ERROR -> FAN_FS_ERROR (Amir)
>   - Update comment (Amir)
>
> Changes since v1:
>   (Amir)
>   - Sort hunks to simplify diff.
> Changes since RFC:
>   (Amir)
>   - Rename fanotify_check_path_fsid -> fanotify_test_fsid.
>   - Use dentry directly instead of path.
> ---
>  fs/notify/fanotify/fanotify_user.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 68a53d3534f8..67b18dfe0025 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -1192,16 +1192,15 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
>         return fd;
>  }
>
> -/* Check if filesystem can encode a unique fid */
> -static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
> +static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid)
>  {
>         __kernel_fsid_t root_fsid;
>         int err;
>
>         /*
> -        * Make sure path is not in filesystem with zero fsid (e.g. tmpfs).
> +        * Make sure dentry is not of a filesystem with zero fsid (e.g. fuse).
>          */
> -       err = vfs_get_fsid(path->dentry, fsid);
> +       err = vfs_get_fsid(dentry, fsid);
>         if (err)
>                 return err;
>
> @@ -1209,10 +1208,10 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
>                 return -ENODEV;
>
>         /*
> -        * Make sure path is not inside a filesystem subvolume (e.g. btrfs)
> +        * Make sure dentry is not of a filesystem subvolume (e.g. btrfs)
>          * which uses a different fsid than sb root.
>          */
> -       err = vfs_get_fsid(path->dentry->d_sb->s_root, &root_fsid);
> +       err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid);
>         if (err)
>                 return err;
>
> @@ -1220,6 +1219,12 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
>             root_fsid.val[1] != fsid->val[1])
>                 return -EXDEV;
>
> +       return 0;
> +}
> +
> +/* Check if filesystem can encode a unique fid */
> +static int fanotify_test_fid(struct dentry *dentry)
> +{
>         /*
>          * We need to make sure that the file system supports at least
>          * encoding a file handle so user can use name_to_handle_at() to
> @@ -1227,8 +1232,8 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
>          * objects. However, name_to_handle_at() requires that the
>          * filesystem also supports decoding file handles.
>          */
> -       if (!path->dentry->d_sb->s_export_op ||
> -           !path->dentry->d_sb->s_export_op->fh_to_dentry)
> +       if (!dentry->d_sb->s_export_op ||
> +           !dentry->d_sb->s_export_op->fh_to_dentry)
>                 return -EOPNOTSUPP;
>
>         return 0;
> @@ -1379,7 +1384,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
>         }
>
>         if (fid_mode) {
> -               ret = fanotify_test_fid(&path, &__fsid);
> +               ret = fanotify_test_fsid(path.dentry, &__fsid);
> +               if (ret)
> +                       goto path_put_and_out;
> +
> +               ret = fanotify_test_fid(path.dentry);
>                 if (ret)
>                         goto path_put_and_out;
>
> --
> 2.32.0
>
Jan Kara July 7, 2021, 7:24 p.m. UTC | #2
On Tue 29-06-21 15:10:23, Gabriel Krisman Bertazi wrote:
> FAN_FS_ERROR will require fsid, but not necessarily require the
> filesystem to expose a file handle.  Split those checks into different
> functions, so they can be used separately when setting up an event.
> 
> While there, update a comment about tmpfs having 0 fsid, which is no
> longer true.
> 
> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> 
> ---
> Changes since v2:
>   - FAN_ERROR -> FAN_FS_ERROR (Amir)
>   - Update comment (Amir)
> 
> Changes since v1:
>   (Amir)
>   - Sort hunks to simplify diff.
> Changes since RFC:
>   (Amir)
>   - Rename fanotify_check_path_fsid -> fanotify_test_fsid.
>   - Use dentry directly instead of path.
> ---
>  fs/notify/fanotify/fanotify_user.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 68a53d3534f8..67b18dfe0025 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -1192,16 +1192,15 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
>  	return fd;
>  }
>  
> -/* Check if filesystem can encode a unique fid */
> -static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
> +static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid)
>  {
>  	__kernel_fsid_t root_fsid;
>  	int err;
>  
>  	/*
> -	 * Make sure path is not in filesystem with zero fsid (e.g. tmpfs).
> +	 * Make sure dentry is not of a filesystem with zero fsid (e.g. fuse).
>  	 */
> -	err = vfs_get_fsid(path->dentry, fsid);
> +	err = vfs_get_fsid(dentry, fsid);
>  	if (err)
>  		return err;
>  
> @@ -1209,10 +1208,10 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
>  		return -ENODEV;
>  
>  	/*
> -	 * Make sure path is not inside a filesystem subvolume (e.g. btrfs)
> +	 * Make sure dentry is not of a filesystem subvolume (e.g. btrfs)
>  	 * which uses a different fsid than sb root.
>  	 */
> -	err = vfs_get_fsid(path->dentry->d_sb->s_root, &root_fsid);
> +	err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid);
>  	if (err)
>  		return err;
>  
> @@ -1220,6 +1219,12 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
>  	    root_fsid.val[1] != fsid->val[1])
>  		return -EXDEV;
>  
> +	return 0;
> +}
> +
> +/* Check if filesystem can encode a unique fid */
> +static int fanotify_test_fid(struct dentry *dentry)
> +{
>  	/*
>  	 * We need to make sure that the file system supports at least
>  	 * encoding a file handle so user can use name_to_handle_at() to
> @@ -1227,8 +1232,8 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
>  	 * objects. However, name_to_handle_at() requires that the
>  	 * filesystem also supports decoding file handles.
>  	 */
> -	if (!path->dentry->d_sb->s_export_op ||
> -	    !path->dentry->d_sb->s_export_op->fh_to_dentry)
> +	if (!dentry->d_sb->s_export_op ||
> +	    !dentry->d_sb->s_export_op->fh_to_dentry)
>  		return -EOPNOTSUPP;
>  
>  	return 0;
> @@ -1379,7 +1384,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
>  	}
>  
>  	if (fid_mode) {
> -		ret = fanotify_test_fid(&path, &__fsid);
> +		ret = fanotify_test_fsid(path.dentry, &__fsid);
> +		if (ret)
> +			goto path_put_and_out;
> +
> +		ret = fanotify_test_fid(path.dentry);
>  		if (ret)
>  			goto path_put_and_out;
>  
> -- 
> 2.32.0
>
diff mbox series

Patch

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 68a53d3534f8..67b18dfe0025 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -1192,16 +1192,15 @@  SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
 	return fd;
 }
 
-/* Check if filesystem can encode a unique fid */
-static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
+static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid)
 {
 	__kernel_fsid_t root_fsid;
 	int err;
 
 	/*
-	 * Make sure path is not in filesystem with zero fsid (e.g. tmpfs).
+	 * Make sure dentry is not of a filesystem with zero fsid (e.g. fuse).
 	 */
-	err = vfs_get_fsid(path->dentry, fsid);
+	err = vfs_get_fsid(dentry, fsid);
 	if (err)
 		return err;
 
@@ -1209,10 +1208,10 @@  static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
 		return -ENODEV;
 
 	/*
-	 * Make sure path is not inside a filesystem subvolume (e.g. btrfs)
+	 * Make sure dentry is not of a filesystem subvolume (e.g. btrfs)
 	 * which uses a different fsid than sb root.
 	 */
-	err = vfs_get_fsid(path->dentry->d_sb->s_root, &root_fsid);
+	err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid);
 	if (err)
 		return err;
 
@@ -1220,6 +1219,12 @@  static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
 	    root_fsid.val[1] != fsid->val[1])
 		return -EXDEV;
 
+	return 0;
+}
+
+/* Check if filesystem can encode a unique fid */
+static int fanotify_test_fid(struct dentry *dentry)
+{
 	/*
 	 * We need to make sure that the file system supports at least
 	 * encoding a file handle so user can use name_to_handle_at() to
@@ -1227,8 +1232,8 @@  static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
 	 * objects. However, name_to_handle_at() requires that the
 	 * filesystem also supports decoding file handles.
 	 */
-	if (!path->dentry->d_sb->s_export_op ||
-	    !path->dentry->d_sb->s_export_op->fh_to_dentry)
+	if (!dentry->d_sb->s_export_op ||
+	    !dentry->d_sb->s_export_op->fh_to_dentry)
 		return -EOPNOTSUPP;
 
 	return 0;
@@ -1379,7 +1384,11 @@  static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
 	}
 
 	if (fid_mode) {
-		ret = fanotify_test_fid(&path, &__fsid);
+		ret = fanotify_test_fsid(path.dentry, &__fsid);
+		if (ret)
+			goto path_put_and_out;
+
+		ret = fanotify_test_fid(path.dentry);
 		if (ret)
 			goto path_put_and_out;