[thin_check] Change the policy of --clear-needs-check-flag to prevent error recurrence
- Disallow clearing the needs_check flag if there's any error, i.e., the metadata must be fully examined, and the result must be NO_ERROR. - Disallow combining --clear-needs-check with -m, --super-blocks-only, --skip-mappings, --override-mapping-root, or --ignore-non-fatal-errors.
This commit is contained in:
@@ -43,27 +43,13 @@ using namespace thin_provisioning;
|
||||
namespace {
|
||||
struct flags {
|
||||
flags()
|
||||
: ignore_non_fatal_errors(false),
|
||||
quiet(false),
|
||||
clear_needs_check_flag_on_success(false) {
|
||||
: quiet(false) {
|
||||
}
|
||||
|
||||
check_options check_opts;
|
||||
|
||||
bool ignore_non_fatal_errors;
|
||||
|
||||
bool quiet;
|
||||
bool clear_needs_check_flag_on_success;
|
||||
};
|
||||
|
||||
void clear_needs_check(string const &path) {
|
||||
block_manager::ptr bm = open_bm(path, block_manager::READ_WRITE);
|
||||
|
||||
superblock_detail::superblock sb = read_superblock(bm);
|
||||
sb.set_needs_check_flag(false);
|
||||
write_superblock(bm, sb);
|
||||
}
|
||||
|
||||
// Returns 0 on success, 1 on failure (this gets returned directly
|
||||
// by main).
|
||||
int check(string const &path, flags fs) {
|
||||
@@ -77,15 +63,7 @@ namespace {
|
||||
}
|
||||
|
||||
output_options output_opts = !fs.quiet ? OUTPUT_NORMAL : OUTPUT_QUIET;
|
||||
error_state err = check_metadata(path, fs.check_opts, output_opts);
|
||||
|
||||
if (fs.ignore_non_fatal_errors)
|
||||
success = (err == FATAL) ? false : true;
|
||||
else
|
||||
success = (err == NO_ERROR) ? true : false;
|
||||
|
||||
if (success && fs.clear_needs_check_flag_on_success)
|
||||
clear_needs_check(path);
|
||||
success = check_metadata(path, fs.check_opts, output_opts);
|
||||
|
||||
} catch (std::exception &e) {
|
||||
if (!fs.quiet)
|
||||
@@ -173,13 +151,12 @@ thin_check_cmd::run(int argc, char **argv)
|
||||
|
||||
case 3:
|
||||
// ignore-non-fatal-errors
|
||||
fs.ignore_non_fatal_errors = true;
|
||||
fs.check_opts.set_ignore_non_fatal();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// clear needs-check flag
|
||||
fs.clear_needs_check_flag_on_success = true;
|
||||
fs.check_opts.set_clear_needs_check();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
@@ -198,12 +175,6 @@ thin_check_cmd::run(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.clear_needs_check_flag_on_success && fs.check_opts.use_metadata_snap_) {
|
||||
cerr << "--metadata-snap cannot be combined with --clear-needs-check-flag." << endl;
|
||||
usage(cerr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!fs.check_opts.check_conformance()) {
|
||||
usage(cerr);
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user