From: David Zafman Date: Thu, 7 Jun 2018 19:04:05 +0000 (-0700) Subject: ceph-objectstore-tool: Add removal options to corrupt objects for testing X-Git-Tag: v14.1.0~947^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=00e669a173426305a9d574c28fa7ebe05350f372;p=ceph-ci.git ceph-objectstore-tool: Add removal options to corrupt objects for testing Signed-off-by: David Zafman --- diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 6e1e94e1058..b40604496a1 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -1892,25 +1892,36 @@ int do_meta(ObjectStore *store, string object, Formatter *formatter, bool debug, return 0; } +enum rmtype { + BOTH, + SNAPMAP, + NOSNAPMAP +}; + int remove_object(coll_t coll, ghobject_t &ghobj, SnapMapper &mapper, MapCacher::Transaction *_t, - ObjectStore::Transaction *t) + ObjectStore::Transaction *t, + enum rmtype type) { - int r = mapper.remove_oid(ghobj.hobj, _t); - if (r < 0 && r != -ENOENT) { - cerr << "remove_oid returned " << cpp_strerror(r) << std::endl; - return r; + if (type == BOTH || type == SNAPMAP) { + int r = mapper.remove_oid(ghobj.hobj, _t); + if (r < 0 && r != -ENOENT) { + cerr << "remove_oid returned " << cpp_strerror(r) << std::endl; + return r; + } } - t->remove(coll, ghobj); + if (type == BOTH || type == NOSNAPMAP) { + t->remove(coll, ghobj); + } return 0; } int get_snapset(ObjectStore *store, coll_t coll, ghobject_t &ghobj, SnapSet &ss, bool silent); int do_remove_object(ObjectStore *store, coll_t coll, - ghobject_t &ghobj, bool all, bool force) + ghobject_t &ghobj, bool all, bool force, enum rmtype type) { auto ch = store->open_collection(coll); spg_t pg; @@ -1951,26 +1962,26 @@ int do_remove_object(ObjectStore *store, coll_t coll, ObjectStore::Transaction t; OSDriver::OSTransaction _t(driver.get_transaction(&t)); - cout << "remove " << ghobj << std::endl; - - if (!dry_run) { - r = remove_object(coll, ghobj, mapper, &_t, &t); - if (r < 0) - return r; - } - ghobject_t snapobj = ghobj; for (vector::iterator i = ss.snaps.begin() ; i != ss.snaps.end() ; ++i) { snapobj.hobj.snap = *i; cout << "remove " << snapobj << std::endl; if (!dry_run) { - r = remove_object(coll, snapobj, mapper, &_t, &t); + r = remove_object(coll, snapobj, mapper, &_t, &t, type); if (r < 0) return r; } } + cout << "remove " << ghobj << std::endl; + + if (!dry_run) { + r = remove_object(coll, ghobj, mapper, &_t, &t, type); + if (r < 0) + return r; + } + if (!dry_run) { wait_until_done(&t, [&] { store->queue_transaction(ch, std::move(t)); @@ -2983,7 +2994,7 @@ int main(int argc, char **argv) { string dpath, jpath, pgidstr, op, file, mountpoint, mon_store_path, object; string target_data_path, fsid; - string objcmd, arg1, arg2, type, format, argnspace, pool; + string objcmd, arg1, arg2, type, format, argnspace, pool, rmtypestr; boost::optional nspace; spg_t pgid; unsigned epoch = 0; @@ -3029,6 +3040,7 @@ int main(int argc, char **argv) ("head", "Find head/snapdir when searching for objects by name") ("dry-run", "Don't modify the objectstore") ("namespace", po::value(&argnspace), "Specify namespace when searching for objects") + ("rmtype", po::value(&rmtypestr), "Specify corrupting object removal 'snapmap' or 'nosnapmap' - TESTING USE ONLY") ; po::options_description positional("Positional options"); @@ -3761,7 +3773,12 @@ int main(int argc, char **argv) ret = 0; if (objcmd == "remove" || objcmd == "removeall") { bool all = (objcmd == "removeall"); - ret = do_remove_object(fs, coll, ghobj, all, force); + enum rmtype type = BOTH; + if (rmtypestr == "nosnapmap") + type = NOSNAPMAP; + else if (rmtypestr == "snapmap") + type = SNAPMAP; + ret = do_remove_object(fs, coll, ghobj, all, force, type); goto out; } else if (objcmd == "list-attrs") { ret = do_list_attrs(fs, coll, ghobj);