3 #include "kerncompat.h"
4 #include "radix-tree.h"
7 #include "transaction.h"
10 * walks the btree of allocated inodes and find a hole.
12 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
13 struct btrfs_root *root,
14 u64 dirid, u64 *objectid)
16 struct btrfs_path path;
24 struct btrfs_key search_key;
25 u64 search_start = dirid;
27 if (root->fs_info->last_inode_alloc_dirid == dirid)
28 search_start = root->fs_info->last_inode_alloc;
30 if (search_start < BTRFS_FIRST_FREE_OBJECTID)
31 search_start = BTRFS_FIRST_FREE_OBJECTID;
32 search_key.objectid = search_start;
34 search_key.offset = 0;
36 btrfs_init_path(&path);
38 ret = btrfs_search_slot(trans, root, &search_key, &path, 0, 0);
42 if (path.slots[0] > 0)
46 l = &path.nodes[0]->leaf;
48 if (slot >= btrfs_header_nritems(&l->header)) {
49 ret = btrfs_next_leaf(root, &path);
55 *objectid = search_start;
59 *objectid = last_ino > search_start ?
60 last_ino : search_start;
63 btrfs_disk_key_to_cpu(&key, &l->items[slot].key);
64 if (key.objectid >= search_start) {
66 if (last_ino < search_start)
67 last_ino = search_start;
68 hole_size = key.objectid - last_ino;
76 last_ino = key.objectid + 1;
81 root->fs_info->last_inode_alloc = *objectid;
82 root->fs_info->last_inode_alloc_dirid = dirid;
83 btrfs_release_path(root, &path);
84 BUG_ON(*objectid < search_start);
87 btrfs_release_path(root, &path);