]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Hadoop: Now does a proper stat.
authorGreg Farnum <gregf@hq.newdream.net>
Fri, 31 Jul 2009 20:03:31 +0000 (13:03 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Mon, 3 Aug 2009 19:01:06 +0000 (12:01 -0700)
src/client/hadoop/CephFSInterface.cc
src/client/hadoop/CephFSInterface.h
src/client/hadoop/ceph/CephFileSystem.java
src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h

index f85f6b536dfd356bc334a443ce2d75c17b054b8b..f86b1e9445f169ebff0e47ebdd9f7f6ba9194644 100644 (file)
@@ -712,3 +712,48 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1wri
   return result;
 }
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+(JNIEnv * env, jobject obj, jstring j_path, jobject j_stat) {
+  //setup variables
+  struct stat st;
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+
+  jclass cls = env->GetObjectClass(j_stat);
+  jfieldID c_size_id = env->GetFieldID(cls, "size", "J");
+  jfieldID c_dir_id = env->GetFieldID(cls, "is_dir", "Z");
+  jfieldID c_block_id = env->GetFieldID(cls, "block_size", "J");
+  jfieldID c_mod_id = env->GetFieldID(cls, "mod_time", "J");
+  jfieldID c_access_id = env->GetFieldID(cls, "access_time", "J");
+  jfieldID c_mode_id = env->GetFieldID(cls, "mode", "I");
+  jfieldID c_user_id = env->GetFieldID(cls, "user_id", "I");
+  jfieldID c_group_id = env->GetFieldID(cls, "group_id", "I");
+
+  //do actual lstat
+  int r = ceph_lstat(c_path, &st);
+
+  if (r < 0) { //clean up variables and fail out; file DNE or Ceph broke
+    env->ReleaseStringUTFChars(j_path, c_path);
+    return false;
+  }
+
+  //put variables from struct stat into Java
+  env->SetLongField(j_stat, c_size_id, (long)st.st_size);
+  env->SetBooleanField(j_stat, c_dir_id, (0 != S_ISDIR(st.st_mode)));
+  env->SetLongField(j_stat, c_block_id, (long)st.st_blksize);
+  env->SetLongField(j_stat, c_mod_id, (long long)st.st_mtime);
+  env->SetLongField(j_stat, c_access_id, (long long)st.st_atime);
+  env->SetIntField(j_stat, c_mode_id, (int)st.st_mode);
+  env->SetIntField(j_stat, c_user_id, (int)st.st_uid);
+  env->SetIntField(j_stat, c_group_id, (int)st.st_gid);
+
+  //clean up variables
+  env->ReleaseStringUTFChars(j_path, c_path);
+
+  //return happy
+  return true;
+}
index f5d2dabbf278f8a3b2ff796487d006940e623f98..3381157be61e93181a6434df6c5eb3605eea6152 100644 (file)
@@ -238,6 +238,14 @@ 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 *, jobject, jint, jbyteArray, jint, jint);
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+  (JNIEnv *, jobject, jstring, jobject);
+
 #ifdef __cplusplus
 }
 #endif
index 881a1a3be15280da0b3d04cce6710f1d8e022a69..779deeabd7145aabb50bd6b1fac5d42324730677 100644 (file)
@@ -17,6 +17,7 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.hadoop.fs.permission.FsAction;
 import org.apache.hadoop.util.Progressable;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.CreateFlag;
@@ -66,7 +67,7 @@ public class CephFileSystem extends FileSystem {
   private native int ceph_open_for_read(String path);
   private native int ceph_open_for_overwrite(String path, int mode);
   private native boolean ceph_kill_client();
-
+  private native boolean ceph_stat(String path, Stat fill);
   public CephFileSystem() {
     debug("CephFileSystem:enter");
     root = new Path("/");
@@ -233,23 +234,20 @@ public class CephFileSystem extends FileSystem {
   public FileStatus getFileStatus(Path p) throws IOException {
     debug("getFileStatus:enter with path " + p);
     Path abs_p = makeAbsolute(p);
-    // For the moment, hardwired replication and modification time
+    // For the moment, hardwired replication
     int replication = 2;
-    int mod_time = 0;
     FileStatus status;
-    if (isFile(abs_p)) {
-      debug("getFileStatus: is file");
-      status = new FileStatus(__getLength(abs_p), false, replication, getBlockSize(abs_p),
-                             mod_time, abs_p);
-    }
-    else if (__isDirectory(abs_p)) {
-      debug("getFileStatus: is directory");
-      status = new FileStatus( 0, true, replication, 0,
-                             mod_time, abs_p);
+    Stat lstat = new Stat();
+    if(ceph_stat(abs_p.toString(), lstat)) {
+      status = new FileStatus(lstat.size, lstat.is_dir, replication,
+                             lstat.block_size, lstat.mod_time, lstat.access_time,
+                             new FsPermission((short)lstat.mode),
+                             new Integer(lstat.user_id).toString(), 
+                             new Integer(lstat.group_id).toString(), abs_p);
     }
     else { //fail out
-      throw new FileNotFoundException("org.apache.hadoop.fs.ceph.CephFileSystem: File "
-                                     + p + " does not exist.");
+       throw new FileNotFoundException("org.apache.hadoop.fs.ceph.CephFileSystem: File "
+                                       + p + " does not exist or could not be accessed");
     }
     debug("getFileStatus:exit");
     return status;
@@ -268,6 +266,10 @@ public class CephFileSystem extends FileSystem {
     return statuses;
   }
 
+  @Override
+    public void setPermission(Path p, FsPermission permission) throws IOException {
+    
+  }
   public FSDataOutputStream create(Path f,
                                   FsPermission permission,
                                   EnumSet<CreateFlag> flag,
@@ -562,14 +564,16 @@ public class CephFileSystem extends FileSystem {
     if (debug) System.err.println(statement);
   }
 
-  // diagnostic methods
-
-  /*  void dump() throws IOException {
-      store.dump();
-      }
-
-      void purge() throws IOException {
-      store.purge();
-      }*/
-
+  private class Stat {
+    public long size;
+    public boolean is_dir;
+    public long block_size;
+    public long mod_time;
+    public long access_time;
+    public int mode;
+    public int user_id;
+    public int group_id; 
+
+    public Stat(){}
+  }
 }
index 3fb1a250ab8e16c5fd87356c2e99815049346f89..521a3f72e5488d231e8ba918feedffaadbc39381 100644 (file)
@@ -169,6 +169,14 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_
 JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1kill_1client
   (JNIEnv *, jobject);
 
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_stat
+ * Signature: (Ljava/lang/String;Lorg/apache/hadoop/fs/ceph/CephFileSystem/Stat;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
+  (JNIEnv *, jobject, jstring, jobject);
+
 #ifdef __cplusplus
 }
 #endif