class: can use ceph utility to add classes

e.g. ./ceph class add foo 1 --in-data=foo.so
This commit is contained in:
Yehuda Sadeh 2009-05-14 12:55:45 -07:00
parent 041e417aef
commit a9c98e0242
5 changed files with 61 additions and 3 deletions

View File

@ -569,6 +569,7 @@ int main(int argc, const char **argv, const char *envp[])
bufferlist indata;
vector<const char*> nargs;
FOR_EACH_ARG(args) {
if (CONF_ARG_EQ("out_file", 'o')) {
CONF_SAFE_SET_ARG_VAL(&outfile, OPT_STR);

View File

@ -77,7 +77,6 @@ void ClassMonitor::create_initial(bufferlist& bl)
::encode(i, inc.impl);
::encode(l, inc.info);
inc.add = true;
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;
int len = info.name.length() + 16;
store_name = (char *)malloc(len);
if (!store_name)
return false;
snprintf(store_name, len, "%s.%d", info.name.c_str(), (int)info.version);
dout(0) << "storing inc.impl length=" << impl.binary.length() << dendl;
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);
dout(0) << "adding name=" << info.name << " version=" << info.version << " store_name=" << store_name << dendl;
free(store_name);
return true;
}
@ -264,6 +268,14 @@ bool ClassMonitor::preprocess_command(MMonCommand *m)
bufferlist rdata;
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) {
string rs;
getline(ss, rs);
@ -281,8 +293,35 @@ bool ClassMonitor::prepare_command(MMonCommand *m)
int err = -EINVAL;
// 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);
mon->reply_command(m, err, rs);
return false;
@ -326,6 +365,7 @@ void ClassMonitor::handle_request(MClass *m)
break;
case CLASS_SET:
{
dout(0) << "ClassMonitor::handle_request() CLASS_SET" << dendl;
/* FIXME should handle entries removal */
ClassLibrary& entry = list.library_map[(*p).name];
entry.name = (*p).name;

View File

@ -22,6 +22,7 @@ using namespace std;
#include "include/types.h"
#include "msg/Messenger.h"
#include "PaxosService.h"
#include "mon/Monitor.h"
#include "include/ClassEntry.h"
@ -56,6 +57,16 @@ private:
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 prepare_command(MMonCommand *m);

View File

@ -228,6 +228,7 @@ void Monitor::handle_command(MMonCommand *m)
string rs;
int r = -EINVAL;
if (!m->cmd.empty()) {
dout(0) << "m->cmd[0]=" << m->cmd[0] << dendl;
if (m->cmd[0] == "mds") {
mdsmon()->dispatch(m);
return;
@ -259,6 +260,10 @@ void Monitor::handle_command(MMonCommand *m)
parse_config_option_string(m->cmd[1]);
return;
}
if (m->cmd[0] == "class") {
classmon()->dispatch(m);
return;
}
if (m->cmd[0] == "mon") {
if (m->cmd[1] == "injectargs" && m->cmd.size() == 4) {
vector<string> args(2);
@ -591,7 +596,7 @@ void Monitor::handle_class(MClass *m)
switch (m->action) {
case CLASS_SET:
case CLASS_GET:
((ClassMonitor *)paxos_service[PAXOS_CLASS])->handle_request(m);
classmon()->handle_request(m);
break;
case CLASS_RESPONSE:
dout(0) << "got a class response (" << *m << ") ???" << dendl;

View File

@ -115,6 +115,7 @@ public:
class MDSMonitor *mdsmon() { return (class MDSMonitor *)paxos_service[PAXOS_MDSMAP]; }
class OSDMonitor *osdmon() { return (class OSDMonitor *)paxos_service[PAXOS_OSDMAP]; }
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 OSDMonitor;