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_OBJCLASS_PUBLIC_H
5 #define CEPH_OBJCLASS_OBJCLASS_PUBLIC_H
14 #define CEPH_CLS_API [[gnu::visibility("default")]]
16 #define CLS_VER(maj,min) \
17 int __cls_ver__## maj ## _ ##min = 0; \
18 int __cls_ver_maj = maj; \
19 int __cls_ver_min = min;
21 #define CLS_NAME(name) \
22 int __cls_name__## name = 0; \
23 const char *__cls_name = #name;
25 #define CLS_INIT(name) \
26 CEPH_CLS_API void __cls_init()
28 #define CLS_METHOD_RD 0x1 /// method executes read operations
29 #define CLS_METHOD_WR 0x2 /// method executes write operations
30 #define CLS_METHOD_PROMOTE 0x8 /// method cannot be proxied to base tier
32 #define CLS_LOG(level, fmt, ...) \
33 cls_log(level, "<cls> %s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
34 #define CLS_ERR(fmt, ...) CLS_LOG(0, fmt, ##__VA_ARGS__)
42 * @typdef cls_handle_t
44 * A handle for interacting with the object class.
46 typedef void *cls_handle_t
;
49 * @typedef cls_method_handle_t
51 * A handle for interacting with the method of the object class.
53 typedef void *cls_method_handle_t
;
56 * @typedef cls_method_context_t
58 * A context for the method of the object class.
60 typedef void* cls_method_context_t
;
63 extern int cls_log(int level
, const char *format
, ...)
64 __attribute__((__format__(printf
, 2, 3)));
66 /* class registration api */
67 extern int cls_register(const char *name
, cls_handle_t
*handle
);
73 * @typedef cls_method_cxx_call_t
76 typedef int (*cls_method_cxx_call_t
)(cls_method_context_t ctx
,
77 class ceph::buffer::list
*inbl
, class ceph::buffer::list
*outbl
);
88 extern int cls_register_cxx_method(cls_handle_t hclass
, const char *method
, int flags
,
89 cls_method_cxx_call_t class_call
, cls_method_handle_t
*handle
);
97 extern int cls_cxx_create(cls_method_context_t hctx
, bool exclusive
);
104 extern int cls_cxx_remove(cls_method_context_t hctx
);
107 * Check on the status of an object.
113 extern int cls_cxx_stat(cls_method_context_t hctx
, uint64_t *size
, time_t *mtime
);
116 * Read contents of an object.
123 extern int cls_cxx_read(cls_method_context_t hctx
, int ofs
, int len
, ceph::bufferlist
*bl
);
126 * Write to the object.
133 extern int cls_cxx_write(cls_method_context_t hctx
, int ofs
, int len
, ceph::bufferlist
*bl
);
136 * Get xattr of the object.
142 extern int cls_cxx_getxattr(cls_method_context_t hctx
, const char *name
,
143 ceph::bufferlist
*outbl
);
146 * Set xattr of the object.
152 extern int cls_cxx_setxattr(cls_method_context_t hctx
, const char *name
,
153 ceph::bufferlist
*inbl
);
156 * Get value corresponding to a key from the map.
162 extern int cls_cxx_map_get_val(cls_method_context_t hctx
,
163 const std::string
&key
, ceph::bufferlist
*outbl
);
166 * Set value corresponding to a key in the map.
172 extern int cls_cxx_map_set_val(cls_method_context_t hctx
,
173 const std::string
&key
, ceph::bufferlist
*inbl
);