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"
13 #include "common/armor.h"
14 #include "common/ceph_json.h"
15 #include "common/config.h"
16 #include "common/ceph_argparse.h"
17 #include "common/Formatter.h"
18 #include "common/errno.h"
19 #include "common/safe_io.h"
21 #include "cls/rgw/cls_rgw_client.h"
23 #include "global/global_init.h"
25 #include "include/utime.h"
26 #include "include/str_list.h"
29 #include "rgw_bucket.h"
30 #include "rgw_rados.h"
32 #include "rgw_acl_s3.h"
35 #include "rgw_formats.h"
36 #include "rgw_usage.h"
37 #include "rgw_replica_log.h"
38 #include "rgw_orphan.h"
40 #include "rgw_data_sync.h"
41 #include "rgw_rest_conn.h"
42 #include "rgw_realm_watcher.h"
44 #include "rgw_reshard.h"
48 #define dout_context g_ceph_context
49 #define dout_subsys ceph_subsys_rgw
51 #define SECRET_KEY_LEN 40
52 #define PUBLIC_ID_LEN 20
54 static RGWRados
*store
= NULL
;
58 cout
<< "usage: radosgw-admin <cmd> [options...]" << std::endl
;
59 cout
<< "commands:\n";
60 cout
<< " user create create a new user\n" ;
61 cout
<< " user modify modify user\n";
62 cout
<< " user info get user info\n";
63 cout
<< " user rm remove user\n";
64 cout
<< " user suspend suspend a user\n";
65 cout
<< " user enable re-enable user after suspension\n";
66 cout
<< " user check check user info\n";
67 cout
<< " user stats show user stats as accounted by quota subsystem\n";
68 cout
<< " user list list users\n";
69 cout
<< " caps add add user capabilities\n";
70 cout
<< " caps rm remove user capabilities\n";
71 cout
<< " subuser create create a new subuser\n" ;
72 cout
<< " subuser modify modify subuser\n";
73 cout
<< " subuser rm remove subuser\n";
74 cout
<< " key create create access key\n";
75 cout
<< " key rm remove access key\n";
76 cout
<< " bucket list list buckets\n";
77 cout
<< " bucket limit check show bucket sharding stats\n";
78 cout
<< " bucket link link bucket to specified user\n";
79 cout
<< " bucket unlink unlink bucket from specified user\n";
80 cout
<< " bucket stats returns bucket statistics\n";
81 cout
<< " bucket rm remove bucket\n";
82 cout
<< " bucket check check bucket index\n";
83 cout
<< " bucket reshard reshard bucket\n";
84 cout
<< " bucket sync disable disable bucket sync\n";
85 cout
<< " bucket sync enable enable bucket sync\n";
86 cout
<< " bi get retrieve bucket index object entries\n";
87 cout
<< " bi put store bucket index object entries\n";
88 cout
<< " bi list list raw bucket index entries\n";
89 cout
<< " object rm remove object\n";
90 cout
<< " object stat stat an object for its metadata\n";
91 cout
<< " object unlink unlink object from bucket index\n";
92 cout
<< " objects expire run expired objects cleanup\n";
93 cout
<< " period delete delete a period\n";
94 cout
<< " period get get period info\n";
95 cout
<< " period get-current get current period info\n";
96 cout
<< " period pull pull a period\n";
97 cout
<< " period push push a period\n";
98 cout
<< " period list list all periods\n";
99 cout
<< " period update update the staging period\n";
100 cout
<< " period commit commit the staging period\n";
101 cout
<< " quota set set quota params\n";
102 cout
<< " quota enable enable quota\n";
103 cout
<< " quota disable disable quota\n";
104 cout
<< " global quota get view global quota params\n";
105 cout
<< " global quota set set global quota params\n";
106 cout
<< " global quota enable enable a global quota\n";
107 cout
<< " global quota disable disable a global quota\n";
108 cout
<< " realm create create a new realm\n";
109 cout
<< " realm delete delete a realm\n";
110 cout
<< " realm get show realm info\n";
111 cout
<< " realm get-default get default realm name\n";
112 cout
<< " realm list list realms\n";
113 cout
<< " realm list-periods list all realm periods\n";
114 cout
<< " realm remove remove a zonegroup from the realm\n";
115 cout
<< " realm rename rename a realm\n";
116 cout
<< " realm set set realm info (requires infile)\n";
117 cout
<< " realm default set realm as default\n";
118 cout
<< " realm pull pull a realm and its current period\n";
119 cout
<< " zonegroup add add a zone to a zonegroup\n";
120 cout
<< " zonegroup create create a new zone group info\n";
121 cout
<< " zonegroup default set default zone group\n";
122 cout
<< " zonegroup delete delete a zone group info\n";
123 cout
<< " zonegroup get show zone group info\n";
124 cout
<< " zonegroup modify modify an existing zonegroup\n";
125 cout
<< " zonegroup set set zone group info (requires infile)\n";
126 cout
<< " zonegroup remove remove a zone from a zonegroup\n";
127 cout
<< " zonegroup rename rename a zone group\n";
128 cout
<< " zonegroup list list all zone groups set on this cluster\n";
129 cout
<< " zonegroup placement list list zonegroup's placement targets\n";
130 cout
<< " zonegroup placement add add a placement target id to a zonegroup\n";
131 cout
<< " zonegroup placement modify modify a placement target of a specific zonegroup\n";
132 cout
<< " zonegroup placement rm remove a placement target from a zonegroup\n";
133 cout
<< " zonegroup placement default set a zonegroup's default placement target\n";
134 cout
<< " zone create create a new zone\n";
135 cout
<< " zone delete delete a zone\n";
136 cout
<< " zone get show zone cluster params\n";
137 cout
<< " zone modify modify an existing zone\n";
138 cout
<< " zone set set zone cluster params (requires infile)\n";
139 cout
<< " zone list list all zones set on this cluster\n";
140 cout
<< " zone rename rename a zone\n";
141 cout
<< " zone placement list list zone's placement targets\n";
142 cout
<< " zone placement add add a zone placement target\n";
143 cout
<< " zone placement modify modify a zone placement target\n";
144 cout
<< " zone placement rm remove a zone placement target\n";
145 cout
<< " pool add add an existing pool for data placement\n";
146 cout
<< " pool rm remove an existing pool from data placement set\n";
147 cout
<< " pools list list placement active set\n";
148 cout
<< " policy read bucket/object policy\n";
149 cout
<< " log list list log objects\n";
150 cout
<< " log show dump a log from specific object or (bucket + date\n";
151 cout
<< " + bucket-id)\n";
152 cout
<< " (NOTE: required to specify formatting of date\n";
153 cout
<< " to \"YYYY-MM-DD-hh\")\n";
154 cout
<< " log rm remove log object\n";
155 cout
<< " usage show show usage (by user, date range)\n";
156 cout
<< " usage trim trim usage (by user, date range)\n";
157 cout
<< " gc list dump expired garbage collection objects (specify\n";
158 cout
<< " --include-all to list all entries, including unexpired)\n";
159 cout
<< " gc process manually process garbage\n";
160 cout
<< " lc list list all bucket lifecycle progress\n";
161 cout
<< " lc process manually process lifecycle\n";
162 cout
<< " metadata get get metadata info\n";
163 cout
<< " metadata put put metadata info\n";
164 cout
<< " metadata rm remove metadata info\n";
165 cout
<< " metadata list list metadata info\n";
166 cout
<< " mdlog list list metadata log\n";
167 cout
<< " mdlog trim trim metadata log (use start-date, end-date or\n";
168 cout
<< " start-marker, end-marker)\n";
169 cout
<< " mdlog status read metadata log status\n";
170 cout
<< " bilog list list bucket index log\n";
171 cout
<< " bilog trim trim bucket index log (use start-marker, end-marker)\n";
172 cout
<< " datalog list list data log\n";
173 cout
<< " datalog trim trim data log\n";
174 cout
<< " datalog status read data log status\n";
175 cout
<< " opstate list list stateful operations entries (use client_id,\n";
176 cout
<< " op_id, object)\n";
177 cout
<< " opstate set set state on an entry (use client_id, op_id, object, state)\n";
178 cout
<< " opstate renew renew state on an entry (use client_id, op_id, object)\n";
179 cout
<< " opstate rm remove entry (use client_id, op_id, object)\n";
180 cout
<< " replicalog get get replica metadata log entry\n";
181 cout
<< " replicalog update update replica metadata log entry\n";
182 cout
<< " replicalog delete delete replica metadata log entry\n";
183 cout
<< " orphans find init and run search for leaked rados objects (use job-id, pool)\n";
184 cout
<< " orphans finish clean up search for leaked rados objects\n";
185 cout
<< " orphans list-jobs list the current job-ids for orphans search\n";
186 cout
<< " role create create a AWS role for use with STS\n";
187 cout
<< " role delete delete a role\n";
188 cout
<< " role get get a role\n";
189 cout
<< " role list list roles with specified path prefix\n";
190 cout
<< " role modify modify the assume role policy of an existing role\n";
191 cout
<< " role-policy put add/update permission policy to role\n";
192 cout
<< " role-policy list list policies attached to a role\n";
193 cout
<< " role-policy get get the specified inline policy document embedded with the given role\n";
194 cout
<< " role-policy delete delete policy attached to a role\n";
195 cout
<< " reshard add schedule a resharding of a bucket\n";
196 cout
<< " reshard list list all bucket resharding or scheduled to be reshared\n";
197 cout
<< " reshard process process of scheduled reshard jobs\n";
198 cout
<< " reshard cancel cancel resharding a bucket\n";
199 cout
<< "options:\n";
200 cout
<< " --tenant=<tenant> tenant name\n";
201 cout
<< " --uid=<id> user id\n";
202 cout
<< " --subuser=<name> subuser name\n";
203 cout
<< " --access-key=<key> S3 access key\n";
204 cout
<< " --email=<email>\n";
205 cout
<< " --secret/--secret-key=<key>\n";
206 cout
<< " specify secret key\n";
207 cout
<< " --gen-access-key generate random access key (for S3)\n";
208 cout
<< " --gen-secret generate random secret key\n";
209 cout
<< " --key-type=<type> key type, options are: swift, s3\n";
210 cout
<< " --temp-url-key[-2]=<key> temp url key\n";
211 cout
<< " --access=<access> Set access permissions for sub-user, should be one\n";
212 cout
<< " of read, write, readwrite, full\n";
213 cout
<< " --display-name=<name>\n";
214 cout
<< " --max-buckets max number of buckets for a user\n";
215 cout
<< " --admin set the admin flag on the user\n";
216 cout
<< " --system set the system flag on the user\n";
217 cout
<< " --bucket=<bucket>\n";
218 cout
<< " --pool=<pool>\n";
219 cout
<< " --object=<object>\n";
220 cout
<< " --date=<date>\n";
221 cout
<< " --start-date=<date>\n";
222 cout
<< " --end-date=<date>\n";
223 cout
<< " --bucket-id=<bucket-id>\n";
224 cout
<< " --shard-id=<shard-id> optional for mdlog list\n";
225 cout
<< " required for: \n";
226 cout
<< " mdlog trim\n";
227 cout
<< " replica mdlog get/delete\n";
228 cout
<< " replica datalog get/delete\n";
229 cout
<< " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
230 cout
<< " --remote=<remote> zone or zonegroup id of remote gateway\n";
231 cout
<< " --period=<id> period id\n";
232 cout
<< " --epoch=<number> period epoch\n";
233 cout
<< " --commit commit the period during 'period update'\n";
234 cout
<< " --staging get staging period info\n";
235 cout
<< " --master set as master\n";
236 cout
<< " --master-url master url\n";
237 cout
<< " --master-zonegroup=<id> master zonegroup id\n";
238 cout
<< " --master-zone=<id> master zone id\n";
239 cout
<< " --rgw-realm=<name> realm name\n";
240 cout
<< " --realm-id=<id> realm id\n";
241 cout
<< " --realm-new-name=<name> realm new name\n";
242 cout
<< " --rgw-zonegroup=<name> zonegroup name\n";
243 cout
<< " --zonegroup-id=<id> zonegroup id\n";
244 cout
<< " --zonegroup-new-name=<name>\n";
245 cout
<< " zonegroup new name\n";
246 cout
<< " --rgw-zone=<name> name of zone in which radosgw is running\n";
247 cout
<< " --zone-id=<id> zone id\n";
248 cout
<< " --zone-new-name=<name> zone new name\n";
249 cout
<< " --source-zone specify the source zone (for data sync)\n";
250 cout
<< " --default set entity (realm, zonegroup, zone) as default\n";
251 cout
<< " --read-only set zone as read-only (when adding to zonegroup)\n";
252 cout
<< " --placement-id placement id for zonegroup placement commands\n";
253 cout
<< " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
254 cout
<< " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
255 cout
<< " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
256 cout
<< " --endpoints=<list> zone endpoints\n";
257 cout
<< " --index-pool=<pool> placement target index pool\n";
258 cout
<< " --data-pool=<pool> placement target data pool\n";
259 cout
<< " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n";
260 cout
<< " --placement-index-type=<type>\n";
261 cout
<< " placement target index type (normal, indexless, or #id)\n";
262 cout
<< " --compression=<type> placement target compression type (plugin name or empty/none)\n";
263 cout
<< " --tier-type=<type> zone tier type\n";
264 cout
<< " --tier-config=<k>=<v>[,...]\n";
265 cout
<< " set zone tier config keys, values\n";
266 cout
<< " --tier-config-rm=<k>[,...]\n";
267 cout
<< " unset zone tier config keys\n";
268 cout
<< " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
269 cout
<< " --sync-from=[zone-name][,...]\n";
270 cout
<< " set list of zones to sync from\n";
271 cout
<< " --sync-from-rm=[zone-name][,...]\n";
272 cout
<< " remove zones from list of zones to sync from\n";
273 cout
<< " --fix besides checking bucket index, will also fix it\n";
274 cout
<< " --check-objects bucket check: rebuilds bucket index according to\n";
275 cout
<< " actual objects state\n";
276 cout
<< " --format=<format> specify output format for certain operations: xml,\n";
278 cout
<< " --purge-data when specified, user removal will also purge all the\n";
279 cout
<< " user data\n";
280 cout
<< " --purge-keys when specified, subuser removal will also purge all the\n";
281 cout
<< " subuser keys\n";
282 cout
<< " --purge-objects remove a bucket's objects before deleting it\n";
283 cout
<< " (NOTE: required to delete a non-empty bucket)\n";
284 cout
<< " --sync-stats option to 'user stats', update user stats with current\n";
285 cout
<< " stats reported by user's buckets indexes\n";
286 cout
<< " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
287 cout
<< " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
288 cout
<< " --skip-zero-entries log show only dumps entries that don't have zero value\n";
289 cout
<< " in one of the numeric field\n";
290 cout
<< " --infile=<file> specify a file to read in when setting data\n";
291 cout
<< " --state=<state string> specify a state for the opstate set command\n";
292 cout
<< " --replica-log-type replica log type (metadata, data, bucket), required for\n";
293 cout
<< " replica log operations\n";
294 cout
<< " --categories=<list> comma separated list of categories, used in usage show\n";
295 cout
<< " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
296 cout
<< " --yes-i-really-mean-it required for certain operations\n";
297 cout
<< " --warnings-only when specified with bucket limit check, list\n";
298 cout
<< " only buckets nearing or over the current max\n";
299 cout
<< " objects per shard value\n";
300 cout
<< " --bypass-gc when specified with bucket deletion, triggers\n";
301 cout
<< " object deletions by not involving GC\n";
302 cout
<< " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
303 cout
<< " ignores bucket index consistency\n";
305 cout
<< "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
306 cout
<< "\nQuota options:\n";
307 cout
<< " --bucket specified bucket for quota command\n";
308 cout
<< " --max-objects specify max objects (negative value to disable)\n";
309 cout
<< " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
310 cout
<< " --quota-scope scope of quota (bucket, user)\n";
311 cout
<< "\nOrphans search options:\n";
312 cout
<< " --pool data pool to scan for leaked rados objects in\n";
313 cout
<< " --num-shards num of shards to use for keeping the temporary scan info\n";
314 cout
<< " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
315 cout
<< " --job-id set the job id (for orphans find)\n";
316 cout
<< " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
317 cout
<< "\nOrphans list-jobs options:\n";
318 cout
<< " --extra-info provide extra info in job list\n";
319 cout
<< "\nRole options:\n";
320 cout
<< " --role-name name of the role to create\n";
321 cout
<< " --path path to the role\n";
322 cout
<< " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
323 cout
<< " --policy-name name of the policy document\n";
324 cout
<< " --policy-doc permission policy document\n";
325 cout
<< " --path-prefix path prefix for filtering roles\n";
327 generic_client_usage();
347 OPT_BUCKET_LIMIT_CHECK
,
352 OPT_BUCKET_SYNC_STATUS
,
353 OPT_BUCKET_SYNC_INIT
,
355 OPT_BUCKET_SYNC_DISABLE
,
356 OPT_BUCKET_SYNC_ENABLE
,
389 OPT_ORPHANS_LIST_JOBS
,
391 OPT_ZONEGROUP_CREATE
,
392 OPT_ZONEGROUP_DEFAULT
,
393 OPT_ZONEGROUP_DELETE
,
395 OPT_ZONEGROUP_MODIFY
,
398 OPT_ZONEGROUP_REMOVE
,
399 OPT_ZONEGROUP_RENAME
,
400 OPT_ZONEGROUP_PLACEMENT_ADD
,
401 OPT_ZONEGROUP_PLACEMENT_MODIFY
,
402 OPT_ZONEGROUP_PLACEMENT_RM
,
403 OPT_ZONEGROUP_PLACEMENT_LIST
,
404 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
413 OPT_ZONE_PLACEMENT_ADD
,
414 OPT_ZONE_PLACEMENT_MODIFY
,
415 OPT_ZONE_PLACEMENT_RM
,
416 OPT_ZONE_PLACEMENT_LIST
,
423 OPT_METADATA_SYNC_STATUS
,
424 OPT_METADATA_SYNC_INIT
,
425 OPT_METADATA_SYNC_RUN
,
435 OPT_DATA_SYNC_STATUS
,
446 OPT_REPLICALOG_UPDATE
,
447 OPT_REPLICALOG_DELETE
,
451 OPT_REALM_GET_DEFAULT
,
453 OPT_REALM_LIST_PERIODS
,
461 OPT_PERIOD_GET_CURRENT
,
467 OPT_GLOBAL_QUOTA_GET
,
468 OPT_GLOBAL_QUOTA_SET
,
469 OPT_GLOBAL_QUOTA_ENABLE
,
470 OPT_GLOBAL_QUOTA_DISABLE
,
478 OPT_ROLE_POLICY_LIST
,
480 OPT_ROLE_POLICY_DELETE
,
488 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
491 // NOTE: please keep the checks in alphabetical order !!!
492 if (strcmp(cmd
, "bi") == 0 ||
493 strcmp(cmd
, "bilog") == 0 ||
494 strcmp(cmd
, "buckets") == 0 ||
495 strcmp(cmd
, "caps") == 0 ||
496 strcmp(cmd
, "data") == 0 ||
497 strcmp(cmd
, "datalog") == 0 ||
498 strcmp(cmd
, "error") == 0 ||
499 strcmp(cmd
, "gc") == 0 ||
500 strcmp(cmd
, "global") == 0 ||
501 strcmp(cmd
, "key") == 0 ||
502 strcmp(cmd
, "log") == 0 ||
503 strcmp(cmd
, "lc") == 0 ||
504 strcmp(cmd
, "mdlog") == 0 ||
505 strcmp(cmd
, "metadata") == 0 ||
506 strcmp(cmd
, "object") == 0 ||
507 strcmp(cmd
, "objects") == 0 ||
508 strcmp(cmd
, "olh") == 0 ||
509 strcmp(cmd
, "opstate") == 0 ||
510 strcmp(cmd
, "orphans") == 0 ||
511 strcmp(cmd
, "period") == 0 ||
512 strcmp(cmd
, "placement") == 0 ||
513 strcmp(cmd
, "pool") == 0 ||
514 strcmp(cmd
, "pools") == 0 ||
515 strcmp(cmd
, "quota") == 0 ||
516 strcmp(cmd
, "realm") == 0 ||
517 strcmp(cmd
, "replicalog") == 0 ||
518 strcmp(cmd
, "role") == 0 ||
519 strcmp(cmd
, "role-policy") == 0 ||
520 strcmp(cmd
, "subuser") == 0 ||
521 strcmp(cmd
, "sync") == 0 ||
522 strcmp(cmd
, "usage") == 0 ||
523 strcmp(cmd
, "user") == 0 ||
524 strcmp(cmd
, "zone") == 0 ||
525 strcmp(cmd
, "zonegroup") == 0 ||
526 strcmp(cmd
, "zonegroups") == 0) {
532 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
534 if (strcmp(cmd
, "reshard") == 0 &&
535 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
539 if (strcmp(cmd
, "bucket") == 0 &&
540 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
545 if (strcmp(cmd
, "policy") == 0)
551 if (strcmp(prev_cmd
, "user") == 0) {
552 if (strcmp(cmd
, "create") == 0)
553 return OPT_USER_CREATE
;
554 if (strcmp(cmd
, "info") == 0)
555 return OPT_USER_INFO
;
556 if (strcmp(cmd
, "modify") == 0)
557 return OPT_USER_MODIFY
;
558 if (strcmp(cmd
, "rm") == 0)
560 if (strcmp(cmd
, "suspend") == 0)
561 return OPT_USER_SUSPEND
;
562 if (strcmp(cmd
, "enable") == 0)
563 return OPT_USER_ENABLE
;
564 if (strcmp(cmd
, "check") == 0)
565 return OPT_USER_CHECK
;
566 if (strcmp(cmd
, "stats") == 0)
567 return OPT_USER_STATS
;
568 if (strcmp(cmd
, "list") == 0)
569 return OPT_USER_LIST
;
570 } else if (strcmp(prev_cmd
, "subuser") == 0) {
571 if (strcmp(cmd
, "create") == 0)
572 return OPT_SUBUSER_CREATE
;
573 if (strcmp(cmd
, "modify") == 0)
574 return OPT_SUBUSER_MODIFY
;
575 if (strcmp(cmd
, "rm") == 0)
576 return OPT_SUBUSER_RM
;
577 } else if (strcmp(prev_cmd
, "key") == 0) {
578 if (strcmp(cmd
, "create") == 0)
579 return OPT_KEY_CREATE
;
580 if (strcmp(cmd
, "rm") == 0)
582 } else if (strcmp(prev_cmd
, "buckets") == 0) {
583 if (strcmp(cmd
, "list") == 0)
584 return OPT_BUCKETS_LIST
;
585 } else if (strcmp(prev_cmd
, "bucket") == 0) {
586 if (strcmp(cmd
, "list") == 0)
587 return OPT_BUCKETS_LIST
;
588 if (strcmp(cmd
, "link") == 0)
589 return OPT_BUCKET_LINK
;
590 if (strcmp(cmd
, "unlink") == 0)
591 return OPT_BUCKET_UNLINK
;
592 if (strcmp(cmd
, "stats") == 0)
593 return OPT_BUCKET_STATS
;
594 if (strcmp(cmd
, "rm") == 0)
595 return OPT_BUCKET_RM
;
596 if (strcmp(cmd
, "rewrite") == 0)
597 return OPT_BUCKET_REWRITE
;
598 if (strcmp(cmd
, "reshard") == 0)
599 return OPT_BUCKET_RESHARD
;
600 if (strcmp(cmd
, "check") == 0)
601 return OPT_BUCKET_CHECK
;
602 if (strcmp(cmd
, "sync") == 0) {
606 if (strcmp(cmd
, "limit") == 0) {
610 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
611 if (strcmp(prev_cmd
, "sync") == 0) {
612 if (strcmp(cmd
, "status") == 0)
613 return OPT_BUCKET_SYNC_STATUS
;
614 if (strcmp(cmd
, "init") == 0)
615 return OPT_BUCKET_SYNC_INIT
;
616 if (strcmp(cmd
, "run") == 0)
617 return OPT_BUCKET_SYNC_RUN
;
618 if (strcmp(cmd
, "disable") == 0)
619 return OPT_BUCKET_SYNC_DISABLE
;
620 if (strcmp(cmd
, "enable") == 0)
621 return OPT_BUCKET_SYNC_ENABLE
;
622 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
623 (strcmp(cmd
, "check") == 0)) {
624 return OPT_BUCKET_LIMIT_CHECK
;
626 } else if (strcmp(prev_cmd
, "log") == 0) {
627 if (strcmp(cmd
, "list") == 0)
629 if (strcmp(cmd
, "show") == 0)
631 if (strcmp(cmd
, "rm") == 0)
633 } else if (strcmp(prev_cmd
, "usage") == 0) {
634 if (strcmp(cmd
, "show") == 0)
635 return OPT_USAGE_SHOW
;
636 if (strcmp(cmd
, "trim") == 0)
637 return OPT_USAGE_TRIM
;
638 } else if (strcmp(prev_cmd
, "caps") == 0) {
639 if (strcmp(cmd
, "add") == 0)
641 if (strcmp(cmd
, "rm") == 0)
643 } else if (strcmp(prev_cmd
, "pool") == 0) {
644 if (strcmp(cmd
, "add") == 0)
646 if (strcmp(cmd
, "rm") == 0)
648 if (strcmp(cmd
, "list") == 0)
649 return OPT_POOLS_LIST
;
650 } else if (strcmp(prev_cmd
, "pools") == 0) {
651 if (strcmp(cmd
, "list") == 0)
652 return OPT_POOLS_LIST
;
653 } else if (strcmp(prev_cmd
, "object") == 0) {
654 if (strcmp(cmd
, "rm") == 0)
655 return OPT_OBJECT_RM
;
656 if (strcmp(cmd
, "unlink") == 0)
657 return OPT_OBJECT_UNLINK
;
658 if (strcmp(cmd
, "stat") == 0)
659 return OPT_OBJECT_STAT
;
660 if (strcmp(cmd
, "rewrite") == 0)
661 return OPT_OBJECT_REWRITE
;
662 } else if (strcmp(prev_cmd
, "objects") == 0) {
663 if (strcmp(cmd
, "expire") == 0)
664 return OPT_OBJECTS_EXPIRE
;
665 } else if (strcmp(prev_cmd
, "olh") == 0) {
666 if (strcmp(cmd
, "get") == 0)
668 if (strcmp(cmd
, "readlog") == 0)
669 return OPT_OLH_READLOG
;
670 } else if (strcmp(prev_cmd
, "bi") == 0) {
671 if (strcmp(cmd
, "get") == 0)
673 if (strcmp(cmd
, "put") == 0)
675 if (strcmp(cmd
, "list") == 0)
677 if (strcmp(cmd
, "purge") == 0)
679 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
680 (strcmp(prev_cmd
, "quota") == 0)) {
681 if (strcmp(cmd
, "get") == 0)
682 return OPT_GLOBAL_QUOTA_GET
;
683 if (strcmp(cmd
, "set") == 0)
684 return OPT_GLOBAL_QUOTA_SET
;
685 if (strcmp(cmd
, "enable") == 0)
686 return OPT_GLOBAL_QUOTA_ENABLE
;
687 if (strcmp(cmd
, "disable") == 0)
688 return OPT_GLOBAL_QUOTA_DISABLE
;
689 } else if (strcmp(prev_cmd
, "period") == 0) {
690 if (strcmp(cmd
, "delete") == 0)
691 return OPT_PERIOD_DELETE
;
692 if (strcmp(cmd
, "get") == 0)
693 return OPT_PERIOD_GET
;
694 if (strcmp(cmd
, "get-current") == 0)
695 return OPT_PERIOD_GET_CURRENT
;
696 if (strcmp(cmd
, "pull") == 0)
697 return OPT_PERIOD_PULL
;
698 if (strcmp(cmd
, "push") == 0)
699 return OPT_PERIOD_PUSH
;
700 if (strcmp(cmd
, "list") == 0)
701 return OPT_PERIOD_LIST
;
702 if (strcmp(cmd
, "update") == 0)
703 return OPT_PERIOD_UPDATE
;
704 if (strcmp(cmd
, "commit") == 0)
705 return OPT_PERIOD_COMMIT
;
706 } else if (strcmp(prev_cmd
, "realm") == 0) {
707 if (strcmp(cmd
, "create") == 0)
708 return OPT_REALM_CREATE
;
709 if (strcmp(cmd
, "delete") == 0)
710 return OPT_REALM_DELETE
;
711 if (strcmp(cmd
, "get") == 0)
712 return OPT_REALM_GET
;
713 if (strcmp(cmd
, "get-default") == 0)
714 return OPT_REALM_GET_DEFAULT
;
715 if (strcmp(cmd
, "list") == 0)
716 return OPT_REALM_LIST
;
717 if (strcmp(cmd
, "list-periods") == 0)
718 return OPT_REALM_LIST_PERIODS
;
719 if (strcmp(cmd
, "remove") == 0)
720 return OPT_REALM_REMOVE
;
721 if (strcmp(cmd
, "rename") == 0)
722 return OPT_REALM_RENAME
;
723 if (strcmp(cmd
, "set") == 0)
724 return OPT_REALM_SET
;
725 if (strcmp(cmd
, "default") == 0)
726 return OPT_REALM_DEFAULT
;
727 if (strcmp(cmd
, "pull") == 0)
728 return OPT_REALM_PULL
;
729 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
730 (strcmp(prev_cmd
, "placement") == 0)) {
731 if (strcmp(cmd
, "add") == 0)
732 return OPT_ZONEGROUP_PLACEMENT_ADD
;
733 if (strcmp(cmd
, "modify") == 0)
734 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
735 if (strcmp(cmd
, "rm") == 0)
736 return OPT_ZONEGROUP_PLACEMENT_RM
;
737 if (strcmp(cmd
, "list") == 0)
738 return OPT_ZONEGROUP_PLACEMENT_LIST
;
739 if (strcmp(cmd
, "default") == 0)
740 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
741 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
742 if (strcmp(cmd
, "add") == 0)
743 return OPT_ZONEGROUP_ADD
;
744 if (strcmp(cmd
, "create")== 0)
745 return OPT_ZONEGROUP_CREATE
;
746 if (strcmp(cmd
, "default") == 0)
747 return OPT_ZONEGROUP_DEFAULT
;
748 if (strcmp(cmd
, "delete") == 0)
749 return OPT_ZONEGROUP_DELETE
;
750 if (strcmp(cmd
, "get") == 0)
751 return OPT_ZONEGROUP_GET
;
752 if (strcmp(cmd
, "modify") == 0)
753 return OPT_ZONEGROUP_MODIFY
;
754 if (strcmp(cmd
, "list") == 0)
755 return OPT_ZONEGROUP_LIST
;
756 if (strcmp(cmd
, "set") == 0)
757 return OPT_ZONEGROUP_SET
;
758 if (strcmp(cmd
, "remove") == 0)
759 return OPT_ZONEGROUP_REMOVE
;
760 if (strcmp(cmd
, "rename") == 0)
761 return OPT_ZONEGROUP_RENAME
;
762 } else if (strcmp(prev_cmd
, "quota") == 0) {
763 if (strcmp(cmd
, "set") == 0)
764 return OPT_QUOTA_SET
;
765 if (strcmp(cmd
, "enable") == 0)
766 return OPT_QUOTA_ENABLE
;
767 if (strcmp(cmd
, "disable") == 0)
768 return OPT_QUOTA_DISABLE
;
769 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
770 if (strcmp(cmd
, "list") == 0)
771 return OPT_ZONEGROUP_LIST
;
772 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
773 (strcmp(prev_cmd
, "placement") == 0)) {
774 if (strcmp(cmd
, "add") == 0)
775 return OPT_ZONE_PLACEMENT_ADD
;
776 if (strcmp(cmd
, "modify") == 0)
777 return OPT_ZONE_PLACEMENT_MODIFY
;
778 if (strcmp(cmd
, "rm") == 0)
779 return OPT_ZONE_PLACEMENT_RM
;
780 if (strcmp(cmd
, "list") == 0)
781 return OPT_ZONE_PLACEMENT_LIST
;
782 } else if (strcmp(prev_cmd
, "zone") == 0) {
783 if (strcmp(cmd
, "delete") == 0)
784 return OPT_ZONE_DELETE
;
785 if (strcmp(cmd
, "create") == 0)
786 return OPT_ZONE_CREATE
;
787 if (strcmp(cmd
, "get") == 0)
789 if (strcmp(cmd
, "set") == 0)
791 if (strcmp(cmd
, "list") == 0)
792 return OPT_ZONE_LIST
;
793 if (strcmp(cmd
, "modify") == 0)
794 return OPT_ZONE_MODIFY
;
795 if (strcmp(cmd
, "rename") == 0)
796 return OPT_ZONE_RENAME
;
797 if (strcmp(cmd
, "default") == 0)
798 return OPT_ZONE_DEFAULT
;
799 } else if (strcmp(prev_cmd
, "zones") == 0) {
800 if (strcmp(cmd
, "list") == 0)
801 return OPT_ZONE_LIST
;
802 } else if (strcmp(prev_cmd
, "gc") == 0) {
803 if (strcmp(cmd
, "list") == 0)
805 if (strcmp(cmd
, "process") == 0)
806 return OPT_GC_PROCESS
;
807 } else if (strcmp(prev_cmd
, "lc") == 0) {
808 if (strcmp(cmd
, "list") == 0)
810 if (strcmp(cmd
, "process") == 0)
811 return OPT_LC_PROCESS
;
812 } else if (strcmp(prev_cmd
, "orphans") == 0) {
813 if (strcmp(cmd
, "find") == 0)
814 return OPT_ORPHANS_FIND
;
815 if (strcmp(cmd
, "finish") == 0)
816 return OPT_ORPHANS_FINISH
;
817 if (strcmp(cmd
, "list-jobs") == 0)
818 return OPT_ORPHANS_LIST_JOBS
;
819 } else if (strcmp(prev_cmd
, "metadata") == 0) {
820 if (strcmp(cmd
, "get") == 0)
821 return OPT_METADATA_GET
;
822 if (strcmp(cmd
, "put") == 0)
823 return OPT_METADATA_PUT
;
824 if (strcmp(cmd
, "rm") == 0)
825 return OPT_METADATA_RM
;
826 if (strcmp(cmd
, "list") == 0)
827 return OPT_METADATA_LIST
;
828 if (strcmp(cmd
, "sync") == 0) {
832 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
833 (strcmp(prev_cmd
, "sync") == 0)) {
834 if (strcmp(cmd
, "status") == 0)
835 return OPT_METADATA_SYNC_STATUS
;
836 if (strcmp(cmd
, "init") == 0)
837 return OPT_METADATA_SYNC_INIT
;
838 if (strcmp(cmd
, "run") == 0)
839 return OPT_METADATA_SYNC_RUN
;
840 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
841 (strcmp(prev_cmd
, "error") == 0)) {
842 if (strcmp(cmd
, "list") == 0)
843 return OPT_SYNC_ERROR_LIST
;
844 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
845 if (strcmp(cmd
, "list") == 0)
846 return OPT_MDLOG_LIST
;
847 if (strcmp(cmd
, "autotrim") == 0)
848 return OPT_MDLOG_AUTOTRIM
;
849 if (strcmp(cmd
, "trim") == 0)
850 return OPT_MDLOG_TRIM
;
851 if (strcmp(cmd
, "fetch") == 0)
852 return OPT_MDLOG_FETCH
;
853 if (strcmp(cmd
, "status") == 0)
854 return OPT_MDLOG_STATUS
;
855 } else if (strcmp(prev_cmd
, "bilog") == 0) {
856 if (strcmp(cmd
, "list") == 0)
857 return OPT_BILOG_LIST
;
858 if (strcmp(cmd
, "trim") == 0)
859 return OPT_BILOG_TRIM
;
860 if (strcmp(cmd
, "status") == 0)
861 return OPT_BILOG_STATUS
;
862 } else if (strcmp(prev_cmd
, "data") == 0) {
863 if (strcmp(cmd
, "sync") == 0) {
867 } else if (strcmp(prev_cmd
, "datalog") == 0) {
868 if (strcmp(cmd
, "list") == 0)
869 return OPT_DATALOG_LIST
;
870 if (strcmp(cmd
, "trim") == 0)
871 return OPT_DATALOG_TRIM
;
872 if (strcmp(cmd
, "status") == 0)
873 return OPT_DATALOG_STATUS
;
874 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
875 (strcmp(prev_cmd
, "sync") == 0)) {
876 if (strcmp(cmd
, "status") == 0)
877 return OPT_DATA_SYNC_STATUS
;
878 if (strcmp(cmd
, "init") == 0)
879 return OPT_DATA_SYNC_INIT
;
880 if (strcmp(cmd
, "run") == 0)
881 return OPT_DATA_SYNC_RUN
;
882 } else if (strcmp(prev_cmd
, "opstate") == 0) {
883 if (strcmp(cmd
, "list") == 0)
884 return OPT_OPSTATE_LIST
;
885 if (strcmp(cmd
, "set") == 0)
886 return OPT_OPSTATE_SET
;
887 if (strcmp(cmd
, "renew") == 0)
888 return OPT_OPSTATE_RENEW
;
889 if (strcmp(cmd
, "rm") == 0)
890 return OPT_OPSTATE_RM
;
891 } else if (strcmp(prev_cmd
, "replicalog") == 0) {
892 if (strcmp(cmd
, "get") == 0)
893 return OPT_REPLICALOG_GET
;
894 if (strcmp(cmd
, "update") == 0)
895 return OPT_REPLICALOG_UPDATE
;
896 if (strcmp(cmd
, "delete") == 0)
897 return OPT_REPLICALOG_DELETE
;
898 } else if (strcmp(prev_cmd
, "sync") == 0) {
899 if (strcmp(cmd
, "status") == 0)
900 return OPT_SYNC_STATUS
;
901 } else if (strcmp(prev_cmd
, "role") == 0) {
902 if (strcmp(cmd
, "create") == 0)
903 return OPT_ROLE_CREATE
;
904 if (strcmp(cmd
, "delete") == 0)
905 return OPT_ROLE_DELETE
;
906 if (strcmp(cmd
, "get") == 0)
908 if (strcmp(cmd
, "modify") == 0)
909 return OPT_ROLE_MODIFY
;
910 if (strcmp(cmd
, "list") == 0)
911 return OPT_ROLE_LIST
;
912 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
913 if (strcmp(cmd
, "put") == 0)
914 return OPT_ROLE_POLICY_PUT
;
915 if (strcmp(cmd
, "list") == 0)
916 return OPT_ROLE_POLICY_LIST
;
917 if (strcmp(cmd
, "get") == 0)
918 return OPT_ROLE_POLICY_GET
;
919 if (strcmp(cmd
, "delete") == 0)
920 return OPT_ROLE_POLICY_DELETE
;
921 } else if (strcmp(prev_cmd
, "reshard") == 0) {
922 if (strcmp(cmd
, "bucket") == 0)
923 return OPT_BUCKET_RESHARD
;
924 if (strcmp(cmd
, "add") == 0)
925 return OPT_RESHARD_ADD
;
926 if (strcmp(cmd
, "list") == 0)
927 return OPT_RESHARD_LIST
;
928 if (strcmp(cmd
, "status") == 0)
929 return OPT_RESHARD_STATUS
;
930 if (strcmp(cmd
, "execute") == 0)
931 return OPT_RESHARD_PROCESS
;
932 if (strcmp(cmd
, "cancel") == 0)
933 return OPT_RESHARD_CANCEL
;
939 enum ReplicaLogType
{
940 ReplicaLog_Invalid
= 0,
946 ReplicaLogType
get_replicalog_type(const string
& name
) {
947 if (name
== "md" || name
== "meta" || name
== "metadata")
948 return ReplicaLog_Metadata
;
950 return ReplicaLog_Data
;
951 if (name
== "bucket")
952 return ReplicaLog_Bucket
;
954 return ReplicaLog_Invalid
;
957 BIIndexType
get_bi_index_type(const string
& type_str
) {
958 if (type_str
== "plain")
960 if (type_str
== "instance")
962 if (type_str
== "olh")
968 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
970 bufferlist::iterator iter
= bl
.begin();
971 switch (index_type
) {
975 rgw_bucket_dir_entry entry
;
976 ::decode(entry
, iter
);
977 encode_json("entry", entry
, formatter
);
982 rgw_bucket_olh_entry entry
;
983 ::decode(entry
, iter
);
984 encode_json("entry", entry
, formatter
);
993 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
995 encode_json("user_info", info
, formatter
);
996 formatter
->flush(cout
);
1000 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1002 formatter
->open_object_section("role");
1003 formatter
->dump_string("Permission policy", perm_policy
);
1004 formatter
->close_section();
1005 formatter
->flush(cout
);
1008 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1010 formatter
->open_array_section("PolicyNames");
1011 for (const auto& it
: policy_names
) {
1012 formatter
->dump_string("policyname", it
);
1014 formatter
->close_section();
1015 formatter
->flush(cout
);
1018 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1020 formatter
->open_object_section("role");
1021 role
.dump(formatter
);
1022 formatter
->close_section();
1023 formatter
->flush(cout
);
1026 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1028 formatter
->open_array_section("Roles");
1029 for (const auto& it
: roles
) {
1030 formatter
->open_object_section("role");
1032 formatter
->close_section();
1034 formatter
->close_section();
1035 formatter
->flush(cout
);
1038 class StoreDestructor
{
1041 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1042 ~StoreDestructor() {
1043 RGWStoreManager::close_storage(store
);
1047 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1048 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1050 if (!bucket_name
.empty()) {
1051 RGWObjectCtx
obj_ctx(store
);
1053 if (bucket_id
.empty()) {
1054 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1056 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1057 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1060 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1063 bucket
= bucket_info
.bucket
;
1068 static int read_input(const string
& infile
, bufferlist
& bl
)
1071 if (infile
.size()) {
1072 fd
= open(infile
.c_str(), O_RDONLY
);
1075 cerr
<< "error reading input file " << infile
<< std::endl
;
1080 #define READ_CHUNK 8196
1085 char buf
[READ_CHUNK
];
1087 r
= safe_read(fd
, buf
, READ_CHUNK
);
1090 cerr
<< "error while reading input" << std::endl
;
1098 if (infile
.size()) {
1105 static int read_decode_json(const string
& infile
, T
& t
)
1108 int ret
= read_input(infile
, bl
);
1110 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1114 if (!p
.parse(bl
.c_str(), bl
.length())) {
1115 cout
<< "failed to parse JSON" << std::endl
;
1120 decode_json_obj(t
, &p
);
1121 } catch (JSONDecoder::err
& e
) {
1122 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1128 template <class T
, class K
>
1129 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1132 int ret
= read_input(infile
, bl
);
1134 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1138 if (!p
.parse(bl
.c_str(), bl
.length())) {
1139 cout
<< "failed to parse JSON" << std::endl
;
1144 t
.decode_json(&p
, k
);
1145 } catch (JSONDecoder::err
& e
) {
1146 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1152 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1157 if (!date_str
.empty()) {
1158 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1160 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1165 ut
= utime_t(epoch
, nsec
);
1171 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1175 bufferlist::iterator iter
= bl
.begin();
1179 } catch (buffer::error
& err
) {
1183 encode_json(field_name
, t
, f
);
1188 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1191 if (bl
.length() > 0) {
1192 val
.assign(bl
.c_str());
1194 f
->dump_string(field_name
, val
);
1199 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1200 bool have_max_size
, bool have_max_objects
)
1203 case OPT_QUOTA_ENABLE
:
1204 case OPT_GLOBAL_QUOTA_ENABLE
:
1205 quota
.enabled
= true;
1207 // falling through on purpose
1210 case OPT_GLOBAL_QUOTA_SET
:
1211 if (have_max_objects
) {
1212 if (max_objects
< 0) {
1213 quota
.max_objects
= -1;
1215 quota
.max_objects
= max_objects
;
1218 if (have_max_size
) {
1220 quota
.max_size
= -1;
1222 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1226 case OPT_QUOTA_DISABLE
:
1227 case OPT_GLOBAL_QUOTA_DISABLE
:
1228 quota
.enabled
= false;
1233 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1234 const string
& tenant_name
, const string
& bucket_name
,
1235 int64_t max_size
, int64_t max_objects
,
1236 bool have_max_size
, bool have_max_objects
)
1238 RGWBucketInfo bucket_info
;
1239 map
<string
, bufferlist
> attrs
;
1240 RGWObjectCtx
obj_ctx(store
);
1241 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1243 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1247 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1249 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1251 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1257 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1258 bool have_max_size
, bool have_max_objects
)
1260 RGWUserInfo
& user_info
= op_state
.get_user_info();
1262 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1264 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1267 int r
= user
.modify(op_state
, &err
);
1269 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1275 int set_user_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
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1282 op_state
.set_user_quota(user_info
.user_quota
);
1285 int r
= user
.modify(op_state
, &err
);
1287 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1293 static bool bucket_object_check_filter(const string
& name
)
1296 string ns
; /* empty namespace */
1297 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1300 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1302 map
<string
, bufferlist
> attrs
;
1305 RGWObjectCtx
obj_ctx(store
);
1306 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1307 RGWRados::Object::Read
read_op(&op_target
);
1309 read_op
.params
.attrs
= &attrs
;
1310 read_op
.params
.obj_size
= &obj_size
;
1312 int ret
= read_op
.prepare();
1314 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1318 map
<string
, bufferlist
>::iterator iter
;
1319 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1320 if (iter
== attrs
.end()) {
1321 *need_rewrite
= (obj_size
>= min_stripe_size
);
1325 RGWObjManifest manifest
;
1328 bufferlist
& bl
= iter
->second
;
1329 bufferlist::iterator biter
= bl
.begin();
1330 ::decode(manifest
, biter
);
1331 } catch (buffer::error
& err
) {
1332 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1336 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1337 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1338 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1339 RGWObjManifestPart
& part
= oiter
->second
;
1341 if (part
.size
>= min_stripe_size
) {
1342 *need_rewrite
= true;
1346 *need_rewrite
= false;
1352 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1353 f
->open_object_section("object");
1354 f
->open_object_section("key");
1355 f
->dump_string("type", "head");
1356 f
->dump_string("name", key
.name
);
1357 f
->dump_string("instance", key
.instance
);
1363 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1365 f
->dump_string("oid", oid
);
1366 f
->dump_string("locator", locator
);
1369 RGWObjectCtx
obj_ctx(store
);
1371 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1372 RGWRados::Object::Read
read_op(&op_target
);
1374 int ret
= read_op
.prepare();
1375 bool needs_fixing
= (ret
== -ENOENT
);
1377 f
->dump_bool("needs_fixing", needs_fixing
);
1379 string status
= (needs_fixing
? "needs_fixing" : "ok");
1381 if ((needs_fixing
|| remove_bad
) && fix
) {
1382 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1384 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1391 f
->dump_string("status", status
);
1398 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1399 f
->open_object_section("object");
1400 f
->open_object_section("key");
1401 f
->dump_string("type", "tail");
1402 f
->dump_string("name", key
.name
);
1403 f
->dump_string("instance", key
.instance
);
1409 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1411 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1414 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1417 f
->dump_bool("needs_fixing", needs_fixing
);
1418 f
->dump_string("status", status
);
1425 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1426 bool fix
, bool remove_bad
, Formatter
*f
)
1428 if (remove_bad
&& !fix
) {
1429 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1433 RGWBucketInfo bucket_info
;
1437 f
->open_object_section("bucket");
1438 f
->dump_string("bucket", bucket_name
);
1439 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1441 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1447 int max_entries
= 1000;
1451 vector
<rgw_bucket_dir_entry
> result
;
1452 map
<string
, bool> common_prefixes
;
1455 RGWRados::Bucket
target(store
, bucket_info
);
1456 RGWRados::Bucket::List
list_op(&target
);
1460 list_op
.params
.prefix
= prefix
;
1461 list_op
.params
.delim
= delim
;
1462 list_op
.params
.marker
= rgw_obj_key(marker
);
1463 list_op
.params
.ns
= ns
;
1464 list_op
.params
.enforce_ns
= true;
1465 list_op
.params
.list_versions
= true;
1467 f
->open_array_section("check_objects");
1469 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1471 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1475 count
+= result
.size();
1477 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1478 rgw_obj_key key
= iter
->key
;
1479 rgw_obj
obj(bucket
, key
);
1481 if (key
.name
[0] == '_') {
1482 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1485 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1490 } while (truncated
&& count
< max_entries
);
1499 int set_bucket_sync_enabled(RGWRados
*store
, int opt_cmd
, const string
& tenant_name
, const string
& bucket_name
)
1501 RGWBucketInfo bucket_info
;
1502 map
<string
, bufferlist
> attrs
;
1503 RGWObjectCtx
obj_ctx(store
);
1505 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1507 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1511 if (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
) {
1512 bucket_info
.flags
&= ~BUCKET_DATASYNC_DISABLED
;
1513 } else if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1514 bucket_info
.flags
|= BUCKET_DATASYNC_DISABLED
;
1517 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1519 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1523 int shards_num
= bucket_info
.num_shards
? bucket_info
.num_shards
: 1;
1524 int shard_id
= bucket_info
.num_shards
? 0 : -1;
1526 if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1527 r
= store
->stop_bi_log_entries(bucket_info
, -1);
1529 lderr(store
->ctx()) << "ERROR: failed writing stop bilog" << dendl
;
1533 r
= store
->resync_bi_log_entries(bucket_info
, -1);
1535 lderr(store
->ctx()) << "ERROR: failed writing resync bilog" << dendl
;
1540 for (int i
= 0; i
< shards_num
; ++i
, ++shard_id
) {
1541 r
= store
->data_log
->add_entry(bucket_info
.bucket
, shard_id
);
1543 lderr(store
->ctx()) << "ERROR: failed writing data log" << dendl
;
1552 /// search for a matching zone/zonegroup id and return a connection if found
1553 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1554 const RGWZoneGroup
& zonegroup
,
1555 const std::string
& remote
)
1557 boost::optional
<RGWRESTConn
> conn
;
1558 if (remote
== zonegroup
.get_id()) {
1559 conn
.emplace(store
->ctx(), store
, remote
, zonegroup
.endpoints
);
1561 for (const auto& z
: zonegroup
.zones
) {
1562 const auto& zone
= z
.second
;
1563 if (remote
== zone
.id
) {
1564 conn
.emplace(store
->ctx(), store
, remote
, zone
.endpoints
);
1572 /// search each zonegroup for a connection
1573 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1574 const RGWPeriodMap
& period_map
,
1575 const std::string
& remote
)
1577 boost::optional
<RGWRESTConn
> conn
;
1578 for (const auto& zg
: period_map
.zonegroups
) {
1579 conn
= get_remote_conn(store
, zg
.second
, remote
);
1587 // we expect a very small response
1588 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1590 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1591 bufferlist
& in_data
, JSONParser
& parser
)
1597 ceph::bufferlist response
;
1599 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1601 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1602 if (parse_ret
< 0) {
1603 cerr
<< "failed to parse response" << std::endl
;
1609 static int send_to_url(const string
& url
, const string
& access
,
1610 const string
& secret
, req_info
& info
,
1611 bufferlist
& in_data
, JSONParser
& parser
)
1613 if (access
.empty() || secret
.empty()) {
1614 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1622 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1624 bufferlist response
;
1625 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1627 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1628 if (parse_ret
< 0) {
1629 cout
<< "failed to parse response" << std::endl
;
1635 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1636 const string
& access
, const string
& secret
,
1637 req_info
& info
, bufferlist
& in_data
,
1641 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1643 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1646 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1647 string remote
, const string
& url
,
1648 const string
& access
, const string
& secret
,
1651 const string
& master_zone
= period
.get_master_zone();
1652 if (master_zone
.empty()) {
1653 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1656 // are we the period's master zone?
1657 if (store
->get_zone_params().get_id() == master_zone
) {
1658 // read the current period
1659 RGWPeriod current_period
;
1660 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1662 cerr
<< "Error initializing current period: "
1663 << cpp_strerror(-ret
) << std::endl
;
1666 // the master zone can commit locally
1667 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1669 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1674 if (remote
.empty() && url
.empty()) {
1675 // use the new master zone's connection
1676 remote
= master_zone
;
1677 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1679 boost::optional
<RGWRESTConn
> conn
;
1680 RGWRESTConn
*remote_conn
= nullptr;
1681 if (!remote
.empty()) {
1682 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1684 cerr
<< "failed to find a zone or zonegroup for remote "
1685 << remote
<< std::endl
;
1688 remote_conn
= &*conn
;
1691 // push period to the master with an empty period id
1695 req_info
info(g_ceph_context
, &env
);
1696 info
.method
= "POST";
1697 info
.request_uri
= "/admin/realm/period";
1699 // json format into a bufferlist
1700 JSONFormatter
jf(false);
1701 encode_json("period", period
, &jf
);
1706 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1708 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1710 // did we parse an error message?
1711 auto message
= p
.find_obj("Message");
1713 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1718 // decode the response and store it back
1720 decode_json_obj(period
, &p
);
1721 } catch (JSONDecoder::err
& e
) {
1722 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1725 if (period
.get_id().empty()) {
1726 cerr
<< "Period commit got back an empty period id" << std::endl
;
1729 // the master zone gave us back the period that it committed, so it's
1730 // safe to save it as our latest epoch
1731 ret
= period
.store_info(false);
1733 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1734 << cpp_strerror(ret
) << std::endl
;
1737 ret
= period
.set_latest_epoch(period
.get_epoch());
1739 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1742 ret
= period
.reflect();
1744 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1747 realm
.notify_new_period(period
);
1751 static int update_period(const string
& realm_id
, const string
& realm_name
,
1752 const string
& period_id
, const string
& period_epoch
,
1753 bool commit
, const string
& remote
, const string
& url
,
1754 const string
& access
, const string
& secret
,
1755 Formatter
*formatter
, bool force
)
1757 RGWRealm
realm(realm_id
, realm_name
);
1758 int ret
= realm
.init(g_ceph_context
, store
);
1760 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1764 if (!period_epoch
.empty()) {
1765 epoch
= atoi(period_epoch
.c_str());
1767 RGWPeriod
period(period_id
, epoch
);
1768 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1770 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1774 ret
= period
.update();
1776 // Dropping the error message here, as both the ret codes were handled in
1780 ret
= period
.store_info(false);
1782 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1786 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1788 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1792 encode_json("period", period
, formatter
);
1793 formatter
->flush(cout
);
1798 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1799 const string
& bucket_id
, rgw_bucket
& bucket
)
1801 RGWBucketInfo bucket_info
;
1803 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1805 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1812 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1813 const string
& access_key
, const string
& secret_key
,
1814 const string
& realm_id
, const string
& realm_name
,
1815 const string
& period_id
, const string
& period_epoch
,
1819 req_info
info(g_ceph_context
, &env
);
1820 info
.method
= "GET";
1821 info
.request_uri
= "/admin/realm/period";
1823 map
<string
, string
> ¶ms
= info
.args
.get_params();
1824 if (!realm_id
.empty())
1825 params
["realm_id"] = realm_id
;
1826 if (!realm_name
.empty())
1827 params
["realm_name"] = realm_name
;
1828 if (!period_id
.empty())
1829 params
["period_id"] = period_id
;
1830 if (!period_epoch
.empty())
1831 params
["epoch"] = period_epoch
;
1835 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1838 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1841 ret
= period
->init(g_ceph_context
, store
, false);
1843 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1847 decode_json_obj(*period
, &p
);
1848 } catch (JSONDecoder::err
& e
) {
1849 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1852 ret
= period
->store_info(false);
1854 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1856 // store latest epoch (ignore errors)
1857 period
->update_latest_epoch(period
->get_epoch());
1861 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1862 const std::string
& realm_name
,
1863 std::string
* period_id
)
1865 RGWRealm
realm(realm_id
, realm_name
);
1866 int ret
= realm
.init(g_ceph_context
, store
);
1868 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1871 *period_id
= realm
.get_current_period();
1875 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1877 if (!ss
.str().empty()) {
1878 l
.push_back(ss
.str());
1883 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1887 ss
<< setw(tab
) << "" << setw(1);
1892 static void get_md_sync_status(list
<string
>& status
)
1894 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1896 int ret
= sync
.init();
1898 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1902 rgw_meta_sync_status sync_status
;
1903 ret
= sync
.read_sync_status(&sync_status
);
1905 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1910 switch (sync_status
.sync_info
.state
) {
1911 case rgw_meta_sync_info::StateInit
:
1912 status_str
= "init";
1914 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1915 status_str
= "preparing for full sync";
1917 case rgw_meta_sync_info::StateSync
:
1918 status_str
= "syncing";
1921 status_str
= "unknown";
1924 status
.push_back(status_str
);
1926 uint64_t full_total
= 0;
1927 uint64_t full_complete
= 0;
1931 int total_shards
= 0;
1933 for (auto marker_iter
: sync_status
.sync_markers
) {
1934 full_total
+= marker_iter
.second
.total_entries
;
1936 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1938 full_complete
+= marker_iter
.second
.pos
;
1940 full_complete
+= marker_iter
.second
.total_entries
;
1942 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1948 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1951 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1954 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1956 rgw_mdlog_info log_info
;
1957 ret
= sync
.read_log_info(&log_info
);
1959 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1963 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1964 string master_period
= store
->get_current_period_id();
1966 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1968 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1972 map
<int, string
> shards_behind
;
1973 if (sync_status
.sync_info
.period
!= master_period
) {
1974 status
.push_back(string("master is on a different period: master_period=" +
1975 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1977 for (auto local_iter
: sync_status
.sync_markers
) {
1978 int shard_id
= local_iter
.first
;
1979 auto iter
= master_shards_info
.find(shard_id
);
1981 if (iter
== master_shards_info
.end()) {
1983 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
1986 auto master_marker
= iter
->second
.marker
;
1987 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
1988 master_marker
> local_iter
.second
.marker
) {
1989 shards_behind
[shard_id
] = local_iter
.second
.marker
;
1994 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
1995 if (total_behind
== 0) {
1996 push_ss(ss
, status
) << "metadata is caught up with master";
1998 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
2000 map
<int, rgw_mdlog_shard_data
> master_pos
;
2001 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
2003 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2005 ceph::real_time oldest
;
2006 for (auto iter
: master_pos
) {
2007 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
2009 if (!shard_data
.entries
.empty()) {
2010 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
2011 if (ceph::real_clock::is_zero(oldest
)) {
2012 oldest
= entry
.timestamp
;
2013 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2014 oldest
= entry
.timestamp
;
2019 if (!ceph::real_clock::is_zero(oldest
)) {
2020 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
2025 flush_ss(ss
, status
);
2028 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
2032 auto ziter
= store
->zone_by_id
.find(source_zone
);
2033 if (ziter
== store
->zone_by_id
.end()) {
2034 push_ss(ss
, status
, tab
) << string("zone not found");
2035 flush_ss(ss
, status
);
2038 RGWZone
& sz
= ziter
->second
;
2040 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
2041 push_ss(ss
, status
, tab
) << string("not syncing from zone");
2042 flush_ss(ss
, status
);
2045 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
2047 int ret
= sync
.init();
2049 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
2050 flush_ss(ss
, status
);
2054 rgw_data_sync_status sync_status
;
2055 ret
= sync
.read_sync_status(&sync_status
);
2056 if (ret
< 0 && ret
!= -ENOENT
) {
2057 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2062 switch (sync_status
.sync_info
.state
) {
2063 case rgw_data_sync_info::StateInit
:
2064 status_str
= "init";
2066 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2067 status_str
= "preparing for full sync";
2069 case rgw_data_sync_info::StateSync
:
2070 status_str
= "syncing";
2073 status_str
= "unknown";
2076 push_ss(ss
, status
, tab
) << status_str
;
2078 uint64_t full_total
= 0;
2079 uint64_t full_complete
= 0;
2083 int total_shards
= 0;
2085 for (auto marker_iter
: sync_status
.sync_markers
) {
2086 full_total
+= marker_iter
.second
.total_entries
;
2088 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2090 full_complete
+= marker_iter
.second
.pos
;
2092 full_complete
+= marker_iter
.second
.total_entries
;
2094 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2099 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2102 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2105 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2107 rgw_datalog_info log_info
;
2108 ret
= sync
.read_log_info(&log_info
);
2110 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2115 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2117 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2119 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2123 map
<int, string
> shards_behind
;
2125 for (auto local_iter
: sync_status
.sync_markers
) {
2126 int shard_id
= local_iter
.first
;
2127 auto iter
= source_shards_info
.find(shard_id
);
2129 if (iter
== source_shards_info
.end()) {
2131 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2134 auto master_marker
= iter
->second
.marker
;
2135 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2136 master_marker
> local_iter
.second
.marker
) {
2137 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2141 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2142 if (total_behind
== 0) {
2143 push_ss(ss
, status
, tab
) << "data is caught up with source";
2145 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2147 map
<int, rgw_datalog_shard_data
> master_pos
;
2148 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2150 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2152 ceph::real_time oldest
;
2153 for (auto iter
: master_pos
) {
2154 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2156 if (!shard_data
.entries
.empty()) {
2157 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2158 if (ceph::real_clock::is_zero(oldest
)) {
2159 oldest
= entry
.timestamp
;
2160 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2161 oldest
= entry
.timestamp
;
2166 if (!ceph::real_clock::is_zero(oldest
)) {
2167 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2172 flush_ss(ss
, status
);
2175 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2179 for (auto e
: entries
) {
2180 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2186 static void sync_status(Formatter
*formatter
)
2188 RGWRealm
& realm
= store
->realm
;
2189 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2190 RGWZone
& zone
= store
->get_zone();
2194 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2195 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2196 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2198 list
<string
> md_status
;
2200 if (store
->is_meta_master()) {
2201 md_status
.push_back("no sync (zone is master)");
2203 get_md_sync_status(md_status
);
2206 tab_dump("metadata sync", width
, md_status
);
2208 list
<string
> data_status
;
2210 for (auto iter
: store
->zone_conn_map
) {
2211 const string
& source_id
= iter
.first
;
2212 string source_str
= "source: ";
2213 string s
= source_str
+ source_id
;
2214 auto siter
= store
->zone_by_id
.find(source_id
);
2215 if (siter
!= store
->zone_by_id
.end()) {
2216 s
+= string(" (") + siter
->second
.name
+ ")";
2218 data_status
.push_back(s
);
2219 get_data_sync_status(source_id
, data_status
, source_str
.size());
2222 tab_dump("data sync", width
, data_status
);
2225 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2228 get_str_list(s
, ",", confs
);
2229 for (auto c
: confs
) {
2230 ssize_t pos
= c
.find("=");
2234 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2239 int check_reshard_bucket_params(RGWRados
*store
,
2240 const string
& bucket_name
,
2241 const string
& tenant
,
2242 const string
& bucket_id
,
2243 bool num_shards_specified
,
2245 int yes_i_really_mean_it
,
2247 RGWBucketInfo
& bucket_info
,
2248 map
<string
, bufferlist
>& attrs
)
2250 if (bucket_name
.empty()) {
2251 cerr
<< "ERROR: bucket not specified" << std::endl
;
2255 if (!num_shards_specified
) {
2256 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2260 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2261 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2265 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2267 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2271 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2273 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2274 cerr
<< "num shards is less or equal to current shards count" << std::endl
2275 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2281 int create_new_bucket_instance(RGWRados
*store
,
2283 const RGWBucketInfo
& bucket_info
,
2284 map
<string
, bufferlist
>& attrs
,
2285 RGWBucketInfo
& new_bucket_info
)
2288 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2289 new_bucket_info
.bucket
.oid
.clear();
2291 new_bucket_info
.num_shards
= new_num_shards
;
2292 new_bucket_info
.objv_tracker
.clear();
2294 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2296 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2300 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2302 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2310 #ifdef BUILDING_FOR_EMBEDDED
2311 extern "C" int cephd_rgw_admin(int argc
, const char **argv
)
2313 int main(int argc
, const char **argv
)
2316 vector
<const char*> args
;
2317 argv_to_vec(argc
, (const char **)argv
, args
);
2320 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2321 CODE_ENVIRONMENT_UTILITY
, 0);
2323 // for region -> zonegroup conversion (must happen before common_init_finish())
2324 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2325 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2328 common_init_finish(g_ceph_context
);
2332 std::string access_key
, secret_key
, user_email
, display_name
;
2333 std::string bucket_name
, pool_name
, object
;
2335 std::string date
, subuser
, access
, format
;
2336 std::string start_date
, end_date
;
2337 std::string key_type_str
;
2338 std::string period_id
, period_epoch
, remote
, url
;
2339 std::string master_zonegroup
, master_zone
;
2340 std::string realm_name
, realm_id
, realm_new_name
;
2341 std::string zone_name
, zone_id
, zone_new_name
;
2342 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2343 std::string api_name
;
2344 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2345 list
<string
> endpoints
;
2347 int sync_from_all_specified
= false;
2348 bool sync_from_all
= false;
2349 list
<string
> sync_from
;
2350 list
<string
> sync_from_rm
;
2351 std::string master_url
;
2353 int set_default
= 0;
2354 bool is_master
= false;
2355 bool is_master_set
= false;
2357 bool read_only
= false;
2358 int is_read_only_set
= false;
2360 int staging
= false;
2361 int key_type
= KEY_TYPE_UNDEFINED
;
2363 uint32_t perm_mask
= 0;
2365 int opt_cmd
= OPT_NO_CMD
;
2367 int gen_access_key
= 0;
2368 int gen_secret_key
= 0;
2369 bool set_perm
= false;
2370 bool set_temp_url_key
= false;
2371 map
<int, string
> temp_url_keys
;
2373 Formatter
*formatter
= NULL
;
2374 int purge_data
= false;
2375 int pretty_format
= false;
2376 int show_log_entries
= true;
2377 int show_log_sum
= true;
2378 int skip_zero_entries
= false; // log show
2379 int purge_keys
= false;
2380 int yes_i_really_mean_it
= false;
2381 int delete_child_objects
= false;
2383 int remove_bad
= false;
2384 int check_head_obj_locator
= false;
2385 int max_buckets
= -1;
2386 bool max_buckets_specified
= false;
2387 map
<string
, bool> categories
;
2389 int check_objects
= false;
2390 RGWUserAdminOpState user_op
;
2391 RGWBucketAdminOpState bucket_op
;
2393 string metadata_key
;
2394 RGWObjVersionTracker objv_tracker
;
2396 string start_marker
;
2398 int max_entries
= -1;
2399 bool max_entries_specified
= false;
2401 bool admin_specified
= false;
2403 bool system_specified
= false;
2405 bool specified_shard_id
= false;
2407 bool specified_daemon_id
= false;
2411 string replica_log_type_str
;
2412 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2415 string object_version
;
2416 string placement_id
;
2418 list
<string
> tags_add
;
2419 list
<string
> tags_rm
;
2421 int64_t max_objects
= -1;
2422 int64_t max_size
= -1;
2423 bool have_max_objects
= false;
2424 bool have_max_size
= false;
2425 int include_all
= false;
2427 int sync_stats
= false;
2428 int bypass_gc
= false;
2429 int warnings_only
= false;
2430 int inconsistent_index
= false;
2432 int verbose
= false;
2434 int extra_info
= false;
2436 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2437 uint64_t max_rewrite_size
= ULLONG_MAX
;
2438 uint64_t min_rewrite_stripe_size
= 0;
2440 BIIndexType bi_index_type
= PlainIdx
;
2444 bool num_shards_specified
= false;
2445 int max_concurrent_ios
= 32;
2446 uint64_t orphan_stale_secs
= (24 * 3600);
2449 std::ostringstream errs
;
2453 string source_zone_name
;
2454 string source_zone
; /* zone id */
2457 bool tier_type_specified
= false;
2459 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2460 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2462 boost::optional
<string
> index_pool
;
2463 boost::optional
<string
> data_pool
;
2464 boost::optional
<string
> data_extra_pool
;
2465 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2466 bool index_type_specified
= false;
2468 boost::optional
<std::string
> compression_type
;
2470 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2471 if (ceph_argparse_double_dash(args
, i
)) {
2473 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2476 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2477 user_id
.from_str(val
);
2478 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2480 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2482 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2484 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2486 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2488 user_op
.user_email_specified
=true;
2489 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2491 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2493 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2495 pool
= rgw_pool(pool_name
);
2496 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2498 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2499 object_version
= val
;
2500 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2502 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2504 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2506 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2508 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2510 if (key_type_str
.compare("swift") == 0) {
2511 key_type
= KEY_TYPE_SWIFT
;
2512 } else if (key_type_str
.compare("s3") == 0) {
2513 key_type
= KEY_TYPE_S3
;
2515 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2519 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2521 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2523 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2525 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2527 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2529 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2531 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2532 admin_specified
= true;
2533 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2534 system_specified
= true;
2535 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2537 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2539 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2541 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2542 if (!errs
.str().empty()) {
2543 cerr
<< errs
.str() << std::endl
;
2546 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2547 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2548 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2549 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2550 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2551 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2552 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2553 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2555 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2558 max_buckets_specified
= true;
2559 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2560 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2561 max_entries_specified
= true;
2563 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2566 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2567 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2569 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2572 have_max_size
= true;
2573 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2574 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2576 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2579 have_max_objects
= true;
2580 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2582 if (end_date
.empty())
2584 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2586 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2588 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2589 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2591 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2594 num_shards_specified
= true;
2595 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2596 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2598 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2601 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2602 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2604 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2607 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2608 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2610 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2613 specified_shard_id
= true;
2614 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2616 specified_daemon_id
= true;
2617 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2619 perm_mask
= rgw_str_to_perm(access
.c_str());
2621 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2622 temp_url_keys
[0] = val
;
2623 set_temp_url_key
= true;
2624 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2625 temp_url_keys
[1] = val
;
2626 set_temp_url_key
= true;
2627 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2629 if (bucket_id
.empty()) {
2630 cerr
<< "bad bucket-id" << std::endl
;
2634 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2636 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2637 string cat_str
= val
;
2638 list
<string
> cat_list
;
2639 list
<string
>::iterator iter
;
2640 get_str_list(cat_str
, cat_list
);
2641 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2642 categories
[*iter
] = true;
2644 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2646 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2648 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2649 delete_child_objects
= purge_data
;
2650 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2652 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2654 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2656 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2658 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2660 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2662 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2664 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2666 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2668 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2670 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2672 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2674 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2676 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2678 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2680 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2682 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2684 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2686 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2688 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2689 replica_log_type_str
= val
;
2690 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2691 if (replica_log_type
== ReplicaLog_Invalid
) {
2692 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2695 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2696 string index_type_str
= val
;
2697 bi_index_type
= get_bi_index_type(index_type_str
);
2698 if (bi_index_type
== InvalidIdx
) {
2699 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2702 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2703 is_master
= (bool)is_master_int
;
2704 is_master_set
= true;
2705 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2707 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2708 read_only
= (bool)read_only_int
;
2709 is_read_only_set
= true;
2710 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2712 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2713 master_zonegroup
= val
;
2714 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2716 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2718 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2720 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2722 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2724 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2726 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2727 realm_new_name
= val
;
2728 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2730 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2731 zonegroup_new_name
= val
;
2732 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2734 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2735 get_str_list(val
, tags
);
2736 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2737 get_str_list(val
, tags_add
);
2738 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2739 get_str_list(val
, tags_rm
);
2740 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2742 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2744 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2745 zone_new_name
= val
;
2746 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2747 get_str_list(val
, endpoints
);
2748 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2749 get_str_list(val
, sync_from
);
2750 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2751 get_str_list(val
, sync_from_rm
);
2752 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2753 sync_from_all
= (bool)tmp_int
;
2754 sync_from_all_specified
= true;
2755 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2756 source_zone_name
= val
;
2757 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2759 tier_type_specified
= true;
2760 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2761 parse_tier_config_param(val
, tier_config_add
);
2762 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2763 parse_tier_config_param(val
, tier_config_rm
);
2764 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2766 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2768 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2769 data_extra_pool
= val
;
2770 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2771 if (val
== "normal") {
2772 placement_index_type
= RGWBIType_Normal
;
2773 } else if (val
== "indexless") {
2774 placement_index_type
= RGWBIType_Indexless
;
2776 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2778 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2782 index_type_specified
= true;
2783 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2784 compression_type
= val
;
2785 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2787 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2789 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2790 assume_role_doc
= val
;
2791 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2793 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2794 perm_policy_doc
= val
;
2795 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2797 } else if (strncmp(*i
, "-", 1) == 0) {
2798 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
2810 const char *prev_cmd
= NULL
;
2811 const char *prev_prev_cmd
= NULL
;
2812 std::vector
<const char*>::iterator i
;
2813 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
2814 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
2816 cerr
<< "unrecognized arg " << *i
<< std::endl
;
2824 prev_prev_cmd
= prev_cmd
;
2828 if (opt_cmd
== OPT_NO_CMD
) {
2833 /* some commands may have an optional extra param */
2834 if (i
!= args
.end()) {
2836 case OPT_METADATA_GET
:
2837 case OPT_METADATA_PUT
:
2838 case OPT_METADATA_RM
:
2839 case OPT_METADATA_LIST
:
2847 if (tenant
.empty()) {
2848 tenant
= user_id
.tenant
;
2850 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
2851 && opt_cmd
!= OPT_ROLE_DELETE
2852 && opt_cmd
!= OPT_ROLE_GET
2853 && opt_cmd
!= OPT_ROLE_MODIFY
2854 && opt_cmd
!= OPT_ROLE_LIST
2855 && opt_cmd
!= OPT_ROLE_POLICY_PUT
2856 && opt_cmd
!= OPT_ROLE_POLICY_LIST
2857 && opt_cmd
!= OPT_ROLE_POLICY_GET
2858 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
) {
2859 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
2862 user_id
.tenant
= tenant
;
2864 /* check key parameter conflict */
2865 if ((!access_key
.empty()) && gen_access_key
) {
2866 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
2869 if ((!secret_key
.empty()) && gen_secret_key
) {
2870 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
2875 // default to pretty json
2876 if (format
.empty()) {
2878 pretty_format
= true;
2881 if (format
== "xml")
2882 formatter
= new XMLFormatter(pretty_format
);
2883 else if (format
== "json")
2884 formatter
= new JSONFormatter(pretty_format
);
2886 cerr
<< "unrecognized format: " << format
<< std::endl
;
2891 realm_name
= g_conf
->rgw_realm
;
2892 zone_name
= g_conf
->rgw_zone
;
2893 zonegroup_name
= g_conf
->rgw_zonegroup
;
2895 RGWStreamFlusher
f(formatter
, cout
);
2897 // not a raw op if 'period update' needs to commit to master
2898 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
2899 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
2900 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
2901 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
2902 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
2903 OPT_ZONEGROUP_REMOVE
,
2904 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
2905 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
2906 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
2907 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
2908 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
2909 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
2910 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
2911 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
2913 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
2915 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
2916 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
2917 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
2918 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
2919 OPT_REALM_LIST_PERIODS
,
2920 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
2921 OPT_REALM_RENAME
, OPT_REALM_SET
,
2922 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
2925 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
2928 if (raw_storage_op
) {
2929 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
2931 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false);
2934 cerr
<< "couldn't init storage provider" << std::endl
;
2938 if (!source_zone_name
.empty()) {
2939 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
2940 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
2941 source_zone
= source_zone_name
;
2945 rgw_user_init(store
);
2946 rgw_bucket_init(store
->meta_mgr
);
2948 StoreDestructor
store_destructor(store
);
2950 if (raw_storage_op
) {
2952 case OPT_PERIOD_DELETE
:
2954 if (period_id
.empty()) {
2955 cerr
<< "missing period id" << std::endl
;
2958 RGWPeriod
period(period_id
);
2959 int ret
= period
.init(g_ceph_context
, store
);
2961 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
2964 ret
= period
.delete_obj();
2966 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
2972 case OPT_PERIOD_GET
:
2975 if (!period_epoch
.empty()) {
2976 epoch
= atoi(period_epoch
.c_str());
2979 RGWRealm
realm(realm_id
, realm_name
);
2980 int ret
= realm
.init(g_ceph_context
, store
);
2982 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
2985 realm_id
= realm
.get_id();
2986 realm_name
= realm
.get_name();
2987 period_id
= RGWPeriod::get_staging_id(realm_id
);
2990 RGWPeriod
period(period_id
, epoch
);
2991 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
2993 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
2996 encode_json("period", period
, formatter
);
2997 formatter
->flush(cout
);
3001 case OPT_PERIOD_GET_CURRENT
:
3003 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3007 formatter
->open_object_section("period_get_current");
3008 encode_json("current_period", period_id
, formatter
);
3009 formatter
->close_section();
3010 formatter
->flush(cout
);
3013 case OPT_PERIOD_LIST
:
3015 list
<string
> periods
;
3016 int ret
= store
->list_periods(periods
);
3018 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
3021 formatter
->open_object_section("periods_list");
3022 encode_json("periods", periods
, formatter
);
3023 formatter
->close_section();
3024 formatter
->flush(cout
);
3028 case OPT_PERIOD_UPDATE
:
3030 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
3031 commit
, remote
, url
, access_key
, secret_key
,
3032 formatter
, yes_i_really_mean_it
);
3038 case OPT_PERIOD_PULL
:
3040 boost::optional
<RGWRESTConn
> conn
;
3041 RGWRESTConn
*remote_conn
= nullptr;
3043 // load current period for endpoints
3044 RGWRealm
realm(realm_id
, realm_name
);
3045 int ret
= realm
.init(g_ceph_context
, store
);
3047 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3050 RGWPeriod
current_period(realm
.get_current_period());
3051 ret
= current_period
.init(g_ceph_context
, store
);
3053 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
3056 if (remote
.empty()) {
3057 // use realm master zone as remote
3058 remote
= current_period
.get_master_zone();
3060 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
3062 cerr
<< "failed to find a zone or zonegroup for remote "
3063 << remote
<< std::endl
;
3066 remote_conn
= &*conn
;
3070 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3071 realm_id
, realm_name
, period_id
, period_epoch
,
3074 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3078 encode_json("period", period
, formatter
);
3079 formatter
->flush(cout
);
3083 case OPT_GLOBAL_QUOTA_GET
:
3084 case OPT_GLOBAL_QUOTA_SET
:
3085 case OPT_GLOBAL_QUOTA_ENABLE
:
3086 case OPT_GLOBAL_QUOTA_DISABLE
:
3088 if (realm_id
.empty()) {
3089 RGWRealm
realm(g_ceph_context
, store
);
3090 if (!realm_name
.empty()) {
3091 // look up realm_id for the given realm_name
3092 int ret
= realm
.read_id(realm_name
, realm_id
);
3094 cerr
<< "ERROR: failed to read realm for " << realm_name
3095 << ": " << cpp_strerror(-ret
) << std::endl
;
3099 // use default realm_id when none is given
3100 int ret
= realm
.read_default_id(realm_id
);
3101 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3102 cerr
<< "ERROR: failed to read default realm: "
3103 << cpp_strerror(-ret
) << std::endl
;
3109 RGWPeriodConfig period_config
;
3110 int ret
= period_config
.read(store
, realm_id
);
3111 if (ret
< 0 && ret
!= -ENOENT
) {
3112 cerr
<< "ERROR: failed to read period config: "
3113 << cpp_strerror(-ret
) << std::endl
;
3117 formatter
->open_object_section("period_config");
3118 if (quota_scope
== "bucket") {
3119 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3120 max_size
, max_objects
,
3121 have_max_size
, have_max_objects
);
3122 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3123 } else if (quota_scope
== "user") {
3124 set_quota_info(period_config
.user_quota
, opt_cmd
,
3125 max_size
, max_objects
,
3126 have_max_size
, have_max_objects
);
3127 encode_json("user quota", period_config
.user_quota
, formatter
);
3128 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3129 // if no scope is given for GET, print both
3130 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3131 encode_json("user quota", period_config
.user_quota
, formatter
);
3133 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3134 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3137 formatter
->close_section();
3139 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3140 // write the modified period config
3141 ret
= period_config
.write(store
, realm_id
);
3143 cerr
<< "ERROR: failed to write period config: "
3144 << cpp_strerror(-ret
) << std::endl
;
3147 if (!realm_id
.empty()) {
3148 cout
<< "Global quota changes saved. Use 'period update' to apply "
3149 "them to the staging period, and 'period commit' to commit the "
3150 "new period." << std::endl
;
3152 cout
<< "Global quota changes saved. They will take effect as "
3153 "the gateways are restarted." << std::endl
;
3157 formatter
->flush(cout
);
3161 case OPT_REALM_CREATE
:
3163 if (realm_name
.empty()) {
3164 cerr
<< "missing realm name" << std::endl
;
3168 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3169 int ret
= realm
.create();
3171 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3176 ret
= realm
.set_as_default();
3178 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3182 encode_json("realm", realm
, formatter
);
3183 formatter
->flush(cout
);
3187 case OPT_REALM_DELETE
:
3189 RGWRealm
realm(realm_id
, realm_name
);
3190 if (realm_name
.empty() && realm_id
.empty()) {
3191 cerr
<< "missing realm name or id" << std::endl
;
3194 int ret
= realm
.init(g_ceph_context
, store
);
3196 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3199 ret
= realm
.delete_obj();
3201 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3209 RGWRealm
realm(realm_id
, realm_name
);
3210 int ret
= realm
.init(g_ceph_context
, store
);
3212 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3213 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3215 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3219 encode_json("realm", realm
, formatter
);
3220 formatter
->flush(cout
);
3224 case OPT_REALM_GET_DEFAULT
:
3226 RGWRealm
realm(g_ceph_context
, store
);
3228 int ret
= realm
.read_default_id(default_id
);
3229 if (ret
== -ENOENT
) {
3230 cout
<< "No default realm is set" << std::endl
;
3232 } else if (ret
< 0) {
3233 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3236 cout
<< "default realm: " << default_id
<< std::endl
;
3239 case OPT_REALM_LIST
:
3241 RGWRealm
realm(g_ceph_context
, store
);
3243 int ret
= realm
.read_default_id(default_id
);
3244 if (ret
< 0 && ret
!= -ENOENT
) {
3245 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3247 list
<string
> realms
;
3248 ret
= store
->list_realms(realms
);
3250 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3253 formatter
->open_object_section("realms_list");
3254 encode_json("default_info", default_id
, formatter
);
3255 encode_json("realms", realms
, formatter
);
3256 formatter
->close_section();
3257 formatter
->flush(cout
);
3261 case OPT_REALM_LIST_PERIODS
:
3263 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3267 list
<string
> periods
;
3268 ret
= store
->list_periods(period_id
, periods
);
3270 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3273 formatter
->open_object_section("realm_periods_list");
3274 encode_json("current_period", period_id
, formatter
);
3275 encode_json("periods", periods
, formatter
);
3276 formatter
->close_section();
3277 formatter
->flush(cout
);
3282 case OPT_REALM_RENAME
:
3284 RGWRealm
realm(realm_id
, realm_name
);
3285 if (realm_new_name
.empty()) {
3286 cerr
<< "missing realm new name" << std::endl
;
3289 if (realm_name
.empty() && realm_id
.empty()) {
3290 cerr
<< "missing realm name or id" << std::endl
;
3293 int ret
= realm
.init(g_ceph_context
, store
);
3295 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3298 ret
= realm
.rename(realm_new_name
);
3300 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3303 cout
<< "Realm name updated. Note that this change only applies to "
3304 "the current cluster, so this command must be run separately "
3305 "on each of the realm's other clusters." << std::endl
;
3310 if (realm_id
.empty() && realm_name
.empty()) {
3311 cerr
<< "no realm name or id provided" << std::endl
;
3314 RGWRealm
realm(realm_id
, realm_name
);
3315 bool new_realm
= false;
3316 int ret
= realm
.init(g_ceph_context
, store
);
3317 if (ret
< 0 && ret
!= -ENOENT
) {
3318 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3320 } else if (ret
== -ENOENT
) {
3323 ret
= read_decode_json(infile
, realm
);
3327 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3328 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3329 realm
.get_name() << std::endl
;
3334 cout
<< "clearing period and epoch for new realm" << std::endl
;
3335 realm
.clear_current_period_and_epoch();
3336 ret
= realm
.create();
3338 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3342 ret
= realm
.update();
3344 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3350 ret
= realm
.set_as_default();
3352 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3355 encode_json("realm", realm
, formatter
);
3356 formatter
->flush(cout
);
3360 case OPT_REALM_DEFAULT
:
3362 RGWRealm
realm(realm_id
, realm_name
);
3363 int ret
= realm
.init(g_ceph_context
, store
);
3365 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3368 ret
= realm
.set_as_default();
3370 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3375 case OPT_REALM_PULL
:
3378 cerr
<< "A --url must be provided." << std::endl
;
3382 req_info
info(g_ceph_context
, &env
);
3383 info
.method
= "GET";
3384 info
.request_uri
= "/admin/realm";
3386 map
<string
, string
> ¶ms
= info
.args
.get_params();
3387 if (!realm_id
.empty())
3388 params
["id"] = realm_id
;
3389 if (!realm_name
.empty())
3390 params
["name"] = realm_name
;
3394 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3396 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3397 if (ret
== -EACCES
) {
3398 cerr
<< "If the realm has been changed on the master zone, the "
3399 "master zone's gateway may need to be restarted to recognize "
3400 "this user." << std::endl
;
3405 realm
.init(g_ceph_context
, store
, false);
3407 decode_json_obj(realm
, &p
);
3408 } catch (JSONDecoder::err
& e
) {
3409 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3413 auto& current_period
= realm
.get_current_period();
3414 if (!current_period
.empty()) {
3415 // pull the latest epoch of the realm's current period
3416 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3417 realm_id
, realm_name
, current_period
, "",
3420 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3424 ret
= realm
.create(false);
3425 if (ret
< 0 && ret
!= -EEXIST
) {
3426 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3427 << cpp_strerror(ret
) << std::endl
;
3429 } else if (ret
==-EEXIST
) {
3430 ret
= realm
.update();
3432 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3433 << cpp_strerror(ret
) << std::endl
;
3438 ret
= realm
.set_as_default();
3440 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3444 encode_json("realm", realm
, formatter
);
3445 formatter
->flush(cout
);
3450 case OPT_ZONEGROUP_ADD
:
3452 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3453 cerr
<< "no zonegroup name or id provided" << std::endl
;
3457 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3458 int ret
= zonegroup
.init(g_ceph_context
, store
);
3460 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3461 << cpp_strerror(-ret
) << std::endl
;
3464 RGWZoneParams
zone(zone_id
, zone_name
);
3465 ret
= zone
.init(g_ceph_context
, store
);
3467 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3470 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3471 zone
.realm_id
= zonegroup
.realm_id
;
3472 ret
= zone
.update();
3474 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
3479 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3480 zone
.tier_config
= tier_config_add
;
3482 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3484 ret
= zonegroup
.add_zone(zone
,
3485 (is_master_set
? &is_master
: NULL
),
3486 (is_read_only_set
? &read_only
: NULL
),
3487 endpoints
, ptier_type
,
3488 psync_from_all
, sync_from
, sync_from_rm
);
3490 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3491 << cpp_strerror(-ret
) << std::endl
;
3495 encode_json("zonegroup", zonegroup
, formatter
);
3496 formatter
->flush(cout
);
3499 case OPT_ZONEGROUP_CREATE
:
3501 if (zonegroup_name
.empty()) {
3502 cerr
<< "Missing zonegroup name" << std::endl
;
3505 RGWRealm
realm(realm_id
, realm_name
);
3506 int ret
= realm
.init(g_ceph_context
, store
);
3508 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3512 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3513 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3514 ret
= zonegroup
.create();
3516 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3521 ret
= zonegroup
.set_as_default();
3523 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3527 encode_json("zonegroup", zonegroup
, formatter
);
3528 formatter
->flush(cout
);
3532 case OPT_ZONEGROUP_DEFAULT
:
3534 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3535 cerr
<< "no zonegroup name or id provided" << std::endl
;
3539 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3540 int ret
= zonegroup
.init(g_ceph_context
, store
);
3542 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3546 ret
= zonegroup
.set_as_default();
3548 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3553 case OPT_ZONEGROUP_DELETE
:
3555 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3556 cerr
<< "no zonegroup name or id provided" << std::endl
;
3559 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3560 int ret
= zonegroup
.init(g_ceph_context
, store
);
3562 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3565 ret
= zonegroup
.delete_obj();
3567 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3572 case OPT_ZONEGROUP_GET
:
3574 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3575 int ret
= zonegroup
.init(g_ceph_context
, store
);
3577 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3581 encode_json("zonegroup", zonegroup
, formatter
);
3582 formatter
->flush(cout
);
3586 case OPT_ZONEGROUP_LIST
:
3588 RGWZoneGroup zonegroup
;
3589 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3591 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3595 list
<string
> zonegroups
;
3596 ret
= store
->list_zonegroups(zonegroups
);
3598 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3601 string default_zonegroup
;
3602 ret
= zonegroup
.read_default_id(default_zonegroup
);
3603 if (ret
< 0 && ret
!= -ENOENT
) {
3604 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3606 formatter
->open_object_section("zonegroups_list");
3607 encode_json("default_info", default_zonegroup
, formatter
);
3608 encode_json("zonegroups", zonegroups
, formatter
);
3609 formatter
->close_section();
3610 formatter
->flush(cout
);
3614 case OPT_ZONEGROUP_MODIFY
:
3616 RGWRealm
realm(realm_id
, realm_name
);
3617 int ret
= realm
.init(g_ceph_context
, store
);
3619 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3623 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3624 ret
= zonegroup
.init(g_ceph_context
, store
);
3626 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3630 bool need_update
= false;
3632 if (!master_zone
.empty()) {
3633 zonegroup
.master_zone
= master_zone
;
3637 if (is_master_set
) {
3638 zonegroup
.update_master(is_master
);
3642 if (!endpoints
.empty()) {
3643 zonegroup
.endpoints
= endpoints
;
3647 if (!api_name
.empty()) {
3648 zonegroup
.api_name
= api_name
;
3652 if (!realm_id
.empty()) {
3653 zonegroup
.realm_id
= realm_id
;
3655 } else if (!realm_name
.empty()) {
3656 // get realm id from name
3657 RGWRealm realm
{g_ceph_context
, store
};
3658 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3660 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3667 ret
= zonegroup
.update();
3669 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3675 ret
= zonegroup
.set_as_default();
3677 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3681 encode_json("zonegroup", zonegroup
, formatter
);
3682 formatter
->flush(cout
);
3685 case OPT_ZONEGROUP_SET
:
3687 RGWRealm
realm(realm_id
, realm_name
);
3688 int ret
= realm
.init(g_ceph_context
, store
);
3690 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3694 RGWZoneGroup zonegroup
;
3695 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3697 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3700 ret
= read_decode_json(infile
, zonegroup
);
3704 if (zonegroup
.realm_id
.empty()) {
3705 zonegroup
.realm_id
= realm
.get_id();
3707 ret
= zonegroup
.create();
3708 if (ret
< 0 && ret
!= -EEXIST
) {
3709 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3711 } else if (ret
== -EEXIST
) {
3712 ret
= zonegroup
.update();
3714 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3720 ret
= zonegroup
.set_as_default();
3722 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3726 encode_json("zonegroup", zonegroup
, formatter
);
3727 formatter
->flush(cout
);
3730 case OPT_ZONEGROUP_REMOVE
:
3732 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3733 int ret
= zonegroup
.init(g_ceph_context
, store
);
3735 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3739 if (zone_id
.empty()) {
3740 if (zone_name
.empty()) {
3741 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
3744 // look up zone id by name
3745 for (auto& z
: zonegroup
.zones
) {
3746 if (zone_name
== z
.second
.name
) {
3747 zone_id
= z
.second
.id
;
3751 if (zone_id
.empty()) {
3752 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
3753 << zonegroup
.get_name() << std::endl
;
3758 ret
= zonegroup
.remove_zone(zone_id
);
3760 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
3764 encode_json("zonegroup", zonegroup
, formatter
);
3765 formatter
->flush(cout
);
3768 case OPT_ZONEGROUP_RENAME
:
3770 if (zonegroup_new_name
.empty()) {
3771 cerr
<< " missing zonegroup new name" << std::endl
;
3774 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3775 cerr
<< "no zonegroup name or id provided" << std::endl
;
3778 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3779 int ret
= zonegroup
.init(g_ceph_context
, store
);
3781 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3784 ret
= zonegroup
.rename(zonegroup_new_name
);
3786 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3791 case OPT_ZONEGROUP_PLACEMENT_LIST
:
3793 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3794 int ret
= zonegroup
.init(g_ceph_context
, store
);
3796 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3800 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3801 formatter
->flush(cout
);
3805 case OPT_ZONEGROUP_PLACEMENT_ADD
:
3806 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
3807 case OPT_ZONEGROUP_PLACEMENT_RM
:
3808 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
3810 if (placement_id
.empty()) {
3811 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
3815 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3816 int ret
= zonegroup
.init(g_ceph_context
, store
);
3818 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3822 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
3823 RGWZoneGroupPlacementTarget target
;
3824 target
.name
= placement_id
;
3825 for (auto& t
: tags
) {
3826 target
.tags
.insert(t
);
3828 zonegroup
.placement_targets
[placement_id
] = target
;
3829 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
3830 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
3831 if (!tags
.empty()) {
3832 target
.tags
.clear();
3833 for (auto& t
: tags
) {
3834 target
.tags
.insert(t
);
3837 target
.name
= placement_id
;
3838 for (auto& t
: tags_rm
) {
3839 target
.tags
.erase(t
);
3841 for (auto& t
: tags_add
) {
3842 target
.tags
.insert(t
);
3844 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
3845 zonegroup
.placement_targets
.erase(placement_id
);
3846 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
3847 if (!zonegroup
.placement_targets
.count(placement_id
)) {
3848 cerr
<< "failed to find a zonegroup placement target named '"
3849 << placement_id
<< "'" << std::endl
;
3852 zonegroup
.default_placement
= placement_id
;
3855 zonegroup
.post_process_params();
3856 ret
= zonegroup
.update();
3858 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3862 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3863 formatter
->flush(cout
);
3866 case OPT_ZONE_CREATE
:
3868 if (zone_name
.empty()) {
3869 cerr
<< "zone name not provided" << std::endl
;
3873 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3874 /* if the user didn't provide zonegroup info , create stand alone zone */
3875 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3876 ret
= zonegroup
.init(g_ceph_context
, store
);
3878 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3881 if (realm_id
.empty() && realm_name
.empty()) {
3882 realm_id
= zonegroup
.realm_id
;
3886 RGWZoneParams
zone(zone_id
, zone_name
);
3887 ret
= zone
.init(g_ceph_context
, store
, false);
3889 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3893 zone
.system_key
.id
= access_key
;
3894 zone
.system_key
.key
= secret_key
;
3895 zone
.realm_id
= realm_id
;
3896 zone
.tier_config
= tier_config_add
;
3898 ret
= zone
.create();
3900 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3904 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3905 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3906 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3907 ret
= zonegroup
.add_zone(zone
,
3908 (is_master_set
? &is_master
: NULL
),
3909 (is_read_only_set
? &read_only
: NULL
),
3913 sync_from
, sync_from_rm
);
3915 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
3916 << ": " << cpp_strerror(-ret
) << std::endl
;
3922 ret
= zone
.set_as_default();
3924 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3928 encode_json("zone", zone
, formatter
);
3929 formatter
->flush(cout
);
3933 case OPT_ZONE_DEFAULT
:
3935 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3936 int ret
= zonegroup
.init(g_ceph_context
, store
);
3938 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3940 if (zone_id
.empty() && zone_name
.empty()) {
3941 cerr
<< "no zone name or id provided" << std::endl
;
3944 RGWZoneParams
zone(zone_id
, zone_name
);
3945 ret
= zone
.init(g_ceph_context
, store
);
3947 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3950 ret
= zone
.set_as_default();
3952 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
3957 case OPT_ZONE_DELETE
:
3959 if (zone_id
.empty() && zone_name
.empty()) {
3960 cerr
<< "no zone name or id provided" << std::endl
;
3963 RGWZoneParams
zone(zone_id
, zone_name
);
3964 int ret
= zone
.init(g_ceph_context
, store
);
3966 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3970 list
<string
> zonegroups
;
3971 ret
= store
->list_zonegroups(zonegroups
);
3973 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3977 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
3978 RGWZoneGroup
zonegroup(string(), *iter
);
3979 int ret
= zonegroup
.init(g_ceph_context
, store
);
3981 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3984 ret
= zonegroup
.remove_zone(zone
.get_id());
3985 if (ret
< 0 && ret
!= -ENOENT
) {
3986 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
3987 << cpp_strerror(-ret
) << std::endl
;
3991 ret
= zone
.delete_obj();
3993 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4000 RGWZoneParams
zone(zone_id
, zone_name
);
4001 int ret
= zone
.init(g_ceph_context
, store
);
4003 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4006 encode_json("zone", zone
, formatter
);
4007 formatter
->flush(cout
);
4012 RGWZoneParams
zone(zone_name
);
4013 int ret
= zone
.init(g_ceph_context
, store
, false);
4019 if (ret
< 0 && ret
!= -ENOENT
) {
4020 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
4024 string orig_id
= zone
.get_id();
4026 ret
= read_decode_json(infile
, zone
);
4031 if(zone
.realm_id
.empty()) {
4032 RGWRealm
realm(realm_id
, realm_name
);
4033 int ret
= realm
.init(g_ceph_context
, store
);
4034 if (ret
< 0 && ret
!= -ENOENT
) {
4035 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4038 zone
.realm_id
= realm
.get_id();
4041 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
4042 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
4046 if (zone
.get_name().empty()) {
4047 zone
.set_name(zone_name
);
4048 if (zone
.get_name().empty()) {
4049 cerr
<< "no zone name specified" << std::endl
;
4054 zone_name
= zone
.get_name();
4056 if (zone
.get_id().empty()) {
4057 zone
.set_id(orig_id
);
4060 if (zone
.get_id().empty()) {
4061 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
4062 if (zone_name
.empty()) {
4063 cerr
<< "missing zone name" << std::endl
;
4066 zone
.set_name(zone_name
);
4067 zone
.set_id(zone_name
);
4070 cerr
<< "zone id " << zone
.get_id();
4071 ret
= zone
.fix_pool_names();
4073 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4076 ret
= zone
.write(false);
4078 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4083 ret
= zone
.set_as_default();
4085 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4089 encode_json("zone", zone
, formatter
);
4090 formatter
->flush(cout
);
4096 int ret
= store
->list_zones(zones
);
4098 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4103 ret
= zone
.init(g_ceph_context
, store
, false);
4105 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4108 string default_zone
;
4109 ret
= zone
.read_default_id(default_zone
);
4110 if (ret
< 0 && ret
!= -ENOENT
) {
4111 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4113 formatter
->open_object_section("zones_list");
4114 encode_json("default_info", default_zone
, formatter
);
4115 encode_json("zones", zones
, formatter
);
4116 formatter
->close_section();
4117 formatter
->flush(cout
);
4121 case OPT_ZONE_MODIFY
:
4123 RGWZoneParams
zone(zone_id
, zone_name
);
4124 int ret
= zone
.init(g_ceph_context
, store
);
4126 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4130 bool need_zone_update
= false;
4131 if (!access_key
.empty()) {
4132 zone
.system_key
.id
= access_key
;
4133 need_zone_update
= true;
4136 if (!secret_key
.empty()) {
4137 zone
.system_key
.key
= secret_key
;
4138 need_zone_update
= true;
4141 if (!realm_id
.empty()) {
4142 zone
.realm_id
= realm_id
;
4143 need_zone_update
= true;
4144 } else if (!realm_name
.empty()) {
4145 // get realm id from name
4146 RGWRealm realm
{g_ceph_context
, store
};
4147 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4149 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4152 need_zone_update
= true;
4155 for (auto add
: tier_config_add
) {
4156 zone
.tier_config
[add
.first
] = add
.second
;
4157 need_zone_update
= true;
4160 for (auto rm
: tier_config_rm
) {
4161 zone
.tier_config
.erase(rm
.first
);
4162 need_zone_update
= true;
4165 if (need_zone_update
) {
4166 ret
= zone
.update();
4168 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4173 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4174 ret
= zonegroup
.init(g_ceph_context
, store
);
4176 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4179 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4181 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4183 ret
= zonegroup
.add_zone(zone
,
4184 (is_master_set
? &is_master
: NULL
),
4185 (is_read_only_set
? &read_only
: NULL
),
4186 endpoints
, ptier_type
,
4187 psync_from_all
, sync_from
, sync_from_rm
);
4189 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4193 ret
= zonegroup
.update();
4195 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4200 ret
= zone
.set_as_default();
4202 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4206 encode_json("zone", zone
, formatter
);
4207 formatter
->flush(cout
);
4210 case OPT_ZONE_RENAME
:
4212 if (zone_new_name
.empty()) {
4213 cerr
<< " missing zone new name" << std::endl
;
4216 if (zone_id
.empty() && zone_name
.empty()) {
4217 cerr
<< "no zonegroup name or id provided" << std::endl
;
4220 RGWZoneParams
zone(zone_id
,zone_name
);
4221 int ret
= zone
.init(g_ceph_context
, store
);
4223 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4226 ret
= zone
.rename(zone_new_name
);
4228 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4232 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4233 ret
= zonegroup
.init(g_ceph_context
, store
);
4235 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4237 ret
= zonegroup
.rename_zone(zone
);
4238 if (ret
< 0 && ret
) {
4239 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4245 case OPT_ZONE_PLACEMENT_ADD
:
4246 case OPT_ZONE_PLACEMENT_MODIFY
:
4247 case OPT_ZONE_PLACEMENT_RM
:
4249 if (placement_id
.empty()) {
4250 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4253 RGWZoneParams
zone(zone_id
, zone_name
);
4254 int ret
= zone
.init(g_ceph_context
, store
);
4256 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4260 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4261 // pool names are required
4262 if (!index_pool
|| index_pool
->empty() ||
4263 !data_pool
|| data_pool
->empty()) {
4264 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4268 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4270 info
.index_pool
= *index_pool
;
4271 info
.data_pool
= *data_pool
;
4272 if (data_extra_pool
) {
4273 info
.data_extra_pool
= *data_extra_pool
;
4275 if (index_type_specified
) {
4276 info
.index_type
= placement_index_type
;
4278 if (compression_type
) {
4279 info
.compression_type
= *compression_type
;
4281 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4282 auto p
= zone
.placement_pools
.find(placement_id
);
4283 if (p
== zone
.placement_pools
.end()) {
4284 cerr
<< "ERROR: zone placement target '" << placement_id
4285 << "' not found" << std::endl
;
4288 auto& info
= p
->second
;
4289 if (index_pool
&& !index_pool
->empty()) {
4290 info
.index_pool
= *index_pool
;
4292 if (data_pool
&& !data_pool
->empty()) {
4293 info
.data_pool
= *data_pool
;
4295 if (data_extra_pool
) {
4296 info
.data_extra_pool
= *data_extra_pool
;
4298 if (index_type_specified
) {
4299 info
.index_type
= placement_index_type
;
4301 if (compression_type
) {
4302 info
.compression_type
= *compression_type
;
4304 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4305 zone
.placement_pools
.erase(placement_id
);
4308 ret
= zone
.update();
4310 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4314 encode_json("zone", zone
, formatter
);
4315 formatter
->flush(cout
);
4318 case OPT_ZONE_PLACEMENT_LIST
:
4320 RGWZoneParams
zone(zone_id
, zone_name
);
4321 int ret
= zone
.init(g_ceph_context
, store
);
4323 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4326 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4327 formatter
->flush(cout
);
4334 if (!user_id
.empty()) {
4335 user_op
.set_user_id(user_id
);
4336 bucket_op
.set_user_id(user_id
);
4339 if (!display_name
.empty())
4340 user_op
.set_display_name(display_name
);
4342 if (!user_email
.empty())
4343 user_op
.set_user_email(user_email
);
4345 if (!access_key
.empty())
4346 user_op
.set_access_key(access_key
);
4348 if (!secret_key
.empty())
4349 user_op
.set_secret_key(secret_key
);
4351 if (!subuser
.empty())
4352 user_op
.set_subuser(subuser
);
4355 user_op
.set_caps(caps
);
4357 user_op
.set_purge_data(purge_data
);
4360 user_op
.set_purge_keys();
4363 user_op
.set_generate_key();
4366 user_op
.set_gen_secret(); // assume that a key pair should be created
4368 if (max_buckets_specified
)
4369 user_op
.set_max_buckets(max_buckets
);
4371 if (admin_specified
)
4372 user_op
.set_admin(admin
);
4374 if (system_specified
)
4375 user_op
.set_system(system
);
4378 user_op
.set_perm(perm_mask
);
4380 if (set_temp_url_key
) {
4381 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4382 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4383 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4387 if (!op_mask_str
.empty()) {
4389 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4391 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4395 user_op
.set_op_mask(op_mask
);
4398 if (key_type
!= KEY_TYPE_UNDEFINED
)
4399 user_op
.set_key_type(key_type
);
4401 // set suspension operation parameters
4402 if (opt_cmd
== OPT_USER_ENABLE
)
4403 user_op
.set_suspension(false);
4404 else if (opt_cmd
== OPT_USER_SUSPEND
)
4405 user_op
.set_suspension(true);
4407 // RGWUser to use for user operations
4410 if (!user_id
.empty() || !subuser
.empty()) {
4411 ret
= user
.init(store
, user_op
);
4413 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4418 /* populate bucket operation */
4419 bucket_op
.set_bucket_name(bucket_name
);
4420 bucket_op
.set_object(object
);
4421 bucket_op
.set_check_objects(check_objects
);
4422 bucket_op
.set_delete_children(delete_child_objects
);
4423 bucket_op
.set_fix_index(fix
);
4424 bucket_op
.set_max_aio(max_concurrent_ios
);
4426 // required to gather errors from operations
4427 std::string err_msg
;
4429 bool output_user_info
= true;
4434 case OPT_USER_CREATE
:
4435 if (!user_op
.has_existing_user()) {
4436 user_op
.set_generate_key(); // generate a new key by default
4438 ret
= user
.add(user_op
, &err_msg
);
4440 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4441 if (ret
== -ERR_INVALID_TENANT_NAME
)
4446 if (!subuser
.empty()) {
4447 ret
= user
.subusers
.add(user_op
, &err_msg
);
4449 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4455 ret
= user
.remove(user_op
, &err_msg
);
4457 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4461 output_user_info
= false;
4463 case OPT_USER_ENABLE
:
4464 case OPT_USER_SUSPEND
:
4465 case OPT_USER_MODIFY
:
4466 ret
= user
.modify(user_op
, &err_msg
);
4468 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4473 case OPT_SUBUSER_CREATE
:
4474 ret
= user
.subusers
.add(user_op
, &err_msg
);
4476 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4481 case OPT_SUBUSER_MODIFY
:
4482 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4484 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4489 case OPT_SUBUSER_RM
:
4490 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4492 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4498 ret
= user
.caps
.add(user_op
, &err_msg
);
4500 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4506 ret
= user
.caps
.remove(user_op
, &err_msg
);
4508 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4513 case OPT_KEY_CREATE
:
4514 ret
= user
.keys
.add(user_op
, &err_msg
);
4516 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4522 ret
= user
.keys
.remove(user_op
, &err_msg
);
4524 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4528 case OPT_PERIOD_PUSH
:
4531 req_info
info(g_ceph_context
, &env
);
4532 info
.method
= "POST";
4533 info
.request_uri
= "/admin/realm/period";
4535 map
<string
, string
> ¶ms
= info
.args
.get_params();
4536 if (!realm_id
.empty())
4537 params
["realm_id"] = realm_id
;
4538 if (!realm_name
.empty())
4539 params
["realm_name"] = realm_name
;
4540 if (!period_id
.empty())
4541 params
["period_id"] = period_id
;
4542 if (!period_epoch
.empty())
4543 params
["epoch"] = period_epoch
;
4546 RGWPeriod
period(period_id
);
4547 int ret
= period
.init(g_ceph_context
, store
);
4549 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4552 // json format into a bufferlist
4553 JSONFormatter
jf(false);
4554 encode_json("period", period
, &jf
);
4559 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4562 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4567 case OPT_PERIOD_UPDATE
:
4569 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4570 commit
, remote
, url
, access_key
, secret_key
,
4571 formatter
, yes_i_really_mean_it
);
4577 case OPT_PERIOD_COMMIT
:
4579 // read realm and staging period
4580 RGWRealm
realm(realm_id
, realm_name
);
4581 int ret
= realm
.init(g_ceph_context
, store
);
4583 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4586 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4587 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4589 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4592 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4593 yes_i_really_mean_it
);
4595 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4599 encode_json("period", period
, formatter
);
4600 formatter
->flush(cout
);
4604 case OPT_ROLE_CREATE
:
4606 if (role_name
.empty()) {
4607 cerr
<< "ERROR: role name is empty" << std::endl
;
4611 if (assume_role_doc
.empty()) {
4612 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4615 /* The following two calls will be replaced by read_decode_json or something
4616 similar when the code for AWS Policies is in places */
4618 int ret
= read_input(assume_role_doc
, bl
);
4620 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4624 if (!p
.parse(bl
.c_str(), bl
.length())) {
4625 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4628 string trust_policy
= bl
.to_str();
4629 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4630 ret
= role
.create(true);
4634 show_role_info(role
, formatter
);
4637 case OPT_ROLE_DELETE
:
4639 if (role_name
.empty()) {
4640 cerr
<< "ERROR: empty role name" << std::endl
;
4643 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4644 ret
= role
.delete_obj();
4648 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4653 if (role_name
.empty()) {
4654 cerr
<< "ERROR: empty role name" << std::endl
;
4657 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4662 show_role_info(role
, formatter
);
4665 case OPT_ROLE_MODIFY
:
4667 if (role_name
.empty()) {
4668 cerr
<< "ERROR: role name is empty" << std::endl
;
4672 if (assume_role_doc
.empty()) {
4673 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4677 /* The following two calls will be replaced by read_decode_json or something
4678 similar when the code for AWS Policies is in place */
4680 int ret
= read_input(assume_role_doc
, bl
);
4682 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4686 if (!p
.parse(bl
.c_str(), bl
.length())) {
4687 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4690 string trust_policy
= bl
.to_str();
4691 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4696 role
.update_trust_policy(trust_policy
);
4697 ret
= role
.update();
4701 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4706 vector
<RGWRole
> result
;
4707 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4711 show_roles_info(result
, formatter
);
4714 case OPT_ROLE_POLICY_PUT
:
4716 if (role_name
.empty()) {
4717 cerr
<< "role name is empty" << std::endl
;
4721 if (policy_name
.empty()) {
4722 cerr
<< "policy name is empty" << std::endl
;
4726 if (perm_policy_doc
.empty()) {
4727 cerr
<< "permission policy document is empty" << std::endl
;
4731 /* The following two calls will be replaced by read_decode_json or something
4732 similar, when code for AWS Policies is in place.*/
4734 int ret
= read_input(perm_policy_doc
, bl
);
4736 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4740 if (!p
.parse(bl
.c_str(), bl
.length())) {
4741 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
4745 perm_policy
= bl
.c_str();
4747 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4752 role
.set_perm_policy(policy_name
, perm_policy
);
4753 ret
= role
.update();
4757 cout
<< "Permission policy attached successfully" << std::endl
;
4760 case OPT_ROLE_POLICY_LIST
:
4762 if (role_name
.empty()) {
4763 cerr
<< "ERROR: Role name is empty" << std::endl
;
4766 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4771 std::vector
<string
> policy_names
= role
.get_role_policy_names();
4772 show_policy_names(policy_names
, formatter
);
4775 case OPT_ROLE_POLICY_GET
:
4777 if (role_name
.empty()) {
4778 cerr
<< "ERROR: role name is empty" << std::endl
;
4782 if (policy_name
.empty()) {
4783 cerr
<< "ERROR: policy name is empty" << std::endl
;
4786 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4787 int ret
= role
.get();
4792 ret
= role
.get_role_policy(policy_name
, perm_policy
);
4796 show_perm_policy(perm_policy
, formatter
);
4799 case OPT_ROLE_POLICY_DELETE
:
4801 if (role_name
.empty()) {
4802 cerr
<< "ERROR: role name is empty" << std::endl
;
4806 if (policy_name
.empty()) {
4807 cerr
<< "ERROR: policy name is empty" << std::endl
;
4810 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4815 ret
= role
.delete_policy(policy_name
);
4819 ret
= role
.update();
4823 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
4824 << role_name
<< std::endl
;
4828 output_user_info
= false;
4831 // output the result of a user operation
4832 if (output_user_info
) {
4833 ret
= user
.info(info
, &err_msg
);
4835 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
4838 show_user_info(info
, formatter
);
4841 if (opt_cmd
== OPT_POLICY
) {
4842 if (format
== "xml") {
4843 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
4845 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4849 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
4851 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4857 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
4859 std::list
<std::string
> user_ids
;
4860 metadata_key
= "user";
4865 if (! user_id
.empty()) {
4866 user_ids
.push_back(user_id
.id
);
4868 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4871 /* list users in groups of max-keys, then perform user-bucket
4872 * limit-check on each group */
4873 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
4875 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
4876 << cpp_strerror(-ret
) << std::endl
;
4881 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
4883 if (ret
< 0 && ret
!= -ENOENT
) {
4884 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
4885 << cpp_strerror(-ret
) << std::endl
;
4888 /* ok, do the limit checks for this group */
4890 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4896 } while (truncated
);
4897 store
->meta_mgr
->list_keys_complete(handle
);
4900 } /* OPT_BUCKET_LIMIT_CHECK */
4902 if (opt_cmd
== OPT_BUCKETS_LIST
) {
4903 if (bucket_name
.empty()) {
4904 RGWBucketAdminOp::info(store
, bucket_op
, f
);
4906 RGWBucketInfo bucket_info
;
4907 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
4909 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
4912 formatter
->open_array_section("entries");
4915 if (max_entries
< 0)
4920 vector
<rgw_bucket_dir_entry
> result
;
4921 map
<string
, bool> common_prefixes
;
4924 RGWRados::Bucket
target(store
, bucket_info
);
4925 RGWRados::Bucket::List
list_op(&target
);
4927 list_op
.params
.prefix
= prefix
;
4928 list_op
.params
.delim
= delim
;
4929 list_op
.params
.marker
= rgw_obj_key(marker
);
4930 list_op
.params
.ns
= ns
;
4931 list_op
.params
.enforce_ns
= false;
4932 list_op
.params
.list_versions
= true;
4935 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
4937 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
4941 count
+= result
.size();
4943 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
4944 rgw_bucket_dir_entry
& entry
= *iter
;
4945 encode_json("entry", entry
, formatter
);
4947 formatter
->flush(cout
);
4948 } while (truncated
&& count
< max_entries
);
4950 formatter
->close_section();
4951 formatter
->flush(cout
);
4952 } /* have bucket_name */
4953 } /* OPT_BUCKETS_LIST */
4955 if (opt_cmd
== OPT_BUCKET_STATS
) {
4956 bucket_op
.set_fetch_stats(true);
4958 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
4960 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4965 if (opt_cmd
== OPT_BUCKET_LINK
) {
4966 bucket_op
.set_bucket_id(bucket_id
);
4968 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
4970 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4975 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
4976 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
4978 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
4983 if (opt_cmd
== OPT_LOG_LIST
) {
4985 if (date
.size() && date
.size() != 10) {
4986 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
4991 formatter
->open_array_section("logs");
4993 int r
= store
->log_list_init(date
, &h
);
4998 cerr
<< "log list: error " << r
<< std::endl
;
5003 int r
= store
->log_list_next(h
, &name
);
5007 cerr
<< "log list: error " << r
<< std::endl
;
5010 formatter
->dump_string("object", name
);
5013 formatter
->close_section();
5014 formatter
->flush(cout
);
5018 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5019 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5020 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5026 if (!object
.empty()) {
5036 if (opt_cmd
== OPT_LOG_SHOW
) {
5039 int r
= store
->log_show_init(oid
, &h
);
5041 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5046 formatter
->open_object_section("log");
5048 struct rgw_log_entry entry
;
5050 // peek at first entry to get bucket metadata
5051 r
= store
->log_show_next(h
, &entry
);
5053 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5056 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5057 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5058 formatter
->dump_string("bucket", entry
.bucket
);
5060 uint64_t agg_time
= 0;
5061 uint64_t agg_bytes_sent
= 0;
5062 uint64_t agg_bytes_received
= 0;
5063 uint64_t total_entries
= 0;
5065 if (show_log_entries
)
5066 formatter
->open_array_section("log_entries");
5069 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5071 agg_time
+= total_time
;
5072 agg_bytes_sent
+= entry
.bytes_sent
;
5073 agg_bytes_received
+= entry
.bytes_received
;
5076 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5077 entry
.bytes_received
== 0)
5080 if (show_log_entries
) {
5082 rgw_format_ops_log_entry(entry
, formatter
);
5083 formatter
->flush(cout
);
5086 r
= store
->log_show_next(h
, &entry
);
5090 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5093 if (show_log_entries
)
5094 formatter
->close_section();
5097 formatter
->open_object_section("log_sum");
5098 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5099 formatter
->dump_int("bytes_received", agg_bytes_received
);
5100 formatter
->dump_int("total_time", agg_time
);
5101 formatter
->dump_int("total_entries", total_entries
);
5102 formatter
->close_section();
5104 formatter
->close_section();
5105 formatter
->flush(cout
);
5108 if (opt_cmd
== OPT_LOG_RM
) {
5109 int r
= store
->log_remove(oid
);
5111 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5117 if (opt_cmd
== OPT_POOL_ADD
) {
5118 if (pool_name
.empty()) {
5119 cerr
<< "need to specify pool to add!" << std::endl
;
5124 int ret
= store
->add_bucket_placement(pool
);
5126 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5129 if (opt_cmd
== OPT_POOL_RM
) {
5130 if (pool_name
.empty()) {
5131 cerr
<< "need to specify pool to remove!" << std::endl
;
5136 int ret
= store
->remove_bucket_placement(pool
);
5138 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5141 if (opt_cmd
== OPT_POOLS_LIST
) {
5142 set
<rgw_pool
> pools
;
5143 int ret
= store
->list_placement_set(pools
);
5145 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5149 formatter
->open_array_section("pools");
5150 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5151 formatter
->open_object_section("pool");
5152 formatter
->dump_string("name", siter
->to_str());
5153 formatter
->close_section();
5155 formatter
->close_section();
5156 formatter
->flush(cout
);
5160 if (opt_cmd
== OPT_USAGE_SHOW
) {
5161 uint64_t start_epoch
= 0;
5162 uint64_t end_epoch
= (uint64_t)-1;
5166 if (!start_date
.empty()) {
5167 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5169 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5173 if (!end_date
.empty()) {
5174 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5176 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5182 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5183 show_log_entries
, show_log_sum
, &categories
,
5186 cerr
<< "ERROR: failed to show usage" << std::endl
;
5191 if (opt_cmd
== OPT_USAGE_TRIM
) {
5192 if (user_id
.empty() && !yes_i_really_mean_it
) {
5193 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5194 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5198 uint64_t start_epoch
= 0;
5199 uint64_t end_epoch
= (uint64_t)-1;
5202 if (!start_date
.empty()) {
5203 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5205 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5210 if (!end_date
.empty()) {
5211 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5213 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5218 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5220 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5225 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5226 if (bucket_name
.empty()) {
5227 cerr
<< "ERROR: bucket not specified" << std::endl
;
5230 if (object
.empty()) {
5231 cerr
<< "ERROR: object not specified" << std::endl
;
5236 if (opt_cmd
== OPT_OLH_GET
) {
5237 RGWBucketInfo bucket_info
;
5238 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5240 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5244 rgw_obj
obj(bucket
, object
);
5245 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5247 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5250 encode_json("olh", olh
, formatter
);
5251 formatter
->flush(cout
);
5254 if (opt_cmd
== OPT_OLH_READLOG
) {
5255 RGWBucketInfo bucket_info
;
5256 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5258 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5261 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5264 RGWObjectCtx
rctx(store
);
5265 rgw_obj
obj(bucket
, object
);
5269 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5274 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5276 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5279 formatter
->open_object_section("result");
5280 encode_json("is_truncated", is_truncated
, formatter
);
5281 encode_json("log", log
, formatter
);
5282 formatter
->close_section();
5283 formatter
->flush(cout
);
5286 if (opt_cmd
== OPT_BI_GET
) {
5287 RGWBucketInfo bucket_info
;
5288 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5290 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5293 rgw_obj
obj(bucket
, object
);
5294 if (!object_version
.empty()) {
5295 obj
.key
.set_instance(object_version
);
5298 rgw_cls_bi_entry entry
;
5300 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5302 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5306 encode_json("entry", entry
, formatter
);
5307 formatter
->flush(cout
);
5310 if (opt_cmd
== OPT_BI_PUT
) {
5311 RGWBucketInfo bucket_info
;
5312 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5314 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5318 rgw_cls_bi_entry entry
;
5319 cls_rgw_obj_key key
;
5320 ret
= read_decode_json(infile
, entry
, &key
);
5325 rgw_obj
obj(bucket
, key
);
5327 ret
= store
->bi_put(bucket
, obj
, entry
);
5329 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5334 if (opt_cmd
== OPT_BI_LIST
) {
5335 if (bucket_name
.empty()) {
5336 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5339 RGWBucketInfo bucket_info
;
5340 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5342 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5346 list
<rgw_cls_bi_entry
> entries
;
5348 if (max_entries
< 0) {
5352 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5354 formatter
->open_array_section("entries");
5356 for (int i
= 0; i
< max_shards
; i
++) {
5357 RGWRados::BucketShard
bs(store
);
5358 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5359 int ret
= bs
.init(bucket
, shard_id
);
5363 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5369 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5371 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5375 list
<rgw_cls_bi_entry
>::iterator iter
;
5376 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5377 rgw_cls_bi_entry
& entry
= *iter
;
5378 encode_json("entry", entry
, formatter
);
5381 formatter
->flush(cout
);
5382 } while (is_truncated
);
5383 formatter
->flush(cout
);
5385 formatter
->close_section();
5386 formatter
->flush(cout
);
5389 if (opt_cmd
== OPT_BI_PURGE
) {
5390 if (bucket_name
.empty()) {
5391 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5394 RGWBucketInfo bucket_info
;
5395 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5397 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5401 RGWBucketInfo cur_bucket_info
;
5402 rgw_bucket cur_bucket
;
5403 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5405 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5409 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5410 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5411 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5415 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5417 for (int i
= 0; i
< max_shards
; i
++) {
5418 RGWRados::BucketShard
bs(store
);
5419 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5420 int ret
= bs
.init(bucket
, shard_id
);
5422 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5426 ret
= store
->bi_remove(bs
);
5428 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5434 if (opt_cmd
== OPT_OBJECT_RM
) {
5435 RGWBucketInfo bucket_info
;
5436 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5438 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5441 rgw_obj_key
key(object
, object_version
);
5442 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5445 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5450 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5451 if (bucket_name
.empty()) {
5452 cerr
<< "ERROR: bucket not specified" << std::endl
;
5455 if (object
.empty()) {
5456 cerr
<< "ERROR: object not specified" << std::endl
;
5460 RGWBucketInfo bucket_info
;
5461 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5463 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5467 rgw_obj
obj(bucket
, object
);
5468 obj
.key
.set_instance(object_version
);
5469 bool need_rewrite
= true;
5470 if (min_rewrite_stripe_size
> 0) {
5471 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5473 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5477 ret
= store
->rewrite_obj(bucket_info
, obj
);
5479 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5483 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5487 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5488 int ret
= store
->process_expire_objects();
5490 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5495 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5496 if (bucket_name
.empty()) {
5497 cerr
<< "ERROR: bucket not specified" << std::endl
;
5501 RGWBucketInfo bucket_info
;
5502 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5504 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5508 uint64_t start_epoch
= 0;
5509 uint64_t end_epoch
= 0;
5511 if (!end_date
.empty()) {
5512 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5514 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5518 if (!start_date
.empty()) {
5519 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5521 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5526 bool is_truncated
= true;
5528 rgw_obj_index_key marker
;
5531 formatter
->open_object_section("result");
5532 formatter
->dump_string("bucket", bucket_name
);
5533 formatter
->open_array_section("objects");
5534 while (is_truncated
) {
5535 map
<string
, rgw_bucket_dir_entry
> result
;
5536 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5537 result
, &is_truncated
, &marker
,
5538 bucket_object_check_filter
);
5540 if (r
< 0 && r
!= -ENOENT
) {
5541 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5547 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5548 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5549 rgw_obj_key key
= iter
->second
.key
;
5550 rgw_bucket_dir_entry
& entry
= iter
->second
;
5552 formatter
->open_object_section("object");
5553 formatter
->dump_string("name", key
.name
);
5554 formatter
->dump_string("instance", key
.instance
);
5555 formatter
->dump_int("size", entry
.meta
.size
);
5556 utime_t
ut(entry
.meta
.mtime
);
5557 ut
.gmtime(formatter
->dump_stream("mtime"));
5559 if ((entry
.meta
.size
< min_rewrite_size
) ||
5560 (entry
.meta
.size
> max_rewrite_size
) ||
5561 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5562 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5563 formatter
->dump_string("status", "Skipped");
5565 rgw_obj
obj(bucket
, key
);
5567 bool need_rewrite
= true;
5568 if (min_rewrite_stripe_size
> 0) {
5569 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5571 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5574 if (!need_rewrite
) {
5575 formatter
->dump_string("status", "Skipped");
5577 r
= store
->rewrite_obj(bucket_info
, obj
);
5579 formatter
->dump_string("status", "Success");
5581 formatter
->dump_string("status", cpp_strerror(-r
));
5585 formatter
->dump_int("flags", entry
.flags
);
5587 formatter
->close_section();
5588 formatter
->flush(cout
);
5591 formatter
->close_section();
5592 formatter
->close_section();
5593 formatter
->flush(cout
);
5596 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5598 RGWBucketInfo bucket_info
;
5599 map
<string
, bufferlist
> attrs
;
5601 int ret
= check_reshard_bucket_params(store
,
5605 num_shards_specified
,
5607 yes_i_really_mean_it
,
5615 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5617 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5618 if (max_entries
< 1) {
5619 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5622 return br
.execute(num_shards
, max_entries
,
5623 verbose
, &cout
, formatter
);
5626 if (opt_cmd
== OPT_RESHARD_ADD
) {
5628 RGWBucketInfo bucket_info
;
5629 map
<string
, bufferlist
> attrs
;
5631 int ret
= check_reshard_bucket_params(store
,
5635 num_shards_specified
,
5637 yes_i_really_mean_it
,
5645 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5647 RGWReshard
reshard(store
);
5648 cls_rgw_reshard_entry entry
;
5649 entry
.time
= real_clock::now();
5650 entry
.tenant
= tenant
;
5651 entry
.bucket_name
= bucket_name
;
5652 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5653 entry
.old_num_shards
= num_source_shards
;
5654 entry
.new_num_shards
= num_shards
;
5656 return reshard
.add(entry
);
5659 if (opt_cmd
== OPT_RESHARD_LIST
) {
5660 list
<cls_rgw_reshard_entry
> entries
;
5663 if (max_entries
< 0) {
5667 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5669 RGWReshard
reshard(store
);
5671 formatter
->open_array_section("reshard");
5672 for (int i
= 0; i
< num_logshards
; i
++) {
5673 bool is_truncated
= true;
5677 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5679 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5682 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5683 cls_rgw_reshard_entry
& entry
= *iter
;
5684 encode_json("entry", entry
, formatter
);
5685 entry
.get_key(&marker
);
5687 count
+= entries
.size();
5688 formatter
->flush(cout
);
5689 } while (is_truncated
&& count
< max_entries
);
5691 if (count
>= max_entries
) {
5696 formatter
->close_section();
5697 formatter
->flush(cout
);
5702 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5703 if (bucket_name
.empty()) {
5704 cerr
<< "ERROR: bucket not specified" << std::endl
;
5709 RGWBucketInfo bucket_info
;
5710 map
<string
, bufferlist
> attrs
;
5711 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5713 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5717 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5718 list
<cls_rgw_bucket_instance_entry
> status
;
5719 int r
= br
.get_status(&status
);
5721 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5725 encode_json("status", status
, formatter
);
5726 formatter
->flush(cout
);
5729 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5730 RGWReshard
reshard(store
, true, &cout
);
5732 int ret
= reshard
.process_all_logshards();
5734 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
5739 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
5740 RGWReshard
reshard(store
);
5742 if (bucket_name
.empty()) {
5743 cerr
<< "ERROR: bucket not specified" << std::endl
;
5746 cls_rgw_reshard_entry entry
;
5747 //entry.tenant = tenant;
5748 entry
.bucket_name
= bucket_name
;
5749 //entry.bucket_id = bucket_id;
5750 int ret
= reshard
.get(entry
);
5752 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5756 /* TBD stop running resharding */
5758 ret
=reshard
.remove(entry
);
5760 cerr
<< "Error removing bucket " << bucket_name
<< " for resharding queue: " << cpp_strerror(-ret
) <<
5766 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
5767 RGWBucketInfo bucket_info
;
5768 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5770 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5773 list
<rgw_obj_index_key
> oid_list
;
5774 rgw_obj_key
key(object
, object_version
);
5775 rgw_obj_index_key index_key
;
5776 key
.get_index_key(&index_key
);
5777 oid_list
.push_back(index_key
);
5778 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
5780 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
5785 if (opt_cmd
== OPT_OBJECT_STAT
) {
5786 RGWBucketInfo bucket_info
;
5787 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5789 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5792 rgw_obj
obj(bucket
, object
);
5793 obj
.key
.set_instance(object_version
);
5796 map
<string
, bufferlist
> attrs
;
5797 RGWObjectCtx
obj_ctx(store
);
5798 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
5799 RGWRados::Object::Read
read_op(&op_target
);
5801 read_op
.params
.attrs
= &attrs
;
5802 read_op
.params
.obj_size
= &obj_size
;
5804 ret
= read_op
.prepare();
5806 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
5809 formatter
->open_object_section("object_metadata");
5810 formatter
->dump_string("name", object
);
5811 formatter
->dump_unsigned("size", obj_size
);
5813 map
<string
, bufferlist
>::iterator iter
;
5814 map
<string
, bufferlist
> other_attrs
;
5815 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5816 bufferlist
& bl
= iter
->second
;
5817 bool handled
= false;
5818 if (iter
->first
== RGW_ATTR_MANIFEST
) {
5819 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
5820 } else if (iter
->first
== RGW_ATTR_ACL
) {
5821 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
5822 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
5823 handled
= dump_string("tag", bl
, formatter
);
5824 } else if (iter
->first
== RGW_ATTR_ETAG
) {
5825 handled
= dump_string("etag", bl
, formatter
);
5829 other_attrs
[iter
->first
] = bl
;
5832 formatter
->open_object_section("attrs");
5833 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
5834 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
5836 formatter
->close_section();
5837 formatter
->close_section();
5838 formatter
->flush(cout
);
5841 if (opt_cmd
== OPT_BUCKET_CHECK
) {
5842 if (check_head_obj_locator
) {
5843 if (bucket_name
.empty()) {
5844 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
5847 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
5849 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
5853 if (opt_cmd
== OPT_BUCKET_RM
) {
5854 if (inconsistent_index
== false) {
5855 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
5857 if (!yes_i_really_mean_it
) {
5858 cerr
<< "using --inconsistent_index can corrupt the bucket index " << std::endl
5859 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5862 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
5866 if (opt_cmd
== OPT_GC_LIST
) {
5869 formatter
->open_array_section("entries");
5872 list
<cls_rgw_gc_obj_info
> result
;
5873 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
5875 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5880 list
<cls_rgw_gc_obj_info
>::iterator iter
;
5881 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5882 cls_rgw_gc_obj_info
& info
= *iter
;
5883 formatter
->open_object_section("chain_info");
5884 formatter
->dump_string("tag", info
.tag
);
5885 formatter
->dump_stream("time") << info
.time
;
5886 formatter
->open_array_section("objs");
5887 list
<cls_rgw_obj
>::iterator liter
;
5888 cls_rgw_obj_chain
& chain
= info
.chain
;
5889 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
5890 cls_rgw_obj
& obj
= *liter
;
5891 encode_json("obj", obj
, formatter
);
5893 formatter
->close_section(); // objs
5894 formatter
->close_section(); // obj_chain
5895 formatter
->flush(cout
);
5897 } while (truncated
);
5898 formatter
->close_section();
5899 formatter
->flush(cout
);
5902 if (opt_cmd
== OPT_GC_PROCESS
) {
5903 int ret
= store
->process_gc();
5905 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5910 if (opt_cmd
== OPT_LC_LIST
) {
5911 formatter
->open_array_section("lifecycle_list");
5912 map
<string
, int> bucket_lc_map
;
5914 #define MAX_LC_LIST_ENTRIES 100
5915 if (max_entries
< 0) {
5916 max_entries
= MAX_LC_LIST_ENTRIES
;
5919 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
5921 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5924 map
<string
, int>::iterator iter
;
5925 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
5926 formatter
->open_object_section("bucket_lc_info");
5927 formatter
->dump_string("bucket", iter
->first
);
5928 string lc_status
= LC_STATUS
[iter
->second
];
5929 formatter
->dump_string("status", lc_status
);
5930 formatter
->close_section(); // objs
5931 formatter
->flush(cout
);
5932 marker
= iter
->first
;
5934 } while (!bucket_lc_map
.empty());
5936 formatter
->close_section(); //lifecycle list
5937 formatter
->flush(cout
);
5941 if (opt_cmd
== OPT_LC_PROCESS
) {
5942 int ret
= store
->process_lc();
5944 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5949 if (opt_cmd
== OPT_ORPHANS_FIND
) {
5950 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5952 if (job_id
.empty()) {
5953 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5956 if (pool_name
.empty()) {
5957 cerr
<< "ERROR: --pool not specified" << std::endl
;
5961 RGWOrphanSearchInfo info
;
5964 info
.job_name
= job_id
;
5965 info
.num_shards
= num_shards
;
5967 int ret
= search
.init(job_id
, &info
);
5969 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
5978 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
5979 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5981 if (job_id
.empty()) {
5982 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5985 int ret
= search
.init(job_id
, NULL
);
5987 if (ret
== -ENOENT
) {
5988 cerr
<< "job not found" << std::endl
;
5992 ret
= search
.finish();
5998 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
5999 RGWOrphanStore
orphan_store(store
);
6000 int ret
= orphan_store
.init();
6002 cerr
<< "connection to cluster failed!" << std::endl
;
6006 map
<string
,RGWOrphanSearchState
> m
;
6007 ret
= orphan_store
.list_jobs(m
);
6009 cerr
<< "job list failed" << std::endl
;
6012 formatter
->open_array_section("entries");
6013 for (const auto &it
: m
){
6015 formatter
->dump_string("job-id",it
.first
);
6017 encode_json("orphan_search_state", it
.second
, formatter
);
6020 formatter
->close_section();
6021 formatter
->flush(cout
);
6024 if (opt_cmd
== OPT_USER_CHECK
) {
6025 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6028 if (opt_cmd
== OPT_USER_STATS
) {
6030 if (!bucket_name
.empty()) {
6031 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6033 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
6037 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6039 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
6045 if (user_id
.empty()) {
6046 cerr
<< "ERROR: uid not specified" << std::endl
;
6049 cls_user_header header
;
6050 string user_str
= user_id
.to_str();
6051 int ret
= store
->cls_user_get_header(user_str
, &header
);
6053 if (ret
== -ENOENT
) { /* in case of ENOENT */
6054 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6056 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6061 encode_json("header", header
, formatter
);
6062 formatter
->flush(cout
);
6065 if (opt_cmd
== OPT_METADATA_GET
) {
6066 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6068 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6072 formatter
->flush(cout
);
6075 if (opt_cmd
== OPT_METADATA_PUT
) {
6077 int ret
= read_input(infile
, bl
);
6079 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6082 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6084 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6089 if (opt_cmd
== OPT_METADATA_RM
) {
6090 int ret
= store
->meta_mgr
->remove(metadata_key
);
6092 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6097 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6098 if (opt_cmd
== OPT_USER_LIST
) {
6099 metadata_key
= "user";
6103 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, marker
, &handle
);
6105 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6112 if (max_entries_specified
) {
6113 formatter
->open_object_section("result");
6115 formatter
->open_array_section("keys");
6120 left
= (max_entries_specified
? max_entries
- count
: max
);
6121 ret
= store
->meta_mgr
->list_keys_next(handle
, left
, keys
, &truncated
);
6122 if (ret
< 0 && ret
!= -ENOENT
) {
6123 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6125 } if (ret
!= -ENOENT
) {
6126 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6127 formatter
->dump_string("key", *iter
);
6130 formatter
->flush(cout
);
6132 } while (truncated
&& left
> 0);
6134 formatter
->close_section();
6136 if (max_entries_specified
) {
6137 encode_json("truncated", truncated
, formatter
);
6138 encode_json("count", count
, formatter
);
6140 encode_json("marker", store
->meta_mgr
->get_marker(handle
), formatter
);
6142 formatter
->close_section();
6144 formatter
->flush(cout
);
6146 store
->meta_mgr
->list_keys_complete(handle
);
6149 if (opt_cmd
== OPT_MDLOG_LIST
) {
6150 utime_t start_time
, end_time
;
6152 int ret
= parse_date_str(start_date
, start_time
);
6156 ret
= parse_date_str(end_date
, end_time
);
6160 int i
= (specified_shard_id
? shard_id
: 0);
6162 if (period_id
.empty()) {
6163 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6167 std::cerr
<< "No --period given, using current period="
6168 << period_id
<< std::endl
;
6170 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6172 formatter
->open_array_section("entries");
6173 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6175 list
<cls_log_entry
> entries
;
6178 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6181 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6183 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6187 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6188 cls_log_entry
& entry
= *iter
;
6189 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6191 formatter
->flush(cout
);
6192 } while (truncated
);
6194 meta_log
->complete_list_entries(handle
);
6196 if (specified_shard_id
)
6201 formatter
->close_section();
6202 formatter
->flush(cout
);
6205 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6206 int i
= (specified_shard_id
? shard_id
: 0);
6208 if (period_id
.empty()) {
6209 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6213 std::cerr
<< "No --period given, using current period="
6214 << period_id
<< std::endl
;
6216 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6218 formatter
->open_array_section("entries");
6220 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6221 RGWMetadataLogInfo info
;
6222 meta_log
->get_info(i
, &info
);
6224 ::encode_json("info", info
, formatter
);
6226 if (specified_shard_id
)
6231 formatter
->close_section();
6232 formatter
->flush(cout
);
6235 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6236 // need a full history for purging old mdlog periods
6237 store
->meta_mgr
->init_oldest_log_period();
6239 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6240 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6241 int ret
= http
.set_threaded();
6243 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6247 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6248 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6250 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6255 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6256 utime_t start_time
, end_time
;
6258 if (!specified_shard_id
) {
6259 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6263 int ret
= parse_date_str(start_date
, start_time
);
6267 ret
= parse_date_str(end_date
, end_time
);
6271 if (period_id
.empty()) {
6272 std::cerr
<< "missing --period argument" << std::endl
;
6275 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6277 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6279 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6284 if (opt_cmd
== OPT_SYNC_STATUS
) {
6285 sync_status(formatter
);
6288 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6289 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6291 int ret
= sync
.init();
6293 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6297 rgw_meta_sync_status sync_status
;
6298 ret
= sync
.read_sync_status(&sync_status
);
6300 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6304 formatter
->open_object_section("summary");
6305 encode_json("sync_status", sync_status
, formatter
);
6307 uint64_t full_total
= 0;
6308 uint64_t full_complete
= 0;
6310 for (auto marker_iter
: sync_status
.sync_markers
) {
6311 full_total
+= marker_iter
.second
.total_entries
;
6312 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6313 full_complete
+= marker_iter
.second
.pos
;
6315 full_complete
+= marker_iter
.second
.total_entries
;
6319 formatter
->open_object_section("full_sync");
6320 encode_json("total", full_total
, formatter
);
6321 encode_json("complete", full_complete
, formatter
);
6322 formatter
->close_section();
6323 formatter
->close_section();
6325 formatter
->flush(cout
);
6329 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6330 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6332 int ret
= sync
.init();
6334 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6337 ret
= sync
.init_sync_status();
6339 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6345 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6346 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6348 int ret
= sync
.init();
6350 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6356 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6361 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6362 if (source_zone
.empty()) {
6363 cerr
<< "ERROR: source zone not specified" << std::endl
;
6366 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6368 int ret
= sync
.init();
6370 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6374 rgw_data_sync_status sync_status
;
6375 ret
= sync
.read_sync_status(&sync_status
);
6376 if (ret
< 0 && ret
!= -ENOENT
) {
6377 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6381 formatter
->open_object_section("summary");
6382 encode_json("sync_status", sync_status
, formatter
);
6384 uint64_t full_total
= 0;
6385 uint64_t full_complete
= 0;
6387 for (auto marker_iter
: sync_status
.sync_markers
) {
6388 full_total
+= marker_iter
.second
.total_entries
;
6389 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6390 full_complete
+= marker_iter
.second
.pos
;
6392 full_complete
+= marker_iter
.second
.total_entries
;
6396 formatter
->open_object_section("full_sync");
6397 encode_json("total", full_total
, formatter
);
6398 encode_json("complete", full_complete
, formatter
);
6399 formatter
->close_section();
6400 formatter
->close_section();
6402 formatter
->flush(cout
);
6405 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6406 if (source_zone
.empty()) {
6407 cerr
<< "ERROR: source zone not specified" << std::endl
;
6410 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6412 int ret
= sync
.init();
6414 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6418 ret
= sync
.init_sync_status();
6420 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6425 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6426 if (source_zone
.empty()) {
6427 cerr
<< "ERROR: source zone not specified" << std::endl
;
6430 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6432 int ret
= sync
.init();
6434 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6440 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6445 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6446 if (source_zone
.empty()) {
6447 cerr
<< "ERROR: source zone not specified" << std::endl
;
6450 if (bucket_name
.empty()) {
6451 cerr
<< "ERROR: bucket not specified" << std::endl
;
6455 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6459 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6463 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6466 ret
= sync
.init_sync_status();
6468 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6473 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
6474 if (bucket_name
.empty()) {
6475 cerr
<< "ERROR: bucket not specified" << std::endl
;
6480 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
6484 ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
, true);
6486 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
6490 if (!store
->is_meta_master()) {
6491 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
6492 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
6496 rgw_obj
obj(bucket
, object
);
6497 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
6502 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6503 if (source_zone
.empty()) {
6504 cerr
<< "ERROR: source zone not specified" << std::endl
;
6507 if (bucket_name
.empty()) {
6508 cerr
<< "ERROR: bucket not specified" << std::endl
;
6512 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6516 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6520 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6523 ret
= sync
.read_sync_status();
6525 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6529 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6531 encode_json("sync_status", sync_status
, formatter
);
6532 formatter
->flush(cout
);
6535 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6536 if (source_zone
.empty()) {
6537 cerr
<< "ERROR: source zone not specified" << std::endl
;
6540 if (bucket_name
.empty()) {
6541 cerr
<< "ERROR: bucket not specified" << std::endl
;
6545 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6549 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6553 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6559 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6564 if (opt_cmd
== OPT_BILOG_LIST
) {
6565 if (bucket_name
.empty()) {
6566 cerr
<< "ERROR: bucket not specified" << std::endl
;
6569 RGWBucketInfo bucket_info
;
6570 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6572 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6575 formatter
->open_array_section("entries");
6578 if (max_entries
< 0)
6582 list
<rgw_bi_log_entry
> entries
;
6583 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6585 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6589 count
+= entries
.size();
6591 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6592 rgw_bi_log_entry
& entry
= *iter
;
6593 encode_json("entry", entry
, formatter
);
6597 formatter
->flush(cout
);
6598 } while (truncated
&& count
< max_entries
);
6600 formatter
->close_section();
6601 formatter
->flush(cout
);
6604 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6605 if (max_entries
< 0) {
6610 utime_t start_time
, end_time
;
6612 int ret
= parse_date_str(start_date
, start_time
);
6616 ret
= parse_date_str(end_date
, end_time
);
6624 formatter
->open_array_section("entries");
6626 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6627 formatter
->open_object_section("shard");
6628 encode_json("shard_id", shard_id
, formatter
);
6629 formatter
->open_array_section("entries");
6632 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6635 list
<cls_log_entry
> entries
;
6636 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6637 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6638 if (ret
== -ENOENT
) {
6642 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6646 count
+= entries
.size();
6648 for (auto& cls_entry
: entries
) {
6649 rgw_sync_error_info log_entry
;
6651 auto iter
= cls_entry
.data
.begin();
6653 ::decode(log_entry
, iter
);
6654 } catch (buffer::error
& err
) {
6655 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6658 formatter
->open_object_section("entry");
6659 encode_json("id", cls_entry
.id
, formatter
);
6660 encode_json("section", cls_entry
.section
, formatter
);
6661 encode_json("name", cls_entry
.name
, formatter
);
6662 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
6663 encode_json("info", log_entry
, formatter
);
6664 formatter
->close_section();
6665 formatter
->flush(cout
);
6667 } while (truncated
&& count
< max_entries
);
6669 formatter
->close_section();
6670 formatter
->close_section();
6672 if (specified_shard_id
) {
6677 formatter
->close_section();
6678 formatter
->flush(cout
);
6681 if (opt_cmd
== OPT_BILOG_TRIM
) {
6682 if (bucket_name
.empty()) {
6683 cerr
<< "ERROR: bucket not specified" << std::endl
;
6686 RGWBucketInfo bucket_info
;
6687 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6689 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6692 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
6694 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6699 if (opt_cmd
== OPT_BILOG_STATUS
) {
6700 if (bucket_name
.empty()) {
6701 cerr
<< "ERROR: bucket not specified" << std::endl
;
6704 RGWBucketInfo bucket_info
;
6705 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6707 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6710 map
<int, string
> markers
;
6711 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
6713 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
6716 formatter
->open_object_section("entries");
6717 encode_json("markers", markers
, formatter
);
6718 formatter
->close_section();
6719 formatter
->flush(cout
);
6722 if (opt_cmd
== OPT_DATALOG_LIST
) {
6723 formatter
->open_array_section("entries");
6726 if (max_entries
< 0)
6729 utime_t start_time
, end_time
;
6731 int ret
= parse_date_str(start_date
, start_time
);
6735 ret
= parse_date_str(end_date
, end_time
);
6739 RGWDataChangesLog
*log
= store
->data_log
;
6740 RGWDataChangesLog::LogMarker marker
;
6743 list
<rgw_data_change_log_entry
> entries
;
6744 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
6746 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6750 count
+= entries
.size();
6752 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6753 rgw_data_change_log_entry
& entry
= *iter
;
6755 encode_json("entry", entry
.entry
, formatter
);
6757 encode_json("entry", entry
, formatter
);
6760 formatter
->flush(cout
);
6761 } while (truncated
&& count
< max_entries
);
6763 formatter
->close_section();
6764 formatter
->flush(cout
);
6767 if (opt_cmd
== OPT_DATALOG_STATUS
) {
6768 RGWDataChangesLog
*log
= store
->data_log
;
6769 int i
= (specified_shard_id
? shard_id
: 0);
6771 formatter
->open_array_section("entries");
6772 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
6773 list
<cls_log_entry
> entries
;
6775 RGWDataChangesLogInfo info
;
6776 log
->get_info(i
, &info
);
6778 ::encode_json("info", info
, formatter
);
6780 if (specified_shard_id
)
6784 formatter
->close_section();
6785 formatter
->flush(cout
);
6788 if (opt_cmd
== OPT_DATALOG_TRIM
) {
6789 utime_t start_time
, end_time
;
6791 int ret
= parse_date_str(start_date
, start_time
);
6795 ret
= parse_date_str(end_date
, end_time
);
6799 RGWDataChangesLog
*log
= store
->data_log
;
6800 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6802 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
6807 if (opt_cmd
== OPT_OPSTATE_LIST
) {
6808 RGWOpState
oc(store
);
6813 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
6814 list
<cls_statelog_entry
> entries
;
6816 formatter
->open_array_section("entries");
6818 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
6820 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
6821 oc
.finish_list_entries(handle
);
6825 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6826 oc
.dump_entry(*iter
, formatter
);
6829 formatter
->flush(cout
);
6831 formatter
->close_section();
6832 formatter
->flush(cout
);
6833 oc
.finish_list_entries(handle
);
6836 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
6837 RGWOpState
oc(store
);
6839 RGWOpState::OpState state
;
6840 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6841 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6844 if (state_str
.empty()) {
6845 cerr
<< "ERROR: state was not specified" << std::endl
;
6848 int ret
= oc
.state_from_str(state_str
, &state
);
6850 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
6854 if (opt_cmd
== OPT_OPSTATE_SET
) {
6855 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
6857 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6861 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
6863 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
6868 if (opt_cmd
== OPT_OPSTATE_RM
) {
6869 RGWOpState
oc(store
);
6871 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6872 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6875 ret
= oc
.remove_entry(client_id
, op_id
, object
);
6877 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6882 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
6883 opt_cmd
== OPT_REPLICALOG_DELETE
) {
6884 if (replica_log_type_str
.empty()) {
6885 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
6890 if (opt_cmd
== OPT_REPLICALOG_GET
) {
6891 RGWReplicaBounds bounds
;
6892 if (replica_log_type
== ReplicaLog_Metadata
) {
6893 if (!specified_shard_id
) {
6894 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6898 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6899 int ret
= logger
.get_bounds(shard_id
, bounds
);
6902 } else if (replica_log_type
== ReplicaLog_Data
) {
6903 if (!specified_shard_id
) {
6904 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6907 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6908 int ret
= logger
.get_bounds(shard_id
, bounds
);
6911 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6912 if (bucket_name
.empty()) {
6913 cerr
<< "ERROR: bucket not specified" << std::endl
;
6916 RGWBucketInfo bucket_info
;
6917 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6919 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6923 RGWReplicaBucketLogger
logger(store
);
6924 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
6927 } else { // shouldn't get here
6930 encode_json("bounds", bounds
, formatter
);
6931 formatter
->flush(cout
);
6935 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
6936 if (replica_log_type
== ReplicaLog_Metadata
) {
6937 if (!specified_shard_id
) {
6938 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6941 if (!specified_daemon_id
) {
6942 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6945 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6946 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6949 } else if (replica_log_type
== ReplicaLog_Data
) {
6950 if (!specified_shard_id
) {
6951 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6954 if (!specified_daemon_id
) {
6955 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6958 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6959 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6962 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6963 if (bucket_name
.empty()) {
6964 cerr
<< "ERROR: bucket not specified" << std::endl
;
6967 RGWBucketInfo bucket_info
;
6968 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6970 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6974 RGWReplicaBucketLogger
logger(store
);
6975 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
6981 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
6982 if (marker
.empty()) {
6983 cerr
<< "ERROR: marker was not specified" <<std::endl
;
6986 utime_t time
= ceph_clock_now();
6987 if (!date
.empty()) {
6988 ret
= parse_date_str(date
, time
);
6990 cerr
<< "ERROR: failed to parse start date" << std::endl
;
6994 list
<RGWReplicaItemMarker
> entries
;
6995 int ret
= read_decode_json(infile
, entries
);
6997 cerr
<< "ERROR: failed to decode entries" << std::endl
;
7000 RGWReplicaBounds bounds
;
7001 if (replica_log_type
== ReplicaLog_Metadata
) {
7002 if (!specified_shard_id
) {
7003 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7007 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7008 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7010 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7013 } else if (replica_log_type
== ReplicaLog_Data
) {
7014 if (!specified_shard_id
) {
7015 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7018 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7019 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7021 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7024 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7025 if (bucket_name
.empty()) {
7026 cerr
<< "ERROR: bucket not specified" << std::endl
;
7029 RGWBucketInfo bucket_info
;
7030 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7032 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7036 RGWReplicaBucketLogger
logger(store
);
7037 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
7039 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7045 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7048 if (bucket_name
.empty() && user_id
.empty()) {
7049 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7053 if (!bucket_name
.empty()) {
7054 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7055 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7058 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7059 max_size
, max_objects
, have_max_size
, have_max_objects
);
7060 } else if (!user_id
.empty()) {
7061 if (quota_scope
== "bucket") {
7062 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7063 } else if (quota_scope
== "user") {
7064 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7066 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;