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

Merge tag 'vfs-6.19-rc1.guards' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull superblock lock guard updates from Christian Brauner:
"This starts the work of introducing guards for superblock related
locks.

Introduce super_write_guard for scoped superblock write protection.

This provides a guard-based alternative to the manual sb_start_write()
and sb_end_write() pattern, allowing the compiler to automatically
handle the cleanup"

* tag 'vfs-6.19-rc1.guards' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
xfs: use super write guard in xfs_file_ioctl()
open: use super write guard in do_ftruncate()
btrfs: use super write guard in relocating_repair_kthread()
ext4: use super write guard in write_mmp_block()
btrfs: use super write guard in sb_start_write()
btrfs: use super write guard btrfs_run_defrag_inode()
btrfs: use super write guard in btrfs_reclaim_bgs_work()
fs: add super_write_guard

+22 -32
+3 -7
fs/btrfs/block-group.c
··· 1850 1850 if (!btrfs_should_reclaim(fs_info)) 1851 1851 return; 1852 1852 1853 - sb_start_write(fs_info->sb); 1853 + guard(super_write)(fs_info->sb); 1854 1854 1855 - if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) { 1856 - sb_end_write(fs_info->sb); 1855 + if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) 1857 1856 return; 1858 - } 1859 1857 1860 1858 /* 1861 1859 * Long running balances can keep us blocked here for eternity, so ··· 1861 1863 */ 1862 1864 if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) { 1863 1865 btrfs_exclop_finish(fs_info); 1864 - sb_end_write(fs_info->sb); 1865 1866 return; 1866 1867 } 1867 1868 ··· 1944 1947 /* 1945 1948 * Get out fast, in case we're read-only or unmounting the 1946 1949 * filesystem. It is OK to drop block groups from the list even 1947 - * for the read-only case. As we did sb_start_write(), 1950 + * for the read-only case. As we did take the super write lock, 1948 1951 * "mount -o remount,ro" won't happen and read-only filesystem 1949 1952 * means it is forced read-only due to a fatal error. So, it 1950 1953 * never gets back to read-write to let us reclaim again. ··· 2027 2030 list_splice_tail(&retry_list, &fs_info->reclaim_bgs); 2028 2031 spin_unlock(&fs_info->unused_bgs_lock); 2029 2032 btrfs_exclop_finish(fs_info); 2030 - sb_end_write(fs_info->sb); 2031 2033 } 2032 2034 2033 2035 void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info)
+3 -4
fs/btrfs/defrag.c
··· 254 254 range.extent_thresh = defrag->extent_thresh; 255 255 file_ra_state_init(ra, inode->vfs_inode.i_mapping); 256 256 257 - sb_start_write(fs_info->sb); 258 - ret = btrfs_defrag_file(inode, ra, &range, defrag->transid, 259 - BTRFS_DEFRAG_BATCH); 260 - sb_end_write(fs_info->sb); 257 + scoped_guard(super_write, fs_info->sb) 258 + ret = btrfs_defrag_file(inode, ra, &range, 259 + defrag->transid, BTRFS_DEFRAG_BATCH); 261 260 iput(&inode->vfs_inode); 262 261 263 262 if (ret < 0)
+4 -5
fs/btrfs/volumes.c
··· 4657 4657 struct btrfs_fs_info *fs_info = data; 4658 4658 int ret = 0; 4659 4659 4660 - sb_start_write(fs_info->sb); 4660 + guard(super_write)(fs_info->sb); 4661 + 4661 4662 mutex_lock(&fs_info->balance_mutex); 4662 4663 if (fs_info->balance_ctl) 4663 4664 ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL); 4664 4665 mutex_unlock(&fs_info->balance_mutex); 4665 - sb_end_write(fs_info->sb); 4666 4666 4667 4667 return ret; 4668 4668 } ··· 8174 8174 target = cache->start; 8175 8175 btrfs_put_block_group(cache); 8176 8176 8177 - sb_start_write(fs_info->sb); 8177 + guard(super_write)(fs_info->sb); 8178 + 8178 8179 if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) { 8179 8180 btrfs_info(fs_info, 8180 8181 "zoned: skip relocating block group %llu to repair: EBUSY", 8181 8182 target); 8182 - sb_end_write(fs_info->sb); 8183 8183 return -EBUSY; 8184 8184 } 8185 8185 ··· 8207 8207 btrfs_put_block_group(cache); 8208 8208 mutex_unlock(&fs_info->reclaim_bgs_lock); 8209 8209 btrfs_exclop_finish(fs_info); 8210 - sb_end_write(fs_info->sb); 8211 8210 8212 8211 return ret; 8213 8212 }
+2 -6
fs/ext4/mmp.c
··· 57 57 58 58 static int write_mmp_block(struct super_block *sb, struct buffer_head *bh) 59 59 { 60 - int err; 61 - 62 60 /* 63 61 * We protect against freezing so that we don't create dirty buffers 64 62 * on frozen filesystem. 65 63 */ 66 - sb_start_write(sb); 67 - err = write_mmp_block_thawed(sb, bh); 68 - sb_end_write(sb); 69 - return err; 64 + scoped_guard(super_write, sb) 65 + return write_mmp_block_thawed(sb, bh); 70 66 } 71 67 72 68 /*
+3 -6
fs/open.c
··· 191 191 if (error) 192 192 return error; 193 193 194 - sb_start_write(inode->i_sb); 195 - error = do_truncate(file_mnt_idmap(file), dentry, length, 196 - ATTR_MTIME | ATTR_CTIME, file); 197 - sb_end_write(inode->i_sb); 198 - 199 - return error; 194 + scoped_guard(super_write, inode->i_sb) 195 + return do_truncate(file_mnt_idmap(file), dentry, length, 196 + ATTR_MTIME | ATTR_CTIME, file); 200 197 } 201 198 202 199 int do_sys_ftruncate(unsigned int fd, loff_t length, int small)
+2 -4
fs/xfs/xfs_ioctl.c
··· 1408 1408 1409 1409 trace_xfs_ioc_free_eofblocks(mp, &icw, _RET_IP_); 1410 1410 1411 - sb_start_write(mp->m_super); 1412 - error = xfs_blockgc_free_space(mp, &icw); 1413 - sb_end_write(mp->m_super); 1414 - return error; 1411 + guard(super_write)(mp->m_super); 1412 + return xfs_blockgc_free_space(mp, &icw); 1415 1413 } 1416 1414 1417 1415 case XFS_IOC_EXCHANGE_RANGE:
+5
include/linux/fs/super.h
··· 125 125 __sb_start_write(sb, SB_FREEZE_WRITE); 126 126 } 127 127 128 + DEFINE_GUARD(super_write, 129 + struct super_block *, 130 + sb_start_write(_T), 131 + sb_end_write(_T)) 132 + 128 133 static inline bool sb_start_write_trylock(struct super_block *sb) 129 134 { 130 135 return __sb_start_write_trylock(sb, SB_FREEZE_WRITE);