]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Client: Add function "get_default_data_pool_name" for java client 16671/head
authordongdong <tdd21151186@gmail.com>
Sat, 29 Jul 2017 10:31:54 +0000 (18:31 +0800)
committerdongdong <tdd21151186@gmail.com>
Sat, 29 Jul 2017 10:31:54 +0000 (18:31 +0800)
Fix: now java client trying to get the default pool througth the root
dir "/", but the thing is when java client is mounted to a sub dir
and the sub dir's pool_id is always -1, this will cause unexpected failure.

Signed-off-by: dongdong tao <tdd21151186@gmail.com>
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h
src/java/java/com/ceph/fs/CephMount.java
src/java/native/libcephfs_jni.cc
src/libcephfs.cc

index 6d9346e7b9dc8afaf9e09af743b054d3bf58b6c3..0ec811fe6232fa950c3cd09822ea8ff7aa414e03 100644 (file)
@@ -12693,6 +12693,12 @@ int Client::fdescribe_layout(int fd, file_layout_t *lp)
   return 0;
 }
 
+int64_t Client::get_default_pool_id()
+{
+  Mutex::Locker lock(client_lock);
+  /* first data pool is the default */ 
+  return mdsmap->get_first_data_pool(); 
+}
 
 // expose osdmap
 
index b6369a29363e13da06ff54751d53a15f8a935dd1..beefa1eba5c8aa2db27777c7cb2e2aa5419cf531 100644 (file)
@@ -1101,6 +1101,9 @@ public:
   int get_file_stripe_address(int fd, loff_t offset, vector<entity_addr_t>& address);
   int get_file_extent_osds(int fd, loff_t off, loff_t *len, vector<int>& osds);
   int get_osd_addr(int osd, entity_addr_t& addr);
+  
+  // expose mdsmap
+  int64_t get_default_pool_id();
 
   // expose osdmap
   int get_local_osd();
index dfb31a1007b8e146cfd642a9262b4b0fc8b10633..45cef34eb47ced86c5026275777bc07b3020b4ff 100644 (file)
@@ -1242,6 +1242,17 @@ int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size
  */
 int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t buflen);
 
+/**
+ * Get the default pool name of cephfs
+ * Write the name of the default pool to the buffer. If buflen is 0, return
+ * a suggested length for the buffer.
+ * @param cmount the ceph mount handle to use.
+ * @param buf buffer to store the name in
+ * @param buflen size of the buffer
+ * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough.
+ */
+int ceph_get_default_data_pool_name(struct ceph_mount_info *cmount, char *buf, size_t buflen);
+
 /**
  * Get the file layout from an open file descriptor.
  *
index d1267142c3ecfea8bf76738c80617752e428e248..786a6ece2f5888df39b9bc06d29256ee5163c3c5 100644 (file)
@@ -938,6 +938,22 @@ public class CephMount {
   }
 
   private static native String native_ceph_get_file_pool_name(long mountp, int fd);
+  
+  /**
+   * Get the default data pool of cephfs.
+   * 
+   * @return The pool name.
+   */ 
+  public String get_default_data_pool_name() {
+    rlock.lock();
+    try {
+      return native_ceph_get_default_data_pool_name(instance_ptr);
+    } finally {
+      rlock.unlock();
+    }
+  }
+  
+  private static native String native_ceph_get_default_data_pool_name(long mountp);
 
   /**
    * Get the replication of a file.
index 975a092dace5a0429b3423632adedba5570306cb..080ec3cbda4ef2688ee77605b8634d40cfda671c 100644 (file)
@@ -2580,6 +2580,51 @@ out:
        return pool;
 }
 
+/**
+ * Class: com_ceph_fs_CephMount
+ * Method: native_ceph_get_default_data_pool_name
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1default_1data_1pool_1name
+  (JNIEnv *env, jclass clz, jlong j_mntp)
+{
+       struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
+       CephContext *cct = ceph_get_mount_context(cmount);
+       jstring pool = NULL;
+       int ret, buflen = 0;
+       char *buf = NULL;
+        
+       CHECK_MOUNTED(cmount, NULL);
+        
+       ldout(cct, 10) << "jni: get_default_data_pool_name" << dendl;
+
+       ret = ceph_get_default_data_pool_name(cmount, NULL, 0);
+       if (ret < 0)
+               goto out;
+       buflen = ret;
+       buf = new (std::nothrow) char[buflen+1]; /* +1 for '\0' */
+       if (!buf) {
+               cephThrowOutOfMemory(env, "head allocation failed");
+               goto out;
+       }
+       memset(buf, 0, (buflen+1)*sizeof(*buf));
+       ret = ceph_get_default_data_pool_name(cmount, buf, buflen);
+       
+       ldout(cct, 10) << "jni: get_default_data_pool_name: ret " << ret << dendl;
+       
+       if (ret < 0)
+               handle_error(env, ret);
+       else
+               pool = env->NewStringUTF(buf);
+
+out:
+       if (buf)
+       delete [] buf;
+
+       return pool;        
+}
+
+
 /*
  * Class:     com_ceph_fs_CephMount
  * Method:    native_ceph_localize_reads
index bfacd1bae51b1af157ece04f693b1efdcaa05336..74652da147280c27ee48002268d178ca2b36dd11 100644 (file)
@@ -1074,6 +1074,21 @@ extern "C" int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const cha
   return name.length();
 }
 
+extern "C" int ceph_get_default_data_pool_name(struct ceph_mount_info *cmount, char *buf, size_t len)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  int64_t pool_id = cmount->get_client()->get_default_pool_id();
+  string name = cmount->get_client()->get_pool_name(pool_id);
+  if (len == 0)
+    return name.length();
+  if (name.length() > len)
+    return -ERANGE;
+  strncpy(buf, name.c_str(), len);
+  return name.length(); 
+}
+
 extern "C" int ceph_get_file_layout(struct ceph_mount_info *cmount, int fh, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool)
 {
   file_layout_t l;