From 02115141ad865eaea46c7f07f59d08f2711c7447 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 13 Sep 2019 08:45:13 -0500 Subject: [PATCH] common/ceph_context: return error code from asok commands Several of these commands (config set, injectargs, etc.) can return errors. Do so. Signed-off-by: Sage Weil --- src/common/ceph_context.cc | 13 +++++++------ src/common/ceph_context.h | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 7cddc4e3b6e20..4437f034a4bf0 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -441,19 +441,19 @@ public: int call(std::string_view command, const cmdmap_t& cmdmap, std::string_view format, bufferlist& out) override { try { - m_cct->do_command(command, cmdmap, format, &out); + return m_cct->do_command(command, cmdmap, format, &out); } catch (const bad_cmd_get& e) { return -EINVAL; } - return 0; } }; -void CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap, +int CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap, std::string_view format, bufferlist *out) { Formatter *f = Formatter::create(format, "json-pretty", "json-pretty"); stringstream ss; + int r = 0; for (auto it = cmdmap.begin(); it != cmdmap.end(); ++it) { if (it->first != "prefix") { ss << it->first << ":" << cmd_vartype_stringify(it->second) << " "; @@ -514,7 +514,7 @@ void CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap, if (!(cmd_getval(this, cmdmap, "var", var))) { f->dump_string("error", "syntax error: 'config unset '"); } else { - int r = _conf.rm_val(var.c_str()); + r = _conf.rm_val(var.c_str()); if (r < 0 && r != -ENOENT) { f->dump_stream("error") << "error unsetting '" << var << "': " << cpp_strerror(r); @@ -536,7 +536,7 @@ void CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap, } else { // val may be multiple words string valstr = str_join(val, " "); - int r = _conf.set_val(var.c_str(), valstr.c_str()); + r = _conf.set_val(var.c_str(), valstr.c_str()); if (r < 0) { f->dump_stream("error") << "error setting '" << var << "' to '" << valstr << "': " << cpp_strerror(r); } else { @@ -553,7 +553,7 @@ void CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap, char buf[4096]; memset(buf, 0, sizeof(buf)); char *tmp = buf; - int r = _conf.get_val(var.c_str(), &tmp, sizeof(buf)); + r = _conf.get_val(var.c_str(), &tmp, sizeof(buf)); if (r < 0) { f->dump_stream("error") << "error getting '" << var << "': " << cpp_strerror(r); } else { @@ -619,6 +619,7 @@ void CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap, delete f; lgeneric_dout(this, 1) << "do_command '" << command << "' '" << ss.str() << "result is " << out->length() << " bytes" << dendl; + return r; } CephContext::CephContext(uint32_t module_type_, diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index 7203452fb1703..733efeebc9adb 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -161,8 +161,8 @@ public: /** * process an admin socket command */ - void do_command(std::string_view command, const cmdmap_t& cmdmap, - std::string_view format, ceph::bufferlist *out); + int do_command(std::string_view command, const cmdmap_t& cmdmap, + std::string_view format, ceph::bufferlist *out); static constexpr std::size_t largest_singleton = 8 * 72; -- 2.39.5