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();
353 OPT_BUCKET_LIMIT_CHECK
,
358 OPT_BUCKET_SYNC_STATUS
,
359 OPT_BUCKET_SYNC_INIT
,
361 OPT_BUCKET_SYNC_DISABLE
,
362 OPT_BUCKET_SYNC_ENABLE
,
395 OPT_ORPHANS_LIST_JOBS
,
397 OPT_ZONEGROUP_CREATE
,
398 OPT_ZONEGROUP_DEFAULT
,
399 OPT_ZONEGROUP_DELETE
,
401 OPT_ZONEGROUP_MODIFY
,
404 OPT_ZONEGROUP_REMOVE
,
405 OPT_ZONEGROUP_RENAME
,
406 OPT_ZONEGROUP_PLACEMENT_ADD
,
407 OPT_ZONEGROUP_PLACEMENT_MODIFY
,
408 OPT_ZONEGROUP_PLACEMENT_RM
,
409 OPT_ZONEGROUP_PLACEMENT_LIST
,
410 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
419 OPT_ZONE_PLACEMENT_ADD
,
420 OPT_ZONE_PLACEMENT_MODIFY
,
421 OPT_ZONE_PLACEMENT_RM
,
422 OPT_ZONE_PLACEMENT_LIST
,
429 OPT_METADATA_SYNC_STATUS
,
430 OPT_METADATA_SYNC_INIT
,
431 OPT_METADATA_SYNC_RUN
,
441 OPT_DATA_SYNC_STATUS
,
452 OPT_REPLICALOG_UPDATE
,
453 OPT_REPLICALOG_DELETE
,
457 OPT_REALM_GET_DEFAULT
,
459 OPT_REALM_LIST_PERIODS
,
467 OPT_PERIOD_GET_CURRENT
,
473 OPT_GLOBAL_QUOTA_GET
,
474 OPT_GLOBAL_QUOTA_SET
,
475 OPT_GLOBAL_QUOTA_ENABLE
,
476 OPT_GLOBAL_QUOTA_DISABLE
,
484 OPT_ROLE_POLICY_LIST
,
486 OPT_ROLE_POLICY_DELETE
,
494 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
497 // NOTE: please keep the checks in alphabetical order !!!
498 if (strcmp(cmd
, "bi") == 0 ||
499 strcmp(cmd
, "bilog") == 0 ||
500 strcmp(cmd
, "buckets") == 0 ||
501 strcmp(cmd
, "caps") == 0 ||
502 strcmp(cmd
, "data") == 0 ||
503 strcmp(cmd
, "datalog") == 0 ||
504 strcmp(cmd
, "error") == 0 ||
505 strcmp(cmd
, "gc") == 0 ||
506 strcmp(cmd
, "global") == 0 ||
507 strcmp(cmd
, "key") == 0 ||
508 strcmp(cmd
, "log") == 0 ||
509 strcmp(cmd
, "lc") == 0 ||
510 strcmp(cmd
, "mdlog") == 0 ||
511 strcmp(cmd
, "metadata") == 0 ||
512 strcmp(cmd
, "object") == 0 ||
513 strcmp(cmd
, "objects") == 0 ||
514 strcmp(cmd
, "olh") == 0 ||
515 strcmp(cmd
, "opstate") == 0 ||
516 strcmp(cmd
, "orphans") == 0 ||
517 strcmp(cmd
, "period") == 0 ||
518 strcmp(cmd
, "placement") == 0 ||
519 strcmp(cmd
, "pool") == 0 ||
520 strcmp(cmd
, "pools") == 0 ||
521 strcmp(cmd
, "quota") == 0 ||
522 strcmp(cmd
, "realm") == 0 ||
523 strcmp(cmd
, "replicalog") == 0 ||
524 strcmp(cmd
, "role") == 0 ||
525 strcmp(cmd
, "role-policy") == 0 ||
526 strcmp(cmd
, "subuser") == 0 ||
527 strcmp(cmd
, "sync") == 0 ||
528 strcmp(cmd
, "usage") == 0 ||
529 strcmp(cmd
, "user") == 0 ||
530 strcmp(cmd
, "zone") == 0 ||
531 strcmp(cmd
, "zonegroup") == 0 ||
532 strcmp(cmd
, "zonegroups") == 0) {
538 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
540 if (strcmp(cmd
, "reshard") == 0 &&
541 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
545 if (strcmp(cmd
, "bucket") == 0 &&
546 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
551 if (strcmp(cmd
, "policy") == 0)
557 if (strcmp(prev_cmd
, "user") == 0) {
558 if (strcmp(cmd
, "create") == 0)
559 return OPT_USER_CREATE
;
560 if (strcmp(cmd
, "info") == 0)
561 return OPT_USER_INFO
;
562 if (strcmp(cmd
, "modify") == 0)
563 return OPT_USER_MODIFY
;
564 if (strcmp(cmd
, "rm") == 0)
566 if (strcmp(cmd
, "suspend") == 0)
567 return OPT_USER_SUSPEND
;
568 if (strcmp(cmd
, "enable") == 0)
569 return OPT_USER_ENABLE
;
570 if (strcmp(cmd
, "check") == 0)
571 return OPT_USER_CHECK
;
572 if (strcmp(cmd
, "stats") == 0)
573 return OPT_USER_STATS
;
574 if (strcmp(cmd
, "list") == 0)
575 return OPT_USER_LIST
;
576 } else if (strcmp(prev_cmd
, "subuser") == 0) {
577 if (strcmp(cmd
, "create") == 0)
578 return OPT_SUBUSER_CREATE
;
579 if (strcmp(cmd
, "modify") == 0)
580 return OPT_SUBUSER_MODIFY
;
581 if (strcmp(cmd
, "rm") == 0)
582 return OPT_SUBUSER_RM
;
583 } else if (strcmp(prev_cmd
, "key") == 0) {
584 if (strcmp(cmd
, "create") == 0)
585 return OPT_KEY_CREATE
;
586 if (strcmp(cmd
, "rm") == 0)
588 } else if (strcmp(prev_cmd
, "buckets") == 0) {
589 if (strcmp(cmd
, "list") == 0)
590 return OPT_BUCKETS_LIST
;
591 } else if (strcmp(prev_cmd
, "bucket") == 0) {
592 if (strcmp(cmd
, "list") == 0)
593 return OPT_BUCKETS_LIST
;
594 if (strcmp(cmd
, "link") == 0)
595 return OPT_BUCKET_LINK
;
596 if (strcmp(cmd
, "unlink") == 0)
597 return OPT_BUCKET_UNLINK
;
598 if (strcmp(cmd
, "stats") == 0)
599 return OPT_BUCKET_STATS
;
600 if (strcmp(cmd
, "rm") == 0)
601 return OPT_BUCKET_RM
;
602 if (strcmp(cmd
, "rewrite") == 0)
603 return OPT_BUCKET_REWRITE
;
604 if (strcmp(cmd
, "reshard") == 0)
605 return OPT_BUCKET_RESHARD
;
606 if (strcmp(cmd
, "check") == 0)
607 return OPT_BUCKET_CHECK
;
608 if (strcmp(cmd
, "sync") == 0) {
612 if (strcmp(cmd
, "limit") == 0) {
616 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
617 if (strcmp(prev_cmd
, "sync") == 0) {
618 if (strcmp(cmd
, "status") == 0)
619 return OPT_BUCKET_SYNC_STATUS
;
620 if (strcmp(cmd
, "init") == 0)
621 return OPT_BUCKET_SYNC_INIT
;
622 if (strcmp(cmd
, "run") == 0)
623 return OPT_BUCKET_SYNC_RUN
;
624 if (strcmp(cmd
, "disable") == 0)
625 return OPT_BUCKET_SYNC_DISABLE
;
626 if (strcmp(cmd
, "enable") == 0)
627 return OPT_BUCKET_SYNC_ENABLE
;
628 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
629 (strcmp(cmd
, "check") == 0)) {
630 return OPT_BUCKET_LIMIT_CHECK
;
632 } else if (strcmp(prev_cmd
, "log") == 0) {
633 if (strcmp(cmd
, "list") == 0)
635 if (strcmp(cmd
, "show") == 0)
637 if (strcmp(cmd
, "rm") == 0)
639 } else if (strcmp(prev_cmd
, "usage") == 0) {
640 if (strcmp(cmd
, "show") == 0)
641 return OPT_USAGE_SHOW
;
642 if (strcmp(cmd
, "trim") == 0)
643 return OPT_USAGE_TRIM
;
644 } else if (strcmp(prev_cmd
, "caps") == 0) {
645 if (strcmp(cmd
, "add") == 0)
647 if (strcmp(cmd
, "rm") == 0)
649 } else if (strcmp(prev_cmd
, "pool") == 0) {
650 if (strcmp(cmd
, "add") == 0)
652 if (strcmp(cmd
, "rm") == 0)
654 if (strcmp(cmd
, "list") == 0)
655 return OPT_POOLS_LIST
;
656 } else if (strcmp(prev_cmd
, "pools") == 0) {
657 if (strcmp(cmd
, "list") == 0)
658 return OPT_POOLS_LIST
;
659 } else if (strcmp(prev_cmd
, "object") == 0) {
660 if (strcmp(cmd
, "rm") == 0)
661 return OPT_OBJECT_RM
;
662 if (strcmp(cmd
, "unlink") == 0)
663 return OPT_OBJECT_UNLINK
;
664 if (strcmp(cmd
, "stat") == 0)
665 return OPT_OBJECT_STAT
;
666 if (strcmp(cmd
, "rewrite") == 0)
667 return OPT_OBJECT_REWRITE
;
668 } else if (strcmp(prev_cmd
, "objects") == 0) {
669 if (strcmp(cmd
, "expire") == 0)
670 return OPT_OBJECTS_EXPIRE
;
671 } else if (strcmp(prev_cmd
, "olh") == 0) {
672 if (strcmp(cmd
, "get") == 0)
674 if (strcmp(cmd
, "readlog") == 0)
675 return OPT_OLH_READLOG
;
676 } else if (strcmp(prev_cmd
, "bi") == 0) {
677 if (strcmp(cmd
, "get") == 0)
679 if (strcmp(cmd
, "put") == 0)
681 if (strcmp(cmd
, "list") == 0)
683 if (strcmp(cmd
, "purge") == 0)
685 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
686 (strcmp(prev_cmd
, "quota") == 0)) {
687 if (strcmp(cmd
, "get") == 0)
688 return OPT_GLOBAL_QUOTA_GET
;
689 if (strcmp(cmd
, "set") == 0)
690 return OPT_GLOBAL_QUOTA_SET
;
691 if (strcmp(cmd
, "enable") == 0)
692 return OPT_GLOBAL_QUOTA_ENABLE
;
693 if (strcmp(cmd
, "disable") == 0)
694 return OPT_GLOBAL_QUOTA_DISABLE
;
695 } else if (strcmp(prev_cmd
, "period") == 0) {
696 if (strcmp(cmd
, "delete") == 0)
697 return OPT_PERIOD_DELETE
;
698 if (strcmp(cmd
, "get") == 0)
699 return OPT_PERIOD_GET
;
700 if (strcmp(cmd
, "get-current") == 0)
701 return OPT_PERIOD_GET_CURRENT
;
702 if (strcmp(cmd
, "pull") == 0)
703 return OPT_PERIOD_PULL
;
704 if (strcmp(cmd
, "push") == 0)
705 return OPT_PERIOD_PUSH
;
706 if (strcmp(cmd
, "list") == 0)
707 return OPT_PERIOD_LIST
;
708 if (strcmp(cmd
, "update") == 0)
709 return OPT_PERIOD_UPDATE
;
710 if (strcmp(cmd
, "commit") == 0)
711 return OPT_PERIOD_COMMIT
;
712 } else if (strcmp(prev_cmd
, "realm") == 0) {
713 if (strcmp(cmd
, "create") == 0)
714 return OPT_REALM_CREATE
;
715 if (strcmp(cmd
, "delete") == 0)
716 return OPT_REALM_DELETE
;
717 if (strcmp(cmd
, "get") == 0)
718 return OPT_REALM_GET
;
719 if (strcmp(cmd
, "get-default") == 0)
720 return OPT_REALM_GET_DEFAULT
;
721 if (strcmp(cmd
, "list") == 0)
722 return OPT_REALM_LIST
;
723 if (strcmp(cmd
, "list-periods") == 0)
724 return OPT_REALM_LIST_PERIODS
;
725 if (strcmp(cmd
, "remove") == 0)
726 return OPT_REALM_REMOVE
;
727 if (strcmp(cmd
, "rename") == 0)
728 return OPT_REALM_RENAME
;
729 if (strcmp(cmd
, "set") == 0)
730 return OPT_REALM_SET
;
731 if (strcmp(cmd
, "default") == 0)
732 return OPT_REALM_DEFAULT
;
733 if (strcmp(cmd
, "pull") == 0)
734 return OPT_REALM_PULL
;
735 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
736 (strcmp(prev_cmd
, "placement") == 0)) {
737 if (strcmp(cmd
, "add") == 0)
738 return OPT_ZONEGROUP_PLACEMENT_ADD
;
739 if (strcmp(cmd
, "modify") == 0)
740 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
741 if (strcmp(cmd
, "rm") == 0)
742 return OPT_ZONEGROUP_PLACEMENT_RM
;
743 if (strcmp(cmd
, "list") == 0)
744 return OPT_ZONEGROUP_PLACEMENT_LIST
;
745 if (strcmp(cmd
, "default") == 0)
746 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
747 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
748 if (strcmp(cmd
, "add") == 0)
749 return OPT_ZONEGROUP_ADD
;
750 if (strcmp(cmd
, "create")== 0)
751 return OPT_ZONEGROUP_CREATE
;
752 if (strcmp(cmd
, "default") == 0)
753 return OPT_ZONEGROUP_DEFAULT
;
754 if (strcmp(cmd
, "delete") == 0)
755 return OPT_ZONEGROUP_DELETE
;
756 if (strcmp(cmd
, "get") == 0)
757 return OPT_ZONEGROUP_GET
;
758 if (strcmp(cmd
, "modify") == 0)
759 return OPT_ZONEGROUP_MODIFY
;
760 if (strcmp(cmd
, "list") == 0)
761 return OPT_ZONEGROUP_LIST
;
762 if (strcmp(cmd
, "set") == 0)
763 return OPT_ZONEGROUP_SET
;
764 if (strcmp(cmd
, "remove") == 0)
765 return OPT_ZONEGROUP_REMOVE
;
766 if (strcmp(cmd
, "rename") == 0)
767 return OPT_ZONEGROUP_RENAME
;
768 } else if (strcmp(prev_cmd
, "quota") == 0) {
769 if (strcmp(cmd
, "set") == 0)
770 return OPT_QUOTA_SET
;
771 if (strcmp(cmd
, "enable") == 0)
772 return OPT_QUOTA_ENABLE
;
773 if (strcmp(cmd
, "disable") == 0)
774 return OPT_QUOTA_DISABLE
;
775 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
776 if (strcmp(cmd
, "list") == 0)
777 return OPT_ZONEGROUP_LIST
;
778 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
779 (strcmp(prev_cmd
, "placement") == 0)) {
780 if (strcmp(cmd
, "add") == 0)
781 return OPT_ZONE_PLACEMENT_ADD
;
782 if (strcmp(cmd
, "modify") == 0)
783 return OPT_ZONE_PLACEMENT_MODIFY
;
784 if (strcmp(cmd
, "rm") == 0)
785 return OPT_ZONE_PLACEMENT_RM
;
786 if (strcmp(cmd
, "list") == 0)
787 return OPT_ZONE_PLACEMENT_LIST
;
788 } else if (strcmp(prev_cmd
, "zone") == 0) {
789 if (strcmp(cmd
, "delete") == 0)
790 return OPT_ZONE_DELETE
;
791 if (strcmp(cmd
, "create") == 0)
792 return OPT_ZONE_CREATE
;
793 if (strcmp(cmd
, "get") == 0)
795 if (strcmp(cmd
, "set") == 0)
797 if (strcmp(cmd
, "list") == 0)
798 return OPT_ZONE_LIST
;
799 if (strcmp(cmd
, "modify") == 0)
800 return OPT_ZONE_MODIFY
;
801 if (strcmp(cmd
, "rename") == 0)
802 return OPT_ZONE_RENAME
;
803 if (strcmp(cmd
, "default") == 0)
804 return OPT_ZONE_DEFAULT
;
805 } else if (strcmp(prev_cmd
, "zones") == 0) {
806 if (strcmp(cmd
, "list") == 0)
807 return OPT_ZONE_LIST
;
808 } else if (strcmp(prev_cmd
, "gc") == 0) {
809 if (strcmp(cmd
, "list") == 0)
811 if (strcmp(cmd
, "process") == 0)
812 return OPT_GC_PROCESS
;
813 } else if (strcmp(prev_cmd
, "lc") == 0) {
814 if (strcmp(cmd
, "list") == 0)
816 if (strcmp(cmd
, "process") == 0)
817 return OPT_LC_PROCESS
;
818 } else if (strcmp(prev_cmd
, "orphans") == 0) {
819 if (strcmp(cmd
, "find") == 0)
820 return OPT_ORPHANS_FIND
;
821 if (strcmp(cmd
, "finish") == 0)
822 return OPT_ORPHANS_FINISH
;
823 if (strcmp(cmd
, "list-jobs") == 0)
824 return OPT_ORPHANS_LIST_JOBS
;
825 } else if (strcmp(prev_cmd
, "metadata") == 0) {
826 if (strcmp(cmd
, "get") == 0)
827 return OPT_METADATA_GET
;
828 if (strcmp(cmd
, "put") == 0)
829 return OPT_METADATA_PUT
;
830 if (strcmp(cmd
, "rm") == 0)
831 return OPT_METADATA_RM
;
832 if (strcmp(cmd
, "list") == 0)
833 return OPT_METADATA_LIST
;
834 if (strcmp(cmd
, "sync") == 0) {
838 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
839 (strcmp(prev_cmd
, "sync") == 0)) {
840 if (strcmp(cmd
, "status") == 0)
841 return OPT_METADATA_SYNC_STATUS
;
842 if (strcmp(cmd
, "init") == 0)
843 return OPT_METADATA_SYNC_INIT
;
844 if (strcmp(cmd
, "run") == 0)
845 return OPT_METADATA_SYNC_RUN
;
846 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
847 (strcmp(prev_cmd
, "error") == 0)) {
848 if (strcmp(cmd
, "list") == 0)
849 return OPT_SYNC_ERROR_LIST
;
850 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
851 if (strcmp(cmd
, "list") == 0)
852 return OPT_MDLOG_LIST
;
853 if (strcmp(cmd
, "autotrim") == 0)
854 return OPT_MDLOG_AUTOTRIM
;
855 if (strcmp(cmd
, "trim") == 0)
856 return OPT_MDLOG_TRIM
;
857 if (strcmp(cmd
, "fetch") == 0)
858 return OPT_MDLOG_FETCH
;
859 if (strcmp(cmd
, "status") == 0)
860 return OPT_MDLOG_STATUS
;
861 } else if (strcmp(prev_cmd
, "bilog") == 0) {
862 if (strcmp(cmd
, "list") == 0)
863 return OPT_BILOG_LIST
;
864 if (strcmp(cmd
, "trim") == 0)
865 return OPT_BILOG_TRIM
;
866 if (strcmp(cmd
, "status") == 0)
867 return OPT_BILOG_STATUS
;
868 } else if (strcmp(prev_cmd
, "data") == 0) {
869 if (strcmp(cmd
, "sync") == 0) {
873 } else if (strcmp(prev_cmd
, "datalog") == 0) {
874 if (strcmp(cmd
, "list") == 0)
875 return OPT_DATALOG_LIST
;
876 if (strcmp(cmd
, "trim") == 0)
877 return OPT_DATALOG_TRIM
;
878 if (strcmp(cmd
, "status") == 0)
879 return OPT_DATALOG_STATUS
;
880 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
881 (strcmp(prev_cmd
, "sync") == 0)) {
882 if (strcmp(cmd
, "status") == 0)
883 return OPT_DATA_SYNC_STATUS
;
884 if (strcmp(cmd
, "init") == 0)
885 return OPT_DATA_SYNC_INIT
;
886 if (strcmp(cmd
, "run") == 0)
887 return OPT_DATA_SYNC_RUN
;
888 } else if (strcmp(prev_cmd
, "opstate") == 0) {
889 if (strcmp(cmd
, "list") == 0)
890 return OPT_OPSTATE_LIST
;
891 if (strcmp(cmd
, "set") == 0)
892 return OPT_OPSTATE_SET
;
893 if (strcmp(cmd
, "renew") == 0)
894 return OPT_OPSTATE_RENEW
;
895 if (strcmp(cmd
, "rm") == 0)
896 return OPT_OPSTATE_RM
;
897 } else if (strcmp(prev_cmd
, "replicalog") == 0) {
898 if (strcmp(cmd
, "get") == 0)
899 return OPT_REPLICALOG_GET
;
900 if (strcmp(cmd
, "update") == 0)
901 return OPT_REPLICALOG_UPDATE
;
902 if (strcmp(cmd
, "delete") == 0)
903 return OPT_REPLICALOG_DELETE
;
904 } else if (strcmp(prev_cmd
, "sync") == 0) {
905 if (strcmp(cmd
, "status") == 0)
906 return OPT_SYNC_STATUS
;
907 } else if (strcmp(prev_cmd
, "role") == 0) {
908 if (strcmp(cmd
, "create") == 0)
909 return OPT_ROLE_CREATE
;
910 if (strcmp(cmd
, "delete") == 0)
911 return OPT_ROLE_DELETE
;
912 if (strcmp(cmd
, "get") == 0)
914 if (strcmp(cmd
, "modify") == 0)
915 return OPT_ROLE_MODIFY
;
916 if (strcmp(cmd
, "list") == 0)
917 return OPT_ROLE_LIST
;
918 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
919 if (strcmp(cmd
, "put") == 0)
920 return OPT_ROLE_POLICY_PUT
;
921 if (strcmp(cmd
, "list") == 0)
922 return OPT_ROLE_POLICY_LIST
;
923 if (strcmp(cmd
, "get") == 0)
924 return OPT_ROLE_POLICY_GET
;
925 if (strcmp(cmd
, "delete") == 0)
926 return OPT_ROLE_POLICY_DELETE
;
927 } else if (strcmp(prev_cmd
, "reshard") == 0) {
928 if (strcmp(cmd
, "bucket") == 0)
929 return OPT_BUCKET_RESHARD
;
930 if (strcmp(cmd
, "add") == 0)
931 return OPT_RESHARD_ADD
;
932 if (strcmp(cmd
, "list") == 0)
933 return OPT_RESHARD_LIST
;
934 if (strcmp(cmd
, "status") == 0)
935 return OPT_RESHARD_STATUS
;
936 if (strcmp(cmd
, "execute") == 0)
937 return OPT_RESHARD_PROCESS
;
938 if (strcmp(cmd
, "cancel") == 0)
939 return OPT_RESHARD_CANCEL
;
945 enum ReplicaLogType
{
946 ReplicaLog_Invalid
= 0,
952 ReplicaLogType
get_replicalog_type(const string
& name
) {
953 if (name
== "md" || name
== "meta" || name
== "metadata")
954 return ReplicaLog_Metadata
;
956 return ReplicaLog_Data
;
957 if (name
== "bucket")
958 return ReplicaLog_Bucket
;
960 return ReplicaLog_Invalid
;
963 BIIndexType
get_bi_index_type(const string
& type_str
) {
964 if (type_str
== "plain")
966 if (type_str
== "instance")
968 if (type_str
== "olh")
974 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
976 bufferlist::iterator iter
= bl
.begin();
977 switch (index_type
) {
981 rgw_bucket_dir_entry entry
;
982 ::decode(entry
, iter
);
983 encode_json("entry", entry
, formatter
);
988 rgw_bucket_olh_entry entry
;
989 ::decode(entry
, iter
);
990 encode_json("entry", entry
, formatter
);
999 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
1001 encode_json("user_info", info
, formatter
);
1002 formatter
->flush(cout
);
1006 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1008 formatter
->open_object_section("role");
1009 formatter
->dump_string("Permission policy", perm_policy
);
1010 formatter
->close_section();
1011 formatter
->flush(cout
);
1014 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1016 formatter
->open_array_section("PolicyNames");
1017 for (const auto& it
: policy_names
) {
1018 formatter
->dump_string("policyname", it
);
1020 formatter
->close_section();
1021 formatter
->flush(cout
);
1024 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1026 formatter
->open_object_section("role");
1027 role
.dump(formatter
);
1028 formatter
->close_section();
1029 formatter
->flush(cout
);
1032 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1034 formatter
->open_array_section("Roles");
1035 for (const auto& it
: roles
) {
1036 formatter
->open_object_section("role");
1038 formatter
->close_section();
1040 formatter
->close_section();
1041 formatter
->flush(cout
);
1044 class StoreDestructor
{
1047 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1048 ~StoreDestructor() {
1049 RGWStoreManager::close_storage(store
);
1053 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1054 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1056 if (!bucket_name
.empty()) {
1057 RGWObjectCtx
obj_ctx(store
);
1059 if (bucket_id
.empty()) {
1060 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1062 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1063 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1066 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1069 bucket
= bucket_info
.bucket
;
1074 static int read_input(const string
& infile
, bufferlist
& bl
)
1077 if (infile
.size()) {
1078 fd
= open(infile
.c_str(), O_RDONLY
);
1081 cerr
<< "error reading input file " << infile
<< std::endl
;
1086 #define READ_CHUNK 8196
1091 char buf
[READ_CHUNK
];
1093 r
= safe_read(fd
, buf
, READ_CHUNK
);
1096 cerr
<< "error while reading input" << std::endl
;
1104 if (infile
.size()) {
1111 static int read_decode_json(const string
& infile
, T
& t
)
1114 int ret
= read_input(infile
, bl
);
1116 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1120 if (!p
.parse(bl
.c_str(), bl
.length())) {
1121 cout
<< "failed to parse JSON" << std::endl
;
1126 decode_json_obj(t
, &p
);
1127 } catch (JSONDecoder::err
& e
) {
1128 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1134 template <class T
, class K
>
1135 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1138 int ret
= read_input(infile
, bl
);
1140 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1144 if (!p
.parse(bl
.c_str(), bl
.length())) {
1145 cout
<< "failed to parse JSON" << std::endl
;
1150 t
.decode_json(&p
, k
);
1151 } catch (JSONDecoder::err
& e
) {
1152 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1158 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1163 if (!date_str
.empty()) {
1164 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1166 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1171 ut
= utime_t(epoch
, nsec
);
1177 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1181 bufferlist::iterator iter
= bl
.begin();
1185 } catch (buffer::error
& err
) {
1189 encode_json(field_name
, t
, f
);
1194 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1197 if (bl
.length() > 0) {
1198 val
.assign(bl
.c_str());
1200 f
->dump_string(field_name
, val
);
1205 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1206 bool have_max_size
, bool have_max_objects
)
1209 case OPT_QUOTA_ENABLE
:
1210 case OPT_GLOBAL_QUOTA_ENABLE
:
1211 quota
.enabled
= true;
1213 // falling through on purpose
1216 case OPT_GLOBAL_QUOTA_SET
:
1217 if (have_max_objects
) {
1218 if (max_objects
< 0) {
1219 quota
.max_objects
= -1;
1221 quota
.max_objects
= max_objects
;
1224 if (have_max_size
) {
1226 quota
.max_size
= -1;
1228 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1232 case OPT_QUOTA_DISABLE
:
1233 case OPT_GLOBAL_QUOTA_DISABLE
:
1234 quota
.enabled
= false;
1239 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1240 const string
& tenant_name
, const string
& bucket_name
,
1241 int64_t max_size
, int64_t max_objects
,
1242 bool have_max_size
, bool have_max_objects
)
1244 RGWBucketInfo bucket_info
;
1245 map
<string
, bufferlist
> attrs
;
1246 RGWObjectCtx
obj_ctx(store
);
1247 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1249 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1253 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1255 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1257 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1263 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1264 bool have_max_size
, bool have_max_objects
)
1266 RGWUserInfo
& user_info
= op_state
.get_user_info();
1268 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1270 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1273 int r
= user
.modify(op_state
, &err
);
1275 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1281 int set_user_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1282 bool have_max_size
, bool have_max_objects
)
1284 RGWUserInfo
& user_info
= op_state
.get_user_info();
1286 set_quota_info(user_info
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1288 op_state
.set_user_quota(user_info
.user_quota
);
1291 int r
= user
.modify(op_state
, &err
);
1293 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1299 static bool bucket_object_check_filter(const string
& name
)
1302 string ns
; /* empty namespace */
1303 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1306 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1308 map
<string
, bufferlist
> attrs
;
1311 RGWObjectCtx
obj_ctx(store
);
1312 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1313 RGWRados::Object::Read
read_op(&op_target
);
1315 read_op
.params
.attrs
= &attrs
;
1316 read_op
.params
.obj_size
= &obj_size
;
1318 int ret
= read_op
.prepare();
1320 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1324 map
<string
, bufferlist
>::iterator iter
;
1325 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1326 if (iter
== attrs
.end()) {
1327 *need_rewrite
= (obj_size
>= min_stripe_size
);
1331 RGWObjManifest manifest
;
1334 bufferlist
& bl
= iter
->second
;
1335 bufferlist::iterator biter
= bl
.begin();
1336 ::decode(manifest
, biter
);
1337 } catch (buffer::error
& err
) {
1338 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1342 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1343 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1344 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1345 RGWObjManifestPart
& part
= oiter
->second
;
1347 if (part
.size
>= min_stripe_size
) {
1348 *need_rewrite
= true;
1352 *need_rewrite
= false;
1358 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1359 f
->open_object_section("object");
1360 f
->open_object_section("key");
1361 f
->dump_string("type", "head");
1362 f
->dump_string("name", key
.name
);
1363 f
->dump_string("instance", key
.instance
);
1369 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1371 f
->dump_string("oid", oid
);
1372 f
->dump_string("locator", locator
);
1375 RGWObjectCtx
obj_ctx(store
);
1377 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1378 RGWRados::Object::Read
read_op(&op_target
);
1380 int ret
= read_op
.prepare();
1381 bool needs_fixing
= (ret
== -ENOENT
);
1383 f
->dump_bool("needs_fixing", needs_fixing
);
1385 string status
= (needs_fixing
? "needs_fixing" : "ok");
1387 if ((needs_fixing
|| remove_bad
) && fix
) {
1388 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1390 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1397 f
->dump_string("status", status
);
1404 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1405 f
->open_object_section("object");
1406 f
->open_object_section("key");
1407 f
->dump_string("type", "tail");
1408 f
->dump_string("name", key
.name
);
1409 f
->dump_string("instance", key
.instance
);
1415 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1417 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1420 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1423 f
->dump_bool("needs_fixing", needs_fixing
);
1424 f
->dump_string("status", status
);
1431 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1432 bool fix
, bool remove_bad
, Formatter
*f
)
1434 if (remove_bad
&& !fix
) {
1435 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1439 RGWBucketInfo bucket_info
;
1443 f
->open_object_section("bucket");
1444 f
->dump_string("bucket", bucket_name
);
1445 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1447 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1453 int max_entries
= 1000;
1457 vector
<rgw_bucket_dir_entry
> result
;
1458 map
<string
, bool> common_prefixes
;
1461 RGWRados::Bucket
target(store
, bucket_info
);
1462 RGWRados::Bucket::List
list_op(&target
);
1466 list_op
.params
.prefix
= prefix
;
1467 list_op
.params
.delim
= delim
;
1468 list_op
.params
.marker
= rgw_obj_key(marker
);
1469 list_op
.params
.ns
= ns
;
1470 list_op
.params
.enforce_ns
= true;
1471 list_op
.params
.list_versions
= true;
1473 f
->open_array_section("check_objects");
1475 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1477 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1481 count
+= result
.size();
1483 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1484 rgw_obj_key key
= iter
->key
;
1485 rgw_obj
obj(bucket
, key
);
1487 if (key
.name
[0] == '_') {
1488 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1491 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1496 } while (truncated
&& count
< max_entries
);
1505 int set_bucket_sync_enabled(RGWRados
*store
, int opt_cmd
, const string
& tenant_name
, const string
& bucket_name
)
1507 RGWBucketInfo bucket_info
;
1508 map
<string
, bufferlist
> attrs
;
1509 RGWObjectCtx
obj_ctx(store
);
1511 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1513 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1517 if (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
) {
1518 bucket_info
.flags
&= ~BUCKET_DATASYNC_DISABLED
;
1519 } else if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1520 bucket_info
.flags
|= BUCKET_DATASYNC_DISABLED
;
1523 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1525 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1529 int shards_num
= bucket_info
.num_shards
? bucket_info
.num_shards
: 1;
1530 int shard_id
= bucket_info
.num_shards
? 0 : -1;
1532 if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1533 r
= store
->stop_bi_log_entries(bucket_info
, -1);
1535 lderr(store
->ctx()) << "ERROR: failed writing stop bilog" << dendl
;
1539 r
= store
->resync_bi_log_entries(bucket_info
, -1);
1541 lderr(store
->ctx()) << "ERROR: failed writing resync bilog" << dendl
;
1546 for (int i
= 0; i
< shards_num
; ++i
, ++shard_id
) {
1547 r
= store
->data_log
->add_entry(bucket_info
.bucket
, shard_id
);
1549 lderr(store
->ctx()) << "ERROR: failed writing data log" << dendl
;
1558 /// search for a matching zone/zonegroup id and return a connection if found
1559 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1560 const RGWZoneGroup
& zonegroup
,
1561 const std::string
& remote
)
1563 boost::optional
<RGWRESTConn
> conn
;
1564 if (remote
== zonegroup
.get_id()) {
1565 conn
.emplace(store
->ctx(), store
, remote
, zonegroup
.endpoints
);
1567 for (const auto& z
: zonegroup
.zones
) {
1568 const auto& zone
= z
.second
;
1569 if (remote
== zone
.id
) {
1570 conn
.emplace(store
->ctx(), store
, remote
, zone
.endpoints
);
1578 /// search each zonegroup for a connection
1579 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1580 const RGWPeriodMap
& period_map
,
1581 const std::string
& remote
)
1583 boost::optional
<RGWRESTConn
> conn
;
1584 for (const auto& zg
: period_map
.zonegroups
) {
1585 conn
= get_remote_conn(store
, zg
.second
, remote
);
1593 // we expect a very small response
1594 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1596 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1597 bufferlist
& in_data
, JSONParser
& parser
)
1603 ceph::bufferlist response
;
1605 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1607 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1608 if (parse_ret
< 0) {
1609 cerr
<< "failed to parse response" << std::endl
;
1615 static int send_to_url(const string
& url
, const string
& access
,
1616 const string
& secret
, req_info
& info
,
1617 bufferlist
& in_data
, JSONParser
& parser
)
1619 if (access
.empty() || secret
.empty()) {
1620 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1628 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1630 bufferlist response
;
1631 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1633 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1634 if (parse_ret
< 0) {
1635 cout
<< "failed to parse response" << std::endl
;
1641 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1642 const string
& access
, const string
& secret
,
1643 req_info
& info
, bufferlist
& in_data
,
1647 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1649 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1652 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1653 string remote
, const string
& url
,
1654 const string
& access
, const string
& secret
,
1657 const string
& master_zone
= period
.get_master_zone();
1658 if (master_zone
.empty()) {
1659 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1662 // are we the period's master zone?
1663 if (store
->get_zone_params().get_id() == master_zone
) {
1664 // read the current period
1665 RGWPeriod current_period
;
1666 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1668 cerr
<< "Error initializing current period: "
1669 << cpp_strerror(-ret
) << std::endl
;
1672 // the master zone can commit locally
1673 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1675 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1680 if (remote
.empty() && url
.empty()) {
1681 // use the new master zone's connection
1682 remote
= master_zone
;
1683 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1685 boost::optional
<RGWRESTConn
> conn
;
1686 RGWRESTConn
*remote_conn
= nullptr;
1687 if (!remote
.empty()) {
1688 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1690 cerr
<< "failed to find a zone or zonegroup for remote "
1691 << remote
<< std::endl
;
1694 remote_conn
= &*conn
;
1697 // push period to the master with an empty period id
1701 req_info
info(g_ceph_context
, &env
);
1702 info
.method
= "POST";
1703 info
.request_uri
= "/admin/realm/period";
1705 // json format into a bufferlist
1706 JSONFormatter
jf(false);
1707 encode_json("period", period
, &jf
);
1712 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1714 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1716 // did we parse an error message?
1717 auto message
= p
.find_obj("Message");
1719 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1724 // decode the response and store it back
1726 decode_json_obj(period
, &p
);
1727 } catch (JSONDecoder::err
& e
) {
1728 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1731 if (period
.get_id().empty()) {
1732 cerr
<< "Period commit got back an empty period id" << std::endl
;
1735 // the master zone gave us back the period that it committed, so it's
1736 // safe to save it as our latest epoch
1737 ret
= period
.store_info(false);
1739 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1740 << cpp_strerror(ret
) << std::endl
;
1743 ret
= period
.set_latest_epoch(period
.get_epoch());
1745 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1748 ret
= period
.reflect();
1750 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1753 realm
.notify_new_period(period
);
1757 static int update_period(const string
& realm_id
, const string
& realm_name
,
1758 const string
& period_id
, const string
& period_epoch
,
1759 bool commit
, const string
& remote
, const string
& url
,
1760 const string
& access
, const string
& secret
,
1761 Formatter
*formatter
, bool force
)
1763 RGWRealm
realm(realm_id
, realm_name
);
1764 int ret
= realm
.init(g_ceph_context
, store
);
1766 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1770 if (!period_epoch
.empty()) {
1771 epoch
= atoi(period_epoch
.c_str());
1773 RGWPeriod
period(period_id
, epoch
);
1774 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1776 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1780 ret
= period
.update();
1782 // Dropping the error message here, as both the ret codes were handled in
1786 ret
= period
.store_info(false);
1788 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1792 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1794 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1798 encode_json("period", period
, formatter
);
1799 formatter
->flush(cout
);
1804 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1805 const string
& bucket_id
, rgw_bucket
& bucket
)
1807 RGWBucketInfo bucket_info
;
1809 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1811 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1818 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1819 const string
& access_key
, const string
& secret_key
,
1820 const string
& realm_id
, const string
& realm_name
,
1821 const string
& period_id
, const string
& period_epoch
,
1825 req_info
info(g_ceph_context
, &env
);
1826 info
.method
= "GET";
1827 info
.request_uri
= "/admin/realm/period";
1829 map
<string
, string
> ¶ms
= info
.args
.get_params();
1830 if (!realm_id
.empty())
1831 params
["realm_id"] = realm_id
;
1832 if (!realm_name
.empty())
1833 params
["realm_name"] = realm_name
;
1834 if (!period_id
.empty())
1835 params
["period_id"] = period_id
;
1836 if (!period_epoch
.empty())
1837 params
["epoch"] = period_epoch
;
1841 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1844 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1847 ret
= period
->init(g_ceph_context
, store
, false);
1849 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1853 decode_json_obj(*period
, &p
);
1854 } catch (JSONDecoder::err
& e
) {
1855 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1858 ret
= period
->store_info(false);
1860 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1862 // store latest epoch (ignore errors)
1863 period
->update_latest_epoch(period
->get_epoch());
1867 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1868 const std::string
& realm_name
,
1869 std::string
* period_id
)
1871 RGWRealm
realm(realm_id
, realm_name
);
1872 int ret
= realm
.init(g_ceph_context
, store
);
1874 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1877 *period_id
= realm
.get_current_period();
1881 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1883 if (!ss
.str().empty()) {
1884 l
.push_back(ss
.str());
1889 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1893 ss
<< setw(tab
) << "" << setw(1);
1898 static void get_md_sync_status(list
<string
>& status
)
1900 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1902 int ret
= sync
.init();
1904 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1908 rgw_meta_sync_status sync_status
;
1909 ret
= sync
.read_sync_status(&sync_status
);
1911 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1916 switch (sync_status
.sync_info
.state
) {
1917 case rgw_meta_sync_info::StateInit
:
1918 status_str
= "init";
1920 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1921 status_str
= "preparing for full sync";
1923 case rgw_meta_sync_info::StateSync
:
1924 status_str
= "syncing";
1927 status_str
= "unknown";
1930 status
.push_back(status_str
);
1932 uint64_t full_total
= 0;
1933 uint64_t full_complete
= 0;
1937 int total_shards
= 0;
1939 for (auto marker_iter
: sync_status
.sync_markers
) {
1940 full_total
+= marker_iter
.second
.total_entries
;
1942 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1944 full_complete
+= marker_iter
.second
.pos
;
1946 full_complete
+= marker_iter
.second
.total_entries
;
1948 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1954 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1957 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1960 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1962 rgw_mdlog_info log_info
;
1963 ret
= sync
.read_log_info(&log_info
);
1965 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1969 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1970 string master_period
= store
->get_current_period_id();
1972 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1974 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1978 map
<int, string
> shards_behind
;
1979 if (sync_status
.sync_info
.period
!= master_period
) {
1980 status
.push_back(string("master is on a different period: master_period=" +
1981 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1983 for (auto local_iter
: sync_status
.sync_markers
) {
1984 int shard_id
= local_iter
.first
;
1985 auto iter
= master_shards_info
.find(shard_id
);
1987 if (iter
== master_shards_info
.end()) {
1989 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
1992 auto master_marker
= iter
->second
.marker
;
1993 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
1994 master_marker
> local_iter
.second
.marker
) {
1995 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2000 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2001 if (total_behind
== 0) {
2002 push_ss(ss
, status
) << "metadata is caught up with master";
2004 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
2006 map
<int, rgw_mdlog_shard_data
> master_pos
;
2007 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
2009 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2011 ceph::real_time oldest
;
2012 for (auto iter
: master_pos
) {
2013 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
2015 if (!shard_data
.entries
.empty()) {
2016 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
2017 if (ceph::real_clock::is_zero(oldest
)) {
2018 oldest
= entry
.timestamp
;
2019 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2020 oldest
= entry
.timestamp
;
2025 if (!ceph::real_clock::is_zero(oldest
)) {
2026 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
2031 flush_ss(ss
, status
);
2034 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
2038 auto ziter
= store
->zone_by_id
.find(source_zone
);
2039 if (ziter
== store
->zone_by_id
.end()) {
2040 push_ss(ss
, status
, tab
) << string("zone not found");
2041 flush_ss(ss
, status
);
2044 RGWZone
& sz
= ziter
->second
;
2046 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
2047 push_ss(ss
, status
, tab
) << string("not syncing from zone");
2048 flush_ss(ss
, status
);
2051 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
2053 int ret
= sync
.init();
2055 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
2056 flush_ss(ss
, status
);
2060 rgw_data_sync_status sync_status
;
2061 ret
= sync
.read_sync_status(&sync_status
);
2062 if (ret
< 0 && ret
!= -ENOENT
) {
2063 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2068 switch (sync_status
.sync_info
.state
) {
2069 case rgw_data_sync_info::StateInit
:
2070 status_str
= "init";
2072 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2073 status_str
= "preparing for full sync";
2075 case rgw_data_sync_info::StateSync
:
2076 status_str
= "syncing";
2079 status_str
= "unknown";
2082 push_ss(ss
, status
, tab
) << status_str
;
2084 uint64_t full_total
= 0;
2085 uint64_t full_complete
= 0;
2089 int total_shards
= 0;
2091 for (auto marker_iter
: sync_status
.sync_markers
) {
2092 full_total
+= marker_iter
.second
.total_entries
;
2094 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2096 full_complete
+= marker_iter
.second
.pos
;
2098 full_complete
+= marker_iter
.second
.total_entries
;
2100 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2105 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2108 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2111 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2113 rgw_datalog_info log_info
;
2114 ret
= sync
.read_log_info(&log_info
);
2116 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2121 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2123 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2125 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2129 map
<int, string
> shards_behind
;
2131 for (auto local_iter
: sync_status
.sync_markers
) {
2132 int shard_id
= local_iter
.first
;
2133 auto iter
= source_shards_info
.find(shard_id
);
2135 if (iter
== source_shards_info
.end()) {
2137 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2140 auto master_marker
= iter
->second
.marker
;
2141 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2142 master_marker
> local_iter
.second
.marker
) {
2143 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2147 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2148 if (total_behind
== 0) {
2149 push_ss(ss
, status
, tab
) << "data is caught up with source";
2151 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2153 map
<int, rgw_datalog_shard_data
> master_pos
;
2154 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2156 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2158 ceph::real_time oldest
;
2159 for (auto iter
: master_pos
) {
2160 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2162 if (!shard_data
.entries
.empty()) {
2163 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2164 if (ceph::real_clock::is_zero(oldest
)) {
2165 oldest
= entry
.timestamp
;
2166 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2167 oldest
= entry
.timestamp
;
2172 if (!ceph::real_clock::is_zero(oldest
)) {
2173 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2178 flush_ss(ss
, status
);
2181 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2185 for (auto e
: entries
) {
2186 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2192 static void sync_status(Formatter
*formatter
)
2194 RGWRealm
& realm
= store
->realm
;
2195 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2196 RGWZone
& zone
= store
->get_zone();
2200 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2201 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2202 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2204 list
<string
> md_status
;
2206 if (store
->is_meta_master()) {
2207 md_status
.push_back("no sync (zone is master)");
2209 get_md_sync_status(md_status
);
2212 tab_dump("metadata sync", width
, md_status
);
2214 list
<string
> data_status
;
2216 for (auto iter
: store
->zone_conn_map
) {
2217 const string
& source_id
= iter
.first
;
2219 string source_str
= "source: ";
2220 string s
= source_str
+ source_id
;
2221 auto siter
= store
->zone_by_id
.find(source_id
);
2222 if (siter
!= store
->zone_by_id
.end()) {
2223 s
+= string(" (") + siter
->second
.name
+ ")";
2225 data_status
.push_back(s
);
2226 get_data_sync_status(source_id
, data_status
, source_str
.size());
2229 tab_dump("data sync", width
, data_status
);
2232 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2235 get_str_list(s
, ",", confs
);
2236 for (auto c
: confs
) {
2237 ssize_t pos
= c
.find("=");
2241 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2246 int check_reshard_bucket_params(RGWRados
*store
,
2247 const string
& bucket_name
,
2248 const string
& tenant
,
2249 const string
& bucket_id
,
2250 bool num_shards_specified
,
2252 int yes_i_really_mean_it
,
2254 RGWBucketInfo
& bucket_info
,
2255 map
<string
, bufferlist
>& attrs
)
2257 if (bucket_name
.empty()) {
2258 cerr
<< "ERROR: bucket not specified" << std::endl
;
2262 if (!num_shards_specified
) {
2263 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2267 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2268 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2272 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2274 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2278 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2280 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2281 cerr
<< "num shards is less or equal to current shards count" << std::endl
2282 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2288 int create_new_bucket_instance(RGWRados
*store
,
2290 const RGWBucketInfo
& bucket_info
,
2291 map
<string
, bufferlist
>& attrs
,
2292 RGWBucketInfo
& new_bucket_info
)
2295 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2296 new_bucket_info
.bucket
.oid
.clear();
2298 new_bucket_info
.num_shards
= new_num_shards
;
2299 new_bucket_info
.objv_tracker
.clear();
2301 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2303 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2307 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2309 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2317 #ifdef BUILDING_FOR_EMBEDDED
2318 extern "C" int cephd_rgw_admin(int argc
, const char **argv
)
2320 int main(int argc
, const char **argv
)
2323 vector
<const char*> args
;
2324 argv_to_vec(argc
, (const char **)argv
, args
);
2327 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2328 CODE_ENVIRONMENT_UTILITY
, 0);
2330 // for region -> zonegroup conversion (must happen before common_init_finish())
2331 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2332 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2335 common_init_finish(g_ceph_context
);
2339 std::string access_key
, secret_key
, user_email
, display_name
;
2340 std::string bucket_name
, pool_name
, object
;
2342 std::string date
, subuser
, access
, format
;
2343 std::string start_date
, end_date
;
2344 std::string key_type_str
;
2345 std::string period_id
, period_epoch
, remote
, url
;
2346 std::string master_zonegroup
, master_zone
;
2347 std::string realm_name
, realm_id
, realm_new_name
;
2348 std::string zone_name
, zone_id
, zone_new_name
;
2349 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2350 std::string api_name
;
2351 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2352 list
<string
> endpoints
;
2354 int sync_from_all_specified
= false;
2355 bool sync_from_all
= false;
2356 list
<string
> sync_from
;
2357 list
<string
> sync_from_rm
;
2358 std::string master_url
;
2360 int set_default
= 0;
2361 bool is_master
= false;
2362 bool is_master_set
= false;
2364 bool read_only
= false;
2365 int is_read_only_set
= false;
2367 int staging
= false;
2368 int key_type
= KEY_TYPE_UNDEFINED
;
2370 uint32_t perm_mask
= 0;
2372 int opt_cmd
= OPT_NO_CMD
;
2374 int gen_access_key
= 0;
2375 int gen_secret_key
= 0;
2376 bool set_perm
= false;
2377 bool set_temp_url_key
= false;
2378 map
<int, string
> temp_url_keys
;
2380 Formatter
*formatter
= NULL
;
2381 int purge_data
= false;
2382 int pretty_format
= false;
2383 int show_log_entries
= true;
2384 int show_log_sum
= true;
2385 int skip_zero_entries
= false; // log show
2386 int purge_keys
= false;
2387 int yes_i_really_mean_it
= false;
2388 int delete_child_objects
= false;
2390 int remove_bad
= false;
2391 int check_head_obj_locator
= false;
2392 int max_buckets
= -1;
2393 bool max_buckets_specified
= false;
2394 map
<string
, bool> categories
;
2396 int check_objects
= false;
2397 RGWUserAdminOpState user_op
;
2398 RGWBucketAdminOpState bucket_op
;
2400 string metadata_key
;
2401 RGWObjVersionTracker objv_tracker
;
2403 string start_marker
;
2405 int max_entries
= -1;
2407 bool admin_specified
= false;
2409 bool system_specified
= false;
2411 bool specified_shard_id
= false;
2413 bool specified_daemon_id
= false;
2417 string replica_log_type_str
;
2418 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2421 string object_version
;
2422 string placement_id
;
2424 list
<string
> tags_add
;
2425 list
<string
> tags_rm
;
2427 int64_t max_objects
= -1;
2428 int64_t max_size
= -1;
2429 bool have_max_objects
= false;
2430 bool have_max_size
= false;
2431 int include_all
= false;
2433 int sync_stats
= false;
2434 int bypass_gc
= false;
2435 int warnings_only
= false;
2436 int inconsistent_index
= false;
2438 int verbose
= false;
2440 int extra_info
= false;
2442 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2443 uint64_t max_rewrite_size
= ULLONG_MAX
;
2444 uint64_t min_rewrite_stripe_size
= 0;
2446 BIIndexType bi_index_type
= PlainIdx
;
2450 bool num_shards_specified
= false;
2451 int max_concurrent_ios
= 32;
2452 uint64_t orphan_stale_secs
= (24 * 3600);
2455 std::ostringstream errs
;
2459 string source_zone_name
;
2460 string source_zone
; /* zone id */
2463 bool tier_type_specified
= false;
2465 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2466 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2468 boost::optional
<string
> index_pool
;
2469 boost::optional
<string
> data_pool
;
2470 boost::optional
<string
> data_extra_pool
;
2471 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2472 bool index_type_specified
= false;
2474 boost::optional
<std::string
> compression_type
;
2476 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2477 if (ceph_argparse_double_dash(args
, i
)) {
2479 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2482 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2483 user_id
.from_str(val
);
2484 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2486 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2488 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2490 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2492 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2494 user_op
.user_email_specified
=true;
2495 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2497 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2499 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2501 pool
= rgw_pool(pool_name
);
2502 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2504 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2505 object_version
= val
;
2506 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2508 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2510 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2512 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2514 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2516 if (key_type_str
.compare("swift") == 0) {
2517 key_type
= KEY_TYPE_SWIFT
;
2518 } else if (key_type_str
.compare("s3") == 0) {
2519 key_type
= KEY_TYPE_S3
;
2521 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2524 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2526 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2528 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2530 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2532 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2534 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2536 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2537 admin_specified
= true;
2538 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2539 system_specified
= true;
2540 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2542 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2544 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2546 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2547 if (!errs
.str().empty()) {
2548 cerr
<< errs
.str() << std::endl
;
2551 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2552 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2553 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2554 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2555 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2556 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2557 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2558 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2560 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2563 max_buckets_specified
= true;
2564 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2565 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2567 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2570 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2571 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2573 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2576 have_max_size
= true;
2577 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2578 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2580 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2583 have_max_objects
= true;
2584 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2586 if (end_date
.empty())
2588 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2590 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2592 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2593 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2595 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2598 num_shards_specified
= true;
2599 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2600 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2602 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2605 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2606 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2608 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2611 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2612 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2614 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2617 specified_shard_id
= true;
2618 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2620 specified_daemon_id
= true;
2621 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2623 perm_mask
= rgw_str_to_perm(access
.c_str());
2625 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2626 temp_url_keys
[0] = val
;
2627 set_temp_url_key
= true;
2628 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2629 temp_url_keys
[1] = val
;
2630 set_temp_url_key
= true;
2631 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2633 if (bucket_id
.empty()) {
2634 cerr
<< "bad bucket-id" << std::endl
;
2637 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2639 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2640 string cat_str
= val
;
2641 list
<string
> cat_list
;
2642 list
<string
>::iterator iter
;
2643 get_str_list(cat_str
, cat_list
);
2644 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2645 categories
[*iter
] = true;
2647 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2649 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2651 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2652 delete_child_objects
= purge_data
;
2653 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2655 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2657 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2659 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2661 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2663 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2665 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2667 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2669 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2671 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2673 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2675 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2677 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2679 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2681 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2683 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2685 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2687 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2689 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2691 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2692 replica_log_type_str
= val
;
2693 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2694 if (replica_log_type
== ReplicaLog_Invalid
) {
2695 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2698 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2699 string index_type_str
= val
;
2700 bi_index_type
= get_bi_index_type(index_type_str
);
2701 if (bi_index_type
== InvalidIdx
) {
2702 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2705 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2706 is_master
= (bool)is_master_int
;
2707 is_master_set
= true;
2708 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2710 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2711 read_only
= (bool)read_only_int
;
2712 is_read_only_set
= true;
2713 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2715 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2716 master_zonegroup
= val
;
2717 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2719 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2721 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2723 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2725 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2727 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2729 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2730 realm_new_name
= val
;
2731 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2733 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2734 zonegroup_new_name
= val
;
2735 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2737 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2738 get_str_list(val
, tags
);
2739 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2740 get_str_list(val
, tags_add
);
2741 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2742 get_str_list(val
, tags_rm
);
2743 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2745 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2747 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2748 zone_new_name
= val
;
2749 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2750 get_str_list(val
, endpoints
);
2751 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2752 get_str_list(val
, sync_from
);
2753 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2754 get_str_list(val
, sync_from_rm
);
2755 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2756 sync_from_all
= (bool)tmp_int
;
2757 sync_from_all_specified
= true;
2758 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2759 source_zone_name
= val
;
2760 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2762 tier_type_specified
= true;
2763 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2764 parse_tier_config_param(val
, tier_config_add
);
2765 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2766 parse_tier_config_param(val
, tier_config_rm
);
2767 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2769 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2771 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2772 data_extra_pool
= val
;
2773 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2774 if (val
== "normal") {
2775 placement_index_type
= RGWBIType_Normal
;
2776 } else if (val
== "indexless") {
2777 placement_index_type
= RGWBIType_Indexless
;
2779 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2781 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2785 index_type_specified
= true;
2786 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2787 compression_type
= val
;
2788 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2790 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2792 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2793 assume_role_doc
= val
;
2794 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2796 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2797 perm_policy_doc
= val
;
2798 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2800 } else if (strncmp(*i
, "-", 1) == 0) {
2801 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
2812 const char *prev_cmd
= NULL
;
2813 const char *prev_prev_cmd
= NULL
;
2814 std::vector
<const char*>::iterator i
;
2815 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
2816 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
2818 cerr
<< "unrecognized arg " << *i
<< std::endl
;
2825 prev_prev_cmd
= prev_cmd
;
2829 if (opt_cmd
== OPT_NO_CMD
)
2832 /* some commands may have an optional extra param */
2833 if (i
!= args
.end()) {
2835 case OPT_METADATA_GET
:
2836 case OPT_METADATA_PUT
:
2837 case OPT_METADATA_RM
:
2838 case OPT_METADATA_LIST
:
2846 if (tenant
.empty()) {
2847 tenant
= user_id
.tenant
;
2849 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
2850 && opt_cmd
!= OPT_ROLE_DELETE
2851 && opt_cmd
!= OPT_ROLE_GET
2852 && opt_cmd
!= OPT_ROLE_MODIFY
2853 && opt_cmd
!= OPT_ROLE_LIST
2854 && opt_cmd
!= OPT_ROLE_POLICY_PUT
2855 && opt_cmd
!= OPT_ROLE_POLICY_LIST
2856 && opt_cmd
!= OPT_ROLE_POLICY_GET
2857 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
) {
2858 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
2861 user_id
.tenant
= tenant
;
2863 /* check key parameter conflict */
2864 if ((!access_key
.empty()) && gen_access_key
) {
2865 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
2868 if ((!secret_key
.empty()) && gen_secret_key
) {
2869 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
2874 // default to pretty json
2875 if (format
.empty()) {
2877 pretty_format
= true;
2880 if (format
== "xml")
2881 formatter
= new XMLFormatter(pretty_format
);
2882 else if (format
== "json")
2883 formatter
= new JSONFormatter(pretty_format
);
2885 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
;
4441 if (!subuser
.empty()) {
4442 ret
= user
.subusers
.add(user_op
, &err_msg
);
4444 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4450 ret
= user
.remove(user_op
, &err_msg
);
4452 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4456 output_user_info
= false;
4458 case OPT_USER_ENABLE
:
4459 case OPT_USER_SUSPEND
:
4460 case OPT_USER_MODIFY
:
4461 ret
= user
.modify(user_op
, &err_msg
);
4463 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4468 case OPT_SUBUSER_CREATE
:
4469 ret
= user
.subusers
.add(user_op
, &err_msg
);
4471 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4476 case OPT_SUBUSER_MODIFY
:
4477 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4479 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4484 case OPT_SUBUSER_RM
:
4485 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4487 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4493 ret
= user
.caps
.add(user_op
, &err_msg
);
4495 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4501 ret
= user
.caps
.remove(user_op
, &err_msg
);
4503 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4508 case OPT_KEY_CREATE
:
4509 ret
= user
.keys
.add(user_op
, &err_msg
);
4511 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4517 ret
= user
.keys
.remove(user_op
, &err_msg
);
4519 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4523 case OPT_PERIOD_PUSH
:
4526 req_info
info(g_ceph_context
, &env
);
4527 info
.method
= "POST";
4528 info
.request_uri
= "/admin/realm/period";
4530 map
<string
, string
> ¶ms
= info
.args
.get_params();
4531 if (!realm_id
.empty())
4532 params
["realm_id"] = realm_id
;
4533 if (!realm_name
.empty())
4534 params
["realm_name"] = realm_name
;
4535 if (!period_id
.empty())
4536 params
["period_id"] = period_id
;
4537 if (!period_epoch
.empty())
4538 params
["epoch"] = period_epoch
;
4541 RGWPeriod
period(period_id
);
4542 int ret
= period
.init(g_ceph_context
, store
);
4544 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4547 // json format into a bufferlist
4548 JSONFormatter
jf(false);
4549 encode_json("period", period
, &jf
);
4554 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4557 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4562 case OPT_PERIOD_UPDATE
:
4564 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4565 commit
, remote
, url
, access_key
, secret_key
,
4566 formatter
, yes_i_really_mean_it
);
4572 case OPT_PERIOD_COMMIT
:
4574 // read realm and staging period
4575 RGWRealm
realm(realm_id
, realm_name
);
4576 int ret
= realm
.init(g_ceph_context
, store
);
4578 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4581 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4582 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4584 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4587 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4588 yes_i_really_mean_it
);
4590 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4594 encode_json("period", period
, formatter
);
4595 formatter
->flush(cout
);
4599 case OPT_ROLE_CREATE
:
4601 if (role_name
.empty()) {
4602 cerr
<< "ERROR: role name is empty" << std::endl
;
4606 if (assume_role_doc
.empty()) {
4607 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4610 /* The following two calls will be replaced by read_decode_json or something
4611 similar when the code for AWS Policies is in places */
4613 int ret
= read_input(assume_role_doc
, bl
);
4615 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4619 if (!p
.parse(bl
.c_str(), bl
.length())) {
4620 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4623 string trust_policy
= bl
.to_str();
4624 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4625 ret
= role
.create(true);
4629 show_role_info(role
, formatter
);
4632 case OPT_ROLE_DELETE
:
4634 if (role_name
.empty()) {
4635 cerr
<< "ERROR: empty role name" << std::endl
;
4638 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4639 ret
= role
.delete_obj();
4643 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4648 if (role_name
.empty()) {
4649 cerr
<< "ERROR: empty role name" << std::endl
;
4652 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4657 show_role_info(role
, formatter
);
4660 case OPT_ROLE_MODIFY
:
4662 if (role_name
.empty()) {
4663 cerr
<< "ERROR: role name is empty" << std::endl
;
4667 if (assume_role_doc
.empty()) {
4668 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4672 /* The following two calls will be replaced by read_decode_json or something
4673 similar when the code for AWS Policies is in place */
4675 int ret
= read_input(assume_role_doc
, bl
);
4677 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4681 if (!p
.parse(bl
.c_str(), bl
.length())) {
4682 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4685 string trust_policy
= bl
.to_str();
4686 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4691 role
.update_trust_policy(trust_policy
);
4692 ret
= role
.update();
4696 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4701 vector
<RGWRole
> result
;
4702 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4706 show_roles_info(result
, formatter
);
4709 case OPT_ROLE_POLICY_PUT
:
4711 if (role_name
.empty()) {
4712 cerr
<< "role name is empty" << std::endl
;
4716 if (policy_name
.empty()) {
4717 cerr
<< "policy name is empty" << std::endl
;
4721 if (perm_policy_doc
.empty()) {
4722 cerr
<< "permission policy document is empty" << std::endl
;
4726 /* The following two calls will be replaced by read_decode_json or something
4727 similar, when code for AWS Policies is in place.*/
4729 int ret
= read_input(perm_policy_doc
, bl
);
4731 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4735 if (!p
.parse(bl
.c_str(), bl
.length())) {
4736 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
4740 perm_policy
= bl
.c_str();
4742 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4747 role
.set_perm_policy(policy_name
, perm_policy
);
4748 ret
= role
.update();
4752 cout
<< "Permission policy attached successfully" << std::endl
;
4755 case OPT_ROLE_POLICY_LIST
:
4757 if (role_name
.empty()) {
4758 cerr
<< "ERROR: Role name is empty" << std::endl
;
4761 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4766 std::vector
<string
> policy_names
= role
.get_role_policy_names();
4767 show_policy_names(policy_names
, formatter
);
4770 case OPT_ROLE_POLICY_GET
:
4772 if (role_name
.empty()) {
4773 cerr
<< "ERROR: role name is empty" << std::endl
;
4777 if (policy_name
.empty()) {
4778 cerr
<< "ERROR: policy name is empty" << std::endl
;
4781 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4782 int ret
= role
.get();
4787 ret
= role
.get_role_policy(policy_name
, perm_policy
);
4791 show_perm_policy(perm_policy
, formatter
);
4794 case OPT_ROLE_POLICY_DELETE
:
4796 if (role_name
.empty()) {
4797 cerr
<< "ERROR: role name is empty" << std::endl
;
4801 if (policy_name
.empty()) {
4802 cerr
<< "ERROR: policy name is empty" << std::endl
;
4805 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4810 ret
= role
.delete_policy(policy_name
);
4814 ret
= role
.update();
4818 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
4819 << role_name
<< std::endl
;
4823 output_user_info
= false;
4826 // output the result of a user operation
4827 if (output_user_info
) {
4828 ret
= user
.info(info
, &err_msg
);
4830 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
4833 show_user_info(info
, formatter
);
4836 if (opt_cmd
== OPT_POLICY
) {
4837 if (format
== "xml") {
4838 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
4840 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4844 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
4846 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4852 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
4854 std::list
<std::string
> user_ids
;
4855 metadata_key
= "user";
4860 if (! user_id
.empty()) {
4861 user_ids
.push_back(user_id
.id
);
4863 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4866 /* list users in groups of max-keys, then perform user-bucket
4867 * limit-check on each group */
4868 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
4870 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
4871 << cpp_strerror(-ret
) << std::endl
;
4876 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
4878 if (ret
< 0 && ret
!= -ENOENT
) {
4879 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
4880 << cpp_strerror(-ret
) << std::endl
;
4883 /* ok, do the limit checks for this group */
4885 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4891 } while (truncated
);
4892 store
->meta_mgr
->list_keys_complete(handle
);
4895 } /* OPT_BUCKET_LIMIT_CHECK */
4897 if (opt_cmd
== OPT_BUCKETS_LIST
) {
4898 if (bucket_name
.empty()) {
4899 RGWBucketAdminOp::info(store
, bucket_op
, f
);
4901 RGWBucketInfo bucket_info
;
4902 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
4904 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
4907 formatter
->open_array_section("entries");
4910 if (max_entries
< 0)
4915 vector
<rgw_bucket_dir_entry
> result
;
4916 map
<string
, bool> common_prefixes
;
4919 RGWRados::Bucket
target(store
, bucket_info
);
4920 RGWRados::Bucket::List
list_op(&target
);
4922 list_op
.params
.prefix
= prefix
;
4923 list_op
.params
.delim
= delim
;
4924 list_op
.params
.marker
= rgw_obj_key(marker
);
4925 list_op
.params
.ns
= ns
;
4926 list_op
.params
.enforce_ns
= false;
4927 list_op
.params
.list_versions
= true;
4930 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
4932 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
4936 count
+= result
.size();
4938 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
4939 rgw_bucket_dir_entry
& entry
= *iter
;
4940 encode_json("entry", entry
, formatter
);
4942 formatter
->flush(cout
);
4943 } while (truncated
&& count
< max_entries
);
4945 formatter
->close_section();
4946 formatter
->flush(cout
);
4947 } /* have bucket_name */
4948 } /* OPT_BUCKETS_LIST */
4950 if (opt_cmd
== OPT_BUCKET_STATS
) {
4951 bucket_op
.set_fetch_stats(true);
4953 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
4955 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4960 if (opt_cmd
== OPT_BUCKET_LINK
) {
4961 bucket_op
.set_bucket_id(bucket_id
);
4963 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
4965 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4970 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
4971 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
4973 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
4978 if (opt_cmd
== OPT_LOG_LIST
) {
4980 if (date
.size() && date
.size() != 10) {
4981 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
4986 formatter
->open_array_section("logs");
4988 int r
= store
->log_list_init(date
, &h
);
4993 cerr
<< "log list: error " << r
<< std::endl
;
4998 int r
= store
->log_list_next(h
, &name
);
5002 cerr
<< "log list: error " << r
<< std::endl
;
5005 formatter
->dump_string("object", name
);
5008 formatter
->close_section();
5009 formatter
->flush(cout
);
5013 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5014 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5015 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5020 if (!object
.empty()) {
5030 if (opt_cmd
== OPT_LOG_SHOW
) {
5033 int r
= store
->log_show_init(oid
, &h
);
5035 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5040 formatter
->open_object_section("log");
5042 struct rgw_log_entry entry
;
5044 // peek at first entry to get bucket metadata
5045 r
= store
->log_show_next(h
, &entry
);
5047 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5050 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5051 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5052 formatter
->dump_string("bucket", entry
.bucket
);
5054 uint64_t agg_time
= 0;
5055 uint64_t agg_bytes_sent
= 0;
5056 uint64_t agg_bytes_received
= 0;
5057 uint64_t total_entries
= 0;
5059 if (show_log_entries
)
5060 formatter
->open_array_section("log_entries");
5063 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5065 agg_time
+= total_time
;
5066 agg_bytes_sent
+= entry
.bytes_sent
;
5067 agg_bytes_received
+= entry
.bytes_received
;
5070 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5071 entry
.bytes_received
== 0)
5074 if (show_log_entries
) {
5076 rgw_format_ops_log_entry(entry
, formatter
);
5077 formatter
->flush(cout
);
5080 r
= store
->log_show_next(h
, &entry
);
5084 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5087 if (show_log_entries
)
5088 formatter
->close_section();
5091 formatter
->open_object_section("log_sum");
5092 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5093 formatter
->dump_int("bytes_received", agg_bytes_received
);
5094 formatter
->dump_int("total_time", agg_time
);
5095 formatter
->dump_int("total_entries", total_entries
);
5096 formatter
->close_section();
5098 formatter
->close_section();
5099 formatter
->flush(cout
);
5102 if (opt_cmd
== OPT_LOG_RM
) {
5103 int r
= store
->log_remove(oid
);
5105 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5111 if (opt_cmd
== OPT_POOL_ADD
) {
5112 if (pool_name
.empty()) {
5113 cerr
<< "need to specify pool to add!" << std::endl
;
5117 int ret
= store
->add_bucket_placement(pool
);
5119 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5122 if (opt_cmd
== OPT_POOL_RM
) {
5123 if (pool_name
.empty()) {
5124 cerr
<< "need to specify pool to remove!" << std::endl
;
5128 int ret
= store
->remove_bucket_placement(pool
);
5130 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5133 if (opt_cmd
== OPT_POOLS_LIST
) {
5134 set
<rgw_pool
> pools
;
5135 int ret
= store
->list_placement_set(pools
);
5137 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5141 formatter
->open_array_section("pools");
5142 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5143 formatter
->open_object_section("pool");
5144 formatter
->dump_string("name", siter
->to_str());
5145 formatter
->close_section();
5147 formatter
->close_section();
5148 formatter
->flush(cout
);
5152 if (opt_cmd
== OPT_USAGE_SHOW
) {
5153 uint64_t start_epoch
= 0;
5154 uint64_t end_epoch
= (uint64_t)-1;
5158 if (!start_date
.empty()) {
5159 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5161 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5165 if (!end_date
.empty()) {
5166 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5168 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5174 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5175 show_log_entries
, show_log_sum
, &categories
,
5178 cerr
<< "ERROR: failed to show usage" << std::endl
;
5183 if (opt_cmd
== OPT_USAGE_TRIM
) {
5184 if (user_id
.empty() && !yes_i_really_mean_it
) {
5185 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5186 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5190 uint64_t start_epoch
= 0;
5191 uint64_t end_epoch
= (uint64_t)-1;
5194 if (!start_date
.empty()) {
5195 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5197 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5202 if (!end_date
.empty()) {
5203 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5205 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5210 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5212 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5217 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5218 if (bucket_name
.empty()) {
5219 cerr
<< "ERROR: bucket not specified" << std::endl
;
5222 if (object
.empty()) {
5223 cerr
<< "ERROR: object not specified" << std::endl
;
5228 if (opt_cmd
== OPT_OLH_GET
) {
5229 RGWBucketInfo bucket_info
;
5230 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5232 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5236 rgw_obj
obj(bucket
, object
);
5237 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5239 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5242 encode_json("olh", olh
, formatter
);
5243 formatter
->flush(cout
);
5246 if (opt_cmd
== OPT_OLH_READLOG
) {
5247 RGWBucketInfo bucket_info
;
5248 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5250 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5253 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5256 RGWObjectCtx
rctx(store
);
5257 rgw_obj
obj(bucket
, object
);
5261 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5266 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5268 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5271 formatter
->open_object_section("result");
5272 encode_json("is_truncated", is_truncated
, formatter
);
5273 encode_json("log", log
, formatter
);
5274 formatter
->close_section();
5275 formatter
->flush(cout
);
5278 if (opt_cmd
== OPT_BI_GET
) {
5279 RGWBucketInfo bucket_info
;
5280 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5282 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5285 rgw_obj
obj(bucket
, object
);
5286 if (!object_version
.empty()) {
5287 obj
.key
.set_instance(object_version
);
5290 rgw_cls_bi_entry entry
;
5292 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5294 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5298 encode_json("entry", entry
, formatter
);
5299 formatter
->flush(cout
);
5302 if (opt_cmd
== OPT_BI_PUT
) {
5303 RGWBucketInfo bucket_info
;
5304 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5306 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5310 rgw_cls_bi_entry entry
;
5311 cls_rgw_obj_key key
;
5312 ret
= read_decode_json(infile
, entry
, &key
);
5317 rgw_obj
obj(bucket
, key
);
5319 ret
= store
->bi_put(bucket
, obj
, entry
);
5321 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5326 if (opt_cmd
== OPT_BI_LIST
) {
5327 if (bucket_name
.empty()) {
5328 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5331 RGWBucketInfo bucket_info
;
5332 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5334 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5338 list
<rgw_cls_bi_entry
> entries
;
5340 if (max_entries
< 0) {
5344 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5346 formatter
->open_array_section("entries");
5348 for (int i
= 0; i
< max_shards
; i
++) {
5349 RGWRados::BucketShard
bs(store
);
5350 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5351 int ret
= bs
.init(bucket
, shard_id
);
5355 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5361 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5363 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5367 list
<rgw_cls_bi_entry
>::iterator iter
;
5368 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5369 rgw_cls_bi_entry
& entry
= *iter
;
5370 encode_json("entry", entry
, formatter
);
5373 formatter
->flush(cout
);
5374 } while (is_truncated
);
5375 formatter
->flush(cout
);
5377 formatter
->close_section();
5378 formatter
->flush(cout
);
5381 if (opt_cmd
== OPT_BI_PURGE
) {
5382 if (bucket_name
.empty()) {
5383 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5386 RGWBucketInfo bucket_info
;
5387 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5389 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5393 RGWBucketInfo cur_bucket_info
;
5394 rgw_bucket cur_bucket
;
5395 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5397 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5401 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5402 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5403 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5407 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5409 for (int i
= 0; i
< max_shards
; i
++) {
5410 RGWRados::BucketShard
bs(store
);
5411 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5412 int ret
= bs
.init(bucket
, shard_id
);
5414 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5418 ret
= store
->bi_remove(bs
);
5420 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5426 if (opt_cmd
== OPT_OBJECT_RM
) {
5427 RGWBucketInfo bucket_info
;
5428 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5430 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5433 rgw_obj_key
key(object
, object_version
);
5434 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5437 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5442 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5443 if (bucket_name
.empty()) {
5444 cerr
<< "ERROR: bucket not specified" << std::endl
;
5447 if (object
.empty()) {
5448 cerr
<< "ERROR: object not specified" << std::endl
;
5452 RGWBucketInfo bucket_info
;
5453 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5455 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5459 rgw_obj
obj(bucket
, object
);
5460 obj
.key
.set_instance(object_version
);
5461 bool need_rewrite
= true;
5462 if (min_rewrite_stripe_size
> 0) {
5463 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5465 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5469 ret
= store
->rewrite_obj(bucket_info
, obj
);
5471 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5475 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5479 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5480 int ret
= store
->process_expire_objects();
5482 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5487 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5488 if (bucket_name
.empty()) {
5489 cerr
<< "ERROR: bucket not specified" << std::endl
;
5493 RGWBucketInfo bucket_info
;
5494 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5496 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5500 uint64_t start_epoch
= 0;
5501 uint64_t end_epoch
= 0;
5503 if (!end_date
.empty()) {
5504 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5506 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5510 if (!start_date
.empty()) {
5511 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5513 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5518 bool is_truncated
= true;
5520 rgw_obj_index_key marker
;
5523 formatter
->open_object_section("result");
5524 formatter
->dump_string("bucket", bucket_name
);
5525 formatter
->open_array_section("objects");
5526 while (is_truncated
) {
5527 map
<string
, rgw_bucket_dir_entry
> result
;
5528 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5529 result
, &is_truncated
, &marker
,
5530 bucket_object_check_filter
);
5532 if (r
< 0 && r
!= -ENOENT
) {
5533 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5539 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5540 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5541 rgw_obj_key key
= iter
->second
.key
;
5542 rgw_bucket_dir_entry
& entry
= iter
->second
;
5544 formatter
->open_object_section("object");
5545 formatter
->dump_string("name", key
.name
);
5546 formatter
->dump_string("instance", key
.instance
);
5547 formatter
->dump_int("size", entry
.meta
.size
);
5548 utime_t
ut(entry
.meta
.mtime
);
5549 ut
.gmtime(formatter
->dump_stream("mtime"));
5551 if ((entry
.meta
.size
< min_rewrite_size
) ||
5552 (entry
.meta
.size
> max_rewrite_size
) ||
5553 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5554 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5555 formatter
->dump_string("status", "Skipped");
5557 rgw_obj
obj(bucket
, key
);
5559 bool need_rewrite
= true;
5560 if (min_rewrite_stripe_size
> 0) {
5561 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5563 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5566 if (!need_rewrite
) {
5567 formatter
->dump_string("status", "Skipped");
5569 r
= store
->rewrite_obj(bucket_info
, obj
);
5571 formatter
->dump_string("status", "Success");
5573 formatter
->dump_string("status", cpp_strerror(-r
));
5577 formatter
->dump_int("flags", entry
.flags
);
5579 formatter
->close_section();
5580 formatter
->flush(cout
);
5583 formatter
->close_section();
5584 formatter
->close_section();
5585 formatter
->flush(cout
);
5588 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5590 RGWBucketInfo bucket_info
;
5591 map
<string
, bufferlist
> attrs
;
5593 int ret
= check_reshard_bucket_params(store
,
5597 num_shards_specified
,
5599 yes_i_really_mean_it
,
5607 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5609 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5610 if (max_entries
< 1) {
5611 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5614 return br
.execute(num_shards
, max_entries
,
5615 verbose
, &cout
, formatter
);
5618 if (opt_cmd
== OPT_RESHARD_ADD
) {
5620 RGWBucketInfo bucket_info
;
5621 map
<string
, bufferlist
> attrs
;
5623 int ret
= check_reshard_bucket_params(store
,
5627 num_shards_specified
,
5629 yes_i_really_mean_it
,
5637 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5639 RGWReshard
reshard(store
);
5640 cls_rgw_reshard_entry entry
;
5641 entry
.time
= real_clock::now();
5642 entry
.tenant
= tenant
;
5643 entry
.bucket_name
= bucket_name
;
5644 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5645 entry
.old_num_shards
= num_source_shards
;
5646 entry
.new_num_shards
= num_shards
;
5648 return reshard
.add(entry
);
5651 if (opt_cmd
== OPT_RESHARD_LIST
) {
5652 list
<cls_rgw_reshard_entry
> entries
;
5655 if (max_entries
< 0) {
5659 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5661 RGWReshard
reshard(store
);
5663 formatter
->open_array_section("reshard");
5664 for (int i
= 0; i
< num_logshards
; i
++) {
5665 bool is_truncated
= true;
5669 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5671 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5674 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5675 cls_rgw_reshard_entry
& entry
= *iter
;
5676 encode_json("entry", entry
, formatter
);
5677 entry
.get_key(&marker
);
5679 count
+= entries
.size();
5680 formatter
->flush(cout
);
5681 } while (is_truncated
&& count
< max_entries
);
5683 if (count
>= max_entries
) {
5688 formatter
->close_section();
5689 formatter
->flush(cout
);
5694 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5695 if (bucket_name
.empty()) {
5696 cerr
<< "ERROR: bucket not specified" << std::endl
;
5701 RGWBucketInfo bucket_info
;
5702 map
<string
, bufferlist
> attrs
;
5703 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5705 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5709 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5710 list
<cls_rgw_bucket_instance_entry
> status
;
5711 int r
= br
.get_status(&status
);
5713 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5717 encode_json("status", status
, formatter
);
5718 formatter
->flush(cout
);
5721 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5722 RGWReshard
reshard(store
, true, &cout
);
5724 int ret
= reshard
.process_all_logshards();
5726 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
5731 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
5732 RGWReshard
reshard(store
);
5734 if (bucket_name
.empty()) {
5735 cerr
<< "ERROR: bucket not specified" << std::endl
;
5738 cls_rgw_reshard_entry entry
;
5739 //entry.tenant = tenant;
5740 entry
.bucket_name
= bucket_name
;
5741 //entry.bucket_id = bucket_id;
5742 int ret
= reshard
.get(entry
);
5744 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5748 /* TBD stop running resharding */
5750 ret
=reshard
.remove(entry
);
5752 cerr
<< "Error removing bucket " << bucket_name
<< " for resharding queue: " << cpp_strerror(-ret
) <<
5758 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
5759 RGWBucketInfo bucket_info
;
5760 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5762 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5765 list
<rgw_obj_index_key
> oid_list
;
5766 rgw_obj_key
key(object
, object_version
);
5767 rgw_obj_index_key index_key
;
5768 key
.get_index_key(&index_key
);
5769 oid_list
.push_back(index_key
);
5770 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
5772 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
5777 if (opt_cmd
== OPT_OBJECT_STAT
) {
5778 RGWBucketInfo bucket_info
;
5779 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5781 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5784 rgw_obj
obj(bucket
, object
);
5785 obj
.key
.set_instance(object_version
);
5788 map
<string
, bufferlist
> attrs
;
5789 RGWObjectCtx
obj_ctx(store
);
5790 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
5791 RGWRados::Object::Read
read_op(&op_target
);
5793 read_op
.params
.attrs
= &attrs
;
5794 read_op
.params
.obj_size
= &obj_size
;
5796 ret
= read_op
.prepare();
5798 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
5801 formatter
->open_object_section("object_metadata");
5802 formatter
->dump_string("name", object
);
5803 formatter
->dump_unsigned("size", obj_size
);
5805 map
<string
, bufferlist
>::iterator iter
;
5806 map
<string
, bufferlist
> other_attrs
;
5807 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5808 bufferlist
& bl
= iter
->second
;
5809 bool handled
= false;
5810 if (iter
->first
== RGW_ATTR_MANIFEST
) {
5811 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
5812 } else if (iter
->first
== RGW_ATTR_ACL
) {
5813 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
5814 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
5815 handled
= dump_string("tag", bl
, formatter
);
5816 } else if (iter
->first
== RGW_ATTR_ETAG
) {
5817 handled
= dump_string("etag", bl
, formatter
);
5821 other_attrs
[iter
->first
] = bl
;
5824 formatter
->open_object_section("attrs");
5825 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
5826 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
5828 formatter
->close_section();
5829 formatter
->close_section();
5830 formatter
->flush(cout
);
5833 if (opt_cmd
== OPT_BUCKET_CHECK
) {
5834 if (check_head_obj_locator
) {
5835 if (bucket_name
.empty()) {
5836 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
5839 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
5841 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
5845 if (opt_cmd
== OPT_BUCKET_RM
) {
5846 if (inconsistent_index
== false) {
5847 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
5849 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
5853 if (opt_cmd
== OPT_GC_LIST
) {
5856 formatter
->open_array_section("entries");
5859 list
<cls_rgw_gc_obj_info
> result
;
5860 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
5862 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5867 list
<cls_rgw_gc_obj_info
>::iterator iter
;
5868 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5869 cls_rgw_gc_obj_info
& info
= *iter
;
5870 formatter
->open_object_section("chain_info");
5871 formatter
->dump_string("tag", info
.tag
);
5872 formatter
->dump_stream("time") << info
.time
;
5873 formatter
->open_array_section("objs");
5874 list
<cls_rgw_obj
>::iterator liter
;
5875 cls_rgw_obj_chain
& chain
= info
.chain
;
5876 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
5877 cls_rgw_obj
& obj
= *liter
;
5878 encode_json("obj", obj
, formatter
);
5880 formatter
->close_section(); // objs
5881 formatter
->close_section(); // obj_chain
5882 formatter
->flush(cout
);
5884 } while (truncated
);
5885 formatter
->close_section();
5886 formatter
->flush(cout
);
5889 if (opt_cmd
== OPT_GC_PROCESS
) {
5890 int ret
= store
->process_gc();
5892 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5897 if (opt_cmd
== OPT_LC_LIST
) {
5898 formatter
->open_array_section("lifecycle_list");
5899 map
<string
, int> bucket_lc_map
;
5901 #define MAX_LC_LIST_ENTRIES 100
5902 if (max_entries
< 0) {
5903 max_entries
= MAX_LC_LIST_ENTRIES
;
5906 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
5908 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5911 map
<string
, int>::iterator iter
;
5912 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
5913 formatter
->open_object_section("bucket_lc_info");
5914 formatter
->dump_string("bucket", iter
->first
);
5915 string lc_status
= LC_STATUS
[iter
->second
];
5916 formatter
->dump_string("status", lc_status
);
5917 formatter
->close_section(); // objs
5918 formatter
->flush(cout
);
5919 marker
= iter
->first
;
5921 } while (!bucket_lc_map
.empty());
5923 formatter
->close_section(); //lifecycle list
5924 formatter
->flush(cout
);
5928 if (opt_cmd
== OPT_LC_PROCESS
) {
5929 int ret
= store
->process_lc();
5931 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5936 if (opt_cmd
== OPT_ORPHANS_FIND
) {
5937 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5939 if (job_id
.empty()) {
5940 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5943 if (pool_name
.empty()) {
5944 cerr
<< "ERROR: --pool not specified" << std::endl
;
5948 RGWOrphanSearchInfo info
;
5951 info
.job_name
= job_id
;
5952 info
.num_shards
= num_shards
;
5954 int ret
= search
.init(job_id
, &info
);
5956 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
5965 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
5966 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5968 if (job_id
.empty()) {
5969 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5972 int ret
= search
.init(job_id
, NULL
);
5974 if (ret
== -ENOENT
) {
5975 cerr
<< "job not found" << std::endl
;
5979 ret
= search
.finish();
5985 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
5986 RGWOrphanStore
orphan_store(store
);
5987 int ret
= orphan_store
.init();
5989 cerr
<< "connection to cluster failed!" << std::endl
;
5993 map
<string
,RGWOrphanSearchState
> m
;
5994 ret
= orphan_store
.list_jobs(m
);
5996 cerr
<< "job list failed" << std::endl
;
5999 formatter
->open_array_section("entries");
6000 for (const auto &it
: m
){
6002 formatter
->dump_string("job-id",it
.first
);
6004 encode_json("orphan_search_state", it
.second
, formatter
);
6007 formatter
->close_section();
6008 formatter
->flush(cout
);
6011 if (opt_cmd
== OPT_USER_CHECK
) {
6012 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6015 if (opt_cmd
== OPT_USER_STATS
) {
6017 if (!bucket_name
.empty()) {
6018 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6020 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
6024 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6026 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
6032 if (user_id
.empty()) {
6033 cerr
<< "ERROR: uid not specified" << std::endl
;
6036 cls_user_header header
;
6037 string user_str
= user_id
.to_str();
6038 int ret
= store
->cls_user_get_header(user_str
, &header
);
6040 if (ret
== -ENOENT
) { /* in case of ENOENT */
6041 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6043 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6048 encode_json("header", header
, formatter
);
6049 formatter
->flush(cout
);
6052 if (opt_cmd
== OPT_METADATA_GET
) {
6053 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6055 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6059 formatter
->flush(cout
);
6062 if (opt_cmd
== OPT_METADATA_PUT
) {
6064 int ret
= read_input(infile
, bl
);
6066 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6069 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6071 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6076 if (opt_cmd
== OPT_METADATA_RM
) {
6077 int ret
= store
->meta_mgr
->remove(metadata_key
);
6079 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6084 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6085 if (opt_cmd
== OPT_USER_LIST
) {
6086 metadata_key
= "user";
6090 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
6092 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6098 formatter
->open_array_section("keys");
6102 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, keys
, &truncated
);
6103 if (ret
< 0 && ret
!= -ENOENT
) {
6104 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6106 } if (ret
!= -ENOENT
) {
6107 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6108 formatter
->dump_string("key", *iter
);
6110 formatter
->flush(cout
);
6112 } while (truncated
);
6114 formatter
->close_section();
6115 formatter
->flush(cout
);
6117 store
->meta_mgr
->list_keys_complete(handle
);
6120 if (opt_cmd
== OPT_MDLOG_LIST
) {
6121 utime_t start_time
, end_time
;
6123 int ret
= parse_date_str(start_date
, start_time
);
6127 ret
= parse_date_str(end_date
, end_time
);
6131 int i
= (specified_shard_id
? shard_id
: 0);
6133 if (period_id
.empty()) {
6134 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6138 std::cerr
<< "No --period given, using current period="
6139 << period_id
<< std::endl
;
6141 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6143 formatter
->open_array_section("entries");
6144 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6146 list
<cls_log_entry
> entries
;
6149 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6152 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6154 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6158 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6159 cls_log_entry
& entry
= *iter
;
6160 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6162 formatter
->flush(cout
);
6163 } while (truncated
);
6165 meta_log
->complete_list_entries(handle
);
6167 if (specified_shard_id
)
6172 formatter
->close_section();
6173 formatter
->flush(cout
);
6176 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6177 int i
= (specified_shard_id
? shard_id
: 0);
6179 if (period_id
.empty()) {
6180 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6184 std::cerr
<< "No --period given, using current period="
6185 << period_id
<< std::endl
;
6187 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6189 formatter
->open_array_section("entries");
6191 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6192 RGWMetadataLogInfo info
;
6193 meta_log
->get_info(i
, &info
);
6195 ::encode_json("info", info
, formatter
);
6197 if (specified_shard_id
)
6202 formatter
->close_section();
6203 formatter
->flush(cout
);
6206 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6207 // need a full history for purging old mdlog periods
6208 store
->meta_mgr
->init_oldest_log_period();
6210 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6211 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6212 int ret
= http
.set_threaded();
6214 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6218 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6219 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6221 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6226 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6227 utime_t start_time
, end_time
;
6229 if (!specified_shard_id
) {
6230 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6234 int ret
= parse_date_str(start_date
, start_time
);
6238 ret
= parse_date_str(end_date
, end_time
);
6242 if (period_id
.empty()) {
6243 std::cerr
<< "missing --period argument" << std::endl
;
6246 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6248 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6250 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6255 if (opt_cmd
== OPT_SYNC_STATUS
) {
6256 sync_status(formatter
);
6259 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6260 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6262 int ret
= sync
.init();
6264 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6268 rgw_meta_sync_status sync_status
;
6269 ret
= sync
.read_sync_status(&sync_status
);
6271 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6275 formatter
->open_object_section("summary");
6276 encode_json("sync_status", sync_status
, formatter
);
6278 uint64_t full_total
= 0;
6279 uint64_t full_complete
= 0;
6281 for (auto marker_iter
: sync_status
.sync_markers
) {
6282 full_total
+= marker_iter
.second
.total_entries
;
6283 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6284 full_complete
+= marker_iter
.second
.pos
;
6286 full_complete
+= marker_iter
.second
.total_entries
;
6290 formatter
->open_object_section("full_sync");
6291 encode_json("total", full_total
, formatter
);
6292 encode_json("complete", full_complete
, formatter
);
6293 formatter
->close_section();
6294 formatter
->close_section();
6296 formatter
->flush(cout
);
6300 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6301 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6303 int ret
= sync
.init();
6305 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6308 ret
= sync
.init_sync_status();
6310 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6316 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6317 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6319 int ret
= sync
.init();
6321 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6327 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6332 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6333 if (source_zone
.empty()) {
6334 cerr
<< "ERROR: source zone not specified" << std::endl
;
6337 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6339 int ret
= sync
.init();
6341 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6345 rgw_data_sync_status sync_status
;
6346 ret
= sync
.read_sync_status(&sync_status
);
6347 if (ret
< 0 && ret
!= -ENOENT
) {
6348 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6352 formatter
->open_object_section("summary");
6353 encode_json("sync_status", sync_status
, formatter
);
6355 uint64_t full_total
= 0;
6356 uint64_t full_complete
= 0;
6358 for (auto marker_iter
: sync_status
.sync_markers
) {
6359 full_total
+= marker_iter
.second
.total_entries
;
6360 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6361 full_complete
+= marker_iter
.second
.pos
;
6363 full_complete
+= marker_iter
.second
.total_entries
;
6367 formatter
->open_object_section("full_sync");
6368 encode_json("total", full_total
, formatter
);
6369 encode_json("complete", full_complete
, formatter
);
6370 formatter
->close_section();
6371 formatter
->close_section();
6373 formatter
->flush(cout
);
6376 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6377 if (source_zone
.empty()) {
6378 cerr
<< "ERROR: source zone not specified" << std::endl
;
6381 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6383 int ret
= sync
.init();
6385 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6389 ret
= sync
.init_sync_status();
6391 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6396 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6397 if (source_zone
.empty()) {
6398 cerr
<< "ERROR: source zone not specified" << std::endl
;
6401 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6403 int ret
= sync
.init();
6405 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6411 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6416 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6417 if (source_zone
.empty()) {
6418 cerr
<< "ERROR: source zone not specified" << std::endl
;
6421 if (bucket_name
.empty()) {
6422 cerr
<< "ERROR: bucket not specified" << std::endl
;
6426 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6430 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6434 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6437 ret
= sync
.init_sync_status();
6439 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6444 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
6445 if (bucket_name
.empty()) {
6446 cerr
<< "ERROR: bucket not specified" << std::endl
;
6451 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
6455 ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
, true);
6457 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
6461 if (!store
->is_meta_master()) {
6462 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
6463 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
6467 rgw_obj
obj(bucket
, object
);
6468 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
6473 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6474 if (source_zone
.empty()) {
6475 cerr
<< "ERROR: source zone not specified" << std::endl
;
6478 if (bucket_name
.empty()) {
6479 cerr
<< "ERROR: bucket not specified" << std::endl
;
6483 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6487 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6491 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6494 ret
= sync
.read_sync_status();
6496 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6500 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6502 encode_json("sync_status", sync_status
, formatter
);
6503 formatter
->flush(cout
);
6506 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6507 if (source_zone
.empty()) {
6508 cerr
<< "ERROR: source zone not specified" << std::endl
;
6511 if (bucket_name
.empty()) {
6512 cerr
<< "ERROR: bucket not specified" << std::endl
;
6516 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6520 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6524 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6530 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6535 if (opt_cmd
== OPT_BILOG_LIST
) {
6536 if (bucket_name
.empty()) {
6537 cerr
<< "ERROR: bucket not specified" << std::endl
;
6540 RGWBucketInfo bucket_info
;
6541 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6543 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6546 formatter
->open_array_section("entries");
6549 if (max_entries
< 0)
6553 list
<rgw_bi_log_entry
> entries
;
6554 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6556 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6560 count
+= entries
.size();
6562 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6563 rgw_bi_log_entry
& entry
= *iter
;
6564 encode_json("entry", entry
, formatter
);
6568 formatter
->flush(cout
);
6569 } while (truncated
&& count
< max_entries
);
6571 formatter
->close_section();
6572 formatter
->flush(cout
);
6575 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6576 if (max_entries
< 0) {
6581 utime_t start_time
, end_time
;
6583 int ret
= parse_date_str(start_date
, start_time
);
6587 ret
= parse_date_str(end_date
, end_time
);
6595 formatter
->open_array_section("entries");
6597 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6598 formatter
->open_object_section("shard");
6599 encode_json("shard_id", shard_id
, formatter
);
6600 formatter
->open_array_section("entries");
6603 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6606 list
<cls_log_entry
> entries
;
6607 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6608 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6609 if (ret
== -ENOENT
) {
6613 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6617 count
+= entries
.size();
6619 for (auto& cls_entry
: entries
) {
6620 rgw_sync_error_info log_entry
;
6622 auto iter
= cls_entry
.data
.begin();
6624 ::decode(log_entry
, iter
);
6625 } catch (buffer::error
& err
) {
6626 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6629 formatter
->open_object_section("entry");
6630 encode_json("id", cls_entry
.id
, formatter
);
6631 encode_json("section", cls_entry
.section
, formatter
);
6632 encode_json("name", cls_entry
.name
, formatter
);
6633 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
6634 encode_json("info", log_entry
, formatter
);
6635 formatter
->close_section();
6636 formatter
->flush(cout
);
6638 } while (truncated
&& count
< max_entries
);
6640 formatter
->close_section();
6641 formatter
->close_section();
6643 if (specified_shard_id
) {
6648 formatter
->close_section();
6649 formatter
->flush(cout
);
6652 if (opt_cmd
== OPT_BILOG_TRIM
) {
6653 if (bucket_name
.empty()) {
6654 cerr
<< "ERROR: bucket not specified" << std::endl
;
6657 RGWBucketInfo bucket_info
;
6658 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6660 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6663 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
6665 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6670 if (opt_cmd
== OPT_BILOG_STATUS
) {
6671 if (bucket_name
.empty()) {
6672 cerr
<< "ERROR: bucket not specified" << std::endl
;
6675 RGWBucketInfo bucket_info
;
6676 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6678 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6681 map
<int, string
> markers
;
6682 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
6684 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
6687 formatter
->open_object_section("entries");
6688 encode_json("markers", markers
, formatter
);
6689 formatter
->close_section();
6690 formatter
->flush(cout
);
6693 if (opt_cmd
== OPT_DATALOG_LIST
) {
6694 formatter
->open_array_section("entries");
6697 if (max_entries
< 0)
6700 utime_t start_time
, end_time
;
6702 int ret
= parse_date_str(start_date
, start_time
);
6706 ret
= parse_date_str(end_date
, end_time
);
6710 RGWDataChangesLog
*log
= store
->data_log
;
6711 RGWDataChangesLog::LogMarker marker
;
6714 list
<rgw_data_change_log_entry
> entries
;
6715 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
6717 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6721 count
+= entries
.size();
6723 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6724 rgw_data_change_log_entry
& entry
= *iter
;
6726 encode_json("entry", entry
.entry
, formatter
);
6728 encode_json("entry", entry
, formatter
);
6731 formatter
->flush(cout
);
6732 } while (truncated
&& count
< max_entries
);
6734 formatter
->close_section();
6735 formatter
->flush(cout
);
6738 if (opt_cmd
== OPT_DATALOG_STATUS
) {
6739 RGWDataChangesLog
*log
= store
->data_log
;
6740 int i
= (specified_shard_id
? shard_id
: 0);
6742 formatter
->open_array_section("entries");
6743 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
6744 list
<cls_log_entry
> entries
;
6746 RGWDataChangesLogInfo info
;
6747 log
->get_info(i
, &info
);
6749 ::encode_json("info", info
, formatter
);
6751 if (specified_shard_id
)
6755 formatter
->close_section();
6756 formatter
->flush(cout
);
6759 if (opt_cmd
== OPT_DATALOG_TRIM
) {
6760 utime_t start_time
, end_time
;
6762 int ret
= parse_date_str(start_date
, start_time
);
6766 ret
= parse_date_str(end_date
, end_time
);
6770 RGWDataChangesLog
*log
= store
->data_log
;
6771 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6773 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
6778 if (opt_cmd
== OPT_OPSTATE_LIST
) {
6779 RGWOpState
oc(store
);
6784 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
6785 list
<cls_statelog_entry
> entries
;
6787 formatter
->open_array_section("entries");
6789 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
6791 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
6792 oc
.finish_list_entries(handle
);
6796 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6797 oc
.dump_entry(*iter
, formatter
);
6800 formatter
->flush(cout
);
6802 formatter
->close_section();
6803 formatter
->flush(cout
);
6804 oc
.finish_list_entries(handle
);
6807 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
6808 RGWOpState
oc(store
);
6810 RGWOpState::OpState state
;
6811 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6812 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6815 if (state_str
.empty()) {
6816 cerr
<< "ERROR: state was not specified" << std::endl
;
6819 int ret
= oc
.state_from_str(state_str
, &state
);
6821 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
6825 if (opt_cmd
== OPT_OPSTATE_SET
) {
6826 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
6828 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6832 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
6834 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
6839 if (opt_cmd
== OPT_OPSTATE_RM
) {
6840 RGWOpState
oc(store
);
6842 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6843 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6846 ret
= oc
.remove_entry(client_id
, op_id
, object
);
6848 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6853 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
6854 opt_cmd
== OPT_REPLICALOG_DELETE
) {
6855 if (replica_log_type_str
.empty()) {
6856 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
6861 if (opt_cmd
== OPT_REPLICALOG_GET
) {
6862 RGWReplicaBounds bounds
;
6863 if (replica_log_type
== ReplicaLog_Metadata
) {
6864 if (!specified_shard_id
) {
6865 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6869 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6870 int ret
= logger
.get_bounds(shard_id
, bounds
);
6873 } else if (replica_log_type
== ReplicaLog_Data
) {
6874 if (!specified_shard_id
) {
6875 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6878 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6879 int ret
= logger
.get_bounds(shard_id
, bounds
);
6882 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6883 if (bucket_name
.empty()) {
6884 cerr
<< "ERROR: bucket not specified" << std::endl
;
6887 RGWBucketInfo bucket_info
;
6888 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6890 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6894 RGWReplicaBucketLogger
logger(store
);
6895 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
6898 } else { // shouldn't get here
6901 encode_json("bounds", bounds
, formatter
);
6902 formatter
->flush(cout
);
6906 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
6907 if (replica_log_type
== ReplicaLog_Metadata
) {
6908 if (!specified_shard_id
) {
6909 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6912 if (!specified_daemon_id
) {
6913 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6916 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6917 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6920 } else if (replica_log_type
== ReplicaLog_Data
) {
6921 if (!specified_shard_id
) {
6922 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6925 if (!specified_daemon_id
) {
6926 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6929 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6930 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6933 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6934 if (bucket_name
.empty()) {
6935 cerr
<< "ERROR: bucket not specified" << std::endl
;
6938 RGWBucketInfo bucket_info
;
6939 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6941 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6945 RGWReplicaBucketLogger
logger(store
);
6946 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
6952 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
6953 if (marker
.empty()) {
6954 cerr
<< "ERROR: marker was not specified" <<std::endl
;
6957 utime_t time
= ceph_clock_now();
6958 if (!date
.empty()) {
6959 ret
= parse_date_str(date
, time
);
6961 cerr
<< "ERROR: failed to parse start date" << std::endl
;
6965 list
<RGWReplicaItemMarker
> entries
;
6966 int ret
= read_decode_json(infile
, entries
);
6968 cerr
<< "ERROR: failed to decode entries" << std::endl
;
6971 RGWReplicaBounds bounds
;
6972 if (replica_log_type
== ReplicaLog_Metadata
) {
6973 if (!specified_shard_id
) {
6974 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6978 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6979 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6981 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6984 } else if (replica_log_type
== ReplicaLog_Data
) {
6985 if (!specified_shard_id
) {
6986 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6989 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6990 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6992 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6995 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6996 if (bucket_name
.empty()) {
6997 cerr
<< "ERROR: bucket not specified" << std::endl
;
7000 RGWBucketInfo bucket_info
;
7001 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7003 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7007 RGWReplicaBucketLogger
logger(store
);
7008 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
7010 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7016 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7019 if (bucket_name
.empty() && user_id
.empty()) {
7020 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7024 if (!bucket_name
.empty()) {
7025 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7026 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7029 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7030 max_size
, max_objects
, have_max_size
, have_max_objects
);
7031 } else if (!user_id
.empty()) {
7032 if (quota_scope
== "bucket") {
7033 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7034 } else if (quota_scope
== "user") {
7035 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7037 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;