return code;
}
-void usage()
+static void usage()
{
cerr << "usage: ceph-mon -i monid [flags]" << std::endl;
cerr << " --debug_mon n\n";
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;
}
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);
osd->handle_signal(signum);
}
-void usage()
+static void usage()
{
cout << "usage: ceph-osd -i <osdid>\n"
<< " --osd-data PATH data directory\n"
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);
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,
*/
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
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
#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"
#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)
{
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()
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);
+}