diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-04-02 14:53:59 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-04-02 14:53:59 -0400 |
commit | 7cfcc17e7f2334a0503331264c1340de4e564c85 (patch) | |
tree | 4ce6ac8520382673006845ec20b2ad83abc9258a /fs/btrfs/inode-map.c | |
parent | 5caf2a002901f0fde475371c4bf1c553b51884af (diff) |
Btrfs: corruptions fixed
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/inode-map.c')
-rw-r--r-- | fs/btrfs/inode-map.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c index fa4adb81b149..b3de823eb628 100644 --- a/fs/btrfs/inode-map.c +++ b/fs/btrfs/inode-map.c | |||
@@ -10,7 +10,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, | |||
10 | struct btrfs_root *fs_root, | 10 | struct btrfs_root *fs_root, |
11 | u64 dirid, u64 *objectid) | 11 | u64 dirid, u64 *objectid) |
12 | { | 12 | { |
13 | struct btrfs_path path; | 13 | struct btrfs_path *path; |
14 | struct btrfs_key key; | 14 | struct btrfs_key key; |
15 | int ret; | 15 | int ret; |
16 | u64 hole_size = 0; | 16 | u64 hole_size = 0; |
@@ -31,20 +31,22 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, | |||
31 | btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); | 31 | btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); |
32 | search_key.offset = 0; | 32 | search_key.offset = 0; |
33 | 33 | ||
34 | btrfs_init_path(&path); | 34 | path = btrfs_alloc_path(); |
35 | BUG_ON(!path); | ||
36 | btrfs_init_path(path); | ||
35 | start_found = 0; | 37 | start_found = 0; |
36 | ret = btrfs_search_slot(trans, root, &search_key, &path, 0, 0); | 38 | ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0); |
37 | if (ret < 0) | 39 | if (ret < 0) |
38 | goto error; | 40 | goto error; |
39 | 41 | ||
40 | if (path.slots[0] > 0) | 42 | if (path->slots[0] > 0) |
41 | path.slots[0]--; | 43 | path->slots[0]--; |
42 | 44 | ||
43 | while (1) { | 45 | while (1) { |
44 | l = btrfs_buffer_leaf(path.nodes[0]); | 46 | l = btrfs_buffer_leaf(path->nodes[0]); |
45 | slot = path.slots[0]; | 47 | slot = path->slots[0]; |
46 | if (slot >= btrfs_header_nritems(&l->header)) { | 48 | if (slot >= btrfs_header_nritems(&l->header)) { |
47 | ret = btrfs_next_leaf(root, &path); | 49 | ret = btrfs_next_leaf(root, path); |
48 | if (ret == 0) | 50 | if (ret == 0) |
49 | continue; | 51 | continue; |
50 | if (ret < 0) | 52 | if (ret < 0) |
@@ -72,17 +74,19 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, | |||
72 | } | 74 | } |
73 | start_found = 1; | 75 | start_found = 1; |
74 | last_ino = key.objectid + 1; | 76 | last_ino = key.objectid + 1; |
75 | path.slots[0]++; | 77 | path->slots[0]++; |
76 | } | 78 | } |
77 | // FIXME -ENOSPC | 79 | // FIXME -ENOSPC |
78 | found: | 80 | found: |
79 | root->fs_info->last_inode_alloc = *objectid; | 81 | root->fs_info->last_inode_alloc = *objectid; |
80 | root->fs_info->last_inode_alloc_dirid = dirid; | 82 | root->fs_info->last_inode_alloc_dirid = dirid; |
81 | btrfs_release_path(root, &path); | 83 | btrfs_release_path(root, path); |
84 | btrfs_free_path(path); | ||
82 | BUG_ON(*objectid < search_start); | 85 | BUG_ON(*objectid < search_start); |
83 | return 0; | 86 | return 0; |
84 | error: | 87 | error: |
85 | btrfs_release_path(root, &path); | 88 | btrfs_release_path(root, path); |
89 | btrfs_free_path(path); | ||
86 | return ret; | 90 | return ret; |
87 | } | 91 | } |
88 | 92 | ||
@@ -91,7 +95,7 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, | |||
91 | u64 objectid, struct btrfs_key *location) | 95 | u64 objectid, struct btrfs_key *location) |
92 | { | 96 | { |
93 | int ret = 0; | 97 | int ret = 0; |
94 | struct btrfs_path path; | 98 | struct btrfs_path *path; |
95 | struct btrfs_inode_map_item *inode_item; | 99 | struct btrfs_inode_map_item *inode_item; |
96 | struct btrfs_key key; | 100 | struct btrfs_key key; |
97 | struct btrfs_root *inode_root = fs_root->fs_info->inode_root; | 101 | struct btrfs_root *inode_root = fs_root->fs_info->inode_root; |
@@ -100,18 +104,21 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, | |||
100 | key.flags = 0; | 104 | key.flags = 0; |
101 | btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY); | 105 | btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY); |
102 | key.offset = 0; | 106 | key.offset = 0; |
103 | btrfs_init_path(&path); | 107 | path = btrfs_alloc_path(); |
104 | ret = btrfs_insert_empty_item(trans, inode_root, &path, &key, | 108 | BUG_ON(!path); |
109 | btrfs_init_path(path); | ||
110 | ret = btrfs_insert_empty_item(trans, inode_root, path, &key, | ||
105 | sizeof(struct btrfs_inode_map_item)); | 111 | sizeof(struct btrfs_inode_map_item)); |
106 | if (ret) | 112 | if (ret) |
107 | goto out; | 113 | goto out; |
108 | 114 | ||
109 | inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), | 115 | inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), |
110 | path.slots[0], struct btrfs_inode_map_item); | 116 | path->slots[0], struct btrfs_inode_map_item); |
111 | btrfs_cpu_key_to_disk(&inode_item->key, location); | 117 | btrfs_cpu_key_to_disk(&inode_item->key, location); |
112 | btrfs_mark_buffer_dirty(path.nodes[0]); | 118 | btrfs_mark_buffer_dirty(path->nodes[0]); |
113 | out: | 119 | out: |
114 | btrfs_release_path(inode_root, &path); | 120 | btrfs_release_path(inode_root, path); |
121 | btrfs_free_path(path); | ||
115 | return ret; | 122 | return ret; |
116 | } | 123 | } |
117 | 124 | ||