diff options
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r-- | fs/btrfs/ctree.c | 65 |
1 files changed, 10 insertions, 55 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 35444013f0cf..ecd25a1b4e51 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -1442,7 +1442,7 @@ int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2) | |||
1442 | */ | 1442 | */ |
1443 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, | 1443 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
1444 | struct btrfs_root *root, struct extent_buffer *parent, | 1444 | struct btrfs_root *root, struct extent_buffer *parent, |
1445 | int start_slot, int cache_only, u64 *last_ret, | 1445 | int start_slot, u64 *last_ret, |
1446 | struct btrfs_key *progress) | 1446 | struct btrfs_key *progress) |
1447 | { | 1447 | { |
1448 | struct extent_buffer *cur; | 1448 | struct extent_buffer *cur; |
@@ -1462,8 +1462,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
1462 | struct btrfs_disk_key disk_key; | 1462 | struct btrfs_disk_key disk_key; |
1463 | 1463 | ||
1464 | parent_level = btrfs_header_level(parent); | 1464 | parent_level = btrfs_header_level(parent); |
1465 | if (cache_only && parent_level != 1) | ||
1466 | return 0; | ||
1467 | 1465 | ||
1468 | WARN_ON(trans->transaction != root->fs_info->running_transaction); | 1466 | WARN_ON(trans->transaction != root->fs_info->running_transaction); |
1469 | WARN_ON(trans->transid != root->fs_info->generation); | 1467 | WARN_ON(trans->transid != root->fs_info->generation); |
@@ -1509,10 +1507,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
1509 | else | 1507 | else |
1510 | uptodate = 0; | 1508 | uptodate = 0; |
1511 | if (!cur || !uptodate) { | 1509 | if (!cur || !uptodate) { |
1512 | if (cache_only) { | ||
1513 | free_extent_buffer(cur); | ||
1514 | continue; | ||
1515 | } | ||
1516 | if (!cur) { | 1510 | if (!cur) { |
1517 | cur = read_tree_block(root, blocknr, | 1511 | cur = read_tree_block(root, blocknr, |
1518 | blocksize, gen); | 1512 | blocksize, gen); |
@@ -4826,8 +4820,8 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) | |||
4826 | 4820 | ||
4827 | /* | 4821 | /* |
4828 | * A helper function to walk down the tree starting at min_key, and looking | 4822 | * A helper function to walk down the tree starting at min_key, and looking |
4829 | * for nodes or leaves that are either in cache or have a minimum | 4823 | * for nodes or leaves that are have a minimum transaction id. |
4830 | * transaction id. This is used by the btree defrag code, and tree logging | 4824 | * This is used by the btree defrag code, and tree logging |
4831 | * | 4825 | * |
4832 | * This does not cow, but it does stuff the starting key it finds back | 4826 | * This does not cow, but it does stuff the starting key it finds back |
4833 | * into min_key, so you can call btrfs_search_slot with cow=1 on the | 4827 | * into min_key, so you can call btrfs_search_slot with cow=1 on the |
@@ -4848,7 +4842,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) | |||
4848 | */ | 4842 | */ |
4849 | int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, | 4843 | int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, |
4850 | struct btrfs_key *max_key, | 4844 | struct btrfs_key *max_key, |
4851 | struct btrfs_path *path, int cache_only, | 4845 | struct btrfs_path *path, |
4852 | u64 min_trans) | 4846 | u64 min_trans) |
4853 | { | 4847 | { |
4854 | struct extent_buffer *cur; | 4848 | struct extent_buffer *cur; |
@@ -4888,15 +4882,12 @@ again: | |||
4888 | if (sret && slot > 0) | 4882 | if (sret && slot > 0) |
4889 | slot--; | 4883 | slot--; |
4890 | /* | 4884 | /* |
4891 | * check this node pointer against the cache_only and | 4885 | * check this node pointer against the min_trans parameters. |
4892 | * min_trans parameters. If it isn't in cache or is too | 4886 | * If it is too old, old, skip to the next one. |
4893 | * old, skip to the next one. | ||
4894 | */ | 4887 | */ |
4895 | while (slot < nritems) { | 4888 | while (slot < nritems) { |
4896 | u64 blockptr; | 4889 | u64 blockptr; |
4897 | u64 gen; | 4890 | u64 gen; |
4898 | struct extent_buffer *tmp; | ||
4899 | struct btrfs_disk_key disk_key; | ||
4900 | 4891 | ||
4901 | blockptr = btrfs_node_blockptr(cur, slot); | 4892 | blockptr = btrfs_node_blockptr(cur, slot); |
4902 | gen = btrfs_node_ptr_generation(cur, slot); | 4893 | gen = btrfs_node_ptr_generation(cur, slot); |
@@ -4904,27 +4895,7 @@ again: | |||
4904 | slot++; | 4895 | slot++; |
4905 | continue; | 4896 | continue; |
4906 | } | 4897 | } |
4907 | if (!cache_only) | 4898 | break; |
4908 | break; | ||
4909 | |||
4910 | if (max_key) { | ||
4911 | btrfs_node_key(cur, &disk_key, slot); | ||
4912 | if (comp_keys(&disk_key, max_key) >= 0) { | ||
4913 | ret = 1; | ||
4914 | goto out; | ||
4915 | } | ||
4916 | } | ||
4917 | |||
4918 | tmp = btrfs_find_tree_block(root, blockptr, | ||
4919 | btrfs_level_size(root, level - 1)); | ||
4920 | |||
4921 | if (tmp && btrfs_buffer_uptodate(tmp, gen, 1) > 0) { | ||
4922 | free_extent_buffer(tmp); | ||
4923 | break; | ||
4924 | } | ||
4925 | if (tmp) | ||
4926 | free_extent_buffer(tmp); | ||
4927 | slot++; | ||
4928 | } | 4899 | } |
4929 | find_next_key: | 4900 | find_next_key: |
4930 | /* | 4901 | /* |
@@ -4935,7 +4906,7 @@ find_next_key: | |||
4935 | path->slots[level] = slot; | 4906 | path->slots[level] = slot; |
4936 | btrfs_set_path_blocking(path); | 4907 | btrfs_set_path_blocking(path); |
4937 | sret = btrfs_find_next_key(root, path, min_key, level, | 4908 | sret = btrfs_find_next_key(root, path, min_key, level, |
4938 | cache_only, min_trans); | 4909 | min_trans); |
4939 | if (sret == 0) { | 4910 | if (sret == 0) { |
4940 | btrfs_release_path(path); | 4911 | btrfs_release_path(path); |
4941 | goto again; | 4912 | goto again; |
@@ -5400,8 +5371,7 @@ out: | |||
5400 | /* | 5371 | /* |
5401 | * this is similar to btrfs_next_leaf, but does not try to preserve | 5372 | * this is similar to btrfs_next_leaf, but does not try to preserve |
5402 | * and fixup the path. It looks for and returns the next key in the | 5373 | * and fixup the path. It looks for and returns the next key in the |
5403 | * tree based on the current path and the cache_only and min_trans | 5374 | * tree based on the current path and the min_trans parameters. |
5404 | * parameters. | ||
5405 | * | 5375 | * |
5406 | * 0 is returned if another key is found, < 0 if there are any errors | 5376 | * 0 is returned if another key is found, < 0 if there are any errors |
5407 | * and 1 is returned if there are no higher keys in the tree | 5377 | * and 1 is returned if there are no higher keys in the tree |
@@ -5410,8 +5380,7 @@ out: | |||
5410 | * calling this function. | 5380 | * calling this function. |
5411 | */ | 5381 | */ |
5412 | int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, | 5382 | int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, |
5413 | struct btrfs_key *key, int level, | 5383 | struct btrfs_key *key, int level, u64 min_trans) |
5414 | int cache_only, u64 min_trans) | ||
5415 | { | 5384 | { |
5416 | int slot; | 5385 | int slot; |
5417 | struct extent_buffer *c; | 5386 | struct extent_buffer *c; |
@@ -5462,22 +5431,8 @@ next: | |||
5462 | if (level == 0) | 5431 | if (level == 0) |
5463 | btrfs_item_key_to_cpu(c, key, slot); | 5432 | btrfs_item_key_to_cpu(c, key, slot); |
5464 | else { | 5433 | else { |
5465 | u64 blockptr = btrfs_node_blockptr(c, slot); | ||
5466 | u64 gen = btrfs_node_ptr_generation(c, slot); | 5434 | u64 gen = btrfs_node_ptr_generation(c, slot); |
5467 | 5435 | ||
5468 | if (cache_only) { | ||
5469 | struct extent_buffer *cur; | ||
5470 | cur = btrfs_find_tree_block(root, blockptr, | ||
5471 | btrfs_level_size(root, level - 1)); | ||
5472 | if (!cur || | ||
5473 | btrfs_buffer_uptodate(cur, gen, 1) <= 0) { | ||
5474 | slot++; | ||
5475 | if (cur) | ||
5476 | free_extent_buffer(cur); | ||
5477 | goto next; | ||
5478 | } | ||
5479 | free_extent_buffer(cur); | ||
5480 | } | ||
5481 | if (gen < min_trans) { | 5436 | if (gen < min_trans) { |
5482 | slot++; | 5437 | slot++; |
5483 | goto next; | 5438 | goto next; |