3 #include "cls/log/cls_log_ops.h"
4 #include "include/rados/librados.hpp"
5 #include "include/compat.h"
8 using namespace librados;
12 void cls_log_add(librados::ObjectWriteOperation& op, list<cls_log_entry>& entries, bool monotonic_inc)
16 call.entries = entries;
18 op.exec("log", "add", in);
21 void cls_log_add(librados::ObjectWriteOperation& op, cls_log_entry& entry)
25 call.entries.push_back(entry);
27 op.exec("log", "add", in);
30 void cls_log_add_prepare_entry(cls_log_entry& entry, const utime_t& timestamp,
31 const string& section, const string& name, bufferlist& bl)
33 entry.timestamp = timestamp;
34 entry.section = section;
39 void cls_log_add(librados::ObjectWriteOperation& op, const utime_t& timestamp,
40 const string& section, const string& name, bufferlist& bl)
44 cls_log_add_prepare_entry(entry, timestamp, section, name, bl);
45 cls_log_add(op, entry);
48 void cls_log_trim(librados::ObjectWriteOperation& op, const utime_t& from_time, const utime_t& to_time,
49 const string& from_marker, const string& to_marker)
53 call.from_time = from_time;
54 call.to_time = to_time;
55 call.from_marker = from_marker;
56 call.to_marker = to_marker;
58 op.exec("log", "trim", in);
61 int cls_log_trim(librados::IoCtx& io_ctx, const string& oid, const utime_t& from_time, const utime_t& to_time,
62 const string& from_marker, const string& to_marker)
67 ObjectWriteOperation op;
69 cls_log_trim(op, from_time, to_time, from_marker, to_marker);
71 int r = io_ctx.operate(oid, &op);
83 class LogListCtx : public ObjectOperationCompletion {
84 list<cls_log_entry> *entries;
88 LogListCtx(list<cls_log_entry> *_entries, string *_marker, bool *_truncated) :
89 entries(_entries), marker(_marker), truncated(_truncated) {}
90 void handle_completion(int r, bufferlist& outbl) override {
94 bufferlist::iterator iter = outbl.begin();
97 *entries = std::move(ret.entries);
99 *truncated = ret.truncated;
101 *marker = std::move(ret.marker);
102 } catch (buffer::error& err) {
103 // nothing we can do about it atm
109 void cls_log_list(librados::ObjectReadOperation& op, utime_t& from, utime_t& to,
110 const string& in_marker, int max_entries,
111 list<cls_log_entry>& entries,
112 string *out_marker, bool *truncated)
115 cls_log_list_op call;
116 call.from_time = from;
118 call.marker = in_marker;
119 call.max_entries = max_entries;
121 ::encode(call, inbl);
123 op.exec("log", "list", inbl, new LogListCtx(&entries, out_marker, truncated));
126 class LogInfoCtx : public ObjectOperationCompletion {
127 cls_log_header *header;
129 explicit LogInfoCtx(cls_log_header *_header) : header(_header) {}
130 void handle_completion(int r, bufferlist& outbl) override {
132 cls_log_info_ret ret;
134 bufferlist::iterator iter = outbl.begin();
137 *header = ret.header;
138 } catch (buffer::error& err) {
139 // nothing we can do about it atm
145 void cls_log_info(librados::ObjectReadOperation& op, cls_log_header *header)
148 cls_log_info_op call;
150 ::encode(call, inbl);
152 op.exec("log", "info", inbl, new LogInfoCtx(header));