aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-13 10:46:10 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-13 10:46:10 -0400
commit234b63a091e1df6bd4261dd7b3a7490074830628 (patch)
tree1947f6e49aa3c19017c948205378c5cb76a7b536 /fs/btrfs/disk-io.c
parentcf27e1eec063fa68a89c57ae0a83f93aa38851d6 (diff)
rename funcs and structs to btrfs
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c106
1 files changed, 54 insertions, 52 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 065e888d2c0b..c34c0c60935f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -13,7 +13,7 @@
13static int allocated_blocks = 0; 13static int allocated_blocks = 0;
14int cache_max = 10000; 14int cache_max = 10000;
15 15
16static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf) 16static int check_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
17{ 17{
18 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) 18 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header))
19 BUG(); 19 BUG();
@@ -23,18 +23,18 @@ static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf)
23 return 0; 23 return 0;
24} 24}
25 25
26static int free_some_buffers(struct ctree_root *root) 26static int free_some_buffers(struct btrfs_root *root)
27{ 27{
28 struct list_head *node, *next; 28 struct list_head *node, *next;
29 struct tree_buffer *b; 29 struct btrfs_buffer *b;
30 if (root->cache_size < cache_max) 30 if (root->cache_size < cache_max)
31 return 0; 31 return 0;
32 list_for_each_safe(node, next, &root->cache) { 32 list_for_each_safe(node, next, &root->cache) {
33 b = list_entry(node, struct tree_buffer, cache); 33 b = list_entry(node, struct btrfs_buffer, cache);
34 if (b->count == 1) { 34 if (b->count == 1) {
35 BUG_ON(!list_empty(&b->dirty)); 35 BUG_ON(!list_empty(&b->dirty));
36 list_del_init(&b->cache); 36 list_del_init(&b->cache);
37 tree_block_release(root, b); 37 btrfs_block_release(root, b);
38 if (root->cache_size < cache_max) 38 if (root->cache_size < cache_max)
39 break; 39 break;
40 } 40 }
@@ -42,11 +42,11 @@ static int free_some_buffers(struct ctree_root *root)
42 return 0; 42 return 0;
43} 43}
44 44
45struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr) 45struct btrfs_buffer *alloc_tree_block(struct btrfs_root *root, u64 blocknr)
46{ 46{
47 struct tree_buffer *buf; 47 struct btrfs_buffer *buf;
48 int ret; 48 int ret;
49 buf = malloc(sizeof(struct tree_buffer)); 49 buf = malloc(sizeof(struct btrfs_buffer));
50 if (!buf) 50 if (!buf)
51 return buf; 51 return buf;
52 allocated_blocks++; 52 allocated_blocks++;
@@ -66,9 +66,9 @@ struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr)
66 return buf; 66 return buf;
67} 67}
68 68
69struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr) 69struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr)
70{ 70{
71 struct tree_buffer *buf; 71 struct btrfs_buffer *buf;
72 buf = radix_tree_lookup(&root->cache_radix, blocknr); 72 buf = radix_tree_lookup(&root->cache_radix, blocknr);
73 if (buf) { 73 if (buf) {
74 buf->count++; 74 buf->count++;
@@ -82,10 +82,10 @@ struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr)
82 return buf; 82 return buf;
83} 83}
84 84
85struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr) 85struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr)
86{ 86{
87 loff_t offset = blocknr * CTREE_BLOCKSIZE; 87 loff_t offset = blocknr * BTRFS_BLOCKSIZE;
88 struct tree_buffer *buf; 88 struct btrfs_buffer *buf;
89 int ret; 89 int ret;
90 90
91 buf = radix_tree_lookup(&root->cache_radix, blocknr); 91 buf = radix_tree_lookup(&root->cache_radix, blocknr);
@@ -95,8 +95,8 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
95 buf = alloc_tree_block(root, blocknr); 95 buf = alloc_tree_block(root, blocknr);
96 if (!buf) 96 if (!buf)
97 return NULL; 97 return NULL;
98 ret = pread(root->fp, &buf->node, CTREE_BLOCKSIZE, offset); 98 ret = pread(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
99 if (ret != CTREE_BLOCKSIZE) { 99 if (ret != BTRFS_BLOCKSIZE) {
100 free(buf); 100 free(buf);
101 return NULL; 101 return NULL;
102 } 102 }
@@ -106,7 +106,7 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
106 return buf; 106 return buf;
107} 107}
108 108
109int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf) 109int dirty_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
110{ 110{
111 if (!list_empty(&buf->dirty)) 111 if (!list_empty(&buf->dirty))
112 return 0; 112 return 0;
@@ -115,46 +115,47 @@ int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf)
115 return 0; 115 return 0;
116} 116}
117 117
118int clean_tree_block(struct ctree_root *root, struct tree_buffer *buf) 118int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
119{ 119{
120 if (!list_empty(&buf->dirty)) { 120 if (!list_empty(&buf->dirty)) {
121 list_del_init(&buf->dirty); 121 list_del_init(&buf->dirty);
122 tree_block_release(root, buf); 122 btrfs_block_release(root, buf);
123 } 123 }
124 return 0; 124 return 0;
125} 125}
126 126
127int write_tree_block(struct ctree_root *root, struct tree_buffer *buf) 127int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
128{ 128{
129 u64 blocknr = buf->blocknr; 129 u64 blocknr = buf->blocknr;
130 loff_t offset = blocknr * CTREE_BLOCKSIZE; 130 loff_t offset = blocknr * BTRFS_BLOCKSIZE;
131 int ret; 131 int ret;
132 132
133 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) 133 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header))
134 BUG(); 134 BUG();
135 ret = pwrite(root->fp, &buf->node, CTREE_BLOCKSIZE, offset); 135 ret = pwrite(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
136 if (ret != CTREE_BLOCKSIZE) 136 if (ret != BTRFS_BLOCKSIZE)
137 return ret; 137 return ret;
138 return 0; 138 return 0;
139} 139}
140 140
141static int __commit_transaction(struct ctree_root *root) 141static int __commit_transaction(struct btrfs_root *root)
142{ 142{
143 struct tree_buffer *b; 143 struct btrfs_buffer *b;
144 int ret = 0; 144 int ret = 0;
145 int wret; 145 int wret;
146 while(!list_empty(&root->trans)) { 146 while(!list_empty(&root->trans)) {
147 b = list_entry(root->trans.next, struct tree_buffer, dirty); 147 b = list_entry(root->trans.next, struct btrfs_buffer, dirty);
148 list_del_init(&b->dirty); 148 list_del_init(&b->dirty);
149 wret = write_tree_block(root, b); 149 wret = write_tree_block(root, b);
150 if (wret) 150 if (wret)
151 ret = wret; 151 ret = wret;
152 tree_block_release(root, b); 152 btrfs_block_release(root, b);
153 } 153 }
154 return ret; 154 return ret;
155} 155}
156 156
157int commit_transaction(struct ctree_root *root, struct ctree_super_block *s) 157int btrfs_commit_transaction(struct btrfs_root *root,
158 struct btrfs_super_block *s)
158{ 159{
159 int ret = 0; 160 int ret = 0;
160 161
@@ -163,20 +164,20 @@ int commit_transaction(struct ctree_root *root, struct ctree_super_block *s)
163 ret = __commit_transaction(root->extent_root); 164 ret = __commit_transaction(root->extent_root);
164 BUG_ON(ret); 165 BUG_ON(ret);
165 if (root->commit_root != root->node) { 166 if (root->commit_root != root->node) {
166 struct tree_buffer *snap = root->commit_root; 167 struct btrfs_buffer *snap = root->commit_root;
167 root->commit_root = root->node; 168 root->commit_root = root->node;
168 root->node->count++; 169 root->node->count++;
169 ret = btrfs_drop_snapshot(root, snap); 170 ret = btrfs_drop_snapshot(root, snap);
170 BUG_ON(ret); 171 BUG_ON(ret);
171 // tree_block_release(root, snap); 172 // btrfs_block_release(root, snap);
172 } 173 }
173 write_ctree_super(root, s); 174 write_ctree_super(root, s);
174 btrfs_finish_extent_commit(root); 175 btrfs_finish_extent_commit(root);
175 return ret; 176 return ret;
176} 177}
177 178
178static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root, 179static int __setup_root(struct btrfs_root *root, struct btrfs_root *extent_root,
179 struct ctree_root_info *info, int fp) 180 struct btrfs_root_info *info, int fp)
180{ 181{
181 INIT_LIST_HEAD(&root->trans); 182 INIT_LIST_HEAD(&root->trans);
182 INIT_LIST_HEAD(&root->cache); 183 INIT_LIST_HEAD(&root->cache);
@@ -191,10 +192,10 @@ static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root,
191 return 0; 192 return 0;
192} 193}
193 194
194struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super) 195struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super)
195{ 196{
196 struct ctree_root *root = malloc(sizeof(struct ctree_root)); 197 struct btrfs_root *root = malloc(sizeof(struct btrfs_root));
197 struct ctree_root *extent_root = malloc(sizeof(struct ctree_root)); 198 struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root));
198 int fp; 199 int fp;
199 int ret; 200 int ret;
200 201
@@ -207,16 +208,16 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
207 INIT_RADIX_TREE(&root->pinned_radix, GFP_KERNEL); 208 INIT_RADIX_TREE(&root->pinned_radix, GFP_KERNEL);
208 INIT_RADIX_TREE(&extent_root->pinned_radix, GFP_KERNEL); 209 INIT_RADIX_TREE(&extent_root->pinned_radix, GFP_KERNEL);
209 INIT_RADIX_TREE(&extent_root->cache_radix, GFP_KERNEL); 210 INIT_RADIX_TREE(&extent_root->cache_radix, GFP_KERNEL);
210 ret = pread(fp, super, sizeof(struct ctree_super_block), 211 ret = pread(fp, super, sizeof(struct btrfs_super_block),
211 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 212 BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
212 if (ret == 0 || super->root_info.tree_root == 0) { 213 if (ret == 0 || super->root_info.tree_root == 0) {
213 printf("making new FS!\n"); 214 printf("making new FS!\n");
214 ret = mkfs(fp); 215 ret = mkfs(fp);
215 if (ret) 216 if (ret)
216 return NULL; 217 return NULL;
217 ret = pread(fp, super, sizeof(struct ctree_super_block), 218 ret = pread(fp, super, sizeof(struct btrfs_super_block),
218 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 219 BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
219 if (ret != sizeof(struct ctree_super_block)) 220 if (ret != sizeof(struct btrfs_super_block))
220 return NULL; 221 return NULL;
221 } 222 }
222 BUG_ON(ret < 0); 223 BUG_ON(ret < 0);
@@ -227,18 +228,19 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
227 return root; 228 return root;
228} 229}
229 230
230static int __update_root(struct ctree_root *root, struct ctree_root_info *info) 231static int __update_root(struct btrfs_root *root, struct btrfs_root_info *info)
231{ 232{
232 info->tree_root = root->node->blocknr; 233 info->tree_root = root->node->blocknr;
233 return 0; 234 return 0;
234} 235}
235 236
236int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s) 237int write_ctree_super(struct btrfs_root *root, struct btrfs_super_block *s)
237{ 238{
238 int ret; 239 int ret;
239 __update_root(root, &s->root_info); 240 __update_root(root, &s->root_info);
240 __update_root(root->extent_root, &s->extent_info); 241 __update_root(root->extent_root, &s->extent_info);
241 ret = pwrite(root->fp, s, sizeof(*s), CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 242 ret = pwrite(root->fp, s, sizeof(*s),
243 BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
242 if (ret != sizeof(*s)) { 244 if (ret != sizeof(*s)) {
243 fprintf(stderr, "failed to write new super block err %d\n", ret); 245 fprintf(stderr, "failed to write new super block err %d\n", ret);
244 return ret; 246 return ret;
@@ -246,19 +248,19 @@ int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s)
246 return 0; 248 return 0;
247} 249}
248 250
249static int drop_cache(struct ctree_root *root) 251static int drop_cache(struct btrfs_root *root)
250{ 252{
251 while(!list_empty(&root->cache)) { 253 while(!list_empty(&root->cache)) {
252 struct tree_buffer *b = list_entry(root->cache.next, 254 struct btrfs_buffer *b = list_entry(root->cache.next,
253 struct tree_buffer, cache); 255 struct btrfs_buffer, cache);
254 list_del_init(&b->cache); 256 list_del_init(&b->cache);
255 tree_block_release(root, b); 257 btrfs_block_release(root, b);
256 } 258 }
257 return 0; 259 return 0;
258} 260}
259int close_ctree(struct ctree_root *root, struct ctree_super_block *s) 261int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s)
260{ 262{
261 commit_transaction(root, s); 263 btrfs_commit_transaction(root, s);
262 __commit_transaction(root->extent_root); 264 __commit_transaction(root->extent_root);
263 write_ctree_super(root, s); 265 write_ctree_super(root, s);
264 drop_cache(root->extent_root); 266 drop_cache(root->extent_root);
@@ -268,16 +270,16 @@ int close_ctree(struct ctree_root *root, struct ctree_super_block *s)
268 270
269 close(root->fp); 271 close(root->fp);
270 if (root->node) 272 if (root->node)
271 tree_block_release(root, root->node); 273 btrfs_block_release(root, root->node);
272 if (root->extent_root->node) 274 if (root->extent_root->node)
273 tree_block_release(root->extent_root, root->extent_root->node); 275 btrfs_block_release(root->extent_root, root->extent_root->node);
274 tree_block_release(root, root->commit_root); 276 btrfs_block_release(root, root->commit_root);
275 free(root); 277 free(root);
276 printf("on close %d blocks are allocated\n", allocated_blocks); 278 printf("on close %d blocks are allocated\n", allocated_blocks);
277 return 0; 279 return 0;
278} 280}
279 281
280void tree_block_release(struct ctree_root *root, struct tree_buffer *buf) 282void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf)
281{ 283{
282 buf->count--; 284 buf->count--;
283 if (buf->count < 0) 285 if (buf->count < 0)