3 #include "include/types.h"
4 #include "cls/statelog/cls_statelog_ops.h"
5 #include "include/rados/librados.hpp"
8 using namespace librados
;
11 void cls_statelog_add(librados::ObjectWriteOperation
& op
, list
<cls_statelog_entry
>& entries
)
14 cls_statelog_add_op call
;
15 call
.entries
= entries
;
17 op
.exec("statelog", "add", in
);
20 void cls_statelog_add(librados::ObjectWriteOperation
& op
, cls_statelog_entry
& entry
)
23 cls_statelog_add_op call
;
24 call
.entries
.push_back(entry
);
26 op
.exec("statelog", "add", in
);
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
)
32 entry
.client_id
= client_id
;
34 entry
.object
= object
;
35 entry
.timestamp
= timestamp
;
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
)
44 cls_statelog_entry entry
;
46 cls_statelog_add_prepare_entry(entry
, client_id
, op_id
, object
, timestamp
, state
, bl
);
47 cls_statelog_add(op
, entry
);
50 void cls_statelog_remove_by_client(librados::ObjectWriteOperation
& op
, const string
& client_id
, const string
& op_id
)
53 cls_statelog_remove_op call
;
54 call
.client_id
= client_id
;
57 op
.exec("statelog", "remove", in
);
60 void cls_statelog_remove_by_object(librados::ObjectWriteOperation
& op
, const string
& object
, const string
& op_id
)
63 cls_statelog_remove_op call
;
67 op
.exec("statelog", "remove", in
);
70 class StateLogListCtx
: public ObjectOperationCompletion
{
71 list
<cls_statelog_entry
> *entries
;
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
{
79 cls_statelog_list_ret ret
;
81 bufferlist::iterator iter
= outbl
.begin();
84 *entries
= ret
.entries
;
86 *truncated
= ret
.truncated
;
89 } catch (buffer::error
& err
) {
90 // nothing we can do about it atm
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
)
102 cls_statelog_list_op call
;
103 call
.client_id
= client_id
;
105 call
.object
= object
;
106 call
.marker
= in_marker
;
107 call
.max_entries
= max_entries
;
109 ::encode(call
, inbl
);
111 op
.exec("statelog", "list", inbl
, new StateLogListCtx(&entries
, out_marker
, truncated
));
114 void cls_statelog_check_state(librados::ObjectOperation
& op
, const string
& client_id
, const string
& op_id
, const string
& object
, uint32_t state
)
117 cls_statelog_check_state_op call
;
118 call
.client_id
= client_id
;
120 call
.object
= object
;
123 ::encode(call
, inbl
);
125 op
.exec("statelog", "check_state", inbl
, NULL
);