3 #include "cls/statelog/cls_statelog_client.h"
4 #include "include/rados/librados.hpp"
7 using namespace librados;
10 void cls_statelog_add(librados::ObjectWriteOperation& op, list<cls_statelog_entry>& entries)
13 cls_statelog_add_op call;
14 call.entries = entries;
16 op.exec("statelog", "add", in);
19 void cls_statelog_add(librados::ObjectWriteOperation& op, cls_statelog_entry& entry)
22 cls_statelog_add_op call;
23 call.entries.push_back(entry);
25 op.exec("statelog", "add", in);
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)
31 entry.client_id = client_id;
33 entry.object = object;
34 entry.timestamp = timestamp;
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)
43 cls_statelog_entry entry;
45 cls_statelog_add_prepare_entry(entry, client_id, op_id, object, timestamp, state, bl);
46 cls_statelog_add(op, entry);
49 void cls_statelog_remove_by_client(librados::ObjectWriteOperation& op, const string& client_id, const string& op_id)
52 cls_statelog_remove_op call;
53 call.client_id = client_id;
56 op.exec("statelog", "remove", in);
59 void cls_statelog_remove_by_object(librados::ObjectWriteOperation& op, const string& object, const string& op_id)
62 cls_statelog_remove_op call;
66 op.exec("statelog", "remove", in);
69 class StateLogListCtx : public ObjectOperationCompletion {
70 list<cls_statelog_entry> *entries;
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 {
78 cls_statelog_list_ret ret;
80 bufferlist::iterator iter = outbl.begin();
83 *entries = ret.entries;
85 *truncated = ret.truncated;
88 } catch (buffer::error& err) {
89 // nothing we can do about it atm
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)
101 cls_statelog_list_op call;
102 call.client_id = client_id;
104 call.object = object;
105 call.marker = in_marker;
106 call.max_entries = max_entries;
108 ::encode(call, inbl);
110 op.exec("statelog", "list", inbl, new StateLogListCtx(&entries, out_marker, truncated));
113 void cls_statelog_check_state(librados::ObjectOperation& op, const string& client_id, const string& op_id, const string& object, uint32_t state)
116 cls_statelog_check_state_op call;
117 call.client_id = client_id;
119 call.object = object;
122 ::encode(call, inbl);
124 op.exec("statelog", "check_state", inbl, NULL);