aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/volumes.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-03-24 15:02:07 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:01 -0400
commit0d81ba5dbedef0c3970d6aa318aa84920943e6e3 (patch)
tree2c5256b4a4e4d544add986e654db56e660f4fb12 /fs/btrfs/volumes.c
parente085def2c4cc2d7c0c316376b4b66b86b10e3a4b (diff)
Btrfs: Move device information into the super block so it can be scanned
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r--fs/btrfs/volumes.c61
1 files changed, 15 insertions, 46 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a52a13f365d6..ae22d01ecf54 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -278,7 +278,7 @@ int btrfs_add_device(struct btrfs_trans_handle *trans,
278 key.offset = free_devid; 278 key.offset = free_devid;
279 279
280 ret = btrfs_insert_empty_item(trans, root, path, &key, 280 ret = btrfs_insert_empty_item(trans, root, path, &key,
281 sizeof(*dev_item) + device->name_len); 281 sizeof(*dev_item));
282 if (ret) 282 if (ret)
283 goto out; 283 goto out;
284 284
@@ -290,15 +290,9 @@ int btrfs_add_device(struct btrfs_trans_handle *trans,
290 btrfs_set_device_io_align(leaf, dev_item, device->io_align); 290 btrfs_set_device_io_align(leaf, dev_item, device->io_align);
291 btrfs_set_device_io_width(leaf, dev_item, device->io_width); 291 btrfs_set_device_io_width(leaf, dev_item, device->io_width);
292 btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); 292 btrfs_set_device_sector_size(leaf, dev_item, device->sector_size);
293 btrfs_set_device_rdev(leaf, dev_item, device->rdev);
294 btrfs_set_device_partition(leaf, dev_item, device->partition);
295 btrfs_set_device_name_len(leaf, dev_item, device->name_len);
296 btrfs_set_device_total_bytes(leaf, dev_item, device->total_bytes); 293 btrfs_set_device_total_bytes(leaf, dev_item, device->total_bytes);
297 btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used); 294 btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used);
298 295
299 ptr = (unsigned long)btrfs_device_name(dev_item);
300 write_extent_buffer(leaf, device->name, ptr, device->name_len);
301
302 ptr = (unsigned long)btrfs_device_uuid(dev_item); 296 ptr = (unsigned long)btrfs_device_uuid(dev_item);
303 write_extent_buffer(leaf, device->uuid, ptr, BTRFS_DEV_UUID_SIZE); 297 write_extent_buffer(leaf, device->uuid, ptr, BTRFS_DEV_UUID_SIZE);
304 btrfs_mark_buffer_dirty(leaf); 298 btrfs_mark_buffer_dirty(leaf);
@@ -345,8 +339,6 @@ int btrfs_update_device(struct btrfs_trans_handle *trans,
345 btrfs_set_device_io_align(leaf, dev_item, device->io_align); 339 btrfs_set_device_io_align(leaf, dev_item, device->io_align);
346 btrfs_set_device_io_width(leaf, dev_item, device->io_width); 340 btrfs_set_device_io_width(leaf, dev_item, device->io_width);
347 btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); 341 btrfs_set_device_sector_size(leaf, dev_item, device->sector_size);
348 btrfs_set_device_rdev(leaf, dev_item, device->rdev);
349 btrfs_set_device_partition(leaf, dev_item, device->partition);
350 btrfs_set_device_total_bytes(leaf, dev_item, device->total_bytes); 342 btrfs_set_device_total_bytes(leaf, dev_item, device->total_bytes);
351 btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used); 343 btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used);
352 btrfs_mark_buffer_dirty(leaf); 344 btrfs_mark_buffer_dirty(leaf);
@@ -676,7 +668,6 @@ static int fill_device_from_item(struct extent_buffer *leaf,
676 struct btrfs_device *device) 668 struct btrfs_device *device)
677{ 669{
678 unsigned long ptr; 670 unsigned long ptr;
679 char *name;
680 671
681 device->devid = btrfs_device_id(leaf, dev_item); 672 device->devid = btrfs_device_id(leaf, dev_item);
682 device->total_bytes = btrfs_device_total_bytes(leaf, dev_item); 673 device->total_bytes = btrfs_device_total_bytes(leaf, dev_item);
@@ -685,24 +676,14 @@ static int fill_device_from_item(struct extent_buffer *leaf,
685 device->io_align = btrfs_device_io_align(leaf, dev_item); 676 device->io_align = btrfs_device_io_align(leaf, dev_item);
686 device->io_width = btrfs_device_io_width(leaf, dev_item); 677 device->io_width = btrfs_device_io_width(leaf, dev_item);
687 device->sector_size = btrfs_device_sector_size(leaf, dev_item); 678 device->sector_size = btrfs_device_sector_size(leaf, dev_item);
688 device->rdev = btrfs_device_rdev(leaf, dev_item);
689 device->partition = btrfs_device_partition(leaf, dev_item);
690 device->name_len = btrfs_device_name_len(leaf, dev_item);
691 679
692 ptr = (unsigned long)btrfs_device_uuid(dev_item); 680 ptr = (unsigned long)btrfs_device_uuid(dev_item);
693 read_extent_buffer(leaf, device->uuid, ptr, BTRFS_DEV_UUID_SIZE); 681 read_extent_buffer(leaf, device->uuid, ptr, BTRFS_DEV_UUID_SIZE);
694 682
695 name = kmalloc(device->name_len + 1, GFP_NOFS);
696 if (!name)
697 return -ENOMEM;
698 device->name = name;
699 ptr = (unsigned long)btrfs_device_name(dev_item);
700 read_extent_buffer(leaf, name, ptr, device->name_len);
701 name[device->name_len] = '\0';
702 return 0; 683 return 0;
703} 684}
704 685
705static int read_one_dev(struct btrfs_root *root, struct btrfs_key *key, 686static int read_one_dev(struct btrfs_root *root,
706 struct extent_buffer *leaf, 687 struct extent_buffer *leaf,
707 struct btrfs_dev_item *dev_item) 688 struct btrfs_dev_item *dev_item)
708{ 689{
@@ -722,7 +703,6 @@ static int read_one_dev(struct btrfs_root *root, struct btrfs_key *key,
722 fill_device_from_item(leaf, dev_item, device); 703 fill_device_from_item(leaf, dev_item, device);
723 device->dev_root = root->fs_info->dev_root; 704 device->dev_root = root->fs_info->dev_root;
724 device->bdev = root->fs_info->sb->s_bdev; 705 device->bdev = root->fs_info->sb->s_bdev;
725 memcpy(&device->dev_key, key, sizeof(*key));
726 ret = 0; 706 ret = 0;
727#if 0 707#if 0
728 ret = btrfs_open_device(device); 708 ret = btrfs_open_device(device);
@@ -733,12 +713,20 @@ static int read_one_dev(struct btrfs_root *root, struct btrfs_key *key,
733 return ret; 713 return ret;
734} 714}
735 715
716int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf)
717{
718 struct btrfs_dev_item *dev_item;
719
720 dev_item = (struct btrfs_dev_item *)offsetof(struct btrfs_super_block,
721 dev_item);
722 return read_one_dev(root, buf, dev_item);
723}
724
736int btrfs_read_sys_array(struct btrfs_root *root) 725int btrfs_read_sys_array(struct btrfs_root *root)
737{ 726{
738 struct btrfs_super_block *super_copy = &root->fs_info->super_copy; 727 struct btrfs_super_block *super_copy = &root->fs_info->super_copy;
739 struct extent_buffer *sb = root->fs_info->sb_buffer; 728 struct extent_buffer *sb = root->fs_info->sb_buffer;
740 struct btrfs_disk_key *disk_key; 729 struct btrfs_disk_key *disk_key;
741 struct btrfs_dev_item *dev_item;
742 struct btrfs_chunk *chunk; 730 struct btrfs_chunk *chunk;
743 struct btrfs_key key; 731 struct btrfs_key key;
744 u32 num_stripes; 732 u32 num_stripes;
@@ -748,7 +736,6 @@ int btrfs_read_sys_array(struct btrfs_root *root)
748 unsigned long sb_ptr; 736 unsigned long sb_ptr;
749 u32 cur; 737 u32 cur;
750 int ret; 738 int ret;
751 int dev_only = 1;
752 739
753 array_size = btrfs_super_sys_array_size(super_copy); 740 array_size = btrfs_super_sys_array_size(super_copy);
754 741
@@ -757,7 +744,6 @@ int btrfs_read_sys_array(struct btrfs_root *root)
757 * once for all of the chunks. This way there are device 744 * once for all of the chunks. This way there are device
758 * structs filled in for every chunk 745 * structs filled in for every chunk
759 */ 746 */
760again:
761 ptr = super_copy->sys_chunk_array; 747 ptr = super_copy->sys_chunk_array;
762 sb_ptr = offsetof(struct btrfs_super_block, sys_chunk_array); 748 sb_ptr = offsetof(struct btrfs_super_block, sys_chunk_array);
763 cur = 0; 749 cur = 0;
@@ -771,22 +757,10 @@ again:
771 sb_ptr += len; 757 sb_ptr += len;
772 cur += len; 758 cur += len;
773 759
774 if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID && 760 if (key.type == BTRFS_CHUNK_ITEM_KEY) {
775 key.type == BTRFS_DEV_ITEM_KEY) {
776 dev_item = (struct btrfs_dev_item *)sb_ptr;
777 if (dev_only) {
778 ret = read_one_dev(root, &key, sb, dev_item);
779 BUG_ON(ret);
780 }
781 len = sizeof(*dev_item);
782 len += btrfs_device_name_len(sb, dev_item);
783 } else if (key.type == BTRFS_CHUNK_ITEM_KEY) {
784
785 chunk = (struct btrfs_chunk *)sb_ptr; 761 chunk = (struct btrfs_chunk *)sb_ptr;
786 if (!dev_only) { 762 ret = read_one_chunk(root, &key, sb, chunk);
787 ret = read_one_chunk(root, &key, sb, chunk); 763 BUG_ON(ret);
788 BUG_ON(ret);
789 }
790 num_stripes = btrfs_chunk_num_stripes(sb, chunk); 764 num_stripes = btrfs_chunk_num_stripes(sb, chunk);
791 len = btrfs_chunk_item_size(num_stripes); 765 len = btrfs_chunk_item_size(num_stripes);
792 } else { 766 } else {
@@ -796,10 +770,6 @@ again:
796 sb_ptr += len; 770 sb_ptr += len;
797 cur += len; 771 cur += len;
798 } 772 }
799 if (dev_only == 1) {
800 dev_only = 0;
801 goto again;
802 }
803 return 0; 773 return 0;
804} 774}
805 775
@@ -846,8 +816,7 @@ again:
846 struct btrfs_dev_item *dev_item; 816 struct btrfs_dev_item *dev_item;
847 dev_item = btrfs_item_ptr(leaf, slot, 817 dev_item = btrfs_item_ptr(leaf, slot,
848 struct btrfs_dev_item); 818 struct btrfs_dev_item);
849 ret = read_one_dev(root, &found_key, leaf, 819 ret = read_one_dev(root, leaf, dev_item);
850 dev_item);
851 BUG_ON(ret); 820 BUG_ON(ret);
852 } 821 }
853 } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { 822 } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) {