mirror of
https://github.com/ceph/ceph
synced 2025-04-07 18:17:22 +00:00
class: can use ceph utility to add classes
e.g. ./ceph class add foo 1 --in-data=foo.so
This commit is contained in:
parent
041e417aef
commit
a9c98e0242
@ -569,6 +569,7 @@ int main(int argc, const char **argv, const char *envp[])
|
|||||||
|
|
||||||
bufferlist indata;
|
bufferlist indata;
|
||||||
vector<const char*> nargs;
|
vector<const char*> nargs;
|
||||||
|
|
||||||
FOR_EACH_ARG(args) {
|
FOR_EACH_ARG(args) {
|
||||||
if (CONF_ARG_EQ("out_file", 'o')) {
|
if (CONF_ARG_EQ("out_file", 'o')) {
|
||||||
CONF_SAFE_SET_ARG_VAL(&outfile, OPT_STR);
|
CONF_SAFE_SET_ARG_VAL(&outfile, OPT_STR);
|
||||||
|
@ -77,7 +77,6 @@ void ClassMonitor::create_initial(bufferlist& bl)
|
|||||||
::encode(i, inc.impl);
|
::encode(i, inc.impl);
|
||||||
::encode(l, inc.info);
|
::encode(l, inc.info);
|
||||||
inc.add = true;
|
inc.add = true;
|
||||||
|
|
||||||
pending_class.insert(pair<utime_t,ClassLibraryIncremental>(i.stamp, inc));
|
pending_class.insert(pair<utime_t,ClassLibraryIncremental>(i.stamp, inc));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +85,9 @@ bool ClassMonitor::store_impl(ClassLibrary& info, ClassImpl& impl)
|
|||||||
char *store_name;
|
char *store_name;
|
||||||
int len = info.name.length() + 16;
|
int len = info.name.length() + 16;
|
||||||
store_name = (char *)malloc(len);
|
store_name = (char *)malloc(len);
|
||||||
|
if (!store_name)
|
||||||
|
return false;
|
||||||
|
|
||||||
snprintf(store_name, len, "%s.%d", info.name.c_str(), (int)info.version);
|
snprintf(store_name, len, "%s.%d", info.name.c_str(), (int)info.version);
|
||||||
dout(0) << "storing inc.impl length=" << impl.binary.length() << dendl;
|
dout(0) << "storing inc.impl length=" << impl.binary.length() << dendl;
|
||||||
mon->store->put_bl_ss(impl.binary, "class_impl", store_name);
|
mon->store->put_bl_ss(impl.binary, "class_impl", store_name);
|
||||||
@ -94,6 +96,8 @@ bool ClassMonitor::store_impl(ClassLibrary& info, ClassImpl& impl)
|
|||||||
mon->store->append_bl_ss(bl, "class_impl", store_name);
|
mon->store->append_bl_ss(bl, "class_impl", store_name);
|
||||||
dout(0) << "adding name=" << info.name << " version=" << info.version << " store_name=" << store_name << dendl;
|
dout(0) << "adding name=" << info.name << " version=" << info.version << " store_name=" << store_name << dendl;
|
||||||
free(store_name);
|
free(store_name);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -264,6 +268,14 @@ bool ClassMonitor::preprocess_command(MMonCommand *m)
|
|||||||
bufferlist rdata;
|
bufferlist rdata;
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
|
if (m->cmd.size() > 1) {
|
||||||
|
if ((m->cmd[1] == "add" || m->cmd[1] == "del")) {
|
||||||
|
if (m->cmd.size() != 4) {
|
||||||
|
ss << "error: usage: ceph <add | set> <name> <version> <-i filename>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (r != -1) {
|
if (r != -1) {
|
||||||
string rs;
|
string rs;
|
||||||
getline(ss, rs);
|
getline(ss, rs);
|
||||||
@ -281,8 +293,35 @@ bool ClassMonitor::prepare_command(MMonCommand *m)
|
|||||||
int err = -EINVAL;
|
int err = -EINVAL;
|
||||||
|
|
||||||
// nothing here yet
|
// nothing here yet
|
||||||
ss << "unrecognized command";
|
if (m->cmd.size() > 1) {
|
||||||
|
if ((m->cmd[1] == "add" || m->cmd[1] == "del") &&
|
||||||
|
m->cmd.size() >= 4) {
|
||||||
|
string name = m->cmd[2];
|
||||||
|
version_t ver = atoi(m->cmd[3].c_str());
|
||||||
|
ClassLibrary& info = list.library_map[name];
|
||||||
|
ClassImpl impl;
|
||||||
|
impl.binary = m->get_data();
|
||||||
|
dout(0) << "payload.length=" << m->get_data().length() << dendl;
|
||||||
|
impl.stamp = g_clock.now();
|
||||||
|
info.name = name;
|
||||||
|
info.version = ver;
|
||||||
|
/* store_impl(info, impl); */
|
||||||
|
dout(0) << "stored class " << name << " v" << ver << dendl;
|
||||||
|
ClassLibraryIncremental inc;
|
||||||
|
::encode(impl, inc.impl);
|
||||||
|
::encode(info, inc.info);
|
||||||
|
inc.add = (m->cmd[1] == "add");
|
||||||
|
pending_list.add(info);
|
||||||
|
pending_class.insert(pair<utime_t,ClassLibraryIncremental>(impl.stamp, inc));
|
||||||
|
|
||||||
|
ss << "updated";
|
||||||
|
getline(ss, rs);
|
||||||
|
paxos->wait_for_commit(new C_ClassMonCmd(mon, m, rs));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ss << "unrecognized command.";
|
||||||
getline(ss, rs);
|
getline(ss, rs);
|
||||||
mon->reply_command(m, err, rs);
|
mon->reply_command(m, err, rs);
|
||||||
return false;
|
return false;
|
||||||
@ -326,6 +365,7 @@ void ClassMonitor::handle_request(MClass *m)
|
|||||||
break;
|
break;
|
||||||
case CLASS_SET:
|
case CLASS_SET:
|
||||||
{
|
{
|
||||||
|
dout(0) << "ClassMonitor::handle_request() CLASS_SET" << dendl;
|
||||||
/* FIXME should handle entries removal */
|
/* FIXME should handle entries removal */
|
||||||
ClassLibrary& entry = list.library_map[(*p).name];
|
ClassLibrary& entry = list.library_map[(*p).name];
|
||||||
entry.name = (*p).name;
|
entry.name = (*p).name;
|
||||||
|
@ -22,6 +22,7 @@ using namespace std;
|
|||||||
#include "include/types.h"
|
#include "include/types.h"
|
||||||
#include "msg/Messenger.h"
|
#include "msg/Messenger.h"
|
||||||
#include "PaxosService.h"
|
#include "PaxosService.h"
|
||||||
|
#include "mon/Monitor.h"
|
||||||
|
|
||||||
#include "include/ClassEntry.h"
|
#include "include/ClassEntry.h"
|
||||||
|
|
||||||
@ -56,6 +57,16 @@ private:
|
|||||||
classmon->_updated_class(ack, who);
|
classmon->_updated_class(ack, who);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
struct C_ClassMonCmd : public Context {
|
||||||
|
Monitor *mon;
|
||||||
|
MMonCommand *m;
|
||||||
|
string rs;
|
||||||
|
C_ClassMonCmd(Monitor *monitor, MMonCommand *m_, string& s) :
|
||||||
|
mon(monitor), m(m_), rs(s) {}
|
||||||
|
void finish(int r) {
|
||||||
|
mon->reply_command(m, 0, rs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
bool preprocess_command(MMonCommand *m);
|
bool preprocess_command(MMonCommand *m);
|
||||||
bool prepare_command(MMonCommand *m);
|
bool prepare_command(MMonCommand *m);
|
||||||
|
@ -228,6 +228,7 @@ void Monitor::handle_command(MMonCommand *m)
|
|||||||
string rs;
|
string rs;
|
||||||
int r = -EINVAL;
|
int r = -EINVAL;
|
||||||
if (!m->cmd.empty()) {
|
if (!m->cmd.empty()) {
|
||||||
|
dout(0) << "m->cmd[0]=" << m->cmd[0] << dendl;
|
||||||
if (m->cmd[0] == "mds") {
|
if (m->cmd[0] == "mds") {
|
||||||
mdsmon()->dispatch(m);
|
mdsmon()->dispatch(m);
|
||||||
return;
|
return;
|
||||||
@ -259,6 +260,10 @@ void Monitor::handle_command(MMonCommand *m)
|
|||||||
parse_config_option_string(m->cmd[1]);
|
parse_config_option_string(m->cmd[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (m->cmd[0] == "class") {
|
||||||
|
classmon()->dispatch(m);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (m->cmd[0] == "mon") {
|
if (m->cmd[0] == "mon") {
|
||||||
if (m->cmd[1] == "injectargs" && m->cmd.size() == 4) {
|
if (m->cmd[1] == "injectargs" && m->cmd.size() == 4) {
|
||||||
vector<string> args(2);
|
vector<string> args(2);
|
||||||
@ -591,7 +596,7 @@ void Monitor::handle_class(MClass *m)
|
|||||||
switch (m->action) {
|
switch (m->action) {
|
||||||
case CLASS_SET:
|
case CLASS_SET:
|
||||||
case CLASS_GET:
|
case CLASS_GET:
|
||||||
((ClassMonitor *)paxos_service[PAXOS_CLASS])->handle_request(m);
|
classmon()->handle_request(m);
|
||||||
break;
|
break;
|
||||||
case CLASS_RESPONSE:
|
case CLASS_RESPONSE:
|
||||||
dout(0) << "got a class response (" << *m << ") ???" << dendl;
|
dout(0) << "got a class response (" << *m << ") ???" << dendl;
|
||||||
|
@ -115,6 +115,7 @@ public:
|
|||||||
class MDSMonitor *mdsmon() { return (class MDSMonitor *)paxos_service[PAXOS_MDSMAP]; }
|
class MDSMonitor *mdsmon() { return (class MDSMonitor *)paxos_service[PAXOS_MDSMAP]; }
|
||||||
class OSDMonitor *osdmon() { return (class OSDMonitor *)paxos_service[PAXOS_OSDMAP]; }
|
class OSDMonitor *osdmon() { return (class OSDMonitor *)paxos_service[PAXOS_OSDMAP]; }
|
||||||
class ClientMonitor *clientmon() { return (class ClientMonitor *)paxos_service[PAXOS_CLIENTMAP]; }
|
class ClientMonitor *clientmon() { return (class ClientMonitor *)paxos_service[PAXOS_CLIENTMAP]; }
|
||||||
|
class ClassMonitor *classmon() { return (class ClassMonitor *)paxos_service[PAXOS_CLASS]; }
|
||||||
|
|
||||||
friend class Paxos;
|
friend class Paxos;
|
||||||
friend class OSDMonitor;
|
friend class OSDMonitor;
|
||||||
|
Loading…
Reference in New Issue
Block a user