summaryrefslogtreecommitdiffstats
path: root/src/osd/ClassHandler.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/osd/ClassHandler.h
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/osd/ClassHandler.h')
-rw-r--r--src/osd/ClassHandler.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/osd/ClassHandler.h b/src/osd/ClassHandler.h
new file mode 100644
index 00000000..58a14225
--- /dev/null
+++ b/src/osd/ClassHandler.h
@@ -0,0 +1,130 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+#ifndef CEPH_CLASSHANDLER_H
+#define CEPH_CLASSHANDLER_H
+
+#include "include/types.h"
+#include "objclass/objclass.h"
+#include "common/Mutex.h"
+
+//forward declaration
+class CephContext;
+
+class ClassHandler
+{
+public:
+ CephContext *cct;
+
+ struct ClassData;
+
+ struct ClassMethod {
+ struct ClassHandler::ClassData *cls;
+ string name;
+ int flags;
+ cls_method_call_t func;
+ cls_method_cxx_call_t cxx_func;
+
+ int exec(cls_method_context_t ctx, bufferlist& indata, bufferlist& outdata);
+ void unregister();
+
+ int get_flags() {
+ std::lock_guard l(cls->handler->mutex);
+ return flags;
+ }
+
+ ClassMethod() : cls(0), flags(0), func(0), cxx_func(0) {}
+ };
+
+ struct ClassFilter {
+ struct ClassHandler::ClassData *cls = nullptr;
+ std::string name;
+ cls_cxx_filter_factory_t fn;
+
+ void unregister();
+
+ ClassFilter() : fn(0)
+ {}
+ };
+
+ struct ClassData {
+ enum Status {
+ CLASS_UNKNOWN,
+ CLASS_MISSING, // missing
+ CLASS_MISSING_DEPS, // missing dependencies
+ CLASS_INITIALIZING, // calling init() right now
+ CLASS_OPEN, // initialized, usable
+ } status;
+
+ string name;
+ ClassHandler *handler;
+ void *handle;
+
+ bool whitelisted = false;
+
+ map<string, ClassMethod> methods_map;
+ map<string, ClassFilter> filters_map;
+
+ set<ClassData *> dependencies; /* our dependencies */
+ set<ClassData *> missing_dependencies; /* only missing dependencies */
+
+ ClassMethod *_get_method(const char *mname);
+
+ ClassData() : status(CLASS_UNKNOWN),
+ handler(NULL),
+ handle(NULL) {}
+ ~ClassData() { }
+
+ ClassMethod *register_method(const char *mname, int flags, cls_method_call_t func);
+ ClassMethod *register_cxx_method(const char *mname, int flags, cls_method_cxx_call_t func);
+ void unregister_method(ClassMethod *method);
+
+ ClassFilter *register_cxx_filter(
+ const std::string &filter_name,
+ cls_cxx_filter_factory_t fn);
+ void unregister_filter(ClassFilter *method);
+
+ ClassMethod *get_method(const char *mname) {
+ std::lock_guard l(handler->mutex);
+ return _get_method(mname);
+ }
+ int get_method_flags(const char *mname);
+
+ ClassFilter *get_filter(const std::string &filter_name)
+ {
+ std::lock_guard l(handler->mutex);
+ std::map<std::string, ClassFilter>::iterator i = filters_map.find(filter_name);
+ if (i == filters_map.end()) {
+ return NULL;
+ } else {
+ return &(i->second);
+ }
+ }
+ };
+
+private:
+ map<string, ClassData> classes;
+
+ ClassData *_get_class(const string& cname, bool check_allowed);
+ int _load_class(ClassData *cls);
+
+ static bool in_class_list(const std::string& cname,
+ const std::string& list);
+
+public:
+ Mutex mutex;
+
+ explicit ClassHandler(CephContext *cct_) : cct(cct_), mutex("ClassHandler") {}
+
+ int open_all_classes();
+
+ void add_embedded_class(const string& cname);
+ int open_class(const string& cname, ClassData **pcls);
+
+ ClassData *register_class(const char *cname);
+ void unregister_class(ClassData *cls);
+
+ void shutdown();
+};
+
+
+#endif