Skip to content

Commit

Permalink
tools: Add dump-headers command to ceph-osdomap-tool
Browse files Browse the repository at this point in the history
Signed-off-by: David Zafman <dzafman@redhat.com>
  • Loading branch information
dzafman committed Mar 27, 2017
1 parent 2d94889 commit f410159
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/os/filestore/DBObjectMap.cc
Expand Up @@ -1262,3 +1262,41 @@ int DBObjectMap::list_objects(vector<ghobject_t> *out)
}
return 0;
}

int DBObjectMap::list_object_headers(vector<_Header> *out)
{
int error = 0;
KeyValueDB::Iterator iter = db->get_iterator(HOBJECT_TO_SEQ);
for (iter->seek_to_first(); iter->valid(); iter->next()) {
bufferlist bl = iter->value();
bufferlist::iterator bliter = bl.begin();
_Header header;
header.decode(bliter);
out->push_back(header);
while (header.parent) {
set<string> to_get;
map<string, bufferlist> got;
to_get.insert(HEADER_KEY);
db->get(sys_parent_prefix(header), to_get, &got);
if (got.empty()) {
dout(0) << "Missing: seq " << header.parent << dendl;
error = -ENOENT;
break;
} else {
bl = got.begin()->second;
bufferlist::iterator bliter = bl.begin();
header.decode(bliter);
out->push_back(header);
}
}
}
return error;
}

ostream& operator<<(ostream& out, const DBObjectMap::_Header& h)
{
out << "seq=" << h.seq << " parent=" << h.parent
<< " num_children=" << h.num_children
<< " ghobject=" << h.oid;
return out;
}
7 changes: 7 additions & 0 deletions src/os/filestore/DBObjectMap.h
Expand Up @@ -222,6 +222,11 @@ class DBObjectMap : public ObjectMap {
int list_objects(vector<ghobject_t> *objs ///< [out] objects
);

struct _Header;
// Util, get all object headers, there must be no other concurrent access
int list_object_headers(vector<_Header> *out ///< [out] headers
);

ObjectMapIterator get_iterator(const ghobject_t &oid) override;

static const string USER_PREFIX;
Expand Down Expand Up @@ -533,4 +538,6 @@ class DBObjectMap : public ObjectMap {
WRITE_CLASS_ENCODER(DBObjectMap::_Header)
WRITE_CLASS_ENCODER(DBObjectMap::State)

ostream& operator<<(ostream& out, const DBObjectMap::_Header& h);

#endif
12 changes: 11 additions & 1 deletion src/tools/ceph_osdomap_tool.cc
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char **argv) {
("paranoid", "use paranoid checking")
("oid", po::value<string>(&oid), "Restrict to this object id when dumping objects")
("command", po::value<string>(&cmd),
"command arg is one of [dump-raw-keys, dump-raw-key-vals, dump-objects, dump-objects-with-keys, check], mandatory")
"command arg is one of [dump-raw-keys, dump-raw-key-vals, dump-objects, dump-objects-with-keys, check, dump-headers], mandatory")
;
po::positional_options_description p;
p.add("command", 1);
Expand Down Expand Up @@ -155,6 +155,16 @@ int main(int argc, char **argv) {
goto done;
}
std::cout << "check succeeded" << std::endl;
} else if (cmd == "dump-headers") {
vector<DBObjectMap::_Header> headers;
r = omap.list_object_headers(&headers);
if (r < 0) {
std::cerr << "list_object_headers got: " << cpp_strerror(r) << std::endl;
r = 1;
goto done;
}
for (auto i : headers)
std::cout << i << std::endl;
} else {
std::cerr << "Did not recognize command " << cmd << std::endl;
goto done;
Expand Down

0 comments on commit f410159

Please sign in to comment.