aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode-map.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/inode-map.c')
-rw-r--r--fs/btrfs/inode-map.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index 298346ae1481..cd6171c2da42 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -32,7 +32,8 @@ int btrfs_find_highest_inode(struct btrfs_root *root, u64 *objectid)
32 path = btrfs_alloc_path(); 32 path = btrfs_alloc_path();
33 BUG_ON(!path); 33 BUG_ON(!path);
34 34
35 search_key.objectid = (u64)-1; 35 search_key.objectid = BTRFS_LAST_FREE_OBJECTID;
36 search_key.type = -1;
36 search_key.offset = (u64)-1; 37 search_key.offset = (u64)-1;
37 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); 38 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
38 if (ret < 0) 39 if (ret < 0)
@@ -70,16 +71,17 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
70 u64 search_start = dirid; 71 u64 search_start = dirid;
71 72
72 mutex_lock(&root->objectid_mutex); 73 mutex_lock(&root->objectid_mutex);
73 if (root->last_inode_alloc) { 74 if (root->last_inode_alloc >= BTRFS_FIRST_FREE_OBJECTID &&
75 root->last_inode_alloc < BTRFS_LAST_FREE_OBJECTID) {
74 *objectid = ++root->last_inode_alloc; 76 *objectid = ++root->last_inode_alloc;
75 mutex_unlock(&root->objectid_mutex); 77 mutex_unlock(&root->objectid_mutex);
76 return 0; 78 return 0;
77 } 79 }
78 path = btrfs_alloc_path(); 80 path = btrfs_alloc_path();
79 BUG_ON(!path); 81 BUG_ON(!path);
80 search_start = root->last_inode_alloc;
81 search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); 82 search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID);
82 search_key.objectid = search_start; 83 search_key.objectid = search_start;
84 search_key.type = 0;
83 search_key.offset = 0; 85 search_key.offset = 0;
84 86
85 btrfs_init_path(path); 87 btrfs_init_path(path);
@@ -88,9 +90,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
88 if (ret < 0) 90 if (ret < 0)
89 goto error; 91 goto error;
90 92
91 if (path->slots[0] > 0)
92 path->slots[0]--;
93
94 while (1) { 93 while (1) {
95 l = path->nodes[0]; 94 l = path->nodes[0];
96 slot = path->slots[0]; 95 slot = path->slots[0];
@@ -120,13 +119,15 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
120 } 119 }
121 } 120 }
122 } 121 }
122 if (key.objectid >= BTRFS_LAST_FREE_OBJECTID)
123 break;
123 start_found = 1; 124 start_found = 1;
124 last_ino = key.objectid + 1; 125 last_ino = key.objectid + 1;
125 path->slots[0]++; 126 path->slots[0]++;
126 } 127 }
127 // FIXME -ENOSPC 128 // FIXME -ENOSPC
129 BUG_ON(1);
128found: 130found:
129 root->last_inode_alloc = *objectid;
130 btrfs_release_path(root, path); 131 btrfs_release_path(root, path);
131 btrfs_free_path(path); 132 btrfs_free_path(path);
132 BUG_ON(*objectid < search_start); 133 BUG_ON(*objectid < search_start);