2 * This is an example RADOS object class built using only the Ceph SDK interface.
4 #include "include/rados/objclass.h"
10 cls_method_handle_t h_test_coverage_write;
11 cls_method_handle_t h_test_coverage_replay;
14 * test_coverage_write - a "write" method that creates an object
16 * This method modifies the object by making multiple write calls (write,
17 * setxattr and set_val).
19 static int test_coverage_write(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
22 int ret = cls_cxx_create(hctx, false);
24 CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__, ret);
29 // get the size of the object
30 ret = cls_cxx_stat(hctx, &size, NULL);
34 std::string c = "test";
38 // write to the object
39 ret = cls_cxx_write(hctx, 0, bl.length(), &bl);
44 // get the new size of the object
45 ret = cls_cxx_stat(hctx, &new_size, NULL);
49 // make some change to the xattr
50 ret = cls_cxx_setxattr(hctx, "foo", &bl);
54 // make some change to the omap
55 ret = cls_cxx_map_set_val(hctx, "foo", &bl);
63 * test_coverage_replay - a "read" method to retrieve previously written data
65 * This method reads the object by making multiple read calls (read, getxattr
66 * and get_val). It also removes the object after reading.
69 static int test_coverage_replay(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
71 CLS_LOG(0, "reading already written object");
73 // get the size of the object
74 int ret = cls_cxx_stat(hctx, &size, NULL);
79 // read the object entry
80 ret = cls_cxx_read(hctx, 0, size, &bl);
84 // if the size is incorrect
85 if (bl.length() != size)
91 ret = cls_cxx_getxattr(hctx, "foo", &bl);
95 // if the size is incorrect
96 if (bl.length() != size)
102 ret = cls_cxx_map_get_val(hctx, "foo", &bl);
106 // if the size is incorrect
107 if (bl.length() != size)
111 ret = cls_cxx_remove(hctx);
120 CLS_LOG(0, "loading cls_sdk");
122 cls_register("sdk", &h_class);
124 cls_register_cxx_method(h_class, "test_coverage_write",
125 CLS_METHOD_RD|CLS_METHOD_WR,
126 test_coverage_write, &h_test_coverage_write);
128 cls_register_cxx_method(h_class, "test_coverage_replay",
129 CLS_METHOD_RD|CLS_METHOD_WR,
130 test_coverage_replay, &h_test_coverage_replay);