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