}
std::vector<std::string> cmdvec = { c };
- bufferlist out;
- string rs;
- int rval = 0;
-
- bool done = false;
- ceph::mutex mylock = ceph::make_mutex("admin_socket::do_accept::mylock");
- ceph::condition_variable mycond;
- C_SafeCond fin(mylock, mycond, &done, &rval);
- bufferlist empty;
- execute_command(
- cmdvec,
- empty /* inbl */,
- [&rs, &out, &fin](int r, const std::string& err, bufferlist& outbl) {
- rs = err;
- out.claim(outbl);
- fin.finish(r);
- });
- {
- std::unique_lock l{mylock};
- mycond.wait(l, [&done] { return done;});
- }
+ bufferlist empty, out;
+ ostringstream err;
+ int rval = execute_command(cmdvec, empty /* inbl */, err, &out);
// Unfortunately, the asok wire protocol does not let us pass an error code,
// and many asok command implementations return helpful error strings. So,
}
}
+int AdminSocket::execute_command(
+ const std::vector<std::string>& cmd,
+ const bufferlist& inbl,
+ std::ostream& errss,
+ bufferlist *outbl)
+{
+ bool done = false;
+ int rval = 0;
+ ceph::mutex mylock = ceph::make_mutex("admin_socket::excute_command::mylock");
+ ceph::condition_variable mycond;
+ C_SafeCond fin(mylock, mycond, &done, &rval);
+ execute_command(
+ cmd,
+ inbl,
+ [&errss, outbl, &fin](int r, const std::string& err, bufferlist& out) {
+ errss << err;
+ outbl->claim(out);
+ fin.finish(r);
+ });
+ {
+ std::unique_lock l{mylock};
+ mycond.wait(l, [&done] { return done;});
+ }
+ return rval;
+}
+
void AdminSocket::execute_command(
const std::vector<std::string>& cmdvec,
const bufferlist& inbl,
void chown(uid_t uid, gid_t gid);
void chmod(mode_t mode);
+
+ /// execute (async)
void execute_command(
const std::vector<std::string>& cmd,
const bufferlist& inbl,
std::function<void(int,const std::string&,bufferlist&)> on_fin);
+ /// execute (blocking)
+ int execute_command(
+ const std::vector<std::string>& cmd,
+ const bufferlist& inbl,
+ std::ostream& errss,
+ bufferlist *outbl);
+
void queue_tell_command(ref_t<MCommand> m);
private:
}
for (auto alloc_name : allocs_name) {
- ceph::bufferlist out;
+ ceph::bufferlist in, out;
+ ostringstream err;
bool b = admin_socket->execute_command(
- {"{\"prefix\": \"bluestore allocator " + action_name + " " + alloc_name + "\"}"}, out);
+ {"{\"prefix\": \"bluestore allocator " + action_name + " " + alloc_name + "\"}"},
+ in, err, &out);
if (!b) {
cerr << "failure querying '" << alloc_name << "'" << std::endl;
exit(EXIT_FAILURE);