diff options
-rw-r--r-- | fs/btrfs/ctree.h | 70 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 11 |
2 files changed, 76 insertions, 5 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 3f3a23f52a3b..01310de2bf4a 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -13,10 +13,11 @@ extern struct kmem_cache *btrfs_path_cachep; | |||
13 | #define BTRFS_MAGIC "_BtRfS_M" | 13 | #define BTRFS_MAGIC "_BtRfS_M" |
14 | 14 | ||
15 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL | 15 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
16 | #define BTRFS_EXTENT_TREE_OBJECTID 2ULL | 16 | #define BTRFS_DEV_TREE_OBJECTID 2ULL |
17 | #define BTRFS_FS_TREE_OBJECTID 3ULL | 17 | #define BTRFS_EXTENT_TREE_OBJECTID 3ULL |
18 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL | 18 | #define BTRFS_FS_TREE_OBJECTID 4ULL |
19 | #define BTRFS_FIRST_FREE_OBJECTID 5ULL | 19 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL |
20 | #define BTRFS_FIRST_FREE_OBJECTID 6ULL | ||
20 | 21 | ||
21 | /* | 22 | /* |
22 | * we can actually store much bigger names, but lets not confuse the rest | 23 | * we can actually store much bigger names, but lets not confuse the rest |
@@ -90,6 +91,10 @@ struct btrfs_super_block { | |||
90 | __le64 total_blocks; | 91 | __le64 total_blocks; |
91 | __le64 blocks_used; | 92 | __le64 blocks_used; |
92 | __le64 root_dir_objectid; | 93 | __le64 root_dir_objectid; |
94 | /* fields below here vary with the underlying disk */ | ||
95 | __le64 device_block_start; | ||
96 | __le64 device_num_blocks; | ||
97 | __le64 device_root; | ||
93 | } __attribute__ ((__packed__)); | 98 | } __attribute__ ((__packed__)); |
94 | 99 | ||
95 | /* | 100 | /* |
@@ -223,10 +228,15 @@ struct btrfs_csum_item { | |||
223 | u8 csum[BTRFS_CSUM_SIZE]; | 228 | u8 csum[BTRFS_CSUM_SIZE]; |
224 | } __attribute__ ((__packed__)); | 229 | } __attribute__ ((__packed__)); |
225 | 230 | ||
231 | struct btrfs_device_item { | ||
232 | __le16 pathlen; | ||
233 | } __attribute__ ((__packed__)); | ||
234 | |||
226 | struct crypto_hash; | 235 | struct crypto_hash; |
227 | struct btrfs_fs_info { | 236 | struct btrfs_fs_info { |
228 | struct btrfs_root *extent_root; | 237 | struct btrfs_root *extent_root; |
229 | struct btrfs_root *tree_root; | 238 | struct btrfs_root *tree_root; |
239 | struct btrfs_root *dev_root; | ||
230 | struct btrfs_key current_insert; | 240 | struct btrfs_key current_insert; |
231 | struct btrfs_key last_insert; | 241 | struct btrfs_key last_insert; |
232 | struct radix_tree_root fs_roots_radix; | 242 | struct radix_tree_root fs_roots_radix; |
@@ -313,10 +323,15 @@ struct btrfs_root { | |||
313 | #define BTRFS_EXTENT_ITEM_KEY 8 | 323 | #define BTRFS_EXTENT_ITEM_KEY 8 |
314 | 324 | ||
315 | /* | 325 | /* |
326 | * dev items list the devices that make up the FS | ||
327 | */ | ||
328 | #define BTRFS_DEV_ITEM_KEY 9 | ||
329 | |||
330 | /* | ||
316 | * string items are for debugging. They just store a short string of | 331 | * string items are for debugging. They just store a short string of |
317 | * data in the FS | 332 | * data in the FS |
318 | */ | 333 | */ |
319 | #define BTRFS_STRING_ITEM_KEY 9 | 334 | #define BTRFS_STRING_ITEM_KEY 10 |
320 | 335 | ||
321 | static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) | 336 | static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) |
322 | { | 337 | { |
@@ -782,6 +797,40 @@ static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64 | |||
782 | s->root_dir_objectid = cpu_to_le64(val); | 797 | s->root_dir_objectid = cpu_to_le64(val); |
783 | } | 798 | } |
784 | 799 | ||
800 | static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s) | ||
801 | { | ||
802 | return le64_to_cpu(s->device_block_start); | ||
803 | } | ||
804 | |||
805 | static inline void btrfs_set_super_device_block_start(struct btrfs_super_block | ||
806 | *s, u64 val) | ||
807 | { | ||
808 | s->device_block_start = cpu_to_le64(val); | ||
809 | } | ||
810 | |||
811 | static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s) | ||
812 | { | ||
813 | return le64_to_cpu(s->device_num_blocks); | ||
814 | } | ||
815 | |||
816 | static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block | ||
817 | *s, u64 val) | ||
818 | { | ||
819 | s->device_num_blocks = cpu_to_le64(val); | ||
820 | } | ||
821 | |||
822 | static inline u64 btrfs_super_device_root(struct btrfs_super_block *s) | ||
823 | { | ||
824 | return le64_to_cpu(s->device_root); | ||
825 | } | ||
826 | |||
827 | static inline void btrfs_set_super_device_root(struct btrfs_super_block | ||
828 | *s, u64 val) | ||
829 | { | ||
830 | s->device_root = cpu_to_le64(val); | ||
831 | } | ||
832 | |||
833 | |||
785 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) | 834 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) |
786 | { | 835 | { |
787 | return (u8 *)l->items; | 836 | return (u8 *)l->items; |
@@ -849,6 +898,17 @@ static inline void btrfs_set_file_extent_num_blocks(struct | |||
849 | e->num_blocks = cpu_to_le64(val); | 898 | e->num_blocks = cpu_to_le64(val); |
850 | } | 899 | } |
851 | 900 | ||
901 | static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d) | ||
902 | { | ||
903 | return le16_to_cpu(d->pathlen); | ||
904 | } | ||
905 | |||
906 | static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d, | ||
907 | u16 val) | ||
908 | { | ||
909 | d->pathlen = cpu_to_le16(val); | ||
910 | } | ||
911 | |||
852 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) | 912 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) |
853 | { | 913 | { |
854 | return sb->s_fs_info; | 914 | return sb->s_fs_info; |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index ff69162829b3..e09233262af6 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -378,6 +378,8 @@ struct btrfs_root *open_ctree(struct super_block *sb) | |||
378 | { | 378 | { |
379 | struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root), | 379 | struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root), |
380 | GFP_NOFS); | 380 | GFP_NOFS); |
381 | struct btrfs_root *dev_root = kmalloc(sizeof(struct btrfs_root), | ||
382 | GFP_NOFS); | ||
381 | struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root), | 383 | struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root), |
382 | GFP_NOFS); | 384 | GFP_NOFS); |
383 | struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info), | 385 | struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info), |
@@ -392,6 +394,7 @@ struct btrfs_root *open_ctree(struct super_block *sb) | |||
392 | fs_info->running_transaction = NULL; | 394 | fs_info->running_transaction = NULL; |
393 | fs_info->tree_root = tree_root; | 395 | fs_info->tree_root = tree_root; |
394 | fs_info->extent_root = extent_root; | 396 | fs_info->extent_root = extent_root; |
397 | fs_info->dev_root = dev_root; | ||
395 | fs_info->sb = sb; | 398 | fs_info->sb = sb; |
396 | fs_info->btree_inode = new_inode(sb); | 399 | fs_info->btree_inode = new_inode(sb); |
397 | fs_info->btree_inode->i_ino = 1; | 400 | fs_info->btree_inode->i_ino = 1; |
@@ -414,6 +417,9 @@ struct btrfs_root *open_ctree(struct super_block *sb) | |||
414 | memset(&fs_info->current_insert, 0, sizeof(fs_info->current_insert)); | 417 | memset(&fs_info->current_insert, 0, sizeof(fs_info->current_insert)); |
415 | memset(&fs_info->last_insert, 0, sizeof(fs_info->last_insert)); | 418 | memset(&fs_info->last_insert, 0, sizeof(fs_info->last_insert)); |
416 | 419 | ||
420 | __setup_root(sb->s_blocksize, dev_root, | ||
421 | fs_info, BTRFS_DEV_TREE_OBJECTID); | ||
422 | |||
417 | __setup_root(sb->s_blocksize, tree_root, | 423 | __setup_root(sb->s_blocksize, tree_root, |
418 | fs_info, BTRFS_ROOT_TREE_OBJECTID); | 424 | fs_info, BTRFS_ROOT_TREE_OBJECTID); |
419 | fs_info->sb_buffer = read_tree_block(tree_root, | 425 | fs_info->sb_buffer = read_tree_block(tree_root, |
@@ -427,6 +433,8 @@ struct btrfs_root *open_ctree(struct super_block *sb) | |||
427 | return NULL; | 433 | return NULL; |
428 | 434 | ||
429 | fs_info->disk_super = disk_super; | 435 | fs_info->disk_super = disk_super; |
436 | dev_root->node = read_tree_block(tree_root, | ||
437 | btrfs_super_device_root(disk_super)); | ||
430 | tree_root->node = read_tree_block(tree_root, | 438 | tree_root->node = read_tree_block(tree_root, |
431 | btrfs_super_root(disk_super)); | 439 | btrfs_super_root(disk_super)); |
432 | BUG_ON(!tree_root->node); | 440 | BUG_ON(!tree_root->node); |
@@ -519,6 +527,9 @@ int close_ctree(struct btrfs_root *root) | |||
519 | if (fs_info->extent_root->node) | 527 | if (fs_info->extent_root->node) |
520 | btrfs_block_release(fs_info->extent_root, | 528 | btrfs_block_release(fs_info->extent_root, |
521 | fs_info->extent_root->node); | 529 | fs_info->extent_root->node); |
530 | if (fs_info->dev_root->node) | ||
531 | btrfs_block_release(fs_info->dev_root, | ||
532 | fs_info->dev_root->node); | ||
522 | if (fs_info->tree_root->node) | 533 | if (fs_info->tree_root->node) |
523 | btrfs_block_release(fs_info->tree_root, | 534 | btrfs_block_release(fs_info->tree_root, |
524 | fs_info->tree_root->node); | 535 | fs_info->tree_root->node); |