diff options
-rw-r--r-- | fs/btrfs/ctree.h | 6 | ||||
-rw-r--r-- | fs/btrfs/dir-test.c | 39 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 2 | ||||
-rw-r--r-- | fs/btrfs/print-tree.c | 5 |
4 files changed, 43 insertions, 9 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 68e3da274f17..b30b2ce72455 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -219,6 +219,7 @@ struct btrfs_fs_info { | |||
219 | struct list_head cache; | 219 | struct list_head cache; |
220 | u64 last_inode_alloc; | 220 | u64 last_inode_alloc; |
221 | u64 last_inode_alloc_dirid; | 221 | u64 last_inode_alloc_dirid; |
222 | u64 generation; | ||
222 | int cache_size; | 223 | int cache_size; |
223 | int fp; | 224 | int fp; |
224 | struct btrfs_trans_handle *running_transaction; | 225 | struct btrfs_trans_handle *running_transaction; |
@@ -802,4 +803,9 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, | |||
802 | int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans, | 803 | int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans, |
803 | struct btrfs_root *root, struct btrfs_path *path, | 804 | struct btrfs_root *root, struct btrfs_path *path, |
804 | u64 objectid, int mod); | 805 | u64 objectid, int mod); |
806 | int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root | ||
807 | *root, u64 objectid, struct btrfs_inode_item | ||
808 | *inode_item); | ||
809 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root | ||
810 | *root, struct btrfs_path *path, u64 objectid, int mod); | ||
805 | #endif | 811 | #endif |
diff --git a/fs/btrfs/dir-test.c b/fs/btrfs/dir-test.c index 56f06c3ba573..8fc77c83a351 100644 --- a/fs/btrfs/dir-test.c +++ b/fs/btrfs/dir-test.c | |||
@@ -39,6 +39,13 @@ again: | |||
39 | return 0; | 39 | return 0; |
40 | } | 40 | } |
41 | 41 | ||
42 | static void initial_inode_init(struct btrfs_root *root, | ||
43 | struct btrfs_inode_item *inode_item) | ||
44 | { | ||
45 | memset(inode_item, 0, sizeof(*inode_item)); | ||
46 | btrfs_set_inode_generation(inode_item, root->fs_info->generation); | ||
47 | } | ||
48 | |||
42 | static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root, | 49 | static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
43 | struct radix_tree_root *radix) | 50 | struct radix_tree_root *radix) |
44 | { | 51 | { |
@@ -48,6 +55,7 @@ static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
48 | u64 objectid; | 55 | u64 objectid; |
49 | struct btrfs_path path; | 56 | struct btrfs_path path; |
50 | struct btrfs_key inode_map; | 57 | struct btrfs_key inode_map; |
58 | struct btrfs_inode_item inode_item; | ||
51 | 59 | ||
52 | find_num(radix, &oid, 0); | 60 | find_num(radix, &oid, 0); |
53 | sprintf(buf, "str-%lu", oid); | 61 | sprintf(buf, "str-%lu", oid); |
@@ -63,6 +71,11 @@ static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
63 | ret = btrfs_insert_inode_map(trans, root, objectid, &inode_map); | 71 | ret = btrfs_insert_inode_map(trans, root, objectid, &inode_map); |
64 | if (ret) | 72 | if (ret) |
65 | goto error; | 73 | goto error; |
74 | |||
75 | initial_inode_init(root, &inode_item); | ||
76 | ret = btrfs_insert_inode(trans, root, objectid, &inode_item); | ||
77 | if (ret) | ||
78 | goto error; | ||
66 | ret = btrfs_insert_dir_item(trans, root, buf, strlen(buf), dir_oid, | 79 | ret = btrfs_insert_dir_item(trans, root, buf, strlen(buf), dir_oid, |
67 | objectid, 1); | 80 | objectid, 1); |
68 | if (ret) | 81 | if (ret) |
@@ -143,7 +156,6 @@ static int del_dir_item(struct btrfs_trans_handle *trans, | |||
143 | unsigned long *ptr; | 156 | unsigned long *ptr; |
144 | u64 file_objectid; | 157 | u64 file_objectid; |
145 | struct btrfs_dir_item *di; | 158 | struct btrfs_dir_item *di; |
146 | struct btrfs_path map_path; | ||
147 | 159 | ||
148 | /* find the inode number of the file */ | 160 | /* find the inode number of the file */ |
149 | di = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0], | 161 | di = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0], |
@@ -153,20 +165,31 @@ static int del_dir_item(struct btrfs_trans_handle *trans, | |||
153 | /* delete the directory item */ | 165 | /* delete the directory item */ |
154 | ret = btrfs_del_item(trans, root, path); | 166 | ret = btrfs_del_item(trans, root, path); |
155 | if (ret) | 167 | if (ret) |
156 | goto out; | 168 | goto out_release; |
169 | btrfs_release_path(root, path); | ||
170 | |||
171 | /* delete the inode */ | ||
172 | btrfs_init_path(path); | ||
173 | ret = btrfs_lookup_inode(trans, root, path, file_objectid, -1); | ||
174 | if (ret) | ||
175 | goto out_release; | ||
176 | ret = btrfs_del_item(trans, root, path); | ||
177 | if (ret) | ||
178 | goto out_release; | ||
179 | btrfs_release_path(root, path); | ||
157 | 180 | ||
158 | /* delete the inode mapping */ | 181 | /* delete the inode mapping */ |
159 | btrfs_init_path(&map_path); | 182 | btrfs_init_path(path); |
160 | ret = btrfs_lookup_inode_map(trans, root, &map_path, file_objectid, -1); | 183 | ret = btrfs_lookup_inode_map(trans, root, path, file_objectid, -1); |
161 | if (ret) | 184 | if (ret) |
162 | goto out_release; | 185 | goto out_release; |
163 | ret = btrfs_del_item(trans, root->fs_info->inode_root, &map_path); | 186 | ret = btrfs_del_item(trans, root->fs_info->inode_root, path); |
164 | if (ret) | 187 | if (ret) |
165 | goto out_release; | 188 | goto out_release; |
166 | 189 | ||
167 | if (root->fs_info->last_inode_alloc > file_objectid) | 190 | if (root->fs_info->last_inode_alloc > file_objectid) |
168 | root->fs_info->last_inode_alloc = file_objectid; | 191 | root->fs_info->last_inode_alloc = file_objectid; |
169 | btrfs_release_path(root, &map_path); | 192 | btrfs_release_path(root, path); |
170 | ptr = radix_tree_delete(radix, radix_index); | 193 | ptr = radix_tree_delete(radix, radix_index); |
171 | if (!ptr) { | 194 | if (!ptr) { |
172 | ret = -5555; | 195 | ret = -5555; |
@@ -174,7 +197,7 @@ static int del_dir_item(struct btrfs_trans_handle *trans, | |||
174 | } | 197 | } |
175 | return 0; | 198 | return 0; |
176 | out_release: | 199 | out_release: |
177 | btrfs_release_path(root, &map_path); | 200 | btrfs_release_path(root, path); |
178 | out: | 201 | out: |
179 | printf("failed to delete %lu %d\n", radix_index, ret); | 202 | printf("failed to delete %lu %d\n", radix_index, ret); |
180 | return -1; | 203 | return -1; |
@@ -201,7 +224,6 @@ static int del_one(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
201 | ret = del_dir_item(trans, root, radix, oid, &path); | 224 | ret = del_dir_item(trans, root, radix, oid, &path); |
202 | if (ret) | 225 | if (ret) |
203 | goto out_release; | 226 | goto out_release; |
204 | btrfs_release_path(root, &path); | ||
205 | return ret; | 227 | return ret; |
206 | out_release: | 228 | out_release: |
207 | btrfs_release_path(root, &path); | 229 | btrfs_release_path(root, &path); |
@@ -312,7 +334,6 @@ static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root | |||
312 | found); | 334 | found); |
313 | return -1; | 335 | return -1; |
314 | } | 336 | } |
315 | btrfs_release_path(root, &path); | ||
316 | if (!keep_running) | 337 | if (!keep_running) |
317 | break; | 338 | break; |
318 | } | 339 | } |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 1849a99690c8..bacaa38ea82e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -226,6 +226,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, struct | |||
226 | 226 | ||
227 | ret = btrfs_del_root(trans, root->fs_info->tree_root, &snap_key); | 227 | ret = btrfs_del_root(trans, root->fs_info->tree_root, &snap_key); |
228 | BUG_ON(ret); | 228 | BUG_ON(ret); |
229 | root->fs_info->generation = root->root_key.offset + 1; | ||
229 | 230 | ||
230 | return ret; | 231 | return ret; |
231 | } | 232 | } |
@@ -328,6 +329,7 @@ struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super) | |||
328 | root->commit_root = root->node; | 329 | root->commit_root = root->node; |
329 | root->node->count++; | 330 | root->node->count++; |
330 | root->ref_cows = 1; | 331 | root->ref_cows = 1; |
332 | root->fs_info->generation = root->root_key.offset + 1; | ||
331 | return root; | 333 | return root; |
332 | } | 334 | } |
333 | 335 | ||
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index f250e5fad773..f53b99da12f3 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c | |||
@@ -14,6 +14,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) | |||
14 | struct btrfs_root_item *ri; | 14 | struct btrfs_root_item *ri; |
15 | struct btrfs_dir_item *di; | 15 | struct btrfs_dir_item *di; |
16 | struct btrfs_inode_map_item *mi; | 16 | struct btrfs_inode_map_item *mi; |
17 | struct btrfs_inode_item *ii; | ||
17 | u32 type; | 18 | u32 type; |
18 | 19 | ||
19 | printf("leaf %Lu total ptrs %d free space %d\n", | 20 | printf("leaf %Lu total ptrs %d free space %d\n", |
@@ -32,6 +33,10 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) | |||
32 | btrfs_item_size(item)); | 33 | btrfs_item_size(item)); |
33 | switch (type) { | 34 | switch (type) { |
34 | case BTRFS_INODE_ITEM_KEY: | 35 | case BTRFS_INODE_ITEM_KEY: |
36 | ii = btrfs_item_ptr(l, i, struct btrfs_inode_item); | ||
37 | printf("\t\tinode generation %Lu size %Lu\n", | ||
38 | btrfs_inode_generation(ii), | ||
39 | btrfs_inode_size(ii)); | ||
35 | break; | 40 | break; |
36 | case BTRFS_DIR_ITEM_KEY: | 41 | case BTRFS_DIR_ITEM_KEY: |
37 | di = btrfs_item_ptr(l, i, struct btrfs_dir_item); | 42 | di = btrfs_item_ptr(l, i, struct btrfs_dir_item); |