From c6b78894e5213b40c718c688d60718e94480cd91 Mon Sep 17 00:00:00 2001 From: sage Date: Sat, 30 Apr 2005 05:26:32 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@184 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/Makefile | 4 ++-- ceph/client/Client.cc | 33 ++++++++++++++++++++++++--------- ceph/client/Client.h | 2 +- ceph/config.cc | 8 ++++---- ceph/mds/CDir.cc | 8 ++++---- ceph/mds/MDCache.cc | 2 +- ceph/msg/CheesySerializer.cc | 27 ++++++++++++++++++--------- ceph/msg/FakeMessenger.cc | 17 ++++++++++++++++- ceph/msg/MPIMessenger.h | 2 +- ceph/msg/Messenger.h | 2 +- ceph/msg/Semaphore.h | 23 +++++++++++++++++------ 11 files changed, 89 insertions(+), 39 deletions(-) diff --git a/ceph/Makefile b/ceph/Makefile index 0e9320240ac..586e8865354 100644 --- a/ceph/Makefile +++ b/ceph/Makefile @@ -49,8 +49,8 @@ import: pmds.o msg/FakeMessenger.o import.cc mpitest: mpitest.o msg/MPIMessenger.cc pmds.o ${MPICC} ${CFLAGS} ${MPILIBS} mpitest.o msg/MPIMessenger.cc pmds.o -o mpitest -singleclient: pmds.o fakesingleclient.o client/Client.o msg/CheesySerializer.o msg/FakeMessenger.o - ${CC} ${CFLAGS} ${LIBS} pmds.o client/Client.o msg/FakeMessenger.o msg/CheesySerializer.o fakesingleclient.o ${LEAKTRACER} -o singleclient +singleclient: pmds.o fakesingleclient.o client/Client.o msg/CheesySerializer.o msg/FakeMessenger.o fsck.o + ${CC} ${CFLAGS} ${LIBS} pmds.o client/Client.o msg/FakeMessenger.o msg/CheesySerializer.o fakesingleclient.o fsck.o ${LEAKTRACER} -o singleclient fuseclient: client/Client.o client/fuse.o msg/CheesySerializer.o msg/FakeMessenger.o ${CC} ${CFLAGS} ${LIBS} pmds.o client/fuse.o client/Client.o msg/FakeMessenger.o msg/CheesySerializer.o ${LEAKTRACER} -o fuseclient diff --git a/ceph/client/Client.cc b/ceph/client/Client.cc index 0e8d07ce45e..b62983f0b3a 100644 --- a/ceph/client/Client.cc +++ b/ceph/client/Client.cc @@ -262,18 +262,33 @@ int Client::utime(const char *path, struct utimbuf *buf) // fyi: typedef int (*dirfillerfunc_t) (void *handle, const char *name, int type, inodeno_t ino); -int Client::getdir(const char *path, map contents) +int Client::getdir(const char *path, map& contents) { + MClientRequest *req = new MClientRequest(MDS_OP_READDIR, whoami); + req->set_path(path); - // ... - int res; + // FIXME where does FUSE maintain user information + req->set_caller_uid(getuid()); + req->set_caller_gid(getgid()); - // return contents to caller - /* - for (...) { - - contents[dentryname] = inodeptr; // ptr to inode_t in our cache + //FIXME enforce caller uid rights? + + MClientReply *reply = (MClientReply*)serial_messenger->sendrecv(req, MSG_ADDR_MDS(0), MDS_PORT_SERVER); + int res = reply->get_result(); + + // dir contents to caller! + vector::iterator it; + for (it = reply->get_dir_contents().begin(); + it != reply->get_dir_contents().end(); + it++) { + // put in cache + + contents[(*it)->ref_dn] = &(*it)->inode; // FIXME don't use one from reply! } - */ + + //delete reply; fix thing above first return res; } + + + diff --git a/ceph/client/Client.h b/ceph/client/Client.h index 6247d101444..d8af0896757 100644 --- a/ceph/client/Client.h +++ b/ceph/client/Client.h @@ -206,7 +206,7 @@ class Client : public Dispatcher { int statfs(const char *path, struct statfs *stbuf); // namespace ops - int getdir(const char *path, map contents); + int getdir(const char *path, map& contents); int link(const char *existing, const char *newname); int unlink(const char *path); int rename(const char *from, const char *to); diff --git a/ceph/config.cc b/ceph/config.cc index a9c200b2ac5..4dafcd1d505 100644 --- a/ceph/config.cc +++ b/ceph/config.cc @@ -33,7 +33,7 @@ md_config_t g_conf = { fake_clock: true, fakemessenger_serialize: true,// false, - debug: 14, + debug: 10, mdcache_size: 500, //MDS_CACHE_SIZE, mdcache_mid: .8, @@ -56,12 +56,12 @@ md_config_t g_conf = { client_op_chown: 10, // untested client_op_readdir: 10, - client_op_mknod: 10, + client_op_mknod: 100, client_op_link: false, client_op_unlink: 10, - client_op_rename: 100, + client_op_rename: 00, - client_op_mkdir: 10, + client_op_mkdir: 100, client_op_rmdir: 10, client_op_symlink: 10, diff --git a/ceph/mds/CDir.cc b/ceph/mds/CDir.cc index dcb8b403ea7..f78ed7cb7a7 100644 --- a/ceph/mds/CDir.cc +++ b/ceph/mds/CDir.cc @@ -154,7 +154,7 @@ CDentry* CDir::add_dentry( const string& dname, CInode *in ) nnull++; } - dout(10) << "add_dentry " << *dn << endl; + dout(12) << "add_dentry " << *dn << endl; // pin? if (nnull + nitems == 1) get(CDIR_PIN_CHILD); @@ -168,7 +168,7 @@ CDentry* CDir::add_dentry( const string& dname, CInode *in ) void CDir::remove_dentry(CDentry *dn) { - dout(10) << "remove_dentry " << *dn << endl; + dout(12) << "remove_dentry " << *dn << endl; if (dn->inode) { // detach inode and dentry @@ -197,7 +197,7 @@ void CDir::remove_dentry(CDentry *dn) void CDir::link_inode( CDentry *dn, CInode *in ) { link_inode_work(dn,in); - dout(10) << "link_inode " << *dn << " " << *in << endl; + dout(12) << "link_inode " << *dn << " " << *in << endl; // remove from null list assert(null_items.count(dn->name) == 1); @@ -231,7 +231,7 @@ void CDir::link_inode_work( CDentry *dn, CInode *in ) void CDir::unlink_inode( CDentry *dn ) { - dout(10) << "unlink_inode " << *dn << " " << *dn->inode << endl; + dout(12) << "unlink_inode " << *dn << " " << *dn->inode << endl; unlink_inode_work(dn); diff --git a/ceph/mds/MDCache.cc b/ceph/mds/MDCache.cc index 25b9e59aaa9..35211f10a0c 100644 --- a/ceph/mds/MDCache.cc +++ b/ceph/mds/MDCache.cc @@ -770,7 +770,7 @@ class C_MDC_TraverseDiscover : public Context { this->onfinish = onfinish; } void finish(int r) { - cout << "TraverseDiscover r = " << r << endl; + //dout(10) << "TraverseDiscover r = " << r << endl; if (r < 0) { // ENOENT on discover, pass back to caller. onfinish->finish(r); } else { diff --git a/ceph/msg/CheesySerializer.cc b/ceph/msg/CheesySerializer.cc index 5e389bd74cb..6d01c8db656 100644 --- a/ceph/msg/CheesySerializer.cc +++ b/ceph/msg/CheesySerializer.cc @@ -6,6 +6,11 @@ #include using namespace std; +#include "include/config.h" +#undef dout +#define dout(l) if (l<=g_conf.debug) cout << "serializer: " + +#define DEBUGLVL 13 // debug level of output // --------- // incoming messages @@ -19,14 +24,15 @@ void CheesySerializer::dispatch(Message *m) // was i expecting it? if (call_sem.count(tid)) { // yes, this is a reply to a pending call. - cout << "serializer: dispatch got reply for " << tid << " " << m << endl; + dout(DEBUGLVL) << "dispatch got reply for " << tid << " " << m << endl; call_reply[tid] = m; // set reply - call_sem[tid]->Post(); + int r = call_sem[tid]->Post(); + //cout << "post = " << r << endl; lock.Unlock(); } else { // no, this is an unsolicited message. lock.Unlock(); - cout << "serializer: dispatch got unsolicited message" << m << endl; + dout(DEBUGLVL) << "dispatch got unsolicited message" << m << endl; dispatcher->dispatch(m); } } @@ -38,13 +44,14 @@ void CheesySerializer::dispatch(Message *m) void CheesySerializer::send(Message *m, msg_addr_t dest, int port, int fromport) { // just pass it on to the messenger - cout << "serializer: send " << m << endl; + dout(DEBUGLVL) << "send " << m << endl; messenger->send_message(m, dest, port, fromport); } Message *CheesySerializer::sendrecv(Message *m, msg_addr_t dest, int port, int fromport) { - Semaphore *sem = new Semaphore(); + static Semaphore stsem; + Semaphore *sem = &stsem;//new Semaphore(); // make up a transaction number that is unique (to me!) /* NOTE: since request+replies are matched up on tid's alone, it means that @@ -56,7 +63,7 @@ Message *CheesySerializer::sendrecv(Message *m, msg_addr_t dest, int port, int f long tid = ++last_tid; m->set_tid(tid); - cout << "serializer: sendrecv sending " << m << " on tid " << tid << endl; + dout(DEBUGLVL) << "sendrecv sending " << m << " on tid " << tid << endl; // add call records lock.Lock(); @@ -69,9 +76,11 @@ Message *CheesySerializer::sendrecv(Message *m, msg_addr_t dest, int port, int f messenger->send_message(m, dest, port, fromport); // wait - cout << "serializer: sendrecv waiting for reply on tid " << tid << endl; + dout(DEBUGLVL) << "sendrecv waiting for reply on tid " << tid << endl; + //cout << "wait start, value = " << sem->Value() << endl; sem->Wait(); + // pick up reply lock.Lock(); Message *reply = call_reply[tid]; @@ -80,9 +89,9 @@ Message *CheesySerializer::sendrecv(Message *m, msg_addr_t dest, int port, int f call_sem.erase(tid); lock.Unlock(); - delete sem; + dout(DEBUGLVL) << "sendrecv got reply " << reply << " on tid " << tid << endl; + //delete sem; - cout << "serializer: sendrecv got reply " << reply << " on tid " << tid << endl; return reply; } diff --git a/ceph/msg/FakeMessenger.cc b/ceph/msg/FakeMessenger.cc index 43f02975924..dc73b81e4c5 100644 --- a/ceph/msg/FakeMessenger.cc +++ b/ceph/msg/FakeMessenger.cc @@ -32,7 +32,7 @@ map directory; hash_map loggers; LogType fakemsg_logtype; - +Mutex lock; Semaphore sem; Semaphore shutdownsem; bool awake = false; @@ -81,6 +81,8 @@ int fakemessenger_do_loop() dout(11) << "do_loop top" << endl; + lock.Lock(); + map::iterator it = directory.begin(); while (it != directory.end()) { Message *m = it->second->get_message(); @@ -109,15 +111,24 @@ int fakemessenger_do_loop() } } + lock.Unlock(); + didone = true; it->second->dispatch(m); + + lock.Lock(); } it++; } + lock.Unlock(); + + if (!didone) break; } + + dout(1) << "do_loop end (no more messages)." << endl; return 0; } @@ -177,6 +188,8 @@ int FakeMessenger::send_message(Message *m, msg_addr_t dest, int port, int fromp m->set_source(whoami, fromport); m->set_dest(dest, port); + lock.Lock(); + // deliver try { #ifdef LOG_MESSAGES @@ -209,6 +222,8 @@ int FakeMessenger::send_message(Message *m, msg_addr_t dest, int port, int fromp awake = true; sem.Post(); } + + lock.Unlock(); } int FakeMessenger::wait_message(time_t seconds) diff --git a/ceph/msg/MPIMessenger.h b/ceph/msg/MPIMessenger.h index ac7175f2e4b..cc4a743a914 100644 --- a/ceph/msg/MPIMessenger.h +++ b/ceph/msg/MPIMessenger.h @@ -8,7 +8,7 @@ #define NUMOSD g_conf.num_osd #define MPI_DEST_TO_RANK(dest,world) ((dest)<(NUMMDS+NUMOSD) ? \ (dest) : \ - ((NUMMDS+NUMOSD)+(((dest)-NUMMDS-NUMOSD) % (world-NUMMDS-NUMOSD)))) + ((NUMMDS+NUMOSD)+(((dest)-NUMMDS-NUMOSD) % ((world)-NUMMDS-NUMOSD)))) class MPIMessenger : public Messenger { diff --git a/ceph/msg/Messenger.h b/ceph/msg/Messenger.h index 1ccb9374d20..9add1211630 100644 --- a/ceph/msg/Messenger.h +++ b/ceph/msg/Messenger.h @@ -57,7 +57,7 @@ class Messenger { // incoming queue Message *get_message() { if (incoming.size() > 0) { - cout << incoming.size() << " messages, taking first" << endl; + //cout << incoming.size() << " messages, taking first" << endl; Message *m = incoming.front(); incoming.pop_front(); return m; diff --git a/ceph/msg/Semaphore.h b/ceph/msg/Semaphore.h index 9ca414ada1c..b15d47309ad 100755 --- a/ceph/msg/Semaphore.h +++ b/ceph/msg/Semaphore.h @@ -12,20 +12,31 @@ #include #include +#include +using namespace std; class Semaphore { sem_t S; public: - Semaphore( int init = 0 ) - { sem_init(&S,0,init); } + Semaphore( int init = 0 ) { + int r = sem_init(&S,0,init); + //cout << "sem_init = " << r << endl; + } - virtual ~Semaphore() - { sem_destroy(&S); } + virtual ~Semaphore() { + int r = sem_destroy(&S); + //cout << "sem_destroy = " << r << endl; + } - void Wait() const - { sem_wait((sem_t *)&S); } + void Wait() const { + while (1) { + int r = sem_wait((sem_t *)&S); + if (r == 0) break; + cout << "sem_wait returned " << r << ", trying again" << endl; + } + } int Wait_Try() const { return (sem_trywait((sem_t *)&S)?errno:0); }