Skip to content

Commit 86bd353

Browse files
committed
os/bluestore: Add admin socket commands to inspect onode metadata
Add admin socket commands: 1) bluestore collections Lists collections. 2) bluestore list <coll> [start object] [max count] Lists collection coll starting from object (optional). Default 100 entries. 0 = unlimited. 3) bluestore onode metadata <object> Prints onode metadata as seen by BlueStore. It might happen (usually in tests) that 2 BlueStore instances are created at the same time. Since admin commands are unique, it fails to register. Use first register to detect whether we can register at all. Signed-off-by: Adam Kupczyk <[email protected]>
1 parent 4d6e7ac commit 86bd353

File tree

7 files changed

+192
-1
lines changed

7 files changed

+192
-1
lines changed

src/crimson/os/alienstore/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(alien_store_srcs
6262
${PROJECT_SOURCE_DIR}/src/os/bluestore/Writer.cc
6363
${PROJECT_SOURCE_DIR}/src/os/bluestore/Compression.cc
6464
${PROJECT_SOURCE_DIR}/src/os/bluestore/BlueStore_debug.cc
65+
${PROJECT_SOURCE_DIR}/src/os/bluestore/BlueAdmin.cc
6566
${PROJECT_SOURCE_DIR}/src/os/memstore/MemStore.cc)
6667

6768
add_library(crimson-alienstore STATIC

src/os/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if(WITH_BLUESTORE)
2828
bluestore/HybridAllocator.cc
2929
bluestore/Writer.cc
3030
bluestore/Compression.cc
31+
bluestore/BlueAdmin.cc
3132
)
3233
endif(WITH_BLUESTORE)
3334

src/os/bluestore/BlueAdmin.cc

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab
3+
4+
#include "BlueAdmin.h"
5+
#include "common/pretty_binary.h"
6+
#include "common/debug.h"
7+
#include <asm-generic/errno-base.h>
8+
#include <vector>
9+
#include <limits>
10+
11+
#define dout_subsys ceph_subsys_bluestore
12+
#define dout_context store.cct
13+
14+
using ceph::bufferlist;
15+
using ceph::Formatter;
16+
using ceph::common::cmd_getval;
17+
18+
BlueStore::SocketHook::SocketHook(BlueStore& store)
19+
: store(store)
20+
{
21+
AdminSocket *admin_socket = store.cct->get_admin_socket();
22+
if (admin_socket) {
23+
int r = admin_socket->register_command(
24+
"bluestore collections",
25+
this,
26+
"list all collections");
27+
if (r != 0) {
28+
dout(1) << __func__ << " cannot register SocketHook" << dendl;
29+
return;
30+
}
31+
r = admin_socket->register_command(
32+
"bluestore list "
33+
"name=collection,type=CephString,req=true "
34+
"name=start,type=CephString,req=false "
35+
"name=max,type=CephInt,req=false",
36+
this,
37+
"list objects in specific collection");
38+
ceph_assert(r == 0);
39+
r = admin_socket->register_command(
40+
"bluestore onode metadata "
41+
"name=object_name,type=CephString,req=true",
42+
this,
43+
"print object internals");
44+
ceph_assert(r == 0);
45+
}
46+
}
47+
48+
BlueStore::SocketHook::~SocketHook()
49+
{
50+
AdminSocket *admin_socket = store.cct->get_admin_socket();
51+
if (admin_socket) {
52+
admin_socket->unregister_commands(this);
53+
}
54+
}
55+
56+
int BlueStore::SocketHook::call(
57+
std::string_view command,
58+
const cmdmap_t& cmdmap,
59+
const bufferlist& inbl,
60+
Formatter *f,
61+
std::ostream& ss,
62+
bufferlist& out)
63+
{
64+
int r = 0;
65+
if (command == "bluestore collections") {
66+
std::vector<coll_t> collections;
67+
store.list_collections(collections);
68+
std::stringstream result;
69+
for (const auto& c : collections) {
70+
result << c << std::endl;
71+
}
72+
out.append(result.str());
73+
return 0;
74+
} else if (command == "bluestore list") {
75+
std::string coll;
76+
std::string start;
77+
int64_t max;
78+
cmd_getval(cmdmap, "collection", coll);
79+
cmd_getval(cmdmap, "start", start);
80+
if (!cmd_getval(cmdmap, "max", max)) {
81+
max = 100;
82+
}
83+
if (max == 0) {
84+
max = std::numeric_limits<int>::max();
85+
}
86+
coll_t c;
87+
if (c.parse(coll) == false) {
88+
ss << "Cannot parse collection" << std::endl;
89+
return -EINVAL;
90+
}
91+
BlueStore::CollectionRef col = store._get_collection(c);
92+
if (!col) {
93+
ss << "No such collection" << std::endl;
94+
return -ENOENT;
95+
}
96+
ghobject_t start_object;
97+
if (start.length() > 0) {
98+
if (start_object.parse(start) == false) {
99+
ss << "Cannot parse start object";
100+
return -EINVAL;
101+
}
102+
}
103+
std::vector<ghobject_t> list;
104+
{
105+
std::shared_lock l(col->lock);
106+
r = store._collection_list(col.get(), start_object, ghobject_t::get_max(),
107+
max, false, &list, nullptr);
108+
}
109+
if (r != 0) {
110+
return 0;
111+
}
112+
std::stringstream result;
113+
for (auto& obj : list) {
114+
result << obj << std::endl;
115+
}
116+
out.append(result.str());
117+
return 0;
118+
} else if (command == "bluestore onode metadata") {
119+
std::string object_name;
120+
cmd_getval(cmdmap, "object_name", object_name);
121+
ghobject_t object;
122+
if (!object.parse(object_name)) {
123+
ss << "Cannot parse object" << std::endl;
124+
return -EINVAL;
125+
}
126+
std::shared_lock l(store.coll_lock);
127+
for (const auto& cp : store.coll_map) {
128+
if (cp.second->contains(object)) {
129+
std::shared_lock l(cp.second->lock);
130+
OnodeRef o = cp.second->get_onode(object, false);
131+
if (!o || !o->exists) {
132+
ss << "Object not found" << std::endl;
133+
return -ENOENT;
134+
}
135+
o->extent_map.fault_range(store.db, 0, 0xffffffff);
136+
using P = BlueStore::printer;
137+
std::stringstream result;
138+
result << o->print(P::PTR + P::DISK + P::USE + P::BUF + P::CHK + P::ATTRS) << std::endl;
139+
out.append(result.str());
140+
return 0;
141+
}
142+
}
143+
r = -ENOENT;
144+
ss << "No collection that can hold such object" << std::endl;
145+
} else {
146+
ss << "Invalid command" << std::endl;
147+
r = -ENOSYS;
148+
}
149+
return r;
150+
}

