[thin_check] --clear-needs-check-flag
This commit is contained in:
parent
fe019f6946
commit
c3249ff757
@ -17,9 +17,10 @@ Feature: thin_check
|
|||||||
{-q|--quiet}
|
{-q|--quiet}
|
||||||
{-h|--help}
|
{-h|--help}
|
||||||
{-V|--version}
|
{-V|--version}
|
||||||
{--super-block-only}
|
{--clear-needs-check-flag}
|
||||||
{--skip-mappings}
|
|
||||||
{--ignore-non-fatal-errors}
|
{--ignore-non-fatal-errors}
|
||||||
|
{--skip-mappings}
|
||||||
|
{--super-block-only}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Scenario: print help
|
Scenario: print help
|
||||||
@ -32,9 +33,10 @@ Feature: thin_check
|
|||||||
{-q|--quiet}
|
{-q|--quiet}
|
||||||
{-h|--help}
|
{-h|--help}
|
||||||
{-V|--version}
|
{-V|--version}
|
||||||
{--super-block-only}
|
{--clear-needs-check-flag}
|
||||||
{--skip-mappings}
|
|
||||||
{--ignore-non-fatal-errors}
|
{--ignore-non-fatal-errors}
|
||||||
|
{--skip-mappings}
|
||||||
|
{--super-block-only}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Scenario: Unrecognised option should cause failure
|
Scenario: Unrecognised option should cause failure
|
||||||
@ -77,3 +79,8 @@ Feature: thin_check
|
|||||||
When I run thin_check with --quiet
|
When I run thin_check with --quiet
|
||||||
Then it should fail
|
Then it should fail
|
||||||
And it should give no output
|
And it should give no output
|
||||||
|
|
||||||
|
Scenario: Accepts --clear-needs-check-flag
|
||||||
|
Given valid metadata
|
||||||
|
When I run thin_check with --clear-needs-check-flag
|
||||||
|
Then it should pass
|
||||||
|
@ -113,6 +113,23 @@ thin_provisioning::superblock_validator()
|
|||||||
|
|
||||||
namespace thin_provisioning {
|
namespace thin_provisioning {
|
||||||
namespace superblock_detail {
|
namespace superblock_detail {
|
||||||
|
namespace {
|
||||||
|
unsigned const NEEDS_CHECK_BIT = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
superblock::get_needs_check_flag() const {
|
||||||
|
return flags_ & (1 << NEEDS_CHECK_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
superblock::set_needs_check_flag(bool val) {
|
||||||
|
if (val)
|
||||||
|
flags_ |= (1 << NEEDS_CHECK_BIT);
|
||||||
|
else
|
||||||
|
flags_ &= ~(1 << NEEDS_CHECK_BIT);
|
||||||
|
};
|
||||||
|
|
||||||
superblock_corruption::superblock_corruption(std::string const &desc)
|
superblock_corruption::superblock_corruption(std::string const &desc)
|
||||||
: desc_(desc) {
|
: desc_(desc) {
|
||||||
}
|
}
|
||||||
@ -144,6 +161,13 @@ namespace thin_provisioning {
|
|||||||
return read_superblock(bm, SUPERBLOCK_LOCATION);
|
return read_superblock(bm, SUPERBLOCK_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_superblock(block_manager<>::ptr bm, superblock_detail::superblock const &sb)
|
||||||
|
{
|
||||||
|
block_manager<>::write_ref w = bm->write_lock(SUPERBLOCK_LOCATION, superblock_validator());
|
||||||
|
superblock_disk *disk = reinterpret_cast<superblock_disk *>(w.data().raw());
|
||||||
|
superblock_traits::pack(sb, *disk);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
check_superblock(block_manager<>::ptr bm,
|
check_superblock(block_manager<>::ptr bm,
|
||||||
superblock_detail::damage_visitor &visitor) {
|
superblock_detail::damage_visitor &visitor) {
|
||||||
|
@ -81,6 +81,9 @@ namespace thin_provisioning {
|
|||||||
uint32_t compat_flags_;
|
uint32_t compat_flags_;
|
||||||
uint32_t compat_ro_flags_;
|
uint32_t compat_ro_flags_;
|
||||||
uint32_t incompat_flags_;
|
uint32_t incompat_flags_;
|
||||||
|
|
||||||
|
bool get_needs_check_flag() const;
|
||||||
|
void set_needs_check_flag(bool val = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct superblock_traits {
|
struct superblock_traits {
|
||||||
@ -126,7 +129,12 @@ namespace thin_provisioning {
|
|||||||
// FIXME: should we put init_superblock in here too?
|
// FIXME: should we put init_superblock in here too?
|
||||||
|
|
||||||
superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm);
|
superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm);
|
||||||
superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm, persistent_data::block_address location);
|
superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm,
|
||||||
|
persistent_data::block_address location);
|
||||||
|
|
||||||
|
void write_superblock(persistent_data::block_manager<>::ptr bm,
|
||||||
|
superblock_detail::superblock const &sb);
|
||||||
|
|
||||||
void check_superblock(persistent_data::block_manager<>::ptr bm,
|
void check_superblock(persistent_data::block_manager<>::ptr bm,
|
||||||
superblock_detail::damage_visitor &visitor);
|
superblock_detail::damage_visitor &visitor);
|
||||||
}
|
}
|
||||||
|
@ -148,6 +148,15 @@ namespace {
|
|||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
struct flags {
|
struct flags {
|
||||||
|
flags()
|
||||||
|
: check_device_tree(true),
|
||||||
|
check_mapping_tree_level1(true),
|
||||||
|
check_mapping_tree_level2(true),
|
||||||
|
ignore_non_fatal_errors(false),
|
||||||
|
quiet(false),
|
||||||
|
clear_needs_check_flag_on_success(false) {
|
||||||
|
}
|
||||||
|
|
||||||
bool check_device_tree;
|
bool check_device_tree;
|
||||||
bool check_mapping_tree_level1;
|
bool check_mapping_tree_level1;
|
||||||
bool check_mapping_tree_level2;
|
bool check_mapping_tree_level2;
|
||||||
@ -155,6 +164,7 @@ namespace {
|
|||||||
bool ignore_non_fatal_errors;
|
bool ignore_non_fatal_errors;
|
||||||
|
|
||||||
bool quiet;
|
bool quiet;
|
||||||
|
bool clear_needs_check_flag_on_success;
|
||||||
};
|
};
|
||||||
|
|
||||||
error_state metadata_check(string const &path, flags fs) {
|
error_state metadata_check(string const &path, flags fs) {
|
||||||
@ -214,12 +224,29 @@ namespace {
|
|||||||
dev_rep.get_error()));
|
dev_rep.get_error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int check(string const &path, flags fs) {
|
void clear_needs_check(string const &path) {
|
||||||
|
block_manager<>::ptr bm = open_bm(path, block_io<>::READ_WRITE);
|
||||||
|
|
||||||
|
superblock_detail::superblock sb = read_superblock(bm);
|
||||||
|
sb.set_needs_check_flag(false);
|
||||||
|
write_superblock(bm, sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check(string const &path, flags fs) {
|
||||||
error_state err;
|
error_state err;
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
err = metadata_check(path, fs);
|
err = metadata_check(path, fs);
|
||||||
|
|
||||||
|
if (fs.ignore_non_fatal_errors)
|
||||||
|
success = (err == FATAL) ? 1 : 0;
|
||||||
|
else
|
||||||
|
success = (err == NO_ERROR) ? 0 : 1;
|
||||||
|
|
||||||
|
if (success && fs.clear_needs_check_flag_on_success)
|
||||||
|
clear_needs_check(path);
|
||||||
|
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
if (!fs.quiet)
|
if (!fs.quiet)
|
||||||
cerr << e.what() << endl;
|
cerr << e.what() << endl;
|
||||||
@ -227,10 +254,7 @@ namespace {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.ignore_non_fatal_errors)
|
return success;
|
||||||
return (err == FATAL) ? 1 : 0;
|
|
||||||
else
|
|
||||||
return (err == NO_ERROR) ? 0 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(ostream &out, string const &cmd) {
|
void usage(ostream &out, string const &cmd) {
|
||||||
@ -239,9 +263,10 @@ namespace {
|
|||||||
<< " {-q|--quiet}" << endl
|
<< " {-q|--quiet}" << endl
|
||||||
<< " {-h|--help}" << endl
|
<< " {-h|--help}" << endl
|
||||||
<< " {-V|--version}" << endl
|
<< " {-V|--version}" << endl
|
||||||
<< " {--super-block-only}" << endl
|
<< " {--clear-needs-check-flag}" << endl
|
||||||
|
<< " {--ignore-non-fatal-errors}" << endl
|
||||||
<< " {--skip-mappings}" << endl
|
<< " {--skip-mappings}" << endl
|
||||||
<< " {--ignore-non-fatal-errors}" << endl;
|
<< " {--super-block-only}" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,11 +274,6 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
flags fs;
|
flags fs;
|
||||||
fs.check_device_tree = true;
|
|
||||||
fs.check_mapping_tree_level1 = true,
|
|
||||||
fs.check_mapping_tree_level2 = true,
|
|
||||||
fs.ignore_non_fatal_errors = false,
|
|
||||||
fs.quiet = false;
|
|
||||||
|
|
||||||
char const shortopts[] = "qhV";
|
char const shortopts[] = "qhV";
|
||||||
option const longopts[] = {
|
option const longopts[] = {
|
||||||
@ -263,6 +283,7 @@ int main(int argc, char **argv)
|
|||||||
{ "super-block-only", no_argument, NULL, 1},
|
{ "super-block-only", no_argument, NULL, 1},
|
||||||
{ "skip-mappings", no_argument, NULL, 2},
|
{ "skip-mappings", no_argument, NULL, 2},
|
||||||
{ "ignore-non-fatal-errors", no_argument, NULL, 3},
|
{ "ignore-non-fatal-errors", no_argument, NULL, 3},
|
||||||
|
{ "clear-needs-check-flag", no_argument, NULL, 4 },
|
||||||
{ NULL, no_argument, NULL, 0 }
|
{ NULL, no_argument, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -297,6 +318,11 @@ int main(int argc, char **argv)
|
|||||||
fs.ignore_non_fatal_errors = true;
|
fs.ignore_non_fatal_errors = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
// clear needs-check flag
|
||||||
|
fs.clear_needs_check_flag_on_success = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage(cerr, basename(argv[0]));
|
usage(cerr, basename(argv[0]));
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user