java: support get pool id/replication interface

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2013-01-16 12:27:16 -08:00
parent 40415d1c2f
commit 736966f38b
6 changed files with 185 additions and 1 deletions

View File

@ -8,7 +8,8 @@ JAVA_SRC = \
java/com/ceph/fs/CephNotMountedException.java \
java/com/ceph/fs/CephFileAlreadyExistsException.java \
java/com/ceph/fs/CephAlreadyMountedException.java \
java/com/ceph/fs/CephNotDirectoryException.java
java/com/ceph/fs/CephNotDirectoryException.java \
java/com/ceph/fs/CephPoolException.java
JAVA_TEST_SRC = \
test/com/ceph/fs/CephDoubleMountTest.java \

View File

@ -899,4 +899,42 @@ public class CephMount {
}
private static native int native_ceph_get_stripe_unit_granularity(long mountp);
/**
* Get the pool id for the named pool.
*
* @param name The pool name.
* @return The pool id.
*/
public int get_pool_id(String name) throws CephPoolException {
rlock.lock();
try {
return native_ceph_get_pool_id(instance_ptr, name);
} catch (FileNotFoundException e) {
throw new CephPoolException("pool name " + name + " not found");
} finally {
rlock.unlock();
}
}
private static native int native_ceph_get_pool_id(long mountp, String name) throws FileNotFoundException;
/**
* Get the pool replication factor.
*
* @param pool_id The pool id.
* @return Number of replicas stored in the pool.
*/
public int get_pool_replication(int pool_id) throws CephPoolException {
rlock.lock();
try {
return native_ceph_get_pool_replication(instance_ptr, pool_id);
} catch (FileNotFoundException e) {
throw new CephPoolException("pool id " + pool_id + " not found");
} finally {
rlock.unlock();
}
}
private static native int native_ceph_get_pool_replication(long mountp, int pool_id) throws FileNotFoundException;
}

View File

@ -0,0 +1,42 @@
/*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package com.ceph.fs;
import java.io.IOException;
/**
* Exception related to Ceph pool.
*/
public class CephPoolException extends IOException {
/**
* Construct CephPoolException.
*/
public CephPoolException() {
super();
}
/**
* Construct CephPoolException with message.
*/
public CephPoolException(String s) {
super(s);
}
}

View File

@ -2434,3 +2434,63 @@ JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1stripe_1uni
return ret;
}
/*
* Class: com_ceph_fs_CephMount
* Method: native_ceph_get_pool_id
* Signature: (JLjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1pool_1id
(JNIEnv *env, jclass clz, jlong j_mntp, jstring jname)
{
struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
CephContext *cct = ceph_get_mount_context(cmount);
const char *c_name;
int ret;
CHECK_MOUNTED(cmount, -1);
CHECK_ARG_NULL(jname, "@name is null", -1);
c_name = env->GetStringUTFChars(jname, NULL);
if (!c_name) {
cephThrowInternal(env, "failed to pin memory");
return -1;
}
ldout(cct, 10) << "jni: get_pool_id: name " << c_name << dendl;
ret = ceph_get_pool_id(cmount, c_name);
if (ret < 0)
handle_error(env, ret);
ldout(cct, 10) << "jni: get_pool_id: ret " << ret << dendl;
env->ReleaseStringUTFChars(jname, c_name);
return ret;
}
/*
* Class: com_ceph_fs_CephMount
* Method: native_ceph_get_pool_replication
* Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1pool_1replication
(JNIEnv *env, jclass clz, jlong j_mntp, jint jpoolid)
{
struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
CephContext *cct = ceph_get_mount_context(cmount);
int ret;
CHECK_MOUNTED(cmount, -1);
ldout(cct, 10) << "jni: get_pool_replication: poolid " << jpoolid << dendl;
ret = ceph_get_pool_replication(cmount, jpoolid);
if (ret < 0)
handle_error(env, ret);
ldout(cct, 10) << "jni: get_pool_replication: ret " << ret << dendl;
return ret;
}

View File

@ -834,4 +834,37 @@ public class CephMountTest {
public void test_get_stripe_unit_gran() throws Exception {
assertTrue(mount.get_stripe_unit_granularity() > 0);
}
/*
* pool info. below we use "data" and "metadata" pool names which we assume
* to exist (they are the default pools created for file data / metadata in
* CephFS).
*/
@Test
public void test_get_pool_id() throws Exception {
/* returns valid pool ids */
assertTrue(mount.get_pool_id("data") >= 0);
assertTrue(mount.get_pool_id("metadata") >= 0);
/* test non-existent pool name */
try {
mount.get_pool_id("asdlfkjlsejflkjef");
assertTrue(false);
} catch (CephPoolException e) {}
}
@Test
public void test_get_pool_replication() throws Exception {
/* test invalid pool id */
try {
mount.get_pool_replication(-1);
assertTrue(false);
} catch (CephPoolException e) {}
/* test valid pool id */
int poolid = mount.get_pool_id("data");
assertTrue(poolid >= 0);
assertTrue(mount.get_pool_replication(poolid) > 0);
}
}

View File

@ -135,4 +135,14 @@ public class CephUnmountedTest {
public void test_get_stripe_unit_gran() throws Exception {
mount.get_stripe_unit_granularity();
}
@Test(expected=CephNotMountedException.class)
public void test_get_pool_id() throws Exception {
mount.get_pool_id("data");
}
@Test(expected=CephNotMountedException.class)
public void test_get_pool_replication() throws Exception {
mount.get_pool_replication(1);
}
}