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 file_write_started() helper

Convenience wrapper for sb_write_started(file_inode(inode)->i_sb)), which
has a single occurrence in the code right now.

Document the false negatives of those helpers, which makes them unusable
to assert that sb_start_write() is not held.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/r/20231122122715.2561213-16-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
3d5cd491 8802e580

+22 -1
+1 -1
fs/read_write.c
··· 1423 1423 struct file *file_out, loff_t pos_out, 1424 1424 size_t len, unsigned int flags) 1425 1425 { 1426 - lockdep_assert(sb_write_started(file_inode(file_out)->i_sb)); 1426 + lockdep_assert(file_write_started(file_out)); 1427 1427 1428 1428 return do_splice_direct(file_in, &pos_in, file_out, &pos_out, 1429 1429 len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0);
+21
include/linux/fs.h
··· 1659 1659 return lockdep_is_held_type(sb->s_writers.rw_sem + level - 1, 1); 1660 1660 } 1661 1661 1662 + /** 1663 + * sb_write_started - check if SB_FREEZE_WRITE is held 1664 + * @sb: the super we write to 1665 + * 1666 + * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 1667 + */ 1662 1668 static inline bool sb_write_started(const struct super_block *sb) 1663 1669 { 1664 1670 return __sb_write_started(sb, SB_FREEZE_WRITE); 1671 + } 1672 + 1673 + /** 1674 + * file_write_started - check if SB_FREEZE_WRITE is held 1675 + * @file: the file we write to 1676 + * 1677 + * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 1678 + * May be false positive with !S_ISREG, because file_start_write() has 1679 + * no effect on !S_ISREG. 1680 + */ 1681 + static inline bool file_write_started(const struct file *file) 1682 + { 1683 + if (!S_ISREG(file_inode(file)->i_mode)) 1684 + return true; 1685 + return sb_write_started(file_inode(file)->i_sb); 1665 1686 } 1666 1687 1667 1688 /**