From: Greg Farnum Date: Wed, 5 Aug 2009 19:27:00 +0000 (-0700) Subject: uClient/libceph: implement get_file_replication X-Git-Tag: v0.13~123^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9bc42b5cab303eea562f0a68ec597a1873d47763;p=ceph.git uClient/libceph: implement get_file_replication add it to libceph. --- diff --git a/src/client/Client.cc b/src/client/Client.cc index ae6c86fbc49c..ddbea0fa885e 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -5215,7 +5215,15 @@ int Client::get_file_stripe_period(int fd) int Client::get_file_replication(int fd) { - return 0; + int pool; + Mutex::Locker lock(client_lock); + + assert(fd_map.count(fd)); + Fh *f = fd_map[fd]; + Inode *in = f->inode; + + pool = ceph_file_layout_pg_pool(in->layout); + return osdmap->get_pg_pool(pool).get_size(); } int Client::get_file_stripe_address(int fd, loff_t offset, string& address) diff --git a/src/client/libceph.cc b/src/client/libceph.cc index a7dd4d63ccdc..00661218f24e 100644 --- a/src/client/libceph.cc +++ b/src/client/libceph.cc @@ -261,6 +261,13 @@ extern "C" int ceph_get_file_stripe_unit(int fh) return client->get_file_stripe_unit(fh); } +extern "C" int ceph_get_file_replication(const char *path) { + int fd = client->open(path, O_RDONLY); + int rep = client->get_file_replication(fd); + client->close(fd); + return rep; +} + int ceph_getdir(const char *relpath, std::list& names) { return client->getdir(relpath, names); diff --git a/src/client/libceph.h b/src/client/libceph.h index 5ebb40a4ddc1..0d4b9e983d80 100644 --- a/src/client/libceph.h +++ b/src/client/libceph.h @@ -69,6 +69,7 @@ int ceph_fstat(int fd, struct stat *stbuf); int ceph_sync_fs(); int ceph_get_file_stripe_unit(int fh); +int ceph_get_file_replication(const char *path); #ifdef __cplusplus //not for C, sorry! int ceph_getdir(const char *relpath, std::list& names); diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 45e2f14a7ba8..cd12e509089e 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -185,6 +185,8 @@ struct ceph_file_layout { ((__s32)le32_to_cpu((l).fl_object_stripe_unit)) #define ceph_file_layout_pg_preferred(l) \ ((__s32)le32_to_cpu((l).fl_pg_preferred)) +#define ceph_file_layout_pg_pool(l) \ + ((__s32)le32_to_cpu((l).fl_pg_pool)) #define ceph_file_layout_stripe_width(l) (le32_to_cpu((l).fl_stripe_unit) * \ le32_to_cpu((l).fl_stripe_count))