Skip to content

Commit f8a713e

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: tune: implement the prerequisite checks for csum change
The overall idea is to make sure no running operations (balance, dev-replace, dirty log) for the fs before csum change. And also reject half converted csums for now. Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2467f43 commit f8a713e

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tune/change-csum.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,68 @@
2626
#include "common/internal.h"
2727
#include "tune/tune.h"
2828

29+
static int check_csum_change_requreiment(struct btrfs_fs_info *fs_info)
30+
{
31+
struct btrfs_root *tree_root = fs_info->tree_root;
32+
struct btrfs_root *dev_root = fs_info->dev_root;
33+
struct btrfs_path path = { 0 };
34+
struct btrfs_key key;
35+
int ret;
36+
37+
if (btrfs_super_log_root(fs_info->super_copy)) {
38+
error("dirty log tree detected, please replay the log or zero it.");
39+
return -EINVAL;
40+
}
41+
if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) {
42+
error("no csum change support for extent-tree-v2 feature yet.");
43+
return -EOPNOTSUPP;
44+
}
45+
if (btrfs_super_flags(fs_info->super_copy) &
46+
(BTRFS_SUPER_FLAG_CHANGING_DATA_CSUM |
47+
BTRFS_SUPER_FLAG_CHANGING_META_CSUM)) {
48+
error("resume from half converted status is not yet supported");
49+
return -EOPNOTSUPP;
50+
}
51+
key.objectid = BTRFS_BALANCE_OBJECTID;
52+
key.type = BTRFS_TEMPORARY_ITEM_KEY;
53+
key.offset = 0;
54+
ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0);
55+
btrfs_release_path(&path);
56+
if (ret < 0) {
57+
errno = -ret;
58+
error("failed to check the balance status: %m");
59+
return ret;
60+
}
61+
if (ret == 0) {
62+
error("running balance detected, please finish or cancel it.");
63+
return -EINVAL;
64+
}
65+
66+
key.objectid = 0;
67+
key.type = BTRFS_DEV_REPLACE_KEY;
68+
key.offset = 0;
69+
ret = btrfs_search_slot(NULL, dev_root, &key, &path, 0, 0);
70+
btrfs_release_path(&path);
71+
if (ret < 0) {
72+
errno = -ret;
73+
error("failed to check the dev-reaplce status: %m");
74+
return ret;
75+
}
76+
if (ret == 0) {
77+
error("running dev-replace detected, please finish or cancel it.");
78+
return -EINVAL;
79+
}
80+
return 0;
81+
}
82+
2983
int btrfs_change_csum_type(struct btrfs_fs_info *fs_info, u16 new_csum_type)
3084
{
85+
int ret;
86+
3187
/* Phase 0, check conflicting features. */
88+
ret = check_csum_change_requreiment(fs_info);
89+
if (ret < 0)
90+
return ret;
3291

3392
/*
3493
* Phase 1, generate new data csums.

0 commit comments

Comments
 (0)