[thin_generate_metadata] Support device deletion

This commit is contained in:
Ming-Hung Tsai 2020-06-02 11:55:30 +08:00
parent a5614f7db2
commit 89409927b4

View File

@ -39,6 +39,7 @@ namespace {
METADATA_OP_OPEN,
METADATA_OP_CREATE_THIN,
METADATA_OP_CREATE_SNAP,
METADATA_OP_DELETE_DEV,
METADATA_OP_LAST
};
@ -82,6 +83,11 @@ namespace {
return false;
}
if (op == METADATA_OP_DELETE_DEV && !dev_id) {
cerr << "no device id provided." << endl;
return false;
}
return true;
}
@ -106,6 +112,9 @@ namespace {
case flags::METADATA_OP_CREATE_SNAP:
pool->create_snap(*fs.dev_id, *fs.origin);
break;
case flags::METADATA_OP_DELETE_DEV:
pool->del(*fs.dev_id);
break;
default:
break;
}
@ -132,6 +141,7 @@ thin_generate_metadata_cmd::usage(std::ostream &out) const
<< " {--format}\n"
<< " {--create-thin} <dev-id>\n"
<< " {--create-snap} <dev-id>\n"
<< " {--delete} <dev-id>\n"
<< " {--data-block-size} <block size>\n"
<< " {--nr-data-blocks} <nr>\n"
<< " {--origin} <origin-id>\n"
@ -152,6 +162,7 @@ thin_generate_metadata_cmd::run(int argc, char **argv)
{ "open", no_argument, NULL, 2 },
{ "create-thin", required_argument, NULL, 3 },
{ "create-snap", required_argument, NULL, 4 },
{ "delete", required_argument, NULL, 5 },
{ "data-block-size", required_argument, NULL, 101 },
{ "nr-data-blocks", required_argument, NULL, 102 },
{ "origin", required_argument, NULL, 401 },
@ -187,6 +198,11 @@ thin_generate_metadata_cmd::run(int argc, char **argv)
fs.dev_id = parse_uint64(optarg, "device id");
break;
case 5:
fs.op = flags::METADATA_OP_DELETE_DEV;
fs.dev_id = parse_uint64(optarg, "device id");
break;
case 101:
fs.data_block_size = parse_uint64(optarg, "data block size");
break;