]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
neorados: build new RADOS client using legacy librados::Rados 35964/head
authorJason Dillaman <dillaman@redhat.com>
Mon, 6 Jul 2020 20:08:56 +0000 (16:08 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 6 Jul 2020 21:11:07 +0000 (17:11 -0400)
Client libraries like librbd cannot force the adaptation to neorados
and it would not be ideal to have two effective RADOS cluster
connections for librados and neorados.

The new neorados::RADOS::make_with_librados helper method will
allow neorados to re-use the existing thread pool, MGR, MON, and
objecter already created for librados::Rados.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/include/neorados/RADOS.hpp
src/include/rados/librados.hpp
src/librados/RadosClient.h
src/neorados/RADOS.cc
src/neorados/RADOSImpl.h
src/test/neorados/CMakeLists.txt
src/test/neorados/test_neorados.cc [new file with mode: 0644]

index dd0806741cc9fabf4528015f7e6795b7d86e8fab..5b0b011d3614cdebaa487d7be9fb164ec0599ad2 100644 (file)
@@ -55,6 +55,7 @@
 #include "include/common_fwd.h"
 
 #include "include/buffer.h"
+#include "include/rados/librados_fwd.hpp"
 
 #include "common/ceph_time.h"
 
@@ -531,6 +532,8 @@ public:
     return init.result.get();
   }
 
+  static RADOS make_with_librados(librados::Rados& rados);
+
   RADOS(const RADOS&) = delete;
   RADOS& operator =(const RADOS&) = delete;
 
index 53aa31925d614d72b4ab9760f963bfb2ee53bd56..7fabc7864fdddc4b4882bb4abad49e3cb67212b0 100644 (file)
@@ -19,6 +19,8 @@ namespace libradosstriper
   class RadosStriper;
 }
 
+namespace neorados { class RADOS; }
+
 namespace librados {
 
 using ceph::bufferlist;
@@ -1503,9 +1505,11 @@ inline namespace v14_2_0 {
                                                callback_t cb_safe)
       __attribute__ ((deprecated));
     static AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete);
-    
+
     friend std::ostream& operator<<(std::ostream &oss, const Rados& r);
   private:
+    friend class neorados::RADOS;
+
     // We don't allow assignment or copying
     Rados(const Rados& rhs);
     const Rados& operator=(const Rados& rhs);
index 7475fc678d12863da79e8421068233b34f538f9f..9292a021cdfe3d8264c117bb14b0056de737e22a 100644 (file)
@@ -40,9 +40,12 @@ class MLog;
 class Messenger;
 class AioCompletionImpl;
 
+namespace neorados { namespace detail { class RadosClient; }}
+
 class librados::RadosClient : public Dispatcher,
                              public md_config_obs_t
 {
+  friend neorados::detail::RadosClient;
 public:
   using Dispatcher::cct;
 private:
index 261cc6a937cbe2fdf2864a9073336f7e144a42cd..8a49f05a9c44c57e15ee3785d785efbae124a157 100644 (file)
@@ -759,6 +759,9 @@ void RADOS::make_with_cct(CephContext* cct,
   }
 }
 
+RADOS RADOS::make_with_librados(librados::Rados& rados) {
+  return RADOS{std::make_unique<detail::RadosClient>(rados.client)};
+}
 
 RADOS::RADOS() = default;
 
index 70a4d4fb4ae15f5ca592252cb5a278751907935e..d45ca948123ed34cf7152049b74ed5819529ac72 100644 (file)
@@ -11,8 +11,8 @@
  * Foundation.  See file COPYING.
  *
  */
-#ifndef CEPH_LIBRADOS_RADOSCLIENT_H
-#define CEPH_LIBRADOS_RADOSCLIENT_H
+#ifndef CEPH_NEORADOS_RADOSIMPL_H
+#define CEPH_NEORADOS_RADOSIMPL_H
 
 #include <functional>
 #include <memory>
@@ -24,6 +24,8 @@
 #include "common/ceph_context.h"
 #include "common/ceph_mutex.h"
 
+#include "librados/RadosClient.h"
+
 #include "mon/MonClient.h"
 
 #include "mgr/MgrClient.h"
@@ -68,9 +70,6 @@ public:
   mon_feature_t get_required_monitor_features() const {
     return monclient.with_monmap(std::mem_fn(&MonMap::get_required_features));
   }
-  int get_instance_id() const {
-    return instance_id;
-  }
 };
 
 class Client {
@@ -107,13 +106,29 @@ public:
   }
 
   int get_instance_id() const override {
-    return rados->get_instance_id();
+    return rados->instance_id;
   }
 
 private:
   std::unique_ptr<RADOS> rados;
 };
 
+class RadosClient : public Client {
+public:
+  RadosClient(librados::RadosClient* rados_client)
+    : Client(rados_client->poolctx, {rados_client->cct},
+             rados_client->monclient, rados_client->objecter),
+      rados_client(rados_client) {
+  }
+
+  int get_instance_id() const override {
+    return rados_client->instance_id;
+  }
+
+public:
+  librados::RadosClient* rados_client;
+};
+
 } // namespace detail
 } // namespace neorados
 
index 04a566de8389d3d6a180411e628f7f8b4a17f1c1..309b1bc6f85032302214de55d2beb62fd9b22686 100644 (file)
@@ -1,3 +1,12 @@
+
+add_executable(ceph_test_neorados test_neorados.cc)
+target_link_libraries(ceph_test_neorados global libneorados
+  ${unittest_libs}
+  radostest
+  radostest-cxx
+  librados
+  GTest::GTest)
+
 add_executable(ceph_test_neorados_start_stop start_stop.cc)
 target_link_libraries(ceph_test_neorados_start_stop global libneorados
   ${unittest_libs})
diff --git a/src/test/neorados/test_neorados.cc b/src/test/neorados/test_neorados.cc
new file mode 100644 (file)
index 0000000..953e772
--- /dev/null
@@ -0,0 +1,47 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "include/rados/librados.hpp"
+#include "include/neorados/RADOS.hpp"
+#include "common/async/blocked_completion.h"
+#include "test/librados/test_cxx.h"
+#include "gtest/gtest.h"
+#include <iostream>
+
+namespace neorados {
+
+class TestNeoRADOS : public ::testing::Test {
+public:
+  TestNeoRADOS() {
+  }
+};
+
+TEST_F(TestNeoRADOS, MakeWithLibRADOS) {
+  librados::Rados paleo_rados;
+  auto result = connect_cluster_pp(paleo_rados);
+  ASSERT_EQ("", result);
+
+  auto rados = RADOS::make_with_librados(paleo_rados);
+
+  ReadOp op;
+  bufferlist bl;
+  op.read(0, 0, &bl);
+
+  // provide pool that doesn't exists -- just testing round-trip
+  ASSERT_THROW(
+    rados.execute({"dummy-obj"}, std::numeric_limits<int64_t>::max(),
+                  std::move(op), nullptr, ceph::async::use_blocked),
+    boost::system::system_error);
+}
+
+} // namespace neorados
+
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+
+  int seed = getpid();
+  std::cout << "seed " << seed << std::endl;
+  srand(seed);
+
+  return RUN_ALL_TESTS();
+}