diff options
author | Zheng Yan <zheng.yan@oracle.com> | 2008-09-05 16:43:53 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:07 -0400 |
commit | 6527cdbe68a27a2ee745f36d001aa32d0f46f370 (patch) | |
tree | 2525855633856050a854cabd6dc46b3c955d3b40 /fs/btrfs | |
parent | b214107eda845f9a5851ae198f5b972e0dc30c45 (diff) |
Btrfs: Update find free objectid function for orphan cleanup code
Orphan items use BTRFS_ORPHAN_OBJECTID (-5UUL) as key objectid. This
affects the find free objectid functions, inode objectid can easily
overflow after orphan file cleanup.
---
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ctree.h | 3 | ||||
-rw-r--r-- | fs/btrfs/inode-map.c | 15 |
2 files changed, 10 insertions, 8 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 754c738ec2e8..2ed6918f32e5 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -82,9 +82,10 @@ struct btrfs_ordered_sum; | |||
82 | #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL | 82 | #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * All files have objectids higher than this. | 85 | * All files have objectids in this range. |
86 | */ | 86 | */ |
87 | #define BTRFS_FIRST_FREE_OBJECTID 256ULL | 87 | #define BTRFS_FIRST_FREE_OBJECTID 256ULL |
88 | #define BTRFS_LAST_FREE_OBJECTID -256ULL | ||
88 | #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL | 89 | #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL |
89 | 90 | ||
90 | 91 | ||
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); | ||
128 | found: | 130 | found: |
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); |