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
<< " bi get retrieve bucket index object entries\n";
85 cout
<< " bi put store bucket index object entries\n";
86 cout
<< " bi list list raw bucket index entries\n";
87 cout
<< " object rm remove object\n";
88 cout
<< " object stat stat an object for its metadata\n";
89 cout
<< " object unlink unlink object from bucket index\n";
90 cout
<< " objects expire run expired objects cleanup\n";
91 cout
<< " period delete delete a period\n";
92 cout
<< " period get get period info\n";
93 cout
<< " period get-current get current period info\n";
94 cout
<< " period pull pull a period\n";
95 cout
<< " period push push a period\n";
96 cout
<< " period list list all periods\n";
97 cout
<< " period update update the staging period\n";
98 cout
<< " period commit commit the staging period\n";
99 cout
<< " quota set set quota params\n";
100 cout
<< " quota enable enable quota\n";
101 cout
<< " quota disable disable quota\n";
102 cout
<< " global quota get view global quota params\n";
103 cout
<< " global quota set set global quota params\n";
104 cout
<< " global quota enable enable a global quota\n";
105 cout
<< " global quota disable disable a global quota\n";
106 cout
<< " realm create create a new realm\n";
107 cout
<< " realm delete delete a realm\n";
108 cout
<< " realm get show realm info\n";
109 cout
<< " realm get-default get default realm name\n";
110 cout
<< " realm list list realms\n";
111 cout
<< " realm list-periods list all realm periods\n";
112 cout
<< " realm remove remove a zonegroup from the realm\n";
113 cout
<< " realm rename rename a realm\n";
114 cout
<< " realm set set realm info (requires infile)\n";
115 cout
<< " realm default set realm as default\n";
116 cout
<< " realm pull pull a realm and its current period\n";
117 cout
<< " zonegroup add add a zone to a zonegroup\n";
118 cout
<< " zonegroup create create a new zone group info\n";
119 cout
<< " zonegroup default set default zone group\n";
120 cout
<< " zonegroup delete delete a zone group info\n";
121 cout
<< " zonegroup get show zone group info\n";
122 cout
<< " zonegroup modify modify an existing zonegroup\n";
123 cout
<< " zonegroup set set zone group info (requires infile)\n";
124 cout
<< " zonegroup remove remove a zone from a zonegroup\n";
125 cout
<< " zonegroup rename rename a zone group\n";
126 cout
<< " zonegroup list list all zone groups set on this cluster\n";
127 cout
<< " zonegroup placement list list zonegroup's placement targets\n";
128 cout
<< " zonegroup placement add add a placement target id to a zonegroup\n";
129 cout
<< " zonegroup placement modify modify a placement target of a specific zonegroup\n";
130 cout
<< " zonegroup placement rm remove a placement target from a zonegroup\n";
131 cout
<< " zonegroup placement default set a zonegroup's default placement target\n";
132 cout
<< " zone create create a new zone\n";
133 cout
<< " zone delete delete a zone\n";
134 cout
<< " zone get show zone cluster params\n";
135 cout
<< " zone modify modify an existing zone\n";
136 cout
<< " zone set set zone cluster params (requires infile)\n";
137 cout
<< " zone list list all zones set on this cluster\n";
138 cout
<< " zone rename rename a zone\n";
139 cout
<< " zone placement list list zone's placement targets\n";
140 cout
<< " zone placement add add a zone placement target\n";
141 cout
<< " zone placement modify modify a zone placement target\n";
142 cout
<< " zone placement rm remove a zone placement target\n";
143 cout
<< " pool add add an existing pool for data placement\n";
144 cout
<< " pool rm remove an existing pool from data placement set\n";
145 cout
<< " pools list list placement active set\n";
146 cout
<< " policy read bucket/object policy\n";
147 cout
<< " log list list log objects\n";
148 cout
<< " log show dump a log from specific object or (bucket + date\n";
149 cout
<< " + bucket-id)\n";
150 cout
<< " (NOTE: required to specify formatting of date\n";
151 cout
<< " to \"YYYY-MM-DD-hh\")\n";
152 cout
<< " log rm remove log object\n";
153 cout
<< " usage show show usage (by user, date range)\n";
154 cout
<< " usage trim trim usage (by user, date range)\n";
155 cout
<< " gc list dump expired garbage collection objects (specify\n";
156 cout
<< " --include-all to list all entries, including unexpired)\n";
157 cout
<< " gc process manually process garbage\n";
158 cout
<< " lc list list all bucket lifecycle progress\n";
159 cout
<< " lc process manually process lifecycle\n";
160 cout
<< " metadata get get metadata info\n";
161 cout
<< " metadata put put metadata info\n";
162 cout
<< " metadata rm remove metadata info\n";
163 cout
<< " metadata list list metadata info\n";
164 cout
<< " mdlog list list metadata log\n";
165 cout
<< " mdlog trim trim metadata log (use start-date, end-date or\n";
166 cout
<< " start-marker, end-marker)\n";
167 cout
<< " mdlog status read metadata log status\n";
168 cout
<< " bilog list list bucket index log\n";
169 cout
<< " bilog trim trim bucket index log (use start-marker, end-marker)\n";
170 cout
<< " datalog list list data log\n";
171 cout
<< " datalog trim trim data log\n";
172 cout
<< " datalog status read data log status\n";
173 cout
<< " opstate list list stateful operations entries (use client_id,\n";
174 cout
<< " op_id, object)\n";
175 cout
<< " opstate set set state on an entry (use client_id, op_id, object, state)\n";
176 cout
<< " opstate renew renew state on an entry (use client_id, op_id, object)\n";
177 cout
<< " opstate rm remove entry (use client_id, op_id, object)\n";
178 cout
<< " replicalog get get replica metadata log entry\n";
179 cout
<< " replicalog update update replica metadata log entry\n";
180 cout
<< " replicalog delete delete replica metadata log entry\n";
181 cout
<< " orphans find init and run search for leaked rados objects (use job-id, pool)\n";
182 cout
<< " orphans finish clean up search for leaked rados objects\n";
183 cout
<< " orphans list-jobs list the current job-ids for orphans search\n";
184 cout
<< " role create create a AWS role for use with STS\n";
185 cout
<< " role delete delete a role\n";
186 cout
<< " role get get a role\n";
187 cout
<< " role list list roles with specified path prefix\n";
188 cout
<< " role modify modify the assume role policy of an existing role\n";
189 cout
<< " role-policy put add/update permission policy to role\n";
190 cout
<< " role-policy list list policies attached to a role\n";
191 cout
<< " role-policy get get the specified inline policy document embedded with the given role\n";
192 cout
<< " role-policy delete delete policy attached to a role\n";
193 cout
<< " reshard add schedule a resharding of a bucket\n";
194 cout
<< " reshard list list all bucket resharding or scheduled to be reshared\n";
195 cout
<< " reshard process process of scheduled reshard jobs\n";
196 cout
<< " reshard cancel cancel resharding a bucket\n";
197 cout
<< "options:\n";
198 cout
<< " --tenant=<tenant> tenant name\n";
199 cout
<< " --uid=<id> user id\n";
200 cout
<< " --subuser=<name> subuser name\n";
201 cout
<< " --access-key=<key> S3 access key\n";
202 cout
<< " --email=<email>\n";
203 cout
<< " --secret/--secret-key=<key>\n";
204 cout
<< " specify secret key\n";
205 cout
<< " --gen-access-key generate random access key (for S3)\n";
206 cout
<< " --gen-secret generate random secret key\n";
207 cout
<< " --key-type=<type> key type, options are: swift, s3\n";
208 cout
<< " --temp-url-key[-2]=<key> temp url key\n";
209 cout
<< " --access=<access> Set access permissions for sub-user, should be one\n";
210 cout
<< " of read, write, readwrite, full\n";
211 cout
<< " --display-name=<name>\n";
212 cout
<< " --max_buckets max number of buckets for a user\n";
213 cout
<< " --admin set the admin flag on the user\n";
214 cout
<< " --system set the system flag on the user\n";
215 cout
<< " --bucket=<bucket>\n";
216 cout
<< " --pool=<pool>\n";
217 cout
<< " --object=<object>\n";
218 cout
<< " --date=<date>\n";
219 cout
<< " --start-date=<date>\n";
220 cout
<< " --end-date=<date>\n";
221 cout
<< " --bucket-id=<bucket-id>\n";
222 cout
<< " --shard-id=<shard-id> optional for mdlog list\n";
223 cout
<< " required for: \n";
224 cout
<< " mdlog trim\n";
225 cout
<< " replica mdlog get/delete\n";
226 cout
<< " replica datalog get/delete\n";
227 cout
<< " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
228 cout
<< " --remote=<remote> zone or zonegroup id of remote gateway\n";
229 cout
<< " --period=<id> period id\n";
230 cout
<< " --epoch=<number> period epoch\n";
231 cout
<< " --commit commit the period during 'period update'\n";
232 cout
<< " --staging get staging period info\n";
233 cout
<< " --master set as master\n";
234 cout
<< " --master-url master url\n";
235 cout
<< " --master-zonegroup=<id> master zonegroup id\n";
236 cout
<< " --master-zone=<id> master zone id\n";
237 cout
<< " --rgw-realm=<name> realm name\n";
238 cout
<< " --realm-id=<id> realm id\n";
239 cout
<< " --realm-new-name=<name> realm new name\n";
240 cout
<< " --rgw-zonegroup=<name> zonegroup name\n";
241 cout
<< " --zonegroup-id=<id> zonegroup id\n";
242 cout
<< " --zonegroup-new-name=<name>\n";
243 cout
<< " zonegroup new name\n";
244 cout
<< " --rgw-zone=<name> name of zone in which radosgw is running\n";
245 cout
<< " --zone-id=<id> zone id\n";
246 cout
<< " --zone-new-name=<name> zone new name\n";
247 cout
<< " --source-zone specify the source zone (for data sync)\n";
248 cout
<< " --default set entity (realm, zonegroup, zone) as default\n";
249 cout
<< " --read-only set zone as read-only (when adding to zonegroup)\n";
250 cout
<< " --placement-id placement id for zonegroup placement commands\n";
251 cout
<< " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
252 cout
<< " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
253 cout
<< " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
254 cout
<< " --endpoints=<list> zone endpoints\n";
255 cout
<< " --index_pool=<pool> placement target index pool\n";
256 cout
<< " --data_pool=<pool> placement target data pool\n";
257 cout
<< " --data_extra_pool=<pool> placement target data extra (non-ec) pool\n";
258 cout
<< " --placement-index-type=<type>\n";
259 cout
<< " placement target index type (normal, indexless, or #id)\n";
260 cout
<< " --compression=<type> placement target compression type (plugin name or empty/none)\n";
261 cout
<< " --tier-type=<type> zone tier type\n";
262 cout
<< " --tier-config=<k>=<v>[,...]\n";
263 cout
<< " set zone tier config keys, values\n";
264 cout
<< " --tier-config-rm=<k>[,...]\n";
265 cout
<< " unset zone tier config keys\n";
266 cout
<< " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
267 cout
<< " --sync-from=[zone-name][,...]\n";
268 cout
<< " set list of zones to sync from\n";
269 cout
<< " --sync-from-rm=[zone-name][,...]\n";
270 cout
<< " remove zones from list of zones to sync from\n";
271 cout
<< " --fix besides checking bucket index, will also fix it\n";
272 cout
<< " --check-objects bucket check: rebuilds bucket index according to\n";
273 cout
<< " actual objects state\n";
274 cout
<< " --format=<format> specify output format for certain operations: xml,\n";
276 cout
<< " --purge-data when specified, user removal will also purge all the\n";
277 cout
<< " user data\n";
278 cout
<< " --purge-keys when specified, subuser removal will also purge all the\n";
279 cout
<< " subuser keys\n";
280 cout
<< " --purge-objects remove a bucket's objects before deleting it\n";
281 cout
<< " (NOTE: required to delete a non-empty bucket)\n";
282 cout
<< " --sync-stats option to 'user stats', update user stats with current\n";
283 cout
<< " stats reported by user's buckets indexes\n";
284 cout
<< " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
285 cout
<< " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
286 cout
<< " --skip-zero-entries log show only dumps entries that don't have zero value\n";
287 cout
<< " in one of the numeric field\n";
288 cout
<< " --infile=<file> specify a file to read in when setting data\n";
289 cout
<< " --state=<state string> specify a state for the opstate set command\n";
290 cout
<< " --replica-log-type replica log type (metadata, data, bucket), required for\n";
291 cout
<< " replica log operations\n";
292 cout
<< " --categories=<list> comma separated list of categories, used in usage show\n";
293 cout
<< " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
294 cout
<< " --yes-i-really-mean-it required for certain operations\n";
295 cout
<< " --warnings-only when specified with bucket limit check, list\n";
296 cout
<< " only buckets nearing or over the current max\n";
297 cout
<< " objects per shard value\n";
298 cout
<< " --bypass-gc when specified with bucket deletion, triggers\n";
299 cout
<< " object deletions by not involving GC\n";
300 cout
<< " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
301 cout
<< " ignores bucket index consistency\n";
303 cout
<< "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
304 cout
<< "\nQuota options:\n";
305 cout
<< " --bucket specified bucket for quota command\n";
306 cout
<< " --max-objects specify max objects (negative value to disable)\n";
307 cout
<< " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
308 cout
<< " --quota-scope scope of quota (bucket, user)\n";
309 cout
<< "\nOrphans search options:\n";
310 cout
<< " --pool data pool to scan for leaked rados objects in\n";
311 cout
<< " --num-shards num of shards to use for keeping the temporary scan info\n";
312 cout
<< " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
313 cout
<< " --job-id set the job id (for orphans find)\n";
314 cout
<< " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
315 cout
<< "\nOrphans list-jobs options:\n";
316 cout
<< " --extra-info provide extra info in job list\n";
317 cout
<< "\nRole options:\n";
318 cout
<< " --role-name name of the role to create\n";
319 cout
<< " --path path to the role\n";
320 cout
<< " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
321 cout
<< " --policy-name name of the policy document\n";
322 cout
<< " --policy-doc permission policy document\n";
323 cout
<< " --path-prefix path prefix for filtering roles\n";
325 generic_client_usage();
351 OPT_BUCKET_LIMIT_CHECK
,
356 OPT_BUCKET_SYNC_STATUS
,
357 OPT_BUCKET_SYNC_INIT
,
391 OPT_ORPHANS_LIST_JOBS
,
393 OPT_ZONEGROUP_CREATE
,
394 OPT_ZONEGROUP_DEFAULT
,
395 OPT_ZONEGROUP_DELETE
,
397 OPT_ZONEGROUP_MODIFY
,
400 OPT_ZONEGROUP_REMOVE
,
401 OPT_ZONEGROUP_RENAME
,
402 OPT_ZONEGROUP_PLACEMENT_ADD
,
403 OPT_ZONEGROUP_PLACEMENT_MODIFY
,
404 OPT_ZONEGROUP_PLACEMENT_RM
,
405 OPT_ZONEGROUP_PLACEMENT_LIST
,
406 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
415 OPT_ZONE_PLACEMENT_ADD
,
416 OPT_ZONE_PLACEMENT_MODIFY
,
417 OPT_ZONE_PLACEMENT_RM
,
418 OPT_ZONE_PLACEMENT_LIST
,
425 OPT_METADATA_SYNC_STATUS
,
426 OPT_METADATA_SYNC_INIT
,
427 OPT_METADATA_SYNC_RUN
,
437 OPT_DATA_SYNC_STATUS
,
448 OPT_REPLICALOG_UPDATE
,
449 OPT_REPLICALOG_DELETE
,
453 OPT_REALM_GET_DEFAULT
,
455 OPT_REALM_LIST_PERIODS
,
463 OPT_PERIOD_GET_CURRENT
,
469 OPT_GLOBAL_QUOTA_GET
,
470 OPT_GLOBAL_QUOTA_SET
,
471 OPT_GLOBAL_QUOTA_ENABLE
,
472 OPT_GLOBAL_QUOTA_DISABLE
,
480 OPT_ROLE_POLICY_LIST
,
482 OPT_ROLE_POLICY_DELETE
,
490 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
493 // NOTE: please keep the checks in alphabetical order !!!
494 if (strcmp(cmd
, "bi") == 0 ||
495 strcmp(cmd
, "bilog") == 0 ||
496 strcmp(cmd
, "buckets") == 0 ||
497 strcmp(cmd
, "caps") == 0 ||
498 strcmp(cmd
, "data") == 0 ||
499 strcmp(cmd
, "datalog") == 0 ||
500 strcmp(cmd
, "error") == 0 ||
501 strcmp(cmd
, "gc") == 0 ||
502 strcmp(cmd
, "global") == 0 ||
503 strcmp(cmd
, "key") == 0 ||
504 strcmp(cmd
, "log") == 0 ||
505 strcmp(cmd
, "lc") == 0 ||
506 strcmp(cmd
, "mdlog") == 0 ||
507 strcmp(cmd
, "metadata") == 0 ||
508 strcmp(cmd
, "object") == 0 ||
509 strcmp(cmd
, "objects") == 0 ||
510 strcmp(cmd
, "olh") == 0 ||
511 strcmp(cmd
, "opstate") == 0 ||
512 strcmp(cmd
, "orphans") == 0 ||
513 strcmp(cmd
, "period") == 0 ||
514 strcmp(cmd
, "placement") == 0 ||
515 strcmp(cmd
, "pool") == 0 ||
516 strcmp(cmd
, "pools") == 0 ||
517 strcmp(cmd
, "quota") == 0 ||
518 strcmp(cmd
, "realm") == 0 ||
519 strcmp(cmd
, "replicalog") == 0 ||
520 strcmp(cmd
, "role") == 0 ||
521 strcmp(cmd
, "role-policy") == 0 ||
522 strcmp(cmd
, "subuser") == 0 ||
523 strcmp(cmd
, "sync") == 0 ||
524 strcmp(cmd
, "usage") == 0 ||
525 strcmp(cmd
, "user") == 0 ||
526 strcmp(cmd
, "zone") == 0 ||
527 strcmp(cmd
, "zonegroup") == 0 ||
528 strcmp(cmd
, "zonegroups") == 0) {
534 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
536 if (strcmp(cmd
, "reshard") == 0 &&
537 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
541 if (strcmp(cmd
, "bucket") == 0 &&
542 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
547 if (strcmp(cmd
, "policy") == 0)
553 if (strcmp(prev_cmd
, "user") == 0) {
554 if (strcmp(cmd
, "create") == 0)
555 return OPT_USER_CREATE
;
556 if (strcmp(cmd
, "info") == 0)
557 return OPT_USER_INFO
;
558 if (strcmp(cmd
, "modify") == 0)
559 return OPT_USER_MODIFY
;
560 if (strcmp(cmd
, "rm") == 0)
562 if (strcmp(cmd
, "suspend") == 0)
563 return OPT_USER_SUSPEND
;
564 if (strcmp(cmd
, "enable") == 0)
565 return OPT_USER_ENABLE
;
566 if (strcmp(cmd
, "check") == 0)
567 return OPT_USER_CHECK
;
568 if (strcmp(cmd
, "stats") == 0)
569 return OPT_USER_STATS
;
570 if (strcmp(cmd
, "list") == 0)
571 return OPT_USER_LIST
;
572 } else if (strcmp(prev_cmd
, "subuser") == 0) {
573 if (strcmp(cmd
, "create") == 0)
574 return OPT_SUBUSER_CREATE
;
575 if (strcmp(cmd
, "modify") == 0)
576 return OPT_SUBUSER_MODIFY
;
577 if (strcmp(cmd
, "rm") == 0)
578 return OPT_SUBUSER_RM
;
579 } else if (strcmp(prev_cmd
, "key") == 0) {
580 if (strcmp(cmd
, "create") == 0)
581 return OPT_KEY_CREATE
;
582 if (strcmp(cmd
, "rm") == 0)
584 } else if (strcmp(prev_cmd
, "buckets") == 0) {
585 if (strcmp(cmd
, "list") == 0)
586 return OPT_BUCKETS_LIST
;
587 } else if (strcmp(prev_cmd
, "bucket") == 0) {
588 if (strcmp(cmd
, "list") == 0)
589 return OPT_BUCKETS_LIST
;
590 if (strcmp(cmd
, "link") == 0)
591 return OPT_BUCKET_LINK
;
592 if (strcmp(cmd
, "unlink") == 0)
593 return OPT_BUCKET_UNLINK
;
594 if (strcmp(cmd
, "stats") == 0)
595 return OPT_BUCKET_STATS
;
596 if (strcmp(cmd
, "rm") == 0)
597 return OPT_BUCKET_RM
;
598 if (strcmp(cmd
, "rewrite") == 0)
599 return OPT_BUCKET_REWRITE
;
600 if (strcmp(cmd
, "reshard") == 0)
601 return OPT_BUCKET_RESHARD
;
602 if (strcmp(cmd
, "check") == 0)
603 return OPT_BUCKET_CHECK
;
604 if (strcmp(cmd
, "sync") == 0) {
608 if (strcmp(cmd
, "limit") == 0) {
612 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
613 if (strcmp(prev_cmd
, "sync") == 0) {
614 if (strcmp(cmd
, "status") == 0)
615 return OPT_BUCKET_SYNC_STATUS
;
616 if (strcmp(cmd
, "init") == 0)
617 return OPT_BUCKET_SYNC_INIT
;
618 if (strcmp(cmd
, "run") == 0)
619 return OPT_BUCKET_SYNC_RUN
;
620 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
621 (strcmp(cmd
, "check") == 0)) {
622 return OPT_BUCKET_LIMIT_CHECK
;
624 } else if (strcmp(prev_cmd
, "log") == 0) {
625 if (strcmp(cmd
, "list") == 0)
627 if (strcmp(cmd
, "show") == 0)
629 if (strcmp(cmd
, "rm") == 0)
631 } else if (strcmp(prev_cmd
, "usage") == 0) {
632 if (strcmp(cmd
, "show") == 0)
633 return OPT_USAGE_SHOW
;
634 if (strcmp(cmd
, "trim") == 0)
635 return OPT_USAGE_TRIM
;
636 } else if (strcmp(prev_cmd
, "caps") == 0) {
637 if (strcmp(cmd
, "add") == 0)
639 if (strcmp(cmd
, "rm") == 0)
641 } else if (strcmp(prev_cmd
, "pool") == 0) {
642 if (strcmp(cmd
, "add") == 0)
644 if (strcmp(cmd
, "rm") == 0)
646 if (strcmp(cmd
, "list") == 0)
647 return OPT_POOLS_LIST
;
648 } else if (strcmp(prev_cmd
, "pools") == 0) {
649 if (strcmp(cmd
, "list") == 0)
650 return OPT_POOLS_LIST
;
651 } else if (strcmp(prev_cmd
, "object") == 0) {
652 if (strcmp(cmd
, "rm") == 0)
653 return OPT_OBJECT_RM
;
654 if (strcmp(cmd
, "unlink") == 0)
655 return OPT_OBJECT_UNLINK
;
656 if (strcmp(cmd
, "stat") == 0)
657 return OPT_OBJECT_STAT
;
658 if (strcmp(cmd
, "rewrite") == 0)
659 return OPT_OBJECT_REWRITE
;
660 } else if (strcmp(prev_cmd
, "objects") == 0) {
661 if (strcmp(cmd
, "expire") == 0)
662 return OPT_OBJECTS_EXPIRE
;
663 } else if (strcmp(prev_cmd
, "olh") == 0) {
664 if (strcmp(cmd
, "get") == 0)
666 if (strcmp(cmd
, "readlog") == 0)
667 return OPT_OLH_READLOG
;
668 } else if (strcmp(prev_cmd
, "bi") == 0) {
669 if (strcmp(cmd
, "get") == 0)
671 if (strcmp(cmd
, "put") == 0)
673 if (strcmp(cmd
, "list") == 0)
675 if (strcmp(cmd
, "purge") == 0)
677 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
678 (strcmp(prev_cmd
, "quota") == 0)) {
679 if (strcmp(cmd
, "get") == 0)
680 return OPT_GLOBAL_QUOTA_GET
;
681 if (strcmp(cmd
, "set") == 0)
682 return OPT_GLOBAL_QUOTA_SET
;
683 if (strcmp(cmd
, "enable") == 0)
684 return OPT_GLOBAL_QUOTA_ENABLE
;
685 if (strcmp(cmd
, "disable") == 0)
686 return OPT_GLOBAL_QUOTA_DISABLE
;
687 } else if (strcmp(prev_cmd
, "period") == 0) {
688 if (strcmp(cmd
, "delete") == 0)
689 return OPT_PERIOD_DELETE
;
690 if (strcmp(cmd
, "get") == 0)
691 return OPT_PERIOD_GET
;
692 if (strcmp(cmd
, "get-current") == 0)
693 return OPT_PERIOD_GET_CURRENT
;
694 if (strcmp(cmd
, "pull") == 0)
695 return OPT_PERIOD_PULL
;
696 if (strcmp(cmd
, "push") == 0)
697 return OPT_PERIOD_PUSH
;
698 if (strcmp(cmd
, "list") == 0)
699 return OPT_PERIOD_LIST
;
700 if (strcmp(cmd
, "update") == 0)
701 return OPT_PERIOD_UPDATE
;
702 if (strcmp(cmd
, "commit") == 0)
703 return OPT_PERIOD_COMMIT
;
704 } else if (strcmp(prev_cmd
, "realm") == 0) {
705 if (strcmp(cmd
, "create") == 0)
706 return OPT_REALM_CREATE
;
707 if (strcmp(cmd
, "delete") == 0)
708 return OPT_REALM_DELETE
;
709 if (strcmp(cmd
, "get") == 0)
710 return OPT_REALM_GET
;
711 if (strcmp(cmd
, "get-default") == 0)
712 return OPT_REALM_GET_DEFAULT
;
713 if (strcmp(cmd
, "list") == 0)
714 return OPT_REALM_LIST
;
715 if (strcmp(cmd
, "list-periods") == 0)
716 return OPT_REALM_LIST_PERIODS
;
717 if (strcmp(cmd
, "remove") == 0)
718 return OPT_REALM_REMOVE
;
719 if (strcmp(cmd
, "rename") == 0)
720 return OPT_REALM_RENAME
;
721 if (strcmp(cmd
, "set") == 0)
722 return OPT_REALM_SET
;
723 if (strcmp(cmd
, "default") == 0)
724 return OPT_REALM_DEFAULT
;
725 if (strcmp(cmd
, "pull") == 0)
726 return OPT_REALM_PULL
;
727 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
728 (strcmp(prev_cmd
, "placement") == 0)) {
729 if (strcmp(cmd
, "add") == 0)
730 return OPT_ZONEGROUP_PLACEMENT_ADD
;
731 if (strcmp(cmd
, "modify") == 0)
732 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
733 if (strcmp(cmd
, "rm") == 0)
734 return OPT_ZONEGROUP_PLACEMENT_RM
;
735 if (strcmp(cmd
, "list") == 0)
736 return OPT_ZONEGROUP_PLACEMENT_LIST
;
737 if (strcmp(cmd
, "default") == 0)
738 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
739 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
740 if (strcmp(cmd
, "add") == 0)
741 return OPT_ZONEGROUP_ADD
;
742 if (strcmp(cmd
, "create")== 0)
743 return OPT_ZONEGROUP_CREATE
;
744 if (strcmp(cmd
, "default") == 0)
745 return OPT_ZONEGROUP_DEFAULT
;
746 if (strcmp(cmd
, "delete") == 0)
747 return OPT_ZONEGROUP_DELETE
;
748 if (strcmp(cmd
, "get") == 0)
749 return OPT_ZONEGROUP_GET
;
750 if (strcmp(cmd
, "modify") == 0)
751 return OPT_ZONEGROUP_MODIFY
;
752 if (strcmp(cmd
, "list") == 0)
753 return OPT_ZONEGROUP_LIST
;
754 if (strcmp(cmd
, "set") == 0)
755 return OPT_ZONEGROUP_SET
;
756 if (strcmp(cmd
, "remove") == 0)
757 return OPT_ZONEGROUP_REMOVE
;
758 if (strcmp(cmd
, "rename") == 0)
759 return OPT_ZONEGROUP_RENAME
;
760 } else if (strcmp(prev_cmd
, "quota") == 0) {
761 if (strcmp(cmd
, "set") == 0)
762 return OPT_QUOTA_SET
;
763 if (strcmp(cmd
, "enable") == 0)
764 return OPT_QUOTA_ENABLE
;
765 if (strcmp(cmd
, "disable") == 0)
766 return OPT_QUOTA_DISABLE
;
767 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
768 if (strcmp(cmd
, "list") == 0)
769 return OPT_ZONEGROUP_LIST
;
770 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
771 (strcmp(prev_cmd
, "placement") == 0)) {
772 if (strcmp(cmd
, "add") == 0)
773 return OPT_ZONE_PLACEMENT_ADD
;
774 if (strcmp(cmd
, "modify") == 0)
775 return OPT_ZONE_PLACEMENT_MODIFY
;
776 if (strcmp(cmd
, "rm") == 0)
777 return OPT_ZONE_PLACEMENT_RM
;
778 if (strcmp(cmd
, "list") == 0)
779 return OPT_ZONE_PLACEMENT_LIST
;
780 } else if (strcmp(prev_cmd
, "zone") == 0) {
781 if (strcmp(cmd
, "delete") == 0)
782 return OPT_ZONE_DELETE
;
783 if (strcmp(cmd
, "create") == 0)
784 return OPT_ZONE_CREATE
;
785 if (strcmp(cmd
, "get") == 0)
787 if (strcmp(cmd
, "set") == 0)
789 if (strcmp(cmd
, "list") == 0)
790 return OPT_ZONE_LIST
;
791 if (strcmp(cmd
, "modify") == 0)
792 return OPT_ZONE_MODIFY
;
793 if (strcmp(cmd
, "rename") == 0)
794 return OPT_ZONE_RENAME
;
795 if (strcmp(cmd
, "default") == 0)
796 return OPT_ZONE_DEFAULT
;
797 } else if (strcmp(prev_cmd
, "zones") == 0) {
798 if (strcmp(cmd
, "list") == 0)
799 return OPT_ZONE_LIST
;
800 } else if (strcmp(prev_cmd
, "gc") == 0) {
801 if (strcmp(cmd
, "list") == 0)
803 if (strcmp(cmd
, "process") == 0)
804 return OPT_GC_PROCESS
;
805 } else if (strcmp(prev_cmd
, "lc") == 0) {
806 if (strcmp(cmd
, "list") == 0)
808 if (strcmp(cmd
, "process") == 0)
809 return OPT_LC_PROCESS
;
810 } else if (strcmp(prev_cmd
, "orphans") == 0) {
811 if (strcmp(cmd
, "find") == 0)
812 return OPT_ORPHANS_FIND
;
813 if (strcmp(cmd
, "finish") == 0)
814 return OPT_ORPHANS_FINISH
;
815 if (strcmp(cmd
, "list-jobs") == 0)
816 return OPT_ORPHANS_LIST_JOBS
;
817 } else if (strcmp(prev_cmd
, "metadata") == 0) {
818 if (strcmp(cmd
, "get") == 0)
819 return OPT_METADATA_GET
;
820 if (strcmp(cmd
, "put") == 0)
821 return OPT_METADATA_PUT
;
822 if (strcmp(cmd
, "rm") == 0)
823 return OPT_METADATA_RM
;
824 if (strcmp(cmd
, "list") == 0)
825 return OPT_METADATA_LIST
;
826 if (strcmp(cmd
, "sync") == 0) {
830 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
831 (strcmp(prev_cmd
, "sync") == 0)) {
832 if (strcmp(cmd
, "status") == 0)
833 return OPT_METADATA_SYNC_STATUS
;
834 if (strcmp(cmd
, "init") == 0)
835 return OPT_METADATA_SYNC_INIT
;
836 if (strcmp(cmd
, "run") == 0)
837 return OPT_METADATA_SYNC_RUN
;
838 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
839 (strcmp(prev_cmd
, "error") == 0)) {
840 if (strcmp(cmd
, "list") == 0)
841 return OPT_SYNC_ERROR_LIST
;
842 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
843 if (strcmp(cmd
, "list") == 0)
844 return OPT_MDLOG_LIST
;
845 if (strcmp(cmd
, "autotrim") == 0)
846 return OPT_MDLOG_AUTOTRIM
;
847 if (strcmp(cmd
, "trim") == 0)
848 return OPT_MDLOG_TRIM
;
849 if (strcmp(cmd
, "fetch") == 0)
850 return OPT_MDLOG_FETCH
;
851 if (strcmp(cmd
, "status") == 0)
852 return OPT_MDLOG_STATUS
;
853 } else if (strcmp(prev_cmd
, "bilog") == 0) {
854 if (strcmp(cmd
, "list") == 0)
855 return OPT_BILOG_LIST
;
856 if (strcmp(cmd
, "trim") == 0)
857 return OPT_BILOG_TRIM
;
858 if (strcmp(cmd
, "status") == 0)
859 return OPT_BILOG_STATUS
;
860 } else if (strcmp(prev_cmd
, "data") == 0) {
861 if (strcmp(cmd
, "sync") == 0) {
865 } else if (strcmp(prev_cmd
, "datalog") == 0) {
866 if (strcmp(cmd
, "list") == 0)
867 return OPT_DATALOG_LIST
;
868 if (strcmp(cmd
, "trim") == 0)
869 return OPT_DATALOG_TRIM
;
870 if (strcmp(cmd
, "status") == 0)
871 return OPT_DATALOG_STATUS
;
872 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
873 (strcmp(prev_cmd
, "sync") == 0)) {
874 if (strcmp(cmd
, "status") == 0)
875 return OPT_DATA_SYNC_STATUS
;
876 if (strcmp(cmd
, "init") == 0)
877 return OPT_DATA_SYNC_INIT
;
878 if (strcmp(cmd
, "run") == 0)
879 return OPT_DATA_SYNC_RUN
;
880 } else if (strcmp(prev_cmd
, "opstate") == 0) {
881 if (strcmp(cmd
, "list") == 0)
882 return OPT_OPSTATE_LIST
;
883 if (strcmp(cmd
, "set") == 0)
884 return OPT_OPSTATE_SET
;
885 if (strcmp(cmd
, "renew") == 0)
886 return OPT_OPSTATE_RENEW
;
887 if (strcmp(cmd
, "rm") == 0)
888 return OPT_OPSTATE_RM
;
889 } else if (strcmp(prev_cmd
, "replicalog") == 0) {
890 if (strcmp(cmd
, "get") == 0)
891 return OPT_REPLICALOG_GET
;
892 if (strcmp(cmd
, "update") == 0)
893 return OPT_REPLICALOG_UPDATE
;
894 if (strcmp(cmd
, "delete") == 0)
895 return OPT_REPLICALOG_DELETE
;
896 } else if (strcmp(prev_cmd
, "sync") == 0) {
897 if (strcmp(cmd
, "status") == 0)
898 return OPT_SYNC_STATUS
;
899 } else if (strcmp(prev_cmd
, "role") == 0) {
900 if (strcmp(cmd
, "create") == 0)
901 return OPT_ROLE_CREATE
;
902 if (strcmp(cmd
, "delete") == 0)
903 return OPT_ROLE_DELETE
;
904 if (strcmp(cmd
, "get") == 0)
906 if (strcmp(cmd
, "modify") == 0)
907 return OPT_ROLE_MODIFY
;
908 if (strcmp(cmd
, "list") == 0)
909 return OPT_ROLE_LIST
;
910 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
911 if (strcmp(cmd
, "put") == 0)
912 return OPT_ROLE_POLICY_PUT
;
913 if (strcmp(cmd
, "list") == 0)
914 return OPT_ROLE_POLICY_LIST
;
915 if (strcmp(cmd
, "get") == 0)
916 return OPT_ROLE_POLICY_GET
;
917 if (strcmp(cmd
, "delete") == 0)
918 return OPT_ROLE_POLICY_DELETE
;
919 } else if (strcmp(prev_cmd
, "reshard") == 0) {
920 if (strcmp(cmd
, "bucket") == 0)
921 return OPT_BUCKET_RESHARD
;
922 if (strcmp(cmd
, "add") == 0)
923 return OPT_RESHARD_ADD
;
924 if (strcmp(cmd
, "list") == 0)
925 return OPT_RESHARD_LIST
;
926 if (strcmp(cmd
, "status") == 0)
927 return OPT_RESHARD_STATUS
;
928 if (strcmp(cmd
, "execute") == 0)
929 return OPT_RESHARD_PROCESS
;
930 if (strcmp(cmd
, "cancel") == 0)
931 return OPT_RESHARD_CANCEL
;
937 enum ReplicaLogType
{
938 ReplicaLog_Invalid
= 0,
944 ReplicaLogType
get_replicalog_type(const string
& name
) {
945 if (name
== "md" || name
== "meta" || name
== "metadata")
946 return ReplicaLog_Metadata
;
948 return ReplicaLog_Data
;
949 if (name
== "bucket")
950 return ReplicaLog_Bucket
;
952 return ReplicaLog_Invalid
;
955 BIIndexType
get_bi_index_type(const string
& type_str
) {
956 if (type_str
== "plain")
958 if (type_str
== "instance")
960 if (type_str
== "olh")
966 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
968 bufferlist::iterator iter
= bl
.begin();
969 switch (index_type
) {
973 rgw_bucket_dir_entry entry
;
974 ::decode(entry
, iter
);
975 encode_json("entry", entry
, formatter
);
980 rgw_bucket_olh_entry entry
;
981 ::decode(entry
, iter
);
982 encode_json("entry", entry
, formatter
);
991 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
993 encode_json("user_info", info
, formatter
);
994 formatter
->flush(cout
);
998 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1000 formatter
->open_object_section("role");
1001 formatter
->dump_string("Permission policy", perm_policy
);
1002 formatter
->close_section();
1003 formatter
->flush(cout
);
1006 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1008 formatter
->open_array_section("PolicyNames");
1009 for (const auto& it
: policy_names
) {
1010 formatter
->dump_string("policyname", it
);
1012 formatter
->close_section();
1013 formatter
->flush(cout
);
1016 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1018 formatter
->open_object_section("role");
1019 role
.dump(formatter
);
1020 formatter
->close_section();
1021 formatter
->flush(cout
);
1024 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1026 formatter
->open_array_section("Roles");
1027 for (const auto& it
: roles
) {
1028 formatter
->open_object_section("role");
1030 formatter
->close_section();
1032 formatter
->close_section();
1033 formatter
->flush(cout
);
1036 class StoreDestructor
{
1039 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1040 ~StoreDestructor() {
1041 RGWStoreManager::close_storage(store
);
1045 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1046 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1048 if (!bucket_name
.empty()) {
1049 RGWObjectCtx
obj_ctx(store
);
1051 if (bucket_id
.empty()) {
1052 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1054 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1055 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1058 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1061 bucket
= bucket_info
.bucket
;
1066 static int read_input(const string
& infile
, bufferlist
& bl
)
1069 if (infile
.size()) {
1070 fd
= open(infile
.c_str(), O_RDONLY
);
1073 cerr
<< "error reading input file " << infile
<< std::endl
;
1078 #define READ_CHUNK 8196
1083 char buf
[READ_CHUNK
];
1085 r
= safe_read(fd
, buf
, READ_CHUNK
);
1088 cerr
<< "error while reading input" << std::endl
;
1096 if (infile
.size()) {
1103 static int read_decode_json(const string
& infile
, T
& t
)
1106 int ret
= read_input(infile
, bl
);
1108 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1112 if (!p
.parse(bl
.c_str(), bl
.length())) {
1113 cout
<< "failed to parse JSON" << std::endl
;
1118 decode_json_obj(t
, &p
);
1119 } catch (JSONDecoder::err
& e
) {
1120 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1126 template <class T
, class K
>
1127 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1130 int ret
= read_input(infile
, bl
);
1132 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1136 if (!p
.parse(bl
.c_str(), bl
.length())) {
1137 cout
<< "failed to parse JSON" << std::endl
;
1142 t
.decode_json(&p
, k
);
1143 } catch (JSONDecoder::err
& e
) {
1144 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1150 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1155 if (!date_str
.empty()) {
1156 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1158 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1163 ut
= utime_t(epoch
, nsec
);
1169 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1173 bufferlist::iterator iter
= bl
.begin();
1177 } catch (buffer::error
& err
) {
1181 encode_json(field_name
, t
, f
);
1186 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1189 if (bl
.length() > 0) {
1190 val
.assign(bl
.c_str());
1192 f
->dump_string(field_name
, val
);
1197 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1198 bool have_max_size
, bool have_max_objects
)
1201 case OPT_QUOTA_ENABLE
:
1202 case OPT_GLOBAL_QUOTA_ENABLE
:
1203 quota
.enabled
= true;
1205 // falling through on purpose
1208 case OPT_GLOBAL_QUOTA_SET
:
1209 if (have_max_objects
) {
1210 if (max_objects
< 0) {
1211 quota
.max_objects
= -1;
1213 quota
.max_objects
= max_objects
;
1216 if (have_max_size
) {
1218 quota
.max_size
= -1;
1220 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1224 case OPT_QUOTA_DISABLE
:
1225 case OPT_GLOBAL_QUOTA_DISABLE
:
1226 quota
.enabled
= false;
1231 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1232 const string
& tenant_name
, const string
& bucket_name
,
1233 int64_t max_size
, int64_t max_objects
,
1234 bool have_max_size
, bool have_max_objects
)
1236 RGWBucketInfo bucket_info
;
1237 map
<string
, bufferlist
> attrs
;
1238 RGWObjectCtx
obj_ctx(store
);
1239 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1241 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1245 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1247 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1249 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1255 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1256 bool have_max_size
, bool have_max_objects
)
1258 RGWUserInfo
& user_info
= op_state
.get_user_info();
1260 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1262 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1265 int r
= user
.modify(op_state
, &err
);
1267 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1273 int set_user_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1274 bool have_max_size
, bool have_max_objects
)
1276 RGWUserInfo
& user_info
= op_state
.get_user_info();
1278 set_quota_info(user_info
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1280 op_state
.set_user_quota(user_info
.user_quota
);
1283 int r
= user
.modify(op_state
, &err
);
1285 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1291 static bool bucket_object_check_filter(const string
& name
)
1294 string ns
; /* empty namespace */
1295 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1298 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1300 map
<string
, bufferlist
> attrs
;
1303 RGWObjectCtx
obj_ctx(store
);
1304 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1305 RGWRados::Object::Read
read_op(&op_target
);
1307 read_op
.params
.attrs
= &attrs
;
1308 read_op
.params
.obj_size
= &obj_size
;
1310 int ret
= read_op
.prepare();
1312 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1316 map
<string
, bufferlist
>::iterator iter
;
1317 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1318 if (iter
== attrs
.end()) {
1319 *need_rewrite
= (obj_size
>= min_stripe_size
);
1323 RGWObjManifest manifest
;
1326 bufferlist
& bl
= iter
->second
;
1327 bufferlist::iterator biter
= bl
.begin();
1328 ::decode(manifest
, biter
);
1329 } catch (buffer::error
& err
) {
1330 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1334 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1335 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1336 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1337 RGWObjManifestPart
& part
= oiter
->second
;
1339 if (part
.size
>= min_stripe_size
) {
1340 *need_rewrite
= true;
1344 *need_rewrite
= false;
1350 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1351 f
->open_object_section("object");
1352 f
->open_object_section("key");
1353 f
->dump_string("type", "head");
1354 f
->dump_string("name", key
.name
);
1355 f
->dump_string("instance", key
.instance
);
1361 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1363 f
->dump_string("oid", oid
);
1364 f
->dump_string("locator", locator
);
1367 RGWObjectCtx
obj_ctx(store
);
1369 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1370 RGWRados::Object::Read
read_op(&op_target
);
1372 int ret
= read_op
.prepare();
1373 bool needs_fixing
= (ret
== -ENOENT
);
1375 f
->dump_bool("needs_fixing", needs_fixing
);
1377 string status
= (needs_fixing
? "needs_fixing" : "ok");
1379 if ((needs_fixing
|| remove_bad
) && fix
) {
1380 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1382 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1389 f
->dump_string("status", status
);
1396 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1397 f
->open_object_section("object");
1398 f
->open_object_section("key");
1399 f
->dump_string("type", "tail");
1400 f
->dump_string("name", key
.name
);
1401 f
->dump_string("instance", key
.instance
);
1407 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1409 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1412 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1415 f
->dump_bool("needs_fixing", needs_fixing
);
1416 f
->dump_string("status", status
);
1423 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1424 bool fix
, bool remove_bad
, Formatter
*f
)
1426 if (remove_bad
&& !fix
) {
1427 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1431 RGWBucketInfo bucket_info
;
1435 f
->open_object_section("bucket");
1436 f
->dump_string("bucket", bucket_name
);
1437 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1439 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1445 int max_entries
= 1000;
1449 vector
<rgw_bucket_dir_entry
> result
;
1450 map
<string
, bool> common_prefixes
;
1453 RGWRados::Bucket
target(store
, bucket_info
);
1454 RGWRados::Bucket::List
list_op(&target
);
1458 list_op
.params
.prefix
= prefix
;
1459 list_op
.params
.delim
= delim
;
1460 list_op
.params
.marker
= rgw_obj_key(marker
);
1461 list_op
.params
.ns
= ns
;
1462 list_op
.params
.enforce_ns
= true;
1463 list_op
.params
.list_versions
= true;
1465 f
->open_array_section("check_objects");
1467 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1469 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1473 count
+= result
.size();
1475 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1476 rgw_obj_key key
= iter
->key
;
1477 rgw_obj
obj(bucket
, key
);
1479 if (key
.name
[0] == '_') {
1480 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1483 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1488 } while (truncated
&& count
< max_entries
);
1497 /// search for a matching zone/zonegroup id and return a connection if found
1498 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1499 const RGWZoneGroup
& zonegroup
,
1500 const std::string
& remote
)
1502 boost::optional
<RGWRESTConn
> conn
;
1503 if (remote
== zonegroup
.get_id()) {
1504 conn
.emplace(store
->ctx(), store
, remote
, zonegroup
.endpoints
);
1506 for (const auto& z
: zonegroup
.zones
) {
1507 const auto& zone
= z
.second
;
1508 if (remote
== zone
.id
) {
1509 conn
.emplace(store
->ctx(), store
, remote
, zone
.endpoints
);
1517 /// search each zonegroup for a connection
1518 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1519 const RGWPeriodMap
& period_map
,
1520 const std::string
& remote
)
1522 boost::optional
<RGWRESTConn
> conn
;
1523 for (const auto& zg
: period_map
.zonegroups
) {
1524 conn
= get_remote_conn(store
, zg
.second
, remote
);
1532 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
1533 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1534 bufferlist
& in_data
, JSONParser
& parser
)
1536 bufferlist response
;
1538 int ret
= conn
->forward(user
, info
, NULL
, MAX_REST_RESPONSE
, &in_data
, &response
);
1540 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1541 if (parse_ret
< 0) {
1542 cerr
<< "failed to parse response" << std::endl
;
1548 static int send_to_url(const string
& url
, const string
& access
,
1549 const string
& secret
, req_info
& info
,
1550 bufferlist
& in_data
, JSONParser
& parser
)
1552 if (access
.empty() || secret
.empty()) {
1553 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1561 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1563 bufferlist response
;
1564 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1566 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1567 if (parse_ret
< 0) {
1568 cout
<< "failed to parse response" << std::endl
;
1574 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1575 const string
& access
, const string
& secret
,
1576 req_info
& info
, bufferlist
& in_data
,
1580 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1582 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1585 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1586 string remote
, const string
& url
,
1587 const string
& access
, const string
& secret
,
1590 const string
& master_zone
= period
.get_master_zone();
1591 if (master_zone
.empty()) {
1592 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1595 // are we the period's master zone?
1596 if (store
->get_zone_params().get_id() == master_zone
) {
1597 // read the current period
1598 RGWPeriod current_period
;
1599 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1601 cerr
<< "Error initializing current period: "
1602 << cpp_strerror(-ret
) << std::endl
;
1605 // the master zone can commit locally
1606 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1608 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1613 if (remote
.empty() && url
.empty()) {
1614 // use the new master zone's connection
1615 remote
= master_zone
;
1616 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1618 boost::optional
<RGWRESTConn
> conn
;
1619 RGWRESTConn
*remote_conn
= nullptr;
1620 if (!remote
.empty()) {
1621 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1623 cerr
<< "failed to find a zone or zonegroup for remote "
1624 << remote
<< std::endl
;
1627 remote_conn
= &*conn
;
1630 // push period to the master with an empty period id
1634 req_info
info(g_ceph_context
, &env
);
1635 info
.method
= "POST";
1636 info
.request_uri
= "/admin/realm/period";
1638 // json format into a bufferlist
1639 JSONFormatter
jf(false);
1640 encode_json("period", period
, &jf
);
1645 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1647 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1649 // did we parse an error message?
1650 auto message
= p
.find_obj("Message");
1652 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1657 // decode the response and store it back
1659 decode_json_obj(period
, &p
);
1660 } catch (JSONDecoder::err
& e
) {
1661 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1664 if (period
.get_id().empty()) {
1665 cerr
<< "Period commit got back an empty period id" << std::endl
;
1668 // the master zone gave us back the period that it committed, so it's
1669 // safe to save it as our latest epoch
1670 ret
= period
.store_info(false);
1672 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1673 << cpp_strerror(ret
) << std::endl
;
1676 ret
= period
.set_latest_epoch(period
.get_epoch());
1678 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1681 ret
= period
.reflect();
1683 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1686 realm
.notify_new_period(period
);
1690 static int update_period(const string
& realm_id
, const string
& realm_name
,
1691 const string
& period_id
, const string
& period_epoch
,
1692 bool commit
, const string
& remote
, const string
& url
,
1693 const string
& access
, const string
& secret
,
1694 Formatter
*formatter
, bool force
)
1696 RGWRealm
realm(realm_id
, realm_name
);
1697 int ret
= realm
.init(g_ceph_context
, store
);
1699 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1703 if (!period_epoch
.empty()) {
1704 epoch
= atoi(period_epoch
.c_str());
1706 RGWPeriod
period(period_id
, epoch
);
1707 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1709 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1713 ret
= period
.update();
1715 // Dropping the error message here, as both the ret codes were handled in
1719 ret
= period
.store_info(false);
1721 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1725 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1727 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1731 encode_json("period", period
, formatter
);
1732 formatter
->flush(cout
);
1737 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1738 const string
& bucket_id
, rgw_bucket
& bucket
)
1740 RGWBucketInfo bucket_info
;
1742 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1744 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1751 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1752 const string
& access_key
, const string
& secret_key
,
1753 const string
& realm_id
, const string
& realm_name
,
1754 const string
& period_id
, const string
& period_epoch
,
1758 req_info
info(g_ceph_context
, &env
);
1759 info
.method
= "GET";
1760 info
.request_uri
= "/admin/realm/period";
1762 map
<string
, string
> ¶ms
= info
.args
.get_params();
1763 if (!realm_id
.empty())
1764 params
["realm_id"] = realm_id
;
1765 if (!realm_name
.empty())
1766 params
["realm_name"] = realm_name
;
1767 if (!period_id
.empty())
1768 params
["period_id"] = period_id
;
1769 if (!period_epoch
.empty())
1770 params
["epoch"] = period_epoch
;
1774 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1777 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1780 ret
= period
->init(g_ceph_context
, store
, false);
1782 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1786 decode_json_obj(*period
, &p
);
1787 } catch (JSONDecoder::err
& e
) {
1788 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1791 ret
= period
->store_info(false);
1793 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1799 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1800 const std::string
& realm_name
,
1801 std::string
* period_id
)
1803 RGWRealm
realm(realm_id
, realm_name
);
1804 int ret
= realm
.init(g_ceph_context
, store
);
1806 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1809 *period_id
= realm
.get_current_period();
1813 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1815 if (!ss
.str().empty()) {
1816 l
.push_back(ss
.str());
1821 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1825 ss
<< setw(tab
) << "" << setw(1);
1830 static void get_md_sync_status(list
<string
>& status
)
1832 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1834 int ret
= sync
.init();
1836 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1840 rgw_meta_sync_status sync_status
;
1841 ret
= sync
.read_sync_status(&sync_status
);
1843 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1848 switch (sync_status
.sync_info
.state
) {
1849 case rgw_meta_sync_info::StateInit
:
1850 status_str
= "init";
1852 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1853 status_str
= "preparing for full sync";
1855 case rgw_meta_sync_info::StateSync
:
1856 status_str
= "syncing";
1859 status_str
= "unknown";
1862 status
.push_back(status_str
);
1864 uint64_t full_total
= 0;
1865 uint64_t full_complete
= 0;
1869 int total_shards
= 0;
1871 for (auto marker_iter
: sync_status
.sync_markers
) {
1872 full_total
+= marker_iter
.second
.total_entries
;
1874 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1876 full_complete
+= marker_iter
.second
.pos
;
1878 full_complete
+= marker_iter
.second
.total_entries
;
1880 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1886 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1889 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1892 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1894 rgw_mdlog_info log_info
;
1895 ret
= sync
.read_log_info(&log_info
);
1897 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1901 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1902 string master_period
= store
->get_current_period_id();
1904 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1906 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1910 map
<int, string
> shards_behind
;
1911 if (sync_status
.sync_info
.period
!= master_period
) {
1912 status
.push_back(string("master is on a different period: master_period=" +
1913 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1915 for (auto local_iter
: sync_status
.sync_markers
) {
1916 int shard_id
= local_iter
.first
;
1917 auto iter
= master_shards_info
.find(shard_id
);
1919 if (iter
== master_shards_info
.end()) {
1921 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
1924 auto master_marker
= iter
->second
.marker
;
1925 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
1926 master_marker
> local_iter
.second
.marker
) {
1927 shards_behind
[shard_id
] = local_iter
.second
.marker
;
1932 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
1933 if (total_behind
== 0) {
1934 push_ss(ss
, status
) << "metadata is caught up with master";
1936 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
1938 map
<int, rgw_mdlog_shard_data
> master_pos
;
1939 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
1941 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
1943 ceph::real_time oldest
;
1944 for (auto iter
: master_pos
) {
1945 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
1947 if (!shard_data
.entries
.empty()) {
1948 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
1949 if (ceph::real_clock::is_zero(oldest
)) {
1950 oldest
= entry
.timestamp
;
1951 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
1952 oldest
= entry
.timestamp
;
1957 if (!ceph::real_clock::is_zero(oldest
)) {
1958 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
1963 flush_ss(ss
, status
);
1966 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
1970 auto ziter
= store
->zone_by_id
.find(source_zone
);
1971 if (ziter
== store
->zone_by_id
.end()) {
1972 push_ss(ss
, status
, tab
) << string("zone not found");
1973 flush_ss(ss
, status
);
1976 RGWZone
& sz
= ziter
->second
;
1978 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
1979 push_ss(ss
, status
, tab
) << string("not syncing from zone");
1980 flush_ss(ss
, status
);
1983 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
1985 int ret
= sync
.init();
1987 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
1988 flush_ss(ss
, status
);
1992 rgw_data_sync_status sync_status
;
1993 ret
= sync
.read_sync_status(&sync_status
);
1994 if (ret
< 0 && ret
!= -ENOENT
) {
1995 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2000 switch (sync_status
.sync_info
.state
) {
2001 case rgw_data_sync_info::StateInit
:
2002 status_str
= "init";
2004 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2005 status_str
= "preparing for full sync";
2007 case rgw_data_sync_info::StateSync
:
2008 status_str
= "syncing";
2011 status_str
= "unknown";
2014 push_ss(ss
, status
, tab
) << status_str
;
2016 uint64_t full_total
= 0;
2017 uint64_t full_complete
= 0;
2021 int total_shards
= 0;
2023 for (auto marker_iter
: sync_status
.sync_markers
) {
2024 full_total
+= marker_iter
.second
.total_entries
;
2026 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2028 full_complete
+= marker_iter
.second
.pos
;
2030 full_complete
+= marker_iter
.second
.total_entries
;
2032 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2037 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2040 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2043 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2045 rgw_datalog_info log_info
;
2046 ret
= sync
.read_log_info(&log_info
);
2048 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2053 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2055 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2057 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2061 map
<int, string
> shards_behind
;
2063 for (auto local_iter
: sync_status
.sync_markers
) {
2064 int shard_id
= local_iter
.first
;
2065 auto iter
= source_shards_info
.find(shard_id
);
2067 if (iter
== source_shards_info
.end()) {
2069 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2072 auto master_marker
= iter
->second
.marker
;
2073 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2074 master_marker
> local_iter
.second
.marker
) {
2075 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2079 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2080 if (total_behind
== 0) {
2081 push_ss(ss
, status
, tab
) << "data is caught up with source";
2083 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2085 map
<int, rgw_datalog_shard_data
> master_pos
;
2086 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2088 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2090 ceph::real_time oldest
;
2091 for (auto iter
: master_pos
) {
2092 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2094 if (!shard_data
.entries
.empty()) {
2095 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2096 if (ceph::real_clock::is_zero(oldest
)) {
2097 oldest
= entry
.timestamp
;
2098 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2099 oldest
= entry
.timestamp
;
2104 if (!ceph::real_clock::is_zero(oldest
)) {
2105 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2110 flush_ss(ss
, status
);
2113 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2117 for (auto e
: entries
) {
2118 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2124 static void sync_status(Formatter
*formatter
)
2126 RGWRealm
& realm
= store
->realm
;
2127 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2128 RGWZone
& zone
= store
->get_zone();
2132 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2133 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2134 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2136 list
<string
> md_status
;
2138 if (store
->is_meta_master()) {
2139 md_status
.push_back("no sync (zone is master)");
2141 get_md_sync_status(md_status
);
2144 tab_dump("metadata sync", width
, md_status
);
2146 list
<string
> data_status
;
2148 for (auto iter
: store
->zone_conn_map
) {
2149 const string
& source_id
= iter
.first
;
2151 string source_str
= "source: ";
2152 string s
= source_str
+ source_id
;
2153 auto siter
= store
->zone_by_id
.find(source_id
);
2154 if (siter
!= store
->zone_by_id
.end()) {
2155 s
+= string(" (") + siter
->second
.name
+ ")";
2157 data_status
.push_back(s
);
2158 get_data_sync_status(source_id
, data_status
, source_str
.size());
2161 tab_dump("data sync", width
, data_status
);
2164 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2167 get_str_list(s
, ",", confs
);
2168 for (auto c
: confs
) {
2169 ssize_t pos
= c
.find("=");
2173 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2178 int check_reshard_bucket_params(RGWRados
*store
,
2179 const string
& bucket_name
,
2180 const string
& tenant
,
2181 const string
& bucket_id
,
2182 bool num_shards_specified
,
2184 int yes_i_really_mean_it
,
2186 RGWBucketInfo
& bucket_info
,
2187 map
<string
, bufferlist
>& attrs
)
2189 if (bucket_name
.empty()) {
2190 cerr
<< "ERROR: bucket not specified" << std::endl
;
2194 if (!num_shards_specified
) {
2195 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2199 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2200 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2204 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2206 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2210 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2212 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2213 cerr
<< "num shards is less or equal to current shards count" << std::endl
2214 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2220 int create_new_bucket_instance(RGWRados
*store
,
2222 const RGWBucketInfo
& bucket_info
,
2223 map
<string
, bufferlist
>& attrs
,
2224 RGWBucketInfo
& new_bucket_info
)
2227 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2228 new_bucket_info
.bucket
.oid
.clear();
2230 new_bucket_info
.num_shards
= new_num_shards
;
2231 new_bucket_info
.objv_tracker
.clear();
2233 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2235 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2239 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2241 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2249 #ifdef BUILDING_FOR_EMBEDDED
2250 extern "C" int cephd_rgw_admin(int argc
, const char **argv
)
2252 int main(int argc
, const char **argv
)
2255 vector
<const char*> args
;
2256 argv_to_vec(argc
, (const char **)argv
, args
);
2259 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2260 CODE_ENVIRONMENT_UTILITY
, 0);
2262 // for region -> zonegroup conversion (must happen before common_init_finish())
2263 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2264 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2267 common_init_finish(g_ceph_context
);
2271 std::string access_key
, secret_key
, user_email
, display_name
;
2272 std::string bucket_name
, pool_name
, object
;
2274 std::string date
, subuser
, access
, format
;
2275 std::string start_date
, end_date
;
2276 std::string key_type_str
;
2277 std::string period_id
, period_epoch
, remote
, url
;
2278 std::string master_zonegroup
, master_zone
;
2279 std::string realm_name
, realm_id
, realm_new_name
;
2280 std::string zone_name
, zone_id
, zone_new_name
;
2281 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2282 std::string api_name
;
2283 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2284 list
<string
> endpoints
;
2286 int sync_from_all_specified
= false;
2287 bool sync_from_all
= false;
2288 list
<string
> sync_from
;
2289 list
<string
> sync_from_rm
;
2290 std::string master_url
;
2292 int set_default
= 0;
2293 bool is_master
= false;
2294 bool is_master_set
= false;
2296 bool read_only
= false;
2297 int is_read_only_set
= false;
2299 int staging
= false;
2300 int key_type
= KEY_TYPE_UNDEFINED
;
2302 uint32_t perm_mask
= 0;
2304 int opt_cmd
= OPT_NO_CMD
;
2306 int gen_access_key
= 0;
2307 int gen_secret_key
= 0;
2308 bool set_perm
= false;
2309 bool set_temp_url_key
= false;
2310 map
<int, string
> temp_url_keys
;
2312 Formatter
*formatter
= NULL
;
2313 int purge_data
= false;
2314 RGWBucketInfo bucket_info
;
2315 int pretty_format
= false;
2316 int show_log_entries
= true;
2317 int show_log_sum
= true;
2318 int skip_zero_entries
= false; // log show
2319 int purge_keys
= false;
2320 int yes_i_really_mean_it
= false;
2321 int delete_child_objects
= false;
2323 int remove_bad
= false;
2324 int check_head_obj_locator
= false;
2325 int max_buckets
= -1;
2326 bool max_buckets_specified
= false;
2327 map
<string
, bool> categories
;
2329 int check_objects
= false;
2330 RGWUserAdminOpState user_op
;
2331 RGWBucketAdminOpState bucket_op
;
2333 string metadata_key
;
2334 RGWObjVersionTracker objv_tracker
;
2336 string start_marker
;
2338 int max_entries
= -1;
2340 bool admin_specified
= false;
2342 bool system_specified
= false;
2344 bool specified_shard_id
= false;
2346 bool specified_daemon_id
= false;
2350 string replica_log_type_str
;
2351 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2354 string object_version
;
2355 string placement_id
;
2357 list
<string
> tags_add
;
2358 list
<string
> tags_rm
;
2360 int64_t max_objects
= -1;
2361 int64_t max_size
= -1;
2362 bool have_max_objects
= false;
2363 bool have_max_size
= false;
2364 int include_all
= false;
2366 int sync_stats
= false;
2367 int bypass_gc
= false;
2368 int warnings_only
= false;
2369 int inconsistent_index
= false;
2371 int verbose
= false;
2373 int extra_info
= false;
2375 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2376 uint64_t max_rewrite_size
= ULLONG_MAX
;
2377 uint64_t min_rewrite_stripe_size
= 0;
2379 BIIndexType bi_index_type
= PlainIdx
;
2383 bool num_shards_specified
= false;
2384 int max_concurrent_ios
= 32;
2385 uint64_t orphan_stale_secs
= (24 * 3600);
2388 std::ostringstream errs
;
2392 string source_zone_name
;
2393 string source_zone
; /* zone id */
2396 bool tier_type_specified
= false;
2398 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2399 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2401 boost::optional
<string
> index_pool
;
2402 boost::optional
<string
> data_pool
;
2403 boost::optional
<string
> data_extra_pool
;
2404 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2405 bool index_type_specified
= false;
2407 boost::optional
<std::string
> compression_type
;
2409 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2410 if (ceph_argparse_double_dash(args
, i
)) {
2412 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2415 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2416 user_id
.from_str(val
);
2417 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2419 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2421 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2423 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2425 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2427 user_op
.user_email_specified
=true;
2428 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2430 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2432 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2434 pool
= rgw_pool(pool_name
);
2435 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2437 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2438 object_version
= val
;
2439 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2441 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2443 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2445 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2447 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2449 if (key_type_str
.compare("swift") == 0) {
2450 key_type
= KEY_TYPE_SWIFT
;
2451 } else if (key_type_str
.compare("s3") == 0) {
2452 key_type
= KEY_TYPE_S3
;
2454 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2457 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2459 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2461 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2463 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2465 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2467 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2469 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2470 admin_specified
= true;
2471 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2472 system_specified
= true;
2473 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2475 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2477 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2479 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2480 if (!errs
.str().empty()) {
2481 cerr
<< errs
.str() << std::endl
;
2484 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2485 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2486 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2487 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2488 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2489 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2490 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2491 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2493 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2496 max_buckets_specified
= true;
2497 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2498 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2500 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2503 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2504 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2506 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2509 have_max_size
= true;
2510 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2511 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2513 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2516 have_max_objects
= true;
2517 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2519 if (end_date
.empty())
2521 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2523 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2525 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2526 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2528 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2531 num_shards_specified
= true;
2532 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2533 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2535 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2538 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2539 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2541 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2544 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2545 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2547 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2550 specified_shard_id
= true;
2551 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2553 specified_daemon_id
= true;
2554 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2556 perm_mask
= rgw_str_to_perm(access
.c_str());
2558 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2559 temp_url_keys
[0] = val
;
2560 set_temp_url_key
= true;
2561 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2562 temp_url_keys
[1] = val
;
2563 set_temp_url_key
= true;
2564 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2566 if (bucket_id
.empty()) {
2567 cerr
<< "bad bucket-id" << std::endl
;
2570 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2572 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2573 string cat_str
= val
;
2574 list
<string
> cat_list
;
2575 list
<string
>::iterator iter
;
2576 get_str_list(cat_str
, cat_list
);
2577 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2578 categories
[*iter
] = true;
2580 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2582 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2584 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2585 delete_child_objects
= purge_data
;
2586 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2588 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2590 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2592 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2594 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2596 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2598 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2600 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2602 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2604 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2606 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2608 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2610 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2612 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2614 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2616 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2618 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2620 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2622 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2624 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2625 replica_log_type_str
= val
;
2626 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2627 if (replica_log_type
== ReplicaLog_Invalid
) {
2628 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2631 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2632 string index_type_str
= val
;
2633 bi_index_type
= get_bi_index_type(index_type_str
);
2634 if (bi_index_type
== InvalidIdx
) {
2635 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2638 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2639 is_master
= (bool)is_master_int
;
2640 is_master_set
= true;
2641 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2643 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2644 read_only
= (bool)read_only_int
;
2645 is_read_only_set
= true;
2646 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2648 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2649 master_zonegroup
= val
;
2650 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2652 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2654 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2656 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2658 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2660 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2662 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2663 realm_new_name
= val
;
2664 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2666 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2667 zonegroup_new_name
= val
;
2668 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2670 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2671 get_str_list(val
, tags
);
2672 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2673 get_str_list(val
, tags_add
);
2674 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2675 get_str_list(val
, tags_rm
);
2676 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2678 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2680 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2681 zone_new_name
= val
;
2682 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2683 get_str_list(val
, endpoints
);
2684 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2685 get_str_list(val
, sync_from
);
2686 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2687 get_str_list(val
, sync_from_rm
);
2688 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2689 sync_from_all
= (bool)tmp_int
;
2690 sync_from_all_specified
= true;
2691 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2692 source_zone_name
= val
;
2693 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2695 tier_type_specified
= true;
2696 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2697 parse_tier_config_param(val
, tier_config_add
);
2698 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2699 parse_tier_config_param(val
, tier_config_rm
);
2700 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2702 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2704 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2705 data_extra_pool
= val
;
2706 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2707 if (val
== "normal") {
2708 placement_index_type
= RGWBIType_Normal
;
2709 } else if (val
== "indexless") {
2710 placement_index_type
= RGWBIType_Indexless
;
2712 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2714 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2718 index_type_specified
= true;
2719 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2720 compression_type
= val
;
2721 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2723 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2725 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2726 assume_role_doc
= val
;
2727 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2729 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2730 perm_policy_doc
= val
;
2731 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2733 } else if (strncmp(*i
, "-", 1) == 0) {
2734 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
2745 const char *prev_cmd
= NULL
;
2746 const char *prev_prev_cmd
= NULL
;
2747 std::vector
<const char*>::iterator i
;
2748 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
2749 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
2751 cerr
<< "unrecognized arg " << *i
<< std::endl
;
2758 prev_prev_cmd
= prev_cmd
;
2762 if (opt_cmd
== OPT_NO_CMD
)
2765 /* some commands may have an optional extra param */
2766 if (i
!= args
.end()) {
2768 case OPT_METADATA_GET
:
2769 case OPT_METADATA_PUT
:
2770 case OPT_METADATA_RM
:
2771 case OPT_METADATA_LIST
:
2779 if (tenant
.empty()) {
2780 tenant
= user_id
.tenant
;
2782 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
2783 && opt_cmd
!= OPT_ROLE_DELETE
2784 && opt_cmd
!= OPT_ROLE_GET
2785 && opt_cmd
!= OPT_ROLE_MODIFY
2786 && opt_cmd
!= OPT_ROLE_LIST
2787 && opt_cmd
!= OPT_ROLE_POLICY_PUT
2788 && opt_cmd
!= OPT_ROLE_POLICY_LIST
2789 && opt_cmd
!= OPT_ROLE_POLICY_GET
2790 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
) {
2791 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
2794 user_id
.tenant
= tenant
;
2796 /* check key parameter conflict */
2797 if ((!access_key
.empty()) && gen_access_key
) {
2798 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
2801 if ((!secret_key
.empty()) && gen_secret_key
) {
2802 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
2807 // default to pretty json
2808 if (format
.empty()) {
2810 pretty_format
= true;
2813 if (format
== "xml")
2814 formatter
= new XMLFormatter(pretty_format
);
2815 else if (format
== "json")
2816 formatter
= new JSONFormatter(pretty_format
);
2818 cerr
<< "unrecognized format: " << format
<< std::endl
;
2822 realm_name
= g_conf
->rgw_realm
;
2823 zone_name
= g_conf
->rgw_zone
;
2824 zonegroup_name
= g_conf
->rgw_zonegroup
;
2826 RGWStreamFlusher
f(formatter
, cout
);
2828 // not a raw op if 'period update' needs to commit to master
2829 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
2830 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
2831 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
2832 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
2833 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
2834 OPT_ZONEGROUP_REMOVE
,
2835 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
2836 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
2837 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
2838 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
2839 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
2840 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
2841 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
2842 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
2844 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
2846 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
2847 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
2848 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
2849 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
2850 OPT_REALM_LIST_PERIODS
,
2851 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
2852 OPT_REALM_RENAME
, OPT_REALM_SET
,
2853 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
2856 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
2859 if (raw_storage_op
) {
2860 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
2862 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false);
2865 cerr
<< "couldn't init storage provider" << std::endl
;
2869 if (!source_zone_name
.empty()) {
2870 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
2871 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
2872 source_zone
= source_zone_name
;
2876 rgw_user_init(store
);
2877 rgw_bucket_init(store
->meta_mgr
);
2879 StoreDestructor
store_destructor(store
);
2881 if (raw_storage_op
) {
2883 case OPT_PERIOD_DELETE
:
2885 if (period_id
.empty()) {
2886 cerr
<< "missing period id" << std::endl
;
2889 RGWPeriod
period(period_id
);
2890 int ret
= period
.init(g_ceph_context
, store
);
2892 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
2895 ret
= period
.delete_obj();
2897 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
2903 case OPT_PERIOD_GET
:
2906 if (!period_epoch
.empty()) {
2907 epoch
= atoi(period_epoch
.c_str());
2910 RGWRealm
realm(realm_id
, realm_name
);
2911 int ret
= realm
.init(g_ceph_context
, store
);
2913 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
2916 realm_id
= realm
.get_id();
2917 realm_name
= realm
.get_name();
2918 period_id
= RGWPeriod::get_staging_id(realm_id
);
2921 RGWPeriod
period(period_id
, epoch
);
2922 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
2924 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
2927 encode_json("period", period
, formatter
);
2928 formatter
->flush(cout
);
2932 case OPT_PERIOD_GET_CURRENT
:
2934 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
2938 formatter
->open_object_section("period_get_current");
2939 encode_json("current_period", period_id
, formatter
);
2940 formatter
->close_section();
2941 formatter
->flush(cout
);
2944 case OPT_PERIOD_LIST
:
2946 list
<string
> periods
;
2947 int ret
= store
->list_periods(periods
);
2949 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
2952 formatter
->open_object_section("periods_list");
2953 encode_json("periods", periods
, formatter
);
2954 formatter
->close_section();
2955 formatter
->flush(cout
);
2959 case OPT_PERIOD_UPDATE
:
2961 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
2962 commit
, remote
, url
, access_key
, secret_key
,
2963 formatter
, yes_i_really_mean_it
);
2969 case OPT_PERIOD_PULL
:
2971 boost::optional
<RGWRESTConn
> conn
;
2972 RGWRESTConn
*remote_conn
= nullptr;
2974 // load current period for endpoints
2975 RGWRealm
realm(realm_id
, realm_name
);
2976 int ret
= realm
.init(g_ceph_context
, store
);
2978 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
2981 RGWPeriod
current_period(realm
.get_current_period());
2982 ret
= current_period
.init(g_ceph_context
, store
);
2984 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
2987 if (remote
.empty()) {
2988 // use realm master zone as remote
2989 remote
= current_period
.get_master_zone();
2991 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
2993 cerr
<< "failed to find a zone or zonegroup for remote "
2994 << remote
<< std::endl
;
2997 remote_conn
= &*conn
;
3001 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3002 realm_id
, realm_name
, period_id
, period_epoch
,
3005 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3009 encode_json("period", period
, formatter
);
3010 formatter
->flush(cout
);
3014 case OPT_GLOBAL_QUOTA_GET
:
3015 case OPT_GLOBAL_QUOTA_SET
:
3016 case OPT_GLOBAL_QUOTA_ENABLE
:
3017 case OPT_GLOBAL_QUOTA_DISABLE
:
3019 if (realm_id
.empty()) {
3020 RGWRealm
realm(g_ceph_context
, store
);
3021 if (!realm_name
.empty()) {
3022 // look up realm_id for the given realm_name
3023 int ret
= realm
.read_id(realm_name
, realm_id
);
3025 cerr
<< "ERROR: failed to read realm for " << realm_name
3026 << ": " << cpp_strerror(-ret
) << std::endl
;
3030 // use default realm_id when none is given
3031 int ret
= realm
.read_default_id(realm_id
);
3032 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3033 cerr
<< "ERROR: failed to read default realm: "
3034 << cpp_strerror(-ret
) << std::endl
;
3040 RGWPeriodConfig period_config
;
3041 int ret
= period_config
.read(store
, realm_id
);
3042 if (ret
< 0 && ret
!= -ENOENT
) {
3043 cerr
<< "ERROR: failed to read period config: "
3044 << cpp_strerror(-ret
) << std::endl
;
3048 formatter
->open_object_section("period_config");
3049 if (quota_scope
== "bucket") {
3050 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3051 max_size
, max_objects
,
3052 have_max_size
, have_max_objects
);
3053 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3054 } else if (quota_scope
== "user") {
3055 set_quota_info(period_config
.user_quota
, opt_cmd
,
3056 max_size
, max_objects
,
3057 have_max_size
, have_max_objects
);
3058 encode_json("user quota", period_config
.user_quota
, formatter
);
3059 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3060 // if no scope is given for GET, print both
3061 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3062 encode_json("user quota", period_config
.user_quota
, formatter
);
3064 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3065 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3068 formatter
->close_section();
3070 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3071 // write the modified period config
3072 ret
= period_config
.write(store
, realm_id
);
3074 cerr
<< "ERROR: failed to write period config: "
3075 << cpp_strerror(-ret
) << std::endl
;
3078 if (!realm_id
.empty()) {
3079 cout
<< "Global quota changes saved. Use 'period update' to apply "
3080 "them to the staging period, and 'period commit' to commit the "
3081 "new period." << std::endl
;
3083 cout
<< "Global quota changes saved. They will take effect as "
3084 "the gateways are restarted." << std::endl
;
3088 formatter
->flush(cout
);
3092 case OPT_REALM_CREATE
:
3094 if (realm_name
.empty()) {
3095 cerr
<< "missing realm name" << std::endl
;
3099 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3100 int ret
= realm
.create();
3102 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3107 ret
= realm
.set_as_default();
3109 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3113 encode_json("realm", realm
, formatter
);
3114 formatter
->flush(cout
);
3118 case OPT_REALM_DELETE
:
3120 RGWRealm
realm(realm_id
, realm_name
);
3121 if (realm_name
.empty() && realm_id
.empty()) {
3122 cerr
<< "missing realm name or id" << std::endl
;
3125 int ret
= realm
.init(g_ceph_context
, store
);
3127 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3130 ret
= realm
.delete_obj();
3132 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3140 RGWRealm
realm(realm_id
, realm_name
);
3141 int ret
= realm
.init(g_ceph_context
, store
);
3143 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3144 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3146 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3150 encode_json("realm", realm
, formatter
);
3151 formatter
->flush(cout
);
3155 case OPT_REALM_GET_DEFAULT
:
3157 RGWRealm
realm(g_ceph_context
, store
);
3159 int ret
= realm
.read_default_id(default_id
);
3160 if (ret
== -ENOENT
) {
3161 cout
<< "No default realm is set" << std::endl
;
3163 } else if (ret
< 0) {
3164 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3167 cout
<< "default realm: " << default_id
<< std::endl
;
3170 case OPT_REALM_LIST
:
3172 RGWRealm
realm(g_ceph_context
, store
);
3174 int ret
= realm
.read_default_id(default_id
);
3175 if (ret
< 0 && ret
!= -ENOENT
) {
3176 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3178 list
<string
> realms
;
3179 ret
= store
->list_realms(realms
);
3181 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3184 formatter
->open_object_section("realms_list");
3185 encode_json("default_info", default_id
, formatter
);
3186 encode_json("realms", realms
, formatter
);
3187 formatter
->close_section();
3188 formatter
->flush(cout
);
3192 case OPT_REALM_LIST_PERIODS
:
3194 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3198 list
<string
> periods
;
3199 ret
= store
->list_periods(period_id
, periods
);
3201 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3204 formatter
->open_object_section("realm_periods_list");
3205 encode_json("current_period", period_id
, formatter
);
3206 encode_json("periods", periods
, formatter
);
3207 formatter
->close_section();
3208 formatter
->flush(cout
);
3213 case OPT_REALM_RENAME
:
3215 RGWRealm
realm(realm_id
, realm_name
);
3216 if (realm_new_name
.empty()) {
3217 cerr
<< "missing realm new name" << std::endl
;
3220 if (realm_name
.empty() && realm_id
.empty()) {
3221 cerr
<< "missing realm name or id" << std::endl
;
3224 int ret
= realm
.init(g_ceph_context
, store
);
3226 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3229 ret
= realm
.rename(realm_new_name
);
3231 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3234 cout
<< "Realm name updated. Note that this change only applies to "
3235 "the current cluster, so this command must be run separately "
3236 "on each of the realm's other clusters." << std::endl
;
3241 if (realm_id
.empty() && realm_name
.empty()) {
3242 cerr
<< "no realm name or id provided" << std::endl
;
3245 RGWRealm
realm(realm_id
, realm_name
);
3246 bool new_realm
= false;
3247 int ret
= realm
.init(g_ceph_context
, store
);
3248 if (ret
< 0 && ret
!= -ENOENT
) {
3249 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3251 } else if (ret
== -ENOENT
) {
3254 ret
= read_decode_json(infile
, realm
);
3258 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3259 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3260 realm
.get_name() << std::endl
;
3265 cout
<< "clearing period and epoch for new realm" << std::endl
;
3266 realm
.clear_current_period_and_epoch();
3267 ret
= realm
.create();
3269 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3273 ret
= realm
.update();
3275 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3281 ret
= realm
.set_as_default();
3283 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3286 encode_json("realm", realm
, formatter
);
3287 formatter
->flush(cout
);
3291 case OPT_REALM_DEFAULT
:
3293 RGWRealm
realm(realm_id
, realm_name
);
3294 int ret
= realm
.init(g_ceph_context
, store
);
3296 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3299 ret
= realm
.set_as_default();
3301 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3306 case OPT_REALM_PULL
:
3309 cerr
<< "A --url must be provided." << std::endl
;
3313 req_info
info(g_ceph_context
, &env
);
3314 info
.method
= "GET";
3315 info
.request_uri
= "/admin/realm";
3317 map
<string
, string
> ¶ms
= info
.args
.get_params();
3318 if (!realm_id
.empty())
3319 params
["id"] = realm_id
;
3320 if (!realm_name
.empty())
3321 params
["name"] = realm_name
;
3325 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3327 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3328 if (ret
== -EACCES
) {
3329 cerr
<< "If the realm has been changed on the master zone, the "
3330 "master zone's gateway may need to be restarted to recognize "
3331 "this user." << std::endl
;
3336 realm
.init(g_ceph_context
, store
, false);
3338 decode_json_obj(realm
, &p
);
3339 } catch (JSONDecoder::err
& e
) {
3340 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3344 auto& current_period
= realm
.get_current_period();
3345 if (!current_period
.empty()) {
3346 // pull the latest epoch of the realm's current period
3347 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3348 realm_id
, realm_name
, current_period
, "",
3351 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3355 ret
= realm
.create(false);
3356 if (ret
< 0 && ret
!= -EEXIST
) {
3357 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3358 << cpp_strerror(ret
) << std::endl
;
3360 } else if (ret
==-EEXIST
) {
3361 ret
= realm
.update();
3363 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3364 << cpp_strerror(ret
) << std::endl
;
3369 ret
= realm
.set_as_default();
3371 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3375 encode_json("realm", realm
, formatter
);
3376 formatter
->flush(cout
);
3381 case OPT_ZONEGROUP_ADD
:
3383 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3384 cerr
<< "no zonegroup name or id provided" << std::endl
;
3388 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3389 int ret
= zonegroup
.init(g_ceph_context
, store
);
3391 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3392 << cpp_strerror(-ret
) << std::endl
;
3395 RGWZoneParams
zone(zone_id
, zone_name
);
3396 ret
= zone
.init(g_ceph_context
, store
);
3398 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3401 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3402 zone
.tier_config
= tier_config_add
;
3404 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3406 ret
= zonegroup
.add_zone(zone
,
3407 (is_master_set
? &is_master
: NULL
),
3408 (is_read_only_set
? &read_only
: NULL
),
3409 endpoints
, ptier_type
,
3410 psync_from_all
, sync_from
, sync_from_rm
);
3412 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3413 << cpp_strerror(-ret
) << std::endl
;
3417 encode_json("zonegroup", zonegroup
, formatter
);
3418 formatter
->flush(cout
);
3421 case OPT_ZONEGROUP_CREATE
:
3423 if (zonegroup_name
.empty()) {
3424 cerr
<< "Missing zonegroup name" << std::endl
;
3427 RGWRealm
realm(realm_id
, realm_name
);
3428 int ret
= realm
.init(g_ceph_context
, store
);
3430 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3434 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3435 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3436 ret
= zonegroup
.create();
3438 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3443 ret
= zonegroup
.set_as_default();
3445 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3449 encode_json("zonegroup", zonegroup
, formatter
);
3450 formatter
->flush(cout
);
3454 case OPT_ZONEGROUP_DEFAULT
:
3456 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3457 cerr
<< "no zonegroup name or id provided" << std::endl
;
3461 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3462 int ret
= zonegroup
.init(g_ceph_context
, store
);
3464 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3468 ret
= zonegroup
.set_as_default();
3470 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3475 case OPT_ZONEGROUP_DELETE
:
3477 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3478 cerr
<< "no zonegroup name or id provided" << std::endl
;
3481 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3482 int ret
= zonegroup
.init(g_ceph_context
, store
);
3484 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3487 ret
= zonegroup
.delete_obj();
3489 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3494 case OPT_ZONEGROUP_GET
:
3496 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3497 int ret
= zonegroup
.init(g_ceph_context
, store
);
3499 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3503 encode_json("zonegroup", zonegroup
, formatter
);
3504 formatter
->flush(cout
);
3508 case OPT_ZONEGROUP_LIST
:
3510 RGWZoneGroup zonegroup
;
3511 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3513 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3517 list
<string
> zonegroups
;
3518 ret
= store
->list_zonegroups(zonegroups
);
3520 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3523 string default_zonegroup
;
3524 ret
= zonegroup
.read_default_id(default_zonegroup
);
3525 cout
<< "read_default_id : " << ret
<< std::endl
;
3526 if (ret
< 0 && ret
!= -ENOENT
) {
3527 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3529 formatter
->open_object_section("zonegroups_list");
3530 encode_json("default_info", default_zonegroup
, formatter
);
3531 encode_json("zonegroups", zonegroups
, formatter
);
3532 formatter
->close_section();
3533 formatter
->flush(cout
);
3537 case OPT_ZONEGROUP_MODIFY
:
3539 RGWRealm
realm(realm_id
, realm_name
);
3540 int ret
= realm
.init(g_ceph_context
, store
);
3542 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3546 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3547 ret
= zonegroup
.init(g_ceph_context
, store
);
3549 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3553 bool need_update
= false;
3555 if (!master_zone
.empty()) {
3556 zonegroup
.master_zone
= master_zone
;
3560 if (is_master_set
) {
3561 zonegroup
.update_master(is_master
);
3565 if (!endpoints
.empty()) {
3566 zonegroup
.endpoints
= endpoints
;
3570 if (!api_name
.empty()) {
3571 zonegroup
.api_name
= api_name
;
3575 if (!realm_id
.empty()) {
3576 zonegroup
.realm_id
= realm_id
;
3578 } else if (!realm_name
.empty()) {
3579 // get realm id from name
3580 RGWRealm realm
{g_ceph_context
, store
};
3581 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3583 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3590 ret
= zonegroup
.update();
3592 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3598 ret
= zonegroup
.set_as_default();
3600 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3604 encode_json("zonegroup", zonegroup
, formatter
);
3605 formatter
->flush(cout
);
3608 case OPT_ZONEGROUP_SET
:
3610 RGWRealm
realm(realm_id
, realm_name
);
3611 int ret
= realm
.init(g_ceph_context
, store
);
3613 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3617 RGWZoneGroup zonegroup
;
3618 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3620 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3623 ret
= read_decode_json(infile
, zonegroup
);
3627 if (zonegroup
.realm_id
.empty()) {
3628 zonegroup
.realm_id
= realm
.get_id();
3630 ret
= zonegroup
.create();
3631 if (ret
< 0 && ret
!= -EEXIST
) {
3632 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3634 } else if (ret
== -EEXIST
) {
3635 ret
= zonegroup
.update();
3637 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3643 ret
= zonegroup
.set_as_default();
3645 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3649 encode_json("zonegroup", zonegroup
, formatter
);
3650 formatter
->flush(cout
);
3653 case OPT_ZONEGROUP_REMOVE
:
3655 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3656 int ret
= zonegroup
.init(g_ceph_context
, store
);
3658 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3662 if (zone_id
.empty()) {
3663 if (zone_name
.empty()) {
3664 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
3667 // look up zone id by name
3668 for (auto& z
: zonegroup
.zones
) {
3669 if (zone_name
== z
.second
.name
) {
3670 zone_id
= z
.second
.id
;
3674 if (zone_id
.empty()) {
3675 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
3676 << zonegroup
.get_name() << std::endl
;
3681 ret
= zonegroup
.remove_zone(zone_id
);
3683 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
3687 encode_json("zonegroup", zonegroup
, formatter
);
3688 formatter
->flush(cout
);
3691 case OPT_ZONEGROUP_RENAME
:
3693 if (zonegroup_new_name
.empty()) {
3694 cerr
<< " missing zonegroup new name" << std::endl
;
3697 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3698 cerr
<< "no zonegroup name or id provided" << std::endl
;
3701 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3702 int ret
= zonegroup
.init(g_ceph_context
, store
);
3704 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3707 ret
= zonegroup
.rename(zonegroup_new_name
);
3709 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3714 case OPT_ZONEGROUP_PLACEMENT_LIST
:
3716 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3717 int ret
= zonegroup
.init(g_ceph_context
, store
);
3719 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3723 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3724 formatter
->flush(cout
);
3728 case OPT_ZONEGROUP_PLACEMENT_ADD
:
3729 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
3730 case OPT_ZONEGROUP_PLACEMENT_RM
:
3731 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
3733 if (placement_id
.empty()) {
3734 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
3738 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3739 int ret
= zonegroup
.init(g_ceph_context
, store
);
3741 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3745 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
3746 RGWZoneGroupPlacementTarget target
;
3747 target
.name
= placement_id
;
3748 for (auto& t
: tags
) {
3749 target
.tags
.insert(t
);
3751 zonegroup
.placement_targets
[placement_id
] = target
;
3752 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
3753 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
3754 if (!tags
.empty()) {
3755 target
.tags
.clear();
3756 for (auto& t
: tags
) {
3757 target
.tags
.insert(t
);
3760 target
.name
= placement_id
;
3761 for (auto& t
: tags_rm
) {
3762 target
.tags
.erase(t
);
3764 for (auto& t
: tags_add
) {
3765 target
.tags
.insert(t
);
3767 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
3768 zonegroup
.placement_targets
.erase(placement_id
);
3769 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
3770 if (!zonegroup
.placement_targets
.count(placement_id
)) {
3771 cerr
<< "failed to find a zonegroup placement target named '"
3772 << placement_id
<< "'" << std::endl
;
3775 zonegroup
.default_placement
= placement_id
;
3778 zonegroup
.post_process_params();
3779 ret
= zonegroup
.update();
3781 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3785 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3786 formatter
->flush(cout
);
3789 case OPT_ZONE_CREATE
:
3791 if (zone_name
.empty()) {
3792 cerr
<< "zone name not provided" << std::endl
;
3796 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3797 /* if the user didn't provide zonegroup info , create stand alone zone */
3798 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3799 ret
= zonegroup
.init(g_ceph_context
, store
);
3801 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3804 if (realm_id
.empty() && realm_name
.empty()) {
3805 realm_id
= zonegroup
.realm_id
;
3809 RGWZoneParams
zone(zone_id
, zone_name
);
3810 ret
= zone
.init(g_ceph_context
, store
, false);
3812 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3816 zone
.system_key
.id
= access_key
;
3817 zone
.system_key
.key
= secret_key
;
3818 zone
.realm_id
= realm_id
;
3819 zone
.tier_config
= tier_config_add
;
3821 ret
= zone
.create();
3823 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3827 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3828 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3829 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3830 ret
= zonegroup
.add_zone(zone
,
3831 (is_master_set
? &is_master
: NULL
),
3832 (is_read_only_set
? &read_only
: NULL
),
3836 sync_from
, sync_from_rm
);
3838 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
3839 << ": " << cpp_strerror(-ret
) << std::endl
;
3845 ret
= zone
.set_as_default();
3847 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3851 encode_json("zone", zone
, formatter
);
3852 formatter
->flush(cout
);
3856 case OPT_ZONE_DEFAULT
:
3858 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3859 int ret
= zonegroup
.init(g_ceph_context
, store
);
3861 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3863 if (zone_id
.empty() && zone_name
.empty()) {
3864 cerr
<< "no zone name or id provided" << std::endl
;
3867 RGWZoneParams
zone(zone_id
, zone_name
);
3868 ret
= zone
.init(g_ceph_context
, store
);
3870 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3873 ret
= zone
.set_as_default();
3875 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
3880 case OPT_ZONE_DELETE
:
3882 if (zone_id
.empty() && zone_name
.empty()) {
3883 cerr
<< "no zone name or id provided" << std::endl
;
3886 RGWZoneParams
zone(zone_id
, zone_name
);
3887 int ret
= zone
.init(g_ceph_context
, store
);
3889 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3893 list
<string
> zonegroups
;
3894 ret
= store
->list_zonegroups(zonegroups
);
3896 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3900 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
3901 RGWZoneGroup
zonegroup(string(), *iter
);
3902 int ret
= zonegroup
.init(g_ceph_context
, store
);
3904 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3907 ret
= zonegroup
.remove_zone(zone
.get_id());
3908 if (ret
< 0 && ret
!= -ENOENT
) {
3909 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
3910 << cpp_strerror(-ret
) << std::endl
;
3914 ret
= zone
.delete_obj();
3916 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3923 RGWZoneParams
zone(zone_id
, zone_name
);
3924 int ret
= zone
.init(g_ceph_context
, store
);
3926 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3929 encode_json("zone", zone
, formatter
);
3930 formatter
->flush(cout
);
3935 RGWZoneParams
zone(zone_name
);
3936 int ret
= zone
.init(g_ceph_context
, store
, false);
3942 if (ret
< 0 && ret
!= -ENOENT
) {
3943 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
3947 string orig_id
= zone
.get_id();
3949 ret
= read_decode_json(infile
, zone
);
3954 if(zone
.realm_id
.empty()) {
3955 RGWRealm
realm(realm_id
, realm_name
);
3956 int ret
= realm
.init(g_ceph_context
, store
);
3957 if (ret
< 0 && ret
!= -ENOENT
) {
3958 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3961 zone
.realm_id
= realm
.get_id();
3964 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
3965 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
3969 if (zone
.get_name().empty()) {
3970 zone
.set_name(zone_name
);
3971 if (zone
.get_name().empty()) {
3972 cerr
<< "no zone name specified" << std::endl
;
3977 zone_name
= zone
.get_name();
3979 if (zone
.get_id().empty()) {
3980 zone
.set_id(orig_id
);
3983 if (zone
.get_id().empty()) {
3984 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
3985 if (zone_name
.empty()) {
3986 cerr
<< "missing zone name" << std::endl
;
3989 zone
.set_name(zone_name
);
3990 zone
.set_id(zone_name
);
3993 cerr
<< "zone id " << zone
.get_id();
3994 ret
= zone
.fix_pool_names();
3996 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
3999 ret
= zone
.write(false);
4001 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4006 ret
= zone
.set_as_default();
4008 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4012 encode_json("zone", zone
, formatter
);
4013 formatter
->flush(cout
);
4019 int ret
= store
->list_zones(zones
);
4021 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4026 ret
= zone
.init(g_ceph_context
, store
, false);
4028 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4031 string default_zone
;
4032 ret
= zone
.read_default_id(default_zone
);
4033 if (ret
< 0 && ret
!= -ENOENT
) {
4034 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4036 formatter
->open_object_section("zones_list");
4037 encode_json("default_info", default_zone
, formatter
);
4038 encode_json("zones", zones
, formatter
);
4039 formatter
->close_section();
4040 formatter
->flush(cout
);
4044 case OPT_ZONE_MODIFY
:
4046 RGWZoneParams
zone(zone_id
, zone_name
);
4047 int ret
= zone
.init(g_ceph_context
, store
);
4049 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4053 bool need_zone_update
= false;
4054 if (!access_key
.empty()) {
4055 zone
.system_key
.id
= access_key
;
4056 need_zone_update
= true;
4059 if (!secret_key
.empty()) {
4060 zone
.system_key
.key
= secret_key
;
4061 need_zone_update
= true;
4064 if (!realm_id
.empty()) {
4065 zone
.realm_id
= realm_id
;
4066 need_zone_update
= true;
4067 } else if (!realm_name
.empty()) {
4068 // get realm id from name
4069 RGWRealm realm
{g_ceph_context
, store
};
4070 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4072 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4075 need_zone_update
= true;
4078 for (auto add
: tier_config_add
) {
4079 zone
.tier_config
[add
.first
] = add
.second
;
4080 need_zone_update
= true;
4083 for (auto rm
: tier_config_rm
) {
4084 zone
.tier_config
.erase(rm
.first
);
4085 need_zone_update
= true;
4088 if (need_zone_update
) {
4089 ret
= zone
.update();
4091 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4096 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4097 ret
= zonegroup
.init(g_ceph_context
, store
);
4099 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4102 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4104 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4106 ret
= zonegroup
.add_zone(zone
,
4107 (is_master_set
? &is_master
: NULL
),
4108 (is_read_only_set
? &read_only
: NULL
),
4109 endpoints
, ptier_type
,
4110 psync_from_all
, sync_from
, sync_from_rm
);
4112 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4116 ret
= zonegroup
.update();
4118 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4123 ret
= zone
.set_as_default();
4125 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4129 encode_json("zone", zone
, formatter
);
4130 formatter
->flush(cout
);
4133 case OPT_ZONE_RENAME
:
4135 if (zone_new_name
.empty()) {
4136 cerr
<< " missing zone new name" << std::endl
;
4139 if (zone_id
.empty() && zone_name
.empty()) {
4140 cerr
<< "no zonegroup name or id provided" << std::endl
;
4143 RGWZoneParams
zone(zone_id
,zone_name
);
4144 int ret
= zone
.init(g_ceph_context
, store
);
4146 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4149 ret
= zone
.rename(zone_new_name
);
4151 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4155 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4156 ret
= zonegroup
.init(g_ceph_context
, store
);
4158 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4160 ret
= zonegroup
.rename_zone(zone
);
4161 if (ret
< 0 && ret
) {
4162 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4168 case OPT_ZONE_PLACEMENT_ADD
:
4169 case OPT_ZONE_PLACEMENT_MODIFY
:
4170 case OPT_ZONE_PLACEMENT_RM
:
4172 if (placement_id
.empty()) {
4173 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4176 RGWZoneParams
zone(zone_id
, zone_name
);
4177 int ret
= zone
.init(g_ceph_context
, store
);
4179 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4183 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4184 // pool names are required
4185 if (!index_pool
|| index_pool
->empty() ||
4186 !data_pool
|| data_pool
->empty()) {
4187 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4191 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4193 info
.index_pool
= *index_pool
;
4194 info
.data_pool
= *data_pool
;
4195 if (data_extra_pool
) {
4196 info
.data_extra_pool
= *data_extra_pool
;
4198 if (index_type_specified
) {
4199 info
.index_type
= placement_index_type
;
4201 if (compression_type
) {
4202 info
.compression_type
= *compression_type
;
4204 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4205 auto p
= zone
.placement_pools
.find(placement_id
);
4206 if (p
== zone
.placement_pools
.end()) {
4207 cerr
<< "ERROR: zone placement target '" << placement_id
4208 << "' not found" << std::endl
;
4211 auto& info
= p
->second
;
4212 if (index_pool
&& !index_pool
->empty()) {
4213 info
.index_pool
= *index_pool
;
4215 if (data_pool
&& !data_pool
->empty()) {
4216 info
.data_pool
= *data_pool
;
4218 if (data_extra_pool
) {
4219 info
.data_extra_pool
= *data_extra_pool
;
4221 if (index_type_specified
) {
4222 info
.index_type
= placement_index_type
;
4224 if (compression_type
) {
4225 info
.compression_type
= *compression_type
;
4227 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4228 zone
.placement_pools
.erase(placement_id
);
4231 ret
= zone
.update();
4233 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4237 encode_json("zone", zone
, formatter
);
4238 formatter
->flush(cout
);
4241 case OPT_ZONE_PLACEMENT_LIST
:
4243 RGWZoneParams
zone(zone_id
, zone_name
);
4244 int ret
= zone
.init(g_ceph_context
, store
);
4246 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4249 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4250 formatter
->flush(cout
);
4257 if (!user_id
.empty()) {
4258 user_op
.set_user_id(user_id
);
4259 bucket_op
.set_user_id(user_id
);
4262 if (!display_name
.empty())
4263 user_op
.set_display_name(display_name
);
4265 if (!user_email
.empty())
4266 user_op
.set_user_email(user_email
);
4268 if (!access_key
.empty())
4269 user_op
.set_access_key(access_key
);
4271 if (!secret_key
.empty())
4272 user_op
.set_secret_key(secret_key
);
4274 if (!subuser
.empty())
4275 user_op
.set_subuser(subuser
);
4278 user_op
.set_caps(caps
);
4280 user_op
.set_purge_data(purge_data
);
4283 user_op
.set_purge_keys();
4286 user_op
.set_generate_key();
4289 user_op
.set_gen_secret(); // assume that a key pair should be created
4291 if (max_buckets_specified
)
4292 user_op
.set_max_buckets(max_buckets
);
4294 if (admin_specified
)
4295 user_op
.set_admin(admin
);
4297 if (system_specified
)
4298 user_op
.set_system(system
);
4301 user_op
.set_perm(perm_mask
);
4303 if (set_temp_url_key
) {
4304 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4305 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4306 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4310 if (!op_mask_str
.empty()) {
4312 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4314 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4318 user_op
.set_op_mask(op_mask
);
4321 if (key_type
!= KEY_TYPE_UNDEFINED
)
4322 user_op
.set_key_type(key_type
);
4324 // set suspension operation parameters
4325 if (opt_cmd
== OPT_USER_ENABLE
)
4326 user_op
.set_suspension(false);
4327 else if (opt_cmd
== OPT_USER_SUSPEND
)
4328 user_op
.set_suspension(true);
4330 // RGWUser to use for user operations
4333 if (!user_id
.empty() || !subuser
.empty()) {
4334 ret
= user
.init(store
, user_op
);
4336 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4341 /* populate bucket operation */
4342 bucket_op
.set_bucket_name(bucket_name
);
4343 bucket_op
.set_object(object
);
4344 bucket_op
.set_check_objects(check_objects
);
4345 bucket_op
.set_delete_children(delete_child_objects
);
4346 bucket_op
.set_fix_index(fix
);
4347 bucket_op
.set_max_aio(max_concurrent_ios
);
4349 // required to gather errors from operations
4350 std::string err_msg
;
4352 bool output_user_info
= true;
4357 case OPT_USER_CREATE
:
4358 if (!user_op
.has_existing_user()) {
4359 user_op
.set_generate_key(); // generate a new key by default
4361 ret
= user
.add(user_op
, &err_msg
);
4363 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4366 if (!subuser
.empty()) {
4367 ret
= user
.subusers
.add(user_op
, &err_msg
);
4369 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4375 ret
= user
.remove(user_op
, &err_msg
);
4377 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4381 output_user_info
= false;
4383 case OPT_USER_ENABLE
:
4384 case OPT_USER_SUSPEND
:
4385 case OPT_USER_MODIFY
:
4386 ret
= user
.modify(user_op
, &err_msg
);
4388 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4393 case OPT_SUBUSER_CREATE
:
4394 ret
= user
.subusers
.add(user_op
, &err_msg
);
4396 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4401 case OPT_SUBUSER_MODIFY
:
4402 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4404 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4409 case OPT_SUBUSER_RM
:
4410 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4412 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4418 ret
= user
.caps
.add(user_op
, &err_msg
);
4420 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4426 ret
= user
.caps
.remove(user_op
, &err_msg
);
4428 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4433 case OPT_KEY_CREATE
:
4434 ret
= user
.keys
.add(user_op
, &err_msg
);
4436 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4442 ret
= user
.keys
.remove(user_op
, &err_msg
);
4444 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4448 case OPT_PERIOD_PUSH
:
4451 req_info
info(g_ceph_context
, &env
);
4452 info
.method
= "POST";
4453 info
.request_uri
= "/admin/realm/period";
4455 map
<string
, string
> ¶ms
= info
.args
.get_params();
4456 if (!realm_id
.empty())
4457 params
["realm_id"] = realm_id
;
4458 if (!realm_name
.empty())
4459 params
["realm_name"] = realm_name
;
4460 if (!period_id
.empty())
4461 params
["period_id"] = period_id
;
4462 if (!period_epoch
.empty())
4463 params
["epoch"] = period_epoch
;
4466 RGWPeriod
period(period_id
);
4467 int ret
= period
.init(g_ceph_context
, store
);
4469 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4472 // json format into a bufferlist
4473 JSONFormatter
jf(false);
4474 encode_json("period", period
, &jf
);
4479 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4482 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4487 case OPT_PERIOD_UPDATE
:
4489 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4490 commit
, remote
, url
, access_key
, secret_key
,
4491 formatter
, yes_i_really_mean_it
);
4497 case OPT_PERIOD_COMMIT
:
4499 // read realm and staging period
4500 RGWRealm
realm(realm_id
, realm_name
);
4501 int ret
= realm
.init(g_ceph_context
, store
);
4503 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4506 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4507 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4509 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4512 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4513 yes_i_really_mean_it
);
4515 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4519 encode_json("period", period
, formatter
);
4520 formatter
->flush(cout
);
4524 case OPT_ROLE_CREATE
:
4526 if (role_name
.empty()) {
4527 cerr
<< "ERROR: role name is empty" << std::endl
;
4531 if (assume_role_doc
.empty()) {
4532 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4535 /* The following two calls will be replaced by read_decode_json or something
4536 similar when the code for AWS Policies is in places */
4538 int ret
= read_input(assume_role_doc
, bl
);
4540 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4544 if (!p
.parse(bl
.c_str(), bl
.length())) {
4545 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4548 string trust_policy
= bl
.to_str();
4549 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4550 ret
= role
.create(true);
4554 show_role_info(role
, formatter
);
4557 case OPT_ROLE_DELETE
:
4559 if (role_name
.empty()) {
4560 cerr
<< "ERROR: empty role name" << std::endl
;
4563 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4564 ret
= role
.delete_obj();
4568 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4573 if (role_name
.empty()) {
4574 cerr
<< "ERROR: empty role name" << std::endl
;
4577 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4582 show_role_info(role
, formatter
);
4585 case OPT_ROLE_MODIFY
:
4587 if (role_name
.empty()) {
4588 cerr
<< "ERROR: role name is empty" << std::endl
;
4592 if (assume_role_doc
.empty()) {
4593 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4597 /* The following two calls will be replaced by read_decode_json or something
4598 similar when the code for AWS Policies is in place */
4600 int ret
= read_input(assume_role_doc
, bl
);
4602 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4606 if (!p
.parse(bl
.c_str(), bl
.length())) {
4607 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4610 string trust_policy
= bl
.to_str();
4611 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4616 role
.update_trust_policy(trust_policy
);
4617 ret
= role
.update();
4621 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4626 vector
<RGWRole
> result
;
4627 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4631 show_roles_info(result
, formatter
);
4634 case OPT_ROLE_POLICY_PUT
:
4636 if (role_name
.empty()) {
4637 cerr
<< "role name is empty" << std::endl
;
4641 if (policy_name
.empty()) {
4642 cerr
<< "policy name is empty" << std::endl
;
4646 if (perm_policy_doc
.empty()) {
4647 cerr
<< "permission policy document is empty" << std::endl
;
4651 /* The following two calls will be replaced by read_decode_json or something
4652 similar, when code for AWS Policies is in place.*/
4654 int ret
= read_input(perm_policy_doc
, bl
);
4656 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4660 if (!p
.parse(bl
.c_str(), bl
.length())) {
4661 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
4665 perm_policy
= bl
.c_str();
4667 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4672 role
.set_perm_policy(policy_name
, perm_policy
);
4673 ret
= role
.update();
4677 cout
<< "Permission policy attached successfully" << std::endl
;
4680 case OPT_ROLE_POLICY_LIST
:
4682 if (role_name
.empty()) {
4683 cerr
<< "ERROR: Role name is empty" << std::endl
;
4686 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4691 std::vector
<string
> policy_names
= role
.get_role_policy_names();
4692 show_policy_names(policy_names
, formatter
);
4695 case OPT_ROLE_POLICY_GET
:
4697 if (role_name
.empty()) {
4698 cerr
<< "ERROR: role name is empty" << std::endl
;
4702 if (policy_name
.empty()) {
4703 cerr
<< "ERROR: policy name is empty" << std::endl
;
4706 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4707 int ret
= role
.get();
4712 ret
= role
.get_role_policy(policy_name
, perm_policy
);
4716 show_perm_policy(perm_policy
, formatter
);
4719 case OPT_ROLE_POLICY_DELETE
:
4721 if (role_name
.empty()) {
4722 cerr
<< "ERROR: role name is empty" << std::endl
;
4726 if (policy_name
.empty()) {
4727 cerr
<< "ERROR: policy name is empty" << std::endl
;
4730 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4735 ret
= role
.delete_policy(policy_name
);
4739 ret
= role
.update();
4743 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
4744 << role_name
<< std::endl
;
4748 output_user_info
= false;
4751 // output the result of a user operation
4752 if (output_user_info
) {
4753 ret
= user
.info(info
, &err_msg
);
4755 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
4758 show_user_info(info
, formatter
);
4761 if (opt_cmd
== OPT_POLICY
) {
4762 if (format
== "xml") {
4763 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
4765 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4769 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
4771 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4777 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
4779 std::list
<std::string
> user_ids
;
4780 metadata_key
= "user";
4785 if (! user_id
.empty()) {
4786 user_ids
.push_back(user_id
.id
);
4788 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4791 /* list users in groups of max-keys, then perform user-bucket
4792 * limit-check on each group */
4793 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
4795 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
4796 << cpp_strerror(-ret
) << std::endl
;
4801 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
4803 if (ret
< 0 && ret
!= -ENOENT
) {
4804 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
4805 << cpp_strerror(-ret
) << std::endl
;
4808 /* ok, do the limit checks for this group */
4810 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4816 } while (truncated
);
4817 store
->meta_mgr
->list_keys_complete(handle
);
4820 } /* OPT_BUCKET_LIMIT_CHECK */
4822 if (opt_cmd
== OPT_BUCKETS_LIST
) {
4823 if (bucket_name
.empty()) {
4824 RGWBucketAdminOp::info(store
, bucket_op
, f
);
4826 RGWBucketInfo bucket_info
;
4827 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
4829 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
4832 formatter
->open_array_section("entries");
4835 if (max_entries
< 0)
4840 vector
<rgw_bucket_dir_entry
> result
;
4841 map
<string
, bool> common_prefixes
;
4844 RGWRados::Bucket
target(store
, bucket_info
);
4845 RGWRados::Bucket::List
list_op(&target
);
4847 list_op
.params
.prefix
= prefix
;
4848 list_op
.params
.delim
= delim
;
4849 list_op
.params
.marker
= rgw_obj_key(marker
);
4850 list_op
.params
.ns
= ns
;
4851 list_op
.params
.enforce_ns
= false;
4852 list_op
.params
.list_versions
= true;
4855 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
4857 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
4861 count
+= result
.size();
4863 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
4864 rgw_bucket_dir_entry
& entry
= *iter
;
4865 encode_json("entry", entry
, formatter
);
4867 formatter
->flush(cout
);
4868 } while (truncated
&& count
< max_entries
);
4870 formatter
->close_section();
4871 formatter
->flush(cout
);
4872 } /* have bucket_name */
4873 } /* OPT_BUCKETS_LIST */
4875 if (opt_cmd
== OPT_BUCKET_STATS
) {
4876 bucket_op
.set_fetch_stats(true);
4878 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
4880 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4885 if (opt_cmd
== OPT_BUCKET_LINK
) {
4886 bucket_op
.set_bucket_id(bucket_id
);
4888 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
4890 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4895 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
4896 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
4898 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
4903 if (opt_cmd
== OPT_LOG_LIST
) {
4905 if (date
.size() && date
.size() != 10) {
4906 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
4911 formatter
->open_array_section("logs");
4913 int r
= store
->log_list_init(date
, &h
);
4918 cerr
<< "log list: error " << r
<< std::endl
;
4923 int r
= store
->log_list_next(h
, &name
);
4927 cerr
<< "log list: error " << r
<< std::endl
;
4930 formatter
->dump_string("object", name
);
4933 formatter
->close_section();
4934 formatter
->flush(cout
);
4938 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
4939 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
4940 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
4945 if (!object
.empty()) {
4955 if (opt_cmd
== OPT_LOG_SHOW
) {
4958 int r
= store
->log_show_init(oid
, &h
);
4960 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
4965 formatter
->open_object_section("log");
4967 struct rgw_log_entry entry
;
4969 // peek at first entry to get bucket metadata
4970 r
= store
->log_show_next(h
, &entry
);
4972 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
4975 formatter
->dump_string("bucket_id", entry
.bucket_id
);
4976 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
4977 formatter
->dump_string("bucket", entry
.bucket
);
4979 uint64_t agg_time
= 0;
4980 uint64_t agg_bytes_sent
= 0;
4981 uint64_t agg_bytes_received
= 0;
4982 uint64_t total_entries
= 0;
4984 if (show_log_entries
)
4985 formatter
->open_array_section("log_entries");
4988 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
4990 agg_time
+= total_time
;
4991 agg_bytes_sent
+= entry
.bytes_sent
;
4992 agg_bytes_received
+= entry
.bytes_received
;
4995 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
4996 entry
.bytes_received
== 0)
4999 if (show_log_entries
) {
5001 rgw_format_ops_log_entry(entry
, formatter
);
5002 formatter
->flush(cout
);
5005 r
= store
->log_show_next(h
, &entry
);
5009 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5012 if (show_log_entries
)
5013 formatter
->close_section();
5016 formatter
->open_object_section("log_sum");
5017 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5018 formatter
->dump_int("bytes_received", agg_bytes_received
);
5019 formatter
->dump_int("total_time", agg_time
);
5020 formatter
->dump_int("total_entries", total_entries
);
5021 formatter
->close_section();
5023 formatter
->close_section();
5024 formatter
->flush(cout
);
5027 if (opt_cmd
== OPT_LOG_RM
) {
5028 int r
= store
->log_remove(oid
);
5030 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5036 if (opt_cmd
== OPT_POOL_ADD
) {
5037 if (pool_name
.empty()) {
5038 cerr
<< "need to specify pool to add!" << std::endl
;
5042 int ret
= store
->add_bucket_placement(pool
);
5044 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5047 if (opt_cmd
== OPT_POOL_RM
) {
5048 if (pool_name
.empty()) {
5049 cerr
<< "need to specify pool to remove!" << std::endl
;
5053 int ret
= store
->remove_bucket_placement(pool
);
5055 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5058 if (opt_cmd
== OPT_POOLS_LIST
) {
5059 set
<rgw_pool
> pools
;
5060 int ret
= store
->list_placement_set(pools
);
5062 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5066 formatter
->open_array_section("pools");
5067 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5068 formatter
->open_object_section("pool");
5069 formatter
->dump_string("name", siter
->to_str());
5070 formatter
->close_section();
5072 formatter
->close_section();
5073 formatter
->flush(cout
);
5077 if (opt_cmd
== OPT_USAGE_SHOW
) {
5078 uint64_t start_epoch
= 0;
5079 uint64_t end_epoch
= (uint64_t)-1;
5083 if (!start_date
.empty()) {
5084 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5086 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5090 if (!end_date
.empty()) {
5091 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5093 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5099 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5100 show_log_entries
, show_log_sum
, &categories
,
5103 cerr
<< "ERROR: failed to show usage" << std::endl
;
5108 if (opt_cmd
== OPT_USAGE_TRIM
) {
5109 if (user_id
.empty() && !yes_i_really_mean_it
) {
5110 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5111 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5115 uint64_t start_epoch
= 0;
5116 uint64_t end_epoch
= (uint64_t)-1;
5119 if (!start_date
.empty()) {
5120 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5122 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5127 if (!end_date
.empty()) {
5128 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5130 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5135 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5137 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5142 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5143 if (bucket_name
.empty()) {
5144 cerr
<< "ERROR: bucket not specified" << std::endl
;
5147 if (object
.empty()) {
5148 cerr
<< "ERROR: object not specified" << std::endl
;
5151 RGWBucketInfo bucket_info
;
5152 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5154 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5159 if (opt_cmd
== OPT_OLH_GET
) {
5160 RGWBucketInfo bucket_info
;
5161 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5163 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5167 rgw_obj
obj(bucket
, object
);
5168 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5170 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5173 encode_json("olh", olh
, formatter
);
5174 formatter
->flush(cout
);
5177 if (opt_cmd
== OPT_OLH_READLOG
) {
5178 RGWBucketInfo bucket_info
;
5179 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5181 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5184 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5187 RGWObjectCtx
rctx(store
);
5188 rgw_obj
obj(bucket
, object
);
5192 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5197 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5199 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5202 formatter
->open_object_section("result");
5203 encode_json("is_truncated", is_truncated
, formatter
);
5204 encode_json("log", log
, formatter
);
5205 formatter
->close_section();
5206 formatter
->flush(cout
);
5209 if (opt_cmd
== OPT_BI_GET
) {
5210 RGWBucketInfo bucket_info
;
5211 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5213 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5216 rgw_obj
obj(bucket
, object
);
5217 if (!object_version
.empty()) {
5218 obj
.key
.set_instance(object_version
);
5221 rgw_cls_bi_entry entry
;
5223 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5225 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5229 encode_json("entry", entry
, formatter
);
5230 formatter
->flush(cout
);
5233 if (opt_cmd
== OPT_BI_PUT
) {
5234 RGWBucketInfo bucket_info
;
5235 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5237 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5241 rgw_cls_bi_entry entry
;
5242 cls_rgw_obj_key key
;
5243 ret
= read_decode_json(infile
, entry
, &key
);
5248 rgw_obj
obj(bucket
, key
);
5250 ret
= store
->bi_put(bucket
, obj
, entry
);
5252 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5257 if (opt_cmd
== OPT_BI_LIST
) {
5258 if (bucket_name
.empty()) {
5259 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5262 RGWBucketInfo bucket_info
;
5263 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5265 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5269 list
<rgw_cls_bi_entry
> entries
;
5271 if (max_entries
< 0) {
5275 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5277 formatter
->open_array_section("entries");
5279 for (int i
= 0; i
< max_shards
; i
++) {
5280 RGWRados::BucketShard
bs(store
);
5281 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5282 int ret
= bs
.init(bucket
, shard_id
);
5286 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5292 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5294 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5298 list
<rgw_cls_bi_entry
>::iterator iter
;
5299 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5300 rgw_cls_bi_entry
& entry
= *iter
;
5301 encode_json("entry", entry
, formatter
);
5304 formatter
->flush(cout
);
5305 } while (is_truncated
);
5306 formatter
->flush(cout
);
5308 formatter
->close_section();
5309 formatter
->flush(cout
);
5312 if (opt_cmd
== OPT_BI_PURGE
) {
5313 if (bucket_name
.empty()) {
5314 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5317 RGWBucketInfo bucket_info
;
5318 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5320 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5324 RGWBucketInfo cur_bucket_info
;
5325 rgw_bucket cur_bucket
;
5326 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5328 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5332 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5333 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5334 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5338 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5340 for (int i
= 0; i
< max_shards
; i
++) {
5341 RGWRados::BucketShard
bs(store
);
5342 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5343 int ret
= bs
.init(bucket
, shard_id
);
5345 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5349 ret
= store
->bi_remove(bs
);
5351 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5357 if (opt_cmd
== OPT_OBJECT_RM
) {
5358 RGWBucketInfo bucket_info
;
5359 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5361 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5364 rgw_obj_key
key(object
, object_version
);
5365 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5368 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5373 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5374 if (bucket_name
.empty()) {
5375 cerr
<< "ERROR: bucket not specified" << std::endl
;
5378 if (object
.empty()) {
5379 cerr
<< "ERROR: object not specified" << std::endl
;
5383 RGWBucketInfo bucket_info
;
5384 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5386 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5390 rgw_obj
obj(bucket
, object
);
5391 obj
.key
.set_instance(object_version
);
5392 bool need_rewrite
= true;
5393 if (min_rewrite_stripe_size
> 0) {
5394 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5396 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5400 ret
= store
->rewrite_obj(bucket_info
, obj
);
5402 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5406 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5410 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5411 int ret
= store
->process_expire_objects();
5413 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5418 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5419 if (bucket_name
.empty()) {
5420 cerr
<< "ERROR: bucket not specified" << std::endl
;
5424 RGWBucketInfo bucket_info
;
5425 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5427 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5431 uint64_t start_epoch
= 0;
5432 uint64_t end_epoch
= 0;
5434 if (!end_date
.empty()) {
5435 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5437 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5441 if (!start_date
.empty()) {
5442 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5444 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5449 bool is_truncated
= true;
5451 rgw_obj_index_key marker
;
5454 formatter
->open_object_section("result");
5455 formatter
->dump_string("bucket", bucket_name
);
5456 formatter
->open_array_section("objects");
5457 while (is_truncated
) {
5458 map
<string
, rgw_bucket_dir_entry
> result
;
5459 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5460 result
, &is_truncated
, &marker
,
5461 bucket_object_check_filter
);
5463 if (r
< 0 && r
!= -ENOENT
) {
5464 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5470 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5471 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5472 rgw_obj_key key
= iter
->second
.key
;
5473 rgw_bucket_dir_entry
& entry
= iter
->second
;
5475 formatter
->open_object_section("object");
5476 formatter
->dump_string("name", key
.name
);
5477 formatter
->dump_string("instance", key
.instance
);
5478 formatter
->dump_int("size", entry
.meta
.size
);
5479 utime_t
ut(entry
.meta
.mtime
);
5480 ut
.gmtime(formatter
->dump_stream("mtime"));
5482 if ((entry
.meta
.size
< min_rewrite_size
) ||
5483 (entry
.meta
.size
> max_rewrite_size
) ||
5484 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5485 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5486 formatter
->dump_string("status", "Skipped");
5488 rgw_obj
obj(bucket
, key
);
5490 bool need_rewrite
= true;
5491 if (min_rewrite_stripe_size
> 0) {
5492 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5494 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5497 if (!need_rewrite
) {
5498 formatter
->dump_string("status", "Skipped");
5500 r
= store
->rewrite_obj(bucket_info
, obj
);
5502 formatter
->dump_string("status", "Success");
5504 formatter
->dump_string("status", cpp_strerror(-r
));
5508 formatter
->dump_int("flags", entry
.flags
);
5510 formatter
->close_section();
5511 formatter
->flush(cout
);
5514 formatter
->close_section();
5515 formatter
->close_section();
5516 formatter
->flush(cout
);
5519 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5521 RGWBucketInfo bucket_info
;
5522 map
<string
, bufferlist
> attrs
;
5524 int ret
= check_reshard_bucket_params(store
,
5528 num_shards_specified
,
5530 yes_i_really_mean_it
,
5538 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5540 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5541 if (max_entries
< 1) {
5542 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5545 return br
.execute(num_shards
, max_entries
,
5546 verbose
, &cout
, formatter
);
5549 if (opt_cmd
== OPT_RESHARD_ADD
) {
5551 RGWBucketInfo bucket_info
;
5552 map
<string
, bufferlist
> attrs
;
5554 int ret
= check_reshard_bucket_params(store
,
5558 num_shards_specified
,
5560 yes_i_really_mean_it
,
5568 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5570 RGWReshard
reshard(store
);
5571 cls_rgw_reshard_entry entry
;
5572 entry
.time
= real_clock::now();
5573 entry
.tenant
= tenant
;
5574 entry
.bucket_name
= bucket_name
;
5575 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5576 entry
.old_num_shards
= num_source_shards
;
5577 entry
.new_num_shards
= num_shards
;
5579 return reshard
.add(entry
);
5582 if (opt_cmd
== OPT_RESHARD_LIST
) {
5583 list
<cls_rgw_reshard_entry
> entries
;
5586 if (max_entries
< 0) {
5590 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5592 RGWReshard
reshard(store
);
5594 formatter
->open_array_section("reshard");
5595 for (int i
= 0; i
< num_logshards
; i
++) {
5596 bool is_truncated
= true;
5600 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5602 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5605 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5606 cls_rgw_reshard_entry
& entry
= *iter
;
5607 encode_json("entry", entry
, formatter
);
5608 entry
.get_key(&marker
);
5610 count
+= entries
.size();
5611 formatter
->flush(cout
);
5612 } while (is_truncated
&& count
< max_entries
);
5614 if (count
>= max_entries
) {
5619 formatter
->close_section();
5620 formatter
->flush(cout
);
5625 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5626 if (bucket_name
.empty()) {
5627 cerr
<< "ERROR: bucket not specified" << std::endl
;
5632 RGWBucketInfo bucket_info
;
5633 map
<string
, bufferlist
> attrs
;
5634 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5636 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5640 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5641 list
<cls_rgw_bucket_instance_entry
> status
;
5642 int r
= br
.get_status(&status
);
5644 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5648 encode_json("status", status
, formatter
);
5649 formatter
->flush(cout
);
5652 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5653 RGWReshard
reshard(store
, true, &cout
);
5655 int ret
= reshard
.process_all_logshards();
5657 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
5662 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
5663 RGWReshard
reshard(store
);
5665 if (bucket_name
.empty()) {
5666 cerr
<< "ERROR: bucket not specified" << std::endl
;
5669 cls_rgw_reshard_entry entry
;
5670 //entry.tenant = tenant;
5671 entry
.bucket_name
= bucket_name
;
5672 //entry.bucket_id = bucket_id;
5673 int ret
= reshard
.get(entry
);
5675 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5679 /* TBD stop running resharding */
5681 ret
=reshard
.remove(entry
);
5683 cerr
<< "Error removing bucket " << bucket_name
<< " for resharding queue: " << cpp_strerror(-ret
) <<
5689 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
5690 RGWBucketInfo bucket_info
;
5691 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5693 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5696 list
<rgw_obj_index_key
> oid_list
;
5697 rgw_obj_key
key(object
, object_version
);
5698 rgw_obj_index_key index_key
;
5699 key
.get_index_key(&index_key
);
5700 oid_list
.push_back(index_key
);
5701 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
5703 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
5708 if (opt_cmd
== OPT_OBJECT_STAT
) {
5709 RGWBucketInfo bucket_info
;
5710 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5712 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5715 rgw_obj
obj(bucket
, object
);
5716 obj
.key
.set_instance(object_version
);
5719 map
<string
, bufferlist
> attrs
;
5720 RGWObjectCtx
obj_ctx(store
);
5721 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
5722 RGWRados::Object::Read
read_op(&op_target
);
5724 read_op
.params
.attrs
= &attrs
;
5725 read_op
.params
.obj_size
= &obj_size
;
5727 ret
= read_op
.prepare();
5729 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
5732 formatter
->open_object_section("object_metadata");
5733 formatter
->dump_string("name", object
);
5734 formatter
->dump_unsigned("size", obj_size
);
5736 map
<string
, bufferlist
>::iterator iter
;
5737 map
<string
, bufferlist
> other_attrs
;
5738 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5739 bufferlist
& bl
= iter
->second
;
5740 bool handled
= false;
5741 if (iter
->first
== RGW_ATTR_MANIFEST
) {
5742 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
5743 } else if (iter
->first
== RGW_ATTR_ACL
) {
5744 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
5745 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
5746 handled
= dump_string("tag", bl
, formatter
);
5747 } else if (iter
->first
== RGW_ATTR_ETAG
) {
5748 handled
= dump_string("etag", bl
, formatter
);
5752 other_attrs
[iter
->first
] = bl
;
5755 formatter
->open_object_section("attrs");
5756 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
5757 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
5759 formatter
->close_section();
5760 formatter
->close_section();
5761 formatter
->flush(cout
);
5764 if (opt_cmd
== OPT_BUCKET_CHECK
) {
5765 if (check_head_obj_locator
) {
5766 if (bucket_name
.empty()) {
5767 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
5770 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
5772 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
5776 if (opt_cmd
== OPT_BUCKET_RM
) {
5777 if (inconsistent_index
== false) {
5778 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
5780 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
5784 if (opt_cmd
== OPT_GC_LIST
) {
5787 formatter
->open_array_section("entries");
5790 list
<cls_rgw_gc_obj_info
> result
;
5791 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
5793 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5798 list
<cls_rgw_gc_obj_info
>::iterator iter
;
5799 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5800 cls_rgw_gc_obj_info
& info
= *iter
;
5801 formatter
->open_object_section("chain_info");
5802 formatter
->dump_string("tag", info
.tag
);
5803 formatter
->dump_stream("time") << info
.time
;
5804 formatter
->open_array_section("objs");
5805 list
<cls_rgw_obj
>::iterator liter
;
5806 cls_rgw_obj_chain
& chain
= info
.chain
;
5807 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
5808 cls_rgw_obj
& obj
= *liter
;
5809 encode_json("obj", obj
, formatter
);
5811 formatter
->close_section(); // objs
5812 formatter
->close_section(); // obj_chain
5813 formatter
->flush(cout
);
5815 } while (truncated
);
5816 formatter
->close_section();
5817 formatter
->flush(cout
);
5820 if (opt_cmd
== OPT_GC_PROCESS
) {
5821 int ret
= store
->process_gc();
5823 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5828 if (opt_cmd
== OPT_LC_LIST
) {
5829 formatter
->open_array_section("lifecycle_list");
5830 map
<string
, int> bucket_lc_map
;
5832 #define MAX_LC_LIST_ENTRIES 100
5833 if (max_entries
< 0) {
5834 max_entries
= MAX_LC_LIST_ENTRIES
;
5837 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
5839 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5842 map
<string
, int>::iterator iter
;
5843 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
5844 formatter
->open_object_section("bucket_lc_info");
5845 formatter
->dump_string("bucket", iter
->first
);
5846 string lc_status
= LC_STATUS
[iter
->second
];
5847 formatter
->dump_string("status", lc_status
);
5848 formatter
->close_section(); // objs
5849 formatter
->flush(cout
);
5850 marker
= iter
->first
;
5852 } while (!bucket_lc_map
.empty());
5854 formatter
->close_section(); //lifecycle list
5855 formatter
->flush(cout
);
5859 if (opt_cmd
== OPT_LC_PROCESS
) {
5860 int ret
= store
->process_lc();
5862 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5867 if (opt_cmd
== OPT_ORPHANS_FIND
) {
5868 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5870 if (job_id
.empty()) {
5871 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5874 if (pool_name
.empty()) {
5875 cerr
<< "ERROR: --pool not specified" << std::endl
;
5879 RGWOrphanSearchInfo info
;
5882 info
.job_name
= job_id
;
5883 info
.num_shards
= num_shards
;
5885 int ret
= search
.init(job_id
, &info
);
5887 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
5896 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
5897 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5899 if (job_id
.empty()) {
5900 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5903 int ret
= search
.init(job_id
, NULL
);
5905 if (ret
== -ENOENT
) {
5906 cerr
<< "job not found" << std::endl
;
5910 ret
= search
.finish();
5916 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
5917 RGWOrphanStore
orphan_store(store
);
5918 int ret
= orphan_store
.init();
5920 cerr
<< "connection to cluster failed!" << std::endl
;
5924 map
<string
,RGWOrphanSearchState
> m
;
5925 ret
= orphan_store
.list_jobs(m
);
5927 cerr
<< "job list failed" << std::endl
;
5930 formatter
->open_array_section("entries");
5931 for (const auto &it
: m
){
5933 formatter
->dump_string("job-id",it
.first
);
5935 encode_json("orphan_search_state", it
.second
, formatter
);
5938 formatter
->close_section();
5939 formatter
->flush(cout
);
5942 if (opt_cmd
== OPT_USER_CHECK
) {
5943 check_bad_user_bucket_mapping(store
, user_id
, fix
);
5946 if (opt_cmd
== OPT_USER_STATS
) {
5948 if (!bucket_name
.empty()) {
5949 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
5951 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
5955 int ret
= rgw_user_sync_all_stats(store
, user_id
);
5957 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
5963 if (user_id
.empty()) {
5964 cerr
<< "ERROR: uid not specified" << std::endl
;
5967 cls_user_header header
;
5968 string user_str
= user_id
.to_str();
5969 int ret
= store
->cls_user_get_header(user_str
, &header
);
5971 if (ret
== -ENOENT
) { /* in case of ENOENT */
5972 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
5974 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
5979 encode_json("header", header
, formatter
);
5980 formatter
->flush(cout
);
5983 if (opt_cmd
== OPT_METADATA_GET
) {
5984 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
5986 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
5990 formatter
->flush(cout
);
5993 if (opt_cmd
== OPT_METADATA_PUT
) {
5995 int ret
= read_input(infile
, bl
);
5997 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6000 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6002 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6007 if (opt_cmd
== OPT_METADATA_RM
) {
6008 int ret
= store
->meta_mgr
->remove(metadata_key
);
6010 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6015 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6016 if (opt_cmd
== OPT_USER_LIST
) {
6017 metadata_key
= "user";
6021 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
6023 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6029 formatter
->open_array_section("keys");
6033 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, keys
, &truncated
);
6034 if (ret
< 0 && ret
!= -ENOENT
) {
6035 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6037 } if (ret
!= -ENOENT
) {
6038 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6039 formatter
->dump_string("key", *iter
);
6041 formatter
->flush(cout
);
6043 } while (truncated
);
6045 formatter
->close_section();
6046 formatter
->flush(cout
);
6048 store
->meta_mgr
->list_keys_complete(handle
);
6051 if (opt_cmd
== OPT_MDLOG_LIST
) {
6052 utime_t start_time
, end_time
;
6054 int ret
= parse_date_str(start_date
, start_time
);
6058 ret
= parse_date_str(end_date
, end_time
);
6062 int i
= (specified_shard_id
? shard_id
: 0);
6064 if (period_id
.empty()) {
6065 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6069 std::cerr
<< "No --period given, using current period="
6070 << period_id
<< std::endl
;
6072 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6074 formatter
->open_array_section("entries");
6075 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6077 list
<cls_log_entry
> entries
;
6080 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6083 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6085 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6089 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6090 cls_log_entry
& entry
= *iter
;
6091 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6093 formatter
->flush(cout
);
6094 } while (truncated
);
6096 meta_log
->complete_list_entries(handle
);
6098 if (specified_shard_id
)
6103 formatter
->close_section();
6104 formatter
->flush(cout
);
6107 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6108 int i
= (specified_shard_id
? shard_id
: 0);
6110 if (period_id
.empty()) {
6111 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6115 std::cerr
<< "No --period given, using current period="
6116 << period_id
<< std::endl
;
6118 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6120 formatter
->open_array_section("entries");
6122 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6123 RGWMetadataLogInfo info
;
6124 meta_log
->get_info(i
, &info
);
6126 ::encode_json("info", info
, formatter
);
6128 if (specified_shard_id
)
6133 formatter
->close_section();
6134 formatter
->flush(cout
);
6137 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6138 // need a full history for purging old mdlog periods
6139 store
->meta_mgr
->init_oldest_log_period();
6141 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6142 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6143 int ret
= http
.set_threaded();
6145 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6149 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6150 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6152 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6157 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6158 utime_t start_time
, end_time
;
6160 if (!specified_shard_id
) {
6161 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6165 int ret
= parse_date_str(start_date
, start_time
);
6169 ret
= parse_date_str(end_date
, end_time
);
6173 if (period_id
.empty()) {
6174 std::cerr
<< "missing --period argument" << std::endl
;
6177 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6179 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6181 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6186 if (opt_cmd
== OPT_SYNC_STATUS
) {
6187 sync_status(formatter
);
6190 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6191 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6193 int ret
= sync
.init();
6195 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6199 rgw_meta_sync_status sync_status
;
6200 ret
= sync
.read_sync_status(&sync_status
);
6202 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6206 formatter
->open_object_section("summary");
6207 encode_json("sync_status", sync_status
, formatter
);
6209 uint64_t full_total
= 0;
6210 uint64_t full_complete
= 0;
6212 for (auto marker_iter
: sync_status
.sync_markers
) {
6213 full_total
+= marker_iter
.second
.total_entries
;
6214 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6215 full_complete
+= marker_iter
.second
.pos
;
6217 full_complete
+= marker_iter
.second
.total_entries
;
6221 formatter
->open_object_section("full_sync");
6222 encode_json("total", full_total
, formatter
);
6223 encode_json("complete", full_complete
, formatter
);
6224 formatter
->close_section();
6225 formatter
->close_section();
6227 formatter
->flush(cout
);
6231 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6232 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6234 int ret
= sync
.init();
6236 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6239 ret
= sync
.init_sync_status();
6241 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6247 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6248 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6250 int ret
= sync
.init();
6252 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6258 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6263 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6264 if (source_zone
.empty()) {
6265 cerr
<< "ERROR: source zone not specified" << std::endl
;
6268 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6270 int ret
= sync
.init();
6272 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6276 rgw_data_sync_status sync_status
;
6277 ret
= sync
.read_sync_status(&sync_status
);
6278 if (ret
< 0 && ret
!= -ENOENT
) {
6279 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6283 formatter
->open_object_section("summary");
6284 encode_json("sync_status", sync_status
, formatter
);
6286 uint64_t full_total
= 0;
6287 uint64_t full_complete
= 0;
6289 for (auto marker_iter
: sync_status
.sync_markers
) {
6290 full_total
+= marker_iter
.second
.total_entries
;
6291 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6292 full_complete
+= marker_iter
.second
.pos
;
6294 full_complete
+= marker_iter
.second
.total_entries
;
6298 formatter
->open_object_section("full_sync");
6299 encode_json("total", full_total
, formatter
);
6300 encode_json("complete", full_complete
, formatter
);
6301 formatter
->close_section();
6302 formatter
->close_section();
6304 formatter
->flush(cout
);
6307 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6308 if (source_zone
.empty()) {
6309 cerr
<< "ERROR: source zone not specified" << std::endl
;
6312 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6314 int ret
= sync
.init();
6316 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6320 ret
= sync
.init_sync_status();
6322 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6327 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6328 if (source_zone
.empty()) {
6329 cerr
<< "ERROR: source zone not specified" << std::endl
;
6332 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6334 int ret
= sync
.init();
6336 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6342 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6347 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6348 if (source_zone
.empty()) {
6349 cerr
<< "ERROR: source zone not specified" << std::endl
;
6352 if (bucket_name
.empty()) {
6353 cerr
<< "ERROR: bucket not specified" << std::endl
;
6357 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6361 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6365 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6368 ret
= sync
.init_sync_status();
6370 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6375 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6376 if (source_zone
.empty()) {
6377 cerr
<< "ERROR: source zone not specified" << std::endl
;
6380 if (bucket_name
.empty()) {
6381 cerr
<< "ERROR: bucket not specified" << std::endl
;
6385 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6389 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6393 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6396 ret
= sync
.read_sync_status();
6398 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6402 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6404 encode_json("sync_status", sync_status
, formatter
);
6405 formatter
->flush(cout
);
6408 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6409 if (source_zone
.empty()) {
6410 cerr
<< "ERROR: source zone not specified" << std::endl
;
6413 if (bucket_name
.empty()) {
6414 cerr
<< "ERROR: bucket not specified" << std::endl
;
6418 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6422 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6426 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6432 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6437 if (opt_cmd
== OPT_BILOG_LIST
) {
6438 if (bucket_name
.empty()) {
6439 cerr
<< "ERROR: bucket not specified" << std::endl
;
6442 RGWBucketInfo bucket_info
;
6443 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6445 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6448 formatter
->open_array_section("entries");
6451 if (max_entries
< 0)
6455 list
<rgw_bi_log_entry
> entries
;
6456 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6458 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6462 count
+= entries
.size();
6464 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6465 rgw_bi_log_entry
& entry
= *iter
;
6466 encode_json("entry", entry
, formatter
);
6470 formatter
->flush(cout
);
6471 } while (truncated
&& count
< max_entries
);
6473 formatter
->close_section();
6474 formatter
->flush(cout
);
6477 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6478 if (max_entries
< 0) {
6483 utime_t start_time
, end_time
;
6485 int ret
= parse_date_str(start_date
, start_time
);
6489 ret
= parse_date_str(end_date
, end_time
);
6497 formatter
->open_array_section("entries");
6499 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6500 formatter
->open_object_section("shard");
6501 encode_json("shard_id", shard_id
, formatter
);
6502 formatter
->open_array_section("entries");
6505 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6508 list
<cls_log_entry
> entries
;
6509 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6510 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6511 if (ret
== -ENOENT
) {
6515 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6519 count
+= entries
.size();
6521 for (auto& cls_entry
: entries
) {
6522 rgw_sync_error_info log_entry
;
6524 auto iter
= cls_entry
.data
.begin();
6526 ::decode(log_entry
, iter
);
6527 } catch (buffer::error
& err
) {
6528 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6531 formatter
->open_object_section("entry");
6532 encode_json("id", cls_entry
.id
, formatter
);
6533 encode_json("section", cls_entry
.section
, formatter
);
6534 encode_json("name", cls_entry
.name
, formatter
);
6535 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
6536 encode_json("info", log_entry
, formatter
);
6537 formatter
->close_section();
6538 formatter
->flush(cout
);
6540 } while (truncated
&& count
< max_entries
);
6542 formatter
->close_section();
6543 formatter
->close_section();
6545 if (specified_shard_id
) {
6550 formatter
->close_section();
6551 formatter
->flush(cout
);
6554 if (opt_cmd
== OPT_BILOG_TRIM
) {
6555 if (bucket_name
.empty()) {
6556 cerr
<< "ERROR: bucket not specified" << std::endl
;
6559 RGWBucketInfo bucket_info
;
6560 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6562 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6565 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
6567 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6572 if (opt_cmd
== OPT_BILOG_STATUS
) {
6573 if (bucket_name
.empty()) {
6574 cerr
<< "ERROR: bucket not specified" << std::endl
;
6577 RGWBucketInfo bucket_info
;
6578 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6580 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6583 map
<int, string
> markers
;
6584 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
6586 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
6589 formatter
->open_object_section("entries");
6590 encode_json("markers", markers
, formatter
);
6591 formatter
->close_section();
6592 formatter
->flush(cout
);
6595 if (opt_cmd
== OPT_DATALOG_LIST
) {
6596 formatter
->open_array_section("entries");
6599 if (max_entries
< 0)
6602 utime_t start_time
, end_time
;
6604 int ret
= parse_date_str(start_date
, start_time
);
6608 ret
= parse_date_str(end_date
, end_time
);
6612 RGWDataChangesLog
*log
= store
->data_log
;
6613 RGWDataChangesLog::LogMarker marker
;
6616 list
<rgw_data_change_log_entry
> entries
;
6617 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
6619 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6623 count
+= entries
.size();
6625 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6626 rgw_data_change_log_entry
& entry
= *iter
;
6628 encode_json("entry", entry
.entry
, formatter
);
6630 encode_json("entry", entry
, formatter
);
6633 formatter
->flush(cout
);
6634 } while (truncated
&& count
< max_entries
);
6636 formatter
->close_section();
6637 formatter
->flush(cout
);
6640 if (opt_cmd
== OPT_DATALOG_STATUS
) {
6641 RGWDataChangesLog
*log
= store
->data_log
;
6642 int i
= (specified_shard_id
? shard_id
: 0);
6644 formatter
->open_array_section("entries");
6645 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
6646 list
<cls_log_entry
> entries
;
6648 RGWDataChangesLogInfo info
;
6649 log
->get_info(i
, &info
);
6651 ::encode_json("info", info
, formatter
);
6653 if (specified_shard_id
)
6657 formatter
->close_section();
6658 formatter
->flush(cout
);
6661 if (opt_cmd
== OPT_DATALOG_TRIM
) {
6662 utime_t start_time
, end_time
;
6664 int ret
= parse_date_str(start_date
, start_time
);
6668 ret
= parse_date_str(end_date
, end_time
);
6672 RGWDataChangesLog
*log
= store
->data_log
;
6673 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6675 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
6680 if (opt_cmd
== OPT_OPSTATE_LIST
) {
6681 RGWOpState
oc(store
);
6686 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
6687 list
<cls_statelog_entry
> entries
;
6689 formatter
->open_array_section("entries");
6691 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
6693 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
6694 oc
.finish_list_entries(handle
);
6698 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6699 oc
.dump_entry(*iter
, formatter
);
6702 formatter
->flush(cout
);
6704 formatter
->close_section();
6705 formatter
->flush(cout
);
6706 oc
.finish_list_entries(handle
);
6709 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
6710 RGWOpState
oc(store
);
6712 RGWOpState::OpState state
;
6713 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6714 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6717 if (state_str
.empty()) {
6718 cerr
<< "ERROR: state was not specified" << std::endl
;
6721 int ret
= oc
.state_from_str(state_str
, &state
);
6723 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
6727 if (opt_cmd
== OPT_OPSTATE_SET
) {
6728 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
6730 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6734 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
6736 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
6741 if (opt_cmd
== OPT_OPSTATE_RM
) {
6742 RGWOpState
oc(store
);
6744 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6745 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6748 ret
= oc
.remove_entry(client_id
, op_id
, object
);
6750 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6755 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
6756 opt_cmd
== OPT_REPLICALOG_DELETE
) {
6757 if (replica_log_type_str
.empty()) {
6758 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
6763 if (opt_cmd
== OPT_REPLICALOG_GET
) {
6764 RGWReplicaBounds bounds
;
6765 if (replica_log_type
== ReplicaLog_Metadata
) {
6766 if (!specified_shard_id
) {
6767 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6771 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6772 int ret
= logger
.get_bounds(shard_id
, bounds
);
6775 } else if (replica_log_type
== ReplicaLog_Data
) {
6776 if (!specified_shard_id
) {
6777 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6780 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6781 int ret
= logger
.get_bounds(shard_id
, bounds
);
6784 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6785 if (bucket_name
.empty()) {
6786 cerr
<< "ERROR: bucket not specified" << std::endl
;
6789 RGWBucketInfo bucket_info
;
6790 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6792 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6796 RGWReplicaBucketLogger
logger(store
);
6797 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
6800 } else { // shouldn't get here
6803 encode_json("bounds", bounds
, formatter
);
6804 formatter
->flush(cout
);
6808 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
6809 if (replica_log_type
== ReplicaLog_Metadata
) {
6810 if (!specified_shard_id
) {
6811 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6814 if (!specified_daemon_id
) {
6815 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6818 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6819 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6822 } else if (replica_log_type
== ReplicaLog_Data
) {
6823 if (!specified_shard_id
) {
6824 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6827 if (!specified_daemon_id
) {
6828 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6831 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6832 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6835 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6836 if (bucket_name
.empty()) {
6837 cerr
<< "ERROR: bucket not specified" << std::endl
;
6840 RGWBucketInfo bucket_info
;
6841 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6843 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6847 RGWReplicaBucketLogger
logger(store
);
6848 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
6854 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
6855 if (marker
.empty()) {
6856 cerr
<< "ERROR: marker was not specified" <<std::endl
;
6859 utime_t time
= ceph_clock_now();
6860 if (!date
.empty()) {
6861 ret
= parse_date_str(date
, time
);
6863 cerr
<< "ERROR: failed to parse start date" << std::endl
;
6867 list
<RGWReplicaItemMarker
> entries
;
6868 int ret
= read_decode_json(infile
, entries
);
6870 cerr
<< "ERROR: failed to decode entries" << std::endl
;
6873 RGWReplicaBounds bounds
;
6874 if (replica_log_type
== ReplicaLog_Metadata
) {
6875 if (!specified_shard_id
) {
6876 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6880 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6881 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6883 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6886 } else if (replica_log_type
== ReplicaLog_Data
) {
6887 if (!specified_shard_id
) {
6888 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6891 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6892 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6894 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6897 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6898 if (bucket_name
.empty()) {
6899 cerr
<< "ERROR: bucket not specified" << std::endl
;
6902 RGWBucketInfo bucket_info
;
6903 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6905 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6909 RGWReplicaBucketLogger
logger(store
);
6910 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
6912 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6918 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
6921 if (bucket_name
.empty() && user_id
.empty()) {
6922 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
6926 if (!bucket_name
.empty()) {
6927 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
6928 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
6931 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
6932 max_size
, max_objects
, have_max_size
, have_max_objects
);
6933 } else if (!user_id
.empty()) {
6934 if (quota_scope
== "bucket") {
6935 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
6936 } else if (quota_scope
== "user") {
6937 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
6939 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;