]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/ClassHandler.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / osd / ClassHandler.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_CLASSHANDLER_H
4 #define CEPH_CLASSHANDLER_H
5
6 #include <variant>
7
8 #include "include/types.h"
9 #include "include/common_fwd.h"
10 #include "common/ceph_mutex.h"
11 #include "objclass/objclass.h"
12
13 //forward declaration
14 class ClassHandler
15 {
16 public:
17 CephContext *cct;
18 struct ClassData;
19
20 struct ClassMethod {
21 const std::string name;
22 using func_t = std::variant<cls_method_cxx_call_t, cls_method_call_t>;
23 func_t func;
24 int flags = 0;
25 ClassData *cls = nullptr;
26
27 int exec(cls_method_context_t ctx,
28 ceph::bufferlist& indata,
29 ceph::bufferlist& outdata);
30 void unregister();
31
32 int get_flags() {
33 std::lock_guard l(cls->handler->mutex);
34 return flags;
35 }
36 ClassMethod(const char* name, func_t call, int flags, ClassData* cls)
37 : name{name}, func{call}, flags{flags}, cls{cls}
38 {}
39 };
40
41 struct ClassFilter {
42 ClassData *cls = nullptr;
43 std::string name;
44 cls_cxx_filter_factory_t fn = nullptr;
45
46 void unregister();
47 };
48
49 struct ClassData {
50 enum Status {
51 CLASS_UNKNOWN,
52 CLASS_MISSING, // missing
53 CLASS_MISSING_DEPS, // missing dependencies
54 CLASS_INITIALIZING, // calling init() right now
55 CLASS_OPEN, // initialized, usable
56 } status = CLASS_UNKNOWN;
57
58 std::string name;
59 ClassHandler *handler = nullptr;
60 void *handle = nullptr;
61
62 bool allowed = false;
63
64 std::map<std::string, ClassMethod> methods_map;
65 std::map<std::string, ClassFilter> filters_map;
66
67 std::set<ClassData *> dependencies; /* our dependencies */
68 std::set<ClassData *> missing_dependencies; /* only missing dependencies */
69
70 ClassMethod *_get_method(const std::string& mname);
71
72 ClassMethod *register_method(const char *mname,
73 int flags,
74 cls_method_call_t func);
75 ClassMethod *register_cxx_method(const char *mname,
76 int flags,
77 cls_method_cxx_call_t func);
78 void unregister_method(ClassMethod *method);
79
80 ClassFilter *register_cxx_filter(const std::string &filter_name,
81 cls_cxx_filter_factory_t fn);
82 void unregister_filter(ClassFilter *method);
83
84 ClassMethod *get_method(const std::string& mname) {
85 std::lock_guard l(handler->mutex);
86 return _get_method(mname);
87 }
88 int get_method_flags(const std::string& mname);
89
90 ClassFilter *get_filter(const std::string &filter_name) {
91 std::lock_guard l(handler->mutex);
92 if (auto i = filters_map.find(filter_name); i == filters_map.end()) {
93 return nullptr;
94 } else {
95 return &(i->second);
96 }
97 }
98 };
99
100 private:
101 std::map<std::string, ClassData> classes;
102
103 ClassData *_get_class(const std::string& cname, bool check_allowed);
104 int _load_class(ClassData *cls);
105
106 static bool in_class_list(const std::string& cname,
107 const std::string& list);
108
109 ceph::mutex mutex = ceph::make_mutex("ClassHandler");
110
111 public:
112 explicit ClassHandler(CephContext *cct) : cct(cct) {}
113
114 int open_all_classes();
115 int open_class(const std::string& cname, ClassData **pcls);
116
117 ClassData *register_class(const char *cname);
118 void unregister_class(ClassData *cls);
119
120 void shutdown();
121
122 static ClassHandler& get_instance();
123 };
124
125
126 #endif