diff options
author | Chris Mason <chris.mason@oracle.com> | 2011-11-03 15:17:42 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-11-06 03:04:15 -0500 |
commit | af31f5e5b84b5bf2bcec464153a5130b170b2770 (patch) | |
tree | f8f5d8f18a115431e8826fa1c46580311dc1e485 /fs/btrfs/ctree.h | |
parent | 6c41761fc6efe1503103a1afe03a6635c0b5d4ec (diff) |
Btrfs: add a log of past tree roots
This takes some of the free space in the btrfs super block
to record information about most of the roots in the last four
commits.
It also adds a -o recovery to use the root history log when
we're not able to read the tree of tree roots, the extent
tree root, the device tree root or the csum root.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 5181c53c1124..78f43d1102a0 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -361,6 +361,47 @@ struct btrfs_header { | |||
361 | #define BTRFS_LABEL_SIZE 256 | 361 | #define BTRFS_LABEL_SIZE 256 |
362 | 362 | ||
363 | /* | 363 | /* |
364 | * just in case we somehow lose the roots and are not able to mount, | ||
365 | * we store an array of the roots from previous transactions | ||
366 | * in the super. | ||
367 | */ | ||
368 | #define BTRFS_NUM_BACKUP_ROOTS 4 | ||
369 | struct btrfs_root_backup { | ||
370 | __le64 tree_root; | ||
371 | __le64 tree_root_gen; | ||
372 | |||
373 | __le64 chunk_root; | ||
374 | __le64 chunk_root_gen; | ||
375 | |||
376 | __le64 extent_root; | ||
377 | __le64 extent_root_gen; | ||
378 | |||
379 | __le64 fs_root; | ||
380 | __le64 fs_root_gen; | ||
381 | |||
382 | __le64 dev_root; | ||
383 | __le64 dev_root_gen; | ||
384 | |||
385 | __le64 csum_root; | ||
386 | __le64 csum_root_gen; | ||
387 | |||
388 | __le64 total_bytes; | ||
389 | __le64 bytes_used; | ||
390 | __le64 num_devices; | ||
391 | /* future */ | ||
392 | __le64 unsed_64[4]; | ||
393 | |||
394 | u8 tree_root_level; | ||
395 | u8 chunk_root_level; | ||
396 | u8 extent_root_level; | ||
397 | u8 fs_root_level; | ||
398 | u8 dev_root_level; | ||
399 | u8 csum_root_level; | ||
400 | /* future and to align */ | ||
401 | u8 unused_8[10]; | ||
402 | } __attribute__ ((__packed__)); | ||
403 | |||
404 | /* | ||
364 | * the super block basically lists the main trees of the FS | 405 | * the super block basically lists the main trees of the FS |
365 | * it currently lacks any block count etc etc | 406 | * it currently lacks any block count etc etc |
366 | */ | 407 | */ |
@@ -406,6 +447,7 @@ struct btrfs_super_block { | |||
406 | /* future expansion */ | 447 | /* future expansion */ |
407 | __le64 reserved[31]; | 448 | __le64 reserved[31]; |
408 | u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; | 449 | u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; |
450 | struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS]; | ||
409 | } __attribute__ ((__packed__)); | 451 | } __attribute__ ((__packed__)); |
410 | 452 | ||
411 | /* | 453 | /* |
@@ -1113,6 +1155,9 @@ struct btrfs_fs_info { | |||
1113 | u64 fs_state; | 1155 | u64 fs_state; |
1114 | 1156 | ||
1115 | struct btrfs_delayed_root *delayed_root; | 1157 | struct btrfs_delayed_root *delayed_root; |
1158 | |||
1159 | /* next backup root to be overwritten */ | ||
1160 | int backup_root_index; | ||
1116 | }; | 1161 | }; |
1117 | 1162 | ||
1118 | /* | 1163 | /* |
@@ -1357,6 +1402,7 @@ struct btrfs_ioctl_defrag_range_args { | |||
1357 | #define BTRFS_MOUNT_ENOSPC_DEBUG (1 << 15) | 1402 | #define BTRFS_MOUNT_ENOSPC_DEBUG (1 << 15) |
1358 | #define BTRFS_MOUNT_AUTO_DEFRAG (1 << 16) | 1403 | #define BTRFS_MOUNT_AUTO_DEFRAG (1 << 16) |
1359 | #define BTRFS_MOUNT_INODE_MAP_CACHE (1 << 17) | 1404 | #define BTRFS_MOUNT_INODE_MAP_CACHE (1 << 17) |
1405 | #define BTRFS_MOUNT_RECOVERY (1 << 18) | ||
1360 | 1406 | ||
1361 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | 1407 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
1362 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | 1408 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
@@ -1972,6 +2018,55 @@ static inline bool btrfs_root_readonly(struct btrfs_root *root) | |||
1972 | return root->root_item.flags & BTRFS_ROOT_SUBVOL_RDONLY; | 2018 | return root->root_item.flags & BTRFS_ROOT_SUBVOL_RDONLY; |
1973 | } | 2019 | } |
1974 | 2020 | ||
2021 | /* struct btrfs_root_backup */ | ||
2022 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, | ||
2023 | tree_root, 64); | ||
2024 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, | ||
2025 | tree_root_gen, 64); | ||
2026 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, | ||
2027 | tree_root_level, 8); | ||
2028 | |||
2029 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, | ||
2030 | chunk_root, 64); | ||
2031 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, | ||
2032 | chunk_root_gen, 64); | ||
2033 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, | ||
2034 | chunk_root_level, 8); | ||
2035 | |||
2036 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, | ||
2037 | extent_root, 64); | ||
2038 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, | ||
2039 | extent_root_gen, 64); | ||
2040 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, | ||
2041 | extent_root_level, 8); | ||
2042 | |||
2043 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, | ||
2044 | fs_root, 64); | ||
2045 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, | ||
2046 | fs_root_gen, 64); | ||
2047 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, | ||
2048 | fs_root_level, 8); | ||
2049 | |||
2050 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, | ||
2051 | dev_root, 64); | ||
2052 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, | ||
2053 | dev_root_gen, 64); | ||
2054 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, | ||
2055 | dev_root_level, 8); | ||
2056 | |||
2057 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, | ||
2058 | csum_root, 64); | ||
2059 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, | ||
2060 | csum_root_gen, 64); | ||
2061 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, | ||
2062 | csum_root_level, 8); | ||
2063 | BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, | ||
2064 | total_bytes, 64); | ||
2065 | BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, | ||
2066 | bytes_used, 64); | ||
2067 | BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, | ||
2068 | num_devices, 64); | ||
2069 | |||
1975 | /* struct btrfs_super_block */ | 2070 | /* struct btrfs_super_block */ |
1976 | 2071 | ||
1977 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); | 2072 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); |