X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=inode-map.c;h=9000e69b8d6fa5931840a6d793ced91baeb10a81;hb=6af3cc08ddb5c0165d357ffa36422c2716ebd2a0;hp=ab74977adf5c8e219b56b9e4da1490b0c5b08125;hpb=7777e63b425f1444d2472ea05a6b2b9cf865f35b;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/inode-map.c b/inode-map.c index ab74977..9000e69 100644 --- a/inode-map.c +++ b/inode-map.c @@ -19,38 +19,7 @@ #include "ctree.h" #include "disk-io.h" #include "transaction.h" - -int btrfs_find_highest_inode(struct btrfs_root *root, u64 *objectid) -{ - struct btrfs_path *path; - int ret; - struct extent_buffer *l; - struct btrfs_key search_key; - struct btrfs_key found_key; - int slot; - - path = btrfs_alloc_path(); - BUG_ON(!path); - - search_key.objectid = (u64)-1; - search_key.offset = (u64)-1; - ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); - if (ret < 0) - goto error; - BUG_ON(ret == 0); - if (path->slots[0] > 0) { - slot = path->slots[0] - 1; - l = path->nodes[0]; - btrfs_item_key_to_cpu(l, &found_key, slot); - *objectid = found_key.objectid; - } else { - *objectid = BTRFS_FIRST_FREE_OBJECTID; - } - ret = 0; -error: - btrfs_free_path(path); - return ret; -} +#include "internal.h" /* * walks the btree of allocated inodes and find a hole. @@ -62,7 +31,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, struct btrfs_path *path; struct btrfs_key key; int ret; - u64 hole_size = 0; int slot = 0; u64 last_ino = 0; int start_found; @@ -71,11 +39,15 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, u64 search_start = dirid; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; + search_start = root->last_inode_alloc; - search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); + search_start = max((unsigned long long)search_start, + BTRFS_FIRST_FREE_OBJECTID); search_key.objectid = search_start; search_key.offset = 0; + search_key.type = 0; btrfs_init_path(path); start_found = 0; @@ -109,8 +81,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, if (start_found) { if (last_ino < search_start) last_ino = search_start; - hole_size = key.objectid - last_ino; - if (hole_size > 0) { + if (key.objectid > last_ino) { *objectid = last_ino; goto found; } @@ -123,12 +94,10 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, // FIXME -ENOSPC found: root->last_inode_alloc = *objectid; - btrfs_release_path(root, path); btrfs_free_path(path); BUG_ON(*objectid < search_start); return 0; error: - btrfs_release_path(root, path); btrfs_free_path(path); return ret; }