src/os/bluestore/BlueAdmin.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab
3+
4+
#ifndef CEPH_OSD_BLUEADMIN_H
5+
#define CEPH_OSD_BLUEADMIN_H
6+
7+
8+
#include "BlueStore.h"
9+
#include "common/admin_socket.h"
10+
11+
using std::string;
12+
using std::to_string;
13+
14+
using ceph::bufferlist;
15+
using ceph::Formatter;
16+
17+
class BlueStore::SocketHook : public AdminSocketHook {
18+
BlueStore& store;
19+
20+
public:
21+
SocketHook(BlueStore& store);
22+
virtual ~SocketHook();
23+
int call(std::string_view command,
24+
const cmdmap_t& cmdmap,
25+
const bufferlist& inbl,
26+
Formatter *f,
27+
std::ostream& ss,
28+
bufferlist& out) override;
29+
};
30+
#endif

src/os/bluestore/BlueStore.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "kv/KeyValueHistogram.h"
6060
#include "Writer.h"
6161
#include "Compression.h"
62+
#include "BlueAdmin.h"
6263

6364
#if defined(WITH_LTTNG)
6465
#define TRACEPOINT_DEFINE
@@ -5673,10 +5674,13 @@ BlueStore::BlueStore(CephContext *cct,
56735674
cct->_conf.add_observer(this);
56745675
set_cache_shards(1);
56755676
bluestore_bdev_label_require_all = cct->_conf.get_val<bool>("bluestore_bdev_label_require_all");
5677+
asok_hook = new SocketHook(*this);
56765678
}
56775679

56785680
BlueStore::~BlueStore()
56795681
{
5682+
delete asok_hook;
5683+
asok_hook = nullptr;
56805684
cct->_conf.remove_observer(this);
56815685
_shutdown_logger();
56825686
ceph_assert(!mounted);

src/os/bluestore/BlueStore.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "bluestore_common.h"
5959
#include "BlueFS.h"
6060
#include "common/EventTrace.h"
61+
#include "common/admin_socket.h"
6162

6263
#ifdef WITH_BLKIN
6364
#include "common/zipkin_trace.h"
@@ -2531,6 +2532,10 @@ class BlueStore : public ObjectStore,
25312532

25322533
bool per_pool_stat_collection = true;
25332534

2535+
class SocketHook;
2536+
friend class SocketHook;
2537+
AdminSocketHook* asok_hook = nullptr;
2538+
25342539
struct MempoolThread : public Thread {
25352540
public:
25362541
BlueStore *store;

src/test/objectstore/store_test_fixture.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void StoreTestFixture::SetUp()
4141
cerr << __func__ << ": unable to create " << data_dir << ": " << cpp_strerror(r) << std::endl;
4242
}
4343
ASSERT_EQ(0, r);
44-
44+
store.reset(nullptr);
4545
store = ObjectStore::create(g_ceph_context,
4646
type,
4747
data_dir,

0 commit comments

Comments
 (0)