From 08219a60b683c4487b8690b0dda44aaaf3b1e4a6 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sat, 5 Mar 2016 13:59:24 +0800 Subject: [PATCH 1/7] [thin] Add default constructor to struct device_details --- thin-provisioning/device_tree.cc | 7 +++++++ thin-provisioning/device_tree.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/thin-provisioning/device_tree.cc b/thin-provisioning/device_tree.cc index 223d816..4837cb7 100644 --- a/thin-provisioning/device_tree.cc +++ b/thin-provisioning/device_tree.cc @@ -47,6 +47,13 @@ namespace { namespace thin_provisioning { namespace device_tree_detail { + device_details::device_details() + : mapped_blocks_(0), + transaction_id_(0), + creation_time_(0), + snapshotted_time_(0) { + } + void device_details_traits::unpack(device_details_disk const &disk, device_details &value) { diff --git a/thin-provisioning/device_tree.h b/thin-provisioning/device_tree.h index 23ae924..ef32b45 100644 --- a/thin-provisioning/device_tree.h +++ b/thin-provisioning/device_tree.h @@ -20,6 +20,8 @@ namespace thin_provisioning { uint64_t transaction_id_; /* when created */ uint32_t creation_time_; uint32_t snapshotted_time_; + + device_details(); }; struct device_details_traits { From 400613305c2feb490366ed383adbe4e4386772ed Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sat, 5 Mar 2016 14:11:38 +0800 Subject: [PATCH 2/7] [thin_ll_restore] Cleanup: use device_details' constructor --- thin-provisioning/thin_ll_restore.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/thin-provisioning/thin_ll_restore.cc b/thin-provisioning/thin_ll_restore.cc index 1168579..27ab184 100644 --- a/thin-provisioning/thin_ll_restore.cc +++ b/thin-provisioning/thin_ll_restore.cc @@ -85,9 +85,6 @@ namespace { void parse_device(metadata::ptr md, emitter::ptr e, attributes const &attr) { uint32_t dev_id = get_attr(attr, "dev_id"); device_tree_detail::device_details details; - details.transaction_id_ = 0; - details.creation_time_ = 0; - details.snapshotted_time_ = 0; device_tree::ptr details_tree; boost::optional details_root = get_opt_attr(attr, "blocknr"); From 6fb5f8241d46caa32ee6e374c45670c738d1ca6d Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sat, 5 Mar 2016 22:31:09 +0800 Subject: [PATCH 3/7] [thin_scan] Factor out range manipulation code --- thin-provisioning/thin_scan.cc | 49 +++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/thin-provisioning/thin_scan.cc b/thin-provisioning/thin_scan.cc index c5afbd9..94edd1d 100644 --- a/thin-provisioning/thin_scan.cc +++ b/thin-provisioning/thin_scan.cc @@ -151,10 +151,43 @@ namespace { value_size_(rhs.value_size_), is_valid_(rhs.is_valid_) { } + + uint64_t size() const { + return (end_ > begin_) ? (end_ - begin_) : 0; + } + + // returns true if r is left or right-adjacent + bool is_adjacent_to(block_range const &r) const { + block_range const &lhs = begin_ < r.begin_ ? *this : r; + block_range const &rhs = begin_ < r.begin_ ? r : *this; + uint64_t common_end = std::min(end_, r.end_); + + if (size() && r.size() && + rhs.begin_ == common_end && + ((!blocknr_begin_ && !r.blocknr_begin_) || + (blocknr_begin_ && r.blocknr_begin_ && + *rhs.blocknr_begin_ > *lhs.blocknr_begin_ && + (*rhs.blocknr_begin_ - *lhs.blocknr_begin_ == rhs.begin_ - lhs.begin_))) && + type_ == r.type_ && + ref_count_ == r.ref_count_ && + value_size_ == r.value_size_ && + is_valid_ == r.is_valid_) + return true; + + return false; + } + + bool concat(block_range const &r) { + if (!is_adjacent_to(r)) + return false; + begin_ = std::min(begin_, r.begin_); + end_ = std::max(end_, r.end_); + return true; + } }; void output_block_range(block_range const &r, std::ostream &out) { - if (r.end_ <= r.begin_) + if (!r.size()) return; if (r.end_ - r.begin_ > 1) { @@ -288,18 +321,8 @@ namespace { curr_range.ref_count_ = -1; } - // output the current block - if (run_range.end_ == 0) - run_range = curr_range; - else if (((!curr_range.blocknr_begin_ && !run_range.blocknr_begin_) || - (curr_range.blocknr_begin_ && run_range.blocknr_begin_ && - *curr_range.blocknr_begin_ == *run_range.blocknr_begin_ + (run_range.end_ - run_range.begin_))) && - curr_range.type_ == run_range.type_ && - curr_range.ref_count_ == run_range.ref_count_ && - curr_range.value_size_ == run_range.value_size_ && - curr_range.is_valid_ == run_range.is_valid_) { - ++run_range.end_; - } else { + // store the current block + if (!run_range.concat(curr_range)) { output_block_range(run_range, out); run_range = curr_range; } From 9f15c5589f8bb851674f97c8bad2ef6ddf637b27 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sun, 6 Mar 2016 00:06:27 +0800 Subject: [PATCH 4/7] [thin_scan] Cleanup: move methods before data member declaration --- thin-provisioning/thin_scan.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/thin-provisioning/thin_scan.cc b/thin-provisioning/thin_scan.cc index 94edd1d..725c3b6 100644 --- a/thin-provisioning/thin_scan.cc +++ b/thin-provisioning/thin_scan.cc @@ -129,14 +129,6 @@ namespace { }; struct block_range { - uint64_t begin_; - uint64_t end_; // one-pass-the-end - boost::optional blocknr_begin_; - metadata_block_type type_; - int64_t ref_count_; // ref_count in metadata space map - size_t value_size_; // btree node only - bool is_valid_; // btree node only - block_range() : begin_(0), end_(0), type_(UNKNOWN), ref_count_(-1), @@ -184,6 +176,14 @@ namespace { end_ = std::max(end_, r.end_); return true; } + + uint64_t begin_; + uint64_t end_; // one-pass-the-end + boost::optional blocknr_begin_; + metadata_block_type type_; + int64_t ref_count_; // ref_count in metadata space map + size_t value_size_; // btree node only + bool is_valid_; }; void output_block_range(block_range const &r, std::ostream &out) { From 8232feb85554b8333ea314f7ec28c9d54d28b136 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sun, 6 Mar 2016 01:23:04 +0800 Subject: [PATCH 5/7] [thin_scan] Cleanup: remove unnecessary variables --- thin-provisioning/thin_scan.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/thin-provisioning/thin_scan.cc b/thin-provisioning/thin_scan.cc index 725c3b6..1ed7a6b 100644 --- a/thin-provisioning/thin_scan.cc +++ b/thin-provisioning/thin_scan.cc @@ -152,13 +152,12 @@ namespace { bool is_adjacent_to(block_range const &r) const { block_range const &lhs = begin_ < r.begin_ ? *this : r; block_range const &rhs = begin_ < r.begin_ ? r : *this; - uint64_t common_end = std::min(end_, r.end_); if (size() && r.size() && - rhs.begin_ == common_end && + rhs.begin_ == lhs.end_ && ((!blocknr_begin_ && !r.blocknr_begin_) || (blocknr_begin_ && r.blocknr_begin_ && - *rhs.blocknr_begin_ > *lhs.blocknr_begin_ && + *rhs.blocknr_begin_ >= *lhs.blocknr_begin_ && (*rhs.blocknr_begin_ - *lhs.blocknr_begin_ == rhs.begin_ - lhs.begin_))) && type_ == r.type_ && ref_count_ == r.ref_count_ && From 220ece1dc8bc868cd3a143a29448b81c92320b2b Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sun, 6 Mar 2016 23:21:09 +0800 Subject: [PATCH 6/7] [thin] Cleanup: move methods before data member declaration --- thin-provisioning/device_tree.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/device_tree.h b/thin-provisioning/device_tree.h index ef32b45..ec0f9f2 100644 --- a/thin-provisioning/device_tree.h +++ b/thin-provisioning/device_tree.h @@ -16,12 +16,12 @@ namespace thin_provisioning { } __attribute__ ((packed)); struct device_details { + device_details(); + uint64_t mapped_blocks_; uint64_t transaction_id_; /* when created */ uint32_t creation_time_; uint32_t snapshotted_time_; - - device_details(); }; struct device_details_traits { From 5cbef4f6efa0eb4565698dd41d54d175d81faf0b Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 8 Mar 2016 15:52:12 +0000 Subject: [PATCH 7/7] [thin_ll_*] move these to dev tools --- thin-provisioning/commands.cc | 4 ++-- thin-provisioning/commands.h | 38 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/thin-provisioning/commands.cc b/thin-provisioning/commands.cc index f4a96fd..4f2af9d 100644 --- a/thin-provisioning/commands.cc +++ b/thin-provisioning/commands.cc @@ -11,8 +11,6 @@ thin_provisioning::register_thin_commands(base::application &app) app.add_cmd(command::ptr(new thin_check_cmd())); app.add_cmd(command::ptr(new thin_delta_cmd())); app.add_cmd(command::ptr(new thin_dump_cmd())); - app.add_cmd(command::ptr(new thin_ll_dump_cmd())); - app.add_cmd(command::ptr(new thin_ll_restore_cmd())); app.add_cmd(command::ptr(new thin_ls_cmd())); app.add_cmd(command::ptr(new thin_metadata_size_cmd())); app.add_cmd(command::ptr(new thin_restore_cmd())); @@ -20,6 +18,8 @@ thin_provisioning::register_thin_commands(base::application &app) app.add_cmd(command::ptr(new thin_rmap_cmd())); #ifdef DEV_TOOLS + app.add_cmd(command::ptr(new thin_ll_dump_cmd())); + app.add_cmd(command::ptr(new thin_ll_restore_cmd())); app.add_cmd(command::ptr(new thin_scan_cmd())); app.add_cmd(command::ptr(new thin_trim_cmd())); app.add_cmd(command::ptr(new thin_generate_metadata_cmd())); diff --git a/thin-provisioning/commands.h b/thin-provisioning/commands.h index 1cff88f..52aeaf8 100644 --- a/thin-provisioning/commands.h +++ b/thin-provisioning/commands.h @@ -28,20 +28,6 @@ namespace thin_provisioning { virtual int run(int argc, char **argv); }; - class thin_ll_dump_cmd : public base::command { - public: - thin_ll_dump_cmd(); - virtual void usage(std::ostream &out) const; - virtual int run(int argc, char **argv); - }; - - class thin_ll_restore_cmd : public base::command { - public: - thin_ll_restore_cmd(); - virtual void usage(std::ostream &out) const; - virtual int run(int argc, char **argv); - }; - class thin_ls_cmd : public base::command { public: thin_ls_cmd(); @@ -77,17 +63,31 @@ namespace thin_provisioning { virtual int run(int argc, char **argv); }; -#ifdef DEV_TOOLS - class thin_scan_cmd : public base::command { + class thin_trim_cmd : public base::command { public: - thin_scan_cmd(); + thin_trim_cmd(); virtual void usage(std::ostream &out) const; virtual int run(int argc, char **argv); }; - class thin_trim_cmd : public base::command { +#ifdef DEV_TOOLS + class thin_ll_dump_cmd : public base::command { public: - thin_trim_cmd(); + thin_ll_dump_cmd(); + virtual void usage(std::ostream &out) const; + virtual int run(int argc, char **argv); + }; + + class thin_ll_restore_cmd : public base::command { + public: + thin_ll_restore_cmd(); + virtual void usage(std::ostream &out) const; + virtual int run(int argc, char **argv); + }; + + class thin_scan_cmd : public base::command { + public: + thin_scan_cmd(); virtual void usage(std::ostream &out) const; virtual int run(int argc, char **argv); };