@@ -80,12 +80,16 @@ superblock is damaged.
--clear-space-cache v1|v2::
completely wipe all free space cache of given type
-
-NOTE: Only v1 free space cache supported is implemented.
+
-Kernel mount option 'clear_cache' is only designed to rebuild free space cache
-which is modified during the lifetime of that mount option. It doesn't rebuild
-all free space cache, nor clear them out.
+For free space cache 'v1', the 'clear_cache' kernel mount option only rebuilds
+the free space cache for block groups that are modified while the filesystem is
+mounted with that option. Thus, using this option with 'v1' makes it possible
+to actually clear the entire free space cache.
++
+For free space cache 'v2', the 'clear_cache' kernel mount option does destroy
+the entire free space cache. This option with 'v2' provides an alternative
+method of clearing the free space cache that doesn't require mounting the
+filesystem.
DANGEROUS OPTIONS
@@ -11170,7 +11170,6 @@ const char * const cmd_check_usage[] = {
"--chunk-root <bytenr> use the given bytenr for the chunk tree root",
"-p|--progress indicate progress",
"--clear-space-cache v1|v2 clear space cache for v1 or v2",
- " NOTE: v1 support implemented",
NULL
};
@@ -11292,13 +11291,16 @@ int cmd_check(int argc, char **argv)
}
break;
case GETOPT_VAL_CLEAR_SPACE_CACHE:
- if (strcmp(optarg, "v1") != 0) {
- error(
- "only v1 support implmented, unrecognized value %s",
- optarg);
+ if (strcmp(optarg, "v1") == 0) {
+ clear_space_cache = 1;
+ } else if (strcmp(optarg, "v2") == 0) {
+ clear_space_cache = 2;
+ ctree_flags |= OPEN_CTREE_INVALIDATE_FST;
+ } else {
+ error("invalid argument to --clear-space-cache; "
+ "must be v1 or v2");
exit(1);
}
- clear_space_cache = 1;
ctree_flags |= OPEN_CTREE_WRITES;
break;
}
@@ -11352,11 +11354,10 @@ int cmd_check(int argc, char **argv)
global_info = info;
root = info->fs_root;
- if (clear_space_cache) {
+ if (clear_space_cache == 1) {
if (btrfs_fs_compat_ro(info,
BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE)) {
- error(
- "free space cache v2 detected, clearing not implemented");
+ error("free space cache v2 detected; use --clear-space-cache v2");
ret = 1;
goto close_out;
}
@@ -11369,6 +11370,21 @@ int cmd_check(int argc, char **argv)
printf("Free space cache cleared\n");
}
goto close_out;
+ } else if (clear_space_cache == 2) {
+ if (!btrfs_fs_compat_ro(info, BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE)) {
+ printf("No free space cache v2 to clear\n");
+ ret = 0;
+ goto close_out;
+ }
+ printf("Clear free space cache v2\n");
+ ret = btrfs_clear_free_space_tree(info);
+ if (ret) {
+ error("Failed to clear free space cache v2");
+ ret = 1;
+ } else {
+ printf("Free space cache v2 cleared\n");
+ }
+ goto close_out;
}
/*