2021-10-15 01:18:45

by Gabriel Krisman Bertazi

[permalink] [raw]
Subject: [PATCH v7 10/28] fsnotify: Retrieve super block from the data field

Some file system events (i.e. FS_ERROR) might not be associated with an
inode or directory. For these, we can retrieve the super block from the
data field. But, since the super_block is available in the data field
on every event type, simplify the code to always retrieve it from there,
through a new helper.

Suggested-by: Jan Kara <[email protected]>
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

--
Changes since v6:
- Always use data field for superblock retrieval
Changes since v5:
- add fsnotify_data_sb handle to retrieve sb from the data field. (jan)
---
fs/notify/fsnotify.c | 7 +++----
include/linux/fsnotify_backend.h | 15 +++++++++++++++
2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 963e6ce75b96..fde3a1115a17 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -455,16 +455,16 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)
* @file_name is relative to
* @file_name: optional file name associated with event
* @inode: optional inode associated with event -
- * either @dir or @inode must be non-NULL.
- * if both are non-NULL event may be reported to both.
+ * If @dir and @inode are both non-NULL, event may be
+ * reported to both.
* @cookie: inotify rename cookie
*/
int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
const struct qstr *file_name, struct inode *inode, u32 cookie)
{
const struct path *path = fsnotify_data_path(data, data_type);
+ struct super_block *sb = fsnotify_data_sb(data, data_type);
struct fsnotify_iter_info iter_info = {};
- struct super_block *sb;
struct mount *mnt = NULL;
struct inode *parent = NULL;
int ret = 0;
@@ -483,7 +483,6 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
*/
parent = dir;
}
- sb = inode->i_sb;

