diff options
Diffstat (limited to 'fs/btrfs/inode-map.c')
-rw-r--r-- | fs/btrfs/inode-map.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c index b3de823eb628..329edb42897e 100644 --- a/fs/btrfs/inode-map.c +++ b/fs/btrfs/inode-map.c | |||
@@ -22,17 +22,31 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, | |||
22 | struct btrfs_key search_key; | 22 | struct btrfs_key search_key; |
23 | u64 search_start = dirid; | 23 | u64 search_start = dirid; |
24 | 24 | ||
25 | if (fs_root->fs_info->last_inode_alloc_dirid == dirid) | 25 | path = btrfs_alloc_path(); |
26 | search_start = fs_root->fs_info->last_inode_alloc; | 26 | BUG_ON(!path); |
27 | search_key.flags = 0; | ||
28 | btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); | ||
27 | 29 | ||
30 | search_start = fs_root->fs_info->last_inode_alloc; | ||
31 | if (search_start == 0) { | ||
32 | struct btrfs_disk_key *last_key; | ||
33 | btrfs_init_path(path); | ||
34 | search_key.objectid = (u64)-1; | ||
35 | search_key.offset = (u64)-1; | ||
36 | ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0); | ||
37 | if (ret < 0) | ||
38 | goto error; | ||
39 | BUG_ON(ret == 0); | ||
40 | if (path->slots[0] > 0) | ||
41 | path->slots[0]--; | ||
42 | l = btrfs_buffer_leaf(path->nodes[0]); | ||
43 | last_key = &l->items[path->slots[0]].key; | ||
44 | search_start = btrfs_disk_key_objectid(last_key); | ||
45 | } | ||
28 | search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); | 46 | search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); |
29 | search_key.objectid = search_start; | 47 | search_key.objectid = search_start; |
30 | search_key.flags = 0; | ||
31 | btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); | ||
32 | search_key.offset = 0; | 48 | search_key.offset = 0; |
33 | 49 | ||
34 | path = btrfs_alloc_path(); | ||
35 | BUG_ON(!path); | ||
36 | btrfs_init_path(path); | 50 | btrfs_init_path(path); |
37 | start_found = 0; | 51 | start_found = 0; |
38 | ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0); | 52 | ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0); |
@@ -79,7 +93,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, | |||
79 | // FIXME -ENOSPC | 93 | // FIXME -ENOSPC |
80 | found: | 94 | found: |
81 | root->fs_info->last_inode_alloc = *objectid; | 95 | root->fs_info->last_inode_alloc = *objectid; |
82 | root->fs_info->last_inode_alloc_dirid = dirid; | ||
83 | btrfs_release_path(root, path); | 96 | btrfs_release_path(root, path); |
84 | btrfs_free_path(path); | 97 | btrfs_free_path(path); |
85 | BUG_ON(*objectid < search_start); | 98 | BUG_ON(*objectid < search_start); |