* [PATCH] btrfs: qgroup: Avoid calling qgroup functions if qgroup is not enabled
@ 2018-10-09 6:36 Qu Wenruo
2018-10-09 15:44 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2018-10-09 6:36 UTC (permalink / raw)
To: linux-btrfs
Some qgroup trace events like btrfs_qgroup_release_data() and
btrfs_qgroup_free_delayed_ref() can still be triggered even qgroup is
not enabled.
This is caused by the lack of qgroup status check before really calling
qgroup functions.
Thankfully related functions can handle quota disabled case well and just
do nothing for qgroup disabled case.
This patch will do earlier check before triggering related trace events.
And for enabled <-> disabled race case:
1) For enabled->disabled case
Disable will wipe out all qgroups data including reservation and
excl/rfer. Even we leaks some reserveration or numbers, it will
still be wiped, so nothing can go wrong.
2) For disabled -> enabled case
Current btrfs_qgroup_release_data() will use extent_io tree to ensure
we won't underflow reservation. And for delayed_ref we use
head->qgroup_reserved to record reserved space, so in that case
head->qgroup_reserved should be 0 and we won't underflow.
Reported-by: Chris Murphy <lists@colorremedies.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/qgroup.c | 4 ++++
fs/btrfs/qgroup.h | 2 ++
2 files changed, 6 insertions(+)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 4353bb69bb86..0656f4e78db6 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3107,6 +3107,10 @@ static int __btrfs_qgroup_release_data(struct inode *inode,
int trace_op = QGROUP_RELEASE;
int ret;
+ if (!test_bit(BTRFS_FS_QUOTA_ENABLED,
+ &BTRFS_I(inode)->root->fs_info->flags))
+ return 0;
+
/* In release case, we shouldn't have @reserved */
WARN_ON(!free && reserved);
if (free && reserved)
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h
index 54b8bb282c0e..4bbcc1e92a93 100644
--- a/fs/btrfs/qgroup.h
+++ b/fs/btrfs/qgroup.h
@@ -249,6 +249,8 @@ void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info,
static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info,
u64 ref_root, u64 num_bytes)
{
+ if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags))
+ return;
trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes);
btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes,
BTRFS_QGROUP_RSV_DATA);
--
2.19.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] btrfs: qgroup: Avoid calling qgroup functions if qgroup is not enabled
2018-10-09 6:36 [PATCH] btrfs: qgroup: Avoid calling qgroup functions if qgroup is not enabled Qu Wenruo
@ 2018-10-09 15:44 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2018-10-09 15:44 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Tue, Oct 09, 2018 at 02:36:45PM +0800, Qu Wenruo wrote:
> Some qgroup trace events like btrfs_qgroup_release_data() and
> btrfs_qgroup_free_delayed_ref() can still be triggered even qgroup is
> not enabled.
>
> This is caused by the lack of qgroup status check before really calling
> qgroup functions.
> Thankfully related functions can handle quota disabled case well and just
> do nothing for qgroup disabled case.
>
> This patch will do earlier check before triggering related trace events.
>
> And for enabled <-> disabled race case:
> 1) For enabled->disabled case
> Disable will wipe out all qgroups data including reservation and
> excl/rfer. Even we leaks some reserveration or numbers, it will
> still be wiped, so nothing can go wrong.
>
> 2) For disabled -> enabled case
> Current btrfs_qgroup_release_data() will use extent_io tree to ensure
> we won't underflow reservation. And for delayed_ref we use
> head->qgroup_reserved to record reserved space, so in that case
> head->qgroup_reserved should be 0 and we won't underflow.
>
> Reported-by: Chris Murphy <lists@colorremedies.com>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
I've added the link to the report.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-09 15:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-09 6:36 [PATCH] btrfs: qgroup: Avoid calling qgroup functions if qgroup is not enabled Qu Wenruo
2018-10-09 15:44 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox