aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/btrfs_inode.h2
-rw-r--r--fs/btrfs/ctree.h39
-rw-r--r--fs/btrfs/disk-io.c25
-rw-r--r--fs/btrfs/inode-item.c2
-rw-r--r--fs/btrfs/inode-map.c65
-rw-r--r--fs/btrfs/print-tree.c8
-rw-r--r--fs/btrfs/super.c89
-rw-r--r--fs/btrfs/transaction.c7
8 files changed, 33 insertions, 204 deletions
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index 3439ffb467b5..43a4f1ddb375 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -2,11 +2,9 @@
2#define __BTRFS_I__ 2#define __BTRFS_I__
3 3
4struct btrfs_inode { 4struct btrfs_inode {
5 u32 magic;
6 struct btrfs_root *root; 5 struct btrfs_root *root;
7 struct btrfs_key location; 6 struct btrfs_key location;
8 struct inode vfs_inode; 7 struct inode vfs_inode;
9 u32 magic2;
10}; 8};
11static inline struct btrfs_inode *BTRFS_I(struct inode *inode) 9static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
12{ 10{
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 2cbcaaeac9e5..5103709bb2b9 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -14,9 +14,8 @@ extern struct kmem_cache *btrfs_path_cachep;
14 14
15#define BTRFS_ROOT_TREE_OBJECTID 1ULL 15#define BTRFS_ROOT_TREE_OBJECTID 1ULL
16#define BTRFS_EXTENT_TREE_OBJECTID 2ULL 16#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
17#define BTRFS_INODE_MAP_OBJECTID 3ULL 17#define BTRFS_FS_TREE_OBJECTID 3ULL
18#define BTRFS_FS_TREE_OBJECTID 4ULL 18#define BTRFS_FIRST_FREE_OBJECTID 4ULL
19#define BTRFS_FIRST_FREE_OBJECTID 5ULL
20 19
21/* 20/*
22 * we can actually store much bigger names, but lets not confuse the rest 21 * we can actually store much bigger names, but lets not confuse the rest
@@ -62,7 +61,6 @@ struct btrfs_header {
62 __le64 blocknr; /* which block this node is supposed to live in */ 61 __le64 blocknr; /* which block this node is supposed to live in */
63 __le64 generation; 62 __le64 generation;
64 __le64 parentid; /* objectid of the tree root */ 63 __le64 parentid; /* objectid of the tree root */
65 __le32 ham;
66 __le16 nritems; 64 __le16 nritems;
67 __le16 flags; 65 __le16 flags;
68 u8 level; 66 u8 level;
@@ -226,23 +224,16 @@ struct btrfs_csum_item {
226 u8 csum[BTRFS_CSUM_SIZE]; 224 u8 csum[BTRFS_CSUM_SIZE];
227} __attribute__ ((__packed__)); 225} __attribute__ ((__packed__));
228 226
229struct btrfs_inode_map_item {
230 u32 refs;
231} __attribute__ ((__packed__));
232
233struct crypto_hash; 227struct crypto_hash;
234struct btrfs_fs_info { 228struct btrfs_fs_info {
235 struct btrfs_root *extent_root; 229 struct btrfs_root *extent_root;
236 struct btrfs_root *tree_root; 230 struct btrfs_root *tree_root;
237 struct btrfs_root *inode_root;
238 struct btrfs_key current_insert; 231 struct btrfs_key current_insert;
239 struct btrfs_key last_insert; 232 struct btrfs_key last_insert;
240 struct radix_tree_root fs_roots_radix; 233 struct radix_tree_root fs_roots_radix;
241 struct radix_tree_root pending_del_radix; 234 struct radix_tree_root pending_del_radix;
242 struct radix_tree_root pinned_radix; 235 struct radix_tree_root pinned_radix;
243 u64 last_inode_alloc;
244 u64 generation; 236 u64 generation;
245 u64 highest_inode;
246 struct btrfs_transaction *running_transaction; 237 struct btrfs_transaction *running_transaction;
247 struct btrfs_super_block *disk_super; 238 struct btrfs_super_block *disk_super;
248 struct buffer_head *sb_buffer; 239 struct buffer_head *sb_buffer;
@@ -272,6 +263,8 @@ struct btrfs_root {
272 u32 blocksize; 263 u32 blocksize;
273 int ref_cows; 264 int ref_cows;
274 u32 type; 265 u32 type;
266 u64 highest_inode;
267 u64 last_inode_alloc;
275}; 268};
276 269
277/* the lower bits in the key flags defines the item type */ 270/* the lower bits in the key flags defines the item type */
@@ -321,15 +314,10 @@ struct btrfs_root {
321#define BTRFS_EXTENT_ITEM_KEY 8 314#define BTRFS_EXTENT_ITEM_KEY 8
322 315
323/* 316/*
324 * the inode map records which inode numbers are in use and where
325 * they actually live on disk
326 */
327#define BTRFS_INODE_MAP_ITEM_KEY 9
328/*
329 * string items are for debugging. They just store a short string of 317 * string items are for debugging. They just store a short string of
330 * data in the FS 318 * data in the FS
331 */ 319 */
332#define BTRFS_STRING_ITEM_KEY 10 320#define BTRFS_STRING_ITEM_KEY 9
333 321
334static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) 322static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
335{ 323{
@@ -883,17 +871,6 @@ static inline void btrfs_set_file_extent_num_blocks(struct
883 e->num_blocks = cpu_to_le64(val); 871 e->num_blocks = cpu_to_le64(val);
884} 872}
885 873
886static inline u32 btrfs_inode_map_refs(struct btrfs_inode_map_item *m)
887{
888 return le32_to_cpu(m->refs);
889}
890
891static inline void btrfs_set_inode_map_refs(struct btrfs_inode_map_item *m,
892 u32 val)
893{
894 m->refs = cpu_to_le32(val);
895}
896
897static inline struct btrfs_root *btrfs_sb(struct super_block *sb) 874static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
898{ 875{
899 return sb->s_fs_info; 876 return sb->s_fs_info;
@@ -996,12 +973,6 @@ int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
996int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, 973int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
997 struct btrfs_root *fs_root, 974 struct btrfs_root *fs_root,
998 u64 dirid, u64 *objectid); 975 u64 dirid, u64 *objectid);
999int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
1000 struct btrfs_root *root,
1001 u64 objectid, struct btrfs_key *location);
1002int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
1003 struct btrfs_root *root, struct btrfs_path *path,
1004 u64 objectid, int mod);
1005int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid); 976int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1006 977
1007/* inode-item.c */ 978/* inode-item.c */
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6b097ede80b1..760fdc9a7664 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -264,6 +264,8 @@ static int __setup_root(int blocksize,
264 root->fs_info = fs_info; 264 root->fs_info = fs_info;
265 root->objectid = objectid; 265 root->objectid = objectid;
266 root->last_trans = 0; 266 root->last_trans = 0;
267 root->highest_inode = 0;
268 root->last_inode_alloc = 0;
267 memset(&root->root_key, 0, sizeof(root->root_key)); 269 memset(&root->root_key, 0, sizeof(root->root_key));
268 memset(&root->root_item, 0, sizeof(root->root_item)); 270 memset(&root->root_item, 0, sizeof(root->root_item));
269 return 0; 271 return 0;
@@ -295,6 +297,7 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
295 struct btrfs_root *tree_root = fs_info->tree_root; 297 struct btrfs_root *tree_root = fs_info->tree_root;
296 struct btrfs_path *path; 298 struct btrfs_path *path;
297 struct btrfs_leaf *l; 299 struct btrfs_leaf *l;
300 u64 highest_inode;
298 int ret = 0; 301 int ret = 0;
299 302
300printk("read_fs_root looking for %Lu %Lu %u\n", location->objectid, location->offset, location->flags); 303printk("read_fs_root looking for %Lu %Lu %u\n", location->objectid, location->offset, location->flags);
@@ -354,6 +357,12 @@ printk("radix_tree_insert gives us %d\n", ret);
354 kfree(root); 357 kfree(root);
355 return ERR_PTR(ret); 358 return ERR_PTR(ret);
356 } 359 }
360 ret = btrfs_find_highest_inode(root, &highest_inode);
361 if (ret == 0) {
362 root->highest_inode = highest_inode;
363 root->last_inode_alloc = highest_inode;
364printk("highest inode is %Lu\n", highest_inode);
365 }
357printk("all worked\n"); 366printk("all worked\n");
358 return root; 367 return root;
359} 368}
@@ -364,8 +373,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
364 GFP_NOFS); 373 GFP_NOFS);
365 struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root), 374 struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root),
366 GFP_NOFS); 375 GFP_NOFS);
367 struct btrfs_root *inode_root = kmalloc(sizeof(struct btrfs_root),
368 GFP_NOFS);
369 struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info), 376 struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
370 GFP_NOFS); 377 GFP_NOFS);
371 int ret; 378 int ret;
@@ -378,9 +385,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
378 fs_info->running_transaction = NULL; 385 fs_info->running_transaction = NULL;
379 fs_info->tree_root = tree_root; 386 fs_info->tree_root = tree_root;
380 fs_info->extent_root = extent_root; 387 fs_info->extent_root = extent_root;
381 fs_info->inode_root = inode_root;
382 fs_info->last_inode_alloc = 0;
383 fs_info->highest_inode = 0;
384 fs_info->sb = sb; 388 fs_info->sb = sb;
385 fs_info->btree_inode = new_inode(sb); 389 fs_info->btree_inode = new_inode(sb);
386 fs_info->btree_inode->i_ino = 1; 390 fs_info->btree_inode->i_ino = 1;
@@ -425,14 +429,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
425 BTRFS_EXTENT_TREE_OBJECTID, extent_root); 429 BTRFS_EXTENT_TREE_OBJECTID, extent_root);
426 BUG_ON(ret); 430 BUG_ON(ret);
427 431
428 ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info,
429 BTRFS_INODE_MAP_OBJECTID, inode_root);
430 BUG_ON(ret);
431
432 fs_info->generation = btrfs_super_generation(disk_super) + 1; 432 fs_info->generation = btrfs_super_generation(disk_super) + 1;
433 ret = btrfs_find_highest_inode(tree_root, &fs_info->last_inode_alloc);
434 if (ret == 0)
435 fs_info->highest_inode = fs_info->last_inode_alloc;
436 memset(&fs_info->kobj, 0, sizeof(fs_info->kobj)); 433 memset(&fs_info->kobj, 0, sizeof(fs_info->kobj));
437 kobj_set_kset_s(fs_info, btrfs_subsys); 434 kobj_set_kset_s(fs_info, btrfs_subsys);
438 kobject_set_name(&fs_info->kobj, "%s", sb->s_id); 435 kobject_set_name(&fs_info->kobj, "%s", sb->s_id);
@@ -512,9 +509,6 @@ int close_ctree(struct btrfs_root *root)
512 if (fs_info->extent_root->node) 509 if (fs_info->extent_root->node)
513 btrfs_block_release(fs_info->extent_root, 510 btrfs_block_release(fs_info->extent_root,
514 fs_info->extent_root->node); 511 fs_info->extent_root->node);
515 if (fs_info->inode_root->node)
516 btrfs_block_release(fs_info->inode_root,
517 fs_info->inode_root->node);
518 if (fs_info->tree_root->node) 512 if (fs_info->tree_root->node)
519 btrfs_block_release(fs_info->tree_root, 513 btrfs_block_release(fs_info->tree_root,
520 fs_info->tree_root->node); 514 fs_info->tree_root->node);
@@ -524,7 +518,6 @@ int close_ctree(struct btrfs_root *root)
524 iput(fs_info->btree_inode); 518 iput(fs_info->btree_inode);
525 del_fs_roots(fs_info); 519 del_fs_roots(fs_info);
526 kfree(fs_info->extent_root); 520 kfree(fs_info->extent_root);
527 kfree(fs_info->inode_root);
528 kfree(fs_info->tree_root); 521 kfree(fs_info->tree_root);
529 kobject_unregister(&fs_info->kobj); 522 kobject_unregister(&fs_info->kobj);
530 return 0; 523 return 0;
diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c
index b276a3b40a66..c3b990b661c2 100644
--- a/fs/btrfs/inode-item.c
+++ b/fs/btrfs/inode-item.c
@@ -22,6 +22,8 @@ int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
22 sizeof(*inode_item)); 22 sizeof(*inode_item));
23 btrfs_release_path(root, path); 23 btrfs_release_path(root, path);
24 btrfs_free_path(path); 24 btrfs_free_path(path);
25 if (ret == 0 && objectid > root->highest_inode)
26 root->highest_inode = objectid;
25 return ret; 27 return ret;
26} 28}
27 29
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index f665221409ac..318e27a6378b 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -3,12 +3,11 @@
3#include "disk-io.h" 3#include "disk-io.h"
4#include "transaction.h" 4#include "transaction.h"
5 5
6int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid) 6int btrfs_find_highest_inode(struct btrfs_root *root, u64 *objectid)
7{ 7{
8 struct btrfs_path *path; 8 struct btrfs_path *path;
9 int ret; 9 int ret;
10 struct btrfs_leaf *l; 10 struct btrfs_leaf *l;
11 struct btrfs_root *root = fs_root->fs_info->inode_root;
12 struct btrfs_key search_key; 11 struct btrfs_key search_key;
13 int slot; 12 int slot;
14 13
@@ -38,7 +37,7 @@ error:
38 * walks the btree of allocated inodes and find a hole. 37 * walks the btree of allocated inodes and find a hole.
39 */ 38 */
40int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, 39int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
41 struct btrfs_root *fs_root, 40 struct btrfs_root *root,
42 u64 dirid, u64 *objectid) 41 u64 dirid, u64 *objectid)
43{ 42{
44 struct btrfs_path *path; 43 struct btrfs_path *path;
@@ -49,16 +48,13 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
49 u64 last_ino = 0; 48 u64 last_ino = 0;
50 int start_found; 49 int start_found;
51 struct btrfs_leaf *l; 50 struct btrfs_leaf *l;
52 struct btrfs_root *root = fs_root->fs_info->inode_root;
53 struct btrfs_key search_key; 51 struct btrfs_key search_key;
54 u64 search_start = dirid; 52 u64 search_start = dirid;
55 53
56 path = btrfs_alloc_path(); 54 path = btrfs_alloc_path();
57 BUG_ON(!path); 55 BUG_ON(!path);
58 search_key.flags = 0; 56 search_key.flags = 0;
59 btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); 57 search_start = root->last_inode_alloc;
60
61 search_start = fs_root->fs_info->last_inode_alloc;
62 search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); 58 search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID);
63 search_key.objectid = search_start; 59 search_key.objectid = search_start;
64 search_key.offset = 0; 60 search_key.offset = 0;
@@ -108,7 +104,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
108 } 104 }
109 // FIXME -ENOSPC 105 // FIXME -ENOSPC
110found: 106found:
111 root->fs_info->last_inode_alloc = *objectid; 107 root->last_inode_alloc = *objectid;
112 btrfs_release_path(root, path); 108 btrfs_release_path(root, path);
113 btrfs_free_path(path); 109 btrfs_free_path(path);
114 BUG_ON(*objectid < search_start); 110 BUG_ON(*objectid < search_start);
@@ -118,56 +114,3 @@ error:
118 btrfs_free_path(path); 114 btrfs_free_path(path);
119 return ret; 115 return ret;
120} 116}
121
122int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
123 struct btrfs_root *fs_root,
124 u64 objectid, struct btrfs_key *location)
125{
126 int ret = 0;
127 struct btrfs_path *path;
128 struct btrfs_inode_map_item *inode_item;
129 struct btrfs_key key;
130 struct btrfs_root *inode_root = fs_root->fs_info->inode_root;
131
132 key.objectid = objectid;
133 key.flags = 0;
134 btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY);
135 key.offset = 0;
136 path = btrfs_alloc_path();
137 BUG_ON(!path);
138 btrfs_init_path(path);
139 ret = btrfs_insert_empty_item(trans, inode_root, path, &key,
140 sizeof(struct btrfs_inode_map_item));
141 if (ret)
142 goto out;
143
144 inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
145 path->slots[0], struct btrfs_inode_map_item);
146 btrfs_cpu_key_to_disk(&inode_item->key, location);
147 btrfs_mark_buffer_dirty(path->nodes[0]);
148 if (objectid > fs_root->fs_info->highest_inode)
149 fs_root->fs_info->highest_inode = objectid;
150out:
151 btrfs_release_path(inode_root, path);
152 btrfs_free_path(path);
153 return ret;
154}
155
156int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
157 struct btrfs_root *fs_root, struct btrfs_path *path,
158 u64 objectid, int mod)
159{
160 int ret;
161 struct btrfs_key key;
162 int ins_len = mod < 0 ? -1 : 0;
163 int cow = mod != 0;
164 struct btrfs_root *inode_root = fs_root->fs_info->inode_root;
165
166 key.objectid = objectid;
167 key.flags = 0;
168 key.offset = 0;
169 btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY);
170 ret = btrfs_search_slot(trans, inode_root, &key, path, ins_len, cow);
171 return ret;
172}
173
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index f0da65c4f96b..854d47d9bdc9 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -10,7 +10,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
10 struct btrfs_extent_item *ei; 10 struct btrfs_extent_item *ei;
11 struct btrfs_root_item *ri; 11 struct btrfs_root_item *ri;
12 struct btrfs_dir_item *di; 12 struct btrfs_dir_item *di;
13 struct btrfs_inode_map_item *mi;
14 struct btrfs_inode_item *ii; 13 struct btrfs_inode_item *ii;
15 u32 type; 14 u32 type;
16 15
@@ -54,13 +53,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
54 printk("\t\textent data refs %u owner %Lu\n", 53 printk("\t\textent data refs %u owner %Lu\n",
55 btrfs_extent_refs(ei), btrfs_extent_owner(ei)); 54 btrfs_extent_refs(ei), btrfs_extent_owner(ei));
56 break; 55 break;
57 case BTRFS_INODE_MAP_ITEM_KEY:
58 mi = btrfs_item_ptr(l, i, struct btrfs_inode_map_item);
59 printk("\t\tinode map key %Lu %u %Lu\n",
60 btrfs_disk_key_objectid(&mi->key),
61 btrfs_disk_key_flags(&mi->key),
62 btrfs_disk_key_offset(&mi->key));
63 break;
64 case BTRFS_STRING_ITEM_KEY: 56 case BTRFS_STRING_ITEM_KEY:
65 printk("\t\titem data %.*s\n", btrfs_item_size(item), 57 printk("\t\titem data %.*s\n", btrfs_item_size(item),
66 btrfs_leaf_data(l) + btrfs_item_offset(item)); 58 btrfs_leaf_data(l) + btrfs_item_offset(item));
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index bbe5cabcb42e..3e8bfb0e5d7e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -45,14 +45,6 @@ static struct inode_operations btrfs_file_inode_operations;
45static struct address_space_operations btrfs_aops; 45static struct address_space_operations btrfs_aops;
46static struct file_operations btrfs_file_operations; 46static struct file_operations btrfs_file_operations;
47 47
48static int check_inode(struct inode *inode)
49{
50 struct btrfs_inode *ei = BTRFS_I(inode);
51 WARN_ON(ei->magic != 0xDEADBEEF);
52 WARN_ON(ei->magic2 != 0xDEADBEAF);
53 return 0;
54}
55
56static void btrfs_read_locked_inode(struct inode *inode) 48static void btrfs_read_locked_inode(struct inode *inode)
57{ 49{
58 struct btrfs_path *path; 50 struct btrfs_path *path;
@@ -66,15 +58,12 @@ static void btrfs_read_locked_inode(struct inode *inode)
66 btrfs_init_path(path); 58 btrfs_init_path(path);
67 mutex_lock(&root->fs_info->fs_mutex); 59 mutex_lock(&root->fs_info->fs_mutex);
68 60
69 check_inode(inode);
70
71 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); 61 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
72 ret = btrfs_lookup_inode(NULL, root, path, &location, 0); 62 ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
73 if (ret) { 63 if (ret) {
74 btrfs_free_path(path); 64 btrfs_free_path(path);
75 goto make_bad; 65 goto make_bad;
76 } 66 }
77 check_inode(inode);
78 inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), 67 inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
79 path->slots[0], 68 path->slots[0],
80 struct btrfs_inode_item); 69 struct btrfs_inode_item);
@@ -97,7 +86,7 @@ static void btrfs_read_locked_inode(struct inode *inode)
97 inode_item = NULL; 86 inode_item = NULL;
98 87
99 mutex_unlock(&root->fs_info->fs_mutex); 88 mutex_unlock(&root->fs_info->fs_mutex);
100 check_inode(inode); 89
101 switch (inode->i_mode & S_IFMT) { 90 switch (inode->i_mode & S_IFMT) {
102#if 0 91#if 0
103 default: 92 default:
@@ -121,7 +110,6 @@ static void btrfs_read_locked_inode(struct inode *inode)
121 // inode->i_op = &page_symlink_inode_operations; 110 // inode->i_op = &page_symlink_inode_operations;
122 break; 111 break;
123 } 112 }
124 check_inode(inode);
125 return; 113 return;
126 114
127make_bad: 115make_bad:
@@ -272,10 +260,7 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans,
272 struct btrfs_root *root, 260 struct btrfs_root *root,
273 struct inode *inode) 261 struct inode *inode)
274{ 262{
275 u64 objectid = inode->i_ino;
276 struct btrfs_path *path; 263 struct btrfs_path *path;
277 struct btrfs_inode_map_item *map;
278 struct btrfs_key stat_data_key;
279 int ret; 264 int ret;
280 265
281 clear_inode(inode); 266 clear_inode(inode);
@@ -283,26 +268,11 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans,
283 path = btrfs_alloc_path(); 268 path = btrfs_alloc_path();
284 BUG_ON(!path); 269 BUG_ON(!path);
285 btrfs_init_path(path); 270 btrfs_init_path(path);
286 ret = btrfs_lookup_inode_map(trans, root, path, objectid, -1);
287 if (ret) {
288 if (ret > 0)
289 ret = -ENOENT;
290 goto error;
291 }
292 map = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
293 struct btrfs_inode_map_item);
294 btrfs_disk_key_to_cpu(&stat_data_key, &map->key);
295 ret = btrfs_del_item(trans, root->fs_info->inode_root, path);
296 BUG_ON(ret);
297 btrfs_release_path(root, path);
298
299 ret = btrfs_lookup_inode(trans, root, path, 271 ret = btrfs_lookup_inode(trans, root, path,
300 &BTRFS_I(inode)->location, -1); 272 &BTRFS_I(inode)->location, -1);
301 BUG_ON(ret); 273 BUG_ON(ret);
302 ret = btrfs_del_item(trans, root, path); 274 ret = btrfs_del_item(trans, root, path);
303 BUG_ON(ret); 275 BUG_ON(ret);
304error:
305 btrfs_release_path(root, path);
306 btrfs_free_path(path); 276 btrfs_free_path(path);
307 return ret; 277 return ret;
308} 278}
@@ -432,7 +402,6 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
432out: 402out:
433 btrfs_release_path(root, path); 403 btrfs_release_path(root, path);
434 btrfs_free_path(path); 404 btrfs_free_path(path);
435 check_inode(dir);
436 return ret; 405 return ret;
437} 406}
438 407
@@ -540,9 +509,7 @@ printk("adding new root for inode %lu root %p (found %p)\n", inode->i_ino, sub_r
540 btrfs_read_locked_inode(inode); 509 btrfs_read_locked_inode(inode);
541 unlock_new_inode(inode); 510 unlock_new_inode(inode);
542 } 511 }
543 check_inode(inode);
544 } 512 }
545 check_inode(dir);
546 return d_splice_alias(inode, dentry); 513 return d_splice_alias(inode, dentry);
547} 514}
548 515
@@ -566,7 +533,6 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
566 /* FIXME, use a real flag for deciding about the key type */ 533 /* FIXME, use a real flag for deciding about the key type */
567 if (root->fs_info->tree_root == root) 534 if (root->fs_info->tree_root == root)
568 key_type = BTRFS_DIR_ITEM_KEY; 535 key_type = BTRFS_DIR_ITEM_KEY;
569
570 mutex_lock(&root->fs_info->fs_mutex); 536 mutex_lock(&root->fs_info->fs_mutex);
571 key.objectid = inode->i_ino; 537 key.objectid = inode->i_ino;
572 key.flags = 0; 538 key.flags = 0;
@@ -575,9 +541,8 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
575 path = btrfs_alloc_path(); 541 path = btrfs_alloc_path();
576 btrfs_init_path(path); 542 btrfs_init_path(path);
577 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 543 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
578 if (ret < 0) { 544 if (ret < 0)
579 goto err; 545 goto err;
580 }
581 advance = 0; 546 advance = 0;
582 while(1) { 547 while(1) {
583 leaf = btrfs_buffer_leaf(path->nodes[0]); 548 leaf = btrfs_buffer_leaf(path->nodes[0]);
@@ -601,8 +566,7 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
601 if (btrfs_disk_key_objectid(&item->key) != key.objectid) 566 if (btrfs_disk_key_objectid(&item->key) != key.objectid)
602 break; 567 break;
603 if (key_type == BTRFS_DIR_INDEX_KEY && 568 if (key_type == BTRFS_DIR_INDEX_KEY &&
604 btrfs_disk_key_offset(&item->key) > 569 btrfs_disk_key_offset(&item->key) > root->highest_inode)
605 root->fs_info->highest_inode)
606 break; 570 break;
607 if (btrfs_disk_key_type(&item->key) != key_type) 571 if (btrfs_disk_key_type(&item->key) != key_type)
608 continue; 572 continue;
@@ -707,7 +671,6 @@ static void fill_inode_item(struct btrfs_inode_item *item,
707 btrfs_set_timespec_nsec(&item->ctime, inode->i_ctime.tv_nsec); 671 btrfs_set_timespec_nsec(&item->ctime, inode->i_ctime.tv_nsec);
708 btrfs_set_inode_nblocks(item, inode->i_blocks); 672 btrfs_set_inode_nblocks(item, inode->i_blocks);
709 btrfs_set_inode_generation(item, inode->i_generation); 673 btrfs_set_inode_generation(item, inode->i_generation);
710 check_inode(inode);
711} 674}
712 675
713static int btrfs_update_inode(struct btrfs_trans_handle *trans, 676static int btrfs_update_inode(struct btrfs_trans_handle *trans,
@@ -721,7 +684,6 @@ static int btrfs_update_inode(struct btrfs_trans_handle *trans,
721 path = btrfs_alloc_path(); 684 path = btrfs_alloc_path();
722 BUG_ON(!path); 685 BUG_ON(!path);
723 btrfs_init_path(path); 686 btrfs_init_path(path);
724
725 ret = btrfs_lookup_inode(trans, root, path, 687 ret = btrfs_lookup_inode(trans, root, path,
726 &BTRFS_I(inode)->location, 1); 688 &BTRFS_I(inode)->location, 1);
727 if (ret) { 689 if (ret) {
@@ -736,11 +698,11 @@ static int btrfs_update_inode(struct btrfs_trans_handle *trans,
736 698
737 fill_inode_item(inode_item, inode); 699 fill_inode_item(inode_item, inode);
738 btrfs_mark_buffer_dirty(path->nodes[0]); 700 btrfs_mark_buffer_dirty(path->nodes[0]);
701 ret = 0;
739failed: 702failed:
740 btrfs_release_path(root, path); 703 btrfs_release_path(root, path);
741 btrfs_free_path(path); 704 btrfs_free_path(path);
742 check_inode(inode); 705 return ret;
743 return 0;
744} 706}
745 707
746static int btrfs_write_inode(struct inode *inode, int wait) 708static int btrfs_write_inode(struct inode *inode, int wait)
@@ -757,7 +719,6 @@ static int btrfs_write_inode(struct inode *inode, int wait)
757 else 719 else
758 btrfs_end_transaction(trans, root); 720 btrfs_end_transaction(trans, root);
759 mutex_unlock(&root->fs_info->fs_mutex); 721 mutex_unlock(&root->fs_info->fs_mutex);
760 check_inode(inode);
761 return ret; 722 return ret;
762} 723}
763 724
@@ -767,7 +728,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
767 struct inode *inode; 728 struct inode *inode;
768 struct btrfs_inode_item inode_item; 729 struct btrfs_inode_item inode_item;
769 struct btrfs_root *root = BTRFS_I(dir)->root; 730 struct btrfs_root *root = BTRFS_I(dir)->root;
770 struct btrfs_key *key; 731 struct btrfs_key *location;
771 int ret; 732 int ret;
772 u64 objectid; 733 u64 objectid;
773 734
@@ -776,8 +737,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
776 return ERR_PTR(-ENOMEM); 737 return ERR_PTR(-ENOMEM);
777 738
778 BTRFS_I(inode)->root = BTRFS_I(dir)->root; 739 BTRFS_I(inode)->root = BTRFS_I(dir)->root;
779 key = &BTRFS_I(inode)->location;
780 check_inode(inode);
781 ret = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid); 740 ret = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
782 BUG_ON(ret); 741 BUG_ON(ret);
783 742
@@ -788,20 +747,16 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
788 inode->i_blocks = 0; 747 inode->i_blocks = 0;
789 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 748 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
790 fill_inode_item(&inode_item, inode); 749 fill_inode_item(&inode_item, inode);
791 750 location = &BTRFS_I(inode)->location;
792 key->objectid = objectid; 751 location->objectid = objectid;
793 key->flags = 0; 752 location->flags = 0;
794 key->offset = 0; 753 location->offset = 0;
795 btrfs_set_key_type(key, BTRFS_INODE_ITEM_KEY); 754 btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
796 ret = btrfs_insert_inode_map(trans, root, objectid, key);
797 BUG_ON(ret);
798 755
799 ret = btrfs_insert_inode(trans, root, objectid, &inode_item); 756 ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
800 BUG_ON(ret); 757 BUG_ON(ret);
801 758
802 insert_inode_hash(inode); 759 insert_inode_hash(inode);
803 check_inode(inode);
804 check_inode(dir);
805 return inode; 760 return inode;
806} 761}
807 762
@@ -825,8 +780,6 @@ static int btrfs_add_link(struct btrfs_trans_handle *trans,
825 ret = btrfs_update_inode(trans, root, 780 ret = btrfs_update_inode(trans, root,
826 dentry->d_parent->d_inode); 781 dentry->d_parent->d_inode);
827 } 782 }
828 check_inode(inode);
829 check_inode(dentry->d_parent->d_inode);
830 return ret; 783 return ret;
831} 784}
832 785
@@ -840,7 +793,6 @@ static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
840 } 793 }
841 if (err > 0) 794 if (err > 0)
842 err = -EEXIST; 795 err = -EEXIST;
843 check_inode(inode);
844 return err; 796 return err;
845} 797}
846 798
@@ -872,8 +824,6 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
872out_unlock: 824out_unlock:
873 btrfs_end_transaction(trans, root); 825 btrfs_end_transaction(trans, root);
874 mutex_unlock(&root->fs_info->fs_mutex); 826 mutex_unlock(&root->fs_info->fs_mutex);
875 check_inode(inode);
876 check_inode(dir);
877 827
878 if (drop_inode) { 828 if (drop_inode) {
879 inode_dec_link_count(inode); 829 inode_dec_link_count(inode);
@@ -1701,7 +1651,8 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
1701 ret = btrfs_update_inode(trans, root, root->inode); 1651 ret = btrfs_update_inode(trans, root, root->inode);
1702 BUG_ON(ret); 1652 BUG_ON(ret);
1703 1653
1704 ret = btrfs_find_free_objectid(trans, root, 0, &objectid); 1654 ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
1655 0, &objectid);
1705 BUG_ON(ret); 1656 BUG_ON(ret);
1706 1657
1707 memset(&new_root_item, 0, sizeof(new_root_item)); 1658 memset(&new_root_item, 0, sizeof(new_root_item));
@@ -1709,13 +1660,6 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
1709 sizeof(new_root_item)); 1660 sizeof(new_root_item));
1710 1661
1711 key.objectid = objectid; 1662 key.objectid = objectid;
1712 key.flags = 0;
1713 key.offset = 0;
1714 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
1715 ret = btrfs_insert_inode_map(trans, root, objectid, &key);
1716 BUG_ON(ret);
1717
1718 key.objectid = objectid;
1719 key.offset = 1; 1663 key.offset = 1;
1720 key.flags = 0; 1664 key.flags = 0;
1721 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); 1665 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
@@ -1791,21 +1735,14 @@ static struct inode *btrfs_alloc_inode(struct super_block *sb)
1791 ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS); 1735 ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS);
1792 if (!ei) 1736 if (!ei)
1793 return NULL; 1737 return NULL;
1794 ei->magic = 0xDEADBEEF;
1795 ei->magic2 = 0xDEADBEAF;
1796 return &ei->vfs_inode; 1738 return &ei->vfs_inode;
1797} 1739}
1798 1740
1799static void btrfs_destroy_inode(struct inode *inode) 1741static void btrfs_destroy_inode(struct inode *inode)
1800{ 1742{
1801 struct btrfs_inode *ei = BTRFS_I(inode);
1802 WARN_ON(ei->magic != 0xDEADBEEF);
1803 WARN_ON(ei->magic2 != 0xDEADBEAF);
1804 WARN_ON(!list_empty(&inode->i_dentry)); 1743 WARN_ON(!list_empty(&inode->i_dentry));
1805 WARN_ON(inode->i_data.nrpages); 1744 WARN_ON(inode->i_data.nrpages);
1806 1745
1807 ei->magic = 0;
1808 ei->magic2 = 0;
1809 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); 1746 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
1810} 1747}
1811 1748
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 83a0194ab163..54978d1bd958 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -115,14 +115,7 @@ int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,
115 struct btrfs_fs_info *fs_info = root->fs_info; 115 struct btrfs_fs_info *fs_info = root->fs_info;
116 struct btrfs_root *tree_root = fs_info->tree_root; 116 struct btrfs_root *tree_root = fs_info->tree_root;
117 struct btrfs_root *extent_root = fs_info->extent_root; 117 struct btrfs_root *extent_root = fs_info->extent_root;
118 struct btrfs_root *inode_root = fs_info->inode_root;
119 118
120 btrfs_set_root_blocknr(&inode_root->root_item,
121 inode_root->node->b_blocknr);
122 ret = btrfs_update_root(trans, tree_root,
123 &inode_root->root_key,
124 &inode_root->root_item);
125 BUG_ON(ret);
126 while(1) { 119 while(1) {
127 old_extent_block = btrfs_root_blocknr(&extent_root->root_item); 120 old_extent_block = btrfs_root_blocknr(&extent_root->root_item);
128 if (old_extent_block == extent_root->node->b_blocknr) 121 if (old_extent_block == extent_root->node->b_blocknr)