commit bc6b877288a610ec2b1769441de8a1129118887c
Author: Radoslaw Zarzynski <rzarzynski@mirantis.com>
Date:   Thu Jan 22 17:46:50 2015 +0100

    librados: rectify the pool name caching in IoCtxImpl.
    
    Fixes: #10458
    Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>

diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp
index 7be9968..979e101 100644
--- a/src/include/rados/librados.hpp
+++ b/src/include/rados/librados.hpp
@@ -620,7 +620,7 @@ namespace librados
     // get pool auid
     int get_auid(uint64_t *auid_);
 
-    std::string get_pool_name();
+    std::string get_pool_name() const;
 
     bool pool_requires_alignment();
     uint64_t pool_required_alignment();
@@ -1016,8 +1016,6 @@ namespace librados
     void set_assert_version(uint64_t ver);
     void set_assert_src_version(const std::string& o, uint64_t ver);
 
-    const std::string& get_pool_name() const;
-
     void locator_set_key(const std::string& key);
     void set_namespace(const std::string& nspace);
 
diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc
index d864217..accff80 100644
--- a/src/librados/IoCtxImpl.cc
+++ b/src/librados/IoCtxImpl.cc
@@ -33,9 +33,8 @@ librados::IoCtxImpl::IoCtxImpl() :
 }
 
 librados::IoCtxImpl::IoCtxImpl(RadosClient *c, Objecter *objecter,
-			       int64_t poolid,
-			       const char *pool_name, snapid_t s)
-  : ref_cnt(0), client(c), poolid(poolid), pool_name(pool_name), snap_seq(s),
+			       int64_t poolid, snapid_t s)
+  : ref_cnt(0), client(c), poolid(poolid), snap_seq(s),
     assert_ver(0), last_objver(0),
     notify_timeout(c->cct->_conf->client_notify_timeout),
     oloc(poolid),
diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h
index ab73cfa..b3b5e87 100644
--- a/src/librados/IoCtxImpl.h
+++ b/src/librados/IoCtxImpl.h
@@ -32,7 +32,6 @@ struct librados::IoCtxImpl {
   atomic_t ref_cnt;
   RadosClient *client;
   int64_t poolid;
-  string pool_name;
   snapid_t snap_seq;
   ::SnapContext snapc;
   uint64_t assert_ver;
@@ -51,13 +50,12 @@ struct librados::IoCtxImpl {
 
   IoCtxImpl();
   IoCtxImpl(RadosClient *c, Objecter *objecter,
-	    int64_t poolid, const char *pool_name, snapid_t s);
+	    int64_t poolid, snapid_t s);
 
   void dup(const IoCtxImpl& rhs) {
     // Copy everything except the ref count
     client = rhs.client;
     poolid = rhs.poolid;
-    pool_name = rhs.pool_name;
     snap_seq = rhs.snap_seq;
     snapc = rhs.snapc;
     assert_ver = rhs.assert_ver;
diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc
index ad01832..5440cfd 100644
--- a/src/librados/RadosClient.cc
+++ b/src/librados/RadosClient.cc
@@ -348,20 +348,13 @@ int librados::RadosClient::create_ioctx(const char *name, IoCtxImpl **io)
     }
   }
 
-  *io = new librados::IoCtxImpl(this, objecter, poolid, name, CEPH_NOSNAP);
+  *io = new librados::IoCtxImpl(this, objecter, poolid, CEPH_NOSNAP);
   return 0;
 }
 
 int librados::RadosClient::create_ioctx(int64_t pool_id, IoCtxImpl **io)
 {
-  std::string pool_name;
-  int r = pool_get_name(pool_id, &pool_name);
-  if (r < 0) {
-    return r;
-  }
-
-  *io = new librados::IoCtxImpl(this, objecter, pool_id, pool_name.c_str(),
-                                CEPH_NOSNAP);
+  *io = new librados::IoCtxImpl(this, objecter, pool_id, CEPH_NOSNAP);
   return 0;
 }
 
