]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/ClassHandler.h
update sources to ceph Nautilus 14.2.1
[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 "include/types.h"
7 #include "objclass/objclass.h"
8 #include "common/Mutex.h"
9
10 //forward declaration
11 class CephContext;
12
13 class ClassHandler
14 {
15 public:
16 CephContext *cct;
17
18 struct ClassData;
19
20 struct ClassMethod {
21 struct ClassHandler::ClassData *cls;
22 string name;
23 int flags;
24 cls_method_call_t func;
25 cls_method_cxx_call_t cxx_func;
26
27 int exec(cls_method_context_t ctx, bufferlist& indata, bufferlist& outdata);
28 void unregister();
29
30 int get_flags() {
31 std::lock_guard l(cls->handler->mutex);
32 return flags;
33 }
34
35 ClassMethod() : cls(0), flags(0), func(0), cxx_func(0) {}
36 };
37
38 struct ClassFilter {
39 struct ClassHandler::ClassData *cls = nullptr;
40 std::string name;
41 cls_cxx_filter_factory_t fn;
42
43 void unregister();
44
45 ClassFilter() : fn(0)
46 {}
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;
57
58 string name;
59 ClassHandler *handler;
60 void *handle;
61
62 bool whitelisted = false;
63
64 map<string, ClassMethod> methods_map;
65 map<string, ClassFilter> filters_map;
66
67 set<ClassData *> dependencies; /* our dependencies */
68 set<ClassData *> missing_dependencies; /* only missing dependencies */
69
70 ClassMethod *_get_method(const char *mname);
71
72 ClassData() : status(CLASS_UNKNOWN),
73 handler(NULL),
74 handle(NULL) {}
75 ~ClassData() { }
76
77 ClassMethod *register_method(const char *mname, int flags, cls_method_call_t func);
78 ClassMethod *register_cxx_method(const char *mname, int flags, cls_method_cxx_call_t func);
79 void unregister_method(ClassMethod *method);
80
81 ClassFilter *register_cxx_filter(
82 const std::string &filter_name,
83 cls_cxx_filter_factory_t fn);
84 void unregister_filter(ClassFilter *method);
85
86 ClassMethod *get_method(const char *mname) {
87 std::lock_guard l(handler->mutex);
88 return _get_method(mname);
89 }
90 int get_method_flags(const char *mname);
91
92 ClassFilter *get_filter(const std::string &filter_name)
93 {
94 std::lock_guard l(handler->mutex);
95 std::map<std::string, ClassFilter>::iterator i = filters_map.find(filter_name);
96 if (i == filters_map.end()) {
97 return NULL;
98 } else {
99 return &(i->second);
100 }
101 }
102 };
103
104 private:
105 map<string, ClassData> classes;
106
107 ClassData *_get_class(const string& cname, bool check_allowed);
108 int _load_class(ClassData *cls);
109
110 static bool in_class_list(const std::string& cname,
111 const std::string& list);
112
113 public:
114 Mutex mutex;
115
116 explicit ClassHandler(CephContext *cct_) : cct(cct_), mutex("ClassHandler") {}
117
118 int open_all_classes();
119
120 void add_embedded_class(const string& cname);
121 int open_class(const string& cname, ClassData **pcls);
122
123 ClassData *register_class(const char *cname);
124 void unregister_class(ClassData *cls);
125
126 void shutdown();
127 };
128
129
130 #endif