From 89409927b46336a37d00760b238b2a6493833838 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 2 Jun 2020 11:55:30 +0800 Subject: [PATCH] [thin_generate_metadata] Support device deletion --- thin-provisioning/thin_generate_metadata.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/thin-provisioning/thin_generate_metadata.cc b/thin-provisioning/thin_generate_metadata.cc index 999c6b1..0e9e65c 100644 --- a/thin-provisioning/thin_generate_metadata.cc +++ b/thin-provisioning/thin_generate_metadata.cc @@ -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} \n" << " {--create-snap} \n" + << " {--delete} \n" << " {--data-block-size} \n" << " {--nr-data-blocks} \n" << " {--origin} \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;