mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
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
This commit is contained in:
@@ -1850,12 +1850,10 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
|
|||||||
if (!btrfs_should_reclaim(fs_info))
|
if (!btrfs_should_reclaim(fs_info))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sb_start_write(fs_info->sb);
|
guard(super_write)(fs_info->sb);
|
||||||
|
|
||||||
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
|
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE))
|
||||||
sb_end_write(fs_info->sb);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Long running balances can keep us blocked here for eternity, so
|
* Long running balances can keep us blocked here for eternity, so
|
||||||
@@ -1863,7 +1861,6 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
|
|||||||
*/
|
*/
|
||||||
if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) {
|
if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) {
|
||||||
btrfs_exclop_finish(fs_info);
|
btrfs_exclop_finish(fs_info);
|
||||||
sb_end_write(fs_info->sb);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1947,7 +1944,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
|
|||||||
/*
|
/*
|
||||||
* Get out fast, in case we're read-only or unmounting the
|
* Get out fast, in case we're read-only or unmounting the
|
||||||
* filesystem. It is OK to drop block groups from the list even
|
* filesystem. It is OK to drop block groups from the list even
|
||||||
* for the read-only case. As we did sb_start_write(),
|
* for the read-only case. As we did take the super write lock,
|
||||||
* "mount -o remount,ro" won't happen and read-only filesystem
|
* "mount -o remount,ro" won't happen and read-only filesystem
|
||||||
* means it is forced read-only due to a fatal error. So, it
|
* means it is forced read-only due to a fatal error. So, it
|
||||||
* never gets back to read-write to let us reclaim again.
|
* never gets back to read-write to let us reclaim again.
|
||||||
@@ -2030,7 +2027,6 @@ end:
|
|||||||
list_splice_tail(&retry_list, &fs_info->reclaim_bgs);
|
list_splice_tail(&retry_list, &fs_info->reclaim_bgs);
|
||||||
spin_unlock(&fs_info->unused_bgs_lock);
|
spin_unlock(&fs_info->unused_bgs_lock);
|
||||||
btrfs_exclop_finish(fs_info);
|
btrfs_exclop_finish(fs_info);
|
||||||
sb_end_write(fs_info->sb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info)
|
void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info)
|
||||||
|
|||||||
@@ -254,10 +254,9 @@ again:
|
|||||||
range.extent_thresh = defrag->extent_thresh;
|
range.extent_thresh = defrag->extent_thresh;
|
||||||
file_ra_state_init(ra, inode->vfs_inode.i_mapping);
|
file_ra_state_init(ra, inode->vfs_inode.i_mapping);
|
||||||
|
|
||||||
sb_start_write(fs_info->sb);
|
scoped_guard(super_write, fs_info->sb)
|
||||||
ret = btrfs_defrag_file(inode, ra, &range, defrag->transid,
|
ret = btrfs_defrag_file(inode, ra, &range,
|
||||||
BTRFS_DEFRAG_BATCH);
|
defrag->transid, BTRFS_DEFRAG_BATCH);
|
||||||
sb_end_write(fs_info->sb);
|
|
||||||
iput(&inode->vfs_inode);
|
iput(&inode->vfs_inode);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|||||||
@@ -4657,12 +4657,12 @@ static int balance_kthread(void *data)
|
|||||||
struct btrfs_fs_info *fs_info = data;
|
struct btrfs_fs_info *fs_info = data;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
sb_start_write(fs_info->sb);
|
guard(super_write)(fs_info->sb);
|
||||||
|
|
||||||
mutex_lock(&fs_info->balance_mutex);
|
mutex_lock(&fs_info->balance_mutex);
|
||||||
if (fs_info->balance_ctl)
|
if (fs_info->balance_ctl)
|
||||||
ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL);
|
ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL);
|
||||||
mutex_unlock(&fs_info->balance_mutex);
|
mutex_unlock(&fs_info->balance_mutex);
|
||||||
sb_end_write(fs_info->sb);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -8174,12 +8174,12 @@ static int relocating_repair_kthread(void *data)
|
|||||||
target = cache->start;
|
target = cache->start;
|
||||||
btrfs_put_block_group(cache);
|
btrfs_put_block_group(cache);
|
||||||
|
|
||||||
sb_start_write(fs_info->sb);
|
guard(super_write)(fs_info->sb);
|
||||||
|
|
||||||
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
|
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
|
||||||
btrfs_info(fs_info,
|
btrfs_info(fs_info,
|
||||||
"zoned: skip relocating block group %llu to repair: EBUSY",
|
"zoned: skip relocating block group %llu to repair: EBUSY",
|
||||||
target);
|
target);
|
||||||
sb_end_write(fs_info->sb);
|
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8207,7 +8207,6 @@ out:
|
|||||||
btrfs_put_block_group(cache);
|
btrfs_put_block_group(cache);
|
||||||
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
||||||
btrfs_exclop_finish(fs_info);
|
btrfs_exclop_finish(fs_info);
|
||||||
sb_end_write(fs_info->sb);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,16 +57,12 @@ static int write_mmp_block_thawed(struct super_block *sb,
|
|||||||
|
|
||||||
static int write_mmp_block(struct super_block *sb, struct buffer_head *bh)
|
static int write_mmp_block(struct super_block *sb, struct buffer_head *bh)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We protect against freezing so that we don't create dirty buffers
|
* We protect against freezing so that we don't create dirty buffers
|
||||||
* on frozen filesystem.
|
* on frozen filesystem.
|
||||||
*/
|
*/
|
||||||
sb_start_write(sb);
|
scoped_guard(super_write, sb)
|
||||||
err = write_mmp_block_thawed(sb, bh);
|
return write_mmp_block_thawed(sb, bh);
|
||||||
sb_end_write(sb);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -191,12 +191,9 @@ int do_ftruncate(struct file *file, loff_t length, int small)
|
|||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
sb_start_write(inode->i_sb);
|
scoped_guard(super_write, inode->i_sb)
|
||||||
error = do_truncate(file_mnt_idmap(file), dentry, length,
|
return do_truncate(file_mnt_idmap(file), dentry, length,
|
||||||
ATTR_MTIME | ATTR_CTIME, file);
|
ATTR_MTIME | ATTR_CTIME, file);
|
||||||
sb_end_write(inode->i_sb);
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_sys_ftruncate(unsigned int fd, loff_t length, int small)
|
int do_sys_ftruncate(unsigned int fd, loff_t length, int small)
|
||||||
|
|||||||
@@ -1408,10 +1408,8 @@ xfs_file_ioctl(
|
|||||||
|
|
||||||
trace_xfs_ioc_free_eofblocks(mp, &icw, _RET_IP_);
|
trace_xfs_ioc_free_eofblocks(mp, &icw, _RET_IP_);
|
||||||
|
|
||||||
sb_start_write(mp->m_super);
|
guard(super_write)(mp->m_super);
|
||||||
error = xfs_blockgc_free_space(mp, &icw);
|
return xfs_blockgc_free_space(mp, &icw);
|
||||||
sb_end_write(mp->m_super);
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case XFS_IOC_EXCHANGE_RANGE:
|
case XFS_IOC_EXCHANGE_RANGE:
|
||||||
|
|||||||
@@ -125,6 +125,11 @@ static inline void sb_start_write(struct super_block *sb)
|
|||||||
__sb_start_write(sb, SB_FREEZE_WRITE);
|
__sb_start_write(sb, SB_FREEZE_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_GUARD(super_write,
|
||||||
|
struct super_block *,
|
||||||
|
sb_start_write(_T),
|
||||||
|
sb_end_write(_T))
|
||||||
|
|
||||||
static inline bool sb_start_write_trylock(struct super_block *sb)
|
static inline bool sb_start_write_trylock(struct super_block *sb)
|
||||||
{
|
{
|
||||||
return __sb_start_write_trylock(sb, SB_FREEZE_WRITE);
|
return __sb_start_write_trylock(sb, SB_FREEZE_WRITE);
|
||||||
|
|||||||
Reference in New Issue
Block a user