From 0da60eadd7acbde344b3e6575dc1aadc20026ce7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 22 Apr 2011 13:15:50 -0700 Subject: [PATCH] client, libceph: clean up layout methods Signed-off-by: Sage Weil --- src/client/Client.cc | 44 ++++++++++---------------------------------- src/client/Client.h | 8 +++----- src/client/libceph.h | 24 ++++++++++++++++-------- src/libceph.cc | 39 ++++++++++++++++++++++++--------------- 4 files changed, 53 insertions(+), 62 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index bbc63cb9cb3d6..5a2aa790a5783 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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); diff --git a/src/client/Client.h b/src/client/Client.h index f479f2e5fce59..e50555809bcff 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -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); diff --git a/src/client/libceph.h b/src/client/libceph.h index 558d04f58dfda..aad537253526a 100644 --- a/src/client/libceph.h +++ b/src/client/libceph.h @@ -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 diff --git a/src/libceph.cc b/src/libceph.cc index bff340b328fb2..bc0cbf6595c7c 100644 --- a/src/libceph.cc +++ b/src/libceph.cc @@ -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 -- 2.39.5