]>
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 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 | ||
b3b6e05e | 63 | int RGWSI_OTP::do_start(optional_yield, const DoutPrefixProvider *dpp) |
9f95a23c TL |
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, | |
b3b6e05e | 91 | optional_yield y, const DoutPrefixProvider *dpp) |
9f95a23c TL |
92 | { |
93 | RGWSI_MBOTP_GetParams params; | |
94 | params.pdevices = devices; | |
95 | params.pmtime = pmtime; | |
96 | ||
b3b6e05e | 97 | int ret = svc.meta_be->get_entry(ctx.get(), key, params, objv_tracker, y, dpp); |
9f95a23c TL |
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, | |
b3b6e05e TL |
110 | optional_yield y, |
111 | const DoutPrefixProvider *dpp) | |
9f95a23c TL |
112 | { |
113 | return read_all(ctx, | |
114 | uid.to_str(), | |
115 | devices, | |
116 | pmtime, | |
117 | objv_tracker, | |
b3b6e05e TL |
118 | y, |
119 | dpp); | |
9f95a23c TL |
120 | } |
121 | ||
b3b6e05e TL |
122 | int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp, |
123 | RGWSI_OTP_BE_Ctx& ctx, | |
9f95a23c TL |
124 | const string& key, |
125 | const otp_devices_list_t& devices, | |
126 | real_time mtime, | |
127 | RGWObjVersionTracker *objv_tracker, | |
128 | optional_yield y) | |
129 | { | |
130 | RGWSI_MBOTP_PutParams params; | |
131 | params.mtime = mtime; | |
132 | params.devices = devices; | |
133 | ||
b3b6e05e | 134 | int ret = svc.meta_be->put_entry(dpp, ctx.get(), key, params, objv_tracker, y); |
9f95a23c TL |
135 | if (ret < 0) { |
136 | return ret; | |
137 | } | |
138 | ||
139 | return 0; | |
140 | } | |
141 | ||
b3b6e05e TL |
142 | int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp, |
143 | RGWSI_OTP_BE_Ctx& ctx, | |
9f95a23c TL |
144 | const rgw_user& uid, |
145 | const otp_devices_list_t& devices, | |
146 | real_time mtime, | |
147 | RGWObjVersionTracker *objv_tracker, | |
148 | optional_yield y) | |
149 | { | |
b3b6e05e | 150 | return store_all(dpp, ctx, |
9f95a23c TL |
151 | uid.to_str(), |
152 | devices, | |
153 | mtime, | |
154 | objv_tracker, | |
155 | y); | |
156 | } | |
157 | ||
b3b6e05e TL |
158 | int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp, |
159 | RGWSI_OTP_BE_Ctx& ctx, | |
9f95a23c TL |
160 | const string& key, |
161 | RGWObjVersionTracker *objv_tracker, | |
162 | optional_yield y) | |
163 | { | |
164 | RGWSI_MBOTP_RemoveParams params; | |
165 | ||
b3b6e05e | 166 | int ret = svc.meta_be->remove_entry(dpp, ctx.get(), key, params, objv_tracker, y); |
9f95a23c TL |
167 | if (ret < 0) { |
168 | return ret; | |
169 | } | |
170 | ||
171 | return 0; | |
172 | } | |
173 | ||
b3b6e05e TL |
174 | int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp, |
175 | RGWSI_OTP_BE_Ctx& ctx, | |
9f95a23c TL |
176 | const rgw_user& uid, |
177 | RGWObjVersionTracker *objv_tracker, | |
178 | optional_yield y) | |
179 | { | |
b3b6e05e | 180 | return remove_all(dpp,ctx, |
9f95a23c TL |
181 | uid.to_str(), |
182 | objv_tracker, | |
183 | y); | |
184 | } |