/*
* Optimization: srcu_read_lock() has a memory barrier which can
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index b323d0c4b967..035438fe4a43 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -289,6 +289,21 @@ static inline const struct path *fsnotify_data_path(const void *data,
}
}

+static inline struct super_block *fsnotify_data_sb(const void *data,
+ int data_type)
+{
+ switch (data_type) {
+ case FSNOTIFY_EVENT_INODE:
+ return ((struct inode *)data)->i_sb;
+ case FSNOTIFY_EVENT_DENTRY:
+ return ((struct dentry *)data)->d_sb;
+ case FSNOTIFY_EVENT_PATH:
+ return ((const struct path *)data)->dentry->d_sb;
+ default:
+ return NULL;
+ }
+}
+
enum fsnotify_obj_type {
FSNOTIFY_OBJ_TYPE_INODE,
FSNOTIFY_OBJ_TYPE_PARENT,
--
2.33.0


2021-10-15 08:23:46

by Amir Goldstein

[permalink] [raw]
Subject: Re: [PATCH v7 10/28] fsnotify: Retrieve super block from the data field

On Fri, Oct 15, 2021 at 12:38 AM Gabriel Krisman Bertazi
<[email protected]> wrote:
>
> Some file system events (i.e. FS_ERROR) might not be associated with an
> inode or directory. For these, we can retrieve the super block from the
> data field. But, since the super_block is available in the data field
> on every event type, simplify the code to always retrieve it from there,
> through a new helper.
>
> Suggested-by: Jan Kara <[email protected]>
> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
Reviewed-by: Amir Goldstein <[email protected]>

>
> --
> Changes since v6:
> - Always use data field for superblock retrieval
> Changes since v5:
> - add fsnotify_data_sb handle to retrieve sb from the data field. (jan)
> ---
> fs/notify/fsnotify.c | 7 +++----
> include/linux/fsnotify_backend.h | 15 +++++++++++++++
> 2 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
> index 963e6ce75b96..fde3a1115a17 100644
> --- a/fs/notify/fsnotify.c
> +++ b/fs/notify/fsnotify.c
> @@ -455,16 +455,16 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)
> * @file_name is relative to
> * @file_name: optional file name associated with event
> * @inode: optional inode associated with event -
> - * either @dir or @inode must be non-NULL.
> - * if both are non-NULL event may be reported to both.
> + * If @dir and @inode are both non-NULL, event may be
> + * reported to both.
> * @cookie: inotify rename cookie
> */
> int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
> const struct qstr *file_name, struct inode *inode, u32 cookie)
> {
> const struct path *path = fsnotify_data_path(data, data_type);
> + struct super_block *sb = fsnotify_data_sb(data, data_type);
> struct fsnotify_iter_info iter_info = {};
> - struct super_block *sb;
> struct mount *mnt = NULL;
> struct inode *parent = NULL;
> int ret = 0;
> @@ -483,7 +483,6 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
> */
> parent = dir;
> }
> - sb = inode->i_sb;
>
> /*
> * Optimization: srcu_read_lock() has a memory barrier which can
> diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
> index b323d0c4b967..035438fe4a43 100644
> --- a/include/linux/fsnotify_backend.h
> +++ b/include/linux/fsnotify_backend.h
> @@ -289,6 +289,21 @@ static inline const struct path *fsnotify_data_path(const void *data,
> }
> }
>
> +static inline struct super_block *fsnotify_data_sb(const void *data,
> + int data_type)
> +{
> + switch (data_type) {
> + case FSNOTIFY_EVENT_INODE:
> + return ((struct inode *)data)->i_sb;
> + case FSNOTIFY_EVENT_DENTRY:
> + return ((struct dentry *)data)->d_sb;
> + case FSNOTIFY_EVENT_PATH:
> + return ((const struct path *)data)->dentry->d_sb;
> + default:
> + return NULL;
> + }
> +}
> +
> enum fsnotify_obj_type {
> FSNOTIFY_OBJ_TYPE_INODE,
> FSNOTIFY_OBJ_TYPE_PARENT,
> --
> 2.33.0
>

2021-10-15 16:15:17

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH v7 10/28] fsnotify: Retrieve super block from the data field

On Thu 14-10-21 18:36:28, Gabriel Krisman Bertazi wrote:
> Some file system events (i.e. FS_ERROR) might not be associated with an
> inode or directory. For these, we can retrieve the super block from the
> data field. But, since the super_block is available in the data field
> on every event type, simplify the code to always retrieve it from there,
> through a new helper.
>
> Suggested-by: Jan Kara <[email protected]>
> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <[email protected]>

Honza

>
> --
> Changes since v6:
> - Always use data field for superblock retrieval
> Changes since v5:
> - add fsnotify_data_sb handle to retrieve sb from the data field. (jan)
> ---
> fs/notify/fsnotify.c | 7 +++----
> include/linux/fsnotify_backend.h | 15 +++++++++++++++
> 2 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
> index 963e6ce75b96..fde3a1115a17 100644
> --- a/fs/notify/fsnotify.c
> +++ b/fs/notify/fsnotify.c
> @@ -455,16 +455,16 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)
> * @file_name is relative to
> * @file_name: optional file name associated with event
> * @inode: optional inode associated with event -
> - * either @dir or @inode must be non-NULL.
> - * if both are non-NULL event may be reported to both.
> + * If @dir and @inode are both non-NULL, event may be
> + * reported to both.
> * @cookie: inotify rename cookie
> */
> int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
> const struct qstr *file_name, struct inode *inode, u32 cookie)
> {
> const struct path *path = fsnotify_data_path(data, data_type);
> + struct super_block *sb = fsnotify_data_sb(data, data_type);
> struct fsnotify_iter_info iter_info = {};
> - struct super_block *sb;
> struct mount *mnt = NULL;
> struct inode *parent = NULL;
> int ret = 0;
> @@ -483,7 +483,6 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
> */
> parent = dir;
> }
> - sb = inode->i_sb;
>
> /*
> * Optimization: srcu_read_lock() has a memory barrier which can
> diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
> index b323d0c4b967..035438fe4a43 100644
> --- a/include/linux/fsnotify_backend.h
> +++ b/include/linux/fsnotify_backend.h
> @@ -289,6 +289,21 @@ static inline const struct path *fsnotify_data_path(const void *data,
> }
> }
>
> +static inline struct super_block *fsnotify_data_sb(const void *data,
> + int data_type)
> +{
> + switch (data_type) {
> + case FSNOTIFY_EVENT_INODE:
> + return ((struct inode *)data)->i_sb;
> + case FSNOTIFY_EVENT_DENTRY:
> + return ((struct dentry *)data)->d_sb;
> + case FSNOTIFY_EVENT_PATH:
> + return ((const struct path *)data)->dentry->d_sb;
> + default:
> + return NULL;
> + }
> +}
> +
> enum fsnotify_obj_type {
> FSNOTIFY_OBJ_TYPE_INODE,
> FSNOTIFY_OBJ_TYPE_PARENT,
> --
> 2.33.0
>
--
Jan Kara <[email protected]>
SUSE Labs, CR