]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
embedded: Support for running MON and OSD from libcephd
authorBassam Tabbara <bassam.tabbara@quantum.com>
Sat, 5 Nov 2016 01:10:08 +0000 (18:10 -0700)
committerBassam Tabbara <bassam.tabbara@quantum.com>
Tue, 29 Nov 2016 07:48:02 +0000 (23:48 -0800)
Added supported for running MON and OSD daemon code almost
untouched directly from libcephd.

Also added two API functions for generating an FSID and secret
key that can be used to bootstrap a new cluster.

Signed-off-by: Bassam Tabbara <bassam.tabbara@quantum.com>
src/ceph_mon.cc
src/ceph_osd.cc
src/include/cephd/libcephd.h
src/libcephd/CMakeLists.txt
src/libcephd/libcephd.cc

index d592b6804127fdbc082ca1addeb0d08d16614f26..d253390d56196dba1219ba9059ccbee94d2a11f3 100644 (file)
@@ -156,7 +156,7 @@ int check_mon_data_empty()
   return code;
 }
 
-void usage()
+static void usage()
 {
   cerr << "usage: ceph-mon -i monid [flags]" << std::endl;
   cerr << "  --debug_mon n\n";
@@ -180,7 +180,12 @@ void usage()
   generic_server_usage();
 }
 
-int main(int argc, const char **argv) 
+#ifdef BUILDING_FOR_EMBEDDED
+void cephd_preload_embedded_plugins();
+extern "C" int cephd_mon(int argc, const char **argv)
+#else
+int main(int argc, const char **argv)
+#endif
 {
   int err;
 
@@ -492,8 +497,12 @@ int main(int argc, const char **argv)
     }
     common_init_finish(g_ceph_context);
     global_init_chdir(g_ceph_context);
+#ifndef BUILDING_FOR_EMBEDDED
     if (global_init_preload_erasure_code(g_ceph_context) < 0)
       prefork.exit(1);
+#else
+    cephd_preload_embedded_plugins();
+#endif
   }
 
   MonitorDBStore *store = new MonitorDBStore(g_conf->mon_data);
index 5f1f26e16d6774cf8fcf4eece42eccab66679fe1..404fcd430a3a1de8214210e431c49c4a83e3ad66 100644 (file)
@@ -66,7 +66,7 @@ void handle_osd_signal(int signum)
     osd->handle_signal(signum);
 }
 
-void usage() 
+static void usage()
 {
   cout << "usage: ceph-osd -i <osdid>\n"
        << "  --osd-data PATH data directory\n"
@@ -90,7 +90,12 @@ void usage()
   generic_server_usage();
 }
 
