2014-05-14 00:30:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Facebook. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BTRFS_QGROUP__
|
|
|
|
#define __BTRFS_QGROUP__
|
|
|
|
|
2015-04-16 06:34:17 +00:00
|
|
|
#include "ulist.h"
|
|
|
|
#include "delayed-ref.h"
|
|
|
|
|
2016-10-18 01:31:26 +00:00
|
|
|
/*
|
|
|
|
* Btrfs qgroup overview
|
|
|
|
*
|
|
|
|
* Btrfs qgroup splits into 3 main part:
|
|
|
|
* 1) Reserve
|
|
|
|
* Reserve metadata/data space for incoming operations
|
|
|
|
* Affect how qgroup limit works
|
|
|
|
*
|
|
|
|
* 2) Trace
|
|
|
|
* Tell btrfs qgroup to trace dirty extents.
|
|
|
|
*
|
|
|
|
* Dirty extents including:
|
|
|
|
* - Newly allocated extents
|
|
|
|
* - Extents going to be deleted (in this trans)
|
|
|
|
* - Extents whose owner is going to be modified
|
|
|
|
*
|
|
|
|
* This is the main part affects whether qgroup numbers will stay
|
|
|
|
* consistent.
|
|
|
|
* Btrfs qgroup can trace clean extents and won't cause any problem,
|
|
|
|
* but it will consume extra CPU time, it should be avoided if possible.
|
|
|
|
*
|
|
|
|
* 3) Account
|
|
|
|
* Btrfs qgroup will updates its numbers, based on dirty extents traced
|
|
|
|
* in previous step.
|
|
|
|
*
|
|
|
|
* Normally at qgroup rescan and transaction commit time.
|
|
|
|
*/
|
|
|
|
|
2015-04-16 06:34:17 +00:00
|
|
|
/*
|
|
|
|
* Record a dirty extent, and info qgroup to update quota on it
|
|
|
|
* TODO: Use kmem cache to alloc it.
|
|
|
|
*/
|
|
|
|
struct btrfs_qgroup_extent_record {
|
|
|
|
struct rb_node node;
|
|
|
|
u64 bytenr;
|
|
|
|
u64 num_bytes;
|
|
|
|
struct ulist *old_roots;
|
|
|
|
};
|
|
|
|
|
2017-03-13 07:52:08 +00:00
|
|
|
/*
|
|
|
|
* one struct for each qgroup, organized in fs_info->qgroup_tree.
|
|
|
|
*/
|
|
|
|
struct btrfs_qgroup {
|
|
|
|
u64 qgroupid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* state
|
|
|
|
*/
|
|
|
|
u64 rfer; /* referenced */
|
|
|
|
u64 rfer_cmpr; /* referenced compressed */
|
|
|
|
u64 excl; /* exclusive */
|
|
|
|
u64 excl_cmpr; /* exclusive compressed */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* limits
|
|
|
|
*/
|
|
|
|
u64 lim_flags; /* which limits are set */
|
|
|
|
u64 max_rfer;
|
|
|
|
u64 max_excl;
|
|
|
|
u64 rsv_rfer;
|
|
|
|
u64 rsv_excl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reservation tracking
|
|
|
|
*/
|
|
|
|
u64 reserved;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lists
|
|
|
|
*/
|
|
|
|
struct list_head groups; /* groups this group is member of */
|
|
|
|
struct list_head members; /* groups that are members of this group */
|
|
|
|
struct list_head dirty; /* dirty groups */
|
|
|
|
struct rb_node node; /* tree of qgroups */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* temp variables for accounting operations
|
|
|
|
* Refer to qgroup_shared_accounting() for details.
|
|
|
|
*/
|
|
|
|
u64 old_refcnt;
|
|
|
|
u64 new_refcnt;
|
|
|
|
};
|
|
|
|
|
2015-09-28 08:57:53 +00:00
|
|
|
/*
|
|
|
|
* For qgroup event trace points only
|
|
|
|
*/
|
|
|
|
#define QGROUP_RESERVE (1<<0)
|
|
|
|
#define QGROUP_RELEASE (1<<1)
|
|
|
|
#define QGROUP_FREE (1<<2)
|
|
|
|
|
2014-05-14 00:30:47 +00:00
|
|
|
int btrfs_quota_enable(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info);
|
|
|
|
int btrfs_quota_disable(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info);
|
|
|
|
int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info);
|
|
|
|
void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info);
|
2016-08-09 02:08:06 +00:00
|
|
|
int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info,
|
|
|
|
bool interruptible);
|
2014-05-14 00:30:47 +00:00
|
|
|
int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info, u64 src, u64 dst);
|
|
|
|
int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info, u64 src, u64 dst);
|
|
|
|
int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
|
2015-01-18 15:59:23 +00:00
|
|
|
struct btrfs_fs_info *fs_info, u64 qgroupid);
|
2014-05-14 00:30:47 +00:00
|
|
|
int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info, u64 qgroupid);
|
|
|
|
int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info, u64 qgroupid,
|
|
|
|
struct btrfs_qgroup_limit *limit);
|
|
|
|
int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info);
|
|
|
|
void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
|
|
|
|
struct btrfs_delayed_extent_op;
|
2017-02-27 07:10:35 +00:00
|
|
|
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
/*
|
2016-10-18 01:31:27 +00:00
|
|
|
* Inform qgroup to trace one dirty extent, its info is recorded in @record.
|
2017-02-15 02:43:03 +00:00
|
|
|
* So qgroup can account it at transaction committing time.
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
*
|
2017-02-15 02:43:03 +00:00
|
|
|
* No lock version, caller must acquire delayed ref lock and allocated memory,
|
|
|
|
* then call btrfs_qgroup_trace_extent_post() after exiting lock context.
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
*
|
|
|
|
* Return 0 for success insert
|
|
|
|
* Return >0 for existing record, caller can free @record safely.
|
|
|
|
* Error is not possible
|
|
|
|
*/
|
2016-10-18 01:31:27 +00:00
|
|
|
int btrfs_qgroup_trace_extent_nolock(
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_delayed_ref_root *delayed_refs,
|
|
|
|
struct btrfs_qgroup_extent_record *record);
|
|
|
|
|
2017-02-15 02:43:03 +00:00
|
|
|
/*
|
|
|
|
* Post handler after qgroup_trace_extent_nolock().
|
|
|
|
*
|
|
|
|
* NOTE: Current qgroup does the expensive backref walk at transaction
|
|
|
|
* committing time with TRANS_STATE_COMMIT_DOING, this blocks incoming
|
|
|
|
* new transaction.
|
|
|
|
* This is designed to allow btrfs_find_all_roots() to get correct new_roots
|
|
|
|
* result.
|
|
|
|
*
|
|
|
|
* However for old_roots there is no need to do backref walk at that time,
|
|
|
|
* since we search commit roots to walk backref and result will always be
|
|
|
|
* correct.
|
|
|
|
*
|
|
|
|
* Due to the nature of no lock version, we can't do backref there.
|
|
|
|
* So we must call btrfs_qgroup_trace_extent_post() after exiting
|
|
|
|
* spinlock context.
|
|
|
|
*
|
|
|
|
* TODO: If we can fix and prove btrfs_find_all_roots() can get correct result
|
|
|
|
* using current root, then we can move all expensive backref walk out of
|
|
|
|
* transaction committing, but not now as qgroup accounting will be wrong again.
|
|
|
|
*/
|
|
|
|
int btrfs_qgroup_trace_extent_post(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_qgroup_extent_record *qrecord);
|
|
|
|
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
/*
|
2016-10-18 01:31:27 +00:00
|
|
|
* Inform qgroup to trace one dirty extent, specified by @bytenr and
|
|
|
|
* @num_bytes.
|
|
|
|
* So qgroup can account it at commit trans time.
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
*
|
2017-02-15 02:43:03 +00:00
|
|
|
* Better encapsulated version, with memory allocation and backref walk for
|
|
|
|
* commit roots.
|
|
|
|
* So this can sleep.
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
*
|
|
|
|
* Return 0 if the operation is done.
|
|
|
|
* Return <0 for error, like memory allocation failure or invalid parameter
|
|
|
|
* (NULL trans)
|
|
|
|
*/
|
2016-10-18 01:31:27 +00:00
|
|
|
int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans,
|
btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
1. btrfs_qgroup_insert_dirty_extent_nolock()
Almost the same with original code.
For delayed_ref usage, which has delayed refs locked.
Change the return value type to int, since caller never needs the
pointer, but only needs to know if they need to free the allocated
memory.
2. btrfs_qgroup_insert_dirty_extent()
The more encapsulated version.
Will do the delayed_refs lock, memory allocation, quota enabled check
and other things.
The original design is to keep exported functions to minimal, but since
more btrfs hacks exposed, like replacing path in balance, we need to
record dirty extents manually, so we have to add such functions.
Also, add comment for both functions, to info developers how to keep
qgroup correct when doing hacks.
Cc: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-08-15 02:36:50 +00:00
|
|
|
struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes,
|
|
|
|
gfp_t gfp_flag);
|
|
|
|
|
2016-10-18 01:31:28 +00:00
|
|
|
/*
|
|
|
|
* Inform qgroup to trace all leaf items of data
|
|
|
|
*
|
|
|
|
* Return 0 for success
|
|
|
|
* Return <0 for error(ENOMEM)
|
|
|
|
*/
|
|
|
|
int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans,
|
2016-06-22 22:54:24 +00:00
|
|
|
struct btrfs_fs_info *fs_info,
|
2016-10-18 01:31:28 +00:00
|
|
|
struct extent_buffer *eb);
|
|
|
|
/*
|
|
|
|
* Inform qgroup to trace a whole subtree, including all its child tree
|
|
|
|
* blocks and data.
|
|
|
|
* The root tree block is specified by @root_eb.
|
|
|
|
*
|
|
|
|
* Normally used by relocation(tree block swap) and subvolume deletion.
|
|
|
|
*
|
|
|
|
* Return 0 for success
|
|
|
|
* Return <0 for error(ENOMEM or tree search error)
|
|
|
|
*/
|
|
|
|
int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_root *root,
|
|
|
|
struct extent_buffer *root_eb,
|
|
|
|
u64 root_gen, int root_level);
|
2015-04-16 09:18:36 +00:00
|
|
|
int
|
|
|
|
btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info,
|
|
|
|
u64 bytenr, u64 num_bytes,
|
|
|
|
struct ulist *old_roots, struct ulist *new_roots);
|
2015-04-16 07:37:33 +00:00
|
|
|
int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info);
|
2014-05-14 00:30:47 +00:00
|
|
|
int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info);
|
|
|
|
int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid,
|
|
|
|
struct btrfs_qgroup_inherit *inherit);
|
2015-09-08 09:08:37 +00:00
|
|
|
void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info,
|
|
|
|
u64 ref_root, u64 num_bytes);
|
|
|
|
static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info,
|
|
|
|
u64 ref_root, u64 num_bytes)
|
|
|
|
{
|
2016-06-09 21:27:55 +00:00
|
|
|
trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes);
|
2017-03-13 07:52:09 +00:00
|
|
|
btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes);
|
2015-09-08 09:08:37 +00:00
|
|
|
}
|
2014-05-14 00:30:47 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
|
|
|
|
int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid,
|
|
|
|
u64 rfer, u64 excl);
|
|
|
|
#endif
|
|
|
|
|
2015-10-12 08:05:40 +00:00
|
|
|
/* New io_tree based accurate qgroup reserve API */
|
2017-02-27 07:10:38 +00:00
|
|
|
int btrfs_qgroup_reserve_data(struct inode *inode,
|
|
|
|
struct extent_changeset **reserved, u64 start, u64 len);
|
2015-10-12 08:28:06 +00:00
|
|
|
int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len);
|
btrfs: qgroup: Fix qgroup reserved space underflow by only freeing reserved ranges
[BUG]
For the following case, btrfs can underflow qgroup reserved space
at an error path:
(Page size 4K, function name without "btrfs_" prefix)
Task A | Task B
----------------------------------------------------------------------
Buffered_write [0, 2K) |
|- check_data_free_space() |
| |- qgroup_reserve_data() |
| Range aligned to page |
| range [0, 4K) <<< |
| 4K bytes reserved <<< |
|- copy pages to page cache |
| Buffered_write [2K, 4K)
| |- check_data_free_space()
| | |- qgroup_reserved_data()
| | Range alinged to page
| | range [0, 4K)
| | Already reserved by A <<<
| | 0 bytes reserved <<<
| |- delalloc_reserve_metadata()
| | And it *FAILED* (Maybe EQUOTA)
| |- free_reserved_data_space()
|- qgroup_free_data()
Range aligned to page range
[0, 4K)
Freeing 4K
(Special thanks to Chandan for the detailed report and analyse)
[CAUSE]
Above Task B is freeing reserved data range [0, 4K) which is actually
reserved by Task A.
And at writeback time, page dirty by Task A will go through writeback
routine, which will free 4K reserved data space at file extent insert
time, causing the qgroup underflow.
[FIX]
For btrfs_qgroup_free_data(), add @reserved parameter to only free
data ranges reserved by previous btrfs_qgroup_reserve_data().
So in above case, Task B will try to free 0 byte, so no underflow.
Reported-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Tested-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-02-27 07:10:39 +00:00
|
|
|
int btrfs_qgroup_free_data(struct inode *inode,
|
|
|
|
struct extent_changeset *reserved, u64 start, u64 len);
|
2015-09-08 09:08:38 +00:00
|
|
|
|
2017-01-25 14:50:33 +00:00
|
|
|
int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes,
|
|
|
|
bool enforce);
|
2015-09-08 09:08:38 +00:00
|
|
|
void btrfs_qgroup_free_meta_all(struct btrfs_root *root);
|
|
|
|
void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes);
|
2015-10-13 01:53:10 +00:00
|
|
|
void btrfs_qgroup_check_reserved_leak(struct inode *inode);
|
2014-05-14 00:30:47 +00:00
|
|
|
#endif /* __BTRFS_QGROUP__ */
|