|
26 | 26 | #include "common/internal.h"
|
27 | 27 | #include "tune/tune.h"
|
28 | 28 |
|
| 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 | + |
29 | 83 | int btrfs_change_csum_type(struct btrfs_fs_info *fs_info, u16 new_csum_type)
|
30 | 84 | {
|
| 85 | + int ret; |
| 86 | + |
31 | 87 | /* Phase 0, check conflicting features. */
|
| 88 | + ret = check_csum_change_requreiment(fs_info); |
| 89 | + if (ret < 0) |
| 90 | + return ret; |
32 | 91 |
|
33 | 92 | /*
|
34 | 93 | * Phase 1, generate new data csums.
|
|
0 commit comments