Update thin_metadata_size manual page

thin_dump: support dumping default metadata snapshot
This commit is contained in:
Heinz Mauelshagen 2013-07-19 12:02:02 +02:00
parent afcf52a35d
commit 691fcae6b7
3 changed files with 207 additions and 1 deletions

View File

@ -0,0 +1,166 @@
diff --git a/man8/thin_dump.8 b/man8/thin_dump.8
index e60a6e5..b26cc2c 100644
--- a/man8/thin_dump.8
+++ b/man8/thin_dump.8
@@ -23,9 +23,12 @@ Print output in XML or human readable format.
.IP "\fB\-r, \-\-repair\fP".
-.IP "\fB\-m, \-\-metadata_snap\fP block#".
-Dump metadata snapshot created by device-mapper thin provisioning target at block#
-
+.IP "\fB\-m, \-\-metadata_snap\fP [block#]".
+Dump metadata snapshot created by device-mapper thin provisioning target.
+If block is not provided, access the default metadata snapshot created by
+the thin provisioning device-mapper target, else try the one at block#.
+See the thin provisioning target documentation on how to create or release
+a metadata snapshot.
.IP "\fB\-h, \-\-help\fP".
Print help and exit.
@@ -44,6 +47,13 @@ to standard output in XML format:
.sp
.B thin_dump /dev/vg/metadata
+Dumps the thin provisioning metadata snapshot on logical volume /dev/vg/metadata
+to standard output in human readable format (not processable by
+.B thin_restore(8)
+):
+.sp
+.B thin_dump --format human_readable --metadata-snap /dev/vg/metadata
+
.SH DIAGNOSTICS
.B thin_dump
returns an exit code of 0 for success or 1 for error.
diff --git a/thin-provisioning/metadata.cc b/thin-provisioning/metadata.cc
index 771325a..bef75ba 100644
--- a/thin-provisioning/metadata.cc
+++ b/thin-provisioning/metadata.cc
@@ -78,6 +78,7 @@ namespace {
<< "data block size " << sb.data_block_size_ << endl
<< "metadata block size " << sb.metadata_block_size_ << endl
<< "metadata nr blocks " << sb.metadata_nr_blocks_ << endl
+ << "metadata snapshot block " << sb.metadata_snap_ << endl
;
}
}
diff --git a/thin-provisioning/thin_dump.cc b/thin-provisioning/thin_dump.cc
index 029a635..a844038 100644
--- a/thin-provisioning/thin_dump.cc
+++ b/thin-provisioning/thin_dump.cc
@@ -31,23 +31,37 @@ using namespace persistent_data;
using namespace std;
using namespace thin_provisioning;
+struct flags {
+ bool find_metadata_snap;
+ bool repair;
+};
+
namespace {
- int dump(string const &path, ostream &out, string const &format, bool repair,
+ int dump(string const &path, ostream *out, string const &format, struct flags &flags,
block_address metadata_snap = 0) {
try {
- metadata::ptr md(metadata_snap ? new metadata(path, metadata_snap) : new metadata(path, metadata::OPEN, 0, 0));
+ metadata::ptr md(new metadata(path, metadata_snap));
emitter::ptr e;
+ uint64_t metadata_snap_root = md->sb_.metadata_snap_;
+
+ if (metadata_snap_root) {
+ md.reset();
+ md = metadata::ptr(new metadata(path, metadata_snap_root));
+ } else if (flags.find_metadata_snap) {
+ cerr << "no metadata snapshot found!" << endl;
+ exit(1);
+ }
if (format == "xml")
- e = create_xml_emitter(out);
+ e = create_xml_emitter(*out);
else if (format == "human_readable")
- e = create_human_readable_emitter(out);
+ e = create_human_readable_emitter(*out);
else {
cerr << "unknown format '" << format << "'" << endl;
exit(1);
}
- metadata_dump(md, e, repair);
+ metadata_dump(md, e, flags.repair);
} catch (std::exception &e) {
cerr << e.what() << endl;
@@ -63,7 +77,7 @@ namespace {
<< " {-h|--help}" << endl
<< " {-f|--format} {xml|human_readable}" << endl
<< " {-r|--repair}" << endl
- << " {-m|--metadata-snap} block#" << endl
+ << " {-m|--metadata-snap} [block#]" << endl
<< " {-o <xml file>}" << endl
<< " {-V|--version}" << endl;
}
@@ -72,16 +86,16 @@ namespace {
int main(int argc, char **argv)
{
int c;
- bool repair = false;
char const *output = NULL;
- const char shortopts[] = "hm:o:f:rV";
+ const char shortopts[] = "hm::o:f:rV";
+ char *end_ptr;
string format = "xml";
block_address metadata_snap = 0;
- char *end_ptr;
+ struct flags flags = { .find_metadata_snap = false, .repair = false };
const struct option longopts[] = {
{ "help", no_argument, NULL, 'h'},
- { "metadata-snap", required_argument, NULL, 'm' },
+ { "metadata-snap", optional_argument, NULL, 'm' },
{ "output", required_argument, NULL, 'o'},
{ "format", required_argument, NULL, 'f' },
{ "repair", no_argument, NULL, 'r'},
@@ -100,16 +114,24 @@ int main(int argc, char **argv)
break;
case 'r':
- repair = true;
+ flags.repair = true;
+ break;
+
+ case 's':
+ flags.find_metadata_snap = true;
break;
case 'm':
- metadata_snap = strtoull(optarg, &end_ptr, 10);
- if (end_ptr == optarg) {
- cerr << "couldn't parse <metadata_snap>" << endl;
- usage(cerr, basename(argv[0]));
- return 1;
- }
+ if (optarg) {
+ metadata_snap = strtoull(optarg, &end_ptr, 10);
+ if (end_ptr == optarg) {
+ cerr << "couldn't parse <metadata_snap>" << endl;
+ usage(cerr, basename(argv[0]));
+ return 1;
+ }
+ } else
+ flags.find_metadata_snap = true;
+
break;
case 'o':
@@ -132,9 +154,5 @@ int main(int argc, char **argv)
return 1;
}
- if (output) {
- ofstream out(output);
- return dump(argv[optind], out, format, repair, metadata_snap);
- } else
- return dump(argv[optind], cout, format, repair, metadata_snap);
+ return dump(argv[optind], output ? new ofstream(output) : &cout, format, flags, metadata_snap);
}

View File

@ -0,0 +1,31 @@
diff --git a/man8/thin_metadata_size.8 b/man8/thin_metadata_size.8
index 33b36b3..6b00e73 100644
--- a/man8/thin_metadata_size.8
+++ b/man8/thin_metadata_size.8
@@ -1,6 +1,6 @@
.TH THIN_METADATA_SIZE 8 "Thin Provisioning Tools" "Red Hat, Inc." \" -*- nroff -*-
.SH NAME
-thin_metadata_size \- thin provisioning metadata file/device size calculator.
+thin_metadata_size \- thin provisioning metadata device/file size calculator.
.SH SYNOPSIS
.B thin_metadata_size
@@ -10,13 +10,15 @@ thin_metadata_size \- thin provisioning metadata file/device size calculator.
.B thin_metadata_size
calculates the size of the thin provisioning metadata based on the block size
of the thin provisioned devices, the size of the thin provisioning pool and
-the maximum number of all thin prisioned devices and snapshots. Size/number
-option arguments can be followed by unit specifiers in short one character
-and long form (eg. -b1m or -b1megabytes).
+the maximum number of all thin prisioned devices and snapshots.
+Because thin provisioning pools are holding widely variable contents,
+this tool is needed to provide sensible initial default size.
.IP "\fB\-b, \-\-block-size\fP \fIBLOCKSIZE[bskKmMgGtTpPeEzZyY]\fP"
Block size of thin provisioned devices in units of bytes,sectors,kilobytes,kibibytes,... respectively.
Default is in sectors without a block size unit specifier.
+Size/number option arguments can be followed by unit specifiers in short one character
+and long form (eg. -b1m or -b1megabytes).
.IP "\fB\-s, \-\-pool-size\fP \fIPOOLSIZE[bskKmMgGtTpPeEzZyY]\fP"
Thin provisioning pool size in units of bytes,sectors,kilobytes,kibibytes,... respectively.

View File

@ -4,7 +4,7 @@
Summary: Device-mapper thin provisioning tools Summary: Device-mapper thin provisioning tools
Name: device-mapper-persistent-data Name: device-mapper-persistent-data
Version: 0.2.1 Version: 0.2.1
Release: 3%{?dist} Release: 4%{?dist}
License: GPLv3+ License: GPLv3+
Group: System Environment/Base Group: System Environment/Base
URL: https://github.com/jthornber/thin-provisioning-tools URL: https://github.com/jthornber/thin-provisioning-tools
@ -14,6 +14,8 @@ Patch0: %{name}-0.2.1-nostrip.patch
Patch1: %{name}-0.2.1-thin_dump-support-metadata-snap-block.patch Patch1: %{name}-0.2.1-thin_dump-support-metadata-snap-block.patch
Patch2: %{name}-0.2.1-new-thin_metadata_size.c.patch Patch2: %{name}-0.2.1-new-thin_metadata_size.c.patch
Patch3: %{name}-0.2.1-man-pages-new-thin_metadata_size-and-fixes.patch Patch3: %{name}-0.2.1-man-pages-new-thin_metadata_size-and-fixes.patch
Patch4: %{name}-0.2.1-update-thin_metadata_size-man-page.patch
Patch5: %{name}-0.2.1-support-thin_dump-default-metadata-snapshot.patch
BuildRequires: autoconf, expat-devel, libstdc++-devel, boost-devel BuildRequires: autoconf, expat-devel, libstdc++-devel, boost-devel
Requires: expat Requires: expat
@ -23,10 +25,13 @@ tools to manage device-mapper thin provisioning target metadata devices.
%prep %prep
%setup -q -n thin-provisioning-tools-%{version} %setup -q -n thin-provisioning-tools-%{version}
echo %{version}-%{release} > VERSION
%patch0 -p1 %patch0 -p1
%patch1 -p1 %patch1 -p1
%patch2 -p1 %patch2 -p1
%patch3 -p1 %patch3 -p1
%patch4 -p1
%patch5 -p1
%build %build
autoconf autoconf
@ -54,6 +59,10 @@ make DESTDIR=%{buildroot} MANDIR=%{_mandir} install
%{_sbindir}/thin_rmap %{_sbindir}/thin_rmap
%changelog %changelog
* Fri Jul 18 2013 Heinz Mauelshagen <heinzm@redhat.com> - 0.2.1-4
- Update thin_metadata_size manual page
- thin_dump: support dumping default metadata snapshot
* Thu Jul 18 2013 Heinz Mauelshagen <heinzm@redhat.com> - 0.2.1-3 * Thu Jul 18 2013 Heinz Mauelshagen <heinzm@redhat.com> - 0.2.1-3
- New thin_metadata_size tool to estimate amount of metadata space - New thin_metadata_size tool to estimate amount of metadata space
based on block size, pool size and maximum amount of thin devs and snapshots based on block size, pool size and maximum amount of thin devs and snapshots