]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/services/svc_meta_be_sobj.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / rgw / services / svc_meta_be_sobj.cc
CommitLineData
9f95a23c
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab ft=cpp
3
4#include "svc_meta_be_sobj.h"
5#include "svc_meta_be_params.h"
6#include "svc_mdlog.h"
7
1e59de90
TL
8#include "rgw_tools.h"
9#include "rgw_metadata.h"
10#include "rgw_mdlog.h"
9f95a23c
TL
11
12#define dout_subsys ceph_subsys_rgw
13
20effc67 14using namespace std;
9f95a23c
TL
15
16RGWSI_MetaBackend_SObj::RGWSI_MetaBackend_SObj(CephContext *cct) : RGWSI_MetaBackend(cct) {
17}
18
19RGWSI_MetaBackend_SObj::~RGWSI_MetaBackend_SObj() {
20}
21
22RGWSI_MetaBackend_Handler *RGWSI_MetaBackend_SObj::alloc_be_handler()
23{
24 return new RGWSI_MetaBackend_Handler_SObj(this);
25}
26
27RGWSI_MetaBackend::Context *RGWSI_MetaBackend_SObj::alloc_ctx()
28{
1e59de90 29 return new Context_SObj;
9f95a23c
TL
30}
31
b3b6e05e 32int RGWSI_MetaBackend_SObj::pre_modify(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *_ctx,
9f95a23c
TL
33 const string& key,
34 RGWMetadataLogData& log_data,
35 RGWObjVersionTracker *objv_tracker,
36 RGWMDLogStatus op_type,
37 optional_yield y)
38{
39 auto ctx = static_cast<Context_SObj *>(_ctx);
b3b6e05e 40 int ret = RGWSI_MetaBackend::pre_modify(dpp, ctx, key, log_data,
9f95a23c
TL
41 objv_tracker, op_type,
42 y);
43 if (ret < 0) {
44 return ret;
45 }
46
47 /* if write version has not been set, and there's a read version, set it so that we can
48 * log it
49 */
50 if (objv_tracker) {
51 log_data.read_version = objv_tracker->read_version;
52 log_data.write_version = objv_tracker->write_version;
53 }
54
55 log_data.status = op_type;
56
57 bufferlist logbl;
58 encode(log_data, logbl);
59
b3b6e05e 60 ret = mdlog_svc->add_entry(dpp, ctx->module->get_hash_key(key), ctx->module->get_section(), key, logbl);
9f95a23c
TL
61 if (ret < 0)
62 return ret;
63
64 return 0;
65}
66
b3b6e05e
TL
67int RGWSI_MetaBackend_SObj::post_modify(const DoutPrefixProvider *dpp,
68 RGWSI_MetaBackend::Context *_ctx,
9f95a23c
TL
69 const string& key,
70 RGWMetadataLogData& log_data,
71 RGWObjVersionTracker *objv_tracker, int ret,
72 optional_yield y)
73{
74 auto ctx = static_cast<Context_SObj *>(_ctx);
75 if (ret >= 0)
76 log_data.status = MDLOG_STATUS_COMPLETE;
77 else
78 log_data.status = MDLOG_STATUS_ABORT;
79
80 bufferlist logbl;
81 encode(log_data, logbl);
82
b3b6e05e 83 int r = mdlog_svc->add_entry(dpp, ctx->module->get_hash_key(key), ctx->module->get_section(), key, logbl);
9f95a23c
TL
84 if (ret < 0)
85 return ret;
86
87 if (r < 0)
88 return r;
89
b3b6e05e 90 return RGWSI_MetaBackend::post_modify(dpp, ctx, key, log_data, objv_tracker, ret, y);
9f95a23c
TL
91}
92
93int RGWSI_MetaBackend_SObj::get_shard_id(RGWSI_MetaBackend::Context *_ctx,
94 const std::string& key,
95 int *shard_id)
96{
97 auto ctx = static_cast<Context_SObj *>(_ctx);
98 *shard_id = mdlog_svc->get_shard_id(ctx->module->get_hash_key(key), shard_id);
99 return 0;
100}
101
102int RGWSI_MetaBackend_SObj::call(std::optional<RGWSI_MetaBackend_CtxParams> opt,
103 std::function<int(RGWSI_MetaBackend::Context *)> f)
104{
1e59de90
TL
105 RGWSI_MetaBackend_SObj::Context_SObj ctx;
106 return f(&ctx);
9f95a23c
TL
107}
108
109void RGWSI_MetaBackend_SObj::Context_SObj::init(RGWSI_MetaBackend_Handler *h)
110{
111 RGWSI_MetaBackend_Handler_SObj *handler = static_cast<RGWSI_MetaBackend_Handler_SObj *>(h);
112 module = handler->module;
9f95a23c
TL
113}
114
115int RGWSI_MetaBackend_SObj::call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)> cb)
116{
117 bufferlist bl;
118 RGWSI_MBSObj_GetParams params;
119 params.pmtime = pmtime;
120 params.pbl = &bl;
121 return cb(params);
122}
123
124int RGWSI_MetaBackend_SObj::get_entry(RGWSI_MetaBackend::Context *_ctx,
125 const string& key,
126 GetParams& _params,
127 RGWObjVersionTracker *objv_tracker,
b3b6e05e 128 optional_yield y,
39ae355f
TL
129 const DoutPrefixProvider *dpp,
130 bool get_raw_attrs)
9f95a23c
TL
131{
132 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
133 RGWSI_MBSObj_GetParams& params = static_cast<RGWSI_MBSObj_GetParams&>(_params);
134
135 rgw_pool pool;
136 string oid;
137 ctx->module->get_pool_and_oid(key, &pool, &oid);
138
39ae355f 139 int ret = 0;
1e59de90 140 ret = rgw_get_system_obj(sysobj_svc, pool, oid, *params.pbl,
9f95a23c 141 objv_tracker, params.pmtime,
b3b6e05e 142 y, dpp,
9f95a23c 143 params.pattrs, params.cache_info,
39ae355f
TL
144 params.refresh_version, get_raw_attrs);
145
146 return ret;
9f95a23c
TL
147}
148
b3b6e05e
TL
149int RGWSI_MetaBackend_SObj::put_entry(const DoutPrefixProvider *dpp,
150 RGWSI_MetaBackend::Context *_ctx,
9f95a23c
TL
151 const string& key,
152 PutParams& _params,
153 RGWObjVersionTracker *objv_tracker,
154 optional_yield y)
155{
156 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
157 RGWSI_MBSObj_PutParams& params = static_cast<RGWSI_MBSObj_PutParams&>(_params);
158
159 rgw_pool pool;
160 string oid;
161 ctx->module->get_pool_and_oid(key, &pool, &oid);
162
1e59de90 163 return rgw_put_system_obj(dpp, sysobj_svc, pool, oid, params.bl, params.exclusive,
9f95a23c
TL
164 objv_tracker, params.mtime, y, params.pattrs);
165}
166
b3b6e05e
TL
167int RGWSI_MetaBackend_SObj::remove_entry(const DoutPrefixProvider *dpp,
168 RGWSI_MetaBackend::Context *_ctx,
9f95a23c
TL
169 const string& key,
170 RemoveParams& params,
171 RGWObjVersionTracker *objv_tracker,
172 optional_yield y)
173{
174 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
175
176 rgw_pool pool;
177 string oid;
178 ctx->module->get_pool_and_oid(key, &pool, &oid);
179 rgw_raw_obj k(pool, oid);
180
1e59de90 181 auto sysobj = sysobj_svc->get_obj(k);
9f95a23c
TL
182 return sysobj.wop()
183 .set_objv_tracker(objv_tracker)
b3b6e05e 184 .remove(dpp, y);
9f95a23c
TL
185}
186
b3b6e05e
TL
187int RGWSI_MetaBackend_SObj::list_init(const DoutPrefixProvider *dpp,
188 RGWSI_MetaBackend::Context *_ctx,
9f95a23c
TL
189 const string& marker)
190{
191 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
192
193 rgw_pool pool;
194
195 string no_key;
196 ctx->module->get_pool_and_oid(no_key, &pool, nullptr);
197
198 ctx->list.pool = sysobj_svc->get_pool(pool);
199 ctx->list.op.emplace(ctx->list.pool->op());
200
201 string prefix = ctx->module->get_oid_prefix();
b3b6e05e 202 ctx->list.op->init(dpp, marker, prefix);
9f95a23c
TL
203
204 return 0;
205}
206
20effc67
TL
207int RGWSI_MetaBackend_SObj::list_next(const DoutPrefixProvider *dpp,
208 RGWSI_MetaBackend::Context *_ctx,
9f95a23c
TL
209 int max, list<string> *keys,
210 bool *truncated)
211{
212 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
213
214 vector<string> oids;
215
216 keys->clear();
217
20effc67 218 int ret = ctx->list.op->get_next(dpp, max, &oids, truncated);
9f95a23c
TL
219 if (ret < 0 && ret != -ENOENT)
220 return ret;
221 if (ret == -ENOENT) {
222 if (truncated)
223 *truncated = false;
224 return 0;
225 }
226
227 auto module = ctx->module;
228
229 for (auto& o : oids) {
230 if (!module->is_valid_oid(o)) {
231 continue;
232 }
233 keys->emplace_back(module->oid_to_key(o));
234 }
235
236 return 0;
237}
238
239int RGWSI_MetaBackend_SObj::list_get_marker(RGWSI_MetaBackend::Context *_ctx,
240 string *marker)
241{
242 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
243
244 return ctx->list.op->get_marker(marker);
245}
246