From 83dc84f790985b13e54864255b1e8693dbf3b8b6 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 24 Mar 2016 15:21:20 +0000 Subject: [PATCH] [contrib] ewheeler_emitter.so For thin_dump --- contrib/Makefile.in | 7 +++- contrib/ewheeler_emitter.cc | 84 +++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 contrib/ewheeler_emitter.cc diff --git a/contrib/Makefile.in b/contrib/Makefile.in index 58cfefc..1df15ec 100644 --- a/contrib/Makefile.in +++ b/contrib/Makefile.in @@ -1,6 +1,7 @@ PLUGINS=\ contrib/thin_sexp_emitter.so \ - contrib/tmakatos_emitter.so + contrib/tmakatos_emitter.so \ + contrib/ewheeler_emitter.so contrib: $(PLUGINS) @@ -12,4 +13,8 @@ contrib/tmakatos_emitter.so: contrib/tmakatos_emitter.o $(V)echo " [LD] $@" $(V)$(CC) -shared -Wl,-soname,tmakatos_emitter.so -o $@ $< +contrib/ewheeler_emitter.so: contrib/ewheeler_emitter.o + $(V)echo " [LD] $@" + $(V)$(CC) -shared -Wl,-soname,ewheeler_emitter.so -o $@ $< + diff --git a/contrib/ewheeler_emitter.cc b/contrib/ewheeler_emitter.cc new file mode 100644 index 0000000..fdc310d --- /dev/null +++ b/contrib/ewheeler_emitter.cc @@ -0,0 +1,84 @@ +#include "thin-provisioning/emitter.h" + +using namespace std; +using namespace thin_provisioning; + +//---------------------------------------------------------------- + +namespace { + template + std::ostream &operator << (ostream &out, boost::optional const &maybe) { + if (maybe) + out << *maybe; + + return out; + } + + class old_emitter : public emitter { + public: + old_emitter(ostream &out) + : out_(out) { + } + + void begin_superblock(string const &uuid, + uint64_t time, + uint64_t trans_id, + boost::optional flags, + boost::optional version, + uint32_t data_block_size, + uint64_t nr_data_blocks, + boost::optional metadata_snap) { + data_block_size_ = data_block_size; + } + + void end_superblock() { + } + + void begin_device(uint32_t dev_id, + uint64_t mapped_blocks, + uint64_t trans_id, + uint64_t creation_time, + uint64_t snap_time) { + } + + void end_device() { + } + + void begin_named_mapping(string const &name) { + } + + void end_named_mapping() { + } + + void identifier(string const &name) { + } + + void range_map(uint64_t origin_begin, uint64_t data_begin, uint32_t time, uint64_t len) { + out_ << (data_block_size_ << 9)*origin_begin + << ":" << (data_block_size_ << 9)*len + << ":" << (data_block_size_ << 9)*data_begin + << endl; + } + + void single_map(uint64_t origin_block, uint64_t data_block, uint32_t time) { + out_ << (data_block_size_ << 9)*origin_block + << ":" << (data_block_size_ << 9) + << ":" << (data_block_size_ << 9)*data_block + << endl; + } + + private: + ostream &out_; + uint64_t data_block_size_; + }; +} + +//---------------------------------------------------------------- + +extern "C" { + emitter::ptr create_emitter(ostream &out) { + return emitter::ptr(new old_emitter(out)); + } +} + +//----------------------------------------------------------------