]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/statelog/cls_statelog_client.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / cls / statelog / cls_statelog_client.cc
1 #include <errno.h>
2
3 #include "include/types.h"
4 #include "cls/statelog/cls_statelog_ops.h"
5 #include "include/rados/librados.hpp"
6
7
8 using namespace librados;
9
10
11 void cls_statelog_add(librados::ObjectWriteOperation& op, list<cls_statelog_entry>& entries)
12 {
13 bufferlist in;
14 cls_statelog_add_op call;
15 call.entries = entries;
16 ::encode(call, in);
17 op.exec("statelog", "add", in);
18 }
19
20 void cls_statelog_add(librados::ObjectWriteOperation& op, cls_statelog_entry& entry)
21 {
22 bufferlist in;
23 cls_statelog_add_op call;
24 call.entries.push_back(entry);
25 ::encode(call, in);
26 op.exec("statelog", "add", in);
27 }
28
29 void cls_statelog_add_prepare_entry(cls_statelog_entry& entry, const string& client_id, const string& op_id,
30 const string& object, const utime_t& timestamp, uint32_t state, bufferlist& bl)
31 {
32 entry.client_id = client_id;
33 entry.op_id = op_id;
34 entry.object = object;
35 entry.timestamp = timestamp;
36 entry.state = state;
37 entry.data = bl;
38 }
39
40 void cls_statelog_add(librados::ObjectWriteOperation& op, const string& client_id, const string& op_id,
41 const string& object, const utime_t& timestamp, uint32_t state, bufferlist& bl)
42
43 {
44 cls_statelog_entry entry;
45
46 cls_statelog_add_prepare_entry(entry, client_id, op_id, object, timestamp, state, bl);
47 cls_statelog_add(op, entry);
48 }
49
50 void cls_statelog_remove_by_client(librados::ObjectWriteOperation& op, const string& client_id, const string& op_id)
51 {
52 bufferlist in;
53 cls_statelog_remove_op call;
54 call.client_id = client_id;
55 call.op_id = op_id;
56 ::encode(call, in);
57 op.exec("statelog", "remove", in);
58 }
59
60 void cls_statelog_remove_by_object(librados::ObjectWriteOperation& op, const string& object, const string& op_id)
61 {
62 bufferlist in;
63 cls_statelog_remove_op call;
64 call.object = object;
65 call.op_id = op_id;
66 ::encode(call, in);
67 op.exec("statelog", "remove", in);
68 }
69
70 class StateLogListCtx : public ObjectOperationCompletion {
71 list<cls_statelog_entry> *entries;
72 string *marker;
73 bool *truncated;
74 public:
75 StateLogListCtx(list<cls_statelog_entry> *_entries, string *_marker, bool *_truncated) :
76 entries(_entries), marker(_marker), truncated(_truncated) {}
77 void handle_completion(int r, bufferlist& outbl) override {
78 if (r >= 0) {
79 cls_statelog_list_ret ret;
80 try {
81 bufferlist::iterator iter = outbl.begin();
82 ::decode(ret, iter);
83 if (entries)
84 *entries = ret.entries;
85 if (truncated)
86 *truncated = ret.truncated;
87 if (marker)
88 *marker = ret.marker;
89 } catch (buffer::error& err) {
90 // nothing we can do about it atm
91 }
92 }
93 }
94 };
95
96 void cls_statelog_list(librados::ObjectReadOperation& op,
97 const string& client_id, const string& op_id, const string& object, /* op_id may be empty, also one of client_id, object*/
98 const string& in_marker, int max_entries, list<cls_statelog_entry>& entries,
99 string *out_marker, bool *truncated)
100 {
101 bufferlist inbl;
102 cls_statelog_list_op call;
103 call.client_id = client_id;
104 call.op_id = op_id;
105 call.object = object;
106 call.marker = in_marker;
107 call.max_entries = max_entries;
108
109 ::encode(call, inbl);
110
111 op.exec("statelog", "list", inbl, new StateLogListCtx(&entries, out_marker, truncated));
112 }
113
114 void cls_statelog_check_state(librados::ObjectOperation& op, const string& client_id, const string& op_id, const string& object, uint32_t state)
115 {
116 bufferlist inbl;
117 cls_statelog_check_state_op call;
118 call.client_id = client_id;
119 call.op_id = op_id;
120 call.object = object;
121 call.state = state;
122
123 ::encode(call, inbl);
124
125 op.exec("statelog", "check_state", inbl, NULL);
126 }
127