btrfs: qgroup: Init flags with RESCAN bit at quota enable time
PATCH 1/1 btrfs: qgroup: Init flags with RESCAN bit at quota enable time
Between btrfs_quota_enable() finished and rescan kicked in, there is a small window that quota status has (ON | INCONSISTENT) bits set but without RESCAN bits set.
And transaction is committed inside the window and then power loss happens, we will have a quota tree with all qgroup numbers set to 0, and not RESCAN bit set.
At next mount time, qgroup rescan will not kick in due to the missing of RESCAN bit, user needs to kick in rescan manually.
This patch will fix it by setting RESCAN bit at btrfs_quota_enable(), so even after power loss we will still kick in rescan automatically.
--- fs/btrfs/qgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/qgroup.c +3 -2
@@ -930,7 +930,8 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,btrfs_set_qgroup_status_generation (leaf, ptr, trans->transid);btrfs_set_qgroup_status_version (leaf, ptr,BTRFS_QGROUP_STATUS_VERSION ); fs_info->qgroup_flags =BTRFS_QGROUP_STATUS_FLAG_ON | -BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ; +BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | +BTRFS_QGROUP_STATUS_FLAG_RESCAN ;btrfs_set_qgroup_status_flags (leaf, ptr, fs_info->qgroup_flags);btrfs_set_qgroup_status_rescan (leaf, ptr,0 );
@@ -987,7 +988,7 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, fs_info->quota_root = quota_root;set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_unlock (&fs_info->qgroup_lock); - ret =qgroup_rescan_init (fs_info,0 ,1 ); + ret =qgroup_rescan_init (fs_info,0 ,0 );if (!ret) {qgroup_rescan_zero_tracking (fs_info); btrfs_queue_work(fs_info->qgroup_rescan_workers,
Signature · 1 line
2.18.0
Quoted 36 lines · Qu Wenruo
Between
btrfs_quota_enable()finished and rescan kicked in, there is a small window that quota status has (ON | INCONSISTENT) bits set but without RESCAN bits set.And transaction is committed inside the window and then power loss happens, we will have a quota tree with all qgroup numbers set to 0, and not RESCAN bit set.
At next mount time, qgroup rescan will not kick in due to the missing of RESCAN bit, user needs to kick in rescan manually.
This patch will fix it by setting RESCAN bit at
btrfs_quota_enable(), so even after power loss we will still kick in rescan automatically.Suggested-by Misono Tomohiro <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/qgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/btrfs/qgroup.c +2
-1@@ -930,7 +930,8 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,btrfs_set_qgroup_status_generation (leaf, ptr, trans->transid);btrfs_set_qgroup_status_version (leaf, ptr,BTRFS_QGROUP_STATUS_VERSION ); fs_info->qgroup_flags =BTRFS_QGROUP_STATUS_FLAG_ON | -BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ; +BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | +BTRFS_QGROUP_STATUS_FLAG_RESCAN ;btrfs_set_qgroup_status_flags (leaf, ptr, fs_info->qgroup_flags);btrfs_set_qgroup_status_rescan (leaf, ptr,0 );
fs/btrfs/qgroup.c int btrfs_quota_enable(struct btrfs_trans_handle *trans, · line 994
Quoted 8 lines
fs/btrfs/qgroup.c +1
-1@@ -987,7 +988,7 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, fs_info->quota_root = quota_root;set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_unlock (&fs_info->qgroup_lock); - ret =qgroup_rescan_init (fs_info,0 ,1 ); + ret =qgroup_rescan_init (fs_info,0 ,0 );if (!ret) {qgroup_rescan_zero_tracking (fs_info); btrfs_queue_work(fs_info->qgroup_rescan_workers,
This is what I think at first, but is it ok not holding fs_info->qgroup_ioctl_lock in brfs_qgroup_rescan() as you concerned in previous thread?
Quoted 35 lines · Misono Tomohiro
Quoted 34 lines · Qu Wenruo
Between
btrfs_quota_enable()finished and rescan kicked in, there is a small window that quota status has (ON | INCONSISTENT) bits set but without RESCAN bits set.And transaction is committed inside the window and then power loss happens, we will have a quota tree with all qgroup numbers set to 0, and not RESCAN bit set.
At next mount time, qgroup rescan will not kick in due to the missing of RESCAN bit, user needs to kick in rescan manually.
This patch will fix it by setting RESCAN bit at
btrfs_quota_enable(), so even after power loss we will still kick in rescan automatically.Suggested-by Misono Tomohiro <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/qgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/btrfs/qgroup.c +2
-1@@ -930,7 +930,8 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,btrfs_set_qgroup_status_generation (leaf, ptr, trans->transid);btrfs_set_qgroup_status_version (leaf, ptr,BTRFS_QGROUP_STATUS_VERSION ); fs_info->qgroup_flags =BTRFS_QGROUP_STATUS_FLAG_ON | -BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ; +BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | +BTRFS_QGROUP_STATUS_FLAG_RESCAN ;btrfs_set_qgroup_status_flags (leaf, ptr, fs_info->qgroup_flags);btrfs_set_qgroup_status_rescan (leaf, ptr,0 );
Quoted 13 lines
fs/btrfs/qgroup.c int btrfs_quota_enable(struct btrfs_trans_handle *trans, · line 994
Quoted 10 lines
fs/btrfs/qgroup.c +1
-1@@ -987,7 +988,7 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, fs_info->quota_root = quota_root;set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_unlock (&fs_info->qgroup_lock); - ret =qgroup_rescan_init (fs_info,0 ,1 ); + ret =qgroup_rescan_init (fs_info,0 ,0 );if (!ret) {qgroup_rescan_zero_tracking (fs_info); btrfs_queue_work(fs_info->qgroup_rescan_workers,This is what I think at first, but is it ok not holding
fs_info->qgroup_ioctl_lockinbrfs_qgroup_rescan()as you concerned in previous thread?
I think it's OK, since we have larger mutex (subvol_sem) for quota_enable/disable() so there will be no concurrency modifying flags. And we're holding trans handler from btrfs_ioctl_quota_ctl(), transaction won't be committed in btrfs_quota_enable().
So I think it's OK.
Thanks,
Qu
Quoted 52 lines · Qu Wenruo
Quoted 35 lines · Misono Tomohiro
Quoted 34 lines · Qu Wenruo
Between
btrfs_quota_enable()finished and rescan kicked in, there is a small window that quota status has (ON | INCONSISTENT) bits set but without RESCAN bits set.And transaction is committed inside the window and then power loss happens, we will have a quota tree with all qgroup numbers set to 0, and not RESCAN bit set.
At next mount time, qgroup rescan will not kick in due to the missing of RESCAN bit, user needs to kick in rescan manually.
This patch will fix it by setting RESCAN bit at
btrfs_quota_enable(), so even after power loss we will still kick in rescan automatically.Suggested-by Misono Tomohiro <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/qgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/btrfs/qgroup.c +2
-1@@ -930,7 +930,8 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,btrfs_set_qgroup_status_generation (leaf, ptr, trans->transid);btrfs_set_qgroup_status_version (leaf, ptr,BTRFS_QGROUP_STATUS_VERSION ); fs_info->qgroup_flags =BTRFS_QGROUP_STATUS_FLAG_ON | -BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ; +BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | +BTRFS_QGROUP_STATUS_FLAG_RESCAN ;btrfs_set_qgroup_status_flags (leaf, ptr, fs_info->qgroup_flags);btrfs_set_qgroup_status_rescan (leaf, ptr,0 );Quoted 13 lines
fs/btrfs/qgroup.c int btrfs_quota_enable(struct btrfs_trans_handle *trans, · line 994
Quoted 10 lines
fs/btrfs/qgroup.c +1
-1@@ -987,7 +988,7 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, fs_info->quota_root = quota_root;set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_unlock (&fs_info->qgroup_lock); - ret =qgroup_rescan_init (fs_info,0 ,1 ); + ret =qgroup_rescan_init (fs_info,0 ,0 );if (!ret) {qgroup_rescan_zero_tracking (fs_info); btrfs_queue_work(fs_info->qgroup_rescan_workers,This is what I think at first, but is it ok not holding
fs_info->qgroup_ioctl_lockinbrfs_qgroup_rescan()as you concerned in previous thread?
Quoted 4 lines
I think it's OK, since we have larger mutex (
subvol_sem) for quota_enable/disable() so there will be no concurrency modifying flags. And we're holding trans handler frombtrfs_ioctl_quota_ctl(), transaction won't be committed inbtrfs_quota_enable().
Ok, but nikolay's patch in misc-next moves transaction commit in btrfs_quota_enable():
https://patchwork.kernel.org/patch/10508819/
("btrfs: qgroups: Move transaction management inside btrfs_quota_enable/disable")
This is related to https://marc.info/?l=linux-btrfs&m=152999289017582.
However, it seems that other people does not see the problem, so I'm not sure how the above patch ends up...
Thanks,
Tomohiro Misono
Quoted 7 lines
So I think it's OK.
Thanks,
Qu
Quoted 53 lines · Misono Tomohiro
Quoted 52 lines · Qu Wenruo
Quoted 48 lines · Misono Tomohiro
Quoted 36 lines · Qu Wenruo
Between
btrfs_quota_enable()finished and rescan kicked in, there is a small window that quota status has (ON | INCONSISTENT) bits set but without RESCAN bits set.And transaction is committed inside the window and then power loss happens, we will have a quota tree with all qgroup numbers set to 0, and not RESCAN bit set.
At next mount time, qgroup rescan will not kick in due to the missing of RESCAN bit, user needs to kick in rescan manually.
This patch will fix it by setting RESCAN bit at
btrfs_quota_enable(), so even after power loss we will still kick in rescan automatically.Suggested-by Misono Tomohiro <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/qgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/btrfs/qgroup.c +2
-1@@ -930,7 +930,8 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,btrfs_set_qgroup_status_generation (leaf, ptr, trans->transid);btrfs_set_qgroup_status_version (leaf, ptr,BTRFS_QGROUP_STATUS_VERSION ); fs_info->qgroup_flags =BTRFS_QGROUP_STATUS_FLAG_ON | -BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ; +BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | +BTRFS_QGROUP_STATUS_FLAG_RESCAN ;btrfs_set_qgroup_status_flags (leaf, ptr, fs_info->qgroup_flags);btrfs_set_qgroup_status_rescan (leaf, ptr,0 );fs/btrfs/qgroup.c int btrfs_quota_enable(struct btrfs_trans_handle *trans, · line 994
Quoted 8 lines
fs/btrfs/qgroup.c +1
-1@@ -987,7 +988,7 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, fs_info->quota_root = quota_root;set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_unlock (&fs_info->qgroup_lock); - ret =qgroup_rescan_init (fs_info,0 ,1 ); + ret =qgroup_rescan_init (fs_info,0 ,0 );if (!ret) {qgroup_rescan_zero_tracking (fs_info); btrfs_queue_work(fs_info->qgroup_rescan_workers,This is what I think at first, but is it ok not holding
fs_info->qgroup_ioctl_lockinbrfs_qgroup_rescan()as you concerned in previous thread?
Quoted 8 lines
Quoted 4 lines
I think it's OK, since we have larger mutex (
subvol_sem) for quota_enable/disable() so there will be no concurrency modifying flags. And we're holding trans handler frombtrfs_ioctl_quota_ctl(), transaction won't be committed inbtrfs_quota_enable().Ok, but nikolay's patch in misc-next moves transaction commit in
btrfs_quota_enable():
https://patchwork.kernel.org/patch/10508819/
("btrfs: qgroups: Move transaction management inside btrfs_quota_enable/disable")
Since qgroup_rescan_init() has nothing do to with transaction, it looks OK even with Nikolay's patch.
Quoted 4 lines
This is related to https://marc.info/?l=linux-btrfs&m=152999289017582.
However, it seems that other people does not see the problem, so I'm not sure how the above patch ends up...
IIRC I also failed to reproduce it, thus can't provide much help for that thread.
Thanks,
Qu
Quoted 12 lines
Thanks,
Tomohiro MisonoQuoted 7 lines
So I think it's OK.
Thanks,
Qu
Quoted 61 lines · Qu Wenruo
Quoted 58 lines · Misono Tomohiro
Quoted 56 lines · Qu Wenruo
Quoted 35 lines · Misono Tomohiro
Quoted 34 lines · Qu Wenruo
Between
btrfs_quota_enable()finished and rescan kicked in, there is a small window that quota status has (ON | INCONSISTENT) bits set but without RESCAN bits set.And transaction is committed inside the window and then power loss happens, we will have a quota tree with all qgroup numbers set to 0, and not RESCAN bit set.
At next mount time, qgroup rescan will not kick in due to the missing of RESCAN bit, user needs to kick in rescan manually.
This patch will fix it by setting RESCAN bit at
btrfs_quota_enable(), so even after power loss we will still kick in rescan automatically.Suggested-by Misono Tomohiro <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/qgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/btrfs/qgroup.c +2
-1@@ -930,7 +930,8 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,btrfs_set_qgroup_status_generation (leaf, ptr, trans->transid);btrfs_set_qgroup_status_version (leaf, ptr,BTRFS_QGROUP_STATUS_VERSION ); fs_info->qgroup_flags =BTRFS_QGROUP_STATUS_FLAG_ON | -BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ; +BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | +BTRFS_QGROUP_STATUS_FLAG_RESCAN ;btrfs_set_qgroup_status_flags (leaf, ptr, fs_info->qgroup_flags);btrfs_set_qgroup_status_rescan (leaf, ptr,0 );Quoted 13 lines
fs/btrfs/qgroup.c int btrfs_quota_enable(struct btrfs_trans_handle *trans, · line 994
Quoted 10 lines
fs/btrfs/qgroup.c +1
-1@@ -987,7 +988,7 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, fs_info->quota_root = quota_root;set_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags);spin_unlock (&fs_info->qgroup_lock); - ret =qgroup_rescan_init (fs_info,0 ,1 ); + ret =qgroup_rescan_init (fs_info,0 ,0 );if (!ret) {qgroup_rescan_zero_tracking (fs_info); btrfs_queue_work(fs_info->qgroup_rescan_workers,This is what I think at first, but is it ok not holding
fs_info->qgroup_ioctl_lockinbrfs_qgroup_rescan()as you concerned in previous thread?I think it's OK, since we have larger mutex (
subvol_sem) for quota_enable/disable() so there will be no concurrency modifying flags. And we're holding trans handler frombtrfs_ioctl_quota_ctl(), transaction won't be committed inbtrfs_quota_enable().
Quoted 7 lines
Quoted 3 lines
Ok, but nikolay's patch in misc-next moves transaction commit in
btrfs_quota_enable():
https://patchwork.kernel.org/patch/10508819/
("btrfs: qgroups: Move transaction management inside btrfs_quota_enable/disable")Since
qgroup_rescan_init()has nothing do to with transaction, it looks OK even with Nikolay's patch.
Understood. Thanks for your explanation.
Misono
Quoted 26 lines
Quoted 4 lines
This is related to https://marc.info/?l=linux-btrfs&m=152999289017582.
However, it seems that other people does not see the problem, so I'm not sure how the above patch ends up...IIRC I also failed to reproduce it, thus can't provide much help for that thread.
Thanks,
QuQuoted 12 lines
Thanks,
Tomohiro MisonoQuoted 7 lines
So I think it's OK.
Thanks,
Qu