private static native int native_ceph_get_file_stripe_unit(long mountp, int fd);
+ /**
+ * Get the name of the pool a file is stored in.
+ *
+ * @param fd An open file descriptor.
+ * @return The pool name.
+ */
+ public String get_file_pool_name(int fd) {
+ rlock.lock();
+ try {
+ return native_ceph_get_file_pool_name(instance_ptr, fd);
+ } finally {
+ rlock.unlock();
+ }
+ }
+
+ private static native String native_ceph_get_file_pool_name(long mountp, int fd);
+
/**
* Get the replication of a file.
*
return ret;
}
+/*
+ * Class: com_ceph_fs_CephMount
+ * Method: native_ceph_get_file_pool_name
+ * Signature: (JI)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1file_1pool_1name
+ (JNIEnv *env, jclass clz, jlong j_mntp, jint j_fd)
+{
+ struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
+ CephContext *cct = ceph_get_mount_context(cmount);
+ jstring pool = NULL;
+ int ret, buflen = 0;
+ char *buf = NULL;
+
+ CHECK_MOUNTED(cmount, NULL);
+
+ ldout(cct, 10) << "jni: get_file_pool_name: fd " << (int)j_fd << dendl;
+
+ for (;;) {
+ /* get pool name length (len==0) */
+ ret = ceph_get_file_pool_name(cmount, (int)j_fd, NULL, 0);
+ if (ret < 0)
+ break;
+
+ /* allocate buffer */
+ if (buf)
+ delete [] buf;
+ buflen = ret;
+ buf = new (std::nothrow) char[buflen+1]; /* +1 for '\0' */
+ if (!buf) {
+ cephThrowOutOfMemory(env, "head allocation failed");
+ goto out;
+ }
+ memset(buf, 0, (buflen+1)*sizeof(*buf));
+
+ /* handle zero-length pool name!? */
+ if (buflen == 0)
+ break;
+
+ /* fill buffer */
+ ret = ceph_get_file_pool_name(cmount, (int)j_fd, buf, buflen);
+ if (ret == -ERANGE) /* size changed! */
+ continue;
+ else
+ break;
+ }
+
+ ldout(cct, 10) << "jni: get_file_pool_name: ret " << ret << dendl;
+
+ if (ret < 0)
+ handle_error(env, ret);
+ else
+ pool = env->NewStringUTF(buf);
+
+out:
+ if (buf)
+ delete [] buf;
+
+ return pool;
+}
+
/*
* Class: com_ceph_fs_CephMount
* Method: native_ceph_localize_reads
assertTrue(poolid >= 0);
assertTrue(mount.get_pool_replication(poolid) > 0);
}
+
+ @Test
+ public void test_get_file_pool_name() throws Exception {
+ String path = makePath();
+ int fd = createFile(path, 1);
+ String pool = mount.get_file_pool_name(fd);
+ mount.close(fd);
+ assertTrue(pool != null);
+ /* assumes using default data pool "data" */
+ assertTrue(pool.compareTo("data") == 0);
+ mount.unlink(path);
+ }
+
+ @Test(expected=IOException.class)
+ public void test_get_file_pool_name_ebadf() throws Exception {
+ String pool = mount.get_file_pool_name(-40);
+ }
}