Skip to content

Commit b7bbc6e

Browse files
fdmananakdave
authored andcommitted
btrfs: qgroup: fix qgroup create ioctl returning success after quotas disabled
When quotas are disabled qgroup ioctls are supposed to return -ENOTCONN, but the qgroup create ioctl stopped doing that when it races with a quota disable operation, returning 0 instead. This change of behaviour happened in commit 6ed0564 ("btrfs: create qgroup earlier in snapshot creation"). The issue happens as follows: 1) Task A enters btrfs_ioctl_qgroup_create(), qgroups are enabled and so qgroup_enabled() returns true since fs_info->quota_root is not NULL; 2) Task B enters btrfs_ioctl_quota_ctl() -> btrfs_quota_disable() and disables qgroups, so now fs_info->quota_root is NULL; 3) Task A enters btrfs_create_qgroup() and calls btrfs_qgroup_mode(), which returns BTRFS_QGROUP_MODE_DISABLED since quotas are disabled, and then btrfs_create_qgroup() returns 0 to the caller, which makes the ioctl return 0 instead of -ENOTCONN. The check for fs_info->quota_root and returning -ENOTCONN if it's NULL is made only after the call btrfs_qgroup_mode(). Fix this by moving the check for disabled quotas with btrfs_qgroup_mode() into transaction.c:create_pending_snapshot(), so that we don't abort the transaction if btrfs_create_qgroup() returns -ENOTCONN and quotas are disabled. Fixes: 6ed0564 ("btrfs: create qgroup earlier in snapshot creation") Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 7229d54 commit b7bbc6e

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

fs/btrfs/qgroup.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,9 +1662,6 @@ int btrfs_create_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
16621662
struct btrfs_qgroup *prealloc = NULL;
16631663
int ret = 0;
16641664

1665-
if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_DISABLED)
1666-
return 0;
1667-
16681665
mutex_lock(&fs_info->qgroup_ioctl_lock);
16691666
if (!fs_info->quota_root) {
16701667
ret = -ENOTCONN;

fs/btrfs/transaction.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
17351735

17361736
ret = btrfs_create_qgroup(trans, objectid);
17371737
if (ret && ret != -EEXIST) {
1738-
btrfs_abort_transaction(trans, ret);
1739-
goto fail;
1738+
if (ret != -ENOTCONN || btrfs_qgroup_enabled(fs_info)) {
1739+
btrfs_abort_transaction(trans, ret);
1740+
goto fail;
1741+
}
17401742
}
17411743

17421744
/*

0 commit comments

Comments
 (0)