Skip to content

Commit f03359b

Browse files
committed
Merge tag 'for-6.9-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - set correct ram_bytes when splitting ordered extent. This can be inconsistent on-disk but harmless as it's not used for calculations and it's only advisory for compression - fix lockdep splat when taking cleaner mutex in qgroups disable ioctl - fix missing mutex unlock on error path when looking up sys chunk for relocation * tag 'for-6.9-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: set correct ram_bytes when splitting ordered extent btrfs: take the cleaner_mutex earlier in qgroup disable btrfs: add missing mutex_unlock in btrfs_relocate_sys_chunks()
2 parents da87c77 + 63a6ce5 commit f03359b

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

fs/btrfs/ioctl.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,23 +3758,50 @@ static long btrfs_ioctl_quota_ctl(struct file *file, void __user *arg)
37583758
goto drop_write;
37593759
}
37603760

3761-
down_write(&fs_info->subvol_sem);
3762-
37633761
switch (sa->cmd) {
37643762
case BTRFS_QUOTA_CTL_ENABLE:
37653763
case BTRFS_QUOTA_CTL_ENABLE_SIMPLE_QUOTA:
3764+
down_write(&fs_info->subvol_sem);
37663765
ret = btrfs_quota_enable(fs_info, sa);
3766+
up_write(&fs_info->subvol_sem);
37673767
break;
37683768
case BTRFS_QUOTA_CTL_DISABLE:
3769+
/*
3770+
* Lock the cleaner mutex to prevent races with concurrent
3771+
* relocation, because relocation may be building backrefs for
3772+
* blocks of the quota root while we are deleting the root. This
3773+
* is like dropping fs roots of deleted snapshots/subvolumes, we
3774+
* need the same protection.
3775+
*
3776+
* This also prevents races between concurrent tasks trying to
3777+
* disable quotas, because we will unlock and relock
3778+
* qgroup_ioctl_lock across BTRFS_FS_QUOTA_ENABLED changes.
3779+
*
3780+
* We take this here because we have the dependency of
3781+
*
3782+
* inode_lock -> subvol_sem
3783+
*
3784+
* because of rename. With relocation we can prealloc extents,
3785+
* so that makes the dependency chain
3786+
*
3787+
* cleaner_mutex -> inode_lock -> subvol_sem
3788+
*
3789+
* so we must take the cleaner_mutex here before we take the
3790+
* subvol_sem. The deadlock can't actually happen, but this
3791+
* quiets lockdep.
3792+
*/
3793+
mutex_lock(&fs_info->cleaner_mutex);
3794+
down_write(&fs_info->subvol_sem);
37693795
ret = btrfs_quota_disable(fs_info);
3796+
up_write(&fs_info->subvol_sem);
3797+
mutex_unlock(&fs_info->cleaner_mutex);
37703798
break;
37713799
default:
37723800
ret = -EINVAL;
37733801
break;
37743802
}
37753803

37763804
kfree(sa);
3777-
up_write(&fs_info->subvol_sem);
37783805
drop_write:
37793806
mnt_drop_write_file(file);
37803807
return ret;

fs/btrfs/ordered-data.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
11881188
ordered->disk_bytenr += len;
11891189
ordered->num_bytes -= len;
11901190
ordered->disk_num_bytes -= len;
1191+
ordered->ram_bytes -= len;
11911192

11921193
if (test_bit(BTRFS_ORDERED_IO_DONE, &ordered->flags)) {
11931194
ASSERT(ordered->bytes_left == 0);

fs/btrfs/qgroup.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,16 +1342,10 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
13421342
lockdep_assert_held_write(&fs_info->subvol_sem);
13431343

13441344
/*
1345-
* Lock the cleaner mutex to prevent races with concurrent relocation,
1346-
* because relocation may be building backrefs for blocks of the quota
1347-
* root while we are deleting the root. This is like dropping fs roots
1348-
* of deleted snapshots/subvolumes, we need the same protection.
1349-
*
1350-
* This also prevents races between concurrent tasks trying to disable
1351-
* quotas, because we will unlock and relock qgroup_ioctl_lock across
1352-
* BTRFS_FS_QUOTA_ENABLED changes.
1345+
* Relocation will mess with backrefs, so make sure we have the
1346+
* cleaner_mutex held to protect us from relocate.
13531347
*/
1354-
mutex_lock(&fs_info->cleaner_mutex);
1348+
lockdep_assert_held(&fs_info->cleaner_mutex);
13551349

13561350
mutex_lock(&fs_info->qgroup_ioctl_lock);
13571351
if (!fs_info->quota_root)
@@ -1373,9 +1367,13 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
13731367
clear_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);
13741368
btrfs_qgroup_wait_for_completion(fs_info, false);
13751369

1370+
/*
1371+
* We have nothing held here and no trans handle, just return the error
1372+
* if there is one.
1373+
*/
13761374
ret = flush_reservations(fs_info);
13771375
if (ret)
1378-
goto out_unlock_cleaner;
1376+
return ret;
13791377

13801378
/*
13811379
* 1 For the root item
@@ -1439,9 +1437,6 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
14391437
btrfs_end_transaction(trans);
14401438
else if (trans)
14411439
ret = btrfs_commit_transaction(trans);
1442-
out_unlock_cleaner:
1443-
mutex_unlock(&fs_info->cleaner_mutex);
1444-
14451440
return ret;
14461441
}
14471442

fs/btrfs/volumes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,6 +3455,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
34553455
* alignment and size).
34563456
*/
34573457
ret = -EUCLEAN;
3458+
mutex_unlock(&fs_info->reclaim_bgs_lock);
34583459
goto error;
34593460
}
34603461

0 commit comments

Comments
 (0)