MDSDaemon *mds;
public:
explicit MDSSocketHook(MDSDaemon *m) : mds(m) {}
- int call(std::string_view command, const cmdmap_t& cmdmap,
- Formatter *f,
- std::ostream& ss,
- bufferlist& out) override {
- stringstream outss;
- int r = mds->asok_command(command, cmdmap, f, outss);
- out.append(outss);
- return r;
+ int call(
+ std::string_view command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
+ std::ostream& errss,
+ ceph::buffer::list& out) override {
+ ceph_abort("shoudl go to call_async");
+ }
+ void call_async(
+ std::string_view command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
+ const bufferlist& inbl,
+ std::function<void(int,const std::string&,bufferlist&)> on_finish) override {
+ mds->asok_command(command, cmdmap, f, inbl, on_finish);
}
};
-int MDSDaemon::asok_command(std::string_view command, const cmdmap_t& cmdmap,
- Formatter *f, std::ostream& ss)
+void MDSDaemon::asok_command(
+ std::string_view command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
+ const bufferlist& inbl,
+ std::function<void(int,const std::string&,bufferlist&)> on_finish)
{
- dout(1) << "asok_command: " << command << " (starting...)" << dendl;
+ dout(1) << "asok_command: " << command << " " << cmdmap
+ << " (starting...)" << dendl;
int r = -ENOSYS;
+ stringstream ss;
if (command == "status") {
dump_status(f);
r = 0;
f->dump_string("error", "mds_not_active");
} else {
try {
- r = mds_rank->handle_asok_command(command, cmdmap, f, ss);
+ mds_rank->handle_asok_command(command, cmdmap, f, inbl, on_finish);
+ return;
} catch (const bad_cmd_get& e) {
ss << e.what();
r = -EINVAL;
}
}
}
- dout(1) << "asok_command: " << command << " (complete)" << dendl;
- return r;
+ bufferlist outbl;
+ on_finish(r, ss.str(), outbl);
}
void MDSDaemon::dump_status(Formatter *f)
snapclient->handle_mds_failure(who);
}
-int MDSRankDispatcher::handle_asok_command(std::string_view command,
- const cmdmap_t& cmdmap,
- Formatter *f,
- std::ostream& ss)
-{
+void MDSRankDispatcher::handle_asok_command(
+ std::string_view command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
+ const bufferlist &inbl,
+ std::function<void(int,const std::string&,bufferlist&)> on_finish)
+{
+ int r = 0;
+ ostringstream ss;
+ bufferlist outbl;
if (command == "dump_ops_in_flight" ||
command == "ops") {
if (!op_tracker.dump_ops_in_flight(f)) {
if (!got_val) {
ss << "no target epoch given";
- return -EINVAL;
+ r = -EINVAL;
+ goto out;
}
{
std::lock_guard l(mds_lock);
const bool got_arg = cmd_getval(g_ceph_context, cmdmap, "client_id", client_id);
if(!got_arg) {
ss << "Invalid client_id specified";
- return -ENOENT;
+ r = -ENOENT;
+ goto out;
}
std::lock_guard l(mds_lock);
- std::stringstream dss;
bool evicted = evict_client(strtol(client_id.c_str(), 0, 10), true,
- g_conf()->mds_session_blacklist_on_evict, dss);
+ g_conf()->mds_session_blacklist_on_evict, ss);
if (!evicted) {
- dout(15) << dss.str() << dendl;
- ss << dss.str();
+ dout(15) << ss.str() << dendl;
+ r = -EBUSY;
}
} else if (command == "session config") {
int64_t client_id;
bool got_value = cmd_getval(g_ceph_context, cmdmap, "value", value);
std::lock_guard l(mds_lock);
- config_client(client_id, !got_value, option, value, ss);
+ r = config_client(client_id, !got_value, option, value, ss);
} else if (command == "scrub_path") {
string path;
vector<string> scrubop_vec;
string path;
if(!cmd_getval(g_ceph_context, cmdmap, "path", path)) {
ss << "malformed path";
- return -EINVAL;
+ r = -EINVAL;
+ goto out;
}
int64_t rank;
if(!cmd_getval(g_ceph_context, cmdmap, "rank", rank)) {
ss << "malformed rank";
- return -EINVAL;
+ r = -EINVAL;
+ goto out;
}
command_export_dir(f, path, (mds_rank_t)rank);
} else if (command == "dump cache") {
std::lock_guard l(mds_lock);
string path;
- int r;
- if(!cmd_getval(g_ceph_context, cmdmap, "path", path)) {
+ if (!cmd_getval(g_ceph_context, cmdmap, "path", path)) {
r = mdcache->dump_cache(f);
} else {
r = mdcache->dump_cache(path);
}
-
- if (r != 0) {
- ss << "Failed to dump cache: " << cpp_strerror(r);
- f->reset();
- }
} else if (command == "cache status") {
std::lock_guard l(mds_lock);
mdcache->cache_status(f);
command_dump_tree(cmdmap, ss, f);
} else if (command == "dump loads") {
std::lock_guard l(mds_lock);
- int r = balancer->dump_loads(f);
- if (r != 0) {
- ss << "Failed to dump loads: " << cpp_strerror(r);
- f->reset();
- }
+ r = balancer->dump_loads(f);
} else if (command == "dump snaps") {
std::lock_guard l(mds_lock);
string server;
if (mdsmap->get_tableserver() == whoami) {
snapserver->dump(f);
} else {
+ r = -EXDEV;
ss << "Not snapserver";
}
} else {
- int r = snapclient->dump_cache(f);
- if (r != 0) {
- ss << "Failed to dump snapclient: " << cpp_strerror(r);
- f->reset();
- }
+ r = snapclient->dump_cache(f);
}
} else if (command == "force_readonly") {
std::lock_guard l(mds_lock);
} else if (command == "dump inode") {
command_dump_inode(f, cmdmap, ss);
} else {
- return -ENOSYS;
+ r = -ENOSYS;
}
-
- return 0;
+out:
+ on_finish(r, ss.str(), outbl);
}
class C_MDS_Send_Command_Reply : public MDSInternalContext {