]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_OBJCLASS_H | |
5 | #define CEPH_OBJCLASS_H | |
6 | ||
7 | #ifdef __cplusplus | |
8 | ||
9 | #include "../include/types.h" | |
10 | #include "msg/msg_types.h" | |
11 | #include "common/hobject.h" | |
12 | #include "common/ceph_time.h" | |
13 | #include "include/rados/objclass.h" | |
14 | ||
15 | struct obj_list_watch_response_t; | |
16 | ||
17 | #if __GNUC__ >= 4 | |
18 | #define CEPH_CLS_API __attribute__ ((visibility ("default"))) | |
19 | #else | |
20 | #define CEPH_CLS_API | |
21 | #endif | |
22 | ||
23 | extern "C" { | |
24 | #endif | |
25 | ||
26 | #define CLS_METHOD_PUBLIC 0x4 /// unused | |
27 | ||
28 | typedef void *cls_filter_handle_t; | |
29 | typedef int (*cls_method_call_t)(cls_method_context_t ctx, | |
30 | char *indata, int datalen, | |
31 | char **outdata, int *outdatalen); | |
32 | typedef struct { | |
33 | const char *name; | |
34 | const char *ver; | |
35 | } cls_deps_t; | |
36 | ||
37 | /* class utils */ | |
38 | extern void *cls_alloc(size_t size); | |
39 | extern void cls_free(void *p); | |
40 | ||
41 | extern int cls_read(cls_method_context_t hctx, int ofs, int len, | |
42 | char **outdata, int *outdatalen); | |
43 | extern int cls_call(cls_method_context_t hctx, const char *cls, const char *method, | |
44 | char *indata, int datalen, | |
45 | char **outdata, int *outdatalen); | |
46 | extern int cls_getxattr(cls_method_context_t hctx, const char *name, | |
47 | char **outdata, int *outdatalen); | |
48 | extern int cls_setxattr(cls_method_context_t hctx, const char *name, | |
49 | const char *value, int val_len); | |
50 | /** This will fill in the passed origin pointer with the origin of the | |
51 | * request which activated your class call. */ | |
52 | extern int cls_get_request_origin(cls_method_context_t hctx, | |
53 | entity_inst_t *origin); | |
54 | ||
55 | /* class registration api */ | |
56 | extern int cls_unregister(cls_handle_t); | |
57 | ||
58 | extern int cls_register_method(cls_handle_t hclass, const char *method, int flags, | |
59 | cls_method_call_t class_call, cls_method_handle_t *handle); | |
60 | extern int cls_unregister_method(cls_method_handle_t handle); | |
61 | extern void cls_unregister_filter(cls_filter_handle_t handle); | |
62 | ||
63 | ||
64 | ||
65 | /* triggers */ | |
66 | #define OBJ_READ 0x1 | |
67 | #define OBJ_WRITE 0x2 | |
68 | ||
69 | typedef int cls_trigger_t; | |
70 | ||
71 | extern int cls_link(cls_method_handle_t handle, int priority, cls_trigger_t trigger); | |
72 | extern int cls_unlink(cls_method_handle_t handle); | |
73 | ||
74 | ||
75 | /* should be defined by the class implementation | |
76 | defined here inorder to get it compiled without C++ mangling */ | |
77 | extern void class_init(void); | |
78 | extern void class_fini(void); | |
79 | ||
80 | #ifdef __cplusplus | |
81 | } | |
82 | ||
83 | class PGLSFilter { | |
84 | CephContext* cct; | |
85 | protected: | |
86 | string xattr; | |
87 | public: | |
88 | PGLSFilter(); | |
89 | virtual ~PGLSFilter(); | |
90 | virtual bool filter(const hobject_t &obj, bufferlist& xattr_data, | |
91 | bufferlist& outdata) = 0; | |
92 | ||
93 | /** | |
94 | * Arguments passed from the RADOS client. Implementations must | |
95 | * handle any encoding errors, and return an appropriate error code, | |
96 | * or 0 on valid input. | |
97 | */ | |
98 | virtual int init(bufferlist::iterator ¶ms) = 0; | |
99 | ||
100 | /** | |
101 | * xattr key, or empty string. If non-empty, this xattr will be fetched | |
102 | * and the value passed into ::filter | |
103 | */ | |
104 | virtual string& get_xattr() { return xattr; } | |
105 | ||
106 | /** | |
107 | * If true, objects without the named xattr (if xattr name is not empty) | |
108 | * will be rejected without calling ::filter | |
109 | */ | |
110 | virtual bool reject_empty_xattr() { return true; } | |
111 | }; | |
112 | ||
113 | // Classes expose a filter constructor that returns a subclass of PGLSFilter | |
114 | typedef PGLSFilter* (*cls_cxx_filter_factory_t)(); | |
115 | ||
116 | ||
117 | extern int cls_register_cxx_filter(cls_handle_t hclass, | |
118 | const std::string &filter_name, | |
119 | cls_cxx_filter_factory_t fn, | |
120 | cls_filter_handle_t *handle=NULL); | |
121 | ||
122 | extern int cls_cxx_stat2(cls_method_context_t hctx, uint64_t *size, ceph::real_time *mtime); | |
123 | extern int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len, | |
124 | bufferlist *bl, uint32_t op_flags); | |
125 | extern int cls_cxx_write2(cls_method_context_t hctx, int ofs, int len, | |
126 | bufferlist *bl, uint32_t op_flags); | |
127 | extern int cls_cxx_write_full(cls_method_context_t hctx, bufferlist *bl); | |
128 | extern int cls_cxx_getxattrs(cls_method_context_t hctx, map<string, bufferlist> *attrset); | |
129 | extern int cls_cxx_replace(cls_method_context_t hctx, int ofs, int len, bufferlist *bl); | |
130 | extern int cls_cxx_snap_revert(cls_method_context_t hctx, snapid_t snapid); | |
131 | extern int cls_cxx_map_clear(cls_method_context_t hctx); | |
132 | extern int cls_cxx_map_get_all_vals(cls_method_context_t hctx, | |
c07f9fc5 FG |
133 | std::map<string, bufferlist> *vals, |
134 | bool *more); | |
7c673cae FG |
135 | extern int cls_cxx_map_get_keys(cls_method_context_t hctx, |
136 | const string &start_after, | |
137 | uint64_t max_to_get, | |
c07f9fc5 FG |
138 | std::set<string> *keys, |
139 | bool *more); | |
7c673cae FG |
140 | extern int cls_cxx_map_get_vals(cls_method_context_t hctx, |
141 | const string &start_after, | |
142 | const string &filter_prefix, | |
143 | uint64_t max_to_get, | |
c07f9fc5 FG |
144 | std::map<string, bufferlist> *vals, |
145 | bool *more); | |
7c673cae FG |
146 | extern int cls_cxx_map_read_header(cls_method_context_t hctx, bufferlist *outbl); |
147 | extern int cls_cxx_map_set_vals(cls_method_context_t hctx, | |
148 | const std::map<string, bufferlist> *map); | |
149 | extern int cls_cxx_map_write_header(cls_method_context_t hctx, bufferlist *inbl); | |
150 | extern int cls_cxx_map_remove_key(cls_method_context_t hctx, const string &key); | |
151 | extern int cls_cxx_map_update(cls_method_context_t hctx, bufferlist *inbl); | |
152 | ||
153 | extern int cls_cxx_list_watchers(cls_method_context_t hctx, | |
154 | obj_list_watch_response_t *watchers); | |
155 | ||
156 | /* utility functions */ | |
157 | extern int cls_gen_random_bytes(char *buf, int size); | |
158 | extern int cls_gen_rand_base64(char *dest, int size); /* size should be the required string size + 1 */ | |
159 | ||
160 | /* environment */ | |
161 | extern uint64_t cls_current_version(cls_method_context_t hctx); | |
162 | extern int cls_current_subop_num(cls_method_context_t hctx); | |
163 | extern uint64_t cls_get_features(cls_method_context_t hctx); | |
164 | extern uint64_t cls_get_client_features(cls_method_context_t hctx); | |
165 | ||
166 | /* helpers */ | |
167 | extern void cls_cxx_subop_version(cls_method_context_t hctx, string *s); | |
168 | ||
169 | /* These are also defined in rados.h and librados.h. Keep them in sync! */ | |
170 | #define CEPH_OSD_TMAP_HDR 'h' | |
171 | #define CEPH_OSD_TMAP_SET 's' | |
172 | #define CEPH_OSD_TMAP_CREATE 'c' | |
173 | #define CEPH_OSD_TMAP_RM 'r' | |
174 | ||
175 | ||
176 | #endif | |
177 | ||
178 | #endif |