1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_OBJCLASS_H
5 #define CEPH_OBJCLASS_H
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"
15 struct obj_list_watch_response_t
;
18 #define CEPH_CLS_API __attribute__ ((visibility ("default")))
26 #define CLS_METHOD_PUBLIC 0x4 /// unused
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
);
38 extern void *cls_alloc(size_t size
);
39 extern void cls_free(void *p
);
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
);
55 /* class registration api */
56 extern int cls_unregister(cls_handle_t
);
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
);
69 typedef int cls_trigger_t
;
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
);
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);
89 virtual ~PGLSFilter();
90 virtual bool filter(const hobject_t
&obj
, bufferlist
& xattr_data
,
91 bufferlist
& outdata
) = 0;
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.
98 virtual int init(bufferlist::iterator
¶ms
) = 0;
101 * xattr key, or empty string. If non-empty, this xattr will be fetched
102 * and the value passed into ::filter
104 virtual string
& get_xattr() { return xattr
; }
107 * If true, objects without the named xattr (if xattr name is not empty)
108 * will be rejected without calling ::filter
110 virtual bool reject_empty_xattr() { return true; }
113 // Classes expose a filter constructor that returns a subclass of PGLSFilter
114 typedef PGLSFilter
* (*cls_cxx_filter_factory_t
)();
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
);
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
,
133 std::map
<string
, bufferlist
> *vals
,
135 extern int cls_cxx_map_get_keys(cls_method_context_t hctx
,
136 const string
&start_after
,
138 std::set
<string
> *keys
,
140 extern int cls_cxx_map_get_vals(cls_method_context_t hctx
,
141 const string
&start_after
,
142 const string
&filter_prefix
,
144 std::map
<string
, bufferlist
> *vals
,
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
);
153 extern int cls_cxx_list_watchers(cls_method_context_t hctx
,
154 obj_list_watch_response_t
*watchers
);
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 */
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
);
167 extern void cls_cxx_subop_version(cls_method_context_t hctx
, string
*s
);
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'