Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Amir Goldstein and committed by
Christian Brauner
21b32e6a 3d5cd491

+26
+26
include/linux/fs.h
··· 1671 1671 } 1672 1672 1673 1673 /** 1674 + * sb_write_not_started - check if SB_FREEZE_WRITE is not held 1675 + * @sb: the super we write to 1676 + * 1677 + * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 1678 + */ 1679 + static inline bool sb_write_not_started(const struct super_block *sb) 1680 + { 1681 + return __sb_write_started(sb, SB_FREEZE_WRITE) <= 0; 1682 + } 1683 + 1684 + /** 1674 1685 * file_write_started - check if SB_FREEZE_WRITE is held 1675 1686 * @file: the file we write to 1676 1687 * ··· 1694 1683 if (!S_ISREG(file_inode(file)->i_mode)) 1695 1684 return true; 1696 1685 return sb_write_started(file_inode(file)->i_sb); 1686 + } 1687 + 1688 + /** 1689 + * file_write_not_started - check if SB_FREEZE_WRITE is not held 1690 + * @file: the file we write to 1691 + * 1692 + * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 1693 + * May be false positive with !S_ISREG, because file_start_write() has 1694 + * no effect on !S_ISREG. 1695 + */ 1696 + static inline bool file_write_not_started(const struct file *file) 1697 + { 1698 + if (!S_ISREG(file_inode(file)->i_mode)) 1699 + return true; 1700 + return sb_write_not_started(file_inode(file)->i_sb); 1697 1701 } 1698 1702 1699 1703 /**