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;
2400 bool admin_specified
= false;
2402 bool system_specified
= false;
2404 bool specified_shard_id
= false;
2406 bool specified_daemon_id
= false;
2410 string replica_log_type_str
;
2411 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2414 string object_version
;
2415 string placement_id
;
2417 list
<string
> tags_add
;
2418 list
<string
> tags_rm
;
2420 int64_t max_objects
= -1;
2421 int64_t max_size
= -1;
2422 bool have_max_objects
= false;
2423 bool have_max_size
= false;
2424 int include_all
= false;
2426 int sync_stats
= false;
2427 int bypass_gc
= false;
2428 int warnings_only
= false;
2429 int inconsistent_index
= false;
2431 int verbose
= false;
2433 int extra_info
= false;
2435 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2436 uint64_t max_rewrite_size
= ULLONG_MAX
;
2437 uint64_t min_rewrite_stripe_size
= 0;
2439 BIIndexType bi_index_type
= PlainIdx
;
2443 bool num_shards_specified
= false;
2444 int max_concurrent_ios
= 32;
2445 uint64_t orphan_stale_secs
= (24 * 3600);
2448 std::ostringstream errs
;
2452 string source_zone_name
;
2453 string source_zone
; /* zone id */
2456 bool tier_type_specified
= false;
2458 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2459 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2461 boost::optional
<string
> index_pool
;
2462 boost::optional
<string
> data_pool
;
2463 boost::optional
<string
> data_extra_pool
;
2464 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2465 bool index_type_specified
= false;
2467 boost::optional
<std::string
> compression_type
;
2469 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2470 if (ceph_argparse_double_dash(args
, i
)) {
2472 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2475 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2476 user_id
.from_str(val
);
2477 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2479 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2481 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2483 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2485 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2487 user_op
.user_email_specified
=true;
2488 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2490 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2492 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2494 pool
= rgw_pool(pool_name
);
2495 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2497 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2498 object_version
= val
;
2499 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2501 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2503 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2505 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2507 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2509 if (key_type_str
.compare("swift") == 0) {
2510 key_type
= KEY_TYPE_SWIFT
;
2511 } else if (key_type_str
.compare("s3") == 0) {
2512 key_type
= KEY_TYPE_S3
;
2514 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2518 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2520 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2522 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2524 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2526 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2528 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2530 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2531 admin_specified
= true;
2532 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2533 system_specified
= true;
2534 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2536 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2538 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2540 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2541 if (!errs
.str().empty()) {
2542 cerr
<< errs
.str() << std::endl
;
2545 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2546 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2547 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2548 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2549 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2550 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2551 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2552 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2554 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2557 max_buckets_specified
= true;
2558 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2559 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2561 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2564 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2565 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2567 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2570 have_max_size
= true;
2571 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2572 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2574 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2577 have_max_objects
= true;
2578 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2580 if (end_date
.empty())
2582 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2584 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2586 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2587 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2589 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2592 num_shards_specified
= true;
2593 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2594 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2596 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2599 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2600 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2602 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2605 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2606 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2608 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2611 specified_shard_id
= true;
2612 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2614 specified_daemon_id
= true;
2615 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2617 perm_mask
= rgw_str_to_perm(access
.c_str());
2619 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2620 temp_url_keys
[0] = val
;
2621 set_temp_url_key
= true;
2622 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2623 temp_url_keys
[1] = val
;
2624 set_temp_url_key
= true;
2625 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2627 if (bucket_id
.empty()) {
2628 cerr
<< "bad bucket-id" << std::endl
;
2632 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2634 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2635 string cat_str
= val
;
2636 list
<string
> cat_list
;
2637 list
<string
>::iterator iter
;
2638 get_str_list(cat_str
, cat_list
);
2639 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2640 categories
[*iter
] = true;
2642 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2644 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2646 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2647 delete_child_objects
= purge_data
;
2648 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2650 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2652 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2654 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2656 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2658 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2660 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2662 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2664 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2666 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2668 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2670 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2672 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2674 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2676 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2678 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2680 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2682 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2684 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2686 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2687 replica_log_type_str
= val
;
2688 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2689 if (replica_log_type
== ReplicaLog_Invalid
) {
2690 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2693 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2694 string index_type_str
= val
;
2695 bi_index_type
= get_bi_index_type(index_type_str
);
2696 if (bi_index_type
== InvalidIdx
) {
2697 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2700 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2701 is_master
= (bool)is_master_int
;
2702 is_master_set
= true;
2703 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2705 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2706 read_only
= (bool)read_only_int
;
2707 is_read_only_set
= true;
2708 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2710 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2711 master_zonegroup
= val
;
2712 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2714 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2716 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2718 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2720 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2722 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2724 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2725 realm_new_name
= val
;
2726 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2728 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2729 zonegroup_new_name
= val
;
2730 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2732 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2733 get_str_list(val
, tags
);
2734 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2735 get_str_list(val
, tags_add
);
2736 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2737 get_str_list(val
, tags_rm
);
2738 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2740 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2742 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2743 zone_new_name
= val
;
2744 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2745 get_str_list(val
, endpoints
);
2746 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2747 get_str_list(val
, sync_from
);
2748 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2749 get_str_list(val
, sync_from_rm
);
2750 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2751 sync_from_all
= (bool)tmp_int
;
2752 sync_from_all_specified
= true;
2753 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2754 source_zone_name
= val
;
2755 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2757 tier_type_specified
= true;
2758 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2759 parse_tier_config_param(val
, tier_config_add
);
2760 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2761 parse_tier_config_param(val
, tier_config_rm
);
2762 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2764 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2766 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2767 data_extra_pool
= val
;
2768 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2769 if (val
== "normal") {
2770 placement_index_type
= RGWBIType_Normal
;
2771 } else if (val
== "indexless") {
2772 placement_index_type
= RGWBIType_Indexless
;
2774 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2776 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2780 index_type_specified
= true;
2781 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2782 compression_type
= val
;
2783 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2785 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2787 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2788 assume_role_doc
= val
;
2789 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2791 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2792 perm_policy_doc
= val
;
2793 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2795 } else if (strncmp(*i
, "-", 1) == 0) {
2796 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
2808 const char *prev_cmd
= NULL
;
2809 const char *prev_prev_cmd
= NULL
;
2810 std::vector
<const char*>::iterator i
;
2811 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
2812 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
2814 cerr
<< "unrecognized arg " << *i
<< std::endl
;
2822 prev_prev_cmd
= prev_cmd
;
2826 if (opt_cmd
== OPT_NO_CMD
) {
2831 /* some commands may have an optional extra param */
2832 if (i
!= args
.end()) {
2834 case OPT_METADATA_GET
:
2835 case OPT_METADATA_PUT
:
2836 case OPT_METADATA_RM
:
2837 case OPT_METADATA_LIST
:
2845 if (tenant
.empty()) {
2846 tenant
= user_id
.tenant
;
2848 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
2849 && opt_cmd
!= OPT_ROLE_DELETE
2850 && opt_cmd
!= OPT_ROLE_GET
2851 && opt_cmd
!= OPT_ROLE_MODIFY
2852 && opt_cmd
!= OPT_ROLE_LIST
2853 && opt_cmd
!= OPT_ROLE_POLICY_PUT
2854 && opt_cmd
!= OPT_ROLE_POLICY_LIST
2855 && opt_cmd
!= OPT_ROLE_POLICY_GET
2856 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
) {
2857 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
2860 user_id
.tenant
= tenant
;
2862 /* check key parameter conflict */
2863 if ((!access_key
.empty()) && gen_access_key
) {
2864 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
2867 if ((!secret_key
.empty()) && gen_secret_key
) {
2868 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
2873 // default to pretty json
2874 if (format
.empty()) {
2876 pretty_format
= true;
2879 if (format
== "xml")
2880 formatter
= new XMLFormatter(pretty_format
);
2881 else if (format
== "json")
2882 formatter
= new JSONFormatter(pretty_format
);
2884 cerr
<< "unrecognized format: " << format
<< std::endl
;
2889 realm_name
= g_conf
->rgw_realm
;
2890 zone_name
= g_conf
->rgw_zone
;
2891 zonegroup_name
= g_conf
->rgw_zonegroup
;
2893 RGWStreamFlusher
f(formatter
, cout
);
2895 // not a raw op if 'period update' needs to commit to master
2896 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
2897 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
2898 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
2899 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
2900 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
2901 OPT_ZONEGROUP_REMOVE
,
2902 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
2903 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
2904 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
2905 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
2906 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
2907 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
2908 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
2909 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
2911 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
2913 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
2914 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
2915 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
2916 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
2917 OPT_REALM_LIST_PERIODS
,
2918 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
2919 OPT_REALM_RENAME
, OPT_REALM_SET
,
2920 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
2923 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
2926 if (raw_storage_op
) {
2927 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
2929 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false);
2932 cerr
<< "couldn't init storage provider" << std::endl
;
2936 if (!source_zone_name
.empty()) {
2937 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
2938 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
2939 source_zone
= source_zone_name
;
2943 rgw_user_init(store
);
2944 rgw_bucket_init(store
->meta_mgr
);
2946 StoreDestructor
store_destructor(store
);
2948 if (raw_storage_op
) {
2950 case OPT_PERIOD_DELETE
:
2952 if (period_id
.empty()) {
2953 cerr
<< "missing period id" << std::endl
;
2956 RGWPeriod
period(period_id
);
2957 int ret
= period
.init(g_ceph_context
, store
);
2959 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
2962 ret
= period
.delete_obj();
2964 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
2970 case OPT_PERIOD_GET
:
2973 if (!period_epoch
.empty()) {
2974 epoch
= atoi(period_epoch
.c_str());
2977 RGWRealm
realm(realm_id
, realm_name
);
2978 int ret
= realm
.init(g_ceph_context
, store
);
2980 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
2983 realm_id
= realm
.get_id();
2984 realm_name
= realm
.get_name();
2985 period_id
= RGWPeriod::get_staging_id(realm_id
);
2988 RGWPeriod
period(period_id
, epoch
);
2989 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
2991 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
2994 encode_json("period", period
, formatter
);
2995 formatter
->flush(cout
);
2999 case OPT_PERIOD_GET_CURRENT
:
3001 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3005 formatter
->open_object_section("period_get_current");
3006 encode_json("current_period", period_id
, formatter
);
3007 formatter
->close_section();
3008 formatter
->flush(cout
);
3011 case OPT_PERIOD_LIST
:
3013 list
<string
> periods
;
3014 int ret
= store
->list_periods(periods
);
3016 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
3019 formatter
->open_object_section("periods_list");
3020 encode_json("periods", periods
, formatter
);
3021 formatter
->close_section();
3022 formatter
->flush(cout
);
3026 case OPT_PERIOD_UPDATE
:
3028 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
3029 commit
, remote
, url
, access_key
, secret_key
,
3030 formatter
, yes_i_really_mean_it
);
3036 case OPT_PERIOD_PULL
:
3038 boost::optional
<RGWRESTConn
> conn
;
3039 RGWRESTConn
*remote_conn
= nullptr;
3041 // load current period for endpoints
3042 RGWRealm
realm(realm_id
, realm_name
);
3043 int ret
= realm
.init(g_ceph_context
, store
);
3045 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3048 RGWPeriod
current_period(realm
.get_current_period());
3049 ret
= current_period
.init(g_ceph_context
, store
);
3051 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
3054 if (remote
.empty()) {
3055 // use realm master zone as remote
3056 remote
= current_period
.get_master_zone();
3058 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
3060 cerr
<< "failed to find a zone or zonegroup for remote "
3061 << remote
<< std::endl
;
3064 remote_conn
= &*conn
;
3068 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3069 realm_id
, realm_name
, period_id
, period_epoch
,
3072 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3076 encode_json("period", period
, formatter
);
3077 formatter
->flush(cout
);
3081 case OPT_GLOBAL_QUOTA_GET
:
3082 case OPT_GLOBAL_QUOTA_SET
:
3083 case OPT_GLOBAL_QUOTA_ENABLE
:
3084 case OPT_GLOBAL_QUOTA_DISABLE
:
3086 if (realm_id
.empty()) {
3087 RGWRealm
realm(g_ceph_context
, store
);
3088 if (!realm_name
.empty()) {
3089 // look up realm_id for the given realm_name
3090 int ret
= realm
.read_id(realm_name
, realm_id
);
3092 cerr
<< "ERROR: failed to read realm for " << realm_name
3093 << ": " << cpp_strerror(-ret
) << std::endl
;
3097 // use default realm_id when none is given
3098 int ret
= realm
.read_default_id(realm_id
);
3099 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3100 cerr
<< "ERROR: failed to read default realm: "
3101 << cpp_strerror(-ret
) << std::endl
;
3107 RGWPeriodConfig period_config
;
3108 int ret
= period_config
.read(store
, realm_id
);
3109 if (ret
< 0 && ret
!= -ENOENT
) {
3110 cerr
<< "ERROR: failed to read period config: "
3111 << cpp_strerror(-ret
) << std::endl
;
3115 formatter
->open_object_section("period_config");
3116 if (quota_scope
== "bucket") {
3117 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3118 max_size
, max_objects
,
3119 have_max_size
, have_max_objects
);
3120 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3121 } else if (quota_scope
== "user") {
3122 set_quota_info(period_config
.user_quota
, opt_cmd
,
3123 max_size
, max_objects
,
3124 have_max_size
, have_max_objects
);
3125 encode_json("user quota", period_config
.user_quota
, formatter
);
3126 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3127 // if no scope is given for GET, print both
3128 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3129 encode_json("user quota", period_config
.user_quota
, formatter
);
3131 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3132 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3135 formatter
->close_section();
3137 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3138 // write the modified period config
3139 ret
= period_config
.write(store
, realm_id
);
3141 cerr
<< "ERROR: failed to write period config: "
3142 << cpp_strerror(-ret
) << std::endl
;
3145 if (!realm_id
.empty()) {
3146 cout
<< "Global quota changes saved. Use 'period update' to apply "
3147 "them to the staging period, and 'period commit' to commit the "
3148 "new period." << std::endl
;
3150 cout
<< "Global quota changes saved. They will take effect as "
3151 "the gateways are restarted." << std::endl
;
3155 formatter
->flush(cout
);
3159 case OPT_REALM_CREATE
:
3161 if (realm_name
.empty()) {
3162 cerr
<< "missing realm name" << std::endl
;
3166 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3167 int ret
= realm
.create();
3169 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3174 ret
= realm
.set_as_default();
3176 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3180 encode_json("realm", realm
, formatter
);
3181 formatter
->flush(cout
);
3185 case OPT_REALM_DELETE
:
3187 RGWRealm
realm(realm_id
, realm_name
);
3188 if (realm_name
.empty() && realm_id
.empty()) {
3189 cerr
<< "missing realm name or id" << std::endl
;
3192 int ret
= realm
.init(g_ceph_context
, store
);
3194 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3197 ret
= realm
.delete_obj();
3199 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3207 RGWRealm
realm(realm_id
, realm_name
);
3208 int ret
= realm
.init(g_ceph_context
, store
);
3210 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3211 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3213 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3217 encode_json("realm", realm
, formatter
);
3218 formatter
->flush(cout
);
3222 case OPT_REALM_GET_DEFAULT
:
3224 RGWRealm
realm(g_ceph_context
, store
);
3226 int ret
= realm
.read_default_id(default_id
);
3227 if (ret
== -ENOENT
) {
3228 cout
<< "No default realm is set" << std::endl
;
3230 } else if (ret
< 0) {
3231 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3234 cout
<< "default realm: " << default_id
<< std::endl
;
3237 case OPT_REALM_LIST
:
3239 RGWRealm
realm(g_ceph_context
, store
);
3241 int ret
= realm
.read_default_id(default_id
);
3242 if (ret
< 0 && ret
!= -ENOENT
) {
3243 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3245 list
<string
> realms
;
3246 ret
= store
->list_realms(realms
);
3248 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3251 formatter
->open_object_section("realms_list");
3252 encode_json("default_info", default_id
, formatter
);
3253 encode_json("realms", realms
, formatter
);
3254 formatter
->close_section();
3255 formatter
->flush(cout
);
3259 case OPT_REALM_LIST_PERIODS
:
3261 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3265 list
<string
> periods
;
3266 ret
= store
->list_periods(period_id
, periods
);
3268 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3271 formatter
->open_object_section("realm_periods_list");
3272 encode_json("current_period", period_id
, formatter
);
3273 encode_json("periods", periods
, formatter
);
3274 formatter
->close_section();
3275 formatter
->flush(cout
);
3280 case OPT_REALM_RENAME
:
3282 RGWRealm
realm(realm_id
, realm_name
);
3283 if (realm_new_name
.empty()) {
3284 cerr
<< "missing realm new name" << std::endl
;
3287 if (realm_name
.empty() && realm_id
.empty()) {
3288 cerr
<< "missing realm name or id" << std::endl
;
3291 int ret
= realm
.init(g_ceph_context
, store
);
3293 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3296 ret
= realm
.rename(realm_new_name
);
3298 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3301 cout
<< "Realm name updated. Note that this change only applies to "
3302 "the current cluster, so this command must be run separately "
3303 "on each of the realm's other clusters." << std::endl
;
3308 if (realm_id
.empty() && realm_name
.empty()) {
3309 cerr
<< "no realm name or id provided" << std::endl
;
3312 RGWRealm
realm(realm_id
, realm_name
);
3313 bool new_realm
= false;
3314 int ret
= realm
.init(g_ceph_context
, store
);
3315 if (ret
< 0 && ret
!= -ENOENT
) {
3316 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3318 } else if (ret
== -ENOENT
) {
3321 ret
= read_decode_json(infile
, realm
);
3325 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3326 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3327 realm
.get_name() << std::endl
;
3332 cout
<< "clearing period and epoch for new realm" << std::endl
;
3333 realm
.clear_current_period_and_epoch();
3334 ret
= realm
.create();
3336 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3340 ret
= realm
.update();
3342 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3348 ret
= realm
.set_as_default();
3350 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3353 encode_json("realm", realm
, formatter
);
3354 formatter
->flush(cout
);
3358 case OPT_REALM_DEFAULT
:
3360 RGWRealm
realm(realm_id
, realm_name
);
3361 int ret
= realm
.init(g_ceph_context
, store
);
3363 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3366 ret
= realm
.set_as_default();
3368 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3373 case OPT_REALM_PULL
:
3376 cerr
<< "A --url must be provided." << std::endl
;
3380 req_info
info(g_ceph_context
, &env
);
3381 info
.method
= "GET";
3382 info
.request_uri
= "/admin/realm";
3384 map
<string
, string
> ¶ms
= info
.args
.get_params();
3385 if (!realm_id
.empty())
3386 params
["id"] = realm_id
;
3387 if (!realm_name
.empty())
3388 params
["name"] = realm_name
;
3392 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3394 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3395 if (ret
== -EACCES
) {
3396 cerr
<< "If the realm has been changed on the master zone, the "
3397 "master zone's gateway may need to be restarted to recognize "
3398 "this user." << std::endl
;
3403 realm
.init(g_ceph_context
, store
, false);
3405 decode_json_obj(realm
, &p
);
3406 } catch (JSONDecoder::err
& e
) {
3407 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3411 auto& current_period
= realm
.get_current_period();
3412 if (!current_period
.empty()) {
3413 // pull the latest epoch of the realm's current period
3414 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3415 realm_id
, realm_name
, current_period
, "",
3418 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3422 ret
= realm
.create(false);
3423 if (ret
< 0 && ret
!= -EEXIST
) {
3424 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3425 << cpp_strerror(ret
) << std::endl
;
3427 } else if (ret
==-EEXIST
) {
3428 ret
= realm
.update();
3430 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3431 << cpp_strerror(ret
) << std::endl
;
3436 ret
= realm
.set_as_default();
3438 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3442 encode_json("realm", realm
, formatter
);
3443 formatter
->flush(cout
);
3448 case OPT_ZONEGROUP_ADD
:
3450 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3451 cerr
<< "no zonegroup name or id provided" << std::endl
;
3455 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3456 int ret
= zonegroup
.init(g_ceph_context
, store
);
3458 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3459 << cpp_strerror(-ret
) << std::endl
;
3462 RGWZoneParams
zone(zone_id
, zone_name
);
3463 ret
= zone
.init(g_ceph_context
, store
);
3465 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3468 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3469 zone
.realm_id
= zonegroup
.realm_id
;
3470 ret
= zone
.update();
3472 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
3477 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3478 zone
.tier_config
= tier_config_add
;
3480 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3482 ret
= zonegroup
.add_zone(zone
,
3483 (is_master_set
? &is_master
: NULL
),
3484 (is_read_only_set
? &read_only
: NULL
),
3485 endpoints
, ptier_type
,
3486 psync_from_all
, sync_from
, sync_from_rm
);
3488 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3489 << cpp_strerror(-ret
) << std::endl
;
3493 encode_json("zonegroup", zonegroup
, formatter
);
3494 formatter
->flush(cout
);
3497 case OPT_ZONEGROUP_CREATE
:
3499 if (zonegroup_name
.empty()) {
3500 cerr
<< "Missing zonegroup name" << std::endl
;
3503 RGWRealm
realm(realm_id
, realm_name
);
3504 int ret
= realm
.init(g_ceph_context
, store
);
3506 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3510 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3511 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3512 ret
= zonegroup
.create();
3514 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3519 ret
= zonegroup
.set_as_default();
3521 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3525 encode_json("zonegroup", zonegroup
, formatter
);
3526 formatter
->flush(cout
);
3530 case OPT_ZONEGROUP_DEFAULT
:
3532 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3533 cerr
<< "no zonegroup name or id provided" << std::endl
;
3537 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3538 int ret
= zonegroup
.init(g_ceph_context
, store
);
3540 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3544 ret
= zonegroup
.set_as_default();
3546 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3551 case OPT_ZONEGROUP_DELETE
:
3553 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3554 cerr
<< "no zonegroup name or id provided" << std::endl
;
3557 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3558 int ret
= zonegroup
.init(g_ceph_context
, store
);
3560 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3563 ret
= zonegroup
.delete_obj();
3565 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3570 case OPT_ZONEGROUP_GET
:
3572 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3573 int ret
= zonegroup
.init(g_ceph_context
, store
);
3575 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3579 encode_json("zonegroup", zonegroup
, formatter
);
3580 formatter
->flush(cout
);
3584 case OPT_ZONEGROUP_LIST
:
3586 RGWZoneGroup zonegroup
;
3587 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3589 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3593 list
<string
> zonegroups
;
3594 ret
= store
->list_zonegroups(zonegroups
);
3596 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3599 string default_zonegroup
;
3600 ret
= zonegroup
.read_default_id(default_zonegroup
);
3601 if (ret
< 0 && ret
!= -ENOENT
) {
3602 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3604 formatter
->open_object_section("zonegroups_list");
3605 encode_json("default_info", default_zonegroup
, formatter
);
3606 encode_json("zonegroups", zonegroups
, formatter
);
3607 formatter
->close_section();
3608 formatter
->flush(cout
);
3612 case OPT_ZONEGROUP_MODIFY
:
3614 RGWRealm
realm(realm_id
, realm_name
);
3615 int ret
= realm
.init(g_ceph_context
, store
);
3617 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3621 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3622 ret
= zonegroup
.init(g_ceph_context
, store
);
3624 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3628 bool need_update
= false;
3630 if (!master_zone
.empty()) {
3631 zonegroup
.master_zone
= master_zone
;
3635 if (is_master_set
) {
3636 zonegroup
.update_master(is_master
);
3640 if (!endpoints
.empty()) {
3641 zonegroup
.endpoints
= endpoints
;
3645 if (!api_name
.empty()) {
3646 zonegroup
.api_name
= api_name
;
3650 if (!realm_id
.empty()) {
3651 zonegroup
.realm_id
= realm_id
;
3653 } else if (!realm_name
.empty()) {
3654 // get realm id from name
3655 RGWRealm realm
{g_ceph_context
, store
};
3656 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3658 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3665 ret
= zonegroup
.update();
3667 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3673 ret
= zonegroup
.set_as_default();
3675 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3679 encode_json("zonegroup", zonegroup
, formatter
);
3680 formatter
->flush(cout
);
3683 case OPT_ZONEGROUP_SET
:
3685 RGWRealm
realm(realm_id
, realm_name
);
3686 int ret
= realm
.init(g_ceph_context
, store
);
3688 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3692 RGWZoneGroup zonegroup
;
3693 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3695 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3698 ret
= read_decode_json(infile
, zonegroup
);
3702 if (zonegroup
.realm_id
.empty()) {
3703 zonegroup
.realm_id
= realm
.get_id();
3705 ret
= zonegroup
.create();
3706 if (ret
< 0 && ret
!= -EEXIST
) {
3707 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3709 } else if (ret
== -EEXIST
) {
3710 ret
= zonegroup
.update();
3712 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3718 ret
= zonegroup
.set_as_default();
3720 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3724 encode_json("zonegroup", zonegroup
, formatter
);
3725 formatter
->flush(cout
);
3728 case OPT_ZONEGROUP_REMOVE
:
3730 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3731 int ret
= zonegroup
.init(g_ceph_context
, store
);
3733 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3737 if (zone_id
.empty()) {
3738 if (zone_name
.empty()) {
3739 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
3742 // look up zone id by name
3743 for (auto& z
: zonegroup
.zones
) {
3744 if (zone_name
== z
.second
.name
) {
3745 zone_id
= z
.second
.id
;
3749 if (zone_id
.empty()) {
3750 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
3751 << zonegroup
.get_name() << std::endl
;
3756 ret
= zonegroup
.remove_zone(zone_id
);
3758 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
3762 encode_json("zonegroup", zonegroup
, formatter
);
3763 formatter
->flush(cout
);
3766 case OPT_ZONEGROUP_RENAME
:
3768 if (zonegroup_new_name
.empty()) {
3769 cerr
<< " missing zonegroup new name" << std::endl
;
3772 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3773 cerr
<< "no zonegroup name or id provided" << std::endl
;
3776 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3777 int ret
= zonegroup
.init(g_ceph_context
, store
);
3779 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3782 ret
= zonegroup
.rename(zonegroup_new_name
);
3784 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3789 case OPT_ZONEGROUP_PLACEMENT_LIST
:
3791 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3792 int ret
= zonegroup
.init(g_ceph_context
, store
);
3794 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3798 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3799 formatter
->flush(cout
);
3803 case OPT_ZONEGROUP_PLACEMENT_ADD
:
3804 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
3805 case OPT_ZONEGROUP_PLACEMENT_RM
:
3806 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
3808 if (placement_id
.empty()) {
3809 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
3813 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3814 int ret
= zonegroup
.init(g_ceph_context
, store
);
3816 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3820 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
3821 RGWZoneGroupPlacementTarget target
;
3822 target
.name
= placement_id
;
3823 for (auto& t
: tags
) {
3824 target
.tags
.insert(t
);
3826 zonegroup
.placement_targets
[placement_id
] = target
;
3827 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
3828 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
3829 if (!tags
.empty()) {
3830 target
.tags
.clear();
3831 for (auto& t
: tags
) {
3832 target
.tags
.insert(t
);
3835 target
.name
= placement_id
;
3836 for (auto& t
: tags_rm
) {
3837 target
.tags
.erase(t
);
3839 for (auto& t
: tags_add
) {
3840 target
.tags
.insert(t
);
3842 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
3843 zonegroup
.placement_targets
.erase(placement_id
);
3844 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
3845 if (!zonegroup
.placement_targets
.count(placement_id
)) {
3846 cerr
<< "failed to find a zonegroup placement target named '"
3847 << placement_id
<< "'" << std::endl
;
3850 zonegroup
.default_placement
= placement_id
;
3853 zonegroup
.post_process_params();
3854 ret
= zonegroup
.update();
3856 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3860 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3861 formatter
->flush(cout
);
3864 case OPT_ZONE_CREATE
:
3866 if (zone_name
.empty()) {
3867 cerr
<< "zone name not provided" << std::endl
;
3871 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3872 /* if the user didn't provide zonegroup info , create stand alone zone */
3873 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3874 ret
= zonegroup
.init(g_ceph_context
, store
);
3876 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3879 if (realm_id
.empty() && realm_name
.empty()) {
3880 realm_id
= zonegroup
.realm_id
;
3884 RGWZoneParams
zone(zone_id
, zone_name
);
3885 ret
= zone
.init(g_ceph_context
, store
, false);
3887 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3891 zone
.system_key
.id
= access_key
;
3892 zone
.system_key
.key
= secret_key
;
3893 zone
.realm_id
= realm_id
;
3894 zone
.tier_config
= tier_config_add
;
3896 ret
= zone
.create();
3898 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3902 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3903 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3904 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3905 ret
= zonegroup
.add_zone(zone
,
3906 (is_master_set
? &is_master
: NULL
),
3907 (is_read_only_set
? &read_only
: NULL
),
3911 sync_from
, sync_from_rm
);
3913 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
3914 << ": " << cpp_strerror(-ret
) << std::endl
;
3920 ret
= zone
.set_as_default();
3922 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3926 encode_json("zone", zone
, formatter
);
3927 formatter
->flush(cout
);
3931 case OPT_ZONE_DEFAULT
:
3933 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3934 int ret
= zonegroup
.init(g_ceph_context
, store
);
3936 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3938 if (zone_id
.empty() && zone_name
.empty()) {
3939 cerr
<< "no zone name or id provided" << std::endl
;
3942 RGWZoneParams
zone(zone_id
, zone_name
);
3943 ret
= zone
.init(g_ceph_context
, store
);
3945 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3948 ret
= zone
.set_as_default();
3950 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
3955 case OPT_ZONE_DELETE
:
3957 if (zone_id
.empty() && zone_name
.empty()) {
3958 cerr
<< "no zone name or id provided" << std::endl
;
3961 RGWZoneParams
zone(zone_id
, zone_name
);
3962 int ret
= zone
.init(g_ceph_context
, store
);
3964 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3968 list
<string
> zonegroups
;
3969 ret
= store
->list_zonegroups(zonegroups
);
3971 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3975 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
3976 RGWZoneGroup
zonegroup(string(), *iter
);
3977 int ret
= zonegroup
.init(g_ceph_context
, store
);
3979 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3982 ret
= zonegroup
.remove_zone(zone
.get_id());
3983 if (ret
< 0 && ret
!= -ENOENT
) {
3984 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
3985 << cpp_strerror(-ret
) << std::endl
;
3989 ret
= zone
.delete_obj();
3991 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3998 RGWZoneParams
zone(zone_id
, zone_name
);
3999 int ret
= zone
.init(g_ceph_context
, store
);
4001 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4004 encode_json("zone", zone
, formatter
);
4005 formatter
->flush(cout
);
4010 RGWZoneParams
zone(zone_name
);
4011 int ret
= zone
.init(g_ceph_context
, store
, false);
4017 if (ret
< 0 && ret
!= -ENOENT
) {
4018 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
4022 string orig_id
= zone
.get_id();
4024 ret
= read_decode_json(infile
, zone
);
4029 if(zone
.realm_id
.empty()) {
4030 RGWRealm
realm(realm_id
, realm_name
);
4031 int ret
= realm
.init(g_ceph_context
, store
);
4032 if (ret
< 0 && ret
!= -ENOENT
) {
4033 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4036 zone
.realm_id
= realm
.get_id();
4039 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
4040 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
4044 if (zone
.get_name().empty()) {
4045 zone
.set_name(zone_name
);
4046 if (zone
.get_name().empty()) {
4047 cerr
<< "no zone name specified" << std::endl
;
4052 zone_name
= zone
.get_name();
4054 if (zone
.get_id().empty()) {
4055 zone
.set_id(orig_id
);
4058 if (zone
.get_id().empty()) {
4059 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
4060 if (zone_name
.empty()) {
4061 cerr
<< "missing zone name" << std::endl
;
4064 zone
.set_name(zone_name
);
4065 zone
.set_id(zone_name
);
4068 cerr
<< "zone id " << zone
.get_id();
4069 ret
= zone
.fix_pool_names();
4071 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4074 ret
= zone
.write(false);
4076 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4081 ret
= zone
.set_as_default();
4083 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4087 encode_json("zone", zone
, formatter
);
4088 formatter
->flush(cout
);
4094 int ret
= store
->list_zones(zones
);
4096 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4101 ret
= zone
.init(g_ceph_context
, store
, false);
4103 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4106 string default_zone
;
4107 ret
= zone
.read_default_id(default_zone
);
4108 if (ret
< 0 && ret
!= -ENOENT
) {
4109 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4111 formatter
->open_object_section("zones_list");
4112 encode_json("default_info", default_zone
, formatter
);
4113 encode_json("zones", zones
, formatter
);
4114 formatter
->close_section();
4115 formatter
->flush(cout
);
4119 case OPT_ZONE_MODIFY
:
4121 RGWZoneParams
zone(zone_id
, zone_name
);
4122 int ret
= zone
.init(g_ceph_context
, store
);
4124 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4128 bool need_zone_update
= false;
4129 if (!access_key
.empty()) {
4130 zone
.system_key
.id
= access_key
;
4131 need_zone_update
= true;
4134 if (!secret_key
.empty()) {
4135 zone
.system_key
.key
= secret_key
;
4136 need_zone_update
= true;
4139 if (!realm_id
.empty()) {
4140 zone
.realm_id
= realm_id
;
4141 need_zone_update
= true;
4142 } else if (!realm_name
.empty()) {
4143 // get realm id from name
4144 RGWRealm realm
{g_ceph_context
, store
};
4145 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4147 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4150 need_zone_update
= true;
4153 for (auto add
: tier_config_add
) {
4154 zone
.tier_config
[add
.first
] = add
.second
;
4155 need_zone_update
= true;
4158 for (auto rm
: tier_config_rm
) {
4159 zone
.tier_config
.erase(rm
.first
);
4160 need_zone_update
= true;
4163 if (need_zone_update
) {
4164 ret
= zone
.update();
4166 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4171 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4172 ret
= zonegroup
.init(g_ceph_context
, store
);
4174 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4177 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4179 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4181 ret
= zonegroup
.add_zone(zone
,
4182 (is_master_set
? &is_master
: NULL
),
4183 (is_read_only_set
? &read_only
: NULL
),
4184 endpoints
, ptier_type
,
4185 psync_from_all
, sync_from
, sync_from_rm
);
4187 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4191 ret
= zonegroup
.update();
4193 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4198 ret
= zone
.set_as_default();
4200 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4204 encode_json("zone", zone
, formatter
);
4205 formatter
->flush(cout
);
4208 case OPT_ZONE_RENAME
:
4210 if (zone_new_name
.empty()) {
4211 cerr
<< " missing zone new name" << std::endl
;
4214 if (zone_id
.empty() && zone_name
.empty()) {
4215 cerr
<< "no zonegroup name or id provided" << std::endl
;
4218 RGWZoneParams
zone(zone_id
,zone_name
);
4219 int ret
= zone
.init(g_ceph_context
, store
);
4221 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4224 ret
= zone
.rename(zone_new_name
);
4226 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4230 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4231 ret
= zonegroup
.init(g_ceph_context
, store
);
4233 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4235 ret
= zonegroup
.rename_zone(zone
);
4236 if (ret
< 0 && ret
) {
4237 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4243 case OPT_ZONE_PLACEMENT_ADD
:
4244 case OPT_ZONE_PLACEMENT_MODIFY
:
4245 case OPT_ZONE_PLACEMENT_RM
:
4247 if (placement_id
.empty()) {
4248 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4251 RGWZoneParams
zone(zone_id
, zone_name
);
4252 int ret
= zone
.init(g_ceph_context
, store
);
4254 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4258 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4259 // pool names are required
4260 if (!index_pool
|| index_pool
->empty() ||
4261 !data_pool
|| data_pool
->empty()) {
4262 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4266 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4268 info
.index_pool
= *index_pool
;
4269 info
.data_pool
= *data_pool
;
4270 if (data_extra_pool
) {
4271 info
.data_extra_pool
= *data_extra_pool
;
4273 if (index_type_specified
) {
4274 info
.index_type
= placement_index_type
;
4276 if (compression_type
) {
4277 info
.compression_type
= *compression_type
;
4279 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4280 auto p
= zone
.placement_pools
.find(placement_id
);
4281 if (p
== zone
.placement_pools
.end()) {
4282 cerr
<< "ERROR: zone placement target '" << placement_id
4283 << "' not found" << std::endl
;
4286 auto& info
= p
->second
;
4287 if (index_pool
&& !index_pool
->empty()) {
4288 info
.index_pool
= *index_pool
;
4290 if (data_pool
&& !data_pool
->empty()) {
4291 info
.data_pool
= *data_pool
;
4293 if (data_extra_pool
) {
4294 info
.data_extra_pool
= *data_extra_pool
;
4296 if (index_type_specified
) {
4297 info
.index_type
= placement_index_type
;
4299 if (compression_type
) {
4300 info
.compression_type
= *compression_type
;
4302 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4303 zone
.placement_pools
.erase(placement_id
);
4306 ret
= zone
.update();
4308 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4312 encode_json("zone", zone
, formatter
);
4313 formatter
->flush(cout
);
4316 case OPT_ZONE_PLACEMENT_LIST
:
4318 RGWZoneParams
zone(zone_id
, zone_name
);
4319 int ret
= zone
.init(g_ceph_context
, store
);
4321 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4324 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4325 formatter
->flush(cout
);
4332 if (!user_id
.empty()) {
4333 user_op
.set_user_id(user_id
);
4334 bucket_op
.set_user_id(user_id
);
4337 if (!display_name
.empty())
4338 user_op
.set_display_name(display_name
);
4340 if (!user_email
.empty())
4341 user_op
.set_user_email(user_email
);
4343 if (!access_key
.empty())
4344 user_op
.set_access_key(access_key
);
4346 if (!secret_key
.empty())
4347 user_op
.set_secret_key(secret_key
);
4349 if (!subuser
.empty())
4350 user_op
.set_subuser(subuser
);
4353 user_op
.set_caps(caps
);
4355 user_op
.set_purge_data(purge_data
);
4358 user_op
.set_purge_keys();
4361 user_op
.set_generate_key();
4364 user_op
.set_gen_secret(); // assume that a key pair should be created
4366 if (max_buckets_specified
)
4367 user_op
.set_max_buckets(max_buckets
);
4369 if (admin_specified
)
4370 user_op
.set_admin(admin
);
4372 if (system_specified
)
4373 user_op
.set_system(system
);
4376 user_op
.set_perm(perm_mask
);
4378 if (set_temp_url_key
) {
4379 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4380 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4381 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4385 if (!op_mask_str
.empty()) {
4387 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4389 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4393 user_op
.set_op_mask(op_mask
);
4396 if (key_type
!= KEY_TYPE_UNDEFINED
)
4397 user_op
.set_key_type(key_type
);
4399 // set suspension operation parameters
4400 if (opt_cmd
== OPT_USER_ENABLE
)
4401 user_op
.set_suspension(false);
4402 else if (opt_cmd
== OPT_USER_SUSPEND
)
4403 user_op
.set_suspension(true);
4405 // RGWUser to use for user operations
4408 if (!user_id
.empty() || !subuser
.empty()) {
4409 ret
= user
.init(store
, user_op
);
4411 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4416 /* populate bucket operation */
4417 bucket_op
.set_bucket_name(bucket_name
);
4418 bucket_op
.set_object(object
);
4419 bucket_op
.set_check_objects(check_objects
);
4420 bucket_op
.set_delete_children(delete_child_objects
);
4421 bucket_op
.set_fix_index(fix
);
4422 bucket_op
.set_max_aio(max_concurrent_ios
);
4424 // required to gather errors from operations
4425 std::string err_msg
;
4427 bool output_user_info
= true;
4432 case OPT_USER_CREATE
:
4433 if (!user_op
.has_existing_user()) {
4434 user_op
.set_generate_key(); // generate a new key by default
4436 ret
= user
.add(user_op
, &err_msg
);
4438 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4439 if (ret
== -ERR_INVALID_TENANT_NAME
)
4444 if (!subuser
.empty()) {
4445 ret
= user
.subusers
.add(user_op
, &err_msg
);
4447 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4453 ret
= user
.remove(user_op
, &err_msg
);
4455 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4459 output_user_info
= false;
4461 case OPT_USER_ENABLE
:
4462 case OPT_USER_SUSPEND
:
4463 case OPT_USER_MODIFY
:
4464 ret
= user
.modify(user_op
, &err_msg
);
4466 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4471 case OPT_SUBUSER_CREATE
:
4472 ret
= user
.subusers
.add(user_op
, &err_msg
);
4474 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4479 case OPT_SUBUSER_MODIFY
:
4480 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4482 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4487 case OPT_SUBUSER_RM
:
4488 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4490 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4496 ret
= user
.caps
.add(user_op
, &err_msg
);
4498 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4504 ret
= user
.caps
.remove(user_op
, &err_msg
);
4506 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4511 case OPT_KEY_CREATE
:
4512 ret
= user
.keys
.add(user_op
, &err_msg
);
4514 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4520 ret
= user
.keys
.remove(user_op
, &err_msg
);
4522 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4526 case OPT_PERIOD_PUSH
:
4529 req_info
info(g_ceph_context
, &env
);
4530 info
.method
= "POST";
4531 info
.request_uri
= "/admin/realm/period";
4533 map
<string
, string
> ¶ms
= info
.args
.get_params();
4534 if (!realm_id
.empty())
4535 params
["realm_id"] = realm_id
;
4536 if (!realm_name
.empty())
4537 params
["realm_name"] = realm_name
;
4538 if (!period_id
.empty())
4539 params
["period_id"] = period_id
;
4540 if (!period_epoch
.empty())
4541 params
["epoch"] = period_epoch
;
4544 RGWPeriod
period(period_id
);
4545 int ret
= period
.init(g_ceph_context
, store
);
4547 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4550 // json format into a bufferlist
4551 JSONFormatter
jf(false);
4552 encode_json("period", period
, &jf
);
4557 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4560 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4565 case OPT_PERIOD_UPDATE
:
4567 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4568 commit
, remote
, url
, access_key
, secret_key
,
4569 formatter
, yes_i_really_mean_it
);
4575 case OPT_PERIOD_COMMIT
:
4577 // read realm and staging period
4578 RGWRealm
realm(realm_id
, realm_name
);
4579 int ret
= realm
.init(g_ceph_context
, store
);
4581 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4584 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4585 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4587 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4590 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4591 yes_i_really_mean_it
);
4593 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4597 encode_json("period", period
, formatter
);
4598 formatter
->flush(cout
);
4602 case OPT_ROLE_CREATE
:
4604 if (role_name
.empty()) {
4605 cerr
<< "ERROR: role name is empty" << std::endl
;
4609 if (assume_role_doc
.empty()) {
4610 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4613 /* The following two calls will be replaced by read_decode_json or something
4614 similar when the code for AWS Policies is in places */
4616 int ret
= read_input(assume_role_doc
, bl
);
4618 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4622 if (!p
.parse(bl
.c_str(), bl
.length())) {
4623 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4626 string trust_policy
= bl
.to_str();
4627 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4628 ret
= role
.create(true);
4632 show_role_info(role
, formatter
);
4635 case OPT_ROLE_DELETE
:
4637 if (role_name
.empty()) {
4638 cerr
<< "ERROR: empty role name" << std::endl
;
4641 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4642 ret
= role
.delete_obj();
4646 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4651 if (role_name
.empty()) {
4652 cerr
<< "ERROR: empty role name" << std::endl
;
4655 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4660 show_role_info(role
, formatter
);
4663 case OPT_ROLE_MODIFY
:
4665 if (role_name
.empty()) {
4666 cerr
<< "ERROR: role name is empty" << std::endl
;
4670 if (assume_role_doc
.empty()) {
4671 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4675 /* The following two calls will be replaced by read_decode_json or something
4676 similar when the code for AWS Policies is in place */
4678 int ret
= read_input(assume_role_doc
, bl
);
4680 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4684 if (!p
.parse(bl
.c_str(), bl
.length())) {
4685 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4688 string trust_policy
= bl
.to_str();
4689 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4694 role
.update_trust_policy(trust_policy
);
4695 ret
= role
.update();
4699 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4704 vector
<RGWRole
> result
;
4705 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4709 show_roles_info(result
, formatter
);
4712 case OPT_ROLE_POLICY_PUT
:
4714 if (role_name
.empty()) {
4715 cerr
<< "role name is empty" << std::endl
;
4719 if (policy_name
.empty()) {
4720 cerr
<< "policy name is empty" << std::endl
;
4724 if (perm_policy_doc
.empty()) {
4725 cerr
<< "permission policy document is empty" << std::endl
;
4729 /* The following two calls will be replaced by read_decode_json or something
4730 similar, when code for AWS Policies is in place.*/
4732 int ret
= read_input(perm_policy_doc
, bl
);
4734 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4738 if (!p
.parse(bl
.c_str(), bl
.length())) {
4739 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
4743 perm_policy
= bl
.c_str();
4745 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4750 role
.set_perm_policy(policy_name
, perm_policy
);
4751 ret
= role
.update();
4755 cout
<< "Permission policy attached successfully" << std::endl
;
4758 case OPT_ROLE_POLICY_LIST
:
4760 if (role_name
.empty()) {
4761 cerr
<< "ERROR: Role name is empty" << std::endl
;
4764 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4769 std::vector
<string
> policy_names
= role
.get_role_policy_names();
4770 show_policy_names(policy_names
, formatter
);
4773 case OPT_ROLE_POLICY_GET
:
4775 if (role_name
.empty()) {
4776 cerr
<< "ERROR: role name is empty" << std::endl
;
4780 if (policy_name
.empty()) {
4781 cerr
<< "ERROR: policy name is empty" << std::endl
;
4784 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4785 int ret
= role
.get();
4790 ret
= role
.get_role_policy(policy_name
, perm_policy
);
4794 show_perm_policy(perm_policy
, formatter
);
4797 case OPT_ROLE_POLICY_DELETE
:
4799 if (role_name
.empty()) {
4800 cerr
<< "ERROR: role name is empty" << std::endl
;
4804 if (policy_name
.empty()) {
4805 cerr
<< "ERROR: policy name is empty" << std::endl
;
4808 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4813 ret
= role
.delete_policy(policy_name
);
4817 ret
= role
.update();
4821 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
4822 << role_name
<< std::endl
;
4826 output_user_info
= false;
4829 // output the result of a user operation
4830 if (output_user_info
) {
4831 ret
= user
.info(info
, &err_msg
);
4833 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
4836 show_user_info(info
, formatter
);
4839 if (opt_cmd
== OPT_POLICY
) {
4840 if (format
== "xml") {
4841 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
4843 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4847 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
4849 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4855 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
4857 std::list
<std::string
> user_ids
;
4858 metadata_key
= "user";
4863 if (! user_id
.empty()) {
4864 user_ids
.push_back(user_id
.id
);
4866 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4869 /* list users in groups of max-keys, then perform user-bucket
4870 * limit-check on each group */
4871 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
4873 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
4874 << cpp_strerror(-ret
) << std::endl
;
4879 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
4881 if (ret
< 0 && ret
!= -ENOENT
) {
4882 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
4883 << cpp_strerror(-ret
) << std::endl
;
4886 /* ok, do the limit checks for this group */
4888 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4894 } while (truncated
);
4895 store
->meta_mgr
->list_keys_complete(handle
);
4898 } /* OPT_BUCKET_LIMIT_CHECK */
4900 if (opt_cmd
== OPT_BUCKETS_LIST
) {
4901 if (bucket_name
.empty()) {
4902 RGWBucketAdminOp::info(store
, bucket_op
, f
);
4904 RGWBucketInfo bucket_info
;
4905 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
4907 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
4910 formatter
->open_array_section("entries");
4913 if (max_entries
< 0)
4918 vector
<rgw_bucket_dir_entry
> result
;
4919 map
<string
, bool> common_prefixes
;
4922 RGWRados::Bucket
target(store
, bucket_info
);
4923 RGWRados::Bucket::List
list_op(&target
);
4925 list_op
.params
.prefix
= prefix
;
4926 list_op
.params
.delim
= delim
;
4927 list_op
.params
.marker
= rgw_obj_key(marker
);
4928 list_op
.params
.ns
= ns
;
4929 list_op
.params
.enforce_ns
= false;
4930 list_op
.params
.list_versions
= true;
4933 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
4935 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
4939 count
+= result
.size();
4941 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
4942 rgw_bucket_dir_entry
& entry
= *iter
;
4943 encode_json("entry", entry
, formatter
);
4945 formatter
->flush(cout
);
4946 } while (truncated
&& count
< max_entries
);
4948 formatter
->close_section();
4949 formatter
->flush(cout
);
4950 } /* have bucket_name */
4951 } /* OPT_BUCKETS_LIST */
4953 if (opt_cmd
== OPT_BUCKET_STATS
) {
4954 bucket_op
.set_fetch_stats(true);
4956 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
4958 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4963 if (opt_cmd
== OPT_BUCKET_LINK
) {
4964 bucket_op
.set_bucket_id(bucket_id
);
4966 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
4968 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4973 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
4974 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
4976 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
4981 if (opt_cmd
== OPT_LOG_LIST
) {
4983 if (date
.size() && date
.size() != 10) {
4984 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
4989 formatter
->open_array_section("logs");
4991 int r
= store
->log_list_init(date
, &h
);
4996 cerr
<< "log list: error " << r
<< std::endl
;
5001 int r
= store
->log_list_next(h
, &name
);
5005 cerr
<< "log list: error " << r
<< std::endl
;
5008 formatter
->dump_string("object", name
);
5011 formatter
->close_section();
5012 formatter
->flush(cout
);
5016 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5017 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5018 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5024 if (!object
.empty()) {
5034 if (opt_cmd
== OPT_LOG_SHOW
) {
5037 int r
= store
->log_show_init(oid
, &h
);
5039 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5044 formatter
->open_object_section("log");
5046 struct rgw_log_entry entry
;
5048 // peek at first entry to get bucket metadata
5049 r
= store
->log_show_next(h
, &entry
);
5051 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5054 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5055 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5056 formatter
->dump_string("bucket", entry
.bucket
);
5058 uint64_t agg_time
= 0;
5059 uint64_t agg_bytes_sent
= 0;
5060 uint64_t agg_bytes_received
= 0;
5061 uint64_t total_entries
= 0;
5063 if (show_log_entries
)
5064 formatter
->open_array_section("log_entries");
5067 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5069 agg_time
+= total_time
;
5070 agg_bytes_sent
+= entry
.bytes_sent
;
5071 agg_bytes_received
+= entry
.bytes_received
;
5074 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5075 entry
.bytes_received
== 0)
5078 if (show_log_entries
) {
5080 rgw_format_ops_log_entry(entry
, formatter
);
5081 formatter
->flush(cout
);
5084 r
= store
->log_show_next(h
, &entry
);
5088 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5091 if (show_log_entries
)
5092 formatter
->close_section();
5095 formatter
->open_object_section("log_sum");
5096 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5097 formatter
->dump_int("bytes_received", agg_bytes_received
);
5098 formatter
->dump_int("total_time", agg_time
);
5099 formatter
->dump_int("total_entries", total_entries
);
5100 formatter
->close_section();
5102 formatter
->close_section();
5103 formatter
->flush(cout
);
5106 if (opt_cmd
== OPT_LOG_RM
) {
5107 int r
= store
->log_remove(oid
);
5109 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5115 if (opt_cmd
== OPT_POOL_ADD
) {
5116 if (pool_name
.empty()) {
5117 cerr
<< "need to specify pool to add!" << std::endl
;
5122 int ret
= store
->add_bucket_placement(pool
);
5124 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5127 if (opt_cmd
== OPT_POOL_RM
) {
5128 if (pool_name
.empty()) {
5129 cerr
<< "need to specify pool to remove!" << std::endl
;
5134 int ret
= store
->remove_bucket_placement(pool
);
5136 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5139 if (opt_cmd
== OPT_POOLS_LIST
) {
5140 set
<rgw_pool
> pools
;
5141 int ret
= store
->list_placement_set(pools
);
5143 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5147 formatter
->open_array_section("pools");
5148 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5149 formatter
->open_object_section("pool");
5150 formatter
->dump_string("name", siter
->to_str());
5151 formatter
->close_section();
5153 formatter
->close_section();
5154 formatter
->flush(cout
);
5158 if (opt_cmd
== OPT_USAGE_SHOW
) {
5159 uint64_t start_epoch
= 0;
5160 uint64_t end_epoch
= (uint64_t)-1;
5164 if (!start_date
.empty()) {
5165 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5167 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5171 if (!end_date
.empty()) {
5172 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5174 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5180 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5181 show_log_entries
, show_log_sum
, &categories
,
5184 cerr
<< "ERROR: failed to show usage" << std::endl
;
5189 if (opt_cmd
== OPT_USAGE_TRIM
) {
5190 if (user_id
.empty() && !yes_i_really_mean_it
) {
5191 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5192 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5196 uint64_t start_epoch
= 0;
5197 uint64_t end_epoch
= (uint64_t)-1;
5200 if (!start_date
.empty()) {
5201 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5203 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5208 if (!end_date
.empty()) {
5209 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5211 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5216 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5218 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5223 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5224 if (bucket_name
.empty()) {
5225 cerr
<< "ERROR: bucket not specified" << std::endl
;
5228 if (object
.empty()) {
5229 cerr
<< "ERROR: object not specified" << std::endl
;
5234 if (opt_cmd
== OPT_OLH_GET
) {
5235 RGWBucketInfo bucket_info
;
5236 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5238 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5242 rgw_obj
obj(bucket
, object
);
5243 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5245 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5248 encode_json("olh", olh
, formatter
);
5249 formatter
->flush(cout
);
5252 if (opt_cmd
== OPT_OLH_READLOG
) {
5253 RGWBucketInfo bucket_info
;
5254 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5256 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5259 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5262 RGWObjectCtx
rctx(store
);
5263 rgw_obj
obj(bucket
, object
);
5267 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5272 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5274 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5277 formatter
->open_object_section("result");
5278 encode_json("is_truncated", is_truncated
, formatter
);
5279 encode_json("log", log
, formatter
);
5280 formatter
->close_section();
5281 formatter
->flush(cout
);
5284 if (opt_cmd
== OPT_BI_GET
) {
5285 RGWBucketInfo bucket_info
;
5286 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5288 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5291 rgw_obj
obj(bucket
, object
);
5292 if (!object_version
.empty()) {
5293 obj
.key
.set_instance(object_version
);
5296 rgw_cls_bi_entry entry
;
5298 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5300 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5304 encode_json("entry", entry
, formatter
);
5305 formatter
->flush(cout
);
5308 if (opt_cmd
== OPT_BI_PUT
) {
5309 RGWBucketInfo bucket_info
;
5310 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5312 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5316 rgw_cls_bi_entry entry
;
5317 cls_rgw_obj_key key
;
5318 ret
= read_decode_json(infile
, entry
, &key
);
5323 rgw_obj
obj(bucket
, key
);
5325 ret
= store
->bi_put(bucket
, obj
, entry
);
5327 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5332 if (opt_cmd
== OPT_BI_LIST
) {
5333 if (bucket_name
.empty()) {
5334 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5337 RGWBucketInfo bucket_info
;
5338 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5340 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5344 list
<rgw_cls_bi_entry
> entries
;
5346 if (max_entries
< 0) {
5350 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5352 formatter
->open_array_section("entries");
5354 for (int i
= 0; i
< max_shards
; i
++) {
5355 RGWRados::BucketShard
bs(store
);
5356 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5357 int ret
= bs
.init(bucket
, shard_id
);
5361 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5367 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5369 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5373 list
<rgw_cls_bi_entry
>::iterator iter
;
5374 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5375 rgw_cls_bi_entry
& entry
= *iter
;
5376 encode_json("entry", entry
, formatter
);
5379 formatter
->flush(cout
);
5380 } while (is_truncated
);
5381 formatter
->flush(cout
);
5383 formatter
->close_section();
5384 formatter
->flush(cout
);
5387 if (opt_cmd
== OPT_BI_PURGE
) {
5388 if (bucket_name
.empty()) {
5389 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5392 RGWBucketInfo bucket_info
;
5393 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5395 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5399 RGWBucketInfo cur_bucket_info
;
5400 rgw_bucket cur_bucket
;
5401 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5403 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5407 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5408 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5409 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5413 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5415 for (int i
= 0; i
< max_shards
; i
++) {
5416 RGWRados::BucketShard
bs(store
);
5417 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5418 int ret
= bs
.init(bucket
, shard_id
);
5420 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5424 ret
= store
->bi_remove(bs
);
5426 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5432 if (opt_cmd
== OPT_OBJECT_RM
) {
5433 RGWBucketInfo bucket_info
;
5434 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5436 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5439 rgw_obj_key
key(object
, object_version
);
5440 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5443 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5448 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5449 if (bucket_name
.empty()) {
5450 cerr
<< "ERROR: bucket not specified" << std::endl
;
5453 if (object
.empty()) {
5454 cerr
<< "ERROR: object not specified" << std::endl
;
5458 RGWBucketInfo bucket_info
;
5459 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5461 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5465 rgw_obj
obj(bucket
, object
);
5466 obj
.key
.set_instance(object_version
);
5467 bool need_rewrite
= true;
5468 if (min_rewrite_stripe_size
> 0) {
5469 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5471 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5475 ret
= store
->rewrite_obj(bucket_info
, obj
);
5477 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5481 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5485 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5486 int ret
= store
->process_expire_objects();
5488 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5493 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5494 if (bucket_name
.empty()) {
5495 cerr
<< "ERROR: bucket not specified" << std::endl
;
5499 RGWBucketInfo bucket_info
;
5500 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5502 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5506 uint64_t start_epoch
= 0;
5507 uint64_t end_epoch
= 0;
5509 if (!end_date
.empty()) {
5510 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5512 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5516 if (!start_date
.empty()) {
5517 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5519 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5524 bool is_truncated
= true;
5526 rgw_obj_index_key marker
;
5529 formatter
->open_object_section("result");
5530 formatter
->dump_string("bucket", bucket_name
);
5531 formatter
->open_array_section("objects");
5532 while (is_truncated
) {
5533 map
<string
, rgw_bucket_dir_entry
> result
;
5534 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5535 result
, &is_truncated
, &marker
,
5536 bucket_object_check_filter
);
5538 if (r
< 0 && r
!= -ENOENT
) {
5539 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5545 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5546 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5547 rgw_obj_key key
= iter
->second
.key
;
5548 rgw_bucket_dir_entry
& entry
= iter
->second
;
5550 formatter
->open_object_section("object");
5551 formatter
->dump_string("name", key
.name
);
5552 formatter
->dump_string("instance", key
.instance
);
5553 formatter
->dump_int("size", entry
.meta
.size
);
5554 utime_t
ut(entry
.meta
.mtime
);
5555 ut
.gmtime(formatter
->dump_stream("mtime"));
5557 if ((entry
.meta
.size
< min_rewrite_size
) ||
5558 (entry
.meta
.size
> max_rewrite_size
) ||
5559 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5560 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5561 formatter
->dump_string("status", "Skipped");
5563 rgw_obj
obj(bucket
, key
);
5565 bool need_rewrite
= true;
5566 if (min_rewrite_stripe_size
> 0) {
5567 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5569 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5572 if (!need_rewrite
) {
5573 formatter
->dump_string("status", "Skipped");
5575 r
= store
->rewrite_obj(bucket_info
, obj
);
5577 formatter
->dump_string("status", "Success");
5579 formatter
->dump_string("status", cpp_strerror(-r
));
5583 formatter
->dump_int("flags", entry
.flags
);
5585 formatter
->close_section();
5586 formatter
->flush(cout
);
5589 formatter
->close_section();
5590 formatter
->close_section();
5591 formatter
->flush(cout
);
5594 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5596 RGWBucketInfo bucket_info
;
5597 map
<string
, bufferlist
> attrs
;
5599 int ret
= check_reshard_bucket_params(store
,
5603 num_shards_specified
,
5605 yes_i_really_mean_it
,
5613 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5615 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5616 if (max_entries
< 1) {
5617 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5620 return br
.execute(num_shards
, max_entries
,
5621 verbose
, &cout
, formatter
);
5624 if (opt_cmd
== OPT_RESHARD_ADD
) {
5626 RGWBucketInfo bucket_info
;
5627 map
<string
, bufferlist
> attrs
;
5629 int ret
= check_reshard_bucket_params(store
,
5633 num_shards_specified
,
5635 yes_i_really_mean_it
,
5643 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5645 RGWReshard
reshard(store
);
5646 cls_rgw_reshard_entry entry
;
5647 entry
.time
= real_clock::now();
5648 entry
.tenant
= tenant
;
5649 entry
.bucket_name
= bucket_name
;
5650 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5651 entry
.old_num_shards
= num_source_shards
;
5652 entry
.new_num_shards
= num_shards
;
5654 return reshard
.add(entry
);
5657 if (opt_cmd
== OPT_RESHARD_LIST
) {
5658 list
<cls_rgw_reshard_entry
> entries
;
5661 if (max_entries
< 0) {
5665 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5667 RGWReshard
reshard(store
);
5669 formatter
->open_array_section("reshard");
5670 for (int i
= 0; i
< num_logshards
; i
++) {
5671 bool is_truncated
= true;
5675 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5677 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5680 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5681 cls_rgw_reshard_entry
& entry
= *iter
;
5682 encode_json("entry", entry
, formatter
);
5683 entry
.get_key(&marker
);
5685 count
+= entries
.size();
5686 formatter
->flush(cout
);
5687 } while (is_truncated
&& count
< max_entries
);
5689 if (count
>= max_entries
) {
5694 formatter
->close_section();
5695 formatter
->flush(cout
);
5700 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5701 if (bucket_name
.empty()) {
5702 cerr
<< "ERROR: bucket not specified" << std::endl
;
5707 RGWBucketInfo bucket_info
;
5708 map
<string
, bufferlist
> attrs
;
5709 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5711 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5715 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5716 list
<cls_rgw_bucket_instance_entry
> status
;
5717 int r
= br
.get_status(&status
);
5719 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5723 encode_json("status", status
, formatter
);
5724 formatter
->flush(cout
);
5727 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5728 RGWReshard
reshard(store
, true, &cout
);
5730 int ret
= reshard
.process_all_logshards();
5732 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
5737 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
5738 RGWReshard
reshard(store
);
5740 if (bucket_name
.empty()) {
5741 cerr
<< "ERROR: bucket not specified" << std::endl
;
5744 cls_rgw_reshard_entry entry
;
5745 //entry.tenant = tenant;
5746 entry
.bucket_name
= bucket_name
;
5747 //entry.bucket_id = bucket_id;
5748 int ret
= reshard
.get(entry
);
5750 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5754 /* TBD stop running resharding */
5756 ret
=reshard
.remove(entry
);
5758 cerr
<< "Error removing bucket " << bucket_name
<< " for resharding queue: " << cpp_strerror(-ret
) <<
5764 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
5765 RGWBucketInfo bucket_info
;
5766 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5768 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5771 list
<rgw_obj_index_key
> oid_list
;
5772 rgw_obj_key
key(object
, object_version
);
5773 rgw_obj_index_key index_key
;
5774 key
.get_index_key(&index_key
);
5775 oid_list
.push_back(index_key
);
5776 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
5778 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
5783 if (opt_cmd
== OPT_OBJECT_STAT
) {
5784 RGWBucketInfo bucket_info
;
5785 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5787 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5790 rgw_obj
obj(bucket
, object
);
5791 obj
.key
.set_instance(object_version
);
5794 map
<string
, bufferlist
> attrs
;
5795 RGWObjectCtx
obj_ctx(store
);
5796 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
5797 RGWRados::Object::Read
read_op(&op_target
);
5799 read_op
.params
.attrs
= &attrs
;
5800 read_op
.params
.obj_size
= &obj_size
;
5802 ret
= read_op
.prepare();
5804 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
5807 formatter
->open_object_section("object_metadata");
5808 formatter
->dump_string("name", object
);
5809 formatter
->dump_unsigned("size", obj_size
);
5811 map
<string
, bufferlist
>::iterator iter
;
5812 map
<string
, bufferlist
> other_attrs
;
5813 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5814 bufferlist
& bl
= iter
->second
;
5815 bool handled
= false;
5816 if (iter
->first
== RGW_ATTR_MANIFEST
) {
5817 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
5818 } else if (iter
->first
== RGW_ATTR_ACL
) {
5819 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
5820 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
5821 handled
= dump_string("tag", bl
, formatter
);
5822 } else if (iter
->first
== RGW_ATTR_ETAG
) {
5823 handled
= dump_string("etag", bl
, formatter
);
5827 other_attrs
[iter
->first
] = bl
;
5830 formatter
->open_object_section("attrs");
5831 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
5832 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
5834 formatter
->close_section();
5835 formatter
->close_section();
5836 formatter
->flush(cout
);
5839 if (opt_cmd
== OPT_BUCKET_CHECK
) {
5840 if (check_head_obj_locator
) {
5841 if (bucket_name
.empty()) {
5842 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
5845 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
5847 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
5851 if (opt_cmd
== OPT_BUCKET_RM
) {
5852 if (inconsistent_index
== false) {
5853 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
5855 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
5859 if (opt_cmd
== OPT_GC_LIST
) {
5862 formatter
->open_array_section("entries");
5865 list
<cls_rgw_gc_obj_info
> result
;
5866 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
5868 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5873 list
<cls_rgw_gc_obj_info
>::iterator iter
;
5874 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5875 cls_rgw_gc_obj_info
& info
= *iter
;
5876 formatter
->open_object_section("chain_info");
5877 formatter
->dump_string("tag", info
.tag
);
5878 formatter
->dump_stream("time") << info
.time
;
5879 formatter
->open_array_section("objs");
5880 list
<cls_rgw_obj
>::iterator liter
;
5881 cls_rgw_obj_chain
& chain
= info
.chain
;
5882 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
5883 cls_rgw_obj
& obj
= *liter
;
5884 encode_json("obj", obj
, formatter
);
5886 formatter
->close_section(); // objs
5887 formatter
->close_section(); // obj_chain
5888 formatter
->flush(cout
);
5890 } while (truncated
);
5891 formatter
->close_section();
5892 formatter
->flush(cout
);
5895 if (opt_cmd
== OPT_GC_PROCESS
) {
5896 int ret
= store
->process_gc();
5898 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5903 if (opt_cmd
== OPT_LC_LIST
) {
5904 formatter
->open_array_section("lifecycle_list");
5905 map
<string
, int> bucket_lc_map
;
5907 #define MAX_LC_LIST_ENTRIES 100
5908 if (max_entries
< 0) {
5909 max_entries
= MAX_LC_LIST_ENTRIES
;
5912 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
5914 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5917 map
<string
, int>::iterator iter
;
5918 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
5919 formatter
->open_object_section("bucket_lc_info");
5920 formatter
->dump_string("bucket", iter
->first
);
5921 string lc_status
= LC_STATUS
[iter
->second
];
5922 formatter
->dump_string("status", lc_status
);
5923 formatter
->close_section(); // objs
5924 formatter
->flush(cout
);
5925 marker
= iter
->first
;
5927 } while (!bucket_lc_map
.empty());
5929 formatter
->close_section(); //lifecycle list
5930 formatter
->flush(cout
);
5934 if (opt_cmd
== OPT_LC_PROCESS
) {
5935 int ret
= store
->process_lc();
5937 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5942 if (opt_cmd
== OPT_ORPHANS_FIND
) {
5943 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5945 if (job_id
.empty()) {
5946 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5949 if (pool_name
.empty()) {
5950 cerr
<< "ERROR: --pool not specified" << std::endl
;
5954 RGWOrphanSearchInfo info
;
5957 info
.job_name
= job_id
;
5958 info
.num_shards
= num_shards
;
5960 int ret
= search
.init(job_id
, &info
);
5962 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
5971 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
5972 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5974 if (job_id
.empty()) {
5975 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5978 int ret
= search
.init(job_id
, NULL
);
5980 if (ret
== -ENOENT
) {
5981 cerr
<< "job not found" << std::endl
;
5985 ret
= search
.finish();
5991 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
5992 RGWOrphanStore
orphan_store(store
);
5993 int ret
= orphan_store
.init();
5995 cerr
<< "connection to cluster failed!" << std::endl
;
5999 map
<string
,RGWOrphanSearchState
> m
;
6000 ret
= orphan_store
.list_jobs(m
);
6002 cerr
<< "job list failed" << std::endl
;
6005 formatter
->open_array_section("entries");
6006 for (const auto &it
: m
){
6008 formatter
->dump_string("job-id",it
.first
);
6010 encode_json("orphan_search_state", it
.second
, formatter
);
6013 formatter
->close_section();
6014 formatter
->flush(cout
);
6017 if (opt_cmd
== OPT_USER_CHECK
) {
6018 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6021 if (opt_cmd
== OPT_USER_STATS
) {
6023 if (!bucket_name
.empty()) {
6024 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6026 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
6030 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6032 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
6038 if (user_id
.empty()) {
6039 cerr
<< "ERROR: uid not specified" << std::endl
;
6042 cls_user_header header
;
6043 string user_str
= user_id
.to_str();
6044 int ret
= store
->cls_user_get_header(user_str
, &header
);
6046 if (ret
== -ENOENT
) { /* in case of ENOENT */
6047 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6049 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6054 encode_json("header", header
, formatter
);
6055 formatter
->flush(cout
);
6058 if (opt_cmd
== OPT_METADATA_GET
) {
6059 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6061 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6065 formatter
->flush(cout
);
6068 if (opt_cmd
== OPT_METADATA_PUT
) {
6070 int ret
= read_input(infile
, bl
);
6072 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6075 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6077 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6082 if (opt_cmd
== OPT_METADATA_RM
) {
6083 int ret
= store
->meta_mgr
->remove(metadata_key
);
6085 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6090 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6091 if (opt_cmd
== OPT_USER_LIST
) {
6092 metadata_key
= "user";
6096 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
6098 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6104 formatter
->open_array_section("keys");
6108 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, keys
, &truncated
);
6109 if (ret
< 0 && ret
!= -ENOENT
) {
6110 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6112 } if (ret
!= -ENOENT
) {
6113 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6114 formatter
->dump_string("key", *iter
);
6116 formatter
->flush(cout
);
6118 } while (truncated
);
6120 formatter
->close_section();
6121 formatter
->flush(cout
);
6123 store
->meta_mgr
->list_keys_complete(handle
);
6126 if (opt_cmd
== OPT_MDLOG_LIST
) {
6127 utime_t start_time
, end_time
;
6129 int ret
= parse_date_str(start_date
, start_time
);
6133 ret
= parse_date_str(end_date
, end_time
);
6137 int i
= (specified_shard_id
? shard_id
: 0);
6139 if (period_id
.empty()) {
6140 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6144 std::cerr
<< "No --period given, using current period="
6145 << period_id
<< std::endl
;
6147 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6149 formatter
->open_array_section("entries");
6150 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6152 list
<cls_log_entry
> entries
;
6155 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6158 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6160 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6164 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6165 cls_log_entry
& entry
= *iter
;
6166 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6168 formatter
->flush(cout
);
6169 } while (truncated
);
6171 meta_log
->complete_list_entries(handle
);
6173 if (specified_shard_id
)
6178 formatter
->close_section();
6179 formatter
->flush(cout
);
6182 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6183 int i
= (specified_shard_id
? shard_id
: 0);
6185 if (period_id
.empty()) {
6186 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6190 std::cerr
<< "No --period given, using current period="
6191 << period_id
<< std::endl
;
6193 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6195 formatter
->open_array_section("entries");
6197 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6198 RGWMetadataLogInfo info
;
6199 meta_log
->get_info(i
, &info
);
6201 ::encode_json("info", info
, formatter
);
6203 if (specified_shard_id
)
6208 formatter
->close_section();
6209 formatter
->flush(cout
);
6212 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6213 // need a full history for purging old mdlog periods
6214 store
->meta_mgr
->init_oldest_log_period();
6216 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6217 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6218 int ret
= http
.set_threaded();
6220 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6224 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6225 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6227 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6232 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6233 utime_t start_time
, end_time
;
6235 if (!specified_shard_id
) {
6236 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6240 int ret
= parse_date_str(start_date
, start_time
);
6244 ret
= parse_date_str(end_date
, end_time
);
6248 if (period_id
.empty()) {
6249 std::cerr
<< "missing --period argument" << std::endl
;
6252 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6254 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6256 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6261 if (opt_cmd
== OPT_SYNC_STATUS
) {
6262 sync_status(formatter
);
6265 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6266 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6268 int ret
= sync
.init();
6270 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6274 rgw_meta_sync_status sync_status
;
6275 ret
= sync
.read_sync_status(&sync_status
);
6277 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6281 formatter
->open_object_section("summary");
6282 encode_json("sync_status", sync_status
, formatter
);
6284 uint64_t full_total
= 0;
6285 uint64_t full_complete
= 0;
6287 for (auto marker_iter
: sync_status
.sync_markers
) {
6288 full_total
+= marker_iter
.second
.total_entries
;
6289 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6290 full_complete
+= marker_iter
.second
.pos
;
6292 full_complete
+= marker_iter
.second
.total_entries
;
6296 formatter
->open_object_section("full_sync");
6297 encode_json("total", full_total
, formatter
);
6298 encode_json("complete", full_complete
, formatter
);
6299 formatter
->close_section();
6300 formatter
->close_section();
6302 formatter
->flush(cout
);
6306 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6307 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6309 int ret
= sync
.init();
6311 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6314 ret
= sync
.init_sync_status();
6316 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6322 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6323 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6325 int ret
= sync
.init();
6327 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6333 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6338 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6339 if (source_zone
.empty()) {
6340 cerr
<< "ERROR: source zone not specified" << std::endl
;
6343 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6345 int ret
= sync
.init();
6347 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6351 rgw_data_sync_status sync_status
;
6352 ret
= sync
.read_sync_status(&sync_status
);
6353 if (ret
< 0 && ret
!= -ENOENT
) {
6354 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6358 formatter
->open_object_section("summary");
6359 encode_json("sync_status", sync_status
, formatter
);
6361 uint64_t full_total
= 0;
6362 uint64_t full_complete
= 0;
6364 for (auto marker_iter
: sync_status
.sync_markers
) {
6365 full_total
+= marker_iter
.second
.total_entries
;
6366 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6367 full_complete
+= marker_iter
.second
.pos
;
6369 full_complete
+= marker_iter
.second
.total_entries
;
6373 formatter
->open_object_section("full_sync");
6374 encode_json("total", full_total
, formatter
);
6375 encode_json("complete", full_complete
, formatter
);
6376 formatter
->close_section();
6377 formatter
->close_section();
6379 formatter
->flush(cout
);
6382 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6383 if (source_zone
.empty()) {
6384 cerr
<< "ERROR: source zone not specified" << std::endl
;
6387 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6389 int ret
= sync
.init();
6391 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6395 ret
= sync
.init_sync_status();
6397 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6402 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6403 if (source_zone
.empty()) {
6404 cerr
<< "ERROR: source zone not specified" << std::endl
;
6407 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6409 int ret
= sync
.init();
6411 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6417 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6422 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6423 if (source_zone
.empty()) {
6424 cerr
<< "ERROR: source zone not specified" << std::endl
;
6427 if (bucket_name
.empty()) {
6428 cerr
<< "ERROR: bucket not specified" << std::endl
;
6432 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6436 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6440 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6443 ret
= sync
.init_sync_status();
6445 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6450 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
6451 if (bucket_name
.empty()) {
6452 cerr
<< "ERROR: bucket not specified" << std::endl
;
6457 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
6461 ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
, true);
6463 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
6467 if (!store
->is_meta_master()) {
6468 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
6469 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
6473 rgw_obj
obj(bucket
, object
);
6474 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
6479 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6480 if (source_zone
.empty()) {
6481 cerr
<< "ERROR: source zone not specified" << std::endl
;
6484 if (bucket_name
.empty()) {
6485 cerr
<< "ERROR: bucket not specified" << std::endl
;
6489 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6493 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6497 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6500 ret
= sync
.read_sync_status();
6502 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6506 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6508 encode_json("sync_status", sync_status
, formatter
);
6509 formatter
->flush(cout
);
6512 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6513 if (source_zone
.empty()) {
6514 cerr
<< "ERROR: source zone not specified" << std::endl
;
6517 if (bucket_name
.empty()) {
6518 cerr
<< "ERROR: bucket not specified" << std::endl
;
6522 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6526 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6530 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6536 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6541 if (opt_cmd
== OPT_BILOG_LIST
) {
6542 if (bucket_name
.empty()) {
6543 cerr
<< "ERROR: bucket not specified" << std::endl
;
6546 RGWBucketInfo bucket_info
;
6547 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6549 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6552 formatter
->open_array_section("entries");
6555 if (max_entries
< 0)
6559 list
<rgw_bi_log_entry
> entries
;
6560 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6562 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6566 count
+= entries
.size();
6568 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6569 rgw_bi_log_entry
& entry
= *iter
;
6570 encode_json("entry", entry
, formatter
);
6574 formatter
->flush(cout
);
6575 } while (truncated
&& count
< max_entries
);
6577 formatter
->close_section();
6578 formatter
->flush(cout
);
6581 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6582 if (max_entries
< 0) {
6587 utime_t start_time
, end_time
;
6589 int ret
= parse_date_str(start_date
, start_time
);
6593 ret
= parse_date_str(end_date
, end_time
);
6601 formatter
->open_array_section("entries");
6603 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6604 formatter
->open_object_section("shard");
6605 encode_json("shard_id", shard_id
, formatter
);
6606 formatter
->open_array_section("entries");
6609 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6612 list
<cls_log_entry
> entries
;
6613 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6614 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6615 if (ret
== -ENOENT
) {
6619 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6623 count
+= entries
.size();
6625 for (auto& cls_entry
: entries
) {
6626 rgw_sync_error_info log_entry
;
6628 auto iter
= cls_entry
.data
.begin();
6630 ::decode(log_entry
, iter
);
6631 } catch (buffer::error
& err
) {
6632 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6635 formatter
->open_object_section("entry");
6636 encode_json("id", cls_entry
.id
, formatter
);
6637 encode_json("section", cls_entry
.section
, formatter
);
6638 encode_json("name", cls_entry
.name
, formatter
);
6639 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
6640 encode_json("info", log_entry
, formatter
);
6641 formatter
->close_section();
6642 formatter
->flush(cout
);
6644 } while (truncated
&& count
< max_entries
);
6646 formatter
->close_section();
6647 formatter
->close_section();
6649 if (specified_shard_id
) {
6654 formatter
->close_section();
6655 formatter
->flush(cout
);
6658 if (opt_cmd
== OPT_BILOG_TRIM
) {
6659 if (bucket_name
.empty()) {
6660 cerr
<< "ERROR: bucket not specified" << std::endl
;
6663 RGWBucketInfo bucket_info
;
6664 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6666 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6669 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
6671 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6676 if (opt_cmd
== OPT_BILOG_STATUS
) {
6677 if (bucket_name
.empty()) {
6678 cerr
<< "ERROR: bucket not specified" << std::endl
;
6681 RGWBucketInfo bucket_info
;
6682 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6684 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6687 map
<int, string
> markers
;
6688 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
6690 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
6693 formatter
->open_object_section("entries");
6694 encode_json("markers", markers
, formatter
);
6695 formatter
->close_section();
6696 formatter
->flush(cout
);
6699 if (opt_cmd
== OPT_DATALOG_LIST
) {
6700 formatter
->open_array_section("entries");
6703 if (max_entries
< 0)
6706 utime_t start_time
, end_time
;
6708 int ret
= parse_date_str(start_date
, start_time
);
6712 ret
= parse_date_str(end_date
, end_time
);
6716 RGWDataChangesLog
*log
= store
->data_log
;
6717 RGWDataChangesLog::LogMarker marker
;
6720 list
<rgw_data_change_log_entry
> entries
;
6721 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
6723 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6727 count
+= entries
.size();
6729 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6730 rgw_data_change_log_entry
& entry
= *iter
;
6732 encode_json("entry", entry
.entry
, formatter
);
6734 encode_json("entry", entry
, formatter
);
6737 formatter
->flush(cout
);
6738 } while (truncated
&& count
< max_entries
);
6740 formatter
->close_section();
6741 formatter
->flush(cout
);
6744 if (opt_cmd
== OPT_DATALOG_STATUS
) {
6745 RGWDataChangesLog
*log
= store
->data_log
;
6746 int i
= (specified_shard_id
? shard_id
: 0);
6748 formatter
->open_array_section("entries");
6749 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
6750 list
<cls_log_entry
> entries
;
6752 RGWDataChangesLogInfo info
;
6753 log
->get_info(i
, &info
);
6755 ::encode_json("info", info
, formatter
);
6757 if (specified_shard_id
)
6761 formatter
->close_section();
6762 formatter
->flush(cout
);
6765 if (opt_cmd
== OPT_DATALOG_TRIM
) {
6766 utime_t start_time
, end_time
;
6768 int ret
= parse_date_str(start_date
, start_time
);
6772 ret
= parse_date_str(end_date
, end_time
);
6776 RGWDataChangesLog
*log
= store
->data_log
;
6777 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6779 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
6784 if (opt_cmd
== OPT_OPSTATE_LIST
) {
6785 RGWOpState
oc(store
);
6790 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
6791 list
<cls_statelog_entry
> entries
;
6793 formatter
->open_array_section("entries");
6795 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
6797 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
6798 oc
.finish_list_entries(handle
);
6802 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6803 oc
.dump_entry(*iter
, formatter
);
6806 formatter
->flush(cout
);
6808 formatter
->close_section();
6809 formatter
->flush(cout
);
6810 oc
.finish_list_entries(handle
);
6813 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
6814 RGWOpState
oc(store
);
6816 RGWOpState::OpState state
;
6817 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6818 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6821 if (state_str
.empty()) {
6822 cerr
<< "ERROR: state was not specified" << std::endl
;
6825 int ret
= oc
.state_from_str(state_str
, &state
);
6827 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
6831 if (opt_cmd
== OPT_OPSTATE_SET
) {
6832 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
6834 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6838 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
6840 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
6845 if (opt_cmd
== OPT_OPSTATE_RM
) {
6846 RGWOpState
oc(store
);
6848 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6849 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6852 ret
= oc
.remove_entry(client_id
, op_id
, object
);
6854 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6859 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
6860 opt_cmd
== OPT_REPLICALOG_DELETE
) {
6861 if (replica_log_type_str
.empty()) {
6862 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
6867 if (opt_cmd
== OPT_REPLICALOG_GET
) {
6868 RGWReplicaBounds bounds
;
6869 if (replica_log_type
== ReplicaLog_Metadata
) {
6870 if (!specified_shard_id
) {
6871 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6875 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6876 int ret
= logger
.get_bounds(shard_id
, bounds
);
6879 } else if (replica_log_type
== ReplicaLog_Data
) {
6880 if (!specified_shard_id
) {
6881 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6884 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6885 int ret
= logger
.get_bounds(shard_id
, bounds
);
6888 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6889 if (bucket_name
.empty()) {
6890 cerr
<< "ERROR: bucket not specified" << std::endl
;
6893 RGWBucketInfo bucket_info
;
6894 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6896 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6900 RGWReplicaBucketLogger
logger(store
);
6901 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
6904 } else { // shouldn't get here
6907 encode_json("bounds", bounds
, formatter
);
6908 formatter
->flush(cout
);
6912 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
6913 if (replica_log_type
== ReplicaLog_Metadata
) {
6914 if (!specified_shard_id
) {
6915 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6918 if (!specified_daemon_id
) {
6919 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6922 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6923 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6926 } else if (replica_log_type
== ReplicaLog_Data
) {
6927 if (!specified_shard_id
) {
6928 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6931 if (!specified_daemon_id
) {
6932 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6935 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6936 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6939 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6940 if (bucket_name
.empty()) {
6941 cerr
<< "ERROR: bucket not specified" << std::endl
;
6944 RGWBucketInfo bucket_info
;
6945 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6947 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6951 RGWReplicaBucketLogger
logger(store
);
6952 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
6958 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
6959 if (marker
.empty()) {
6960 cerr
<< "ERROR: marker was not specified" <<std::endl
;
6963 utime_t time
= ceph_clock_now();
6964 if (!date
.empty()) {
6965 ret
= parse_date_str(date
, time
);
6967 cerr
<< "ERROR: failed to parse start date" << std::endl
;
6971 list
<RGWReplicaItemMarker
> entries
;
6972 int ret
= read_decode_json(infile
, entries
);
6974 cerr
<< "ERROR: failed to decode entries" << std::endl
;
6977 RGWReplicaBounds bounds
;
6978 if (replica_log_type
== ReplicaLog_Metadata
) {
6979 if (!specified_shard_id
) {
6980 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6984 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6985 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6987 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6990 } else if (replica_log_type
== ReplicaLog_Data
) {
6991 if (!specified_shard_id
) {
6992 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6995 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6996 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6998 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7001 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7002 if (bucket_name
.empty()) {
7003 cerr
<< "ERROR: bucket not specified" << std::endl
;
7006 RGWBucketInfo bucket_info
;
7007 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7009 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7013 RGWReplicaBucketLogger
logger(store
);
7014 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
7016 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7022 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7025 if (bucket_name
.empty() && user_id
.empty()) {
7026 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7030 if (!bucket_name
.empty()) {
7031 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7032 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7035 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7036 max_size
, max_objects
, have_max_size
, have_max_objects
);
7037 } else if (!user_id
.empty()) {
7038 if (quota_scope
== "bucket") {
7039 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7040 } else if (quota_scope
== "user") {
7041 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7043 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;