Eric Sandeen
2013-Apr-26 21:06 UTC
[PATCH 0/9] Btrfs-progs: start at kernel/userspace syncup
A first round of small, hopefully obviously-correct and/or no-op patches that start to make the userspace copies of kernelspace code look a bit more similar. Many of these are direct ports from userspace, a couple others are just my cleanups of various bits here and there. There''ll be a fair bit more after this, but I''ll do it in chunks. (Thanks David!) :) Thanks, -Eric [PATCH 1/9] Btrfs-progs: remove dead btrfs-defrag.c [PATCH 2/9] Btrfs-progs: remove cut & paste btrfs_next_leaf from restore [PATCH 3/9] Btrfs-progs: fix array bound checking [PATCH 4/9] Btrfs-progs: move btrfs_fsck_reinit_root to cmds-check.c [PATCH 5/9] Btrfs-progs: remove some dead/unbuilt code [PATCH 6/9] Btrfs-progs: cleanup duplicated division functions [PATCH 7/9] Btrfs-progs: make extent_ref_type() match kernelspace [PATCH 8/9] Btrfs-progs: remove the unnecessary ''return -1;'' at the end of bin_search [PATCH 9/9] Btrfs-progs: remove btrfs_init_path calls from ctree.c -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Files with only #include directives are boring. :) This is just a leftover after the move to the btrfs tool. Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- btrfs-defrag.c | 39 --------------------------------------- 1 files changed, 0 insertions(+), 39 deletions(-) delete mode 100644 btrfs-defrag.c diff --git a/btrfs-defrag.c b/btrfs-defrag.c deleted file mode 100644 index 8f1525a..0000000 --- a/btrfs-defrag.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2010 Oracle. 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 __CHECKER__ -#include <sys/ioctl.h> -#include <sys/mount.h> -#include "ioctl.h" -#endif -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <ctype.h> -#include <unistd.h> -#include <dirent.h> -#include <libgen.h> -#include <getopt.h> -#include "kerncompat.h" -#include "ctree.h" -#include "transaction.h" -#include "utils.h" -#include "version.h" - -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Eric Sandeen
2013-Apr-26 21:06 UTC
[PATCH 2/9] Btrfs-progs: remove cut & paste btrfs_next_leaf from restore
cmds-restore.c cut & paste btrfs_next_leaf w/ a little extra; we can just call btrfs_next_leaf from there, after the bit of additional pre-checking that it does. Strangely, every caller in restore checks for a negative return as an error, but the copy never returned negative. Calling btrfs_next_leaf does return -EIO in cases where read_node_slot fails. Also, remove the slot assignment which was overwritten in every case. Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- cmds-restore.c | 41 ++--------------------------------------- ctree.c | 5 +++-- ctree.h | 4 ---- 3 files changed, 5 insertions(+), 45 deletions(-) diff --git a/cmds-restore.c b/cmds-restore.c index fc31f0c..e2c1640 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -147,12 +147,9 @@ static int decompress(char *inbuf, char *outbuf, u64 compress_len, return -1; } -int next_leaf(struct btrfs_root *root, struct btrfs_path *path) +static int next_leaf(struct btrfs_root *root, struct btrfs_path *path) { - int slot; int level = 1; - struct extent_buffer *c; - struct extent_buffer *next = NULL; for (; level < BTRFS_MAX_LEVEL; level++) { if (path->nodes[level]) @@ -162,41 +159,7 @@ int next_leaf(struct btrfs_root *root, struct btrfs_path *path) if (level == BTRFS_MAX_LEVEL) return 1; - slot = path->slots[level] + 1; - - while(level < BTRFS_MAX_LEVEL) { - if (!path->nodes[level]) - return 1; - - slot = path->slots[level] + 1; - c = path->nodes[level]; - if (slot >= btrfs_header_nritems(c)) { - level++; - if (level == BTRFS_MAX_LEVEL) - return 1; - continue; - } - - if (path->reada) - reada_for_search(root, path, level, slot, 0); - - next = read_node_slot(root, c, slot); - break; - } - path->slots[level] = slot; - while(1) { - level--; - c = path->nodes[level]; - free_extent_buffer(c); - path->nodes[level] = next; - path->slots[level] = 0; - if (!level) - break; - if (path->reada) - reada_for_search(root, path, level, 0, 0); - next = read_node_slot(root, next, 0); - } - return 0; + return btrfs_next_leaf(root, path); } static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos) diff --git a/ctree.c b/ctree.c index 16f4daa..0311e25 100644 --- a/ctree.c +++ b/ctree.c @@ -777,7 +777,7 @@ static int bin_search(struct extent_buffer *eb, struct btrfs_key *key, return -1; } -struct extent_buffer *read_node_slot(struct btrfs_root *root, +static noinline struct extent_buffer *read_node_slot(struct btrfs_root *root, struct extent_buffer *parent, int slot) { int level = btrfs_header_level(parent); @@ -1104,7 +1104,8 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans, /* * readahead one full node of leaves */ -void reada_for_search(struct btrfs_root *root, struct btrfs_path *path, +static void reada_for_search(struct btrfs_root *root, + struct btrfs_path *path, int level, int slot, u64 objectid) { struct extent_buffer *node; diff --git a/ctree.h b/ctree.h index 0ebb72a..0506aa1 100644 --- a/ctree.h +++ b/ctree.h @@ -2177,10 +2177,6 @@ int btrfs_check_leaf(struct btrfs_root *root, struct extent_buffer *buf); int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, struct btrfs_root *root); -void reada_for_search(struct btrfs_root *root, struct btrfs_path *path, - int level, int slot, u64 objectid); -struct extent_buffer *read_node_slot(struct btrfs_root *root, - struct extent_buffer *parent, int slot); int btrfs_previous_item(struct btrfs_root *root, struct btrfs_path *path, u64 min_objectid, int type); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Otherwise we can execced the array bound of path->slots[]. [Eric Sandeen: port kernel commit a05a9bb to userspace] Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- ctree.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ctree.c b/ctree.c index 0311e25..5409552 100644 --- a/ctree.c +++ b/ctree.c @@ -815,9 +815,10 @@ static int balance_level(struct btrfs_trans_handle *trans, orig_ptr = btrfs_node_blockptr(mid, orig_slot); - if (level < BTRFS_MAX_LEVEL - 1) + if (level < BTRFS_MAX_LEVEL - 1) { parent = path->nodes[level + 1]; - pslot = path->slots[level + 1]; + pslot = path->slots[level + 1]; + } /* * deal with the case where there is only one pointer in the root @@ -1007,9 +1008,10 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans, mid = path->nodes[level]; WARN_ON(btrfs_header_generation(mid) != trans->transid); - if (level < BTRFS_MAX_LEVEL - 1) + if (level < BTRFS_MAX_LEVEL - 1) { parent = path->nodes[level + 1]; - pslot = path->slots[level + 1]; + pslot = path->slots[level + 1]; + } if (!parent) return 1; -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Eric Sandeen
2013-Apr-26 21:06 UTC
[PATCH 4/9] Btrfs-progs: move btrfs_fsck_reinit_root to cmds-check.c
cmds-check.c contains the only caller of btrfs_fsck_reinit_root; moving it to the caller''s source file gets ctree.c a little closer to kernelspace, although it does require exporting add_root_to_dirty_list(), which is not done in kernelspace. Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- cmds-check.c | 43 +++++++++++++++++++++++++++++++++++++++++++ ctree.c | 44 +------------------------------------------- ctree.h | 3 +-- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 9fd53f4..f9723c6 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -3981,6 +3981,49 @@ static int check_extents(struct btrfs_trans_handle *trans, return ret; } + +static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, + struct btrfs_root *root) +{ + struct extent_buffer *c; + struct extent_buffer *old = root->node; + int level; + struct btrfs_disk_key disk_key = {0,0,0}; + + level = 0; + + c = btrfs_alloc_free_block(trans, root, + btrfs_level_size(root, 0), + root->root_key.objectid, + &disk_key, level, 0, 0); + if (IS_ERR(c)) { + c = old; + extent_buffer_get(c); + } + + memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header)); + btrfs_set_header_level(c, level); + btrfs_set_header_bytenr(c, c->start); + btrfs_set_header_generation(c, trans->transid); + btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV); + btrfs_set_header_owner(c, root->root_key.objectid); + + write_extent_buffer(c, root->fs_info->fsid, + (unsigned long)btrfs_header_fsid(c), + BTRFS_FSID_SIZE); + + write_extent_buffer(c, root->fs_info->chunk_tree_uuid, + (unsigned long)btrfs_header_chunk_tree_uuid(c), + BTRFS_UUID_SIZE); + + btrfs_mark_buffer_dirty(c); + + free_extent_buffer(old); + root->node = c; + add_root_to_dirty_list(root); + return 0; +} + static struct option long_options[] = { { "super", 1, NULL, ''s'' }, { "repair", 0, NULL, 0 }, diff --git a/ctree.c b/ctree.c index 5409552..0b73bdf 100644 --- a/ctree.c +++ b/ctree.c @@ -67,7 +67,7 @@ void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p) memset(p, 0, sizeof(*p)); } -static void add_root_to_dirty_list(struct btrfs_root *root) +void add_root_to_dirty_list(struct btrfs_root *root) { if (root->track_dirty && list_empty(&root->dirty_list)) { list_add(&root->dirty_list, @@ -137,48 +137,6 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, return 0; } -int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, - struct btrfs_root *root) -{ - struct extent_buffer *c; - struct extent_buffer *old = root->node; - int level; - struct btrfs_disk_key disk_key = {0,0,0}; - - level = 0; - - c = btrfs_alloc_free_block(trans, root, - btrfs_level_size(root, 0), - root->root_key.objectid, - &disk_key, level, 0, 0); - if (IS_ERR(c)) { - c = old; - extent_buffer_get(c); - } - - memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header)); - btrfs_set_header_level(c, level); - btrfs_set_header_bytenr(c, c->start); - btrfs_set_header_generation(c, trans->transid); - btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV); - btrfs_set_header_owner(c, root->root_key.objectid); - - write_extent_buffer(c, root->fs_info->fsid, - (unsigned long)btrfs_header_fsid(c), - BTRFS_FSID_SIZE); - - write_extent_buffer(c, root->fs_info->chunk_tree_uuid, - (unsigned long)btrfs_header_chunk_tree_uuid(c), - BTRFS_UUID_SIZE); - - btrfs_mark_buffer_dirty(c); - - free_extent_buffer(old); - root->node = c; - add_root_to_dirty_list(root); - return 0; -} - /* * check if the tree block can be shared by multiple trees */ diff --git a/ctree.h b/ctree.h index 0506aa1..f96b2f0 100644 --- a/ctree.h +++ b/ctree.h @@ -2175,8 +2175,6 @@ int btrfs_check_node(struct btrfs_root *root, int btrfs_check_leaf(struct btrfs_root *root, struct btrfs_disk_key *parent_key, struct extent_buffer *buf); -int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, - struct btrfs_root *root); int btrfs_previous_item(struct btrfs_root *root, struct btrfs_path *path, u64 min_objectid, int type); @@ -2214,6 +2212,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, int start_slot, int cache_only, u64 *last_ret, struct btrfs_key *progress); void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); +void add_root_to_dirty_list(struct btrfs_root *root); struct btrfs_path *btrfs_alloc_path(void); void btrfs_free_path(struct btrfs_path *p); void btrfs_init_path(struct btrfs_path *p); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Remove some commented-out & #if 0''d code: * close_blocks() * btrfs_drop_snapshot() * btrfs_realloc_node() * btrfs_find_dead_roots() There are still some #if 0''d functions in there, but I''m hedging on those for now, they have been copied to cmds-check.c and I want to see if they can be brough back into ctree.c eventually. Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- ctree.c | 140 --------------------------------------------------------- ctree.h | 8 --- extent-tree.c | 71 ----------------------------- root-tree.c | 71 ----------------------------- 4 files changed, 0 insertions(+), 290 deletions(-) diff --git a/ctree.c b/ctree.c index 0b73bdf..b7b12a3 100644 --- a/ctree.c +++ b/ctree.c @@ -373,17 +373,6 @@ int btrfs_cow_block(struct btrfs_trans_handle *trans, } /* -static int close_blocks(u64 blocknr, u64 other, u32 blocksize) -{ - if (blocknr < other && other - (blocknr + blocksize) < 32768) - return 1; - if (blocknr > other && blocknr - (other + blocksize) < 32768) - return 1; - return 0; -} -*/ - -/* * compare two keys in a memcmp fashion */ int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2) @@ -407,135 +396,6 @@ int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2) return 0; } - -#if 0 -int btrfs_realloc_node(struct btrfs_trans_handle *trans, - struct btrfs_root *root, struct extent_buffer *parent, - int start_slot, int cache_only, u64 *last_ret, - struct btrfs_key *progress) -{ - struct extent_buffer *cur; - struct extent_buffer *tmp; - u64 blocknr; - u64 gen; - u64 search_start = *last_ret; - u64 last_block = 0; - u64 other; - u32 parent_nritems; - int end_slot; - int i; - int err = 0; - int parent_level; - int uptodate; - u32 blocksize; - int progress_passed = 0; - struct btrfs_disk_key disk_key; - - parent_level = btrfs_header_level(parent); - if (cache_only && parent_level != 1) - return 0; - - if (trans->transaction != root->fs_info->running_transaction) { - printk(KERN_CRIT "trans %Lu running %Lu\n", trans->transid, - root->fs_info->running_transaction->transid); - WARN_ON(1); - } - if (trans->transid != root->fs_info->generation) { - printk(KERN_CRIT "trans %Lu running %Lu\n", trans->transid, - root->fs_info->generation); - WARN_ON(1); - } - - parent_nritems = btrfs_header_nritems(parent); - blocksize = btrfs_level_size(root, parent_level - 1); - end_slot = parent_nritems; - - if (parent_nritems == 1) - return 0; - - for (i = start_slot; i < end_slot; i++) { - int close = 1; - - if (!parent->map_token) { - map_extent_buffer(parent, - btrfs_node_key_ptr_offset(i), - sizeof(struct btrfs_key_ptr), - &parent->map_token, &parent->kaddr, - &parent->map_start, &parent->map_len, - KM_USER1); - } - btrfs_node_key(parent, &disk_key, i); - if (!progress_passed && comp_keys(&disk_key, progress) < 0) - continue; - - progress_passed = 1; - blocknr = btrfs_node_blockptr(parent, i); - gen = btrfs_node_ptr_generation(parent, i); - if (last_block == 0) - last_block = blocknr; - - if (i > 0) { - other = btrfs_node_blockptr(parent, i - 1); - close = close_blocks(blocknr, other, blocksize); - } - if (close && i < end_slot - 2) { - other = btrfs_node_blockptr(parent, i + 1); - close = close_blocks(blocknr, other, blocksize); - } - if (close) { - last_block = blocknr; - continue; - } - if (parent->map_token) { - unmap_extent_buffer(parent, parent->map_token, - KM_USER1); - parent->map_token = NULL; - } - - cur = btrfs_find_tree_block(root, blocknr, blocksize); - if (cur) - uptodate = btrfs_buffer_uptodate(cur, gen); - else - uptodate = 0; - if (!cur || !uptodate) { - if (cache_only) { - free_extent_buffer(cur); - continue; - } - if (!cur) { - cur = read_tree_block(root, blocknr, - blocksize, gen); - } else if (!uptodate) { - btrfs_read_buffer(cur, gen); - } - } - if (search_start == 0) - search_start = last_block; - - err = __btrfs_cow_block(trans, root, cur, parent, i, - &tmp, search_start, - min(16 * blocksize, - (end_slot - i) * blocksize)); - if (err) { - free_extent_buffer(cur); - break; - } - search_start = tmp->start; - last_block = tmp->start; - *last_ret = search_start; - if (parent_level == 1) - btrfs_clear_buffer_defrag(tmp); - free_extent_buffer(tmp); - } - if (parent->map_token) { - unmap_extent_buffer(parent, parent->map_token, - KM_USER1); - parent->map_token = NULL; - } - return err; -} -#endif - /* * The leaf data grows from end-to-front in the node. * this returns the address of the start of the last item, diff --git a/ctree.h b/ctree.h index f96b2f0..a73384d 100644 --- a/ctree.h +++ b/ctree.h @@ -2207,10 +2207,6 @@ int btrfs_split_item(struct btrfs_trans_handle *trans, int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_key *key, struct btrfs_path *p, int ins_len, int cow); -int btrfs_realloc_node(struct btrfs_trans_handle *trans, - struct btrfs_root *root, struct extent_buffer *parent, - int start_slot, int cache_only, u64 *last_ret, - struct btrfs_key *progress); void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); void add_root_to_dirty_list(struct btrfs_root *root); struct btrfs_path *btrfs_alloc_path(void); @@ -2245,8 +2241,6 @@ static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf); -int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root - *root); int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, struct btrfs_key *new_key); @@ -2267,8 +2261,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root *item); int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct btrfs_root_item *item, struct btrfs_key *key); -int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid, - struct btrfs_root *latest_root); /* dir-item.c */ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, const char *name, int name_len, u64 dir, diff --git a/extent-tree.c b/extent-tree.c index 381572d..e8b6999 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -3098,77 +3098,6 @@ static int noinline walk_up_tree(struct btrfs_trans_handle *trans, return 1; } -/* - * drop the reference count on the tree rooted at ''snap''. This traverses - * the tree freeing any blocks that have a ref count of zero after being - * decremented. - */ -int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root - *root) -{ - int ret = 0; - int wret; - int level; - struct btrfs_path *path; - int i; - int orig_level; - struct btrfs_root_item *root_item = &root->root_item; - - path = btrfs_alloc_path(); - BUG_ON(!path); - - level = btrfs_header_level(root->node); - orig_level = level; - if (btrfs_disk_key_objectid(&root_item->drop_progress) == 0) { - path->nodes[level] = root->node; - extent_buffer_get(root->node); - path->slots[level] = 0; - } else { - struct btrfs_key key; - struct btrfs_disk_key found_key; - struct extent_buffer *node; - - btrfs_disk_key_to_cpu(&key, &root_item->drop_progress); - level = root_item->drop_level; - path->lowest_level = level; - wret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - if (wret < 0) { - ret = wret; - goto out; - } - node = path->nodes[level]; - btrfs_node_key(node, &found_key, path->slots[level]); - WARN_ON(memcmp(&found_key, &root_item->drop_progress, - sizeof(found_key))); - } - while(1) { - wret = walk_down_tree(trans, root, path, &level); - if (wret < 0) - ret = wret; - if (wret != 0) - break; - - wret = walk_up_tree(trans, root, path, &level); - if (wret < 0) - ret = wret; - if (wret != 0) - break; - /* - ret = -EAGAIN; - break; - */ - } - for (i = 0; i <= orig_level; i++) { - if (path->nodes[i]) { - free_extent_buffer(path->nodes[i]); - path->nodes[i] = NULL; - } - } -out: - btrfs_free_path(path); - return ret; -} - #endif int btrfs_free_block_groups(struct btrfs_fs_info *info) diff --git a/root-tree.c b/root-tree.c index ba380bd..c6b13dc 100644 --- a/root-tree.c +++ b/root-tree.c @@ -138,77 +138,6 @@ int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root return ret; } -#if 0 -int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid, - struct btrfs_root *latest) -{ - struct btrfs_root *dead_root; - struct btrfs_item *item; - struct btrfs_root_item *ri; - struct btrfs_key key; - struct btrfs_path *path; - int ret; - u32 nritems; - struct extent_buffer *leaf; - int slot; - - key.objectid = objectid; - btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); - key.offset = 0; - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - if (ret < 0) - goto err; - while(1) { - leaf = path->nodes[0]; - nritems = btrfs_header_nritems(leaf); - slot = path->slots[0]; - if (slot >= nritems) { - ret = btrfs_next_leaf(root, path); - if (ret) - break; - leaf = path->nodes[0]; - nritems = btrfs_header_nritems(leaf); - slot = path->slots[0]; - } - item = btrfs_item_nr(leaf, slot); - btrfs_item_key_to_cpu(leaf, &key, slot); - if (btrfs_key_type(&key) != BTRFS_ROOT_ITEM_KEY) - goto next; - - if (key.objectid < objectid) - goto next; - - if (key.objectid > objectid) - break; - - ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item); - if (btrfs_disk_root_refs(leaf, ri) != 0) - goto next; - - dead_root = btrfs_read_fs_root_no_radix(root->fs_info, &key); - if (IS_ERR(dead_root)) { - ret = PTR_ERR(dead_root); - goto err; - } - - ret = btrfs_add_dead_root(dead_root, latest, - &root->fs_info->dead_roots); - if (ret) - goto err; -next: - slot++; - path->slots[0]++; - } - ret = 0; -err: - btrfs_free_path(path); - return ret; -} -#endif - int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_key *key) { -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Eric Sandeen
2013-Apr-26 21:06 UTC
[PATCH 6/9] Btrfs-progs: cleanup duplicated division functions
div_factor has been implemented for two times, cleanup it. And I move them into a independent file named math.h because they are common math functions. [Eric Sandeen: port kernel commit 3fed40c to userspace] Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- extent-tree.c | 10 +--------- math.h | 33 +++++++++++++++++++++++++++++++++ volumes.c | 9 +-------- 3 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 math.h diff --git a/extent-tree.c b/extent-tree.c index e8b6999..b8403d6 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -27,6 +27,7 @@ #include "crc32c.h" #include "volumes.h" #include "free-space-cache.h" +#include "math.h" #define BLOCK_GROUP_DATA EXTENT_WRITEBACK #define BLOCK_GROUP_METADATA EXTENT_UPTODATE @@ -313,15 +314,6 @@ no_cache: goto again; } -static u64 div_factor(u64 num, int factor) -{ - if (factor == 10) - return num; - num *= factor; - num /= 10; - return num; -} - static int block_group_state_bits(u64 flags) { int bits = 0; diff --git a/math.h b/math.h new file mode 100644 index 0000000..482dba3 --- /dev/null +++ b/math.h @@ -0,0 +1,33 @@ + +/* + * Copyright (C) 2012 Fujitsu. All rights reserved. + * Written by Miao Xie <miaox@cn.fujitsu.com> + * + * 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_MATH_H +#define __BTRFS_MATH_H + +static inline u64 div_factor(u64 num, int factor) +{ + if (factor == 10) + return num; + num *= factor; + num /= 10; + return num; +} + +#endif diff --git a/volumes.c b/volumes.c index d6f81f8..aa1c3dd 100644 --- a/volumes.c +++ b/volumes.c @@ -29,6 +29,7 @@ #include "transaction.h" #include "print-tree.h" #include "volumes.h" +#include "math.h" struct stripe { struct btrfs_device *dev; @@ -623,14 +624,6 @@ int btrfs_add_system_chunk(struct btrfs_trans_handle *trans, return 0; } -static u64 div_factor(u64 num, int factor) -{ - if (factor == 10) - return num; - num *= factor; - return num / 10; -} - static u64 chunk_bytes_by_type(u64 type, u64 calc_size, int num_stripes, int sub_stripes) { -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Eric Sandeen
2013-Apr-26 21:06 UTC
[PATCH 7/9] Btrfs-progs: make extent_ref_type() match kernelspace
extent_ref_type() contains inconsequential differences between kernelspace and userspace, and has since the initial commits to each. Just make userspace look like kernelspace. Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- extent-tree.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/extent-tree.c b/extent-tree.c index b8403d6..fe74f99 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -967,17 +967,19 @@ static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans, static inline int extent_ref_type(u64 parent, u64 owner) { + int type; if (owner < BTRFS_FIRST_FREE_OBJECTID) { if (parent > 0) - return BTRFS_SHARED_BLOCK_REF_KEY; + type = BTRFS_SHARED_BLOCK_REF_KEY; else - return BTRFS_TREE_BLOCK_REF_KEY; + type = BTRFS_TREE_BLOCK_REF_KEY; } else { if (parent > 0) - return BTRFS_SHARED_DATA_REF_KEY; + type = BTRFS_SHARED_DATA_REF_KEY; else - return BTRFS_EXTENT_DATA_REF_KEY; + type = BTRFS_EXTENT_DATA_REF_KEY; } + return type; } static int find_next_key(struct btrfs_path *path, struct btrfs_key *key) -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Eric Sandeen
2013-Apr-26 21:06 UTC
[PATCH 8/9] Btrfs-progs: remove the unnecessary ''return -1;'' at the end of bin_search
The code path should not reach there. Remove it. [Eric Sandeen: port kernel commit 3fed40c to userspace] Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- ctree.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ctree.c b/ctree.c index b7b12a3..7257e6f 100644 --- a/ctree.c +++ b/ctree.c @@ -579,20 +579,18 @@ static int generic_bin_search(struct extent_buffer *eb, unsigned long p, static int bin_search(struct extent_buffer *eb, struct btrfs_key *key, int level, int *slot) { - if (level == 0) { + if (level == 0) return generic_bin_search(eb, offsetof(struct btrfs_leaf, items), sizeof(struct btrfs_item), key, btrfs_header_nritems(eb), slot); - } else { + else return generic_bin_search(eb, offsetof(struct btrfs_node, ptrs), sizeof(struct btrfs_key_ptr), key, btrfs_header_nritems(eb), slot); - } - return -1; } static noinline struct extent_buffer *read_node_slot(struct btrfs_root *root, -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Eric Sandeen
2013-Apr-26 21:06 UTC
[PATCH 9/9] Btrfs-progs: remove btrfs_init_path calls from ctree.c
btrfs_init_path was initially used when the path objects were on the stack. Now all the work is done by btrfs_alloc_path and btrfs_init_path isn''t required. This patch removes it, and just uses kmem_cache_zalloc to zero out the object. [Eric Sandeen: port kernel commit e00f730 to userspace] (Note, the rest of userspace has an on-path stack, so the actual function remains for now). Signed-off-by: Chris Mason <chris.mason@oracle.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> --- ctree.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-) diff --git a/ctree.c b/ctree.c index 7257e6f..24ca6f3 100644 --- a/ctree.c +++ b/ctree.c @@ -42,11 +42,7 @@ inline void btrfs_init_path(struct btrfs_path *p) struct btrfs_path *btrfs_alloc_path(void) { struct btrfs_path *path; - path = kmalloc(sizeof(struct btrfs_path), GFP_NOFS); - if (path) { - btrfs_init_path(path); - path->reada = 0; - } + path = kzalloc(sizeof(struct btrfs_path), GFP_NOFS); return path; } -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html