From 8149c9302ded6a5b4310bbe847db55050120133e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 6 Jul 2020 18:12:31 +0800 Subject: [PATCH] tools/ceph-dencoder: add get_struct_v,get_struct_compat commands for understanding the current encoding version and the lower bound of supported decoders. Signed-off-by: Kefu Chai --- src/tools/ceph-dencoder/ceph_dencoder.cc | 6 ++++++ src/tools/ceph-dencoder/denc_registry.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/tools/ceph-dencoder/ceph_dencoder.cc b/src/tools/ceph-dencoder/ceph_dencoder.cc index 53cf4c33696..2e4940256af 100644 --- a/src/tools/ceph-dencoder/ceph_dencoder.cc +++ b/src/tools/ceph-dencoder/ceph_dencoder.cc @@ -42,6 +42,8 @@ void usage(ostream &out) out << " encode encode in-memory object\n"; out << " dump_json dump in-memory object as json (to stdout)\n"; out << " hexdump print encoded data in hex\n"; + out << " get_struct_v print version of the encoded object\n"; + out << " get_struct_compat print the oldest version of decoder that can decode the encoded object\n"; out << "\n"; out << " copy copy object (via operator=)\n"; out << " copy_ctor copy object (via copy ctor)\n"; @@ -154,6 +156,10 @@ int main(int argc, const char **argv) } else if (*i == string("hexdump")) { encbl.hexdump(cout); + } else if (*i == string("get_struct_v")) { + std::cout << den->get_struct_v(encbl, 0) << std::endl; + } else if (*i == string("get_struct_compat")) { + std::cout << den->get_struct_v(encbl, sizeof(uint8_t)) << std::endl; } else if (*i == string("import")) { ++i; if (i == args.end()) { diff --git a/src/tools/ceph-dencoder/denc_registry.h b/src/tools/ceph-dencoder/denc_registry.h index d98c23130c1..74c7be97db7 100644 --- a/src/tools/ceph-dencoder/denc_registry.h +++ b/src/tools/ceph-dencoder/denc_registry.h @@ -27,6 +27,12 @@ struct Dencoder { virtual int num_generated() = 0; virtual std::string select_generated(unsigned n) = 0; virtual bool is_deterministic() = 0; + unsigned get_struct_v(bufferlist bl, uint64_t seek) const { + auto p = bl.cbegin(seek); + uint8_t struct_v = 0; + ceph::decode(struct_v, p); + return struct_v; + } //virtual void print(ostream& out) = 0; }; -- 2.39.5