Commit de78b51a authored by Eric Sandeen's avatar Eric Sandeen Committed by Josef Bacik

btrfs: remove cache only arguments from defrag path

The entry point at the defrag ioctl always sets "cache only" to 0;
the codepaths haven't run for a long time as far as I can
tell.  Chris says they're dead code, so remove them.
Signed-off-by: default avatarEric Sandeen <sandeen@redhat.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent e4a2bcac
...@@ -1442,7 +1442,7 @@ int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2) ...@@ -1442,7 +1442,7 @@ int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2)
*/ */
int btrfs_realloc_node(struct btrfs_trans_handle *trans, int btrfs_realloc_node(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct extent_buffer *parent, struct btrfs_root *root, struct extent_buffer *parent,
int start_slot, int cache_only, u64 *last_ret, int start_slot, u64 *last_ret,
struct btrfs_key *progress) struct btrfs_key *progress)
{ {
struct extent_buffer *cur; struct extent_buffer *cur;
...@@ -1462,8 +1462,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, ...@@ -1462,8 +1462,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
parent_level = btrfs_header_level(parent); parent_level = btrfs_header_level(parent);
if (cache_only && parent_level != 1)
return 0;
WARN_ON(trans->transaction != root->fs_info->running_transaction); WARN_ON(trans->transaction != root->fs_info->running_transaction);
WARN_ON(trans->transid != root->fs_info->generation); WARN_ON(trans->transid != root->fs_info->generation);
...@@ -1509,10 +1507,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, ...@@ -1509,10 +1507,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
else else
uptodate = 0; uptodate = 0;
if (!cur || !uptodate) { if (!cur || !uptodate) {
if (cache_only) {
free_extent_buffer(cur);
continue;
}
if (!cur) { if (!cur) {
cur = read_tree_block(root, blocknr, cur = read_tree_block(root, blocknr,
blocksize, gen); blocksize, gen);
...@@ -4826,8 +4820,8 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) ...@@ -4826,8 +4820,8 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
/* /*
* A helper function to walk down the tree starting at min_key, and looking * A helper function to walk down the tree starting at min_key, and looking
* for nodes or leaves that are either in cache or have a minimum * for nodes or leaves that are have a minimum transaction id.
* transaction id. This is used by the btree defrag code, and tree logging * This is used by the btree defrag code, and tree logging
* *
* This does not cow, but it does stuff the starting key it finds back * This does not cow, but it does stuff the starting key it finds back
* into min_key, so you can call btrfs_search_slot with cow=1 on the * 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,7 +4842,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
*/ */
int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
struct btrfs_key *max_key, struct btrfs_key *max_key,
struct btrfs_path *path, int cache_only, struct btrfs_path *path,
u64 min_trans) u64 min_trans)
{ {
struct extent_buffer *cur; struct extent_buffer *cur;
...@@ -4888,15 +4882,12 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, ...@@ -4888,15 +4882,12 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
if (sret && slot > 0) if (sret && slot > 0)
slot--; slot--;
/* /*
* check this node pointer against the cache_only and * check this node pointer against the min_trans parameters.
* min_trans parameters. If it isn't in cache or is too * If it is too old, old, skip to the next one.
* old, skip to the next one.
*/ */
while (slot < nritems) { while (slot < nritems) {
u64 blockptr; u64 blockptr;
u64 gen; u64 gen;
struct extent_buffer *tmp;
struct btrfs_disk_key disk_key;
blockptr = btrfs_node_blockptr(cur, slot); blockptr = btrfs_node_blockptr(cur, slot);
gen = btrfs_node_ptr_generation(cur, slot); gen = btrfs_node_ptr_generation(cur, slot);
...@@ -4904,27 +4895,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, ...@@ -4904,27 +4895,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
slot++; slot++;
continue; continue;
} }
if (!cache_only)
break; break;
if (max_key) {
btrfs_node_key(cur, &disk_key, slot);
if (comp_keys(&disk_key, max_key) >= 0) {
ret = 1;
goto out;
}
}
tmp = btrfs_find_tree_block(root, blockptr,
btrfs_level_size(root, level - 1));
if (tmp && btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
free_extent_buffer(tmp);
break;
}
if (tmp)
free_extent_buffer(tmp);
slot++;
} }
find_next_key: find_next_key:
/* /*
...@@ -4935,7 +4906,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, ...@@ -4935,7 +4906,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
path->slots[level] = slot; path->slots[level] = slot;
btrfs_set_path_blocking(path); btrfs_set_path_blocking(path);
sret = btrfs_find_next_key(root, path, min_key, level, sret = btrfs_find_next_key(root, path, min_key, level,
cache_only, min_trans); min_trans);
if (sret == 0) { if (sret == 0) {
btrfs_release_path(path); btrfs_release_path(path);
goto again; goto again;
...@@ -5400,8 +5371,7 @@ int btrfs_compare_trees(struct btrfs_root *left_root, ...@@ -5400,8 +5371,7 @@ int btrfs_compare_trees(struct btrfs_root *left_root,
/* /*
* this is similar to btrfs_next_leaf, but does not try to preserve * this is similar to btrfs_next_leaf, but does not try to preserve
* and fixup the path. It looks for and returns the next key in the * and fixup the path. It looks for and returns the next key in the
* tree based on the current path and the cache_only and min_trans * tree based on the current path and the min_trans parameters.
* parameters.
* *
* 0 is returned if another key is found, < 0 if there are any errors * 0 is returned if another key is found, < 0 if there are any errors
* and 1 is returned if there are no higher keys in the tree * and 1 is returned if there are no higher keys in the tree
...@@ -5410,8 +5380,7 @@ int btrfs_compare_trees(struct btrfs_root *left_root, ...@@ -5410,8 +5380,7 @@ int btrfs_compare_trees(struct btrfs_root *left_root,
* calling this function. * calling this function.
*/ */
int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
struct btrfs_key *key, int level, struct btrfs_key *key, int level, u64 min_trans)
int cache_only, u64 min_trans)
{ {
int slot; int slot;
struct extent_buffer *c; struct extent_buffer *c;
...@@ -5462,22 +5431,8 @@ int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, ...@@ -5462,22 +5431,8 @@ int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
if (level == 0) if (level == 0)
btrfs_item_key_to_cpu(c, key, slot); btrfs_item_key_to_cpu(c, key, slot);
else { else {
u64 blockptr = btrfs_node_blockptr(c, slot);
u64 gen = btrfs_node_ptr_generation(c, slot); u64 gen = btrfs_node_ptr_generation(c, slot);
if (cache_only) {
struct extent_buffer *cur;
cur = btrfs_find_tree_block(root, blockptr,
btrfs_level_size(root, level - 1));
if (!cur ||
btrfs_buffer_uptodate(cur, gen, 1) <= 0) {
slot++;
if (cur)
free_extent_buffer(cur);
goto next;
}
free_extent_buffer(cur);
}
if (gen < min_trans) { if (gen < min_trans) {
slot++; slot++;
goto next; goto next;
......
...@@ -3125,10 +3125,10 @@ struct extent_buffer *btrfs_root_node(struct btrfs_root *root); ...@@ -3125,10 +3125,10 @@ struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
struct btrfs_key *key, int lowest_level, struct btrfs_key *key, int lowest_level,
int cache_only, u64 min_trans); u64 min_trans);
int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
struct btrfs_key *max_key, struct btrfs_key *max_key,
struct btrfs_path *path, int cache_only, struct btrfs_path *path,
u64 min_trans); u64 min_trans);
enum btrfs_compare_tree_result { enum btrfs_compare_tree_result {
BTRFS_COMPARE_TREE_NEW, BTRFS_COMPARE_TREE_NEW,
...@@ -3181,7 +3181,7 @@ int btrfs_search_slot_for_read(struct btrfs_root *root, ...@@ -3181,7 +3181,7 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,
int find_higher, int return_any); int find_higher, int return_any);
int btrfs_realloc_node(struct btrfs_trans_handle *trans, int btrfs_realloc_node(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct extent_buffer *parent, struct btrfs_root *root, struct extent_buffer *parent,
int start_slot, int cache_only, u64 *last_ret, int start_slot, u64 *last_ret,
struct btrfs_key *progress); struct btrfs_key *progress);
void btrfs_release_path(struct btrfs_path *p); void btrfs_release_path(struct btrfs_path *p);
struct btrfs_path *btrfs_alloc_path(void); struct btrfs_path *btrfs_alloc_path(void);
...@@ -3576,7 +3576,7 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode, ...@@ -3576,7 +3576,7 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
/* tree-defrag.c */ /* tree-defrag.c */
int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
struct btrfs_root *root, int cache_only); struct btrfs_root *root);
/* sysfs.c */ /* sysfs.c */
int btrfs_init_sysfs(void); int btrfs_init_sysfs(void);
......
...@@ -818,7 +818,7 @@ static int find_new_extents(struct btrfs_root *root, ...@@ -818,7 +818,7 @@ static int find_new_extents(struct btrfs_root *root,
while(1) { while(1) {
ret = btrfs_search_forward(root, &min_key, &max_key, ret = btrfs_search_forward(root, &min_key, &max_key,
path, 0, newer_than); path, newer_than);
if (ret != 0) if (ret != 0)
goto none; goto none;
if (min_key.objectid != ino) if (min_key.objectid != ino)
...@@ -1864,7 +1864,7 @@ static noinline int search_ioctl(struct inode *inode, ...@@ -1864,7 +1864,7 @@ static noinline int search_ioctl(struct inode *inode,
path->keep_locks = 1; path->keep_locks = 1;
while(1) { while(1) {
ret = btrfs_search_forward(root, &key, &max_key, path, 0, ret = btrfs_search_forward(root, &key, &max_key, path,
sk->min_transid); sk->min_transid);
if (ret != 0) { if (ret != 0) {
if (ret > 0) if (ret > 0)
...@@ -2212,10 +2212,10 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) ...@@ -2212,10 +2212,10 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
ret = -EPERM; ret = -EPERM;
goto out; goto out;
} }
ret = btrfs_defrag_root(root, 0); ret = btrfs_defrag_root(root);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_defrag_root(root->fs_info->extent_root, 0); ret = btrfs_defrag_root(root->fs_info->extent_root);
break; break;
case S_IFREG: case S_IFREG:
if (!(file->f_mode & FMODE_WRITE)) { if (!(file->f_mode & FMODE_WRITE)) {
......
...@@ -959,10 +959,10 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans, ...@@ -959,10 +959,10 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans,
} }
/* /*
* defrag a given btree. If cacheonly == 1, this won't read from the disk, * defrag a given btree.
* otherwise every leaf in the btree is read and defragged. * Every leaf in the btree is read and defragged.
*/ */
int btrfs_defrag_root(struct btrfs_root *root, int cacheonly) int btrfs_defrag_root(struct btrfs_root *root)
{ {
struct btrfs_fs_info *info = root->fs_info; struct btrfs_fs_info *info = root->fs_info;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
...@@ -976,7 +976,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly) ...@@ -976,7 +976,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
if (IS_ERR(trans)) if (IS_ERR(trans))
return PTR_ERR(trans); return PTR_ERR(trans);
ret = btrfs_defrag_leaves(trans, root, cacheonly); ret = btrfs_defrag_leaves(trans, root);
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
btrfs_btree_balance_dirty(info->tree_root); btrfs_btree_balance_dirty(info->tree_root);
......
...@@ -117,7 +117,7 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, ...@@ -117,7 +117,7 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
struct btrfs_root *root); struct btrfs_root *root);
int btrfs_add_dead_root(struct btrfs_root *root); int btrfs_add_dead_root(struct btrfs_root *root);
int btrfs_defrag_root(struct btrfs_root *root, int cacheonly); int btrfs_defrag_root(struct btrfs_root *root);
int btrfs_clean_old_snapshots(struct btrfs_root *root); int btrfs_clean_old_snapshots(struct btrfs_root *root);
int btrfs_commit_transaction(struct btrfs_trans_handle *trans, int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
struct btrfs_root *root); struct btrfs_root *root);
......
...@@ -23,13 +23,14 @@ ...@@ -23,13 +23,14 @@
#include "transaction.h" #include "transaction.h"
#include "locking.h" #include "locking.h"
/* defrag all the leaves in a given btree. If cache_only == 1, don't read /*
* things from disk, otherwise read all the leaves and try to get key order to * Defrag all the leaves in a given btree.
* Read all the leaves and try to get key order to
* better reflect disk order * better reflect disk order
*/ */
int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
struct btrfs_root *root, int cache_only) struct btrfs_root *root)
{ {
struct btrfs_path *path = NULL; struct btrfs_path *path = NULL;
struct btrfs_key key; struct btrfs_key key;
...@@ -41,9 +42,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, ...@@ -41,9 +42,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
u64 last_ret = 0; u64 last_ret = 0;
u64 min_trans = 0; u64 min_trans = 0;
if (cache_only)
goto out;
if (root->fs_info->extent_root == root) { if (root->fs_info->extent_root == root) {
/* /*
* there's recursion here right now in the tree locking, * there's recursion here right now in the tree locking,
...@@ -86,11 +84,8 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, ...@@ -86,11 +84,8 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
} }
path->keep_locks = 1; path->keep_locks = 1;
if (cache_only)
min_trans = root->defrag_trans_start;
ret = btrfs_search_forward(root, &key, NULL, path, ret = btrfs_search_forward(root, &key, NULL, path, min_trans);
cache_only, min_trans);
if (ret < 0) if (ret < 0)
goto out; goto out;
if (ret > 0) { if (ret > 0) {
...@@ -109,11 +104,11 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, ...@@ -109,11 +104,11 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
goto out; goto out;
} }
path->slots[1] = btrfs_header_nritems(path->nodes[1]); path->slots[1] = btrfs_header_nritems(path->nodes[1]);
next_key_ret = btrfs_find_next_key(root, path, &key, 1, cache_only, next_key_ret = btrfs_find_next_key(root, path, &key, 1,
min_trans); min_trans);
ret = btrfs_realloc_node(trans, root, ret = btrfs_realloc_node(trans, root,
path->nodes[1], 0, path->nodes[1], 0,
cache_only, &last_ret, &last_ret,
&root->defrag_progress); &root->defrag_progress);
if (ret) { if (ret) {
WARN_ON(ret == -EAGAIN); WARN_ON(ret == -EAGAIN);
......
...@@ -2738,7 +2738,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2738,7 +2738,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
path->keep_locks = 1; path->keep_locks = 1;
ret = btrfs_search_forward(root, &min_key, &max_key, ret = btrfs_search_forward(root, &min_key, &max_key,
path, 0, trans->transid); path, trans->transid);
/* /*
* we didn't find anything from this transaction, see if there * we didn't find anything from this transaction, see if there
...@@ -3680,7 +3680,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -3680,7 +3680,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
while (1) { while (1) {
ins_nr = 0; ins_nr = 0;
ret = btrfs_search_forward(root, &min_key, &max_key, ret = btrfs_search_forward(root, &min_key, &max_key,
path, 0, trans->transid); path, trans->transid);
if (ret != 0) if (ret != 0)
break; break;
again: again:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment