btrfs: remove BTRFS_FS_QUOTA_DISABLING flag
PATCH 1/1 btrfs: remove BTRFS_FS_QUOTA_DISABLING flag
Currently, "btrfs quota enable" would fail after "btrfs quota disable" on the first time with syslog output "qgroup_rescan_init failed with -22", but it would succeed on the second time.
When "quota disable" is called, BTRFS_FS_QUOTA_DISABLING flag bit will be set in fs_info->flags in btrfs_quota_disable(), but it will not be droppd in btrfs_run_qgroups() (which is called in btrfs_commit_transaction()) because quota_root has already been freed. If "quota enable" is called after that, both BTRFS_FS_QUOTA_DISABLING and BTRFS_FS_QUOTA_ENABLED flag would be dropped in the btrfs_run_qgroups() since quota_root is not NULL. This leads to the failure of "quota enable" on the first time.
BTRFS_FS_QUOTA_DISABLING flag is not used outside of "quota disable" context and is equivalent to whether quota_root is NULL or not. btrfs_run_qgroups() checks whether quota_root is NULL or not in the first place.
So, let's remove BTRFS_FS_QUOTA_DISABLING flag.
--- fs/btrfs/ctree.h | 1 - fs/btrfs/qgroup.c | 4 ---- 2 files changed, 5 deletions(-)
fs/btrfs/ctree.h +0 -1
@@ -709,7 +709,6 @@ struct btrfs_delayed_root;#define BTRFS_FS_OPEN 5#define BTRFS_FS_QUOTA_ENABLED 6#define BTRFS_FS_QUOTA_ENABLING 7 -#define BTRFS_FS_QUOTA_DISABLING 8#define BTRFS_FS_UPDATE_UUID_TREE_GEN 9#define BTRFS_FS_CREATING_FREE_SPACE_TREE 10#define BTRFS_FS_BTREE_ERR 11
fs/btrfs/qgroup.c +0 -4
@@ -807,7 +807,6 @@ static int btrfs_clean_quota_tree(struct btrfs_trans_handle *trans, } ret =0 ; out: -set_bit (BTRFS_FS_QUOTA_DISABLING , &root->fs_info->flags);btrfs_free_path (path);return ret; }
@@ -954,7 +953,6 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,if (!fs_info->quota_root) goto out;clear_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags); -set_bit (BTRFS_FS_QUOTA_DISABLING , &fs_info->flags);btrfs_qgroup_wait_for_completion (fs_info, false);spin_lock (&fs_info->qgroup_lock); quota_root = fs_info->quota_root;
@@ -2087,8 +2085,6 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans,if (test_and_clear_bit (BTRFS_FS_QUOTA_ENABLING , &fs_info->flags))set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags); -if (test_and_clear_bit (BTRFS_FS_QUOTA_DISABLING , &fs_info->flags)) -clear_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_lock (&fs_info->qgroup_lock);while (!list_empty (&fs_info->dirty_qgroups)) {
Signature · 1 line
2.9.5
PATCH 1/1 btrfs: remove BTRFS_FS_QUOTA_DISABLING flag
Hello,
Does anyone have a comment on this?
Regards, Tomohiro
-------- Forwarded Message --------
Subject: [PATCH] btrfs: remove BTRFS_FS_QUOTA_DISABLING flag
Date: Wed, 30 Aug 2017 16:33:16 +0900
From: Misono, Tomohiro <[email protected]>
To: [email protected]
Currently, "btrfs quota enable" would fail after "btrfs quota disable" on the first time with syslog output "qgroup_rescan_init failed with -22", but it would succeed on the second time.
When "quota disable" is called, BTRFS_FS_QUOTA_DISABLING flag bit will be set in fs_info->flags in btrfs_quota_disable(), but it will not be droppd in btrfs_run_qgroups() (which is called in btrfs_commit_transaction()) because quota_root has already been freed. If "quota enable" is called after that, both BTRFS_FS_QUOTA_DISABLING and BTRFS_FS_QUOTA_ENABLED flag would be dropped in the btrfs_run_qgroups() since quota_root is not NULL. This leads to the failure of "quota enable" on the first time.
BTRFS_FS_QUOTA_DISABLING flag is not used outside of "quota disable" context and is equivalent to whether quota_root is NULL or not. btrfs_run_qgroups() checks whether quota_root is NULL or not in the first place.
So, let's remove BTRFS_FS_QUOTA_DISABLING flag.
--- fs/btrfs/ctree.h | 1 - fs/btrfs/qgroup.c | 4 ---- 2 files changed, 5 deletions(-)
fs/btrfs/ctree.h +0 -1
@@ -709,7 +709,6 @@ struct btrfs_delayed_root;#define BTRFS_FS_OPEN 5#define BTRFS_FS_QUOTA_ENABLED 6#define BTRFS_FS_QUOTA_ENABLING 7 -#define BTRFS_FS_QUOTA_DISABLING 8#define BTRFS_FS_UPDATE_UUID_TREE_GEN 9#define BTRFS_FS_CREATING_FREE_SPACE_TREE 10#define BTRFS_FS_BTREE_ERR 11
fs/btrfs/qgroup.c +0 -4
@@ -807,7 +807,6 @@ static int btrfs_clean_quota_tree(struct btrfs_trans_handle *trans, } ret =0 ; out: -set_bit (BTRFS_FS_QUOTA_DISABLING , &root->fs_info->flags);btrfs_free_path (path);return ret; }
@@ -954,7 +953,6 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,if (!fs_info->quota_root) goto out;clear_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags); -set_bit (BTRFS_FS_QUOTA_DISABLING , &fs_info->flags);btrfs_qgroup_wait_for_completion (fs_info, false);spin_lock (&fs_info->qgroup_lock); quota_root = fs_info->quota_root;
@@ -2087,8 +2085,6 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans,if (test_and_clear_bit (BTRFS_FS_QUOTA_ENABLING , &fs_info->flags))set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags); -if (test_and_clear_bit (BTRFS_FS_QUOTA_DISABLING , &fs_info->flags)) -clear_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_lock (&fs_info->qgroup_lock);while (!list_empty (&fs_info->dirty_qgroups)) {
Signature · 7 lines
2.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Tomohiro
Currently, "btrfs quota enable" would fail after "btrfs quota disable" on the first time with syslog output "
qgroup_rescan_initfailed with -22", but it would succeed on the second time.When "quota disable" is called,
BTRFS_FS_QUOTA_DISABLINGflag bit will be set infs_info->flagsinbtrfs_quota_disable(), but it will not be droppd inbtrfs_run_qgroups()(which is called inbtrfs_commit_transaction()) becausequota_roothas already been freed. If "quota enable" is called after that, bothBTRFS_FS_QUOTA_DISABLINGandBTRFS_FS_QUOTA_ENABLEDflag would be dropped in thebtrfs_run_qgroups()sincequota_rootis not NULL. This leads to the failure of "quota enable" on the first time.
Quoted 6 lines
BTRFS_FS_QUOTA_DISABLINGflag is not used outside of "quota disable" context and is equivalent to whetherquota_rootis NULL or not.btrfs_run_qgroups()checks whetherquota_rootis NULL or not in the first place.So, let's remove
BTRFS_FS_QUOTA_DISABLINGflag.
The state bits and transitions are messy and keeping them consistent could lead to the problmes you observe. By the analysis above it looks correct to me to remove the 'disabling' bit.