1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
9 #include <boost/optional.hpp>
11 #include "auth/Crypto.h"
12 #include "compressor/Compressor.h"
14 #include "common/armor.h"
15 #include "common/ceph_json.h"
16 #include "common/config.h"
17 #include "common/ceph_argparse.h"
18 #include "common/Formatter.h"
19 #include "common/errno.h"
20 #include "common/safe_io.h"
22 #include "cls/rgw/cls_rgw_client.h"
24 #include "global/global_init.h"
26 #include "include/utime.h"
27 #include "include/str_list.h"
30 #include "rgw_bucket.h"
31 #include "rgw_rados.h"
33 #include "rgw_acl_s3.h"
36 #include "rgw_formats.h"
37 #include "rgw_usage.h"
38 #include "rgw_replica_log.h"
39 #include "rgw_orphan.h"
41 #include "rgw_sync_log_trim.h"
42 #include "rgw_data_sync.h"
43 #include "rgw_rest_conn.h"
44 #include "rgw_realm_watcher.h"
46 #include "rgw_reshard.h"
47 #include "rgw_http_client_curl.h"
51 #define dout_context g_ceph_context
52 #define dout_subsys ceph_subsys_rgw
54 #define SECRET_KEY_LEN 40
55 #define PUBLIC_ID_LEN 20
57 static RGWRados
*store
= NULL
;
61 cout
<< "usage: radosgw-admin <cmd> [options...]" << std::endl
;
62 cout
<< "commands:\n";
63 cout
<< " user create create a new user\n" ;
64 cout
<< " user modify modify user\n";
65 cout
<< " user info get user info\n";
66 cout
<< " user rm remove user\n";
67 cout
<< " user suspend suspend a user\n";
68 cout
<< " user enable re-enable user after suspension\n";
69 cout
<< " user check check user info\n";
70 cout
<< " user stats show user stats as accounted by quota subsystem\n";
71 cout
<< " user list list users\n";
72 cout
<< " caps add add user capabilities\n";
73 cout
<< " caps rm remove user capabilities\n";
74 cout
<< " subuser create create a new subuser\n" ;
75 cout
<< " subuser modify modify subuser\n";
76 cout
<< " subuser rm remove subuser\n";
77 cout
<< " key create create access key\n";
78 cout
<< " key rm remove access key\n";
79 cout
<< " bucket list list buckets\n";
80 cout
<< " bucket limit check show bucket sharding stats\n";
81 cout
<< " bucket link link bucket to specified user\n";
82 cout
<< " bucket unlink unlink bucket from specified user\n";
83 cout
<< " bucket stats returns bucket statistics\n";
84 cout
<< " bucket rm remove bucket\n";
85 cout
<< " bucket check check bucket index\n";
86 cout
<< " bucket reshard reshard bucket\n";
87 cout
<< " bucket sync disable disable bucket sync\n";
88 cout
<< " bucket sync enable enable bucket sync\n";
89 cout
<< " bi get retrieve bucket index object entries\n";
90 cout
<< " bi put store bucket index object entries\n";
91 cout
<< " bi list list raw bucket index entries\n";
92 cout
<< " object rm remove object\n";
93 cout
<< " object stat stat an object for its metadata\n";
94 cout
<< " object unlink unlink object from bucket index\n";
95 cout
<< " objects expire run expired objects cleanup\n";
96 cout
<< " period delete delete a period\n";
97 cout
<< " period get get period info\n";
98 cout
<< " period get-current get current period info\n";
99 cout
<< " period pull pull a period\n";
100 cout
<< " period push push a period\n";
101 cout
<< " period list list all periods\n";
102 cout
<< " period update update the staging period\n";
103 cout
<< " period commit commit the staging period\n";
104 cout
<< " quota set set quota params\n";
105 cout
<< " quota enable enable quota\n";
106 cout
<< " quota disable disable quota\n";
107 cout
<< " global quota get view global quota params\n";
108 cout
<< " global quota set set global quota params\n";
109 cout
<< " global quota enable enable a global quota\n";
110 cout
<< " global quota disable disable a global quota\n";
111 cout
<< " realm create create a new realm\n";
112 cout
<< " realm delete delete a realm\n";
113 cout
<< " realm get show realm info\n";
114 cout
<< " realm get-default get default realm name\n";
115 cout
<< " realm list list realms\n";
116 cout
<< " realm list-periods list all realm periods\n";
117 cout
<< " realm remove remove a zonegroup from the realm\n";
118 cout
<< " realm rename rename a realm\n";
119 cout
<< " realm set set realm info (requires infile)\n";
120 cout
<< " realm default set realm as default\n";
121 cout
<< " realm pull pull a realm and its current period\n";
122 cout
<< " zonegroup add add a zone to a zonegroup\n";
123 cout
<< " zonegroup create create a new zone group info\n";
124 cout
<< " zonegroup default set default zone group\n";
125 cout
<< " zonegroup delete delete a zone group info\n";
126 cout
<< " zonegroup get show zone group info\n";
127 cout
<< " zonegroup modify modify an existing zonegroup\n";
128 cout
<< " zonegroup set set zone group info (requires infile)\n";
129 cout
<< " zonegroup remove remove a zone from a zonegroup\n";
130 cout
<< " zonegroup rename rename a zone group\n";
131 cout
<< " zonegroup list list all zone groups set on this cluster\n";
132 cout
<< " zonegroup placement list list zonegroup's placement targets\n";
133 cout
<< " zonegroup placement add add a placement target id to a zonegroup\n";
134 cout
<< " zonegroup placement modify modify a placement target of a specific zonegroup\n";
135 cout
<< " zonegroup placement rm remove a placement target from a zonegroup\n";
136 cout
<< " zonegroup placement default set a zonegroup's default placement target\n";
137 cout
<< " zone create create a new zone\n";
138 cout
<< " zone delete delete a zone\n";
139 cout
<< " zone get show zone cluster params\n";
140 cout
<< " zone modify modify an existing zone\n";
141 cout
<< " zone set set zone cluster params (requires infile)\n";
142 cout
<< " zone list list all zones set on this cluster\n";
143 cout
<< " zone rename rename a zone\n";
144 cout
<< " zone placement list list zone's placement targets\n";
145 cout
<< " zone placement add add a zone placement target\n";
146 cout
<< " zone placement modify modify a zone placement target\n";
147 cout
<< " zone placement rm remove a zone placement target\n";
148 cout
<< " pool add add an existing pool for data placement\n";
149 cout
<< " pool rm remove an existing pool from data placement set\n";
150 cout
<< " pools list list placement active set\n";
151 cout
<< " policy read bucket/object policy\n";
152 cout
<< " log list list log objects\n";
153 cout
<< " log show dump a log from specific object or (bucket + date\n";
154 cout
<< " + bucket-id)\n";
155 cout
<< " (NOTE: required to specify formatting of date\n";
156 cout
<< " to \"YYYY-MM-DD-hh\")\n";
157 cout
<< " log rm remove log object\n";
158 cout
<< " usage show show usage (by user, date range)\n";
159 cout
<< " usage trim trim usage (by user, date range)\n";
160 cout
<< " gc list dump expired garbage collection objects (specify\n";
161 cout
<< " --include-all to list all entries, including unexpired)\n";
162 cout
<< " gc process manually process garbage\n";
163 cout
<< " lc list list all bucket lifecycle progress\n";
164 cout
<< " lc process manually process lifecycle\n";
165 cout
<< " metadata get get metadata info\n";
166 cout
<< " metadata put put metadata info\n";
167 cout
<< " metadata rm remove metadata info\n";
168 cout
<< " metadata list list metadata info\n";
169 cout
<< " mdlog list list metadata log\n";
170 cout
<< " mdlog trim trim metadata log (use start-date, end-date or\n";
171 cout
<< " start-marker, end-marker)\n";
172 cout
<< " mdlog status read metadata log status\n";
173 cout
<< " bilog list list bucket index log\n";
174 cout
<< " bilog trim trim bucket index log (use start-marker, end-marker)\n";
175 cout
<< " datalog list list data log\n";
176 cout
<< " datalog trim trim data log\n";
177 cout
<< " datalog status read data log status\n";
178 cout
<< " opstate list list stateful operations entries (use client_id,\n";
179 cout
<< " op_id, object)\n";
180 cout
<< " opstate set set state on an entry (use client_id, op_id, object, state)\n";
181 cout
<< " opstate renew renew state on an entry (use client_id, op_id, object)\n";
182 cout
<< " opstate rm remove entry (use client_id, op_id, object)\n";
183 cout
<< " replicalog get get replica metadata log entry\n";
184 cout
<< " replicalog update update replica metadata log entry\n";
185 cout
<< " replicalog delete delete replica metadata log entry\n";
186 cout
<< " orphans find init and run search for leaked rados objects (use job-id, pool)\n";
187 cout
<< " orphans finish clean up search for leaked rados objects\n";
188 cout
<< " orphans list-jobs list the current job-ids for orphans search\n";
189 cout
<< " role create create a AWS role for use with STS\n";
190 cout
<< " role delete delete a role\n";
191 cout
<< " role get get a role\n";
192 cout
<< " role list list roles with specified path prefix\n";
193 cout
<< " role modify modify the assume role policy of an existing role\n";
194 cout
<< " role-policy put add/update permission policy to role\n";
195 cout
<< " role-policy list list policies attached to a role\n";
196 cout
<< " role-policy get get the specified inline policy document embedded with the given role\n";
197 cout
<< " role-policy delete delete policy attached to a role\n";
198 cout
<< " reshard add schedule a resharding of a bucket\n";
199 cout
<< " reshard list list all bucket resharding or scheduled to be reshared\n";
200 cout
<< " reshard process process of scheduled reshard jobs\n";
201 cout
<< " reshard cancel cancel resharding a bucket\n";
202 cout
<< " sync error list list sync error\n";
203 cout
<< " sync error trim trim sync error\n";
204 cout
<< "options:\n";
205 cout
<< " --tenant=<tenant> tenant name\n";
206 cout
<< " --uid=<id> user id\n";
207 cout
<< " --subuser=<name> subuser name\n";
208 cout
<< " --access-key=<key> S3 access key\n";
209 cout
<< " --email=<email>\n";
210 cout
<< " --secret/--secret-key=<key>\n";
211 cout
<< " specify secret key\n";
212 cout
<< " --gen-access-key generate random access key (for S3)\n";
213 cout
<< " --gen-secret generate random secret key\n";
214 cout
<< " --key-type=<type> key type, options are: swift, s3\n";
215 cout
<< " --temp-url-key[-2]=<key> temp url key\n";
216 cout
<< " --access=<access> Set access permissions for sub-user, should be one\n";
217 cout
<< " of read, write, readwrite, full\n";
218 cout
<< " --display-name=<name>\n";
219 cout
<< " --max-buckets max number of buckets for a user\n";
220 cout
<< " --admin set the admin flag on the user\n";
221 cout
<< " --system set the system flag on the user\n";
222 cout
<< " --bucket=<bucket> Specify the bucket name. Also used by the quota command.\n";
223 cout
<< " --pool=<pool> Specify the pool name. Also used to scan for leaked rados objects.\n";
224 cout
<< " --object=<object> object name\n";
225 cout
<< " --date=<date> date in the format yyyy-mm-dd\n";
226 cout
<< " --start-date=<date> start date in the format yyyy-mm-dd\n";
227 cout
<< " --end-date=<date> end date in the format yyyy-mm-dd\n";
228 cout
<< " --bucket-id=<bucket-id> bucket id\n";
229 cout
<< " --shard-id=<shard-id> optional for: \n";
230 cout
<< " mdlog list\n";
231 cout
<< " data sync status\n";
232 cout
<< " required for: \n";
233 cout
<< " mdlog trim\n";
234 cout
<< " replica mdlog get/delete\n";
235 cout
<< " replica datalog get/delete\n";
236 cout
<< " --max-entries=<entries> max entries for listing operations\n";
237 cout
<< " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
238 cout
<< " --remote=<remote> zone or zonegroup id of remote gateway\n";
239 cout
<< " --period=<id> period id\n";
240 cout
<< " --epoch=<number> period epoch\n";
241 cout
<< " --commit commit the period during 'period update'\n";
242 cout
<< " --staging get staging period info\n";
243 cout
<< " --master set as master\n";
244 cout
<< " --master-url master url\n";
245 cout
<< " --master-zonegroup=<id> master zonegroup id\n";
246 cout
<< " --master-zone=<id> master zone id\n";
247 cout
<< " --rgw-realm=<name> realm name\n";
248 cout
<< " --realm-id=<id> realm id\n";
249 cout
<< " --realm-new-name=<name> realm new name\n";
250 cout
<< " --rgw-zonegroup=<name> zonegroup name\n";
251 cout
<< " --zonegroup-id=<id> zonegroup id\n";
252 cout
<< " --zonegroup-new-name=<name>\n";
253 cout
<< " zonegroup new name\n";
254 cout
<< " --rgw-zone=<name> name of zone in which radosgw is running\n";
255 cout
<< " --zone-id=<id> zone id\n";
256 cout
<< " --zone-new-name=<name> zone new name\n";
257 cout
<< " --source-zone specify the source zone (for data sync)\n";
258 cout
<< " --default set entity (realm, zonegroup, zone) as default\n";
259 cout
<< " --read-only set zone as read-only (when adding to zonegroup)\n";
260 cout
<< " --placement-id placement id for zonegroup placement commands\n";
261 cout
<< " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
262 cout
<< " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
263 cout
<< " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
264 cout
<< " --endpoints=<list> zone endpoints\n";
265 cout
<< " --index-pool=<pool> placement target index pool\n";
266 cout
<< " --data-pool=<pool> placement target data pool\n";
267 cout
<< " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n";
268 cout
<< " --placement-index-type=<type>\n";
269 cout
<< " placement target index type (normal, indexless, or #id)\n";
270 cout
<< " --compression=<type> placement target compression type (plugin name or empty/none)\n";
271 cout
<< " --tier-type=<type> zone tier type\n";
272 cout
<< " --tier-config=<k>=<v>[,...]\n";
273 cout
<< " set zone tier config keys, values\n";
274 cout
<< " --tier-config-rm=<k>[,...]\n";
275 cout
<< " unset zone tier config keys\n";
276 cout
<< " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
277 cout
<< " --sync-from=[zone-name][,...]\n";
278 cout
<< " set list of zones to sync from\n";
279 cout
<< " --sync-from-rm=[zone-name][,...]\n";
280 cout
<< " remove zones from list of zones to sync from\n";
281 cout
<< " --fix besides checking bucket index, will also fix it\n";
282 cout
<< " --check-objects bucket check: rebuilds bucket index according to\n";
283 cout
<< " actual objects state\n";
284 cout
<< " --format=<format> specify output format for certain operations: xml,\n";
286 cout
<< " --purge-data when specified, user removal will also purge all the\n";
287 cout
<< " user data\n";
288 cout
<< " --purge-keys when specified, subuser removal will also purge all the\n";
289 cout
<< " subuser keys\n";
290 cout
<< " --purge-objects remove a bucket's objects before deleting it\n";
291 cout
<< " (NOTE: required to delete a non-empty bucket)\n";
292 cout
<< " --sync-stats option to 'user stats', update user stats with current\n";
293 cout
<< " stats reported by user's buckets indexes\n";
294 cout
<< " --reset-stats option to 'user stats', reset stats in accordance with user buckets\n";
295 cout
<< " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
296 cout
<< " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
297 cout
<< " --skip-zero-entries log show only dumps entries that don't have zero value\n";
298 cout
<< " in one of the numeric field\n";
299 cout
<< " --infile=<file> specify a file to read in when setting data\n";
300 cout
<< " --state=<state string> specify a state for the opstate set command\n";
301 cout
<< " --replica-log-type replica log type (metadata, data, bucket), required for\n";
302 cout
<< " replica log operations\n";
303 cout
<< " --categories=<list> comma separated list of categories, used in usage show\n";
304 cout
<< " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
305 cout
<< " --yes-i-really-mean-it required for certain operations\n";
306 cout
<< " --warnings-only when specified with bucket limit check, list\n";
307 cout
<< " only buckets nearing or over the current max\n";
308 cout
<< " objects per shard value\n";
309 cout
<< " --bypass-gc when specified with bucket deletion, triggers\n";
310 cout
<< " object deletions by not involving GC\n";
311 cout
<< " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
312 cout
<< " ignores bucket index consistency\n";
314 cout
<< "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
315 cout
<< "\nQuota options:\n";
316 cout
<< " --bucket specified bucket for quota command\n";
317 cout
<< " --max-objects specify max objects (negative value to disable)\n";
318 cout
<< " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
319 cout
<< " --quota-scope scope of quota (bucket, user)\n";
320 cout
<< "\nOrphans search options:\n";
321 cout
<< " --pool data pool to scan for leaked rados objects in\n";
322 cout
<< " --num-shards num of shards to use for keeping the temporary scan info\n";
323 cout
<< " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
324 cout
<< " --job-id set the job id (for orphans find)\n";
325 cout
<< " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
326 cout
<< "\nOrphans list-jobs options:\n";
327 cout
<< " --extra-info provide extra info in job list\n";
328 cout
<< "\nRole options:\n";
329 cout
<< " --role-name name of the role to create\n";
330 cout
<< " --path path to the role\n";
331 cout
<< " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
332 cout
<< " --policy-name name of the policy document\n";
333 cout
<< " --policy-doc permission policy document\n";
334 cout
<< " --path-prefix path prefix for filtering roles\n";
336 generic_client_usage();
356 OPT_BUCKET_LIMIT_CHECK
,
361 OPT_BUCKET_SYNC_STATUS
,
362 OPT_BUCKET_SYNC_MARKERS
,
363 OPT_BUCKET_SYNC_INIT
,
365 OPT_BUCKET_SYNC_DISABLE
,
366 OPT_BUCKET_SYNC_ENABLE
,
399 OPT_ORPHANS_LIST_JOBS
,
401 OPT_ZONEGROUP_CREATE
,
402 OPT_ZONEGROUP_DEFAULT
,
403 OPT_ZONEGROUP_DELETE
,
405 OPT_ZONEGROUP_MODIFY
,
408 OPT_ZONEGROUP_REMOVE
,
409 OPT_ZONEGROUP_RENAME
,
410 OPT_ZONEGROUP_PLACEMENT_ADD
,
411 OPT_ZONEGROUP_PLACEMENT_MODIFY
,
412 OPT_ZONEGROUP_PLACEMENT_RM
,
413 OPT_ZONEGROUP_PLACEMENT_LIST
,
414 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
423 OPT_ZONE_PLACEMENT_ADD
,
424 OPT_ZONE_PLACEMENT_MODIFY
,
425 OPT_ZONE_PLACEMENT_RM
,
426 OPT_ZONE_PLACEMENT_LIST
,
433 OPT_METADATA_SYNC_STATUS
,
434 OPT_METADATA_SYNC_INIT
,
435 OPT_METADATA_SYNC_RUN
,
447 OPT_DATA_SYNC_STATUS
,
458 OPT_REPLICALOG_UPDATE
,
459 OPT_REPLICALOG_DELETE
,
463 OPT_REALM_GET_DEFAULT
,
465 OPT_REALM_LIST_PERIODS
,
473 OPT_PERIOD_GET_CURRENT
,
479 OPT_GLOBAL_QUOTA_GET
,
480 OPT_GLOBAL_QUOTA_SET
,
481 OPT_GLOBAL_QUOTA_ENABLE
,
482 OPT_GLOBAL_QUOTA_DISABLE
,
490 OPT_ROLE_POLICY_LIST
,
492 OPT_ROLE_POLICY_DELETE
,
500 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
503 // NOTE: please keep the checks in alphabetical order !!!
504 if (strcmp(cmd
, "bi") == 0 ||
505 strcmp(cmd
, "bilog") == 0 ||
506 strcmp(cmd
, "buckets") == 0 ||
507 strcmp(cmd
, "caps") == 0 ||
508 strcmp(cmd
, "data") == 0 ||
509 strcmp(cmd
, "datalog") == 0 ||
510 strcmp(cmd
, "error") == 0 ||
511 strcmp(cmd
, "gc") == 0 ||
512 strcmp(cmd
, "global") == 0 ||
513 strcmp(cmd
, "key") == 0 ||
514 strcmp(cmd
, "log") == 0 ||
515 strcmp(cmd
, "lc") == 0 ||
516 strcmp(cmd
, "mdlog") == 0 ||
517 strcmp(cmd
, "metadata") == 0 ||
518 strcmp(cmd
, "object") == 0 ||
519 strcmp(cmd
, "objects") == 0 ||
520 strcmp(cmd
, "olh") == 0 ||
521 strcmp(cmd
, "opstate") == 0 ||
522 strcmp(cmd
, "orphans") == 0 ||
523 strcmp(cmd
, "period") == 0 ||
524 strcmp(cmd
, "placement") == 0 ||
525 strcmp(cmd
, "pool") == 0 ||
526 strcmp(cmd
, "pools") == 0 ||
527 strcmp(cmd
, "quota") == 0 ||
528 strcmp(cmd
, "realm") == 0 ||
529 strcmp(cmd
, "replicalog") == 0 ||
530 strcmp(cmd
, "role") == 0 ||
531 strcmp(cmd
, "role-policy") == 0 ||
532 strcmp(cmd
, "subuser") == 0 ||
533 strcmp(cmd
, "sync") == 0 ||
534 strcmp(cmd
, "usage") == 0 ||
535 strcmp(cmd
, "user") == 0 ||
536 strcmp(cmd
, "zone") == 0 ||
537 strcmp(cmd
, "zonegroup") == 0 ||
538 strcmp(cmd
, "zonegroups") == 0) {
544 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
546 if (strcmp(cmd
, "reshard") == 0 &&
547 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
551 if (strcmp(cmd
, "bucket") == 0 &&
552 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
557 if (strcmp(cmd
, "policy") == 0)
563 if (strcmp(prev_cmd
, "user") == 0) {
564 if (strcmp(cmd
, "create") == 0)
565 return OPT_USER_CREATE
;
566 if (strcmp(cmd
, "info") == 0)
567 return OPT_USER_INFO
;
568 if (strcmp(cmd
, "modify") == 0)
569 return OPT_USER_MODIFY
;
570 if (strcmp(cmd
, "rm") == 0)
572 if (strcmp(cmd
, "suspend") == 0)
573 return OPT_USER_SUSPEND
;
574 if (strcmp(cmd
, "enable") == 0)
575 return OPT_USER_ENABLE
;
576 if (strcmp(cmd
, "check") == 0)
577 return OPT_USER_CHECK
;
578 if (strcmp(cmd
, "stats") == 0)
579 return OPT_USER_STATS
;
580 if (strcmp(cmd
, "list") == 0)
581 return OPT_USER_LIST
;
582 } else if (strcmp(prev_cmd
, "subuser") == 0) {
583 if (strcmp(cmd
, "create") == 0)
584 return OPT_SUBUSER_CREATE
;
585 if (strcmp(cmd
, "modify") == 0)
586 return OPT_SUBUSER_MODIFY
;
587 if (strcmp(cmd
, "rm") == 0)
588 return OPT_SUBUSER_RM
;
589 } else if (strcmp(prev_cmd
, "key") == 0) {
590 if (strcmp(cmd
, "create") == 0)
591 return OPT_KEY_CREATE
;
592 if (strcmp(cmd
, "rm") == 0)
594 } else if (strcmp(prev_cmd
, "buckets") == 0) {
595 if (strcmp(cmd
, "list") == 0)
596 return OPT_BUCKETS_LIST
;
597 } else if (strcmp(prev_cmd
, "bucket") == 0) {
598 if (strcmp(cmd
, "list") == 0)
599 return OPT_BUCKETS_LIST
;
600 if (strcmp(cmd
, "link") == 0)
601 return OPT_BUCKET_LINK
;
602 if (strcmp(cmd
, "unlink") == 0)
603 return OPT_BUCKET_UNLINK
;
604 if (strcmp(cmd
, "stats") == 0)
605 return OPT_BUCKET_STATS
;
606 if (strcmp(cmd
, "rm") == 0)
607 return OPT_BUCKET_RM
;
608 if (strcmp(cmd
, "rewrite") == 0)
609 return OPT_BUCKET_REWRITE
;
610 if (strcmp(cmd
, "reshard") == 0)
611 return OPT_BUCKET_RESHARD
;
612 if (strcmp(cmd
, "check") == 0)
613 return OPT_BUCKET_CHECK
;
614 if (strcmp(cmd
, "sync") == 0) {
618 if (strcmp(cmd
, "limit") == 0) {
622 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
623 if (strcmp(prev_cmd
, "sync") == 0) {
624 if (strcmp(cmd
, "status") == 0)
625 return OPT_BUCKET_SYNC_STATUS
;
626 if (strcmp(cmd
, "markers") == 0)
627 return OPT_BUCKET_SYNC_MARKERS
;
628 if (strcmp(cmd
, "init") == 0)
629 return OPT_BUCKET_SYNC_INIT
;
630 if (strcmp(cmd
, "run") == 0)
631 return OPT_BUCKET_SYNC_RUN
;
632 if (strcmp(cmd
, "disable") == 0)
633 return OPT_BUCKET_SYNC_DISABLE
;
634 if (strcmp(cmd
, "enable") == 0)
635 return OPT_BUCKET_SYNC_ENABLE
;
636 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
637 (strcmp(cmd
, "check") == 0)) {
638 return OPT_BUCKET_LIMIT_CHECK
;
640 } else if (strcmp(prev_cmd
, "log") == 0) {
641 if (strcmp(cmd
, "list") == 0)
643 if (strcmp(cmd
, "show") == 0)
645 if (strcmp(cmd
, "rm") == 0)
647 } else if (strcmp(prev_cmd
, "usage") == 0) {
648 if (strcmp(cmd
, "show") == 0)
649 return OPT_USAGE_SHOW
;
650 if (strcmp(cmd
, "trim") == 0)
651 return OPT_USAGE_TRIM
;
652 } else if (strcmp(prev_cmd
, "caps") == 0) {
653 if (strcmp(cmd
, "add") == 0)
655 if (strcmp(cmd
, "rm") == 0)
657 } else if (strcmp(prev_cmd
, "pool") == 0) {
658 if (strcmp(cmd
, "add") == 0)
660 if (strcmp(cmd
, "rm") == 0)
662 if (strcmp(cmd
, "list") == 0)
663 return OPT_POOLS_LIST
;
664 } else if (strcmp(prev_cmd
, "pools") == 0) {
665 if (strcmp(cmd
, "list") == 0)
666 return OPT_POOLS_LIST
;
667 } else if (strcmp(prev_cmd
, "object") == 0) {
668 if (strcmp(cmd
, "rm") == 0)
669 return OPT_OBJECT_RM
;
670 if (strcmp(cmd
, "unlink") == 0)
671 return OPT_OBJECT_UNLINK
;
672 if (strcmp(cmd
, "stat") == 0)
673 return OPT_OBJECT_STAT
;
674 if (strcmp(cmd
, "rewrite") == 0)
675 return OPT_OBJECT_REWRITE
;
676 } else if (strcmp(prev_cmd
, "objects") == 0) {
677 if (strcmp(cmd
, "expire") == 0)
678 return OPT_OBJECTS_EXPIRE
;
679 } else if (strcmp(prev_cmd
, "olh") == 0) {
680 if (strcmp(cmd
, "get") == 0)
682 if (strcmp(cmd
, "readlog") == 0)
683 return OPT_OLH_READLOG
;
684 } else if (strcmp(prev_cmd
, "bi") == 0) {
685 if (strcmp(cmd
, "get") == 0)
687 if (strcmp(cmd
, "put") == 0)
689 if (strcmp(cmd
, "list") == 0)
691 if (strcmp(cmd
, "purge") == 0)
693 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
694 (strcmp(prev_cmd
, "quota") == 0)) {
695 if (strcmp(cmd
, "get") == 0)
696 return OPT_GLOBAL_QUOTA_GET
;
697 if (strcmp(cmd
, "set") == 0)
698 return OPT_GLOBAL_QUOTA_SET
;
699 if (strcmp(cmd
, "enable") == 0)
700 return OPT_GLOBAL_QUOTA_ENABLE
;
701 if (strcmp(cmd
, "disable") == 0)
702 return OPT_GLOBAL_QUOTA_DISABLE
;
703 } else if (strcmp(prev_cmd
, "period") == 0) {
704 if (strcmp(cmd
, "delete") == 0)
705 return OPT_PERIOD_DELETE
;
706 if (strcmp(cmd
, "get") == 0)
707 return OPT_PERIOD_GET
;
708 if (strcmp(cmd
, "get-current") == 0)
709 return OPT_PERIOD_GET_CURRENT
;
710 if (strcmp(cmd
, "pull") == 0)
711 return OPT_PERIOD_PULL
;
712 if (strcmp(cmd
, "push") == 0)
713 return OPT_PERIOD_PUSH
;
714 if (strcmp(cmd
, "list") == 0)
715 return OPT_PERIOD_LIST
;
716 if (strcmp(cmd
, "update") == 0)
717 return OPT_PERIOD_UPDATE
;
718 if (strcmp(cmd
, "commit") == 0)
719 return OPT_PERIOD_COMMIT
;
720 } else if (strcmp(prev_cmd
, "realm") == 0) {
721 if (strcmp(cmd
, "create") == 0)
722 return OPT_REALM_CREATE
;
723 if (strcmp(cmd
, "delete") == 0)
724 return OPT_REALM_DELETE
;
725 if (strcmp(cmd
, "get") == 0)
726 return OPT_REALM_GET
;
727 if (strcmp(cmd
, "get-default") == 0)
728 return OPT_REALM_GET_DEFAULT
;
729 if (strcmp(cmd
, "list") == 0)
730 return OPT_REALM_LIST
;
731 if (strcmp(cmd
, "list-periods") == 0)
732 return OPT_REALM_LIST_PERIODS
;
733 if (strcmp(cmd
, "remove") == 0)
734 return OPT_REALM_REMOVE
;
735 if (strcmp(cmd
, "rename") == 0)
736 return OPT_REALM_RENAME
;
737 if (strcmp(cmd
, "set") == 0)
738 return OPT_REALM_SET
;
739 if (strcmp(cmd
, "default") == 0)
740 return OPT_REALM_DEFAULT
;
741 if (strcmp(cmd
, "pull") == 0)
742 return OPT_REALM_PULL
;
743 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
744 (strcmp(prev_cmd
, "placement") == 0)) {
745 if (strcmp(cmd
, "add") == 0)
746 return OPT_ZONEGROUP_PLACEMENT_ADD
;
747 if (strcmp(cmd
, "modify") == 0)
748 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
749 if (strcmp(cmd
, "rm") == 0)
750 return OPT_ZONEGROUP_PLACEMENT_RM
;
751 if (strcmp(cmd
, "list") == 0)
752 return OPT_ZONEGROUP_PLACEMENT_LIST
;
753 if (strcmp(cmd
, "default") == 0)
754 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
755 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
756 if (strcmp(cmd
, "add") == 0)
757 return OPT_ZONEGROUP_ADD
;
758 if (strcmp(cmd
, "create")== 0)
759 return OPT_ZONEGROUP_CREATE
;
760 if (strcmp(cmd
, "default") == 0)
761 return OPT_ZONEGROUP_DEFAULT
;
762 if (strcmp(cmd
, "delete") == 0)
763 return OPT_ZONEGROUP_DELETE
;
764 if (strcmp(cmd
, "get") == 0)
765 return OPT_ZONEGROUP_GET
;
766 if (strcmp(cmd
, "modify") == 0)
767 return OPT_ZONEGROUP_MODIFY
;
768 if (strcmp(cmd
, "list") == 0)
769 return OPT_ZONEGROUP_LIST
;
770 if (strcmp(cmd
, "set") == 0)
771 return OPT_ZONEGROUP_SET
;
772 if (strcmp(cmd
, "remove") == 0)
773 return OPT_ZONEGROUP_REMOVE
;
774 if (strcmp(cmd
, "rename") == 0)
775 return OPT_ZONEGROUP_RENAME
;
776 } else if (strcmp(prev_cmd
, "quota") == 0) {
777 if (strcmp(cmd
, "set") == 0)
778 return OPT_QUOTA_SET
;
779 if (strcmp(cmd
, "enable") == 0)
780 return OPT_QUOTA_ENABLE
;
781 if (strcmp(cmd
, "disable") == 0)
782 return OPT_QUOTA_DISABLE
;
783 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
784 if (strcmp(cmd
, "list") == 0)
785 return OPT_ZONEGROUP_LIST
;
786 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
787 (strcmp(prev_cmd
, "placement") == 0)) {
788 if (strcmp(cmd
, "add") == 0)
789 return OPT_ZONE_PLACEMENT_ADD
;
790 if (strcmp(cmd
, "modify") == 0)
791 return OPT_ZONE_PLACEMENT_MODIFY
;
792 if (strcmp(cmd
, "rm") == 0)
793 return OPT_ZONE_PLACEMENT_RM
;
794 if (strcmp(cmd
, "list") == 0)
795 return OPT_ZONE_PLACEMENT_LIST
;
796 } else if (strcmp(prev_cmd
, "zone") == 0) {
797 if (strcmp(cmd
, "delete") == 0)
798 return OPT_ZONE_DELETE
;
799 if (strcmp(cmd
, "create") == 0)
800 return OPT_ZONE_CREATE
;
801 if (strcmp(cmd
, "get") == 0)
803 if (strcmp(cmd
, "set") == 0)
805 if (strcmp(cmd
, "list") == 0)
806 return OPT_ZONE_LIST
;
807 if (strcmp(cmd
, "modify") == 0)
808 return OPT_ZONE_MODIFY
;
809 if (strcmp(cmd
, "rename") == 0)
810 return OPT_ZONE_RENAME
;
811 if (strcmp(cmd
, "default") == 0)
812 return OPT_ZONE_DEFAULT
;
813 } else if (strcmp(prev_cmd
, "zones") == 0) {
814 if (strcmp(cmd
, "list") == 0)
815 return OPT_ZONE_LIST
;
816 } else if (strcmp(prev_cmd
, "gc") == 0) {
817 if (strcmp(cmd
, "list") == 0)
819 if (strcmp(cmd
, "process") == 0)
820 return OPT_GC_PROCESS
;
821 } else if (strcmp(prev_cmd
, "lc") == 0) {
822 if (strcmp(cmd
, "list") == 0)
824 if (strcmp(cmd
, "process") == 0)
825 return OPT_LC_PROCESS
;
826 } else if (strcmp(prev_cmd
, "orphans") == 0) {
827 if (strcmp(cmd
, "find") == 0)
828 return OPT_ORPHANS_FIND
;
829 if (strcmp(cmd
, "finish") == 0)
830 return OPT_ORPHANS_FINISH
;
831 if (strcmp(cmd
, "list-jobs") == 0)
832 return OPT_ORPHANS_LIST_JOBS
;
833 } else if (strcmp(prev_cmd
, "metadata") == 0) {
834 if (strcmp(cmd
, "get") == 0)
835 return OPT_METADATA_GET
;
836 if (strcmp(cmd
, "put") == 0)
837 return OPT_METADATA_PUT
;
838 if (strcmp(cmd
, "rm") == 0)
839 return OPT_METADATA_RM
;
840 if (strcmp(cmd
, "list") == 0)
841 return OPT_METADATA_LIST
;
842 if (strcmp(cmd
, "sync") == 0) {
846 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
847 (strcmp(prev_cmd
, "sync") == 0)) {
848 if (strcmp(cmd
, "status") == 0)
849 return OPT_METADATA_SYNC_STATUS
;
850 if (strcmp(cmd
, "init") == 0)
851 return OPT_METADATA_SYNC_INIT
;
852 if (strcmp(cmd
, "run") == 0)
853 return OPT_METADATA_SYNC_RUN
;
854 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
855 (strcmp(prev_cmd
, "error") == 0)) {
856 if (strcmp(cmd
, "list") == 0)
857 return OPT_SYNC_ERROR_LIST
;
858 if (strcmp(cmd
, "trim") == 0)
859 return OPT_SYNC_ERROR_TRIM
;
860 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
861 if (strcmp(cmd
, "list") == 0)
862 return OPT_MDLOG_LIST
;
863 if (strcmp(cmd
, "autotrim") == 0)
864 return OPT_MDLOG_AUTOTRIM
;
865 if (strcmp(cmd
, "trim") == 0)
866 return OPT_MDLOG_TRIM
;
867 if (strcmp(cmd
, "fetch") == 0)
868 return OPT_MDLOG_FETCH
;
869 if (strcmp(cmd
, "status") == 0)
870 return OPT_MDLOG_STATUS
;
871 } else if (strcmp(prev_cmd
, "bilog") == 0) {
872 if (strcmp(cmd
, "list") == 0)
873 return OPT_BILOG_LIST
;
874 if (strcmp(cmd
, "trim") == 0)
875 return OPT_BILOG_TRIM
;
876 if (strcmp(cmd
, "status") == 0)
877 return OPT_BILOG_STATUS
;
878 if (strcmp(cmd
, "autotrim") == 0)
879 return OPT_BILOG_AUTOTRIM
;
880 } else if (strcmp(prev_cmd
, "data") == 0) {
881 if (strcmp(cmd
, "sync") == 0) {
885 } else if (strcmp(prev_cmd
, "datalog") == 0) {
886 if (strcmp(cmd
, "list") == 0)
887 return OPT_DATALOG_LIST
;
888 if (strcmp(cmd
, "trim") == 0)
889 return OPT_DATALOG_TRIM
;
890 if (strcmp(cmd
, "status") == 0)
891 return OPT_DATALOG_STATUS
;
892 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
893 (strcmp(prev_cmd
, "sync") == 0)) {
894 if (strcmp(cmd
, "status") == 0)
895 return OPT_DATA_SYNC_STATUS
;
896 if (strcmp(cmd
, "init") == 0)
897 return OPT_DATA_SYNC_INIT
;
898 if (strcmp(cmd
, "run") == 0)
899 return OPT_DATA_SYNC_RUN
;
900 } else if (strcmp(prev_cmd
, "opstate") == 0) {
901 if (strcmp(cmd
, "list") == 0)
902 return OPT_OPSTATE_LIST
;
903 if (strcmp(cmd
, "set") == 0)
904 return OPT_OPSTATE_SET
;
905 if (strcmp(cmd
, "renew") == 0)
906 return OPT_OPSTATE_RENEW
;
907 if (strcmp(cmd
, "rm") == 0)
908 return OPT_OPSTATE_RM
;
909 } else if (strcmp(prev_cmd
, "replicalog") == 0) {
910 if (strcmp(cmd
, "get") == 0)
911 return OPT_REPLICALOG_GET
;
912 if (strcmp(cmd
, "update") == 0)
913 return OPT_REPLICALOG_UPDATE
;
914 if (strcmp(cmd
, "delete") == 0)
915 return OPT_REPLICALOG_DELETE
;
916 } else if (strcmp(prev_cmd
, "sync") == 0) {
917 if (strcmp(cmd
, "status") == 0)
918 return OPT_SYNC_STATUS
;
919 } else if (strcmp(prev_cmd
, "role") == 0) {
920 if (strcmp(cmd
, "create") == 0)
921 return OPT_ROLE_CREATE
;
922 if (strcmp(cmd
, "delete") == 0)
923 return OPT_ROLE_DELETE
;
924 if (strcmp(cmd
, "get") == 0)
926 if (strcmp(cmd
, "modify") == 0)
927 return OPT_ROLE_MODIFY
;
928 if (strcmp(cmd
, "list") == 0)
929 return OPT_ROLE_LIST
;
930 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
931 if (strcmp(cmd
, "put") == 0)
932 return OPT_ROLE_POLICY_PUT
;
933 if (strcmp(cmd
, "list") == 0)
934 return OPT_ROLE_POLICY_LIST
;
935 if (strcmp(cmd
, "get") == 0)
936 return OPT_ROLE_POLICY_GET
;
937 if (strcmp(cmd
, "delete") == 0)
938 return OPT_ROLE_POLICY_DELETE
;
939 } else if (strcmp(prev_cmd
, "reshard") == 0) {
940 if (strcmp(cmd
, "bucket") == 0)
941 return OPT_BUCKET_RESHARD
;
942 if (strcmp(cmd
, "add") == 0)
943 return OPT_RESHARD_ADD
;
944 if (strcmp(cmd
, "list") == 0)
945 return OPT_RESHARD_LIST
;
946 if (strcmp(cmd
, "status") == 0)
947 return OPT_RESHARD_STATUS
;
948 if (strcmp(cmd
, "process") == 0)
949 return OPT_RESHARD_PROCESS
;
950 if (strcmp(cmd
, "cancel") == 0)
951 return OPT_RESHARD_CANCEL
;
957 enum ReplicaLogType
{
958 ReplicaLog_Invalid
= 0,
964 ReplicaLogType
get_replicalog_type(const string
& name
) {
965 if (name
== "md" || name
== "meta" || name
== "metadata")
966 return ReplicaLog_Metadata
;
968 return ReplicaLog_Data
;
969 if (name
== "bucket")
970 return ReplicaLog_Bucket
;
972 return ReplicaLog_Invalid
;
975 BIIndexType
get_bi_index_type(const string
& type_str
) {
976 if (type_str
== "plain")
978 if (type_str
== "instance")
980 if (type_str
== "olh")
986 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
988 bufferlist::iterator iter
= bl
.begin();
989 switch (index_type
) {
993 rgw_bucket_dir_entry entry
;
994 ::decode(entry
, iter
);
995 encode_json("entry", entry
, formatter
);
1000 rgw_bucket_olh_entry entry
;
1001 ::decode(entry
, iter
);
1002 encode_json("entry", entry
, formatter
);
1011 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
1013 encode_json("user_info", info
, formatter
);
1014 formatter
->flush(cout
);
1018 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1020 formatter
->open_object_section("role");
1021 formatter
->dump_string("Permission policy", perm_policy
);
1022 formatter
->close_section();
1023 formatter
->flush(cout
);
1026 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1028 formatter
->open_array_section("PolicyNames");
1029 for (const auto& it
: policy_names
) {
1030 formatter
->dump_string("policyname", it
);
1032 formatter
->close_section();
1033 formatter
->flush(cout
);
1036 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1038 formatter
->open_object_section("role");
1039 role
.dump(formatter
);
1040 formatter
->close_section();
1041 formatter
->flush(cout
);
1044 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1046 formatter
->open_array_section("Roles");
1047 for (const auto& it
: roles
) {
1048 formatter
->open_object_section("role");
1050 formatter
->close_section();
1052 formatter
->close_section();
1053 formatter
->flush(cout
);
1056 class StoreDestructor
{
1059 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1060 ~StoreDestructor() {
1061 RGWStoreManager::close_storage(store
);
1065 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1066 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1068 if (!bucket_name
.empty()) {
1069 RGWObjectCtx
obj_ctx(store
);
1071 if (bucket_id
.empty()) {
1072 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1074 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1075 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1078 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1081 bucket
= bucket_info
.bucket
;
1086 static int read_input(const string
& infile
, bufferlist
& bl
)
1089 if (infile
.size()) {
1090 fd
= open(infile
.c_str(), O_RDONLY
);
1093 cerr
<< "error reading input file " << infile
<< std::endl
;
1098 #define READ_CHUNK 8196
1103 char buf
[READ_CHUNK
];
1105 r
= safe_read(fd
, buf
, READ_CHUNK
);
1108 cerr
<< "error while reading input" << std::endl
;
1116 if (infile
.size()) {
1123 static int read_decode_json(const string
& infile
, T
& t
)
1126 int ret
= read_input(infile
, bl
);
1128 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1132 if (!p
.parse(bl
.c_str(), bl
.length())) {
1133 cout
<< "failed to parse JSON" << std::endl
;
1138 decode_json_obj(t
, &p
);
1139 } catch (JSONDecoder::err
& e
) {
1140 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1146 template <class T
, class K
>
1147 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1150 int ret
= read_input(infile
, bl
);
1152 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1156 if (!p
.parse(bl
.c_str(), bl
.length())) {
1157 cout
<< "failed to parse JSON" << std::endl
;
1162 t
.decode_json(&p
, k
);
1163 } catch (JSONDecoder::err
& e
) {
1164 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1170 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1175 if (!date_str
.empty()) {
1176 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1178 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1183 ut
= utime_t(epoch
, nsec
);
1189 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1193 bufferlist::iterator iter
= bl
.begin();
1197 } catch (buffer::error
& err
) {
1201 encode_json(field_name
, t
, f
);
1206 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1209 if (bl
.length() > 0) {
1210 val
.assign(bl
.c_str());
1212 f
->dump_string(field_name
, val
);
1217 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1218 bool have_max_size
, bool have_max_objects
)
1221 case OPT_QUOTA_ENABLE
:
1222 case OPT_GLOBAL_QUOTA_ENABLE
:
1223 quota
.enabled
= true;
1225 // falling through on purpose
1228 case OPT_GLOBAL_QUOTA_SET
:
1229 if (have_max_objects
) {
1230 if (max_objects
< 0) {
1231 quota
.max_objects
= -1;
1233 quota
.max_objects
= max_objects
;
1236 if (have_max_size
) {
1238 quota
.max_size
= -1;
1240 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1244 case OPT_QUOTA_DISABLE
:
1245 case OPT_GLOBAL_QUOTA_DISABLE
:
1246 quota
.enabled
= false;
1251 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1252 const string
& tenant_name
, const string
& bucket_name
,
1253 int64_t max_size
, int64_t max_objects
,
1254 bool have_max_size
, bool have_max_objects
)
1256 RGWBucketInfo bucket_info
;
1257 map
<string
, bufferlist
> attrs
;
1258 RGWObjectCtx
obj_ctx(store
);
1259 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1261 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1265 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1267 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1269 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1275 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1276 bool have_max_size
, bool have_max_objects
)
1278 RGWUserInfo
& user_info
= op_state
.get_user_info();
1280 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1282 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1285 int r
= user
.modify(op_state
, &err
);
1287 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1293 int set_user_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1294 bool have_max_size
, bool have_max_objects
)
1296 RGWUserInfo
& user_info
= op_state
.get_user_info();
1298 set_quota_info(user_info
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1300 op_state
.set_user_quota(user_info
.user_quota
);
1303 int r
= user
.modify(op_state
, &err
);
1305 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1311 static bool bucket_object_check_filter(const string
& name
)
1314 string ns
; /* empty namespace */
1315 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1318 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1320 map
<string
, bufferlist
> attrs
;
1323 RGWObjectCtx
obj_ctx(store
);
1324 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1325 RGWRados::Object::Read
read_op(&op_target
);
1327 read_op
.params
.attrs
= &attrs
;
1328 read_op
.params
.obj_size
= &obj_size
;
1330 int ret
= read_op
.prepare();
1332 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1336 map
<string
, bufferlist
>::iterator iter
;
1337 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1338 if (iter
== attrs
.end()) {
1339 *need_rewrite
= (obj_size
>= min_stripe_size
);
1343 RGWObjManifest manifest
;
1346 bufferlist
& bl
= iter
->second
;
1347 bufferlist::iterator biter
= bl
.begin();
1348 ::decode(manifest
, biter
);
1349 } catch (buffer::error
& err
) {
1350 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1354 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1355 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1356 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1357 RGWObjManifestPart
& part
= oiter
->second
;
1359 if (part
.size
>= min_stripe_size
) {
1360 *need_rewrite
= true;
1364 *need_rewrite
= false;
1370 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1371 f
->open_object_section("object");
1372 f
->open_object_section("key");
1373 f
->dump_string("type", "head");
1374 f
->dump_string("name", key
.name
);
1375 f
->dump_string("instance", key
.instance
);
1381 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1383 f
->dump_string("oid", oid
);
1384 f
->dump_string("locator", locator
);
1387 RGWObjectCtx
obj_ctx(store
);
1389 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1390 RGWRados::Object::Read
read_op(&op_target
);
1392 int ret
= read_op
.prepare();
1393 bool needs_fixing
= (ret
== -ENOENT
);
1395 f
->dump_bool("needs_fixing", needs_fixing
);
1397 string status
= (needs_fixing
? "needs_fixing" : "ok");
1399 if ((needs_fixing
|| remove_bad
) && fix
) {
1400 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1402 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1409 f
->dump_string("status", status
);
1416 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1417 f
->open_object_section("object");
1418 f
->open_object_section("key");
1419 f
->dump_string("type", "tail");
1420 f
->dump_string("name", key
.name
);
1421 f
->dump_string("instance", key
.instance
);
1427 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1429 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1432 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1435 f
->dump_bool("needs_fixing", needs_fixing
);
1436 f
->dump_string("status", status
);
1443 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1444 bool fix
, bool remove_bad
, Formatter
*f
)
1446 if (remove_bad
&& !fix
) {
1447 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1451 RGWBucketInfo bucket_info
;
1455 f
->open_object_section("bucket");
1456 f
->dump_string("bucket", bucket_name
);
1457 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1459 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1465 int max_entries
= 1000;
1469 vector
<rgw_bucket_dir_entry
> result
;
1470 map
<string
, bool> common_prefixes
;
1473 RGWRados::Bucket
target(store
, bucket_info
);
1474 RGWRados::Bucket::List
list_op(&target
);
1478 list_op
.params
.prefix
= prefix
;
1479 list_op
.params
.delim
= delim
;
1480 list_op
.params
.marker
= rgw_obj_key(marker
);
1481 list_op
.params
.ns
= ns
;
1482 list_op
.params
.enforce_ns
= true;
1483 list_op
.params
.list_versions
= true;
1485 f
->open_array_section("check_objects");
1487 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1489 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1493 count
+= result
.size();
1495 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1496 rgw_obj_key key
= iter
->key
;
1497 rgw_obj
obj(bucket
, key
);
1499 if (key
.name
[0] == '_') {
1500 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1503 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1508 } while (truncated
&& count
< max_entries
);
1517 int set_bucket_sync_enabled(RGWRados
*store
, int opt_cmd
, const string
& tenant_name
, const string
& bucket_name
)
1519 RGWBucketInfo bucket_info
;
1520 map
<string
, bufferlist
> attrs
;
1521 RGWObjectCtx
obj_ctx(store
);
1523 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1525 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1529 if (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
) {
1530 bucket_info
.flags
&= ~BUCKET_DATASYNC_DISABLED
;
1531 } else if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1532 bucket_info
.flags
|= BUCKET_DATASYNC_DISABLED
;
1535 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1537 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1541 int shards_num
= bucket_info
.num_shards
? bucket_info
.num_shards
: 1;
1542 int shard_id
= bucket_info
.num_shards
? 0 : -1;
1544 if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1545 r
= store
->stop_bi_log_entries(bucket_info
, -1);
1547 lderr(store
->ctx()) << "ERROR: failed writing stop bilog" << dendl
;
1551 r
= store
->resync_bi_log_entries(bucket_info
, -1);
1553 lderr(store
->ctx()) << "ERROR: failed writing resync bilog" << dendl
;
1558 for (int i
= 0; i
< shards_num
; ++i
, ++shard_id
) {
1559 r
= store
->data_log
->add_entry(bucket_info
.bucket
, shard_id
);
1561 lderr(store
->ctx()) << "ERROR: failed writing data log" << dendl
;
1570 /// search for a matching zone/zonegroup id and return a connection if found
1571 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1572 const RGWZoneGroup
& zonegroup
,
1573 const std::string
& remote
)
1575 boost::optional
<RGWRESTConn
> conn
;
1576 if (remote
== zonegroup
.get_id()) {
1577 conn
.emplace(store
->ctx(), store
, remote
, zonegroup
.endpoints
);
1579 for (const auto& z
: zonegroup
.zones
) {
1580 const auto& zone
= z
.second
;
1581 if (remote
== zone
.id
) {
1582 conn
.emplace(store
->ctx(), store
, remote
, zone
.endpoints
);
1590 /// search each zonegroup for a connection
1591 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1592 const RGWPeriodMap
& period_map
,
1593 const std::string
& remote
)
1595 boost::optional
<RGWRESTConn
> conn
;
1596 for (const auto& zg
: period_map
.zonegroups
) {
1597 conn
= get_remote_conn(store
, zg
.second
, remote
);
1605 // we expect a very small response
1606 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1608 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1609 bufferlist
& in_data
, JSONParser
& parser
)
1615 ceph::bufferlist response
;
1617 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1619 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1620 if (parse_ret
< 0) {
1621 cerr
<< "failed to parse response" << std::endl
;
1627 static int send_to_url(const string
& url
, const string
& access
,
1628 const string
& secret
, req_info
& info
,
1629 bufferlist
& in_data
, JSONParser
& parser
)
1631 if (access
.empty() || secret
.empty()) {
1632 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1640 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1642 bufferlist response
;
1643 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1645 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1646 if (parse_ret
< 0) {
1647 cout
<< "failed to parse response" << std::endl
;
1653 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1654 const string
& access
, const string
& secret
,
1655 req_info
& info
, bufferlist
& in_data
,
1659 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1661 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1664 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1665 string remote
, const string
& url
,
1666 const string
& access
, const string
& secret
,
1669 const string
& master_zone
= period
.get_master_zone();
1670 if (master_zone
.empty()) {
1671 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1674 // are we the period's master zone?
1675 if (store
->get_zone_params().get_id() == master_zone
) {
1676 // read the current period
1677 RGWPeriod current_period
;
1678 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1680 cerr
<< "Error initializing current period: "
1681 << cpp_strerror(-ret
) << std::endl
;
1684 // the master zone can commit locally
1685 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1687 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1692 if (remote
.empty() && url
.empty()) {
1693 // use the new master zone's connection
1694 remote
= master_zone
;
1695 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1697 boost::optional
<RGWRESTConn
> conn
;
1698 RGWRESTConn
*remote_conn
= nullptr;
1699 if (!remote
.empty()) {
1700 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1702 cerr
<< "failed to find a zone or zonegroup for remote "
1703 << remote
<< std::endl
;
1706 remote_conn
= &*conn
;
1709 // push period to the master with an empty period id
1713 req_info
info(g_ceph_context
, &env
);
1714 info
.method
= "POST";
1715 info
.request_uri
= "/admin/realm/period";
1717 // json format into a bufferlist
1718 JSONFormatter
jf(false);
1719 encode_json("period", period
, &jf
);
1724 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1726 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1728 // did we parse an error message?
1729 auto message
= p
.find_obj("Message");
1731 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1736 // decode the response and store it back
1738 decode_json_obj(period
, &p
);
1739 } catch (JSONDecoder::err
& e
) {
1740 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1743 if (period
.get_id().empty()) {
1744 cerr
<< "Period commit got back an empty period id" << std::endl
;
1747 // the master zone gave us back the period that it committed, so it's
1748 // safe to save it as our latest epoch
1749 ret
= period
.store_info(false);
1751 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1752 << cpp_strerror(ret
) << std::endl
;
1755 ret
= period
.set_latest_epoch(period
.get_epoch());
1757 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1760 ret
= period
.reflect();
1762 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1765 realm
.notify_new_period(period
);
1769 static int update_period(const string
& realm_id
, const string
& realm_name
,
1770 const string
& period_id
, const string
& period_epoch
,
1771 bool commit
, const string
& remote
, const string
& url
,
1772 const string
& access
, const string
& secret
,
1773 Formatter
*formatter
, bool force
)
1775 RGWRealm
realm(realm_id
, realm_name
);
1776 int ret
= realm
.init(g_ceph_context
, store
);
1778 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1782 if (!period_epoch
.empty()) {
1783 epoch
= atoi(period_epoch
.c_str());
1785 RGWPeriod
period(period_id
, epoch
);
1786 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1788 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1792 ret
= period
.update();
1794 // Dropping the error message here, as both the ret codes were handled in
1798 ret
= period
.store_info(false);
1800 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1804 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1806 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1810 encode_json("period", period
, formatter
);
1811 formatter
->flush(cout
);
1816 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1817 const string
& bucket_id
, rgw_bucket
& bucket
)
1819 RGWBucketInfo bucket_info
;
1821 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1823 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1830 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1831 const string
& access_key
, const string
& secret_key
,
1832 const string
& realm_id
, const string
& realm_name
,
1833 const string
& period_id
, const string
& period_epoch
,
1837 req_info
info(g_ceph_context
, &env
);
1838 info
.method
= "GET";
1839 info
.request_uri
= "/admin/realm/period";
1841 map
<string
, string
> ¶ms
= info
.args
.get_params();
1842 if (!realm_id
.empty())
1843 params
["realm_id"] = realm_id
;
1844 if (!realm_name
.empty())
1845 params
["realm_name"] = realm_name
;
1846 if (!period_id
.empty())
1847 params
["period_id"] = period_id
;
1848 if (!period_epoch
.empty())
1849 params
["epoch"] = period_epoch
;
1853 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1856 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1859 ret
= period
->init(g_ceph_context
, store
, false);
1861 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1865 decode_json_obj(*period
, &p
);
1866 } catch (JSONDecoder::err
& e
) {
1867 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1870 ret
= period
->store_info(false);
1872 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1874 // store latest epoch (ignore errors)
1875 period
->update_latest_epoch(period
->get_epoch());
1879 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1880 const std::string
& realm_name
,
1881 std::string
* period_id
)
1883 RGWRealm
realm(realm_id
, realm_name
);
1884 int ret
= realm
.init(g_ceph_context
, store
);
1886 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1889 *period_id
= realm
.get_current_period();
1893 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1895 if (!ss
.str().empty()) {
1896 l
.push_back(ss
.str());
1901 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1905 ss
<< setw(tab
) << "" << setw(1);
1910 static void get_md_sync_status(list
<string
>& status
)
1912 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1914 int ret
= sync
.init();
1916 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1920 rgw_meta_sync_status sync_status
;
1921 ret
= sync
.read_sync_status(&sync_status
);
1923 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1928 switch (sync_status
.sync_info
.state
) {
1929 case rgw_meta_sync_info::StateInit
:
1930 status_str
= "init";
1932 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1933 status_str
= "preparing for full sync";
1935 case rgw_meta_sync_info::StateSync
:
1936 status_str
= "syncing";
1939 status_str
= "unknown";
1942 status
.push_back(status_str
);
1944 uint64_t full_total
= 0;
1945 uint64_t full_complete
= 0;
1949 int total_shards
= 0;
1950 set
<int> shards_behind_set
;
1952 for (auto marker_iter
: sync_status
.sync_markers
) {
1953 full_total
+= marker_iter
.second
.total_entries
;
1955 int shard_id
= marker_iter
.first
;
1956 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1958 full_complete
+= marker_iter
.second
.pos
;
1959 shards_behind_set
.insert(shard_id
);
1961 full_complete
+= marker_iter
.second
.total_entries
;
1963 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1969 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1972 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1975 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1977 rgw_mdlog_info log_info
;
1978 ret
= sync
.read_log_info(&log_info
);
1980 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1984 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1985 string master_period
= store
->get_current_period_id();
1987 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1989 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1993 map
<int, string
> shards_behind
;
1994 if (sync_status
.sync_info
.period
!= master_period
) {
1995 status
.push_back(string("master is on a different period: master_period=" +
1996 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1998 for (auto local_iter
: sync_status
.sync_markers
) {
1999 int shard_id
= local_iter
.first
;
2000 auto iter
= master_shards_info
.find(shard_id
);
2002 if (iter
== master_shards_info
.end()) {
2004 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2007 auto master_marker
= iter
->second
.marker
;
2008 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
2009 master_marker
> local_iter
.second
.marker
) {
2010 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2011 shards_behind_set
.insert(shard_id
);
2016 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2017 if (total_behind
== 0) {
2018 push_ss(ss
, status
) << "metadata is caught up with master";
2020 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
2022 push_ss(ss
, status
) << "behind shards: " << "[" << shards_behind_set
<< "]";
2024 map
<int, rgw_mdlog_shard_data
> master_pos
;
2025 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
2027 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2029 ceph::real_time oldest
;
2030 for (auto iter
: master_pos
) {
2031 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
2033 if (!shard_data
.entries
.empty()) {
2034 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
2035 if (ceph::real_clock::is_zero(oldest
)) {
2036 oldest
= entry
.timestamp
;
2037 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2038 oldest
= entry
.timestamp
;
2043 if (!ceph::real_clock::is_zero(oldest
)) {
2044 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
2049 flush_ss(ss
, status
);
2052 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
2056 auto ziter
= store
->zone_by_id
.find(source_zone
);
2057 if (ziter
== store
->zone_by_id
.end()) {
2058 push_ss(ss
, status
, tab
) << string("zone not found");
2059 flush_ss(ss
, status
);
2062 RGWZone
& sz
= ziter
->second
;
2064 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
2065 push_ss(ss
, status
, tab
) << string("not syncing from zone");
2066 flush_ss(ss
, status
);
2069 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
2071 int ret
= sync
.init();
2073 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
2074 flush_ss(ss
, status
);
2078 rgw_data_sync_status sync_status
;
2079 ret
= sync
.read_sync_status(&sync_status
);
2080 if (ret
< 0 && ret
!= -ENOENT
) {
2081 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2085 set
<int> recovering_shards
;
2086 ret
= sync
.read_recovering_shards(sync_status
.sync_info
.num_shards
, recovering_shards
);
2087 if (ret
< 0 && ret
!= ENOENT
) {
2088 push_ss(ss
, status
, tab
) << string("failed read recovering shards: ") + cpp_strerror(-ret
);
2093 switch (sync_status
.sync_info
.state
) {
2094 case rgw_data_sync_info::StateInit
:
2095 status_str
= "init";
2097 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2098 status_str
= "preparing for full sync";
2100 case rgw_data_sync_info::StateSync
:
2101 status_str
= "syncing";
2104 status_str
= "unknown";
2107 push_ss(ss
, status
, tab
) << status_str
;
2109 uint64_t full_total
= 0;
2110 uint64_t full_complete
= 0;
2114 int total_shards
= 0;
2115 set
<int> shards_behind_set
;
2117 for (auto marker_iter
: sync_status
.sync_markers
) {
2118 int shard_id
= marker_iter
.first
;
2119 full_total
+= marker_iter
.second
.total_entries
;
2121 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2123 full_complete
+= marker_iter
.second
.pos
;
2124 shards_behind_set
.insert(shard_id
);
2126 full_complete
+= marker_iter
.second
.total_entries
;
2128 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2133 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2136 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2139 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2141 rgw_datalog_info log_info
;
2142 ret
= sync
.read_log_info(&log_info
);
2144 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2149 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2151 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2153 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2157 map
<int, string
> shards_behind
;
2159 for (auto local_iter
: sync_status
.sync_markers
) {
2160 int shard_id
= local_iter
.first
;
2161 auto iter
= source_shards_info
.find(shard_id
);
2163 if (iter
== source_shards_info
.end()) {
2165 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2168 auto master_marker
= iter
->second
.marker
;
2169 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2170 master_marker
> local_iter
.second
.marker
) {
2171 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2172 shards_behind_set
.insert(shard_id
);
2176 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2177 int total_recovering
= recovering_shards
.size();
2178 if (total_behind
== 0 && total_recovering
== 0) {
2179 push_ss(ss
, status
, tab
) << "data is caught up with source";
2180 } else if (total_behind
> 0) {
2181 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2183 push_ss(ss
, status
, tab
) << "behind shards: " << "[" << shards_behind_set
<< "]" ;
2185 map
<int, rgw_datalog_shard_data
> master_pos
;
2186 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2188 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2190 ceph::real_time oldest
;
2191 for (auto iter
: master_pos
) {
2192 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2194 if (!shard_data
.entries
.empty()) {
2195 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2196 if (ceph::real_clock::is_zero(oldest
)) {
2197 oldest
= entry
.timestamp
;
2198 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2199 oldest
= entry
.timestamp
;
2204 if (!ceph::real_clock::is_zero(oldest
)) {
2205 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2210 if (total_recovering
> 0) {
2211 push_ss(ss
, status
, tab
) << total_recovering
<< " shards are recovering";
2212 push_ss(ss
, status
, tab
) << "recovering shards: " << "[" << recovering_shards
<< "]";
2215 flush_ss(ss
, status
);
2218 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2222 for (auto e
: entries
) {
2223 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2229 static void sync_status(Formatter
*formatter
)
2231 RGWRealm
& realm
= store
->realm
;
2232 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2233 RGWZone
& zone
= store
->get_zone();
2237 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2238 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2239 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2241 list
<string
> md_status
;
2243 if (store
->is_meta_master()) {
2244 md_status
.push_back("no sync (zone is master)");
2246 get_md_sync_status(md_status
);
2249 tab_dump("metadata sync", width
, md_status
);
2251 list
<string
> data_status
;
2253 for (auto iter
: store
->zone_conn_map
) {
2254 const string
& source_id
= iter
.first
;
2255 string source_str
= "source: ";
2256 string s
= source_str
+ source_id
;
2257 auto siter
= store
->zone_by_id
.find(source_id
);
2258 if (siter
!= store
->zone_by_id
.end()) {
2259 s
+= string(" (") + siter
->second
.name
+ ")";
2261 data_status
.push_back(s
);
2262 get_data_sync_status(source_id
, data_status
, source_str
.size());
2265 tab_dump("data sync", width
, data_status
);
2269 int w
; // indent width
2270 boost::string_view header
;
2271 indented(int w
, boost::string_view header
= "") : w(w
), header(header
) {}
2273 std::ostream
& operator<<(std::ostream
& out
, const indented
& h
) {
2274 return out
<< std::setw(h
.w
) << h
.header
<< std::setw(1) << ' ';
2277 static int remote_bilog_markers(RGWRados
*store
, const RGWZone
& source
,
2278 RGWRESTConn
*conn
, const RGWBucketInfo
& info
,
2279 BucketIndexShardsManager
*markers
)
2281 const auto instance_key
= info
.bucket
.get_key();
2282 const rgw_http_param_pair params
[] = {
2283 { "type" , "bucket-index" },
2284 { "bucket-instance", instance_key
.c_str() },
2285 { "info" , nullptr },
2286 { nullptr, nullptr }
2288 rgw_bucket_index_marker_info result
;
2289 int r
= conn
->get_json_resource("/admin/log/", params
, result
);
2291 lderr(store
->ctx()) << "failed to fetch remote log markers: " << cpp_strerror(r
) << dendl
;
2294 r
= markers
->from_string(result
.max_marker
, -1);
2296 lderr(store
->ctx()) << "failed to decode remote log markers" << dendl
;
2302 static int bucket_source_sync_status(RGWRados
*store
, const RGWZone
& zone
,
2303 const RGWZone
& source
, RGWRESTConn
*conn
,
2304 const RGWBucketInfo
& bucket_info
,
2305 int width
, std::ostream
& out
)
2307 out
<< indented
{width
, "source zone"} << source
.id
<< " (" << source
.name
<< ")\n";
2309 // syncing from this zone?
2310 if (!zone
.syncs_from(source
.id
)) {
2311 out
<< indented
{width
} << "not in sync_from\n";
2314 std::vector
<rgw_bucket_shard_sync_info
> status
;
2315 int r
= rgw_bucket_sync_status(store
, source
.id
, bucket_info
, &status
);
2317 lderr(store
->ctx()) << "failed to read bucket sync status: " << cpp_strerror(r
) << dendl
;
2323 uint64_t full_complete
= 0;
2324 const int total_shards
= status
.size();
2326 using BucketSyncState
= rgw_bucket_shard_sync_info::SyncState
;
2327 for (size_t shard_id
= 0; shard_id
< total_shards
; shard_id
++) {
2328 auto& m
= status
[shard_id
];
2329 if (m
.state
== BucketSyncState::StateFullSync
) {
2331 full_complete
+= m
.full_marker
.count
;
2332 } else if (m
.state
== BucketSyncState::StateIncrementalSync
) {
2337 out
<< indented
{width
} << "full sync: " << num_full
<< "/" << total_shards
<< " shards\n";
2339 out
<< indented
{width
} << "full sync: " << full_complete
<< " objects completed\n";
2341 out
<< indented
{width
} << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards\n";
2343 BucketIndexShardsManager remote_markers
;
2344 r
= remote_bilog_markers(store
, source
, conn
, bucket_info
, &remote_markers
);
2346 lderr(store
->ctx()) << "failed to read remote log: " << cpp_strerror(r
) << dendl
;
2350 std::set
<int> shards_behind
;
2351 for (auto& r
: remote_markers
.get()) {
2352 auto shard_id
= r
.first
;
2353 auto& m
= status
[shard_id
];
2354 if (r
.second
.empty()) {
2355 continue; // empty bucket index shard
2357 auto pos
= BucketIndexShardsManager::get_shard_marker(m
.inc_marker
.position
);
2358 if (m
.state
!= BucketSyncState::StateIncrementalSync
|| pos
!= r
.second
) {
2359 shards_behind
.insert(shard_id
);
2362 if (shards_behind
.empty()) {
2363 out
<< indented
{width
} << "bucket is caught up with source\n";
2365 out
<< indented
{width
} << "bucket is behind on " << shards_behind
.size() << " shards\n";
2366 out
<< indented
{width
} << "behind shards: [" << shards_behind
<< "]\n" ;
2371 static int bucket_sync_status(RGWRados
*store
, const RGWBucketInfo
& info
,
2372 const std::string
& source_zone_id
,
2375 RGWRealm
& realm
= store
->realm
;
2376 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2377 RGWZone
& zone
= store
->get_zone();
2378 constexpr int width
= 15;
2380 out
<< indented
{width
, "realm"} << realm
.get_id() << " (" << realm
.get_name() << ")\n";
2381 out
<< indented
{width
, "zonegroup"} << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")\n";
2382 out
<< indented
{width
, "zone"} << zone
.id
<< " (" << zone
.name
<< ")\n";
2383 out
<< indented
{width
, "bucket"} << info
.bucket
<< "\n\n";
2385 if (!info
.datasync_flag_enabled()) {
2386 out
<< "Sync is disabled for bucket " << info
.bucket
.name
<< '\n';
2390 if (!source_zone_id
.empty()) {
2391 auto z
= zonegroup
.zones
.find(source_zone_id
);
2392 if (z
== zonegroup
.zones
.end()) {
2393 lderr(store
->ctx()) << "Source zone not found in zonegroup "
2394 << zonegroup
.get_name() << dendl
;
2397 auto c
= store
->zone_conn_map
.find(source_zone_id
);
2398 if (c
== store
->zone_conn_map
.end()) {
2399 lderr(store
->ctx()) << "No connection to zone " << z
->second
.name
<< dendl
;
2402 return bucket_source_sync_status(store
, zone
, z
->second
, c
->second
,
2406 for (const auto& z
: zonegroup
.zones
) {
2407 auto c
= store
->zone_conn_map
.find(z
.second
.id
);
2408 if (c
!= store
->zone_conn_map
.end()) {
2409 bucket_source_sync_status(store
, zone
, z
.second
, c
->second
,
2416 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2419 get_str_list(s
, ",", confs
);
2420 for (auto c
: confs
) {
2421 ssize_t pos
= c
.find("=");
2425 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2430 int check_reshard_bucket_params(RGWRados
*store
,
2431 const string
& bucket_name
,
2432 const string
& tenant
,
2433 const string
& bucket_id
,
2434 bool num_shards_specified
,
2436 int yes_i_really_mean_it
,
2438 RGWBucketInfo
& bucket_info
,
2439 map
<string
, bufferlist
>& attrs
)
2441 if (bucket_name
.empty()) {
2442 cerr
<< "ERROR: bucket not specified" << std::endl
;
2446 if (!num_shards_specified
) {
2447 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2451 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2452 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2456 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2458 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2462 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2464 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2465 cerr
<< "num shards is less or equal to current shards count" << std::endl
2466 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2472 int create_new_bucket_instance(RGWRados
*store
,
2474 const RGWBucketInfo
& bucket_info
,
2475 map
<string
, bufferlist
>& attrs
,
2476 RGWBucketInfo
& new_bucket_info
)
2479 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2480 new_bucket_info
.bucket
.oid
.clear();
2482 new_bucket_info
.num_shards
= new_num_shards
;
2483 new_bucket_info
.objv_tracker
.clear();
2485 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2487 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2491 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2493 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2501 #ifdef BUILDING_FOR_EMBEDDED
2502 extern "C" int cephd_rgw_admin(int argc
, const char **argv
)
2504 int main(int argc
, const char **argv
)
2507 vector
<const char*> args
;
2508 argv_to_vec(argc
, (const char **)argv
, args
);
2511 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2512 CODE_ENVIRONMENT_UTILITY
, 0);
2514 // for region -> zonegroup conversion (must happen before common_init_finish())
2515 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2516 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2519 common_init_finish(g_ceph_context
);
2523 std::string access_key
, secret_key
, user_email
, display_name
;
2524 std::string bucket_name
, pool_name
, object
;
2526 std::string date
, subuser
, access
, format
;
2527 std::string start_date
, end_date
;
2528 std::string key_type_str
;
2529 std::string period_id
, period_epoch
, remote
, url
;
2530 std::string master_zonegroup
, master_zone
;
2531 std::string realm_name
, realm_id
, realm_new_name
;
2532 std::string zone_name
, zone_id
, zone_new_name
;
2533 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2534 std::string api_name
;
2535 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2536 list
<string
> endpoints
;
2538 int sync_from_all_specified
= false;
2539 bool sync_from_all
= false;
2540 list
<string
> sync_from
;
2541 list
<string
> sync_from_rm
;
2542 std::string master_url
;
2544 int set_default
= 0;
2545 bool is_master
= false;
2546 bool is_master_set
= false;
2548 bool read_only
= false;
2549 int is_read_only_set
= false;
2551 int staging
= false;
2552 int key_type
= KEY_TYPE_UNDEFINED
;
2554 uint32_t perm_mask
= 0;
2556 int opt_cmd
= OPT_NO_CMD
;
2558 int gen_access_key
= 0;
2559 int gen_secret_key
= 0;
2560 bool set_perm
= false;
2561 bool set_temp_url_key
= false;
2562 map
<int, string
> temp_url_keys
;
2564 Formatter
*formatter
= NULL
;
2565 int purge_data
= false;
2566 int pretty_format
= false;
2567 int show_log_entries
= true;
2568 int show_log_sum
= true;
2569 int skip_zero_entries
= false; // log show
2570 int purge_keys
= false;
2571 int yes_i_really_mean_it
= false;
2572 int delete_child_objects
= false;
2574 int remove_bad
= false;
2575 int check_head_obj_locator
= false;
2576 int max_buckets
= -1;
2577 bool max_buckets_specified
= false;
2578 map
<string
, bool> categories
;
2580 int check_objects
= false;
2581 RGWUserAdminOpState user_op
;
2582 RGWBucketAdminOpState bucket_op
;
2584 string metadata_key
;
2585 RGWObjVersionTracker objv_tracker
;
2587 string start_marker
;
2589 int max_entries
= -1;
2590 bool max_entries_specified
= false;
2592 bool admin_specified
= false;
2594 bool system_specified
= false;
2596 bool specified_shard_id
= false;
2598 bool specified_daemon_id
= false;
2602 string replica_log_type_str
;
2603 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2606 string object_version
;
2607 string placement_id
;
2609 list
<string
> tags_add
;
2610 list
<string
> tags_rm
;
2612 int64_t max_objects
= -1;
2613 int64_t max_size
= -1;
2614 bool have_max_objects
= false;
2615 bool have_max_size
= false;
2616 int include_all
= false;
2618 int sync_stats
= false;
2619 int reset_stats
= false;
2620 int bypass_gc
= false;
2621 int warnings_only
= false;
2622 int inconsistent_index
= false;
2624 int verbose
= false;
2626 int extra_info
= false;
2628 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2629 uint64_t max_rewrite_size
= ULLONG_MAX
;
2630 uint64_t min_rewrite_stripe_size
= 0;
2632 BIIndexType bi_index_type
= PlainIdx
;
2636 bool num_shards_specified
= false;
2637 int max_concurrent_ios
= 32;
2638 uint64_t orphan_stale_secs
= (24 * 3600);
2641 std::ostringstream errs
;
2645 string source_zone_name
;
2646 string source_zone
; /* zone id */
2649 bool tier_type_specified
= false;
2651 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2652 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2654 boost::optional
<string
> index_pool
;
2655 boost::optional
<string
> data_pool
;
2656 boost::optional
<string
> data_extra_pool
;
2657 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2658 bool index_type_specified
= false;
2660 boost::optional
<std::string
> compression_type
;
2662 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2663 if (ceph_argparse_double_dash(args
, i
)) {
2665 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2668 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2669 user_id
.from_str(val
);
2670 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2672 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2674 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2676 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2678 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2680 user_op
.user_email_specified
=true;
2681 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2683 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2685 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2687 pool
= rgw_pool(pool_name
);
2688 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2690 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2691 object_version
= val
;
2692 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2694 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2696 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2698 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2700 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2702 if (key_type_str
.compare("swift") == 0) {
2703 key_type
= KEY_TYPE_SWIFT
;
2704 } else if (key_type_str
.compare("s3") == 0) {
2705 key_type
= KEY_TYPE_S3
;
2707 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2711 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2713 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2715 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2717 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2719 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2721 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2723 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2724 admin_specified
= true;
2725 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2726 system_specified
= true;
2727 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2729 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2731 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2733 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2734 if (!errs
.str().empty()) {
2735 cerr
<< errs
.str() << std::endl
;
2738 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2739 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2740 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2741 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2742 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2743 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2744 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2745 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2747 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2750 max_buckets_specified
= true;
2751 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2752 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2753 max_entries_specified
= true;
2755 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2758 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2759 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2761 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2764 have_max_size
= true;
2765 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2766 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2768 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2771 have_max_objects
= true;
2772 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2774 if (end_date
.empty())
2776 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2778 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2780 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2781 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2783 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2786 num_shards_specified
= true;
2787 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2788 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2790 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2793 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2794 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2796 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2799 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2800 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2802 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2805 specified_shard_id
= true;
2806 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2808 specified_daemon_id
= true;
2809 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2811 perm_mask
= rgw_str_to_perm(access
.c_str());
2813 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2814 temp_url_keys
[0] = val
;
2815 set_temp_url_key
= true;
2816 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2817 temp_url_keys
[1] = val
;
2818 set_temp_url_key
= true;
2819 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2821 if (bucket_id
.empty()) {
2822 cerr
<< "bad bucket-id" << std::endl
;
2826 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2828 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2829 string cat_str
= val
;
2830 list
<string
> cat_list
;
2831 list
<string
>::iterator iter
;
2832 get_str_list(cat_str
, cat_list
);
2833 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2834 categories
[*iter
] = true;
2836 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2838 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2840 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2841 delete_child_objects
= purge_data
;
2842 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2844 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2846 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2848 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2850 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2852 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2854 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2856 } else if (ceph_argparse_binary_flag(args
, i
, &reset_stats
, NULL
, "--reset-stats", (char*)NULL
)) {
2858 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2860 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2862 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2864 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2866 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2868 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2870 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2872 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2874 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2876 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2878 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2880 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2882 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2883 replica_log_type_str
= val
;
2884 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2885 if (replica_log_type
== ReplicaLog_Invalid
) {
2886 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2889 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2890 string index_type_str
= val
;
2891 bi_index_type
= get_bi_index_type(index_type_str
);
2892 if (bi_index_type
== InvalidIdx
) {
2893 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2896 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2897 is_master
= (bool)is_master_int
;
2898 is_master_set
= true;
2899 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2901 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2902 read_only
= (bool)read_only_int
;
2903 is_read_only_set
= true;
2904 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2906 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2907 master_zonegroup
= val
;
2908 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2910 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2912 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2914 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2916 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2918 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2920 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2921 realm_new_name
= val
;
2922 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2924 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2925 zonegroup_new_name
= val
;
2926 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2928 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2929 get_str_list(val
, tags
);
2930 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2931 get_str_list(val
, tags_add
);
2932 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2933 get_str_list(val
, tags_rm
);
2934 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2936 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2938 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2939 zone_new_name
= val
;
2940 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2941 get_str_list(val
, endpoints
);
2942 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2943 get_str_list(val
, sync_from
);
2944 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2945 get_str_list(val
, sync_from_rm
);
2946 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2947 sync_from_all
= (bool)tmp_int
;
2948 sync_from_all_specified
= true;
2949 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2950 source_zone_name
= val
;
2951 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2953 tier_type_specified
= true;
2954 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2955 parse_tier_config_param(val
, tier_config_add
);
2956 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2957 parse_tier_config_param(val
, tier_config_rm
);
2958 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2960 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2962 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2963 data_extra_pool
= val
;
2964 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2965 if (val
== "normal") {
2966 placement_index_type
= RGWBIType_Normal
;
2967 } else if (val
== "indexless") {
2968 placement_index_type
= RGWBIType_Indexless
;
2970 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2972 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2976 index_type_specified
= true;
2977 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2978 compression_type
= val
;
2979 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2981 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2983 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2984 assume_role_doc
= val
;
2985 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2987 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2988 perm_policy_doc
= val
;
2989 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2991 } else if (strncmp(*i
, "-", 1) == 0) {
2992 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
3004 const char *prev_cmd
= NULL
;
3005 const char *prev_prev_cmd
= NULL
;
3006 std::vector
<const char*>::iterator i
;
3007 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
3008 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
3010 cerr
<< "unrecognized arg " << *i
<< std::endl
;
3018 prev_prev_cmd
= prev_cmd
;
3022 if (opt_cmd
== OPT_NO_CMD
) {
3027 /* some commands may have an optional extra param */
3028 if (i
!= args
.end()) {
3030 case OPT_METADATA_GET
:
3031 case OPT_METADATA_PUT
:
3032 case OPT_METADATA_RM
:
3033 case OPT_METADATA_LIST
:
3041 if (tenant
.empty()) {
3042 tenant
= user_id
.tenant
;
3044 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
3045 && opt_cmd
!= OPT_ROLE_DELETE
3046 && opt_cmd
!= OPT_ROLE_GET
3047 && opt_cmd
!= OPT_ROLE_MODIFY
3048 && opt_cmd
!= OPT_ROLE_LIST
3049 && opt_cmd
!= OPT_ROLE_POLICY_PUT
3050 && opt_cmd
!= OPT_ROLE_POLICY_LIST
3051 && opt_cmd
!= OPT_ROLE_POLICY_GET
3052 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
3053 && opt_cmd
!= OPT_RESHARD_ADD
3054 && opt_cmd
!= OPT_RESHARD_CANCEL
3055 && opt_cmd
!= OPT_RESHARD_STATUS
) {
3056 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
3059 user_id
.tenant
= tenant
;
3061 /* check key parameter conflict */
3062 if ((!access_key
.empty()) && gen_access_key
) {
3063 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
3066 if ((!secret_key
.empty()) && gen_secret_key
) {
3067 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
3072 // default to pretty json
3073 if (format
.empty()) {
3075 pretty_format
= true;
3078 if (format
== "xml")
3079 formatter
= new XMLFormatter(pretty_format
);
3080 else if (format
== "json")
3081 formatter
= new JSONFormatter(pretty_format
);
3083 cerr
<< "unrecognized format: " << format
<< std::endl
;
3088 realm_name
= g_conf
->rgw_realm
;
3089 zone_name
= g_conf
->rgw_zone
;
3090 zonegroup_name
= g_conf
->rgw_zonegroup
;
3092 RGWStreamFlusher
f(formatter
, cout
);
3094 // not a raw op if 'period update' needs to commit to master
3095 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
3096 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
3097 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
3098 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
3099 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
3100 OPT_ZONEGROUP_REMOVE
,
3101 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
3102 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
3103 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
3104 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
3105 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
3106 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
3107 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
3108 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
3110 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
3112 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
3113 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
3114 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
3115 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
3116 OPT_REALM_LIST_PERIODS
,
3117 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
3118 OPT_REALM_RENAME
, OPT_REALM_SET
,
3119 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
3121 std::set
<int> readonly_ops_list
= {
3125 OPT_BUCKET_LIMIT_CHECK
,
3127 OPT_BUCKET_SYNC_STATUS
,
3138 OPT_ORPHANS_LIST_JOBS
,
3141 OPT_ZONEGROUP_PLACEMENT_LIST
,
3144 OPT_ZONE_PLACEMENT_LIST
,
3147 OPT_METADATA_SYNC_STATUS
,
3150 OPT_SYNC_ERROR_LIST
,
3153 OPT_DATA_SYNC_STATUS
,
3159 OPT_REALM_GET_DEFAULT
,
3161 OPT_REALM_LIST_PERIODS
,
3163 OPT_PERIOD_GET_CURRENT
,
3165 OPT_GLOBAL_QUOTA_GET
,
3169 OPT_ROLE_POLICY_LIST
,
3170 OPT_ROLE_POLICY_GET
,
3175 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
3177 bool need_cache
= readonly_ops_list
.find(opt_cmd
) == readonly_ops_list
.end();
3179 if (raw_storage_op
) {
3180 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
3182 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false,
3183 need_cache
&& g_conf
->rgw_cache_enabled
);
3186 cerr
<< "couldn't init storage provider" << std::endl
;
3190 if (!source_zone_name
.empty()) {
3191 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
3192 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
3193 source_zone
= source_zone_name
;
3197 rgw_user_init(store
);
3198 rgw_bucket_init(store
->meta_mgr
);
3200 struct rgw_curl_setup
{
3202 rgw::curl::setup_curl(boost::none
);
3205 rgw::curl::cleanup_curl();
3209 StoreDestructor
store_destructor(store
);
3211 if (raw_storage_op
) {
3213 case OPT_PERIOD_DELETE
:
3215 if (period_id
.empty()) {
3216 cerr
<< "missing period id" << std::endl
;
3219 RGWPeriod
period(period_id
);
3220 int ret
= period
.init(g_ceph_context
, store
);
3222 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
3225 ret
= period
.delete_obj();
3227 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
3233 case OPT_PERIOD_GET
:
3236 if (!period_epoch
.empty()) {
3237 epoch
= atoi(period_epoch
.c_str());
3240 RGWRealm
realm(realm_id
, realm_name
);
3241 int ret
= realm
.init(g_ceph_context
, store
);
3243 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
3246 realm_id
= realm
.get_id();
3247 realm_name
= realm
.get_name();
3248 period_id
= RGWPeriod::get_staging_id(realm_id
);
3251 RGWPeriod
period(period_id
, epoch
);
3252 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
3254 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
3257 encode_json("period", period
, formatter
);
3258 formatter
->flush(cout
);
3262 case OPT_PERIOD_GET_CURRENT
:
3264 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3268 formatter
->open_object_section("period_get_current");
3269 encode_json("current_period", period_id
, formatter
);
3270 formatter
->close_section();
3271 formatter
->flush(cout
);
3274 case OPT_PERIOD_LIST
:
3276 list
<string
> periods
;
3277 int ret
= store
->list_periods(periods
);
3279 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
3282 formatter
->open_object_section("periods_list");
3283 encode_json("periods", periods
, formatter
);
3284 formatter
->close_section();
3285 formatter
->flush(cout
);
3289 case OPT_PERIOD_UPDATE
:
3291 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
3292 commit
, remote
, url
, access_key
, secret_key
,
3293 formatter
, yes_i_really_mean_it
);
3299 case OPT_PERIOD_PULL
:
3301 boost::optional
<RGWRESTConn
> conn
;
3302 RGWRESTConn
*remote_conn
= nullptr;
3304 // load current period for endpoints
3305 RGWRealm
realm(realm_id
, realm_name
);
3306 int ret
= realm
.init(g_ceph_context
, store
);
3308 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3311 RGWPeriod
current_period(realm
.get_current_period());
3312 ret
= current_period
.init(g_ceph_context
, store
);
3314 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
3317 if (remote
.empty()) {
3318 // use realm master zone as remote
3319 remote
= current_period
.get_master_zone();
3321 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
3323 cerr
<< "failed to find a zone or zonegroup for remote "
3324 << remote
<< std::endl
;
3327 remote_conn
= &*conn
;
3331 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3332 realm_id
, realm_name
, period_id
, period_epoch
,
3335 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3339 encode_json("period", period
, formatter
);
3340 formatter
->flush(cout
);
3344 case OPT_GLOBAL_QUOTA_GET
:
3345 case OPT_GLOBAL_QUOTA_SET
:
3346 case OPT_GLOBAL_QUOTA_ENABLE
:
3347 case OPT_GLOBAL_QUOTA_DISABLE
:
3349 if (realm_id
.empty()) {
3350 RGWRealm
realm(g_ceph_context
, store
);
3351 if (!realm_name
.empty()) {
3352 // look up realm_id for the given realm_name
3353 int ret
= realm
.read_id(realm_name
, realm_id
);
3355 cerr
<< "ERROR: failed to read realm for " << realm_name
3356 << ": " << cpp_strerror(-ret
) << std::endl
;
3360 // use default realm_id when none is given
3361 int ret
= realm
.read_default_id(realm_id
);
3362 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3363 cerr
<< "ERROR: failed to read default realm: "
3364 << cpp_strerror(-ret
) << std::endl
;
3370 RGWPeriodConfig period_config
;
3371 int ret
= period_config
.read(store
, realm_id
);
3372 if (ret
< 0 && ret
!= -ENOENT
) {
3373 cerr
<< "ERROR: failed to read period config: "
3374 << cpp_strerror(-ret
) << std::endl
;
3378 formatter
->open_object_section("period_config");
3379 if (quota_scope
== "bucket") {
3380 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3381 max_size
, max_objects
,
3382 have_max_size
, have_max_objects
);
3383 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3384 } else if (quota_scope
== "user") {
3385 set_quota_info(period_config
.user_quota
, opt_cmd
,
3386 max_size
, max_objects
,
3387 have_max_size
, have_max_objects
);
3388 encode_json("user quota", period_config
.user_quota
, formatter
);
3389 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3390 // if no scope is given for GET, print both
3391 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3392 encode_json("user quota", period_config
.user_quota
, formatter
);
3394 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3395 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3398 formatter
->close_section();
3400 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3401 // write the modified period config
3402 ret
= period_config
.write(store
, realm_id
);
3404 cerr
<< "ERROR: failed to write period config: "
3405 << cpp_strerror(-ret
) << std::endl
;
3408 if (!realm_id
.empty()) {
3409 cout
<< "Global quota changes saved. Use 'period update' to apply "
3410 "them to the staging period, and 'period commit' to commit the "
3411 "new period." << std::endl
;
3413 cout
<< "Global quota changes saved. They will take effect as "
3414 "the gateways are restarted." << std::endl
;
3418 formatter
->flush(cout
);
3422 case OPT_REALM_CREATE
:
3424 if (realm_name
.empty()) {
3425 cerr
<< "missing realm name" << std::endl
;
3429 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3430 int ret
= realm
.create();
3432 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3437 ret
= realm
.set_as_default();
3439 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3443 encode_json("realm", realm
, formatter
);
3444 formatter
->flush(cout
);
3448 case OPT_REALM_DELETE
:
3450 RGWRealm
realm(realm_id
, realm_name
);
3451 if (realm_name
.empty() && realm_id
.empty()) {
3452 cerr
<< "missing realm name or id" << std::endl
;
3455 int ret
= realm
.init(g_ceph_context
, store
);
3457 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3460 ret
= realm
.delete_obj();
3462 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3470 RGWRealm
realm(realm_id
, realm_name
);
3471 int ret
= realm
.init(g_ceph_context
, store
);
3473 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3474 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3476 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3480 encode_json("realm", realm
, formatter
);
3481 formatter
->flush(cout
);
3485 case OPT_REALM_GET_DEFAULT
:
3487 RGWRealm
realm(g_ceph_context
, store
);
3489 int ret
= realm
.read_default_id(default_id
);
3490 if (ret
== -ENOENT
) {
3491 cout
<< "No default realm is set" << std::endl
;
3493 } else if (ret
< 0) {
3494 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3497 cout
<< "default realm: " << default_id
<< std::endl
;
3500 case OPT_REALM_LIST
:
3502 RGWRealm
realm(g_ceph_context
, store
);
3504 int ret
= realm
.read_default_id(default_id
);
3505 if (ret
< 0 && ret
!= -ENOENT
) {
3506 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3508 list
<string
> realms
;
3509 ret
= store
->list_realms(realms
);
3511 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3514 formatter
->open_object_section("realms_list");
3515 encode_json("default_info", default_id
, formatter
);
3516 encode_json("realms", realms
, formatter
);
3517 formatter
->close_section();
3518 formatter
->flush(cout
);
3522 case OPT_REALM_LIST_PERIODS
:
3524 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3528 list
<string
> periods
;
3529 ret
= store
->list_periods(period_id
, periods
);
3531 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3534 formatter
->open_object_section("realm_periods_list");
3535 encode_json("current_period", period_id
, formatter
);
3536 encode_json("periods", periods
, formatter
);
3537 formatter
->close_section();
3538 formatter
->flush(cout
);
3543 case OPT_REALM_RENAME
:
3545 RGWRealm
realm(realm_id
, realm_name
);
3546 if (realm_new_name
.empty()) {
3547 cerr
<< "missing realm new name" << std::endl
;
3550 if (realm_name
.empty() && realm_id
.empty()) {
3551 cerr
<< "missing realm name or id" << std::endl
;
3554 int ret
= realm
.init(g_ceph_context
, store
);
3556 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3559 ret
= realm
.rename(realm_new_name
);
3561 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3564 cout
<< "Realm name updated. Note that this change only applies to "
3565 "the current cluster, so this command must be run separately "
3566 "on each of the realm's other clusters." << std::endl
;
3571 if (realm_id
.empty() && realm_name
.empty()) {
3572 cerr
<< "no realm name or id provided" << std::endl
;
3575 RGWRealm
realm(realm_id
, realm_name
);
3576 bool new_realm
= false;
3577 int ret
= realm
.init(g_ceph_context
, store
);
3578 if (ret
< 0 && ret
!= -ENOENT
) {
3579 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3581 } else if (ret
== -ENOENT
) {
3584 ret
= read_decode_json(infile
, realm
);
3588 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3589 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3590 realm
.get_name() << std::endl
;
3595 cout
<< "clearing period and epoch for new realm" << std::endl
;
3596 realm
.clear_current_period_and_epoch();
3597 ret
= realm
.create();
3599 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3603 ret
= realm
.update();
3605 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3611 ret
= realm
.set_as_default();
3613 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3616 encode_json("realm", realm
, formatter
);
3617 formatter
->flush(cout
);
3621 case OPT_REALM_DEFAULT
:
3623 RGWRealm
realm(realm_id
, realm_name
);
3624 int ret
= realm
.init(g_ceph_context
, store
);
3626 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3629 ret
= realm
.set_as_default();
3631 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3636 case OPT_REALM_PULL
:
3639 cerr
<< "A --url must be provided." << std::endl
;
3643 req_info
info(g_ceph_context
, &env
);
3644 info
.method
= "GET";
3645 info
.request_uri
= "/admin/realm";
3647 map
<string
, string
> ¶ms
= info
.args
.get_params();
3648 if (!realm_id
.empty())
3649 params
["id"] = realm_id
;
3650 if (!realm_name
.empty())
3651 params
["name"] = realm_name
;
3655 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3657 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3658 if (ret
== -EACCES
) {
3659 cerr
<< "If the realm has been changed on the master zone, the "
3660 "master zone's gateway may need to be restarted to recognize "
3661 "this user." << std::endl
;
3666 realm
.init(g_ceph_context
, store
, false);
3668 decode_json_obj(realm
, &p
);
3669 } catch (JSONDecoder::err
& e
) {
3670 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3674 auto& current_period
= realm
.get_current_period();
3675 if (!current_period
.empty()) {
3676 // pull the latest epoch of the realm's current period
3677 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3678 realm_id
, realm_name
, current_period
, "",
3681 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3685 ret
= realm
.create(false);
3686 if (ret
< 0 && ret
!= -EEXIST
) {
3687 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3688 << cpp_strerror(ret
) << std::endl
;
3690 } else if (ret
==-EEXIST
) {
3691 ret
= realm
.update();
3693 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3694 << cpp_strerror(ret
) << std::endl
;
3699 ret
= realm
.set_as_default();
3701 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3705 encode_json("realm", realm
, formatter
);
3706 formatter
->flush(cout
);
3711 case OPT_ZONEGROUP_ADD
:
3713 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3714 cerr
<< "no zonegroup name or id provided" << std::endl
;
3718 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3719 int ret
= zonegroup
.init(g_ceph_context
, store
);
3721 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3722 << cpp_strerror(-ret
) << std::endl
;
3725 RGWZoneParams
zone(zone_id
, zone_name
);
3726 ret
= zone
.init(g_ceph_context
, store
);
3728 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3731 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3732 zone
.realm_id
= zonegroup
.realm_id
;
3733 ret
= zone
.update();
3735 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
3740 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3741 zone
.tier_config
= tier_config_add
;
3743 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3745 ret
= zonegroup
.add_zone(zone
,
3746 (is_master_set
? &is_master
: NULL
),
3747 (is_read_only_set
? &read_only
: NULL
),
3748 endpoints
, ptier_type
,
3749 psync_from_all
, sync_from
, sync_from_rm
);
3751 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3752 << cpp_strerror(-ret
) << std::endl
;
3756 encode_json("zonegroup", zonegroup
, formatter
);
3757 formatter
->flush(cout
);
3760 case OPT_ZONEGROUP_CREATE
:
3762 if (zonegroup_name
.empty()) {
3763 cerr
<< "Missing zonegroup name" << std::endl
;
3766 RGWRealm
realm(realm_id
, realm_name
);
3767 int ret
= realm
.init(g_ceph_context
, store
);
3769 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3773 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3774 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3775 ret
= zonegroup
.create();
3777 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3782 ret
= zonegroup
.set_as_default();
3784 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3788 encode_json("zonegroup", zonegroup
, formatter
);
3789 formatter
->flush(cout
);
3793 case OPT_ZONEGROUP_DEFAULT
:
3795 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3796 cerr
<< "no zonegroup name or id provided" << std::endl
;
3800 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3801 int ret
= zonegroup
.init(g_ceph_context
, store
);
3803 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3807 ret
= zonegroup
.set_as_default();
3809 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3814 case OPT_ZONEGROUP_DELETE
:
3816 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3817 cerr
<< "no zonegroup name or id provided" << std::endl
;
3820 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3821 int ret
= zonegroup
.init(g_ceph_context
, store
);
3823 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3826 ret
= zonegroup
.delete_obj();
3828 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3833 case OPT_ZONEGROUP_GET
:
3835 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3836 int ret
= zonegroup
.init(g_ceph_context
, store
);
3838 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3842 encode_json("zonegroup", zonegroup
, formatter
);
3843 formatter
->flush(cout
);
3847 case OPT_ZONEGROUP_LIST
:
3849 RGWZoneGroup zonegroup
;
3850 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3852 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3856 list
<string
> zonegroups
;
3857 ret
= store
->list_zonegroups(zonegroups
);
3859 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3862 string default_zonegroup
;
3863 ret
= zonegroup
.read_default_id(default_zonegroup
);
3864 if (ret
< 0 && ret
!= -ENOENT
) {
3865 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3867 formatter
->open_object_section("zonegroups_list");
3868 encode_json("default_info", default_zonegroup
, formatter
);
3869 encode_json("zonegroups", zonegroups
, formatter
);
3870 formatter
->close_section();
3871 formatter
->flush(cout
);
3875 case OPT_ZONEGROUP_MODIFY
:
3877 RGWRealm
realm(realm_id
, realm_name
);
3878 int ret
= realm
.init(g_ceph_context
, store
);
3880 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3884 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3885 ret
= zonegroup
.init(g_ceph_context
, store
);
3887 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3891 bool need_update
= false;
3893 if (!master_zone
.empty()) {
3894 zonegroup
.master_zone
= master_zone
;
3898 if (is_master_set
) {
3899 zonegroup
.update_master(is_master
);
3903 if (!endpoints
.empty()) {
3904 zonegroup
.endpoints
= endpoints
;
3908 if (!api_name
.empty()) {
3909 zonegroup
.api_name
= api_name
;
3913 if (!realm_id
.empty()) {
3914 zonegroup
.realm_id
= realm_id
;
3916 } else if (!realm_name
.empty()) {
3917 // get realm id from name
3918 RGWRealm realm
{g_ceph_context
, store
};
3919 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3921 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3928 ret
= zonegroup
.update();
3930 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3936 ret
= zonegroup
.set_as_default();
3938 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3942 encode_json("zonegroup", zonegroup
, formatter
);
3943 formatter
->flush(cout
);
3946 case OPT_ZONEGROUP_SET
:
3948 RGWRealm
realm(realm_id
, realm_name
);
3949 int ret
= realm
.init(g_ceph_context
, store
);
3951 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3955 RGWZoneGroup zonegroup
;
3956 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3958 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3961 ret
= read_decode_json(infile
, zonegroup
);
3965 if (zonegroup
.realm_id
.empty()) {
3966 zonegroup
.realm_id
= realm
.get_id();
3968 ret
= zonegroup
.create();
3969 if (ret
< 0 && ret
!= -EEXIST
) {
3970 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3972 } else if (ret
== -EEXIST
) {
3973 ret
= zonegroup
.update();
3975 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3981 ret
= zonegroup
.set_as_default();
3983 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3987 encode_json("zonegroup", zonegroup
, formatter
);
3988 formatter
->flush(cout
);
3991 case OPT_ZONEGROUP_REMOVE
:
3993 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3994 int ret
= zonegroup
.init(g_ceph_context
, store
);
3996 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4000 if (zone_id
.empty()) {
4001 if (zone_name
.empty()) {
4002 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
4005 // look up zone id by name
4006 for (auto& z
: zonegroup
.zones
) {
4007 if (zone_name
== z
.second
.name
) {
4008 zone_id
= z
.second
.id
;
4012 if (zone_id
.empty()) {
4013 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
4014 << zonegroup
.get_name() << std::endl
;
4019 ret
= zonegroup
.remove_zone(zone_id
);
4021 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
4025 encode_json("zonegroup", zonegroup
, formatter
);
4026 formatter
->flush(cout
);
4029 case OPT_ZONEGROUP_RENAME
:
4031 if (zonegroup_new_name
.empty()) {
4032 cerr
<< " missing zonegroup new name" << std::endl
;
4035 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
4036 cerr
<< "no zonegroup name or id provided" << std::endl
;
4039 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4040 int ret
= zonegroup
.init(g_ceph_context
, store
);
4042 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4045 ret
= zonegroup
.rename(zonegroup_new_name
);
4047 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4052 case OPT_ZONEGROUP_PLACEMENT_LIST
:
4054 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4055 int ret
= zonegroup
.init(g_ceph_context
, store
);
4057 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4061 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
4062 formatter
->flush(cout
);
4066 case OPT_ZONEGROUP_PLACEMENT_ADD
:
4067 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
4068 case OPT_ZONEGROUP_PLACEMENT_RM
:
4069 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
4071 if (placement_id
.empty()) {
4072 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4076 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4077 int ret
= zonegroup
.init(g_ceph_context
, store
);
4079 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4083 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
4084 RGWZoneGroupPlacementTarget target
;
4085 target
.name
= placement_id
;
4086 for (auto& t
: tags
) {
4087 target
.tags
.insert(t
);
4089 zonegroup
.placement_targets
[placement_id
] = target
;
4090 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
4091 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
4092 if (!tags
.empty()) {
4093 target
.tags
.clear();
4094 for (auto& t
: tags
) {
4095 target
.tags
.insert(t
);
4098 target
.name
= placement_id
;
4099 for (auto& t
: tags_rm
) {
4100 target
.tags
.erase(t
);
4102 for (auto& t
: tags_add
) {
4103 target
.tags
.insert(t
);
4105 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
4106 zonegroup
.placement_targets
.erase(placement_id
);
4107 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
4108 if (!zonegroup
.placement_targets
.count(placement_id
)) {
4109 cerr
<< "failed to find a zonegroup placement target named '"
4110 << placement_id
<< "'" << std::endl
;
4113 zonegroup
.default_placement
= placement_id
;
4116 zonegroup
.post_process_params();
4117 ret
= zonegroup
.update();
4119 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4123 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
4124 formatter
->flush(cout
);
4127 case OPT_ZONE_CREATE
:
4129 if (zone_name
.empty()) {
4130 cerr
<< "zone name not provided" << std::endl
;
4134 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4135 /* if the user didn't provide zonegroup info , create stand alone zone */
4136 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
4137 ret
= zonegroup
.init(g_ceph_context
, store
);
4139 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4142 if (realm_id
.empty() && realm_name
.empty()) {
4143 realm_id
= zonegroup
.realm_id
;
4147 RGWZoneParams
zone(zone_id
, zone_name
);
4148 ret
= zone
.init(g_ceph_context
, store
, false);
4150 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4154 zone
.system_key
.id
= access_key
;
4155 zone
.system_key
.key
= secret_key
;
4156 zone
.realm_id
= realm_id
;
4157 zone
.tier_config
= tier_config_add
;
4159 ret
= zone
.create();
4161 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4165 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
4166 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4167 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4168 ret
= zonegroup
.add_zone(zone
,
4169 (is_master_set
? &is_master
: NULL
),
4170 (is_read_only_set
? &read_only
: NULL
),
4174 sync_from
, sync_from_rm
);
4176 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
4177 << ": " << cpp_strerror(-ret
) << std::endl
;
4183 ret
= zone
.set_as_default();
4185 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4189 encode_json("zone", zone
, formatter
);
4190 formatter
->flush(cout
);
4194 case OPT_ZONE_DEFAULT
:
4196 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
4197 int ret
= zonegroup
.init(g_ceph_context
, store
);
4199 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4201 if (zone_id
.empty() && zone_name
.empty()) {
4202 cerr
<< "no zone name or id provided" << std::endl
;
4205 RGWZoneParams
zone(zone_id
, zone_name
);
4206 ret
= zone
.init(g_ceph_context
, store
);
4208 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4211 ret
= zone
.set_as_default();
4213 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
4218 case OPT_ZONE_DELETE
:
4220 if (zone_id
.empty() && zone_name
.empty()) {
4221 cerr
<< "no zone name or id provided" << std::endl
;
4224 RGWZoneParams
zone(zone_id
, zone_name
);
4225 int ret
= zone
.init(g_ceph_context
, store
);
4227 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4231 list
<string
> zonegroups
;
4232 ret
= store
->list_zonegroups(zonegroups
);
4234 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
4238 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
4239 RGWZoneGroup
zonegroup(string(), *iter
);
4240 int ret
= zonegroup
.init(g_ceph_context
, store
);
4242 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4245 ret
= zonegroup
.remove_zone(zone
.get_id());
4246 if (ret
< 0 && ret
!= -ENOENT
) {
4247 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
4248 << cpp_strerror(-ret
) << std::endl
;
4252 ret
= zone
.delete_obj();
4254 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4261 RGWZoneParams
zone(zone_id
, zone_name
);
4262 int ret
= zone
.init(g_ceph_context
, store
);
4264 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4267 encode_json("zone", zone
, formatter
);
4268 formatter
->flush(cout
);
4273 RGWZoneParams
zone(zone_name
);
4274 int ret
= zone
.init(g_ceph_context
, store
, false);
4280 if (ret
< 0 && ret
!= -ENOENT
) {
4281 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
4285 string orig_id
= zone
.get_id();
4287 ret
= read_decode_json(infile
, zone
);
4292 if(zone
.realm_id
.empty()) {
4293 RGWRealm
realm(realm_id
, realm_name
);
4294 int ret
= realm
.init(g_ceph_context
, store
);
4295 if (ret
< 0 && ret
!= -ENOENT
) {
4296 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4299 zone
.realm_id
= realm
.get_id();
4302 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
4303 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
4307 if (zone
.get_name().empty()) {
4308 zone
.set_name(zone_name
);
4309 if (zone
.get_name().empty()) {
4310 cerr
<< "no zone name specified" << std::endl
;
4315 zone_name
= zone
.get_name();
4317 if (zone
.get_id().empty()) {
4318 zone
.set_id(orig_id
);
4321 if (zone
.get_id().empty()) {
4322 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
4323 if (zone_name
.empty()) {
4324 cerr
<< "missing zone name" << std::endl
;
4327 zone
.set_name(zone_name
);
4328 zone
.set_id(zone_name
);
4331 cerr
<< "zone id " << zone
.get_id();
4332 ret
= zone
.fix_pool_names();
4334 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4337 ret
= zone
.write(false);
4339 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4344 ret
= zone
.set_as_default();
4346 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4350 encode_json("zone", zone
, formatter
);
4351 formatter
->flush(cout
);
4357 int ret
= store
->list_zones(zones
);
4359 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4364 ret
= zone
.init(g_ceph_context
, store
, false);
4366 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4369 string default_zone
;
4370 ret
= zone
.read_default_id(default_zone
);
4371 if (ret
< 0 && ret
!= -ENOENT
) {
4372 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4374 formatter
->open_object_section("zones_list");
4375 encode_json("default_info", default_zone
, formatter
);
4376 encode_json("zones", zones
, formatter
);
4377 formatter
->close_section();
4378 formatter
->flush(cout
);
4382 case OPT_ZONE_MODIFY
:
4384 RGWZoneParams
zone(zone_id
, zone_name
);
4385 int ret
= zone
.init(g_ceph_context
, store
);
4387 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4391 bool need_zone_update
= false;
4392 if (!access_key
.empty()) {
4393 zone
.system_key
.id
= access_key
;
4394 need_zone_update
= true;
4397 if (!secret_key
.empty()) {
4398 zone
.system_key
.key
= secret_key
;
4399 need_zone_update
= true;
4402 if (!realm_id
.empty()) {
4403 zone
.realm_id
= realm_id
;
4404 need_zone_update
= true;
4405 } else if (!realm_name
.empty()) {
4406 // get realm id from name
4407 RGWRealm realm
{g_ceph_context
, store
};
4408 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4410 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4413 need_zone_update
= true;
4416 for (auto add
: tier_config_add
) {
4417 zone
.tier_config
[add
.first
] = add
.second
;
4418 need_zone_update
= true;
4421 for (auto rm
: tier_config_rm
) {
4422 zone
.tier_config
.erase(rm
.first
);
4423 need_zone_update
= true;
4426 if (need_zone_update
) {
4427 ret
= zone
.update();
4429 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4434 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4435 ret
= zonegroup
.init(g_ceph_context
, store
);
4437 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4440 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4442 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4444 ret
= zonegroup
.add_zone(zone
,
4445 (is_master_set
? &is_master
: NULL
),
4446 (is_read_only_set
? &read_only
: NULL
),
4447 endpoints
, ptier_type
,
4448 psync_from_all
, sync_from
, sync_from_rm
);
4450 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4454 ret
= zonegroup
.update();
4456 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4461 ret
= zone
.set_as_default();
4463 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4467 encode_json("zone", zone
, formatter
);
4468 formatter
->flush(cout
);
4471 case OPT_ZONE_RENAME
:
4473 if (zone_new_name
.empty()) {
4474 cerr
<< " missing zone new name" << std::endl
;
4477 if (zone_id
.empty() && zone_name
.empty()) {
4478 cerr
<< "no zonegroup name or id provided" << std::endl
;
4481 RGWZoneParams
zone(zone_id
,zone_name
);
4482 int ret
= zone
.init(g_ceph_context
, store
);
4484 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4487 ret
= zone
.rename(zone_new_name
);
4489 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4493 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4494 ret
= zonegroup
.init(g_ceph_context
, store
);
4496 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4498 ret
= zonegroup
.rename_zone(zone
);
4499 if (ret
< 0 && ret
) {
4500 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4506 case OPT_ZONE_PLACEMENT_ADD
:
4507 case OPT_ZONE_PLACEMENT_MODIFY
:
4508 case OPT_ZONE_PLACEMENT_RM
:
4510 if (placement_id
.empty()) {
4511 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4514 // validate compression type
4515 if (compression_type
&& *compression_type
!= "random"
4516 && !Compressor::get_comp_alg_type(*compression_type
)) {
4517 std::cerr
<< "Unrecognized compression type" << std::endl
;
4521 RGWZoneParams
zone(zone_id
, zone_name
);
4522 int ret
= zone
.init(g_ceph_context
, store
);
4524 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4528 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4529 // pool names are required
4530 if (!index_pool
|| index_pool
->empty() ||
4531 !data_pool
|| data_pool
->empty()) {
4532 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4536 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4538 info
.index_pool
= *index_pool
;
4539 info
.data_pool
= *data_pool
;
4540 if (data_extra_pool
) {
4541 info
.data_extra_pool
= *data_extra_pool
;
4543 if (index_type_specified
) {
4544 info
.index_type
= placement_index_type
;
4546 if (compression_type
) {
4547 info
.compression_type
= *compression_type
;
4549 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4550 auto p
= zone
.placement_pools
.find(placement_id
);
4551 if (p
== zone
.placement_pools
.end()) {
4552 cerr
<< "ERROR: zone placement target '" << placement_id
4553 << "' not found" << std::endl
;
4556 auto& info
= p
->second
;
4557 if (index_pool
&& !index_pool
->empty()) {
4558 info
.index_pool
= *index_pool
;
4560 if (data_pool
&& !data_pool
->empty()) {
4561 info
.data_pool
= *data_pool
;
4563 if (data_extra_pool
) {
4564 info
.data_extra_pool
= *data_extra_pool
;
4566 if (index_type_specified
) {
4567 info
.index_type
= placement_index_type
;
4569 if (compression_type
) {
4570 info
.compression_type
= *compression_type
;
4572 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4573 zone
.placement_pools
.erase(placement_id
);
4576 ret
= zone
.update();
4578 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4582 encode_json("zone", zone
, formatter
);
4583 formatter
->flush(cout
);
4586 case OPT_ZONE_PLACEMENT_LIST
:
4588 RGWZoneParams
zone(zone_id
, zone_name
);
4589 int ret
= zone
.init(g_ceph_context
, store
);
4591 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4594 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4595 formatter
->flush(cout
);
4602 if (!user_id
.empty()) {
4603 user_op
.set_user_id(user_id
);
4604 bucket_op
.set_user_id(user_id
);
4607 if (!display_name
.empty())
4608 user_op
.set_display_name(display_name
);
4610 if (!user_email
.empty())
4611 user_op
.set_user_email(user_email
);
4613 if (!access_key
.empty())
4614 user_op
.set_access_key(access_key
);
4616 if (!secret_key
.empty())
4617 user_op
.set_secret_key(secret_key
);
4619 if (!subuser
.empty())
4620 user_op
.set_subuser(subuser
);
4623 user_op
.set_caps(caps
);
4625 user_op
.set_purge_data(purge_data
);
4628 user_op
.set_purge_keys();
4631 user_op
.set_generate_key();
4634 user_op
.set_gen_secret(); // assume that a key pair should be created
4636 if (max_buckets_specified
)
4637 user_op
.set_max_buckets(max_buckets
);
4639 if (admin_specified
)
4640 user_op
.set_admin(admin
);
4642 if (system_specified
)
4643 user_op
.set_system(system
);
4646 user_op
.set_perm(perm_mask
);
4648 if (set_temp_url_key
) {
4649 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4650 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4651 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4655 if (!op_mask_str
.empty()) {
4657 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4659 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4663 user_op
.set_op_mask(op_mask
);
4666 if (key_type
!= KEY_TYPE_UNDEFINED
)
4667 user_op
.set_key_type(key_type
);
4669 // set suspension operation parameters
4670 if (opt_cmd
== OPT_USER_ENABLE
)
4671 user_op
.set_suspension(false);
4672 else if (opt_cmd
== OPT_USER_SUSPEND
)
4673 user_op
.set_suspension(true);
4675 // RGWUser to use for user operations
4678 if (!user_id
.empty() || !subuser
.empty()) {
4679 ret
= user
.init(store
, user_op
);
4681 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4686 /* populate bucket operation */
4687 bucket_op
.set_bucket_name(bucket_name
);
4688 bucket_op
.set_object(object
);
4689 bucket_op
.set_check_objects(check_objects
);
4690 bucket_op
.set_delete_children(delete_child_objects
);
4691 bucket_op
.set_fix_index(fix
);
4692 bucket_op
.set_max_aio(max_concurrent_ios
);
4694 // required to gather errors from operations
4695 std::string err_msg
;
4697 bool output_user_info
= true;
4702 case OPT_USER_CREATE
:
4703 if (!user_op
.has_existing_user()) {
4704 user_op
.set_generate_key(); // generate a new key by default
4706 ret
= user
.add(user_op
, &err_msg
);
4708 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4709 if (ret
== -ERR_INVALID_TENANT_NAME
)
4714 if (!subuser
.empty()) {
4715 ret
= user
.subusers
.add(user_op
, &err_msg
);
4717 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4723 ret
= user
.remove(user_op
, &err_msg
);
4725 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4729 output_user_info
= false;
4731 case OPT_USER_ENABLE
:
4732 case OPT_USER_SUSPEND
:
4733 case OPT_USER_MODIFY
:
4734 ret
= user
.modify(user_op
, &err_msg
);
4736 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4741 case OPT_SUBUSER_CREATE
:
4742 ret
= user
.subusers
.add(user_op
, &err_msg
);
4744 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4749 case OPT_SUBUSER_MODIFY
:
4750 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4752 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4757 case OPT_SUBUSER_RM
:
4758 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4760 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4766 ret
= user
.caps
.add(user_op
, &err_msg
);
4768 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4774 ret
= user
.caps
.remove(user_op
, &err_msg
);
4776 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4781 case OPT_KEY_CREATE
:
4782 ret
= user
.keys
.add(user_op
, &err_msg
);
4784 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4790 ret
= user
.keys
.remove(user_op
, &err_msg
);
4792 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4796 case OPT_PERIOD_PUSH
:
4799 req_info
info(g_ceph_context
, &env
);
4800 info
.method
= "POST";
4801 info
.request_uri
= "/admin/realm/period";
4803 map
<string
, string
> ¶ms
= info
.args
.get_params();
4804 if (!realm_id
.empty())
4805 params
["realm_id"] = realm_id
;
4806 if (!realm_name
.empty())
4807 params
["realm_name"] = realm_name
;
4808 if (!period_id
.empty())
4809 params
["period_id"] = period_id
;
4810 if (!period_epoch
.empty())
4811 params
["epoch"] = period_epoch
;
4814 RGWPeriod
period(period_id
);
4815 int ret
= period
.init(g_ceph_context
, store
);
4817 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4820 // json format into a bufferlist
4821 JSONFormatter
jf(false);
4822 encode_json("period", period
, &jf
);
4827 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4830 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4835 case OPT_PERIOD_UPDATE
:
4837 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4838 commit
, remote
, url
, access_key
, secret_key
,
4839 formatter
, yes_i_really_mean_it
);
4845 case OPT_PERIOD_COMMIT
:
4847 // read realm and staging period
4848 RGWRealm
realm(realm_id
, realm_name
);
4849 int ret
= realm
.init(g_ceph_context
, store
);
4851 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4854 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4855 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4857 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4860 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4861 yes_i_really_mean_it
);
4863 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4867 encode_json("period", period
, formatter
);
4868 formatter
->flush(cout
);
4872 case OPT_ROLE_CREATE
:
4874 if (role_name
.empty()) {
4875 cerr
<< "ERROR: role name is empty" << std::endl
;
4879 if (assume_role_doc
.empty()) {
4880 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4883 /* The following two calls will be replaced by read_decode_json or something
4884 similar when the code for AWS Policies is in places */
4886 int ret
= read_input(assume_role_doc
, bl
);
4888 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4892 if (!p
.parse(bl
.c_str(), bl
.length())) {
4893 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4896 string trust_policy
= bl
.to_str();
4897 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4898 ret
= role
.create(true);
4902 show_role_info(role
, formatter
);
4905 case OPT_ROLE_DELETE
:
4907 if (role_name
.empty()) {
4908 cerr
<< "ERROR: empty role name" << std::endl
;
4911 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4912 ret
= role
.delete_obj();
4916 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4921 if (role_name
.empty()) {
4922 cerr
<< "ERROR: empty role name" << std::endl
;
4925 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4930 show_role_info(role
, formatter
);
4933 case OPT_ROLE_MODIFY
:
4935 if (role_name
.empty()) {
4936 cerr
<< "ERROR: role name is empty" << std::endl
;
4940 if (assume_role_doc
.empty()) {
4941 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4945 /* The following two calls will be replaced by read_decode_json or something
4946 similar when the code for AWS Policies is in place */
4948 int ret
= read_input(assume_role_doc
, bl
);
4950 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4954 if (!p
.parse(bl
.c_str(), bl
.length())) {
4955 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4958 string trust_policy
= bl
.to_str();
4959 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4964 role
.update_trust_policy(trust_policy
);
4965 ret
= role
.update();
4969 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4974 vector
<RGWRole
> result
;
4975 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4979 show_roles_info(result
, formatter
);
4982 case OPT_ROLE_POLICY_PUT
:
4984 if (role_name
.empty()) {
4985 cerr
<< "role name is empty" << std::endl
;
4989 if (policy_name
.empty()) {
4990 cerr
<< "policy name is empty" << std::endl
;
4994 if (perm_policy_doc
.empty()) {
4995 cerr
<< "permission policy document is empty" << std::endl
;
4999 /* The following two calls will be replaced by read_decode_json or something
5000 similar, when code for AWS Policies is in place.*/
5002 int ret
= read_input(perm_policy_doc
, bl
);
5004 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
5008 if (!p
.parse(bl
.c_str(), bl
.length())) {
5009 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
5013 perm_policy
= bl
.c_str();
5015 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5020 role
.set_perm_policy(policy_name
, perm_policy
);
5021 ret
= role
.update();
5025 cout
<< "Permission policy attached successfully" << std::endl
;
5028 case OPT_ROLE_POLICY_LIST
:
5030 if (role_name
.empty()) {
5031 cerr
<< "ERROR: Role name is empty" << std::endl
;
5034 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5039 std::vector
<string
> policy_names
= role
.get_role_policy_names();
5040 show_policy_names(policy_names
, formatter
);
5043 case OPT_ROLE_POLICY_GET
:
5045 if (role_name
.empty()) {
5046 cerr
<< "ERROR: role name is empty" << std::endl
;
5050 if (policy_name
.empty()) {
5051 cerr
<< "ERROR: policy name is empty" << std::endl
;
5054 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5055 int ret
= role
.get();
5060 ret
= role
.get_role_policy(policy_name
, perm_policy
);
5064 show_perm_policy(perm_policy
, formatter
);
5067 case OPT_ROLE_POLICY_DELETE
:
5069 if (role_name
.empty()) {
5070 cerr
<< "ERROR: role name is empty" << std::endl
;
5074 if (policy_name
.empty()) {
5075 cerr
<< "ERROR: policy name is empty" << std::endl
;
5078 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5083 ret
= role
.delete_policy(policy_name
);
5087 ret
= role
.update();
5091 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
5092 << role_name
<< std::endl
;
5096 output_user_info
= false;
5099 // output the result of a user operation
5100 if (output_user_info
) {
5101 ret
= user
.info(info
, &err_msg
);
5103 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
5106 show_user_info(info
, formatter
);
5109 if (opt_cmd
== OPT_POLICY
) {
5110 if (format
== "xml") {
5111 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
5113 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
5117 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
5119 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
5125 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
5127 std::list
<std::string
> user_ids
;
5128 metadata_key
= "user";
5133 if (! user_id
.empty()) {
5134 user_ids
.push_back(user_id
.id
);
5136 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
5139 /* list users in groups of max-keys, then perform user-bucket
5140 * limit-check on each group */
5141 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
5143 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
5144 << cpp_strerror(-ret
) << std::endl
;
5149 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
5151 if (ret
< 0 && ret
!= -ENOENT
) {
5152 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
5153 << cpp_strerror(-ret
) << std::endl
;
5156 /* ok, do the limit checks for this group */
5158 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
5164 } while (truncated
);
5165 store
->meta_mgr
->list_keys_complete(handle
);
5168 } /* OPT_BUCKET_LIMIT_CHECK */
5170 if (opt_cmd
== OPT_BUCKETS_LIST
) {
5171 if (bucket_name
.empty()) {
5172 RGWBucketAdminOp::info(store
, bucket_op
, f
);
5174 RGWBucketInfo bucket_info
;
5175 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5177 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5180 formatter
->open_array_section("entries");
5183 if (max_entries
< 0)
5188 vector
<rgw_bucket_dir_entry
> result
;
5189 map
<string
, bool> common_prefixes
;
5192 RGWRados::Bucket
target(store
, bucket_info
);
5193 RGWRados::Bucket::List
list_op(&target
);
5195 list_op
.params
.prefix
= prefix
;
5196 list_op
.params
.delim
= delim
;
5197 list_op
.params
.marker
= rgw_obj_key(marker
);
5198 list_op
.params
.ns
= ns
;
5199 list_op
.params
.enforce_ns
= false;
5200 list_op
.params
.list_versions
= true;
5203 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
5205 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
5209 count
+= result
.size();
5211 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5212 rgw_bucket_dir_entry
& entry
= *iter
;
5213 encode_json("entry", entry
, formatter
);
5215 formatter
->flush(cout
);
5216 } while (truncated
&& count
< max_entries
);
5218 formatter
->close_section();
5219 formatter
->flush(cout
);
5220 } /* have bucket_name */
5221 } /* OPT_BUCKETS_LIST */
5223 if (opt_cmd
== OPT_BUCKET_STATS
) {
5224 bucket_op
.set_fetch_stats(true);
5226 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
5228 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
5233 if (opt_cmd
== OPT_BUCKET_LINK
) {
5234 bucket_op
.set_bucket_id(bucket_id
);
5236 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
5238 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
5243 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
5244 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
5246 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
5251 if (opt_cmd
== OPT_LOG_LIST
) {
5253 if (date
.size() && date
.size() != 10) {
5254 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
5259 formatter
->open_array_section("logs");
5261 int r
= store
->log_list_init(date
, &h
);
5266 cerr
<< "log list: error " << r
<< std::endl
;
5271 int r
= store
->log_list_next(h
, &name
);
5275 cerr
<< "log list: error " << r
<< std::endl
;
5278 formatter
->dump_string("object", name
);
5281 formatter
->close_section();
5282 formatter
->flush(cout
);
5286 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5287 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5288 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5294 if (!object
.empty()) {
5304 if (opt_cmd
== OPT_LOG_SHOW
) {
5307 int r
= store
->log_show_init(oid
, &h
);
5309 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5314 formatter
->open_object_section("log");
5316 struct rgw_log_entry entry
;
5318 // peek at first entry to get bucket metadata
5319 r
= store
->log_show_next(h
, &entry
);
5321 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5324 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5325 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5326 formatter
->dump_string("bucket", entry
.bucket
);
5328 uint64_t agg_time
= 0;
5329 uint64_t agg_bytes_sent
= 0;
5330 uint64_t agg_bytes_received
= 0;
5331 uint64_t total_entries
= 0;
5333 if (show_log_entries
)
5334 formatter
->open_array_section("log_entries");
5337 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5339 agg_time
+= total_time
;
5340 agg_bytes_sent
+= entry
.bytes_sent
;
5341 agg_bytes_received
+= entry
.bytes_received
;
5344 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5345 entry
.bytes_received
== 0)
5348 if (show_log_entries
) {
5350 rgw_format_ops_log_entry(entry
, formatter
);
5351 formatter
->flush(cout
);
5354 r
= store
->log_show_next(h
, &entry
);
5358 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5361 if (show_log_entries
)
5362 formatter
->close_section();
5365 formatter
->open_object_section("log_sum");
5366 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5367 formatter
->dump_int("bytes_received", agg_bytes_received
);
5368 formatter
->dump_int("total_time", agg_time
);
5369 formatter
->dump_int("total_entries", total_entries
);
5370 formatter
->close_section();
5372 formatter
->close_section();
5373 formatter
->flush(cout
);
5376 if (opt_cmd
== OPT_LOG_RM
) {
5377 int r
= store
->log_remove(oid
);
5379 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5385 if (opt_cmd
== OPT_POOL_ADD
) {
5386 if (pool_name
.empty()) {
5387 cerr
<< "need to specify pool to add!" << std::endl
;
5392 int ret
= store
->add_bucket_placement(pool
);
5394 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5397 if (opt_cmd
== OPT_POOL_RM
) {
5398 if (pool_name
.empty()) {
5399 cerr
<< "need to specify pool to remove!" << std::endl
;
5404 int ret
= store
->remove_bucket_placement(pool
);
5406 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5409 if (opt_cmd
== OPT_POOLS_LIST
) {
5410 set
<rgw_pool
> pools
;
5411 int ret
= store
->list_placement_set(pools
);
5413 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5417 formatter
->open_array_section("pools");
5418 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5419 formatter
->open_object_section("pool");
5420 formatter
->dump_string("name", siter
->to_str());
5421 formatter
->close_section();
5423 formatter
->close_section();
5424 formatter
->flush(cout
);
5428 if (opt_cmd
== OPT_USAGE_SHOW
) {
5429 uint64_t start_epoch
= 0;
5430 uint64_t end_epoch
= (uint64_t)-1;
5434 if (!start_date
.empty()) {
5435 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5437 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5441 if (!end_date
.empty()) {
5442 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5444 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5450 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5451 show_log_entries
, show_log_sum
, &categories
,
5454 cerr
<< "ERROR: failed to show usage" << std::endl
;
5459 if (opt_cmd
== OPT_USAGE_TRIM
) {
5460 if (user_id
.empty() && !yes_i_really_mean_it
) {
5461 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5462 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5466 uint64_t start_epoch
= 0;
5467 uint64_t end_epoch
= (uint64_t)-1;
5470 if (!start_date
.empty()) {
5471 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5473 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5478 if (!end_date
.empty()) {
5479 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5481 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5486 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5488 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5493 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5494 if (bucket_name
.empty()) {
5495 cerr
<< "ERROR: bucket not specified" << std::endl
;
5498 if (object
.empty()) {
5499 cerr
<< "ERROR: object not specified" << std::endl
;
5504 if (opt_cmd
== OPT_OLH_GET
) {
5505 RGWBucketInfo bucket_info
;
5506 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5508 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5512 rgw_obj
obj(bucket
, object
);
5513 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5515 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5518 encode_json("olh", olh
, formatter
);
5519 formatter
->flush(cout
);
5522 if (opt_cmd
== OPT_OLH_READLOG
) {
5523 RGWBucketInfo bucket_info
;
5524 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5526 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5529 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5532 RGWObjectCtx
rctx(store
);
5533 rgw_obj
obj(bucket
, object
);
5537 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5542 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5544 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5547 formatter
->open_object_section("result");
5548 encode_json("is_truncated", is_truncated
, formatter
);
5549 encode_json("log", log
, formatter
);
5550 formatter
->close_section();
5551 formatter
->flush(cout
);
5554 if (opt_cmd
== OPT_BI_GET
) {
5555 RGWBucketInfo bucket_info
;
5556 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5558 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5561 rgw_obj
obj(bucket
, object
);
5562 if (!object_version
.empty()) {
5563 obj
.key
.set_instance(object_version
);
5566 rgw_cls_bi_entry entry
;
5568 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5570 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5574 encode_json("entry", entry
, formatter
);
5575 formatter
->flush(cout
);
5578 if (opt_cmd
== OPT_BI_PUT
) {
5579 RGWBucketInfo bucket_info
;
5580 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5582 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5586 rgw_cls_bi_entry entry
;
5587 cls_rgw_obj_key key
;
5588 ret
= read_decode_json(infile
, entry
, &key
);
5593 rgw_obj
obj(bucket
, key
);
5595 ret
= store
->bi_put(bucket
, obj
, entry
);
5597 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5602 if (opt_cmd
== OPT_BI_LIST
) {
5603 if (bucket_name
.empty()) {
5604 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5607 RGWBucketInfo bucket_info
;
5608 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5610 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5614 list
<rgw_cls_bi_entry
> entries
;
5616 if (max_entries
< 0) {
5620 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5622 formatter
->open_array_section("entries");
5624 for (int i
= 0; i
< max_shards
; i
++) {
5625 RGWRados::BucketShard
bs(store
);
5626 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5627 int ret
= bs
.init(bucket
, shard_id
);
5631 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5637 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5639 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5643 list
<rgw_cls_bi_entry
>::iterator iter
;
5644 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5645 rgw_cls_bi_entry
& entry
= *iter
;
5646 encode_json("entry", entry
, formatter
);
5649 formatter
->flush(cout
);
5650 } while (is_truncated
);
5651 formatter
->flush(cout
);
5653 formatter
->close_section();
5654 formatter
->flush(cout
);
5657 if (opt_cmd
== OPT_BI_PURGE
) {
5658 if (bucket_name
.empty()) {
5659 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5662 RGWBucketInfo bucket_info
;
5663 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5665 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5669 RGWBucketInfo cur_bucket_info
;
5670 rgw_bucket cur_bucket
;
5671 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5673 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5677 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5678 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5679 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5683 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5685 for (int i
= 0; i
< max_shards
; i
++) {
5686 RGWRados::BucketShard
bs(store
);
5687 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5688 int ret
= bs
.init(bucket
, shard_id
);
5690 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5694 ret
= store
->bi_remove(bs
);
5696 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5702 if (opt_cmd
== OPT_OBJECT_RM
) {
5703 RGWBucketInfo bucket_info
;
5704 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5706 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5709 rgw_obj_key
key(object
, object_version
);
5710 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5713 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5718 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5719 if (bucket_name
.empty()) {
5720 cerr
<< "ERROR: bucket not specified" << std::endl
;
5723 if (object
.empty()) {
5724 cerr
<< "ERROR: object not specified" << std::endl
;
5728 RGWBucketInfo bucket_info
;
5729 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5731 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5735 rgw_obj
obj(bucket
, object
);
5736 obj
.key
.set_instance(object_version
);
5737 bool need_rewrite
= true;
5738 if (min_rewrite_stripe_size
> 0) {
5739 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5741 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5745 ret
= store
->rewrite_obj(bucket_info
, obj
);
5747 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5751 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5755 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5756 int ret
= store
->process_expire_objects();
5758 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5763 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5764 if (bucket_name
.empty()) {
5765 cerr
<< "ERROR: bucket not specified" << std::endl
;
5769 RGWBucketInfo bucket_info
;
5770 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5772 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5776 uint64_t start_epoch
= 0;
5777 uint64_t end_epoch
= 0;
5779 if (!end_date
.empty()) {
5780 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5782 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5786 if (!start_date
.empty()) {
5787 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5789 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5794 bool is_truncated
= true;
5796 rgw_obj_index_key marker
;
5799 formatter
->open_object_section("result");
5800 formatter
->dump_string("bucket", bucket_name
);
5801 formatter
->open_array_section("objects");
5802 while (is_truncated
) {
5803 map
<string
, rgw_bucket_dir_entry
> result
;
5804 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5805 result
, &is_truncated
, &marker
,
5806 bucket_object_check_filter
);
5808 if (r
< 0 && r
!= -ENOENT
) {
5809 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5815 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5816 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5817 rgw_obj_key key
= iter
->second
.key
;
5818 rgw_bucket_dir_entry
& entry
= iter
->second
;
5820 formatter
->open_object_section("object");
5821 formatter
->dump_string("name", key
.name
);
5822 formatter
->dump_string("instance", key
.instance
);
5823 formatter
->dump_int("size", entry
.meta
.size
);
5824 utime_t
ut(entry
.meta
.mtime
);
5825 ut
.gmtime(formatter
->dump_stream("mtime"));
5827 if ((entry
.meta
.size
< min_rewrite_size
) ||
5828 (entry
.meta
.size
> max_rewrite_size
) ||
5829 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5830 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5831 formatter
->dump_string("status", "Skipped");
5833 rgw_obj
obj(bucket
, key
);
5835 bool need_rewrite
= true;
5836 if (min_rewrite_stripe_size
> 0) {
5837 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5839 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5842 if (!need_rewrite
) {
5843 formatter
->dump_string("status", "Skipped");
5845 r
= store
->rewrite_obj(bucket_info
, obj
);
5847 formatter
->dump_string("status", "Success");
5849 formatter
->dump_string("status", cpp_strerror(-r
));
5853 formatter
->dump_int("flags", entry
.flags
);
5855 formatter
->close_section();
5856 formatter
->flush(cout
);
5859 formatter
->close_section();
5860 formatter
->close_section();
5861 formatter
->flush(cout
);
5864 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5866 RGWBucketInfo bucket_info
;
5867 map
<string
, bufferlist
> attrs
;
5869 int ret
= check_reshard_bucket_params(store
,
5873 num_shards_specified
,
5875 yes_i_really_mean_it
,
5883 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5885 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5886 if (max_entries
< 1) {
5887 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5890 return br
.execute(num_shards
, max_entries
,
5891 verbose
, &cout
, formatter
);
5894 if (opt_cmd
== OPT_RESHARD_ADD
) {
5896 RGWBucketInfo bucket_info
;
5897 map
<string
, bufferlist
> attrs
;
5899 int ret
= check_reshard_bucket_params(store
,
5903 num_shards_specified
,
5905 yes_i_really_mean_it
,
5913 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5915 RGWReshard
reshard(store
);
5916 cls_rgw_reshard_entry entry
;
5917 entry
.time
= real_clock::now();
5918 entry
.tenant
= tenant
;
5919 entry
.bucket_name
= bucket_name
;
5920 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5921 entry
.old_num_shards
= num_source_shards
;
5922 entry
.new_num_shards
= num_shards
;
5924 return reshard
.add(entry
);
5927 if (opt_cmd
== OPT_RESHARD_LIST
) {
5928 list
<cls_rgw_reshard_entry
> entries
;
5931 if (max_entries
< 0) {
5935 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5937 RGWReshard
reshard(store
);
5939 formatter
->open_array_section("reshard");
5940 for (int i
= 0; i
< num_logshards
; i
++) {
5941 bool is_truncated
= true;
5945 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5947 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5950 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5951 cls_rgw_reshard_entry
& entry
= *iter
;
5952 encode_json("entry", entry
, formatter
);
5953 entry
.get_key(&marker
);
5955 count
+= entries
.size();
5956 formatter
->flush(cout
);
5957 } while (is_truncated
&& count
< max_entries
);
5959 if (count
>= max_entries
) {
5964 formatter
->close_section();
5965 formatter
->flush(cout
);
5970 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5971 if (bucket_name
.empty()) {
5972 cerr
<< "ERROR: bucket not specified" << std::endl
;
5977 RGWBucketInfo bucket_info
;
5978 map
<string
, bufferlist
> attrs
;
5979 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5981 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5985 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5986 list
<cls_rgw_bucket_instance_entry
> status
;
5987 int r
= br
.get_status(&status
);
5989 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5993 encode_json("status", status
, formatter
);
5994 formatter
->flush(cout
);
5997 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5998 RGWReshard
reshard(store
, true, &cout
);
6000 int ret
= reshard
.process_all_logshards();
6002 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
6007 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
6008 if (bucket_name
.empty()) {
6009 cerr
<< "ERROR: bucket not specified" << std::endl
;
6014 RGWBucketInfo bucket_info
;
6015 map
<string
, bufferlist
> attrs
;
6016 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
6018 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6022 RGWBucketReshard
br(store
, bucket_info
, attrs
);
6023 int ret
= br
.cancel();
6025 if (ret
== -EBUSY
) {
6026 cerr
<< "There is ongoing resharding, please retry after " << g_conf
->rgw_reshard_bucket_lock_duration
<<
6027 " seconds " << std::endl
;
6029 cerr
<< "Error canceling bucket " << bucket_name
<< " resharding: " << cpp_strerror(-ret
) <<
6034 RGWReshard
reshard(store
);
6036 cls_rgw_reshard_entry entry
;
6037 //entry.tenant = tenant;
6038 entry
.bucket_name
= bucket_name
;
6039 //entry.bucket_id = bucket_id;
6041 ret
= reshard
.remove(entry
);
6042 if (ret
< 0 && ret
!= -ENOENT
) {
6043 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
6048 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
6049 RGWBucketInfo bucket_info
;
6050 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6052 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6055 list
<rgw_obj_index_key
> oid_list
;
6056 rgw_obj_key
key(object
, object_version
);
6057 rgw_obj_index_key index_key
;
6058 key
.get_index_key(&index_key
);
6059 oid_list
.push_back(index_key
);
6060 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
6062 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
6067 if (opt_cmd
== OPT_OBJECT_STAT
) {
6068 RGWBucketInfo bucket_info
;
6069 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6071 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6074 rgw_obj
obj(bucket
, object
);
6075 obj
.key
.set_instance(object_version
);
6078 map
<string
, bufferlist
> attrs
;
6079 RGWObjectCtx
obj_ctx(store
);
6080 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
6081 RGWRados::Object::Read
read_op(&op_target
);
6083 read_op
.params
.attrs
= &attrs
;
6084 read_op
.params
.obj_size
= &obj_size
;
6086 ret
= read_op
.prepare();
6088 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
6091 formatter
->open_object_section("object_metadata");
6092 formatter
->dump_string("name", object
);
6093 formatter
->dump_unsigned("size", obj_size
);
6095 map
<string
, bufferlist
>::iterator iter
;
6096 map
<string
, bufferlist
> other_attrs
;
6097 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
6098 bufferlist
& bl
= iter
->second
;
6099 bool handled
= false;
6100 if (iter
->first
== RGW_ATTR_MANIFEST
) {
6101 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
6102 } else if (iter
->first
== RGW_ATTR_ACL
) {
6103 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
6104 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
6105 handled
= dump_string("tag", bl
, formatter
);
6106 } else if (iter
->first
== RGW_ATTR_ETAG
) {
6107 handled
= dump_string("etag", bl
, formatter
);
6111 other_attrs
[iter
->first
] = bl
;
6114 formatter
->open_object_section("attrs");
6115 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
6116 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
6118 formatter
->close_section();
6119 formatter
->close_section();
6120 formatter
->flush(cout
);
6123 if (opt_cmd
== OPT_BUCKET_CHECK
) {
6124 if (check_head_obj_locator
) {
6125 if (bucket_name
.empty()) {
6126 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
6129 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
6131 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
6135 if (opt_cmd
== OPT_BUCKET_RM
) {
6136 if (inconsistent_index
== false) {
6137 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
6139 if (!yes_i_really_mean_it
) {
6140 cerr
<< "using --inconsistent_index can corrupt the bucket index " << std::endl
6141 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
6144 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
6148 if (opt_cmd
== OPT_GC_LIST
) {
6151 formatter
->open_array_section("entries");
6154 list
<cls_rgw_gc_obj_info
> result
;
6155 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
6157 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
6162 list
<cls_rgw_gc_obj_info
>::iterator iter
;
6163 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
6164 cls_rgw_gc_obj_info
& info
= *iter
;
6165 formatter
->open_object_section("chain_info");
6166 formatter
->dump_string("tag", info
.tag
);
6167 formatter
->dump_stream("time") << info
.time
;
6168 formatter
->open_array_section("objs");
6169 list
<cls_rgw_obj
>::iterator liter
;
6170 cls_rgw_obj_chain
& chain
= info
.chain
;
6171 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
6172 cls_rgw_obj
& obj
= *liter
;
6173 encode_json("obj", obj
, formatter
);
6175 formatter
->close_section(); // objs
6176 formatter
->close_section(); // obj_chain
6177 formatter
->flush(cout
);
6179 } while (truncated
);
6180 formatter
->close_section();
6181 formatter
->flush(cout
);
6184 if (opt_cmd
== OPT_GC_PROCESS
) {
6185 int ret
= store
->process_gc();
6187 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
6192 if (opt_cmd
== OPT_LC_LIST
) {
6193 formatter
->open_array_section("lifecycle_list");
6194 map
<string
, int> bucket_lc_map
;
6196 #define MAX_LC_LIST_ENTRIES 100
6197 if (max_entries
< 0) {
6198 max_entries
= MAX_LC_LIST_ENTRIES
;
6201 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
6203 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
6206 map
<string
, int>::iterator iter
;
6207 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
6208 formatter
->open_object_section("bucket_lc_info");
6209 formatter
->dump_string("bucket", iter
->first
);
6210 string lc_status
= LC_STATUS
[iter
->second
];
6211 formatter
->dump_string("status", lc_status
);
6212 formatter
->close_section(); // objs
6213 formatter
->flush(cout
);
6214 marker
= iter
->first
;
6216 } while (!bucket_lc_map
.empty());
6218 formatter
->close_section(); //lifecycle list
6219 formatter
->flush(cout
);
6223 if (opt_cmd
== OPT_LC_PROCESS
) {
6224 int ret
= store
->process_lc();
6226 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
6231 if (opt_cmd
== OPT_ORPHANS_FIND
) {
6232 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6234 if (job_id
.empty()) {
6235 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6238 if (pool_name
.empty()) {
6239 cerr
<< "ERROR: --pool not specified" << std::endl
;
6243 RGWOrphanSearchInfo info
;
6246 info
.job_name
= job_id
;
6247 info
.num_shards
= num_shards
;
6249 int ret
= search
.init(job_id
, &info
);
6251 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
6260 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
6261 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6263 if (job_id
.empty()) {
6264 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6267 int ret
= search
.init(job_id
, NULL
);
6269 if (ret
== -ENOENT
) {
6270 cerr
<< "job not found" << std::endl
;
6274 ret
= search
.finish();
6280 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
6281 RGWOrphanStore
orphan_store(store
);
6282 int ret
= orphan_store
.init();
6284 cerr
<< "connection to cluster failed!" << std::endl
;
6288 map
<string
,RGWOrphanSearchState
> m
;
6289 ret
= orphan_store
.list_jobs(m
);
6291 cerr
<< "job list failed" << std::endl
;
6294 formatter
->open_array_section("entries");
6295 for (const auto &it
: m
){
6297 formatter
->dump_string("job-id",it
.first
);
6299 encode_json("orphan_search_state", it
.second
, formatter
);
6302 formatter
->close_section();
6303 formatter
->flush(cout
);
6306 if (opt_cmd
== OPT_USER_CHECK
) {
6307 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6310 if (opt_cmd
== OPT_USER_STATS
) {
6311 if (user_id
.empty()) {
6312 cerr
<< "ERROR: uid not specified" << std::endl
;
6316 string user_str
= user_id
.to_str();
6318 if (!bucket_name
.empty()){
6319 cerr
<< "ERROR: recalculate doesn't work on buckets" << std::endl
;
6322 ret
= store
->cls_user_reset_stats(user_str
);
6324 cerr
<< "ERROR: could not clear user stats: " << cpp_strerror(-ret
) << std::endl
;
6330 if (!bucket_name
.empty()) {
6331 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6333 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
6337 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6339 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
6345 cls_user_header header
;
6346 int ret
= store
->cls_user_get_header(user_str
, &header
);
6348 if (ret
== -ENOENT
) { /* in case of ENOENT */
6349 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6351 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6356 encode_json("header", header
, formatter
);
6357 formatter
->flush(cout
);
6360 if (opt_cmd
== OPT_METADATA_GET
) {
6361 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6363 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6367 formatter
->flush(cout
);
6370 if (opt_cmd
== OPT_METADATA_PUT
) {
6372 int ret
= read_input(infile
, bl
);
6374 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6377 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6379 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6384 if (opt_cmd
== OPT_METADATA_RM
) {
6385 int ret
= store
->meta_mgr
->remove(metadata_key
);
6387 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6392 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6393 if (opt_cmd
== OPT_USER_LIST
) {
6394 metadata_key
= "user";
6398 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, marker
, &handle
);
6400 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6407 if (max_entries_specified
) {
6408 formatter
->open_object_section("result");
6410 formatter
->open_array_section("keys");
6415 left
= (max_entries_specified
? max_entries
- count
: max
);
6416 ret
= store
->meta_mgr
->list_keys_next(handle
, left
, keys
, &truncated
);
6417 if (ret
< 0 && ret
!= -ENOENT
) {
6418 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6420 } if (ret
!= -ENOENT
) {
6421 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6422 formatter
->dump_string("key", *iter
);
6425 formatter
->flush(cout
);
6427 } while (truncated
&& left
> 0);
6429 formatter
->close_section();
6431 if (max_entries_specified
) {
6432 encode_json("truncated", truncated
, formatter
);
6433 encode_json("count", count
, formatter
);
6435 encode_json("marker", store
->meta_mgr
->get_marker(handle
), formatter
);
6437 formatter
->close_section();
6439 formatter
->flush(cout
);
6441 store
->meta_mgr
->list_keys_complete(handle
);
6444 if (opt_cmd
== OPT_MDLOG_LIST
) {
6445 utime_t start_time
, end_time
;
6447 int ret
= parse_date_str(start_date
, start_time
);
6451 ret
= parse_date_str(end_date
, end_time
);
6455 int i
= (specified_shard_id
? shard_id
: 0);
6457 if (period_id
.empty()) {
6458 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6462 std::cerr
<< "No --period given, using current period="
6463 << period_id
<< std::endl
;
6465 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6467 formatter
->open_array_section("entries");
6468 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6470 list
<cls_log_entry
> entries
;
6473 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6476 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6478 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6482 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6483 cls_log_entry
& entry
= *iter
;
6484 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6486 formatter
->flush(cout
);
6487 } while (truncated
);
6489 meta_log
->complete_list_entries(handle
);
6491 if (specified_shard_id
)
6496 formatter
->close_section();
6497 formatter
->flush(cout
);
6500 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6501 int i
= (specified_shard_id
? shard_id
: 0);
6503 if (period_id
.empty()) {
6504 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6508 std::cerr
<< "No --period given, using current period="
6509 << period_id
<< std::endl
;
6511 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6513 formatter
->open_array_section("entries");
6515 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6516 RGWMetadataLogInfo info
;
6517 meta_log
->get_info(i
, &info
);
6519 ::encode_json("info", info
, formatter
);
6521 if (specified_shard_id
)
6526 formatter
->close_section();
6527 formatter
->flush(cout
);
6530 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6531 // need a full history for purging old mdlog periods
6532 store
->meta_mgr
->init_oldest_log_period();
6534 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6535 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6536 int ret
= http
.set_threaded();
6538 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6542 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6543 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6545 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6550 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6551 utime_t start_time
, end_time
;
6553 if (!specified_shard_id
) {
6554 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6558 int ret
= parse_date_str(start_date
, start_time
);
6562 ret
= parse_date_str(end_date
, end_time
);
6566 if (period_id
.empty()) {
6567 std::cerr
<< "missing --period argument" << std::endl
;
6570 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6572 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6574 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6579 if (opt_cmd
== OPT_SYNC_STATUS
) {
6580 sync_status(formatter
);
6583 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6584 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6586 int ret
= sync
.init();
6588 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6592 rgw_meta_sync_status sync_status
;
6593 ret
= sync
.read_sync_status(&sync_status
);
6595 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6599 formatter
->open_object_section("summary");
6600 encode_json("sync_status", sync_status
, formatter
);
6602 uint64_t full_total
= 0;
6603 uint64_t full_complete
= 0;
6605 for (auto marker_iter
: sync_status
.sync_markers
) {
6606 full_total
+= marker_iter
.second
.total_entries
;
6607 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6608 full_complete
+= marker_iter
.second
.pos
;
6610 full_complete
+= marker_iter
.second
.total_entries
;
6614 formatter
->open_object_section("full_sync");
6615 encode_json("total", full_total
, formatter
);
6616 encode_json("complete", full_complete
, formatter
);
6617 formatter
->close_section();
6618 formatter
->close_section();
6620 formatter
->flush(cout
);
6624 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6625 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6627 int ret
= sync
.init();
6629 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6632 ret
= sync
.init_sync_status();
6634 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6640 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6641 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6643 int ret
= sync
.init();
6645 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6651 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6656 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6657 if (source_zone
.empty()) {
6658 cerr
<< "ERROR: source zone not specified" << std::endl
;
6661 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6663 int ret
= sync
.init();
6665 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6669 rgw_data_sync_status sync_status
;
6670 if (specified_shard_id
) {
6671 set
<string
> pending_buckets
;
6672 set
<string
> recovering_buckets
;
6673 rgw_data_sync_marker sync_marker
;
6674 ret
= sync
.read_shard_status(shard_id
, pending_buckets
, recovering_buckets
, &sync_marker
,
6675 max_entries_specified
? max_entries
: 20);
6676 if (ret
< 0 && ret
!= -ENOENT
) {
6677 cerr
<< "ERROR: sync.read_shard_status() returned ret=" << ret
<< std::endl
;
6680 formatter
->open_object_section("summary");
6681 encode_json("shard_id", shard_id
, formatter
);
6682 encode_json("marker", sync_marker
, formatter
);
6683 encode_json("pending_buckets", pending_buckets
, formatter
);
6684 encode_json("recovering_buckets", recovering_buckets
, formatter
);
6685 formatter
->close_section();
6686 formatter
->flush(cout
);
6688 ret
= sync
.read_sync_status(&sync_status
);
6689 if (ret
< 0 && ret
!= -ENOENT
) {
6690 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6694 formatter
->open_object_section("summary");
6695 encode_json("sync_status", sync_status
, formatter
);
6697 uint64_t full_total
= 0;
6698 uint64_t full_complete
= 0;
6700 for (auto marker_iter
: sync_status
.sync_markers
) {
6701 full_total
+= marker_iter
.second
.total_entries
;
6702 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6703 full_complete
+= marker_iter
.second
.pos
;
6705 full_complete
+= marker_iter
.second
.total_entries
;
6709 formatter
->open_object_section("full_sync");
6710 encode_json("total", full_total
, formatter
);
6711 encode_json("complete", full_complete
, formatter
);
6712 formatter
->close_section();
6713 formatter
->close_section();
6715 formatter
->flush(cout
);
6719 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6720 if (source_zone
.empty()) {
6721 cerr
<< "ERROR: source zone not specified" << std::endl
;
6725 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6727 int ret
= sync
.init();
6729 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6733 ret
= sync
.init_sync_status();
6735 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6740 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6741 if (source_zone
.empty()) {
6742 cerr
<< "ERROR: source zone not specified" << std::endl
;
6746 RGWSyncModuleInstanceRef sync_module
;
6747 int ret
= store
->get_sync_modules_manager()->create_instance(g_ceph_context
, store
->get_zone().tier_type
,
6748 store
->get_zone_params().tier_config
, &sync_module
);
6750 lderr(cct
) << "ERROR: failed to init sync module instance, ret=" << ret
<< dendl
;
6754 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
, sync_module
);
6758 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6764 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6769 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6770 if (source_zone
.empty()) {
6771 cerr
<< "ERROR: source zone not specified" << std::endl
;
6774 if (bucket_name
.empty()) {
6775 cerr
<< "ERROR: bucket not specified" << std::endl
;
6779 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6783 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6787 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6790 ret
= sync
.init_sync_status();
6792 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6797 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
6798 if (bucket_name
.empty()) {
6799 cerr
<< "ERROR: bucket not specified" << std::endl
;
6804 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
6808 ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
, true);
6810 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
6814 if (!store
->is_meta_master()) {
6815 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
6816 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
6820 rgw_obj
obj(bucket
, object
);
6821 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
6826 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6827 if (bucket_name
.empty()) {
6828 cerr
<< "ERROR: bucket not specified" << std::endl
;
6831 RGWBucketInfo bucket_info
;
6833 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6837 bucket_sync_status(store
, bucket_info
, source_zone
, std::cout
);
6840 if (opt_cmd
== OPT_BUCKET_SYNC_MARKERS
) {
6841 if (source_zone
.empty()) {
6842 cerr
<< "ERROR: source zone not specified" << std::endl
;
6845 if (bucket_name
.empty()) {
6846 cerr
<< "ERROR: bucket not specified" << std::endl
;
6850 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6854 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6858 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6861 ret
= sync
.read_sync_status();
6863 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6867 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6869 encode_json("sync_status", sync_status
, formatter
);
6870 formatter
->flush(cout
);
6873 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6874 if (source_zone
.empty()) {
6875 cerr
<< "ERROR: source zone not specified" << std::endl
;
6878 if (bucket_name
.empty()) {
6879 cerr
<< "ERROR: bucket not specified" << std::endl
;
6883 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6887 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6891 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6897 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6902 if (opt_cmd
== OPT_BILOG_LIST
) {
6903 if (bucket_name
.empty()) {
6904 cerr
<< "ERROR: bucket not specified" << std::endl
;
6907 RGWBucketInfo bucket_info
;
6908 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6910 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6913 formatter
->open_array_section("entries");
6916 if (max_entries
< 0)
6920 list
<rgw_bi_log_entry
> entries
;
6921 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6923 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6927 count
+= entries
.size();
6929 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6930 rgw_bi_log_entry
& entry
= *iter
;
6931 encode_json("entry", entry
, formatter
);
6935 formatter
->flush(cout
);
6936 } while (truncated
&& count
< max_entries
);
6938 formatter
->close_section();
6939 formatter
->flush(cout
);
6942 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6943 if (max_entries
< 0) {
6948 utime_t start_time
, end_time
;
6950 int ret
= parse_date_str(start_date
, start_time
);
6954 ret
= parse_date_str(end_date
, end_time
);
6962 formatter
->open_array_section("entries");
6964 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6965 formatter
->open_object_section("shard");
6966 encode_json("shard_id", shard_id
, formatter
);
6967 formatter
->open_array_section("entries");
6970 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6973 list
<cls_log_entry
> entries
;
6974 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6975 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6976 if (ret
== -ENOENT
) {
6980 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6984 count
+= entries
.size();
6986 for (auto& cls_entry
: entries
) {
6987 rgw_sync_error_info log_entry
;
6989 auto iter
= cls_entry
.data
.begin();
6991 ::decode(log_entry
, iter
);
6992 } catch (buffer::error
& err
) {
6993 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6996 formatter
->open_object_section("entry");
6997 encode_json("id", cls_entry
.id
, formatter
);
6998 encode_json("section", cls_entry
.section
, formatter
);
6999 encode_json("name", cls_entry
.name
, formatter
);
7000 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
7001 encode_json("info", log_entry
, formatter
);
7002 formatter
->close_section();
7003 formatter
->flush(cout
);
7005 } while (truncated
&& count
< max_entries
);
7007 formatter
->close_section();
7008 formatter
->close_section();
7010 if (specified_shard_id
) {
7015 formatter
->close_section();
7016 formatter
->flush(cout
);
7019 if (opt_cmd
== OPT_SYNC_ERROR_TRIM
) {
7020 utime_t start_time
, end_time
;
7021 int ret
= parse_date_str(start_date
, start_time
);
7025 ret
= parse_date_str(end_date
, end_time
);
7033 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
7034 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
7035 ret
= store
->time_log_trim(oid
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
7036 if (ret
< 0 && ret
!= -ENODATA
) {
7037 cerr
<< "ERROR: sync error trim: " << cpp_strerror(-ret
) << std::endl
;
7040 if (specified_shard_id
) {
7046 if (opt_cmd
== OPT_BILOG_TRIM
) {
7047 if (bucket_name
.empty()) {
7048 cerr
<< "ERROR: bucket not specified" << std::endl
;
7051 RGWBucketInfo bucket_info
;
7052 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7054 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7057 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
7059 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
7064 if (opt_cmd
== OPT_BILOG_STATUS
) {
7065 if (bucket_name
.empty()) {
7066 cerr
<< "ERROR: bucket not specified" << std::endl
;
7069 RGWBucketInfo bucket_info
;
7070 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7072 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7075 map
<int, string
> markers
;
7076 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
7078 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
7081 formatter
->open_object_section("entries");
7082 encode_json("markers", markers
, formatter
);
7083 formatter
->close_section();
7084 formatter
->flush(cout
);
7087 if (opt_cmd
== OPT_BILOG_AUTOTRIM
) {
7088 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
7089 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
7090 int ret
= http
.set_threaded();
7092 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
7096 rgw::BucketTrimConfig config
;
7097 configure_bucket_trim(store
->ctx(), config
);
7099 rgw::BucketTrimManager
trim(store
, config
);
7102 cerr
<< "trim manager init failed with " << cpp_strerror(ret
) << std::endl
;
7105 ret
= crs
.run(trim
.create_admin_bucket_trim_cr(&http
));
7107 cerr
<< "automated bilog trim failed with " << cpp_strerror(ret
) << std::endl
;
7112 if (opt_cmd
== OPT_DATALOG_LIST
) {
7113 formatter
->open_array_section("entries");
7116 if (max_entries
< 0)
7119 utime_t start_time
, end_time
;
7121 int ret
= parse_date_str(start_date
, start_time
);
7125 ret
= parse_date_str(end_date
, end_time
);
7129 RGWDataChangesLog
*log
= store
->data_log
;
7130 RGWDataChangesLog::LogMarker marker
;
7133 list
<rgw_data_change_log_entry
> entries
;
7134 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
7136 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
7140 count
+= entries
.size();
7142 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
7143 rgw_data_change_log_entry
& entry
= *iter
;
7145 encode_json("entry", entry
.entry
, formatter
);
7147 encode_json("entry", entry
, formatter
);
7150 formatter
->flush(cout
);
7151 } while (truncated
&& count
< max_entries
);
7153 formatter
->close_section();
7154 formatter
->flush(cout
);
7157 if (opt_cmd
== OPT_DATALOG_STATUS
) {
7158 RGWDataChangesLog
*log
= store
->data_log
;
7159 int i
= (specified_shard_id
? shard_id
: 0);
7161 formatter
->open_array_section("entries");
7162 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
7163 list
<cls_log_entry
> entries
;
7165 RGWDataChangesLogInfo info
;
7166 log
->get_info(i
, &info
);
7168 ::encode_json("info", info
, formatter
);
7170 if (specified_shard_id
)
7174 formatter
->close_section();
7175 formatter
->flush(cout
);
7178 if (opt_cmd
== OPT_DATALOG_TRIM
) {
7179 utime_t start_time
, end_time
;
7181 int ret
= parse_date_str(start_date
, start_time
);
7185 ret
= parse_date_str(end_date
, end_time
);
7189 RGWDataChangesLog
*log
= store
->data_log
;
7190 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
7192 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
7197 if (opt_cmd
== OPT_OPSTATE_LIST
) {
7198 RGWOpState
oc(store
);
7203 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
7204 list
<cls_statelog_entry
> entries
;
7206 formatter
->open_array_section("entries");
7208 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
7210 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
7211 oc
.finish_list_entries(handle
);
7215 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
7216 oc
.dump_entry(*iter
, formatter
);
7219 formatter
->flush(cout
);
7221 formatter
->close_section();
7222 formatter
->flush(cout
);
7223 oc
.finish_list_entries(handle
);
7226 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
7227 RGWOpState
oc(store
);
7229 RGWOpState::OpState state
;
7230 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
7231 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
7234 if (state_str
.empty()) {
7235 cerr
<< "ERROR: state was not specified" << std::endl
;
7238 int ret
= oc
.state_from_str(state_str
, &state
);
7240 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
7244 if (opt_cmd
== OPT_OPSTATE_SET
) {
7245 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
7247 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
7251 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
7253 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
7258 if (opt_cmd
== OPT_OPSTATE_RM
) {
7259 RGWOpState
oc(store
);
7261 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
7262 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
7265 ret
= oc
.remove_entry(client_id
, op_id
, object
);
7267 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
7272 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
7273 opt_cmd
== OPT_REPLICALOG_DELETE
) {
7274 if (replica_log_type_str
.empty()) {
7275 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
7280 if (opt_cmd
== OPT_REPLICALOG_GET
) {
7281 RGWReplicaBounds bounds
;
7282 if (replica_log_type
== ReplicaLog_Metadata
) {
7283 if (!specified_shard_id
) {
7284 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7288 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7289 int ret
= logger
.get_bounds(shard_id
, bounds
);
7292 } else if (replica_log_type
== ReplicaLog_Data
) {
7293 if (!specified_shard_id
) {
7294 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7297 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7298 int ret
= logger
.get_bounds(shard_id
, bounds
);
7301 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7302 if (bucket_name
.empty()) {
7303 cerr
<< "ERROR: bucket not specified" << std::endl
;
7306 RGWBucketInfo bucket_info
;
7307 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7309 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7313 RGWReplicaBucketLogger
logger(store
);
7314 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
7317 } else { // shouldn't get here
7320 encode_json("bounds", bounds
, formatter
);
7321 formatter
->flush(cout
);
7325 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
7326 if (replica_log_type
== ReplicaLog_Metadata
) {
7327 if (!specified_shard_id
) {
7328 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
7331 if (!specified_daemon_id
) {
7332 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
7335 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7336 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
7339 } else if (replica_log_type
== ReplicaLog_Data
) {
7340 if (!specified_shard_id
) {
7341 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
7344 if (!specified_daemon_id
) {
7345 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
7348 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7349 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
7352 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7353 if (bucket_name
.empty()) {
7354 cerr
<< "ERROR: bucket not specified" << std::endl
;
7357 RGWBucketInfo bucket_info
;
7358 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7360 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7364 RGWReplicaBucketLogger
logger(store
);
7365 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
7371 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
7372 if (marker
.empty()) {
7373 cerr
<< "ERROR: marker was not specified" <<std::endl
;
7376 utime_t time
= ceph_clock_now();
7377 if (!date
.empty()) {
7378 ret
= parse_date_str(date
, time
);
7380 cerr
<< "ERROR: failed to parse start date" << std::endl
;
7384 list
<RGWReplicaItemMarker
> entries
;
7385 int ret
= read_decode_json(infile
, entries
);
7387 cerr
<< "ERROR: failed to decode entries" << std::endl
;
7390 RGWReplicaBounds bounds
;
7391 if (replica_log_type
== ReplicaLog_Metadata
) {
7392 if (!specified_shard_id
) {
7393 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7397 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7398 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7400 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7403 } else if (replica_log_type
== ReplicaLog_Data
) {
7404 if (!specified_shard_id
) {
7405 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7408 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7409 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7411 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7414 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7415 if (bucket_name
.empty()) {
7416 cerr
<< "ERROR: bucket not specified" << std::endl
;
7419 RGWBucketInfo bucket_info
;
7420 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7422 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7426 RGWReplicaBucketLogger
logger(store
);
7427 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
7429 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7435 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7438 if (bucket_name
.empty() && user_id
.empty()) {
7439 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7443 if (!bucket_name
.empty()) {
7444 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7445 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7448 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7449 max_size
, max_objects
, have_max_size
, have_max_objects
);
7450 } else if (!user_id
.empty()) {
7451 if (quota_scope
== "bucket") {
7452 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7453 } else if (quota_scope
== "user") {
7454 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7456 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;