diff --git a/src/librados/librados.cc b/src/librados/librados.cc
index dfbedaa..54f3679 100644
--- a/src/librados/librados.cc
+++ b/src/librados/librados.cc
@@ -1030,10 +1030,10 @@ uint64_t librados::IoCtx::pool_required_alignment()
   return io_ctx_impl->client->pool_required_alignment(get_id());
 }
 
-std::string librados::IoCtx::get_pool_name()
+std::string librados::IoCtx::get_pool_name() const
 {
   std::string s;
-  io_ctx_impl->client->pool_get_name(get_id(), &s);
+  io_ctx_impl->client->pool_get_name(io_ctx_impl->get_id(), &s);
   return s;
 }
 
@@ -1780,11 +1780,6 @@ void librados::IoCtx::set_assert_src_version(const std::string& oid, uint64_t ve
   io_ctx_impl->set_assert_src_version(obj, ver);
 }
 
-const std::string& librados::IoCtx::get_pool_name() const
-{
-  return io_ctx_impl->pool_name;
-}
-
 void librados::IoCtx::locator_set_key(const string& key)
 {
   io_ctx_impl->oloc.key = key;
@@ -2752,7 +2747,10 @@ extern "C" int rados_ioctx_pool_stat(rados_ioctx_t io, struct rados_pool_stat_t
   tracepoint(librados, rados_ioctx_pool_stat_enter, io);
   librados::IoCtxImpl *io_ctx_impl = (librados::IoCtxImpl *)io;
   list<string> ls;
-  ls.push_back(io_ctx_impl->pool_name);
+  std::string pool_name;
+
+  io_ctx_impl->client->pool_get_name(io_ctx_impl->get_id(), &pool_name);
+  ls.push_back(pool_name);
   map<string, ::pool_stat_t> rawresult;
 
   int err = io_ctx_impl->client->get_pool_stats(ls, rawresult);
@@ -2761,7 +2759,7 @@ extern "C" int rados_ioctx_pool_stat(rados_ioctx_t io, struct rados_pool_stat_t
     return err;
   }
 
-  ::pool_stat_t& r = rawresult[io_ctx_impl->pool_name];
+  ::pool_stat_t& r = rawresult[pool_name];
   stats->num_kb = SHIFT_ROUND_UP(r.stats.sum.num_bytes, 10);
   stats->num_bytes = r.stats.sum.num_bytes;
   stats->num_objects = r.stats.sum.num_objects;
@@ -3061,12 +3059,15 @@ extern "C" int rados_ioctx_get_pool_name(rados_ioctx_t io, char *s, unsigned max
 {
   tracepoint(librados, rados_ioctx_get_pool_name_enter, io, maxlen);
   librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
-  if (ctx->pool_name.length() >= maxlen) {
+  std::string pool_name;
+
+  ctx->client->pool_get_name(ctx->get_id(), &pool_name);
+  if (pool_name.length() >= maxlen) {
     tracepoint(librados, rados_ioctx_get_pool_name_exit, -ERANGE, "");
     return -ERANGE;
   }
-  strcpy(s, ctx->pool_name.c_str());
-  int retval = ctx->pool_name.length();
+  strcpy(s, pool_name.c_str());
+  int retval = pool_name.length();
   tracepoint(librados, rados_ioctx_get_pool_name_exit, retval, s);
   return retval;
 }
diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc
index 0fb46da..950875c 100644
--- a/src/test/librados_test_stub/LibradosTestStub.cc
+++ b/src/test/librados_test_stub/LibradosTestStub.cc
@@ -341,7 +341,7 @@ uint64_t IoCtx::get_last_version() {
   return ctx->get_last_version();
 }
 
-std::string IoCtx::get_pool_name() {
+std::string IoCtx::get_pool_name() const {
   TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl);
   return ctx->get_pool_name();
 }
