summaryrefslogtreecommitdiff
path: root/include/linux/fs.h
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2023-11-22 14:27:15 +0200
committerChristian Brauner <brauner@kernel.org>2023-11-24 10:39:19 +0100
commit21b32e6a0ab5b174fa1ca2fb4c212577cf405d83 (patch)
treedeb60a18c0741ab4460fe2f15d7baafb4c7d2102 /include/linux/fs.h
parent3d5cd4911e04683df8f4439fddd788e00a2510a8 (diff)
fs: create {sb,file}_write_not_started() helpers
Create new helpers {sb,file}_write_not_started() that can be used to assert that sb_start_write() is not held. This is needed for fanotify "pre content" events. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Link: https://lore.kernel.org/r/20231122122715.2561213-17-amir73il@gmail.com Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r--include/linux/fs.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 75a10b632edd..ae0e2fb7bcea 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1671,6 +1671,17 @@ static inline bool sb_write_started(const struct super_block *sb)
}
/**
+ * sb_write_not_started - check if SB_FREEZE_WRITE is not held
+ * @sb: the super we write to
+ *
+ * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN.
+ */
+static inline bool sb_write_not_started(const struct super_block *sb)
+{
+ return __sb_write_started(sb, SB_FREEZE_WRITE) <= 0;
+}
+
+/**
* file_write_started - check if SB_FREEZE_WRITE is held
* @file: the file we write to
*
@@ -1686,6 +1697,21 @@ static inline bool file_write_started(const struct file *file)
}
/**
+ * file_write_not_started - check if SB_FREEZE_WRITE is not held
+ * @file: the file we write to
+ *
+ * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN.
+ * May be false positive with !S_ISREG, because file_start_write() has
+ * no effect on !S_ISREG.
+ */
+static inline bool file_write_not_started(const struct file *file)
+{
+ if (!S_ISREG(file_inode(file)->i_mode))
+ return true;
+ return sb_write_not_started(file_inode(file)->i_sb);
+}
+
+/**
* sb_end_write - drop write access to a superblock
* @sb: the super we wrote to
*