diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3d4bf6833f2a..8d9457b5aef5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -46,7 +46,8 @@ struct btrfs_buffer *alloc_tree_block(struct btrfs_root *root, u64 blocknr) | |||
46 | { | 46 | { |
47 | struct btrfs_buffer *buf; | 47 | struct btrfs_buffer *buf; |
48 | int ret; | 48 | int ret; |
49 | buf = malloc(sizeof(struct btrfs_buffer)); | 49 | |
50 | buf = malloc(sizeof(struct btrfs_buffer) + root->blocksize); | ||
50 | if (!buf) | 51 | if (!buf) |
51 | return buf; | 52 | return buf; |
52 | allocated_blocks++; | 53 | allocated_blocks++; |
@@ -84,7 +85,7 @@ struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr) | |||
84 | 85 | ||
85 | struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr) | 86 | struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr) |
86 | { | 87 | { |
87 | loff_t offset = blocknr * BTRFS_BLOCKSIZE; | 88 | loff_t offset = blocknr * root->blocksize; |
88 | struct btrfs_buffer *buf; | 89 | struct btrfs_buffer *buf; |
89 | int ret; | 90 | int ret; |
90 | 91 | ||
@@ -95,8 +96,8 @@ struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr) | |||
95 | buf = alloc_tree_block(root, blocknr); | 96 | buf = alloc_tree_block(root, blocknr); |
96 | if (!buf) | 97 | if (!buf) |
97 | return NULL; | 98 | return NULL; |
98 | ret = pread(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset); | 99 | ret = pread(root->fp, &buf->node, root->blocksize, offset); |
99 | if (ret != BTRFS_BLOCKSIZE) { | 100 | if (ret != root->blocksize) { |
100 | free(buf); | 101 | free(buf); |
101 | return NULL; | 102 | return NULL; |
102 | } | 103 | } |
@@ -127,13 +128,13 @@ int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf) | |||
127 | int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf) | 128 | int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf) |
128 | { | 129 | { |
129 | u64 blocknr = buf->blocknr; | 130 | u64 blocknr = buf->blocknr; |
130 | loff_t offset = blocknr * BTRFS_BLOCKSIZE; | 131 | loff_t offset = blocknr * root->blocksize; |
131 | int ret; | 132 | int ret; |
132 | 133 | ||
133 | if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) | 134 | if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) |
134 | BUG(); | 135 | BUG(); |
135 | ret = pwrite(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset); | 136 | ret = pwrite(root->fp, &buf->node, root->blocksize, offset); |
136 | if (ret != BTRFS_BLOCKSIZE) | 137 | if (ret != root->blocksize) |
137 | return ret; | 138 | return ret; |
138 | return 0; | 139 | return 0; |
139 | } | 140 | } |
@@ -215,7 +216,8 @@ int btrfs_commit_transaction(struct btrfs_root *root, | |||
215 | return ret; | 216 | return ret; |
216 | } | 217 | } |
217 | 218 | ||
218 | static int __setup_root(struct btrfs_root *root, u64 objectid, int fp) | 219 | static int __setup_root(struct btrfs_super_block *super, |
220 | struct btrfs_root *root, u64 objectid, int fp) | ||
219 | { | 221 | { |
220 | INIT_LIST_HEAD(&root->trans); | 222 | INIT_LIST_HEAD(&root->trans); |
221 | INIT_LIST_HEAD(&root->cache); | 223 | INIT_LIST_HEAD(&root->cache); |
@@ -223,6 +225,8 @@ static int __setup_root(struct btrfs_root *root, u64 objectid, int fp) | |||
223 | root->fp = fp; | 225 | root->fp = fp; |
224 | root->node = NULL; | 226 | root->node = NULL; |
225 | root->commit_root = NULL; | 227 | root->commit_root = NULL; |
228 | root->blocksize = btrfs_super_blocksize(super); | ||
229 | root->ref_cows = 0; | ||
226 | memset(&root->current_insert, 0, sizeof(root->current_insert)); | 230 | memset(&root->current_insert, 0, sizeof(root->current_insert)); |
227 | memset(&root->last_insert, 0, sizeof(root->last_insert)); | 231 | memset(&root->last_insert, 0, sizeof(root->last_insert)); |
228 | memset(&root->root_key, 0, sizeof(root->root_key)); | 232 | memset(&root->root_key, 0, sizeof(root->root_key)); |
@@ -230,19 +234,19 @@ static int __setup_root(struct btrfs_root *root, u64 objectid, int fp) | |||
230 | return 0; | 234 | return 0; |
231 | } | 235 | } |
232 | 236 | ||
233 | static int find_and_setup_root(struct btrfs_root *tree_root, u64 objectid, | 237 | static int find_and_setup_root(struct btrfs_super_block *super, |
234 | struct btrfs_root *root, int fp) | 238 | struct btrfs_root *tree_root, u64 objectid, |
239 | struct btrfs_root *root, int fp) | ||
235 | { | 240 | { |
236 | int ret; | 241 | int ret; |
237 | 242 | ||
238 | __setup_root(root, objectid, fp); | 243 | __setup_root(super, root, objectid, fp); |
239 | ret = btrfs_find_last_root(tree_root, objectid, | 244 | ret = btrfs_find_last_root(tree_root, objectid, |
240 | &root->root_item, &root->root_key); | 245 | &root->root_item, &root->root_key); |
241 | BUG_ON(ret); | 246 | BUG_ON(ret); |
242 | 247 | ||
243 | root->node = read_tree_block(root, | 248 | root->node = read_tree_block(root, |
244 | btrfs_root_blocknr(&root->root_item)); | 249 | btrfs_root_blocknr(&root->root_item)); |
245 | root->ref_cows = 0; | ||
246 | BUG_ON(!root->node); | 250 | BUG_ON(!root->node); |
247 | return 0; | 251 | return 0; |
248 | } | 252 | } |
@@ -277,28 +281,28 @@ struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super) | |||
277 | INIT_RADIX_TREE(&tree_root->cache_radix, GFP_KERNEL); | 281 | INIT_RADIX_TREE(&tree_root->cache_radix, GFP_KERNEL); |
278 | 282 | ||
279 | ret = pread(fp, super, sizeof(struct btrfs_super_block), | 283 | ret = pread(fp, super, sizeof(struct btrfs_super_block), |
280 | BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE)); | 284 | BTRFS_SUPER_INFO_OFFSET); |
281 | if (ret == 0 || btrfs_super_root(super) == 0) { | 285 | if (ret == 0 || btrfs_super_root(super) == 0) { |
282 | printf("making new FS!\n"); | 286 | printf("making new FS!\n"); |
283 | ret = mkfs(fp, 0, BTRFS_BLOCKSIZE); | 287 | ret = mkfs(fp, 0, 1024); |
284 | if (ret) | 288 | if (ret) |
285 | return NULL; | 289 | return NULL; |
286 | ret = pread(fp, super, sizeof(struct btrfs_super_block), | 290 | ret = pread(fp, super, sizeof(struct btrfs_super_block), |
287 | BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE)); | 291 | BTRFS_SUPER_INFO_OFFSET); |
288 | if (ret != sizeof(struct btrfs_super_block)) | 292 | if (ret != sizeof(struct btrfs_super_block)) |
289 | return NULL; | 293 | return NULL; |
290 | } | 294 | } |
291 | BUG_ON(ret < 0); | 295 | BUG_ON(ret < 0); |
292 | 296 | ||
293 | __setup_root(tree_root, BTRFS_ROOT_TREE_OBJECTID, fp); | 297 | __setup_root(super, tree_root, BTRFS_ROOT_TREE_OBJECTID, fp); |
294 | tree_root->node = read_tree_block(tree_root, btrfs_super_root(super)); | 298 | tree_root->node = read_tree_block(tree_root, btrfs_super_root(super)); |
295 | BUG_ON(!tree_root->node); | 299 | BUG_ON(!tree_root->node); |
296 | 300 | ||
297 | ret = find_and_setup_root(tree_root, BTRFS_EXTENT_TREE_OBJECTID, | 301 | ret = find_and_setup_root(super, tree_root, BTRFS_EXTENT_TREE_OBJECTID, |
298 | extent_root, fp); | 302 | extent_root, fp); |
299 | BUG_ON(ret); | 303 | BUG_ON(ret); |
300 | 304 | ||
301 | ret = find_and_setup_root(tree_root, BTRFS_FS_TREE_OBJECTID, | 305 | ret = find_and_setup_root(super, tree_root, BTRFS_FS_TREE_OBJECTID, |
302 | root, fp); | 306 | root, fp); |
303 | BUG_ON(ret); | 307 | BUG_ON(ret); |
304 | 308 | ||
@@ -313,7 +317,7 @@ int write_ctree_super(struct btrfs_root *root, struct btrfs_super_block *s) | |||
313 | int ret; | 317 | int ret; |
314 | btrfs_set_super_root(s, root->tree_root->node->blocknr); | 318 | btrfs_set_super_root(s, root->tree_root->node->blocknr); |
315 | ret = pwrite(root->fp, s, sizeof(*s), | 319 | ret = pwrite(root->fp, s, sizeof(*s), |
316 | BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE)); | 320 | BTRFS_SUPER_INFO_OFFSET); |
317 | if (ret != sizeof(*s)) { | 321 | if (ret != sizeof(*s)) { |
318 | fprintf(stderr, "failed to write new super block err %d\n", ret); | 322 | fprintf(stderr, "failed to write new super block err %d\n", ret); |
319 | return ret; | 323 | return ret; |