2 * Permission is hereby granted, free of charge, to any person obtaining a
3 * copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation
5 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 * DEALINGS IN THE SOFTWARE.
20 #include <sys/types.h>
29 #include "ScopedLocalRef.h"
30 #include "JniConstants.h"
32 #include "include/cephfs/libcephfs.h"
33 #include "common/dout.h"
35 #define dout_subsys ceph_subsys_javaclient
37 #include "com_ceph_fs_CephMount.h"
39 #define CEPH_STAT_CP "com/ceph/fs/CephStat"
40 #define CEPH_STAT_VFS_CP "com/ceph/fs/CephStatVFS"
41 #define CEPH_FILE_EXTENT_CP "com/ceph/fs/CephFileExtent"
42 #define CEPH_MOUNT_CP "com/ceph/fs/CephMount"
43 #define CEPH_NOTMOUNTED_CP "com/ceph/fs/CephNotMountedException"
44 #define CEPH_FILEEXISTS_CP "com/ceph/fs/CephFileAlreadyExistsException"
45 #define CEPH_ALREADYMOUNTED_CP "com/ceph/fs/CephAlreadyMountedException"
46 #define CEPH_NOTDIR_CP "com/ceph/fs/CephNotDirectoryException"
49 * Flags to open(). must be synchronized with CephMount.java
51 * There are two versions of flags: the version in Java and the version in the
52 * target library (e.g. libc or libcephfs). We control the Java values and map
53 * to the target value with fixup_* functions below. This is much faster than
54 * keeping the values in Java and making a cross-JNI up-call to retrieve them,
55 * and makes it easy to keep any platform specific value changes in this file.
57 #define JAVA_O_RDONLY 1
59 #define JAVA_O_APPEND 4
60 #define JAVA_O_CREAT 8
61 #define JAVA_O_TRUNC 16
62 #define JAVA_O_EXCL 32
63 #define JAVA_O_WRONLY 64
64 #define JAVA_O_DIRECTORY 128
67 * Whence flags for seek(). sync with CephMount.java if changed.
69 * Mapping of SEEK_* done in seek function.
71 #define JAVA_SEEK_SET 1
72 #define JAVA_SEEK_CUR 2
73 #define JAVA_SEEK_END 3
76 * File attribute flags. sync with CephMount.java if changed.
78 #define JAVA_SETATTR_MODE 1
79 #define JAVA_SETATTR_UID 2
80 #define JAVA_SETATTR_GID 4
81 #define JAVA_SETATTR_MTIME 8
82 #define JAVA_SETATTR_ATIME 16
85 * Setxattr flags. sync with CephMount.java if changed.
87 #define JAVA_XATTR_CREATE 1
88 #define JAVA_XATTR_REPLACE 2
89 #define JAVA_XATTR_NONE 3
92 * flock flags. sync with CephMount.java if changed.
94 #define JAVA_LOCK_SH 1
95 #define JAVA_LOCK_EX 2
96 #define JAVA_LOCK_NB 4
97 #define JAVA_LOCK_UN 8
101 /* Map JAVA_O_* open flags to values in libc */
102 static inline int fixup_open_flags(jint jflags
)
106 #define FIXUP_OPEN_FLAG(name) \
107 if (jflags & JAVA_##name) \
110 FIXUP_OPEN_FLAG(O_RDONLY
)
111 FIXUP_OPEN_FLAG(O_RDWR
)
112 FIXUP_OPEN_FLAG(O_APPEND
)
113 FIXUP_OPEN_FLAG(O_CREAT
)
114 FIXUP_OPEN_FLAG(O_TRUNC
)
115 FIXUP_OPEN_FLAG(O_EXCL
)
116 FIXUP_OPEN_FLAG(O_WRONLY
)
117 FIXUP_OPEN_FLAG(O_DIRECTORY
)
119 #undef FIXUP_OPEN_FLAG
124 /* Map JAVA_SETATTR_* to values in ceph lib */
125 static inline int fixup_attr_mask(jint jmask
)
129 #define FIXUP_ATTR_MASK(name) \
130 if (jmask & JAVA_##name) \
133 FIXUP_ATTR_MASK(SETATTR_MODE
)
134 FIXUP_ATTR_MASK(SETATTR_UID
)
135 FIXUP_ATTR_MASK(SETATTR_GID
)
136 FIXUP_ATTR_MASK(SETATTR_MTIME
)
137 FIXUP_ATTR_MASK(SETATTR_ATIME
)
139 #undef FIXUP_ATTR_MASK
144 /* Cached field IDs for com.ceph.fs.CephStat */
145 static jfieldID cephstat_mode_fid
;
146 static jfieldID cephstat_uid_fid
;
147 static jfieldID cephstat_gid_fid
;
148 static jfieldID cephstat_size_fid
;
149 static jfieldID cephstat_blksize_fid
;
150 static jfieldID cephstat_blocks_fid
;
151 static jfieldID cephstat_a_time_fid
;
152 static jfieldID cephstat_m_time_fid
;
153 static jfieldID cephstat_is_file_fid
;
154 static jfieldID cephstat_is_directory_fid
;
155 static jfieldID cephstat_is_symlink_fid
;
157 /* Cached field IDs for com.ceph.fs.CephStatVFS */
158 static jfieldID cephstatvfs_bsize_fid
;
159 static jfieldID cephstatvfs_frsize_fid
;
160 static jfieldID cephstatvfs_blocks_fid
;
161 static jfieldID cephstatvfs_bavail_fid
;
162 static jfieldID cephstatvfs_files_fid
;
163 static jfieldID cephstatvfs_fsid_fid
;
164 static jfieldID cephstatvfs_namemax_fid
;
166 /* Cached field IDs for com.ceph.fs.CephMount */
167 static jfieldID cephmount_instance_ptr_fid
;
169 /* Cached field IDs for com.ceph.fs.CephFileExtent */
170 static jclass cephfileextent_cls
;
171 static jmethodID cephfileextent_ctor_fid
;
174 * Exception throwing helper. Adapted from Apache Hadoop header
175 * org_apache_hadoop.h by adding the do {} while (0) construct.
177 #define THROW(env, exception_name, message) \
179 jclass ecls = env->FindClass(exception_name); \
181 int ret = env->ThrowNew(ecls, message); \
183 printf("(CephFS) Fatal Error\n"); \
185 env->DeleteLocalRef(ecls); \
190 static void cephThrowNullArg(JNIEnv
*env
, const char *msg
)
192 THROW(env
, "java/lang/NullPointerException", msg
);
195 static void cephThrowOutOfMemory(JNIEnv
*env
, const char *msg
)
197 THROW(env
, "java/lang/OutOfMemoryError", msg
);
200 static void cephThrowInternal(JNIEnv
*env
, const char *msg
)
202 THROW(env
, "java/lang/InternalError", msg
);
205 static void cephThrowIndexBounds(JNIEnv
*env
, const char *msg
)
207 THROW(env
, "java/lang/IndexOutOfBoundsException", msg
);
210 static void cephThrowIllegalArg(JNIEnv
*env
, const char *msg
)
212 THROW(env
, "java/lang/IllegalArgumentException", msg
);
215 static void cephThrowFNF(JNIEnv
*env
, const char *msg
)
217 THROW(env
, "java/io/FileNotFoundException", msg
);
220 static void cephThrowFileExists(JNIEnv
*env
, const char *msg
)
222 THROW(env
, CEPH_FILEEXISTS_CP
, msg
);
225 static void cephThrowNotDir(JNIEnv
*env
, const char *msg
)
227 THROW(env
, CEPH_NOTDIR_CP
, msg
);
230 static void handle_error(JNIEnv
*env
, int rc
)
234 cephThrowFNF(env
, "");
237 cephThrowFileExists(env
, "");
240 cephThrowNotDir(env
, "");
246 THROW(env
, "java/io/IOException", strerror(-rc
));
249 #define CHECK_ARG_NULL(v, m, r) do { \
251 cephThrowNullArg(env, (m)); \
255 #define CHECK_ARG_BOUNDS(c, m, r) do { \
257 cephThrowIndexBounds(env, (m)); \
261 #define CHECK_MOUNTED(_c, _r) do { \
262 if (!ceph_is_mounted((_c))) { \
263 THROW(env, CEPH_NOTMOUNTED_CP, "not mounted"); \
268 * Cast a jlong to ceph_mount_info. Each JNI function is expected to pass in
269 * the class instance variable instance_ptr. Passing a parameter is faster
270 * than reaching back into Java via an upcall to retrieve this pointer.
272 static inline struct ceph_mount_info
*get_ceph_mount(jlong j_mntp
)
274 return (struct ceph_mount_info
*)j_mntp
;
278 * Setup cached field IDs
280 static void setup_field_ids(JNIEnv
*env
, jclass clz
)
283 jclass cephstatvfs_cls
;
284 jclass tmp_cephfileextent_cls
;
287 * Get a fieldID from a class with a specific type
290 * field: field in clz
291 * type: integer, long, etc..
293 * This macro assumes some naming convention that is used
296 * GETFID(cephstat, mode, I) gets translated into
297 * cephstat_mode_fid = env->GetFieldID(cephstat_cls, "mode", "I");
299 #define GETFID(clz, field, type) do { \
300 clz ## _ ## field ## _fid = env->GetFieldID(clz ## _cls, #field, #type); \
301 if ( ! clz ## _ ## field ## _fid ) \
305 /* Cache CephStat fields */
307 cephstat_cls
= env
->FindClass(CEPH_STAT_CP
);
311 GETFID(cephstat
, mode
, I
);
312 GETFID(cephstat
, uid
, I
);
313 GETFID(cephstat
, gid
, I
);
314 GETFID(cephstat
, size
, J
);
315 GETFID(cephstat
, blksize
, J
);
316 GETFID(cephstat
, blocks
, J
);
317 GETFID(cephstat
, a_time
, J
);
318 GETFID(cephstat
, m_time
, J
);
319 GETFID(cephstat
, is_file
, Z
);
320 GETFID(cephstat
, is_directory
, Z
);
321 GETFID(cephstat
, is_symlink
, Z
);
323 /* Cache CephStatVFS fields */
325 cephstatvfs_cls
= env
->FindClass(CEPH_STAT_VFS_CP
);
326 if (!cephstatvfs_cls
)
329 GETFID(cephstatvfs
, bsize
, J
);
330 GETFID(cephstatvfs
, frsize
, J
);
331 GETFID(cephstatvfs
, blocks
, J
);
332 GETFID(cephstatvfs
, bavail
, J
);
333 GETFID(cephstatvfs
, files
, J
);
334 GETFID(cephstatvfs
, fsid
, J
);
335 GETFID(cephstatvfs
, namemax
, J
);
337 /* Cache CephFileExtent fields */
339 tmp_cephfileextent_cls
= env
->FindClass(CEPH_FILE_EXTENT_CP
);
340 if (!tmp_cephfileextent_cls
)
343 cephfileextent_cls
= (jclass
)env
->NewGlobalRef(tmp_cephfileextent_cls
);
344 env
->DeleteLocalRef(tmp_cephfileextent_cls
);
346 cephfileextent_ctor_fid
= env
->GetMethodID(cephfileextent_cls
, "<init>", "(JJ[I)V");
347 if (!cephfileextent_ctor_fid
)
350 JniConstants::init(env
);
354 cephmount_instance_ptr_fid
= env
->GetFieldID(clz
, "instance_ptr", "J");
359 * Class: com_ceph_fs_CephMount
360 * Method: native_initialize
363 JNIEXPORT
void JNICALL Java_com_ceph_fs_CephMount_native_1initialize
364 (JNIEnv
*env
, jclass clz
)
366 setup_field_ids(env
, clz
);
370 * Class: com_ceph_fs_CephMount
371 * Method: native_ceph_create
372 * Signature: (Lcom/ceph/fs/CephMount;Ljava/lang/String;)I
374 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1create
375 (JNIEnv
*env
, jclass clz
, jobject j_cephmount
, jstring j_id
)
377 struct ceph_mount_info
*cmount
;
378 const char *c_id
= NULL
;
381 CHECK_ARG_NULL(j_cephmount
, "@mount is null", -1);
384 c_id
= env
->GetStringUTFChars(j_id
, NULL
);
386 cephThrowInternal(env
, "Failed to pin memory");
391 ret
= ceph_create(&cmount
, c_id
);
394 env
->ReleaseStringUTFChars(j_id
, c_id
);
397 THROW(env
, "java/lang/RuntimeException", "failed to create Ceph mount object");
401 env
->SetLongField(j_cephmount
, cephmount_instance_ptr_fid
, (long)cmount
);
407 * Class: com_ceph_fs_CephMount
408 * Method: native_ceph_mount
409 * Signature: (JLjava/lang/String;)I
411 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1mount
412 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_root
)
414 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
415 CephContext
*cct
= ceph_get_mount_context(cmount
);
416 const char *c_root
= NULL
;
420 * Toss a message up if we are already mounted.
422 if (ceph_is_mounted(cmount
)) {
423 THROW(env
, CEPH_ALREADYMOUNTED_CP
, "");
428 c_root
= env
->GetStringUTFChars(j_root
, NULL
);
430 cephThrowInternal(env
, "Failed to pin memory");
435 ldout(cct
, 10) << "jni: ceph_mount: " << (c_root
? c_root
: "<NULL>") << dendl
;
437 ret
= ceph_mount(cmount
, c_root
);
439 ldout(cct
, 10) << "jni: ceph_mount: exit ret " << ret
<< dendl
;
442 env
->ReleaseStringUTFChars(j_root
, c_root
);
445 handle_error(env
, ret
);
451 * Class: com_ceph_fs_CephMount
452 * Method: native_ceph_unmount
455 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1unmount
456 (JNIEnv
*env
, jclass clz
, jlong j_mntp
)
458 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
459 CephContext
*cct
= ceph_get_mount_context(cmount
);
462 ldout(cct
, 10) << "jni: ceph_unmount enter" << dendl
;
464 CHECK_MOUNTED(cmount
, -1);
466 ret
= ceph_unmount(cmount
);
468 ldout(cct
, 10) << "jni: ceph_unmount exit ret " << ret
<< dendl
;
471 handle_error(env
, ret
);
477 * Class: com_ceph_fs_CephMount
478 * Method: native_ceph_release
481 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1release
482 (JNIEnv
*env
, jclass clz
, jlong j_mntp
)
484 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
485 CephContext
*cct
= ceph_get_mount_context(cmount
);
488 ldout(cct
, 10) << "jni: ceph_release called" << dendl
;
490 ret
= ceph_release(cmount
);
493 handle_error(env
, ret
);
499 * Class: com_ceph_fs_CephMount
500 * Method: native_ceph_conf_set
501 * Signature: (JLjava/lang/String;Ljava/lang/String;)I
503 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1conf_1set
504 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_opt
, jstring j_val
)
506 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
507 CephContext
*cct
= ceph_get_mount_context(cmount
);
508 const char *c_opt
, *c_val
;
511 CHECK_ARG_NULL(j_opt
, "@option is null", -1);
512 CHECK_ARG_NULL(j_val
, "@value is null", -1);
514 c_opt
= env
->GetStringUTFChars(j_opt
, NULL
);
516 cephThrowInternal(env
, "failed to pin memory");
520 c_val
= env
->GetStringUTFChars(j_val
, NULL
);
522 env
->ReleaseStringUTFChars(j_opt
, c_opt
);
523 cephThrowInternal(env
, "failed to pin memory");
527 ldout(cct
, 10) << "jni: conf_set: opt " << c_opt
<< " val " << c_val
<< dendl
;
529 ret
= ceph_conf_set(cmount
, c_opt
, c_val
);
531 ldout(cct
, 10) << "jni: conf_set: exit ret " << ret
<< dendl
;
533 env
->ReleaseStringUTFChars(j_opt
, c_opt
);
534 env
->ReleaseStringUTFChars(j_val
, c_val
);
537 handle_error(env
, ret
);
543 * Class: com_ceph_fs_CephMount
544 * Method: native_ceph_conf_get
545 * Signature: (JLjava/lang/String;)Ljava/lang/String;
547 JNIEXPORT jstring JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1conf_1get
548 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_opt
)
550 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
551 CephContext
*cct
= ceph_get_mount_context(cmount
);
553 jstring value
= NULL
;
557 CHECK_ARG_NULL(j_opt
, "@option is null", NULL
);
559 c_opt
= env
->GetStringUTFChars(j_opt
, NULL
);
561 cephThrowInternal(env
, "failed to pin memory");
566 buf
= new (std::nothrow
) char[buflen
];
568 cephThrowOutOfMemory(env
, "head allocation failed");
573 memset(buf
, 0, sizeof(char)*buflen
);
574 ldout(cct
, 10) << "jni: conf_get: opt " << c_opt
<< " len " << buflen
<< dendl
;
575 ret
= ceph_conf_get(cmount
, c_opt
, buf
, buflen
);
576 if (ret
== -ENAMETOOLONG
) {
579 buf
= new (std::nothrow
) char[buflen
];
581 cephThrowOutOfMemory(env
, "head allocation failed");
588 ldout(cct
, 10) << "jni: conf_get: ret " << ret
<< dendl
;
591 value
= env
->NewStringUTF(buf
);
592 else if (ret
!= -ENOENT
)
593 handle_error(env
, ret
);
598 env
->ReleaseStringUTFChars(j_opt
, c_opt
);
603 * Class: com_ceph_fs_CephMount
604 * Method: native_ceph_conf_read_file
605 * Signature: (JLjava/lang/String;)I
607 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1conf_1read_1file
608 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
610 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
611 CephContext
*cct
= ceph_get_mount_context(cmount
);
615 CHECK_ARG_NULL(j_path
, "@path is null", -1);
617 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
619 cephThrowInternal(env
, "failed to pin memory");
623 ldout(cct
, 10) << "jni: conf_read_file: path " << c_path
<< dendl
;
625 ret
= ceph_conf_read_file(cmount
, c_path
);
627 ldout(cct
, 10) << "jni: conf_read_file: exit ret " << ret
<< dendl
;
629 env
->ReleaseStringUTFChars(j_path
, c_path
);
632 handle_error(env
, ret
);
638 * Class: com_ceph_fs_CephMount
639 * Method: native_ceph_statfs
640 * Signature: (JLjava/lang/String;Lcom/ceph/fs/CephStatVFS;)I
642 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1statfs
643 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jobject j_cephstatvfs
)
645 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
646 CephContext
*cct
= ceph_get_mount_context(cmount
);
651 CHECK_ARG_NULL(j_path
, "@path is null", -1);
652 CHECK_ARG_NULL(j_cephstatvfs
, "@stat is null", -1);
653 CHECK_MOUNTED(cmount
, -1);
655 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
657 cephThrowInternal(env
, "Failed to pin memory");
661 ldout(cct
, 10) << "jni: statfs: path " << c_path
<< dendl
;
663 ret
= ceph_statfs(cmount
, c_path
, &st
);
665 ldout(cct
, 10) << "jni: statfs: exit ret " << ret
<< dendl
;
667 env
->ReleaseStringUTFChars(j_path
, c_path
);
670 handle_error(env
, ret
);
674 env
->SetLongField(j_cephstatvfs
, cephstatvfs_bsize_fid
, st
.f_bsize
);
675 env
->SetLongField(j_cephstatvfs
, cephstatvfs_frsize_fid
, st
.f_frsize
);
676 env
->SetLongField(j_cephstatvfs
, cephstatvfs_blocks_fid
, st
.f_blocks
);
677 env
->SetLongField(j_cephstatvfs
, cephstatvfs_bavail_fid
, st
.f_bavail
);
678 env
->SetLongField(j_cephstatvfs
, cephstatvfs_files_fid
, st
.f_files
);
679 env
->SetLongField(j_cephstatvfs
, cephstatvfs_fsid_fid
, st
.f_fsid
);
680 env
->SetLongField(j_cephstatvfs
, cephstatvfs_namemax_fid
, st
.f_namemax
);
686 * Class: com_ceph_fs_CephMount
687 * Method: native_ceph_getcwd
688 * Signature: (J)Ljava/lang/String;
690 JNIEXPORT jstring JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1getcwd
691 (JNIEnv
*env
, jclass clz
, jlong j_mntp
)
693 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
694 CephContext
*cct
= ceph_get_mount_context(cmount
);
697 CHECK_MOUNTED(cmount
, NULL
);
699 ldout(cct
, 10) << "jni: getcwd: enter" << dendl
;
701 c_cwd
= ceph_getcwd(cmount
);
703 cephThrowOutOfMemory(env
, "ceph_getcwd");
707 ldout(cct
, 10) << "jni: getcwd: exit ret " << c_cwd
<< dendl
;
709 return env
->NewStringUTF(c_cwd
);
713 * Class: com_ceph_fs_CephMount
714 * Method: native_ceph_chdir
715 * Signature: (JLjava/lang/String;)I
717 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1chdir
718 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
720 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
721 CephContext
*cct
= ceph_get_mount_context(cmount
);
725 CHECK_ARG_NULL(j_path
, "@path is null", -1);
726 CHECK_MOUNTED(cmount
, -1);
728 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
730 cephThrowInternal(env
, "failed to pin memory");
734 ldout(cct
, 10) << "jni: chdir: path " << c_path
<< dendl
;
736 ret
= ceph_chdir(cmount
, c_path
);
738 ldout(cct
, 10) << "jni: chdir: exit ret " << ret
<< dendl
;
740 env
->ReleaseStringUTFChars(j_path
, c_path
);
743 handle_error(env
, ret
);
749 * Class: com_ceph_fs_CephMount
750 * Method: native_ceph_listdir
751 * Signature: (JLjava/lang/String;)[Ljava/lang/String;
753 JNIEXPORT jobjectArray JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1listdir
754 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
756 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
757 CephContext
*cct
= ceph_get_mount_context(cmount
);
758 struct ceph_dir_result
*dirp
;
759 list
<string
>::iterator it
;
760 list
<string
> contents
;
762 jobjectArray dirlist
;
764 int ret
, buflen
, bufpos
, i
;
768 CHECK_ARG_NULL(j_path
, "@path is null", NULL
);
769 CHECK_MOUNTED(cmount
, NULL
);
771 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
773 cephThrowInternal(env
, "failed to pin memory");
777 ldout(cct
, 10) << "jni: listdir: opendir: path " << c_path
<< dendl
;
779 /* ret < 0 also includes -ENOTDIR which should return NULL */
780 ret
= ceph_opendir(cmount
, c_path
, &dirp
);
782 env
->ReleaseStringUTFChars(j_path
, c_path
);
783 handle_error(env
, ret
);
787 ldout(cct
, 10) << "jni: listdir: opendir: exit ret " << ret
<< dendl
;
789 /* buffer for ceph_getdnames() results */
791 buf
= new (std::nothrow
) char[buflen
];
793 cephThrowOutOfMemory(env
, "heap allocation failed");
798 ldout(cct
, 10) << "jni: listdir: getdnames: enter" << dendl
;
799 ret
= ceph_getdnames(cmount
, dirp
, buf
, buflen
);
800 if (ret
== -ERANGE
) {
803 buf
= new (std::nothrow
) char[buflen
];
805 cephThrowOutOfMemory(env
, "heap allocation failed");
811 ldout(cct
, 10) << "jni: listdir: getdnames: exit ret " << ret
<< dendl
;
816 /* got at least one name */
818 while (bufpos
< ret
) {
819 ent
= new (std::nothrow
) string(buf
+ bufpos
);
822 cephThrowOutOfMemory(env
, "heap allocation failed");
826 /* filter out dot files: xref: java.io.File::list() */
827 if (ent
->compare(".") && ent
->compare("..")) {
828 contents
.push_back(*ent
);
829 ldout(cct
, 20) << "jni: listdir: take path " << *ent
<< dendl
;
832 bufpos
+= ent
->size() + 1;
840 handle_error(env
, ret
);
845 dirlist
= env
->NewObjectArray(contents
.size(), env
->FindClass("java/lang/String"), NULL
);
850 * Fill directory listing array.
852 * FIXME: how should a partially filled array be cleaned-up properly?
854 for (i
= 0, it
= contents
.begin(); it
!= contents
.end(); ++it
) {
855 name
= env
->NewStringUTF(it
->c_str());
858 env
->SetObjectArrayElement(dirlist
, i
++, name
);
859 if (env
->ExceptionOccurred())
861 env
->DeleteLocalRef(name
);
864 env
->ReleaseStringUTFChars(j_path
, c_path
);
865 ceph_closedir(cmount
, dirp
);
870 env
->ReleaseStringUTFChars(j_path
, c_path
);
871 ceph_closedir(cmount
, dirp
);
876 * Class: com_ceph_fs_CephMount
877 * Method: native_ceph_link
878 * Signature: (JLjava/lang/String;Ljava/lang/String;)I
880 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1link
881 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_oldpath
, jstring j_newpath
)
883 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
884 CephContext
*cct
= ceph_get_mount_context(cmount
);
885 const char *c_oldpath
, *c_newpath
;
888 CHECK_ARG_NULL(j_oldpath
, "@oldpath is null", -1);
889 CHECK_ARG_NULL(j_newpath
, "@newpath is null", -1);
890 CHECK_MOUNTED(cmount
, -1);
892 c_oldpath
= env
->GetStringUTFChars(j_oldpath
, NULL
);
894 cephThrowInternal(env
, "failed to pin memory");
898 c_newpath
= env
->GetStringUTFChars(j_newpath
, NULL
);
900 env
->ReleaseStringUTFChars(j_oldpath
, c_oldpath
);
901 cephThrowInternal(env
, "failed to pin memory");
905 ldout(cct
, 10) << "jni: link: oldpath " << c_oldpath
<<
906 " newpath " << c_newpath
<< dendl
;
908 ret
= ceph_link(cmount
, c_oldpath
, c_newpath
);
910 ldout(cct
, 10) << "jni: link: exit ret " << ret
<< dendl
;
912 env
->ReleaseStringUTFChars(j_oldpath
, c_oldpath
);
913 env
->ReleaseStringUTFChars(j_newpath
, c_newpath
);
916 handle_error(env
, ret
);
922 * Class: com_ceph_fs_CephMount
923 * Method: native_ceph_unlink
924 * Signature: (JLjava/lang/String;)I
926 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1unlink
927 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
929 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
930 CephContext
*cct
= ceph_get_mount_context(cmount
);
934 CHECK_ARG_NULL(j_path
, "@path is null", -1);
935 CHECK_MOUNTED(cmount
, -1);
937 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
939 cephThrowInternal(env
, "failed to pin memory");
943 ldout(cct
, 10) << "jni: unlink: path " << c_path
<< dendl
;
945 ret
= ceph_unlink(cmount
, c_path
);
947 ldout(cct
, 10) << "jni: unlink: exit ret " << ret
<< dendl
;
949 env
->ReleaseStringUTFChars(j_path
, c_path
);
952 handle_error(env
, ret
);
958 * Class: com_ceph_fs_CephMount
959 * Method: native_ceph_rename
960 * Signature: (JLjava/lang/String;Ljava/lang/String;)I
962 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1rename
963 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_from
, jstring j_to
)
965 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
966 CephContext
*cct
= ceph_get_mount_context(cmount
);
967 const char *c_from
, *c_to
;
970 CHECK_ARG_NULL(j_from
, "@from is null", -1);
971 CHECK_ARG_NULL(j_to
, "@to is null", -1);
972 CHECK_MOUNTED(cmount
, -1);
974 c_from
= env
->GetStringUTFChars(j_from
, NULL
);
976 cephThrowInternal(env
, "Failed to pin memory!");
980 c_to
= env
->GetStringUTFChars(j_to
, NULL
);
982 env
->ReleaseStringUTFChars(j_from
, c_from
);
983 cephThrowInternal(env
, "Failed to pin memory.");
987 ldout(cct
, 10) << "jni: rename: from " << c_from
<< " to " << c_to
<< dendl
;
989 ret
= ceph_rename(cmount
, c_from
, c_to
);
991 ldout(cct
, 10) << "jni: rename: exit ret " << ret
<< dendl
;
993 env
->ReleaseStringUTFChars(j_from
, c_from
);
994 env
->ReleaseStringUTFChars(j_to
, c_to
);
997 handle_error(env
, ret
);
1003 * Class: com_ceph_fs_CephMount
1004 * Method: native_ceph_mkdir
1005 * Signature: (JLjava/lang/String;I)I
1007 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1mkdir
1008 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jint j_mode
)
1010 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1011 CephContext
*cct
= ceph_get_mount_context(cmount
);
1015 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1016 CHECK_MOUNTED(cmount
, -1);
1018 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1020 cephThrowInternal(env
, "failed to pin memory");
1024 ldout(cct
, 10) << "jni: mkdir: path " << c_path
<< " mode " << (int)j_mode
<< dendl
;
1026 ret
= ceph_mkdir(cmount
, c_path
, (int)j_mode
);
1028 ldout(cct
, 10) << "jni: mkdir: exit ret " << ret
<< dendl
;
1030 env
->ReleaseStringUTFChars(j_path
, c_path
);
1033 handle_error(env
, ret
);
1039 * Class: com_ceph_fs_CephMount
1040 * Method: native_ceph_mkdirs
1041 * Signature: (JLjava/lang/String;I)I
1043 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1mkdirs
1044 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jint j_mode
)
1046 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1047 CephContext
*cct
= ceph_get_mount_context(cmount
);
1051 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1052 CHECK_MOUNTED(cmount
, -1);
1054 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1056 cephThrowInternal(env
, "failed to pin memory");
1060 ldout(cct
, 10) << "jni: mkdirs: path " << c_path
<< " mode " << (int)j_mode
<< dendl
;
1062 ret
= ceph_mkdirs(cmount
, c_path
, (int)j_mode
);
1064 ldout(cct
, 10) << "jni: mkdirs: exit ret " << ret
<< dendl
;
1066 env
->ReleaseStringUTFChars(j_path
, c_path
);
1069 handle_error(env
, ret
);
1075 * Class: com_ceph_fs_CephMount
1076 * Method: native_ceph_rmdir
1077 * Signature: (JLjava/lang/String;)I
1079 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1rmdir
1080 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
1082 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1083 CephContext
*cct
= ceph_get_mount_context(cmount
);
1087 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1088 CHECK_MOUNTED(cmount
, -1);
1090 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1092 cephThrowInternal(env
, "failed to pin memory");
1096 ldout(cct
, 10) << "jni: rmdir: path " << c_path
<< dendl
;
1098 ret
= ceph_rmdir(cmount
, c_path
);
1100 ldout(cct
, 10) << "jni: rmdir: exit ret " << ret
<< dendl
;
1102 env
->ReleaseStringUTFChars(j_path
, c_path
);
1105 handle_error(env
, ret
);
1111 * Class: com_ceph_fs_CephMount
1112 * Method: native_ceph_readlink
1113 * Signature: (JLjava/lang/String;)Ljava/lang/String;
1115 JNIEXPORT jstring JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1readlink
1116 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
1118 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1119 CephContext
*cct
= ceph_get_mount_context(cmount
);
1122 struct ceph_statx stx
;
1125 CHECK_ARG_NULL(j_path
, "@path is null", NULL
);
1126 CHECK_MOUNTED(cmount
, NULL
);
1128 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1130 cephThrowInternal(env
, "failed to pin memory");
1135 ldout(cct
, 10) << "jni: readlink: lstatx " << c_path
<< dendl
;
1136 int ret
= ceph_statx(cmount
, c_path
, &stx
, CEPH_STATX_SIZE
,
1137 AT_SYMLINK_NOFOLLOW
);
1138 ldout(cct
, 10) << "jni: readlink: lstat exit ret " << ret
<< dendl
;
1140 env
->ReleaseStringUTFChars(j_path
, c_path
);
1141 handle_error(env
, ret
);
1145 linkname
= new (std::nothrow
) char[stx
.stx_size
+ 1];
1147 env
->ReleaseStringUTFChars(j_path
, c_path
);
1148 cephThrowOutOfMemory(env
, "head allocation failed");
1152 ldout(cct
, 10) << "jni: readlink: size " << stx
.stx_size
<< " path " << c_path
<< dendl
;
1154 ret
= ceph_readlink(cmount
, c_path
, linkname
, stx
.stx_size
+ 1);
1156 ldout(cct
, 10) << "jni: readlink: exit ret " << ret
<< dendl
;
1160 env
->ReleaseStringUTFChars(j_path
, c_path
);
1161 handle_error(env
, ret
);
1165 /* re-stat and try again */
1166 if (ret
> (int)stx
.stx_size
) {
1171 linkname
[ret
] = '\0';
1175 env
->ReleaseStringUTFChars(j_path
, c_path
);
1177 j_linkname
= env
->NewStringUTF(linkname
);
1184 * Class: com_ceph_fs_CephMount
1185 * Method: native_ceph_symlink
1186 * Signature: (JLjava/lang/String;Ljava/lang/String;)I
1188 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1symlink
1189 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_oldpath
, jstring j_newpath
)
1191 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1192 CephContext
*cct
= ceph_get_mount_context(cmount
);
1193 const char *c_oldpath
, *c_newpath
;
1196 CHECK_ARG_NULL(j_oldpath
, "@oldpath is null", -1);
1197 CHECK_ARG_NULL(j_newpath
, "@newpath is null", -1);
1198 CHECK_MOUNTED(cmount
, -1);
1200 c_oldpath
= env
->GetStringUTFChars(j_oldpath
, NULL
);
1202 cephThrowInternal(env
, "failed to pin memory");
1206 c_newpath
= env
->GetStringUTFChars(j_newpath
, NULL
);
1208 env
->ReleaseStringUTFChars(j_oldpath
, c_oldpath
);
1209 cephThrowInternal(env
, "failed to pin memory");
1213 ldout(cct
, 10) << "jni: symlink: oldpath " << c_oldpath
<<
1214 " newpath " << c_newpath
<< dendl
;
1216 ret
= ceph_symlink(cmount
, c_oldpath
, c_newpath
);
1218 ldout(cct
, 10) << "jni: symlink: exit ret " << ret
<< dendl
;
1220 env
->ReleaseStringUTFChars(j_oldpath
, c_oldpath
);
1221 env
->ReleaseStringUTFChars(j_newpath
, c_newpath
);
1224 handle_error(env
, ret
);
1229 #define CEPH_J_CEPHSTAT_MASK (CEPH_STATX_UID|CEPH_STATX_GID|CEPH_STATX_SIZE|CEPH_STATX_BLOCKS|CEPH_STATX_MTIME|CEPH_STATX_ATIME)
1231 static void fill_cephstat(JNIEnv
*env
, jobject j_cephstat
, struct ceph_statx
*stx
)
1233 env
->SetIntField(j_cephstat
, cephstat_mode_fid
, stx
->stx_mode
);
1234 env
->SetIntField(j_cephstat
, cephstat_uid_fid
, stx
->stx_uid
);
1235 env
->SetIntField(j_cephstat
, cephstat_gid_fid
, stx
->stx_gid
);
1236 env
->SetLongField(j_cephstat
, cephstat_size_fid
, stx
->stx_size
);
1237 env
->SetLongField(j_cephstat
, cephstat_blksize_fid
, stx
->stx_blksize
);
1238 env
->SetLongField(j_cephstat
, cephstat_blocks_fid
, stx
->stx_blocks
);
1240 long long time
= stx
->stx_mtime
.tv_sec
;
1242 time
+= stx
->stx_mtime
.tv_nsec
/ 1000000;
1243 env
->SetLongField(j_cephstat
, cephstat_m_time_fid
, time
);
1245 time
= stx
->stx_atime
.tv_sec
;
1247 time
+= stx
->stx_atime
.tv_nsec
/ 1000000;
1248 env
->SetLongField(j_cephstat
, cephstat_a_time_fid
, time
);
1250 env
->SetBooleanField(j_cephstat
, cephstat_is_file_fid
,
1251 S_ISREG(stx
->stx_mode
) ? JNI_TRUE
: JNI_FALSE
);
1253 env
->SetBooleanField(j_cephstat
, cephstat_is_directory_fid
,
1254 S_ISDIR(stx
->stx_mode
) ? JNI_TRUE
: JNI_FALSE
);
1256 env
->SetBooleanField(j_cephstat
, cephstat_is_symlink_fid
,
1257 S_ISLNK(stx
->stx_mode
) ? JNI_TRUE
: JNI_FALSE
);
1261 * Class: com_ceph_fs_CephMount
1262 * Method: native_ceph_lstat
1263 * Signature: (JLjava/lang/String;Lcom/ceph/fs/CephStat;)I
1265 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1lstat
1266 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jobject j_cephstat
)
1268 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1269 CephContext
*cct
= ceph_get_mount_context(cmount
);
1271 struct ceph_statx stx
;
1274 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1275 CHECK_ARG_NULL(j_cephstat
, "@stat is null", -1);
1276 CHECK_MOUNTED(cmount
, -1);
1278 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1280 cephThrowInternal(env
, "Failed to pin memory");
1284 ldout(cct
, 10) << "jni: lstat: path " << c_path
<< dendl
;
1286 ret
= ceph_statx(cmount
, c_path
, &stx
, CEPH_J_CEPHSTAT_MASK
, AT_SYMLINK_NOFOLLOW
);
1288 ldout(cct
, 10) << "jni: lstat exit ret " << ret
<< dendl
;
1290 env
->ReleaseStringUTFChars(j_path
, c_path
);
1293 handle_error(env
, ret
);
1297 fill_cephstat(env
, j_cephstat
, &stx
);
1303 * Class: com_ceph_fs_CephMount
1304 * Method: native_ceph_stat
1305 * Signature: (JLjava/lang/String;Lcom/ceph/fs/CephStat;)I
1307 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1stat
1308 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jobject j_cephstat
)
1310 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1311 CephContext
*cct
= ceph_get_mount_context(cmount
);
1313 struct ceph_statx stx
;
1316 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1317 CHECK_ARG_NULL(j_cephstat
, "@stat is null", -1);
1318 CHECK_MOUNTED(cmount
, -1);
1320 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1322 cephThrowInternal(env
, "Failed to pin memory");
1326 ldout(cct
, 10) << "jni: stat: path " << c_path
<< dendl
;
1328 ret
= ceph_statx(cmount
, c_path
, &stx
, CEPH_J_CEPHSTAT_MASK
, 0);
1330 ldout(cct
, 10) << "jni: stat exit ret " << ret
<< dendl
;
1332 env
->ReleaseStringUTFChars(j_path
, c_path
);
1335 handle_error(env
, ret
);
1339 fill_cephstat(env
, j_cephstat
, &stx
);
1345 * Class: com_ceph_fs_CephMount
1346 * Method: native_ceph_setattr
1347 * Signature: (JLjava/lang/String;Lcom/ceph/fs/CephStat;I)I
1349 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1setattr
1350 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jobject j_cephstat
, jint j_mask
)
1352 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1353 CephContext
*cct
= ceph_get_mount_context(cmount
);
1355 struct ceph_statx stx
;
1356 int ret
, mask
= fixup_attr_mask(j_mask
);
1358 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1359 CHECK_ARG_NULL(j_cephstat
, "@stat is null", -1);
1360 CHECK_MOUNTED(cmount
, -1);
1362 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1364 cephThrowInternal(env
, "Failed to pin memory");
1368 memset(&stx
, 0, sizeof(stx
));
1370 stx
.stx_mode
= env
->GetIntField(j_cephstat
, cephstat_mode_fid
);
1371 stx
.stx_uid
= env
->GetIntField(j_cephstat
, cephstat_uid_fid
);
1372 stx
.stx_gid
= env
->GetIntField(j_cephstat
, cephstat_gid_fid
);
1373 long mtime_msec
= env
->GetLongField(j_cephstat
, cephstat_m_time_fid
);
1374 long atime_msec
= env
->GetLongField(j_cephstat
, cephstat_a_time_fid
);
1375 stx
.stx_mtime
.tv_sec
= mtime_msec
/ 1000;
1376 stx
.stx_mtime
.tv_nsec
= (mtime_msec
% 1000) * 1000000;
1377 stx
.stx_atime
.tv_sec
= atime_msec
/ 1000;
1378 stx
.stx_atime
.tv_nsec
= (atime_msec
% 1000) * 1000000;
1380 ldout(cct
, 10) << "jni: setattr: path " << c_path
<< " mask " << mask
<< dendl
;
1382 ret
= ceph_setattrx(cmount
, c_path
, &stx
, mask
, 0);
1384 ldout(cct
, 10) << "jni: setattr: exit ret " << ret
<< dendl
;
1386 env
->ReleaseStringUTFChars(j_path
, c_path
);
1389 handle_error(env
, ret
);
1395 * Class: com_ceph_fs_CephMount
1396 * Method: native_ceph_chmod
1397 * Signature: (JLjava/lang/String;I)I
1399 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1chmod
1400 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jint j_mode
)
1402 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1403 CephContext
*cct
= ceph_get_mount_context(cmount
);
1407 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1408 CHECK_MOUNTED(cmount
, -1);
1410 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1412 cephThrowInternal(env
, "Failed to pin memory");
1416 ldout(cct
, 10) << "jni: chmod: path " << c_path
<< " mode " << (int)j_mode
<< dendl
;
1418 ret
= ceph_chmod(cmount
, c_path
, (int)j_mode
);
1420 ldout(cct
, 10) << "jni: chmod: exit ret " << ret
<< dendl
;
1422 env
->ReleaseStringUTFChars(j_path
, c_path
);
1425 handle_error(env
, ret
);
1431 * Class: com_ceph_fs_CephMount
1432 * Method: native_ceph_fchmod
1435 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1fchmod
1436 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jint j_mode
)
1438 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1439 CephContext
*cct
= ceph_get_mount_context(cmount
);
1442 CHECK_MOUNTED(cmount
, -1);
1444 ldout(cct
, 10) << "jni: fchmod: fd " << (int)j_fd
<< " mode " << (int)j_mode
<< dendl
;
1446 ret
= ceph_fchmod(cmount
, (int)j_fd
, (int)j_mode
);
1448 ldout(cct
, 10) << "jni: fchmod: exit ret " << ret
<< dendl
;
1451 handle_error(env
, ret
);
1457 * Class: com_ceph_fs_CephMount
1458 * Method: native_ceph_truncate
1459 * Signature: (JLjava/lang/String;J)I
1461 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1truncate
1462 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jlong j_size
)
1464 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1465 CephContext
*cct
= ceph_get_mount_context(cmount
);
1469 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1470 CHECK_MOUNTED(cmount
, -1);
1472 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1474 cephThrowInternal(env
, "Failed to pin memory");
1478 ldout(cct
, 10) << "jni: truncate: path " << c_path
<< " size " << (loff_t
)j_size
<< dendl
;
1480 ret
= ceph_truncate(cmount
, c_path
, (loff_t
)j_size
);
1482 ldout(cct
, 10) << "jni: truncate: exit ret " << ret
<< dendl
;
1484 env
->ReleaseStringUTFChars(j_path
, c_path
);
1487 handle_error(env
, ret
);
1493 * Class: com_ceph_fs_CephMount
1494 * Method: native_ceph_open
1495 * Signature: (JLjava/lang/String;II)I
1497 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1open
1498 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jint j_flags
, jint j_mode
)
1500 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1501 CephContext
*cct
= ceph_get_mount_context(cmount
);
1503 int ret
, flags
= fixup_open_flags(j_flags
);
1505 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1506 CHECK_MOUNTED(cmount
, -1);
1508 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1510 cephThrowInternal(env
, "Failed to pin memory");
1514 ldout(cct
, 10) << "jni: open: path " << c_path
<< " flags " << flags
1515 << " mode " << (int)j_mode
<< dendl
;
1517 ret
= ceph_open(cmount
, c_path
, flags
, (int)j_mode
);
1519 ldout(cct
, 10) << "jni: open: exit ret " << ret
<< dendl
;
1521 env
->ReleaseStringUTFChars(j_path
, c_path
);
1524 handle_error(env
, ret
);
1530 * Class: com_ceph_fs_CephMount
1531 * Method: native_ceph_open_layout
1532 * Signature: (JLjava/lang/String;IIIIILjava/lang/String;)I
1534 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1open_1layout
1535 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jint j_flags
, jint j_mode
,
1536 jint stripe_unit
, jint stripe_count
, jint object_size
, jstring j_data_pool
)
1538 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1539 CephContext
*cct
= ceph_get_mount_context(cmount
);
1540 const char *c_path
, *c_data_pool
= NULL
;
1541 int ret
, flags
= fixup_open_flags(j_flags
);
1543 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1544 CHECK_MOUNTED(cmount
, -1);
1546 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1548 cephThrowInternal(env
, "Failed to pin memory");
1553 c_data_pool
= env
->GetStringUTFChars(j_data_pool
, NULL
);
1555 env
->ReleaseStringUTFChars(j_path
, c_path
);
1556 cephThrowInternal(env
, "Failed to pin memory");
1561 ldout(cct
, 10) << "jni: open_layout: path " << c_path
<< " flags " << flags
1562 << " mode " << (int)j_mode
<< " stripe_unit " << stripe_unit
1563 << " stripe_count " << stripe_count
<< " object_size " << object_size
1564 << " data_pool " << (c_data_pool
? c_data_pool
: "<NULL>") << dendl
;
1566 ret
= ceph_open_layout(cmount
, c_path
, flags
, (int)j_mode
,
1567 (int)stripe_unit
, (int)stripe_count
, (int)object_size
, c_data_pool
);
1569 ldout(cct
, 10) << "jni: open_layout: exit ret " << ret
<< dendl
;
1571 env
->ReleaseStringUTFChars(j_path
, c_path
);
1573 env
->ReleaseStringUTFChars(j_data_pool
, c_data_pool
);
1576 handle_error(env
, ret
);
1582 * Class: com_ceph_fs_CephMount
1583 * Method: native_ceph_close
1586 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1close
1587 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
)
1589 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1590 CephContext
*cct
= ceph_get_mount_context(cmount
);
1593 CHECK_MOUNTED(cmount
, -1);
1595 ldout(cct
, 10) << "jni: close: fd " << (int)j_fd
<< dendl
;
1597 ret
= ceph_close(cmount
, (int)j_fd
);
1599 ldout(cct
, 10) << "jni: close: ret " << ret
<< dendl
;
1602 handle_error(env
, ret
);
1608 * Class: com_ceph_fs_CephMount
1609 * Method: native_ceph_lseek
1610 * Signature: (JIJI)J
1612 JNIEXPORT jlong JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1lseek
1613 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jlong j_offset
, jint j_whence
)
1615 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1616 CephContext
*cct
= ceph_get_mount_context(cmount
);
1620 CHECK_MOUNTED(cmount
, -1);
1633 cephThrowIllegalArg(env
, "Unknown whence value");
1637 ldout(cct
, 10) << "jni: lseek: fd " << (int)j_fd
<< " offset "
1638 << (long)j_offset
<< " whence " << whence
<< dendl
;
1640 ret
= ceph_lseek(cmount
, (int)j_fd
, (long)j_offset
, whence
);
1642 ldout(cct
, 10) << "jni: lseek: exit ret " << ret
<< dendl
;
1645 handle_error(env
, ret
);
1651 * Class: com_ceph_fs_CephMount
1652 * Method: native_ceph_read
1653 * Signature: (JI[BJJ)J
1655 JNIEXPORT jlong JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1read
1656 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jbyteArray j_buf
, jlong j_size
, jlong j_offset
)
1658 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1659 CephContext
*cct
= ceph_get_mount_context(cmount
);
1664 CHECK_ARG_NULL(j_buf
, "@buf is null", -1);
1665 CHECK_ARG_BOUNDS(j_size
< 0, "@size is negative", -1);
1666 CHECK_MOUNTED(cmount
, -1);
1668 buf_size
= env
->GetArrayLength(j_buf
);
1669 CHECK_ARG_BOUNDS(j_size
> buf_size
, "@size > @buf.length", -1);
1671 c_buf
= env
->GetByteArrayElements(j_buf
, NULL
);
1673 cephThrowInternal(env
, "failed to pin memory");
1677 ldout(cct
, 10) << "jni: read: fd " << (int)j_fd
<< " len " << (long)j_size
<<
1678 " offset " << (long)j_offset
<< dendl
;
1680 ret
= ceph_read(cmount
, (int)j_fd
, (char*)c_buf
, (long)j_size
, (long)j_offset
);
1682 ldout(cct
, 10) << "jni: read: exit ret " << ret
<< dendl
;
1685 handle_error(env
, (int)ret
);
1687 env
->ReleaseByteArrayElements(j_buf
, c_buf
, 0);
1693 * Class: com_ceph_fs_CephMount
1694 * Method: native_ceph_write
1695 * Signature: (JI[BJJ)J
1697 JNIEXPORT jlong JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1write
1698 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jbyteArray j_buf
, jlong j_size
, jlong j_offset
)
1700 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1701 CephContext
*cct
= ceph_get_mount_context(cmount
);
1706 CHECK_ARG_NULL(j_buf
, "@buf is null", -1);
1707 CHECK_ARG_BOUNDS(j_size
< 0, "@size is negative", -1);
1708 CHECK_MOUNTED(cmount
, -1);
1710 buf_size
= env
->GetArrayLength(j_buf
);
1711 CHECK_ARG_BOUNDS(j_size
> buf_size
, "@size > @buf.length", -1);
1713 c_buf
= env
->GetByteArrayElements(j_buf
, NULL
);
1715 cephThrowInternal(env
, "failed to pin memory");
1719 ldout(cct
, 10) << "jni: write: fd " << (int)j_fd
<< " len " << (long)j_size
<<
1720 " offset " << (long)j_offset
<< dendl
;
1722 ret
= ceph_write(cmount
, (int)j_fd
, (char*)c_buf
, (long)j_size
, (long)j_offset
);
1724 ldout(cct
, 10) << "jni: write: exit ret " << ret
<< dendl
;
1727 handle_error(env
, (int)ret
);
1729 env
->ReleaseByteArrayElements(j_buf
, c_buf
, JNI_ABORT
);
1736 * Class: com_ceph_fs_CephMount
1737 * Method: native_ceph_ftruncate
1740 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1ftruncate
1741 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jlong j_size
)
1743 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1744 CephContext
*cct
= ceph_get_mount_context(cmount
);
1747 CHECK_MOUNTED(cmount
, -1);
1749 ldout(cct
, 10) << "jni: ftruncate: fd " << (int)j_fd
<<
1750 " size " << (loff_t
)j_size
<< dendl
;
1752 ret
= ceph_ftruncate(cmount
, (int)j_fd
, (loff_t
)j_size
);
1754 ldout(cct
, 10) << "jni: ftruncate: exit ret " << ret
<< dendl
;
1757 handle_error(env
, ret
);
1763 * Class: com_ceph_fs_CephMount
1764 * Method: native_ceph_fsync
1767 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1fsync
1768 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jboolean j_dataonly
)
1770 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1771 CephContext
*cct
= ceph_get_mount_context(cmount
);
1774 ldout(cct
, 10) << "jni: fsync: fd " << (int)j_fd
<<
1775 " dataonly " << (j_dataonly
? 1 : 0) << dendl
;
1777 ret
= ceph_fsync(cmount
, (int)j_fd
, j_dataonly
? 1 : 0);
1779 ldout(cct
, 10) << "jni: fsync: exit ret " << ret
<< dendl
;
1782 handle_error(env
, ret
);
1788 * Class: com_ceph_fs_CephMount
1789 * Method: native_ceph_flock
1792 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1flock
1793 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jint j_operation
, jlong j_owner
)
1795 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1796 CephContext
*cct
= ceph_get_mount_context(cmount
);
1799 ldout(cct
, 10) << "jni: flock: fd " << (int)j_fd
<<
1800 " operation " << j_operation
<< " owner " << j_owner
<< dendl
;
1804 #define MAP_FLOCK_FLAG(JNI_MASK, NATIVE_MASK) do { \
1805 if ((j_operation & JNI_MASK) != 0) { \
1806 operation |= NATIVE_MASK; \
1807 j_operation &= ~JNI_MASK; \
1810 MAP_FLOCK_FLAG(JAVA_LOCK_SH
, LOCK_SH
);
1811 MAP_FLOCK_FLAG(JAVA_LOCK_EX
, LOCK_EX
);
1812 MAP_FLOCK_FLAG(JAVA_LOCK_NB
, LOCK_NB
);
1813 MAP_FLOCK_FLAG(JAVA_LOCK_UN
, LOCK_UN
);
1814 if (j_operation
!= 0) {
1815 cephThrowIllegalArg(env
, "flock flags");
1818 #undef MAP_FLOCK_FLAG
1820 ret
= ceph_flock(cmount
, (int)j_fd
, operation
, (uint64_t) j_owner
);
1822 ldout(cct
, 10) << "jni: flock: exit ret " << ret
<< dendl
;
1825 handle_error(env
, ret
);
1831 * Class: com_ceph_fs_CephMount
1832 * Method: native_ceph_fstat
1833 * Signature: (JILcom/ceph/fs/CephStat;)I
1835 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1fstat
1836 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
, jobject j_cephstat
)
1838 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1839 CephContext
*cct
= ceph_get_mount_context(cmount
);
1840 struct ceph_statx stx
;
1843 CHECK_ARG_NULL(j_cephstat
, "@stat is null", -1);
1844 CHECK_MOUNTED(cmount
, -1);
1846 ldout(cct
, 10) << "jni: fstat: fd " << (int)j_fd
<< dendl
;
1848 ret
= ceph_fstatx(cmount
, (int)j_fd
, &stx
, CEPH_J_CEPHSTAT_MASK
, 0);
1850 ldout(cct
, 10) << "jni: fstat exit ret " << ret
<< dendl
;
1853 handle_error(env
, ret
);
1857 fill_cephstat(env
, j_cephstat
, &stx
);
1863 * Class: com_ceph_fs_CephMount
1864 * Method: native_ceph_sync_fs
1867 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1sync_1fs
1868 (JNIEnv
*env
, jclass clz
, jlong j_mntp
)
1870 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1871 CephContext
*cct
= ceph_get_mount_context(cmount
);
1874 ldout(cct
, 10) << "jni: sync_fs: enter" << dendl
;
1876 ret
= ceph_sync_fs(cmount
);
1878 ldout(cct
, 10) << "jni: sync_fs: exit ret " << ret
<< dendl
;
1881 handle_error(env
, ret
);
1887 * Class: com_ceph_fs_CephMount
1888 * Method: native_ceph_getxattr
1889 * Signature: (JLjava/lang/String;Ljava/lang/String;[B)J
1891 JNIEXPORT jlong JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1getxattr
1892 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jstring j_name
, jbyteArray j_buf
)
1894 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1895 CephContext
*cct
= ceph_get_mount_context(cmount
);
1899 jbyte
*c_buf
= NULL
; /* please gcc with goto */
1902 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1903 CHECK_ARG_NULL(j_name
, "@name is null", -1);
1904 CHECK_MOUNTED(cmount
, -1);
1906 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1908 cephThrowInternal(env
, "Failed to pin memory");
1912 c_name
= env
->GetStringUTFChars(j_name
, NULL
);
1914 env
->ReleaseStringUTFChars(j_path
, c_path
);
1915 cephThrowInternal(env
, "Failed to pin memory");
1919 /* just lookup the size if buf is null */
1925 c_buf
= env
->GetByteArrayElements(j_buf
, NULL
);
1927 env
->ReleaseStringUTFChars(j_path
, c_path
);
1928 env
->ReleaseStringUTFChars(j_name
, c_name
);
1929 cephThrowInternal(env
, "failed to pin memory");
1933 buf_size
= env
->GetArrayLength(j_buf
);
1937 ldout(cct
, 10) << "jni: getxattr: path " << c_path
<< " name " << c_name
<<
1938 " len " << buf_size
<< dendl
;
1940 ret
= ceph_getxattr(cmount
, c_path
, c_name
, c_buf
, buf_size
);
1942 ret
= ceph_getxattr(cmount
, c_path
, c_name
, c_buf
, 0);
1944 ldout(cct
, 10) << "jni: getxattr: exit ret " << ret
<< dendl
;
1946 env
->ReleaseStringUTFChars(j_path
, c_path
);
1947 env
->ReleaseStringUTFChars(j_name
, c_name
);
1949 env
->ReleaseByteArrayElements(j_buf
, c_buf
, 0);
1952 handle_error(env
, (int)ret
);
1958 * Class: com_ceph_fs_CephMount
1959 * Method: native_ceph_lgetxattr
1960 * Signature: (JLjava/lang/String;Ljava/lang/String;[B)I
1962 JNIEXPORT jlong JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1lgetxattr
1963 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jstring j_name
, jbyteArray j_buf
)
1965 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
1966 CephContext
*cct
= ceph_get_mount_context(cmount
);
1970 jbyte
*c_buf
= NULL
; /* please gcc with goto */
1973 CHECK_ARG_NULL(j_path
, "@path is null", -1);
1974 CHECK_ARG_NULL(j_name
, "@name is null", -1);
1975 CHECK_MOUNTED(cmount
, -1);
1977 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
1979 cephThrowInternal(env
, "Failed to pin memory");
1983 c_name
= env
->GetStringUTFChars(j_name
, NULL
);
1985 env
->ReleaseStringUTFChars(j_path
, c_path
);
1986 cephThrowInternal(env
, "Failed to pin memory");
1990 /* just lookup the size if buf is null */
1996 c_buf
= env
->GetByteArrayElements(j_buf
, NULL
);
1998 env
->ReleaseStringUTFChars(j_path
, c_path
);
1999 env
->ReleaseStringUTFChars(j_name
, c_name
);
2000 cephThrowInternal(env
, "failed to pin memory");
2004 buf_size
= env
->GetArrayLength(j_buf
);
2008 ldout(cct
, 10) << "jni: lgetxattr: path " << c_path
<< " name " << c_name
<<
2009 " len " << buf_size
<< dendl
;
2011 ret
= ceph_lgetxattr(cmount
, c_path
, c_name
, c_buf
, buf_size
);
2013 ret
= ceph_lgetxattr(cmount
, c_path
, c_name
, c_buf
, 0);
2015 ldout(cct
, 10) << "jni: lgetxattr: exit ret " << ret
<< dendl
;
2017 env
->ReleaseStringUTFChars(j_path
, c_path
);
2018 env
->ReleaseStringUTFChars(j_name
, c_name
);
2020 env
->ReleaseByteArrayElements(j_buf
, c_buf
, 0);
2023 handle_error(env
, (int)ret
);
2029 * Class: com_ceph_fs_CephMount
2030 * Method: native_ceph_listxattr
2031 * Signature: (JLjava/lang/String;)[Ljava/lang/String;
2033 JNIEXPORT jobjectArray JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1listxattr
2034 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
2036 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2037 CephContext
*cct
= ceph_get_mount_context(cmount
);
2038 jobjectArray xattrlist
;
2042 list
<string
>::iterator it
;
2043 list
<string
> contents
;
2044 int ret
, buflen
, bufpos
, i
;
2047 CHECK_ARG_NULL(j_path
, "@path is null", NULL
);
2048 CHECK_MOUNTED(cmount
, NULL
);
2050 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
2052 cephThrowInternal(env
, "Failed to pin memory");
2057 buf
= new (std::nothrow
) char[buflen
];
2059 cephThrowOutOfMemory(env
, "head allocation failed");
2064 ldout(cct
, 10) << "jni: listxattr: path " << c_path
<< " len " << buflen
<< dendl
;
2065 ret
= ceph_listxattr(cmount
, c_path
, buf
, buflen
);
2066 if (ret
== -ERANGE
) {
2069 buf
= new (std::nothrow
) char[buflen
];
2071 cephThrowOutOfMemory(env
, "heap allocation failed");
2079 ldout(cct
, 10) << "jni: listxattr: ret " << ret
<< dendl
;
2083 handle_error(env
, ret
);
2088 while (bufpos
< ret
) {
2089 ent
= new (std::nothrow
) string(buf
+ bufpos
);
2092 cephThrowOutOfMemory(env
, "heap allocation failed");
2095 contents
.push_back(*ent
);
2096 bufpos
+= ent
->size() + 1;
2102 xattrlist
= env
->NewObjectArray(contents
.size(), env
->FindClass("java/lang/String"), NULL
);
2106 for (i
= 0, it
= contents
.begin(); it
!= contents
.end(); ++it
) {
2107 name
= env
->NewStringUTF(it
->c_str());
2110 env
->SetObjectArrayElement(xattrlist
, i
++, name
);
2111 if (env
->ExceptionOccurred())
2113 env
->DeleteLocalRef(name
);
2116 env
->ReleaseStringUTFChars(j_path
, c_path
);
2120 env
->ReleaseStringUTFChars(j_path
, c_path
);
2125 * Class: com_ceph_fs_CephMount
2126 * Method: native_ceph_llistxattr
2127 * Signature: (JLjava/lang/String;)[Ljava/lang/String;
2129 JNIEXPORT jobjectArray JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1llistxattr
2130 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
)
2132 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2133 CephContext
*cct
= ceph_get_mount_context(cmount
);
2134 jobjectArray xattrlist
;
2138 list
<string
>::iterator it
;
2139 list
<string
> contents
;
2140 int ret
, buflen
, bufpos
, i
;
2143 CHECK_ARG_NULL(j_path
, "@path is null", NULL
);
2144 CHECK_MOUNTED(cmount
, NULL
);
2146 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
2148 cephThrowInternal(env
, "Failed to pin memory");
2153 buf
= new (std::nothrow
) char[buflen
];
2155 cephThrowOutOfMemory(env
, "head allocation failed");
2160 ldout(cct
, 10) << "jni: llistxattr: path " << c_path
<< " len " << buflen
<< dendl
;
2161 ret
= ceph_llistxattr(cmount
, c_path
, buf
, buflen
);
2162 if (ret
== -ERANGE
) {
2165 buf
= new (std::nothrow
) char[buflen
];
2167 cephThrowOutOfMemory(env
, "heap allocation failed");
2175 ldout(cct
, 10) << "jni: llistxattr: ret " << ret
<< dendl
;
2179 handle_error(env
, ret
);
2184 while (bufpos
< ret
) {
2185 ent
= new (std::nothrow
) string(buf
+ bufpos
);
2188 cephThrowOutOfMemory(env
, "heap allocation failed");
2191 contents
.push_back(*ent
);
2192 bufpos
+= ent
->size() + 1;
2198 xattrlist
= env
->NewObjectArray(contents
.size(), env
->FindClass("java/lang/String"), NULL
);
2202 for (i
= 0, it
= contents
.begin(); it
!= contents
.end(); ++it
) {
2203 name
= env
->NewStringUTF(it
->c_str());
2206 env
->SetObjectArrayElement(xattrlist
, i
++, name
);
2207 if (env
->ExceptionOccurred())
2209 env
->DeleteLocalRef(name
);
2212 env
->ReleaseStringUTFChars(j_path
, c_path
);
2216 env
->ReleaseStringUTFChars(j_path
, c_path
);
2221 * Class: com_ceph_fs_CephMount
2222 * Method: native_ceph_removexattr
2223 * Signature: (JLjava/lang/String;Ljava/lang/String;)I
2225 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1removexattr
2226 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jstring j_name
)
2228 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2229 CephContext
*cct
= ceph_get_mount_context(cmount
);
2234 CHECK_ARG_NULL(j_path
, "@path is null", -1);
2235 CHECK_ARG_NULL(j_name
, "@name is null", -1);
2236 CHECK_MOUNTED(cmount
, -1);
2238 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
2240 cephThrowInternal(env
, "Failed to pin memory");
2244 c_name
= env
->GetStringUTFChars(j_name
, NULL
);
2246 env
->ReleaseStringUTFChars(j_path
, c_path
);
2247 cephThrowInternal(env
, "Failed to pin memory");
2251 ldout(cct
, 10) << "jni: removexattr: path " << c_path
<< " name " << c_name
<< dendl
;
2253 ret
= ceph_removexattr(cmount
, c_path
, c_name
);
2255 ldout(cct
, 10) << "jni: removexattr: exit ret " << ret
<< dendl
;
2257 env
->ReleaseStringUTFChars(j_path
, c_path
);
2258 env
->ReleaseStringUTFChars(j_name
, c_name
);
2261 handle_error(env
, ret
);
2267 * Class: com_ceph_fs_CephMount
2268 * Method: native_ceph_lremovexattr
2269 * Signature: (JLjava/lang/String;Ljava/lang/String;)I
2271 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1lremovexattr
2272 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jstring j_name
)
2274 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2275 CephContext
*cct
= ceph_get_mount_context(cmount
);
2280 CHECK_ARG_NULL(j_path
, "@path is null", -1);
2281 CHECK_ARG_NULL(j_name
, "@name is null", -1);
2282 CHECK_MOUNTED(cmount
, -1);
2284 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
2286 cephThrowInternal(env
, "Failed to pin memory");
2290 c_name
= env
->GetStringUTFChars(j_name
, NULL
);
2292 env
->ReleaseStringUTFChars(j_path
, c_path
);
2293 cephThrowInternal(env
, "Failed to pin memory");
2297 ldout(cct
, 10) << "jni: lremovexattr: path " << c_path
<< " name " << c_name
<< dendl
;
2299 ret
= ceph_lremovexattr(cmount
, c_path
, c_name
);
2301 ldout(cct
, 10) << "jni: lremovexattr: exit ret " << ret
<< dendl
;
2303 env
->ReleaseStringUTFChars(j_path
, c_path
);
2304 env
->ReleaseStringUTFChars(j_name
, c_name
);
2307 handle_error(env
, ret
);
2313 * Class: com_ceph_fs_CephMount
2314 * Method: native_ceph_setxattr
2315 * Signature: (JLjava/lang/String;Ljava/lang/String;[BJI)I
2317 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1setxattr
2318 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jstring j_name
,
2319 jbyteArray j_buf
, jlong j_size
, jint j_flags
)
2321 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2322 CephContext
*cct
= ceph_get_mount_context(cmount
);
2329 CHECK_ARG_NULL(j_path
, "@path is null", -1);
2330 CHECK_ARG_NULL(j_name
, "@name is null", -1);
2331 CHECK_ARG_NULL(j_buf
, "@buf is null", -1);
2332 CHECK_ARG_BOUNDS(j_size
< 0, "@size is negative", -1);
2333 CHECK_MOUNTED(cmount
, -1);
2335 buf_size
= env
->GetArrayLength(j_buf
);
2336 CHECK_ARG_BOUNDS(j_size
> buf_size
, "@size > @buf.length", -1);
2338 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
2340 cephThrowInternal(env
, "Failed to pin memory");
2344 c_name
= env
->GetStringUTFChars(j_name
, NULL
);
2346 env
->ReleaseStringUTFChars(j_path
, c_path
);
2347 cephThrowInternal(env
, "Failed to pin memory");
2351 c_buf
= env
->GetByteArrayElements(j_buf
, NULL
);
2353 env
->ReleaseStringUTFChars(j_path
, c_path
);
2354 env
->ReleaseStringUTFChars(j_name
, c_name
);
2355 cephThrowInternal(env
, "failed to pin memory");
2360 case JAVA_XATTR_CREATE
:
2361 flags
= CEPH_XATTR_CREATE
;
2363 case JAVA_XATTR_REPLACE
:
2364 flags
= CEPH_XATTR_REPLACE
;
2366 case JAVA_XATTR_NONE
:
2370 env
->ReleaseStringUTFChars(j_path
, c_path
);
2371 env
->ReleaseStringUTFChars(j_name
, c_name
);
2372 env
->ReleaseByteArrayElements(j_buf
, c_buf
, JNI_ABORT
);
2373 cephThrowIllegalArg(env
, "setxattr flag");
2377 ldout(cct
, 10) << "jni: setxattr: path " << c_path
<< " name " << c_name
2378 << " len " << j_size
<< " flags " << flags
<< dendl
;
2380 ret
= ceph_setxattr(cmount
, c_path
, c_name
, c_buf
, j_size
, flags
);
2382 ldout(cct
, 10) << "jni: setxattr: exit ret " << ret
<< dendl
;
2384 env
->ReleaseStringUTFChars(j_path
, c_path
);
2385 env
->ReleaseStringUTFChars(j_name
, c_name
);
2386 env
->ReleaseByteArrayElements(j_buf
, c_buf
, JNI_ABORT
);
2389 handle_error(env
, ret
);
2395 * Class: com_ceph_fs_CephMount
2396 * Method: native_ceph_lsetxattr
2397 * Signature: (JLjava/lang/String;Ljava/lang/String;[BJI)I
2399 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1lsetxattr
2400 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring j_path
, jstring j_name
,
2401 jbyteArray j_buf
, jlong j_size
, jint j_flags
)
2403 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2404 CephContext
*cct
= ceph_get_mount_context(cmount
);
2411 CHECK_ARG_NULL(j_path
, "@path is null", -1);
2412 CHECK_ARG_NULL(j_name
, "@name is null", -1);
2413 CHECK_ARG_NULL(j_buf
, "@buf is null", -1);
2414 CHECK_ARG_BOUNDS(j_size
< 0, "@size is negative", -1);
2415 CHECK_MOUNTED(cmount
, -1);
2417 buf_size
= env
->GetArrayLength(j_buf
);
2418 CHECK_ARG_BOUNDS(j_size
> buf_size
, "@size > @buf.length", -1);
2420 c_path
= env
->GetStringUTFChars(j_path
, NULL
);
2422 cephThrowInternal(env
, "Failed to pin memory");
2426 c_name
= env
->GetStringUTFChars(j_name
, NULL
);
2428 env
->ReleaseStringUTFChars(j_path
, c_path
);
2429 cephThrowInternal(env
, "Failed to pin memory");
2433 c_buf
= env
->GetByteArrayElements(j_buf
, NULL
);
2435 env
->ReleaseStringUTFChars(j_path
, c_path
);
2436 env
->ReleaseStringUTFChars(j_name
, c_name
);
2437 cephThrowInternal(env
, "failed to pin memory");
2442 case JAVA_XATTR_CREATE
:
2443 flags
= CEPH_XATTR_CREATE
;
2445 case JAVA_XATTR_REPLACE
:
2446 flags
= CEPH_XATTR_REPLACE
;
2448 case JAVA_XATTR_NONE
:
2452 env
->ReleaseStringUTFChars(j_path
, c_path
);
2453 env
->ReleaseStringUTFChars(j_name
, c_name
);
2454 env
->ReleaseByteArrayElements(j_buf
, c_buf
, JNI_ABORT
);
2455 cephThrowIllegalArg(env
, "lsetxattr flag");
2459 ldout(cct
, 10) << "jni: lsetxattr: path " << c_path
<< " name " << c_name
2460 << " len " << j_size
<< " flags " << flags
<< dendl
;
2462 ret
= ceph_lsetxattr(cmount
, c_path
, c_name
, c_buf
, j_size
, flags
);
2464 ldout(cct
, 10) << "jni: lsetxattr: exit ret " << ret
<< dendl
;
2466 env
->ReleaseStringUTFChars(j_path
, c_path
);
2467 env
->ReleaseStringUTFChars(j_name
, c_name
);
2468 env
->ReleaseByteArrayElements(j_buf
, c_buf
, JNI_ABORT
);
2471 handle_error(env
, ret
);
2477 * Class: com_ceph_fs_CephMount
2478 * Method: native_ceph_get_file_stripe_unit
2481 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1file_1stripe_1unit
2482 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
)
2484 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2485 CephContext
*cct
= ceph_get_mount_context(cmount
);
2488 CHECK_MOUNTED(cmount
, -1);
2490 ldout(cct
, 10) << "jni: get_file_stripe_unit: fd " << (int)j_fd
<< dendl
;
2492 ret
= ceph_get_file_stripe_unit(cmount
, (int)j_fd
);
2494 ldout(cct
, 10) << "jni: get_file_stripe_unit: exit ret " << ret
<< dendl
;
2497 handle_error(env
, ret
);
2503 * Class: com_ceph_fs_CephMount
2504 * Method: native_ceph_get_file_replication
2507 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1file_1replication
2508 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
)
2510 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2511 CephContext
*cct
= ceph_get_mount_context(cmount
);
2514 CHECK_MOUNTED(cmount
, -1);
2516 ldout(cct
, 10) << "jni: get_file_replication: fd " << (int)j_fd
<< dendl
;
2518 ret
= ceph_get_file_replication(cmount
, (int)j_fd
);
2520 ldout(cct
, 10) << "jni: get_file_replication: exit ret " << ret
<< dendl
;
2523 handle_error(env
, ret
);
2529 * Class: com_ceph_fs_CephMount
2530 * Method: native_ceph_get_file_pool_name
2531 * Signature: (JI)Ljava/lang/String;
2533 JNIEXPORT jstring JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1file_1pool_1name
2534 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint j_fd
)
2536 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2537 CephContext
*cct
= ceph_get_mount_context(cmount
);
2538 jstring pool
= NULL
;
2539 int ret
, buflen
= 0;
2542 CHECK_MOUNTED(cmount
, NULL
);
2544 ldout(cct
, 10) << "jni: get_file_pool_name: fd " << (int)j_fd
<< dendl
;
2547 /* get pool name length (len==0) */
2548 ret
= ceph_get_file_pool_name(cmount
, (int)j_fd
, NULL
, 0);
2552 /* allocate buffer */
2556 buf
= new (std::nothrow
) char[buflen
+1]; /* +1 for '\0' */
2558 cephThrowOutOfMemory(env
, "head allocation failed");
2561 memset(buf
, 0, (buflen
+1)*sizeof(*buf
));
2563 /* handle zero-length pool name!? */
2568 ret
= ceph_get_file_pool_name(cmount
, (int)j_fd
, buf
, buflen
);
2569 if (ret
== -ERANGE
) /* size changed! */
2575 ldout(cct
, 10) << "jni: get_file_pool_name: ret " << ret
<< dendl
;
2578 handle_error(env
, ret
);
2580 pool
= env
->NewStringUTF(buf
);
2590 * Class: com_ceph_fs_CephMount
2591 * Method: native_ceph_get_default_data_pool_name
2592 * Signature: (J)Ljava/lang/String;
2594 JNIEXPORT jstring JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1default_1data_1pool_1name
2595 (JNIEnv
*env
, jclass clz
, jlong j_mntp
)
2597 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2598 CephContext
*cct
= ceph_get_mount_context(cmount
);
2599 jstring pool
= NULL
;
2600 int ret
, buflen
= 0;
2603 CHECK_MOUNTED(cmount
, NULL
);
2605 ldout(cct
, 10) << "jni: get_default_data_pool_name" << dendl
;
2607 ret
= ceph_get_default_data_pool_name(cmount
, NULL
, 0);
2611 buf
= new (std::nothrow
) char[buflen
+1]; /* +1 for '\0' */
2613 cephThrowOutOfMemory(env
, "head allocation failed");
2616 memset(buf
, 0, (buflen
+1)*sizeof(*buf
));
2617 ret
= ceph_get_default_data_pool_name(cmount
, buf
, buflen
);
2619 ldout(cct
, 10) << "jni: get_default_data_pool_name: ret " << ret
<< dendl
;
2622 handle_error(env
, ret
);
2624 pool
= env
->NewStringUTF(buf
);
2635 * Class: com_ceph_fs_CephMount
2636 * Method: native_ceph_localize_reads
2639 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1localize_1reads
2640 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jboolean j_on
)
2642 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2643 CephContext
*cct
= ceph_get_mount_context(cmount
);
2644 int ret
, val
= j_on
? 1 : 0;
2646 CHECK_MOUNTED(cmount
, -1);
2648 ldout(cct
, 10) << "jni: localize_reads: val " << val
<< dendl
;
2650 ret
= ceph_localize_reads(cmount
, val
);
2652 ldout(cct
, 10) << "jni: localize_reads: exit ret " << ret
<< dendl
;
2655 handle_error(env
, ret
);
2661 * Class: com_ceph_fs_CephMount
2662 * Method: native_ceph_get_stripe_unit_granularity
2665 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1stripe_1unit_1granularity
2666 (JNIEnv
*env
, jclass clz
, jlong j_mntp
)
2668 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2669 CephContext
*cct
= ceph_get_mount_context(cmount
);
2672 CHECK_MOUNTED(cmount
, -1);
2674 ldout(cct
, 10) << "jni: get_stripe_unit_granularity" << dendl
;
2676 ret
= ceph_get_stripe_unit_granularity(cmount
);
2678 ldout(cct
, 10) << "jni: get_stripe_unit_granularity: exit ret " << ret
<< dendl
;
2681 handle_error(env
, ret
);
2687 * Class: com_ceph_fs_CephMount
2688 * Method: native_ceph_get_pool_id
2689 * Signature: (JLjava/lang/String;)I
2691 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1pool_1id
2692 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jstring jname
)
2694 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2695 CephContext
*cct
= ceph_get_mount_context(cmount
);
2699 CHECK_MOUNTED(cmount
, -1);
2700 CHECK_ARG_NULL(jname
, "@name is null", -1);
2702 c_name
= env
->GetStringUTFChars(jname
, NULL
);
2704 cephThrowInternal(env
, "failed to pin memory");
2708 ldout(cct
, 10) << "jni: get_pool_id: name " << c_name
<< dendl
;
2710 ret
= ceph_get_pool_id(cmount
, c_name
);
2712 handle_error(env
, ret
);
2714 ldout(cct
, 10) << "jni: get_pool_id: ret " << ret
<< dendl
;
2716 env
->ReleaseStringUTFChars(jname
, c_name
);
2722 * Class: com_ceph_fs_CephMount
2723 * Method: native_ceph_get_pool_replication
2726 JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1pool_1replication
2727 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint jpoolid
)
2729 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2730 CephContext
*cct
= ceph_get_mount_context(cmount
);
2733 CHECK_MOUNTED(cmount
, -1);
2735 ldout(cct
, 10) << "jni: get_pool_replication: poolid " << jpoolid
<< dendl
;
2737 ret
= ceph_get_pool_replication(cmount
, jpoolid
);
2739 handle_error(env
, ret
);
2741 ldout(cct
, 10) << "jni: get_pool_replication: ret " << ret
<< dendl
;
2747 * Class: com_ceph_fs_CephMount
2748 * Method: native_ceph_get_file_extent_osds
2749 * Signature: (JIJ)Lcom/ceph/fs/CephFileExtent;
2751 JNIEXPORT jobject JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1file_1extent_1osds
2752 (JNIEnv
*env
, jclass clz
, jlong mntp
, jint fd
, jlong off
)
2754 struct ceph_mount_info
*cmount
= get_ceph_mount(mntp
);
2755 CephContext
*cct
= ceph_get_mount_context(cmount
);
2756 jobject extent
= NULL
;
2757 int ret
, nosds
, *osds
= NULL
;
2758 jintArray osd_array
;
2761 CHECK_MOUNTED(cmount
, NULL
);
2763 ldout(cct
, 10) << "jni: get_file_extent_osds: fd " << fd
<< " off " << off
<< dendl
;
2767 ret
= ceph_get_file_extent_osds(cmount
, fd
, off
, NULL
, NULL
, 0);
2771 /* alloc osd id array */
2775 osds
= new int[nosds
];
2778 ret
= ceph_get_file_extent_osds(cmount
, fd
, off
, &len
, osds
, nosds
);
2785 ldout(cct
, 10) << "jni: get_file_extent_osds: ret " << ret
<< dendl
;
2788 handle_error(env
, ret
);
2794 osd_array
= env
->NewIntArray(nosds
);
2798 env
->SetIntArrayRegion(osd_array
, 0, nosds
, osds
);
2799 if (env
->ExceptionOccurred())
2802 extent
= env
->NewObject(cephfileextent_cls
, cephfileextent_ctor_fid
, off
, len
, osd_array
);
2814 * Class: com_ceph_fs_CephMount
2815 * Method: native_ceph_get_osd_crush_location
2816 * Signature: (JI)[Ljava/lang/String;
2818 JNIEXPORT jobjectArray JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1osd_1crush_1location
2819 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint osdid
)
2821 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
2822 CephContext
*cct
= ceph_get_mount_context(cmount
);
2823 jobjectArray path
= NULL
;
2824 vector
<string
> str_path
;
2825 int ret
, bufpos
, buflen
= 0;
2828 CHECK_MOUNTED(cmount
, NULL
);
2830 ldout(cct
, 10) << "jni: osd loc: osd " << osdid
<< dendl
;
2833 /* get length of the location path */
2834 ret
= ceph_get_osd_crush_location(cmount
, osdid
, NULL
, 0);
2838 /* alloc path buffer */
2842 buf
= new char[buflen
+1];
2843 memset(buf
, 0, buflen
*sizeof(*buf
));
2850 ret
= ceph_get_osd_crush_location(cmount
, osdid
, buf
, buflen
);
2857 ldout(cct
, 10) << "jni: osd loc: osd " << osdid
<< " ret " << ret
<< dendl
;
2860 handle_error(env
, ret
);
2865 while (bufpos
< ret
) {
2866 string
type(buf
+ bufpos
);
2867 bufpos
+= type
.size() + 1;
2868 string
name(buf
+ bufpos
);
2869 bufpos
+= name
.size() + 1;
2870 str_path
.push_back(type
);
2871 str_path
.push_back(name
);
2874 path
= env
->NewObjectArray(str_path
.size(), env
->FindClass("java/lang/String"), NULL
);
2878 for (unsigned i
= 0; i
< str_path
.size(); i
++) {
2879 jstring ent
= env
->NewStringUTF(str_path
[i
].c_str());
2882 env
->SetObjectArrayElement(path
, i
, ent
);
2883 if (env
->ExceptionOccurred())
2885 env
->DeleteLocalRef(ent
);
2896 * sockaddrToInetAddress uses with the following license, and is adapted for
2897 * use in this project by using Ceph JNI exception utilities.
2901 * Copyright (C) 2010 The Android Open Source Project
2903 * Licensed under the Apache License, Version 2.0 (the "License");
2904 * you may not use this file except in compliance with the License.
2905 * You may obtain a copy of the License at
2907 * http://www.apache.org/licenses/LICENSE-2.0
2909 * Unless required by applicable law or agreed to in writing, software
2910 * distributed under the License is distributed on an "AS IS" BASIS,
2911 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2912 * See the License for the specific language governing permissions and
2913 * limitations under the License.
2915 jobject
sockaddrToInetAddress(JNIEnv
* env
, const sockaddr_storage
& ss
, jint
* port
) {
2916 // Convert IPv4-mapped IPv6 addresses to IPv4 addresses.
2917 // The RI states "Java will never return an IPv4-mapped address".
2918 const sockaddr_in6
& sin6
= reinterpret_cast<const sockaddr_in6
&>(ss
);
2919 if (ss
.ss_family
== AF_INET6
&& IN6_IS_ADDR_V4MAPPED(&sin6
.sin6_addr
)) {
2920 // Copy the IPv6 address into the temporary sockaddr_storage.
2921 sockaddr_storage tmp
;
2922 memset(&tmp
, 0, sizeof(tmp
));
2923 memcpy(&tmp
, &ss
, sizeof(sockaddr_in6
));
2924 // Unmap it into an IPv4 address.
2925 sockaddr_in
& sin
= reinterpret_cast<sockaddr_in
&>(tmp
);
2926 sin
.sin_family
= AF_INET
;
2927 sin
.sin_port
= sin6
.sin6_port
;
2928 memcpy(&sin
.sin_addr
.s_addr
, &sin6
.sin6_addr
.s6_addr
[12], 4);
2929 // Do the regular conversion using the unmapped address.
2930 return sockaddrToInetAddress(env
, tmp
, port
);
2933 const void* rawAddress
;
2934 size_t addressLength
;
2937 if (ss
.ss_family
== AF_INET
) {
2938 const sockaddr_in
& sin
= reinterpret_cast<const sockaddr_in
&>(ss
);
2939 rawAddress
= &sin
.sin_addr
.s_addr
;
2941 sin_port
= ntohs(sin
.sin_port
);
2942 } else if (ss
.ss_family
== AF_INET6
) {
2943 const sockaddr_in6
& sin6
= reinterpret_cast<const sockaddr_in6
&>(ss
);
2944 rawAddress
= &sin6
.sin6_addr
.s6_addr
;
2946 sin_port
= ntohs(sin6
.sin6_port
);
2947 scope_id
= sin6
.sin6_scope_id
;
2948 } else if (ss
.ss_family
== AF_UNIX
) {
2949 const sockaddr_un
& sun
= reinterpret_cast<const sockaddr_un
&>(ss
);
2950 rawAddress
= &sun
.sun_path
;
2951 addressLength
= strlen(sun
.sun_path
);
2953 // We can't throw SocketException. We aren't meant to see bad addresses, so seeing one
2954 // really does imply an internal error.
2955 //jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
2956 // "sockaddrToInetAddress unsupported ss_family: %i", ss.ss_family);
2957 cephThrowIllegalArg(env
, "sockaddrToInetAddress unsupposed ss_family");
2964 ScopedLocalRef
<jbyteArray
> byteArray(env
, env
->NewByteArray(addressLength
));
2965 if (byteArray
.get() == NULL
) {
2968 env
->SetByteArrayRegion(byteArray
.get(), 0, addressLength
,
2969 reinterpret_cast<jbyte
*>(const_cast<void*>(rawAddress
)));
2971 if (ss
.ss_family
== AF_UNIX
) {
2972 // Note that we get here for AF_UNIX sockets on accept(2). The unix(7) man page claims
2973 // that the peer's sun_path will contain the path, but in practice it doesn't, and the
2974 // peer length is returned as 2 (meaning only the sun_family field was set).
2976 // Ceph Note: this isn't supported. inetUnixAddress appears to just be
2977 // something in Dalvik/Android stuff.
2978 cephThrowInternal(env
, "OSD address should never be a UNIX socket");
2980 //static jmethodID ctor = env->GetMethodID(JniConstants::inetUnixAddressClass, "<init>", "([B)V");
2981 //return env->NewObject(JniConstants::inetUnixAddressClass, ctor, byteArray.get());
2984 if (addressLength
== 4) {
2985 static jmethodID getByAddressMethod
= env
->GetStaticMethodID(JniConstants::inetAddressClass
,
2986 "getByAddress", "(Ljava/lang/String;[B)Ljava/net/InetAddress;");
2987 if (getByAddressMethod
== NULL
) {
2990 return env
->CallStaticObjectMethod(JniConstants::inetAddressClass
, getByAddressMethod
,
2991 NULL
, byteArray
.get());
2992 } else if (addressLength
== 16) {
2993 static jmethodID getByAddressMethod
= env
->GetStaticMethodID(JniConstants::inet6AddressClass
,
2994 "getByAddress", "(Ljava/lang/String;[BI)Ljava/net/Inet6Address;");
2995 if (getByAddressMethod
== NULL
) {
2998 return env
->CallStaticObjectMethod(JniConstants::inet6AddressClass
, getByAddressMethod
,
2999 NULL
, byteArray
.get(), scope_id
);
3007 * Class: com_ceph_fs_CephMount
3008 * Method: native_ceph_get_osd_addr
3009 * Signature: (JI)Ljava/net/InetAddress;
3011 JNIEXPORT jobject JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1osd_1addr
3012 (JNIEnv
*env
, jclass clz
, jlong j_mntp
, jint osd
)
3014 struct ceph_mount_info
*cmount
= get_ceph_mount(j_mntp
);
3015 CephContext
*cct
= ceph_get_mount_context(cmount
);
3016 struct sockaddr_storage addr
;
3019 CHECK_MOUNTED(cmount
, NULL
);
3021 ldout(cct
, 10) << "jni: get_osd_addr: osd " << osd
<< dendl
;
3023 ret
= ceph_get_osd_addr(cmount
, osd
, &addr
);
3025 ldout(cct
, 10) << "jni: get_osd_addr: ret " << ret
<< dendl
;
3028 handle_error(env
, ret
);
3032 return sockaddrToInetAddress(env
, addr
, NULL
);