From cb612b147664a990197ee7b879a70982cab7646f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 17 Jan 2008 13:00:36 -0800 Subject: [PATCH] resurrected ldceph.so, sort of --- src/Makefile | 5 +++++ src/client/ldceph.cc | 43 ++++++++++++++++++++++--------------------- src/mon/MonMap.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/mon/MonMap.h | 36 ++---------------------------------- 4 files changed, 69 insertions(+), 55 deletions(-) create mode 100644 src/mon/MonMap.cc diff --git a/src/Makefile b/src/Makefile index dd4ecac802f3d..7e489d32423e3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -103,6 +103,7 @@ COMMON_OBJS= \ common/Logger.o\ common/Clock.o\ common/Timer.o\ + mon/MonMap.o\ config.o CLIENT_OBJS= \ @@ -233,6 +234,10 @@ libhadoopcephfs.so: client/hadoop/CephFSInterface.cc client.o osdc.o msg/SimpleM libceph.o: client/ldceph.o client/Client.o msg/SimpleMessenger.o ${COMMON_OBJS} ${SYN_OBJS} ${OSDC_OBJS} ${LDINC} $^ -o $@ +ldceph.so: libceph.o msg/SimpleMessenger.o + ${CXX} -shared -fPIC ${CFLAGS} $< -o $@ + + # some benchmarking tools bench/mdtest/mdtest.o: bench/mdtest/mdtest.c mpicc -c $^ -o $@ diff --git a/src/client/ldceph.cc b/src/client/ldceph.cc index b17133ee1e6f2..9d6faa4f10495 100644 --- a/src/client/ldceph.cc +++ b/src/client/ldceph.cc @@ -17,6 +17,11 @@ #include using namespace std; + +#define _FCNTL_H +#include + + // ceph stuff #include "config.h" #include "client/Client.h" @@ -27,10 +32,6 @@ using namespace std; #include #include //#include - -#define _FCNTL_H -#include - #define CEPH_FD_OFF 50000 @@ -68,7 +69,7 @@ public: if (o[b] == "..") p.pop_dentry(); else - p.add_dentry(o[b]); + p.push_dentry(o[b]); } // FIXME rewrite @@ -124,26 +125,27 @@ public: mount_point(0), mount_point_parent(0), mount_point_len(0), cwd_above_mp(false), cwd_in_mp(false) { + cerr << "ldceph init " << std::endl; // args - vector args; + vector args; env_to_vec(args); parse_config_options(args); - - tcpaddr_t nsa; - if (tcpmessenger_findns(nsa) < 0) - return; - tcpmessenger_init(); - tcpmessenger_start(); - tcpmessenger_start_rankserver(nsa); - - client = new Client(new TCPMessenger(MSG_ADDR_CLIENT_NEW)); + // load monmap + MonMap monmap; + int r = monmap.read(".ceph_monmap"); + assert(r >= 0); + + // start up network + rank.start_rank(); + + client = new Client(rank.register_entity(entity_name_t(entity_name_t::TYPE_CLIENT,-1)), &monmap); client->init(); - int r = client->mount(); + r = client->mount(); if (r < 0) { // failure - cerr << "ldceph init: mount failed " << r << endl; + cerr << "ldceph init: mount failed " << r << std::endl; delete client; client = 0; } else { @@ -155,20 +157,19 @@ public: fp_mount_point = mount_point; - cerr << "ldceph init: mounted on " << mount_point << " as " << client->get_myaddr() << endl; + cerr << "ldceph init: mounted on " << mount_point << " as client" << client->get_nodeid() << std::endl; refresh_cwd(); } } ~LdCeph() { - cout << "ldceph fini" << endl; + cout << "ldceph fini" << std::endl; if (false && client) { client->unmount(); client->shutdown(); delete client; client = 0; - tcpmessenger_wait(); - tcpmessenger_shutdown(); + rank.wait(); } } diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc new file mode 100644 index 0000000000000..d018eddb82c33 --- /dev/null +++ b/src/mon/MonMap.cc @@ -0,0 +1,40 @@ + +#include "MonMap.h" + +#include +#include +#include + +// read from/write to a file +int MonMap::write(const char *fn) +{ + // encode + bufferlist bl; + encode(bl); + + // write + int fd = ::open(fn, O_RDWR|O_CREAT); + if (fd < 0) return fd; + ::fchmod(fd, 0644); + ::write(fd, (void*)bl.c_str(), bl.length()); + ::close(fd); + return 0; +} + +int MonMap::read(const char *fn) +{ + // read + bufferlist bl; + int fd = ::open(fn, O_RDONLY); + if (fd < 0) return fd; + struct stat st; + ::fstat(fd, &st); + bufferptr bp(st.st_size); + bl.append(bp); + ::read(fd, (void*)bl.c_str(), bl.length()); + ::close(fd); + + // decode + decode(bl); + return 0; +} diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 818d84b95534d..e0166ace9b7b1 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -15,10 +15,6 @@ #ifndef __MONMAP_H #define __MONMAP_H -#include -#include -#include - #include "msg/Message.h" #include "include/types.h" @@ -77,36 +73,8 @@ class MonMap { } // read from/write to a file - int write(const char *fn) { - // encode - bufferlist bl; - encode(bl); - - // write - int fd = ::open(fn, O_RDWR|O_CREAT); - if (fd < 0) return fd; - ::fchmod(fd, 0644); - ::write(fd, (void*)bl.c_str(), bl.length()); - ::close(fd); - return 0; - } - - int read(const char *fn) { - // read - bufferlist bl; - int fd = ::open(fn, O_RDONLY); - if (fd < 0) return fd; - struct stat st; - ::fstat(fd, &st); - bufferptr bp(st.st_size); - bl.append(bp); - ::read(fd, (void*)bl.c_str(), bl.length()); - ::close(fd); - - // decode - decode(bl); - return 0; - } + int write(const char *fn); + int read(const char *fn); }; -- 2.39.5