aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-04-12 12:14:00 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-04-12 12:14:00 -0400
commitb4100d64241fed93a3f821ddf59d11ab4443a3ba (patch)
tree57d3cb2367b5852a9017ec9ff58653338ef45a9f /fs/btrfs/disk-io.c
parent8352d8a473ac84bf7a1c69690b626946d744ca58 (diff)
Btrfs: add a device id to device items
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3ba4df20c913..06b969c14625 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -13,11 +13,13 @@
13struct dev_lookup { 13struct dev_lookup {
14 u64 block_start; 14 u64 block_start;
15 u64 num_blocks; 15 u64 num_blocks;
16 u64 device_id;
16 struct block_device *bdev; 17 struct block_device *bdev;
17}; 18};
18 19
19int btrfs_insert_dev_radix(struct btrfs_root *root, 20int btrfs_insert_dev_radix(struct btrfs_root *root,
20 struct block_device *bdev, 21 struct block_device *bdev,
22 u64 device_id,
21 u64 block_start, 23 u64 block_start,
22 u64 num_blocks) 24 u64 num_blocks)
23{ 25{
@@ -31,6 +33,7 @@ int btrfs_insert_dev_radix(struct btrfs_root *root,
31 lookup->block_start = block_start; 33 lookup->block_start = block_start;
32 lookup->num_blocks = num_blocks; 34 lookup->num_blocks = num_blocks;
33 lookup->bdev = bdev; 35 lookup->bdev = bdev;
36 lookup->device_id = device_id;
34printk("inserting %s into dev radix %Lu %Lu\n", bdevname(bdev, b), block_start, num_blocks); 37printk("inserting %s into dev radix %Lu %Lu\n", bdevname(bdev, b), block_start, num_blocks);
35 38
36 ret = radix_tree_insert(&root->fs_info->dev_radix, block_start + 39 ret = radix_tree_insert(&root->fs_info->dev_radix, block_start +
@@ -418,17 +421,14 @@ printk("all worked\n");
418 return root; 421 return root;
419} 422}
420 423
421int btrfs_open_disk(struct btrfs_root *root, u64 block_start, u64 num_blocks, 424static int btrfs_open_disk(struct btrfs_root *root, u64 device_id,
422 char *filename, int name_len) 425 u64 block_start, u64 num_blocks,
426 char *filename, int name_len)
423{ 427{
424 char *null_filename; 428 char *null_filename;
425 struct block_device *bdev; 429 struct block_device *bdev;
426 int ret; 430 int ret;
427 431
428 if (block_start == 0) {
429printk("skipping disk with block_start == 0\n");
430return 0;
431 }
432 null_filename = kmalloc(name_len + 1, GFP_NOFS); 432 null_filename = kmalloc(name_len + 1, GFP_NOFS);
433 if (!null_filename) 433 if (!null_filename)
434 return -ENOMEM; 434 return -ENOMEM;
@@ -441,7 +441,8 @@ return 0;
441 goto out; 441 goto out;
442 } 442 }
443 set_blocksize(bdev, root->fs_info->sb->s_blocksize); 443 set_blocksize(bdev, root->fs_info->sb->s_blocksize);
444 ret = btrfs_insert_dev_radix(root, bdev, block_start, num_blocks); 444 ret = btrfs_insert_dev_radix(root, bdev, device_id,
445 block_start, num_blocks);
445 BUG_ON(ret); 446 BUG_ON(ret);
446 ret = 0; 447 ret = 0;
447out: 448out:
@@ -490,10 +491,14 @@ static int read_device_info(struct btrfs_root *root)
490 } 491 }
491 dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_device_item); 492 dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_device_item);
492printk("found key %Lu %Lu\n", key.objectid, key.offset); 493printk("found key %Lu %Lu\n", key.objectid, key.offset);
493 ret = btrfs_open_disk(root, key.objectid, key.offset, 494 if (btrfs_device_id(dev_item) !=
494 (char *)(dev_item + 1), 495 btrfs_super_device_id(root->fs_info->disk_super)) {
495 btrfs_device_pathlen(dev_item)); 496 ret = btrfs_open_disk(root, btrfs_device_id(dev_item),
496 BUG_ON(ret); 497 key.objectid, key.offset,
498 (char *)(dev_item + 1),
499 btrfs_device_pathlen(dev_item));
500 BUG_ON(ret);
501 }
497 path->slots[0]++; 502 path->slots[0]++;
498 } 503 }
499 btrfs_free_path(path); 504 btrfs_free_path(path);
@@ -556,6 +561,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
556 dev_lookup->block_start = 0; 561 dev_lookup->block_start = 0;
557 dev_lookup->num_blocks = (u32)-2; 562 dev_lookup->num_blocks = (u32)-2;
558 dev_lookup->bdev = sb->s_bdev; 563 dev_lookup->bdev = sb->s_bdev;
564 dev_lookup->device_id = 0;
559 ret = radix_tree_insert(&fs_info->dev_radix, (u32)-2, dev_lookup); 565 ret = radix_tree_insert(&fs_info->dev_radix, (u32)-2, dev_lookup);
560 BUG_ON(ret); 566 BUG_ON(ret);
561 fs_info->sb_buffer = read_tree_block(tree_root, 567 fs_info->sb_buffer = read_tree_block(tree_root,
@@ -575,6 +581,8 @@ struct btrfs_root *open_ctree(struct super_block *sb)
575 radix_tree_delete(&fs_info->dev_radix, (u32)-2); 581 radix_tree_delete(&fs_info->dev_radix, (u32)-2);
576 dev_lookup->block_start = btrfs_super_device_block_start(disk_super); 582 dev_lookup->block_start = btrfs_super_device_block_start(disk_super);
577 dev_lookup->num_blocks = btrfs_super_device_num_blocks(disk_super); 583 dev_lookup->num_blocks = btrfs_super_device_num_blocks(disk_super);
584 dev_lookup->device_id = btrfs_super_device_id(disk_super);
585
578 ret = radix_tree_insert(&fs_info->dev_radix, 586 ret = radix_tree_insert(&fs_info->dev_radix,
579 dev_lookup->block_start + 587 dev_lookup->block_start +
580 dev_lookup->num_blocks - 1, dev_lookup); 588 dev_lookup->num_blocks - 1, dev_lookup);
@@ -659,6 +667,7 @@ int del_fs_roots(struct btrfs_fs_info *fs_info)
659 } 667 }
660 return 0; 668 return 0;
661} 669}
670
662static int free_dev_radix(struct btrfs_fs_info *fs_info) 671static int free_dev_radix(struct btrfs_fs_info *fs_info)
663{ 672{
664 struct dev_lookup *lookup[8]; 673 struct dev_lookup *lookup[8];