summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Watkins <noahwatkins@gmail.com>2012-11-20 13:07:00 -0800
committerSage Weil <sage@inktank.com>2012-11-26 11:15:47 -0800
commit1f8c32347b6eba3ab2ab61c12f3b02f3431e10fc (patch)
treecf5e57f40af7f1eb43092780a19b8efb6cc0f623
parentf0c608c0d674abed228b2bbf916e08b77afe1535 (diff)
downloadceph-1f8c32347b6eba3ab2ab61c12f3b02f3431e10fc.tar.gz
java: add ceph_open_layout interface
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r--src/java/java/com/ceph/fs/CephMount.java21
-rw-r--r--src/java/native/libcephfs_jni.cc52
-rw-r--r--src/java/test/com/ceph/fs/CephMountTest.java9
-rw-r--r--src/java/test/com/ceph/fs/CephUnmountedTest.java5
4 files changed, 87 insertions, 0 deletions
diff --git a/src/java/java/com/ceph/fs/CephMount.java b/src/java/java/com/ceph/fs/CephMount.java
index a30961f9245..5416b857ac2 100644
--- a/src/java/java/com/ceph/fs/CephMount.java
+++ b/src/java/java/com/ceph/fs/CephMount.java
@@ -396,6 +396,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.
*
* @param fd The file descriptor.
diff --git a/src/java/native/libcephfs_jni.cc b/src/java/native/libcephfs_jni.cc
index b8fdd01e1cc..775812f189f 100644
--- a/src/java/native/libcephfs_jni.cc
+++ b/src/java/native/libcephfs_jni.cc
@@ -1404,6 +1404,58 @@ JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1open
/*
* 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
* Signature: (JI)I
*/
diff --git a/src/java/test/com/ceph/fs/CephMountTest.java b/src/java/test/com/ceph/fs/CephMountTest.java
index 859ffa62f9b..5510c1a58a1 100644
--- a/src/java/test/com/ceph/fs/CephMountTest.java
+++ b/src/java/test/com/ceph/fs/CephMountTest.java
@@ -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
*/
diff --git a/src/java/test/com/ceph/fs/CephUnmountedTest.java b/src/java/test/com/ceph/fs/CephUnmountedTest.java
index 79f9d7ac18c..7074168ee10 100644
--- a/src/java/test/com/ceph/fs/CephUnmountedTest.java
+++ b/src/java/test/com/ceph/fs/CephUnmountedTest.java
@@ -95,6 +95,11 @@ public class CephUnmountedTest {
}
@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);
}