diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2015-04-19 22:09:06 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-06-10 12:26:29 -0400 |
commit | d67263354541982a29e22a327a9d8c71d1099766 (patch) | |
tree | 1c3d14f9c17d74c8a3f9b54c33bcd879cbc1ce27 | |
parent | 9086db86e0b09c39abead4d747119695553e3978 (diff) |
btrfs: qgroup: Make snapshot accounting work with new extent-oriented
qgroup.
Make snapshot accounting work with new extent-oriented mechanism by
skipping given root in new/old_roots in create_pending_snapshot().
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r-- | fs/btrfs/transaction.c | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 3e3793dcb4c2..c0f18e7266b6 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -1295,6 +1295,12 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1295 | if (pending->error) | 1295 | if (pending->error) |
1296 | goto no_free_objectid; | 1296 | goto no_free_objectid; |
1297 | 1297 | ||
1298 | /* | ||
1299 | * Make qgroup to skip current new snapshot's qgroupid, as it is | ||
1300 | * accounted by later btrfs_qgroup_inherit(). | ||
1301 | */ | ||
1302 | btrfs_set_skip_qgroup(trans, objectid); | ||
1303 | |||
1298 | btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); | 1304 | btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); |
1299 | 1305 | ||
1300 | if (to_reserve > 0) { | 1306 | if (to_reserve > 0) { |
@@ -1303,7 +1309,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1303 | to_reserve, | 1309 | to_reserve, |
1304 | BTRFS_RESERVE_NO_FLUSH); | 1310 | BTRFS_RESERVE_NO_FLUSH); |
1305 | if (pending->error) | 1311 | if (pending->error) |
1306 | goto no_free_objectid; | 1312 | goto clear_skip_qgroup; |
1307 | } | 1313 | } |
1308 | 1314 | ||
1309 | key.objectid = objectid; | 1315 | key.objectid = objectid; |
@@ -1401,25 +1407,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1401 | btrfs_abort_transaction(trans, root, ret); | 1407 | btrfs_abort_transaction(trans, root, ret); |
1402 | goto fail; | 1408 | goto fail; |
1403 | } | 1409 | } |
1404 | |||
1405 | /* | ||
1406 | * We need to flush delayed refs in order to make sure all of our quota | ||
1407 | * operations have been done before we call btrfs_qgroup_inherit. | ||
1408 | */ | ||
1409 | ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); | ||
1410 | if (ret) { | ||
1411 | btrfs_abort_transaction(trans, root, ret); | ||
1412 | goto fail; | ||
1413 | } | ||
1414 | |||
1415 | ret = btrfs_qgroup_inherit(trans, fs_info, | ||
1416 | root->root_key.objectid, | ||
1417 | objectid, pending->inherit); | ||
1418 | if (ret) { | ||
1419 | btrfs_abort_transaction(trans, root, ret); | ||
1420 | goto fail; | ||
1421 | } | ||
1422 | |||
1423 | /* see comments in should_cow_block() */ | 1410 | /* see comments in should_cow_block() */ |
1424 | set_bit(BTRFS_ROOT_FORCE_COW, &root->state); | 1411 | set_bit(BTRFS_ROOT_FORCE_COW, &root->state); |
1425 | smp_wmb(); | 1412 | smp_wmb(); |
@@ -1502,11 +1489,37 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1502 | goto fail; | 1489 | goto fail; |
1503 | } | 1490 | } |
1504 | } | 1491 | } |
1492 | |||
1493 | ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); | ||
1494 | if (ret) { | ||
1495 | btrfs_abort_transaction(trans, root, ret); | ||
1496 | goto fail; | ||
1497 | } | ||
1498 | |||
1499 | /* | ||
1500 | * account qgroup counters before qgroup_inherit() | ||
1501 | */ | ||
1502 | ret = btrfs_qgroup_prepare_account_extents(trans, fs_info); | ||
1503 | if (ret) | ||
1504 | goto fail; | ||
1505 | ret = btrfs_qgroup_account_extents(trans, fs_info); | ||
1506 | if (ret) | ||
1507 | goto fail; | ||
1508 | ret = btrfs_qgroup_inherit(trans, fs_info, | ||
1509 | root->root_key.objectid, | ||
1510 | objectid, pending->inherit); | ||
1511 | if (ret) { | ||
1512 | btrfs_abort_transaction(trans, root, ret); | ||
1513 | goto fail; | ||
1514 | } | ||
1515 | |||
1505 | fail: | 1516 | fail: |
1506 | pending->error = ret; | 1517 | pending->error = ret; |
1507 | dir_item_existed: | 1518 | dir_item_existed: |
1508 | trans->block_rsv = rsv; | 1519 | trans->block_rsv = rsv; |
1509 | trans->bytes_reserved = 0; | 1520 | trans->bytes_reserved = 0; |
1521 | clear_skip_qgroup: | ||
1522 | btrfs_clear_skip_qgroup(trans); | ||
1510 | no_free_objectid: | 1523 | no_free_objectid: |
1511 | kfree(new_root_item); | 1524 | kfree(new_root_item); |
1512 | root_item_alloc_fail: | 1525 | root_item_alloc_fail: |