]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: get the pool name of a file path 253/head
authorAndras Elso <elso.andras@gmail.com>
Fri, 17 May 2013 19:15:35 +0000 (21:15 +0200)
committerAndras Elso <elso.andras@gmail.com>
Fri, 17 May 2013 19:50:47 +0000 (21:50 +0200)
Signed-off-by: Andras Elso <elso.andras@gmail.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index bd4f9fca816df4bebf88a205543434bf3c10062f..12f62b34d5c0657fb311c94d89890763ab2934ba 100644 (file)
@@ -913,7 +913,7 @@ int ceph_get_file_pool(struct ceph_mount_info *cmount, int fh);
 int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path);
 
 /**
- * Get the name of the pool a file is stored in,
+ * Get the name of the pool a opened file is stored in,
  *
  * Write the name of the file's pool to the buffer.  If buflen is 0, return
  * a suggested length for the buffer.
@@ -926,6 +926,20 @@ int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path);
  */
 int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, size_t buflen);
 
+/**
+ * Get the name of the pool a file is stored in
+ *
+ * Write the name of the file's pool to the buffer.  If buflen is 0, return
+ * a suggested length for the buffer.
+ *
+ * @param cmount the ceph mount handle to use.
+ * @param path the path of the file/directory
+ * @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_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t buflen);
+
 /**
  * Get the file layout from an open file descriptor.
  *
index e1b4c287a3739b1751ec1707b5317333b41ba138..6044f7689a943892ff892ff871ff8f0d669ea344 100644 (file)
@@ -838,6 +838,25 @@ extern "C" int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, c
   return name.length();
 }
 
+extern "C" int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t len)
+{
+  struct ceph_file_layout l;
+  int r;
+
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  r = cmount->get_client()->describe_layout(path, &l);
+  if (r < 0)
+    return r;
+  string name = cmount->get_client()->get_pool_name(l.fl_pg_pool);
+  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)
 {
   struct ceph_file_layout l;