-int main(int argc, const char **argv) 
+#ifdef BUILDING_FOR_EMBEDDED
+void cephd_preload_embedded_plugins();
+extern "C" int cephd_osd(int argc, const char **argv)
+#else
+int main(int argc, const char **argv)
+#endif
 {
   vector<const char*> args;
   argv_to_vec(argc, argv, args);
@@ -569,8 +574,10 @@ int main(int argc, const char **argv)
     return -1;
   global_init_chdir(g_ceph_context);
 
+#ifndef BUILDING_FOR_EMBEDDED
   if (global_init_preload_erasure_code(g_ceph_context) < 0)
     return -1;
+#endif
 
   osd = new OSD(g_ceph_context,
                 store,
index 6bc7871c852a21e4a07e60869fb280f03549401e..d8f90c6ddd3d71509a0c573e40b40d9722106e43 100644 (file)
@@ -36,6 +36,46 @@ CEPH_LIBCEPHD_API void cephd_version(int *pmajor, int *pminor, int *ppatch);
  */
 CEPH_LIBCEPHD_API const char *ceph_version(int *pmajor, int *pminor, int *ppatch);
 
+/**
+ * Generates a new cluster id (fsid) and returns a hexadecimal string.
+ *
+ * @param context where to the store the handle
+ * @param buf where to write the fsid
+ * @param len the size of buf in bytes (should be at least 37)
+ * @returns 0 on success, negative error code on failure
+ * @returns -ERANGE if the buffer is too short to contain the key
+  */
+CEPH_LIBCEPHD_API int cephd_generate_fsid(char *buf, size_t len);
+
+/**
+ * Generates a new secret key and returns a base64 encoded string.
+ *
+ * @param context where to the store the handle
+ * @param buf where to write the fsid
+ * @param len the size of buf in bytes
+ * @returns 0 on success, negative error code on failure
+ * @returns -ERANGE if the buffer is too short to contain the key
+ */
+CEPH_LIBCEPHD_API int cephd_generate_secret_key(char *buf, size_t len);
+
+/**
+ * Runs ceph-mon passing in command line args
+ *
+ * @param argc number of parameters
+ * @param argv array of string arguments
+ * @returns 0 on success, negative error code on failure
+ */
+CEPH_LIBCEPHD_API int cephd_run_mon(int argc, const char **argv);
+
+/**
+ * Runs ceph-osd passing in command line args
+ *
+ * @param argc number of parameters
+ * @param argv array of string arguments
+ * @returns 0 on success, negative error code on failure
+ */
+CEPH_LIBCEPHD_API int cephd_run_osd(int argc, const char **argv);
+
 #ifdef __cplusplus
 }
 #endif
index 675e2d386a5564f126fc84d5d7bbf1ab077f8191..31ce2886834a2f32d8b35593c2d33529dc59ca63 100644 (file)
@@ -1,7 +1,11 @@
 include(MergeStaticLibraries)
 
 add_library(cephd_base STATIC
-  libcephd.cc)
+  libcephd.cc
+  ../ceph_mon.cc
+  ../ceph_osd.cc)
+
+set_target_properties(cephd_base PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
 
 set(merge_libs
   cephd_base
index f360017f5b69c438fa8f72185c6f81afbd1a40a1..4a75e433c4d4c150f064f764e82e35ce529ff0c6 100644 (file)
@@ -1,4 +1,8 @@
 #include "acconfig.h"
+#include "auth/Auth.h"
+#include "auth/Crypto.h"
+#include "auth/KeyRing.h"
+#include "common/ceph_argparse.h"
 #include "common/version.h"
 #include "common/PluginRegistry.h"
 #include "compressor/snappy/CompressionPluginSnappy.h"
@@ -12,6 +16,8 @@
 #include "erasure-code/lrc/ErasureCodePluginLrc.h"
 #include "erasure-code/shec/ErasureCodePluginShec.h"
 #include "include/cephd/libcephd.h"
+#include "global/global_context.h"
+#include "global/global_init.h"
 
 extern "C" void cephd_version(int *pmajor, int *pminor, int *ppatch)
 {
@@ -38,6 +44,40 @@ extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch)
   return v;
 }
 
+extern "C" int cephd_generate_fsid(char *buf, size_t len)
+{
+    if (len < sizeof("b06ad912-70d7-4263-a5ff-011462a5929a")) {
+        return -ERANGE;
+    }
+
+    uuid_d fsid;
+    fsid.generate_random();
+    fsid.print(buf);
+
+    return 0;
+}
+
+extern "C" int cephd_generate_secret_key(char *buf, size_t len)
+{
+    CephInitParameters iparams(CEPH_ENTITY_TYPE_MON);
+    CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0);
+    cct->_conf->apply_changes(NULL);
+    cct->init_crypto();
+
+    CryptoKey key;
+    key.create(cct, CEPH_CRYPTO_AES);
+
+    cct->put();
+
+    string keystr;
+    key.encode_base64(keystr);
+    if (keystr.length() >= len) {
+        return -ERANGE;
+    }
+    strcpy(buf, keystr.c_str());
+    return keystr.length();
+}
+
 // load the embedded plugins. This is safe to call multiple
 // times in the same process
 void cephd_preload_embedded_plugins()
@@ -109,3 +149,16 @@ void cephd_preload_embedded_plugins()
     assert(r == 0);
   }
 }
+
+extern "C" int cephd_mon(int argc, const char **argv);
+extern "C" int cephd_osd(int argc, const char **argv);
+
+int cephd_run_mon(int argc, const char **argv)
+{
+    return cephd_mon(argc, argv);
+}
+
+int cephd_run_osd(int argc, const char **argv)
+{
+    return cephd_osd(argc, argv);
+}