From: Kefu Chai Date: Mon, 6 Jul 2020 10:12:31 +0000 (+0800) Subject: tools/ceph-dencoder: add get_struct_v,get_struct_compat commands X-Git-Tag: wip-pdonnell-testing-20200918.022351~760^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8149c9302ded6a5b4310bbe847db55050120133e;p=ceph-ci.git 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 --- 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; };