]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Hadoop: Use the new ceph_getdnames instead of getdir
authorGreg Farnum <gregf@hq.newdream.net>
Fri, 21 Aug 2009 21:29:26 +0000 (14:29 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Mon, 24 Aug 2009 18:09:51 +0000 (11:09 -0700)
Hypertable: fix a nasty not-closing-the-dir bug

src/client/hadoop/CephFSInterface.cc
src/client/hypertable/CephBroker.cc
src/client/libceph.h

index f41b1d1750fd5ddb0cb8070799f2f0863d33dc22..488c799668d223b28309c57344594de3cf848112 100644 (file)
@@ -302,10 +302,36 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_cep
   list<string> contents;
   const char* c_path = env->GetStringUTFChars(j_path, 0);
   if (c_path == NULL) return NULL;
-  int result = ceph_getdir(c_path, contents);
+  DIR *dirp;
+  ceph_opendir(c_path, &dirp);
+  int r;
+  int buflen = 100; //good default?
+  char *buf = new char[buflen];
+  string *ent;
+  int bufpos;
+  while (1) {
+    r = ceph_getdnames(dirp, buf, buflen);
+    if (r==-ERANGE) { //expand the buffer
+      delete buf;
+      buflen *= 2;
+      buf = new char[buflen];
+      continue;
+    }
+    if (r<=0) break;
+
+    //if we make it here, we got at least one name or an unexpected return value
+    bufpos = 0;
+    while (bufpos<r) {//make new strings and add them to listing
+      ent = new string(buf+bufpos);
+      contents.push_back(*ent);
+      bufpos+=ent->size()+1;
+      delete ent;
+    }
+  }
+  ceph_closedir(dirp);
   env->ReleaseStringUTFChars(j_path, c_path);
   
-  if (result < 0) return NULL;
+  if (r < 0) return NULL;
 
   dout(10) << "checking for empty dir" << dendl;
   int dir_size = contents.size();
index ce2477e390152338b49b22f2828860b9d48be79a..1892714c86076ab9e5371a4167d8ea994e654b8e 100644 (file)
@@ -421,6 +421,7 @@ void CephBroker::readdir(ResponseCallbackReaddir *cb, const char *dname) {
       delete ent;
     }
   }
+  ceph_closedir(dirp);
   cb->response(listing);
 }
 
index 7c4b2bbfc4570f02fe908e7bb6a1d24c6f7a90d9..c13c661acd790fba70b8fb220e1f425c31589386 100644 (file)
@@ -28,6 +28,8 @@ struct stat_precise {
   time_t st_ctime_sec;
   time_t st_ctime_micro;
 };
+
+extern "C" {
 int ceph_initialize(int argc, const char **argv);
 void ceph_deinitialize();
 
@@ -88,5 +90,6 @@ int ceph_sync_fs();
 int ceph_get_file_stripe_unit(int fh);
 int ceph_get_file_replication(const char *path);
 int ceph_get_file_stripe_address(int fd, loff_t offset, char *buf, int buflen);
+}
 
 #endif