]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include <errno.h> | |
5 | #include <iostream> | |
6 | #include <sstream> | |
7 | #include <string> | |
8 | ||
9 | #include <boost/optional.hpp> | |
10 | ||
11 | #include "auth/Crypto.h" | |
3efd9988 | 12 | #include "compressor/Compressor.h" |
7c673cae FG |
13 | |
14 | #include "common/armor.h" | |
15 | #include "common/ceph_json.h" | |
16 | #include "common/config.h" | |
17 | #include "common/ceph_argparse.h" | |
18 | #include "common/Formatter.h" | |
19 | #include "common/errno.h" | |
20 | #include "common/safe_io.h" | |
21 | ||
22 | #include "cls/rgw/cls_rgw_client.h" | |
23 | ||
24 | #include "global/global_init.h" | |
25 | ||
26 | #include "include/utime.h" | |
27 | #include "include/str_list.h" | |
28 | ||
29 | #include "rgw_user.h" | |
30 | #include "rgw_bucket.h" | |
31 | #include "rgw_rados.h" | |
32 | #include "rgw_acl.h" | |
33 | #include "rgw_acl_s3.h" | |
34 | #include "rgw_lc.h" | |
35 | #include "rgw_log.h" | |
36 | #include "rgw_formats.h" | |
37 | #include "rgw_usage.h" | |
38 | #include "rgw_replica_log.h" | |
39 | #include "rgw_orphan.h" | |
40 | #include "rgw_sync.h" | |
b32b8144 | 41 | #include "rgw_sync_log_trim.h" |
7c673cae FG |
42 | #include "rgw_data_sync.h" |
43 | #include "rgw_rest_conn.h" | |
44 | #include "rgw_realm_watcher.h" | |
45 | #include "rgw_role.h" | |
31f18b77 | 46 | #include "rgw_reshard.h" |
7c673cae FG |
47 | |
48 | using namespace std; | |
49 | ||
50 | #define dout_context g_ceph_context | |
51 | #define dout_subsys ceph_subsys_rgw | |
52 | ||
53 | #define SECRET_KEY_LEN 40 | |
54 | #define PUBLIC_ID_LEN 20 | |
55 | ||
56 | static RGWRados *store = NULL; | |
57 | ||
d2e6a577 | 58 | void usage() |
7c673cae FG |
59 | { |
60 | cout << "usage: radosgw-admin <cmd> [options...]" << std::endl; | |
61 | cout << "commands:\n"; | |
62 | cout << " user create create a new user\n" ; | |
63 | cout << " user modify modify user\n"; | |
64 | cout << " user info get user info\n"; | |
65 | cout << " user rm remove user\n"; | |
66 | cout << " user suspend suspend a user\n"; | |
67 | cout << " user enable re-enable user after suspension\n"; | |
68 | cout << " user check check user info\n"; | |
69 | cout << " user stats show user stats as accounted by quota subsystem\n"; | |
70 | cout << " user list list users\n"; | |
71 | cout << " caps add add user capabilities\n"; | |
72 | cout << " caps rm remove user capabilities\n"; | |
73 | cout << " subuser create create a new subuser\n" ; | |
74 | cout << " subuser modify modify subuser\n"; | |
75 | cout << " subuser rm remove subuser\n"; | |
76 | cout << " key create create access key\n"; | |
77 | cout << " key rm remove access key\n"; | |
78 | cout << " bucket list list buckets\n"; | |
79 | cout << " bucket limit check show bucket sharding stats\n"; | |
80 | cout << " bucket link link bucket to specified user\n"; | |
81 | cout << " bucket unlink unlink bucket from specified user\n"; | |
82 | cout << " bucket stats returns bucket statistics\n"; | |
83 | cout << " bucket rm remove bucket\n"; | |
84 | cout << " bucket check check bucket index\n"; | |
85 | cout << " bucket reshard reshard bucket\n"; | |
c07f9fc5 FG |
86 | cout << " bucket sync disable disable bucket sync\n"; |
87 | cout << " bucket sync enable enable bucket sync\n"; | |
7c673cae FG |
88 | cout << " bi get retrieve bucket index object entries\n"; |
89 | cout << " bi put store bucket index object entries\n"; | |
90 | cout << " bi list list raw bucket index entries\n"; | |
91 | cout << " object rm remove object\n"; | |
92 | cout << " object stat stat an object for its metadata\n"; | |
93 | cout << " object unlink unlink object from bucket index\n"; | |
94 | cout << " objects expire run expired objects cleanup\n"; | |
95 | cout << " period delete delete a period\n"; | |
96 | cout << " period get get period info\n"; | |
97 | cout << " period get-current get current period info\n"; | |
98 | cout << " period pull pull a period\n"; | |
99 | cout << " period push push a period\n"; | |
100 | cout << " period list list all periods\n"; | |
101 | cout << " period update update the staging period\n"; | |
102 | cout << " period commit commit the staging period\n"; | |
103 | cout << " quota set set quota params\n"; | |
104 | cout << " quota enable enable quota\n"; | |
105 | cout << " quota disable disable quota\n"; | |
106 | cout << " global quota get view global quota params\n"; | |
107 | cout << " global quota set set global quota params\n"; | |
108 | cout << " global quota enable enable a global quota\n"; | |
109 | cout << " global quota disable disable a global quota\n"; | |
110 | cout << " realm create create a new realm\n"; | |
111 | cout << " realm delete delete a realm\n"; | |
112 | cout << " realm get show realm info\n"; | |
113 | cout << " realm get-default get default realm name\n"; | |
114 | cout << " realm list list realms\n"; | |
115 | cout << " realm list-periods list all realm periods\n"; | |
116 | cout << " realm remove remove a zonegroup from the realm\n"; | |
117 | cout << " realm rename rename a realm\n"; | |
118 | cout << " realm set set realm info (requires infile)\n"; | |
119 | cout << " realm default set realm as default\n"; | |
120 | cout << " realm pull pull a realm and its current period\n"; | |
121 | cout << " zonegroup add add a zone to a zonegroup\n"; | |
122 | cout << " zonegroup create create a new zone group info\n"; | |
123 | cout << " zonegroup default set default zone group\n"; | |
124 | cout << " zonegroup delete delete a zone group info\n"; | |
125 | cout << " zonegroup get show zone group info\n"; | |
126 | cout << " zonegroup modify modify an existing zonegroup\n"; | |
127 | cout << " zonegroup set set zone group info (requires infile)\n"; | |
128 | cout << " zonegroup remove remove a zone from a zonegroup\n"; | |
129 | cout << " zonegroup rename rename a zone group\n"; | |
130 | cout << " zonegroup list list all zone groups set on this cluster\n"; | |
131 | cout << " zonegroup placement list list zonegroup's placement targets\n"; | |
132 | cout << " zonegroup placement add add a placement target id to a zonegroup\n"; | |
133 | cout << " zonegroup placement modify modify a placement target of a specific zonegroup\n"; | |
134 | cout << " zonegroup placement rm remove a placement target from a zonegroup\n"; | |
135 | cout << " zonegroup placement default set a zonegroup's default placement target\n"; | |
136 | cout << " zone create create a new zone\n"; | |
137 | cout << " zone delete delete a zone\n"; | |
138 | cout << " zone get show zone cluster params\n"; | |
139 | cout << " zone modify modify an existing zone\n"; | |
140 | cout << " zone set set zone cluster params (requires infile)\n"; | |
141 | cout << " zone list list all zones set on this cluster\n"; | |
142 | cout << " zone rename rename a zone\n"; | |
143 | cout << " zone placement list list zone's placement targets\n"; | |
144 | cout << " zone placement add add a zone placement target\n"; | |
145 | cout << " zone placement modify modify a zone placement target\n"; | |
146 | cout << " zone placement rm remove a zone placement target\n"; | |
147 | cout << " pool add add an existing pool for data placement\n"; | |
148 | cout << " pool rm remove an existing pool from data placement set\n"; | |
149 | cout << " pools list list placement active set\n"; | |
150 | cout << " policy read bucket/object policy\n"; | |
151 | cout << " log list list log objects\n"; | |
152 | cout << " log show dump a log from specific object or (bucket + date\n"; | |
153 | cout << " + bucket-id)\n"; | |
154 | cout << " (NOTE: required to specify formatting of date\n"; | |
155 | cout << " to \"YYYY-MM-DD-hh\")\n"; | |
156 | cout << " log rm remove log object\n"; | |
157 | cout << " usage show show usage (by user, date range)\n"; | |
158 | cout << " usage trim trim usage (by user, date range)\n"; | |
159 | cout << " gc list dump expired garbage collection objects (specify\n"; | |
160 | cout << " --include-all to list all entries, including unexpired)\n"; | |
161 | cout << " gc process manually process garbage\n"; | |
162 | cout << " lc list list all bucket lifecycle progress\n"; | |
163 | cout << " lc process manually process lifecycle\n"; | |
164 | cout << " metadata get get metadata info\n"; | |
165 | cout << " metadata put put metadata info\n"; | |
166 | cout << " metadata rm remove metadata info\n"; | |
167 | cout << " metadata list list metadata info\n"; | |
168 | cout << " mdlog list list metadata log\n"; | |
169 | cout << " mdlog trim trim metadata log (use start-date, end-date or\n"; | |
170 | cout << " start-marker, end-marker)\n"; | |
171 | cout << " mdlog status read metadata log status\n"; | |
172 | cout << " bilog list list bucket index log\n"; | |
173 | cout << " bilog trim trim bucket index log (use start-marker, end-marker)\n"; | |
174 | cout << " datalog list list data log\n"; | |
175 | cout << " datalog trim trim data log\n"; | |
176 | cout << " datalog status read data log status\n"; | |
177 | cout << " opstate list list stateful operations entries (use client_id,\n"; | |
178 | cout << " op_id, object)\n"; | |
179 | cout << " opstate set set state on an entry (use client_id, op_id, object, state)\n"; | |
180 | cout << " opstate renew renew state on an entry (use client_id, op_id, object)\n"; | |
181 | cout << " opstate rm remove entry (use client_id, op_id, object)\n"; | |
182 | cout << " replicalog get get replica metadata log entry\n"; | |
183 | cout << " replicalog update update replica metadata log entry\n"; | |
184 | cout << " replicalog delete delete replica metadata log entry\n"; | |
185 | cout << " orphans find init and run search for leaked rados objects (use job-id, pool)\n"; | |
186 | cout << " orphans finish clean up search for leaked rados objects\n"; | |
187 | cout << " orphans list-jobs list the current job-ids for orphans search\n"; | |
188 | cout << " role create create a AWS role for use with STS\n"; | |
189 | cout << " role delete delete a role\n"; | |
190 | cout << " role get get a role\n"; | |
191 | cout << " role list list roles with specified path prefix\n"; | |
192 | cout << " role modify modify the assume role policy of an existing role\n"; | |
193 | cout << " role-policy put add/update permission policy to role\n"; | |
194 | cout << " role-policy list list policies attached to a role\n"; | |
195 | cout << " role-policy get get the specified inline policy document embedded with the given role\n"; | |
196 | cout << " role-policy delete delete policy attached to a role\n"; | |
31f18b77 FG |
197 | cout << " reshard add schedule a resharding of a bucket\n"; |
198 | cout << " reshard list list all bucket resharding or scheduled to be reshared\n"; | |
199 | cout << " reshard process process of scheduled reshard jobs\n"; | |
200 | cout << " reshard cancel cancel resharding a bucket\n"; | |
7c673cae FG |
201 | cout << "options:\n"; |
202 | cout << " --tenant=<tenant> tenant name\n"; | |
203 | cout << " --uid=<id> user id\n"; | |
204 | cout << " --subuser=<name> subuser name\n"; | |
205 | cout << " --access-key=<key> S3 access key\n"; | |
206 | cout << " --email=<email>\n"; | |
207 | cout << " --secret/--secret-key=<key>\n"; | |
208 | cout << " specify secret key\n"; | |
209 | cout << " --gen-access-key generate random access key (for S3)\n"; | |
210 | cout << " --gen-secret generate random secret key\n"; | |
211 | cout << " --key-type=<type> key type, options are: swift, s3\n"; | |
212 | cout << " --temp-url-key[-2]=<key> temp url key\n"; | |
213 | cout << " --access=<access> Set access permissions for sub-user, should be one\n"; | |
214 | cout << " of read, write, readwrite, full\n"; | |
215 | cout << " --display-name=<name>\n"; | |
c07f9fc5 | 216 | cout << " --max-buckets max number of buckets for a user\n"; |
7c673cae FG |
217 | cout << " --admin set the admin flag on the user\n"; |
218 | cout << " --system set the system flag on the user\n"; | |
219 | cout << " --bucket=<bucket>\n"; | |
220 | cout << " --pool=<pool>\n"; | |
221 | cout << " --object=<object>\n"; | |
222 | cout << " --date=<date>\n"; | |
223 | cout << " --start-date=<date>\n"; | |
224 | cout << " --end-date=<date>\n"; | |
225 | cout << " --bucket-id=<bucket-id>\n"; | |
226 | cout << " --shard-id=<shard-id> optional for mdlog list\n"; | |
227 | cout << " required for: \n"; | |
228 | cout << " mdlog trim\n"; | |
229 | cout << " replica mdlog get/delete\n"; | |
230 | cout << " replica datalog get/delete\n"; | |
231 | cout << " --metadata-key=<key> key to retrieve metadata from with metadata get\n"; | |
232 | cout << " --remote=<remote> zone or zonegroup id of remote gateway\n"; | |
233 | cout << " --period=<id> period id\n"; | |
234 | cout << " --epoch=<number> period epoch\n"; | |
235 | cout << " --commit commit the period during 'period update'\n"; | |
236 | cout << " --staging get staging period info\n"; | |
237 | cout << " --master set as master\n"; | |
238 | cout << " --master-url master url\n"; | |
239 | cout << " --master-zonegroup=<id> master zonegroup id\n"; | |
240 | cout << " --master-zone=<id> master zone id\n"; | |
241 | cout << " --rgw-realm=<name> realm name\n"; | |
242 | cout << " --realm-id=<id> realm id\n"; | |
243 | cout << " --realm-new-name=<name> realm new name\n"; | |
244 | cout << " --rgw-zonegroup=<name> zonegroup name\n"; | |
245 | cout << " --zonegroup-id=<id> zonegroup id\n"; | |
246 | cout << " --zonegroup-new-name=<name>\n"; | |
247 | cout << " zonegroup new name\n"; | |
248 | cout << " --rgw-zone=<name> name of zone in which radosgw is running\n"; | |
249 | cout << " --zone-id=<id> zone id\n"; | |
250 | cout << " --zone-new-name=<name> zone new name\n"; | |
251 | cout << " --source-zone specify the source zone (for data sync)\n"; | |
252 | cout << " --default set entity (realm, zonegroup, zone) as default\n"; | |
253 | cout << " --read-only set zone as read-only (when adding to zonegroup)\n"; | |
254 | cout << " --placement-id placement id for zonegroup placement commands\n"; | |
255 | cout << " --tags=<list> list of tags for zonegroup placement add and modify commands\n"; | |
256 | cout << " --tags-add=<list> list of tags to add for zonegroup placement modify command\n"; | |
257 | cout << " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n"; | |
258 | cout << " --endpoints=<list> zone endpoints\n"; | |
c07f9fc5 | 259 | cout << " --index-pool=<pool> placement target index pool\n"; |
224ce89b WB |
260 | cout << " --data-pool=<pool> placement target data pool\n"; |
261 | cout << " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n"; | |
7c673cae FG |
262 | cout << " --placement-index-type=<type>\n"; |
263 | cout << " placement target index type (normal, indexless, or #id)\n"; | |
264 | cout << " --compression=<type> placement target compression type (plugin name or empty/none)\n"; | |
265 | cout << " --tier-type=<type> zone tier type\n"; | |
266 | cout << " --tier-config=<k>=<v>[,...]\n"; | |
267 | cout << " set zone tier config keys, values\n"; | |
268 | cout << " --tier-config-rm=<k>[,...]\n"; | |
269 | cout << " unset zone tier config keys\n"; | |
270 | cout << " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n"; | |
271 | cout << " --sync-from=[zone-name][,...]\n"; | |
272 | cout << " set list of zones to sync from\n"; | |
273 | cout << " --sync-from-rm=[zone-name][,...]\n"; | |
274 | cout << " remove zones from list of zones to sync from\n"; | |
275 | cout << " --fix besides checking bucket index, will also fix it\n"; | |
276 | cout << " --check-objects bucket check: rebuilds bucket index according to\n"; | |
277 | cout << " actual objects state\n"; | |
278 | cout << " --format=<format> specify output format for certain operations: xml,\n"; | |
279 | cout << " json\n"; | |
280 | cout << " --purge-data when specified, user removal will also purge all the\n"; | |
281 | cout << " user data\n"; | |
282 | cout << " --purge-keys when specified, subuser removal will also purge all the\n"; | |
283 | cout << " subuser keys\n"; | |
284 | cout << " --purge-objects remove a bucket's objects before deleting it\n"; | |
285 | cout << " (NOTE: required to delete a non-empty bucket)\n"; | |
286 | cout << " --sync-stats option to 'user stats', update user stats with current\n"; | |
287 | cout << " stats reported by user's buckets indexes\n"; | |
288 | cout << " --show-log-entries=<flag> enable/disable dump of log entries on log show\n"; | |
289 | cout << " --show-log-sum=<flag> enable/disable dump of log summation on log show\n"; | |
290 | cout << " --skip-zero-entries log show only dumps entries that don't have zero value\n"; | |
291 | cout << " in one of the numeric field\n"; | |
292 | cout << " --infile=<file> specify a file to read in when setting data\n"; | |
293 | cout << " --state=<state string> specify a state for the opstate set command\n"; | |
294 | cout << " --replica-log-type replica log type (metadata, data, bucket), required for\n"; | |
295 | cout << " replica log operations\n"; | |
296 | cout << " --categories=<list> comma separated list of categories, used in usage show\n"; | |
297 | cout << " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n"; | |
298 | cout << " --yes-i-really-mean-it required for certain operations\n"; | |
299 | cout << " --warnings-only when specified with bucket limit check, list\n"; | |
300 | cout << " only buckets nearing or over the current max\n"; | |
301 | cout << " objects per shard value\n"; | |
302 | cout << " --bypass-gc when specified with bucket deletion, triggers\n"; | |
303 | cout << " object deletions by not involving GC\n"; | |
304 | cout << " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n"; | |
305 | cout << " ignores bucket index consistency\n"; | |
306 | cout << "\n"; | |
307 | cout << "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n"; | |
308 | cout << "\nQuota options:\n"; | |
309 | cout << " --bucket specified bucket for quota command\n"; | |
310 | cout << " --max-objects specify max objects (negative value to disable)\n"; | |
311 | cout << " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n"; | |
312 | cout << " --quota-scope scope of quota (bucket, user)\n"; | |
313 | cout << "\nOrphans search options:\n"; | |
314 | cout << " --pool data pool to scan for leaked rados objects in\n"; | |
315 | cout << " --num-shards num of shards to use for keeping the temporary scan info\n"; | |
316 | cout << " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n"; | |
317 | cout << " --job-id set the job id (for orphans find)\n"; | |
318 | cout << " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n"; | |
319 | cout << "\nOrphans list-jobs options:\n"; | |
320 | cout << " --extra-info provide extra info in job list\n"; | |
321 | cout << "\nRole options:\n"; | |
322 | cout << " --role-name name of the role to create\n"; | |
323 | cout << " --path path to the role\n"; | |
324 | cout << " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n"; | |
325 | cout << " --policy-name name of the policy document\n"; | |
326 | cout << " --policy-doc permission policy document\n"; | |
327 | cout << " --path-prefix path prefix for filtering roles\n"; | |
328 | cout << "\n"; | |
329 | generic_client_usage(); | |
330 | } | |
331 | ||
7c673cae FG |
332 | enum { |
333 | OPT_NO_CMD = 0, | |
334 | OPT_USER_CREATE, | |
335 | OPT_USER_INFO, | |
336 | OPT_USER_MODIFY, | |
337 | OPT_USER_RM, | |
338 | OPT_USER_SUSPEND, | |
339 | OPT_USER_ENABLE, | |
340 | OPT_USER_CHECK, | |
341 | OPT_USER_STATS, | |
342 | OPT_USER_LIST, | |
343 | OPT_SUBUSER_CREATE, | |
344 | OPT_SUBUSER_MODIFY, | |
345 | OPT_SUBUSER_RM, | |
346 | OPT_KEY_CREATE, | |
347 | OPT_KEY_RM, | |
348 | OPT_BUCKETS_LIST, | |
31f18b77 | 349 | OPT_BUCKET_LIMIT_CHECK, |
7c673cae FG |
350 | OPT_BUCKET_LINK, |
351 | OPT_BUCKET_UNLINK, | |
352 | OPT_BUCKET_STATS, | |
353 | OPT_BUCKET_CHECK, | |
354 | OPT_BUCKET_SYNC_STATUS, | |
355 | OPT_BUCKET_SYNC_INIT, | |
356 | OPT_BUCKET_SYNC_RUN, | |
c07f9fc5 FG |
357 | OPT_BUCKET_SYNC_DISABLE, |
358 | OPT_BUCKET_SYNC_ENABLE, | |
7c673cae FG |
359 | OPT_BUCKET_RM, |
360 | OPT_BUCKET_REWRITE, | |
361 | OPT_BUCKET_RESHARD, | |
362 | OPT_POLICY, | |
363 | OPT_POOL_ADD, | |
364 | OPT_POOL_RM, | |
365 | OPT_POOLS_LIST, | |
366 | OPT_LOG_LIST, | |
367 | OPT_LOG_SHOW, | |
368 | OPT_LOG_RM, | |
369 | OPT_USAGE_SHOW, | |
370 | OPT_USAGE_TRIM, | |
371 | OPT_OBJECT_RM, | |
372 | OPT_OBJECT_UNLINK, | |
373 | OPT_OBJECT_STAT, | |
374 | OPT_OBJECT_REWRITE, | |
375 | OPT_OBJECTS_EXPIRE, | |
376 | OPT_BI_GET, | |
377 | OPT_BI_PUT, | |
378 | OPT_BI_LIST, | |
379 | OPT_BI_PURGE, | |
380 | OPT_OLH_GET, | |
381 | OPT_OLH_READLOG, | |
382 | OPT_QUOTA_SET, | |
383 | OPT_QUOTA_ENABLE, | |
384 | OPT_QUOTA_DISABLE, | |
385 | OPT_GC_LIST, | |
386 | OPT_GC_PROCESS, | |
387 | OPT_LC_LIST, | |
388 | OPT_LC_PROCESS, | |
389 | OPT_ORPHANS_FIND, | |
390 | OPT_ORPHANS_FINISH, | |
391 | OPT_ORPHANS_LIST_JOBS, | |
392 | OPT_ZONEGROUP_ADD, | |
393 | OPT_ZONEGROUP_CREATE, | |
394 | OPT_ZONEGROUP_DEFAULT, | |
395 | OPT_ZONEGROUP_DELETE, | |
396 | OPT_ZONEGROUP_GET, | |
397 | OPT_ZONEGROUP_MODIFY, | |
398 | OPT_ZONEGROUP_SET, | |
399 | OPT_ZONEGROUP_LIST, | |
400 | OPT_ZONEGROUP_REMOVE, | |
401 | OPT_ZONEGROUP_RENAME, | |
402 | OPT_ZONEGROUP_PLACEMENT_ADD, | |
403 | OPT_ZONEGROUP_PLACEMENT_MODIFY, | |
404 | OPT_ZONEGROUP_PLACEMENT_RM, | |
405 | OPT_ZONEGROUP_PLACEMENT_LIST, | |
406 | OPT_ZONEGROUP_PLACEMENT_DEFAULT, | |
407 | OPT_ZONE_CREATE, | |
408 | OPT_ZONE_DELETE, | |
409 | OPT_ZONE_GET, | |
410 | OPT_ZONE_MODIFY, | |
411 | OPT_ZONE_SET, | |
412 | OPT_ZONE_LIST, | |
413 | OPT_ZONE_RENAME, | |
414 | OPT_ZONE_DEFAULT, | |
415 | OPT_ZONE_PLACEMENT_ADD, | |
416 | OPT_ZONE_PLACEMENT_MODIFY, | |
417 | OPT_ZONE_PLACEMENT_RM, | |
418 | OPT_ZONE_PLACEMENT_LIST, | |
419 | OPT_CAPS_ADD, | |
420 | OPT_CAPS_RM, | |
421 | OPT_METADATA_GET, | |
422 | OPT_METADATA_PUT, | |
423 | OPT_METADATA_RM, | |
424 | OPT_METADATA_LIST, | |
425 | OPT_METADATA_SYNC_STATUS, | |
426 | OPT_METADATA_SYNC_INIT, | |
427 | OPT_METADATA_SYNC_RUN, | |
428 | OPT_MDLOG_LIST, | |
429 | OPT_MDLOG_AUTOTRIM, | |
430 | OPT_MDLOG_TRIM, | |
431 | OPT_MDLOG_FETCH, | |
432 | OPT_MDLOG_STATUS, | |
433 | OPT_SYNC_ERROR_LIST, | |
434 | OPT_BILOG_LIST, | |
435 | OPT_BILOG_TRIM, | |
436 | OPT_BILOG_STATUS, | |
b32b8144 | 437 | OPT_BILOG_AUTOTRIM, |
7c673cae FG |
438 | OPT_DATA_SYNC_STATUS, |
439 | OPT_DATA_SYNC_INIT, | |
440 | OPT_DATA_SYNC_RUN, | |
441 | OPT_DATALOG_LIST, | |
442 | OPT_DATALOG_STATUS, | |
443 | OPT_DATALOG_TRIM, | |
444 | OPT_OPSTATE_LIST, | |
445 | OPT_OPSTATE_SET, | |
446 | OPT_OPSTATE_RENEW, | |
447 | OPT_OPSTATE_RM, | |
448 | OPT_REPLICALOG_GET, | |
449 | OPT_REPLICALOG_UPDATE, | |
450 | OPT_REPLICALOG_DELETE, | |
451 | OPT_REALM_CREATE, | |
452 | OPT_REALM_DELETE, | |
453 | OPT_REALM_GET, | |
454 | OPT_REALM_GET_DEFAULT, | |
455 | OPT_REALM_LIST, | |
456 | OPT_REALM_LIST_PERIODS, | |
457 | OPT_REALM_REMOVE, | |
458 | OPT_REALM_RENAME, | |
459 | OPT_REALM_SET, | |
460 | OPT_REALM_DEFAULT, | |
461 | OPT_REALM_PULL, | |
462 | OPT_PERIOD_DELETE, | |
463 | OPT_PERIOD_GET, | |
464 | OPT_PERIOD_GET_CURRENT, | |
465 | OPT_PERIOD_PULL, | |
466 | OPT_PERIOD_PUSH, | |
467 | OPT_PERIOD_LIST, | |
468 | OPT_PERIOD_UPDATE, | |
469 | OPT_PERIOD_COMMIT, | |
470 | OPT_GLOBAL_QUOTA_GET, | |
471 | OPT_GLOBAL_QUOTA_SET, | |
472 | OPT_GLOBAL_QUOTA_ENABLE, | |
473 | OPT_GLOBAL_QUOTA_DISABLE, | |
474 | OPT_SYNC_STATUS, | |
475 | OPT_ROLE_CREATE, | |
476 | OPT_ROLE_DELETE, | |
477 | OPT_ROLE_GET, | |
478 | OPT_ROLE_MODIFY, | |
479 | OPT_ROLE_LIST, | |
480 | OPT_ROLE_POLICY_PUT, | |
481 | OPT_ROLE_POLICY_LIST, | |
482 | OPT_ROLE_POLICY_GET, | |
483 | OPT_ROLE_POLICY_DELETE, | |
31f18b77 FG |
484 | OPT_RESHARD_ADD, |
485 | OPT_RESHARD_LIST, | |
486 | OPT_RESHARD_STATUS, | |
487 | OPT_RESHARD_PROCESS, | |
488 | OPT_RESHARD_CANCEL, | |
7c673cae FG |
489 | }; |
490 | ||
491 | static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_cmd, bool *need_more) | |
492 | { | |
493 | *need_more = false; | |
494 | // NOTE: please keep the checks in alphabetical order !!! | |
495 | if (strcmp(cmd, "bi") == 0 || | |
496 | strcmp(cmd, "bilog") == 0 || | |
7c673cae FG |
497 | strcmp(cmd, "buckets") == 0 || |
498 | strcmp(cmd, "caps") == 0 || | |
499 | strcmp(cmd, "data") == 0 || | |
500 | strcmp(cmd, "datalog") == 0 || | |
501 | strcmp(cmd, "error") == 0 || | |
502 | strcmp(cmd, "gc") == 0 || | |
503 | strcmp(cmd, "global") == 0 || | |
504 | strcmp(cmd, "key") == 0 || | |
505 | strcmp(cmd, "log") == 0 || | |
506 | strcmp(cmd, "lc") == 0 || | |
507 | strcmp(cmd, "mdlog") == 0 || | |
508 | strcmp(cmd, "metadata") == 0 || | |
509 | strcmp(cmd, "object") == 0 || | |
510 | strcmp(cmd, "objects") == 0 || | |
511 | strcmp(cmd, "olh") == 0 || | |
512 | strcmp(cmd, "opstate") == 0 || | |
513 | strcmp(cmd, "orphans") == 0 || | |
514 | strcmp(cmd, "period") == 0 || | |
515 | strcmp(cmd, "placement") == 0 || | |
516 | strcmp(cmd, "pool") == 0 || | |
517 | strcmp(cmd, "pools") == 0 || | |
518 | strcmp(cmd, "quota") == 0 || | |
519 | strcmp(cmd, "realm") == 0 || | |
520 | strcmp(cmd, "replicalog") == 0 || | |
521 | strcmp(cmd, "role") == 0 || | |
522 | strcmp(cmd, "role-policy") == 0 || | |
523 | strcmp(cmd, "subuser") == 0 || | |
524 | strcmp(cmd, "sync") == 0 || | |
525 | strcmp(cmd, "usage") == 0 || | |
526 | strcmp(cmd, "user") == 0 || | |
527 | strcmp(cmd, "zone") == 0 || | |
528 | strcmp(cmd, "zonegroup") == 0 || | |
31f18b77 FG |
529 | strcmp(cmd, "zonegroups") == 0) { |
530 | *need_more = true; | |
531 | return 0; | |
532 | } | |
533 | ||
534 | /* | |
535 | * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket | |
536 | */ | |
537 | if (strcmp(cmd, "reshard") == 0 && | |
538 | !(prev_cmd && strcmp(prev_cmd, "bucket") == 0)) { | |
539 | *need_more = true; | |
540 | return 0; | |
541 | } | |
542 | if (strcmp(cmd, "bucket") == 0 && | |
543 | !(prev_cmd && strcmp(prev_cmd, "reshard") == 0)) { | |
7c673cae FG |
544 | *need_more = true; |
545 | return 0; | |
546 | } | |
547 | ||
548 | if (strcmp(cmd, "policy") == 0) | |
549 | return OPT_POLICY; | |
550 | ||
551 | if (!prev_cmd) | |
552 | return -EINVAL; | |
553 | ||
554 | if (strcmp(prev_cmd, "user") == 0) { | |
555 | if (strcmp(cmd, "create") == 0) | |
556 | return OPT_USER_CREATE; | |
557 | if (strcmp(cmd, "info") == 0) | |
558 | return OPT_USER_INFO; | |
559 | if (strcmp(cmd, "modify") == 0) | |
560 | return OPT_USER_MODIFY; | |
561 | if (strcmp(cmd, "rm") == 0) | |
562 | return OPT_USER_RM; | |
563 | if (strcmp(cmd, "suspend") == 0) | |
564 | return OPT_USER_SUSPEND; | |
565 | if (strcmp(cmd, "enable") == 0) | |
566 | return OPT_USER_ENABLE; | |
567 | if (strcmp(cmd, "check") == 0) | |
568 | return OPT_USER_CHECK; | |
569 | if (strcmp(cmd, "stats") == 0) | |
570 | return OPT_USER_STATS; | |
571 | if (strcmp(cmd, "list") == 0) | |
572 | return OPT_USER_LIST; | |
573 | } else if (strcmp(prev_cmd, "subuser") == 0) { | |
574 | if (strcmp(cmd, "create") == 0) | |
575 | return OPT_SUBUSER_CREATE; | |
576 | if (strcmp(cmd, "modify") == 0) | |
577 | return OPT_SUBUSER_MODIFY; | |
578 | if (strcmp(cmd, "rm") == 0) | |
579 | return OPT_SUBUSER_RM; | |
580 | } else if (strcmp(prev_cmd, "key") == 0) { | |
581 | if (strcmp(cmd, "create") == 0) | |
582 | return OPT_KEY_CREATE; | |
583 | if (strcmp(cmd, "rm") == 0) | |
584 | return OPT_KEY_RM; | |
585 | } else if (strcmp(prev_cmd, "buckets") == 0) { | |
586 | if (strcmp(cmd, "list") == 0) | |
587 | return OPT_BUCKETS_LIST; | |
7c673cae FG |
588 | } else if (strcmp(prev_cmd, "bucket") == 0) { |
589 | if (strcmp(cmd, "list") == 0) | |
590 | return OPT_BUCKETS_LIST; | |
591 | if (strcmp(cmd, "link") == 0) | |
592 | return OPT_BUCKET_LINK; | |
593 | if (strcmp(cmd, "unlink") == 0) | |
594 | return OPT_BUCKET_UNLINK; | |
595 | if (strcmp(cmd, "stats") == 0) | |
596 | return OPT_BUCKET_STATS; | |
597 | if (strcmp(cmd, "rm") == 0) | |
598 | return OPT_BUCKET_RM; | |
599 | if (strcmp(cmd, "rewrite") == 0) | |
600 | return OPT_BUCKET_REWRITE; | |
601 | if (strcmp(cmd, "reshard") == 0) | |
602 | return OPT_BUCKET_RESHARD; | |
603 | if (strcmp(cmd, "check") == 0) | |
604 | return OPT_BUCKET_CHECK; | |
605 | if (strcmp(cmd, "sync") == 0) { | |
606 | *need_more = true; | |
607 | return 0; | |
608 | } | |
31f18b77 FG |
609 | if (strcmp(cmd, "limit") == 0) { |
610 | *need_more = true; | |
611 | return 0; | |
612 | } | |
7c673cae FG |
613 | } else if (prev_prev_cmd && strcmp(prev_prev_cmd, "bucket") == 0) { |
614 | if (strcmp(prev_cmd, "sync") == 0) { | |
615 | if (strcmp(cmd, "status") == 0) | |
c07f9fc5 | 616 | return OPT_BUCKET_SYNC_STATUS; |
7c673cae | 617 | if (strcmp(cmd, "init") == 0) |
c07f9fc5 | 618 | return OPT_BUCKET_SYNC_INIT; |
7c673cae | 619 | if (strcmp(cmd, "run") == 0) |
c07f9fc5 FG |
620 | return OPT_BUCKET_SYNC_RUN; |
621 | if (strcmp(cmd, "disable") == 0) | |
622 | return OPT_BUCKET_SYNC_DISABLE; | |
623 | if (strcmp(cmd, "enable") == 0) | |
624 | return OPT_BUCKET_SYNC_ENABLE; | |
7c673cae FG |
625 | } else if ((strcmp(prev_cmd, "limit") == 0) && |
626 | (strcmp(cmd, "check") == 0)) { | |
31f18b77 | 627 | return OPT_BUCKET_LIMIT_CHECK; |
7c673cae FG |
628 | } |
629 | } else if (strcmp(prev_cmd, "log") == 0) { | |
630 | if (strcmp(cmd, "list") == 0) | |
631 | return OPT_LOG_LIST; | |
632 | if (strcmp(cmd, "show") == 0) | |
633 | return OPT_LOG_SHOW; | |
634 | if (strcmp(cmd, "rm") == 0) | |
635 | return OPT_LOG_RM; | |
636 | } else if (strcmp(prev_cmd, "usage") == 0) { | |
637 | if (strcmp(cmd, "show") == 0) | |
638 | return OPT_USAGE_SHOW; | |
639 | if (strcmp(cmd, "trim") == 0) | |
640 | return OPT_USAGE_TRIM; | |
641 | } else if (strcmp(prev_cmd, "caps") == 0) { | |
642 | if (strcmp(cmd, "add") == 0) | |
643 | return OPT_CAPS_ADD; | |
644 | if (strcmp(cmd, "rm") == 0) | |
645 | return OPT_CAPS_RM; | |
646 | } else if (strcmp(prev_cmd, "pool") == 0) { | |
647 | if (strcmp(cmd, "add") == 0) | |
648 | return OPT_POOL_ADD; | |
649 | if (strcmp(cmd, "rm") == 0) | |
650 | return OPT_POOL_RM; | |
651 | if (strcmp(cmd, "list") == 0) | |
652 | return OPT_POOLS_LIST; | |
653 | } else if (strcmp(prev_cmd, "pools") == 0) { | |
654 | if (strcmp(cmd, "list") == 0) | |
655 | return OPT_POOLS_LIST; | |
656 | } else if (strcmp(prev_cmd, "object") == 0) { | |
657 | if (strcmp(cmd, "rm") == 0) | |
658 | return OPT_OBJECT_RM; | |
659 | if (strcmp(cmd, "unlink") == 0) | |
660 | return OPT_OBJECT_UNLINK; | |
661 | if (strcmp(cmd, "stat") == 0) | |
662 | return OPT_OBJECT_STAT; | |
663 | if (strcmp(cmd, "rewrite") == 0) | |
664 | return OPT_OBJECT_REWRITE; | |
665 | } else if (strcmp(prev_cmd, "objects") == 0) { | |
666 | if (strcmp(cmd, "expire") == 0) | |
667 | return OPT_OBJECTS_EXPIRE; | |
668 | } else if (strcmp(prev_cmd, "olh") == 0) { | |
669 | if (strcmp(cmd, "get") == 0) | |
670 | return OPT_OLH_GET; | |
671 | if (strcmp(cmd, "readlog") == 0) | |
672 | return OPT_OLH_READLOG; | |
673 | } else if (strcmp(prev_cmd, "bi") == 0) { | |
674 | if (strcmp(cmd, "get") == 0) | |
675 | return OPT_BI_GET; | |
676 | if (strcmp(cmd, "put") == 0) | |
677 | return OPT_BI_PUT; | |
678 | if (strcmp(cmd, "list") == 0) | |
679 | return OPT_BI_LIST; | |
680 | if (strcmp(cmd, "purge") == 0) | |
681 | return OPT_BI_PURGE; | |
682 | } else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "global") == 0) && | |
683 | (strcmp(prev_cmd, "quota") == 0)) { | |
684 | if (strcmp(cmd, "get") == 0) | |
685 | return OPT_GLOBAL_QUOTA_GET; | |
686 | if (strcmp(cmd, "set") == 0) | |
687 | return OPT_GLOBAL_QUOTA_SET; | |
688 | if (strcmp(cmd, "enable") == 0) | |
689 | return OPT_GLOBAL_QUOTA_ENABLE; | |
690 | if (strcmp(cmd, "disable") == 0) | |
691 | return OPT_GLOBAL_QUOTA_DISABLE; | |
692 | } else if (strcmp(prev_cmd, "period") == 0) { | |
693 | if (strcmp(cmd, "delete") == 0) | |
694 | return OPT_PERIOD_DELETE; | |
695 | if (strcmp(cmd, "get") == 0) | |
696 | return OPT_PERIOD_GET; | |
697 | if (strcmp(cmd, "get-current") == 0) | |
698 | return OPT_PERIOD_GET_CURRENT; | |
699 | if (strcmp(cmd, "pull") == 0) | |
700 | return OPT_PERIOD_PULL; | |
701 | if (strcmp(cmd, "push") == 0) | |
702 | return OPT_PERIOD_PUSH; | |
703 | if (strcmp(cmd, "list") == 0) | |
704 | return OPT_PERIOD_LIST; | |
705 | if (strcmp(cmd, "update") == 0) | |
706 | return OPT_PERIOD_UPDATE; | |
707 | if (strcmp(cmd, "commit") == 0) | |
708 | return OPT_PERIOD_COMMIT; | |
709 | } else if (strcmp(prev_cmd, "realm") == 0) { | |
710 | if (strcmp(cmd, "create") == 0) | |
711 | return OPT_REALM_CREATE; | |
712 | if (strcmp(cmd, "delete") == 0) | |
713 | return OPT_REALM_DELETE; | |
714 | if (strcmp(cmd, "get") == 0) | |
715 | return OPT_REALM_GET; | |
716 | if (strcmp(cmd, "get-default") == 0) | |
717 | return OPT_REALM_GET_DEFAULT; | |
718 | if (strcmp(cmd, "list") == 0) | |
719 | return OPT_REALM_LIST; | |
720 | if (strcmp(cmd, "list-periods") == 0) | |
721 | return OPT_REALM_LIST_PERIODS; | |
722 | if (strcmp(cmd, "remove") == 0) | |
723 | return OPT_REALM_REMOVE; | |
724 | if (strcmp(cmd, "rename") == 0) | |
725 | return OPT_REALM_RENAME; | |
726 | if (strcmp(cmd, "set") == 0) | |
727 | return OPT_REALM_SET; | |
728 | if (strcmp(cmd, "default") == 0) | |
729 | return OPT_REALM_DEFAULT; | |
730 | if (strcmp(cmd, "pull") == 0) | |
731 | return OPT_REALM_PULL; | |
732 | } else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "zonegroup") == 0) && | |
733 | (strcmp(prev_cmd, "placement") == 0)) { | |
734 | if (strcmp(cmd, "add") == 0) | |
735 | return OPT_ZONEGROUP_PLACEMENT_ADD; | |
736 | if (strcmp(cmd, "modify") == 0) | |
737 | return OPT_ZONEGROUP_PLACEMENT_MODIFY; | |
738 | if (strcmp(cmd, "rm") == 0) | |
739 | return OPT_ZONEGROUP_PLACEMENT_RM; | |
740 | if (strcmp(cmd, "list") == 0) | |
741 | return OPT_ZONEGROUP_PLACEMENT_LIST; | |
742 | if (strcmp(cmd, "default") == 0) | |
743 | return OPT_ZONEGROUP_PLACEMENT_DEFAULT; | |
744 | } else if (strcmp(prev_cmd, "zonegroup") == 0) { | |
745 | if (strcmp(cmd, "add") == 0) | |
746 | return OPT_ZONEGROUP_ADD; | |
747 | if (strcmp(cmd, "create")== 0) | |
748 | return OPT_ZONEGROUP_CREATE; | |
749 | if (strcmp(cmd, "default") == 0) | |
750 | return OPT_ZONEGROUP_DEFAULT; | |
751 | if (strcmp(cmd, "delete") == 0) | |
752 | return OPT_ZONEGROUP_DELETE; | |
753 | if (strcmp(cmd, "get") == 0) | |
754 | return OPT_ZONEGROUP_GET; | |
755 | if (strcmp(cmd, "modify") == 0) | |
756 | return OPT_ZONEGROUP_MODIFY; | |
757 | if (strcmp(cmd, "list") == 0) | |
758 | return OPT_ZONEGROUP_LIST; | |
759 | if (strcmp(cmd, "set") == 0) | |
760 | return OPT_ZONEGROUP_SET; | |
761 | if (strcmp(cmd, "remove") == 0) | |
762 | return OPT_ZONEGROUP_REMOVE; | |
763 | if (strcmp(cmd, "rename") == 0) | |
764 | return OPT_ZONEGROUP_RENAME; | |
765 | } else if (strcmp(prev_cmd, "quota") == 0) { | |
766 | if (strcmp(cmd, "set") == 0) | |
767 | return OPT_QUOTA_SET; | |
768 | if (strcmp(cmd, "enable") == 0) | |
769 | return OPT_QUOTA_ENABLE; | |
770 | if (strcmp(cmd, "disable") == 0) | |
771 | return OPT_QUOTA_DISABLE; | |
772 | } else if (strcmp(prev_cmd, "zonegroups") == 0) { | |
773 | if (strcmp(cmd, "list") == 0) | |
774 | return OPT_ZONEGROUP_LIST; | |
775 | } else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "zone") == 0) && | |
776 | (strcmp(prev_cmd, "placement") == 0)) { | |
777 | if (strcmp(cmd, "add") == 0) | |
778 | return OPT_ZONE_PLACEMENT_ADD; | |
779 | if (strcmp(cmd, "modify") == 0) | |
780 | return OPT_ZONE_PLACEMENT_MODIFY; | |
781 | if (strcmp(cmd, "rm") == 0) | |
782 | return OPT_ZONE_PLACEMENT_RM; | |
783 | if (strcmp(cmd, "list") == 0) | |
784 | return OPT_ZONE_PLACEMENT_LIST; | |
785 | } else if (strcmp(prev_cmd, "zone") == 0) { | |
786 | if (strcmp(cmd, "delete") == 0) | |
787 | return OPT_ZONE_DELETE; | |
788 | if (strcmp(cmd, "create") == 0) | |
789 | return OPT_ZONE_CREATE; | |
790 | if (strcmp(cmd, "get") == 0) | |
791 | return OPT_ZONE_GET; | |
792 | if (strcmp(cmd, "set") == 0) | |
793 | return OPT_ZONE_SET; | |
794 | if (strcmp(cmd, "list") == 0) | |
795 | return OPT_ZONE_LIST; | |
796 | if (strcmp(cmd, "modify") == 0) | |
797 | return OPT_ZONE_MODIFY; | |
798 | if (strcmp(cmd, "rename") == 0) | |
799 | return OPT_ZONE_RENAME; | |
800 | if (strcmp(cmd, "default") == 0) | |
801 | return OPT_ZONE_DEFAULT; | |
802 | } else if (strcmp(prev_cmd, "zones") == 0) { | |
803 | if (strcmp(cmd, "list") == 0) | |
804 | return OPT_ZONE_LIST; | |
805 | } else if (strcmp(prev_cmd, "gc") == 0) { | |
806 | if (strcmp(cmd, "list") == 0) | |
807 | return OPT_GC_LIST; | |
808 | if (strcmp(cmd, "process") == 0) | |
809 | return OPT_GC_PROCESS; | |
810 | } else if (strcmp(prev_cmd, "lc") == 0) { | |
811 | if (strcmp(cmd, "list") == 0) | |
812 | return OPT_LC_LIST; | |
813 | if (strcmp(cmd, "process") == 0) | |
814 | return OPT_LC_PROCESS; | |
815 | } else if (strcmp(prev_cmd, "orphans") == 0) { | |
816 | if (strcmp(cmd, "find") == 0) | |
817 | return OPT_ORPHANS_FIND; | |
818 | if (strcmp(cmd, "finish") == 0) | |
819 | return OPT_ORPHANS_FINISH; | |
820 | if (strcmp(cmd, "list-jobs") == 0) | |
821 | return OPT_ORPHANS_LIST_JOBS; | |
822 | } else if (strcmp(prev_cmd, "metadata") == 0) { | |
823 | if (strcmp(cmd, "get") == 0) | |
824 | return OPT_METADATA_GET; | |
825 | if (strcmp(cmd, "put") == 0) | |
826 | return OPT_METADATA_PUT; | |
827 | if (strcmp(cmd, "rm") == 0) | |
828 | return OPT_METADATA_RM; | |
829 | if (strcmp(cmd, "list") == 0) | |
830 | return OPT_METADATA_LIST; | |
831 | if (strcmp(cmd, "sync") == 0) { | |
832 | *need_more = true; | |
833 | return 0; | |
834 | } | |
835 | } else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "metadata") == 0) && | |
836 | (strcmp(prev_cmd, "sync") == 0)) { | |
837 | if (strcmp(cmd, "status") == 0) | |
838 | return OPT_METADATA_SYNC_STATUS; | |
839 | if (strcmp(cmd, "init") == 0) | |
840 | return OPT_METADATA_SYNC_INIT; | |
841 | if (strcmp(cmd, "run") == 0) | |
842 | return OPT_METADATA_SYNC_RUN; | |
843 | } else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "sync") == 0) && | |
844 | (strcmp(prev_cmd, "error") == 0)) { | |
845 | if (strcmp(cmd, "list") == 0) | |
846 | return OPT_SYNC_ERROR_LIST; | |
847 | } else if (strcmp(prev_cmd, "mdlog") == 0) { | |
848 | if (strcmp(cmd, "list") == 0) | |
849 | return OPT_MDLOG_LIST; | |
850 | if (strcmp(cmd, "autotrim") == 0) | |
851 | return OPT_MDLOG_AUTOTRIM; | |
852 | if (strcmp(cmd, "trim") == 0) | |
853 | return OPT_MDLOG_TRIM; | |
854 | if (strcmp(cmd, "fetch") == 0) | |
855 | return OPT_MDLOG_FETCH; | |
856 | if (strcmp(cmd, "status") == 0) | |
857 | return OPT_MDLOG_STATUS; | |
858 | } else if (strcmp(prev_cmd, "bilog") == 0) { | |
859 | if (strcmp(cmd, "list") == 0) | |
860 | return OPT_BILOG_LIST; | |
861 | if (strcmp(cmd, "trim") == 0) | |
862 | return OPT_BILOG_TRIM; | |
863 | if (strcmp(cmd, "status") == 0) | |
864 | return OPT_BILOG_STATUS; | |
b32b8144 FG |
865 | if (strcmp(cmd, "autotrim") == 0) |
866 | return OPT_BILOG_AUTOTRIM; | |
7c673cae FG |
867 | } else if (strcmp(prev_cmd, "data") == 0) { |
868 | if (strcmp(cmd, "sync") == 0) { | |
869 | *need_more = true; | |
870 | return 0; | |
871 | } | |
872 | } else if (strcmp(prev_cmd, "datalog") == 0) { | |
873 | if (strcmp(cmd, "list") == 0) | |
874 | return OPT_DATALOG_LIST; | |
875 | if (strcmp(cmd, "trim") == 0) | |
876 | return OPT_DATALOG_TRIM; | |
877 | if (strcmp(cmd, "status") == 0) | |
878 | return OPT_DATALOG_STATUS; | |
879 | } else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "data") == 0) && | |
880 | (strcmp(prev_cmd, "sync") == 0)) { | |
881 | if (strcmp(cmd, "status") == 0) | |
882 | return OPT_DATA_SYNC_STATUS; | |
883 | if (strcmp(cmd, "init") == 0) | |
884 | return OPT_DATA_SYNC_INIT; | |
885 | if (strcmp(cmd, "run") == 0) | |
886 | return OPT_DATA_SYNC_RUN; | |
887 | } else if (strcmp(prev_cmd, "opstate") == 0) { | |
888 | if (strcmp(cmd, "list") == 0) | |
889 | return OPT_OPSTATE_LIST; | |
890 | if (strcmp(cmd, "set") == 0) | |
891 | return OPT_OPSTATE_SET; | |
892 | if (strcmp(cmd, "renew") == 0) | |
893 | return OPT_OPSTATE_RENEW; | |
894 | if (strcmp(cmd, "rm") == 0) | |
895 | return OPT_OPSTATE_RM; | |
896 | } else if (strcmp(prev_cmd, "replicalog") == 0) { | |
897 | if (strcmp(cmd, "get") == 0) | |
898 | return OPT_REPLICALOG_GET; | |
899 | if (strcmp(cmd, "update") == 0) | |
900 | return OPT_REPLICALOG_UPDATE; | |
901 | if (strcmp(cmd, "delete") == 0) | |
902 | return OPT_REPLICALOG_DELETE; | |
903 | } else if (strcmp(prev_cmd, "sync") == 0) { | |
904 | if (strcmp(cmd, "status") == 0) | |
905 | return OPT_SYNC_STATUS; | |
906 | } else if (strcmp(prev_cmd, "role") == 0) { | |
907 | if (strcmp(cmd, "create") == 0) | |
908 | return OPT_ROLE_CREATE; | |
909 | if (strcmp(cmd, "delete") == 0) | |
910 | return OPT_ROLE_DELETE; | |
911 | if (strcmp(cmd, "get") == 0) | |
912 | return OPT_ROLE_GET; | |
913 | if (strcmp(cmd, "modify") == 0) | |
914 | return OPT_ROLE_MODIFY; | |
915 | if (strcmp(cmd, "list") == 0) | |
916 | return OPT_ROLE_LIST; | |
917 | } else if (strcmp(prev_cmd, "role-policy") == 0) { | |
918 | if (strcmp(cmd, "put") == 0) | |
919 | return OPT_ROLE_POLICY_PUT; | |
920 | if (strcmp(cmd, "list") == 0) | |
921 | return OPT_ROLE_POLICY_LIST; | |
922 | if (strcmp(cmd, "get") == 0) | |
923 | return OPT_ROLE_POLICY_GET; | |
924 | if (strcmp(cmd, "delete") == 0) | |
925 | return OPT_ROLE_POLICY_DELETE; | |
31f18b77 FG |
926 | } else if (strcmp(prev_cmd, "reshard") == 0) { |
927 | if (strcmp(cmd, "bucket") == 0) | |
928 | return OPT_BUCKET_RESHARD; | |
929 | if (strcmp(cmd, "add") == 0) | |
930 | return OPT_RESHARD_ADD; | |
931 | if (strcmp(cmd, "list") == 0) | |
932 | return OPT_RESHARD_LIST; | |
933 | if (strcmp(cmd, "status") == 0) | |
934 | return OPT_RESHARD_STATUS; | |
b32b8144 | 935 | if (strcmp(cmd, "process") == 0) |
31f18b77 FG |
936 | return OPT_RESHARD_PROCESS; |
937 | if (strcmp(cmd, "cancel") == 0) | |
938 | return OPT_RESHARD_CANCEL; | |
7c673cae FG |
939 | } |
940 | ||
941 | return -EINVAL; | |
942 | } | |
943 | ||
944 | enum ReplicaLogType { | |
945 | ReplicaLog_Invalid = 0, | |
946 | ReplicaLog_Metadata, | |
947 | ReplicaLog_Data, | |
948 | ReplicaLog_Bucket, | |
949 | }; | |
950 | ||
951 | ReplicaLogType get_replicalog_type(const string& name) { | |
952 | if (name == "md" || name == "meta" || name == "metadata") | |
953 | return ReplicaLog_Metadata; | |
954 | if (name == "data") | |
955 | return ReplicaLog_Data; | |
956 | if (name == "bucket") | |
957 | return ReplicaLog_Bucket; | |
958 | ||
959 | return ReplicaLog_Invalid; | |
960 | } | |
961 | ||
962 | BIIndexType get_bi_index_type(const string& type_str) { | |
963 | if (type_str == "plain") | |
964 | return PlainIdx; | |
965 | if (type_str == "instance") | |
966 | return InstanceIdx; | |
967 | if (type_str == "olh") | |
968 | return OLHIdx; | |
969 | ||
970 | return InvalidIdx; | |
971 | } | |
972 | ||
973 | void dump_bi_entry(bufferlist& bl, BIIndexType index_type, Formatter *formatter) | |
974 | { | |
975 | bufferlist::iterator iter = bl.begin(); | |
976 | switch (index_type) { | |
977 | case PlainIdx: | |
978 | case InstanceIdx: | |
979 | { | |
980 | rgw_bucket_dir_entry entry; | |
981 | ::decode(entry, iter); | |
982 | encode_json("entry", entry, formatter); | |
983 | } | |
984 | break; | |
985 | case OLHIdx: | |
986 | { | |
987 | rgw_bucket_olh_entry entry; | |
988 | ::decode(entry, iter); | |
989 | encode_json("entry", entry, formatter); | |
990 | } | |
991 | break; | |
992 | default: | |
993 | ceph_abort(); | |
994 | break; | |
995 | } | |
996 | } | |
997 | ||
998 | static void show_user_info(RGWUserInfo& info, Formatter *formatter) | |
999 | { | |
1000 | encode_json("user_info", info, formatter); | |
1001 | formatter->flush(cout); | |
1002 | cout << std::endl; | |
1003 | } | |
1004 | ||
1005 | static void show_perm_policy(string perm_policy, Formatter* formatter) | |
1006 | { | |
1007 | formatter->open_object_section("role"); | |
1008 | formatter->dump_string("Permission policy", perm_policy); | |
1009 | formatter->close_section(); | |
1010 | formatter->flush(cout); | |
1011 | } | |
1012 | ||
1013 | static void show_policy_names(std::vector<string> policy_names, Formatter* formatter) | |
1014 | { | |
1015 | formatter->open_array_section("PolicyNames"); | |
1016 | for (const auto& it : policy_names) { | |
1017 | formatter->dump_string("policyname", it); | |
1018 | } | |
1019 | formatter->close_section(); | |
1020 | formatter->flush(cout); | |
1021 | } | |
1022 | ||
1023 | static void show_role_info(RGWRole& role, Formatter* formatter) | |
1024 | { | |
1025 | formatter->open_object_section("role"); | |
1026 | role.dump(formatter); | |
1027 | formatter->close_section(); | |
1028 | formatter->flush(cout); | |
1029 | } | |
1030 | ||
1031 | static void show_roles_info(vector<RGWRole>& roles, Formatter* formatter) | |
1032 | { | |
1033 | formatter->open_array_section("Roles"); | |
1034 | for (const auto& it : roles) { | |
1035 | formatter->open_object_section("role"); | |
1036 | it.dump(formatter); | |
1037 | formatter->close_section(); | |
1038 | } | |
1039 | formatter->close_section(); | |
1040 | formatter->flush(cout); | |
1041 | } | |
1042 | ||
7c673cae FG |
1043 | class StoreDestructor { |
1044 | RGWRados *store; | |
1045 | public: | |
1046 | explicit StoreDestructor(RGWRados *_s) : store(_s) {} | |
1047 | ~StoreDestructor() { | |
1048 | RGWStoreManager::close_storage(store); | |
1049 | } | |
1050 | }; | |
1051 | ||
1052 | static int init_bucket(const string& tenant_name, const string& bucket_name, const string& bucket_id, | |
1053 | RGWBucketInfo& bucket_info, rgw_bucket& bucket, map<string, bufferlist> *pattrs = nullptr) | |
1054 | { | |
1055 | if (!bucket_name.empty()) { | |
1056 | RGWObjectCtx obj_ctx(store); | |
1057 | int r; | |
1058 | if (bucket_id.empty()) { | |
1059 | r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, nullptr, pattrs); | |
1060 | } else { | |
1061 | string bucket_instance_id = bucket_name + ":" + bucket_id; | |
1062 | r = store->get_bucket_instance_info(obj_ctx, bucket_instance_id, bucket_info, NULL, pattrs); | |
1063 | } | |
1064 | if (r < 0) { | |
1065 | cerr << "could not get bucket info for bucket=" << bucket_name << std::endl; | |
1066 | return r; | |
1067 | } | |
1068 | bucket = bucket_info.bucket; | |
1069 | } | |
1070 | return 0; | |
1071 | } | |
1072 | ||
1073 | static int read_input(const string& infile, bufferlist& bl) | |
1074 | { | |
1075 | int fd = 0; | |
1076 | if (infile.size()) { | |
1077 | fd = open(infile.c_str(), O_RDONLY); | |
1078 | if (fd < 0) { | |
1079 | int err = -errno; | |
1080 | cerr << "error reading input file " << infile << std::endl; | |
1081 | return err; | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | #define READ_CHUNK 8196 | |
1086 | int r; | |
1087 | int err; | |
1088 | ||
1089 | do { | |
1090 | char buf[READ_CHUNK]; | |
1091 | ||
1092 | r = safe_read(fd, buf, READ_CHUNK); | |
1093 | if (r < 0) { | |
1094 | err = -errno; | |
1095 | cerr << "error while reading input" << std::endl; | |
1096 | goto out; | |
1097 | } | |
1098 | bl.append(buf, r); | |
1099 | } while (r > 0); | |
1100 | err = 0; | |
1101 | ||
1102 | out: | |
1103 | if (infile.size()) { | |
1104 | close(fd); | |
1105 | } | |
1106 | return err; | |
1107 | } | |
1108 | ||
1109 | template <class T> | |
1110 | static int read_decode_json(const string& infile, T& t) | |
1111 | { | |
1112 | bufferlist bl; | |
1113 | int ret = read_input(infile, bl); | |
1114 | if (ret < 0) { | |
1115 | cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl; | |
1116 | return ret; | |
1117 | } | |
1118 | JSONParser p; | |
1119 | if (!p.parse(bl.c_str(), bl.length())) { | |
1120 | cout << "failed to parse JSON" << std::endl; | |
1121 | return -EINVAL; | |
1122 | } | |
1123 | ||
1124 | try { | |
1125 | decode_json_obj(t, &p); | |
1126 | } catch (JSONDecoder::err& e) { | |
1127 | cout << "failed to decode JSON input: " << e.message << std::endl; | |
1128 | return -EINVAL; | |
1129 | } | |
1130 | return 0; | |
1131 | } | |
1132 | ||
1133 | template <class T, class K> | |
1134 | static int read_decode_json(const string& infile, T& t, K *k) | |
1135 | { | |
1136 | bufferlist bl; | |
1137 | int ret = read_input(infile, bl); | |
1138 | if (ret < 0) { | |
1139 | cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl; | |
1140 | return ret; | |
1141 | } | |
1142 | JSONParser p; | |
1143 | if (!p.parse(bl.c_str(), bl.length())) { | |
1144 | cout << "failed to parse JSON" << std::endl; | |
1145 | return -EINVAL; | |
1146 | } | |
1147 | ||
1148 | try { | |
1149 | t.decode_json(&p, k); | |
1150 | } catch (JSONDecoder::err& e) { | |
1151 | cout << "failed to decode JSON input: " << e.message << std::endl; | |
1152 | return -EINVAL; | |
1153 | } | |
1154 | return 0; | |
1155 | } | |
1156 | ||
1157 | static int parse_date_str(const string& date_str, utime_t& ut) | |
1158 | { | |
1159 | uint64_t epoch = 0; | |
1160 | uint64_t nsec = 0; | |
1161 | ||
1162 | if (!date_str.empty()) { | |
1163 | int ret = utime_t::parse_date(date_str, &epoch, &nsec); | |
1164 | if (ret < 0) { | |
1165 | cerr << "ERROR: failed to parse date: " << date_str << std::endl; | |
1166 | return -EINVAL; | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | ut = utime_t(epoch, nsec); | |
1171 | ||
1172 | return 0; | |
1173 | } | |
1174 | ||
1175 | template <class T> | |
1176 | static bool decode_dump(const char *field_name, bufferlist& bl, Formatter *f) | |
1177 | { | |
1178 | T t; | |
1179 | ||
1180 | bufferlist::iterator iter = bl.begin(); | |
1181 | ||
1182 | try { | |
1183 | ::decode(t, iter); | |
1184 | } catch (buffer::error& err) { | |
1185 | return false; | |
1186 | } | |
1187 | ||
1188 | encode_json(field_name, t, f); | |
1189 | ||
1190 | return true; | |
1191 | } | |
1192 | ||
1193 | static bool dump_string(const char *field_name, bufferlist& bl, Formatter *f) | |
1194 | { | |
1195 | string val; | |
1196 | if (bl.length() > 0) { | |
31f18b77 | 1197 | val.assign(bl.c_str()); |
7c673cae FG |
1198 | } |
1199 | f->dump_string(field_name, val); | |
1200 | ||
1201 | return true; | |
1202 | } | |
1203 | ||
1204 | void set_quota_info(RGWQuotaInfo& quota, int opt_cmd, int64_t max_size, int64_t max_objects, | |
1205 | bool have_max_size, bool have_max_objects) | |
1206 | { | |
1207 | switch (opt_cmd) { | |
1208 | case OPT_QUOTA_ENABLE: | |
1209 | case OPT_GLOBAL_QUOTA_ENABLE: | |
1210 | quota.enabled = true; | |
1211 | ||
1212 | // falling through on purpose | |
1213 | ||
1214 | case OPT_QUOTA_SET: | |
1215 | case OPT_GLOBAL_QUOTA_SET: | |
1216 | if (have_max_objects) { | |
1217 | if (max_objects < 0) { | |
1218 | quota.max_objects = -1; | |
1219 | } else { | |
1220 | quota.max_objects = max_objects; | |
1221 | } | |
1222 | } | |
1223 | if (have_max_size) { | |
1224 | if (max_size < 0) { | |
1225 | quota.max_size = -1; | |
1226 | } else { | |
1227 | quota.max_size = rgw_rounded_kb(max_size) * 1024; | |
1228 | } | |
1229 | } | |
1230 | break; | |
1231 | case OPT_QUOTA_DISABLE: | |
1232 | case OPT_GLOBAL_QUOTA_DISABLE: | |
1233 | quota.enabled = false; | |
1234 | break; | |
1235 | } | |
1236 | } | |
1237 | ||
1238 | int set_bucket_quota(RGWRados *store, int opt_cmd, | |
1239 | const string& tenant_name, const string& bucket_name, | |
1240 | int64_t max_size, int64_t max_objects, | |
1241 | bool have_max_size, bool have_max_objects) | |
1242 | { | |
1243 | RGWBucketInfo bucket_info; | |
1244 | map<string, bufferlist> attrs; | |
1245 | RGWObjectCtx obj_ctx(store); | |
1246 | int r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL, &attrs); | |
1247 | if (r < 0) { | |
1248 | cerr << "could not get bucket info for bucket=" << bucket_name << ": " << cpp_strerror(-r) << std::endl; | |
1249 | return -r; | |
1250 | } | |
1251 | ||
1252 | set_quota_info(bucket_info.quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects); | |
1253 | ||
1254 | r = store->put_bucket_instance_info(bucket_info, false, real_time(), &attrs); | |
1255 | if (r < 0) { | |
1256 | cerr << "ERROR: failed writing bucket instance info: " << cpp_strerror(-r) << std::endl; | |
1257 | return -r; | |
1258 | } | |
1259 | return 0; | |
1260 | } | |
1261 | ||
1262 | int set_user_bucket_quota(int opt_cmd, RGWUser& user, RGWUserAdminOpState& op_state, int64_t max_size, int64_t max_objects, | |
1263 | bool have_max_size, bool have_max_objects) | |
1264 | { | |
1265 | RGWUserInfo& user_info = op_state.get_user_info(); | |
1266 | ||
1267 | set_quota_info(user_info.bucket_quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects); | |
1268 | ||
1269 | op_state.set_bucket_quota(user_info.bucket_quota); | |
1270 | ||
1271 | string err; | |
1272 | int r = user.modify(op_state, &err); | |
1273 | if (r < 0) { | |
1274 | cerr << "ERROR: failed updating user info: " << cpp_strerror(-r) << ": " << err << std::endl; | |
1275 | return -r; | |
1276 | } | |
1277 | return 0; | |
1278 | } | |
1279 | ||
1280 | int set_user_quota(int opt_cmd, RGWUser& user, RGWUserAdminOpState& op_state, int64_t max_size, int64_t max_objects, | |
1281 | bool have_max_size, bool have_max_objects) | |
1282 | { | |
1283 | RGWUserInfo& user_info = op_state.get_user_info(); | |
1284 | ||
1285 | set_quota_info(user_info.user_quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects); | |
1286 | ||
1287 | op_state.set_user_quota(user_info.user_quota); | |
1288 | ||
1289 | string err; | |
1290 | int r = user.modify(op_state, &err); | |
1291 | if (r < 0) { | |
1292 | cerr << "ERROR: failed updating user info: " << cpp_strerror(-r) << ": " << err << std::endl; | |
1293 | return -r; | |
1294 | } | |
1295 | return 0; | |
1296 | } | |
1297 | ||
1298 | static bool bucket_object_check_filter(const string& name) | |
1299 | { | |
1300 | rgw_obj_key k; | |
1301 | string ns; /* empty namespace */ | |
1302 | return rgw_obj_key::oid_to_key_in_ns(name, &k, ns); | |
1303 | } | |
1304 | ||
1305 | int check_min_obj_stripe_size(RGWRados *store, RGWBucketInfo& bucket_info, rgw_obj& obj, uint64_t min_stripe_size, bool *need_rewrite) | |
1306 | { | |
1307 | map<string, bufferlist> attrs; | |
1308 | uint64_t obj_size; | |
1309 | ||
1310 | RGWObjectCtx obj_ctx(store); | |
1311 | RGWRados::Object op_target(store, bucket_info, obj_ctx, obj); | |
1312 | RGWRados::Object::Read read_op(&op_target); | |
1313 | ||
1314 | read_op.params.attrs = &attrs; | |
1315 | read_op.params.obj_size = &obj_size; | |
1316 | ||
1317 | int ret = read_op.prepare(); | |
1318 | if (ret < 0) { | |
1319 | lderr(store->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret) << dendl; | |
1320 | return ret; | |
1321 | } | |
1322 | ||
1323 | map<string, bufferlist>::iterator iter; | |
1324 | iter = attrs.find(RGW_ATTR_MANIFEST); | |
1325 | if (iter == attrs.end()) { | |
1326 | *need_rewrite = (obj_size >= min_stripe_size); | |
1327 | return 0; | |
1328 | } | |
1329 | ||
1330 | RGWObjManifest manifest; | |
1331 | ||
1332 | try { | |
1333 | bufferlist& bl = iter->second; | |
1334 | bufferlist::iterator biter = bl.begin(); | |
1335 | ::decode(manifest, biter); | |
1336 | } catch (buffer::error& err) { | |
1337 | ldout(store->ctx(), 0) << "ERROR: failed to decode manifest" << dendl; | |
1338 | return -EIO; | |
1339 | } | |
1340 | ||
1341 | map<uint64_t, RGWObjManifestPart>& objs = manifest.get_explicit_objs(); | |
1342 | map<uint64_t, RGWObjManifestPart>::iterator oiter; | |
1343 | for (oiter = objs.begin(); oiter != objs.end(); ++oiter) { | |
1344 | RGWObjManifestPart& part = oiter->second; | |
1345 | ||
1346 | if (part.size >= min_stripe_size) { | |
1347 | *need_rewrite = true; | |
1348 | return 0; | |
1349 | } | |
1350 | } | |
1351 | *need_rewrite = false; | |
1352 | ||
1353 | return 0; | |
1354 | } | |
1355 | ||
1356 | ||
1357 | int check_obj_locator_underscore(RGWBucketInfo& bucket_info, rgw_obj& obj, rgw_obj_key& key, bool fix, bool remove_bad, Formatter *f) { | |
1358 | f->open_object_section("object"); | |
1359 | f->open_object_section("key"); | |
1360 | f->dump_string("type", "head"); | |
1361 | f->dump_string("name", key.name); | |
1362 | f->dump_string("instance", key.instance); | |
1363 | f->close_section(); | |
1364 | ||
1365 | string oid; | |
1366 | string locator; | |
1367 | ||
1368 | get_obj_bucket_and_oid_loc(obj, oid, locator); | |
1369 | ||
1370 | f->dump_string("oid", oid); | |
1371 | f->dump_string("locator", locator); | |
1372 | ||
1373 | ||
1374 | RGWObjectCtx obj_ctx(store); | |
1375 | ||
1376 | RGWRados::Object op_target(store, bucket_info, obj_ctx, obj); | |
1377 | RGWRados::Object::Read read_op(&op_target); | |
1378 | ||
1379 | int ret = read_op.prepare(); | |
1380 | bool needs_fixing = (ret == -ENOENT); | |
1381 | ||
1382 | f->dump_bool("needs_fixing", needs_fixing); | |
1383 | ||
1384 | string status = (needs_fixing ? "needs_fixing" : "ok"); | |
1385 | ||
1386 | if ((needs_fixing || remove_bad) && fix) { | |
1387 | ret = store->fix_head_obj_locator(bucket_info, needs_fixing, remove_bad, key); | |
1388 | if (ret < 0) { | |
1389 | cerr << "ERROR: fix_head_object_locator() returned ret=" << ret << std::endl; | |
1390 | goto done; | |
1391 | } | |
1392 | status = "fixed"; | |
1393 | } | |
1394 | ||
1395 | done: | |
1396 | f->dump_string("status", status); | |
1397 | ||
1398 | f->close_section(); | |
1399 | ||
1400 | return 0; | |
1401 | } | |
1402 | ||
1403 | int check_obj_tail_locator_underscore(RGWBucketInfo& bucket_info, rgw_obj& obj, rgw_obj_key& key, bool fix, Formatter *f) { | |
1404 | f->open_object_section("object"); | |
1405 | f->open_object_section("key"); | |
1406 | f->dump_string("type", "tail"); | |
1407 | f->dump_string("name", key.name); | |
1408 | f->dump_string("instance", key.instance); | |
1409 | f->close_section(); | |
1410 | ||
1411 | bool needs_fixing; | |
1412 | string status; | |
1413 | ||
1414 | int ret = store->fix_tail_obj_locator(bucket_info, key, fix, &needs_fixing); | |
1415 | if (ret < 0) { | |
1416 | cerr << "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret << std::endl; | |
1417 | status = "failed"; | |
1418 | } else { | |
1419 | status = (needs_fixing && !fix ? "needs_fixing" : "ok"); | |
1420 | } | |
1421 | ||
1422 | f->dump_bool("needs_fixing", needs_fixing); | |
1423 | f->dump_string("status", status); | |
1424 | ||
1425 | f->close_section(); | |
1426 | ||
1427 | return 0; | |
1428 | } | |
1429 | ||
1430 | int do_check_object_locator(const string& tenant_name, const string& bucket_name, | |
1431 | bool fix, bool remove_bad, Formatter *f) | |
1432 | { | |
1433 | if (remove_bad && !fix) { | |
1434 | cerr << "ERROR: can't have remove_bad specified without fix" << std::endl; | |
1435 | return -EINVAL; | |
1436 | } | |
1437 | ||
1438 | RGWBucketInfo bucket_info; | |
1439 | rgw_bucket bucket; | |
1440 | string bucket_id; | |
1441 | ||
1442 | f->open_object_section("bucket"); | |
1443 | f->dump_string("bucket", bucket_name); | |
1444 | int ret = init_bucket(tenant_name, bucket_name, bucket_id, bucket_info, bucket); | |
1445 | if (ret < 0) { | |
1446 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
1447 | return ret; | |
1448 | } | |
1449 | bool truncated; | |
1450 | int count = 0; | |
1451 | ||
1452 | int max_entries = 1000; | |
1453 | ||
1454 | string prefix; | |
1455 | string delim; | |
1456 | vector<rgw_bucket_dir_entry> result; | |
1457 | map<string, bool> common_prefixes; | |
1458 | string ns; | |
1459 | ||
1460 | RGWRados::Bucket target(store, bucket_info); | |
1461 | RGWRados::Bucket::List list_op(&target); | |
1462 | ||
1463 | string marker; | |
1464 | ||
1465 | list_op.params.prefix = prefix; | |
1466 | list_op.params.delim = delim; | |
1467 | list_op.params.marker = rgw_obj_key(marker); | |
1468 | list_op.params.ns = ns; | |
1469 | list_op.params.enforce_ns = true; | |
1470 | list_op.params.list_versions = true; | |
1471 | ||
1472 | f->open_array_section("check_objects"); | |
1473 | do { | |
1474 | ret = list_op.list_objects(max_entries - count, &result, &common_prefixes, &truncated); | |
1475 | if (ret < 0) { | |
1476 | cerr << "ERROR: store->list_objects(): " << cpp_strerror(-ret) << std::endl; | |
1477 | return -ret; | |
1478 | } | |
1479 | ||
1480 | count += result.size(); | |
1481 | ||
1482 | for (vector<rgw_bucket_dir_entry>::iterator iter = result.begin(); iter != result.end(); ++iter) { | |
1483 | rgw_obj_key key = iter->key; | |
1484 | rgw_obj obj(bucket, key); | |
1485 | ||
1486 | if (key.name[0] == '_') { | |
1487 | ret = check_obj_locator_underscore(bucket_info, obj, key, fix, remove_bad, f); | |
1488 | ||
1489 | if (ret >= 0) { | |
1490 | ret = check_obj_tail_locator_underscore(bucket_info, obj, key, fix, f); | |
1491 | } | |
1492 | } | |
1493 | } | |
1494 | f->flush(cout); | |
1495 | } while (truncated && count < max_entries); | |
1496 | f->close_section(); | |
1497 | f->close_section(); | |
1498 | ||
1499 | f->flush(cout); | |
1500 | ||
1501 | return 0; | |
1502 | } | |
1503 | ||
c07f9fc5 FG |
1504 | int set_bucket_sync_enabled(RGWRados *store, int opt_cmd, const string& tenant_name, const string& bucket_name) |
1505 | { | |
1506 | RGWBucketInfo bucket_info; | |
1507 | map<string, bufferlist> attrs; | |
1508 | RGWObjectCtx obj_ctx(store); | |
1509 | ||
1510 | int r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL, &attrs); | |
1511 | if (r < 0) { | |
1512 | cerr << "could not get bucket info for bucket=" << bucket_name << ": " << cpp_strerror(-r) << std::endl; | |
1513 | return -r; | |
1514 | } | |
1515 | ||
1516 | if (opt_cmd == OPT_BUCKET_SYNC_ENABLE) { | |
1517 | bucket_info.flags &= ~BUCKET_DATASYNC_DISABLED; | |
1518 | } else if (opt_cmd == OPT_BUCKET_SYNC_DISABLE) { | |
1519 | bucket_info.flags |= BUCKET_DATASYNC_DISABLED; | |
1520 | } | |
1521 | ||
1522 | r = store->put_bucket_instance_info(bucket_info, false, real_time(), &attrs); | |
1523 | if (r < 0) { | |
1524 | cerr << "ERROR: failed writing bucket instance info: " << cpp_strerror(-r) << std::endl; | |
1525 | return -r; | |
1526 | } | |
1527 | ||
1528 | int shards_num = bucket_info.num_shards? bucket_info.num_shards : 1; | |
1529 | int shard_id = bucket_info.num_shards? 0 : -1; | |
1530 | ||
1531 | if (opt_cmd == OPT_BUCKET_SYNC_DISABLE) { | |
1532 | r = store->stop_bi_log_entries(bucket_info, -1); | |
1533 | if (r < 0) { | |
1534 | lderr(store->ctx()) << "ERROR: failed writing stop bilog" << dendl; | |
1535 | return r; | |
1536 | } | |
1537 | } else { | |
1538 | r = store->resync_bi_log_entries(bucket_info, -1); | |
1539 | if (r < 0) { | |
1540 | lderr(store->ctx()) << "ERROR: failed writing resync bilog" << dendl; | |
1541 | return r; | |
1542 | } | |
1543 | } | |
1544 | ||
1545 | for (int i = 0; i < shards_num; ++i, ++shard_id) { | |
1546 | r = store->data_log->add_entry(bucket_info.bucket, shard_id); | |
1547 | if (r < 0) { | |
1548 | lderr(store->ctx()) << "ERROR: failed writing data log" << dendl; | |
1549 | return r; | |
1550 | } | |
1551 | } | |
1552 | ||
1553 | return 0; | |
1554 | } | |
1555 | ||
1556 | ||
7c673cae FG |
1557 | /// search for a matching zone/zonegroup id and return a connection if found |
1558 | static boost::optional<RGWRESTConn> get_remote_conn(RGWRados *store, | |
1559 | const RGWZoneGroup& zonegroup, | |
1560 | const std::string& remote) | |
1561 | { | |
1562 | boost::optional<RGWRESTConn> conn; | |
1563 | if (remote == zonegroup.get_id()) { | |
1564 | conn.emplace(store->ctx(), store, remote, zonegroup.endpoints); | |
1565 | } else { | |
1566 | for (const auto& z : zonegroup.zones) { | |
1567 | const auto& zone = z.second; | |
1568 | if (remote == zone.id) { | |
1569 | conn.emplace(store->ctx(), store, remote, zone.endpoints); | |
1570 | break; | |
1571 | } | |
1572 | } | |
1573 | } | |
1574 | return conn; | |
1575 | } | |
1576 | ||
1577 | /// search each zonegroup for a connection | |
1578 | static boost::optional<RGWRESTConn> get_remote_conn(RGWRados *store, | |
1579 | const RGWPeriodMap& period_map, | |
1580 | const std::string& remote) | |
1581 | { | |
1582 | boost::optional<RGWRESTConn> conn; | |
1583 | for (const auto& zg : period_map.zonegroups) { | |
1584 | conn = get_remote_conn(store, zg.second, remote); | |
1585 | if (conn) { | |
1586 | break; | |
1587 | } | |
1588 | } | |
1589 | return conn; | |
1590 | } | |
1591 | ||
224ce89b WB |
1592 | // we expect a very small response |
1593 | static constexpr size_t MAX_REST_RESPONSE = 128 * 1024; | |
1594 | ||
7c673cae FG |
1595 | static int send_to_remote_gateway(RGWRESTConn* conn, req_info& info, |
1596 | bufferlist& in_data, JSONParser& parser) | |
1597 | { | |
224ce89b WB |
1598 | if (!conn) { |
1599 | return -EINVAL; | |
1600 | } | |
1601 | ||
1602 | ceph::bufferlist response; | |
7c673cae | 1603 | rgw_user user; |
224ce89b | 1604 | int ret = conn->forward(user, info, nullptr, MAX_REST_RESPONSE, &in_data, &response); |
7c673cae FG |
1605 | |
1606 | int parse_ret = parser.parse(response.c_str(), response.length()); | |
1607 | if (parse_ret < 0) { | |
1608 | cerr << "failed to parse response" << std::endl; | |
1609 | return parse_ret; | |
1610 | } | |
1611 | return ret; | |
1612 | } | |
1613 | ||
1614 | static int send_to_url(const string& url, const string& access, | |
1615 | const string& secret, req_info& info, | |
1616 | bufferlist& in_data, JSONParser& parser) | |
1617 | { | |
1618 | if (access.empty() || secret.empty()) { | |
1619 | cerr << "An --access-key and --secret must be provided with --url." << std::endl; | |
1620 | return -EINVAL; | |
1621 | } | |
1622 | RGWAccessKey key; | |
1623 | key.id = access; | |
1624 | key.key = secret; | |
1625 | ||
1626 | param_vec_t params; | |
1627 | RGWRESTSimpleRequest req(g_ceph_context, url, NULL, ¶ms); | |
1628 | ||
1629 | bufferlist response; | |
1630 | int ret = req.forward_request(key, info, MAX_REST_RESPONSE, &in_data, &response); | |
1631 | ||
1632 | int parse_ret = parser.parse(response.c_str(), response.length()); | |
1633 | if (parse_ret < 0) { | |
1634 | cout << "failed to parse response" << std::endl; | |
1635 | return parse_ret; | |
1636 | } | |
1637 | return ret; | |
1638 | } | |
1639 | ||
1640 | static int send_to_remote_or_url(RGWRESTConn *conn, const string& url, | |
1641 | const string& access, const string& secret, | |
1642 | req_info& info, bufferlist& in_data, | |
1643 | JSONParser& parser) | |
1644 | { | |
1645 | if (url.empty()) { | |
1646 | return send_to_remote_gateway(conn, info, in_data, parser); | |
1647 | } | |
1648 | return send_to_url(url, access, secret, info, in_data, parser); | |
1649 | } | |
1650 | ||
1651 | static int commit_period(RGWRealm& realm, RGWPeriod& period, | |
1652 | string remote, const string& url, | |
1653 | const string& access, const string& secret, | |
1654 | bool force) | |
1655 | { | |
1656 | const string& master_zone = period.get_master_zone(); | |
1657 | if (master_zone.empty()) { | |
1658 | cerr << "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl; | |
1659 | return -EINVAL; | |
1660 | } | |
1661 | // are we the period's master zone? | |
1662 | if (store->get_zone_params().get_id() == master_zone) { | |
1663 | // read the current period | |
1664 | RGWPeriod current_period; | |
1665 | int ret = current_period.init(g_ceph_context, store, realm.get_id()); | |
1666 | if (ret < 0) { | |
1667 | cerr << "Error initializing current period: " | |
1668 | << cpp_strerror(-ret) << std::endl; | |
1669 | return ret; | |
1670 | } | |
1671 | // the master zone can commit locally | |
1672 | ret = period.commit(realm, current_period, cerr, force); | |
1673 | if (ret < 0) { | |
1674 | cerr << "failed to commit period: " << cpp_strerror(-ret) << std::endl; | |
1675 | } | |
1676 | return ret; | |
1677 | } | |
1678 | ||
1679 | if (remote.empty() && url.empty()) { | |
1680 | // use the new master zone's connection | |
1681 | remote = master_zone; | |
1682 | cout << "Sending period to new master zone " << remote << std::endl; | |
1683 | } | |
1684 | boost::optional<RGWRESTConn> conn; | |
1685 | RGWRESTConn *remote_conn = nullptr; | |
1686 | if (!remote.empty()) { | |
1687 | conn = get_remote_conn(store, period.get_map(), remote); | |
1688 | if (!conn) { | |
1689 | cerr << "failed to find a zone or zonegroup for remote " | |
1690 | << remote << std::endl; | |
1691 | return -ENOENT; | |
1692 | } | |
1693 | remote_conn = &*conn; | |
1694 | } | |
1695 | ||
1696 | // push period to the master with an empty period id | |
1697 | period.set_id(""); | |
1698 | ||
1699 | RGWEnv env; | |
1700 | req_info info(g_ceph_context, &env); | |
1701 | info.method = "POST"; | |
1702 | info.request_uri = "/admin/realm/period"; | |
1703 | ||
1704 | // json format into a bufferlist | |
1705 | JSONFormatter jf(false); | |
1706 | encode_json("period", period, &jf); | |
1707 | bufferlist bl; | |
1708 | jf.flush(bl); | |
1709 | ||
1710 | JSONParser p; | |
1711 | int ret = send_to_remote_or_url(remote_conn, url, access, secret, info, bl, p); | |
1712 | if (ret < 0) { | |
1713 | cerr << "request failed: " << cpp_strerror(-ret) << std::endl; | |
1714 | ||
1715 | // did we parse an error message? | |
1716 | auto message = p.find_obj("Message"); | |
1717 | if (message) { | |
1718 | cerr << "Reason: " << message->get_data() << std::endl; | |
1719 | } | |
1720 | return ret; | |
1721 | } | |
1722 | ||
1723 | // decode the response and store it back | |
1724 | try { | |
1725 | decode_json_obj(period, &p); | |
1726 | } catch (JSONDecoder::err& e) { | |
1727 | cout << "failed to decode JSON input: " << e.message << std::endl; | |
1728 | return -EINVAL; | |
1729 | } | |
1730 | if (period.get_id().empty()) { | |
1731 | cerr << "Period commit got back an empty period id" << std::endl; | |
1732 | return -EINVAL; | |
1733 | } | |
1734 | // the master zone gave us back the period that it committed, so it's | |
1735 | // safe to save it as our latest epoch | |
1736 | ret = period.store_info(false); | |
1737 | if (ret < 0) { | |
1738 | cerr << "Error storing committed period " << period.get_id() << ": " | |
1739 | << cpp_strerror(ret) << std::endl; | |
1740 | return ret; | |
1741 | } | |
1742 | ret = period.set_latest_epoch(period.get_epoch()); | |
1743 | if (ret < 0) { | |
1744 | cerr << "Error updating period epoch: " << cpp_strerror(ret) << std::endl; | |
1745 | return ret; | |
1746 | } | |
1747 | ret = period.reflect(); | |
1748 | if (ret < 0) { | |
1749 | cerr << "Error updating local objects: " << cpp_strerror(ret) << std::endl; | |
1750 | return ret; | |
1751 | } | |
1752 | realm.notify_new_period(period); | |
1753 | return ret; | |
1754 | } | |
1755 | ||
1756 | static int update_period(const string& realm_id, const string& realm_name, | |
1757 | const string& period_id, const string& period_epoch, | |
1758 | bool commit, const string& remote, const string& url, | |
1759 | const string& access, const string& secret, | |
1760 | Formatter *formatter, bool force) | |
1761 | { | |
1762 | RGWRealm realm(realm_id, realm_name); | |
1763 | int ret = realm.init(g_ceph_context, store); | |
1764 | if (ret < 0 ) { | |
1765 | cerr << "Error initializing realm " << cpp_strerror(-ret) << std::endl; | |
1766 | return ret; | |
1767 | } | |
1768 | epoch_t epoch = 0; | |
1769 | if (!period_epoch.empty()) { | |
1770 | epoch = atoi(period_epoch.c_str()); | |
1771 | } | |
1772 | RGWPeriod period(period_id, epoch); | |
1773 | ret = period.init(g_ceph_context, store, realm.get_id()); | |
1774 | if (ret < 0) { | |
1775 | cerr << "period init failed: " << cpp_strerror(-ret) << std::endl; | |
1776 | return ret; | |
1777 | } | |
1778 | period.fork(); | |
1779 | ret = period.update(); | |
1780 | if(ret < 0) { | |
1781 | // Dropping the error message here, as both the ret codes were handled in | |
1782 | // period.update() | |
1783 | return ret; | |
1784 | } | |
1785 | ret = period.store_info(false); | |
1786 | if (ret < 0) { | |
1787 | cerr << "failed to store period: " << cpp_strerror(-ret) << std::endl; | |
1788 | return ret; | |
1789 | } | |
1790 | if (commit) { | |
1791 | ret = commit_period(realm, period, remote, url, access, secret, force); | |
1792 | if (ret < 0) { | |
1793 | cerr << "failed to commit period: " << cpp_strerror(-ret) << std::endl; | |
1794 | return ret; | |
1795 | } | |
1796 | } | |
1797 | encode_json("period", period, formatter); | |
1798 | formatter->flush(cout); | |
1799 | cout << std::endl; | |
1800 | return 0; | |
1801 | } | |
1802 | ||
1803 | static int init_bucket_for_sync(const string& tenant, const string& bucket_name, | |
1804 | const string& bucket_id, rgw_bucket& bucket) | |
1805 | { | |
1806 | RGWBucketInfo bucket_info; | |
1807 | ||
1808 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
1809 | if (ret < 0) { | |
1810 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
1811 | return ret; | |
1812 | } | |
1813 | ||
1814 | return 0; | |
1815 | } | |
1816 | ||
1817 | static int do_period_pull(RGWRESTConn *remote_conn, const string& url, | |
1818 | const string& access_key, const string& secret_key, | |
1819 | const string& realm_id, const string& realm_name, | |
1820 | const string& period_id, const string& period_epoch, | |
1821 | RGWPeriod *period) | |
1822 | { | |
1823 | RGWEnv env; | |
1824 | req_info info(g_ceph_context, &env); | |
1825 | info.method = "GET"; | |
1826 | info.request_uri = "/admin/realm/period"; | |
1827 | ||
1828 | map<string, string> ¶ms = info.args.get_params(); | |
1829 | if (!realm_id.empty()) | |
1830 | params["realm_id"] = realm_id; | |
1831 | if (!realm_name.empty()) | |
1832 | params["realm_name"] = realm_name; | |
1833 | if (!period_id.empty()) | |
1834 | params["period_id"] = period_id; | |
1835 | if (!period_epoch.empty()) | |
1836 | params["epoch"] = period_epoch; | |
1837 | ||
1838 | bufferlist bl; | |
1839 | JSONParser p; | |
1840 | int ret = send_to_remote_or_url(remote_conn, url, access_key, secret_key, | |
1841 | info, bl, p); | |
1842 | if (ret < 0) { | |
1843 | cerr << "request failed: " << cpp_strerror(-ret) << std::endl; | |
1844 | return ret; | |
1845 | } | |
1846 | ret = period->init(g_ceph_context, store, false); | |
1847 | if (ret < 0) { | |
1848 | cerr << "faile to init period " << cpp_strerror(-ret) << std::endl; | |
1849 | return ret; | |
1850 | } | |
1851 | try { | |
1852 | decode_json_obj(*period, &p); | |
1853 | } catch (JSONDecoder::err& e) { | |
1854 | cout << "failed to decode JSON input: " << e.message << std::endl; | |
1855 | return -EINVAL; | |
1856 | } | |
1857 | ret = period->store_info(false); | |
1858 | if (ret < 0) { | |
1859 | cerr << "Error storing period " << period->get_id() << ": " << cpp_strerror(ret) << std::endl; | |
1860 | } | |
224ce89b WB |
1861 | // store latest epoch (ignore errors) |
1862 | period->update_latest_epoch(period->get_epoch()); | |
7c673cae FG |
1863 | return 0; |
1864 | } | |
1865 | ||
1866 | static int read_current_period_id(RGWRados* store, const std::string& realm_id, | |
1867 | const std::string& realm_name, | |
1868 | std::string* period_id) | |
1869 | { | |
1870 | RGWRealm realm(realm_id, realm_name); | |
1871 | int ret = realm.init(g_ceph_context, store); | |
1872 | if (ret < 0) { | |
1873 | std::cerr << "failed to read realm: " << cpp_strerror(-ret) << std::endl; | |
1874 | return ret; | |
1875 | } | |
1876 | *period_id = realm.get_current_period(); | |
1877 | return 0; | |
1878 | } | |
1879 | ||
1880 | void flush_ss(stringstream& ss, list<string>& l) | |
1881 | { | |
1882 | if (!ss.str().empty()) { | |
1883 | l.push_back(ss.str()); | |
1884 | } | |
1885 | ss.str(""); | |
1886 | } | |
1887 | ||
1888 | stringstream& push_ss(stringstream& ss, list<string>& l, int tab = 0) | |
1889 | { | |
1890 | flush_ss(ss, l); | |
1891 | if (tab > 0) { | |
1892 | ss << setw(tab) << "" << setw(1); | |
1893 | } | |
1894 | return ss; | |
1895 | } | |
1896 | ||
1897 | static void get_md_sync_status(list<string>& status) | |
1898 | { | |
1899 | RGWMetaSyncStatusManager sync(store, store->get_async_rados()); | |
1900 | ||
1901 | int ret = sync.init(); | |
1902 | if (ret < 0) { | |
1903 | status.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret)); | |
1904 | return; | |
1905 | } | |
1906 | ||
1907 | rgw_meta_sync_status sync_status; | |
1908 | ret = sync.read_sync_status(&sync_status); | |
1909 | if (ret < 0) { | |
1910 | status.push_back(string("failed to read sync status: ") + cpp_strerror(-ret)); | |
1911 | return; | |
1912 | } | |
1913 | ||
1914 | string status_str; | |
1915 | switch (sync_status.sync_info.state) { | |
1916 | case rgw_meta_sync_info::StateInit: | |
1917 | status_str = "init"; | |
1918 | break; | |
1919 | case rgw_meta_sync_info::StateBuildingFullSyncMaps: | |
1920 | status_str = "preparing for full sync"; | |
1921 | break; | |
1922 | case rgw_meta_sync_info::StateSync: | |
1923 | status_str = "syncing"; | |
1924 | break; | |
1925 | default: | |
1926 | status_str = "unknown"; | |
1927 | } | |
1928 | ||
1929 | status.push_back(status_str); | |
1930 | ||
1931 | uint64_t full_total = 0; | |
1932 | uint64_t full_complete = 0; | |
1933 | ||
1934 | int num_full = 0; | |
1935 | int num_inc = 0; | |
1936 | int total_shards = 0; | |
1937 | ||
1938 | for (auto marker_iter : sync_status.sync_markers) { | |
1939 | full_total += marker_iter.second.total_entries; | |
1940 | total_shards++; | |
1941 | if (marker_iter.second.state == rgw_meta_sync_marker::SyncState::FullSync) { | |
1942 | num_full++; | |
1943 | full_complete += marker_iter.second.pos; | |
1944 | } else { | |
1945 | full_complete += marker_iter.second.total_entries; | |
1946 | } | |
1947 | if (marker_iter.second.state == rgw_meta_sync_marker::SyncState::IncrementalSync) { | |
1948 | num_inc++; | |
1949 | } | |
1950 | } | |
1951 | ||
1952 | stringstream ss; | |
1953 | push_ss(ss, status) << "full sync: " << num_full << "/" << total_shards << " shards"; | |
1954 | ||
1955 | if (num_full > 0) { | |
1956 | push_ss(ss, status) << "full sync: " << full_total - full_complete << " entries to sync"; | |
1957 | } | |
1958 | ||
1959 | push_ss(ss, status) << "incremental sync: " << num_inc << "/" << total_shards << " shards"; | |
1960 | ||
1961 | rgw_mdlog_info log_info; | |
1962 | ret = sync.read_log_info(&log_info); | |
1963 | if (ret < 0) { | |
1964 | status.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret)); | |
1965 | return; | |
1966 | } | |
1967 | ||
1968 | map<int, RGWMetadataLogInfo> master_shards_info; | |
1969 | string master_period = store->get_current_period_id(); | |
1970 | ||
1971 | ret = sync.read_master_log_shards_info(master_period, &master_shards_info); | |
1972 | if (ret < 0) { | |
1973 | status.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret)); | |
1974 | return; | |
1975 | } | |
1976 | ||
1977 | map<int, string> shards_behind; | |
1978 | if (sync_status.sync_info.period != master_period) { | |
1979 | status.push_back(string("master is on a different period: master_period=" + | |
1980 | master_period + " local_period=" + sync_status.sync_info.period)); | |
1981 | } else { | |
1982 | for (auto local_iter : sync_status.sync_markers) { | |
1983 | int shard_id = local_iter.first; | |
1984 | auto iter = master_shards_info.find(shard_id); | |
1985 | ||
1986 | if (iter == master_shards_info.end()) { | |
1987 | /* huh? */ | |
1988 | derr << "ERROR: could not find remote sync shard status for shard_id=" << shard_id << dendl; | |
1989 | continue; | |
1990 | } | |
1991 | auto master_marker = iter->second.marker; | |
1992 | if (local_iter.second.state == rgw_meta_sync_marker::SyncState::IncrementalSync && | |
1993 | master_marker > local_iter.second.marker) { | |
1994 | shards_behind[shard_id] = local_iter.second.marker; | |
1995 | } | |
1996 | } | |
1997 | } | |
1998 | ||
1999 | int total_behind = shards_behind.size() + (sync_status.sync_info.num_shards - num_inc); | |
2000 | if (total_behind == 0) { | |
2001 | push_ss(ss, status) << "metadata is caught up with master"; | |
2002 | } else { | |
2003 | push_ss(ss, status) << "metadata is behind on " << total_behind << " shards"; | |
2004 | ||
2005 | map<int, rgw_mdlog_shard_data> master_pos; | |
2006 | ret = sync.read_master_log_shards_next(sync_status.sync_info.period, shards_behind, &master_pos); | |
2007 | if (ret < 0) { | |
2008 | derr << "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret) << ")" << dendl; | |
2009 | } else { | |
2010 | ceph::real_time oldest; | |
2011 | for (auto iter : master_pos) { | |
2012 | rgw_mdlog_shard_data& shard_data = iter.second; | |
2013 | ||
2014 | if (!shard_data.entries.empty()) { | |
2015 | rgw_mdlog_entry& entry = shard_data.entries.front(); | |
2016 | if (ceph::real_clock::is_zero(oldest)) { | |
2017 | oldest = entry.timestamp; | |
2018 | } else if (!ceph::real_clock::is_zero(entry.timestamp) && entry.timestamp < oldest) { | |
2019 | oldest = entry.timestamp; | |
2020 | } | |
2021 | } | |
2022 | } | |
2023 | ||
2024 | if (!ceph::real_clock::is_zero(oldest)) { | |
2025 | push_ss(ss, status) << "oldest incremental change not applied: " << oldest; | |
2026 | } | |
2027 | } | |
2028 | } | |
2029 | ||
2030 | flush_ss(ss, status); | |
2031 | } | |
2032 | ||
2033 | static void get_data_sync_status(const string& source_zone, list<string>& status, int tab) | |
2034 | { | |
2035 | stringstream ss; | |
2036 | ||
2037 | auto ziter = store->zone_by_id.find(source_zone); | |
2038 | if (ziter == store->zone_by_id.end()) { | |
2039 | push_ss(ss, status, tab) << string("zone not found"); | |
2040 | flush_ss(ss, status); | |
2041 | return; | |
2042 | } | |
2043 | RGWZone& sz = ziter->second; | |
2044 | ||
2045 | if (!store->zone_syncs_from(store->get_zone(), sz)) { | |
2046 | push_ss(ss, status, tab) << string("not syncing from zone"); | |
2047 | flush_ss(ss, status); | |
2048 | return; | |
2049 | } | |
2050 | RGWDataSyncStatusManager sync(store, store->get_async_rados(), source_zone); | |
2051 | ||
2052 | int ret = sync.init(); | |
2053 | if (ret < 0) { | |
2054 | push_ss(ss, status, tab) << string("failed to retrieve sync info: ") + cpp_strerror(-ret); | |
2055 | flush_ss(ss, status); | |
2056 | return; | |
2057 | } | |
2058 | ||
2059 | rgw_data_sync_status sync_status; | |
2060 | ret = sync.read_sync_status(&sync_status); | |
2061 | if (ret < 0 && ret != -ENOENT) { | |
2062 | push_ss(ss, status, tab) << string("failed read sync status: ") + cpp_strerror(-ret); | |
2063 | return; | |
2064 | } | |
2065 | ||
2066 | string status_str; | |
2067 | switch (sync_status.sync_info.state) { | |
2068 | case rgw_data_sync_info::StateInit: | |
2069 | status_str = "init"; | |
2070 | break; | |
2071 | case rgw_data_sync_info::StateBuildingFullSyncMaps: | |
2072 | status_str = "preparing for full sync"; | |
2073 | break; | |
2074 | case rgw_data_sync_info::StateSync: | |
2075 | status_str = "syncing"; | |
2076 | break; | |
2077 | default: | |
2078 | status_str = "unknown"; | |
2079 | } | |
2080 | ||
2081 | push_ss(ss, status, tab) << status_str; | |
2082 | ||
2083 | uint64_t full_total = 0; | |
2084 | uint64_t full_complete = 0; | |
2085 | ||
2086 | int num_full = 0; | |
2087 | int num_inc = 0; | |
2088 | int total_shards = 0; | |
2089 | ||
2090 | for (auto marker_iter : sync_status.sync_markers) { | |
2091 | full_total += marker_iter.second.total_entries; | |
2092 | total_shards++; | |
2093 | if (marker_iter.second.state == rgw_data_sync_marker::SyncState::FullSync) { | |
2094 | num_full++; | |
2095 | full_complete += marker_iter.second.pos; | |
2096 | } else { | |
2097 | full_complete += marker_iter.second.total_entries; | |
2098 | } | |
2099 | if (marker_iter.second.state == rgw_data_sync_marker::SyncState::IncrementalSync) { | |
2100 | num_inc++; | |
2101 | } | |
2102 | } | |
2103 | ||
2104 | push_ss(ss, status, tab) << "full sync: " << num_full << "/" << total_shards << " shards"; | |
2105 | ||
2106 | if (num_full > 0) { | |
2107 | push_ss(ss, status, tab) << "full sync: " << full_total - full_complete << " buckets to sync"; | |
2108 | } | |
2109 | ||
2110 | push_ss(ss, status, tab) << "incremental sync: " << num_inc << "/" << total_shards << " shards"; | |
2111 | ||
2112 | rgw_datalog_info log_info; | |
2113 | ret = sync.read_log_info(&log_info); | |
2114 | if (ret < 0) { | |
2115 | push_ss(ss, status, tab) << string("failed to fetch local sync status: ") + cpp_strerror(-ret); | |
2116 | return; | |
2117 | } | |
2118 | ||
2119 | ||
2120 | map<int, RGWDataChangesLogInfo> source_shards_info; | |
2121 | ||
2122 | ret = sync.read_source_log_shards_info(&source_shards_info); | |
2123 | if (ret < 0) { | |
2124 | push_ss(ss, status, tab) << string("failed to fetch source sync status: ") + cpp_strerror(-ret); | |
2125 | return; | |
2126 | } | |
2127 | ||
2128 | map<int, string> shards_behind; | |
2129 | ||
2130 | for (auto local_iter : sync_status.sync_markers) { | |
2131 | int shard_id = local_iter.first; | |
2132 | auto iter = source_shards_info.find(shard_id); | |
2133 | ||
2134 | if (iter == source_shards_info.end()) { | |
2135 | /* huh? */ | |
2136 | derr << "ERROR: could not find remote sync shard status for shard_id=" << shard_id << dendl; | |
2137 | continue; | |
2138 | } | |
2139 | auto master_marker = iter->second.marker; | |
2140 | if (local_iter.second.state == rgw_data_sync_marker::SyncState::IncrementalSync && | |
2141 | master_marker > local_iter.second.marker) { | |
2142 | shards_behind[shard_id] = local_iter.second.marker; | |
2143 | } | |
2144 | } | |
2145 | ||
2146 | int total_behind = shards_behind.size() + (sync_status.sync_info.num_shards - num_inc); | |
2147 | if (total_behind == 0) { | |
2148 | push_ss(ss, status, tab) << "data is caught up with source"; | |
2149 | } else { | |
2150 | push_ss(ss, status, tab) << "data is behind on " << total_behind << " shards"; | |
2151 | ||
2152 | map<int, rgw_datalog_shard_data> master_pos; | |
2153 | ret = sync.read_source_log_shards_next(shards_behind, &master_pos); | |
2154 | if (ret < 0) { | |
2155 | derr << "ERROR: failed to fetch next positions (" << cpp_strerror(-ret) << ")" << dendl; | |
2156 | } else { | |
2157 | ceph::real_time oldest; | |
2158 | for (auto iter : master_pos) { | |
2159 | rgw_datalog_shard_data& shard_data = iter.second; | |
2160 | ||
2161 | if (!shard_data.entries.empty()) { | |
2162 | rgw_datalog_entry& entry = shard_data.entries.front(); | |
2163 | if (ceph::real_clock::is_zero(oldest)) { | |
2164 | oldest = entry.timestamp; | |
2165 | } else if (!ceph::real_clock::is_zero(entry.timestamp) && entry.timestamp < oldest) { | |
2166 | oldest = entry.timestamp; | |
2167 | } | |
2168 | } | |
2169 | } | |
2170 | ||
2171 | if (!ceph::real_clock::is_zero(oldest)) { | |
2172 | push_ss(ss, status, tab) << "oldest incremental change not applied: " << oldest; | |
2173 | } | |
2174 | } | |
2175 | } | |
2176 | ||
2177 | flush_ss(ss, status); | |
2178 | } | |
2179 | ||
2180 | static void tab_dump(const string& header, int width, const list<string>& entries) | |
2181 | { | |
2182 | string s = header; | |
2183 | ||
2184 | for (auto e : entries) { | |
2185 | cout << std::setw(width) << s << std::setw(1) << " " << e << std::endl; | |
2186 | s.clear(); | |
2187 | } | |
2188 | } | |
2189 | ||
2190 | ||
2191 | static void sync_status(Formatter *formatter) | |
2192 | { | |
2193 | RGWRealm& realm = store->realm; | |
2194 | RGWZoneGroup& zonegroup = store->get_zonegroup(); | |
2195 | RGWZone& zone = store->get_zone(); | |
2196 | ||
2197 | int width = 15; | |
2198 | ||
2199 | cout << std::setw(width) << "realm" << std::setw(1) << " " << realm.get_id() << " (" << realm.get_name() << ")" << std::endl; | |
2200 | cout << std::setw(width) << "zonegroup" << std::setw(1) << " " << zonegroup.get_id() << " (" << zonegroup.get_name() << ")" << std::endl; | |
2201 | cout << std::setw(width) << "zone" << std::setw(1) << " " << zone.id << " (" << zone.name << ")" << std::endl; | |
2202 | ||
2203 | list<string> md_status; | |
2204 | ||
2205 | if (store->is_meta_master()) { | |
2206 | md_status.push_back("no sync (zone is master)"); | |
2207 | } else { | |
2208 | get_md_sync_status(md_status); | |
2209 | } | |
2210 | ||
2211 | tab_dump("metadata sync", width, md_status); | |
2212 | ||
2213 | list<string> data_status; | |
2214 | ||
2215 | for (auto iter : store->zone_conn_map) { | |
2216 | const string& source_id = iter.first; | |
7c673cae FG |
2217 | string source_str = "source: "; |
2218 | string s = source_str + source_id; | |
2219 | auto siter = store->zone_by_id.find(source_id); | |
2220 | if (siter != store->zone_by_id.end()) { | |
2221 | s += string(" (") + siter->second.name + ")"; | |
2222 | } | |
2223 | data_status.push_back(s); | |
2224 | get_data_sync_status(source_id, data_status, source_str.size()); | |
2225 | } | |
2226 | ||
2227 | tab_dump("data sync", width, data_status); | |
2228 | } | |
2229 | ||
31f18b77 | 2230 | static void parse_tier_config_param(const string& s, map<string, string, ltstr_nocase>& out) |
7c673cae FG |
2231 | { |
2232 | list<string> confs; | |
2233 | get_str_list(s, ",", confs); | |
2234 | for (auto c : confs) { | |
2235 | ssize_t pos = c.find("="); | |
2236 | if (pos < 0) { | |
2237 | out[c] = ""; | |
2238 | } else { | |
2239 | out[c.substr(0, pos)] = c.substr(pos + 1); | |
2240 | } | |
2241 | } | |
2242 | } | |
2243 | ||
31f18b77 FG |
2244 | int check_reshard_bucket_params(RGWRados *store, |
2245 | const string& bucket_name, | |
2246 | const string& tenant, | |
2247 | const string& bucket_id, | |
2248 | bool num_shards_specified, | |
2249 | int num_shards, | |
2250 | int yes_i_really_mean_it, | |
2251 | rgw_bucket& bucket, | |
2252 | RGWBucketInfo& bucket_info, | |
2253 | map<string, bufferlist>& attrs) | |
2254 | { | |
2255 | if (bucket_name.empty()) { | |
2256 | cerr << "ERROR: bucket not specified" << std::endl; | |
2257 | return -EINVAL; | |
7c673cae FG |
2258 | } |
2259 | ||
31f18b77 FG |
2260 | if (!num_shards_specified) { |
2261 | cerr << "ERROR: --num-shards not specified" << std::endl; | |
2262 | return -EINVAL; | |
7c673cae FG |
2263 | } |
2264 | ||
31f18b77 FG |
2265 | if (num_shards > (int)store->get_max_bucket_shards()) { |
2266 | cerr << "ERROR: num_shards too high, max value: " << store->get_max_bucket_shards() << std::endl; | |
2267 | return -EINVAL; | |
7c673cae FG |
2268 | } |
2269 | ||
31f18b77 FG |
2270 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket, &attrs); |
2271 | if (ret < 0) { | |
2272 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
2273 | return -ret; | |
7c673cae | 2274 | } |
7c673cae | 2275 | |
31f18b77 | 2276 | int num_source_shards = (bucket_info.num_shards > 0 ? bucket_info.num_shards : 1); |
7c673cae | 2277 | |
31f18b77 FG |
2278 | if (num_shards <= num_source_shards && !yes_i_really_mean_it) { |
2279 | cerr << "num shards is less or equal to current shards count" << std::endl | |
2280 | << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl; | |
2281 | return -EINVAL; | |
7c673cae | 2282 | } |
31f18b77 FG |
2283 | return 0; |
2284 | } | |
7c673cae | 2285 | |
31f18b77 FG |
2286 | int create_new_bucket_instance(RGWRados *store, |
2287 | int new_num_shards, | |
2288 | const RGWBucketInfo& bucket_info, | |
2289 | map<string, bufferlist>& attrs, | |
2290 | RGWBucketInfo& new_bucket_info) | |
2291 | { | |
7c673cae | 2292 | |
31f18b77 FG |
2293 | store->create_bucket_id(&new_bucket_info.bucket.bucket_id); |
2294 | new_bucket_info.bucket.oid.clear(); | |
7c673cae | 2295 | |
31f18b77 FG |
2296 | new_bucket_info.num_shards = new_num_shards; |
2297 | new_bucket_info.objv_tracker.clear(); | |
7c673cae | 2298 | |
31f18b77 FG |
2299 | int ret = store->init_bucket_index(new_bucket_info, new_bucket_info.num_shards); |
2300 | if (ret < 0) { | |
2301 | cerr << "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret) << std::endl; | |
2302 | return -ret; | |
7c673cae FG |
2303 | } |
2304 | ||
31f18b77 FG |
2305 | ret = store->put_bucket_instance_info(new_bucket_info, true, real_time(), &attrs); |
2306 | if (ret < 0) { | |
2307 | cerr << "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret) << std::endl; | |
2308 | return -ret; | |
7c673cae FG |
2309 | } |
2310 | ||
31f18b77 FG |
2311 | return 0; |
2312 | } | |
2313 | ||
7c673cae FG |
2314 | |
2315 | #ifdef BUILDING_FOR_EMBEDDED | |
2316 | extern "C" int cephd_rgw_admin(int argc, const char **argv) | |
2317 | #else | |
2318 | int main(int argc, const char **argv) | |
2319 | #endif | |
2320 | { | |
2321 | vector<const char*> args; | |
2322 | argv_to_vec(argc, (const char **)argv, args); | |
2323 | env_to_vec(args); | |
2324 | ||
2325 | auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, | |
2326 | CODE_ENVIRONMENT_UTILITY, 0); | |
2327 | ||
2328 | // for region -> zonegroup conversion (must happen before common_init_finish()) | |
2329 | if (!g_conf->rgw_region.empty() && g_conf->rgw_zonegroup.empty()) { | |
2330 | g_conf->set_val_or_die("rgw_zonegroup", g_conf->rgw_region.c_str()); | |
2331 | } | |
2332 | ||
2333 | common_init_finish(g_ceph_context); | |
2334 | ||
2335 | rgw_user user_id; | |
2336 | string tenant; | |
2337 | std::string access_key, secret_key, user_email, display_name; | |
2338 | std::string bucket_name, pool_name, object; | |
2339 | rgw_pool pool; | |
2340 | std::string date, subuser, access, format; | |
2341 | std::string start_date, end_date; | |
2342 | std::string key_type_str; | |
2343 | std::string period_id, period_epoch, remote, url; | |
2344 | std::string master_zonegroup, master_zone; | |
2345 | std::string realm_name, realm_id, realm_new_name; | |
2346 | std::string zone_name, zone_id, zone_new_name; | |
2347 | std::string zonegroup_name, zonegroup_id, zonegroup_new_name; | |
2348 | std::string api_name; | |
2349 | std::string role_name, path, assume_role_doc, policy_name, perm_policy_doc, path_prefix; | |
2350 | list<string> endpoints; | |
2351 | int tmp_int; | |
2352 | int sync_from_all_specified = false; | |
2353 | bool sync_from_all = false; | |
2354 | list<string> sync_from; | |
2355 | list<string> sync_from_rm; | |
2356 | std::string master_url; | |
2357 | int is_master_int; | |
2358 | int set_default = 0; | |
2359 | bool is_master = false; | |
2360 | bool is_master_set = false; | |
2361 | int read_only_int; | |
2362 | bool read_only = false; | |
2363 | int is_read_only_set = false; | |
2364 | int commit = false; | |
2365 | int staging = false; | |
2366 | int key_type = KEY_TYPE_UNDEFINED; | |
2367 | rgw_bucket bucket; | |
2368 | uint32_t perm_mask = 0; | |
2369 | RGWUserInfo info; | |
2370 | int opt_cmd = OPT_NO_CMD; | |
2371 | bool need_more; | |
2372 | int gen_access_key = 0; | |
2373 | int gen_secret_key = 0; | |
2374 | bool set_perm = false; | |
2375 | bool set_temp_url_key = false; | |
2376 | map<int, string> temp_url_keys; | |
2377 | string bucket_id; | |
2378 | Formatter *formatter = NULL; | |
2379 | int purge_data = false; | |
7c673cae FG |
2380 | int pretty_format = false; |
2381 | int show_log_entries = true; | |
2382 | int show_log_sum = true; | |
2383 | int skip_zero_entries = false; // log show | |
2384 | int purge_keys = false; | |
2385 | int yes_i_really_mean_it = false; | |
2386 | int delete_child_objects = false; | |
2387 | int fix = false; | |
2388 | int remove_bad = false; | |
2389 | int check_head_obj_locator = false; | |
2390 | int max_buckets = -1; | |
2391 | bool max_buckets_specified = false; | |
2392 | map<string, bool> categories; | |
2393 | string caps; | |
2394 | int check_objects = false; | |
2395 | RGWUserAdminOpState user_op; | |
2396 | RGWBucketAdminOpState bucket_op; | |
2397 | string infile; | |
2398 | string metadata_key; | |
2399 | RGWObjVersionTracker objv_tracker; | |
2400 | string marker; | |
2401 | string start_marker; | |
2402 | string end_marker; | |
2403 | int max_entries = -1; | |
181888fb | 2404 | bool max_entries_specified = false; |
7c673cae FG |
2405 | int admin = false; |
2406 | bool admin_specified = false; | |
2407 | int system = false; | |
2408 | bool system_specified = false; | |
2409 | int shard_id = -1; | |
2410 | bool specified_shard_id = false; | |
2411 | string daemon_id; | |
2412 | bool specified_daemon_id = false; | |
2413 | string client_id; | |
2414 | string op_id; | |
2415 | string state_str; | |
2416 | string replica_log_type_str; | |
2417 | ReplicaLogType replica_log_type = ReplicaLog_Invalid; | |
2418 | string op_mask_str; | |
2419 | string quota_scope; | |
2420 | string object_version; | |
2421 | string placement_id; | |
2422 | list<string> tags; | |
2423 | list<string> tags_add; | |
2424 | list<string> tags_rm; | |
2425 | ||
2426 | int64_t max_objects = -1; | |
2427 | int64_t max_size = -1; | |
2428 | bool have_max_objects = false; | |
2429 | bool have_max_size = false; | |
2430 | int include_all = false; | |
2431 | ||
2432 | int sync_stats = false; | |
2433 | int bypass_gc = false; | |
2434 | int warnings_only = false; | |
2435 | int inconsistent_index = false; | |
2436 | ||
2437 | int verbose = false; | |
2438 | ||
2439 | int extra_info = false; | |
2440 | ||
2441 | uint64_t min_rewrite_size = 4 * 1024 * 1024; | |
2442 | uint64_t max_rewrite_size = ULLONG_MAX; | |
2443 | uint64_t min_rewrite_stripe_size = 0; | |
2444 | ||
2445 | BIIndexType bi_index_type = PlainIdx; | |
2446 | ||
2447 | string job_id; | |
2448 | int num_shards = 0; | |
2449 | bool num_shards_specified = false; | |
2450 | int max_concurrent_ios = 32; | |
2451 | uint64_t orphan_stale_secs = (24 * 3600); | |
2452 | ||
2453 | std::string val; | |
2454 | std::ostringstream errs; | |
2455 | string err; | |
2456 | long long tmp = 0; | |
2457 | ||
2458 | string source_zone_name; | |
2459 | string source_zone; /* zone id */ | |
2460 | ||
2461 | string tier_type; | |
2462 | bool tier_type_specified = false; | |
2463 | ||
31f18b77 FG |
2464 | map<string, string, ltstr_nocase> tier_config_add; |
2465 | map<string, string, ltstr_nocase> tier_config_rm; | |
7c673cae FG |
2466 | |
2467 | boost::optional<string> index_pool; | |
2468 | boost::optional<string> data_pool; | |
2469 | boost::optional<string> data_extra_pool; | |
2470 | RGWBucketIndexType placement_index_type = RGWBIType_Normal; | |
2471 | bool index_type_specified = false; | |
2472 | ||
2473 | boost::optional<std::string> compression_type; | |
2474 | ||
2475 | for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) { | |
2476 | if (ceph_argparse_double_dash(args, i)) { | |
2477 | break; | |
2478 | } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { | |
2479 | usage(); | |
d2e6a577 | 2480 | assert(false); |
7c673cae FG |
2481 | } else if (ceph_argparse_witharg(args, i, &val, "-i", "--uid", (char*)NULL)) { |
2482 | user_id.from_str(val); | |
2483 | } else if (ceph_argparse_witharg(args, i, &val, "--tenant", (char*)NULL)) { | |
2484 | tenant = val; | |
2485 | } else if (ceph_argparse_witharg(args, i, &val, "--access-key", (char*)NULL)) { | |
2486 | access_key = val; | |
2487 | } else if (ceph_argparse_witharg(args, i, &val, "--subuser", (char*)NULL)) { | |
2488 | subuser = val; | |
2489 | } else if (ceph_argparse_witharg(args, i, &val, "--secret", "--secret-key", (char*)NULL)) { | |
2490 | secret_key = val; | |
2491 | } else if (ceph_argparse_witharg(args, i, &val, "-e", "--email", (char*)NULL)) { | |
2492 | user_email = val; | |
2493 | user_op.user_email_specified=true; | |
2494 | } else if (ceph_argparse_witharg(args, i, &val, "-n", "--display-name", (char*)NULL)) { | |
2495 | display_name = val; | |
2496 | } else if (ceph_argparse_witharg(args, i, &val, "-b", "--bucket", (char*)NULL)) { | |
2497 | bucket_name = val; | |
2498 | } else if (ceph_argparse_witharg(args, i, &val, "-p", "--pool", (char*)NULL)) { | |
2499 | pool_name = val; | |
2500 | pool = rgw_pool(pool_name); | |
2501 | } else if (ceph_argparse_witharg(args, i, &val, "-o", "--object", (char*)NULL)) { | |
2502 | object = val; | |
2503 | } else if (ceph_argparse_witharg(args, i, &val, "--object-version", (char*)NULL)) { | |
2504 | object_version = val; | |
2505 | } else if (ceph_argparse_witharg(args, i, &val, "--client-id", (char*)NULL)) { | |
2506 | client_id = val; | |
2507 | } else if (ceph_argparse_witharg(args, i, &val, "--op-id", (char*)NULL)) { | |
2508 | op_id = val; | |
2509 | } else if (ceph_argparse_witharg(args, i, &val, "--state", (char*)NULL)) { | |
2510 | state_str = val; | |
2511 | } else if (ceph_argparse_witharg(args, i, &val, "--op-mask", (char*)NULL)) { | |
2512 | op_mask_str = val; | |
2513 | } else if (ceph_argparse_witharg(args, i, &val, "--key-type", (char*)NULL)) { | |
2514 | key_type_str = val; | |
2515 | if (key_type_str.compare("swift") == 0) { | |
2516 | key_type = KEY_TYPE_SWIFT; | |
2517 | } else if (key_type_str.compare("s3") == 0) { | |
2518 | key_type = KEY_TYPE_S3; | |
2519 | } else { | |
2520 | cerr << "bad key type: " << key_type_str << std::endl; | |
d2e6a577 FG |
2521 | usage(); |
2522 | assert(false); | |
7c673cae FG |
2523 | } |
2524 | } else if (ceph_argparse_witharg(args, i, &val, "--job-id", (char*)NULL)) { | |
2525 | job_id = val; | |
2526 | } else if (ceph_argparse_binary_flag(args, i, &gen_access_key, NULL, "--gen-access-key", (char*)NULL)) { | |
2527 | // do nothing | |
2528 | } else if (ceph_argparse_binary_flag(args, i, &gen_secret_key, NULL, "--gen-secret", (char*)NULL)) { | |
2529 | // do nothing | |
2530 | } else if (ceph_argparse_binary_flag(args, i, &show_log_entries, NULL, "--show_log_entries", (char*)NULL)) { | |
2531 | // do nothing | |
2532 | } else if (ceph_argparse_binary_flag(args, i, &show_log_sum, NULL, "--show_log_sum", (char*)NULL)) { | |
2533 | // do nothing | |
2534 | } else if (ceph_argparse_binary_flag(args, i, &skip_zero_entries, NULL, "--skip_zero_entries", (char*)NULL)) { | |
2535 | // do nothing | |
2536 | } else if (ceph_argparse_binary_flag(args, i, &admin, NULL, "--admin", (char*)NULL)) { | |
2537 | admin_specified = true; | |
2538 | } else if (ceph_argparse_binary_flag(args, i, &system, NULL, "--system", (char*)NULL)) { | |
2539 | system_specified = true; | |
2540 | } else if (ceph_argparse_binary_flag(args, i, &verbose, NULL, "--verbose", (char*)NULL)) { | |
2541 | // do nothing | |
2542 | } else if (ceph_argparse_binary_flag(args, i, &staging, NULL, "--staging", (char*)NULL)) { | |
2543 | // do nothing | |
2544 | } else if (ceph_argparse_binary_flag(args, i, &commit, NULL, "--commit", (char*)NULL)) { | |
2545 | // do nothing | |
2546 | } else if (ceph_argparse_witharg(args, i, &tmp, errs, "-a", "--auth-uid", (char*)NULL)) { | |
2547 | if (!errs.str().empty()) { | |
2548 | cerr << errs.str() << std::endl; | |
2549 | exit(EXIT_FAILURE); | |
2550 | } | |
2551 | } else if (ceph_argparse_witharg(args, i, &val, "--min-rewrite-size", (char*)NULL)) { | |
2552 | min_rewrite_size = (uint64_t)atoll(val.c_str()); | |
2553 | } else if (ceph_argparse_witharg(args, i, &val, "--max-rewrite-size", (char*)NULL)) { | |
2554 | max_rewrite_size = (uint64_t)atoll(val.c_str()); | |
2555 | } else if (ceph_argparse_witharg(args, i, &val, "--min-rewrite-stripe-size", (char*)NULL)) { | |
2556 | min_rewrite_stripe_size = (uint64_t)atoll(val.c_str()); | |
2557 | } else if (ceph_argparse_witharg(args, i, &val, "--max-buckets", (char*)NULL)) { | |
2558 | max_buckets = (int)strict_strtol(val.c_str(), 10, &err); | |
2559 | if (!err.empty()) { | |
2560 | cerr << "ERROR: failed to parse max buckets: " << err << std::endl; | |
2561 | return EINVAL; | |
2562 | } | |
2563 | max_buckets_specified = true; | |
2564 | } else if (ceph_argparse_witharg(args, i, &val, "--max-entries", (char*)NULL)) { | |
2565 | max_entries = (int)strict_strtol(val.c_str(), 10, &err); | |
181888fb | 2566 | max_entries_specified = true; |
7c673cae FG |
2567 | if (!err.empty()) { |
2568 | cerr << "ERROR: failed to parse max entries: " << err << std::endl; | |
2569 | return EINVAL; | |
2570 | } | |
2571 | } else if (ceph_argparse_witharg(args, i, &val, "--max-size", (char*)NULL)) { | |
2572 | max_size = strict_si_cast<int64_t>(val.c_str(), &err); | |
2573 | if (!err.empty()) { | |
2574 | cerr << "ERROR: failed to parse max size: " << err << std::endl; | |
2575 | return EINVAL; | |
2576 | } | |
2577 | have_max_size = true; | |
2578 | } else if (ceph_argparse_witharg(args, i, &val, "--max-objects", (char*)NULL)) { | |
2579 | max_objects = (int64_t)strict_strtoll(val.c_str(), 10, &err); | |
2580 | if (!err.empty()) { | |
2581 | cerr << "ERROR: failed to parse max objects: " << err << std::endl; | |
2582 | return EINVAL; | |
2583 | } | |
2584 | have_max_objects = true; | |
2585 | } else if (ceph_argparse_witharg(args, i, &val, "--date", "--time", (char*)NULL)) { | |
2586 | date = val; | |
2587 | if (end_date.empty()) | |
2588 | end_date = date; | |
2589 | } else if (ceph_argparse_witharg(args, i, &val, "--start-date", "--start-time", (char*)NULL)) { | |
2590 | start_date = val; | |
2591 | } else if (ceph_argparse_witharg(args, i, &val, "--end-date", "--end-time", (char*)NULL)) { | |
2592 | end_date = val; | |
2593 | } else if (ceph_argparse_witharg(args, i, &val, "--num-shards", (char*)NULL)) { | |
2594 | num_shards = (int)strict_strtol(val.c_str(), 10, &err); | |
2595 | if (!err.empty()) { | |
2596 | cerr << "ERROR: failed to parse num shards: " << err << std::endl; | |
2597 | return EINVAL; | |
2598 | } | |
2599 | num_shards_specified = true; | |
2600 | } else if (ceph_argparse_witharg(args, i, &val, "--max-concurrent-ios", (char*)NULL)) { | |
2601 | max_concurrent_ios = (int)strict_strtol(val.c_str(), 10, &err); | |
2602 | if (!err.empty()) { | |
2603 | cerr << "ERROR: failed to parse max concurrent ios: " << err << std::endl; | |
2604 | return EINVAL; | |
2605 | } | |
2606 | } else if (ceph_argparse_witharg(args, i, &val, "--orphan-stale-secs", (char*)NULL)) { | |
2607 | orphan_stale_secs = (uint64_t)strict_strtoll(val.c_str(), 10, &err); | |
2608 | if (!err.empty()) { | |
2609 | cerr << "ERROR: failed to parse orphan stale secs: " << err << std::endl; | |
2610 | return EINVAL; | |
2611 | } | |
2612 | } else if (ceph_argparse_witharg(args, i, &val, "--shard-id", (char*)NULL)) { | |
2613 | shard_id = (int)strict_strtol(val.c_str(), 10, &err); | |
2614 | if (!err.empty()) { | |
2615 | cerr << "ERROR: failed to parse shard id: " << err << std::endl; | |
2616 | return EINVAL; | |
2617 | } | |
2618 | specified_shard_id = true; | |
2619 | } else if (ceph_argparse_witharg(args, i, &val, "--daemon-id", (char*)NULL)) { | |
2620 | daemon_id = val; | |
2621 | specified_daemon_id = true; | |
2622 | } else if (ceph_argparse_witharg(args, i, &val, "--access", (char*)NULL)) { | |
2623 | access = val; | |
2624 | perm_mask = rgw_str_to_perm(access.c_str()); | |
2625 | set_perm = true; | |
2626 | } else if (ceph_argparse_witharg(args, i, &val, "--temp-url-key", (char*)NULL)) { | |
2627 | temp_url_keys[0] = val; | |
2628 | set_temp_url_key = true; | |
2629 | } else if (ceph_argparse_witharg(args, i, &val, "--temp-url-key2", "--temp-url-key-2", (char*)NULL)) { | |
2630 | temp_url_keys[1] = val; | |
2631 | set_temp_url_key = true; | |
2632 | } else if (ceph_argparse_witharg(args, i, &val, "--bucket-id", (char*)NULL)) { | |
2633 | bucket_id = val; | |
2634 | if (bucket_id.empty()) { | |
2635 | cerr << "bad bucket-id" << std::endl; | |
d2e6a577 FG |
2636 | usage(); |
2637 | assert(false); | |
7c673cae FG |
2638 | } |
2639 | } else if (ceph_argparse_witharg(args, i, &val, "--format", (char*)NULL)) { | |
2640 | format = val; | |
2641 | } else if (ceph_argparse_witharg(args, i, &val, "--categories", (char*)NULL)) { | |
2642 | string cat_str = val; | |
2643 | list<string> cat_list; | |
2644 | list<string>::iterator iter; | |
2645 | get_str_list(cat_str, cat_list); | |
2646 | for (iter = cat_list.begin(); iter != cat_list.end(); ++iter) { | |
2647 | categories[*iter] = true; | |
2648 | } | |
2649 | } else if (ceph_argparse_binary_flag(args, i, &delete_child_objects, NULL, "--purge-objects", (char*)NULL)) { | |
2650 | // do nothing | |
2651 | } else if (ceph_argparse_binary_flag(args, i, &pretty_format, NULL, "--pretty-format", (char*)NULL)) { | |
2652 | // do nothing | |
2653 | } else if (ceph_argparse_binary_flag(args, i, &purge_data, NULL, "--purge-data", (char*)NULL)) { | |
2654 | delete_child_objects = purge_data; | |
2655 | } else if (ceph_argparse_binary_flag(args, i, &purge_keys, NULL, "--purge-keys", (char*)NULL)) { | |
2656 | // do nothing | |
2657 | } else if (ceph_argparse_binary_flag(args, i, &yes_i_really_mean_it, NULL, "--yes-i-really-mean-it", (char*)NULL)) { | |
2658 | // do nothing | |
2659 | } else if (ceph_argparse_binary_flag(args, i, &fix, NULL, "--fix", (char*)NULL)) { | |
2660 | // do nothing | |
2661 | } else if (ceph_argparse_binary_flag(args, i, &remove_bad, NULL, "--remove-bad", (char*)NULL)) { | |
2662 | // do nothing | |
2663 | } else if (ceph_argparse_binary_flag(args, i, &check_head_obj_locator, NULL, "--check-head-obj-locator", (char*)NULL)) { | |
2664 | // do nothing | |
2665 | } else if (ceph_argparse_binary_flag(args, i, &check_objects, NULL, "--check-objects", (char*)NULL)) { | |
2666 | // do nothing | |
2667 | } else if (ceph_argparse_binary_flag(args, i, &sync_stats, NULL, "--sync-stats", (char*)NULL)) { | |
2668 | // do nothing | |
2669 | } else if (ceph_argparse_binary_flag(args, i, &include_all, NULL, "--include-all", (char*)NULL)) { | |
2670 | // do nothing | |
2671 | } else if (ceph_argparse_binary_flag(args, i, &extra_info, NULL, "--extra-info", (char*)NULL)) { | |
2672 | // do nothing | |
2673 | } else if (ceph_argparse_binary_flag(args, i, &bypass_gc, NULL, "--bypass-gc", (char*)NULL)) { | |
2674 | // do nothing | |
2675 | } else if (ceph_argparse_binary_flag(args, i, &warnings_only, NULL, "--warnings-only", (char*)NULL)) { | |
2676 | // do nothing | |
2677 | } else if (ceph_argparse_binary_flag(args, i, &inconsistent_index, NULL, "--inconsistent-index", (char*)NULL)) { | |
2678 | // do nothing | |
2679 | } else if (ceph_argparse_witharg(args, i, &val, "--caps", (char*)NULL)) { | |
2680 | caps = val; | |
2681 | } else if (ceph_argparse_witharg(args, i, &val, "-i", "--infile", (char*)NULL)) { | |
2682 | infile = val; | |
2683 | } else if (ceph_argparse_witharg(args, i, &val, "--metadata-key", (char*)NULL)) { | |
2684 | metadata_key = val; | |
2685 | } else if (ceph_argparse_witharg(args, i, &val, "--marker", (char*)NULL)) { | |
2686 | marker = val; | |
2687 | } else if (ceph_argparse_witharg(args, i, &val, "--start-marker", (char*)NULL)) { | |
2688 | start_marker = val; | |
2689 | } else if (ceph_argparse_witharg(args, i, &val, "--end-marker", (char*)NULL)) { | |
2690 | end_marker = val; | |
2691 | } else if (ceph_argparse_witharg(args, i, &val, "--quota-scope", (char*)NULL)) { | |
2692 | quota_scope = val; | |
2693 | } else if (ceph_argparse_witharg(args, i, &val, "--replica-log-type", (char*)NULL)) { | |
2694 | replica_log_type_str = val; | |
2695 | replica_log_type = get_replicalog_type(replica_log_type_str); | |
2696 | if (replica_log_type == ReplicaLog_Invalid) { | |
2697 | cerr << "ERROR: invalid replica log type" << std::endl; | |
2698 | return EINVAL; | |
2699 | } | |
2700 | } else if (ceph_argparse_witharg(args, i, &val, "--index-type", (char*)NULL)) { | |
2701 | string index_type_str = val; | |
2702 | bi_index_type = get_bi_index_type(index_type_str); | |
2703 | if (bi_index_type == InvalidIdx) { | |
2704 | cerr << "ERROR: invalid bucket index entry type" << std::endl; | |
2705 | return EINVAL; | |
2706 | } | |
2707 | } else if (ceph_argparse_binary_flag(args, i, &is_master_int, NULL, "--master", (char*)NULL)) { | |
2708 | is_master = (bool)is_master_int; | |
2709 | is_master_set = true; | |
2710 | } else if (ceph_argparse_binary_flag(args, i, &set_default, NULL, "--default", (char*)NULL)) { | |
2711 | /* do nothing */ | |
2712 | } else if (ceph_argparse_binary_flag(args, i, &read_only_int, NULL, "--read-only", (char*)NULL)) { | |
2713 | read_only = (bool)read_only_int; | |
2714 | is_read_only_set = true; | |
2715 | } else if (ceph_argparse_witharg(args, i, &val, "--master-url", (char*)NULL)) { | |
2716 | master_url = val; | |
2717 | } else if (ceph_argparse_witharg(args, i, &val, "--master-zonegroup", (char*)NULL)) { | |
2718 | master_zonegroup = val; | |
2719 | } else if (ceph_argparse_witharg(args, i, &val, "--master-zone", (char*)NULL)) { | |
2720 | master_zone = val; | |
2721 | } else if (ceph_argparse_witharg(args, i, &val, "--period", (char*)NULL)) { | |
2722 | period_id = val; | |
2723 | } else if (ceph_argparse_witharg(args, i, &val, "--epoch", (char*)NULL)) { | |
2724 | period_epoch = val; | |
2725 | } else if (ceph_argparse_witharg(args, i, &val, "--remote", (char*)NULL)) { | |
2726 | remote = val; | |
2727 | } else if (ceph_argparse_witharg(args, i, &val, "--url", (char*)NULL)) { | |
2728 | url = val; | |
2729 | } else if (ceph_argparse_witharg(args, i, &val, "--realm-id", (char*)NULL)) { | |
2730 | realm_id = val; | |
2731 | } else if (ceph_argparse_witharg(args, i, &val, "--realm-new-name", (char*)NULL)) { | |
2732 | realm_new_name = val; | |
2733 | } else if (ceph_argparse_witharg(args, i, &val, "--zonegroup-id", (char*)NULL)) { | |
2734 | zonegroup_id = val; | |
2735 | } else if (ceph_argparse_witharg(args, i, &val, "--zonegroup-new-name", (char*)NULL)) { | |
2736 | zonegroup_new_name = val; | |
2737 | } else if (ceph_argparse_witharg(args, i, &val, "--placement-id", (char*)NULL)) { | |
2738 | placement_id = val; | |
2739 | } else if (ceph_argparse_witharg(args, i, &val, "--tags", (char*)NULL)) { | |
2740 | get_str_list(val, tags); | |
2741 | } else if (ceph_argparse_witharg(args, i, &val, "--tags-add", (char*)NULL)) { | |
2742 | get_str_list(val, tags_add); | |
2743 | } else if (ceph_argparse_witharg(args, i, &val, "--tags-rm", (char*)NULL)) { | |
2744 | get_str_list(val, tags_rm); | |
2745 | } else if (ceph_argparse_witharg(args, i, &val, "--api-name", (char*)NULL)) { | |
2746 | api_name = val; | |
2747 | } else if (ceph_argparse_witharg(args, i, &val, "--zone-id", (char*)NULL)) { | |
2748 | zone_id = val; | |
2749 | } else if (ceph_argparse_witharg(args, i, &val, "--zone-new-name", (char*)NULL)) { | |
2750 | zone_new_name = val; | |
2751 | } else if (ceph_argparse_witharg(args, i, &val, "--endpoints", (char*)NULL)) { | |
2752 | get_str_list(val, endpoints); | |
2753 | } else if (ceph_argparse_witharg(args, i, &val, "--sync-from", (char*)NULL)) { | |
2754 | get_str_list(val, sync_from); | |
2755 | } else if (ceph_argparse_witharg(args, i, &val, "--sync-from-rm", (char*)NULL)) { | |
2756 | get_str_list(val, sync_from_rm); | |
2757 | } else if (ceph_argparse_binary_flag(args, i, &tmp_int, NULL, "--sync-from-all", (char*)NULL)) { | |
2758 | sync_from_all = (bool)tmp_int; | |
2759 | sync_from_all_specified = true; | |
2760 | } else if (ceph_argparse_witharg(args, i, &val, "--source-zone", (char*)NULL)) { | |
2761 | source_zone_name = val; | |
2762 | } else if (ceph_argparse_witharg(args, i, &val, "--tier-type", (char*)NULL)) { | |
2763 | tier_type = val; | |
2764 | tier_type_specified = true; | |
2765 | } else if (ceph_argparse_witharg(args, i, &val, "--tier-config", (char*)NULL)) { | |
2766 | parse_tier_config_param(val, tier_config_add); | |
2767 | } else if (ceph_argparse_witharg(args, i, &val, "--tier-config-rm", (char*)NULL)) { | |
2768 | parse_tier_config_param(val, tier_config_rm); | |
2769 | } else if (ceph_argparse_witharg(args, i, &val, "--index-pool", (char*)NULL)) { | |
2770 | index_pool = val; | |
2771 | } else if (ceph_argparse_witharg(args, i, &val, "--data-pool", (char*)NULL)) { | |
2772 | data_pool = val; | |
2773 | } else if (ceph_argparse_witharg(args, i, &val, "--data-extra-pool", (char*)NULL)) { | |
2774 | data_extra_pool = val; | |
2775 | } else if (ceph_argparse_witharg(args, i, &val, "--placement-index-type", (char*)NULL)) { | |
2776 | if (val == "normal") { | |
2777 | placement_index_type = RGWBIType_Normal; | |
2778 | } else if (val == "indexless") { | |
2779 | placement_index_type = RGWBIType_Indexless; | |
2780 | } else { | |
2781 | placement_index_type = (RGWBucketIndexType)strict_strtol(val.c_str(), 10, &err); | |
2782 | if (!err.empty()) { | |
2783 | cerr << "ERROR: failed to parse index type index: " << err << std::endl; | |
2784 | return EINVAL; | |
2785 | } | |
2786 | } | |
2787 | index_type_specified = true; | |
2788 | } else if (ceph_argparse_witharg(args, i, &val, "--compression", (char*)NULL)) { | |
2789 | compression_type = val; | |
2790 | } else if (ceph_argparse_witharg(args, i, &val, "--role-name", (char*)NULL)) { | |
2791 | role_name = val; | |
2792 | } else if (ceph_argparse_witharg(args, i, &val, "--path", (char*)NULL)) { | |
2793 | path = val; | |
2794 | } else if (ceph_argparse_witharg(args, i, &val, "--assume-role-policy-doc", (char*)NULL)) { | |
2795 | assume_role_doc = val; | |
2796 | } else if (ceph_argparse_witharg(args, i, &val, "--policy-name", (char*)NULL)) { | |
2797 | policy_name = val; | |
2798 | } else if (ceph_argparse_witharg(args, i, &val, "--policy-doc", (char*)NULL)) { | |
2799 | perm_policy_doc = val; | |
2800 | } else if (ceph_argparse_witharg(args, i, &val, "--path-prefix", (char*)NULL)) { | |
2801 | path_prefix = val; | |
2802 | } else if (strncmp(*i, "-", 1) == 0) { | |
2803 | cerr << "ERROR: invalid flag " << *i << std::endl; | |
2804 | return EINVAL; | |
2805 | } else { | |
2806 | ++i; | |
2807 | } | |
2808 | } | |
7c673cae FG |
2809 | |
2810 | if (args.empty()) { | |
d2e6a577 FG |
2811 | usage(); |
2812 | assert(false); | |
7c673cae FG |
2813 | } |
2814 | else { | |
2815 | const char *prev_cmd = NULL; | |
2816 | const char *prev_prev_cmd = NULL; | |
2817 | std::vector<const char*>::iterator i ; | |
2818 | for (i = args.begin(); i != args.end(); ++i) { | |
2819 | opt_cmd = get_cmd(*i, prev_cmd, prev_prev_cmd, &need_more); | |
2820 | if (opt_cmd < 0) { | |
2821 | cerr << "unrecognized arg " << *i << std::endl; | |
d2e6a577 FG |
2822 | usage(); |
2823 | assert(false); | |
7c673cae FG |
2824 | } |
2825 | if (!need_more) { | |
2826 | ++i; | |
2827 | break; | |
2828 | } | |
2829 | prev_prev_cmd = prev_cmd; | |
2830 | prev_cmd = *i; | |
2831 | } | |
2832 | ||
d2e6a577 FG |
2833 | if (opt_cmd == OPT_NO_CMD) { |
2834 | usage(); | |
2835 | assert(false); | |
2836 | } | |
7c673cae FG |
2837 | |
2838 | /* some commands may have an optional extra param */ | |
2839 | if (i != args.end()) { | |
2840 | switch (opt_cmd) { | |
2841 | case OPT_METADATA_GET: | |
2842 | case OPT_METADATA_PUT: | |
2843 | case OPT_METADATA_RM: | |
2844 | case OPT_METADATA_LIST: | |
2845 | metadata_key = *i; | |
2846 | break; | |
2847 | default: | |
2848 | break; | |
2849 | } | |
2850 | } | |
2851 | ||
31f18b77 FG |
2852 | if (tenant.empty()) { |
2853 | tenant = user_id.tenant; | |
2854 | } else { | |
2855 | if (user_id.empty() && opt_cmd != OPT_ROLE_CREATE | |
2856 | && opt_cmd != OPT_ROLE_DELETE | |
2857 | && opt_cmd != OPT_ROLE_GET | |
2858 | && opt_cmd != OPT_ROLE_MODIFY | |
2859 | && opt_cmd != OPT_ROLE_LIST | |
2860 | && opt_cmd != OPT_ROLE_POLICY_PUT | |
2861 | && opt_cmd != OPT_ROLE_POLICY_LIST | |
2862 | && opt_cmd != OPT_ROLE_POLICY_GET | |
b32b8144 FG |
2863 | && opt_cmd != OPT_ROLE_POLICY_DELETE |
2864 | && opt_cmd != OPT_RESHARD_ADD | |
2865 | && opt_cmd != OPT_RESHARD_CANCEL | |
2866 | && opt_cmd != OPT_RESHARD_STATUS) { | |
31f18b77 FG |
2867 | cerr << "ERROR: --tenant is set, but there's no user ID" << std::endl; |
2868 | return EINVAL; | |
2869 | } | |
2870 | user_id.tenant = tenant; | |
2871 | } | |
7c673cae FG |
2872 | /* check key parameter conflict */ |
2873 | if ((!access_key.empty()) && gen_access_key) { | |
2874 | cerr << "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl; | |
2875 | return EINVAL; | |
2876 | } | |
2877 | if ((!secret_key.empty()) && gen_secret_key) { | |
2878 | cerr << "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl; | |
2879 | return EINVAL; | |
2880 | } | |
2881 | } | |
2882 | ||
2883 | // default to pretty json | |
2884 | if (format.empty()) { | |
2885 | format = "json"; | |
2886 | pretty_format = true; | |
2887 | } | |
2888 | ||
2889 | if (format == "xml") | |
2890 | formatter = new XMLFormatter(pretty_format); | |
2891 | else if (format == "json") | |
2892 | formatter = new JSONFormatter(pretty_format); | |
2893 | else { | |
2894 | cerr << "unrecognized format: " << format << std::endl; | |
d2e6a577 FG |
2895 | usage(); |
2896 | assert(false); | |
7c673cae FG |
2897 | } |
2898 | ||
2899 | realm_name = g_conf->rgw_realm; | |
2900 | zone_name = g_conf->rgw_zone; | |
2901 | zonegroup_name = g_conf->rgw_zonegroup; | |
2902 | ||
2903 | RGWStreamFlusher f(formatter, cout); | |
2904 | ||
2905 | // not a raw op if 'period update' needs to commit to master | |
2906 | bool raw_period_update = opt_cmd == OPT_PERIOD_UPDATE && !commit; | |
2907 | std::set<int> raw_storage_ops_list = {OPT_ZONEGROUP_ADD, OPT_ZONEGROUP_CREATE, OPT_ZONEGROUP_DELETE, | |
2908 | OPT_ZONEGROUP_GET, OPT_ZONEGROUP_LIST, | |
2909 | OPT_ZONEGROUP_SET, OPT_ZONEGROUP_DEFAULT, | |
2910 | OPT_ZONEGROUP_RENAME, OPT_ZONEGROUP_MODIFY, | |
2911 | OPT_ZONEGROUP_REMOVE, | |
2912 | OPT_ZONEGROUP_PLACEMENT_ADD, OPT_ZONEGROUP_PLACEMENT_RM, | |
2913 | OPT_ZONEGROUP_PLACEMENT_MODIFY, OPT_ZONEGROUP_PLACEMENT_LIST, | |
2914 | OPT_ZONEGROUP_PLACEMENT_DEFAULT, | |
2915 | OPT_ZONE_CREATE, OPT_ZONE_DELETE, | |
2916 | OPT_ZONE_GET, OPT_ZONE_SET, OPT_ZONE_RENAME, | |
2917 | OPT_ZONE_LIST, OPT_ZONE_MODIFY, OPT_ZONE_DEFAULT, | |
2918 | OPT_ZONE_PLACEMENT_ADD, OPT_ZONE_PLACEMENT_RM, | |
2919 | OPT_ZONE_PLACEMENT_MODIFY, OPT_ZONE_PLACEMENT_LIST, | |
2920 | OPT_REALM_CREATE, | |
2921 | OPT_PERIOD_DELETE, OPT_PERIOD_GET, | |
2922 | OPT_PERIOD_PULL, | |
2923 | OPT_PERIOD_GET_CURRENT, OPT_PERIOD_LIST, | |
2924 | OPT_GLOBAL_QUOTA_GET, OPT_GLOBAL_QUOTA_SET, | |
2925 | OPT_GLOBAL_QUOTA_ENABLE, OPT_GLOBAL_QUOTA_DISABLE, | |
2926 | OPT_REALM_DELETE, OPT_REALM_GET, OPT_REALM_LIST, | |
2927 | OPT_REALM_LIST_PERIODS, | |
2928 | OPT_REALM_GET_DEFAULT, OPT_REALM_REMOVE, | |
2929 | OPT_REALM_RENAME, OPT_REALM_SET, | |
2930 | OPT_REALM_DEFAULT, OPT_REALM_PULL}; | |
2931 | ||
2932 | ||
2933 | bool raw_storage_op = (raw_storage_ops_list.find(opt_cmd) != raw_storage_ops_list.end() || | |
2934 | raw_period_update); | |
2935 | ||
2936 | if (raw_storage_op) { | |
2937 | store = RGWStoreManager::get_raw_storage(g_ceph_context); | |
2938 | } else { | |
31f18b77 | 2939 | store = RGWStoreManager::get_storage(g_ceph_context, false, false, false, false, false); |
7c673cae FG |
2940 | } |
2941 | if (!store) { | |
2942 | cerr << "couldn't init storage provider" << std::endl; | |
2943 | return 5; //EIO | |
2944 | } | |
2945 | ||
2946 | if (!source_zone_name.empty()) { | |
2947 | if (!store->find_zone_id_by_name(source_zone_name, &source_zone)) { | |
2948 | cerr << "WARNING: cannot find source zone id for name=" << source_zone_name << std::endl; | |
2949 | source_zone = source_zone_name; | |
2950 | } | |
2951 | } | |
2952 | ||
2953 | rgw_user_init(store); | |
2954 | rgw_bucket_init(store->meta_mgr); | |
2955 | ||
2956 | StoreDestructor store_destructor(store); | |
2957 | ||
2958 | if (raw_storage_op) { | |
2959 | switch (opt_cmd) { | |
2960 | case OPT_PERIOD_DELETE: | |
2961 | { | |
2962 | if (period_id.empty()) { | |
2963 | cerr << "missing period id" << std::endl; | |
2964 | return EINVAL; | |
2965 | } | |
2966 | RGWPeriod period(period_id); | |
2967 | int ret = period.init(g_ceph_context, store); | |
2968 | if (ret < 0) { | |
2969 | cerr << "period.init failed: " << cpp_strerror(-ret) << std::endl; | |
2970 | return -ret; | |
2971 | } | |
2972 | ret = period.delete_obj(); | |
2973 | if (ret < 0) { | |
2974 | cerr << "ERROR: couldn't delete period: " << cpp_strerror(-ret) << std::endl; | |
2975 | return -ret; | |
2976 | } | |
2977 | ||
2978 | } | |
2979 | break; | |
2980 | case OPT_PERIOD_GET: | |
2981 | { | |
2982 | epoch_t epoch = 0; | |
2983 | if (!period_epoch.empty()) { | |
2984 | epoch = atoi(period_epoch.c_str()); | |
2985 | } | |
2986 | if (staging) { | |
2987 | RGWRealm realm(realm_id, realm_name); | |
2988 | int ret = realm.init(g_ceph_context, store); | |
2989 | if (ret < 0 ) { | |
2990 | cerr << "Error initializing realm " << cpp_strerror(-ret) << std::endl; | |
2991 | return -ret; | |
2992 | } | |
2993 | realm_id = realm.get_id(); | |
2994 | realm_name = realm.get_name(); | |
2995 | period_id = RGWPeriod::get_staging_id(realm_id); | |
2996 | epoch = 1; | |
2997 | } | |
2998 | RGWPeriod period(period_id, epoch); | |
2999 | int ret = period.init(g_ceph_context, store, realm_id, realm_name); | |
3000 | if (ret < 0) { | |
3001 | cerr << "period init failed: " << cpp_strerror(-ret) << std::endl; | |
3002 | return -ret; | |
3003 | } | |
3004 | encode_json("period", period, formatter); | |
3005 | formatter->flush(cout); | |
3006 | cout << std::endl; | |
3007 | } | |
3008 | break; | |
3009 | case OPT_PERIOD_GET_CURRENT: | |
3010 | { | |
3011 | int ret = read_current_period_id(store, realm_id, realm_name, &period_id); | |
3012 | if (ret < 0) { | |
3013 | return -ret; | |
3014 | } | |
3015 | formatter->open_object_section("period_get_current"); | |
3016 | encode_json("current_period", period_id, formatter); | |
3017 | formatter->close_section(); | |
3018 | formatter->flush(cout); | |
3019 | } | |
3020 | break; | |
3021 | case OPT_PERIOD_LIST: | |
3022 | { | |
3023 | list<string> periods; | |
3024 | int ret = store->list_periods(periods); | |
3025 | if (ret < 0) { | |
3026 | cerr << "failed to list periods: " << cpp_strerror(-ret) << std::endl; | |
3027 | return -ret; | |
3028 | } | |
3029 | formatter->open_object_section("periods_list"); | |
3030 | encode_json("periods", periods, formatter); | |
3031 | formatter->close_section(); | |
3032 | formatter->flush(cout); | |
3033 | cout << std::endl; | |
3034 | } | |
3035 | break; | |
3036 | case OPT_PERIOD_UPDATE: | |
3037 | { | |
3038 | int ret = update_period(realm_id, realm_name, period_id, period_epoch, | |
3039 | commit, remote, url, access_key, secret_key, | |
3040 | formatter, yes_i_really_mean_it); | |
3041 | if (ret < 0) { | |
3042 | return -ret; | |
3043 | } | |
3044 | } | |
3045 | break; | |
3046 | case OPT_PERIOD_PULL: | |
3047 | { | |
3048 | boost::optional<RGWRESTConn> conn; | |
3049 | RGWRESTConn *remote_conn = nullptr; | |
3050 | if (url.empty()) { | |
3051 | // load current period for endpoints | |
3052 | RGWRealm realm(realm_id, realm_name); | |
3053 | int ret = realm.init(g_ceph_context, store); | |
3054 | if (ret < 0) { | |
3055 | cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; | |
3056 | return -ret; | |
3057 | } | |
3058 | RGWPeriod current_period(realm.get_current_period()); | |
3059 | ret = current_period.init(g_ceph_context, store); | |
3060 | if (ret < 0) { | |
3061 | cerr << "failed to init current period: " << cpp_strerror(-ret) << std::endl; | |
3062 | return -ret; | |
3063 | } | |
3064 | if (remote.empty()) { | |
3065 | // use realm master zone as remote | |
3066 | remote = current_period.get_master_zone(); | |
3067 | } | |
3068 | conn = get_remote_conn(store, current_period.get_map(), remote); | |
3069 | if (!conn) { | |
3070 | cerr << "failed to find a zone or zonegroup for remote " | |
3071 | << remote << std::endl; | |
3072 | return -ENOENT; | |
3073 | } | |
3074 | remote_conn = &*conn; | |
3075 | } | |
3076 | ||
3077 | RGWPeriod period; | |
3078 | int ret = do_period_pull(remote_conn, url, access_key, secret_key, | |
3079 | realm_id, realm_name, period_id, period_epoch, | |
3080 | &period); | |
3081 | if (ret < 0) { | |
3082 | cerr << "period pull failed: " << cpp_strerror(-ret) << std::endl; | |
3083 | return -ret; | |
3084 | } | |
3085 | ||
3086 | encode_json("period", period, formatter); | |
3087 | formatter->flush(cout); | |
3088 | cout << std::endl; | |
3089 | } | |
3090 | break; | |
3091 | case OPT_GLOBAL_QUOTA_GET: | |
3092 | case OPT_GLOBAL_QUOTA_SET: | |
3093 | case OPT_GLOBAL_QUOTA_ENABLE: | |
3094 | case OPT_GLOBAL_QUOTA_DISABLE: | |
3095 | { | |
3096 | if (realm_id.empty()) { | |
3097 | RGWRealm realm(g_ceph_context, store); | |
3098 | if (!realm_name.empty()) { | |
3099 | // look up realm_id for the given realm_name | |
3100 | int ret = realm.read_id(realm_name, realm_id); | |
3101 | if (ret < 0) { | |
3102 | cerr << "ERROR: failed to read realm for " << realm_name | |
3103 | << ": " << cpp_strerror(-ret) << std::endl; | |
3104 | return -ret; | |
3105 | } | |
3106 | } else { | |
3107 | // use default realm_id when none is given | |
3108 | int ret = realm.read_default_id(realm_id); | |
3109 | if (ret < 0 && ret != -ENOENT) { // on ENOENT, use empty realm_id | |
3110 | cerr << "ERROR: failed to read default realm: " | |
3111 | << cpp_strerror(-ret) << std::endl; | |
3112 | return -ret; | |
3113 | } | |
3114 | } | |
3115 | } | |
3116 | ||
3117 | RGWPeriodConfig period_config; | |
3118 | int ret = period_config.read(store, realm_id); | |
3119 | if (ret < 0 && ret != -ENOENT) { | |
3120 | cerr << "ERROR: failed to read period config: " | |
3121 | << cpp_strerror(-ret) << std::endl; | |
3122 | return -ret; | |
3123 | } | |
3124 | ||
3125 | formatter->open_object_section("period_config"); | |
3126 | if (quota_scope == "bucket") { | |
3127 | set_quota_info(period_config.bucket_quota, opt_cmd, | |
3128 | max_size, max_objects, | |
3129 | have_max_size, have_max_objects); | |
3130 | encode_json("bucket quota", period_config.bucket_quota, formatter); | |
3131 | } else if (quota_scope == "user") { | |
3132 | set_quota_info(period_config.user_quota, opt_cmd, | |
3133 | max_size, max_objects, | |
3134 | have_max_size, have_max_objects); | |
3135 | encode_json("user quota", period_config.user_quota, formatter); | |
3136 | } else if (quota_scope.empty() && opt_cmd == OPT_GLOBAL_QUOTA_GET) { | |
3137 | // if no scope is given for GET, print both | |
3138 | encode_json("bucket quota", period_config.bucket_quota, formatter); | |
3139 | encode_json("user quota", period_config.user_quota, formatter); | |
3140 | } else { | |
3141 | cerr << "ERROR: invalid quota scope specification. Please specify " | |
3142 | "either --quota-scope=bucket, or --quota-scope=user" << std::endl; | |
3143 | return EINVAL; | |
3144 | } | |
3145 | formatter->close_section(); | |
3146 | ||
3147 | if (opt_cmd != OPT_GLOBAL_QUOTA_GET) { | |
3148 | // write the modified period config | |
3149 | ret = period_config.write(store, realm_id); | |
3150 | if (ret < 0) { | |
3151 | cerr << "ERROR: failed to write period config: " | |
3152 | << cpp_strerror(-ret) << std::endl; | |
3153 | return -ret; | |
3154 | } | |
3155 | if (!realm_id.empty()) { | |
3156 | cout << "Global quota changes saved. Use 'period update' to apply " | |
3157 | "them to the staging period, and 'period commit' to commit the " | |
3158 | "new period." << std::endl; | |
3159 | } else { | |
3160 | cout << "Global quota changes saved. They will take effect as " | |
3161 | "the gateways are restarted." << std::endl; | |
3162 | } | |
3163 | } | |
3164 | ||
3165 | formatter->flush(cout); | |
3166 | cout << std::endl; | |
3167 | } | |
3168 | break; | |
3169 | case OPT_REALM_CREATE: | |
3170 | { | |
3171 | if (realm_name.empty()) { | |
3172 | cerr << "missing realm name" << std::endl; | |
3173 | return EINVAL; | |
3174 | } | |
3175 | ||
3176 | RGWRealm realm(realm_name, g_ceph_context, store); | |
3177 | int ret = realm.create(); | |
3178 | if (ret < 0) { | |
3179 | cerr << "ERROR: couldn't create realm " << realm_name << ": " << cpp_strerror(-ret) << std::endl; | |
3180 | return -ret; | |
3181 | } | |
3182 | ||
3183 | if (set_default) { | |
3184 | ret = realm.set_as_default(); | |
3185 | if (ret < 0) { | |
3186 | cerr << "failed to set realm " << realm_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
3187 | } | |
3188 | } | |
3189 | ||
3190 | encode_json("realm", realm, formatter); | |
3191 | formatter->flush(cout); | |
3192 | cout << std::endl; | |
3193 | } | |
3194 | break; | |
3195 | case OPT_REALM_DELETE: | |
3196 | { | |
3197 | RGWRealm realm(realm_id, realm_name); | |
3198 | if (realm_name.empty() && realm_id.empty()) { | |
3199 | cerr << "missing realm name or id" << std::endl; | |
3200 | return EINVAL; | |
3201 | } | |
3202 | int ret = realm.init(g_ceph_context, store); | |
3203 | if (ret < 0) { | |
3204 | cerr << "realm.init failed: " << cpp_strerror(-ret) << std::endl; | |
3205 | return -ret; | |
3206 | } | |
3207 | ret = realm.delete_obj(); | |
3208 | if (ret < 0) { | |
3209 | cerr << "ERROR: couldn't : " << cpp_strerror(-ret) << std::endl; | |
3210 | return -ret; | |
3211 | } | |
3212 | ||
3213 | } | |
3214 | break; | |
3215 | case OPT_REALM_GET: | |
3216 | { | |
3217 | RGWRealm realm(realm_id, realm_name); | |
3218 | int ret = realm.init(g_ceph_context, store); | |
3219 | if (ret < 0) { | |
3220 | if (ret == -ENOENT && realm_name.empty() && realm_id.empty()) { | |
3221 | cerr << "missing realm name or id, or default realm not found" << std::endl; | |
3222 | } else { | |
3223 | cerr << "realm.init failed: " << cpp_strerror(-ret) << std::endl; | |
3224 | } | |
3225 | return -ret; | |
3226 | } | |
3227 | encode_json("realm", realm, formatter); | |
3228 | formatter->flush(cout); | |
3229 | cout << std::endl; | |
3230 | } | |
3231 | break; | |
3232 | case OPT_REALM_GET_DEFAULT: | |
3233 | { | |
3234 | RGWRealm realm(g_ceph_context, store); | |
3235 | string default_id; | |
3236 | int ret = realm.read_default_id(default_id); | |
3237 | if (ret == -ENOENT) { | |
3238 | cout << "No default realm is set" << std::endl; | |
3239 | return -ret; | |
3240 | } else if (ret < 0) { | |
3241 | cerr << "Error reading default realm:" << cpp_strerror(-ret) << std::endl; | |
3242 | return -ret; | |
3243 | } | |
3244 | cout << "default realm: " << default_id << std::endl; | |
3245 | } | |
3246 | break; | |
3247 | case OPT_REALM_LIST: | |
3248 | { | |
3249 | RGWRealm realm(g_ceph_context, store); | |
3250 | string default_id; | |
3251 | int ret = realm.read_default_id(default_id); | |
3252 | if (ret < 0 && ret != -ENOENT) { | |
3253 | cerr << "could not determine default realm: " << cpp_strerror(-ret) << std::endl; | |
3254 | } | |
3255 | list<string> realms; | |
3256 | ret = store->list_realms(realms); | |
3257 | if (ret < 0) { | |
3258 | cerr << "failed to list realms: " << cpp_strerror(-ret) << std::endl; | |
3259 | return -ret; | |
3260 | } | |
3261 | formatter->open_object_section("realms_list"); | |
3262 | encode_json("default_info", default_id, formatter); | |
3263 | encode_json("realms", realms, formatter); | |
3264 | formatter->close_section(); | |
3265 | formatter->flush(cout); | |
3266 | cout << std::endl; | |
3267 | } | |
3268 | break; | |
3269 | case OPT_REALM_LIST_PERIODS: | |
3270 | { | |
3271 | int ret = read_current_period_id(store, realm_id, realm_name, &period_id); | |
3272 | if (ret < 0) { | |
3273 | return -ret; | |
3274 | } | |
3275 | list<string> periods; | |
3276 | ret = store->list_periods(period_id, periods); | |
3277 | if (ret < 0) { | |
3278 | cerr << "list periods failed: " << cpp_strerror(-ret) << std::endl; | |
3279 | return -ret; | |
3280 | } | |
3281 | formatter->open_object_section("realm_periods_list"); | |
3282 | encode_json("current_period", period_id, formatter); | |
3283 | encode_json("periods", periods, formatter); | |
3284 | formatter->close_section(); | |
3285 | formatter->flush(cout); | |
3286 | cout << std::endl; | |
3287 | } | |
3288 | break; | |
3289 | ||
3290 | case OPT_REALM_RENAME: | |
3291 | { | |
3292 | RGWRealm realm(realm_id, realm_name); | |
3293 | if (realm_new_name.empty()) { | |
3294 | cerr << "missing realm new name" << std::endl; | |
3295 | return EINVAL; | |
3296 | } | |
3297 | if (realm_name.empty() && realm_id.empty()) { | |
3298 | cerr << "missing realm name or id" << std::endl; | |
3299 | return EINVAL; | |
3300 | } | |
3301 | int ret = realm.init(g_ceph_context, store); | |
3302 | if (ret < 0) { | |
3303 | cerr << "realm.init failed: " << cpp_strerror(-ret) << std::endl; | |
3304 | return -ret; | |
3305 | } | |
3306 | ret = realm.rename(realm_new_name); | |
3307 | if (ret < 0) { | |
3308 | cerr << "realm.rename failed: " << cpp_strerror(-ret) << std::endl; | |
3309 | return -ret; | |
3310 | } | |
3311 | cout << "Realm name updated. Note that this change only applies to " | |
3312 | "the current cluster, so this command must be run separately " | |
3313 | "on each of the realm's other clusters." << std::endl; | |
3314 | } | |
3315 | break; | |
3316 | case OPT_REALM_SET: | |
3317 | { | |
3318 | if (realm_id.empty() && realm_name.empty()) { | |
3319 | cerr << "no realm name or id provided" << std::endl; | |
3320 | return EINVAL; | |
3321 | } | |
3322 | RGWRealm realm(realm_id, realm_name); | |
3323 | bool new_realm = false; | |
3324 | int ret = realm.init(g_ceph_context, store); | |
3325 | if (ret < 0 && ret != -ENOENT) { | |
3326 | cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; | |
3327 | return -ret; | |
3328 | } else if (ret == -ENOENT) { | |
3329 | new_realm = true; | |
3330 | } | |
3331 | ret = read_decode_json(infile, realm); | |
3332 | if (ret < 0) { | |
3333 | return 1; | |
3334 | } | |
3335 | if (!realm_name.empty() && realm.get_name() != realm_name) { | |
3336 | cerr << "mismatch between --rgw-realm " << realm_name << " and json input file name " << | |
3337 | realm.get_name() << std::endl; | |
3338 | return EINVAL; | |
3339 | } | |
3340 | /* new realm */ | |
3341 | if (new_realm) { | |
3342 | cout << "clearing period and epoch for new realm" << std::endl; | |
3343 | realm.clear_current_period_and_epoch(); | |
3344 | ret = realm.create(); | |
3345 | if (ret < 0) { | |
3346 | cerr << "ERROR: couldn't create new realm: " << cpp_strerror(-ret) << std::endl; | |
3347 | return 1; | |
3348 | } | |
3349 | } else { | |
3350 | ret = realm.update(); | |
3351 | if (ret < 0) { | |
3352 | cerr << "ERROR: couldn't store realm info: " << cpp_strerror(-ret) << std::endl; | |
3353 | return 1; | |
3354 | } | |
3355 | } | |
3356 | ||
3357 | if (set_default) { | |
3358 | ret = realm.set_as_default(); | |
3359 | if (ret < 0) { | |
3360 | cerr << "failed to set realm " << realm_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
3361 | } | |
3362 | } | |
3363 | encode_json("realm", realm, formatter); | |
3364 | formatter->flush(cout); | |
3365 | } | |
3366 | break; | |
3367 | ||
3368 | case OPT_REALM_DEFAULT: | |
3369 | { | |
3370 | RGWRealm realm(realm_id, realm_name); | |
3371 | int ret = realm.init(g_ceph_context, store); | |
3372 | if (ret < 0) { | |
3373 | cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; | |
3374 | return -ret; | |
3375 | } | |
3376 | ret = realm.set_as_default(); | |
3377 | if (ret < 0) { | |
3378 | cerr << "failed to set realm as default: " << cpp_strerror(-ret) << std::endl; | |
3379 | return -ret; | |
3380 | } | |
3381 | } | |
3382 | break; | |
3383 | case OPT_REALM_PULL: | |
3384 | { | |
3385 | if (url.empty()) { | |
3386 | cerr << "A --url must be provided." << std::endl; | |
3387 | return EINVAL; | |
3388 | } | |
3389 | RGWEnv env; | |
3390 | req_info info(g_ceph_context, &env); | |
3391 | info.method = "GET"; | |
3392 | info.request_uri = "/admin/realm"; | |
3393 | ||
3394 | map<string, string> ¶ms = info.args.get_params(); | |
3395 | if (!realm_id.empty()) | |
3396 | params["id"] = realm_id; | |
3397 | if (!realm_name.empty()) | |
3398 | params["name"] = realm_name; | |
3399 | ||
3400 | bufferlist bl; | |
3401 | JSONParser p; | |
3402 | int ret = send_to_url(url, access_key, secret_key, info, bl, p); | |
3403 | if (ret < 0) { | |
3404 | cerr << "request failed: " << cpp_strerror(-ret) << std::endl; | |
3405 | if (ret == -EACCES) { | |
3406 | cerr << "If the realm has been changed on the master zone, the " | |
3407 | "master zone's gateway may need to be restarted to recognize " | |
3408 | "this user." << std::endl; | |
3409 | } | |
3410 | return -ret; | |
3411 | } | |
3412 | RGWRealm realm; | |
3413 | realm.init(g_ceph_context, store, false); | |
3414 | try { | |
3415 | decode_json_obj(realm, &p); | |
3416 | } catch (JSONDecoder::err& e) { | |
3417 | cerr << "failed to decode JSON response: " << e.message << std::endl; | |
3418 | return EINVAL; | |
3419 | } | |
3420 | RGWPeriod period; | |
3421 | auto& current_period = realm.get_current_period(); | |
3422 | if (!current_period.empty()) { | |
3423 | // pull the latest epoch of the realm's current period | |
3424 | ret = do_period_pull(nullptr, url, access_key, secret_key, | |
3425 | realm_id, realm_name, current_period, "", | |
3426 | &period); | |
3427 | if (ret < 0) { | |
3428 | cerr << "could not fetch period " << current_period << std::endl; | |
3429 | return -ret; | |
3430 | } | |
3431 | } | |
3432 | ret = realm.create(false); | |
3433 | if (ret < 0 && ret != -EEXIST) { | |
3434 | cerr << "Error storing realm " << realm.get_id() << ": " | |
3435 | << cpp_strerror(ret) << std::endl; | |
3436 | return -ret; | |
3437 | } else if (ret ==-EEXIST) { | |
3438 | ret = realm.update(); | |
3439 | if (ret < 0) { | |
3440 | cerr << "Error storing realm " << realm.get_id() << ": " | |
3441 | << cpp_strerror(ret) << std::endl; | |
3442 | } | |
3443 | } | |
3444 | ||
3445 | if (set_default) { | |
3446 | ret = realm.set_as_default(); | |
3447 | if (ret < 0) { | |
3448 | cerr << "failed to set realm " << realm_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
3449 | } | |
3450 | } | |
3451 | ||
3452 | encode_json("realm", realm, formatter); | |
3453 | formatter->flush(cout); | |
3454 | cout << std::endl; | |
3455 | } | |
3456 | return 0; | |
3457 | ||
3458 | case OPT_ZONEGROUP_ADD: | |
3459 | { | |
3460 | if (zonegroup_id.empty() && zonegroup_name.empty()) { | |
3461 | cerr << "no zonegroup name or id provided" << std::endl; | |
3462 | return EINVAL; | |
3463 | } | |
3464 | ||
3465 | RGWZoneGroup zonegroup(zonegroup_id,zonegroup_name); | |
3466 | int ret = zonegroup.init(g_ceph_context, store); | |
3467 | if (ret < 0) { | |
3468 | cerr << "failed to initialize zonegroup " << zonegroup_name << " id " << zonegroup_id << " :" | |
3469 | << cpp_strerror(-ret) << std::endl; | |
3470 | return -ret; | |
3471 | } | |
3472 | RGWZoneParams zone(zone_id, zone_name); | |
3473 | ret = zone.init(g_ceph_context, store); | |
3474 | if (ret < 0) { | |
3475 | cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; | |
3476 | return -ret; | |
3477 | } | |
224ce89b WB |
3478 | if (zone.realm_id != zonegroup.realm_id) { |
3479 | zone.realm_id = zonegroup.realm_id; | |
3480 | ret = zone.update(); | |
3481 | if (ret < 0) { | |
3482 | cerr << "failed to save zone info: " << cpp_strerror(-ret) << std::endl; | |
3483 | return -ret; | |
3484 | } | |
3485 | } | |
3486 | ||
7c673cae FG |
3487 | string *ptier_type = (tier_type_specified ? &tier_type : nullptr); |
3488 | zone.tier_config = tier_config_add; | |
3489 | ||
3490 | bool *psync_from_all = (sync_from_all_specified ? &sync_from_all : nullptr); | |
3491 | ||
3492 | ret = zonegroup.add_zone(zone, | |
3493 | (is_master_set ? &is_master : NULL), | |
3494 | (is_read_only_set ? &read_only : NULL), | |
3495 | endpoints, ptier_type, | |
3496 | psync_from_all, sync_from, sync_from_rm); | |
3497 | if (ret < 0) { | |
3498 | cerr << "failed to add zone " << zone_name << " to zonegroup " << zonegroup.get_name() << ": " | |
3499 | << cpp_strerror(-ret) << std::endl; | |
3500 | return -ret; | |
3501 | } | |
3502 | ||
3503 | encode_json("zonegroup", zonegroup, formatter); | |
3504 | formatter->flush(cout); | |
3505 | } | |
3506 | break; | |
3507 | case OPT_ZONEGROUP_CREATE: | |
3508 | { | |
3509 | if (zonegroup_name.empty()) { | |
3510 | cerr << "Missing zonegroup name" << std::endl; | |
3511 | return EINVAL; | |
3512 | } | |
3513 | RGWRealm realm(realm_id, realm_name); | |
3514 | int ret = realm.init(g_ceph_context, store); | |
3515 | if (ret < 0) { | |
3516 | cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; | |
3517 | return -ret; | |
3518 | } | |
3519 | ||
3520 | RGWZoneGroup zonegroup(zonegroup_name, is_master, g_ceph_context, store, realm.get_id(), endpoints); | |
3521 | zonegroup.api_name = (api_name.empty() ? zonegroup_name : api_name); | |
3522 | ret = zonegroup.create(); | |
3523 | if (ret < 0) { | |
3524 | cerr << "failed to create zonegroup " << zonegroup_name << ": " << cpp_strerror(-ret) << std::endl; | |
3525 | return -ret; | |
3526 | } | |
3527 | ||
3528 | if (set_default) { | |
3529 | ret = zonegroup.set_as_default(); | |
3530 | if (ret < 0) { | |
3531 | cerr << "failed to set zonegroup " << zonegroup_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
3532 | } | |
3533 | } | |
3534 | ||
3535 | encode_json("zonegroup", zonegroup, formatter); | |
3536 | formatter->flush(cout); | |
3537 | cout << std::endl; | |
3538 | } | |
3539 | break; | |
3540 | case OPT_ZONEGROUP_DEFAULT: | |
3541 | { | |
3542 | if (zonegroup_id.empty() && zonegroup_name.empty()) { | |
3543 | cerr << "no zonegroup name or id provided" << std::endl; | |
3544 | return EINVAL; | |
3545 | } | |
3546 | ||
3547 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3548 | int ret = zonegroup.init(g_ceph_context, store); | |
3549 | if (ret < 0) { | |
3550 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3551 | return -ret; | |
3552 | } | |
3553 | ||
3554 | ret = zonegroup.set_as_default(); | |
3555 | if (ret < 0) { | |
3556 | cerr << "failed to set zonegroup as default: " << cpp_strerror(-ret) << std::endl; | |
3557 | return -ret; | |
3558 | } | |
3559 | } | |
3560 | break; | |
3561 | case OPT_ZONEGROUP_DELETE: | |
3562 | { | |
3563 | if (zonegroup_id.empty() && zonegroup_name.empty()) { | |
3564 | cerr << "no zonegroup name or id provided" << std::endl; | |
3565 | return EINVAL; | |
3566 | } | |
3567 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3568 | int ret = zonegroup.init(g_ceph_context, store); | |
3569 | if (ret < 0) { | |
3570 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3571 | return -ret; | |
3572 | } | |
3573 | ret = zonegroup.delete_obj(); | |
3574 | if (ret < 0) { | |
3575 | cerr << "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3576 | return -ret; | |
3577 | } | |
3578 | } | |
3579 | break; | |
3580 | case OPT_ZONEGROUP_GET: | |
3581 | { | |
3582 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3583 | int ret = zonegroup.init(g_ceph_context, store); | |
3584 | if (ret < 0) { | |
3585 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3586 | return -ret; | |
3587 | } | |
3588 | ||
3589 | encode_json("zonegroup", zonegroup, formatter); | |
3590 | formatter->flush(cout); | |
3591 | cout << std::endl; | |
3592 | } | |
3593 | break; | |
3594 | case OPT_ZONEGROUP_LIST: | |
3595 | { | |
3596 | RGWZoneGroup zonegroup; | |
3597 | int ret = zonegroup.init(g_ceph_context, store, false); | |
3598 | if (ret < 0) { | |
3599 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3600 | return -ret; | |
3601 | } | |
3602 | ||
3603 | list<string> zonegroups; | |
3604 | ret = store->list_zonegroups(zonegroups); | |
3605 | if (ret < 0) { | |
3606 | cerr << "failed to list zonegroups: " << cpp_strerror(-ret) << std::endl; | |
3607 | return -ret; | |
3608 | } | |
3609 | string default_zonegroup; | |
3610 | ret = zonegroup.read_default_id(default_zonegroup); | |
7c673cae FG |
3611 | if (ret < 0 && ret != -ENOENT) { |
3612 | cerr << "could not determine default zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3613 | } | |
3614 | formatter->open_object_section("zonegroups_list"); | |
3615 | encode_json("default_info", default_zonegroup, formatter); | |
3616 | encode_json("zonegroups", zonegroups, formatter); | |
3617 | formatter->close_section(); | |
3618 | formatter->flush(cout); | |
3619 | cout << std::endl; | |
3620 | } | |
3621 | break; | |
3622 | case OPT_ZONEGROUP_MODIFY: | |
3623 | { | |
3624 | RGWRealm realm(realm_id, realm_name); | |
3625 | int ret = realm.init(g_ceph_context, store); | |
3626 | if (ret < 0) { | |
3627 | cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; | |
3628 | return -ret; | |
3629 | } | |
3630 | ||
3631 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3632 | ret = zonegroup.init(g_ceph_context, store); | |
3633 | if (ret < 0) { | |
3634 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3635 | return -ret; | |
3636 | } | |
3637 | ||
3638 | bool need_update = false; | |
3639 | ||
3640 | if (!master_zone.empty()) { | |
3641 | zonegroup.master_zone = master_zone; | |
3642 | need_update = true; | |
3643 | } | |
3644 | ||
3645 | if (is_master_set) { | |
3646 | zonegroup.update_master(is_master); | |
3647 | need_update = true; | |
3648 | } | |
3649 | ||
3650 | if (!endpoints.empty()) { | |
3651 | zonegroup.endpoints = endpoints; | |
3652 | need_update = true; | |
3653 | } | |
3654 | ||
3655 | if (!api_name.empty()) { | |
3656 | zonegroup.api_name = api_name; | |
3657 | need_update = true; | |
3658 | } | |
3659 | ||
3660 | if (!realm_id.empty()) { | |
3661 | zonegroup.realm_id = realm_id; | |
3662 | need_update = true; | |
3663 | } else if (!realm_name.empty()) { | |
3664 | // get realm id from name | |
3665 | RGWRealm realm{g_ceph_context, store}; | |
3666 | ret = realm.read_id(realm_name, zonegroup.realm_id); | |
3667 | if (ret < 0) { | |
3668 | cerr << "failed to find realm by name " << realm_name << std::endl; | |
3669 | return -ret; | |
3670 | } | |
3671 | need_update = true; | |
3672 | } | |
3673 | ||
3674 | if (need_update) { | |
3675 | ret = zonegroup.update(); | |
3676 | if (ret < 0) { | |
3677 | cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3678 | return -ret; | |
3679 | } | |
3680 | } | |
3681 | ||
3682 | if (set_default) { | |
3683 | ret = zonegroup.set_as_default(); | |
3684 | if (ret < 0) { | |
3685 | cerr << "failed to set zonegroup " << zonegroup_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
3686 | } | |
3687 | } | |
3688 | ||
3689 | encode_json("zonegroup", zonegroup, formatter); | |
3690 | formatter->flush(cout); | |
3691 | } | |
3692 | break; | |
3693 | case OPT_ZONEGROUP_SET: | |
3694 | { | |
3695 | RGWRealm realm(realm_id, realm_name); | |
3696 | int ret = realm.init(g_ceph_context, store); | |
3697 | if (ret < 0) { | |
3698 | cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; | |
3699 | return -ret; | |
3700 | } | |
3701 | ||
3702 | RGWZoneGroup zonegroup; | |
3703 | ret = zonegroup.init(g_ceph_context, store, false); | |
3704 | if (ret < 0) { | |
3705 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3706 | return -ret; | |
3707 | } | |
3708 | ret = read_decode_json(infile, zonegroup); | |
3709 | if (ret < 0) { | |
3710 | return 1; | |
3711 | } | |
3712 | if (zonegroup.realm_id.empty()) { | |
3713 | zonegroup.realm_id = realm.get_id(); | |
3714 | } | |
3715 | ret = zonegroup.create(); | |
3716 | if (ret < 0 && ret != -EEXIST) { | |
3717 | cerr << "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret) << std::endl; | |
3718 | return 1; | |
3719 | } else if (ret == -EEXIST) { | |
3720 | ret = zonegroup.update(); | |
3721 | if (ret < 0) { | |
3722 | cerr << "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret) << std::endl; | |
3723 | return 1; | |
3724 | } | |
3725 | } | |
3726 | ||
3727 | if (set_default) { | |
3728 | ret = zonegroup.set_as_default(); | |
3729 | if (ret < 0) { | |
3730 | cerr << "failed to set zonegroup " << zonegroup_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
3731 | } | |
3732 | } | |
3733 | ||
3734 | encode_json("zonegroup", zonegroup, formatter); | |
3735 | formatter->flush(cout); | |
3736 | } | |
3737 | break; | |
3738 | case OPT_ZONEGROUP_REMOVE: | |
3739 | { | |
3740 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3741 | int ret = zonegroup.init(g_ceph_context, store); | |
3742 | if (ret < 0) { | |
3743 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3744 | return -ret; | |
3745 | } | |
3746 | ||
3747 | if (zone_id.empty()) { | |
3748 | if (zone_name.empty()) { | |
3749 | cerr << "no --zone-id or --rgw-zone name provided" << std::endl; | |
3750 | return EINVAL; | |
3751 | } | |
3752 | // look up zone id by name | |
3753 | for (auto& z : zonegroup.zones) { | |
3754 | if (zone_name == z.second.name) { | |
3755 | zone_id = z.second.id; | |
3756 | break; | |
3757 | } | |
3758 | } | |
3759 | if (zone_id.empty()) { | |
3760 | cerr << "zone name " << zone_name << " not found in zonegroup " | |
3761 | << zonegroup.get_name() << std::endl; | |
3762 | return ENOENT; | |
3763 | } | |
3764 | } | |
3765 | ||
3766 | ret = zonegroup.remove_zone(zone_id); | |
3767 | if (ret < 0) { | |
3768 | cerr << "failed to remove zone: " << cpp_strerror(-ret) << std::endl; | |
3769 | return -ret; | |
3770 | } | |
3771 | ||
3772 | encode_json("zonegroup", zonegroup, formatter); | |
3773 | formatter->flush(cout); | |
3774 | } | |
3775 | break; | |
3776 | case OPT_ZONEGROUP_RENAME: | |
3777 | { | |
3778 | if (zonegroup_new_name.empty()) { | |
3779 | cerr << " missing zonegroup new name" << std::endl; | |
3780 | return EINVAL; | |
3781 | } | |
3782 | if (zonegroup_id.empty() && zonegroup_name.empty()) { | |
3783 | cerr << "no zonegroup name or id provided" << std::endl; | |
3784 | return EINVAL; | |
3785 | } | |
3786 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3787 | int ret = zonegroup.init(g_ceph_context, store); | |
3788 | if (ret < 0) { | |
3789 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3790 | return -ret; | |
3791 | } | |
3792 | ret = zonegroup.rename(zonegroup_new_name); | |
3793 | if (ret < 0) { | |
3794 | cerr << "failed to rename zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3795 | return -ret; | |
3796 | } | |
3797 | } | |
3798 | break; | |
3799 | case OPT_ZONEGROUP_PLACEMENT_LIST: | |
3800 | { | |
3801 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3802 | int ret = zonegroup.init(g_ceph_context, store); | |
3803 | if (ret < 0) { | |
3804 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3805 | return -ret; | |
3806 | } | |
3807 | ||
3808 | encode_json("placement_targets", zonegroup.placement_targets, formatter); | |
3809 | formatter->flush(cout); | |
3810 | cout << std::endl; | |
3811 | } | |
3812 | break; | |
3813 | case OPT_ZONEGROUP_PLACEMENT_ADD: | |
3814 | case OPT_ZONEGROUP_PLACEMENT_MODIFY: | |
3815 | case OPT_ZONEGROUP_PLACEMENT_RM: | |
3816 | case OPT_ZONEGROUP_PLACEMENT_DEFAULT: | |
3817 | { | |
3818 | if (placement_id.empty()) { | |
3819 | cerr << "ERROR: --placement-id not specified" << std::endl; | |
3820 | return EINVAL; | |
3821 | } | |
3822 | ||
3823 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3824 | int ret = zonegroup.init(g_ceph_context, store); | |
3825 | if (ret < 0) { | |
3826 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3827 | return -ret; | |
3828 | } | |
3829 | ||
3830 | if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_ADD) { | |
3831 | RGWZoneGroupPlacementTarget target; | |
3832 | target.name = placement_id; | |
3833 | for (auto& t : tags) { | |
3834 | target.tags.insert(t); | |
3835 | } | |
3836 | zonegroup.placement_targets[placement_id] = target; | |
3837 | } else if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_MODIFY) { | |
3838 | RGWZoneGroupPlacementTarget& target = zonegroup.placement_targets[placement_id]; | |
3839 | if (!tags.empty()) { | |
3840 | target.tags.clear(); | |
3841 | for (auto& t : tags) { | |
3842 | target.tags.insert(t); | |
3843 | } | |
3844 | } | |
3845 | target.name = placement_id; | |
3846 | for (auto& t : tags_rm) { | |
3847 | target.tags.erase(t); | |
3848 | } | |
3849 | for (auto& t : tags_add) { | |
3850 | target.tags.insert(t); | |
3851 | } | |
3852 | } else if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_RM) { | |
3853 | zonegroup.placement_targets.erase(placement_id); | |
3854 | } else if (opt_cmd == OPT_ZONEGROUP_PLACEMENT_DEFAULT) { | |
3855 | if (!zonegroup.placement_targets.count(placement_id)) { | |
3856 | cerr << "failed to find a zonegroup placement target named '" | |
3857 | << placement_id << "'" << std::endl; | |
3858 | return -ENOENT; | |
3859 | } | |
3860 | zonegroup.default_placement = placement_id; | |
3861 | } | |
3862 | ||
3863 | zonegroup.post_process_params(); | |
3864 | ret = zonegroup.update(); | |
3865 | if (ret < 0) { | |
3866 | cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; | |
3867 | return -ret; | |
3868 | } | |
3869 | ||
3870 | encode_json("placement_targets", zonegroup.placement_targets, formatter); | |
3871 | formatter->flush(cout); | |
3872 | } | |
3873 | break; | |
3874 | case OPT_ZONE_CREATE: | |
3875 | { | |
3876 | if (zone_name.empty()) { | |
3877 | cerr << "zone name not provided" << std::endl; | |
3878 | return EINVAL; | |
3879 | } | |
3880 | int ret; | |
3881 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
3882 | /* if the user didn't provide zonegroup info , create stand alone zone */ | |
3883 | if (!zonegroup_id.empty() || !zonegroup_name.empty()) { | |
3884 | ret = zonegroup.init(g_ceph_context, store); | |
3885 | if (ret < 0) { | |
3886 | cerr << "unable to initialize zonegroup " << zonegroup_name << ": " << cpp_strerror(-ret) << std::endl; | |
3887 | return -ret; | |
3888 | } | |
3889 | if (realm_id.empty() && realm_name.empty()) { | |
3890 | realm_id = zonegroup.realm_id; | |
3891 | } | |
3892 | } | |
3893 | ||
3894 | RGWZoneParams zone(zone_id, zone_name); | |
3895 | ret = zone.init(g_ceph_context, store, false); | |
3896 | if (ret < 0) { | |
3897 | cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; | |
3898 | return -ret; | |
3899 | } | |
3900 | ||
3901 | zone.system_key.id = access_key; | |
3902 | zone.system_key.key = secret_key; | |
3903 | zone.realm_id = realm_id; | |
31f18b77 | 3904 | zone.tier_config = tier_config_add; |
7c673cae FG |
3905 | |
3906 | ret = zone.create(); | |
3907 | if (ret < 0) { | |
3908 | cerr << "failed to create zone " << zone_name << ": " << cpp_strerror(-ret) << std::endl; | |
3909 | return -ret; | |
3910 | } | |
3911 | ||
3912 | if (!zonegroup_id.empty() || !zonegroup_name.empty()) { | |
3913 | string *ptier_type = (tier_type_specified ? &tier_type : nullptr); | |
3914 | bool *psync_from_all = (sync_from_all_specified ? &sync_from_all : nullptr); | |
3915 | ret = zonegroup.add_zone(zone, | |
3916 | (is_master_set ? &is_master : NULL), | |
3917 | (is_read_only_set ? &read_only : NULL), | |
3918 | endpoints, | |
3919 | ptier_type, | |
3920 | psync_from_all, | |
3921 | sync_from, sync_from_rm); | |
3922 | if (ret < 0) { | |
3923 | cerr << "failed to add zone " << zone_name << " to zonegroup " << zonegroup.get_name() | |
3924 | << ": " << cpp_strerror(-ret) << std::endl; | |
3925 | return -ret; | |
3926 | } | |
3927 | } | |
3928 | ||
3929 | if (set_default) { | |
3930 | ret = zone.set_as_default(); | |
3931 | if (ret < 0) { | |
3932 | cerr << "failed to set zone " << zone_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
3933 | } | |
3934 | } | |
3935 | ||
3936 | encode_json("zone", zone, formatter); | |
3937 | formatter->flush(cout); | |
3938 | cout << std::endl; | |
3939 | } | |
3940 | break; | |
3941 | case OPT_ZONE_DEFAULT: | |
3942 | { | |
3943 | RGWZoneGroup zonegroup(zonegroup_id,zonegroup_name); | |
3944 | int ret = zonegroup.init(g_ceph_context, store); | |
3945 | if (ret < 0) { | |
3946 | cerr << "WARNING: failed to initialize zonegroup " << zonegroup_name << std::endl; | |
3947 | } | |
3948 | if (zone_id.empty() && zone_name.empty()) { | |
3949 | cerr << "no zone name or id provided" << std::endl; | |
3950 | return EINVAL; | |
3951 | } | |
3952 | RGWZoneParams zone(zone_id, zone_name); | |
3953 | ret = zone.init(g_ceph_context, store); | |
3954 | if (ret < 0) { | |
3955 | cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; | |
3956 | return -ret; | |
3957 | } | |
3958 | ret = zone.set_as_default(); | |
3959 | if (ret < 0) { | |
3960 | cerr << "failed to set zone as default: " << cpp_strerror(-ret) << std::endl; | |
3961 | return -ret; | |
3962 | } | |
3963 | } | |
3964 | break; | |
3965 | case OPT_ZONE_DELETE: | |
3966 | { | |
3967 | if (zone_id.empty() && zone_name.empty()) { | |
3968 | cerr << "no zone name or id provided" << std::endl; | |
3969 | return EINVAL; | |
3970 | } | |
3971 | RGWZoneParams zone(zone_id, zone_name); | |
3972 | int ret = zone.init(g_ceph_context, store); | |
3973 | if (ret < 0) { | |
3974 | cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; | |
3975 | return -ret; | |
3976 | } | |
3977 | ||
3978 | list<string> zonegroups; | |
3979 | ret = store->list_zonegroups(zonegroups); | |
3980 | if (ret < 0) { | |
3981 | cerr << "failed to list zonegroups: " << cpp_strerror(-ret) << std::endl; | |
3982 | return -ret; | |
3983 | } | |
3984 | ||
3985 | for (list<string>::iterator iter = zonegroups.begin(); iter != zonegroups.end(); ++iter) { | |
3986 | RGWZoneGroup zonegroup(string(), *iter); | |
3987 | int ret = zonegroup.init(g_ceph_context, store); | |
3988 | if (ret < 0) { | |
3989 | cerr << "WARNING: failed to initialize zonegroup " << zonegroup_name << std::endl; | |
3990 | continue; | |
3991 | } | |
3992 | ret = zonegroup.remove_zone(zone.get_id()); | |
3993 | if (ret < 0 && ret != -ENOENT) { | |
3994 | cerr << "failed to remove zone " << zone_name << " from zonegroup " << zonegroup.get_name() << ": " | |
3995 | << cpp_strerror(-ret) << std::endl; | |
3996 | } | |
3997 | } | |
3998 | ||
3999 | ret = zone.delete_obj(); | |
4000 | if (ret < 0) { | |
4001 | cerr << "failed to delete zone " << zone_name << ": " << cpp_strerror(-ret) << std::endl; | |
4002 | return -ret; | |
4003 | } | |
4004 | } | |
4005 | break; | |
4006 | case OPT_ZONE_GET: | |
4007 | { | |
4008 | RGWZoneParams zone(zone_id, zone_name); | |
4009 | int ret = zone.init(g_ceph_context, store); | |
4010 | if (ret < 0) { | |
4011 | cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; | |
4012 | return -ret; | |
4013 | } | |
4014 | encode_json("zone", zone, formatter); | |
4015 | formatter->flush(cout); | |
4016 | } | |
4017 | break; | |
4018 | case OPT_ZONE_SET: | |
4019 | { | |
4020 | RGWZoneParams zone(zone_name); | |
4021 | int ret = zone.init(g_ceph_context, store, false); | |
4022 | if (ret < 0) { | |
4023 | return -ret; | |
4024 | } | |
4025 | ||
4026 | ret = zone.read(); | |
4027 | if (ret < 0 && ret != -ENOENT) { | |
4028 | cerr << "zone.read() returned ret=" << ret << std::endl; | |
4029 | return -ret; | |
4030 | } | |
4031 | ||
4032 | string orig_id = zone.get_id(); | |
4033 | ||
4034 | ret = read_decode_json(infile, zone); | |
4035 | if (ret < 0) { | |
4036 | return 1; | |
4037 | } | |
4038 | ||
4039 | if(zone.realm_id.empty()) { | |
4040 | RGWRealm realm(realm_id, realm_name); | |
4041 | int ret = realm.init(g_ceph_context, store); | |
4042 | if (ret < 0 && ret != -ENOENT) { | |
4043 | cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; | |
4044 | return -ret; | |
4045 | } | |
4046 | zone.realm_id = realm.get_id(); | |
4047 | } | |
4048 | ||
4049 | if( !zone_name.empty() && !zone.get_name().empty() && zone.get_name() != zone_name) { | |
4050 | cerr << "Error: zone name" << zone_name << " is different than the zone name " << zone.get_name() << " in the provided json " << std::endl; | |
4051 | return EINVAL; | |
4052 | } | |
4053 | ||
4054 | if (zone.get_name().empty()) { | |
4055 | zone.set_name(zone_name); | |
4056 | if (zone.get_name().empty()) { | |
4057 | cerr << "no zone name specified" << std::endl; | |
4058 | return EINVAL; | |
4059 | } | |
4060 | } | |
4061 | ||
4062 | zone_name = zone.get_name(); | |
4063 | ||
4064 | if (zone.get_id().empty()) { | |
4065 | zone.set_id(orig_id); | |
4066 | } | |
4067 | ||
4068 | if (zone.get_id().empty()) { | |
4069 | cerr << "no zone name id the json provided, assuming old format" << std::endl; | |
4070 | if (zone_name.empty()) { | |
4071 | cerr << "missing zone name" << std::endl; | |
4072 | return EINVAL; | |
4073 | } | |
4074 | zone.set_name(zone_name); | |
4075 | zone.set_id(zone_name); | |
4076 | } | |
4077 | ||
4078 | cerr << "zone id " << zone.get_id(); | |
4079 | ret = zone.fix_pool_names(); | |
4080 | if (ret < 0) { | |
4081 | cerr << "ERROR: couldn't fix zone: " << cpp_strerror(-ret) << std::endl; | |
4082 | return -ret; | |
4083 | } | |
4084 | ret = zone.write(false); | |
4085 | if (ret < 0) { | |
4086 | cerr << "ERROR: couldn't create zone: " << cpp_strerror(-ret) << std::endl; | |
4087 | return 1; | |
4088 | } | |
4089 | ||
4090 | if (set_default) { | |
4091 | ret = zone.set_as_default(); | |
4092 | if (ret < 0) { | |
4093 | cerr << "failed to set zone " << zone_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
4094 | } | |
4095 | } | |
4096 | ||
4097 | encode_json("zone", zone, formatter); | |
4098 | formatter->flush(cout); | |
4099 | } | |
4100 | break; | |
4101 | case OPT_ZONE_LIST: | |
4102 | { | |
4103 | list<string> zones; | |
4104 | int ret = store->list_zones(zones); | |
4105 | if (ret < 0) { | |
4106 | cerr << "failed to list zones: " << cpp_strerror(-ret) << std::endl; | |
4107 | return -ret; | |
4108 | } | |
4109 | ||
4110 | RGWZoneParams zone; | |
4111 | ret = zone.init(g_ceph_context, store, false); | |
4112 | if (ret < 0) { | |
4113 | cerr << "failed to init zone: " << cpp_strerror(-ret) << std::endl; | |
4114 | return -ret; | |
4115 | } | |
4116 | string default_zone; | |
4117 | ret = zone.read_default_id(default_zone); | |
4118 | if (ret < 0 && ret != -ENOENT) { | |
4119 | cerr << "could not determine default zone: " << cpp_strerror(-ret) << std::endl; | |
4120 | } | |
4121 | formatter->open_object_section("zones_list"); | |
4122 | encode_json("default_info", default_zone, formatter); | |
4123 | encode_json("zones", zones, formatter); | |
4124 | formatter->close_section(); | |
4125 | formatter->flush(cout); | |
4126 | cout << std::endl; | |
4127 | } | |
4128 | break; | |
4129 | case OPT_ZONE_MODIFY: | |
4130 | { | |
4131 | RGWZoneParams zone(zone_id, zone_name); | |
4132 | int ret = zone.init(g_ceph_context, store); | |
4133 | if (ret < 0) { | |
4134 | cerr << "failed to init zone: " << cpp_strerror(-ret) << std::endl; | |
4135 | return -ret; | |
4136 | } | |
4137 | ||
4138 | bool need_zone_update = false; | |
4139 | if (!access_key.empty()) { | |
4140 | zone.system_key.id = access_key; | |
4141 | need_zone_update = true; | |
4142 | } | |
4143 | ||
4144 | if (!secret_key.empty()) { | |
4145 | zone.system_key.key = secret_key; | |
4146 | need_zone_update = true; | |
4147 | } | |
4148 | ||
4149 | if (!realm_id.empty()) { | |
4150 | zone.realm_id = realm_id; | |
4151 | need_zone_update = true; | |
4152 | } else if (!realm_name.empty()) { | |
4153 | // get realm id from name | |
4154 | RGWRealm realm{g_ceph_context, store}; | |
4155 | ret = realm.read_id(realm_name, zone.realm_id); | |
4156 | if (ret < 0) { | |
4157 | cerr << "failed to find realm by name " << realm_name << std::endl; | |
4158 | return -ret; | |
4159 | } | |
4160 | need_zone_update = true; | |
4161 | } | |
4162 | ||
4163 | for (auto add : tier_config_add) { | |
4164 | zone.tier_config[add.first] = add.second; | |
4165 | need_zone_update = true; | |
4166 | } | |
4167 | ||
4168 | for (auto rm : tier_config_rm) { | |
4169 | zone.tier_config.erase(rm.first); | |
4170 | need_zone_update = true; | |
4171 | } | |
4172 | ||
4173 | if (need_zone_update) { | |
4174 | ret = zone.update(); | |
4175 | if (ret < 0) { | |
4176 | cerr << "failed to save zone info: " << cpp_strerror(-ret) << std::endl; | |
4177 | return -ret; | |
4178 | } | |
4179 | } | |
4180 | ||
4181 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
4182 | ret = zonegroup.init(g_ceph_context, store); | |
4183 | if (ret < 0) { | |
4184 | cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; | |
4185 | return -ret; | |
4186 | } | |
4187 | string *ptier_type = (tier_type_specified ? &tier_type : nullptr); | |
4188 | ||
4189 | bool *psync_from_all = (sync_from_all_specified ? &sync_from_all : nullptr); | |
4190 | ||
4191 | ret = zonegroup.add_zone(zone, | |
4192 | (is_master_set ? &is_master : NULL), | |
4193 | (is_read_only_set ? &read_only : NULL), | |
4194 | endpoints, ptier_type, | |
4195 | psync_from_all, sync_from, sync_from_rm); | |
4196 | if (ret < 0) { | |
4197 | cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; | |
4198 | return -ret; | |
4199 | } | |
4200 | ||
4201 | ret = zonegroup.update(); | |
4202 | if (ret < 0) { | |
4203 | cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; | |
4204 | return -ret; | |
4205 | } | |
4206 | ||
4207 | if (set_default) { | |
4208 | ret = zone.set_as_default(); | |
4209 | if (ret < 0) { | |
4210 | cerr << "failed to set zone " << zone_name << " as default: " << cpp_strerror(-ret) << std::endl; | |
4211 | } | |
4212 | } | |
4213 | ||
4214 | encode_json("zone", zone, formatter); | |
4215 | formatter->flush(cout); | |
4216 | } | |
4217 | break; | |
4218 | case OPT_ZONE_RENAME: | |
4219 | { | |
4220 | if (zone_new_name.empty()) { | |
4221 | cerr << " missing zone new name" << std::endl; | |
4222 | return EINVAL; | |
4223 | } | |
4224 | if (zone_id.empty() && zone_name.empty()) { | |
4225 | cerr << "no zonegroup name or id provided" << std::endl; | |
4226 | return EINVAL; | |
4227 | } | |
4228 | RGWZoneParams zone(zone_id,zone_name); | |
4229 | int ret = zone.init(g_ceph_context, store); | |
4230 | if (ret < 0) { | |
4231 | cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; | |
4232 | return -ret; | |
4233 | } | |
4234 | ret = zone.rename(zone_new_name); | |
4235 | if (ret < 0) { | |
4236 | cerr << "failed to rename zone " << zone_name << " to " << zone_new_name << ": " << cpp_strerror(-ret) | |
4237 | << std::endl; | |
4238 | return -ret; | |
4239 | } | |
4240 | RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); | |
4241 | ret = zonegroup.init(g_ceph_context, store); | |
4242 | if (ret < 0) { | |
4243 | cerr << "WARNING: failed to initialize zonegroup " << zonegroup_name << std::endl; | |
4244 | } else { | |
4245 | ret = zonegroup.rename_zone(zone); | |
4246 | if (ret < 0 && ret ) { | |
4247 | cerr << "Error in zonegroup rename for " << zone_name << ": " << cpp_strerror(-ret) << std::endl; | |
4248 | return -ret; | |
4249 | } | |
4250 | } | |
4251 | } | |
4252 | break; | |
4253 | case OPT_ZONE_PLACEMENT_ADD: | |
4254 | case OPT_ZONE_PLACEMENT_MODIFY: | |
4255 | case OPT_ZONE_PLACEMENT_RM: | |
4256 | { | |
4257 | if (placement_id.empty()) { | |
4258 | cerr << "ERROR: --placement-id not specified" << std::endl; | |
4259 | return EINVAL; | |
4260 | } | |
3efd9988 FG |
4261 | // validate compression type |
4262 | if (compression_type && *compression_type != "random" | |
4263 | && !Compressor::get_comp_alg_type(*compression_type)) { | |
4264 | std::cerr << "Unrecognized compression type" << std::endl; | |
4265 | return EINVAL; | |
4266 | } | |
4267 | ||
7c673cae FG |
4268 | RGWZoneParams zone(zone_id, zone_name); |
4269 | int ret = zone.init(g_ceph_context, store); | |
4270 | if (ret < 0) { | |
4271 | cerr << "failed to init zone: " << cpp_strerror(-ret) << std::endl; | |
4272 | return -ret; | |
4273 | } | |
4274 | ||
4275 | if (opt_cmd == OPT_ZONE_PLACEMENT_ADD) { | |
4276 | // pool names are required | |
4277 | if (!index_pool || index_pool->empty() || | |
4278 | !data_pool || data_pool->empty()) { | |
4279 | cerr << "ERROR: need to specify both --index-pool and --data-pool" << std::endl; | |
4280 | return EINVAL; | |
4281 | } | |
4282 | ||
4283 | RGWZonePlacementInfo& info = zone.placement_pools[placement_id]; | |
4284 | ||
4285 | info.index_pool = *index_pool; | |
4286 | info.data_pool = *data_pool; | |
4287 | if (data_extra_pool) { | |
4288 | info.data_extra_pool = *data_extra_pool; | |
4289 | } | |
4290 | if (index_type_specified) { | |
4291 | info.index_type = placement_index_type; | |
4292 | } | |
4293 | if (compression_type) { | |
4294 | info.compression_type = *compression_type; | |
4295 | } | |
4296 | } else if (opt_cmd == OPT_ZONE_PLACEMENT_MODIFY) { | |
4297 | auto p = zone.placement_pools.find(placement_id); | |
4298 | if (p == zone.placement_pools.end()) { | |
4299 | cerr << "ERROR: zone placement target '" << placement_id | |
4300 | << "' not found" << std::endl; | |
4301 | return -ENOENT; | |
4302 | } | |
4303 | auto& info = p->second; | |
4304 | if (index_pool && !index_pool->empty()) { | |
4305 | info.index_pool = *index_pool; | |
4306 | } | |
4307 | if (data_pool && !data_pool->empty()) { | |
4308 | info.data_pool = *data_pool; | |
4309 | } | |
4310 | if (data_extra_pool) { | |
4311 | info.data_extra_pool = *data_extra_pool; | |
4312 | } | |
4313 | if (index_type_specified) { | |
4314 | info.index_type = placement_index_type; | |
4315 | } | |
4316 | if (compression_type) { | |
4317 | info.compression_type = *compression_type; | |
4318 | } | |
4319 | } else if (opt_cmd == OPT_ZONE_PLACEMENT_RM) { | |
4320 | zone.placement_pools.erase(placement_id); | |
4321 | } | |
4322 | ||
4323 | ret = zone.update(); | |
4324 | if (ret < 0) { | |
4325 | cerr << "failed to save zone info: " << cpp_strerror(-ret) << std::endl; | |
4326 | return -ret; | |
4327 | } | |
4328 | ||
4329 | encode_json("zone", zone, formatter); | |
4330 | formatter->flush(cout); | |
4331 | } | |
4332 | break; | |
4333 | case OPT_ZONE_PLACEMENT_LIST: | |
4334 | { | |
4335 | RGWZoneParams zone(zone_id, zone_name); | |
4336 | int ret = zone.init(g_ceph_context, store); | |
4337 | if (ret < 0) { | |
4338 | cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; | |
4339 | return -ret; | |
4340 | } | |
4341 | encode_json("placement_pools", zone.placement_pools, formatter); | |
4342 | formatter->flush(cout); | |
4343 | } | |
4344 | break; | |
4345 | } | |
4346 | return 0; | |
4347 | } | |
4348 | ||
4349 | if (!user_id.empty()) { | |
4350 | user_op.set_user_id(user_id); | |
4351 | bucket_op.set_user_id(user_id); | |
4352 | } | |
4353 | ||
4354 | if (!display_name.empty()) | |
4355 | user_op.set_display_name(display_name); | |
4356 | ||
4357 | if (!user_email.empty()) | |
4358 | user_op.set_user_email(user_email); | |
4359 | ||
4360 | if (!access_key.empty()) | |
4361 | user_op.set_access_key(access_key); | |
4362 | ||
4363 | if (!secret_key.empty()) | |
4364 | user_op.set_secret_key(secret_key); | |
4365 | ||
4366 | if (!subuser.empty()) | |
4367 | user_op.set_subuser(subuser); | |
4368 | ||
4369 | if (!caps.empty()) | |
4370 | user_op.set_caps(caps); | |
4371 | ||
4372 | user_op.set_purge_data(purge_data); | |
4373 | ||
4374 | if (purge_keys) | |
4375 | user_op.set_purge_keys(); | |
4376 | ||
4377 | if (gen_access_key) | |
4378 | user_op.set_generate_key(); | |
4379 | ||
4380 | if (gen_secret_key) | |
4381 | user_op.set_gen_secret(); // assume that a key pair should be created | |
4382 | ||
4383 | if (max_buckets_specified) | |
4384 | user_op.set_max_buckets(max_buckets); | |
4385 | ||
4386 | if (admin_specified) | |
4387 | user_op.set_admin(admin); | |
4388 | ||
4389 | if (system_specified) | |
4390 | user_op.set_system(system); | |
4391 | ||
4392 | if (set_perm) | |
4393 | user_op.set_perm(perm_mask); | |
4394 | ||
4395 | if (set_temp_url_key) { | |
4396 | map<int, string>::iterator iter = temp_url_keys.begin(); | |
4397 | for (; iter != temp_url_keys.end(); ++iter) { | |
4398 | user_op.set_temp_url_key(iter->second, iter->first); | |
4399 | } | |
4400 | } | |
4401 | ||
4402 | if (!op_mask_str.empty()) { | |
4403 | uint32_t op_mask; | |
4404 | int ret = rgw_parse_op_type_list(op_mask_str, &op_mask); | |
4405 | if (ret < 0) { | |
4406 | cerr << "failed to parse op_mask: " << cpp_strerror(-ret) << std::endl; | |
4407 | return -ret; | |
4408 | } | |
4409 | ||
4410 | user_op.set_op_mask(op_mask); | |
4411 | } | |
4412 | ||
4413 | if (key_type != KEY_TYPE_UNDEFINED) | |
4414 | user_op.set_key_type(key_type); | |
4415 | ||
4416 | // set suspension operation parameters | |
4417 | if (opt_cmd == OPT_USER_ENABLE) | |
4418 | user_op.set_suspension(false); | |
4419 | else if (opt_cmd == OPT_USER_SUSPEND) | |
4420 | user_op.set_suspension(true); | |
4421 | ||
4422 | // RGWUser to use for user operations | |
4423 | RGWUser user; | |
4424 | int ret = 0; | |
4425 | if (!user_id.empty() || !subuser.empty()) { | |
4426 | ret = user.init(store, user_op); | |
4427 | if (ret < 0) { | |
4428 | cerr << "user.init failed: " << cpp_strerror(-ret) << std::endl; | |
4429 | return -ret; | |
4430 | } | |
4431 | } | |
4432 | ||
4433 | /* populate bucket operation */ | |
4434 | bucket_op.set_bucket_name(bucket_name); | |
4435 | bucket_op.set_object(object); | |
4436 | bucket_op.set_check_objects(check_objects); | |
4437 | bucket_op.set_delete_children(delete_child_objects); | |
4438 | bucket_op.set_fix_index(fix); | |
4439 | bucket_op.set_max_aio(max_concurrent_ios); | |
4440 | ||
4441 | // required to gather errors from operations | |
4442 | std::string err_msg; | |
4443 | ||
4444 | bool output_user_info = true; | |
4445 | ||
4446 | switch (opt_cmd) { | |
4447 | case OPT_USER_INFO: | |
4448 | break; | |
4449 | case OPT_USER_CREATE: | |
4450 | if (!user_op.has_existing_user()) { | |
4451 | user_op.set_generate_key(); // generate a new key by default | |
4452 | } | |
4453 | ret = user.add(user_op, &err_msg); | |
4454 | if (ret < 0) { | |
4455 | cerr << "could not create user: " << err_msg << std::endl; | |
d2e6a577 FG |
4456 | if (ret == -ERR_INVALID_TENANT_NAME) |
4457 | ret = -EINVAL; | |
4458 | ||
7c673cae FG |
4459 | return -ret; |
4460 | } | |
4461 | if (!subuser.empty()) { | |
4462 | ret = user.subusers.add(user_op, &err_msg); | |
4463 | if (ret < 0) { | |
4464 | cerr << "could not create subuser: " << err_msg << std::endl; | |
4465 | return -ret; | |
4466 | } | |
4467 | } | |
4468 | break; | |
4469 | case OPT_USER_RM: | |
4470 | ret = user.remove(user_op, &err_msg); | |
31f18b77 | 4471 | if (ret < 0) { |
7c673cae FG |
4472 | cerr << "could not remove user: " << err_msg << std::endl; |
4473 | return -ret; | |
4474 | } | |
4475 | ||
4476 | output_user_info = false; | |
4477 | break; | |
4478 | case OPT_USER_ENABLE: | |
4479 | case OPT_USER_SUSPEND: | |
4480 | case OPT_USER_MODIFY: | |
4481 | ret = user.modify(user_op, &err_msg); | |
4482 | if (ret < 0) { | |
4483 | cerr << "could not modify user: " << err_msg << std::endl; | |
4484 | return -ret; | |
4485 | } | |
4486 | ||
4487 | break; | |
4488 | case OPT_SUBUSER_CREATE: | |
4489 | ret = user.subusers.add(user_op, &err_msg); | |
4490 | if (ret < 0) { | |
4491 | cerr << "could not create subuser: " << err_msg << std::endl; | |
4492 | return -ret; | |
4493 | } | |
4494 | ||
4495 | break; | |
4496 | case OPT_SUBUSER_MODIFY: | |
4497 | ret = user.subusers.modify(user_op, &err_msg); | |
4498 | if (ret < 0) { | |
4499 | cerr << "could not modify subuser: " << err_msg << std::endl; | |
4500 | return -ret; | |
4501 | } | |
4502 | ||
4503 | break; | |
4504 | case OPT_SUBUSER_RM: | |
4505 | ret = user.subusers.remove(user_op, &err_msg); | |
4506 | if (ret < 0) { | |
4507 | cerr << "could not remove subuser: " << err_msg << std::endl; | |
4508 | return -ret; | |
4509 | } | |
4510 | ||
4511 | break; | |
4512 | case OPT_CAPS_ADD: | |
4513 | ret = user.caps.add(user_op, &err_msg); | |
4514 | if (ret < 0) { | |
4515 | cerr << "could not add caps: " << err_msg << std::endl; | |
4516 | return -ret; | |
4517 | } | |
4518 | ||
4519 | break; | |
4520 | case OPT_CAPS_RM: | |
4521 | ret = user.caps.remove(user_op, &err_msg); | |
4522 | if (ret < 0) { | |
4523 | cerr << "could not remove caps: " << err_msg << std::endl; | |
4524 | return -ret; | |
4525 | } | |
4526 | ||
4527 | break; | |
4528 | case OPT_KEY_CREATE: | |
4529 | ret = user.keys.add(user_op, &err_msg); | |
4530 | if (ret < 0) { | |
4531 | cerr << "could not create key: " << err_msg << std::endl; | |
4532 | return -ret; | |
4533 | } | |
4534 | ||
4535 | break; | |
4536 | case OPT_KEY_RM: | |
4537 | ret = user.keys.remove(user_op, &err_msg); | |
4538 | if (ret < 0) { | |
4539 | cerr << "could not remove key: " << err_msg << std::endl; | |
4540 | return -ret; | |
4541 | } | |
4542 | break; | |
4543 | case OPT_PERIOD_PUSH: | |
4544 | { | |
4545 | RGWEnv env; | |
4546 | req_info info(g_ceph_context, &env); | |
4547 | info.method = "POST"; | |
4548 | info.request_uri = "/admin/realm/period"; | |
4549 | ||
4550 | map<string, string> ¶ms = info.args.get_params(); | |
4551 | if (!realm_id.empty()) | |
4552 | params["realm_id"] = realm_id; | |
4553 | if (!realm_name.empty()) | |
4554 | params["realm_name"] = realm_name; | |
4555 | if (!period_id.empty()) | |
4556 | params["period_id"] = period_id; | |
4557 | if (!period_epoch.empty()) | |
4558 | params["epoch"] = period_epoch; | |
4559 | ||
4560 | // load the period | |
4561 | RGWPeriod period(period_id); | |
4562 | int ret = period.init(g_ceph_context, store); | |
4563 | if (ret < 0) { | |
4564 | cerr << "period init failed: " << cpp_strerror(-ret) << std::endl; | |
4565 | return -ret; | |
4566 | } | |
4567 | // json format into a bufferlist | |
4568 | JSONFormatter jf(false); | |
4569 | encode_json("period", period, &jf); | |
4570 | bufferlist bl; | |
4571 | jf.flush(bl); | |
4572 | ||
4573 | JSONParser p; | |
4574 | ret = send_to_remote_or_url(nullptr, url, access_key, secret_key, | |
4575 | info, bl, p); | |
4576 | if (ret < 0) { | |
4577 | cerr << "request failed: " << cpp_strerror(-ret) << std::endl; | |
4578 | return -ret; | |
4579 | } | |
4580 | } | |
4581 | return 0; | |
4582 | case OPT_PERIOD_UPDATE: | |
4583 | { | |
4584 | int ret = update_period(realm_id, realm_name, period_id, period_epoch, | |
4585 | commit, remote, url, access_key, secret_key, | |
4586 | formatter, yes_i_really_mean_it); | |
4587 | if (ret < 0) { | |
4588 | return -ret; | |
4589 | } | |
4590 | } | |
4591 | return 0; | |
4592 | case OPT_PERIOD_COMMIT: | |
4593 | { | |
4594 | // read realm and staging period | |
4595 | RGWRealm realm(realm_id, realm_name); | |
4596 | int ret = realm.init(g_ceph_context, store); | |
4597 | if (ret < 0) { | |
4598 | cerr << "Error initializing realm: " << cpp_strerror(-ret) << std::endl; | |
4599 | return -ret; | |
4600 | } | |
4601 | RGWPeriod period(RGWPeriod::get_staging_id(realm.get_id()), 1); | |
4602 | ret = period.init(g_ceph_context, store, realm.get_id()); | |
4603 | if (ret < 0) { | |
4604 | cerr << "period init failed: " << cpp_strerror(-ret) << std::endl; | |
4605 | return -ret; | |
4606 | } | |
4607 | ret = commit_period(realm, period, remote, url, access_key, secret_key, | |
4608 | yes_i_really_mean_it); | |
4609 | if (ret < 0) { | |
4610 | cerr << "failed to commit period: " << cpp_strerror(-ret) << std::endl; | |
4611 | return -ret; | |
4612 | } | |
4613 | ||
4614 | encode_json("period", period, formatter); | |
4615 | formatter->flush(cout); | |
4616 | cout << std::endl; | |
4617 | } | |
4618 | return 0; | |
4619 | case OPT_ROLE_CREATE: | |
4620 | { | |
31f18b77 FG |
4621 | if (role_name.empty()) { |
4622 | cerr << "ERROR: role name is empty" << std::endl; | |
4623 | return -EINVAL; | |
4624 | } | |
4625 | ||
4626 | if (assume_role_doc.empty()) { | |
4627 | cerr << "ERROR: assume role policy document is empty" << std::endl; | |
7c673cae FG |
4628 | return -EINVAL; |
4629 | } | |
4630 | /* The following two calls will be replaced by read_decode_json or something | |
4631 | similar when the code for AWS Policies is in places */ | |
4632 | bufferlist bl; | |
4633 | int ret = read_input(assume_role_doc, bl); | |
4634 | if (ret < 0) { | |
4635 | cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl; | |
4636 | return ret; | |
4637 | } | |
4638 | JSONParser p; | |
4639 | if (!p.parse(bl.c_str(), bl.length())) { | |
4640 | cout << "ERROR: failed to parse JSON: " << assume_role_doc << std::endl; | |
4641 | return -EINVAL; | |
4642 | } | |
4643 | string trust_policy = bl.to_str(); | |
31f18b77 | 4644 | RGWRole role(g_ceph_context, store, role_name, path, trust_policy, tenant); |
7c673cae FG |
4645 | ret = role.create(true); |
4646 | if (ret < 0) { | |
4647 | return -ret; | |
4648 | } | |
4649 | show_role_info(role, formatter); | |
4650 | return 0; | |
4651 | } | |
4652 | case OPT_ROLE_DELETE: | |
4653 | { | |
4654 | if (role_name.empty()) { | |
4655 | cerr << "ERROR: empty role name" << std::endl; | |
4656 | return -EINVAL; | |
4657 | } | |
31f18b77 | 4658 | RGWRole role(g_ceph_context, store, role_name, tenant); |
7c673cae FG |
4659 | ret = role.delete_obj(); |
4660 | if (ret < 0) { | |
4661 | return -ret; | |
4662 | } | |
4663 | cout << "role: " << role_name << " successfully deleted" << std::endl; | |
4664 | return 0; | |
4665 | } | |
4666 | case OPT_ROLE_GET: | |
4667 | { | |
4668 | if (role_name.empty()) { | |
4669 | cerr << "ERROR: empty role name" << std::endl; | |
4670 | return -EINVAL; | |
4671 | } | |
31f18b77 | 4672 | RGWRole role(g_ceph_context, store, role_name, tenant); |
7c673cae FG |
4673 | ret = role.get(); |
4674 | if (ret < 0) { | |
4675 | return -ret; | |
4676 | } | |
4677 | show_role_info(role, formatter); | |
4678 | return 0; | |
4679 | } | |
4680 | case OPT_ROLE_MODIFY: | |
4681 | { | |
31f18b77 FG |
4682 | if (role_name.empty()) { |
4683 | cerr << "ERROR: role name is empty" << std::endl; | |
7c673cae FG |
4684 | return -EINVAL; |
4685 | } | |
31f18b77 FG |
4686 | |
4687 | if (assume_role_doc.empty()) { | |
4688 | cerr << "ERROR: assume role policy document is empty" << std::endl; | |
4689 | return -EINVAL; | |
4690 | } | |
4691 | ||
7c673cae FG |
4692 | /* The following two calls will be replaced by read_decode_json or something |
4693 | similar when the code for AWS Policies is in place */ | |
4694 | bufferlist bl; | |
4695 | int ret = read_input(assume_role_doc, bl); | |
4696 | if (ret < 0) { | |
4697 | cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl; | |
4698 | return ret; | |
4699 | } | |
4700 | JSONParser p; | |
4701 | if (!p.parse(bl.c_str(), bl.length())) { | |
4702 | cout << "ERROR: failed to parse JSON: " << assume_role_doc << std::endl; | |
4703 | return -EINVAL; | |
4704 | } | |
4705 | string trust_policy = bl.to_str(); | |
31f18b77 | 4706 | RGWRole role(g_ceph_context, store, role_name, tenant); |
7c673cae FG |
4707 | ret = role.get(); |
4708 | if (ret < 0) { | |
4709 | return -ret; | |
4710 | } | |
4711 | role.update_trust_policy(trust_policy); | |
4712 | ret = role.update(); | |
4713 | if (ret < 0) { | |
4714 | return -ret; | |
4715 | } | |
4716 | cout << "Assume role policy document updated successfully for role: " << role_name << std::endl; | |
4717 | return 0; | |
4718 | } | |
4719 | case OPT_ROLE_LIST: | |
4720 | { | |
4721 | vector<RGWRole> result; | |
31f18b77 | 4722 | ret = RGWRole::get_roles_by_path_prefix(store, g_ceph_context, path_prefix, tenant, result); |
7c673cae FG |
4723 | if (ret < 0) { |
4724 | return -ret; | |
4725 | } | |
4726 | show_roles_info(result, formatter); | |
4727 | return 0; | |
4728 | } | |
4729 | case OPT_ROLE_POLICY_PUT: | |
4730 | { | |
31f18b77 FG |
4731 | if (role_name.empty()) { |
4732 | cerr << "role name is empty" << std::endl; | |
7c673cae FG |
4733 | return -EINVAL; |
4734 | } | |
31f18b77 FG |
4735 | |
4736 | if (policy_name.empty()) { | |
4737 | cerr << "policy name is empty" << std::endl; | |
4738 | return -EINVAL; | |
4739 | } | |
4740 | ||
4741 | if (perm_policy_doc.empty()) { | |
4742 | cerr << "permission policy document is empty" << std::endl; | |
4743 | return -EINVAL; | |
4744 | } | |
4745 | ||
7c673cae FG |
4746 | /* The following two calls will be replaced by read_decode_json or something |
4747 | similar, when code for AWS Policies is in place.*/ | |
4748 | bufferlist bl; | |
4749 | int ret = read_input(perm_policy_doc, bl); | |
4750 | if (ret < 0) { | |
4751 | cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl; | |
4752 | return ret; | |
4753 | } | |
4754 | JSONParser p; | |
4755 | if (!p.parse(bl.c_str(), bl.length())) { | |
4756 | cout << "ERROR: failed to parse JSON: " << std::endl; | |
4757 | return -EINVAL; | |
4758 | } | |
4759 | string perm_policy; | |
4760 | perm_policy = bl.c_str(); | |
4761 | ||
31f18b77 | 4762 | RGWRole role(g_ceph_context, store, role_name, tenant); |
7c673cae FG |
4763 | ret = role.get(); |
4764 | if (ret < 0) { | |
4765 | return -ret; | |
4766 | } | |
4767 | role.set_perm_policy(policy_name, perm_policy); | |
4768 | ret = role.update(); | |
4769 | if (ret < 0) { | |
4770 | return -ret; | |
4771 | } | |
4772 | cout << "Permission policy attached successfully" << std::endl; | |
4773 | return 0; | |
4774 | } | |
4775 | case OPT_ROLE_POLICY_LIST: | |
4776 | { | |
4777 | if (role_name.empty()) { | |
4778 | cerr << "ERROR: Role name is empty" << std::endl; | |
4779 | return -EINVAL; | |
4780 | } | |
31f18b77 | 4781 | RGWRole role(g_ceph_context, store, role_name, tenant); |
7c673cae FG |
4782 | ret = role.get(); |
4783 | if (ret < 0) { | |
4784 | return -ret; | |
4785 | } | |
4786 | std::vector<string> policy_names = role.get_role_policy_names(); | |
4787 | show_policy_names(policy_names, formatter); | |
4788 | return 0; | |
4789 | } | |
4790 | case OPT_ROLE_POLICY_GET: | |
4791 | { | |
31f18b77 FG |
4792 | if (role_name.empty()) { |
4793 | cerr << "ERROR: role name is empty" << std::endl; | |
7c673cae FG |
4794 | return -EINVAL; |
4795 | } | |
31f18b77 FG |
4796 | |
4797 | if (policy_name.empty()) { | |
4798 | cerr << "ERROR: policy name is empty" << std::endl; | |
4799 | return -EINVAL; | |
4800 | } | |
4801 | RGWRole role(g_ceph_context, store, role_name, tenant); | |
7c673cae FG |
4802 | int ret = role.get(); |
4803 | if (ret < 0) { | |
4804 | return -ret; | |
4805 | } | |
4806 | string perm_policy; | |
4807 | ret = role.get_role_policy(policy_name, perm_policy); | |
4808 | if (ret < 0) { | |
4809 | return -ret; | |
4810 | } | |
4811 | show_perm_policy(perm_policy, formatter); | |
4812 | return 0; | |
4813 | } | |
4814 | case OPT_ROLE_POLICY_DELETE: | |
4815 | { | |
31f18b77 FG |
4816 | if (role_name.empty()) { |
4817 | cerr << "ERROR: role name is empty" << std::endl; | |
4818 | return -EINVAL; | |
4819 | } | |
4820 | ||
4821 | if (policy_name.empty()) { | |
4822 | cerr << "ERROR: policy name is empty" << std::endl; | |
7c673cae FG |
4823 | return -EINVAL; |
4824 | } | |
31f18b77 | 4825 | RGWRole role(g_ceph_context, store, role_name, tenant); |
7c673cae FG |
4826 | ret = role.get(); |
4827 | if (ret < 0) { | |
4828 | return -ret; | |
4829 | } | |
4830 | ret = role.delete_policy(policy_name); | |
4831 | if (ret < 0) { | |
4832 | return -ret; | |
4833 | } | |
4834 | ret = role.update(); | |
4835 | if (ret < 0) { | |
4836 | return -ret; | |
4837 | } | |
4838 | cout << "Policy: " << policy_name << " successfully deleted for role: " | |
4839 | << role_name << std::endl; | |
4840 | return 0; | |
4841 | } | |
4842 | default: | |
4843 | output_user_info = false; | |
4844 | } | |
4845 | ||
4846 | // output the result of a user operation | |
4847 | if (output_user_info) { | |
4848 | ret = user.info(info, &err_msg); | |
4849 | if (ret < 0) { | |
4850 | cerr << "could not fetch user info: " << err_msg << std::endl; | |
4851 | return -ret; | |
4852 | } | |
4853 | show_user_info(info, formatter); | |
4854 | } | |
4855 | ||
4856 | if (opt_cmd == OPT_POLICY) { | |
4857 | if (format == "xml") { | |
4858 | int ret = RGWBucketAdminOp::dump_s3_policy(store, bucket_op, cout); | |
4859 | if (ret < 0) { | |
4860 | cerr << "ERROR: failed to get policy: " << cpp_strerror(-ret) << std::endl; | |
4861 | return -ret; | |
4862 | } | |
4863 | } else { | |
4864 | int ret = RGWBucketAdminOp::get_policy(store, bucket_op, f); | |
4865 | if (ret < 0) { | |
4866 | cerr << "ERROR: failed to get policy: " << cpp_strerror(-ret) << std::endl; | |
4867 | return -ret; | |
4868 | } | |
4869 | } | |
4870 | } | |
4871 | ||
31f18b77 | 4872 | if (opt_cmd == OPT_BUCKET_LIMIT_CHECK) { |
7c673cae FG |
4873 | void *handle; |
4874 | std::list<std::string> user_ids; | |
4875 | metadata_key = "user"; | |
4876 | int max = 1000; | |
4877 | ||
4878 | bool truncated; | |
4879 | ||
4880 | if (! user_id.empty()) { | |
4881 | user_ids.push_back(user_id.id); | |
4882 | ret = | |
4883 | RGWBucketAdminOp::limit_check(store, bucket_op, user_ids, f, | |
4884 | warnings_only); | |
4885 | } else { | |
4886 | /* list users in groups of max-keys, then perform user-bucket | |
4887 | * limit-check on each group */ | |
4888 | ret = store->meta_mgr->list_keys_init(metadata_key, &handle); | |
4889 | if (ret < 0) { | |
4890 | cerr << "ERROR: buckets limit check can't get user metadata_key: " | |
4891 | << cpp_strerror(-ret) << std::endl; | |
4892 | return -ret; | |
4893 | } | |
4894 | ||
4895 | do { | |
4896 | ret = store->meta_mgr->list_keys_next(handle, max, user_ids, | |
4897 | &truncated); | |
4898 | if (ret < 0 && ret != -ENOENT) { | |
4899 | cerr << "ERROR: buckets limit check lists_keys_next(): " | |
4900 | << cpp_strerror(-ret) << std::endl; | |
4901 | break; | |
4902 | } else { | |
4903 | /* ok, do the limit checks for this group */ | |
4904 | ret = | |
4905 | RGWBucketAdminOp::limit_check(store, bucket_op, user_ids, f, | |
4906 | warnings_only); | |
4907 | if (ret < 0) | |
4908 | break; | |
4909 | } | |
4910 | user_ids.clear(); | |
4911 | } while (truncated); | |
4912 | store->meta_mgr->list_keys_complete(handle); | |
4913 | } | |
4914 | return -ret; | |
31f18b77 | 4915 | } /* OPT_BUCKET_LIMIT_CHECK */ |
7c673cae FG |
4916 | |
4917 | if (opt_cmd == OPT_BUCKETS_LIST) { | |
4918 | if (bucket_name.empty()) { | |
4919 | RGWBucketAdminOp::info(store, bucket_op, f); | |
4920 | } else { | |
4921 | RGWBucketInfo bucket_info; | |
4922 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
4923 | if (ret < 0) { | |
4924 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
4925 | return -ret; | |
4926 | } | |
4927 | formatter->open_array_section("entries"); | |
4928 | bool truncated; | |
4929 | int count = 0; | |
4930 | if (max_entries < 0) | |
4931 | max_entries = 1000; | |
4932 | ||
4933 | string prefix; | |
4934 | string delim; | |
4935 | vector<rgw_bucket_dir_entry> result; | |
4936 | map<string, bool> common_prefixes; | |
4937 | string ns; | |
4938 | ||
4939 | RGWRados::Bucket target(store, bucket_info); | |
4940 | RGWRados::Bucket::List list_op(&target); | |
4941 | ||
4942 | list_op.params.prefix = prefix; | |
4943 | list_op.params.delim = delim; | |
4944 | list_op.params.marker = rgw_obj_key(marker); | |
4945 | list_op.params.ns = ns; | |
4946 | list_op.params.enforce_ns = false; | |
4947 | list_op.params.list_versions = true; | |
4948 | ||
4949 | do { | |
4950 | ret = list_op.list_objects(max_entries - count, &result, &common_prefixes, &truncated); | |
4951 | if (ret < 0) { | |
4952 | cerr << "ERROR: store->list_objects(): " << cpp_strerror(-ret) << std::endl; | |
4953 | return -ret; | |
4954 | } | |
4955 | ||
4956 | count += result.size(); | |
4957 | ||
4958 | for (vector<rgw_bucket_dir_entry>::iterator iter = result.begin(); iter != result.end(); ++iter) { | |
4959 | rgw_bucket_dir_entry& entry = *iter; | |
4960 | encode_json("entry", entry, formatter); | |
4961 | } | |
4962 | formatter->flush(cout); | |
4963 | } while (truncated && count < max_entries); | |
4964 | ||
4965 | formatter->close_section(); | |
4966 | formatter->flush(cout); | |
4967 | } /* have bucket_name */ | |
4968 | } /* OPT_BUCKETS_LIST */ | |
4969 | ||
4970 | if (opt_cmd == OPT_BUCKET_STATS) { | |
4971 | bucket_op.set_fetch_stats(true); | |
4972 | ||
31f18b77 FG |
4973 | int r = RGWBucketAdminOp::info(store, bucket_op, f); |
4974 | if (r < 0) { | |
4975 | cerr << "failure: " << cpp_strerror(-r) << ": " << err << std::endl; | |
4976 | return -r; | |
4977 | } | |
7c673cae FG |
4978 | } |
4979 | ||
4980 | if (opt_cmd == OPT_BUCKET_LINK) { | |
4981 | bucket_op.set_bucket_id(bucket_id); | |
4982 | string err; | |
4983 | int r = RGWBucketAdminOp::link(store, bucket_op, &err); | |
4984 | if (r < 0) { | |
4985 | cerr << "failure: " << cpp_strerror(-r) << ": " << err << std::endl; | |
4986 | return -r; | |
4987 | } | |
4988 | } | |
4989 | ||
4990 | if (opt_cmd == OPT_BUCKET_UNLINK) { | |
4991 | int r = RGWBucketAdminOp::unlink(store, bucket_op); | |
4992 | if (r < 0) { | |
4993 | cerr << "failure: " << cpp_strerror(-r) << std::endl; | |
4994 | return -r; | |
4995 | } | |
4996 | } | |
4997 | ||
4998 | if (opt_cmd == OPT_LOG_LIST) { | |
4999 | // filter by date? | |
5000 | if (date.size() && date.size() != 10) { | |
5001 | cerr << "bad date format for '" << date << "', expect YYYY-MM-DD" << std::endl; | |
5002 | return EINVAL; | |
5003 | } | |
5004 | ||
5005 | formatter->reset(); | |
5006 | formatter->open_array_section("logs"); | |
5007 | RGWAccessHandle h; | |
5008 | int r = store->log_list_init(date, &h); | |
5009 | if (r == -ENOENT) { | |
5010 | // no logs. | |
5011 | } else { | |
5012 | if (r < 0) { | |
5013 | cerr << "log list: error " << r << std::endl; | |
5014 | return -r; | |
5015 | } | |
5016 | while (true) { | |
5017 | string name; | |
5018 | int r = store->log_list_next(h, &name); | |
5019 | if (r == -ENOENT) | |
5020 | break; | |
5021 | if (r < 0) { | |
5022 | cerr << "log list: error " << r << std::endl; | |
5023 | return -r; | |
5024 | } | |
5025 | formatter->dump_string("object", name); | |
5026 | } | |
5027 | } | |
5028 | formatter->close_section(); | |
5029 | formatter->flush(cout); | |
5030 | cout << std::endl; | |
5031 | } | |
5032 | ||
5033 | if (opt_cmd == OPT_LOG_SHOW || opt_cmd == OPT_LOG_RM) { | |
5034 | if (object.empty() && (date.empty() || bucket_name.empty() || bucket_id.empty())) { | |
5035 | cerr << "specify an object or a date, bucket and bucket-id" << std::endl; | |
d2e6a577 FG |
5036 | usage(); |
5037 | assert(false); | |
7c673cae FG |
5038 | } |
5039 | ||
5040 | string oid; | |
5041 | if (!object.empty()) { | |
5042 | oid = object; | |
5043 | } else { | |
5044 | oid = date; | |
5045 | oid += "-"; | |
5046 | oid += bucket_id; | |
5047 | oid += "-"; | |
5048 | oid += bucket_name; | |
5049 | } | |
5050 | ||
5051 | if (opt_cmd == OPT_LOG_SHOW) { | |
5052 | RGWAccessHandle h; | |
5053 | ||
5054 | int r = store->log_show_init(oid, &h); | |
5055 | if (r < 0) { | |
5056 | cerr << "error opening log " << oid << ": " << cpp_strerror(-r) << std::endl; | |
5057 | return -r; | |
5058 | } | |
5059 | ||
5060 | formatter->reset(); | |
5061 | formatter->open_object_section("log"); | |
5062 | ||
5063 | struct rgw_log_entry entry; | |
5064 | ||
5065 | // peek at first entry to get bucket metadata | |
5066 | r = store->log_show_next(h, &entry); | |
5067 | if (r < 0) { | |
5068 | cerr << "error reading log " << oid << ": " << cpp_strerror(-r) << std::endl; | |
5069 | return -r; | |
5070 | } | |
5071 | formatter->dump_string("bucket_id", entry.bucket_id); | |
5072 | formatter->dump_string("bucket_owner", entry.bucket_owner.to_str()); | |
5073 | formatter->dump_string("bucket", entry.bucket); | |
5074 | ||
5075 | uint64_t agg_time = 0; | |
5076 | uint64_t agg_bytes_sent = 0; | |
5077 | uint64_t agg_bytes_received = 0; | |
5078 | uint64_t total_entries = 0; | |
5079 | ||
5080 | if (show_log_entries) | |
5081 | formatter->open_array_section("log_entries"); | |
5082 | ||
5083 | do { | |
5084 | uint64_t total_time = entry.total_time.sec() * 1000000LL + entry.total_time.usec(); | |
5085 | ||
5086 | agg_time += total_time; | |
5087 | agg_bytes_sent += entry.bytes_sent; | |
5088 | agg_bytes_received += entry.bytes_received; | |
5089 | total_entries++; | |
5090 | ||
5091 | if (skip_zero_entries && entry.bytes_sent == 0 && | |
5092 | entry.bytes_received == 0) | |
5093 | goto next; | |
5094 | ||
5095 | if (show_log_entries) { | |
5096 | ||
5097 | rgw_format_ops_log_entry(entry, formatter); | |
5098 | formatter->flush(cout); | |
5099 | } | |
5100 | next: | |
5101 | r = store->log_show_next(h, &entry); | |
5102 | } while (r > 0); | |
5103 | ||
5104 | if (r < 0) { | |
5105 | cerr << "error reading log " << oid << ": " << cpp_strerror(-r) << std::endl; | |
5106 | return -r; | |
5107 | } | |
5108 | if (show_log_entries) | |
5109 | formatter->close_section(); | |
5110 | ||
5111 | if (show_log_sum) { | |
5112 | formatter->open_object_section("log_sum"); | |
5113 | formatter->dump_int("bytes_sent", agg_bytes_sent); | |
5114 | formatter->dump_int("bytes_received", agg_bytes_received); | |
5115 | formatter->dump_int("total_time", agg_time); | |
5116 | formatter->dump_int("total_entries", total_entries); | |
5117 | formatter->close_section(); | |
5118 | } | |
5119 | formatter->close_section(); | |
5120 | formatter->flush(cout); | |
5121 | cout << std::endl; | |
5122 | } | |
5123 | if (opt_cmd == OPT_LOG_RM) { | |
5124 | int r = store->log_remove(oid); | |
5125 | if (r < 0) { | |
5126 | cerr << "error removing log " << oid << ": " << cpp_strerror(-r) << std::endl; | |
5127 | return -r; | |
5128 | } | |
5129 | } | |
5130 | } | |
5131 | ||
5132 | if (opt_cmd == OPT_POOL_ADD) { | |
5133 | if (pool_name.empty()) { | |
5134 | cerr << "need to specify pool to add!" << std::endl; | |
d2e6a577 FG |
5135 | usage(); |
5136 | assert(false); | |
7c673cae FG |
5137 | } |
5138 | ||
5139 | int ret = store->add_bucket_placement(pool); | |
5140 | if (ret < 0) | |
5141 | cerr << "failed to add bucket placement: " << cpp_strerror(-ret) << std::endl; | |
5142 | } | |
5143 | ||
5144 | if (opt_cmd == OPT_POOL_RM) { | |
5145 | if (pool_name.empty()) { | |
5146 | cerr << "need to specify pool to remove!" << std::endl; | |
d2e6a577 FG |
5147 | usage(); |
5148 | assert(false); | |
7c673cae FG |
5149 | } |
5150 | ||
5151 | int ret = store->remove_bucket_placement(pool); | |
5152 | if (ret < 0) | |
5153 | cerr << "failed to remove bucket placement: " << cpp_strerror(-ret) << std::endl; | |
5154 | } | |
5155 | ||
5156 | if (opt_cmd == OPT_POOLS_LIST) { | |
5157 | set<rgw_pool> pools; | |
5158 | int ret = store->list_placement_set(pools); | |
5159 | if (ret < 0) { | |
5160 | cerr << "could not list placement set: " << cpp_strerror(-ret) << std::endl; | |
5161 | return -ret; | |
5162 | } | |
5163 | formatter->reset(); | |
5164 | formatter->open_array_section("pools"); | |
5165 | for (auto siter = pools.begin(); siter != pools.end(); ++siter) { | |
5166 | formatter->open_object_section("pool"); | |
5167 | formatter->dump_string("name", siter->to_str()); | |
5168 | formatter->close_section(); | |
5169 | } | |
5170 | formatter->close_section(); | |
5171 | formatter->flush(cout); | |
5172 | cout << std::endl; | |
5173 | } | |
5174 | ||
5175 | if (opt_cmd == OPT_USAGE_SHOW) { | |
5176 | uint64_t start_epoch = 0; | |
5177 | uint64_t end_epoch = (uint64_t)-1; | |
5178 | ||
5179 | int ret; | |
5180 | ||
5181 | if (!start_date.empty()) { | |
5182 | ret = utime_t::parse_date(start_date, &start_epoch, NULL); | |
5183 | if (ret < 0) { | |
5184 | cerr << "ERROR: failed to parse start date" << std::endl; | |
5185 | return 1; | |
5186 | } | |
5187 | } | |
5188 | if (!end_date.empty()) { | |
5189 | ret = utime_t::parse_date(end_date, &end_epoch, NULL); | |
5190 | if (ret < 0) { | |
5191 | cerr << "ERROR: failed to parse end date" << std::endl; | |
5192 | return 1; | |
5193 | } | |
5194 | } | |
5195 | ||
5196 | ||
5197 | ret = RGWUsage::show(store, user_id, start_epoch, end_epoch, | |
5198 | show_log_entries, show_log_sum, &categories, | |
5199 | f); | |
5200 | if (ret < 0) { | |
5201 | cerr << "ERROR: failed to show usage" << std::endl; | |
5202 | return 1; | |
5203 | } | |
5204 | } | |
5205 | ||
5206 | if (opt_cmd == OPT_USAGE_TRIM) { | |
5207 | if (user_id.empty() && !yes_i_really_mean_it) { | |
5208 | cerr << "usage trim without user specified will remove *all* users data" << std::endl; | |
5209 | cerr << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl; | |
5210 | return 1; | |
5211 | } | |
5212 | int ret; | |
5213 | uint64_t start_epoch = 0; | |
5214 | uint64_t end_epoch = (uint64_t)-1; | |
5215 | ||
5216 | ||
5217 | if (!start_date.empty()) { | |
5218 | ret = utime_t::parse_date(start_date, &start_epoch, NULL); | |
5219 | if (ret < 0) { | |
5220 | cerr << "ERROR: failed to parse start date" << std::endl; | |
5221 | return 1; | |
5222 | } | |
5223 | } | |
5224 | ||
5225 | if (!end_date.empty()) { | |
5226 | ret = utime_t::parse_date(end_date, &end_epoch, NULL); | |
5227 | if (ret < 0) { | |
5228 | cerr << "ERROR: failed to parse end date" << std::endl; | |
5229 | return 1; | |
5230 | } | |
5231 | } | |
5232 | ||
5233 | ret = RGWUsage::trim(store, user_id, start_epoch, end_epoch); | |
5234 | if (ret < 0) { | |
5235 | cerr << "ERROR: read_usage() returned ret=" << ret << std::endl; | |
5236 | return 1; | |
5237 | } | |
5238 | } | |
5239 | ||
5240 | if (opt_cmd == OPT_OLH_GET || opt_cmd == OPT_OLH_READLOG) { | |
5241 | if (bucket_name.empty()) { | |
5242 | cerr << "ERROR: bucket not specified" << std::endl; | |
5243 | return EINVAL; | |
5244 | } | |
5245 | if (object.empty()) { | |
5246 | cerr << "ERROR: object not specified" << std::endl; | |
5247 | return EINVAL; | |
5248 | } | |
7c673cae FG |
5249 | } |
5250 | ||
5251 | if (opt_cmd == OPT_OLH_GET) { | |
5252 | RGWBucketInfo bucket_info; | |
5253 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5254 | if (ret < 0) { | |
5255 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5256 | return -ret; | |
5257 | } | |
5258 | RGWOLHInfo olh; | |
5259 | rgw_obj obj(bucket, object); | |
5260 | ret = store->get_olh(bucket_info, obj, &olh); | |
5261 | if (ret < 0) { | |
5262 | cerr << "ERROR: failed reading olh: " << cpp_strerror(-ret) << std::endl; | |
5263 | return -ret; | |
5264 | } | |
5265 | encode_json("olh", olh, formatter); | |
5266 | formatter->flush(cout); | |
5267 | } | |
5268 | ||
5269 | if (opt_cmd == OPT_OLH_READLOG) { | |
5270 | RGWBucketInfo bucket_info; | |
5271 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5272 | if (ret < 0) { | |
5273 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5274 | return -ret; | |
5275 | } | |
5276 | map<uint64_t, vector<rgw_bucket_olh_log_entry> > log; | |
5277 | bool is_truncated; | |
5278 | ||
5279 | RGWObjectCtx rctx(store); | |
5280 | rgw_obj obj(bucket, object); | |
5281 | ||
5282 | RGWObjState *state; | |
5283 | ||
5284 | ret = store->get_obj_state(&rctx, bucket_info, obj, &state, false); /* don't follow olh */ | |
5285 | if (ret < 0) { | |
5286 | return -ret; | |
5287 | } | |
5288 | ||
5289 | ret = store->bucket_index_read_olh_log(bucket_info, *state, obj, 0, &log, &is_truncated); | |
5290 | if (ret < 0) { | |
5291 | cerr << "ERROR: failed reading olh: " << cpp_strerror(-ret) << std::endl; | |
5292 | return -ret; | |
5293 | } | |
5294 | formatter->open_object_section("result"); | |
5295 | encode_json("is_truncated", is_truncated, formatter); | |
5296 | encode_json("log", log, formatter); | |
5297 | formatter->close_section(); | |
5298 | formatter->flush(cout); | |
5299 | } | |
5300 | ||
5301 | if (opt_cmd == OPT_BI_GET) { | |
5302 | RGWBucketInfo bucket_info; | |
5303 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5304 | if (ret < 0) { | |
5305 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5306 | return -ret; | |
5307 | } | |
5308 | rgw_obj obj(bucket, object); | |
5309 | if (!object_version.empty()) { | |
5310 | obj.key.set_instance(object_version); | |
5311 | } | |
5312 | ||
5313 | rgw_cls_bi_entry entry; | |
5314 | ||
5315 | ret = store->bi_get(bucket, obj, bi_index_type, &entry); | |
5316 | if (ret < 0) { | |
5317 | cerr << "ERROR: bi_get(): " << cpp_strerror(-ret) << std::endl; | |
5318 | return -ret; | |
5319 | } | |
5320 | ||
5321 | encode_json("entry", entry, formatter); | |
5322 | formatter->flush(cout); | |
5323 | } | |
5324 | ||
5325 | if (opt_cmd == OPT_BI_PUT) { | |
5326 | RGWBucketInfo bucket_info; | |
5327 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5328 | if (ret < 0) { | |
5329 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5330 | return -ret; | |
5331 | } | |
5332 | ||
5333 | rgw_cls_bi_entry entry; | |
5334 | cls_rgw_obj_key key; | |
5335 | ret = read_decode_json(infile, entry, &key); | |
5336 | if (ret < 0) { | |
5337 | return 1; | |
5338 | } | |
5339 | ||
5340 | rgw_obj obj(bucket, key); | |
5341 | ||
5342 | ret = store->bi_put(bucket, obj, entry); | |
5343 | if (ret < 0) { | |
5344 | cerr << "ERROR: bi_put(): " << cpp_strerror(-ret) << std::endl; | |
5345 | return -ret; | |
5346 | } | |
5347 | } | |
5348 | ||
5349 | if (opt_cmd == OPT_BI_LIST) { | |
5350 | if (bucket_name.empty()) { | |
5351 | cerr << "ERROR: bucket name not specified" << std::endl; | |
5352 | return EINVAL; | |
5353 | } | |
5354 | RGWBucketInfo bucket_info; | |
5355 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5356 | if (ret < 0) { | |
5357 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5358 | return -ret; | |
5359 | } | |
5360 | ||
5361 | list<rgw_cls_bi_entry> entries; | |
5362 | bool is_truncated; | |
5363 | if (max_entries < 0) { | |
5364 | max_entries = 1000; | |
5365 | } | |
5366 | ||
5367 | int max_shards = (bucket_info.num_shards > 0 ? bucket_info.num_shards : 1); | |
5368 | ||
5369 | formatter->open_array_section("entries"); | |
5370 | ||
5371 | for (int i = 0; i < max_shards; i++) { | |
5372 | RGWRados::BucketShard bs(store); | |
5373 | int shard_id = (bucket_info.num_shards > 0 ? i : -1); | |
5374 | int ret = bs.init(bucket, shard_id); | |
5375 | marker.clear(); | |
5376 | ||
5377 | if (ret < 0) { | |
5378 | cerr << "ERROR: bs.init(bucket=" << bucket << ", shard=" << shard_id << "): " << cpp_strerror(-ret) << std::endl; | |
5379 | return -ret; | |
5380 | } | |
5381 | ||
5382 | do { | |
5383 | entries.clear(); | |
5384 | ret = store->bi_list(bs, object, marker, max_entries, &entries, &is_truncated); | |
5385 | if (ret < 0) { | |
5386 | cerr << "ERROR: bi_list(): " << cpp_strerror(-ret) << std::endl; | |
5387 | return -ret; | |
5388 | } | |
5389 | ||
5390 | list<rgw_cls_bi_entry>::iterator iter; | |
5391 | for (iter = entries.begin(); iter != entries.end(); ++iter) { | |
5392 | rgw_cls_bi_entry& entry = *iter; | |
5393 | encode_json("entry", entry, formatter); | |
5394 | marker = entry.idx; | |
5395 | } | |
5396 | formatter->flush(cout); | |
5397 | } while (is_truncated); | |
5398 | formatter->flush(cout); | |
5399 | } | |
5400 | formatter->close_section(); | |
5401 | formatter->flush(cout); | |
5402 | } | |
5403 | ||
5404 | if (opt_cmd == OPT_BI_PURGE) { | |
5405 | if (bucket_name.empty()) { | |
5406 | cerr << "ERROR: bucket name not specified" << std::endl; | |
5407 | return EINVAL; | |
5408 | } | |
5409 | RGWBucketInfo bucket_info; | |
5410 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5411 | if (ret < 0) { | |
5412 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5413 | return -ret; | |
5414 | } | |
5415 | ||
5416 | RGWBucketInfo cur_bucket_info; | |
5417 | rgw_bucket cur_bucket; | |
5418 | ret = init_bucket(tenant, bucket_name, string(), cur_bucket_info, cur_bucket); | |
5419 | if (ret < 0) { | |
5420 | cerr << "ERROR: could not init current bucket info for bucket_name=" << bucket_name << ": " << cpp_strerror(-ret) << std::endl; | |
5421 | return -ret; | |
5422 | } | |
5423 | ||
5424 | if (cur_bucket_info.bucket.bucket_id == bucket_info.bucket.bucket_id && !yes_i_really_mean_it) { | |
5425 | cerr << "specified bucket instance points to a current bucket instance" << std::endl; | |
5426 | cerr << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl; | |
5427 | return EINVAL; | |
5428 | } | |
5429 | ||
5430 | int max_shards = (bucket_info.num_shards > 0 ? bucket_info.num_shards : 1); | |
5431 | ||
5432 | for (int i = 0; i < max_shards; i++) { | |
5433 | RGWRados::BucketShard bs(store); | |
5434 | int shard_id = (bucket_info.num_shards > 0 ? i : -1); | |
5435 | int ret = bs.init(bucket, shard_id); | |
5436 | if (ret < 0) { | |
5437 | cerr << "ERROR: bs.init(bucket=" << bucket << ", shard=" << shard_id << "): " << cpp_strerror(-ret) << std::endl; | |
5438 | return -ret; | |
5439 | } | |
5440 | ||
5441 | ret = store->bi_remove(bs); | |
5442 | if (ret < 0) { | |
5443 | cerr << "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret) << std::endl; | |
5444 | return -ret; | |
5445 | } | |
5446 | } | |
5447 | } | |
5448 | ||
5449 | if (opt_cmd == OPT_OBJECT_RM) { | |
5450 | RGWBucketInfo bucket_info; | |
5451 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5452 | if (ret < 0) { | |
5453 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5454 | return -ret; | |
5455 | } | |
5456 | rgw_obj_key key(object, object_version); | |
5457 | ret = rgw_remove_object(store, bucket_info, bucket, key); | |
5458 | ||
5459 | if (ret < 0) { | |
5460 | cerr << "ERROR: object remove returned: " << cpp_strerror(-ret) << std::endl; | |
5461 | return -ret; | |
5462 | } | |
5463 | } | |
5464 | ||
5465 | if (opt_cmd == OPT_OBJECT_REWRITE) { | |
5466 | if (bucket_name.empty()) { | |
5467 | cerr << "ERROR: bucket not specified" << std::endl; | |
5468 | return EINVAL; | |
5469 | } | |
5470 | if (object.empty()) { | |
5471 | cerr << "ERROR: object not specified" << std::endl; | |
5472 | return EINVAL; | |
5473 | } | |
5474 | ||
5475 | RGWBucketInfo bucket_info; | |
5476 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5477 | if (ret < 0) { | |
5478 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5479 | return -ret; | |
5480 | } | |
5481 | ||
5482 | rgw_obj obj(bucket, object); | |
5483 | obj.key.set_instance(object_version); | |
5484 | bool need_rewrite = true; | |
5485 | if (min_rewrite_stripe_size > 0) { | |
5486 | ret = check_min_obj_stripe_size(store, bucket_info, obj, min_rewrite_stripe_size, &need_rewrite); | |
5487 | if (ret < 0) { | |
5488 | ldout(store->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret << dendl; | |
5489 | } | |
5490 | } | |
5491 | if (need_rewrite) { | |
5492 | ret = store->rewrite_obj(bucket_info, obj); | |
5493 | if (ret < 0) { | |
5494 | cerr << "ERROR: object rewrite returned: " << cpp_strerror(-ret) << std::endl; | |
5495 | return -ret; | |
5496 | } | |
5497 | } else { | |
5498 | ldout(store->ctx(), 20) << "skipped object" << dendl; | |
5499 | } | |
5500 | } | |
5501 | ||
5502 | if (opt_cmd == OPT_OBJECTS_EXPIRE) { | |
5503 | int ret = store->process_expire_objects(); | |
5504 | if (ret < 0) { | |
5505 | cerr << "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret) << std::endl; | |
5506 | return 1; | |
5507 | } | |
5508 | } | |
5509 | ||
5510 | if (opt_cmd == OPT_BUCKET_REWRITE) { | |
5511 | if (bucket_name.empty()) { | |
5512 | cerr << "ERROR: bucket not specified" << std::endl; | |
5513 | return EINVAL; | |
5514 | } | |
5515 | ||
5516 | RGWBucketInfo bucket_info; | |
5517 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5518 | if (ret < 0) { | |
5519 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5520 | return -ret; | |
5521 | } | |
5522 | ||
5523 | uint64_t start_epoch = 0; | |
5524 | uint64_t end_epoch = 0; | |
5525 | ||
5526 | if (!end_date.empty()) { | |
5527 | int ret = utime_t::parse_date(end_date, &end_epoch, NULL); | |
5528 | if (ret < 0) { | |
5529 | cerr << "ERROR: failed to parse end date" << std::endl; | |
5530 | return EINVAL; | |
5531 | } | |
5532 | } | |
5533 | if (!start_date.empty()) { | |
5534 | int ret = utime_t::parse_date(start_date, &start_epoch, NULL); | |
5535 | if (ret < 0) { | |
5536 | cerr << "ERROR: failed to parse start date" << std::endl; | |
5537 | return EINVAL; | |
5538 | } | |
5539 | } | |
5540 | ||
5541 | bool is_truncated = true; | |
5542 | ||
5543 | rgw_obj_index_key marker; | |
5544 | string prefix; | |
5545 | ||
5546 | formatter->open_object_section("result"); | |
5547 | formatter->dump_string("bucket", bucket_name); | |
5548 | formatter->open_array_section("objects"); | |
5549 | while (is_truncated) { | |
5550 | map<string, rgw_bucket_dir_entry> result; | |
5551 | int r = store->cls_bucket_list(bucket_info, RGW_NO_SHARD, marker, prefix, 1000, true, | |
5552 | result, &is_truncated, &marker, | |
5553 | bucket_object_check_filter); | |
5554 | ||
5555 | if (r < 0 && r != -ENOENT) { | |
5556 | cerr << "ERROR: failed operation r=" << r << std::endl; | |
5557 | } | |
5558 | ||
5559 | if (r == -ENOENT) | |
5560 | break; | |
5561 | ||
5562 | map<string, rgw_bucket_dir_entry>::iterator iter; | |
5563 | for (iter = result.begin(); iter != result.end(); ++iter) { | |
5564 | rgw_obj_key key = iter->second.key; | |
5565 | rgw_bucket_dir_entry& entry = iter->second; | |
5566 | ||
5567 | formatter->open_object_section("object"); | |
5568 | formatter->dump_string("name", key.name); | |
5569 | formatter->dump_string("instance", key.instance); | |
5570 | formatter->dump_int("size", entry.meta.size); | |
5571 | utime_t ut(entry.meta.mtime); | |
5572 | ut.gmtime(formatter->dump_stream("mtime")); | |
5573 | ||
5574 | if ((entry.meta.size < min_rewrite_size) || | |
5575 | (entry.meta.size > max_rewrite_size) || | |
5576 | (start_epoch > 0 && start_epoch > (uint64_t)ut.sec()) || | |
5577 | (end_epoch > 0 && end_epoch < (uint64_t)ut.sec())) { | |
5578 | formatter->dump_string("status", "Skipped"); | |
5579 | } else { | |
5580 | rgw_obj obj(bucket, key); | |
5581 | ||
5582 | bool need_rewrite = true; | |
5583 | if (min_rewrite_stripe_size > 0) { | |
5584 | r = check_min_obj_stripe_size(store, bucket_info, obj, min_rewrite_stripe_size, &need_rewrite); | |
5585 | if (r < 0) { | |
5586 | ldout(store->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r << dendl; | |
5587 | } | |
5588 | } | |
5589 | if (!need_rewrite) { | |
5590 | formatter->dump_string("status", "Skipped"); | |
5591 | } else { | |
5592 | r = store->rewrite_obj(bucket_info, obj); | |
5593 | if (r == 0) { | |
5594 | formatter->dump_string("status", "Success"); | |
5595 | } else { | |
5596 | formatter->dump_string("status", cpp_strerror(-r)); | |
5597 | } | |
5598 | } | |
5599 | } | |
5600 | formatter->dump_int("flags", entry.flags); | |
5601 | ||
5602 | formatter->close_section(); | |
5603 | formatter->flush(cout); | |
5604 | } | |
5605 | } | |
5606 | formatter->close_section(); | |
5607 | formatter->close_section(); | |
5608 | formatter->flush(cout); | |
5609 | } | |
5610 | ||
5611 | if (opt_cmd == OPT_BUCKET_RESHARD) { | |
31f18b77 | 5612 | rgw_bucket bucket; |
7c673cae FG |
5613 | RGWBucketInfo bucket_info; |
5614 | map<string, bufferlist> attrs; | |
31f18b77 FG |
5615 | |
5616 | int ret = check_reshard_bucket_params(store, | |
5617 | bucket_name, | |
5618 | tenant, | |
5619 | bucket_id, | |
5620 | num_shards_specified, | |
5621 | num_shards, | |
5622 | yes_i_really_mean_it, | |
5623 | bucket, | |
5624 | bucket_info, | |
5625 | attrs); | |
7c673cae | 5626 | if (ret < 0) { |
31f18b77 | 5627 | return ret; |
7c673cae FG |
5628 | } |
5629 | ||
31f18b77 | 5630 | RGWBucketReshard br(store, bucket_info, attrs); |
7c673cae | 5631 | |
31f18b77 FG |
5632 | #define DEFAULT_RESHARD_MAX_ENTRIES 1000 |
5633 | if (max_entries < 1) { | |
5634 | max_entries = DEFAULT_RESHARD_MAX_ENTRIES; | |
7c673cae FG |
5635 | } |
5636 | ||
31f18b77 FG |
5637 | return br.execute(num_shards, max_entries, |
5638 | verbose, &cout, formatter); | |
5639 | } | |
7c673cae | 5640 | |
31f18b77 FG |
5641 | if (opt_cmd == OPT_RESHARD_ADD) { |
5642 | rgw_bucket bucket; | |
5643 | RGWBucketInfo bucket_info; | |
5644 | map<string, bufferlist> attrs; | |
7c673cae | 5645 | |
31f18b77 FG |
5646 | int ret = check_reshard_bucket_params(store, |
5647 | bucket_name, | |
5648 | tenant, | |
5649 | bucket_id, | |
5650 | num_shards_specified, | |
5651 | num_shards, | |
5652 | yes_i_really_mean_it, | |
5653 | bucket, | |
5654 | bucket_info, | |
5655 | attrs); | |
7c673cae | 5656 | if (ret < 0) { |
31f18b77 | 5657 | return ret; |
7c673cae FG |
5658 | } |
5659 | ||
31f18b77 | 5660 | int num_source_shards = (bucket_info.num_shards > 0 ? bucket_info.num_shards : 1); |
7c673cae | 5661 | |
31f18b77 FG |
5662 | RGWReshard reshard(store); |
5663 | cls_rgw_reshard_entry entry; | |
5664 | entry.time = real_clock::now(); | |
5665 | entry.tenant = tenant; | |
5666 | entry.bucket_name = bucket_name; | |
5667 | entry.bucket_id = bucket_info.bucket.bucket_id; | |
5668 | entry.old_num_shards = num_source_shards; | |
5669 | entry.new_num_shards = num_shards; | |
7c673cae | 5670 | |
31f18b77 FG |
5671 | return reshard.add(entry); |
5672 | } | |
7c673cae | 5673 | |
31f18b77 FG |
5674 | if (opt_cmd == OPT_RESHARD_LIST) { |
5675 | list<cls_rgw_reshard_entry> entries; | |
5676 | int ret; | |
5677 | int count = 0; | |
5678 | if (max_entries < 0) { | |
5679 | max_entries = 1000; | |
7c673cae FG |
5680 | } |
5681 | ||
31f18b77 | 5682 | int num_logshards = store->ctx()->_conf->rgw_reshard_num_logs; |
7c673cae | 5683 | |
31f18b77 | 5684 | RGWReshard reshard(store); |
7c673cae | 5685 | |
31f18b77 FG |
5686 | formatter->open_array_section("reshard"); |
5687 | for (int i = 0; i < num_logshards; i++) { | |
7c673cae | 5688 | bool is_truncated = true; |
31f18b77 FG |
5689 | string marker; |
5690 | do { | |
7c673cae | 5691 | entries.clear(); |
31f18b77 | 5692 | ret = reshard.list(i, marker, max_entries, entries, &is_truncated); |
7c673cae | 5693 | if (ret < 0) { |
31f18b77 FG |
5694 | cerr << "Error listing resharding buckets: " << cpp_strerror(-ret) << std::endl; |
5695 | return ret; | |
7c673cae | 5696 | } |
31f18b77 FG |
5697 | for (auto iter=entries.begin(); iter != entries.end(); ++iter) { |
5698 | cls_rgw_reshard_entry& entry = *iter; | |
5699 | encode_json("entry", entry, formatter); | |
5700 | entry.get_key(&marker); | |
5701 | } | |
5702 | count += entries.size(); | |
5703 | formatter->flush(cout); | |
5704 | } while (is_truncated && count < max_entries); | |
7c673cae | 5705 | |
31f18b77 FG |
5706 | if (count >= max_entries) { |
5707 | break; | |
5708 | } | |
5709 | } | |
7c673cae | 5710 | |
31f18b77 FG |
5711 | formatter->close_section(); |
5712 | formatter->flush(cout); | |
5713 | return 0; | |
5714 | } | |
7c673cae | 5715 | |
7c673cae | 5716 | |
31f18b77 FG |
5717 | if (opt_cmd == OPT_RESHARD_STATUS) { |
5718 | if (bucket_name.empty()) { | |
5719 | cerr << "ERROR: bucket not specified" << std::endl; | |
5720 | return EINVAL; | |
5721 | } | |
7c673cae | 5722 | |
31f18b77 FG |
5723 | rgw_bucket bucket; |
5724 | RGWBucketInfo bucket_info; | |
5725 | map<string, bufferlist> attrs; | |
5726 | ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket, &attrs); | |
5727 | if (ret < 0) { | |
5728 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5729 | return -ret; | |
5730 | } | |
7c673cae | 5731 | |
31f18b77 FG |
5732 | RGWBucketReshard br(store, bucket_info, attrs); |
5733 | list<cls_rgw_bucket_instance_entry> status; | |
5734 | int r = br.get_status(&status); | |
5735 | if (r < 0) { | |
5736 | cerr << "ERROR: could not get resharding status for bucket " << bucket_name << std::endl; | |
5737 | return -r; | |
7c673cae | 5738 | } |
31f18b77 FG |
5739 | |
5740 | encode_json("status", status, formatter); | |
5741 | formatter->flush(cout); | |
5742 | } | |
5743 | ||
5744 | if (opt_cmd == OPT_RESHARD_PROCESS) { | |
5745 | RGWReshard reshard(store, true, &cout); | |
5746 | ||
5747 | int ret = reshard.process_all_logshards(); | |
5748 | if (ret < 0) { | |
5749 | cerr << "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret) << std::endl; | |
5750 | return -ret; | |
7c673cae | 5751 | } |
31f18b77 | 5752 | } |
7c673cae | 5753 | |
31f18b77 FG |
5754 | if (opt_cmd == OPT_RESHARD_CANCEL) { |
5755 | RGWReshard reshard(store); | |
5756 | ||
5757 | if (bucket_name.empty()) { | |
5758 | cerr << "ERROR: bucket not specified" << std::endl; | |
5759 | return EINVAL; | |
5760 | } | |
5761 | cls_rgw_reshard_entry entry; | |
5762 | //entry.tenant = tenant; | |
5763 | entry.bucket_name = bucket_name; | |
5764 | //entry.bucket_id = bucket_id; | |
5765 | int ret = reshard.get(entry); | |
7c673cae | 5766 | if (ret < 0) { |
31f18b77 FG |
5767 | cerr << "Error in getting bucket " << bucket_name << ": " << cpp_strerror(-ret) << std::endl; |
5768 | return ret; | |
7c673cae FG |
5769 | } |
5770 | ||
31f18b77 FG |
5771 | /* TBD stop running resharding */ |
5772 | ||
5773 | ret =reshard.remove(entry); | |
5774 | if (ret < 0) { | |
5775 | cerr << "Error removing bucket " << bucket_name << " for resharding queue: " << cpp_strerror(-ret) << | |
5776 | std::endl; | |
5777 | return ret; | |
7c673cae FG |
5778 | } |
5779 | } | |
5780 | ||
5781 | if (opt_cmd == OPT_OBJECT_UNLINK) { | |
5782 | RGWBucketInfo bucket_info; | |
5783 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5784 | if (ret < 0) { | |
5785 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5786 | return -ret; | |
5787 | } | |
5788 | list<rgw_obj_index_key> oid_list; | |
5789 | rgw_obj_key key(object, object_version); | |
5790 | rgw_obj_index_key index_key; | |
5791 | key.get_index_key(&index_key); | |
5792 | oid_list.push_back(index_key); | |
5793 | ret = store->remove_objs_from_index(bucket_info, oid_list); | |
5794 | if (ret < 0) { | |
5795 | cerr << "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret) << std::endl; | |
5796 | return 1; | |
5797 | } | |
5798 | } | |
5799 | ||
5800 | if (opt_cmd == OPT_OBJECT_STAT) { | |
5801 | RGWBucketInfo bucket_info; | |
5802 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
5803 | if (ret < 0) { | |
5804 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
5805 | return -ret; | |
5806 | } | |
5807 | rgw_obj obj(bucket, object); | |
5808 | obj.key.set_instance(object_version); | |
5809 | ||
5810 | uint64_t obj_size; | |
5811 | map<string, bufferlist> attrs; | |
5812 | RGWObjectCtx obj_ctx(store); | |
5813 | RGWRados::Object op_target(store, bucket_info, obj_ctx, obj); | |
5814 | RGWRados::Object::Read read_op(&op_target); | |
5815 | ||
5816 | read_op.params.attrs = &attrs; | |
5817 | read_op.params.obj_size = &obj_size; | |
5818 | ||
5819 | ret = read_op.prepare(); | |
5820 | if (ret < 0) { | |
5821 | cerr << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret) << std::endl; | |
5822 | return 1; | |
5823 | } | |
5824 | formatter->open_object_section("object_metadata"); | |
5825 | formatter->dump_string("name", object); | |
5826 | formatter->dump_unsigned("size", obj_size); | |
5827 | ||
5828 | map<string, bufferlist>::iterator iter; | |
5829 | map<string, bufferlist> other_attrs; | |
5830 | for (iter = attrs.begin(); iter != attrs.end(); ++iter) { | |
5831 | bufferlist& bl = iter->second; | |
5832 | bool handled = false; | |
5833 | if (iter->first == RGW_ATTR_MANIFEST) { | |
5834 | handled = decode_dump<RGWObjManifest>("manifest", bl, formatter); | |
5835 | } else if (iter->first == RGW_ATTR_ACL) { | |
5836 | handled = decode_dump<RGWAccessControlPolicy>("policy", bl, formatter); | |
5837 | } else if (iter->first == RGW_ATTR_ID_TAG) { | |
5838 | handled = dump_string("tag", bl, formatter); | |
5839 | } else if (iter->first == RGW_ATTR_ETAG) { | |
5840 | handled = dump_string("etag", bl, formatter); | |
5841 | } | |
5842 | ||
5843 | if (!handled) | |
5844 | other_attrs[iter->first] = bl; | |
5845 | } | |
5846 | ||
5847 | formatter->open_object_section("attrs"); | |
5848 | for (iter = other_attrs.begin(); iter != other_attrs.end(); ++iter) { | |
5849 | dump_string(iter->first.c_str(), iter->second, formatter); | |
5850 | } | |
5851 | formatter->close_section(); | |
5852 | formatter->close_section(); | |
5853 | formatter->flush(cout); | |
5854 | } | |
5855 | ||
5856 | if (opt_cmd == OPT_BUCKET_CHECK) { | |
5857 | if (check_head_obj_locator) { | |
5858 | if (bucket_name.empty()) { | |
5859 | cerr << "ERROR: need to specify bucket name" << std::endl; | |
5860 | return EINVAL; | |
5861 | } | |
5862 | do_check_object_locator(tenant, bucket_name, fix, remove_bad, formatter); | |
5863 | } else { | |
5864 | RGWBucketAdminOp::check_index(store, bucket_op, f); | |
5865 | } | |
5866 | } | |
5867 | ||
5868 | if (opt_cmd == OPT_BUCKET_RM) { | |
5869 | if (inconsistent_index == false) { | |
5870 | RGWBucketAdminOp::remove_bucket(store, bucket_op, bypass_gc, true); | |
5871 | } else { | |
181888fb FG |
5872 | if (!yes_i_really_mean_it) { |
5873 | cerr << "using --inconsistent_index can corrupt the bucket index " << std::endl | |
5874 | << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl; | |
5875 | return 1; | |
5876 | } | |
7c673cae FG |
5877 | RGWBucketAdminOp::remove_bucket(store, bucket_op, bypass_gc, false); |
5878 | } | |
5879 | } | |
5880 | ||
5881 | if (opt_cmd == OPT_GC_LIST) { | |
5882 | int index = 0; | |
5883 | bool truncated; | |
5884 | formatter->open_array_section("entries"); | |
5885 | ||
5886 | do { | |
5887 | list<cls_rgw_gc_obj_info> result; | |
5888 | int ret = store->list_gc_objs(&index, marker, 1000, !include_all, result, &truncated); | |
5889 | if (ret < 0) { | |
5890 | cerr << "ERROR: failed to list objs: " << cpp_strerror(-ret) << std::endl; | |
5891 | return 1; | |
5892 | } | |
5893 | ||
5894 | ||
5895 | list<cls_rgw_gc_obj_info>::iterator iter; | |
5896 | for (iter = result.begin(); iter != result.end(); ++iter) { | |
5897 | cls_rgw_gc_obj_info& info = *iter; | |
5898 | formatter->open_object_section("chain_info"); | |
5899 | formatter->dump_string("tag", info.tag); | |
5900 | formatter->dump_stream("time") << info.time; | |
5901 | formatter->open_array_section("objs"); | |
5902 | list<cls_rgw_obj>::iterator liter; | |
5903 | cls_rgw_obj_chain& chain = info.chain; | |
5904 | for (liter = chain.objs.begin(); liter != chain.objs.end(); ++liter) { | |
5905 | cls_rgw_obj& obj = *liter; | |
5906 | encode_json("obj", obj, formatter); | |
5907 | } | |
5908 | formatter->close_section(); // objs | |
5909 | formatter->close_section(); // obj_chain | |
5910 | formatter->flush(cout); | |
5911 | } | |
5912 | } while (truncated); | |
5913 | formatter->close_section(); | |
5914 | formatter->flush(cout); | |
5915 | } | |
5916 | ||
5917 | if (opt_cmd == OPT_GC_PROCESS) { | |
5918 | int ret = store->process_gc(); | |
5919 | if (ret < 0) { | |
5920 | cerr << "ERROR: gc processing returned error: " << cpp_strerror(-ret) << std::endl; | |
5921 | return 1; | |
5922 | } | |
5923 | } | |
5924 | ||
5925 | if (opt_cmd == OPT_LC_LIST) { | |
5926 | formatter->open_array_section("lifecycle_list"); | |
5927 | map<string, int> bucket_lc_map; | |
5928 | string marker; | |
5929 | #define MAX_LC_LIST_ENTRIES 100 | |
5930 | if (max_entries < 0) { | |
5931 | max_entries = MAX_LC_LIST_ENTRIES; | |
5932 | } | |
5933 | do { | |
5934 | int ret = store->list_lc_progress(marker, max_entries, &bucket_lc_map); | |
5935 | if (ret < 0) { | |
5936 | cerr << "ERROR: failed to list objs: " << cpp_strerror(-ret) << std::endl; | |
5937 | return 1; | |
5938 | } | |
5939 | map<string, int>::iterator iter; | |
5940 | for (iter = bucket_lc_map.begin(); iter != bucket_lc_map.end(); ++iter) { | |
5941 | formatter->open_object_section("bucket_lc_info"); | |
5942 | formatter->dump_string("bucket", iter->first); | |
5943 | string lc_status = LC_STATUS[iter->second]; | |
5944 | formatter->dump_string("status", lc_status); | |
5945 | formatter->close_section(); // objs | |
5946 | formatter->flush(cout); | |
5947 | marker = iter->first; | |
5948 | } | |
5949 | } while (!bucket_lc_map.empty()); | |
5950 | ||
5951 | formatter->close_section(); //lifecycle list | |
5952 | formatter->flush(cout); | |
5953 | } | |
5954 | ||
5955 | ||
5956 | if (opt_cmd == OPT_LC_PROCESS) { | |
5957 | int ret = store->process_lc(); | |
5958 | if (ret < 0) { | |
5959 | cerr << "ERROR: lc processing returned error: " << cpp_strerror(-ret) << std::endl; | |
5960 | return 1; | |
5961 | } | |
5962 | } | |
5963 | ||
5964 | if (opt_cmd == OPT_ORPHANS_FIND) { | |
5965 | RGWOrphanSearch search(store, max_concurrent_ios, orphan_stale_secs); | |
5966 | ||
5967 | if (job_id.empty()) { | |
5968 | cerr << "ERROR: --job-id not specified" << std::endl; | |
5969 | return EINVAL; | |
5970 | } | |
5971 | if (pool_name.empty()) { | |
5972 | cerr << "ERROR: --pool not specified" << std::endl; | |
5973 | return EINVAL; | |
5974 | } | |
5975 | ||
5976 | RGWOrphanSearchInfo info; | |
5977 | ||
5978 | info.pool = pool; | |
5979 | info.job_name = job_id; | |
5980 | info.num_shards = num_shards; | |
5981 | ||
5982 | int ret = search.init(job_id, &info); | |
5983 | if (ret < 0) { | |
5984 | cerr << "could not init search, ret=" << ret << std::endl; | |
5985 | return -ret; | |
5986 | } | |
5987 | ret = search.run(); | |
5988 | if (ret < 0) { | |
5989 | return -ret; | |
5990 | } | |
5991 | } | |
5992 | ||
5993 | if (opt_cmd == OPT_ORPHANS_FINISH) { | |
5994 | RGWOrphanSearch search(store, max_concurrent_ios, orphan_stale_secs); | |
5995 | ||
5996 | if (job_id.empty()) { | |
5997 | cerr << "ERROR: --job-id not specified" << std::endl; | |
5998 | return EINVAL; | |
5999 | } | |
6000 | int ret = search.init(job_id, NULL); | |
6001 | if (ret < 0) { | |
6002 | if (ret == -ENOENT) { | |
6003 | cerr << "job not found" << std::endl; | |
6004 | } | |
6005 | return -ret; | |
6006 | } | |
6007 | ret = search.finish(); | |
6008 | if (ret < 0) { | |
6009 | return -ret; | |
6010 | } | |
6011 | } | |
6012 | ||
6013 | if (opt_cmd == OPT_ORPHANS_LIST_JOBS){ | |
6014 | RGWOrphanStore orphan_store(store); | |
6015 | int ret = orphan_store.init(); | |
6016 | if (ret < 0){ | |
6017 | cerr << "connection to cluster failed!" << std::endl; | |
6018 | return -ret; | |
6019 | } | |
6020 | ||
6021 | map <string,RGWOrphanSearchState> m; | |
6022 | ret = orphan_store.list_jobs(m); | |
6023 | if (ret < 0) { | |
6024 | cerr << "job list failed" << std::endl; | |
6025 | return -ret; | |
6026 | } | |
6027 | formatter->open_array_section("entries"); | |
6028 | for (const auto &it: m){ | |
6029 | if (!extra_info){ | |
6030 | formatter->dump_string("job-id",it.first); | |
6031 | } else { | |
6032 | encode_json("orphan_search_state", it.second, formatter); | |
6033 | } | |
6034 | } | |
6035 | formatter->close_section(); | |
6036 | formatter->flush(cout); | |
6037 | } | |
6038 | ||
6039 | if (opt_cmd == OPT_USER_CHECK) { | |
6040 | check_bad_user_bucket_mapping(store, user_id, fix); | |
6041 | } | |
6042 | ||
6043 | if (opt_cmd == OPT_USER_STATS) { | |
6044 | if (sync_stats) { | |
6045 | if (!bucket_name.empty()) { | |
6046 | int ret = rgw_bucket_sync_user_stats(store, tenant, bucket_name); | |
6047 | if (ret < 0) { | |
6048 | cerr << "ERROR: could not sync bucket stats: " << cpp_strerror(-ret) << std::endl; | |
6049 | return -ret; | |
6050 | } | |
6051 | } else { | |
6052 | int ret = rgw_user_sync_all_stats(store, user_id); | |
6053 | if (ret < 0) { | |
6054 | cerr << "ERROR: failed to sync user stats: " << cpp_strerror(-ret) << std::endl; | |
6055 | return -ret; | |
6056 | } | |
6057 | } | |
6058 | } | |
6059 | ||
6060 | if (user_id.empty()) { | |
6061 | cerr << "ERROR: uid not specified" << std::endl; | |
6062 | return EINVAL; | |
6063 | } | |
6064 | cls_user_header header; | |
6065 | string user_str = user_id.to_str(); | |
6066 | int ret = store->cls_user_get_header(user_str, &header); | |
6067 | if (ret < 0) { | |
6068 | if (ret == -ENOENT) { /* in case of ENOENT */ | |
6069 | cerr << "User has not been initialized or user does not exist" << std::endl; | |
6070 | } else { | |
6071 | cerr << "ERROR: can't read user: " << cpp_strerror(ret) << std::endl; | |
6072 | } | |
6073 | return -ret; | |
6074 | } | |
6075 | ||
6076 | encode_json("header", header, formatter); | |
6077 | formatter->flush(cout); | |
6078 | } | |
6079 | ||
6080 | if (opt_cmd == OPT_METADATA_GET) { | |
6081 | int ret = store->meta_mgr->get(metadata_key, formatter); | |
6082 | if (ret < 0) { | |
6083 | cerr << "ERROR: can't get key: " << cpp_strerror(-ret) << std::endl; | |
6084 | return -ret; | |
6085 | } | |
6086 | ||
6087 | formatter->flush(cout); | |
6088 | } | |
6089 | ||
6090 | if (opt_cmd == OPT_METADATA_PUT) { | |
6091 | bufferlist bl; | |
6092 | int ret = read_input(infile, bl); | |
6093 | if (ret < 0) { | |
6094 | cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl; | |
6095 | return -ret; | |
6096 | } | |
6097 | ret = store->meta_mgr->put(metadata_key, bl, RGWMetadataHandler::APPLY_ALWAYS); | |
6098 | if (ret < 0) { | |
6099 | cerr << "ERROR: can't put key: " << cpp_strerror(-ret) << std::endl; | |
6100 | return -ret; | |
6101 | } | |
6102 | } | |
6103 | ||
6104 | if (opt_cmd == OPT_METADATA_RM) { | |
6105 | int ret = store->meta_mgr->remove(metadata_key); | |
6106 | if (ret < 0) { | |
6107 | cerr << "ERROR: can't remove key: " << cpp_strerror(-ret) << std::endl; | |
6108 | return -ret; | |
6109 | } | |
6110 | } | |
6111 | ||
6112 | if (opt_cmd == OPT_METADATA_LIST || opt_cmd == OPT_USER_LIST) { | |
6113 | if (opt_cmd == OPT_USER_LIST) { | |
6114 | metadata_key = "user"; | |
6115 | } | |
6116 | void *handle; | |
6117 | int max = 1000; | |
181888fb | 6118 | int ret = store->meta_mgr->list_keys_init(metadata_key, marker, &handle); |
7c673cae FG |
6119 | if (ret < 0) { |
6120 | cerr << "ERROR: can't get key: " << cpp_strerror(-ret) << std::endl; | |
6121 | return -ret; | |
6122 | } | |
6123 | ||
6124 | bool truncated; | |
181888fb | 6125 | uint64_t count = 0; |
7c673cae | 6126 | |
181888fb FG |
6127 | if (max_entries_specified) { |
6128 | formatter->open_object_section("result"); | |
6129 | } | |
7c673cae FG |
6130 | formatter->open_array_section("keys"); |
6131 | ||
181888fb | 6132 | uint64_t left; |
7c673cae FG |
6133 | do { |
6134 | list<string> keys; | |
181888fb FG |
6135 | left = (max_entries_specified ? max_entries - count : max); |
6136 | ret = store->meta_mgr->list_keys_next(handle, left, keys, &truncated); | |
7c673cae FG |
6137 | if (ret < 0 && ret != -ENOENT) { |
6138 | cerr << "ERROR: lists_keys_next(): " << cpp_strerror(-ret) << std::endl; | |
6139 | return -ret; | |
6140 | } if (ret != -ENOENT) { | |
6141 | for (list<string>::iterator iter = keys.begin(); iter != keys.end(); ++iter) { | |
6142 | formatter->dump_string("key", *iter); | |
181888fb | 6143 | ++count; |
7c673cae FG |
6144 | } |
6145 | formatter->flush(cout); | |
6146 | } | |
181888fb | 6147 | } while (truncated && left > 0); |
7c673cae FG |
6148 | |
6149 | formatter->close_section(); | |
181888fb FG |
6150 | |
6151 | if (max_entries_specified) { | |
6152 | encode_json("truncated", truncated, formatter); | |
6153 | encode_json("count", count, formatter); | |
6154 | if (truncated) { | |
6155 | encode_json("marker", store->meta_mgr->get_marker(handle), formatter); | |
6156 | } | |
6157 | formatter->close_section(); | |
6158 | } | |
7c673cae FG |
6159 | formatter->flush(cout); |
6160 | ||
6161 | store->meta_mgr->list_keys_complete(handle); | |
6162 | } | |
6163 | ||
6164 | if (opt_cmd == OPT_MDLOG_LIST) { | |
6165 | utime_t start_time, end_time; | |
6166 | ||
6167 | int ret = parse_date_str(start_date, start_time); | |
6168 | if (ret < 0) | |
6169 | return -ret; | |
6170 | ||
6171 | ret = parse_date_str(end_date, end_time); | |
6172 | if (ret < 0) | |
6173 | return -ret; | |
6174 | ||
6175 | int i = (specified_shard_id ? shard_id : 0); | |
6176 | ||
6177 | if (period_id.empty()) { | |
6178 | int ret = read_current_period_id(store, realm_id, realm_name, &period_id); | |
6179 | if (ret < 0) { | |
6180 | return -ret; | |
6181 | } | |
6182 | std::cerr << "No --period given, using current period=" | |
6183 | << period_id << std::endl; | |
6184 | } | |
6185 | RGWMetadataLog *meta_log = store->meta_mgr->get_log(period_id); | |
6186 | ||
6187 | formatter->open_array_section("entries"); | |
6188 | for (; i < g_ceph_context->_conf->rgw_md_log_max_shards; i++) { | |
6189 | void *handle; | |
6190 | list<cls_log_entry> entries; | |
6191 | ||
6192 | ||
6193 | meta_log->init_list_entries(i, start_time.to_real_time(), end_time.to_real_time(), marker, &handle); | |
6194 | bool truncated; | |
6195 | do { | |
6196 | int ret = meta_log->list_entries(handle, 1000, entries, NULL, &truncated); | |
6197 | if (ret < 0) { | |
6198 | cerr << "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret) << std::endl; | |
6199 | return -ret; | |
6200 | } | |
6201 | ||
6202 | for (list<cls_log_entry>::iterator iter = entries.begin(); iter != entries.end(); ++iter) { | |
6203 | cls_log_entry& entry = *iter; | |
6204 | store->meta_mgr->dump_log_entry(entry, formatter); | |
6205 | } | |
6206 | formatter->flush(cout); | |
6207 | } while (truncated); | |
6208 | ||
6209 | meta_log->complete_list_entries(handle); | |
6210 | ||
6211 | if (specified_shard_id) | |
6212 | break; | |
6213 | } | |
6214 | ||
6215 | ||
6216 | formatter->close_section(); | |
6217 | formatter->flush(cout); | |
6218 | } | |
6219 | ||
6220 | if (opt_cmd == OPT_MDLOG_STATUS) { | |
6221 | int i = (specified_shard_id ? shard_id : 0); | |
6222 | ||
6223 | if (period_id.empty()) { | |
6224 | int ret = read_current_period_id(store, realm_id, realm_name, &period_id); | |
6225 | if (ret < 0) { | |
6226 | return -ret; | |
6227 | } | |
6228 | std::cerr << "No --period given, using current period=" | |
6229 | << period_id << std::endl; | |
6230 | } | |
6231 | RGWMetadataLog *meta_log = store->meta_mgr->get_log(period_id); | |
6232 | ||
6233 | formatter->open_array_section("entries"); | |
6234 | ||
6235 | for (; i < g_ceph_context->_conf->rgw_md_log_max_shards; i++) { | |
6236 | RGWMetadataLogInfo info; | |
6237 | meta_log->get_info(i, &info); | |
6238 | ||
6239 | ::encode_json("info", info, formatter); | |
6240 | ||
6241 | if (specified_shard_id) | |
6242 | break; | |
6243 | } | |
6244 | ||
6245 | ||
6246 | formatter->close_section(); | |
6247 | formatter->flush(cout); | |
6248 | } | |
6249 | ||
6250 | if (opt_cmd == OPT_MDLOG_AUTOTRIM) { | |
6251 | // need a full history for purging old mdlog periods | |
6252 | store->meta_mgr->init_oldest_log_period(); | |
6253 | ||
6254 | RGWCoroutinesManager crs(store->ctx(), store->get_cr_registry()); | |
6255 | RGWHTTPManager http(store->ctx(), crs.get_completion_mgr()); | |
6256 | int ret = http.set_threaded(); | |
6257 | if (ret < 0) { | |
6258 | cerr << "failed to initialize http client with " << cpp_strerror(ret) << std::endl; | |
6259 | return -ret; | |
6260 | } | |
6261 | ||
6262 | auto num_shards = g_conf->rgw_md_log_max_shards; | |
6263 | ret = crs.run(create_admin_meta_log_trim_cr(store, &http, num_shards)); | |
6264 | if (ret < 0) { | |
6265 | cerr << "automated mdlog trim failed with " << cpp_strerror(ret) << std::endl; | |
6266 | return -ret; | |
6267 | } | |
6268 | } | |
6269 | ||
6270 | if (opt_cmd == OPT_MDLOG_TRIM) { | |
6271 | utime_t start_time, end_time; | |
6272 | ||
6273 | if (!specified_shard_id) { | |
6274 | cerr << "ERROR: shard-id must be specified for trim operation" << std::endl; | |
6275 | return EINVAL; | |
6276 | } | |
6277 | ||
6278 | int ret = parse_date_str(start_date, start_time); | |
6279 | if (ret < 0) | |
6280 | return -ret; | |
6281 | ||
6282 | ret = parse_date_str(end_date, end_time); | |
6283 | if (ret < 0) | |
6284 | return -ret; | |
6285 | ||
6286 | if (period_id.empty()) { | |
6287 | std::cerr << "missing --period argument" << std::endl; | |
6288 | return EINVAL; | |
6289 | } | |
6290 | RGWMetadataLog *meta_log = store->meta_mgr->get_log(period_id); | |
6291 | ||
6292 | ret = meta_log->trim(shard_id, start_time.to_real_time(), end_time.to_real_time(), start_marker, end_marker); | |
6293 | if (ret < 0) { | |
6294 | cerr << "ERROR: meta_log->trim(): " << cpp_strerror(-ret) << std::endl; | |
6295 | return -ret; | |
6296 | } | |
6297 | } | |
6298 | ||
6299 | if (opt_cmd == OPT_SYNC_STATUS) { | |
6300 | sync_status(formatter); | |
6301 | } | |
6302 | ||
6303 | if (opt_cmd == OPT_METADATA_SYNC_STATUS) { | |
6304 | RGWMetaSyncStatusManager sync(store, store->get_async_rados()); | |
6305 | ||
6306 | int ret = sync.init(); | |
6307 | if (ret < 0) { | |
6308 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6309 | return -ret; | |
6310 | } | |
6311 | ||
6312 | rgw_meta_sync_status sync_status; | |
6313 | ret = sync.read_sync_status(&sync_status); | |
6314 | if (ret < 0) { | |
6315 | cerr << "ERROR: sync.read_sync_status() returned ret=" << ret << std::endl; | |
6316 | return -ret; | |
6317 | } | |
6318 | ||
6319 | formatter->open_object_section("summary"); | |
6320 | encode_json("sync_status", sync_status, formatter); | |
6321 | ||
6322 | uint64_t full_total = 0; | |
6323 | uint64_t full_complete = 0; | |
6324 | ||
6325 | for (auto marker_iter : sync_status.sync_markers) { | |
6326 | full_total += marker_iter.second.total_entries; | |
6327 | if (marker_iter.second.state == rgw_meta_sync_marker::SyncState::FullSync) { | |
6328 | full_complete += marker_iter.second.pos; | |
6329 | } else { | |
6330 | full_complete += marker_iter.second.total_entries; | |
6331 | } | |
6332 | } | |
6333 | ||
6334 | formatter->open_object_section("full_sync"); | |
6335 | encode_json("total", full_total, formatter); | |
6336 | encode_json("complete", full_complete, formatter); | |
6337 | formatter->close_section(); | |
6338 | formatter->close_section(); | |
6339 | ||
6340 | formatter->flush(cout); | |
6341 | ||
6342 | } | |
6343 | ||
6344 | if (opt_cmd == OPT_METADATA_SYNC_INIT) { | |
6345 | RGWMetaSyncStatusManager sync(store, store->get_async_rados()); | |
6346 | ||
6347 | int ret = sync.init(); | |
6348 | if (ret < 0) { | |
6349 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6350 | return -ret; | |
6351 | } | |
6352 | ret = sync.init_sync_status(); | |
6353 | if (ret < 0) { | |
6354 | cerr << "ERROR: sync.init_sync_status() returned ret=" << ret << std::endl; | |
6355 | return -ret; | |
6356 | } | |
6357 | } | |
6358 | ||
6359 | ||
6360 | if (opt_cmd == OPT_METADATA_SYNC_RUN) { | |
6361 | RGWMetaSyncStatusManager sync(store, store->get_async_rados()); | |
6362 | ||
6363 | int ret = sync.init(); | |
6364 | if (ret < 0) { | |
6365 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6366 | return -ret; | |
6367 | } | |
6368 | ||
6369 | ret = sync.run(); | |
6370 | if (ret < 0) { | |
6371 | cerr << "ERROR: sync.run() returned ret=" << ret << std::endl; | |
6372 | return -ret; | |
6373 | } | |
6374 | } | |
6375 | ||
6376 | if (opt_cmd == OPT_DATA_SYNC_STATUS) { | |
6377 | if (source_zone.empty()) { | |
6378 | cerr << "ERROR: source zone not specified" << std::endl; | |
6379 | return EINVAL; | |
6380 | } | |
6381 | RGWDataSyncStatusManager sync(store, store->get_async_rados(), source_zone); | |
6382 | ||
6383 | int ret = sync.init(); | |
6384 | if (ret < 0) { | |
6385 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6386 | return -ret; | |
6387 | } | |
6388 | ||
6389 | rgw_data_sync_status sync_status; | |
6390 | ret = sync.read_sync_status(&sync_status); | |
6391 | if (ret < 0 && ret != -ENOENT) { | |
6392 | cerr << "ERROR: sync.read_sync_status() returned ret=" << ret << std::endl; | |
6393 | return -ret; | |
6394 | } | |
6395 | ||
6396 | formatter->open_object_section("summary"); | |
6397 | encode_json("sync_status", sync_status, formatter); | |
6398 | ||
6399 | uint64_t full_total = 0; | |
6400 | uint64_t full_complete = 0; | |
6401 | ||
6402 | for (auto marker_iter : sync_status.sync_markers) { | |
6403 | full_total += marker_iter.second.total_entries; | |
6404 | if (marker_iter.second.state == rgw_meta_sync_marker::SyncState::FullSync) { | |
6405 | full_complete += marker_iter.second.pos; | |
6406 | } else { | |
6407 | full_complete += marker_iter.second.total_entries; | |
6408 | } | |
6409 | } | |
6410 | ||
6411 | formatter->open_object_section("full_sync"); | |
6412 | encode_json("total", full_total, formatter); | |
6413 | encode_json("complete", full_complete, formatter); | |
6414 | formatter->close_section(); | |
6415 | formatter->close_section(); | |
6416 | ||
6417 | formatter->flush(cout); | |
6418 | } | |
6419 | ||
6420 | if (opt_cmd == OPT_DATA_SYNC_INIT) { | |
6421 | if (source_zone.empty()) { | |
6422 | cerr << "ERROR: source zone not specified" << std::endl; | |
6423 | return EINVAL; | |
6424 | } | |
6425 | RGWDataSyncStatusManager sync(store, store->get_async_rados(), source_zone); | |
6426 | ||
6427 | int ret = sync.init(); | |
6428 | if (ret < 0) { | |
6429 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6430 | return -ret; | |
6431 | } | |
6432 | ||
6433 | ret = sync.init_sync_status(); | |
6434 | if (ret < 0) { | |
6435 | cerr << "ERROR: sync.init_sync_status() returned ret=" << ret << std::endl; | |
6436 | return -ret; | |
6437 | } | |
6438 | } | |
6439 | ||
6440 | if (opt_cmd == OPT_DATA_SYNC_RUN) { | |
6441 | if (source_zone.empty()) { | |
6442 | cerr << "ERROR: source zone not specified" << std::endl; | |
6443 | return EINVAL; | |
6444 | } | |
6445 | RGWDataSyncStatusManager sync(store, store->get_async_rados(), source_zone); | |
6446 | ||
6447 | int ret = sync.init(); | |
6448 | if (ret < 0) { | |
6449 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6450 | return -ret; | |
6451 | } | |
6452 | ||
6453 | ret = sync.run(); | |
6454 | if (ret < 0) { | |
6455 | cerr << "ERROR: sync.run() returned ret=" << ret << std::endl; | |
6456 | return -ret; | |
6457 | } | |
6458 | } | |
6459 | ||
6460 | if (opt_cmd == OPT_BUCKET_SYNC_INIT) { | |
6461 | if (source_zone.empty()) { | |
6462 | cerr << "ERROR: source zone not specified" << std::endl; | |
6463 | return EINVAL; | |
6464 | } | |
6465 | if (bucket_name.empty()) { | |
6466 | cerr << "ERROR: bucket not specified" << std::endl; | |
6467 | return EINVAL; | |
6468 | } | |
6469 | rgw_bucket bucket; | |
6470 | int ret = init_bucket_for_sync(tenant, bucket_name, bucket_id, bucket); | |
6471 | if (ret < 0) { | |
6472 | return -ret; | |
6473 | } | |
6474 | RGWBucketSyncStatusManager sync(store, source_zone, bucket); | |
6475 | ||
6476 | ret = sync.init(); | |
6477 | if (ret < 0) { | |
6478 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6479 | return -ret; | |
6480 | } | |
6481 | ret = sync.init_sync_status(); | |
6482 | if (ret < 0) { | |
6483 | cerr << "ERROR: sync.init_sync_status() returned ret=" << ret << std::endl; | |
6484 | return -ret; | |
6485 | } | |
6486 | } | |
6487 | ||
c07f9fc5 FG |
6488 | if ((opt_cmd == OPT_BUCKET_SYNC_DISABLE) || (opt_cmd == OPT_BUCKET_SYNC_ENABLE)) { |
6489 | if (bucket_name.empty()) { | |
6490 | cerr << "ERROR: bucket not specified" << std::endl; | |
6491 | return EINVAL; | |
6492 | } | |
6493 | ||
6494 | if (ret < 0) { | |
6495 | cerr << "could not init realm " << ": " << cpp_strerror(-ret) << std::endl; | |
6496 | return ret; | |
6497 | } | |
6498 | RGWPeriod period; | |
6499 | ret = period.init(g_ceph_context, store, realm_id, realm_name, true); | |
6500 | if (ret < 0) { | |
6501 | cerr << "failed to init period " << ": " << cpp_strerror(-ret) << std::endl; | |
6502 | return ret; | |
6503 | } | |
6504 | ||
6505 | if (!store->is_meta_master()) { | |
6506 | cerr << "failed to update bucket sync: only allowed on meta master zone " << std::endl; | |
6507 | cerr << period.get_master_zone() << " | " << period.get_realm() << std::endl; | |
6508 | return EINVAL; | |
6509 | } | |
6510 | ||
6511 | rgw_obj obj(bucket, object); | |
6512 | ret = set_bucket_sync_enabled(store, opt_cmd, tenant, bucket_name); | |
6513 | if (ret < 0) | |
6514 | return -ret; | |
6515 | } | |
6516 | ||
7c673cae FG |
6517 | if (opt_cmd == OPT_BUCKET_SYNC_STATUS) { |
6518 | if (source_zone.empty()) { | |
6519 | cerr << "ERROR: source zone not specified" << std::endl; | |
6520 | return EINVAL; | |
6521 | } | |
6522 | if (bucket_name.empty()) { | |
6523 | cerr << "ERROR: bucket not specified" << std::endl; | |
6524 | return EINVAL; | |
6525 | } | |
6526 | rgw_bucket bucket; | |
6527 | int ret = init_bucket_for_sync(tenant, bucket_name, bucket_id, bucket); | |
6528 | if (ret < 0) { | |
6529 | return -ret; | |
6530 | } | |
6531 | RGWBucketSyncStatusManager sync(store, source_zone, bucket); | |
6532 | ||
6533 | ret = sync.init(); | |
6534 | if (ret < 0) { | |
6535 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6536 | return -ret; | |
6537 | } | |
6538 | ret = sync.read_sync_status(); | |
6539 | if (ret < 0) { | |
6540 | cerr << "ERROR: sync.read_sync_status() returned ret=" << ret << std::endl; | |
6541 | return -ret; | |
6542 | } | |
6543 | ||
6544 | map<int, rgw_bucket_shard_sync_info>& sync_status = sync.get_sync_status(); | |
6545 | ||
6546 | encode_json("sync_status", sync_status, formatter); | |
6547 | formatter->flush(cout); | |
6548 | } | |
6549 | ||
6550 | if (opt_cmd == OPT_BUCKET_SYNC_RUN) { | |
6551 | if (source_zone.empty()) { | |
6552 | cerr << "ERROR: source zone not specified" << std::endl; | |
6553 | return EINVAL; | |
6554 | } | |
6555 | if (bucket_name.empty()) { | |
6556 | cerr << "ERROR: bucket not specified" << std::endl; | |
6557 | return EINVAL; | |
6558 | } | |
6559 | rgw_bucket bucket; | |
6560 | int ret = init_bucket_for_sync(tenant, bucket_name, bucket_id, bucket); | |
6561 | if (ret < 0) { | |
6562 | return -ret; | |
6563 | } | |
6564 | RGWBucketSyncStatusManager sync(store, source_zone, bucket); | |
6565 | ||
6566 | ret = sync.init(); | |
6567 | if (ret < 0) { | |
6568 | cerr << "ERROR: sync.init() returned ret=" << ret << std::endl; | |
6569 | return -ret; | |
6570 | } | |
6571 | ||
6572 | ret = sync.run(); | |
6573 | if (ret < 0) { | |
6574 | cerr << "ERROR: sync.run() returned ret=" << ret << std::endl; | |
6575 | return -ret; | |
6576 | } | |
6577 | } | |
6578 | ||
6579 | if (opt_cmd == OPT_BILOG_LIST) { | |
6580 | if (bucket_name.empty()) { | |
6581 | cerr << "ERROR: bucket not specified" << std::endl; | |
6582 | return EINVAL; | |
6583 | } | |
6584 | RGWBucketInfo bucket_info; | |
6585 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
6586 | if (ret < 0) { | |
6587 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
6588 | return -ret; | |
6589 | } | |
6590 | formatter->open_array_section("entries"); | |
6591 | bool truncated; | |
6592 | int count = 0; | |
6593 | if (max_entries < 0) | |
6594 | max_entries = 1000; | |
6595 | ||
6596 | do { | |
6597 | list<rgw_bi_log_entry> entries; | |
6598 | ret = store->list_bi_log_entries(bucket_info, shard_id, marker, max_entries - count, entries, &truncated); | |
6599 | if (ret < 0) { | |
6600 | cerr << "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret) << std::endl; | |
6601 | return -ret; | |
6602 | } | |
6603 | ||
6604 | count += entries.size(); | |
6605 | ||
6606 | for (list<rgw_bi_log_entry>::iterator iter = entries.begin(); iter != entries.end(); ++iter) { | |
6607 | rgw_bi_log_entry& entry = *iter; | |
6608 | encode_json("entry", entry, formatter); | |
6609 | ||
6610 | marker = entry.id; | |
6611 | } | |
6612 | formatter->flush(cout); | |
6613 | } while (truncated && count < max_entries); | |
6614 | ||
6615 | formatter->close_section(); | |
6616 | formatter->flush(cout); | |
6617 | } | |
6618 | ||
6619 | if (opt_cmd == OPT_SYNC_ERROR_LIST) { | |
6620 | if (max_entries < 0) { | |
6621 | max_entries = 1000; | |
6622 | } | |
6623 | ||
6624 | bool truncated; | |
6625 | utime_t start_time, end_time; | |
6626 | ||
6627 | int ret = parse_date_str(start_date, start_time); | |
6628 | if (ret < 0) | |
6629 | return -ret; | |
6630 | ||
6631 | ret = parse_date_str(end_date, end_time); | |
6632 | if (ret < 0) | |
6633 | return -ret; | |
6634 | ||
6635 | if (shard_id < 0) { | |
6636 | shard_id = 0; | |
6637 | } | |
6638 | ||
6639 | formatter->open_array_section("entries"); | |
6640 | ||
6641 | for (; shard_id < ERROR_LOGGER_SHARDS; ++shard_id) { | |
6642 | formatter->open_object_section("shard"); | |
6643 | encode_json("shard_id", shard_id, formatter); | |
6644 | formatter->open_array_section("entries"); | |
6645 | ||
6646 | int count = 0; | |
6647 | string oid = RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX, shard_id); | |
6648 | ||
6649 | do { | |
6650 | list<cls_log_entry> entries; | |
6651 | ret = store->time_log_list(oid, start_time.to_real_time(), end_time.to_real_time(), | |
6652 | max_entries - count, entries, marker, &marker, &truncated); | |
6653 | if (ret == -ENOENT) { | |
6654 | break; | |
6655 | } | |
6656 | if (ret < 0) { | |
6657 | cerr << "ERROR: store->time_log_list(): " << cpp_strerror(-ret) << std::endl; | |
6658 | return -ret; | |
6659 | } | |
6660 | ||
6661 | count += entries.size(); | |
6662 | ||
6663 | for (auto& cls_entry : entries) { | |
6664 | rgw_sync_error_info log_entry; | |
6665 | ||
6666 | auto iter = cls_entry.data.begin(); | |
6667 | try { | |
6668 | ::decode(log_entry, iter); | |
6669 | } catch (buffer::error& err) { | |
6670 | cerr << "ERROR: failed to decode log entry" << std::endl; | |
6671 | continue; | |
6672 | } | |
6673 | formatter->open_object_section("entry"); | |
6674 | encode_json("id", cls_entry.id, formatter); | |
6675 | encode_json("section", cls_entry.section, formatter); | |
6676 | encode_json("name", cls_entry.name, formatter); | |
6677 | encode_json("timestamp", cls_entry.timestamp, formatter); | |
6678 | encode_json("info", log_entry, formatter); | |
6679 | formatter->close_section(); | |
6680 | formatter->flush(cout); | |
6681 | } | |
6682 | } while (truncated && count < max_entries); | |
6683 | ||
6684 | formatter->close_section(); | |
6685 | formatter->close_section(); | |
6686 | ||
6687 | if (specified_shard_id) { | |
6688 | break; | |
6689 | } | |
6690 | } | |
6691 | ||
6692 | formatter->close_section(); | |
6693 | formatter->flush(cout); | |
6694 | } | |
6695 | ||
6696 | if (opt_cmd == OPT_BILOG_TRIM) { | |
6697 | if (bucket_name.empty()) { | |
6698 | cerr << "ERROR: bucket not specified" << std::endl; | |
6699 | return EINVAL; | |
6700 | } | |
6701 | RGWBucketInfo bucket_info; | |
6702 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
6703 | if (ret < 0) { | |
6704 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
6705 | return -ret; | |
6706 | } | |
6707 | ret = store->trim_bi_log_entries(bucket_info, shard_id, start_marker, end_marker); | |
6708 | if (ret < 0) { | |
6709 | cerr << "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret) << std::endl; | |
6710 | return -ret; | |
6711 | } | |
6712 | } | |
6713 | ||
6714 | if (opt_cmd == OPT_BILOG_STATUS) { | |
6715 | if (bucket_name.empty()) { | |
6716 | cerr << "ERROR: bucket not specified" << std::endl; | |
6717 | return EINVAL; | |
6718 | } | |
6719 | RGWBucketInfo bucket_info; | |
6720 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
6721 | if (ret < 0) { | |
6722 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
6723 | return -ret; | |
6724 | } | |
6725 | map<int, string> markers; | |
6726 | ret = store->get_bi_log_status(bucket_info, shard_id, markers); | |
6727 | if (ret < 0) { | |
31f18b77 | 6728 | cerr << "ERROR: get_bi_log_status(): " << cpp_strerror(-ret) << std::endl; |
7c673cae FG |
6729 | return -ret; |
6730 | } | |
6731 | formatter->open_object_section("entries"); | |
6732 | encode_json("markers", markers, formatter); | |
6733 | formatter->close_section(); | |
6734 | formatter->flush(cout); | |
6735 | } | |
6736 | ||
b32b8144 FG |
6737 | if (opt_cmd == OPT_BILOG_AUTOTRIM) { |
6738 | RGWCoroutinesManager crs(store->ctx(), store->get_cr_registry()); | |
6739 | RGWHTTPManager http(store->ctx(), crs.get_completion_mgr()); | |
6740 | int ret = http.set_threaded(); | |
6741 | if (ret < 0) { | |
6742 | cerr << "failed to initialize http client with " << cpp_strerror(ret) << std::endl; | |
6743 | return -ret; | |
6744 | } | |
6745 | ||
6746 | rgw::BucketTrimConfig config; | |
6747 | configure_bucket_trim(store->ctx(), config); | |
6748 | ||
6749 | rgw::BucketTrimManager trim(store, config); | |
6750 | ret = trim.init(); | |
6751 | if (ret < 0) { | |
6752 | cerr << "trim manager init failed with " << cpp_strerror(ret) << std::endl; | |
6753 | return -ret; | |
6754 | } | |
6755 | ret = crs.run(trim.create_admin_bucket_trim_cr(&http)); | |
6756 | if (ret < 0) { | |
6757 | cerr << "automated bilog trim failed with " << cpp_strerror(ret) << std::endl; | |
6758 | return -ret; | |
6759 | } | |
6760 | } | |
6761 | ||
7c673cae FG |
6762 | if (opt_cmd == OPT_DATALOG_LIST) { |
6763 | formatter->open_array_section("entries"); | |
6764 | bool truncated; | |
6765 | int count = 0; | |
6766 | if (max_entries < 0) | |
6767 | max_entries = 1000; | |
6768 | ||
6769 | utime_t start_time, end_time; | |
6770 | ||
6771 | int ret = parse_date_str(start_date, start_time); | |
6772 | if (ret < 0) | |
6773 | return -ret; | |
6774 | ||
6775 | ret = parse_date_str(end_date, end_time); | |
6776 | if (ret < 0) | |
6777 | return -ret; | |
6778 | ||
6779 | RGWDataChangesLog *log = store->data_log; | |
6780 | RGWDataChangesLog::LogMarker marker; | |
6781 | ||
6782 | do { | |
6783 | list<rgw_data_change_log_entry> entries; | |
6784 | ret = log->list_entries(start_time.to_real_time(), end_time.to_real_time(), max_entries - count, entries, marker, &truncated); | |
6785 | if (ret < 0) { | |
6786 | cerr << "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret) << std::endl; | |
6787 | return -ret; | |
6788 | } | |
6789 | ||
6790 | count += entries.size(); | |
6791 | ||
6792 | for (list<rgw_data_change_log_entry>::iterator iter = entries.begin(); iter != entries.end(); ++iter) { | |
6793 | rgw_data_change_log_entry& entry = *iter; | |
6794 | if (!extra_info) { | |
6795 | encode_json("entry", entry.entry, formatter); | |
6796 | } else { | |
6797 | encode_json("entry", entry, formatter); | |
6798 | } | |
6799 | } | |
6800 | formatter->flush(cout); | |
6801 | } while (truncated && count < max_entries); | |
6802 | ||
6803 | formatter->close_section(); | |
6804 | formatter->flush(cout); | |
6805 | } | |
6806 | ||
6807 | if (opt_cmd == OPT_DATALOG_STATUS) { | |
6808 | RGWDataChangesLog *log = store->data_log; | |
6809 | int i = (specified_shard_id ? shard_id : 0); | |
6810 | ||
6811 | formatter->open_array_section("entries"); | |
6812 | for (; i < g_ceph_context->_conf->rgw_data_log_num_shards; i++) { | |
6813 | list<cls_log_entry> entries; | |
6814 | ||
6815 | RGWDataChangesLogInfo info; | |
6816 | log->get_info(i, &info); | |
6817 | ||
6818 | ::encode_json("info", info, formatter); | |
6819 | ||
6820 | if (specified_shard_id) | |
6821 | break; | |
6822 | } | |
6823 | ||
6824 | formatter->close_section(); | |
6825 | formatter->flush(cout); | |
6826 | } | |
6827 | ||
6828 | if (opt_cmd == OPT_DATALOG_TRIM) { | |
6829 | utime_t start_time, end_time; | |
6830 | ||
6831 | int ret = parse_date_str(start_date, start_time); | |
6832 | if (ret < 0) | |
6833 | return -ret; | |
6834 | ||
6835 | ret = parse_date_str(end_date, end_time); | |
6836 | if (ret < 0) | |
6837 | return -ret; | |
6838 | ||
6839 | RGWDataChangesLog *log = store->data_log; | |
6840 | ret = log->trim_entries(start_time.to_real_time(), end_time.to_real_time(), start_marker, end_marker); | |
6841 | if (ret < 0) { | |
6842 | cerr << "ERROR: trim_entries(): " << cpp_strerror(-ret) << std::endl; | |
6843 | return -ret; | |
6844 | } | |
6845 | } | |
6846 | ||
6847 | if (opt_cmd == OPT_OPSTATE_LIST) { | |
6848 | RGWOpState oc(store); | |
6849 | ||
6850 | int max = 1000; | |
6851 | ||
6852 | void *handle; | |
6853 | oc.init_list_entries(client_id, op_id, object, &handle); | |
6854 | list<cls_statelog_entry> entries; | |
6855 | bool done; | |
6856 | formatter->open_array_section("entries"); | |
6857 | do { | |
6858 | int ret = oc.list_entries(handle, max, entries, &done); | |
6859 | if (ret < 0) { | |
6860 | cerr << "oc.list_entries returned " << cpp_strerror(-ret) << std::endl; | |
6861 | oc.finish_list_entries(handle); | |
6862 | return -ret; | |
6863 | } | |
6864 | ||
6865 | for (list<cls_statelog_entry>::iterator iter = entries.begin(); iter != entries.end(); ++iter) { | |
6866 | oc.dump_entry(*iter, formatter); | |
6867 | } | |
6868 | ||
6869 | formatter->flush(cout); | |
6870 | } while (!done); | |
6871 | formatter->close_section(); | |
6872 | formatter->flush(cout); | |
6873 | oc.finish_list_entries(handle); | |
6874 | } | |
6875 | ||
6876 | if (opt_cmd == OPT_OPSTATE_SET || opt_cmd == OPT_OPSTATE_RENEW) { | |
6877 | RGWOpState oc(store); | |
6878 | ||
6879 | RGWOpState::OpState state; | |
6880 | if (object.empty() || client_id.empty() || op_id.empty()) { | |
6881 | cerr << "ERROR: need to specify client_id, op_id, and object" << std::endl; | |
6882 | return EINVAL; | |
6883 | } | |
6884 | if (state_str.empty()) { | |
6885 | cerr << "ERROR: state was not specified" << std::endl; | |
6886 | return EINVAL; | |
6887 | } | |
6888 | int ret = oc.state_from_str(state_str, &state); | |
6889 | if (ret < 0) { | |
6890 | cerr << "ERROR: invalid state: " << state_str << std::endl; | |
6891 | return -ret; | |
6892 | } | |
6893 | ||
6894 | if (opt_cmd == OPT_OPSTATE_SET) { | |
6895 | ret = oc.set_state(client_id, op_id, object, state); | |
6896 | if (ret < 0) { | |
6897 | cerr << "ERROR: failed to set state: " << cpp_strerror(-ret) << std::endl; | |
6898 | return -ret; | |
6899 | } | |
6900 | } else { | |
6901 | ret = oc.renew_state(client_id, op_id, object, state); | |
6902 | if (ret < 0) { | |
6903 | cerr << "ERROR: failed to renew state: " << cpp_strerror(-ret) << std::endl; | |
6904 | return -ret; | |
6905 | } | |
6906 | } | |
6907 | } | |
6908 | if (opt_cmd == OPT_OPSTATE_RM) { | |
6909 | RGWOpState oc(store); | |
6910 | ||
6911 | if (object.empty() || client_id.empty() || op_id.empty()) { | |
6912 | cerr << "ERROR: need to specify client_id, op_id, and object" << std::endl; | |
6913 | return EINVAL; | |
6914 | } | |
6915 | ret = oc.remove_entry(client_id, op_id, object); | |
6916 | if (ret < 0) { | |
6917 | cerr << "ERROR: failed to set state: " << cpp_strerror(-ret) << std::endl; | |
6918 | return -ret; | |
6919 | } | |
6920 | } | |
6921 | ||
6922 | if (opt_cmd == OPT_REPLICALOG_GET || opt_cmd == OPT_REPLICALOG_UPDATE || | |
6923 | opt_cmd == OPT_REPLICALOG_DELETE) { | |
6924 | if (replica_log_type_str.empty()) { | |
6925 | cerr << "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl; | |
6926 | return EINVAL; | |
6927 | } | |
6928 | } | |
6929 | ||
6930 | if (opt_cmd == OPT_REPLICALOG_GET) { | |
6931 | RGWReplicaBounds bounds; | |
6932 | if (replica_log_type == ReplicaLog_Metadata) { | |
6933 | if (!specified_shard_id) { | |
6934 | cerr << "ERROR: shard-id must be specified for get operation" << std::endl; | |
6935 | return EINVAL; | |
6936 | } | |
6937 | ||
6938 | RGWReplicaObjectLogger logger(store, pool, META_REPLICA_LOG_OBJ_PREFIX); | |
6939 | int ret = logger.get_bounds(shard_id, bounds); | |
6940 | if (ret < 0) | |
6941 | return -ret; | |
6942 | } else if (replica_log_type == ReplicaLog_Data) { | |
6943 | if (!specified_shard_id) { | |
6944 | cerr << "ERROR: shard-id must be specified for get operation" << std::endl; | |
6945 | return EINVAL; | |
6946 | } | |
6947 | RGWReplicaObjectLogger logger(store, pool, DATA_REPLICA_LOG_OBJ_PREFIX); | |
6948 | int ret = logger.get_bounds(shard_id, bounds); | |
6949 | if (ret < 0) | |
6950 | return -ret; | |
6951 | } else if (replica_log_type == ReplicaLog_Bucket) { | |
6952 | if (bucket_name.empty()) { | |
6953 | cerr << "ERROR: bucket not specified" << std::endl; | |
6954 | return EINVAL; | |
6955 | } | |
6956 | RGWBucketInfo bucket_info; | |
6957 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
6958 | if (ret < 0) { | |
6959 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
6960 | return -ret; | |
6961 | } | |
6962 | ||
6963 | RGWReplicaBucketLogger logger(store); | |
6964 | ret = logger.get_bounds(bucket, shard_id, bounds); | |
6965 | if (ret < 0) | |
6966 | return -ret; | |
6967 | } else { // shouldn't get here | |
6968 | ceph_abort(); | |
6969 | } | |
6970 | encode_json("bounds", bounds, formatter); | |
6971 | formatter->flush(cout); | |
6972 | cout << std::endl; | |
6973 | } | |
6974 | ||
6975 | if (opt_cmd == OPT_REPLICALOG_DELETE) { | |
6976 | if (replica_log_type == ReplicaLog_Metadata) { | |
6977 | if (!specified_shard_id) { | |
6978 | cerr << "ERROR: shard-id must be specified for delete operation" << std::endl; | |
6979 | return EINVAL; | |
6980 | } | |
6981 | if (!specified_daemon_id) { | |
6982 | cerr << "ERROR: daemon-id must be specified for delete operation" << std::endl; | |
6983 | return EINVAL; | |
6984 | } | |
6985 | RGWReplicaObjectLogger logger(store, pool, META_REPLICA_LOG_OBJ_PREFIX); | |
6986 | int ret = logger.delete_bound(shard_id, daemon_id, false); | |
6987 | if (ret < 0) | |
6988 | return -ret; | |
6989 | } else if (replica_log_type == ReplicaLog_Data) { | |
6990 | if (!specified_shard_id) { | |
6991 | cerr << "ERROR: shard-id must be specified for delete operation" << std::endl; | |
6992 | return EINVAL; | |
6993 | } | |
6994 | if (!specified_daemon_id) { | |
6995 | cerr << "ERROR: daemon-id must be specified for delete operation" << std::endl; | |
6996 | return EINVAL; | |
6997 | } | |
6998 | RGWReplicaObjectLogger logger(store, pool, DATA_REPLICA_LOG_OBJ_PREFIX); | |
6999 | int ret = logger.delete_bound(shard_id, daemon_id, false); | |
7000 | if (ret < 0) | |
7001 | return -ret; | |
7002 | } else if (replica_log_type == ReplicaLog_Bucket) { | |
7003 | if (bucket_name.empty()) { | |
7004 | cerr << "ERROR: bucket not specified" << std::endl; | |
7005 | return EINVAL; | |
7006 | } | |
7007 | RGWBucketInfo bucket_info; | |
7008 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
7009 | if (ret < 0) { | |
7010 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
7011 | return -ret; | |
7012 | } | |
7013 | ||
7014 | RGWReplicaBucketLogger logger(store); | |
7015 | ret = logger.delete_bound(bucket, shard_id, daemon_id, false); | |
7016 | if (ret < 0) | |
7017 | return -ret; | |
7018 | } | |
7019 | } | |
7020 | ||
7021 | if (opt_cmd == OPT_REPLICALOG_UPDATE) { | |
7022 | if (marker.empty()) { | |
7023 | cerr << "ERROR: marker was not specified" <<std::endl; | |
7024 | return EINVAL; | |
7025 | } | |
7026 | utime_t time = ceph_clock_now(); | |
7027 | if (!date.empty()) { | |
7028 | ret = parse_date_str(date, time); | |
7029 | if (ret < 0) { | |
7030 | cerr << "ERROR: failed to parse start date" << std::endl; | |
7031 | return EINVAL; | |
7032 | } | |
7033 | } | |
7034 | list<RGWReplicaItemMarker> entries; | |
7035 | int ret = read_decode_json(infile, entries); | |
7036 | if (ret < 0) { | |
7037 | cerr << "ERROR: failed to decode entries" << std::endl; | |
7038 | return EINVAL; | |
7039 | } | |
7040 | RGWReplicaBounds bounds; | |
7041 | if (replica_log_type == ReplicaLog_Metadata) { | |
7042 | if (!specified_shard_id) { | |
7043 | cerr << "ERROR: shard-id must be specified for get operation" << std::endl; | |
7044 | return EINVAL; | |
7045 | } | |
7046 | ||
7047 | RGWReplicaObjectLogger logger(store, pool, META_REPLICA_LOG_OBJ_PREFIX); | |
7048 | int ret = logger.update_bound(shard_id, daemon_id, marker, time, &entries); | |
7049 | if (ret < 0) { | |
7050 | cerr << "ERROR: failed to update bounds: " << cpp_strerror(-ret) << std::endl; | |
7051 | return -ret; | |
7052 | } | |
7053 | } else if (replica_log_type == ReplicaLog_Data) { | |
7054 | if (!specified_shard_id) { | |
7055 | cerr << "ERROR: shard-id must be specified for get operation" << std::endl; | |
7056 | return EINVAL; | |
7057 | } | |
7058 | RGWReplicaObjectLogger logger(store, pool, DATA_REPLICA_LOG_OBJ_PREFIX); | |
7059 | int ret = logger.update_bound(shard_id, daemon_id, marker, time, &entries); | |
7060 | if (ret < 0) { | |
7061 | cerr << "ERROR: failed to update bounds: " << cpp_strerror(-ret) << std::endl; | |
7062 | return -ret; | |
7063 | } | |
7064 | } else if (replica_log_type == ReplicaLog_Bucket) { | |
7065 | if (bucket_name.empty()) { | |
7066 | cerr << "ERROR: bucket not specified" << std::endl; | |
7067 | return EINVAL; | |
7068 | } | |
7069 | RGWBucketInfo bucket_info; | |
7070 | int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket); | |
7071 | if (ret < 0) { | |
7072 | cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl; | |
7073 | return -ret; | |
7074 | } | |
7075 | ||
7076 | RGWReplicaBucketLogger logger(store); | |
7077 | ret = logger.update_bound(bucket, shard_id, daemon_id, marker, time, &entries); | |
7078 | if (ret < 0) { | |
7079 | cerr << "ERROR: failed to update bounds: " << cpp_strerror(-ret) << std::endl; | |
7080 | return -ret; | |
7081 | } | |
7082 | } | |
7083 | } | |
7084 | ||
7085 | bool quota_op = (opt_cmd == OPT_QUOTA_SET || opt_cmd == OPT_QUOTA_ENABLE || opt_cmd == OPT_QUOTA_DISABLE); | |
7086 | ||
7087 | if (quota_op) { | |
7088 | if (bucket_name.empty() && user_id.empty()) { | |
7089 | cerr << "ERROR: bucket name or uid is required for quota operation" << std::endl; | |
7090 | return EINVAL; | |
7091 | } | |
7092 | ||
7093 | if (!bucket_name.empty()) { | |
7094 | if (!quota_scope.empty() && quota_scope != "bucket") { | |
7095 | cerr << "ERROR: invalid quota scope specification." << std::endl; | |
7096 | return EINVAL; | |
7097 | } | |
7098 | set_bucket_quota(store, opt_cmd, tenant, bucket_name, | |
7099 | max_size, max_objects, have_max_size, have_max_objects); | |
7100 | } else if (!user_id.empty()) { | |
7101 | if (quota_scope == "bucket") { | |
7102 | set_user_bucket_quota(opt_cmd, user, user_op, max_size, max_objects, have_max_size, have_max_objects); | |
7103 | } else if (quota_scope == "user") { | |
7104 | set_user_quota(opt_cmd, user, user_op, max_size, max_objects, have_max_size, have_max_objects); | |
7105 | } else { | |
7106 | cerr << "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl; | |
7107 | return EINVAL; | |
7108 | } | |
7109 | } | |
7110 | } | |
7111 | ||
7112 | return 0; | |
7113 | } |