From dbd0c650882bb80554604da3554d632b786aff13 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 19 Aug 2015 09:41:14 +0100 Subject: [PATCH] [thin_show_duplicates] stub new command --- Makefile.in | 2 + bin/thin_show_duplicates | 1 + main.cc | 1 + thin-provisioning/commands.h | 1 + thin-provisioning/thin_show_duplicates.cc | 111 ++++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 120000 bin/thin_show_duplicates create mode 100644 thin-provisioning/thin_show_duplicates.cc diff --git a/Makefile.in b/Makefile.in index e67b300..08f895a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -88,6 +88,7 @@ SOURCE=\ thin-provisioning/thin_repair.cc \ thin-provisioning/thin_restore.cc \ thin-provisioning/thin_rmap.cc \ + thin-provisioning/thin_show_duplicates.cc \ thin-provisioning/thin_trim.cc \ thin-provisioning/xml_format.cc @@ -176,6 +177,7 @@ install: bin/pdata_tools ln -s -f pdata_tools $(BINDIR)/thin_repair ln -s -f pdata_tools $(BINDIR)/thin_restore ln -s -f pdata_tools $(BINDIR)/thin_rmap + ln -s -f pdata_tools $(BINDIR)/thin_show_duplicates ln -s -f pdata_tools $(BINDIR)/thin_trim ln -s -f pdata_tools $(BINDIR)/thin_metadata_size ln -s -f pdata_tools $(BINDIR)/era_check diff --git a/bin/thin_show_duplicates b/bin/thin_show_duplicates new file mode 120000 index 0000000..84c01e7 --- /dev/null +++ b/bin/thin_show_duplicates @@ -0,0 +1 @@ +pdata_tools \ No newline at end of file diff --git a/main.cc b/main.cc index ed69ba9..ff9017b 100644 --- a/main.cc +++ b/main.cc @@ -32,6 +32,7 @@ int main(int argc, char **argv) app.add_cmd(thin_provisioning::thin_restore_cmd); app.add_cmd(thin_provisioning::thin_repair_cmd); app.add_cmd(thin_provisioning::thin_rmap_cmd); + app.add_cmd(thin_provisioning::thin_show_dups_cmd); // FIXME: convert thin_metadata_size to c++ //app.add_cmd(thin_provisioning::thin_metadata_size_cmd); diff --git a/thin-provisioning/commands.h b/thin-provisioning/commands.h index de63e53..65714ec 100644 --- a/thin-provisioning/commands.h +++ b/thin-provisioning/commands.h @@ -15,6 +15,7 @@ namespace thin_provisioning { extern base::command thin_rmap_cmd; extern base::command thin_trim_cmd; extern base::command thin_metadata_size_cmd; + extern base::command thin_show_dups_cmd; } //---------------------------------------------------------------- diff --git a/thin-provisioning/thin_show_duplicates.cc b/thin-provisioning/thin_show_duplicates.cc new file mode 100644 index 0000000..06066b1 --- /dev/null +++ b/thin-provisioning/thin_show_duplicates.cc @@ -0,0 +1,111 @@ +// Copyright (C) 2015 Red Hat, Inc. All rights reserved. +// +// This file is part of the thin-provisioning-tools source. +// +// thin-provisioning-tools is free software: you can redistribute it +// and/or modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// thin-provisioning-tools is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with thin-provisioning-tools. If not, see +// . + +#include +#include +#include + +#include "version.h" + +#include "base/application.h" +#include "base/error_state.h" +#include "persistent-data/file_utils.h" +#include "persistent-data/space-maps/core.h" +#include "persistent-data/space-maps/disk.h" +#include "thin-provisioning/commands.h" +#include "thin-provisioning/device_tree.h" +#include "thin-provisioning/mapping_tree.h" +#include "thin-provisioning/superblock.h" + +using namespace base; +using namespace std; +using namespace thin_provisioning; + +//---------------------------------------------------------------- + +namespace { + block_manager<>::ptr + open_bm(string const &path) { + block_address nr_blocks = get_nr_blocks(path); + block_manager<>::mode m = block_manager<>::READ_ONLY; + return block_manager<>::ptr(new block_manager<>(path, nr_blocks, 1, m)); + } + + transaction_manager::ptr + open_tm(block_manager<>::ptr bm) { + space_map::ptr sm(new core_map(bm->get_nr_blocks())); + sm->inc(superblock_detail::SUPERBLOCK_LOCATION); + transaction_manager::ptr tm(new transaction_manager(bm, sm)); + return tm; + } + + //-------------------------------- + + struct flags { + flags() { + } + }; + + void usage(ostream &out, string const &cmd) { + out << "Usage: " << cmd << " [options] {device|file}" << endl + << "Options:" << endl + << " {-h|--help}" << endl + << " {-V|--version}" << endl; + } +} + +int thin_show_dups_main(int argc, char **argv) +{ + int c; + flags fs; + + char const shortopts[] = "qhV"; + option const longopts[] = { + { "help", no_argument, NULL, 'h'}, + { "version", no_argument, NULL, 'V'}, + { NULL, no_argument, NULL, 0 } + }; + + while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { + switch(c) { + case 'h': + usage(cout, basename(argv[0])); + return 0; + + case 'V': + cout << THIN_PROVISIONING_TOOLS_VERSION << endl; + return 0; + + default: + usage(cerr, basename(argv[0])); + return 1; + } + } + + if (argc == optind) { + cerr << "No input file provided." << endl; + usage(cerr, basename(argv[0])); + exit(1); + } + + return 0; +} + +base::command thin_provisioning::thin_show_dups_cmd("thin_show_duplicates", thin_show_dups_main); + +//----------------------------------------------------------------