mirror of
https://github.com/ceph/ceph
synced 2024-12-18 09:25:49 +00:00
Merge branch 'master' of github.com:ceph/ceph
This commit is contained in:
commit
1b258764bc
Binary file not shown.
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 117 KiB |
@ -5,7 +5,9 @@ JAVA_SRC = \
|
||||
java/com/ceph/fs/CephStat.java \
|
||||
java/com/ceph/fs/CephStatVFS.java \
|
||||
java/com/ceph/fs/CephNativeLoader.java \
|
||||
java/com/ceph/fs/CephNotMountedException.java
|
||||
java/com/ceph/fs/CephNotMountedException.java \
|
||||
java/com/ceph/fs/CephFileAlreadyExistsException.java \
|
||||
java/com/ceph/fs/CephAlreadyMountedException.java
|
||||
|
||||
EXTRA_DIST = $(JAVA_SRC) test
|
||||
|
||||
|
42
src/java/java/com/ceph/fs/CephAlreadyMountedException.java
Normal file
42
src/java/java/com/ceph/fs/CephAlreadyMountedException.java
Normal 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;
|
||||
|
||||
/**
|
||||
* Ceph is already mounted.
|
||||
*/
|
||||
public class CephAlreadyMountedException extends IOException {
|
||||
|
||||
/**
|
||||
* Construct CephAlreadyMountedException.
|
||||
*/
|
||||
public CephAlreadyMountedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct CephAlreadyMountedException with message.
|
||||
*/
|
||||
public CephAlreadyMountedException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
/**
|
||||
* Ceph file/directory already exists.
|
||||
*/
|
||||
public class CephFileAlreadyExistsException extends IOException {
|
||||
|
||||
/**
|
||||
* Construct CephFileAlreadyExistsException.
|
||||
*/
|
||||
public CephFileAlreadyExistsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct CephFileAlreadyExistsException with message.
|
||||
*/
|
||||
public CephFileAlreadyExistsException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@ public class CephMount {
|
||||
public static final int O_CREAT = 8;
|
||||
public static final int O_TRUNC = 16;
|
||||
public static final int O_EXCL = 32;
|
||||
public static final int O_WRONLY = 64;
|
||||
|
||||
/*
|
||||
* Whence flags for seek().
|
||||
@ -88,6 +89,30 @@ public class CephMount {
|
||||
*/
|
||||
static native void native_initialize();
|
||||
|
||||
/*
|
||||
* Controls clean-up synchronization between the constructor and finalize().
|
||||
* If native_ceph_create fails, then we want a call to finalize() to not
|
||||
* attempt to clean-up native context, because there is none.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/*
|
||||
* Try to clean-up. First, unmount() will catch users who forget to do the
|
||||
* unmount manually. Second, release() will destroy the entire context. It
|
||||
* is safe to call release after a failure in unmount.
|
||||
*/
|
||||
protected void finalize() throws Throwable {
|
||||
if (initialized) {
|
||||
try {
|
||||
unmount();
|
||||
} catch (Exception e) {}
|
||||
try {
|
||||
native_ceph_release(instance_ptr);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new CephMount with specific client id.
|
||||
*
|
||||
@ -95,9 +120,10 @@ public class CephMount {
|
||||
*/
|
||||
public CephMount(String id) {
|
||||
native_ceph_create(this, id);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_create(CephMount mount, String id);
|
||||
private static synchronized native int native_ceph_create(CephMount mount, String id);
|
||||
|
||||
/**
|
||||
* Create a new CephMount with default client id.
|
||||
@ -115,16 +141,24 @@ public class CephMount {
|
||||
native_ceph_mount(instance_ptr, root);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_mount(long mountp, String root);
|
||||
private static synchronized native int native_ceph_mount(long mountp, String root);
|
||||
|
||||
/**
|
||||
* Shutdown the mount.
|
||||
* Deactivate the mount.
|
||||
*
|
||||
* The mount can be reactivated using mount(). Configuration parameters
|
||||
* previously set are not reset.
|
||||
*/
|
||||
public void shutdown() {
|
||||
native_ceph_shutdown(instance_ptr);
|
||||
public synchronized void unmount() {
|
||||
native_ceph_unmount(instance_ptr);
|
||||
}
|
||||
|
||||
private static synchronized native void native_ceph_shutdown(long mountp);
|
||||
private static synchronized native int native_ceph_unmount(long mountp);
|
||||
|
||||
/*
|
||||
* Private access to low-level ceph_release.
|
||||
*/
|
||||
private static synchronized native int native_ceph_release(long mountp);
|
||||
|
||||
/**
|
||||
* Load configuration from a file.
|
||||
@ -135,7 +169,7 @@ public class CephMount {
|
||||
native_ceph_conf_read_file(instance_ptr, path);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_conf_read_file(long mountp, String path);
|
||||
private static synchronized native int native_ceph_conf_read_file(long mountp, String path);
|
||||
|
||||
/**
|
||||
* Set the value of a configuration option.
|
||||
@ -147,7 +181,7 @@ public class CephMount {
|
||||
native_ceph_conf_set(instance_ptr, option, value);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_conf_set(long mountp, String option, String value);
|
||||
private static synchronized native int native_ceph_conf_set(long mountp, String option, String value);
|
||||
|
||||
/**
|
||||
* Get the value of a configuration option.
|
||||
@ -171,7 +205,7 @@ public class CephMount {
|
||||
native_ceph_statfs(instance_ptr, path, statvfs);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_statfs(long mountp, String path, CephStatVFS statvfs);
|
||||
private static synchronized native int native_ceph_statfs(long mountp, String path, CephStatVFS statvfs);
|
||||
|
||||
/**
|
||||
* Get the current working directory.
|
||||
@ -182,7 +216,7 @@ public class CephMount {
|
||||
return native_ceph_getcwd(instance_ptr);
|
||||
}
|
||||
|
||||
private static synchronized native String native_ceph_getcwd(long mountp);
|
||||
private static synchronized native String native_ceph_getcwd(long mountp);
|
||||
|
||||
/**
|
||||
* Set the current working directory.
|
||||
@ -193,7 +227,7 @@ public class CephMount {
|
||||
native_ceph_chdir(instance_ptr, path);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_chdir(long mountp, String cwd);
|
||||
private static synchronized native int native_ceph_chdir(long mountp, String cwd);
|
||||
|
||||
/**
|
||||
* List the contents of a directory.
|
||||
@ -217,7 +251,7 @@ public class CephMount {
|
||||
native_ceph_link(instance_ptr, oldpath, newpath);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_link(long mountp, String existing, String newname);
|
||||
private static synchronized native int native_ceph_link(long mountp, String existing, String newname);
|
||||
|
||||
/**
|
||||
* Unlink/delete a name from the file system.
|
||||
@ -228,7 +262,7 @@ public class CephMount {
|
||||
native_ceph_unlink(instance_ptr, path);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_unlink(long mountp, String path);
|
||||
private static synchronized native int native_ceph_unlink(long mountp, String path);
|
||||
|
||||
/**
|
||||
* Rename a file or directory.
|
||||
@ -240,7 +274,7 @@ public class CephMount {
|
||||
native_ceph_rename(instance_ptr, from, to);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_rename(long mountp, String from, String to);
|
||||
private static synchronized native int native_ceph_rename(long mountp, String from, String to);
|
||||
|
||||
/**
|
||||
* Create a directory.
|
||||
@ -252,7 +286,7 @@ public class CephMount {
|
||||
native_ceph_mkdir(instance_ptr, path, mode);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_mkdir(long mountp, String path, int mode);
|
||||
private static synchronized native int native_ceph_mkdir(long mountp, String path, int mode);
|
||||
|
||||
/**
|
||||
* Create a directory and all parents.
|
||||
@ -260,11 +294,11 @@ public class CephMount {
|
||||
* @param path The directory to create.
|
||||
* @param mode The mode of the new directory.
|
||||
*/
|
||||
public void mkdirs(String path, int mode) {
|
||||
public void mkdirs(String path, int mode) throws IOException {
|
||||
native_ceph_mkdirs(instance_ptr, path, mode);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_mkdirs(long mountp, String path, int mode);
|
||||
private static synchronized native int native_ceph_mkdirs(long mountp, String path, int mode);
|
||||
|
||||
/**
|
||||
* Delete a directory.
|
||||
@ -275,7 +309,7 @@ public class CephMount {
|
||||
native_ceph_rmdir(instance_ptr, path);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_rmdir(long mountp, String path);
|
||||
private static synchronized native int native_ceph_rmdir(long mountp, String path);
|
||||
|
||||
/**
|
||||
* Read the value of a symbolic link.
|
||||
@ -308,7 +342,7 @@ public class CephMount {
|
||||
native_ceph_lstat(instance_ptr, path, stat);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_lstat(long mountp, String path, CephStat stat);
|
||||
private static synchronized native int native_ceph_lstat(long mountp, String path, CephStat stat);
|
||||
|
||||
/**
|
||||
* Set file attributes.
|
||||
@ -321,7 +355,7 @@ public class CephMount {
|
||||
native_ceph_setattr(instance_ptr, path, stat, mask);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_setattr(long mountp, String relpath, CephStat stat, int mask);
|
||||
private static synchronized native int native_ceph_setattr(long mountp, String relpath, CephStat stat, int mask);
|
||||
|
||||
/**
|
||||
* Change file mode.
|
||||
@ -333,7 +367,7 @@ public class CephMount {
|
||||
native_ceph_chmod(instance_ptr, path, mode);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_chmod(long mountp, String path, int mode);
|
||||
private static synchronized native int native_ceph_chmod(long mountp, String path, int mode);
|
||||
|
||||
/**
|
||||
* Truncate a file to a specified length.
|
||||
@ -345,7 +379,7 @@ public class CephMount {
|
||||
native_ceph_truncate(instance_ptr, path, size);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_truncate(long mountp, String path, long size);
|
||||
private static synchronized native int native_ceph_truncate(long mountp, String path, long size);
|
||||
|
||||
/**
|
||||
* Open a file.
|
||||
@ -359,7 +393,7 @@ public class CephMount {
|
||||
return native_ceph_open(instance_ptr, path, flags, mode);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_open(long mountp, String path, int flags, int mode);
|
||||
private static synchronized native int native_ceph_open(long mountp, String path, int flags, int mode);
|
||||
|
||||
/**
|
||||
* Close an open file.
|
||||
@ -370,7 +404,7 @@ public class CephMount {
|
||||
native_ceph_close(instance_ptr, fd);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_close(long mountp, int fd);
|
||||
private static synchronized native int native_ceph_close(long mountp, int fd);
|
||||
|
||||
/**
|
||||
* Seek to a position in a file.
|
||||
@ -384,7 +418,7 @@ public class CephMount {
|
||||
return native_ceph_lseek(instance_ptr, fd, offset, whence);
|
||||
}
|
||||
|
||||
private static synchronized native long native_ceph_lseek(long mountp, int fd, long offset, int whence);
|
||||
private static synchronized native long native_ceph_lseek(long mountp, int fd, long offset, int whence);
|
||||
|
||||
/**
|
||||
* Read from a file.
|
||||
@ -399,7 +433,7 @@ public class CephMount {
|
||||
return native_ceph_read(instance_ptr, fd, buf, size, offset);
|
||||
}
|
||||
|
||||
private static synchronized native long native_ceph_read(long mountp, int fd, byte[] buf, long size, long offset);
|
||||
private static synchronized native long native_ceph_read(long mountp, int fd, byte[] buf, long size, long offset);
|
||||
|
||||
/**
|
||||
* Write to a file at a specific offset.
|
||||
@ -414,7 +448,7 @@ public class CephMount {
|
||||
return native_ceph_write(instance_ptr, fd, buf, size, offset);
|
||||
}
|
||||
|
||||
private static synchronized native long native_ceph_write(long mountp, int fd, byte[] buf, long size, long offset);
|
||||
private static synchronized native long native_ceph_write(long mountp, int fd, byte[] buf, long size, long offset);
|
||||
|
||||
/**
|
||||
* Truncate a file.
|
||||
@ -426,7 +460,7 @@ public class CephMount {
|
||||
native_ceph_ftruncate(instance_ptr, fd, size);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_ftruncate(long mountp, int fd, long size);
|
||||
private static synchronized native int native_ceph_ftruncate(long mountp, int fd, long size);
|
||||
|
||||
/**
|
||||
* Synchronize a file with the file system.
|
||||
@ -438,7 +472,7 @@ public class CephMount {
|
||||
native_ceph_fsync(instance_ptr, fd, dataonly);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_fsync(long mountp, int fd, boolean dataonly);
|
||||
private static synchronized native int native_ceph_fsync(long mountp, int fd, boolean dataonly);
|
||||
|
||||
/**
|
||||
* Get file status.
|
||||
@ -450,7 +484,7 @@ public class CephMount {
|
||||
native_ceph_fstat(instance_ptr, fd, stat);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_fstat(long mountp, int fd, CephStat stat);
|
||||
private static synchronized native int native_ceph_fstat(long mountp, int fd, CephStat stat);
|
||||
|
||||
/**
|
||||
* Synchronize the client with the file system.
|
||||
@ -459,7 +493,7 @@ public class CephMount {
|
||||
native_ceph_sync_fs(instance_ptr);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_sync_fs(long mountp);
|
||||
private static synchronized native int native_ceph_sync_fs(long mountp);
|
||||
|
||||
/**
|
||||
* Get an extended attribute value.
|
||||
@ -585,7 +619,7 @@ public class CephMount {
|
||||
return native_ceph_get_file_stripe_unit(instance_ptr, fd);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_get_file_stripe_unit(long mountp, int fd);
|
||||
private static synchronized native int native_ceph_get_file_stripe_unit(long mountp, int fd);
|
||||
|
||||
/**
|
||||
* Get the replication of a file.
|
||||
@ -597,7 +631,7 @@ public class CephMount {
|
||||
return native_ceph_get_file_replication(instance_ptr, fd);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_get_file_replication(long mountp, int fd);
|
||||
private static synchronized native int native_ceph_get_file_replication(long mountp, int fd);
|
||||
|
||||
/**
|
||||
* Set the default file stripe unit.
|
||||
@ -608,7 +642,7 @@ public class CephMount {
|
||||
native_ceph_set_default_file_stripe_unit(instance_ptr, stripe_unit);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_set_default_file_stripe_unit(long mountp, int stripe_unit);
|
||||
private static synchronized native int native_ceph_set_default_file_stripe_unit(long mountp, int stripe_unit);
|
||||
|
||||
/**
|
||||
* Set the default file stripe count.
|
||||
@ -619,7 +653,7 @@ public class CephMount {
|
||||
native_ceph_set_default_file_stripe_count(instance_ptr, stripe_count);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_set_default_file_stripe_count(long mountp, int stripe_count);
|
||||
private static synchronized native int native_ceph_set_default_file_stripe_count(long mountp, int stripe_count);
|
||||
|
||||
/**
|
||||
* Set the default object size.
|
||||
@ -630,7 +664,7 @@ public class CephMount {
|
||||
native_ceph_set_default_object_size(instance_ptr, object_size);
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_set_default_object_size(long mountp, int object_size);
|
||||
private static synchronized native int native_ceph_set_default_object_size(long mountp, int object_size);
|
||||
|
||||
/**
|
||||
* Favor reading from local replicas when possible.
|
||||
|
@ -36,6 +36,8 @@
|
||||
#define CEPH_STAT_VFS_CP "com/ceph/fs/CephStatVFS"
|
||||
#define CEPH_MOUNT_CP "com/ceph/fs/CephMount"
|
||||
#define CEPH_NOTMOUNTED_CP "com/ceph/fs/CephNotMountedException"
|
||||
#define CEPH_FILEEXISTS_CP "com/ceph/fs/CephFileAlreadyExistsException"
|
||||
#define CEPH_ALREADYMOUNTED_CP "com/ceph/fs/CephAlreadyMountedException"
|
||||
|
||||
/*
|
||||
* Flags to open(). must be synchronized with CephMount.java
|
||||
@ -52,6 +54,7 @@
|
||||
#define JAVA_O_CREAT 8
|
||||
#define JAVA_O_TRUNC 16
|
||||
#define JAVA_O_EXCL 32
|
||||
#define JAVA_O_WRONLY 64
|
||||
|
||||
/*
|
||||
* Whence flags for seek(). sync with CephMount.java if changed.
|
||||
@ -93,6 +96,7 @@ static inline int fixup_open_flags(jint jflags)
|
||||
FIXUP_OPEN_FLAG(O_CREAT)
|
||||
FIXUP_OPEN_FLAG(O_TRUNC)
|
||||
FIXUP_OPEN_FLAG(O_EXCL)
|
||||
FIXUP_OPEN_FLAG(O_WRONLY)
|
||||
|
||||
#undef FIXUP_OPEN_FLAG
|
||||
|
||||
@ -191,12 +195,20 @@ static void cephThrowFNF(JNIEnv *env, const char *msg)
|
||||
THROW(env, "java/io/FileNotFoundException", msg);
|
||||
}
|
||||
|
||||
static void cephThrowFileExists(JNIEnv *env, const char *msg)
|
||||
{
|
||||
THROW(env, CEPH_FILEEXISTS_CP, msg);
|
||||
}
|
||||
|
||||
static void handle_error(JNIEnv *env, int rc)
|
||||
{
|
||||
switch (rc) {
|
||||
case -ENOENT:
|
||||
cephThrowFNF(env, "");
|
||||
return;
|
||||
case -EEXIST:
|
||||
cephThrowFileExists(env, "");
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -222,12 +234,6 @@ static void handle_error(JNIEnv *env, int rc)
|
||||
return (_r); \
|
||||
} } while (0)
|
||||
|
||||
#define CHECK_MOUNTED_NORV(_c) do { \
|
||||
if (!ceph_is_mounted((_c))) { \
|
||||
THROW(env, CEPH_NOTMOUNTED_CP, "not mounted"); \
|
||||
return; \
|
||||
} } while (0)
|
||||
|
||||
/*
|
||||
* Cast a jlong to ceph_mount_info. Each JNI function is expected to pass in
|
||||
* the class instance variable instance_ptr. Passing a parameter is faster
|
||||
@ -364,6 +370,14 @@ JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1mount
|
||||
const char *c_root = NULL;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* Toss a message up if we are already mounted.
|
||||
*/
|
||||
if (ceph_is_mounted(cmount)) {
|
||||
THROW(env, CEPH_ALREADYMOUNTED_CP, "");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (j_root) {
|
||||
c_root = env->GetStringUTFChars(j_root, NULL);
|
||||
if (!c_root) {
|
||||
@ -389,22 +403,50 @@ JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1mount
|
||||
|
||||
/*
|
||||
* Class: com_ceph_fs_CephMount
|
||||
* Method: native_ceph_shutdown
|
||||
* Signature: (J)V
|
||||
* Method: native_ceph_unmount
|
||||
* Signature: (J)I
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1shutdown
|
||||
(JNIEnv *env, jclass clz, jlong j_mntp)
|
||||
JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1unmount
|
||||
(JNIEnv *env, jclass clz, jlong j_mntp)
|
||||
{
|
||||
struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
|
||||
CephContext *cct = ceph_get_mount_context(cmount);
|
||||
struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
|
||||
CephContext *cct = ceph_get_mount_context(cmount);
|
||||
int ret;
|
||||
|
||||
CHECK_MOUNTED_NORV(cmount);
|
||||
ldout(cct, 10) << "jni: ceph_unmount enter" << dendl;
|
||||
|
||||
ldout(cct, 10) << "jni: ceph_shutdown: enter" << dendl;
|
||||
CHECK_MOUNTED(cmount, -1);
|
||||
|
||||
ceph_shutdown(cmount);
|
||||
ret = ceph_unmount(cmount);
|
||||
|
||||
ldout(cct, 10) << "jni: ceph_shutdown: exit" << dendl;
|
||||
ldout(cct, 10) << "jni: ceph_unmount exit ret " << ret << dendl;
|
||||
|
||||
if (ret)
|
||||
handle_error(env, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: com_ceph_fs_CephMount
|
||||
* Method: native_ceph_release
|
||||
* Signature: (J)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1release
|
||||
(JNIEnv *env, jclass clz, jlong j_mntp)
|
||||
{
|
||||
struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
|
||||
CephContext *cct = ceph_get_mount_context(cmount);
|
||||
int ret;
|
||||
|
||||
ldout(cct, 10) << "jni: ceph_release called" << dendl;
|
||||
|
||||
ret = ceph_release(cmount);
|
||||
|
||||
if (ret)
|
||||
handle_error(env, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -736,8 +778,10 @@ JNIEXPORT jobjectArray JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1listdir
|
||||
}
|
||||
|
||||
/* filter out dot files: xref: java.io.File::list() */
|
||||
if (ent->compare(".") && ent->compare(".."))
|
||||
if (ent->compare(".") && ent->compare("..")) {
|
||||
contents.push_back(*ent);
|
||||
ldout(cct, 20) << "jni: listdir: take path " << *ent << dendl;
|
||||
}
|
||||
|
||||
bufpos += ent->size() + 1;
|
||||
delete ent;
|
||||
|
44
src/java/test/CephDoubleMountTest.java
Normal file
44
src/java/test/CephDoubleMountTest.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import com.ceph.fs.*;
|
||||
|
||||
public class CephDoubleMountTest {
|
||||
|
||||
@Test(expected=CephAlreadyMountedException.class)
|
||||
public void test_double_mount() throws Exception {
|
||||
CephMount mount = new CephMount("admin");
|
||||
String conf_file = System.getProperty("CEPH_CONF_FILE");
|
||||
if (conf_file != null)
|
||||
mount.conf_read_file(conf_file);
|
||||
mount.mount(null);
|
||||
try {
|
||||
mount.mount(null);
|
||||
} finally {
|
||||
mount.unmount();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
import java.io.FileNotFoundException;
|
||||
import org.junit.*;
|
||||
import java.util.UUID;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import com.ceph.fs.*;
|
||||
@ -52,37 +53,38 @@ public class CephMountCreateTest {
|
||||
CephMount mount;
|
||||
boolean found;
|
||||
|
||||
String dir = "libcephfs_junit_" + UUID.randomUUID();
|
||||
|
||||
/* root dir has more than one dir */
|
||||
mount = setupMount(null);
|
||||
mount = setupMount("/");
|
||||
|
||||
try {
|
||||
mount.rmdir("/libcephfs_java_test_dir");
|
||||
mount.rmdir("/" + dir);
|
||||
} catch (FileNotFoundException e) {}
|
||||
mount.mkdirs("/libcephfs_java_test_dir", 777);
|
||||
mount.mkdirs("/" + dir, 777);
|
||||
String[] subdirs = mount.listdir("/");
|
||||
found = false;
|
||||
for (String d : subdirs) {
|
||||
if (d.compareTo("libcephfs_java_test_dir") == 0)
|
||||
if (d.compareTo(dir) == 0)
|
||||
found = true;
|
||||
}
|
||||
assertTrue(found);
|
||||
mount.shutdown();
|
||||
mount.unmount();
|
||||
|
||||
/* changing root to empty dir */
|
||||
mount = setupMount("/libcephfs_java_test_dir");
|
||||
mount = setupMount("/" + dir);
|
||||
|
||||
subdirs = mount.listdir("/");
|
||||
found = false;
|
||||
for (String d : subdirs) {
|
||||
if (d.compareTo(".") != 0 && d.compareTo("..") != 0)
|
||||
found = true;
|
||||
found = true;
|
||||
}
|
||||
assertFalse(found);
|
||||
mount.shutdown();
|
||||
mount.unmount();
|
||||
|
||||
/* cleanup */
|
||||
mount = setupMount(null);
|
||||
mount.rmdir("/libcephfs_java_test_dir");
|
||||
mount.shutdown();
|
||||
mount = setupMount("/");
|
||||
mount.rmdir("/" + dir);
|
||||
mount.unmount();
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class CephMountTest {
|
||||
for (String l : list)
|
||||
System.out.println(l);
|
||||
mount.rmdir(basedir);
|
||||
mount.shutdown();
|
||||
mount.unmount();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -98,7 +98,7 @@ public class CephMountTest {
|
||||
if (conf_file != null)
|
||||
mount2.conf_read_file(conf_file);
|
||||
mount2.mount("/wlfkjwlekfjwlejfwe");
|
||||
mount2.shutdown();
|
||||
mount2.unmount();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -32,8 +32,8 @@ public class CephUnmountedTest {
|
||||
}
|
||||
|
||||
@Test(expected=CephNotMountedException.class)
|
||||
public void test_shutdown() throws Exception {
|
||||
mount.shutdown();
|
||||
public void test_unmount() throws Exception {
|
||||
mount.unmount();
|
||||
}
|
||||
|
||||
@Test(expected=CephNotMountedException.class)
|
||||
|
@ -52,7 +52,8 @@ namespace librbd {
|
||||
}
|
||||
}
|
||||
|
||||
complete();
|
||||
if (!building)
|
||||
complete();
|
||||
}
|
||||
put_unlock();
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ namespace librbd {
|
||||
callback_t complete_cb;
|
||||
void *complete_arg;
|
||||
rbd_completion_t rbd_comp;
|
||||
int pending_count;
|
||||
int pending_count; ///< number of requests
|
||||
bool building; ///< true if we are still building this completion
|
||||
int ref;
|
||||
bool released;
|
||||
ImageCtx *ictx;
|
||||
@ -61,7 +62,8 @@ namespace librbd {
|
||||
|
||||
AioCompletion() : lock("AioCompletion::lock", true),
|
||||
done(false), rval(0), complete_cb(NULL),
|
||||
complete_arg(NULL), rbd_comp(NULL), pending_count(1),
|
||||
complete_arg(NULL), rbd_comp(NULL),
|
||||
pending_count(0), building(true),
|
||||
ref(1), released(false), ictx(NULL),
|
||||
aio_type(AIO_TYPE_NONE),
|
||||
read_bl(NULL), read_buf(NULL), read_buf_len(0) {
|
||||
@ -86,9 +88,9 @@ namespace librbd {
|
||||
|
||||
void finish_adding_requests() {
|
||||
lock.Lock();
|
||||
assert(pending_count);
|
||||
int count = --pending_count;
|
||||
if (!count) {
|
||||
assert(building);
|
||||
building = false;
|
||||
if (!pending_count) {
|
||||
complete();
|
||||
}
|
||||
lock.Unlock();
|
||||
|
@ -3576,10 +3576,6 @@ void ReplicatedPG::op_applied(RepGather *repop)
|
||||
dout(10) << "op_applied " << *repop << dendl;
|
||||
if (repop->ctx->op)
|
||||
repop->ctx->op->mark_event("op_applied");
|
||||
|
||||
// discard my reference to the buffer
|
||||
if (repop->ctx->op)
|
||||
repop->ctx->op->request->clear_data();
|
||||
|
||||
repop->applying = false;
|
||||
repop->applied = true;
|
||||
|
Loading…
Reference in New Issue
Block a user