Btrfs-progs: add skinny metadata support to progs V3
PATCH 1/1 Btrfs-progs: add skinny metadata support to progs V3
This fixes up the progs to properly deal with skinny metadata. This adds the -x option to mkfs and btrfstune for enabling the skinny metadata option. This also makes changes to fsck so it can properly deal with the skinny metadata entries. Thanks,
Signed-off-by Josef Bacik <[email protected]>
---V2->V3: update the mkfs.btrfs man page with the new option
This is based on Chris's master branch btw.
btrfs-image.c | 8 ++- btrfstune.c | 28 ++++++- cmds-check.c | 78 +++++++++++++----- ctree.c | 6 +- ctree.h | 23 +++++- extent-tree.c | 226 +++++++++++++++++++++++++++++++++++++++++++++------ man/mkfs.btrfs.8.in | 8 ++ mkfs.c | 13 +++- print-tree.c | 20 ++++- 9 files changed, 348 insertions(+), 62 deletions(-)
btrfs-image.c +6 -2
@@ -528,13 +528,17 @@ static int create_metadump(const char *input, FILE *out, int num_threads,btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]);if (key.objectid < bytenr || - key.type !=BTRFS_EXTENT_ITEM_KEY ) { + (key.type !=BTRFS_EXTENT_ITEM_KEY && + key.type !=BTRFS_METADATA_ITEM_KEY )) { path->slots[0 ]++;continue ; } bytenr = key.objectid; - num_bytes = key.offset; +if (key.type ==BTRFS_METADATA_ITEM_KEY ) + num_bytes = key.offset; +else + num_bytes = root->leafsize;if (btrfs_item_size_nr (leaf, path->slots[0 ]) >sizeof (*ei)) { ei = btrfs_item_ptr(leaf, path->slots[0],
btrfstune.c +27 -1
@@ -81,11 +81,28 @@ int enable_extrefs_flag(struct btrfs_root *root)return 0 ; } +int enable_skinny_metadata (struct btrfs_root *root) +{ +struct btrfs_trans_handle *trans; +struct btrfs_super_block *disk_super; +u64 super_flags; + + disk_super = &root->fs_info->super_copy; + super_flags =btrfs_super_incompat_flags (disk_super); + super_flags |=BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA ; + trans =btrfs_start_transaction (root,1 ); +btrfs_set_super_incompat_flags (disk_super, super_flags); +btrfs_commit_transaction (trans, root); + +return 0 ; +} +static void print_usage (void ) {fprintf (stderr,"usage: btrfstune [options] device\n" );fprintf (stderr,"\t-S value\tenable/disable seeding\n" );fprintf (stderr,"\t-r \t\tenable extended inode refs\n" ); +fprintf (stderr,"\t-x enable skinny metadata extent refs\n" ); }int main (int argc,char *argv[])
@@ -95,10 +112,11 @@ int main(int argc, char *argv[])int extrefs_flag =0 ;int seeding_flag =0 ;int seeding_value =0 ; +int skinny_flag =0 ;int ret;while (1 ) { -int c =getopt (argc, argv,"S:r" ); +int c =getopt (argc, argv,"S:rx" );if (c <0 )break ;switch (c) {
@@ -109,6 +127,9 @@ int main(int argc, char *argv[])case 'r' : extrefs_flag =1 ;break ; +case 'x' : + skinny_flag =1 ; +break ;default :print_usage ();return 1 ;
@@ -145,6 +166,11 @@ int main(int argc, char *argv[]) success++; } +if (skinny_flag) { +enable_skinny_metadata (root); + success++; + } +if (success >0 ) { ret =0 ; }else {
cmds-check.c +56 -22
230 lines not on this page · raw message
ctree.c +4 -2
@@ -235,7 +235,8 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,if (btrfs_block_can_be_shared (root, buf)) { ret =btrfs_lookup_extent_info (trans, root, buf->start, - buf->len, &refs, &flags); +btrfs_header_level (buf),1 , + &refs, &flags);BUG_ON (ret);BUG_ON (refs ==0 ); }else {
@@ -277,7 +278,8 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, }if (new_flags !=0 ) { ret =btrfs_set_block_flags (trans, root, buf->start, - buf->len, new_flags); +btrfs_header_level (buf), + new_flags);BUG_ON (ret); } }else {
ctree.h +19 -4
@@ -445,9 +445,10 @@ struct btrfs_super_block {* code was pretty buggy. Lets not let them try anymore. */ #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5) +#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7) +#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8) -#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)#define BTRFS_FEATURE_COMPAT_SUPP 0ULL#define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
@@ -458,7 +459,8 @@ struct btrfs_super_block {BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \BTRFS_FEATURE_INCOMPAT_RAID56 | \ - BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) +BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \ + BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)/* * A leaf is full of items. offset and size tell us where to find
@@ -1034,6 +1036,12 @@ struct btrfs_root {*/ #define BTRFS_EXTENT_ITEM_KEY 168 +/* +* The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know +* the length, so we save the level in key->offset instead of the length. +*/ +#define BTRFS_METADATA_ITEM_KEY 169 +#define BTRFS_TREE_BLOCK_REF_KEY 176#define BTRFS_EXTENT_DATA_REF_KEY 178
@@ -2018,6 +2026,13 @@ static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {return root->nodesize; } +static inline int btrfs_fs_incompat (struct btrfs_fs_info *fs_info,u64 flag) +{ +struct btrfs_super_block *disk_super; + disk_super = &fs_info->super_copy; +return !!(btrfs_super_incompat_flags (disk_super) & flag); +} +/* helper function to cast into the data area of the leaf. */ #define btrfs_item_ptr (leaf, slot, type) \ ((type *)(btrfs_leaf_data(leaf) + \
@@ -2055,10 +2070,10 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans, u64 search_end, struct btrfs_key *ins, int data);int btrfs_lookup_extent_info (struct btrfs_trans_handle *trans,struct btrfs_root *root,u64 bytenr, -u64 num_bytes,u64 *refs,u64 *flags); +u64 offset,int metadata,u64 *refs,u64 *flags);int btrfs_set_block_flags (struct btrfs_trans_handle *trans,struct btrfs_root *root, -u64 bytenr,u64 num_bytes,u64 flags); +u64 bytenr,int level,u64 flags);int btrfs_inc_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct extent_buffer *buf,int record_parent); int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
extent-tree.c +201 -25
396 lines not on this page · raw message
man/mkfs.btrfs.8.in +8 -0
@@ -17,6 +17,7 @@ mkfs.btrfs \- create a btrfs filesystem [ \fB\-K\fP ] [ \fB\-h\fP ] [ \fB\-V\fP ] +[ \fB\-x\fP\fI skinny-extents\fP ] \fI device\fP [ \fIdevice ...\fP ] .SH DESCRIPTION .B mkfs.btrfs
@@ -78,6 +79,13 @@ Do not perform whole device TRIM operation by default. .TP \fB\-V\fR, \fB\-\-version\fR Print the \fBmkfs.btrfs\fP version and exit. +.TP +\fB\-x\fR, \fB\-\-skinny\-extents\fR +Use the new skinny extents disk format. This is an non-backwards compatible +format change. This allows btrfs to use a smaller item for describing +metadata blocks in the extent tree. This results in a 30% savings in the +extent tree size, which improves performance on file systems with lots of +metadata. .SH UNIT As default the unit is the byte, however it is possible to append a suffix to the arguments like \fBk\fP for KBytes, \fBm\fP for MBytes...
mkfs.c +11 -2
@@ -336,6 +336,7 @@ static void print_usage(void)fprintf (stderr,"\t -r --rootdir the source directory\n" );fprintf (stderr,"\t -K --nodiscard do not perform whole device TRIM\n" );fprintf (stderr,"\t -V --version print the mkfs.btrfs version and exit\n" ); +fprintf (stderr,"\t -x --skinny-extents use the new skinny extent disk format" );fprintf (stderr,"%s\n" ,BTRFS_BUILD_VERSION );exit (1 ); }
@@ -395,6 +396,7 @@ static struct option long_options[] = { { "version", 0, NULL, 'V' }, { "rootdir", 1, NULL, 'r' }, { "nodiscard", 0, NULL, 'K' }, + { "skinny-extents", 0, NULL, 'x'}, { 0, 0, 0, 0} };
@@ -1367,6 +1369,7 @@ int main(int ac, char **av)int nodiscard =0 ;int ssd =0 ;int force_overwrite =0 ; +int skinny_meta_extents =0 ;char *source_dir =NULL ;int source_dir_set =0 ;
@@ -1379,8 +1382,8 @@ int main(int ac, char **av)while (1 ) {int c; - c =getopt_long (ac, av,"A:b:fl:n:s:m:d:L:r:VMK" , long_options, - &option_index); + c =getopt_long (ac, av,"A:b:fl:n:s:m:d:L:r:VMKx" , + long_options, &option_index);if (c <0 )break ;switch (c) {
@@ -1431,6 +1434,9 @@ int main(int ac, char **av)case 'K' : nodiscard=1 ;break ; +case 'x' : + skinny_meta_extents =1 ; +break ;default :print_usage (); }
@@ -1657,6 +1663,9 @@ raid_groups:if (mixed) flags |=BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS ; +if (skinny_meta_extents) + flags |=BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA ; +btrfs_set_super_incompat_flags (super, flags); if ((data_profile | metadata_profile) &
print-tree.c +16 -4
@@ -202,7 +202,7 @@ static void print_file_extent_item(struct extent_buffer *eb, btrfs_file_extent_compression(eb, fi)); } -static void print_extent_item (struct extent_buffer *eb,int slot) +static void print_extent_item (struct extent_buffer *eb,int slot,int metadata) {struct btrfs_extent_item *ei;struct btrfs_extent_inline_ref *iref;
@@ -237,7 +237,7 @@ static void print_extent_item(struct extent_buffer *eb, int slot) (unsigned long long )btrfs_extent_generation (eb, ei), (unsigned long long)flags); -if (flags &BTRFS_EXTENT_FLAG_TREE_BLOCK ) { +if (flags &BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {struct btrfs_tree_block_info *info; info = (struct btrfs_tree_block_info *)(ei +1 );btrfs_tree_block_key (eb, info, &key);
@@ -245,7 +245,13 @@ static void print_extent_item(struct extent_buffer *eb, int slot)btrfs_print_key (&key);printf (" level %d\n" ,btrfs_tree_block_level (eb, info)); iref = (struct btrfs_extent_inline_ref *)(info +1 ); - }else { + }else if (metadata) { +struct btrfs_key tmp; + +btrfs_item_key_to_cpu (eb, &tmp, slot); +printf ("\t\ttree block skinny level %d\n" , (int )tmp.offset); + iref = (struct btrfs_extent_inline_ref *)(ei +1 ); + }else { iref = (struct btrfs_extent_inline_ref *)(ei +1 ); }
@@ -440,6 +446,9 @@ static void print_key_type(u64 objectid, u8 type)case BTRFS_EXTENT_ITEM_KEY :printf ("EXTENT_ITEM" );break ; +case BTRFS_METADATA_ITEM_KEY : +printf ("METADATA_ITEM" ); +break ;case BTRFS_TREE_BLOCK_REF_KEY :printf ("TREE_BLOCK_REF" );break ;
@@ -699,7 +708,10 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)print_root_ref (l, i,"backref" );break ;case BTRFS_EXTENT_ITEM_KEY : -print_extent_item (l, i); +print_extent_item (l, i,0 ); +break ; +case BTRFS_METADATA_ITEM_KEY : +print_extent_item (l, i,1 );break ;case BTRFS_TREE_BLOCK_REF_KEY :printf ("\t\ttree block backref\n" );
Signature · 1 line
1.7.7.6