aboutsummaryrefslogtreecommitdiffstats
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
parente085def2c4cc2d7c0c316376b4b66b86b10e3a4b (diff)
Btrfs: Move device information into the super block so it can be scanned
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r--fs/btrfs/ctree.h21
-rw-r--r--fs/btrfs/disk-io.c4
-rw-r--r--fs/btrfs/print-tree.c15
-rw-r--r--fs/btrfs/volumes.c61
-rw-r--r--fs/btrfs/volumes.h13
5 files changed, 23 insertions, 91 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 285fb7e46106..96a493217860 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -150,21 +150,11 @@ struct btrfs_dev_item {
150 /* minimal io size for this device */ 150 /* minimal io size for this device */
151 __le32 sector_size; 151 __le32 sector_size;
152 152
153 /* the kernel device number */
154 __le64 rdev;
155
156 /* type and info about this device */ 153 /* type and info about this device */
157 __le64 type; 154 __le64 type;
158 155
159 /* partition number, 0 for whole dev */ 156 /* btrfs generated uuid for this device */
160 __le32 partition;
161
162 /* length of the name data at the end of the item */
163 __le16 name_len;
164
165 /* physical drive uuid (or lvm uuid) */
166 u8 uuid[BTRFS_DEV_UUID_SIZE]; 157 u8 uuid[BTRFS_DEV_UUID_SIZE];
167 /* name goes here */
168} __attribute__ ((__packed__)); 158} __attribute__ ((__packed__));
169 159
170struct btrfs_stripe { 160struct btrfs_stripe {
@@ -255,6 +245,7 @@ struct btrfs_super_block {
255 __le32 sys_chunk_array_size; 245 __le32 sys_chunk_array_size;
256 u8 root_level; 246 u8 root_level;
257 u8 chunk_root_level; 247 u8 chunk_root_level;
248 struct btrfs_dev_item dev_item;
258 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; 249 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
259} __attribute__ ((__packed__)); 250} __attribute__ ((__packed__));
260 251
@@ -685,20 +676,12 @@ BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
685BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); 676BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
686BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); 677BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
687BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); 678BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
688BTRFS_SETGET_FUNCS(device_rdev, struct btrfs_dev_item, rdev, 64);
689BTRFS_SETGET_FUNCS(device_partition, struct btrfs_dev_item, partition, 32);
690BTRFS_SETGET_FUNCS(device_name_len, struct btrfs_dev_item, name_len, 16);
691 679
692static inline char *btrfs_device_uuid(struct btrfs_dev_item *d) 680static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
693{ 681{
694 return (char *)d + offsetof(struct btrfs_dev_item, uuid); 682 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
695} 683}
696 684
697static inline char *btrfs_device_name(struct btrfs_dev_item *d)
698{
699 return (char *)(d + 1);
700}
701
702BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); 685BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
703BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); 686BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
704BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); 687BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2a239ae49f78..26185d46712c 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -370,7 +370,6 @@ static int close_all_devices(struct btrfs_fs_info *fs_info)
370 next = list->next; 370 next = list->next;
371 list_del(next); 371 list_del(next);
372 device = list_entry(next, struct btrfs_device, dev_list); 372 device = list_entry(next, struct btrfs_device, dev_list);
373 kfree(device->name);
374 kfree(device); 373 kfree(device);
375 } 374 }
376 return 0; 375 return 0;
@@ -800,6 +799,9 @@ struct btrfs_root *open_ctree(struct super_block *sb)
800 } 799 }
801 800
802 mutex_lock(&fs_info->fs_mutex); 801 mutex_lock(&fs_info->fs_mutex);
802 ret = btrfs_read_super_device(tree_root, fs_info->sb_buffer);
803 BUG_ON(ret);
804
803 ret = btrfs_read_sys_array(tree_root); 805 ret = btrfs_read_sys_array(tree_root);
804 BUG_ON(ret); 806 BUG_ON(ret);
805 807
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 9c1335dad40c..ee0de112cf5a 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -37,22 +37,11 @@ static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
37static void print_dev_item(struct extent_buffer *eb, 37static void print_dev_item(struct extent_buffer *eb,
38 struct btrfs_dev_item *dev_item) 38 struct btrfs_dev_item *dev_item)
39{ 39{
40 char *name; 40 printk("\t\tdev item devid %llu "
41 int name_len; 41 "total_bytes %llu bytes used %Lu\n",
42
43 name_len = btrfs_device_name_len(eb, dev_item);
44 name = kmalloc(name_len, GFP_NOFS);
45 if (name) {
46 read_extent_buffer(eb, name,
47 (unsigned long)btrfs_device_name(dev_item),
48 name_len);
49 }
50 printk("\t\tdev item name %.*s devid %llu "
51 "total_bytes %llu bytes used %Lu\n", name_len, name,
52 (unsigned long long)btrfs_device_id(eb, dev_item), 42 (unsigned long long)btrfs_device_id(eb, dev_item),
53 (unsigned long long)btrfs_device_total_bytes(eb, dev_item), 43 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
54 (unsigned long long)btrfs_device_bytes_used(eb, dev_item)); 44 (unsigned long long)btrfs_device_bytes_used(eb, dev_item));
55 kfree(name);
56} 45}
57void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) 46void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
58{ 47{
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) {
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 4ab9891878a8..77fa6efd79cf 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -21,7 +21,6 @@
21struct btrfs_device { 21struct btrfs_device {
22 struct list_head dev_list; 22 struct list_head dev_list;
23 struct btrfs_root *dev_root; 23 struct btrfs_root *dev_root;
24 struct btrfs_key dev_key;
25 24
26 struct block_device *bdev; 25 struct block_device *bdev;
27 26
@@ -43,22 +42,11 @@ struct btrfs_device {
43 /* minimal io size for this device */ 42 /* minimal io size for this device */
44 u32 sector_size; 43 u32 sector_size;
45 44
46 /* the kernel device number */
47 u64 rdev;
48
49 /* type and info about this device */ 45 /* type and info about this device */
50 u64 type; 46 u64 type;
51 47
52 /* partition number, 0 for whole dev */
53 int partition;
54
55 /* length of the name data at the end of the item */
56 int name_len;
57
58 /* physical drive uuid (or lvm uuid) */ 48 /* physical drive uuid (or lvm uuid) */
59 u8 uuid[BTRFS_DEV_UUID_SIZE]; 49 u8 uuid[BTRFS_DEV_UUID_SIZE];
60
61 char *name;
62}; 50};
63 51
64int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, 52int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
@@ -75,4 +63,5 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
75void btrfs_mapping_init(struct btrfs_mapping_tree *tree); 63void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
76void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); 64void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
77int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio); 65int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio);
66int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf);
78#endif 67#endif