From 84f5ba5a55b2cf6fc42f4b55aa70e1caf14f8ab9 Mon Sep 17 00:00:00 2001 From: sage Date: Fri, 9 Jul 2004 18:40:50 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@19 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/Client.cc | 74 ++++++++++++++++++++++++++++++++++ ceph/MDS.cc | 55 +++++++++++++++++++++---- ceph/Makefile | 2 +- ceph/include/Client.h | 38 +++++++++++++++++ ceph/include/MDS.h | 43 +++++++++++++++----- ceph/messages/MClientReply.h | 20 +++++++++ ceph/messages/MClientRequest.h | 20 +++++++++ ceph/msg/FakeMessenger.cc | 2 +- ceph/msg/Message.h | 8 ++-- ceph/test/fakemds.cc | 37 ++++++++++++++--- 10 files changed, 270 insertions(+), 29 deletions(-) create mode 100644 ceph/Client.cc create mode 100644 ceph/include/Client.h create mode 100644 ceph/messages/MClientReply.h create mode 100644 ceph/messages/MClientRequest.h diff --git a/ceph/Client.cc b/ceph/Client.cc new file mode 100644 index 0000000000000..d5522cd22ae97 --- /dev/null +++ b/ceph/Client.cc @@ -0,0 +1,74 @@ + +#include "include/types.h" +#include "include/Client.h" +#include "include/Messenger.h" +#include "include/Message.h" + +#include "include/MDS.h" +#include "include/MDCache.h" + +#include "messages/MClientRequest.h" + +Client::Client(int id, Messenger *m) +{ + whoami = id; + messenger = m; + cwd = 0; + mdcache = new DentryCache(); + tid = 0; +} + +Client::~Client() +{ + if (messenger) { delete messenger; messenger = 0; } + if (mdcache) { delete mdcache; mdcache = 0; } +} + +int Client::init() +{ + messenger->set_dispatcher(this); + return 0; +} + +int Client::shutdown() +{ + mdcache->clear(); + messenger->shutdown(); + return 0; +} + + + +// dispatch + +void Client::dispatch(Message *m) +{ + switch (m->get_type()) { + case MSG_OSD_READREPLY: + case MSG_OSD_WRITEREPLY: + //assim_response(m); + + issue_request(); + break; + + default: + cout << "client" << whoami << " got unknown message " << m->get_type() << endl; + } +} + + +/*void Client::assim_response() +{ + +} +*/ + + +void Client::issue_request() +{ + MClientRequest *req = new MClientRequest(tid++, MDS_OP_STAT); + req->ino = 1; + messenger->send_message(req, + MSG_ADDR_MDS(0), MDS_PORT_SERVER, + 0); +} diff --git a/ceph/MDS.cc b/ceph/MDS.cc index 8b549ccda7c91..301ab7be9dfa1 100644 --- a/ceph/MDS.cc +++ b/ceph/MDS.cc @@ -7,11 +7,14 @@ #include "include/MDLog.h" #include "messages/MPing.h" + #include "messages/MOSDRead.h" #include "messages/MOSDWrite.h" #include "messages/MOSDReadReply.h" #include "messages/MOSDWriteReply.h" +#include "messages/MClientRequest.h" + #include #include @@ -23,7 +26,7 @@ using namespace std; // cons/des MDS::MDS(int id, int num, Messenger *m) { - nodeid = id; + whoami = id; num_nodes = num; mdcache = new DentryCache(); @@ -58,12 +61,13 @@ int MDS::shutdown() void MDS::proc_message(Message *m) { - cout << "mds::proc_message has " << m->get_type() << endl; + switch (m->get_type()) { + // MISC case MSG_PING: - cout << nodeid << " received ping from " << m->get_source() << " with ttl " << ((MPing*)m)->ttl << endl; + cout << "mds" << whoami << " received ping from " << m->get_source() << " with ttl " << ((MPing*)m)->ttl << endl; if (((MPing*)m)->ttl > 0) { - cout << nodeid << " responding to " << m->get_source() << endl; + //cout << "mds" << whoami << " responding to " << m->get_source() << endl; messenger->send_message(new MPing(((MPing*)m)->ttl-1), m->get_source(), m->get_source_port(), MDS_PORT_MAIN); @@ -71,20 +75,24 @@ void MDS::proc_message(Message *m) break; + // CLIENTS + case MSG_CLIENT_REQUEST: + handle_client_request((MClientRequest*)m); + break; // OSD I/O case MSG_OSD_READREPLY: - cout << "read reply!" << endl; + cout << "mds" << whoami << " read reply!" << endl; osd_read_finish(m); break; case MSG_OSD_WRITEREPLY: - cout << "write reply!" << endl; + cout << "mds" << whoami << " write reply!" << endl; osd_write_finish(m); break; default: - cout << "implement MDS::proc_message" << endl; + cout << "mds" << whoami << " unknown message " << m->get_type() << endl; } } @@ -109,6 +117,7 @@ void MDS::dispatch(Message *m) */ case MDS_PORT_MAIN: + case MDS_PORT_SERVER: proc_message(m); break; @@ -120,6 +129,36 @@ void MDS::dispatch(Message *m) + +// Client fun + +int MDS::handle_client_request(MClientRequest *req) +{ + cout << "mds" << whoami << " got client request from " << req->get_source() << ", op " << req->op << endl; + + + +} + + + + + + + + + + + + + + + + + + +// OSD fun + int MDS::osd_read(int osd, object_t oid, size_t len, size_t offset, char **bufptr, size_t *read, Context *c) { osd_last_tid++; @@ -255,7 +294,7 @@ public: bool MDS::open_root(Context *c) { // open root inode - if (nodeid == 0) { + if (whoami == 0) { // i am root CInode *root = new CInode(); root->inode.ino = 1; diff --git a/ceph/Makefile b/ceph/Makefile index 8bc10d3e13618..08f1bc6a20f76 100644 --- a/ceph/Makefile +++ b/ceph/Makefile @@ -3,7 +3,7 @@ CC=g++ CFLAGS=-D __gnu_cxx=std -g SRCS=*.cc -OBJS=CDentry.o CDir.o CInode.o MDCache.o MDStore.o clock.o MDS.o FakeMessenger.o LogStream.o MDLog.o OSD.o +OBJS=CDentry.o CDir.o CInode.o MDCache.o MDStore.o clock.o MDS.o FakeMessenger.o LogStream.o MDLog.o OSD.o Client.o TARGETS=test import all: depend ${TARGETS} diff --git a/ceph/include/Client.h b/ceph/include/Client.h new file mode 100644 index 0000000000000..6ebbd0b1c6d9d --- /dev/null +++ b/ceph/include/Client.h @@ -0,0 +1,38 @@ +#ifndef __CLIENT_H +#define __CLIENT_H + +#include "Dispatcher.h" + +class Messenger; +class Message; + +class DentryCache; +class CInode; + +class Client : public Dispatcher { + protected: + Messenger *messenger; + int whoami; + + DentryCache *mdcache; + + CInode *cwd; + + long tid; + + public: + Client(int id, Messenger *m); + ~Client(); + + int init(); + int shutdown(); + + virtual void dispatch(Message *m); + + virtual void issue_request(); + +}; + + + +#endif diff --git a/ceph/include/MDS.h b/ceph/include/MDS.h index 47981d618d765..b06f77e9be64d 100644 --- a/ceph/include/MDS.h +++ b/ceph/include/MDS.h @@ -9,21 +9,36 @@ #include "Context.h" #include "Dispatcher.h" -class CInode; -class DentryCache; -class MDStore; -class MDLog; -class Messenger; -class Message; typedef __uint64_t object_t; using namespace std; -#define MDS_PORT_MAIN 1 -#define MDS_PORT_STORE 10 +#define MDS_PORT_MAIN 1 +#define MDS_PORT_SERVER 5 +#define MDS_PORT_STORE 10 + +// md ops +#define MDS_OP_STAT 100 +#define MDS_OP_READDIR 101 + +#define MDS_OP_OPEN 111 +#define MDS_OP_CLOSE 112 + +#define MDS_OP_RENAME 121 +#define MDS_OP_UNLINK 122 +#define MDS_OP_LINK 123 + + +class CInode; +class DentryCache; +class MDStore; +class MDLog; +class Messenger; +class Message; +class MClientRequest; // @@ -37,7 +52,7 @@ typedef struct { class MDS : public Dispatcher { protected: - int nodeid; + int whoami; int num_nodes; // import/export @@ -69,7 +84,7 @@ class MDS : public Dispatcher { ~MDS(); int get_nodeid() { - return nodeid; + return whoami; } int init(); @@ -81,6 +96,14 @@ class MDS : public Dispatcher { bool open_root(Context *c); bool open_root_2(int result, Context *c); + + // client fun + int handle_client_request(MClientRequest *m); + + int do_stat(MClientRequest *m); + + + // osd fun int osd_read(int osd, object_t oid, size_t len, size_t offset, char *bufptr, size_t *bytesread, Context *c); int osd_read(int osd, object_t oid, size_t len, size_t offset, char **bufptr, size_t *bytesread, Context *c); diff --git a/ceph/messages/MClientReply.h b/ceph/messages/MClientReply.h new file mode 100644 index 0000000000000..8e84e43faa3a9 --- /dev/null +++ b/ceph/messages/MClientReply.h @@ -0,0 +1,20 @@ +#ifndef __MCLIENTREPLY_H +#define __MCLIENTREPLY_H + +#include "../include/Message.h" + +class MClientReply : public Message { + public: + long tid; + int op; + + // reply data + + + MClientReply(MClientRequest *req) : Message(MSG_CLIENT_REQUEST) { + this->tid = req->tid; + this->op = req->mop; + } +}; + +#endif diff --git a/ceph/messages/MClientRequest.h b/ceph/messages/MClientRequest.h new file mode 100644 index 0000000000000..7bb70f7b03df7 --- /dev/null +++ b/ceph/messages/MClientRequest.h @@ -0,0 +1,20 @@ +#ifndef __MCLIENTREQUEST_H +#define __MCLIENTREQUEST_H + +#include "../include/Message.h" + +class MClientRequest : public Message { + public: + long tid; + int op; + + inodeno_t ino; + string path; + + MClientRequest(long tid, int mop) : Message(MSG_CLIENT_REQUEST) { + this->tid = tid; + this->op = mop; + } +}; + +#endif diff --git a/ceph/msg/FakeMessenger.cc b/ceph/msg/FakeMessenger.cc index c7a7679798f82..3959004849236 100644 --- a/ceph/msg/FakeMessenger.cc +++ b/ceph/msg/FakeMessenger.cc @@ -25,7 +25,7 @@ int fakemessenger_do_loop() while (it != directory.end()) { Message *m = it->second->get_message(); if (m) { - cout << "do_loop dispatching t " << m->get_type() << " for " << m->get_dest() << ':' << m->get_dest_port() << " from " << m->get_source() << ':' << m->get_source_port() << endl; + cout << "---- do_loop dispatching t " << m->get_type() << " for " << m->get_dest() << ':' << m->get_dest_port() << " from " << m->get_source() << ':' << m->get_source_port() << " ----" << endl; didone = true; it->second->dispatch(m); } diff --git a/ceph/msg/Message.h b/ceph/msg/Message.h index b90fa6b6b3e97..25af7d0271fef 100644 --- a/ceph/msg/Message.h +++ b/ceph/msg/Message.h @@ -11,10 +11,10 @@ #define MSG_OSD_WRITE 12 #define MSG_OSD_WRITEREPLY 13 -#define MSG_SUBSYS_SERVER 1 -#define MSG_SUBSYS_BALANCER 2 -#define MSG_SUBSYS_MDSTORE 3 -#define MSG_SUBSYS_MDLOG 4 +#define MSG_CLIENT_REQUEST 20 +#define MSG_CLIENT_REPLY 21 + +#define MSG_MDS_HEARTBEAT 30 #define MSG_ADDR_MDS(x) (x) diff --git a/ceph/test/fakemds.cc b/ceph/test/fakemds.cc index bba222c4e48ec..577cf4174f5a5 100644 --- a/ceph/test/fakemds.cc +++ b/ceph/test/fakemds.cc @@ -6,6 +6,8 @@ #include "include/MDS.h" #include "include/OSD.h" +#include "include/Client.h" + #include "include/MDCache.h" #include "include/MDStore.h" #include "include/FakeMessenger.h" @@ -17,6 +19,11 @@ using namespace std; __uint64_t ino = 1; +#define NUMMDSS 10 +#define NUMOSDS 10 +#define NUMCLIENTS 10 + + // this parses find output int play(); @@ -32,12 +39,12 @@ int main(char **argv, int argc) { } int play() { - cout << "hello" << endl; + cout << "creating stuff" << endl; // init // create mds MDS *mds[10]; - for (int i=0; i<10; i++) { + for (int i=0; iopen_root(NULL); mds[i]->init(); @@ -45,29 +52,41 @@ int play() { // create osds OSD *osd[10]; - for (int i=0; i<10; i++) { + for (int i=0; iinit(); } + // create clients + Client *client[NUMCLIENTS]; + for (int i=0; iinit(); + } + + cout << "sending test ping, load" << endl; + // fetch root on mds0 mds[0]->mdstore->fetch_dir( mds[0]->mdcache->get_root(), NULL ); // send an initial message...? mds[0]->messenger->send_message(new MPing(10), 1, MDS_PORT_MAIN, MDS_PORT_MAIN); + client[0]->issue_request(); // loop fakemessenger_do_loop(); // cleanup - for (int i=0; i<10; i++) { + cout << "cleanup" << endl; + for (int i=0; ishutdown() == 0) { //cout << "clean shutdown of mds " << i << endl; delete mds[i]; } else { cout << "problems shutting down mds " << i << endl; } - + } + for (int i=0; ishutdown() == 0) { //cout << "clean shutdown of osd " << i << endl; delete osd[i]; @@ -75,6 +94,14 @@ int play() { cout << "problems shutting down osd " << i << endl; } } + for (int i=0; ishutdown() == 0) { + //cout << "clean shutdown of client " << i << endl; + delete client[i]; + } else { + cout << "problems shutting down client " << i << endl; + } + } cout << "done." << endl; return 0; } -- 2.39.5