]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_otp.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / services / svc_otp.cc
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_otp.h"
5 #include "svc_zone.h"
6 #include "svc_meta.h"
7 #include "svc_meta_be_sobj.h"
8
9 #include "rgw_zone.h"
10
11 #define dout_subsys ceph_subsys_rgw
12
13 using namespace std;
14
15 class RGW_MB_Handler_Module_OTP : public RGWSI_MBSObj_Handler_Module {
16 RGWSI_Zone *zone_svc;
17 string prefix;
18 public:
19 RGW_MB_Handler_Module_OTP(RGWSI_Zone *_zone_svc) : RGWSI_MBSObj_Handler_Module("otp"),
20 zone_svc(_zone_svc) {}
21
22 void get_pool_and_oid(const string& key, rgw_pool *pool, string *oid) override {
23 if (pool) {
24 *pool = zone_svc->get_zone_params().otp_pool;
25 }
26
27 if (oid) {
28 *oid = key;
29 }
30 }
31
32 const string& get_oid_prefix() override {
33 return prefix;
34 }
35
36 bool is_valid_oid(const string& oid) override {
37 return true;
38 }
39
40 string key_to_oid(const string& key) override {
41 return key;
42 }
43
44 string oid_to_key(const string& oid) override {
45 return oid;
46 }
47 };
48
49 RGWSI_OTP::RGWSI_OTP(CephContext *cct): RGWServiceInstance(cct) {
50 }
51
52 RGWSI_OTP::~RGWSI_OTP() {
53 }
54
55 void RGWSI_OTP::init(RGWSI_Zone *_zone_svc,
56 RGWSI_Meta *_meta_svc,
57 RGWSI_MetaBackend *_meta_be_svc)
58 {
59 svc.otp = this;
60 svc.zone = _zone_svc;
61 svc.meta = _meta_svc;
62 svc.meta_be = _meta_be_svc;
63 }
64
65 int RGWSI_OTP::do_start(optional_yield, const DoutPrefixProvider *dpp)
66 {
67 /* create first backend handler for bucket entrypoints */
68
69 RGWSI_MetaBackend_Handler *_otp_be_handler;
70
71 int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_OTP, &_otp_be_handler);
72 if (r < 0) {
73 ldout(ctx(), 0) << "ERROR: failed to create be handler: r=" << r << dendl;
74 return r;
75 }
76
77 be_handler = _otp_be_handler;
78
79 RGWSI_MetaBackend_Handler_OTP *otp_be_handler = static_cast<RGWSI_MetaBackend_Handler_OTP *>(_otp_be_handler);
80
81 auto otp_be_module = new RGW_MB_Handler_Module_OTP(svc.zone);
82 be_module.reset(otp_be_module);
83 otp_be_handler->set_module(otp_be_module);
84
85 return 0;
86 }
87
88 int RGWSI_OTP::read_all(RGWSI_OTP_BE_Ctx& ctx,
89 const string& key,
90 otp_devices_list_t *devices,
91 real_time *pmtime,
92 RGWObjVersionTracker *objv_tracker,
93 optional_yield y, const DoutPrefixProvider *dpp)
94 {
95 RGWSI_MBOTP_GetParams params;
96 params.pdevices = devices;
97 params.pmtime = pmtime;
98
99 int ret = svc.meta_be->get_entry(ctx.get(), key, params, objv_tracker, y, dpp);
100 if (ret < 0) {
101 return ret;
102 }
103
104 return 0;
105 }
106
107 int RGWSI_OTP::read_all(RGWSI_OTP_BE_Ctx& ctx,
108 const rgw_user& uid,
109 otp_devices_list_t *devices,
110 real_time *pmtime,
111 RGWObjVersionTracker *objv_tracker,
112 optional_yield y,
113 const DoutPrefixProvider *dpp)
114 {
115 return read_all(ctx,
116 uid.to_str(),
117 devices,
118 pmtime,
119 objv_tracker,
120 y,
121 dpp);
122 }
123
124 int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp,
125 RGWSI_OTP_BE_Ctx& ctx,
126 const string& key,
127 const otp_devices_list_t& devices,
128 real_time mtime,
129 RGWObjVersionTracker *objv_tracker,
130 optional_yield y)
131 {
132 RGWSI_MBOTP_PutParams params;
133 params.mtime = mtime;
134 params.devices = devices;
135
136 int ret = svc.meta_be->put_entry(dpp, ctx.get(), key, params, objv_tracker, y);
137 if (ret < 0) {
138 return ret;
139 }
140
141 return 0;
142 }
143
144 int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp,
145 RGWSI_OTP_BE_Ctx& ctx,
146 const rgw_user& uid,
147 const otp_devices_list_t& devices,
148 real_time mtime,
149 RGWObjVersionTracker *objv_tracker,
150 optional_yield y)
151 {
152 return store_all(dpp, ctx,
153 uid.to_str(),
154 devices,
155 mtime,
156 objv_tracker,
157 y);
158 }
159
160 int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp,
161 RGWSI_OTP_BE_Ctx& ctx,
162 const string& key,
163 RGWObjVersionTracker *objv_tracker,
164 optional_yield y)
165 {
166 RGWSI_MBOTP_RemoveParams params;
167
168 int ret = svc.meta_be->remove_entry(dpp, ctx.get(), key, params, objv_tracker, y);
169 if (ret < 0) {
170 return ret;
171 }
172
173 return 0;
174 }
175
176 int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp,
177 RGWSI_OTP_BE_Ctx& ctx,
178 const rgw_user& uid,
179 RGWObjVersionTracker *objv_tracker,
180 optional_yield y)
181 {
182 return remove_all(dpp,ctx,
183 uid.to_str(),
184 objv_tracker,
185 y);
186 }