]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | #include <errno.h> | |
4 | ||
5 | #include "cls/rgw/cls_rgw_ops.h" | |
6 | #include "cls/rgw_gc/cls_rgw_gc_ops.h" | |
7 | #include "cls/queue/cls_queue_ops.h" | |
8 | #include "cls/rgw_gc/cls_rgw_gc_const.h" | |
9 | #include "cls/queue/cls_queue_const.h" | |
10 | #include "cls/rgw_gc/cls_rgw_gc_client.h" | |
11 | ||
f67539c2 TL |
12 | using std::list; |
13 | using std::string; | |
14 | ||
15 | using ceph::decode; | |
16 | using ceph::encode; | |
17 | ||
9f95a23c TL |
18 | using namespace librados; |
19 | ||
20 | void cls_rgw_gc_queue_init(ObjectWriteOperation& op, uint64_t size, uint64_t num_deferred_entries) | |
21 | { | |
22 | bufferlist in; | |
23 | cls_rgw_gc_queue_init_op call; | |
24 | call.size = size; | |
25 | call.num_deferred_entries = num_deferred_entries; | |
26 | encode(call, in); | |
27 | op.exec(RGW_GC_CLASS, RGW_GC_QUEUE_INIT, in); | |
28 | } | |
29 | ||
30 | int cls_rgw_gc_queue_get_capacity(IoCtx& io_ctx, const string& oid, uint64_t& size) | |
31 | { | |
32 | bufferlist in, out; | |
33 | int r = io_ctx.exec(oid, QUEUE_CLASS, QUEUE_GET_CAPACITY, in, out); | |
34 | if (r < 0) | |
35 | return r; | |
36 | ||
37 | cls_queue_get_capacity_ret op_ret; | |
38 | auto iter = out.cbegin(); | |
39 | try { | |
40 | decode(op_ret, iter); | |
f67539c2 | 41 | } catch (ceph::buffer::error& err) { |
9f95a23c TL |
42 | return -EIO; |
43 | } | |
44 | ||
45 | size = op_ret.queue_capacity; | |
46 | ||
47 | return 0; | |
48 | } | |
49 | ||
50 | void cls_rgw_gc_queue_enqueue(ObjectWriteOperation& op, uint32_t expiration_secs, const cls_rgw_gc_obj_info& info) | |
51 | { | |
52 | bufferlist in; | |
53 | cls_rgw_gc_set_entry_op call; | |
54 | call.expiration_secs = expiration_secs; | |
55 | call.info = info; | |
56 | encode(call, in); | |
57 | op.exec(RGW_GC_CLASS, RGW_GC_QUEUE_ENQUEUE, in); | |
58 | } | |
59 | ||
60 | int cls_rgw_gc_queue_list_entries(IoCtx& io_ctx, const string& oid, const string& marker, uint32_t max, bool expired_only, | |
61 | list<cls_rgw_gc_obj_info>& entries, bool *truncated, string& next_marker) | |
62 | { | |
63 | bufferlist in, out; | |
64 | cls_rgw_gc_list_op op; | |
65 | op.marker = marker; | |
66 | op.max = max; | |
67 | op.expired_only = expired_only; | |
68 | encode(op, in); | |
69 | ||
70 | int r = io_ctx.exec(oid, RGW_GC_CLASS, RGW_GC_QUEUE_LIST_ENTRIES, in, out); | |
71 | if (r < 0) | |
72 | return r; | |
73 | ||
74 | cls_rgw_gc_list_ret ret; | |
75 | auto iter = out.cbegin(); | |
76 | try { | |
77 | decode(ret, iter); | |
f67539c2 | 78 | } catch (ceph::buffer::error& err) { |
9f95a23c TL |
79 | return -EIO; |
80 | } | |
81 | ||
82 | entries.swap(ret.entries); | |
83 | ||
84 | *truncated = ret.truncated; | |
85 | ||
86 | next_marker = std::move(ret.next_marker); | |
87 | ||
88 | return 0; | |
89 | } | |
90 | ||
91 | void cls_rgw_gc_queue_remove_entries(ObjectWriteOperation& op, uint32_t num_entries) | |
92 | { | |
93 | bufferlist in, out; | |
94 | cls_rgw_gc_queue_remove_entries_op rem_op; | |
95 | rem_op.num_entries = num_entries; | |
96 | encode(rem_op, in); | |
97 | op.exec(RGW_GC_CLASS, RGW_GC_QUEUE_REMOVE_ENTRIES, in); | |
98 | } | |
99 | ||
100 | void cls_rgw_gc_queue_defer_entry(ObjectWriteOperation& op, uint32_t expiration_secs, const cls_rgw_gc_obj_info& info) | |
101 | { | |
102 | bufferlist in; | |
103 | cls_rgw_gc_queue_defer_entry_op defer_op; | |
104 | defer_op.expiration_secs = expiration_secs; | |
105 | defer_op.info = info; | |
106 | encode(defer_op, in); | |
107 | op.exec(RGW_GC_CLASS, RGW_GC_QUEUE_UPDATE_ENTRY, in); | |
108 | } |