]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client, libceph: clean up layout methods
authorSage Weil <sage@newdream.net>
Fri, 22 Apr 2011 20:15:50 +0000 (13:15 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 25 Apr 2011 18:05:44 +0000 (11:05 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/client/Client.cc
src/client/Client.h
src/client/libceph.h
src/libceph.cc

index bbc63cb9cb3d6c0b4f540bec24549a781cb7c70c..5a2aa790a578351853ea2eccafeebe723760423d 100644 (file)
@@ -6387,6 +6387,9 @@ int Client::ll_release(Fh *fh)
 
 // =========================================
 // layout
+
+// default layout
+
 void Client::set_default_file_stripe_unit(int stripe_unit)
 {
   if (stripe_unit > 0)
@@ -6419,6 +6422,9 @@ void Client::set_default_preferred_pg(int pg)
     dout(5) << "Attempt to set preferred_pg " << pg << " < -1!" << dendl;
 }
 
+
+// expose file layouts
+
 int Client::describe_layout(int fd, ceph_file_layout *lp)
 {
   Mutex::Locker lock(client_lock);
@@ -6433,47 +6439,17 @@ int Client::describe_layout(int fd, ceph_file_layout *lp)
   return 0;
 }
 
-int Client::get_file_stripe_unit(int fd)
-{
-  ceph_file_layout layout;
-  describe_layout(fd, &layout);
-  return layout.fl_stripe_unit;
-}
-
-int Client::get_file_stripe_width(int fd)
-{
-  ceph_file_layout layout;
-  describe_layout(fd, &layout);
-  return layout.fl_stripe_unit * layout.fl_stripe_count;
-}
 
-int Client::get_file_stripe_period(int fd)
-{
-  ceph_file_layout layout;
-  describe_layout(fd, &layout);
-  return layout.fl_object_size * layout.fl_stripe_count;
-}
+// expose osdmap
 
-int Client::get_file_replication(int fd)
+int Client::get_pool_replication(int pool)
 {
-  int pool;
   Mutex::Locker lock(client_lock);
-
-  assert(fd_map.count(fd));
-  Fh *f = fd_map[fd];
-  Inode *in = f->inode;
-
-  pool = in->layout.fl_pg_pool;
+  if (!osdmap->have_pg_pool(pool))
+    return -ENOENT;
   return osdmap->get_pg_pool(pool)->get_size();
 }
 
-int Client::get_default_preferred_pg(int fd)
-{
-  ceph_file_layout layout;
-  describe_layout(fd, &layout);
-  return layout.fl_pg_preferred;
-}
-
 int Client::get_file_stripe_address(int fd, loff_t offset, string& address)
 {
   Mutex::Locker lock(client_lock);
index f479f2e5fce59676883f8994f3e59fbcf0cdd293..e50555809bcff3918ef454e38b4e0a3a10ab5666 100644 (file)
@@ -1302,13 +1302,11 @@ public:
 
   // expose file layout
   int describe_layout(int fd, ceph_file_layout* layout);
-  int get_file_stripe_unit(int fd);
-  int get_file_stripe_width(int fd);
-  int get_file_stripe_period(int fd);
-  int get_file_replication(int fd);
   int get_file_stripe_address(int fd, loff_t offset, string& address);
+
+  // expose osdmap 
   int get_local_osd();
-  int get_default_preferred_pg(int fd);
+  int get_pool_replication(int pool);
 
   void set_default_file_stripe_unit(int stripe_unit);
   void set_default_file_stripe_count(int count);
index 558d04f58dfdabc4c0532a0150cdf086ca8fd8ee..aad537253526a8de03bc83cc8ff132ee57a261c4 100644 (file)
@@ -79,7 +79,6 @@ int ceph_conf_set(ceph_mount_t *cmount, const char *option, const char *value);
 int ceph_conf_get(ceph_mount_t *cmount, const char *option, char *buf, size_t len);
 
 int ceph_statfs(ceph_mount_t *cmount, const char *path, struct statvfs *stbuf);
-int ceph_get_local_osd(ceph_mount_t *cmount);
 
 /* Get the current working directory.
  *
@@ -105,16 +104,16 @@ int ceph_link(ceph_mount_t *cmount, const char *existing, const char *newname);
 int ceph_unlink(ceph_mount_t *cmount, const char *path);
 int ceph_rename(ceph_mount_t *cmount, const char *from, const char *to);
 
-// dirs
+/* dirs */
 int ceph_mkdir(ceph_mount_t *cmount, const char *path, mode_t mode);
 int ceph_mkdirs(ceph_mount_t *cmount, const char *path, mode_t mode);
 int ceph_rmdir(ceph_mount_t *cmount, const char *path);
 
-// symlinks
+/* symlinks */
 int ceph_readlink(ceph_mount_t *cmount, const char *path, char *buf, loff_t size);
 int ceph_symlink(ceph_mount_t *cmount, const char *existing, const char *newname);
 
-// inode stuff
+/* inode stuff */
 int ceph_lstat(ceph_mount_t *cmount, const char *path, struct stat *stbuf);
 int ceph_lstat_precise(ceph_mount_t *cmount, const char *path, struct stat_precise *stbuf);
 
@@ -126,7 +125,7 @@ int ceph_chown(ceph_mount_t *cmount, const char *path, uid_t uid, gid_t gid);
 int ceph_utime(ceph_mount_t *cmount, const char *path, struct utimbuf *buf);
 int ceph_truncate(ceph_mount_t *cmount, const char *path, loff_t size);
 
-// file ops
+/* file ops */
 int ceph_mknod(ceph_mount_t *cmount, const char *path, mode_t mode, dev_t rdev);
 int ceph_open(ceph_mount_t *cmount, const char *path, int flags, mode_t mode);
 int ceph_close(ceph_mount_t *cmount, int fd);
@@ -139,18 +138,27 @@ int ceph_fsync(ceph_mount_t *cmount, int fd, int syncdataonly);
 int ceph_fstat(ceph_mount_t *cmount, int fd, struct stat *stbuf);
 
 int ceph_sync_fs(ceph_mount_t *cmount);
+
+
+/* expose file layout */
 int ceph_get_file_stripe_unit(ceph_mount_t *cmount, int fh);
-int ceph_get_file_replication(ceph_mount_t *cmount, const char *path);
-int ceph_get_default_preferred_pg(ceph_mount_t *cmount, int fd);
+int ceph_get_file_pool(ceph_mount_t *cmount, int fh);
+int ceph_get_file_replication(ceph_mount_t *cmount, int fh);
 int ceph_get_file_stripe_address(ceph_mount_t *cmount, int fd,
                                 loff_t offset, char *buf, int buflen);
+
+/* set default layout for new files */
 int ceph_set_default_file_stripe_unit(ceph_mount_t *cmount, int stripe);
 int ceph_set_default_file_stripe_count(ceph_mount_t *cmount, int count);
 int ceph_set_default_object_size(ceph_mount_t *cmount, int size);
 int ceph_set_default_file_replication(ceph_mount_t *cmount, int replication);
-int ceph_set_default_preferred_pg(ceph_mount_t *cmount, int pg);
+
+/* read from local replicas when possible */
 int ceph_localize_reads(ceph_mount_t *cmount, int val);
 
+/* return osd on local node, if any */
+int ceph_get_local_osd(ceph_mount_t *cmount);
+
 #ifdef __cplusplus
 }
 #endif
index bff340b328fb29451ac68c5f575be0474f01aa28..bc0cbf6595c7c32cb9ff9672a913994e67c637ea 100644 (file)
@@ -506,25 +506,33 @@ extern "C" int ceph_sync_fs(ceph_mount_t *cmount)
   return cmount->get_client()->sync_fs();
 }
 
+
 extern "C" int ceph_get_file_stripe_unit(ceph_mount_t *cmount, int fh)
 {
-  return cmount->get_client()->get_file_stripe_unit(fh);
+  struct ceph_file_layout l;
+  int r = cmount->get_client()->describe_layout(fh, &l);
+  if (r < 0)
+    return r;
+  return l.fl_stripe_unit;
 }
 
-extern "C" int ceph_get_file_replication(ceph_mount_t *cmount,
-                                        const char *path)
+extern "C" int ceph_get_file_pool(ceph_mount_t *cmount, int fh)
 {
-  int fd = cmount->get_client()->open(path, O_RDONLY);
-  if (fd < 0)
-    return fd;
-  int rep = cmount->get_client()->get_file_replication(fd);
-  cmount->get_client()->close(fd);
-  return rep;
+  struct ceph_file_layout l;
+  int r = cmount->get_client()->describe_layout(fh, &l);
+  if (r < 0)
+    return r;
+  return l.fl_pg_pool;
 }
 
-extern "C" int ceph_get_default_preferred_pg(ceph_mount_t *cmount, int fd)
+extern "C" int ceph_get_file_replication(ceph_mount_t *cmount, int fh)
 {
-  return cmount->get_client()->get_default_preferred_pg(fd);
+  struct ceph_file_layout l;
+  int r = cmount->get_client()->describe_layout(fh, &l);
+  if (r < 0)
+    return r;
+  int rep = cmount->get_client()->get_pool_replication(l.fl_pg_pool);
+  return rep;
 }
 
 extern "C" int ceph_set_default_file_stripe_unit(ceph_mount_t *cmount,
@@ -565,12 +573,13 @@ extern "C" int ceph_get_file_stripe_address(ceph_mount_t *cmount, int fh,
 {
   string address;
   int r = cmount->get_client()->get_file_stripe_address(fh, offset, address);
-  if (r != 0) return r; //at time of writing, method ONLY returns
-  // 0 or -EINVAL if there are no known osds
+  if (r < 0)
+    return r; 
   int len = address.size()+1;
   if (len > buflen) {
-    if (buflen == 0) return len;
-    else return -ERANGE;
+    if (buflen == 0)
+      return len;
+    return -ERANGE;
   }
   len = address.copy(buf, len, 0);
   buf[len] = '\0'; // write a null char to terminate c-style string