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