From 77864193a1162393ade783480aee39a232934377 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Wed, 30 Jul 2014 11:22:29 -0700 Subject: [PATCH] Renames and removal towards a unified ceph_objectstore_tool Rename ceph_filestore_dump.cc and ceph_filestore_dump.py Remove ceph_filestore_tool.cc Signed-off-by: David Zafman --- ...store_dump.py => ceph_objectstore_tool.py} | 0 src/tools/ceph_filestore_tool.cc | 253 ------------------ ...store_dump.cc => ceph_objectstore_tool.cc} | 29 +- 3 files changed, 14 insertions(+), 268 deletions(-) rename src/test/{ceph_filestore_dump.py => ceph_objectstore_tool.py} (100%) delete mode 100644 src/tools/ceph_filestore_tool.cc rename src/tools/{ceph_filestore_dump.cc => ceph_objectstore_tool.cc} (99%) diff --git a/src/test/ceph_filestore_dump.py b/src/test/ceph_objectstore_tool.py similarity index 100% rename from src/test/ceph_filestore_dump.py rename to src/test/ceph_objectstore_tool.py diff --git a/src/tools/ceph_filestore_tool.cc b/src/tools/ceph_filestore_tool.cc deleted file mode 100644 index e461ebed3b77..000000000000 --- a/src/tools/ceph_filestore_tool.cc +++ /dev/null @@ -1,253 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2013 Inktank - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include -#include - -#include - -#include "common/Formatter.h" -#include "common/errno.h" - -#include "global/global_init.h" - -#include "os/ObjectStore.h" -#include "os/FileStore.h" - -#include "osd/PGLog.h" -#include "osd/osd_types.h" -#include "osd/OSD.h" - -namespace po = boost::program_options; -using namespace std; - -static void invalid_path(string &path) -{ - cout << "Invalid path to osd store specified: " << path << "\n"; - exit(1); -} - -int main(int argc, char **argv) -{ - string fspath, jpath, pgidstr; - bool list_lost_objects = false; - bool fix_lost_objects = false; - unsigned LIST_AT_A_TIME = 100; - unsigned scanned = 0; - - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "produce help message") - ("filestore-path", po::value(&fspath), - "path to filestore directory, mandatory") - ("journal-path", po::value(&jpath), - "path to journal, mandatory") - ("pgid", po::value(&pgidstr), - "PG id") - ("list-lost-objects", po::value( - &list_lost_objects)->default_value(false), - "list lost objects") - ("fix-lost-objects", po::value( - &fix_lost_objects)->default_value(false), - "fix lost objects") - ; - - po::variables_map vm; - po::parsed_options parsed = - po::command_line_parser(argc, argv).options(desc). - allow_unregistered().run(); - po::store( parsed, vm); - try { - po::notify(vm); - } - catch(...) { - cout << desc << std::endl; - exit(1); - } - - if (vm.count("help")) { - cout << desc << std::endl; - return 1; - } - - if (!vm.count("filestore-path")) { - cerr << "Must provide filestore-path" << std::endl - << desc << std::endl; - return 1; - } - if (!vm.count("journal-path")) { - cerr << "Must provide journal-path" << std::endl - << desc << std::endl; - return 1; - } - - if ((fspath.length() == 0 || jpath.length() == 0)) { - cerr << "Invalid params" << desc << std::endl; - exit(1); - } - - vector ceph_options, def_args; - vector ceph_option_strings = po::collect_unrecognized( - parsed.options, po::include_positional); - ceph_options.reserve(ceph_option_strings.size()); - for (vector::iterator i = ceph_option_strings.begin(); - i != ceph_option_strings.end(); - ++i) { - ceph_options.push_back(i->c_str()); - } - - global_init( - &def_args, ceph_options, CEPH_ENTITY_TYPE_OSD, - CODE_ENVIRONMENT_UTILITY, 0); - //CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); - common_init_finish(g_ceph_context); - g_ceph_context->_conf->apply_changes(NULL); - g_conf = g_ceph_context->_conf; - - //Verify that fspath really is an osd store - struct stat st; - if (::stat(fspath.c_str(), &st) == -1) { - perror("fspath"); - invalid_path(fspath); - } - if (!S_ISDIR(st.st_mode)) { - invalid_path(fspath); - } - string check = fspath + "/whoami"; - if (::stat(check.c_str(), &st) == -1) { - perror("whoami"); - invalid_path(fspath); - } - if (!S_ISREG(st.st_mode)) { - invalid_path(fspath); - } - check = fspath + "/current"; - if (::stat(check.c_str(), &st) == -1) { - perror("current"); - invalid_path(fspath); - } - if (!S_ISDIR(st.st_mode)) { - invalid_path(fspath); - } - - ObjectStore *fs = new FileStore(fspath, jpath); - - int r = fs->mount(); - if (r < 0) { - if (r == -EBUSY) { - cout << "OSD has the store locked" << std::endl; - } else { - cout << "Mount failed with '" << cpp_strerror(-r) << "'" << std::endl; - } - return 1; - } - - vector colls_to_check; - if (pgidstr.length()) { - spg_t pgid; - if (!pgid.parse(pgidstr.c_str())) { - cout << "Invalid pgid '" << pgidstr << "' specified" << std::endl; - exit(1); - } - colls_to_check.push_back(coll_t(pgid)); - } else { - vector candidates; - r = fs->list_collections(candidates); - if (r < 0) { - cerr << "Error listing collections: " << cpp_strerror(r) << std::endl; - goto UMOUNT; - } - for (vector::iterator i = candidates.begin(); - i != candidates.end(); - ++i) { - spg_t pgid; - snapid_t snap; - if (i->is_pg(pgid, snap)) { - colls_to_check.push_back(*i); - } - } - } - - cerr << colls_to_check.size() << " pgs to scan" << std::endl; - for (vector::iterator i = colls_to_check.begin(); - i != colls_to_check.end(); - ++i, ++scanned) { - cerr << "Scanning " << *i << ", " << scanned << "/" - << colls_to_check.size() << " completed" << std::endl; - ghobject_t next; - while (!next.is_max()) { - vector list; - r = fs->collection_list_partial( - *i, - next, - LIST_AT_A_TIME, - LIST_AT_A_TIME, - CEPH_NOSNAP, - &list, - &next); - if (r < 0) { - cerr << "Error listing collection: " << *i << ", " - << cpp_strerror(r) << std::endl; - goto UMOUNT; - } - for (vector::iterator obj = list.begin(); - obj != list.end(); - ++obj) { - bufferlist attr; - r = fs->getattr(*i, *obj, OI_ATTR, attr); - if (r < 0) { - cerr << "Error getting attr on : " << make_pair(*i, *obj) << ", " - << cpp_strerror(r) << std::endl; - goto UMOUNT; - } - object_info_t oi; - bufferlist::iterator bp = attr.begin(); - try { - ::decode(oi, bp); - } catch (...) { - r = -EINVAL; - cerr << "Error getting attr on : " << make_pair(*i, *obj) << ", " - << cpp_strerror(r) << std::endl; - goto UMOUNT; - } - if (oi.is_lost()) { - if (list_lost_objects) { - cout << *i << "/" << *obj << " is lost" << std::endl; - } - if (fix_lost_objects) { - cerr << *i << "/" << *obj << " is lost, fixing" << std::endl; - oi.clear_flag(object_info_t::FLAG_LOST); - bufferlist bl2; - ::encode(oi, bl2); - ObjectStore::Transaction t; - t.setattr(*i, *obj, OI_ATTR, bl2); - r = fs->apply_transaction(t); - if (r < 0) { - cerr << "Error getting fixing attr on : " << make_pair(*i, *obj) - << ", " - << cpp_strerror(r) << std::endl; - goto UMOUNT; - } - } - } - } - } - } - cerr << "Completed" << std::endl; - - UMOUNT: - fs->sync_and_flush(); - fs->umount(); - return r; -} diff --git a/src/tools/ceph_filestore_dump.cc b/src/tools/ceph_objectstore_tool.cc similarity index 99% rename from src/tools/ceph_filestore_dump.cc rename to src/tools/ceph_objectstore_tool.cc index 0ff018c84acc..6655497d229a 100644 --- a/src/tools/ceph_filestore_dump.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -419,7 +419,7 @@ static void invalid_path(string &path) int get_log(ObjectStore *fs, coll_t coll, spg_t pgid, const pg_info_t &info, PGLog::IndexedLog &log, pg_missing_t &missing) -{ +{ map divergent_priors; try { ostringstream oss; @@ -892,10 +892,10 @@ int get_attrs(ObjectStore *store, coll_t coll, ghobject_t hoid, bufferlist attr_bl; attr_bl.push_back(mi->second); object_info_t oi(attr_bl); - + if (debug) cerr << "object_info " << oi << std::endl; - + OSDriver::OSTransaction _t(driver.get_transaction(t)); set oi_snaps(oi.snaps.begin(), oi.snaps.end()); snap_mapper.add_oid(hoid.hobj, oi_snaps, &_t); @@ -1010,7 +1010,7 @@ int get_pg_metadata(ObjectStore *store, coll_t coll, bufferlist &bl) formatter->close_section(); formatter->flush(cout); cout << std::endl; - + formatter->open_object_section("log"); ms.log.dump(formatter); formatter->close_section(); @@ -1550,11 +1550,11 @@ int main(int argc, char **argv) if (!vm.count("filestore-path")) { cerr << "Must provide --filestore-path" << std::endl; usage(desc); - } + } if (!vm.count("journal-path")) { cerr << "Must provide --journal-path" << std::endl; usage(desc); - } + } if (vm.count("object") && !vm.count("objcmd")) { cerr << "Invalid syntax, missing command" << std::endl; usage(desc); @@ -1563,7 +1563,7 @@ int main(int argc, char **argv) cerr << "Must provide --type or object command..." << std::endl; usage(desc); - } + } if (vm.count("type") && vm.count("object")) { cerr << "Can't specify both --type and object command syntax" << std::endl; usage(desc); @@ -1571,7 +1571,7 @@ int main(int argc, char **argv) if (type != "import" && !vm.count("pgid")) { cerr << "Must provide pgid" << std::endl; usage(desc); - } + } if (vm.count("object")) { json_spirit::Value v; @@ -1619,7 +1619,7 @@ int main(int argc, char **argv) perror("open"); return 1; } - + if ((fspath.length() == 0 || jpath.length() == 0) || (type != "import" && pgidstr.length() == 0)) { cerr << "Invalid params" << std::endl; @@ -1698,7 +1698,7 @@ int main(int argc, char **argv) } ObjectStore *fs = ObjectStore::create(NULL, "filestore", fspath, jpath, flags); - + int r = fs->mount(); if (r < 0) { if (r == -EBUSY) { @@ -1835,9 +1835,9 @@ int main(int argc, char **argv) epoch_t map_epoch; // The following code for export, info, log require omap or !skip-mount-omap if (it != ls.end()) { - + coll_t coll = *it; - + if (vm.count("objcmd")) { ret = 0; if (objcmd == "remove") { @@ -2017,7 +2017,7 @@ int main(int argc, char **argv) map past_intervals; hobject_t biginfo_oid = OSD::make_pg_biginfo_oid(pgid); interval_set snap_collections; - + __u8 struct_ver; r = PG::read_info(fs, coll, bl, info, past_intervals, biginfo_oid, infos_oid, snap_collections, struct_ver); @@ -2045,7 +2045,7 @@ int main(int argc, char **argv) ret = get_log(fs, coll, pgid, info, log, missing); if (ret > 0) goto out; - + formatter->open_object_section("log"); log.dump(formatter); formatter->close_section(); @@ -2074,4 +2074,3 @@ out: return (ret != 0); } - -- 2.47.3