aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/root-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-10-15 16:14:19 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:03:56 -0400
commit5f39d397dfbe140a14edecd4e73c34ce23c4f9ee (patch)
tree280561e4b68d573590557dd27df656869eed8023 /fs/btrfs/root-tree.c
parent50b78c24d594e6985f36a9a8d8e2fb74e1664e90 (diff)
Btrfs: Create extent_buffer interface for large blocksizes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/root-tree.c')
-rw-r--r--fs/btrfs/root-tree.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 3b5926dfbeba..88bcdd33f56e 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -26,12 +26,13 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
26{ 26{
27 struct btrfs_path *path; 27 struct btrfs_path *path;
28 struct btrfs_key search_key; 28 struct btrfs_key search_key;
29 struct btrfs_leaf *l; 29 struct btrfs_key found_key;
30 struct extent_buffer *l;
30 int ret; 31 int ret;
31 int slot; 32 int slot;
32 33
33 search_key.objectid = objectid; 34 search_key.objectid = objectid;
34 search_key.flags = (u32)-1; 35 search_key.type = (u8)-1;
35 search_key.offset = (u64)-1; 36 search_key.offset = (u64)-1;
36 37
37 path = btrfs_alloc_path(); 38 path = btrfs_alloc_path();
@@ -39,17 +40,19 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
39 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); 40 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
40 if (ret < 0) 41 if (ret < 0)
41 goto out; 42 goto out;
43
42 BUG_ON(ret == 0); 44 BUG_ON(ret == 0);
43 l = btrfs_buffer_leaf(path->nodes[0]); 45 l = path->nodes[0];
44 BUG_ON(path->slots[0] == 0); 46 BUG_ON(path->slots[0] == 0);
45 slot = path->slots[0] - 1; 47 slot = path->slots[0] - 1;
46 if (btrfs_disk_key_objectid(&l->items[slot].key) != objectid) { 48 btrfs_item_key_to_cpu(l, &found_key, slot);
49 if (found_key.objectid != objectid) {
47 ret = 1; 50 ret = 1;
48 goto out; 51 goto out;
49 } 52 }
50 memcpy(item, btrfs_item_ptr(l, slot, struct btrfs_root_item), 53 read_extent_buffer(l, item, btrfs_item_ptr_offset(l, slot),
51 sizeof(*item)); 54 sizeof(*item));
52 btrfs_disk_key_to_cpu(key, &l->items[slot].key); 55 memcpy(key, &found_key, sizeof(found_key));
53 ret = 0; 56 ret = 0;
54out: 57out:
55 btrfs_release_path(root, path); 58 btrfs_release_path(root, path);
@@ -62,10 +65,10 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
62 *item) 65 *item)
63{ 66{
64 struct btrfs_path *path; 67 struct btrfs_path *path;
65 struct btrfs_leaf *l; 68 struct extent_buffer *l;
66 int ret; 69 int ret;
67 int slot; 70 int slot;
68 struct btrfs_root_item *update_item; 71 unsigned long ptr;
69 72
70 path = btrfs_alloc_path(); 73 path = btrfs_alloc_path();
71 BUG_ON(!path); 74 BUG_ON(!path);
@@ -73,10 +76,10 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
73 if (ret < 0) 76 if (ret < 0)
74 goto out; 77 goto out;
75 BUG_ON(ret != 0); 78 BUG_ON(ret != 0);
76 l = btrfs_buffer_leaf(path->nodes[0]); 79 l = path->nodes[0];
77 slot = path->slots[0]; 80 slot = path->slots[0];
78 update_item = btrfs_item_ptr(l, slot, struct btrfs_root_item); 81 ptr = btrfs_item_ptr_offset(l, slot);
79 btrfs_memcpy(root, l, update_item, item, sizeof(*item)); 82 write_extent_buffer(l, item, ptr, sizeof(*item));
80 btrfs_mark_buffer_dirty(path->nodes[0]); 83 btrfs_mark_buffer_dirty(path->nodes[0]);
81out: 84out:
82 btrfs_release_path(root, path); 85 btrfs_release_path(root, path);
@@ -103,11 +106,10 @@ int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
103 struct btrfs_path *path; 106 struct btrfs_path *path;
104 int ret; 107 int ret;
105 u32 nritems; 108 u32 nritems;
106 struct btrfs_leaf *leaf; 109 struct extent_buffer *leaf;
107 int slot; 110 int slot;
108 111
109 key.objectid = objectid; 112 key.objectid = objectid;
110 key.flags = 0;
111 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); 113 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
112 key.offset = 0; 114 key.offset = 0;
113 path = btrfs_alloc_path(); 115 path = btrfs_alloc_path();
@@ -117,19 +119,19 @@ int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
117 if (ret < 0) 119 if (ret < 0)
118 goto err; 120 goto err;
119 while(1) { 121 while(1) {
120 leaf = btrfs_buffer_leaf(path->nodes[0]); 122 leaf = path->nodes[0];
121 nritems = btrfs_header_nritems(&leaf->header); 123 nritems = btrfs_header_nritems(leaf);
122 slot = path->slots[0]; 124 slot = path->slots[0];
123 if (slot >= nritems) { 125 if (slot >= nritems) {
124 ret = btrfs_next_leaf(root, path); 126 ret = btrfs_next_leaf(root, path);
125 if (ret) 127 if (ret)
126 break; 128 break;
127 leaf = btrfs_buffer_leaf(path->nodes[0]); 129 leaf = path->nodes[0];
128 nritems = btrfs_header_nritems(&leaf->header); 130 nritems = btrfs_header_nritems(leaf);
129 slot = path->slots[0]; 131 slot = path->slots[0];
130 } 132 }
131 item = leaf->items + slot; 133 item = btrfs_item_nr(leaf, slot);
132 btrfs_disk_key_to_cpu(&key, &item->key); 134 btrfs_item_key_to_cpu(leaf, &key, slot);
133 if (btrfs_key_type(&key) != BTRFS_ROOT_ITEM_KEY) 135 if (btrfs_key_type(&key) != BTRFS_ROOT_ITEM_KEY)
134 goto next; 136 goto next;
135 137
@@ -140,7 +142,7 @@ int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
140 break; 142 break;
141 143
142 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item); 144 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
143 if (btrfs_root_refs(ri) != 0) 145 if (btrfs_disk_root_refs(leaf, ri) != 0)
144 goto next; 146 goto next;
145 147
146 dead_root = btrfs_read_fs_root_no_radix(root->fs_info, &key); 148 dead_root = btrfs_read_fs_root_no_radix(root->fs_info, &key);
@@ -170,6 +172,7 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
170 int ret; 172 int ret;
171 u32 refs; 173 u32 refs;
172 struct btrfs_root_item *ri; 174 struct btrfs_root_item *ri;
175 struct extent_buffer *leaf;
173 176
174 path = btrfs_alloc_path(); 177 path = btrfs_alloc_path();
175 BUG_ON(!path); 178 BUG_ON(!path);
@@ -177,10 +180,10 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
177 if (ret < 0) 180 if (ret < 0)
178 goto out; 181 goto out;
179 BUG_ON(ret != 0); 182 BUG_ON(ret != 0);
180 ri = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), 183 leaf = path->nodes[0];
181 path->slots[0], struct btrfs_root_item); 184 ri = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_item);
182 185
183 refs = btrfs_root_refs(ri); 186 refs = btrfs_disk_root_refs(leaf, ri);
184 BUG_ON(refs != 0); 187 BUG_ON(refs != 0);
185 ret = btrfs_del_item(trans, root, path); 188 ret = btrfs_del_item(trans, root, path);
186out: 189out: