diff mbox series

[v2,14/16] fs: create __sb_write_started() helper

Message ID 20231122122715.2561213-15-amir73il@gmail.com (mailing list archive)
State New
Headers show
Series Tidy up file permission hooks | expand

Commit Message

Amir Goldstein Nov. 22, 2023, 12:27 p.m. UTC
Similar to sb_write_started() for use by other sb freeze levels.

Unlike the boolean sb_write_started(), this helper returns a tristate
to distiguish the cases of lockdep disabled or unknown lock state.

This is needed for fanotify "pre content" events.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 include/linux/fs.h | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Jan Kara Nov. 23, 2023, 5:31 p.m. UTC | #1
On Wed 22-11-23 14:27:13, Amir Goldstein wrote:
> Similar to sb_write_started() for use by other sb freeze levels.
> 
> Unlike the boolean sb_write_started(), this helper returns a tristate
> to distiguish the cases of lockdep disabled or unknown lock state.
> 
> This is needed for fanotify "pre content" events.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Looks good. Feel free to add:

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

								Honza

> ---
>  include/linux/fs.h | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 98b7a7a8c42e..e8aa48797bf4 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1645,9 +1645,22 @@ static inline bool __sb_start_write_trylock(struct super_block *sb, int level)
>  #define __sb_writers_release(sb, lev)	\
>  	percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_)
>  
> +/**
> + * __sb_write_started - check if sb freeze level is held
> + * @sb: the super we write to
> + *
> + * > 0 sb freeze level is held
> + *   0 sb freeze level is not held
> + * < 0 !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN
> + */
> +static inline int __sb_write_started(const struct super_block *sb, int level)
> +{
> +	return lockdep_is_held_type(sb->s_writers.rw_sem + level - 1, 1);
> +}
> +
>  static inline bool sb_write_started(const struct super_block *sb)
>  {
> -	return lockdep_is_held_type(sb->s_writers.rw_sem + SB_FREEZE_WRITE - 1, 1);
> +	return __sb_write_started(sb, SB_FREEZE_WRITE);
>  }
>  
>  /**
> -- 
> 2.34.1
>
Amir Goldstein Nov. 24, 2023, 9:14 a.m. UTC | #2
On Wed, Nov 22, 2023 at 2:27 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> Similar to sb_write_started() for use by other sb freeze levels.
>
> Unlike the boolean sb_write_started(), this helper returns a tristate
> to distiguish the cases of lockdep disabled or unknown lock state.
>
> This is needed for fanotify "pre content" events.
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  include/linux/fs.h | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 98b7a7a8c42e..e8aa48797bf4 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1645,9 +1645,22 @@ static inline bool __sb_start_write_trylock(struct super_block *sb, int level)
>  #define __sb_writers_release(sb, lev)  \
>         percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_)
>
> +/**
> + * __sb_write_started - check if sb freeze level is held
> + * @sb: the super we write to

Missing Kerneldoc of arg:
+ * @level: the freeze level

> + *
> + * > 0 sb freeze level is held
> + *   0 sb freeze level is not held
> + * < 0 !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN
> + */
> +static inline int __sb_write_started(const struct super_block *sb, int level)
> +{
> +       return lockdep_is_held_type(sb->s_writers.rw_sem + level - 1, 1);
> +}
> +
>  static inline bool sb_write_started(const struct super_block *sb)
>  {
> -       return lockdep_is_held_type(sb->s_writers.rw_sem + SB_FREEZE_WRITE - 1, 1);
> +       return __sb_write_started(sb, SB_FREEZE_WRITE);
>  }
>
>  /**
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 98b7a7a8c42e..e8aa48797bf4 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1645,9 +1645,22 @@  static inline bool __sb_start_write_trylock(struct super_block *sb, int level)
 #define __sb_writers_release(sb, lev)	\
 	percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_)
 
+/**
+ * __sb_write_started - check if sb freeze level is held
+ * @sb: the super we write to
+ *
+ * > 0 sb freeze level is held
+ *   0 sb freeze level is not held
+ * < 0 !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN
+ */
+static inline int __sb_write_started(const struct super_block *sb, int level)
+{
+	return lockdep_is_held_type(sb->s_writers.rw_sem + level - 1, 1);
+}
+
 static inline bool sb_write_started(const struct super_block *sb)
 {
-	return lockdep_is_held_type(sb->s_writers.rw_sem + SB_FREEZE_WRITE - 1, 1);
+	return __sb_write_started(sb, SB_FREEZE_WRITE);
 }
 
 /**