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