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 // we expect a very small response
1533 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1535 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1536 bufferlist
& in_data
, JSONParser
& parser
)
1542 ceph::bufferlist response
;
1544 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1546 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1547 if (parse_ret
< 0) {
1548 cerr
<< "failed to parse response" << std::endl
;
1554 static int send_to_url(const string
& url
, const string
& access
,
1555 const string
& secret
, req_info
& info
,
1556 bufferlist
& in_data
, JSONParser
& parser
)
1558 if (access
.empty() || secret
.empty()) {
1559 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1567 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1569 bufferlist response
;
1570 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1572 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1573 if (parse_ret
< 0) {
1574 cout
<< "failed to parse response" << std::endl
;
1580 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1581 const string
& access
, const string
& secret
,
1582 req_info
& info
, bufferlist
& in_data
,
1586 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1588 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1591 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1592 string remote
, const string
& url
,
1593 const string
& access
, const string
& secret
,
1596 const string
& master_zone
= period
.get_master_zone();
1597 if (master_zone
.empty()) {
1598 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1601 // are we the period's master zone?
1602 if (store
->get_zone_params().get_id() == master_zone
) {
1603 // read the current period
1604 RGWPeriod current_period
;
1605 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1607 cerr
<< "Error initializing current period: "
1608 << cpp_strerror(-ret
) << std::endl
;
1611 // the master zone can commit locally
1612 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1614 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1619 if (remote
.empty() && url
.empty()) {
1620 // use the new master zone's connection
1621 remote
= master_zone
;
1622 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1624 boost::optional
<RGWRESTConn
> conn
;
1625 RGWRESTConn
*remote_conn
= nullptr;
1626 if (!remote
.empty()) {
1627 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1629 cerr
<< "failed to find a zone or zonegroup for remote "
1630 << remote
<< std::endl
;
1633 remote_conn
= &*conn
;
1636 // push period to the master with an empty period id
1640 req_info
info(g_ceph_context
, &env
);
1641 info
.method
= "POST";
1642 info
.request_uri
= "/admin/realm/period";
1644 // json format into a bufferlist
1645 JSONFormatter
jf(false);
1646 encode_json("period", period
, &jf
);
1651 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1653 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1655 // did we parse an error message?
1656 auto message
= p
.find_obj("Message");
1658 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1663 // decode the response and store it back
1665 decode_json_obj(period
, &p
);
1666 } catch (JSONDecoder::err
& e
) {
1667 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1670 if (period
.get_id().empty()) {
1671 cerr
<< "Period commit got back an empty period id" << std::endl
;
1674 // the master zone gave us back the period that it committed, so it's
1675 // safe to save it as our latest epoch
1676 ret
= period
.store_info(false);
1678 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1679 << cpp_strerror(ret
) << std::endl
;
1682 ret
= period
.set_latest_epoch(period
.get_epoch());
1684 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1687 ret
= period
.reflect();
1689 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1692 realm
.notify_new_period(period
);
1696 static int update_period(const string
& realm_id
, const string
& realm_name
,
1697 const string
& period_id
, const string
& period_epoch
,
1698 bool commit
, const string
& remote
, const string
& url
,
1699 const string
& access
, const string
& secret
,
1700 Formatter
*formatter
, bool force
)
1702 RGWRealm
realm(realm_id
, realm_name
);
1703 int ret
= realm
.init(g_ceph_context
, store
);
1705 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1709 if (!period_epoch
.empty()) {
1710 epoch
= atoi(period_epoch
.c_str());
1712 RGWPeriod
period(period_id
, epoch
);
1713 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1715 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1719 ret
= period
.update();
1721 // Dropping the error message here, as both the ret codes were handled in
1725 ret
= period
.store_info(false);
1727 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1731 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1733 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1737 encode_json("period", period
, formatter
);
1738 formatter
->flush(cout
);
1743 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1744 const string
& bucket_id
, rgw_bucket
& bucket
)
1746 RGWBucketInfo bucket_info
;
1748 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1750 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1757 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1758 const string
& access_key
, const string
& secret_key
,
1759 const string
& realm_id
, const string
& realm_name
,
1760 const string
& period_id
, const string
& period_epoch
,
1764 req_info
info(g_ceph_context
, &env
);
1765 info
.method
= "GET";
1766 info
.request_uri
= "/admin/realm/period";
1768 map
<string
, string
> ¶ms
= info
.args
.get_params();
1769 if (!realm_id
.empty())
1770 params
["realm_id"] = realm_id
;
1771 if (!realm_name
.empty())
1772 params
["realm_name"] = realm_name
;
1773 if (!period_id
.empty())
1774 params
["period_id"] = period_id
;
1775 if (!period_epoch
.empty())
1776 params
["epoch"] = period_epoch
;
1780 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1783 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1786 ret
= period
->init(g_ceph_context
, store
, false);
1788 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1792 decode_json_obj(*period
, &p
);
1793 } catch (JSONDecoder::err
& e
) {
1794 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1797 ret
= period
->store_info(false);
1799 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1801 // store latest epoch (ignore errors)
1802 period
->update_latest_epoch(period
->get_epoch());
1806 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1807 const std::string
& realm_name
,
1808 std::string
* period_id
)
1810 RGWRealm
realm(realm_id
, realm_name
);
1811 int ret
= realm
.init(g_ceph_context
, store
);
1813 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1816 *period_id
= realm
.get_current_period();
1820 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1822 if (!ss
.str().empty()) {
1823 l
.push_back(ss
.str());
1828 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1832 ss
<< setw(tab
) << "" << setw(1);
1837 static void get_md_sync_status(list
<string
>& status
)
1839 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1841 int ret
= sync
.init();
1843 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1847 rgw_meta_sync_status sync_status
;
1848 ret
= sync
.read_sync_status(&sync_status
);
1850 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1855 switch (sync_status
.sync_info
.state
) {
1856 case rgw_meta_sync_info::StateInit
:
1857 status_str
= "init";
1859 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1860 status_str
= "preparing for full sync";
1862 case rgw_meta_sync_info::StateSync
:
1863 status_str
= "syncing";
1866 status_str
= "unknown";
1869 status
.push_back(status_str
);
1871 uint64_t full_total
= 0;
1872 uint64_t full_complete
= 0;
1876 int total_shards
= 0;
1878 for (auto marker_iter
: sync_status
.sync_markers
) {
1879 full_total
+= marker_iter
.second
.total_entries
;
1881 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1883 full_complete
+= marker_iter
.second
.pos
;
1885 full_complete
+= marker_iter
.second
.total_entries
;
1887 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1893 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1896 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1899 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1901 rgw_mdlog_info log_info
;
1902 ret
= sync
.read_log_info(&log_info
);
1904 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1908 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1909 string master_period
= store
->get_current_period_id();
1911 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1913 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1917 map
<int, string
> shards_behind
;
1918 if (sync_status
.sync_info
.period
!= master_period
) {
1919 status
.push_back(string("master is on a different period: master_period=" +
1920 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1922 for (auto local_iter
: sync_status
.sync_markers
) {
1923 int shard_id
= local_iter
.first
;
1924 auto iter
= master_shards_info
.find(shard_id
);
1926 if (iter
== master_shards_info
.end()) {
1928 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
1931 auto master_marker
= iter
->second
.marker
;
1932 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
1933 master_marker
> local_iter
.second
.marker
) {
1934 shards_behind
[shard_id
] = local_iter
.second
.marker
;
1939 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
1940 if (total_behind
== 0) {
1941 push_ss(ss
, status
) << "metadata is caught up with master";
1943 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
1945 map
<int, rgw_mdlog_shard_data
> master_pos
;
1946 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
1948 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
1950 ceph::real_time oldest
;
1951 for (auto iter
: master_pos
) {
1952 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
1954 if (!shard_data
.entries
.empty()) {
1955 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
1956 if (ceph::real_clock::is_zero(oldest
)) {
1957 oldest
= entry
.timestamp
;
1958 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
1959 oldest
= entry
.timestamp
;
1964 if (!ceph::real_clock::is_zero(oldest
)) {
1965 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
1970 flush_ss(ss
, status
);
1973 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
1977 auto ziter
= store
->zone_by_id
.find(source_zone
);
1978 if (ziter
== store
->zone_by_id
.end()) {
1979 push_ss(ss
, status
, tab
) << string("zone not found");
1980 flush_ss(ss
, status
);
1983 RGWZone
& sz
= ziter
->second
;
1985 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
1986 push_ss(ss
, status
, tab
) << string("not syncing from zone");
1987 flush_ss(ss
, status
);
1990 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
1992 int ret
= sync
.init();
1994 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
1995 flush_ss(ss
, status
);
1999 rgw_data_sync_status sync_status
;
2000 ret
= sync
.read_sync_status(&sync_status
);
2001 if (ret
< 0 && ret
!= -ENOENT
) {
2002 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2007 switch (sync_status
.sync_info
.state
) {
2008 case rgw_data_sync_info::StateInit
:
2009 status_str
= "init";
2011 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2012 status_str
= "preparing for full sync";
2014 case rgw_data_sync_info::StateSync
:
2015 status_str
= "syncing";
2018 status_str
= "unknown";
2021 push_ss(ss
, status
, tab
) << status_str
;
2023 uint64_t full_total
= 0;
2024 uint64_t full_complete
= 0;
2028 int total_shards
= 0;
2030 for (auto marker_iter
: sync_status
.sync_markers
) {
2031 full_total
+= marker_iter
.second
.total_entries
;
2033 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2035 full_complete
+= marker_iter
.second
.pos
;
2037 full_complete
+= marker_iter
.second
.total_entries
;
2039 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2044 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2047 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2050 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2052 rgw_datalog_info log_info
;
2053 ret
= sync
.read_log_info(&log_info
);
2055 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2060 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2062 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2064 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2068 map
<int, string
> shards_behind
;
2070 for (auto local_iter
: sync_status
.sync_markers
) {
2071 int shard_id
= local_iter
.first
;
2072 auto iter
= source_shards_info
.find(shard_id
);
2074 if (iter
== source_shards_info
.end()) {
2076 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2079 auto master_marker
= iter
->second
.marker
;
2080 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2081 master_marker
> local_iter
.second
.marker
) {
2082 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2086 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2087 if (total_behind
== 0) {
2088 push_ss(ss
, status
, tab
) << "data is caught up with source";
2090 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2092 map
<int, rgw_datalog_shard_data
> master_pos
;
2093 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2095 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2097 ceph::real_time oldest
;
2098 for (auto iter
: master_pos
) {
2099 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2101 if (!shard_data
.entries
.empty()) {
2102 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2103 if (ceph::real_clock::is_zero(oldest
)) {
2104 oldest
= entry
.timestamp
;
2105 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2106 oldest
= entry
.timestamp
;
2111 if (!ceph::real_clock::is_zero(oldest
)) {
2112 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2117 flush_ss(ss
, status
);
2120 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2124 for (auto e
: entries
) {
2125 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2131 static void sync_status(Formatter
*formatter
)
2133 RGWRealm
& realm
= store
->realm
;
2134 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2135 RGWZone
& zone
= store
->get_zone();
2139 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2140 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2141 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2143 list
<string
> md_status
;
2145 if (store
->is_meta_master()) {
2146 md_status
.push_back("no sync (zone is master)");
2148 get_md_sync_status(md_status
);
2151 tab_dump("metadata sync", width
, md_status
);
2153 list
<string
> data_status
;
2155 for (auto iter
: store
->zone_conn_map
) {
2156 const string
& source_id
= iter
.first
;
2158 string source_str
= "source: ";
2159 string s
= source_str
+ source_id
;
2160 auto siter
= store
->zone_by_id
.find(source_id
);
2161 if (siter
!= store
->zone_by_id
.end()) {
2162 s
+= string(" (") + siter
->second
.name
+ ")";
2164 data_status
.push_back(s
);
2165 get_data_sync_status(source_id
, data_status
, source_str
.size());
2168 tab_dump("data sync", width
, data_status
);
2171 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2174 get_str_list(s
, ",", confs
);
2175 for (auto c
: confs
) {
2176 ssize_t pos
= c
.find("=");
2180 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2185 int check_reshard_bucket_params(RGWRados
*store
,
2186 const string
& bucket_name
,
2187 const string
& tenant
,
2188 const string
& bucket_id
,
2189 bool num_shards_specified
,
2191 int yes_i_really_mean_it
,
2193 RGWBucketInfo
& bucket_info
,
2194 map
<string
, bufferlist
>& attrs
)
2196 if (bucket_name
.empty()) {
2197 cerr
<< "ERROR: bucket not specified" << std::endl
;
2201 if (!num_shards_specified
) {
2202 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2206 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2207 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2211 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2213 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2217 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2219 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2220 cerr
<< "num shards is less or equal to current shards count" << std::endl
2221 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2227 int create_new_bucket_instance(RGWRados
*store
,
2229 const RGWBucketInfo
& bucket_info
,
2230 map
<string
, bufferlist
>& attrs
,
2231 RGWBucketInfo
& new_bucket_info
)
2234 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2235 new_bucket_info
.bucket
.oid
.clear();
2237 new_bucket_info
.num_shards
= new_num_shards
;
2238 new_bucket_info
.objv_tracker
.clear();
2240 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2242 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2246 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2248 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2256 #ifdef BUILDING_FOR_EMBEDDED
2257 extern "C" int cephd_rgw_admin(int argc
, const char **argv
)
2259 int main(int argc
, const char **argv
)
2262 vector
<const char*> args
;
2263 argv_to_vec(argc
, (const char **)argv
, args
);
2266 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2267 CODE_ENVIRONMENT_UTILITY
, 0);
2269 // for region -> zonegroup conversion (must happen before common_init_finish())
2270 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2271 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2274 common_init_finish(g_ceph_context
);
2278 std::string access_key
, secret_key
, user_email
, display_name
;
2279 std::string bucket_name
, pool_name
, object
;
2281 std::string date
, subuser
, access
, format
;
2282 std::string start_date
, end_date
;
2283 std::string key_type_str
;
2284 std::string period_id
, period_epoch
, remote
, url
;
2285 std::string master_zonegroup
, master_zone
;
2286 std::string realm_name
, realm_id
, realm_new_name
;
2287 std::string zone_name
, zone_id
, zone_new_name
;
2288 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2289 std::string api_name
;
2290 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2291 list
<string
> endpoints
;
2293 int sync_from_all_specified
= false;
2294 bool sync_from_all
= false;
2295 list
<string
> sync_from
;
2296 list
<string
> sync_from_rm
;
2297 std::string master_url
;
2299 int set_default
= 0;
2300 bool is_master
= false;
2301 bool is_master_set
= false;
2303 bool read_only
= false;
2304 int is_read_only_set
= false;
2306 int staging
= false;
2307 int key_type
= KEY_TYPE_UNDEFINED
;
2309 uint32_t perm_mask
= 0;
2311 int opt_cmd
= OPT_NO_CMD
;
2313 int gen_access_key
= 0;
2314 int gen_secret_key
= 0;
2315 bool set_perm
= false;
2316 bool set_temp_url_key
= false;
2317 map
<int, string
> temp_url_keys
;
2319 Formatter
*formatter
= NULL
;
2320 int purge_data
= false;
2321 int pretty_format
= false;
2322 int show_log_entries
= true;
2323 int show_log_sum
= true;
2324 int skip_zero_entries
= false; // log show
2325 int purge_keys
= false;
2326 int yes_i_really_mean_it
= false;
2327 int delete_child_objects
= false;
2329 int remove_bad
= false;
2330 int check_head_obj_locator
= false;
2331 int max_buckets
= -1;
2332 bool max_buckets_specified
= false;
2333 map
<string
, bool> categories
;
2335 int check_objects
= false;
2336 RGWUserAdminOpState user_op
;
2337 RGWBucketAdminOpState bucket_op
;
2339 string metadata_key
;
2340 RGWObjVersionTracker objv_tracker
;
2342 string start_marker
;
2344 int max_entries
= -1;
2346 bool admin_specified
= false;
2348 bool system_specified
= false;
2350 bool specified_shard_id
= false;
2352 bool specified_daemon_id
= false;
2356 string replica_log_type_str
;
2357 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2360 string object_version
;
2361 string placement_id
;
2363 list
<string
> tags_add
;
2364 list
<string
> tags_rm
;
2366 int64_t max_objects
= -1;
2367 int64_t max_size
= -1;
2368 bool have_max_objects
= false;
2369 bool have_max_size
= false;
2370 int include_all
= false;
2372 int sync_stats
= false;
2373 int bypass_gc
= false;
2374 int warnings_only
= false;
2375 int inconsistent_index
= false;
2377 int verbose
= false;
2379 int extra_info
= false;
2381 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2382 uint64_t max_rewrite_size
= ULLONG_MAX
;
2383 uint64_t min_rewrite_stripe_size
= 0;
2385 BIIndexType bi_index_type
= PlainIdx
;
2389 bool num_shards_specified
= false;
2390 int max_concurrent_ios
= 32;
2391 uint64_t orphan_stale_secs
= (24 * 3600);
2394 std::ostringstream errs
;
2398 string source_zone_name
;
2399 string source_zone
; /* zone id */
2402 bool tier_type_specified
= false;
2404 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2405 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2407 boost::optional
<string
> index_pool
;
2408 boost::optional
<string
> data_pool
;
2409 boost::optional
<string
> data_extra_pool
;
2410 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2411 bool index_type_specified
= false;
2413 boost::optional
<std::string
> compression_type
;
2415 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2416 if (ceph_argparse_double_dash(args
, i
)) {
2418 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2421 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2422 user_id
.from_str(val
);
2423 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2425 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2427 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2429 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2431 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2433 user_op
.user_email_specified
=true;
2434 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2436 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2438 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2440 pool
= rgw_pool(pool_name
);
2441 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2443 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2444 object_version
= val
;
2445 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2447 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2449 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2451 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2453 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2455 if (key_type_str
.compare("swift") == 0) {
2456 key_type
= KEY_TYPE_SWIFT
;
2457 } else if (key_type_str
.compare("s3") == 0) {
2458 key_type
= KEY_TYPE_S3
;
2460 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2463 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2465 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2467 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2469 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2471 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2473 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2475 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2476 admin_specified
= true;
2477 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2478 system_specified
= true;
2479 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2481 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2483 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2485 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2486 if (!errs
.str().empty()) {
2487 cerr
<< errs
.str() << std::endl
;
2490 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2491 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2492 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2493 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2494 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2495 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2496 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2497 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2499 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2502 max_buckets_specified
= true;
2503 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2504 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2506 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2509 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2510 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2512 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2515 have_max_size
= true;
2516 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2517 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2519 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2522 have_max_objects
= true;
2523 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2525 if (end_date
.empty())
2527 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2529 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2531 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2532 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2534 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2537 num_shards_specified
= true;
2538 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2539 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2541 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2544 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2545 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2547 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2550 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2551 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2553 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2556 specified_shard_id
= true;
2557 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2559 specified_daemon_id
= true;
2560 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2562 perm_mask
= rgw_str_to_perm(access
.c_str());
2564 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2565 temp_url_keys
[0] = val
;
2566 set_temp_url_key
= true;
2567 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2568 temp_url_keys
[1] = val
;
2569 set_temp_url_key
= true;
2570 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2572 if (bucket_id
.empty()) {
2573 cerr
<< "bad bucket-id" << std::endl
;
2576 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2578 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2579 string cat_str
= val
;
2580 list
<string
> cat_list
;
2581 list
<string
>::iterator iter
;
2582 get_str_list(cat_str
, cat_list
);
2583 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2584 categories
[*iter
] = true;
2586 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2588 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2590 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2591 delete_child_objects
= purge_data
;
2592 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2594 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2596 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2598 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2600 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2602 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2604 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2606 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2608 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2610 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2612 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2614 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2616 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2618 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2620 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2622 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2624 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2626 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2628 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2630 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2631 replica_log_type_str
= val
;
2632 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2633 if (replica_log_type
== ReplicaLog_Invalid
) {
2634 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2637 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2638 string index_type_str
= val
;
2639 bi_index_type
= get_bi_index_type(index_type_str
);
2640 if (bi_index_type
== InvalidIdx
) {
2641 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2644 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2645 is_master
= (bool)is_master_int
;
2646 is_master_set
= true;
2647 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2649 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2650 read_only
= (bool)read_only_int
;
2651 is_read_only_set
= true;
2652 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2654 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2655 master_zonegroup
= val
;
2656 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2658 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2660 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2662 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2664 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2666 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2668 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2669 realm_new_name
= val
;
2670 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2672 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2673 zonegroup_new_name
= val
;
2674 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2676 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2677 get_str_list(val
, tags
);
2678 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2679 get_str_list(val
, tags_add
);
2680 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2681 get_str_list(val
, tags_rm
);
2682 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2684 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2686 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2687 zone_new_name
= val
;
2688 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2689 get_str_list(val
, endpoints
);
2690 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2691 get_str_list(val
, sync_from
);
2692 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2693 get_str_list(val
, sync_from_rm
);
2694 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2695 sync_from_all
= (bool)tmp_int
;
2696 sync_from_all_specified
= true;
2697 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2698 source_zone_name
= val
;
2699 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2701 tier_type_specified
= true;
2702 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2703 parse_tier_config_param(val
, tier_config_add
);
2704 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2705 parse_tier_config_param(val
, tier_config_rm
);
2706 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2708 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2710 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2711 data_extra_pool
= val
;
2712 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2713 if (val
== "normal") {
2714 placement_index_type
= RGWBIType_Normal
;
2715 } else if (val
== "indexless") {
2716 placement_index_type
= RGWBIType_Indexless
;
2718 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2720 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2724 index_type_specified
= true;
2725 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2726 compression_type
= val
;
2727 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2729 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2731 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2732 assume_role_doc
= val
;
2733 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2735 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2736 perm_policy_doc
= val
;
2737 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2739 } else if (strncmp(*i
, "-", 1) == 0) {
2740 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
2751 const char *prev_cmd
= NULL
;
2752 const char *prev_prev_cmd
= NULL
;
2753 std::vector
<const char*>::iterator i
;
2754 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
2755 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
2757 cerr
<< "unrecognized arg " << *i
<< std::endl
;
2764 prev_prev_cmd
= prev_cmd
;
2768 if (opt_cmd
== OPT_NO_CMD
)
2771 /* some commands may have an optional extra param */
2772 if (i
!= args
.end()) {
2774 case OPT_METADATA_GET
:
2775 case OPT_METADATA_PUT
:
2776 case OPT_METADATA_RM
:
2777 case OPT_METADATA_LIST
:
2785 if (tenant
.empty()) {
2786 tenant
= user_id
.tenant
;
2788 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
2789 && opt_cmd
!= OPT_ROLE_DELETE
2790 && opt_cmd
!= OPT_ROLE_GET
2791 && opt_cmd
!= OPT_ROLE_MODIFY
2792 && opt_cmd
!= OPT_ROLE_LIST
2793 && opt_cmd
!= OPT_ROLE_POLICY_PUT
2794 && opt_cmd
!= OPT_ROLE_POLICY_LIST
2795 && opt_cmd
!= OPT_ROLE_POLICY_GET
2796 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
) {
2797 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
2800 user_id
.tenant
= tenant
;
2802 /* check key parameter conflict */
2803 if ((!access_key
.empty()) && gen_access_key
) {
2804 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
2807 if ((!secret_key
.empty()) && gen_secret_key
) {
2808 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
2813 // default to pretty json
2814 if (format
.empty()) {
2816 pretty_format
= true;
2819 if (format
== "xml")
2820 formatter
= new XMLFormatter(pretty_format
);
2821 else if (format
== "json")
2822 formatter
= new JSONFormatter(pretty_format
);
2824 cerr
<< "unrecognized format: " << format
<< std::endl
;
2828 realm_name
= g_conf
->rgw_realm
;
2829 zone_name
= g_conf
->rgw_zone
;
2830 zonegroup_name
= g_conf
->rgw_zonegroup
;
2832 RGWStreamFlusher
f(formatter
, cout
);
2834 // not a raw op if 'period update' needs to commit to master
2835 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
2836 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
2837 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
2838 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
2839 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
2840 OPT_ZONEGROUP_REMOVE
,
2841 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
2842 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
2843 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
2844 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
2845 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
2846 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
2847 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
2848 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
2850 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
2852 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
2853 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
2854 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
2855 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
2856 OPT_REALM_LIST_PERIODS
,
2857 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
2858 OPT_REALM_RENAME
, OPT_REALM_SET
,
2859 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
2862 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
2865 if (raw_storage_op
) {
2866 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
2868 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false);
2871 cerr
<< "couldn't init storage provider" << std::endl
;
2875 if (!source_zone_name
.empty()) {
2876 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
2877 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
2878 source_zone
= source_zone_name
;
2882 rgw_user_init(store
);
2883 rgw_bucket_init(store
->meta_mgr
);
2885 StoreDestructor
store_destructor(store
);
2887 if (raw_storage_op
) {
2889 case OPT_PERIOD_DELETE
:
2891 if (period_id
.empty()) {
2892 cerr
<< "missing period id" << std::endl
;
2895 RGWPeriod
period(period_id
);
2896 int ret
= period
.init(g_ceph_context
, store
);
2898 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
2901 ret
= period
.delete_obj();
2903 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
2909 case OPT_PERIOD_GET
:
2912 if (!period_epoch
.empty()) {
2913 epoch
= atoi(period_epoch
.c_str());
2916 RGWRealm
realm(realm_id
, realm_name
);
2917 int ret
= realm
.init(g_ceph_context
, store
);
2919 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
2922 realm_id
= realm
.get_id();
2923 realm_name
= realm
.get_name();
2924 period_id
= RGWPeriod::get_staging_id(realm_id
);
2927 RGWPeriod
period(period_id
, epoch
);
2928 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
2930 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
2933 encode_json("period", period
, formatter
);
2934 formatter
->flush(cout
);
2938 case OPT_PERIOD_GET_CURRENT
:
2940 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
2944 formatter
->open_object_section("period_get_current");
2945 encode_json("current_period", period_id
, formatter
);
2946 formatter
->close_section();
2947 formatter
->flush(cout
);
2950 case OPT_PERIOD_LIST
:
2952 list
<string
> periods
;
2953 int ret
= store
->list_periods(periods
);
2955 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
2958 formatter
->open_object_section("periods_list");
2959 encode_json("periods", periods
, formatter
);
2960 formatter
->close_section();
2961 formatter
->flush(cout
);
2965 case OPT_PERIOD_UPDATE
:
2967 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
2968 commit
, remote
, url
, access_key
, secret_key
,
2969 formatter
, yes_i_really_mean_it
);
2975 case OPT_PERIOD_PULL
:
2977 boost::optional
<RGWRESTConn
> conn
;
2978 RGWRESTConn
*remote_conn
= nullptr;
2980 // load current period for endpoints
2981 RGWRealm
realm(realm_id
, realm_name
);
2982 int ret
= realm
.init(g_ceph_context
, store
);
2984 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
2987 RGWPeriod
current_period(realm
.get_current_period());
2988 ret
= current_period
.init(g_ceph_context
, store
);
2990 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
2993 if (remote
.empty()) {
2994 // use realm master zone as remote
2995 remote
= current_period
.get_master_zone();
2997 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
2999 cerr
<< "failed to find a zone or zonegroup for remote "
3000 << remote
<< std::endl
;
3003 remote_conn
= &*conn
;
3007 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3008 realm_id
, realm_name
, period_id
, period_epoch
,
3011 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3015 encode_json("period", period
, formatter
);
3016 formatter
->flush(cout
);
3020 case OPT_GLOBAL_QUOTA_GET
:
3021 case OPT_GLOBAL_QUOTA_SET
:
3022 case OPT_GLOBAL_QUOTA_ENABLE
:
3023 case OPT_GLOBAL_QUOTA_DISABLE
:
3025 if (realm_id
.empty()) {
3026 RGWRealm
realm(g_ceph_context
, store
);
3027 if (!realm_name
.empty()) {
3028 // look up realm_id for the given realm_name
3029 int ret
= realm
.read_id(realm_name
, realm_id
);
3031 cerr
<< "ERROR: failed to read realm for " << realm_name
3032 << ": " << cpp_strerror(-ret
) << std::endl
;
3036 // use default realm_id when none is given
3037 int ret
= realm
.read_default_id(realm_id
);
3038 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3039 cerr
<< "ERROR: failed to read default realm: "
3040 << cpp_strerror(-ret
) << std::endl
;
3046 RGWPeriodConfig period_config
;
3047 int ret
= period_config
.read(store
, realm_id
);
3048 if (ret
< 0 && ret
!= -ENOENT
) {
3049 cerr
<< "ERROR: failed to read period config: "
3050 << cpp_strerror(-ret
) << std::endl
;
3054 formatter
->open_object_section("period_config");
3055 if (quota_scope
== "bucket") {
3056 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3057 max_size
, max_objects
,
3058 have_max_size
, have_max_objects
);
3059 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3060 } else if (quota_scope
== "user") {
3061 set_quota_info(period_config
.user_quota
, opt_cmd
,
3062 max_size
, max_objects
,
3063 have_max_size
, have_max_objects
);
3064 encode_json("user quota", period_config
.user_quota
, formatter
);
3065 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3066 // if no scope is given for GET, print both
3067 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3068 encode_json("user quota", period_config
.user_quota
, formatter
);
3070 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3071 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3074 formatter
->close_section();
3076 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3077 // write the modified period config
3078 ret
= period_config
.write(store
, realm_id
);
3080 cerr
<< "ERROR: failed to write period config: "
3081 << cpp_strerror(-ret
) << std::endl
;
3084 if (!realm_id
.empty()) {
3085 cout
<< "Global quota changes saved. Use 'period update' to apply "
3086 "them to the staging period, and 'period commit' to commit the "
3087 "new period." << std::endl
;
3089 cout
<< "Global quota changes saved. They will take effect as "
3090 "the gateways are restarted." << std::endl
;
3094 formatter
->flush(cout
);
3098 case OPT_REALM_CREATE
:
3100 if (realm_name
.empty()) {
3101 cerr
<< "missing realm name" << std::endl
;
3105 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3106 int ret
= realm
.create();
3108 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3113 ret
= realm
.set_as_default();
3115 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3119 encode_json("realm", realm
, formatter
);
3120 formatter
->flush(cout
);
3124 case OPT_REALM_DELETE
:
3126 RGWRealm
realm(realm_id
, realm_name
);
3127 if (realm_name
.empty() && realm_id
.empty()) {
3128 cerr
<< "missing realm name or id" << std::endl
;
3131 int ret
= realm
.init(g_ceph_context
, store
);
3133 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3136 ret
= realm
.delete_obj();
3138 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3146 RGWRealm
realm(realm_id
, realm_name
);
3147 int ret
= realm
.init(g_ceph_context
, store
);
3149 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3150 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3152 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3156 encode_json("realm", realm
, formatter
);
3157 formatter
->flush(cout
);
3161 case OPT_REALM_GET_DEFAULT
:
3163 RGWRealm
realm(g_ceph_context
, store
);
3165 int ret
= realm
.read_default_id(default_id
);
3166 if (ret
== -ENOENT
) {
3167 cout
<< "No default realm is set" << std::endl
;
3169 } else if (ret
< 0) {
3170 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3173 cout
<< "default realm: " << default_id
<< std::endl
;
3176 case OPT_REALM_LIST
:
3178 RGWRealm
realm(g_ceph_context
, store
);
3180 int ret
= realm
.read_default_id(default_id
);
3181 if (ret
< 0 && ret
!= -ENOENT
) {
3182 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3184 list
<string
> realms
;
3185 ret
= store
->list_realms(realms
);
3187 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3190 formatter
->open_object_section("realms_list");
3191 encode_json("default_info", default_id
, formatter
);
3192 encode_json("realms", realms
, formatter
);
3193 formatter
->close_section();
3194 formatter
->flush(cout
);
3198 case OPT_REALM_LIST_PERIODS
:
3200 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3204 list
<string
> periods
;
3205 ret
= store
->list_periods(period_id
, periods
);
3207 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3210 formatter
->open_object_section("realm_periods_list");
3211 encode_json("current_period", period_id
, formatter
);
3212 encode_json("periods", periods
, formatter
);
3213 formatter
->close_section();
3214 formatter
->flush(cout
);
3219 case OPT_REALM_RENAME
:
3221 RGWRealm
realm(realm_id
, realm_name
);
3222 if (realm_new_name
.empty()) {
3223 cerr
<< "missing realm new name" << std::endl
;
3226 if (realm_name
.empty() && realm_id
.empty()) {
3227 cerr
<< "missing realm name or id" << std::endl
;
3230 int ret
= realm
.init(g_ceph_context
, store
);
3232 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3235 ret
= realm
.rename(realm_new_name
);
3237 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3240 cout
<< "Realm name updated. Note that this change only applies to "
3241 "the current cluster, so this command must be run separately "
3242 "on each of the realm's other clusters." << std::endl
;
3247 if (realm_id
.empty() && realm_name
.empty()) {
3248 cerr
<< "no realm name or id provided" << std::endl
;
3251 RGWRealm
realm(realm_id
, realm_name
);
3252 bool new_realm
= false;
3253 int ret
= realm
.init(g_ceph_context
, store
);
3254 if (ret
< 0 && ret
!= -ENOENT
) {
3255 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3257 } else if (ret
== -ENOENT
) {
3260 ret
= read_decode_json(infile
, realm
);
3264 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3265 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3266 realm
.get_name() << std::endl
;
3271 cout
<< "clearing period and epoch for new realm" << std::endl
;
3272 realm
.clear_current_period_and_epoch();
3273 ret
= realm
.create();
3275 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3279 ret
= realm
.update();
3281 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3287 ret
= realm
.set_as_default();
3289 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3292 encode_json("realm", realm
, formatter
);
3293 formatter
->flush(cout
);
3297 case OPT_REALM_DEFAULT
:
3299 RGWRealm
realm(realm_id
, realm_name
);
3300 int ret
= realm
.init(g_ceph_context
, store
);
3302 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3305 ret
= realm
.set_as_default();
3307 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3312 case OPT_REALM_PULL
:
3315 cerr
<< "A --url must be provided." << std::endl
;
3319 req_info
info(g_ceph_context
, &env
);
3320 info
.method
= "GET";
3321 info
.request_uri
= "/admin/realm";
3323 map
<string
, string
> ¶ms
= info
.args
.get_params();
3324 if (!realm_id
.empty())
3325 params
["id"] = realm_id
;
3326 if (!realm_name
.empty())
3327 params
["name"] = realm_name
;
3331 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3333 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3334 if (ret
== -EACCES
) {
3335 cerr
<< "If the realm has been changed on the master zone, the "
3336 "master zone's gateway may need to be restarted to recognize "
3337 "this user." << std::endl
;
3342 realm
.init(g_ceph_context
, store
, false);
3344 decode_json_obj(realm
, &p
);
3345 } catch (JSONDecoder::err
& e
) {
3346 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3350 auto& current_period
= realm
.get_current_period();
3351 if (!current_period
.empty()) {
3352 // pull the latest epoch of the realm's current period
3353 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3354 realm_id
, realm_name
, current_period
, "",
3357 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3361 ret
= realm
.create(false);
3362 if (ret
< 0 && ret
!= -EEXIST
) {
3363 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3364 << cpp_strerror(ret
) << std::endl
;
3366 } else if (ret
==-EEXIST
) {
3367 ret
= realm
.update();
3369 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3370 << cpp_strerror(ret
) << std::endl
;
3375 ret
= realm
.set_as_default();
3377 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3381 encode_json("realm", realm
, formatter
);
3382 formatter
->flush(cout
);
3387 case OPT_ZONEGROUP_ADD
:
3389 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3390 cerr
<< "no zonegroup name or id provided" << std::endl
;
3394 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3395 int ret
= zonegroup
.init(g_ceph_context
, store
);
3397 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3398 << cpp_strerror(-ret
) << std::endl
;
3401 RGWZoneParams
zone(zone_id
, zone_name
);
3402 ret
= zone
.init(g_ceph_context
, store
);
3404 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3407 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3408 zone
.realm_id
= zonegroup
.realm_id
;
3409 ret
= zone
.update();
3411 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
3416 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3417 zone
.tier_config
= tier_config_add
;
3419 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3421 ret
= zonegroup
.add_zone(zone
,
3422 (is_master_set
? &is_master
: NULL
),
3423 (is_read_only_set
? &read_only
: NULL
),
3424 endpoints
, ptier_type
,
3425 psync_from_all
, sync_from
, sync_from_rm
);
3427 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3428 << cpp_strerror(-ret
) << std::endl
;
3432 encode_json("zonegroup", zonegroup
, formatter
);
3433 formatter
->flush(cout
);
3436 case OPT_ZONEGROUP_CREATE
:
3438 if (zonegroup_name
.empty()) {
3439 cerr
<< "Missing zonegroup name" << std::endl
;
3442 RGWRealm
realm(realm_id
, realm_name
);
3443 int ret
= realm
.init(g_ceph_context
, store
);
3445 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3449 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3450 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3451 ret
= zonegroup
.create();
3453 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3458 ret
= zonegroup
.set_as_default();
3460 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3464 encode_json("zonegroup", zonegroup
, formatter
);
3465 formatter
->flush(cout
);
3469 case OPT_ZONEGROUP_DEFAULT
:
3471 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3472 cerr
<< "no zonegroup name or id provided" << std::endl
;
3476 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3477 int ret
= zonegroup
.init(g_ceph_context
, store
);
3479 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3483 ret
= zonegroup
.set_as_default();
3485 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3490 case OPT_ZONEGROUP_DELETE
:
3492 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3493 cerr
<< "no zonegroup name or id provided" << std::endl
;
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
;
3502 ret
= zonegroup
.delete_obj();
3504 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3509 case OPT_ZONEGROUP_GET
:
3511 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3512 int ret
= zonegroup
.init(g_ceph_context
, store
);
3514 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3518 encode_json("zonegroup", zonegroup
, formatter
);
3519 formatter
->flush(cout
);
3523 case OPT_ZONEGROUP_LIST
:
3525 RGWZoneGroup zonegroup
;
3526 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3528 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3532 list
<string
> zonegroups
;
3533 ret
= store
->list_zonegroups(zonegroups
);
3535 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3538 string default_zonegroup
;
3539 ret
= zonegroup
.read_default_id(default_zonegroup
);
3540 if (ret
< 0 && ret
!= -ENOENT
) {
3541 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3543 formatter
->open_object_section("zonegroups_list");
3544 encode_json("default_info", default_zonegroup
, formatter
);
3545 encode_json("zonegroups", zonegroups
, formatter
);
3546 formatter
->close_section();
3547 formatter
->flush(cout
);
3551 case OPT_ZONEGROUP_MODIFY
:
3553 RGWRealm
realm(realm_id
, realm_name
);
3554 int ret
= realm
.init(g_ceph_context
, store
);
3556 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3560 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3561 ret
= zonegroup
.init(g_ceph_context
, store
);
3563 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3567 bool need_update
= false;
3569 if (!master_zone
.empty()) {
3570 zonegroup
.master_zone
= master_zone
;
3574 if (is_master_set
) {
3575 zonegroup
.update_master(is_master
);
3579 if (!endpoints
.empty()) {
3580 zonegroup
.endpoints
= endpoints
;
3584 if (!api_name
.empty()) {
3585 zonegroup
.api_name
= api_name
;
3589 if (!realm_id
.empty()) {
3590 zonegroup
.realm_id
= realm_id
;
3592 } else if (!realm_name
.empty()) {
3593 // get realm id from name
3594 RGWRealm realm
{g_ceph_context
, store
};
3595 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3597 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3604 ret
= zonegroup
.update();
3606 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3612 ret
= zonegroup
.set_as_default();
3614 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3618 encode_json("zonegroup", zonegroup
, formatter
);
3619 formatter
->flush(cout
);
3622 case OPT_ZONEGROUP_SET
:
3624 RGWRealm
realm(realm_id
, realm_name
);
3625 int ret
= realm
.init(g_ceph_context
, store
);
3627 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3631 RGWZoneGroup zonegroup
;
3632 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3634 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3637 ret
= read_decode_json(infile
, zonegroup
);
3641 if (zonegroup
.realm_id
.empty()) {
3642 zonegroup
.realm_id
= realm
.get_id();
3644 ret
= zonegroup
.create();
3645 if (ret
< 0 && ret
!= -EEXIST
) {
3646 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3648 } else if (ret
== -EEXIST
) {
3649 ret
= zonegroup
.update();
3651 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3657 ret
= zonegroup
.set_as_default();
3659 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3663 encode_json("zonegroup", zonegroup
, formatter
);
3664 formatter
->flush(cout
);
3667 case OPT_ZONEGROUP_REMOVE
:
3669 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3670 int ret
= zonegroup
.init(g_ceph_context
, store
);
3672 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3676 if (zone_id
.empty()) {
3677 if (zone_name
.empty()) {
3678 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
3681 // look up zone id by name
3682 for (auto& z
: zonegroup
.zones
) {
3683 if (zone_name
== z
.second
.name
) {
3684 zone_id
= z
.second
.id
;
3688 if (zone_id
.empty()) {
3689 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
3690 << zonegroup
.get_name() << std::endl
;
3695 ret
= zonegroup
.remove_zone(zone_id
);
3697 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
3701 encode_json("zonegroup", zonegroup
, formatter
);
3702 formatter
->flush(cout
);
3705 case OPT_ZONEGROUP_RENAME
:
3707 if (zonegroup_new_name
.empty()) {
3708 cerr
<< " missing zonegroup new name" << std::endl
;
3711 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3712 cerr
<< "no zonegroup name or id provided" << std::endl
;
3715 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3716 int ret
= zonegroup
.init(g_ceph_context
, store
);
3718 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3721 ret
= zonegroup
.rename(zonegroup_new_name
);
3723 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3728 case OPT_ZONEGROUP_PLACEMENT_LIST
:
3730 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3731 int ret
= zonegroup
.init(g_ceph_context
, store
);
3733 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3737 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3738 formatter
->flush(cout
);
3742 case OPT_ZONEGROUP_PLACEMENT_ADD
:
3743 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
3744 case OPT_ZONEGROUP_PLACEMENT_RM
:
3745 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
3747 if (placement_id
.empty()) {
3748 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
3752 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3753 int ret
= zonegroup
.init(g_ceph_context
, store
);
3755 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3759 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
3760 RGWZoneGroupPlacementTarget target
;
3761 target
.name
= placement_id
;
3762 for (auto& t
: tags
) {
3763 target
.tags
.insert(t
);
3765 zonegroup
.placement_targets
[placement_id
] = target
;
3766 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
3767 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
3768 if (!tags
.empty()) {
3769 target
.tags
.clear();
3770 for (auto& t
: tags
) {
3771 target
.tags
.insert(t
);
3774 target
.name
= placement_id
;
3775 for (auto& t
: tags_rm
) {
3776 target
.tags
.erase(t
);
3778 for (auto& t
: tags_add
) {
3779 target
.tags
.insert(t
);
3781 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
3782 zonegroup
.placement_targets
.erase(placement_id
);
3783 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
3784 if (!zonegroup
.placement_targets
.count(placement_id
)) {
3785 cerr
<< "failed to find a zonegroup placement target named '"
3786 << placement_id
<< "'" << std::endl
;
3789 zonegroup
.default_placement
= placement_id
;
3792 zonegroup
.post_process_params();
3793 ret
= zonegroup
.update();
3795 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3799 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3800 formatter
->flush(cout
);
3803 case OPT_ZONE_CREATE
:
3805 if (zone_name
.empty()) {
3806 cerr
<< "zone name not provided" << std::endl
;
3810 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3811 /* if the user didn't provide zonegroup info , create stand alone zone */
3812 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3813 ret
= zonegroup
.init(g_ceph_context
, store
);
3815 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3818 if (realm_id
.empty() && realm_name
.empty()) {
3819 realm_id
= zonegroup
.realm_id
;
3823 RGWZoneParams
zone(zone_id
, zone_name
);
3824 ret
= zone
.init(g_ceph_context
, store
, false);
3826 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3830 zone
.system_key
.id
= access_key
;
3831 zone
.system_key
.key
= secret_key
;
3832 zone
.realm_id
= realm_id
;
3833 zone
.tier_config
= tier_config_add
;
3835 ret
= zone
.create();
3837 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3841 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3842 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3843 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3844 ret
= zonegroup
.add_zone(zone
,
3845 (is_master_set
? &is_master
: NULL
),
3846 (is_read_only_set
? &read_only
: NULL
),
3850 sync_from
, sync_from_rm
);
3852 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
3853 << ": " << cpp_strerror(-ret
) << std::endl
;
3859 ret
= zone
.set_as_default();
3861 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3865 encode_json("zone", zone
, formatter
);
3866 formatter
->flush(cout
);
3870 case OPT_ZONE_DEFAULT
:
3872 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3873 int ret
= zonegroup
.init(g_ceph_context
, store
);
3875 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3877 if (zone_id
.empty() && zone_name
.empty()) {
3878 cerr
<< "no zone name or id provided" << std::endl
;
3881 RGWZoneParams
zone(zone_id
, zone_name
);
3882 ret
= zone
.init(g_ceph_context
, store
);
3884 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3887 ret
= zone
.set_as_default();
3889 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
3894 case OPT_ZONE_DELETE
:
3896 if (zone_id
.empty() && zone_name
.empty()) {
3897 cerr
<< "no zone name or id provided" << std::endl
;
3900 RGWZoneParams
zone(zone_id
, zone_name
);
3901 int ret
= zone
.init(g_ceph_context
, store
);
3903 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3907 list
<string
> zonegroups
;
3908 ret
= store
->list_zonegroups(zonegroups
);
3910 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3914 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
3915 RGWZoneGroup
zonegroup(string(), *iter
);
3916 int ret
= zonegroup
.init(g_ceph_context
, store
);
3918 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3921 ret
= zonegroup
.remove_zone(zone
.get_id());
3922 if (ret
< 0 && ret
!= -ENOENT
) {
3923 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
3924 << cpp_strerror(-ret
) << std::endl
;
3928 ret
= zone
.delete_obj();
3930 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3937 RGWZoneParams
zone(zone_id
, zone_name
);
3938 int ret
= zone
.init(g_ceph_context
, store
);
3940 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3943 encode_json("zone", zone
, formatter
);
3944 formatter
->flush(cout
);
3949 RGWZoneParams
zone(zone_name
);
3950 int ret
= zone
.init(g_ceph_context
, store
, false);
3956 if (ret
< 0 && ret
!= -ENOENT
) {
3957 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
3961 string orig_id
= zone
.get_id();
3963 ret
= read_decode_json(infile
, zone
);
3968 if(zone
.realm_id
.empty()) {
3969 RGWRealm
realm(realm_id
, realm_name
);
3970 int ret
= realm
.init(g_ceph_context
, store
);
3971 if (ret
< 0 && ret
!= -ENOENT
) {
3972 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3975 zone
.realm_id
= realm
.get_id();
3978 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
3979 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
3983 if (zone
.get_name().empty()) {
3984 zone
.set_name(zone_name
);
3985 if (zone
.get_name().empty()) {
3986 cerr
<< "no zone name specified" << std::endl
;
3991 zone_name
= zone
.get_name();
3993 if (zone
.get_id().empty()) {
3994 zone
.set_id(orig_id
);
3997 if (zone
.get_id().empty()) {
3998 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
3999 if (zone_name
.empty()) {
4000 cerr
<< "missing zone name" << std::endl
;
4003 zone
.set_name(zone_name
);
4004 zone
.set_id(zone_name
);
4007 cerr
<< "zone id " << zone
.get_id();
4008 ret
= zone
.fix_pool_names();
4010 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4013 ret
= zone
.write(false);
4015 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4020 ret
= zone
.set_as_default();
4022 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4026 encode_json("zone", zone
, formatter
);
4027 formatter
->flush(cout
);
4033 int ret
= store
->list_zones(zones
);
4035 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4040 ret
= zone
.init(g_ceph_context
, store
, false);
4042 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4045 string default_zone
;
4046 ret
= zone
.read_default_id(default_zone
);
4047 if (ret
< 0 && ret
!= -ENOENT
) {
4048 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4050 formatter
->open_object_section("zones_list");
4051 encode_json("default_info", default_zone
, formatter
);
4052 encode_json("zones", zones
, formatter
);
4053 formatter
->close_section();
4054 formatter
->flush(cout
);
4058 case OPT_ZONE_MODIFY
:
4060 RGWZoneParams
zone(zone_id
, zone_name
);
4061 int ret
= zone
.init(g_ceph_context
, store
);
4063 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4067 bool need_zone_update
= false;
4068 if (!access_key
.empty()) {
4069 zone
.system_key
.id
= access_key
;
4070 need_zone_update
= true;
4073 if (!secret_key
.empty()) {
4074 zone
.system_key
.key
= secret_key
;
4075 need_zone_update
= true;
4078 if (!realm_id
.empty()) {
4079 zone
.realm_id
= realm_id
;
4080 need_zone_update
= true;
4081 } else if (!realm_name
.empty()) {
4082 // get realm id from name
4083 RGWRealm realm
{g_ceph_context
, store
};
4084 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4086 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4089 need_zone_update
= true;
4092 for (auto add
: tier_config_add
) {
4093 zone
.tier_config
[add
.first
] = add
.second
;
4094 need_zone_update
= true;
4097 for (auto rm
: tier_config_rm
) {
4098 zone
.tier_config
.erase(rm
.first
);
4099 need_zone_update
= true;
4102 if (need_zone_update
) {
4103 ret
= zone
.update();
4105 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4110 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4111 ret
= zonegroup
.init(g_ceph_context
, store
);
4113 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4116 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4118 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4120 ret
= zonegroup
.add_zone(zone
,
4121 (is_master_set
? &is_master
: NULL
),
4122 (is_read_only_set
? &read_only
: NULL
),
4123 endpoints
, ptier_type
,
4124 psync_from_all
, sync_from
, sync_from_rm
);
4126 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4130 ret
= zonegroup
.update();
4132 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4137 ret
= zone
.set_as_default();
4139 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4143 encode_json("zone", zone
, formatter
);
4144 formatter
->flush(cout
);
4147 case OPT_ZONE_RENAME
:
4149 if (zone_new_name
.empty()) {
4150 cerr
<< " missing zone new name" << std::endl
;
4153 if (zone_id
.empty() && zone_name
.empty()) {
4154 cerr
<< "no zonegroup name or id provided" << std::endl
;
4157 RGWZoneParams
zone(zone_id
,zone_name
);
4158 int ret
= zone
.init(g_ceph_context
, store
);
4160 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4163 ret
= zone
.rename(zone_new_name
);
4165 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4169 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4170 ret
= zonegroup
.init(g_ceph_context
, store
);
4172 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4174 ret
= zonegroup
.rename_zone(zone
);
4175 if (ret
< 0 && ret
) {
4176 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4182 case OPT_ZONE_PLACEMENT_ADD
:
4183 case OPT_ZONE_PLACEMENT_MODIFY
:
4184 case OPT_ZONE_PLACEMENT_RM
:
4186 if (placement_id
.empty()) {
4187 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4190 RGWZoneParams
zone(zone_id
, zone_name
);
4191 int ret
= zone
.init(g_ceph_context
, store
);
4193 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4197 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4198 // pool names are required
4199 if (!index_pool
|| index_pool
->empty() ||
4200 !data_pool
|| data_pool
->empty()) {
4201 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4205 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4207 info
.index_pool
= *index_pool
;
4208 info
.data_pool
= *data_pool
;
4209 if (data_extra_pool
) {
4210 info
.data_extra_pool
= *data_extra_pool
;
4212 if (index_type_specified
) {
4213 info
.index_type
= placement_index_type
;
4215 if (compression_type
) {
4216 info
.compression_type
= *compression_type
;
4218 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4219 auto p
= zone
.placement_pools
.find(placement_id
);
4220 if (p
== zone
.placement_pools
.end()) {
4221 cerr
<< "ERROR: zone placement target '" << placement_id
4222 << "' not found" << std::endl
;
4225 auto& info
= p
->second
;
4226 if (index_pool
&& !index_pool
->empty()) {
4227 info
.index_pool
= *index_pool
;
4229 if (data_pool
&& !data_pool
->empty()) {
4230 info
.data_pool
= *data_pool
;
4232 if (data_extra_pool
) {
4233 info
.data_extra_pool
= *data_extra_pool
;
4235 if (index_type_specified
) {
4236 info
.index_type
= placement_index_type
;
4238 if (compression_type
) {
4239 info
.compression_type
= *compression_type
;
4241 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4242 zone
.placement_pools
.erase(placement_id
);
4245 ret
= zone
.update();
4247 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4251 encode_json("zone", zone
, formatter
);
4252 formatter
->flush(cout
);
4255 case OPT_ZONE_PLACEMENT_LIST
:
4257 RGWZoneParams
zone(zone_id
, zone_name
);
4258 int ret
= zone
.init(g_ceph_context
, store
);
4260 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4263 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4264 formatter
->flush(cout
);
4271 if (!user_id
.empty()) {
4272 user_op
.set_user_id(user_id
);
4273 bucket_op
.set_user_id(user_id
);
4276 if (!display_name
.empty())
4277 user_op
.set_display_name(display_name
);
4279 if (!user_email
.empty())
4280 user_op
.set_user_email(user_email
);
4282 if (!access_key
.empty())
4283 user_op
.set_access_key(access_key
);
4285 if (!secret_key
.empty())
4286 user_op
.set_secret_key(secret_key
);
4288 if (!subuser
.empty())
4289 user_op
.set_subuser(subuser
);
4292 user_op
.set_caps(caps
);
4294 user_op
.set_purge_data(purge_data
);
4297 user_op
.set_purge_keys();
4300 user_op
.set_generate_key();
4303 user_op
.set_gen_secret(); // assume that a key pair should be created
4305 if (max_buckets_specified
)
4306 user_op
.set_max_buckets(max_buckets
);
4308 if (admin_specified
)
4309 user_op
.set_admin(admin
);
4311 if (system_specified
)
4312 user_op
.set_system(system
);
4315 user_op
.set_perm(perm_mask
);
4317 if (set_temp_url_key
) {
4318 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4319 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4320 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4324 if (!op_mask_str
.empty()) {
4326 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4328 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4332 user_op
.set_op_mask(op_mask
);
4335 if (key_type
!= KEY_TYPE_UNDEFINED
)
4336 user_op
.set_key_type(key_type
);
4338 // set suspension operation parameters
4339 if (opt_cmd
== OPT_USER_ENABLE
)
4340 user_op
.set_suspension(false);
4341 else if (opt_cmd
== OPT_USER_SUSPEND
)
4342 user_op
.set_suspension(true);
4344 // RGWUser to use for user operations
4347 if (!user_id
.empty() || !subuser
.empty()) {
4348 ret
= user
.init(store
, user_op
);
4350 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4355 /* populate bucket operation */
4356 bucket_op
.set_bucket_name(bucket_name
);
4357 bucket_op
.set_object(object
);
4358 bucket_op
.set_check_objects(check_objects
);
4359 bucket_op
.set_delete_children(delete_child_objects
);
4360 bucket_op
.set_fix_index(fix
);
4361 bucket_op
.set_max_aio(max_concurrent_ios
);
4363 // required to gather errors from operations
4364 std::string err_msg
;
4366 bool output_user_info
= true;
4371 case OPT_USER_CREATE
:
4372 if (!user_op
.has_existing_user()) {
4373 user_op
.set_generate_key(); // generate a new key by default
4375 ret
= user
.add(user_op
, &err_msg
);
4377 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4380 if (!subuser
.empty()) {
4381 ret
= user
.subusers
.add(user_op
, &err_msg
);
4383 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4389 ret
= user
.remove(user_op
, &err_msg
);
4391 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4395 output_user_info
= false;
4397 case OPT_USER_ENABLE
:
4398 case OPT_USER_SUSPEND
:
4399 case OPT_USER_MODIFY
:
4400 ret
= user
.modify(user_op
, &err_msg
);
4402 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4407 case OPT_SUBUSER_CREATE
:
4408 ret
= user
.subusers
.add(user_op
, &err_msg
);
4410 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4415 case OPT_SUBUSER_MODIFY
:
4416 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4418 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4423 case OPT_SUBUSER_RM
:
4424 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4426 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4432 ret
= user
.caps
.add(user_op
, &err_msg
);
4434 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4440 ret
= user
.caps
.remove(user_op
, &err_msg
);
4442 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4447 case OPT_KEY_CREATE
:
4448 ret
= user
.keys
.add(user_op
, &err_msg
);
4450 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4456 ret
= user
.keys
.remove(user_op
, &err_msg
);
4458 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4462 case OPT_PERIOD_PUSH
:
4465 req_info
info(g_ceph_context
, &env
);
4466 info
.method
= "POST";
4467 info
.request_uri
= "/admin/realm/period";
4469 map
<string
, string
> ¶ms
= info
.args
.get_params();
4470 if (!realm_id
.empty())
4471 params
["realm_id"] = realm_id
;
4472 if (!realm_name
.empty())
4473 params
["realm_name"] = realm_name
;
4474 if (!period_id
.empty())
4475 params
["period_id"] = period_id
;
4476 if (!period_epoch
.empty())
4477 params
["epoch"] = period_epoch
;
4480 RGWPeriod
period(period_id
);
4481 int ret
= period
.init(g_ceph_context
, store
);
4483 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4486 // json format into a bufferlist
4487 JSONFormatter
jf(false);
4488 encode_json("period", period
, &jf
);
4493 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4496 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4501 case OPT_PERIOD_UPDATE
:
4503 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4504 commit
, remote
, url
, access_key
, secret_key
,
4505 formatter
, yes_i_really_mean_it
);
4511 case OPT_PERIOD_COMMIT
:
4513 // read realm and staging period
4514 RGWRealm
realm(realm_id
, realm_name
);
4515 int ret
= realm
.init(g_ceph_context
, store
);
4517 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4520 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4521 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4523 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4526 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4527 yes_i_really_mean_it
);
4529 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4533 encode_json("period", period
, formatter
);
4534 formatter
->flush(cout
);
4538 case OPT_ROLE_CREATE
:
4540 if (role_name
.empty()) {
4541 cerr
<< "ERROR: role name is empty" << std::endl
;
4545 if (assume_role_doc
.empty()) {
4546 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4549 /* The following two calls will be replaced by read_decode_json or something
4550 similar when the code for AWS Policies is in places */
4552 int ret
= read_input(assume_role_doc
, bl
);
4554 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4558 if (!p
.parse(bl
.c_str(), bl
.length())) {
4559 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4562 string trust_policy
= bl
.to_str();
4563 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4564 ret
= role
.create(true);
4568 show_role_info(role
, formatter
);
4571 case OPT_ROLE_DELETE
:
4573 if (role_name
.empty()) {
4574 cerr
<< "ERROR: empty role name" << std::endl
;
4577 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4578 ret
= role
.delete_obj();
4582 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4587 if (role_name
.empty()) {
4588 cerr
<< "ERROR: empty role name" << std::endl
;
4591 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4596 show_role_info(role
, formatter
);
4599 case OPT_ROLE_MODIFY
:
4601 if (role_name
.empty()) {
4602 cerr
<< "ERROR: role name is empty" << std::endl
;
4606 if (assume_role_doc
.empty()) {
4607 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4611 /* The following two calls will be replaced by read_decode_json or something
4612 similar when the code for AWS Policies is in place */
4614 int ret
= read_input(assume_role_doc
, bl
);
4616 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4620 if (!p
.parse(bl
.c_str(), bl
.length())) {
4621 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4624 string trust_policy
= bl
.to_str();
4625 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4630 role
.update_trust_policy(trust_policy
);
4631 ret
= role
.update();
4635 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4640 vector
<RGWRole
> result
;
4641 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4645 show_roles_info(result
, formatter
);
4648 case OPT_ROLE_POLICY_PUT
:
4650 if (role_name
.empty()) {
4651 cerr
<< "role name is empty" << std::endl
;
4655 if (policy_name
.empty()) {
4656 cerr
<< "policy name is empty" << std::endl
;
4660 if (perm_policy_doc
.empty()) {
4661 cerr
<< "permission policy document is empty" << std::endl
;
4665 /* The following two calls will be replaced by read_decode_json or something
4666 similar, when code for AWS Policies is in place.*/
4668 int ret
= read_input(perm_policy_doc
, bl
);
4670 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4674 if (!p
.parse(bl
.c_str(), bl
.length())) {
4675 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
4679 perm_policy
= bl
.c_str();
4681 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4686 role
.set_perm_policy(policy_name
, perm_policy
);
4687 ret
= role
.update();
4691 cout
<< "Permission policy attached successfully" << std::endl
;
4694 case OPT_ROLE_POLICY_LIST
:
4696 if (role_name
.empty()) {
4697 cerr
<< "ERROR: Role name is empty" << std::endl
;
4700 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4705 std::vector
<string
> policy_names
= role
.get_role_policy_names();
4706 show_policy_names(policy_names
, formatter
);
4709 case OPT_ROLE_POLICY_GET
:
4711 if (role_name
.empty()) {
4712 cerr
<< "ERROR: role name is empty" << std::endl
;
4716 if (policy_name
.empty()) {
4717 cerr
<< "ERROR: policy name is empty" << std::endl
;
4720 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4721 int ret
= role
.get();
4726 ret
= role
.get_role_policy(policy_name
, perm_policy
);
4730 show_perm_policy(perm_policy
, formatter
);
4733 case OPT_ROLE_POLICY_DELETE
:
4735 if (role_name
.empty()) {
4736 cerr
<< "ERROR: role name is empty" << std::endl
;
4740 if (policy_name
.empty()) {
4741 cerr
<< "ERROR: policy name is empty" << std::endl
;
4744 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4749 ret
= role
.delete_policy(policy_name
);
4753 ret
= role
.update();
4757 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
4758 << role_name
<< std::endl
;
4762 output_user_info
= false;
4765 // output the result of a user operation
4766 if (output_user_info
) {
4767 ret
= user
.info(info
, &err_msg
);
4769 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
4772 show_user_info(info
, formatter
);
4775 if (opt_cmd
== OPT_POLICY
) {
4776 if (format
== "xml") {
4777 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
4779 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4783 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
4785 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4791 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
4793 std::list
<std::string
> user_ids
;
4794 metadata_key
= "user";
4799 if (! user_id
.empty()) {
4800 user_ids
.push_back(user_id
.id
);
4802 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4805 /* list users in groups of max-keys, then perform user-bucket
4806 * limit-check on each group */
4807 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
4809 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
4810 << cpp_strerror(-ret
) << std::endl
;
4815 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
4817 if (ret
< 0 && ret
!= -ENOENT
) {
4818 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
4819 << cpp_strerror(-ret
) << std::endl
;
4822 /* ok, do the limit checks for this group */
4824 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4830 } while (truncated
);
4831 store
->meta_mgr
->list_keys_complete(handle
);
4834 } /* OPT_BUCKET_LIMIT_CHECK */
4836 if (opt_cmd
== OPT_BUCKETS_LIST
) {
4837 if (bucket_name
.empty()) {
4838 RGWBucketAdminOp::info(store
, bucket_op
, f
);
4840 RGWBucketInfo bucket_info
;
4841 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
4843 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
4846 formatter
->open_array_section("entries");
4849 if (max_entries
< 0)
4854 vector
<rgw_bucket_dir_entry
> result
;
4855 map
<string
, bool> common_prefixes
;
4858 RGWRados::Bucket
target(store
, bucket_info
);
4859 RGWRados::Bucket::List
list_op(&target
);
4861 list_op
.params
.prefix
= prefix
;
4862 list_op
.params
.delim
= delim
;
4863 list_op
.params
.marker
= rgw_obj_key(marker
);
4864 list_op
.params
.ns
= ns
;
4865 list_op
.params
.enforce_ns
= false;
4866 list_op
.params
.list_versions
= true;
4869 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
4871 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
4875 count
+= result
.size();
4877 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
4878 rgw_bucket_dir_entry
& entry
= *iter
;
4879 encode_json("entry", entry
, formatter
);
4881 formatter
->flush(cout
);
4882 } while (truncated
&& count
< max_entries
);
4884 formatter
->close_section();
4885 formatter
->flush(cout
);
4886 } /* have bucket_name */
4887 } /* OPT_BUCKETS_LIST */
4889 if (opt_cmd
== OPT_BUCKET_STATS
) {
4890 bucket_op
.set_fetch_stats(true);
4892 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
4894 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4899 if (opt_cmd
== OPT_BUCKET_LINK
) {
4900 bucket_op
.set_bucket_id(bucket_id
);
4902 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
4904 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4909 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
4910 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
4912 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
4917 if (opt_cmd
== OPT_LOG_LIST
) {
4919 if (date
.size() && date
.size() != 10) {
4920 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
4925 formatter
->open_array_section("logs");
4927 int r
= store
->log_list_init(date
, &h
);
4932 cerr
<< "log list: error " << r
<< std::endl
;
4937 int r
= store
->log_list_next(h
, &name
);
4941 cerr
<< "log list: error " << r
<< std::endl
;
4944 formatter
->dump_string("object", name
);
4947 formatter
->close_section();
4948 formatter
->flush(cout
);
4952 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
4953 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
4954 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
4959 if (!object
.empty()) {
4969 if (opt_cmd
== OPT_LOG_SHOW
) {
4972 int r
= store
->log_show_init(oid
, &h
);
4974 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
4979 formatter
->open_object_section("log");
4981 struct rgw_log_entry entry
;
4983 // peek at first entry to get bucket metadata
4984 r
= store
->log_show_next(h
, &entry
);
4986 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
4989 formatter
->dump_string("bucket_id", entry
.bucket_id
);
4990 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
4991 formatter
->dump_string("bucket", entry
.bucket
);
4993 uint64_t agg_time
= 0;
4994 uint64_t agg_bytes_sent
= 0;
4995 uint64_t agg_bytes_received
= 0;
4996 uint64_t total_entries
= 0;
4998 if (show_log_entries
)
4999 formatter
->open_array_section("log_entries");
5002 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5004 agg_time
+= total_time
;
5005 agg_bytes_sent
+= entry
.bytes_sent
;
5006 agg_bytes_received
+= entry
.bytes_received
;
5009 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5010 entry
.bytes_received
== 0)
5013 if (show_log_entries
) {
5015 rgw_format_ops_log_entry(entry
, formatter
);
5016 formatter
->flush(cout
);
5019 r
= store
->log_show_next(h
, &entry
);
5023 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5026 if (show_log_entries
)
5027 formatter
->close_section();
5030 formatter
->open_object_section("log_sum");
5031 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5032 formatter
->dump_int("bytes_received", agg_bytes_received
);
5033 formatter
->dump_int("total_time", agg_time
);
5034 formatter
->dump_int("total_entries", total_entries
);
5035 formatter
->close_section();
5037 formatter
->close_section();
5038 formatter
->flush(cout
);
5041 if (opt_cmd
== OPT_LOG_RM
) {
5042 int r
= store
->log_remove(oid
);
5044 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5050 if (opt_cmd
== OPT_POOL_ADD
) {
5051 if (pool_name
.empty()) {
5052 cerr
<< "need to specify pool to add!" << std::endl
;
5056 int ret
= store
->add_bucket_placement(pool
);
5058 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5061 if (opt_cmd
== OPT_POOL_RM
) {
5062 if (pool_name
.empty()) {
5063 cerr
<< "need to specify pool to remove!" << std::endl
;
5067 int ret
= store
->remove_bucket_placement(pool
);
5069 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5072 if (opt_cmd
== OPT_POOLS_LIST
) {
5073 set
<rgw_pool
> pools
;
5074 int ret
= store
->list_placement_set(pools
);
5076 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5080 formatter
->open_array_section("pools");
5081 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5082 formatter
->open_object_section("pool");
5083 formatter
->dump_string("name", siter
->to_str());
5084 formatter
->close_section();
5086 formatter
->close_section();
5087 formatter
->flush(cout
);
5091 if (opt_cmd
== OPT_USAGE_SHOW
) {
5092 uint64_t start_epoch
= 0;
5093 uint64_t end_epoch
= (uint64_t)-1;
5097 if (!start_date
.empty()) {
5098 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5100 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5104 if (!end_date
.empty()) {
5105 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5107 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5113 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5114 show_log_entries
, show_log_sum
, &categories
,
5117 cerr
<< "ERROR: failed to show usage" << std::endl
;
5122 if (opt_cmd
== OPT_USAGE_TRIM
) {
5123 if (user_id
.empty() && !yes_i_really_mean_it
) {
5124 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5125 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5129 uint64_t start_epoch
= 0;
5130 uint64_t end_epoch
= (uint64_t)-1;
5133 if (!start_date
.empty()) {
5134 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5136 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5141 if (!end_date
.empty()) {
5142 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5144 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5149 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5151 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5156 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5157 if (bucket_name
.empty()) {
5158 cerr
<< "ERROR: bucket not specified" << std::endl
;
5161 if (object
.empty()) {
5162 cerr
<< "ERROR: object not specified" << std::endl
;
5167 if (opt_cmd
== OPT_OLH_GET
) {
5168 RGWBucketInfo bucket_info
;
5169 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5171 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5175 rgw_obj
obj(bucket
, object
);
5176 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5178 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5181 encode_json("olh", olh
, formatter
);
5182 formatter
->flush(cout
);
5185 if (opt_cmd
== OPT_OLH_READLOG
) {
5186 RGWBucketInfo bucket_info
;
5187 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5189 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5192 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5195 RGWObjectCtx
rctx(store
);
5196 rgw_obj
obj(bucket
, object
);
5200 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5205 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5207 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5210 formatter
->open_object_section("result");
5211 encode_json("is_truncated", is_truncated
, formatter
);
5212 encode_json("log", log
, formatter
);
5213 formatter
->close_section();
5214 formatter
->flush(cout
);
5217 if (opt_cmd
== OPT_BI_GET
) {
5218 RGWBucketInfo bucket_info
;
5219 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5221 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5224 rgw_obj
obj(bucket
, object
);
5225 if (!object_version
.empty()) {
5226 obj
.key
.set_instance(object_version
);
5229 rgw_cls_bi_entry entry
;
5231 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5233 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5237 encode_json("entry", entry
, formatter
);
5238 formatter
->flush(cout
);
5241 if (opt_cmd
== OPT_BI_PUT
) {
5242 RGWBucketInfo bucket_info
;
5243 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5245 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5249 rgw_cls_bi_entry entry
;
5250 cls_rgw_obj_key key
;
5251 ret
= read_decode_json(infile
, entry
, &key
);
5256 rgw_obj
obj(bucket
, key
);
5258 ret
= store
->bi_put(bucket
, obj
, entry
);
5260 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5265 if (opt_cmd
== OPT_BI_LIST
) {
5266 if (bucket_name
.empty()) {
5267 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5270 RGWBucketInfo bucket_info
;
5271 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5273 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5277 list
<rgw_cls_bi_entry
> entries
;
5279 if (max_entries
< 0) {
5283 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5285 formatter
->open_array_section("entries");
5287 for (int i
= 0; i
< max_shards
; i
++) {
5288 RGWRados::BucketShard
bs(store
);
5289 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5290 int ret
= bs
.init(bucket
, shard_id
);
5294 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5300 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5302 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5306 list
<rgw_cls_bi_entry
>::iterator iter
;
5307 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5308 rgw_cls_bi_entry
& entry
= *iter
;
5309 encode_json("entry", entry
, formatter
);
5312 formatter
->flush(cout
);
5313 } while (is_truncated
);
5314 formatter
->flush(cout
);
5316 formatter
->close_section();
5317 formatter
->flush(cout
);
5320 if (opt_cmd
== OPT_BI_PURGE
) {
5321 if (bucket_name
.empty()) {
5322 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5325 RGWBucketInfo bucket_info
;
5326 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5328 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5332 RGWBucketInfo cur_bucket_info
;
5333 rgw_bucket cur_bucket
;
5334 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5336 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5340 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5341 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5342 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5346 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5348 for (int i
= 0; i
< max_shards
; i
++) {
5349 RGWRados::BucketShard
bs(store
);
5350 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5351 int ret
= bs
.init(bucket
, shard_id
);
5353 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5357 ret
= store
->bi_remove(bs
);
5359 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5365 if (opt_cmd
== OPT_OBJECT_RM
) {
5366 RGWBucketInfo bucket_info
;
5367 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5369 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5372 rgw_obj_key
key(object
, object_version
);
5373 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5376 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5381 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5382 if (bucket_name
.empty()) {
5383 cerr
<< "ERROR: bucket not specified" << std::endl
;
5386 if (object
.empty()) {
5387 cerr
<< "ERROR: object not specified" << std::endl
;
5391 RGWBucketInfo bucket_info
;
5392 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5394 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5398 rgw_obj
obj(bucket
, object
);
5399 obj
.key
.set_instance(object_version
);
5400 bool need_rewrite
= true;
5401 if (min_rewrite_stripe_size
> 0) {
5402 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5404 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5408 ret
= store
->rewrite_obj(bucket_info
, obj
);
5410 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5414 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5418 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5419 int ret
= store
->process_expire_objects();
5421 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5426 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5427 if (bucket_name
.empty()) {
5428 cerr
<< "ERROR: bucket not specified" << std::endl
;
5432 RGWBucketInfo bucket_info
;
5433 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5435 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5439 uint64_t start_epoch
= 0;
5440 uint64_t end_epoch
= 0;
5442 if (!end_date
.empty()) {
5443 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5445 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5449 if (!start_date
.empty()) {
5450 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5452 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5457 bool is_truncated
= true;
5459 rgw_obj_index_key marker
;
5462 formatter
->open_object_section("result");
5463 formatter
->dump_string("bucket", bucket_name
);
5464 formatter
->open_array_section("objects");
5465 while (is_truncated
) {
5466 map
<string
, rgw_bucket_dir_entry
> result
;
5467 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5468 result
, &is_truncated
, &marker
,
5469 bucket_object_check_filter
);
5471 if (r
< 0 && r
!= -ENOENT
) {
5472 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5478 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5479 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5480 rgw_obj_key key
= iter
->second
.key
;
5481 rgw_bucket_dir_entry
& entry
= iter
->second
;
5483 formatter
->open_object_section("object");
5484 formatter
->dump_string("name", key
.name
);
5485 formatter
->dump_string("instance", key
.instance
);
5486 formatter
->dump_int("size", entry
.meta
.size
);
5487 utime_t
ut(entry
.meta
.mtime
);
5488 ut
.gmtime(formatter
->dump_stream("mtime"));
5490 if ((entry
.meta
.size
< min_rewrite_size
) ||
5491 (entry
.meta
.size
> max_rewrite_size
) ||
5492 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5493 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5494 formatter
->dump_string("status", "Skipped");
5496 rgw_obj
obj(bucket
, key
);
5498 bool need_rewrite
= true;
5499 if (min_rewrite_stripe_size
> 0) {
5500 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5502 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5505 if (!need_rewrite
) {
5506 formatter
->dump_string("status", "Skipped");
5508 r
= store
->rewrite_obj(bucket_info
, obj
);
5510 formatter
->dump_string("status", "Success");
5512 formatter
->dump_string("status", cpp_strerror(-r
));
5516 formatter
->dump_int("flags", entry
.flags
);
5518 formatter
->close_section();
5519 formatter
->flush(cout
);
5522 formatter
->close_section();
5523 formatter
->close_section();
5524 formatter
->flush(cout
);
5527 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5529 RGWBucketInfo bucket_info
;
5530 map
<string
, bufferlist
> attrs
;
5532 int ret
= check_reshard_bucket_params(store
,
5536 num_shards_specified
,
5538 yes_i_really_mean_it
,
5546 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5548 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5549 if (max_entries
< 1) {
5550 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5553 return br
.execute(num_shards
, max_entries
,
5554 verbose
, &cout
, formatter
);
5557 if (opt_cmd
== OPT_RESHARD_ADD
) {
5559 RGWBucketInfo bucket_info
;
5560 map
<string
, bufferlist
> attrs
;
5562 int ret
= check_reshard_bucket_params(store
,
5566 num_shards_specified
,
5568 yes_i_really_mean_it
,
5576 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5578 RGWReshard
reshard(store
);
5579 cls_rgw_reshard_entry entry
;
5580 entry
.time
= real_clock::now();
5581 entry
.tenant
= tenant
;
5582 entry
.bucket_name
= bucket_name
;
5583 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5584 entry
.old_num_shards
= num_source_shards
;
5585 entry
.new_num_shards
= num_shards
;
5587 return reshard
.add(entry
);
5590 if (opt_cmd
== OPT_RESHARD_LIST
) {
5591 list
<cls_rgw_reshard_entry
> entries
;
5594 if (max_entries
< 0) {
5598 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5600 RGWReshard
reshard(store
);
5602 formatter
->open_array_section("reshard");
5603 for (int i
= 0; i
< num_logshards
; i
++) {
5604 bool is_truncated
= true;
5608 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5610 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5613 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5614 cls_rgw_reshard_entry
& entry
= *iter
;
5615 encode_json("entry", entry
, formatter
);
5616 entry
.get_key(&marker
);
5618 count
+= entries
.size();
5619 formatter
->flush(cout
);
5620 } while (is_truncated
&& count
< max_entries
);
5622 if (count
>= max_entries
) {
5627 formatter
->close_section();
5628 formatter
->flush(cout
);
5633 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5634 if (bucket_name
.empty()) {
5635 cerr
<< "ERROR: bucket not specified" << std::endl
;
5640 RGWBucketInfo bucket_info
;
5641 map
<string
, bufferlist
> attrs
;
5642 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5644 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5648 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5649 list
<cls_rgw_bucket_instance_entry
> status
;
5650 int r
= br
.get_status(&status
);
5652 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5656 encode_json("status", status
, formatter
);
5657 formatter
->flush(cout
);
5660 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5661 RGWReshard
reshard(store
, true, &cout
);
5663 int ret
= reshard
.process_all_logshards();
5665 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
5670 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
5671 RGWReshard
reshard(store
);
5673 if (bucket_name
.empty()) {
5674 cerr
<< "ERROR: bucket not specified" << std::endl
;
5677 cls_rgw_reshard_entry entry
;
5678 //entry.tenant = tenant;
5679 entry
.bucket_name
= bucket_name
;
5680 //entry.bucket_id = bucket_id;
5681 int ret
= reshard
.get(entry
);
5683 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5687 /* TBD stop running resharding */
5689 ret
=reshard
.remove(entry
);
5691 cerr
<< "Error removing bucket " << bucket_name
<< " for resharding queue: " << cpp_strerror(-ret
) <<
5697 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
5698 RGWBucketInfo bucket_info
;
5699 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5701 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5704 list
<rgw_obj_index_key
> oid_list
;
5705 rgw_obj_key
key(object
, object_version
);
5706 rgw_obj_index_key index_key
;
5707 key
.get_index_key(&index_key
);
5708 oid_list
.push_back(index_key
);
5709 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
5711 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
5716 if (opt_cmd
== OPT_OBJECT_STAT
) {
5717 RGWBucketInfo bucket_info
;
5718 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5720 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5723 rgw_obj
obj(bucket
, object
);
5724 obj
.key
.set_instance(object_version
);
5727 map
<string
, bufferlist
> attrs
;
5728 RGWObjectCtx
obj_ctx(store
);
5729 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
5730 RGWRados::Object::Read
read_op(&op_target
);
5732 read_op
.params
.attrs
= &attrs
;
5733 read_op
.params
.obj_size
= &obj_size
;
5735 ret
= read_op
.prepare();
5737 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
5740 formatter
->open_object_section("object_metadata");
5741 formatter
->dump_string("name", object
);
5742 formatter
->dump_unsigned("size", obj_size
);
5744 map
<string
, bufferlist
>::iterator iter
;
5745 map
<string
, bufferlist
> other_attrs
;
5746 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5747 bufferlist
& bl
= iter
->second
;
5748 bool handled
= false;
5749 if (iter
->first
== RGW_ATTR_MANIFEST
) {
5750 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
5751 } else if (iter
->first
== RGW_ATTR_ACL
) {
5752 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
5753 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
5754 handled
= dump_string("tag", bl
, formatter
);
5755 } else if (iter
->first
== RGW_ATTR_ETAG
) {
5756 handled
= dump_string("etag", bl
, formatter
);
5760 other_attrs
[iter
->first
] = bl
;
5763 formatter
->open_object_section("attrs");
5764 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
5765 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
5767 formatter
->close_section();
5768 formatter
->close_section();
5769 formatter
->flush(cout
);
5772 if (opt_cmd
== OPT_BUCKET_CHECK
) {
5773 if (check_head_obj_locator
) {
5774 if (bucket_name
.empty()) {
5775 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
5778 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
5780 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
5784 if (opt_cmd
== OPT_BUCKET_RM
) {
5785 if (inconsistent_index
== false) {
5786 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
5788 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
5792 if (opt_cmd
== OPT_GC_LIST
) {
5795 formatter
->open_array_section("entries");
5798 list
<cls_rgw_gc_obj_info
> result
;
5799 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
5801 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5806 list
<cls_rgw_gc_obj_info
>::iterator iter
;
5807 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5808 cls_rgw_gc_obj_info
& info
= *iter
;
5809 formatter
->open_object_section("chain_info");
5810 formatter
->dump_string("tag", info
.tag
);
5811 formatter
->dump_stream("time") << info
.time
;
5812 formatter
->open_array_section("objs");
5813 list
<cls_rgw_obj
>::iterator liter
;
5814 cls_rgw_obj_chain
& chain
= info
.chain
;
5815 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
5816 cls_rgw_obj
& obj
= *liter
;
5817 encode_json("obj", obj
, formatter
);
5819 formatter
->close_section(); // objs
5820 formatter
->close_section(); // obj_chain
5821 formatter
->flush(cout
);
5823 } while (truncated
);
5824 formatter
->close_section();
5825 formatter
->flush(cout
);
5828 if (opt_cmd
== OPT_GC_PROCESS
) {
5829 int ret
= store
->process_gc();
5831 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5836 if (opt_cmd
== OPT_LC_LIST
) {
5837 formatter
->open_array_section("lifecycle_list");
5838 map
<string
, int> bucket_lc_map
;
5840 #define MAX_LC_LIST_ENTRIES 100
5841 if (max_entries
< 0) {
5842 max_entries
= MAX_LC_LIST_ENTRIES
;
5845 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
5847 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5850 map
<string
, int>::iterator iter
;
5851 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
5852 formatter
->open_object_section("bucket_lc_info");
5853 formatter
->dump_string("bucket", iter
->first
);
5854 string lc_status
= LC_STATUS
[iter
->second
];
5855 formatter
->dump_string("status", lc_status
);
5856 formatter
->close_section(); // objs
5857 formatter
->flush(cout
);
5858 marker
= iter
->first
;
5860 } while (!bucket_lc_map
.empty());
5862 formatter
->close_section(); //lifecycle list
5863 formatter
->flush(cout
);
5867 if (opt_cmd
== OPT_LC_PROCESS
) {
5868 int ret
= store
->process_lc();
5870 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5875 if (opt_cmd
== OPT_ORPHANS_FIND
) {
5876 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5878 if (job_id
.empty()) {
5879 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5882 if (pool_name
.empty()) {
5883 cerr
<< "ERROR: --pool not specified" << std::endl
;
5887 RGWOrphanSearchInfo info
;
5890 info
.job_name
= job_id
;
5891 info
.num_shards
= num_shards
;
5893 int ret
= search
.init(job_id
, &info
);
5895 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
5904 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
5905 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5907 if (job_id
.empty()) {
5908 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5911 int ret
= search
.init(job_id
, NULL
);
5913 if (ret
== -ENOENT
) {
5914 cerr
<< "job not found" << std::endl
;
5918 ret
= search
.finish();
5924 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
5925 RGWOrphanStore
orphan_store(store
);
5926 int ret
= orphan_store
.init();
5928 cerr
<< "connection to cluster failed!" << std::endl
;
5932 map
<string
,RGWOrphanSearchState
> m
;
5933 ret
= orphan_store
.list_jobs(m
);
5935 cerr
<< "job list failed" << std::endl
;
5938 formatter
->open_array_section("entries");
5939 for (const auto &it
: m
){
5941 formatter
->dump_string("job-id",it
.first
);
5943 encode_json("orphan_search_state", it
.second
, formatter
);
5946 formatter
->close_section();
5947 formatter
->flush(cout
);
5950 if (opt_cmd
== OPT_USER_CHECK
) {
5951 check_bad_user_bucket_mapping(store
, user_id
, fix
);
5954 if (opt_cmd
== OPT_USER_STATS
) {
5956 if (!bucket_name
.empty()) {
5957 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
5959 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
5963 int ret
= rgw_user_sync_all_stats(store
, user_id
);
5965 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
5971 if (user_id
.empty()) {
5972 cerr
<< "ERROR: uid not specified" << std::endl
;
5975 cls_user_header header
;
5976 string user_str
= user_id
.to_str();
5977 int ret
= store
->cls_user_get_header(user_str
, &header
);
5979 if (ret
== -ENOENT
) { /* in case of ENOENT */
5980 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
5982 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
5987 encode_json("header", header
, formatter
);
5988 formatter
->flush(cout
);
5991 if (opt_cmd
== OPT_METADATA_GET
) {
5992 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
5994 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
5998 formatter
->flush(cout
);
6001 if (opt_cmd
== OPT_METADATA_PUT
) {
6003 int ret
= read_input(infile
, bl
);
6005 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6008 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6010 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6015 if (opt_cmd
== OPT_METADATA_RM
) {
6016 int ret
= store
->meta_mgr
->remove(metadata_key
);
6018 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6023 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6024 if (opt_cmd
== OPT_USER_LIST
) {
6025 metadata_key
= "user";
6029 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
6031 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6037 formatter
->open_array_section("keys");
6041 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, keys
, &truncated
);
6042 if (ret
< 0 && ret
!= -ENOENT
) {
6043 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6045 } if (ret
!= -ENOENT
) {
6046 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6047 formatter
->dump_string("key", *iter
);
6049 formatter
->flush(cout
);
6051 } while (truncated
);
6053 formatter
->close_section();
6054 formatter
->flush(cout
);
6056 store
->meta_mgr
->list_keys_complete(handle
);
6059 if (opt_cmd
== OPT_MDLOG_LIST
) {
6060 utime_t start_time
, end_time
;
6062 int ret
= parse_date_str(start_date
, start_time
);
6066 ret
= parse_date_str(end_date
, end_time
);
6070 int i
= (specified_shard_id
? shard_id
: 0);
6072 if (period_id
.empty()) {
6073 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6077 std::cerr
<< "No --period given, using current period="
6078 << period_id
<< std::endl
;
6080 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6082 formatter
->open_array_section("entries");
6083 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6085 list
<cls_log_entry
> entries
;
6088 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6091 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6093 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6097 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6098 cls_log_entry
& entry
= *iter
;
6099 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6101 formatter
->flush(cout
);
6102 } while (truncated
);
6104 meta_log
->complete_list_entries(handle
);
6106 if (specified_shard_id
)
6111 formatter
->close_section();
6112 formatter
->flush(cout
);
6115 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6116 int i
= (specified_shard_id
? shard_id
: 0);
6118 if (period_id
.empty()) {
6119 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6123 std::cerr
<< "No --period given, using current period="
6124 << period_id
<< std::endl
;
6126 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6128 formatter
->open_array_section("entries");
6130 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6131 RGWMetadataLogInfo info
;
6132 meta_log
->get_info(i
, &info
);
6134 ::encode_json("info", info
, formatter
);
6136 if (specified_shard_id
)
6141 formatter
->close_section();
6142 formatter
->flush(cout
);
6145 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6146 // need a full history for purging old mdlog periods
6147 store
->meta_mgr
->init_oldest_log_period();
6149 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6150 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6151 int ret
= http
.set_threaded();
6153 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6157 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6158 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6160 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6165 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6166 utime_t start_time
, end_time
;
6168 if (!specified_shard_id
) {
6169 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6173 int ret
= parse_date_str(start_date
, start_time
);
6177 ret
= parse_date_str(end_date
, end_time
);
6181 if (period_id
.empty()) {
6182 std::cerr
<< "missing --period argument" << std::endl
;
6185 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6187 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6189 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6194 if (opt_cmd
== OPT_SYNC_STATUS
) {
6195 sync_status(formatter
);
6198 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6199 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6201 int ret
= sync
.init();
6203 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6207 rgw_meta_sync_status sync_status
;
6208 ret
= sync
.read_sync_status(&sync_status
);
6210 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6214 formatter
->open_object_section("summary");
6215 encode_json("sync_status", sync_status
, formatter
);
6217 uint64_t full_total
= 0;
6218 uint64_t full_complete
= 0;
6220 for (auto marker_iter
: sync_status
.sync_markers
) {
6221 full_total
+= marker_iter
.second
.total_entries
;
6222 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6223 full_complete
+= marker_iter
.second
.pos
;
6225 full_complete
+= marker_iter
.second
.total_entries
;
6229 formatter
->open_object_section("full_sync");
6230 encode_json("total", full_total
, formatter
);
6231 encode_json("complete", full_complete
, formatter
);
6232 formatter
->close_section();
6233 formatter
->close_section();
6235 formatter
->flush(cout
);
6239 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6240 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6242 int ret
= sync
.init();
6244 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6247 ret
= sync
.init_sync_status();
6249 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6255 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6256 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6258 int ret
= sync
.init();
6260 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6266 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6271 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6272 if (source_zone
.empty()) {
6273 cerr
<< "ERROR: source zone not specified" << std::endl
;
6276 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6278 int ret
= sync
.init();
6280 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6284 rgw_data_sync_status sync_status
;
6285 ret
= sync
.read_sync_status(&sync_status
);
6286 if (ret
< 0 && ret
!= -ENOENT
) {
6287 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6291 formatter
->open_object_section("summary");
6292 encode_json("sync_status", sync_status
, formatter
);
6294 uint64_t full_total
= 0;
6295 uint64_t full_complete
= 0;
6297 for (auto marker_iter
: sync_status
.sync_markers
) {
6298 full_total
+= marker_iter
.second
.total_entries
;
6299 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6300 full_complete
+= marker_iter
.second
.pos
;
6302 full_complete
+= marker_iter
.second
.total_entries
;
6306 formatter
->open_object_section("full_sync");
6307 encode_json("total", full_total
, formatter
);
6308 encode_json("complete", full_complete
, formatter
);
6309 formatter
->close_section();
6310 formatter
->close_section();
6312 formatter
->flush(cout
);
6315 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6316 if (source_zone
.empty()) {
6317 cerr
<< "ERROR: source zone not specified" << std::endl
;
6320 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6322 int ret
= sync
.init();
6324 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6328 ret
= sync
.init_sync_status();
6330 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6335 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6336 if (source_zone
.empty()) {
6337 cerr
<< "ERROR: source zone not specified" << std::endl
;
6340 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6342 int ret
= sync
.init();
6344 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6350 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6355 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6356 if (source_zone
.empty()) {
6357 cerr
<< "ERROR: source zone not specified" << std::endl
;
6360 if (bucket_name
.empty()) {
6361 cerr
<< "ERROR: bucket not specified" << std::endl
;
6365 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6369 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6373 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6376 ret
= sync
.init_sync_status();
6378 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6383 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6384 if (source_zone
.empty()) {
6385 cerr
<< "ERROR: source zone not specified" << std::endl
;
6388 if (bucket_name
.empty()) {
6389 cerr
<< "ERROR: bucket not specified" << std::endl
;
6393 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6397 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6401 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6404 ret
= sync
.read_sync_status();
6406 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6410 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6412 encode_json("sync_status", sync_status
, formatter
);
6413 formatter
->flush(cout
);
6416 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6417 if (source_zone
.empty()) {
6418 cerr
<< "ERROR: source zone not specified" << std::endl
;
6421 if (bucket_name
.empty()) {
6422 cerr
<< "ERROR: bucket not specified" << std::endl
;
6426 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6430 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6434 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6440 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6445 if (opt_cmd
== OPT_BILOG_LIST
) {
6446 if (bucket_name
.empty()) {
6447 cerr
<< "ERROR: bucket not specified" << std::endl
;
6450 RGWBucketInfo bucket_info
;
6451 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6453 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6456 formatter
->open_array_section("entries");
6459 if (max_entries
< 0)
6463 list
<rgw_bi_log_entry
> entries
;
6464 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6466 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6470 count
+= entries
.size();
6472 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6473 rgw_bi_log_entry
& entry
= *iter
;
6474 encode_json("entry", entry
, formatter
);
6478 formatter
->flush(cout
);
6479 } while (truncated
&& count
< max_entries
);
6481 formatter
->close_section();
6482 formatter
->flush(cout
);
6485 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6486 if (max_entries
< 0) {
6491 utime_t start_time
, end_time
;
6493 int ret
= parse_date_str(start_date
, start_time
);
6497 ret
= parse_date_str(end_date
, end_time
);
6505 formatter
->open_array_section("entries");
6507 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6508 formatter
->open_object_section("shard");
6509 encode_json("shard_id", shard_id
, formatter
);
6510 formatter
->open_array_section("entries");
6513 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6516 list
<cls_log_entry
> entries
;
6517 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6518 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6519 if (ret
== -ENOENT
) {
6523 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6527 count
+= entries
.size();
6529 for (auto& cls_entry
: entries
) {
6530 rgw_sync_error_info log_entry
;
6532 auto iter
= cls_entry
.data
.begin();
6534 ::decode(log_entry
, iter
);
6535 } catch (buffer::error
& err
) {
6536 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6539 formatter
->open_object_section("entry");
6540 encode_json("id", cls_entry
.id
, formatter
);
6541 encode_json("section", cls_entry
.section
, formatter
);
6542 encode_json("name", cls_entry
.name
, formatter
);
6543 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
6544 encode_json("info", log_entry
, formatter
);
6545 formatter
->close_section();
6546 formatter
->flush(cout
);
6548 } while (truncated
&& count
< max_entries
);
6550 formatter
->close_section();
6551 formatter
->close_section();
6553 if (specified_shard_id
) {
6558 formatter
->close_section();
6559 formatter
->flush(cout
);
6562 if (opt_cmd
== OPT_BILOG_TRIM
) {
6563 if (bucket_name
.empty()) {
6564 cerr
<< "ERROR: bucket not specified" << std::endl
;
6567 RGWBucketInfo bucket_info
;
6568 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6570 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6573 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
6575 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6580 if (opt_cmd
== OPT_BILOG_STATUS
) {
6581 if (bucket_name
.empty()) {
6582 cerr
<< "ERROR: bucket not specified" << std::endl
;
6585 RGWBucketInfo bucket_info
;
6586 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6588 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6591 map
<int, string
> markers
;
6592 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
6594 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
6597 formatter
->open_object_section("entries");
6598 encode_json("markers", markers
, formatter
);
6599 formatter
->close_section();
6600 formatter
->flush(cout
);
6603 if (opt_cmd
== OPT_DATALOG_LIST
) {
6604 formatter
->open_array_section("entries");
6607 if (max_entries
< 0)
6610 utime_t start_time
, end_time
;
6612 int ret
= parse_date_str(start_date
, start_time
);
6616 ret
= parse_date_str(end_date
, end_time
);
6620 RGWDataChangesLog
*log
= store
->data_log
;
6621 RGWDataChangesLog::LogMarker marker
;
6624 list
<rgw_data_change_log_entry
> entries
;
6625 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
6627 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6631 count
+= entries
.size();
6633 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6634 rgw_data_change_log_entry
& entry
= *iter
;
6636 encode_json("entry", entry
.entry
, formatter
);
6638 encode_json("entry", entry
, formatter
);
6641 formatter
->flush(cout
);
6642 } while (truncated
&& count
< max_entries
);
6644 formatter
->close_section();
6645 formatter
->flush(cout
);
6648 if (opt_cmd
== OPT_DATALOG_STATUS
) {
6649 RGWDataChangesLog
*log
= store
->data_log
;
6650 int i
= (specified_shard_id
? shard_id
: 0);
6652 formatter
->open_array_section("entries");
6653 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
6654 list
<cls_log_entry
> entries
;
6656 RGWDataChangesLogInfo info
;
6657 log
->get_info(i
, &info
);
6659 ::encode_json("info", info
, formatter
);
6661 if (specified_shard_id
)
6665 formatter
->close_section();
6666 formatter
->flush(cout
);
6669 if (opt_cmd
== OPT_DATALOG_TRIM
) {
6670 utime_t start_time
, end_time
;
6672 int ret
= parse_date_str(start_date
, start_time
);
6676 ret
= parse_date_str(end_date
, end_time
);
6680 RGWDataChangesLog
*log
= store
->data_log
;
6681 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6683 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
6688 if (opt_cmd
== OPT_OPSTATE_LIST
) {
6689 RGWOpState
oc(store
);
6694 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
6695 list
<cls_statelog_entry
> entries
;
6697 formatter
->open_array_section("entries");
6699 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
6701 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
6702 oc
.finish_list_entries(handle
);
6706 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6707 oc
.dump_entry(*iter
, formatter
);
6710 formatter
->flush(cout
);
6712 formatter
->close_section();
6713 formatter
->flush(cout
);
6714 oc
.finish_list_entries(handle
);
6717 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
6718 RGWOpState
oc(store
);
6720 RGWOpState::OpState state
;
6721 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6722 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6725 if (state_str
.empty()) {
6726 cerr
<< "ERROR: state was not specified" << std::endl
;
6729 int ret
= oc
.state_from_str(state_str
, &state
);
6731 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
6735 if (opt_cmd
== OPT_OPSTATE_SET
) {
6736 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
6738 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6742 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
6744 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
6749 if (opt_cmd
== OPT_OPSTATE_RM
) {
6750 RGWOpState
oc(store
);
6752 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6753 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6756 ret
= oc
.remove_entry(client_id
, op_id
, object
);
6758 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6763 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
6764 opt_cmd
== OPT_REPLICALOG_DELETE
) {
6765 if (replica_log_type_str
.empty()) {
6766 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
6771 if (opt_cmd
== OPT_REPLICALOG_GET
) {
6772 RGWReplicaBounds bounds
;
6773 if (replica_log_type
== ReplicaLog_Metadata
) {
6774 if (!specified_shard_id
) {
6775 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6779 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6780 int ret
= logger
.get_bounds(shard_id
, bounds
);
6783 } else if (replica_log_type
== ReplicaLog_Data
) {
6784 if (!specified_shard_id
) {
6785 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6788 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6789 int ret
= logger
.get_bounds(shard_id
, bounds
);
6792 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6793 if (bucket_name
.empty()) {
6794 cerr
<< "ERROR: bucket not specified" << std::endl
;
6797 RGWBucketInfo bucket_info
;
6798 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6800 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6804 RGWReplicaBucketLogger
logger(store
);
6805 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
6808 } else { // shouldn't get here
6811 encode_json("bounds", bounds
, formatter
);
6812 formatter
->flush(cout
);
6816 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
6817 if (replica_log_type
== ReplicaLog_Metadata
) {
6818 if (!specified_shard_id
) {
6819 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6822 if (!specified_daemon_id
) {
6823 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6826 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6827 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6830 } else if (replica_log_type
== ReplicaLog_Data
) {
6831 if (!specified_shard_id
) {
6832 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6835 if (!specified_daemon_id
) {
6836 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6839 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6840 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6843 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6844 if (bucket_name
.empty()) {
6845 cerr
<< "ERROR: bucket not specified" << std::endl
;
6848 RGWBucketInfo bucket_info
;
6849 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6851 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6855 RGWReplicaBucketLogger
logger(store
);
6856 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
6862 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
6863 if (marker
.empty()) {
6864 cerr
<< "ERROR: marker was not specified" <<std::endl
;
6867 utime_t time
= ceph_clock_now();
6868 if (!date
.empty()) {
6869 ret
= parse_date_str(date
, time
);
6871 cerr
<< "ERROR: failed to parse start date" << std::endl
;
6875 list
<RGWReplicaItemMarker
> entries
;
6876 int ret
= read_decode_json(infile
, entries
);
6878 cerr
<< "ERROR: failed to decode entries" << std::endl
;
6881 RGWReplicaBounds bounds
;
6882 if (replica_log_type
== ReplicaLog_Metadata
) {
6883 if (!specified_shard_id
) {
6884 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6888 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6889 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6891 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6894 } else if (replica_log_type
== ReplicaLog_Data
) {
6895 if (!specified_shard_id
) {
6896 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6899 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6900 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
6902 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6905 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6906 if (bucket_name
.empty()) {
6907 cerr
<< "ERROR: bucket not specified" << std::endl
;
6910 RGWBucketInfo bucket_info
;
6911 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6913 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6917 RGWReplicaBucketLogger
logger(store
);
6918 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
6920 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
6926 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
6929 if (bucket_name
.empty() && user_id
.empty()) {
6930 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
6934 if (!bucket_name
.empty()) {
6935 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
6936 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
6939 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
6940 max_size
, max_objects
, have_max_size
, have_max_objects
);
6941 } else if (!user_id
.empty()) {
6942 if (quota_scope
== "bucket") {
6943 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
6944 } else if (quota_scope
== "user") {
6945 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
6947 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;