3 #include "auth/Crypto.h"
4 #include "auth/KeyRing.h"
5 #include "common/ceph_argparse.h"
6 #include "common/version.h"
7 #include "common/PluginRegistry.h"
8 #include "compressor/snappy/CompressionPluginSnappy.h"
9 #include "compressor/zlib/CompressionPluginZlib.h"
10 #include "compressor/zstd/CompressionPluginZstd.h"
11 #include "erasure-code/ErasureCodePlugin.h"
12 #if __x86_64__ && defined(HAVE_BETTER_YASM_ELF64)
13 #include "erasure-code/isa/ErasureCodePluginIsa.h"
15 #include "erasure-code/jerasure/ErasureCodePluginJerasure.h"
16 #include "erasure-code/jerasure/jerasure_init.h"
17 #include "erasure-code/lrc/ErasureCodePluginLrc.h"
18 #include "erasure-code/shec/ErasureCodePluginShec.h"
19 #include "include/cephd/libcephd.h"
20 #include "global/global_context.h"
21 #include "global/global_init.h"
22 #include "objclass/objclass.h"
24 #include "osd/ClassHandler.h"
26 // forward declarations of RADOS class init functions
37 CLS_INIT(replica_log);
44 extern "C" void cephd_version(int *pmajor, int *pminor, int *ppatch)
47 *pmajor = LIBCEPHD_VER_MAJOR;
49 *pminor = LIBCEPHD_VER_MINOR;
51 *ppatch = LIBCEPHD_VER_PATCH;
54 extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch)
56 int major, minor, patch;
57 const char *v = ceph_version_to_str();
59 int n = sscanf(v, "%d.%d.%d", &major, &minor, &patch);
61 *pmajor = (n >= 1) ? major : 0;
63 *pminor = (n >= 2) ? minor : 0;
65 *ppatch = (n >= 3) ? patch : 0;
69 extern "C" int cephd_generate_fsid(char *buf, size_t len)
71 if (len < sizeof("b06ad912-70d7-4263-a5ff-011462a5929a")) {
76 fsid.generate_random();
82 extern "C" int cephd_generate_secret_key(char *buf, size_t len)
84 CephInitParameters iparams(CEPH_ENTITY_TYPE_MON);
85 CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0);
86 cct->_conf->apply_changes(NULL);
90 key.create(cct, CEPH_CRYPTO_AES);
95 key.encode_base64(keystr);
96 if (keystr.length() >= len) {
99 strcpy(buf, keystr.c_str());
100 return keystr.length();
103 // load the embedded plugins. This is safe to call multiple
104 // times in the same process
105 void cephd_preload_embedded_plugins()
109 // load erasure coding plugins
111 ErasureCodePlugin* plugin;
112 ErasureCodePluginRegistry& reg = ErasureCodePluginRegistry::instance();
113 Mutex::Locker l(reg.lock);
114 reg.disable_dlclose = true;
116 // initialize jerasure (and gf-complete)
117 int w[] = { 4, 8, 16, 32 };
118 r = jerasure_init(4, w);
121 plugin = new ErasureCodePluginJerasure();
122 r = reg.add("jerasure", plugin);
128 plugin = new ErasureCodePluginLrc();
129 r = reg.add("lrc", plugin);
135 plugin = new ErasureCodePluginShec();
136 r = reg.add("shec", plugin);
142 #if __x86_64__ && defined(HAVE_BETTER_YASM_ELF64)
143 plugin = new ErasureCodePluginIsa();
144 r = reg.add("isa", plugin);
152 // now load the compression plugins
155 PluginRegistry *reg = g_ceph_context->get_plugin_registry();
156 Mutex::Locker l(reg->lock);
157 reg->disable_dlclose = true;
159 plugin = new CompressionPluginSnappy(g_ceph_context);
160 r = reg->add("compressor", "snappy", plugin);
166 plugin = new CompressionPluginZlib(g_ceph_context);
167 r = reg->add("compressor", "zlib", plugin);
173 plugin = new CompressionPluginZstd(g_ceph_context);
174 r = reg->add("compressor", "zstd", plugin);
182 void cephd_preload_rados_classes(OSD *osd)
184 // intialize RADOS classes
186 ClassHandler *class_handler = osd->class_handler;
187 Mutex::Locker l(class_handler->mutex);
190 class_handler->add_embedded_class("cephfs");
193 class_handler->add_embedded_class("hello");
195 class_handler->add_embedded_class("journal");
198 class_handler->add_embedded_class("kvs");
201 class_handler->add_embedded_class("lock");
203 class_handler->add_embedded_class("log");
205 class_handler->add_embedded_class("lua");
207 class_handler->add_embedded_class("numops");
210 class_handler->add_embedded_class("rbd");
213 class_handler->add_embedded_class("refcount");
215 class_handler->add_embedded_class("replica_log");
216 replica_log_cls_init();
218 class_handler->add_embedded_class("rgw");
221 class_handler->add_embedded_class("statelog");
223 class_handler->add_embedded_class("timeindex");
224 timeindex_cls_init();
225 class_handler->add_embedded_class("user");
227 class_handler->add_embedded_class("version");
232 extern "C" int cephd_mon(int argc, const char **argv);
233 extern "C" int cephd_osd(int argc, const char **argv);
234 extern "C" int cephd_mds(int argc, const char **argv);
235 extern "C" int cephd_rgw(int argc, const char **argv);
236 extern "C" int cephd_rgw_admin(int argc, const char **argv);
238 int cephd_run_mon(int argc, const char **argv)
240 return cephd_mon(argc, argv);
243 int cephd_run_osd(int argc, const char **argv)
245 return cephd_osd(argc, argv);
248 int cephd_run_mds(int argc, const char **argv)
250 return cephd_mds(argc, argv);
254 int cephd_run_rgw(int argc, const char **argv)
256 return cephd_rgw(argc, argv);
259 int cephd_run_rgw_admin(int argc, const char **argv)
261 return cephd_rgw_admin(argc, argv);