提交 4d31778a 编写于 作者: Q Qu Wenruo 提交者: David Sterba

btrfs: qgroup: Fix root item corruption when multiple same source snapshots...

btrfs: qgroup: Fix root item corruption when multiple same source snapshots are created with quota enabled

When multiple pending snapshots referring to the same source subvolume
are executed, enabled quota will cause root item corruption, where root
items are using old bytenr (no backref in extent tree).

This can be triggered by fstests btrfs/152.

The cause is when source subvolume is still dirty, extra commit
(simplied transaction commit) of qgroup_account_snapshot() can skip
dirty roots not recorded in current transaction, making root item of
source subvolume not updated.

Fix it by forcing recording source subvolume in current transaction
before qgroup sub-transaction commit.
Reported-by: NJustin Maggard <jmaggard@netgear.com>
Signed-off-by: NQu Wenruo <wqu@suse.com>
Reviewed-by: NFilipe Manana <fdmanana@suse.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 2e32ef87
...@@ -319,7 +319,7 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans, ...@@ -319,7 +319,7 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans,
if ((test_bit(BTRFS_ROOT_REF_COWS, &root->state) && if ((test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
root->last_trans < trans->transid) || force) { root->last_trans < trans->transid) || force) {
WARN_ON(root == fs_info->extent_root); WARN_ON(root == fs_info->extent_root);
WARN_ON(root->commit_root != root->node); WARN_ON(!force && root->commit_root != root->node);
/* /*
* see below for IN_TRANS_SETUP usage rules * see below for IN_TRANS_SETUP usage rules
...@@ -1371,6 +1371,14 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, ...@@ -1371,6 +1371,14 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags))
return 0; return 0;
/*
* Ensure dirty @src will be commited. Or, after comming
* commit_fs_roots() and switch_commit_roots(), any dirty but not
* recorded root will never be updated again, causing an outdated root
* item.
*/
record_root_in_trans(trans, src, 1);
/* /*
* We are going to commit transaction, see btrfs_commit_transaction() * We are going to commit transaction, see btrfs_commit_transaction()
* comment for reason locking tree_log_mutex * comment for reason locking tree_log_mutex
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册