]> git.proxmox.com Git - ceph.git/blame - ceph/src/objclass/objclass.h
update sources to v12.1.2
[ceph.git] / ceph / src / objclass / objclass.h
CommitLineData
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
15struct 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
23extern "C" {
24#endif
25
26#define CLS_METHOD_PUBLIC 0x4 /// unused
27
28typedef void *cls_filter_handle_t;
29typedef int (*cls_method_call_t)(cls_method_context_t ctx,
30 char *indata, int datalen,
31 char **outdata, int *outdatalen);
32typedef struct {
33 const char *name;
34 const char *ver;
35} cls_deps_t;
36
37/* class utils */
38extern void *cls_alloc(size_t size);
39extern void cls_free(void *p);
40
41extern int cls_read(cls_method_context_t hctx, int ofs, int len,
42 char **outdata, int *outdatalen);
43extern int cls_call(cls_method_context_t hctx, const char *cls, const char *method,
44 char *indata, int datalen,
45 char **outdata, int *outdatalen);
46extern int cls_getxattr(cls_method_context_t hctx, const char *name,
47 char **outdata, int *outdatalen);
48extern 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. */
52extern int cls_get_request_origin(cls_method_context_t hctx,
53 entity_inst_t *origin);
54
55/* class registration api */
56extern int cls_unregister(cls_handle_t);
57
58extern 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);
60extern int cls_unregister_method(cls_method_handle_t handle);
61extern 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
69typedef int cls_trigger_t;
70
71extern int cls_link(cls_method_handle_t handle, int priority, cls_trigger_t trigger);
72extern 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 */
77extern void class_init(void);
78extern void class_fini(void);
79
80#ifdef __cplusplus
81}
82
83class PGLSFilter {
84 CephContext* cct;
85protected:
86 string xattr;
87public:
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 &params) = 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
114typedef PGLSFilter* (*cls_cxx_filter_factory_t)();
115
116
117extern 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
122extern int cls_cxx_stat2(cls_method_context_t hctx, uint64_t *size, ceph::real_time *mtime);
123extern int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len,
124 bufferlist *bl, uint32_t op_flags);
125extern int cls_cxx_write2(cls_method_context_t hctx, int ofs, int len,
126 bufferlist *bl, uint32_t op_flags);
127extern int cls_cxx_write_full(cls_method_context_t hctx, bufferlist *bl);
128extern int cls_cxx_getxattrs(cls_method_context_t hctx, map<string, bufferlist> *attrset);
129extern int cls_cxx_replace(cls_method_context_t hctx, int ofs, int len, bufferlist *bl);
130extern int cls_cxx_snap_revert(cls_method_context_t hctx, snapid_t snapid);
131extern int cls_cxx_map_clear(cls_method_context_t hctx);
132extern 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
135extern 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
140extern 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
146extern int cls_cxx_map_read_header(cls_method_context_t hctx, bufferlist *outbl);
147extern int cls_cxx_map_set_vals(cls_method_context_t hctx,
148 const std::map<string, bufferlist> *map);
149extern int cls_cxx_map_write_header(cls_method_context_t hctx, bufferlist *inbl);
150extern int cls_cxx_map_remove_key(cls_method_context_t hctx, const string &key);
151extern int cls_cxx_map_update(cls_method_context_t hctx, bufferlist *inbl);
152
153extern int cls_cxx_list_watchers(cls_method_context_t hctx,
154 obj_list_watch_response_t *watchers);
155
156/* utility functions */
157extern int cls_gen_random_bytes(char *buf, int size);
158extern int cls_gen_rand_base64(char *dest, int size); /* size should be the required string size + 1 */
159
160/* environment */
161extern uint64_t cls_current_version(cls_method_context_t hctx);
162extern int cls_current_subop_num(cls_method_context_t hctx);
163extern uint64_t cls_get_features(cls_method_context_t hctx);
164extern uint64_t cls_get_client_features(cls_method_context_t hctx);
165
166/* helpers */
167extern 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