]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
java: add ceph_open_layout interface
authorNoah Watkins <noahwatkins@gmail.com>
Tue, 20 Nov 2012 21:07:00 +0000 (13:07 -0800)
committerSage Weil <sage@inktank.com>
Mon, 26 Nov 2012 19:15:47 +0000 (11:15 -0800)
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/java/java/com/ceph/fs/CephMount.java
src/java/native/libcephfs_jni.cc
src/java/test/com/ceph/fs/CephMountTest.java
src/java/test/com/ceph/fs/CephUnmountedTest.java

index a30961f9245b4101911f1cdd04d8e9b57c09e466..5416b857ac29618103c409b7fe9db6af373a37b3 100644 (file)
@@ -395,6 +395,27 @@ public class CephMount {
 
   private static synchronized native int native_ceph_open(long mountp, String path, int flags, int mode);
 
+  /**
+   * Open a file with a specific file layout.
+   *
+   * @param path Path of file to open or create.
+   * @param flags Open flags.
+   * @param mode Permission mode.
+   * @param stripe_unit File layout stripe unit size.
+   * @param stripe_count File layout stripe count.
+   * @param object_size Size of each object.
+   * @param data_pool The target data pool.
+   * @return File descriptor.
+   */
+  public int open(String path, int flags, int mode, int stripe_unit, int stripe_count,
+      int object_size, String data_pool) throws FileNotFoundException {
+    return native_ceph_open_layout(instance_ptr, path, flags, mode, stripe_unit,
+        stripe_count, object_size, data_pool);
+  }
+
+  private static synchronized native int native_ceph_open_layout(long mountp, String path,
+      int flags, int mode, int stripe_unit, int stripe_count, int object_size, String data_pool);
+
   /**
    * Close an open file.
    *
index b8fdd01e1cc6a2cc59c759827d755f27e23071f6..775812f189f13245ffc4dd0447488133851bc01b 100644 (file)
@@ -1402,6 +1402,58 @@ JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1open
        return ret;
 }
 
+/*
+ * Class:     com_ceph_fs_CephMount
+ * Method:    native_ceph_open_layout
+ * Signature: (JLjava/lang/String;IIIIILjava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1open_1layout
+  (JNIEnv *env, jclass clz, jlong j_mntp, jstring j_path, jint j_flags, jint j_mode,
+   jint stripe_unit, jint stripe_count, jint object_size, jstring j_data_pool)
+{
+       struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
+       CephContext *cct = ceph_get_mount_context(cmount);
+       const char *c_path, *c_data_pool = NULL;
+       int ret, flags = fixup_open_flags(j_flags);
+
+       CHECK_ARG_NULL(j_path, "@path is null", -1);
+       CHECK_MOUNTED(cmount, -1);
+
+       c_path = env->GetStringUTFChars(j_path, NULL);
+       if (!c_path) {
+               cephThrowInternal(env, "Failed to pin memory");
+               return -1;
+       }
+
+       if (j_data_pool) {
+               c_data_pool = env->GetStringUTFChars(j_data_pool, NULL);
+               if (!c_data_pool) {
+                       env->ReleaseStringUTFChars(j_path, c_path);
+                       cephThrowInternal(env, "Failed to pin memory");
+                       return -1;
+               }
+       }
+
+       ldout(cct, 10) << "jni: open_layout: path " << c_path << " flags " << flags
+               << " mode " << (int)j_mode << " stripe_unit " << stripe_unit
+               << " stripe_count " << stripe_count << " object_size " << object_size
+               << " data_pool " << (c_data_pool ? c_data_pool : "<NULL>") << dendl;
+
+       ret = ceph_open_layout(cmount, c_path, flags, (int)j_mode,
+                       (int)stripe_unit, (int)stripe_count, (int)object_size, c_data_pool);
+
+       ldout(cct, 10) << "jni: open_layout: exit ret " << ret << dendl;
+
+       env->ReleaseStringUTFChars(j_path, c_path);
+       if (j_data_pool)
+               env->ReleaseStringUTFChars(j_data_pool, c_data_pool);
+
+  if (ret < 0)
+    handle_error(env, ret);
+
+       return ret;
+}
+
 /*
  * Class:     com_ceph_fs_CephMount
  * Method:    native_ceph_close
index 859ffa62f9b7fc257ab1ddef71666b2237f6c4c6..5510c1a58a112972035ff5aeda570ae1d679ec8f 100644 (file)
@@ -609,6 +609,15 @@ public class CephMountTest {
     mount.unlink(path);
   }
 
+  @Test
+  public void test_open_layout() throws Exception {
+    String path = makePath();
+    int fd = mount.open(path, CephMount.O_WRONLY|CephMount.O_CREAT, 0,
+        (1<<20), 1, (1<<20), null);
+    mount.close(fd);
+    mount.unlink(path);
+  }
+
   /*
    * open/close
    */
index 79f9d7ac18ca4d00241a94dea25c6b209c26f5e1..7074168ee101a59af5c343dc0537713769354376 100644 (file)
@@ -94,6 +94,11 @@ public class CephUnmountedTest {
     mount.open("/a/path", 0, 0);
   }
 
+  @Test(expected=CephNotMountedException.class)
+  public void test_open_layout() throws Exception {
+    mount.open("/a/path", 0, 0, 0, 0, 0, null);
+  }
+
   @Test(expected=CephNotMountedException.class)
   public void test_close() throws Exception {
     mount.close(0);