]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
java: support fchmod
authorNoah Watkins <noahwatkins@gmail.com>
Thu, 27 Dec 2012 21:13:40 +0000 (13:13 -0800)
committerNoah Watkins <noahwatkins@gmail.com>
Thu, 24 Jan 2013 19:33:37 +0000 (11:33 -0800)
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/java/java/com/ceph/fs/CephMount.java
src/java/native/libcephfs_jni.cc
src/java/test/com/ceph/fs/CephMountTest.java
src/java/test/com/ceph/fs/CephUnmountedTest.java

index 76b4dab12c345c7cd4478074fae88932d237ac43..e1e1466a24d3c4b950d87c98a56ee8cd0506969e 100644 (file)
@@ -495,6 +495,23 @@ public class CephMount {
 
   private static native int native_ceph_chmod(long mountp, String path, int mode);
 
+  /**
+   * Change file mode of an open file.
+   *
+   * @param fd The open file descriptor to change the mode bits on.
+   * @param mode New mode bits.
+   */
+  public void fchmod(int fd, int mode) {
+    rlock.lock();
+    try {
+      native_ceph_fchmod(instance_ptr, fd, mode);
+    } finally {
+      rlock.unlock();
+    }
+  }
+
+  private static native int native_ceph_fchmod(long mountp, int fd, int mode);
+
   /**
    * Truncate a file to a specified length.
    *
index 2b9c9cee84791afd356c88beebfdfee91cbc74d0..103d90b80d0efc8382838ea42c78192b3234199e 100644 (file)
@@ -1385,6 +1385,32 @@ JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1chmod
        return ret;
 }
 
+/*
+ * Class:     com_ceph_fs_CephMount
+ * Method:    native_ceph_fchmod
+ * Signature: (JII)I
+ */
+JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1fchmod
+  (JNIEnv *env, jclass clz, jlong j_mntp, jint j_fd, jint j_mode)
+{
+  struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
+  CephContext *cct = ceph_get_mount_context(cmount);
+  int ret;
+
+  CHECK_MOUNTED(cmount, -1);
+
+  ldout(cct, 10) << "jni: fchmod: fd " << (int)j_fd << " mode " << (int)j_mode << dendl;
+
+  ret = ceph_fchmod(cmount, (int)j_fd, (int)j_mode);
+
+  ldout(cct, 10) << "jni: fchmod: exit ret " << ret << dendl;
+
+  if (ret)
+    handle_error(env, ret);
+
+  return ret;
+}
+
 /*
  * Class:     com_ceph_fs_CephMount
  * Method:    native_ceph_truncate
index cc351cc792f90a3176303fbee7517916e84c670e..ca0db76255e0a67f75be68b2cffd9d3d49737f74 100644 (file)
@@ -615,6 +615,36 @@ public class CephMountTest {
     mount.unlink(path);
   }
 
+  /*
+   * fchmod
+   */
+
+  @Test
+  public void test_fchmod() throws Exception {
+    /* create a file */
+    String path = makePath();
+    int fd = createFile(path, 1);
+
+    CephStat st = new CephStat();
+    mount.lstat(path, st);
+
+    /* flip a bit */
+    int mode = st.mode;
+    if ((mode & 1) != 0)
+      mode -= 1;
+    else
+      mode += 1;
+
+    mount.fchmod(fd, mode);
+    mount.close(fd);
+
+    CephStat st2 = new CephStat();
+    mount.lstat(path, st2);
+    assertTrue(st2.mode == mode);
+
+    mount.unlink(path);
+  }
+
   /*
    * truncate
    */
index 602bd5ad4d664450e053298181329b1353e5ee5f..80147ac8e822df6b1181d768488b9b85351f8ba7 100644 (file)
@@ -151,4 +151,9 @@ public class CephUnmountedTest {
   public void test_get_pool_replication() throws Exception {
     mount.get_pool_replication(1);
   }
+
+  @Test(expected=CephNotMountedException.class)
+  public void test_fchmod() throws Exception {
+    mount.fchmod(1, 0);
+  }
 }