]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/timeindex/cls_timeindex_client.cc
update sources to v12.1.0
[ceph.git] / ceph / src / cls / timeindex / cls_timeindex_client.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <errno.h>
5
6 #include "cls/timeindex/cls_timeindex_ops.h"
7 #include "cls/timeindex/cls_timeindex_client.h"
8 #include "include/compat.h"
9
10 void cls_timeindex_add(
11 librados::ObjectWriteOperation& op,
12 std::list<cls_timeindex_entry>& entries)
13 {
14 librados::bufferlist in;
15 cls_timeindex_add_op call;
16 call.entries = entries;
17
18 ::encode(call, in);
19 op.exec("timeindex", "add", in);
20 }
21
22 void cls_timeindex_add(
23 librados::ObjectWriteOperation& op,
24 cls_timeindex_entry& entry)
25 {
26 librados::bufferlist in;
27 cls_timeindex_add_op call;
28 call.entries.push_back(entry);
29
30 ::encode(call, in);
31 op.exec("timeindex", "add", in);
32 }
33
34 void cls_timeindex_add_prepare_entry(
35 cls_timeindex_entry& entry,
36 const utime_t& key_timestamp,
37 const std::string& key_ext,
38 const librados::bufferlist& bl)
39 {
40 entry.key_ts = key_timestamp;
41 entry.key_ext = key_ext;
42 entry.value = bl;
43 }
44
45 void cls_timeindex_add(
46 librados::ObjectWriteOperation& op,
47 const utime_t& key_timestamp,
48 const std::string& key_ext,
49 const librados::bufferlist& bl)
50 {
51 cls_timeindex_entry entry;
52 cls_timeindex_add_prepare_entry(entry, key_timestamp, key_ext, bl);
53 cls_timeindex_add(op, entry);
54 }
55
56 void cls_timeindex_trim(
57 librados::ObjectWriteOperation& op,
58 const utime_t& from_time,
59 const utime_t& to_time,
60 const std::string& from_marker,
61 const std::string& to_marker)
62 {
63 librados::bufferlist in;
64 cls_timeindex_trim_op call;
65 call.from_time = from_time;
66 call.to_time = to_time;
67 call.from_marker = from_marker;
68 call.to_marker = to_marker;
69
70 ::encode(call, in);
71
72 op.exec("timeindex", "trim", in);
73 }
74
75 int cls_timeindex_trim(
76 librados::IoCtx& io_ctx,
77 const std::string& oid,
78 const utime_t& from_time,
79 const utime_t& to_time,
80 const std::string& from_marker,
81 const std::string& to_marker)
82 {
83 bool done = false;
84
85 do {
86 librados::ObjectWriteOperation op;
87 cls_timeindex_trim(op, from_time, to_time, from_marker, to_marker);
88 int r = io_ctx.operate(oid, &op);
89
90 if (r == -ENODATA)
91 done = true;
92 else if (r < 0)
93 return r;
94 } while (!done);
95
96 return 0;
97 }
98
99 void cls_timeindex_list(
100 librados::ObjectReadOperation& op,
101 const utime_t& from,
102 const utime_t& to,
103 const std::string& in_marker,
104 const int max_entries,
105 std::list<cls_timeindex_entry>& entries,
106 std::string *out_marker,
107 bool *truncated)
108 {
109 librados::bufferlist in;
110 cls_timeindex_list_op call;
111 call.from_time = from;
112 call.to_time = to;
113 call.marker = in_marker;
114 call.max_entries = max_entries;
115
116 ::encode(call, in);
117
118 op.exec("timeindex", "list", in,
119 new TimeindexListCtx(&entries, out_marker, truncated));
120 }