Skip to content

Commit 2467f43

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: tune: rework the main idea of csum change
The existing attempt for changing csum types is as the following: - Create a new temporary csum root - Generate new data csums into the temporary csum root - Drop the old csum tree and make the temporary one as csum root - Change the checksums for metadata in-place Unfortunately after some experiments, the csum root switch method has a big pitfall, the backref items in extent tree. Those backref items still point back to the old tree, meaning without a lot of extra tricks, the extent tree would be corrupted. Thus we have to go a new single tree variant: - Generate new data csums into the csum root The new data csums would have a different objectid to distinguish them. - Drop the old data csum items - Change the key objectids of the new csums - Change the checksums for metadata in-place This means unfortunately we have to revert most of the old code, and update the temporary item format. The new temporary item would only record the target csum type. At every stage we have a method to determine the progress, thus no need for an item, but in the future it's still open for change. Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent bd3a60f commit 2467f43

File tree

9 files changed

+33
-542
lines changed

9 files changed

+33
-542
lines changed

kernel-shared/ctree.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,6 @@ int btrfs_create_root(struct btrfs_trans_handle *trans,
403403
fs_info->block_group_root = new_root;
404404
break;
405405

406-
case BTRFS_CSUM_TREE_TMP_OBJECTID:
407-
fs_info->csum_tree_tmp = new_root;
408-
break;
409406
/*
410407
* Essential trees can't be created by this function, yet.
411408
* As we expect such skeleton exists, or a lot of functions like

kernel-shared/ctree.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
5656
sizeof(struct btrfs_stripe) * (num_stripes - 1);
5757
}
5858

59-
/* Temporary flag not on-disk for blocks that have changed csum already */
60-
#define BTRFS_HEADER_FLAG_CSUM_NEW (1ULL << 16)
61-
#define BTRFS_SUPER_FLAG_CHANGING_CSUM (1ULL << 37)
59+
#define BTRFS_SUPER_FLAG_CHANGING_DATA_CSUM (1ULL << 36)
60+
#define BTRFS_SUPER_FLAG_CHANGING_META_CSUM (1ULL << 37)
6261

6362
/*
6463
* The fs is undergoing block group tree feature change.
@@ -306,9 +305,6 @@ struct btrfs_fs_info {
306305
/* the log root tree is a directory of all the other log roots */
307306
struct btrfs_root *log_root_tree;
308307

309-
/* When switching csums */
310-
struct btrfs_root *csum_tree_tmp;
311-
312308
struct cache_tree extent_cache;
313309
u64 max_cache_size;
314310
u64 cache_size;
@@ -365,7 +361,6 @@ struct btrfs_fs_info {
365361
unsigned int skip_leaf_item_checks:1;
366362

367363
int transaction_aborted;
368-
int force_csum_type;
369364

370365
int (*free_extent_hook)(u64 bytenr, u64 num_bytes, u64 parent,
371366
u64 root_objectid, u64 owner, u64 offset,
@@ -670,17 +665,11 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
670665
* - balance status item (objectid -4)
671666
* (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
672667
*
673-
* - second csum tree for conversion (objecitd
668+
* - second csum tree for conversion (objecitd -13)
669+
* (BTRFS_CSUM_CHANGE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, <target csum type>)
674670
*/
675671
#define BTRFS_TEMPORARY_ITEM_KEY 248
676672

677-
/*
678-
* Temporary value
679-
*
680-
* root tree pointer of checksum tree with new checksum type
681-
*/
682-
#define BTRFS_CSUM_TREE_TMP_OBJECTID 13ULL
683-
684673
/*
685674
* Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
686675
*/

kernel-shared/disk-io.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,6 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
215215
u16 csum_size = fs_info->csum_size;
216216
u16 csum_type = fs_info->csum_type;
217217

218-
if (fs_info->force_csum_type != -1) {
219-
/* printf("CSUM TREE: offset %llu\n", buf->start); */
220-
csum_type = fs_info->force_csum_type;
221-
csum_size = btrfs_csum_type_size(csum_type);
222-
}
223-
224218
if (verify && fs_info->suppress_check_block_errors)
225219
return verify_tree_block_csum_silent(buf, csum_size, csum_type);
226220
return csum_tree_block_size(buf, csum_size, verify, csum_type);
@@ -475,7 +469,6 @@ int write_tree_block(struct btrfs_trans_handle *trans,
475469
if (trans && !btrfs_buffer_uptodate(eb, trans->transid, 0))
476470
BUG();
477471

478-
btrfs_clear_header_flag(eb, BTRFS_HEADER_FLAG_CSUM_NEW);
479472
btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);
480473
csum_tree_block(fs_info, eb, 0);
481474

@@ -885,7 +878,6 @@ struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr)
885878
fs_info->metadata_alloc_profile = (u64)-1;
886879
fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
887880
fs_info->nr_global_roots = 1;
888-
fs_info->force_csum_type = -1;
889881

890882
return fs_info;
891883

kernel-shared/file-item.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ btrfs_lookup_csum(struct btrfs_trans_handle *trans,
142142
struct btrfs_csum_item *item;
143143
struct extent_buffer *leaf;
144144
u64 csum_offset = 0;
145-
u16 csum_type = root->fs_info->csum_type;
146145
u16 csum_size = root->fs_info->csum_size;
147146
int csums_in_item;
148147

@@ -154,11 +153,6 @@ btrfs_lookup_csum(struct btrfs_trans_handle *trans,
154153
goto fail;
155154
leaf = path->nodes[0];
156155

157-
if (leaf->fs_info->force_csum_type != -1) {
158-
csum_type = root->fs_info->force_csum_type;
159-
csum_size = btrfs_csum_type_size(csum_type);
160-
}
161-
162156
if (ret > 0) {
163157
ret = 1;
164158
if (path->slots[0] == 0)
@@ -208,12 +202,6 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
208202
u16 csum_size = root->fs_info->csum_size;
209203
u16 csum_type = root->fs_info->csum_type;
210204

211-
if (root->fs_info->force_csum_type != -1) {
212-
/* printf("CSUM DATA: offset %llu (%d -> %d)\n", bytenr, csum_type, root->fs_info->force_csum_type); */
213-
csum_type = root->fs_info->force_csum_type;
214-
csum_size = btrfs_csum_type_size(csum_type);
215-
}
216-
217205
path = btrfs_alloc_path();
218206
if (!path)
219207
return -ENOMEM;

kernel-shared/print-tree.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
790790
case BTRFS_BLOCK_GROUP_TREE_OBJECTID:
791791
fprintf(stream, "BLOCK_GROUP_TREE");
792792
break;
793+
case BTRFS_CSUM_CHANGE_OBJECTID:
794+
fprintf(stream, "CSUM_CHANGE");
795+
break;
793796
case (u64)-1:
794797
fprintf(stream, "-1");
795798
break;
@@ -1142,8 +1145,12 @@ static void print_temporary_item(struct extent_buffer *eb, void *ptr,
11421145
case BTRFS_BALANCE_OBJECTID:
11431146
print_balance_item(eb, ptr);
11441147
break;
1145-
case BTRFS_CSUM_TREE_TMP_OBJECTID:
1146-
printf("\t\tcsum tree tmp root %llu\n", offset);
1148+
case BTRFS_CSUM_CHANGE_OBJECTID:
1149+
if (offset < btrfs_get_num_csums())
1150+
printf("\t\ttarget csum type %s (%llu)\n",
1151+
btrfs_super_csum_name(offset) ,offset);
1152+
else
1153+
printf("\t\tunknown csum type %llu\n", offset);
11471154
break;
11481155
default:
11491156
printf("\t\tunknown temporary item objectid %llu\n", objectid);

kernel-shared/uapi/btrfs_tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
*/
107107
#define BTRFS_FREE_INO_OBJECTID -12ULL
108108

109+
#define BTRFS_CSUM_CHANGE_OBJECTID -13ULL
109110
/* dummy objectid represents multiple objectids */
110111
#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
111112

0 commit comments

Comments
 (0)