Skip to contentSkip to conversation

Btrfs: Make kernel support chunk tree backup

RFC PATCH New WuBo 1 participant 1 message Jun 23, 2011 Btrfs file system

lore
Share & tools
lore

WuBo

author
#0 lore raw

RFC PATCH 1/1 Btrfs: Make kernel support chunk tree backup

I've been diging into the idea of chunk tree backups. Here is the design, before finishing chunk alloc, the first block in this chunk will be written in some information, these information will be useful for chunk tree rebuilding if crash, also the first block will be moved into fs_info->freed_extents[2], just as the super block. after crash, we can search all the stripe header to get the whole view of the chunk tree and rebuild it.

Also I consider the balance stuff, cause the relocation will remove the block group. If then, I clear the stripe header for fear mistake.

To keep backward compatibility, BTRFS_FEATURE_INCOMPAT_CHUNK_TREE_BACKUP will be added for a incompat flag. This means the chunk tree only with the new kernel can be recovered if crash.

What we should do is making some changes in these functions:
btrfs_make_block_group
btrfs_read_block_groups
btrfs_remove_block_group

I have tested this patch by rebuilding chunk tree through writting and deleting data(using fstress.sh) repeatly, Also for stuffs like defragment balance and "add/delete device". But I appreciated if anybody do extra test for it still.

---
 fs/btrfs/ctree.h       |   14 +++--
 fs/btrfs/extent-tree.c |   94 ++++++++++++++++++++++++++++++--
 fs/btrfs/volumes.c     |  141 +++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/volumes.h     |   25 +++++++++
 4 files changed, 263 insertions(+), 11 deletions(-)
fs/btrfs/ctree.h +9 -5
index 2e61fe1..0f6d055 100644
@@ -43,6 +43,7 @@ extern struct kmem_cache *btrfs_bit_radix_cachep;
 extern struct kmem_cache *btrfs_path_cachep;
 extern struct kmem_cache *btrfs_free_space_cachep;
 struct btrfs_ordered_sum;
+struct map_lookup;
 
 #define BTRFS_MAGIC "_BHRfS_M"
 
@@ -410,6 +411,7 @@ struct btrfs_super_block {
 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL	(1ULL << 1)
 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS	(1ULL << 2)
 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO	(1ULL << 3)
+#define BTRFS_FEATURE_INCOMPAT_CHUNK_TREE_BACKUP (1ULL << 4)
 
 #define BTRFS_FEATURE_COMPAT_SUPP		0ULL
 #define BTRFS_FEATURE_COMPAT_RO_SUPP		0ULL
@@ -417,7 +419,8 @@ struct btrfs_super_block {
 	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
 	 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |	\
 	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO)
+	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |		\
+	 BTRFS_FEATURE_INCOMPAT_CHUNK_TREE_BACKUP)
 
 /*
  * A leaf is full of items. offset and size tell us where to find
@@ -2179,11 +2182,12 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info);
 int btrfs_read_block_groups(struct btrfs_root *root);
 int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr);
 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
-			   struct btrfs_root *root, u64 bytes_used,
-			   u64 type, u64 chunk_objectid, u64 chunk_offset,
-			   u64 size);
+				struct btrfs_root *root, struct map_lookup *map,
+				u64 bytes_used, u64 type, u64 chunk_objectid,
+				u64 chunk_offset, u64 size);
 int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *root, u64 group_start);
+				struct btrfs_root *root, struct map_lookup *map,
+				u64 group_start);
 u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags);
 u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data);
 void btrfs_set_inode_space_info(struct btrfs_root *root, struct inode *ionde);
fs/btrfs/extent-tree.c +90 -4

152 lines not on this page · raw message

fs/btrfs/volumes.c +139 -2

189 lines not on this page · raw message

fs/btrfs/volumes.h +25 -0
index cc2eada..fbfc338 100644
@@ -157,6 +157,31 @@ struct map_lookup {
 	struct btrfs_bio_stripe stripes[];
 };
 
+#define BTRFS_STRIPE_HEADER_TAG 19860505
+
+struct btrfs_stripe_header {
+	u8 fsid[BTRFS_FSID_SIZE];
+	u8 uuid[BTRFS_UUID_SIZE];
+	__le64 tag;
+	__le64 owner;
+	__le64 devid;
+	__le64 dev_offset;
+	__le64 chunk_offset;
+	__le64 chunk_size;
+	__le64 type;
+	__le64 stripe_len;
+	__le32 stripe_index;
+	__le32 io_align;
+	__le32 io_width;
+	__le32 sector_size;
+	__le16 num_stripes;
+	__le16 sub_stripes;
+	__le32 crc;
+} __attribute__ ((__packed__));
+
+int erase_chunk_stripes_header(struct btrfs_root *root,
+					struct map_lookup *map);
+
 /* Used to sort the devices by max_avail(descending sort) */
 int btrfs_cmp_device_free_bytes(const void *dev_info1, const void *dev_info2);
 
Signature · 1 line
1.7.3.1