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