From bd8c9409fd3143306c9783e6031b443f6336339a Mon Sep 17 00:00:00 2001 From: eestolan Date: Wed, 18 Apr 2007 00:32:52 +0000 Subject: [PATCH] git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1345 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/Makefile | 8 +-- trunk/ceph/client/hadoop/CephFSInterface.cc | 63 ++++++++++++++------- trunk/ceph/client/hadoop/CephFSInterface.h | 8 +++ 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/trunk/ceph/Makefile b/trunk/ceph/Makefile index 82a73d6891ddb..e8fb11534a48b 100644 --- a/trunk/ceph/Makefile +++ b/trunk/ceph/Makefile @@ -10,7 +10,7 @@ # mpicxx if you get paranoid. #CC = g++ -#CFLAGS = -g -Wall -I. -D_FILE_OFFSET_BITS=64 -DMPICH_IGNORE_CXX_SEEK -D_REENTRANT -D_THREAD_SAFE +#CFLAGS = -g -fPIC -Wall -I. -D_FILE_OFFSET_BITS=64 -DMPICH_IGNORE_CXX_SEEK -D_REENTRANT -D_THREAD_SAFE #LIBS = -lpthread # Hook for extra -I options, etc. @@ -22,7 +22,7 @@ CFLAGS = -g -Wall -I. -D_FILE_OFFSET_BITS=64 -DMPICH_IGNORE_CXX_SEEK -D_REENTRAN LDINC = ar -rc else # For linux -CFLAGS = -g -Wall -I. -D_FILE_OFFSET_BITS=64 -DMPICH_IGNORE_CXX_SEEK -D_REENTRANT -D_THREAD_SAFE +CFLAGS = -g -fPIC -Wall -I. -D_FILE_OFFSET_BITS=64 -DMPICH_IGNORE_CXX_SEEK -D_REENTRANT -D_THREAD_SAFE LDINC = ld -i -o endif @@ -187,8 +187,8 @@ osd_obfs.o: osd/OBFSStore.o osd/OSD.cc osd/PG.o osd/ObjectStore.o osd/FakeStore. # hadoop -libhadoopcephfs.so: client/hadoop/CephFSInterface.o client.o osdc.o msg/SimpleMessenger.o common.o - ${CC} -shared -Wl,-soname,$@.1 ${CFLAGS} -I/cse/grads/eestolan/java_local/jdk1.6.0/include ${LIBS} $^ -o $@ +libhadoopcephfs.so: client/hadoop/CephFSInterface.cc client.o osdc.o msg/SimpleMessenger.o common.o + ${CC} -fPIC -shared -Wl,-soname,$@.1 ${CFLAGS} -I/usr/local/java/include -I/usr/local/java/include/linux ${LIBS} $^ -o $@ # libceph libceph.o: client/ldceph.o client/Client.o msg/SimpleMessenger.o ${COMMON_OBJS} ${SYN_OBJS} ${OSDC_OBJS} diff --git a/trunk/ceph/client/hadoop/CephFSInterface.cc b/trunk/ceph/client/hadoop/CephFSInterface.cc index 3202c662153dc..64d6d76fe00e5 100644 --- a/trunk/ceph/client/hadoop/CephFSInterface.cc +++ b/trunk/ceph/client/hadoop/CephFSInterface.cc @@ -48,16 +48,6 @@ JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1init return clientp; } -/* on shutdown, - -client->unmount(); -client->shutdown(); -delete client; - -// wait for messenger to finish -rank.wait(); - -*/ /* @@ -485,6 +475,7 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1i * Class: org_apache_hadoop_fs_ceph_CephFileSystem * Method: ceph_getdir * Signature: (JLjava/lang/String;)[Ljava/lang/String; + * Returns a Java array of Strings with the directory contents */ JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getdir (JNIEnv *env, jobject obj, jlong clientp, jstring j_path) { @@ -507,13 +498,15 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_cep //cout << "checking for empty dir" << endl; jint dir_size = contents.size(); - if (dir_size < 1) - { - // cout << "dir was empty" << endl; - //return NULL; - } - //out << "dir was not empty" << endl; + // Hadoop doesn't want . or .. in the listing, so we shrink the + // listing size by two, or by one if the directory's root + if(('/' == c_path[0]) && (0 == c_path[1])) + dir_size -= 1; + else + dir_size -= 2; + assert (dir_size >= 0); + // Create a Java String array of the size of the directory listing // jstring blankString = env->NewStringUTF(""); jclass stringClass = env->FindClass("java/lang/String"); @@ -523,13 +516,21 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_cep } jobjectArray dirListingStringArray = (jobjectArray) env->NewObjectArray(dir_size, stringClass, NULL); - // populate the array with the elements of the directory list + // populate the array with the elements of the directory list, + // omitting . and .. int i = 0; + string dot("."); + string dotdot (".."); for (map::iterator it = contents.begin(); it != contents.end(); it++) { + // is it "."? + if (it->first == dot) continue; + if (it->first == dotdot) continue; + if (0 == dir_size) cout << "WARNING: adding stuff to an empty array" << endl; + assert (i < dir_size); env->SetObjectArrayElement(dirListingStringArray, i, env->NewStringUTF(it->first.c_str())); ++i; @@ -595,6 +596,30 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_ return result; } +/* + * Class: org_apache_hadoop_fs_ceph_CephFileSystem + * Method: ceph_kill_client + * Signature: (J)Z + * + * Closes the Ceph client. + */ +JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1kill_1client + (JNIEnv *env, jobject obj, jlong clientp) +{ + Client* client; + client = *(Client**)&clientp; + + client->unmount(); + client->shutdown(); + delete client; + + // wait for messenger to finish + rank.wait(); + + return true; +} + + /* * Class: org_apache_hadoop_fs_ceph_CephInputStream @@ -769,8 +794,8 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1clo JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1write (JNIEnv *env, jobject obj, jlong clientp, jint fh, jbyteArray j_buffer, jint buffer_offset, jint length) { - cout << "In write" << endl; - cout.flush(); + //cout << "In write" << endl; + //cout.flush(); // IMPORTANT NOTE: Hadoop write arguments are a bit different from POSIX so we diff --git a/trunk/ceph/client/hadoop/CephFSInterface.h b/trunk/ceph/client/hadoop/CephFSInterface.h index 8cba3248c33dc..0930ecb25b8f1 100644 --- a/trunk/ceph/client/hadoop/CephFSInterface.h +++ b/trunk/ceph/client/hadoop/CephFSInterface.h @@ -155,6 +155,14 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_1for_1overwrite (JNIEnv *, jobject, jlong, jstring); +/* + * Class: org_apache_hadoop_fs_ceph_CephFileSystem + * Method: ceph_kill_client + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1kill_1client + (JNIEnv *, jobject, jlong); + #undef org_apache_hadoop_fs_ceph_CephInputStream_SKIP_BUFFER_SIZE #define org_apache_hadoop_fs_ceph_CephInputStream_SKIP_BUFFER_SIZE 2048L /* -- 2.39.5