#include "global/global_init.h"
#include "os/ObjectStore.h"
-#include "os/filestore/FileJournal.h"
-#include "os/filestore/FileStore.h"
#ifdef HAVE_LIBFUSE
#include "os/FuseStore.h"
#endif
&& pgb.superblock.cluster_fsid != sb.cluster_fsid) {
cerr << "Export came from different cluster with fsid "
<< pgb.superblock.cluster_fsid << std::endl;
- return -EINVAL;
+ if (force) {
+ cerr << "Ignoring this problem due to --force" << std::endl;
+ } else {
+ return -EINVAL;
+ }
}
if (debug) {
return check.size() >= ending.size() && check.rfind(ending) == (check.size() - ending.size());
}
-// Based on FileStore::dump_journal(), set-up enough to only dump
-int mydump_journal(Formatter *f, string journalpath, bool m_journal_dio)
-{
- int r;
-
- if (!journalpath.length())
- return -EINVAL;
-
- FileJournal *journal = new FileJournal(g_ceph_context, uuid_d(), NULL, NULL,
- journalpath.c_str(), m_journal_dio);
- r = journal->_fdump(*f, false);
- delete journal;
- return r;
-}
-
-int apply_layout_settings(ObjectStore *os, const OSDSuperblock &superblock,
- const string &pool_name, const spg_t &pgid, bool dry_run,
- int target_level)
-{
- int r = 0;
-
- FileStore *fs = dynamic_cast<FileStore*>(os);
- if (!fs) {
- cerr << "Nothing to do for non-filestore backend" << std::endl;
- return 0; // making this return success makes testing easier
- }
-
- OSDMap curmap;
- bufferlist bl;
- r = get_osdmap(os, superblock.current_epoch, curmap, bl);
- if (r) {
- cerr << "Can't find local OSDMap: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- int64_t poolid = -1;
- if (pool_name.length()) {
- poolid = curmap.lookup_pg_pool_name(pool_name);
- if (poolid < 0) {
- cerr << "Couldn't find pool " << pool_name << ": " << cpp_strerror(poolid)
- << std::endl;
- return poolid;
- }
- }
-
- vector<coll_t> collections, filtered_colls;
- r = os->list_collections(collections);
- if (r < 0) {
- cerr << "Error listing collections: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- for (auto const &coll : collections) {
- spg_t coll_pgid;
- if (coll.is_pg(&coll_pgid) &&
- ((poolid >= 0 && coll_pgid.pool() == (uint64_t)poolid) ||
- coll_pgid == pgid)) {
- filtered_colls.push_back(coll);
- }
- }
-
- size_t done = 0, total = filtered_colls.size();
- for (auto const &coll : filtered_colls) {
- if (dry_run) {
- cerr << "Would apply layout settings to " << coll << std::endl;
- } else {
- cerr << "Finished " << done << "/" << total << " collections" << "\r";
- r = fs->apply_layout_settings(coll, target_level);
- if (r < 0) {
- cerr << "Error applying layout settings to " << coll << std::endl;
- return r;
- }
- }
- ++done;
- }
-
- cerr << "Finished " << total << "/" << total << " collections" << "\r" << std::endl;
- return r;
-}
-
int main(int argc, char **argv)
{
string dpath, jpath, pgidstr, op, file, mountpoint, mon_store_path, object;
desc.add_options()
("help", "produce help message")
("type", po::value<string>(&type),
- "Arg is one of [bluestore (default), filestore, memstore]")
+ "Arg is one of [bluestore (default), memstore]")
("data-path", po::value<string>(&dpath),
"path to object store, mandatory")
("journal-path", po::value<string>(&jpath),
"path to journal, use if tool can't find it")
("pgid", po::value<string>(&pgidstr),
- "PG id, mandatory for info, log, remove, export, export-remove, mark-complete, trim-pg-log, trim-pg-log-dups and mandatory for apply-layout-settings if --pool is not specified")
+ "PG id, mandatory for info, log, remove, export, export-remove, mark-complete, trim-pg-log, trim-pg-log-dups")
("pool", po::value<string>(&pool),
- "Pool name, mandatory for apply-layout-settings if --pgid is not specified")
+ "Pool name")
("op", po::value<string>(&op),
- "Arg is one of [info, log, remove, mkfs, fsck, repair, fuse, dup, export, export-remove, import, list, list-slow-omap, fix-lost, list-pgs, dump-journal, dump-super, meta-list, "
- "get-osdmap, set-osdmap, get-inc-osdmap, set-inc-osdmap, mark-complete, reset-last-complete, apply-layout-settings, update-mon-db, dump-export, trim-pg-log, trim-pg-log-dups statfs]")
+ "Arg is one of [info, log, remove, mkfs, fsck, repair, fuse, dup, export, export-remove, import, list, list-slow-omap, fix-lost, list-pgs, dump-super, meta-list, "
+ "get-osdmap, set-osdmap, get-inc-osdmap, set-inc-osdmap, mark-complete, reset-last-complete, update-mon-db, dump-export, trim-pg-log, trim-pg-log-dups statfs]")
("epoch", po::value<unsigned>(&epoch),
"epoch# for get-osdmap and get-inc-osdmap, the current epoch in use if not specified")
("file", po::value<string>(&file),
}
::close(fd);
}
-
if (!vm.count("type") && type == "") {
type = "bluestore";
}
if (!vm.count("data-path") &&
- op != "dump-export" &&
- !(op == "dump-journal" && type == "filestore")) {
+ op != "dump-export") {
cerr << "Must provide --data-path" << std::endl;
usage(desc);
return 1;
}
- if (type == "filestore" && !vm.count("journal-path")) {
- jpath = dpath + "/journal";
- }
if (!vm.count("op") && !vm.count("object")) {
cerr << "Must provide --op or object command..." << std::endl;
usage(desc);
return 1;
}
- if (op != "list" && op != "apply-layout-settings" &&
- vm.count("op") && vm.count("object")) {
- cerr << "Can't specify both --op and object command syntax" << std::endl;
- usage(desc);
- return 1;
- }
- if (op == "apply-layout-settings" && !(vm.count("pool") ^ vm.count("pgid"))) {
- cerr << "apply-layout-settings requires either --pool or --pgid"
- << std::endl;
- usage(desc);
- return 1;
- }
- if (op != "list" && op != "apply-layout-settings" && vm.count("object") && !vm.count("objcmd")) {
- cerr << "Invalid syntax, missing command" << std::endl;
- usage(desc);
- return 1;
- }
if (op == "fuse" && mountpoint.length() == 0) {
cerr << "Missing fuse mountpoint" << std::endl;
usage(desc);
return 1;
}
- // Special handling for filestore journal, so we can dump it without mounting
- if (op == "dump-journal" && type == "filestore") {
- int ret = mydump_journal(formatter, jpath, g_conf()->journal_dio);
- if (ret < 0) {
- cerr << "journal-path: " << jpath << ": "
- << cpp_strerror(ret) << std::endl;
- return 1;
- }
- formatter->flush(cout);
- return 0;
- }
-
if (op == "dump-export") {
int ret = tool.dump_export(formatter);
if (ret < 0) {
return 1;
}
- //Verify that the journal-path really exists
- if (type == "filestore") {
- if (::stat(jpath.c_str(), &st) == -1) {
- string err = string("journal-path: ") + jpath;
- perror(err.c_str());
- return 1;
- }
- if (S_ISDIR(st.st_mode)) {
- cerr << "journal-path: " << jpath << ": "
- << cpp_strerror(EISDIR) << std::endl;
- return 1;
- }
- }
-
std::unique_ptr<ObjectStore> fs = ObjectStore::create(g_ceph_context, type, dpath, jpath, flags);
if (!fs) {
cerr << "Unable to create store of type " << type << std::endl;
}
}
- if (op == "apply-layout-settings") {
- int target_level = 0;
- // Single positional argument with apply-layout-settings
- // for target_level.
- if (vm.count("object") && isdigit(object[0])) {
- target_level = atoi(object.c_str());
- // This requires --arg1 to be specified since
- // this is the third positional argument and normally
- // used with object operations.
- } else if (vm.count("arg1") && isdigit(arg1[0])) {
- target_level = atoi(arg1.c_str());
- }
- ceph_assert(superblock != nullptr);
- ret = apply_layout_settings(fs.get(), *superblock, pool, pgid, dry_run, target_level);
- goto out;
- }
-
if (op != "list" && vm.count("object")) {
// Special case: Create pgmeta_oid if empty string specified
// This can't conflict with any actual object names.
// If not an object command nor any of the ops handled below, then output this usage
// before complaining about a bad pgid
if (!vm.count("objcmd") && op != "export" && op != "export-remove" && op != "info" && op != "log" && op != "mark-complete" && op != "trim-pg-log" && op != "trim-pg-log-dups" && op != "pg-log-inject-dups") {
- cerr << "Must provide --op (info, log, remove, mkfs, fsck, repair, export, export-remove, import, list, fix-lost, list-pgs, dump-journal, dump-super, meta-list, "
+ cerr << "Must provide --op (info, log, remove, mkfs, fsck, repair, export, export-remove, import, list, fix-lost, list-pgs, dump-super, meta-list, "
"get-osdmap, set-osdmap, get-inc-osdmap, set-inc-osdmap, mark-complete, reset-last-complete, dump-export, trim-pg-log, trim-pg-log-dups statfs)"
<< std::endl;
usage(desc);
if (debug) {
ostringstream ostr;
Formatter* f = Formatter::create("json-pretty", "json-pretty", "json-pretty");
- cct->get_perfcounters_collection()->dump_formatted(f, false);
+ cct->get_perfcounters_collection()->dump_formatted(f, false, false);
ostr << "ceph-objectstore-tool ";
f->flush(ostr);
delete f;