mirror of
https://github.com/ceph/ceph
synced 2025-01-03 09:32:43 +00:00
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 <david.zafman@inktank.com>
This commit is contained in:
parent
f464f5772a
commit
77864193a1
@ -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 <boost/program_options/variables_map.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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<string>(&fspath),
|
||||
"path to filestore directory, mandatory")
|
||||
("journal-path", po::value<string>(&jpath),
|
||||
"path to journal, mandatory")
|
||||
("pgid", po::value<string>(&pgidstr),
|
||||
"PG id")
|
||||
("list-lost-objects", po::value<bool>(
|
||||
&list_lost_objects)->default_value(false),
|
||||
"list lost objects")
|
||||
("fix-lost-objects", po::value<bool>(
|
||||
&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<const char *> ceph_options, def_args;
|
||||
vector<string> ceph_option_strings = po::collect_unrecognized(
|
||||
parsed.options, po::include_positional);
|
||||
ceph_options.reserve(ceph_option_strings.size());
|
||||
for (vector<string>::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<coll_t> 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<coll_t> candidates;
|
||||
r = fs->list_collections(candidates);
|
||||
if (r < 0) {
|
||||
cerr << "Error listing collections: " << cpp_strerror(r) << std::endl;
|
||||
goto UMOUNT;
|
||||
}
|
||||
for (vector<coll_t>::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<coll_t>::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<ghobject_t> 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<ghobject_t>::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;
|
||||
}
|
@ -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<eversion_t, hobject_t> 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<snapid_t> 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<epoch_t,pg_interval_t> past_intervals;
|
||||
hobject_t biginfo_oid = OSD::make_pg_biginfo_oid(pgid);
|
||||
interval_set<snapid_t> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user