From 702a38f43882dce419751913907d6c714f9336ba Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 21 Jul 2016 15:42:10 +0100 Subject: [PATCH 1/3] [many tools] fix bug in previous patch --- base/output_file_requirements.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/base/output_file_requirements.cc b/base/output_file_requirements.cc index 001e127..fefdc0f 100644 --- a/base/output_file_requirements.cc +++ b/base/output_file_requirements.cc @@ -37,14 +37,17 @@ base::check_output_file_requirements(string const &path) explain_output_file_requirements(); } - if (!info.st_size) { - cerr << "Zero size output file.\n\n"; - explain_output_file_requirements(); - } + // We only really want these checks for regular files + if (S_ISREG(info.st_mode)) { + if (!info.st_size) { + cerr << "Zero size output file.\n\n"; + explain_output_file_requirements(); + } - if (info.st_size < MIN_SIZE) { - cerr << "Output file too small.\n\n"; - explain_output_file_requirements(); + if (info.st_size < MIN_SIZE) { + cerr << "Output file too small.\n\n"; + explain_output_file_requirements(); + } } } From 6863db6f8682995f2d50458d7ec9dd22d52166e4 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Wed, 10 Aug 2016 23:40:48 +0800 Subject: [PATCH 2/3] [thin] fix duplicated counting of mapped blocks in restore emitter --- persistent-data/data-structures/btree.h | 2 +- persistent-data/data-structures/btree.tcc | 4 +++- thin-provisioning/restore_emitter.cc | 5 ++--- thin-provisioning/thin_pool.cc | 2 +- thin-provisioning/thin_pool.h | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/persistent-data/data-structures/btree.h b/persistent-data/data-structures/btree.h index b91fb20..9e85a36 100644 --- a/persistent-data/data-structures/btree.h +++ b/persistent-data/data-structures/btree.h @@ -322,7 +322,7 @@ namespace persistent_data { maybe_pair lookup_le(key const &key) const; maybe_pair lookup_ge(key const &key) const; - void insert(key const &key, typename ValueTraits::value_type const &value); + bool insert(key const &key, typename ValueTraits::value_type const &value); void remove(key const &key); void set_root(block_address root); diff --git a/persistent-data/data-structures/btree.tcc b/persistent-data/data-structures/btree.tcc index 3fc96e4..ce49a30 100644 --- a/persistent-data/data-structures/btree.tcc +++ b/persistent-data/data-structures/btree.tcc @@ -498,7 +498,7 @@ namespace persistent_data { } template - void + bool btree:: insert(key const &key, typename ValueTraits::value_type const &value) @@ -531,6 +531,8 @@ namespace persistent_data { n.set_value(index, value); root_ = spine.get_root(); + + return need_insert; } template diff --git a/thin-provisioning/restore_emitter.cc b/thin-provisioning/restore_emitter.cc index c16eb70..46b7f92 100644 --- a/thin-provisioning/restore_emitter.cc +++ b/thin-provisioning/restore_emitter.cc @@ -136,10 +136,9 @@ namespace { mapping_tree_detail::block_time bt; bt.block_ = data_block; bt.time_ = time; - current_mapping_->insert(key, bt); + current_device_details_.mapped_blocks_ += + static_cast(current_mapping_->insert(key, bt)); md_->data_sm_->inc(data_block); - - current_device_details_.mapped_blocks_ += 1; } private: diff --git a/thin-provisioning/thin_pool.cc b/thin-provisioning/thin_pool.cc index 1abaa57..d133711 100644 --- a/thin-provisioning/thin_pool.cc +++ b/thin-provisioning/thin_pool.cc @@ -50,7 +50,7 @@ thin::lookup(block_address thin_block) return pool_->md_->mappings_->lookup(key); } -void +bool thin::insert(block_address thin_block, block_address data_block) { uint64_t key[2] = {dev_, thin_block}; diff --git a/thin-provisioning/thin_pool.h b/thin-provisioning/thin_pool.h index 66ae307..0c6b156 100644 --- a/thin-provisioning/thin_pool.h +++ b/thin-provisioning/thin_pool.h @@ -39,7 +39,7 @@ namespace thin_provisioning { thin_dev_t get_dev_t() const; maybe_address lookup(block_address thin_block); - void insert(block_address thin_block, block_address data_block); + bool insert(block_address thin_block, block_address data_block); void remove(block_address thin_block); void set_snapshot_time(uint32_t time); From 45dbc2593aa5f9cdd7fa05b7c6925d49530cee08 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Wed, 10 Aug 2016 23:41:25 +0800 Subject: [PATCH 3/3] [thin_ll_restore] check preallocation of output file --- thin-provisioning/thin_ll_restore.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/thin_ll_restore.cc b/thin-provisioning/thin_ll_restore.cc index 4082e0b..ff62298 100644 --- a/thin-provisioning/thin_ll_restore.cc +++ b/thin-provisioning/thin_ll_restore.cc @@ -14,6 +14,7 @@ // with thin-provisioning-tools. If not, see // . +#include "base/output_file_requirements.h" #include "base/xml_utils.h" #include "metadata_dumper.h" #include "metadata.h" @@ -261,12 +262,25 @@ thin_ll_restore_cmd::run(int argc, char **argv) { return 1; } - if (!input_metadata.length() || !input.length() || !output.length()) { - cerr << "No input/output file provided." << endl; + if (!input.length()) { + cerr << "No input file provided." << endl; usage(cerr); return 1; } + if (!input_metadata.length()) { + cerr << "No input metadata provided." << endl; + usage(cerr); + return 1; + } + + if (!output.length()) { + cerr << "No output file provided." << endl; + usage(cerr); + return 1; + } else + check_output_file_requirements(output); + return low_level_restore(input_metadata, input, output, f); }