2012-03-08 22:50:46 +05:30
|
|
|
// Copyright (C) 2012 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
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2021-01-13 09:26:18 +05:30
|
|
|
#include "base/math_utils.h"
|
2021-02-19 11:36:21 +05:30
|
|
|
#include "dbg-lib/array_block_dumper.h"
|
|
|
|
#include "dbg-lib/btree_node_dumper.h"
|
|
|
|
#include "dbg-lib/index_block_dumper.h"
|
|
|
|
#include "dbg-lib/command_interpreter.h"
|
|
|
|
#include "dbg-lib/commands.h"
|
|
|
|
#include "dbg-lib/output_formatter.h"
|
|
|
|
#include "dbg-lib/sm_show_traits.h"
|
2016-02-18 22:05:10 +05:30
|
|
|
#include "persistent-data/file_utils.h"
|
2021-01-13 09:13:14 +05:30
|
|
|
#include "persistent-data/space-maps/disk_structures.h"
|
2016-02-18 22:05:10 +05:30
|
|
|
#include "thin-provisioning/commands.h"
|
2013-01-02 18:25:41 +05:30
|
|
|
#include "thin-provisioning/metadata.h"
|
2021-01-12 18:29:02 +05:30
|
|
|
#include "thin-provisioning/superblock.h"
|
2012-03-08 22:50:46 +05:30
|
|
|
#include "version.h"
|
|
|
|
|
2021-01-21 13:35:28 +05:30
|
|
|
using namespace dbg;
|
2012-03-08 22:50:46 +05:30
|
|
|
using namespace persistent_data;
|
|
|
|
using namespace std;
|
|
|
|
using namespace thin_provisioning;
|
|
|
|
|
|
|
|
namespace {
|
2021-01-21 13:35:28 +05:30
|
|
|
class help : public dbg::command {
|
2021-01-12 18:29:02 +05:30
|
|
|
virtual void exec(strings const &args, ostream &out) {
|
|
|
|
out << "Commands:" << endl
|
2021-02-05 13:45:24 +05:30
|
|
|
<< " superblock [block#]" << endl
|
2021-01-12 18:29:02 +05:30
|
|
|
<< " m1_node <block# of top-level mapping tree node>" << endl
|
|
|
|
<< " m2_node <block# of bottom-level mapping tree node>" << endl
|
|
|
|
<< " detail_node <block# of device details tree node>" << endl
|
2021-01-13 09:26:18 +05:30
|
|
|
<< " index_block <block# of metadata space map root>" << endl
|
|
|
|
<< " index_node <block# of data space map node>" << endl
|
2021-01-12 18:29:02 +05:30
|
|
|
<< " exit" << endl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-21 13:35:28 +05:30
|
|
|
class show_superblock : public dbg::command {
|
2012-03-08 22:50:46 +05:30
|
|
|
public:
|
2021-02-05 13:45:24 +05:30
|
|
|
explicit show_superblock(block_manager::ptr bm)
|
|
|
|
: bm_(bm) {
|
2012-03-08 22:50:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void exec(strings const &args, ostream &out) {
|
2021-02-05 13:45:24 +05:30
|
|
|
if (args.size() > 2)
|
|
|
|
throw runtime_error("incorrect number of arguments");
|
2012-03-08 22:50:46 +05:30
|
|
|
|
2021-02-05 13:45:24 +05:30
|
|
|
block_address b = superblock_detail::SUPERBLOCK_LOCATION;
|
|
|
|
if (args.size() == 2)
|
|
|
|
b = boost::lexical_cast<block_address>(args[1]);
|
|
|
|
superblock_detail::superblock sb = read_superblock(bm_, b);
|
2012-03-08 22:50:46 +05:30
|
|
|
|
2021-02-05 13:45:24 +05:30
|
|
|
formatter::ptr f = create_xml_formatter();
|
2021-02-03 14:41:24 +05:30
|
|
|
field(*f, "csum", sb.csum_);
|
|
|
|
field(*f, "flags", sb.flags_);
|
|
|
|
field(*f, "blocknr", sb.blocknr_);
|
|
|
|
field(*f, "uuid", sb.uuid_); // FIXME: delimit, and handle non-printable chars
|
|
|
|
field(*f, "magic", sb.magic_);
|
|
|
|
field(*f, "version", sb.version_);
|
|
|
|
field(*f, "time", sb.time_);
|
|
|
|
field(*f, "trans_id", sb.trans_id_);
|
|
|
|
field(*f, "metadata_snap", sb.metadata_snap_);
|
2021-01-13 09:13:14 +05:30
|
|
|
|
|
|
|
sm_disk_detail::sm_root_disk const *d;
|
|
|
|
sm_disk_detail::sm_root v;
|
|
|
|
{
|
|
|
|
d = reinterpret_cast<sm_disk_detail::sm_root_disk const *>(sb.metadata_space_map_root_);
|
|
|
|
sm_disk_detail::sm_root_traits::unpack(*d, v);
|
2021-02-03 14:41:24 +05:30
|
|
|
formatter::ptr f2 = create_xml_formatter();
|
|
|
|
sm_root_show_traits::show(f2, "value", v);
|
|
|
|
f->child("metadata_space_map_root", f2);
|
2021-01-13 09:13:14 +05:30
|
|
|
}
|
|
|
|
{
|
|
|
|
d = reinterpret_cast<sm_disk_detail::sm_root_disk const *>(sb.data_space_map_root_);
|
|
|
|
sm_disk_detail::sm_root_traits::unpack(*d, v);
|
2021-02-03 14:41:24 +05:30
|
|
|
formatter::ptr f2 = create_xml_formatter();
|
|
|
|
sm_root_show_traits::show(f2, "value", v);
|
|
|
|
f->child("data_space_map_root", f2);
|
2021-01-13 09:13:14 +05:30
|
|
|
}
|
|
|
|
|
2021-02-03 14:41:24 +05:30
|
|
|
field(*f, "data_mapping_root", sb.data_mapping_root_);
|
|
|
|
field(*f, "device_details_root", sb.device_details_root_);
|
|
|
|
field(*f, "data_block_size", sb.data_block_size_);
|
|
|
|
field(*f, "metadata_block_size", sb.metadata_block_size_);
|
|
|
|
field(*f, "metadata_nr_blocks", sb.metadata_nr_blocks_);
|
|
|
|
field(*f, "compat_flags", sb.compat_flags_);
|
|
|
|
field(*f, "compat_ro_flags", sb.compat_ro_flags_);
|
|
|
|
field(*f, "incompat_flags", sb.incompat_flags_);
|
2012-03-08 22:50:46 +05:30
|
|
|
|
2021-02-03 14:41:24 +05:30
|
|
|
f->output(out, 0);
|
2012-03-08 22:50:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-05 13:45:24 +05:30
|
|
|
block_manager::ptr bm_;
|
2012-03-08 22:50:46 +05:30
|
|
|
};
|
|
|
|
|
2021-02-19 11:36:21 +05:30
|
|
|
class device_details_show_traits {
|
2012-03-13 16:31:14 +05:30
|
|
|
public:
|
2021-01-12 15:39:00 +05:30
|
|
|
typedef thin_provisioning::device_tree_detail::device_details_traits value_trait;
|
|
|
|
|
2021-02-03 14:41:24 +05:30
|
|
|
static void show(formatter::ptr f, string const &key,
|
2016-02-18 22:05:10 +05:30
|
|
|
thin_provisioning::device_tree_detail::device_details const &value) {
|
2021-02-03 14:41:24 +05:30
|
|
|
field(*f, "mapped_blocks", value.mapped_blocks_);
|
|
|
|
field(*f, "transaction_id", value.transaction_id_);
|
|
|
|
field(*f, "creation_time", value.creation_time_);
|
|
|
|
field(*f, "snap_time", value.snapshotted_time_);
|
2012-03-13 16:31:14 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-19 11:36:21 +05:30
|
|
|
class block_show_traits {
|
2012-03-13 16:31:14 +05:30
|
|
|
public:
|
2021-01-12 15:39:00 +05:30
|
|
|
typedef thin_provisioning::mapping_tree_detail::block_traits value_trait;
|
|
|
|
|
2021-02-03 14:41:24 +05:30
|
|
|
static void show(formatter::ptr f, string const &key,
|
2016-02-18 22:05:10 +05:30
|
|
|
thin_provisioning::mapping_tree_detail::block_time const &value) {
|
2021-02-03 14:41:24 +05:30
|
|
|
field(*f, "block", value.block_);
|
|
|
|
field(*f, "time", value.time_);
|
2012-03-13 16:31:14 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-19 11:36:21 +05:30
|
|
|
//--------------------------------
|
2021-01-13 09:26:18 +05:30
|
|
|
|
2021-01-12 15:39:00 +05:30
|
|
|
template <typename ShowTraits>
|
2021-02-19 11:36:21 +05:30
|
|
|
dbg::command::ptr
|
|
|
|
create_btree_node_handler(block_manager::ptr bm) {
|
|
|
|
return create_block_handler(bm, create_btree_node_dumper<ShowTraits>());
|
|
|
|
}
|
2021-01-13 09:26:18 +05:30
|
|
|
|
2021-02-19 11:36:21 +05:30
|
|
|
dbg::command::ptr
|
|
|
|
create_index_block_handler(block_manager::ptr bm) {
|
|
|
|
return create_block_handler(bm, create_index_block_dumper());
|
|
|
|
}
|
2012-03-08 22:50:46 +05:30
|
|
|
|
2021-02-05 13:45:24 +05:30
|
|
|
int debug_(string const &path) {
|
2021-01-21 13:35:28 +05:30
|
|
|
using dbg::command;
|
|
|
|
|
2012-03-08 22:50:46 +05:30
|
|
|
try {
|
2016-02-18 22:05:10 +05:30
|
|
|
block_manager::ptr bm = open_bm(path, block_manager::READ_ONLY, 1);
|
2021-02-03 14:41:24 +05:30
|
|
|
command_interpreter::ptr interp = create_command_interpreter(cin, cout);
|
2021-02-19 11:36:21 +05:30
|
|
|
interp->register_command("hello", create_hello_handler());
|
2021-02-05 13:45:24 +05:30
|
|
|
interp->register_command("superblock", command::ptr(new show_superblock(bm)));
|
2021-02-19 11:36:21 +05:30
|
|
|
interp->register_command("m1_node", create_btree_node_handler<uint64_show_traits>(bm));
|
|
|
|
interp->register_command("m2_node", create_btree_node_handler<block_show_traits>(bm));
|
|
|
|
interp->register_command("detail_node", create_btree_node_handler<device_details_show_traits>(bm));
|
|
|
|
interp->register_command("index_block", create_index_block_handler(bm));
|
|
|
|
interp->register_command("index_node", create_btree_node_handler<index_entry_show_traits>(bm));
|
2021-02-03 14:41:24 +05:30
|
|
|
interp->register_command("help", command::ptr(new help));
|
2021-02-19 11:36:21 +05:30
|
|
|
interp->register_command("exit", create_exit_handler(interp));
|
2021-02-03 14:41:24 +05:30
|
|
|
interp->enter_main_loop();
|
2012-03-08 22:50:46 +05:30
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
2021-01-12 18:29:02 +05:30
|
|
|
cerr << e.what() << endl;
|
2012-03-08 22:50:46 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-18 22:05:10 +05:30
|
|
|
thin_debug_cmd::thin_debug_cmd()
|
|
|
|
: command("thin_debug")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
thin_debug_cmd::usage(std::ostream &out) const
|
|
|
|
{
|
|
|
|
out << "Usage: " << get_name() << " {device|file}" << endl
|
|
|
|
<< "Options:" << endl
|
|
|
|
<< " {-h|--help}" << endl
|
|
|
|
<< " {-V|--version}" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
thin_debug_cmd::run(int argc, char **argv)
|
2012-03-08 22:50:46 +05:30
|
|
|
{
|
|
|
|
int c;
|
|
|
|
const char shortopts[] = "hV";
|
|
|
|
const struct option 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':
|
2016-02-18 22:05:10 +05:30
|
|
|
usage(cout);
|
2012-03-08 22:50:46 +05:30
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == optind) {
|
2016-02-18 22:05:10 +05:30
|
|
|
usage(cerr);
|
2012-03-08 22:50:46 +05:30
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-02-05 13:45:24 +05:30
|
|
|
return debug_(argv[optind]);
|
2012-03-08 22:50:46 +05:30
|
|
|
}
|