From: David Zafman Date: Fri, 20 Jul 2018 19:31:56 +0000 (-0700) Subject: tools: Add testing feature "corrupt-info" to ceph-objectstore-tool X-Git-Tag: v12.2.8~71^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=86927993ea5ec38cbd523980a20a9bfec60f79fc;p=ceph.git tools: Add testing feature "corrupt-info" to ceph-objectstore-tool Signed-off-by: David Zafman (cherry picked from commit 8e9c08524da0cf465553f99b2e160e59abc8e84b) Conflicts: src/tools/ceph_objectstore_tool.cc (adjust for Luminous transactions) --- diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 2e34268805b2..c640ec50e5f7 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -2405,6 +2405,43 @@ int print_obj_info(ObjectStore *store, coll_t coll, ghobject_t &ghobj, Formatter return r; } +int corrupt_info(ObjectStore *store, coll_t coll, ghobject_t &ghobj, Formatter* formatter, + ObjectStore::Sequencer &osr) +{ + bufferlist attr; + int r = store->getattr(coll, ghobj, OI_ATTR, attr); + if (r < 0) { + cerr << "Error getting attr on : " << make_pair(coll, ghobj) << ", " + << cpp_strerror(r) << std::endl; + return r; + } + object_info_t oi; + bufferlist::iterator bp = attr.begin(); + try { + ::decode(oi, bp); + } catch (...) { + r = -EINVAL; + cerr << "Error getting attr on : " << make_pair(coll, ghobj) << ", " + << cpp_strerror(r) << std::endl; + return r; + } + cout << "Corrupting info" << std::endl; + if (!dry_run) { + attr.clear(); + oi.alloc_hint_flags += 0xff; + ObjectStore::Transaction t; + ::encode(oi, attr, -1); /* fixme: using full features */ + t.setattr(coll, ghobj, OI_ATTR, attr); + r = store->apply_transaction(&osr, std::move(t)); + if (r < 0) { + cerr << "Error writing object info: " << make_pair(coll, ghobj) << ", " + << cpp_strerror(r) << std::endl; + return r; + } + } + return 0; +} + int set_size(ObjectStore *store, coll_t coll, ghobject_t &ghobj, uint64_t setsize, Formatter* formatter, ObjectStore::Sequencer &osr, bool corrupt) { @@ -3868,6 +3905,15 @@ int main(int argc, char **argv) } ret = print_obj_info(fs, coll, ghobj, formatter); goto out; + } else if (objcmd == "corrupt-info") { // Undocumented testing feature + // There should not be any other arguments + if (vm.count("arg1") || vm.count("arg2")) { + usage(desc); + ret = 1; + goto out; + } + ret = corrupt_info(fs, coll, ghobj, formatter, *osr); + goto out; } else if (objcmd == "set-size" || objcmd == "corrupt-size") { // Undocumented testing feature bool corrupt = (objcmd == "corrupt-size");