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"
12 #include "compressor/Compressor.h"
14 #include "common/armor.h"
15 #include "common/ceph_json.h"
16 #include "common/config.h"
17 #include "common/ceph_argparse.h"
18 #include "common/Formatter.h"
19 #include "common/errno.h"
20 #include "common/safe_io.h"
22 #include "cls/rgw/cls_rgw_client.h"
24 #include "global/global_init.h"
26 #include "include/utime.h"
27 #include "include/str_list.h"
30 #include "rgw_bucket.h"
31 #include "rgw_rados.h"
33 #include "rgw_acl_s3.h"
36 #include "rgw_formats.h"
37 #include "rgw_usage.h"
38 #include "rgw_replica_log.h"
39 #include "rgw_orphan.h"
41 #include "rgw_sync_log_trim.h"
42 #include "rgw_data_sync.h"
43 #include "rgw_rest_conn.h"
44 #include "rgw_realm_watcher.h"
46 #include "rgw_reshard.h"
50 #define dout_context g_ceph_context
51 #define dout_subsys ceph_subsys_rgw
53 #define SECRET_KEY_LEN 40
54 #define PUBLIC_ID_LEN 20
56 static RGWRados
*store
= NULL
;
60 cout
<< "usage: radosgw-admin <cmd> [options...]" << std::endl
;
61 cout
<< "commands:\n";
62 cout
<< " user create create a new user\n" ;
63 cout
<< " user modify modify user\n";
64 cout
<< " user info get user info\n";
65 cout
<< " user rm remove user\n";
66 cout
<< " user suspend suspend a user\n";
67 cout
<< " user enable re-enable user after suspension\n";
68 cout
<< " user check check user info\n";
69 cout
<< " user stats show user stats as accounted by quota subsystem\n";
70 cout
<< " user list list users\n";
71 cout
<< " caps add add user capabilities\n";
72 cout
<< " caps rm remove user capabilities\n";
73 cout
<< " subuser create create a new subuser\n" ;
74 cout
<< " subuser modify modify subuser\n";
75 cout
<< " subuser rm remove subuser\n";
76 cout
<< " key create create access key\n";
77 cout
<< " key rm remove access key\n";
78 cout
<< " bucket list list buckets\n";
79 cout
<< " bucket limit check show bucket sharding stats\n";
80 cout
<< " bucket link link bucket to specified user\n";
81 cout
<< " bucket unlink unlink bucket from specified user\n";
82 cout
<< " bucket stats returns bucket statistics\n";
83 cout
<< " bucket rm remove bucket\n";
84 cout
<< " bucket check check bucket index\n";
85 cout
<< " bucket reshard reshard bucket\n";
86 cout
<< " bucket sync disable disable bucket sync\n";
87 cout
<< " bucket sync enable enable bucket sync\n";
88 cout
<< " bi get retrieve bucket index object entries\n";
89 cout
<< " bi put store bucket index object entries\n";
90 cout
<< " bi list list raw bucket index entries\n";
91 cout
<< " object rm remove object\n";
92 cout
<< " object stat stat an object for its metadata\n";
93 cout
<< " object unlink unlink object from bucket index\n";
94 cout
<< " objects expire run expired objects cleanup\n";
95 cout
<< " period delete delete a period\n";
96 cout
<< " period get get period info\n";
97 cout
<< " period get-current get current period info\n";
98 cout
<< " period pull pull a period\n";
99 cout
<< " period push push a period\n";
100 cout
<< " period list list all periods\n";
101 cout
<< " period update update the staging period\n";
102 cout
<< " period commit commit the staging period\n";
103 cout
<< " quota set set quota params\n";
104 cout
<< " quota enable enable quota\n";
105 cout
<< " quota disable disable quota\n";
106 cout
<< " global quota get view global quota params\n";
107 cout
<< " global quota set set global quota params\n";
108 cout
<< " global quota enable enable a global quota\n";
109 cout
<< " global quota disable disable a global quota\n";
110 cout
<< " realm create create a new realm\n";
111 cout
<< " realm delete delete a realm\n";
112 cout
<< " realm get show realm info\n";
113 cout
<< " realm get-default get default realm name\n";
114 cout
<< " realm list list realms\n";
115 cout
<< " realm list-periods list all realm periods\n";
116 cout
<< " realm remove remove a zonegroup from the realm\n";
117 cout
<< " realm rename rename a realm\n";
118 cout
<< " realm set set realm info (requires infile)\n";
119 cout
<< " realm default set realm as default\n";
120 cout
<< " realm pull pull a realm and its current period\n";
121 cout
<< " zonegroup add add a zone to a zonegroup\n";
122 cout
<< " zonegroup create create a new zone group info\n";
123 cout
<< " zonegroup default set default zone group\n";
124 cout
<< " zonegroup delete delete a zone group info\n";
125 cout
<< " zonegroup get show zone group info\n";
126 cout
<< " zonegroup modify modify an existing zonegroup\n";
127 cout
<< " zonegroup set set zone group info (requires infile)\n";
128 cout
<< " zonegroup remove remove a zone from a zonegroup\n";
129 cout
<< " zonegroup rename rename a zone group\n";
130 cout
<< " zonegroup list list all zone groups set on this cluster\n";
131 cout
<< " zonegroup placement list list zonegroup's placement targets\n";
132 cout
<< " zonegroup placement add add a placement target id to a zonegroup\n";
133 cout
<< " zonegroup placement modify modify a placement target of a specific zonegroup\n";
134 cout
<< " zonegroup placement rm remove a placement target from a zonegroup\n";
135 cout
<< " zonegroup placement default set a zonegroup's default placement target\n";
136 cout
<< " zone create create a new zone\n";
137 cout
<< " zone delete delete a zone\n";
138 cout
<< " zone get show zone cluster params\n";
139 cout
<< " zone modify modify an existing zone\n";
140 cout
<< " zone set set zone cluster params (requires infile)\n";
141 cout
<< " zone list list all zones set on this cluster\n";
142 cout
<< " zone rename rename a zone\n";
143 cout
<< " zone placement list list zone's placement targets\n";
144 cout
<< " zone placement add add a zone placement target\n";
145 cout
<< " zone placement modify modify a zone placement target\n";
146 cout
<< " zone placement rm remove a zone placement target\n";
147 cout
<< " pool add add an existing pool for data placement\n";
148 cout
<< " pool rm remove an existing pool from data placement set\n";
149 cout
<< " pools list list placement active set\n";
150 cout
<< " policy read bucket/object policy\n";
151 cout
<< " log list list log objects\n";
152 cout
<< " log show dump a log from specific object or (bucket + date\n";
153 cout
<< " + bucket-id)\n";
154 cout
<< " (NOTE: required to specify formatting of date\n";
155 cout
<< " to \"YYYY-MM-DD-hh\")\n";
156 cout
<< " log rm remove log object\n";
157 cout
<< " usage show show usage (by user, date range)\n";
158 cout
<< " usage trim trim usage (by user, date range)\n";
159 cout
<< " gc list dump expired garbage collection objects (specify\n";
160 cout
<< " --include-all to list all entries, including unexpired)\n";
161 cout
<< " gc process manually process garbage\n";
162 cout
<< " lc list list all bucket lifecycle progress\n";
163 cout
<< " lc process manually process lifecycle\n";
164 cout
<< " metadata get get metadata info\n";
165 cout
<< " metadata put put metadata info\n";
166 cout
<< " metadata rm remove metadata info\n";
167 cout
<< " metadata list list metadata info\n";
168 cout
<< " mdlog list list metadata log\n";
169 cout
<< " mdlog trim trim metadata log (use start-date, end-date or\n";
170 cout
<< " start-marker, end-marker)\n";
171 cout
<< " mdlog status read metadata log status\n";
172 cout
<< " bilog list list bucket index log\n";
173 cout
<< " bilog trim trim bucket index log (use start-marker, end-marker)\n";
174 cout
<< " datalog list list data log\n";
175 cout
<< " datalog trim trim data log\n";
176 cout
<< " datalog status read data log status\n";
177 cout
<< " opstate list list stateful operations entries (use client_id,\n";
178 cout
<< " op_id, object)\n";
179 cout
<< " opstate set set state on an entry (use client_id, op_id, object, state)\n";
180 cout
<< " opstate renew renew state on an entry (use client_id, op_id, object)\n";
181 cout
<< " opstate rm remove entry (use client_id, op_id, object)\n";
182 cout
<< " replicalog get get replica metadata log entry\n";
183 cout
<< " replicalog update update replica metadata log entry\n";
184 cout
<< " replicalog delete delete replica metadata log entry\n";
185 cout
<< " orphans find init and run search for leaked rados objects (use job-id, pool)\n";
186 cout
<< " orphans finish clean up search for leaked rados objects\n";
187 cout
<< " orphans list-jobs list the current job-ids for orphans search\n";
188 cout
<< " role create create a AWS role for use with STS\n";
189 cout
<< " role delete delete a role\n";
190 cout
<< " role get get a role\n";
191 cout
<< " role list list roles with specified path prefix\n";
192 cout
<< " role modify modify the assume role policy of an existing role\n";
193 cout
<< " role-policy put add/update permission policy to role\n";
194 cout
<< " role-policy list list policies attached to a role\n";
195 cout
<< " role-policy get get the specified inline policy document embedded with the given role\n";
196 cout
<< " role-policy delete delete policy attached to a role\n";
197 cout
<< " reshard add schedule a resharding of a bucket\n";
198 cout
<< " reshard list list all bucket resharding or scheduled to be reshared\n";
199 cout
<< " reshard process process of scheduled reshard jobs\n";
200 cout
<< " reshard cancel cancel resharding a bucket\n";
201 cout
<< "options:\n";
202 cout
<< " --tenant=<tenant> tenant name\n";
203 cout
<< " --uid=<id> user id\n";
204 cout
<< " --subuser=<name> subuser name\n";
205 cout
<< " --access-key=<key> S3 access key\n";
206 cout
<< " --email=<email>\n";
207 cout
<< " --secret/--secret-key=<key>\n";
208 cout
<< " specify secret key\n";
209 cout
<< " --gen-access-key generate random access key (for S3)\n";
210 cout
<< " --gen-secret generate random secret key\n";
211 cout
<< " --key-type=<type> key type, options are: swift, s3\n";
212 cout
<< " --temp-url-key[-2]=<key> temp url key\n";
213 cout
<< " --access=<access> Set access permissions for sub-user, should be one\n";
214 cout
<< " of read, write, readwrite, full\n";
215 cout
<< " --display-name=<name>\n";
216 cout
<< " --max-buckets max number of buckets for a user\n";
217 cout
<< " --admin set the admin flag on the user\n";
218 cout
<< " --system set the system flag on the user\n";
219 cout
<< " --bucket=<bucket>\n";
220 cout
<< " --pool=<pool>\n";
221 cout
<< " --object=<object>\n";
222 cout
<< " --date=<date>\n";
223 cout
<< " --start-date=<date>\n";
224 cout
<< " --end-date=<date>\n";
225 cout
<< " --bucket-id=<bucket-id>\n";
226 cout
<< " --shard-id=<shard-id> optional for mdlog list\n";
227 cout
<< " required for: \n";
228 cout
<< " mdlog trim\n";
229 cout
<< " replica mdlog get/delete\n";
230 cout
<< " replica datalog get/delete\n";
231 cout
<< " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
232 cout
<< " --remote=<remote> zone or zonegroup id of remote gateway\n";
233 cout
<< " --period=<id> period id\n";
234 cout
<< " --epoch=<number> period epoch\n";
235 cout
<< " --commit commit the period during 'period update'\n";
236 cout
<< " --staging get staging period info\n";
237 cout
<< " --master set as master\n";
238 cout
<< " --master-url master url\n";
239 cout
<< " --master-zonegroup=<id> master zonegroup id\n";
240 cout
<< " --master-zone=<id> master zone id\n";
241 cout
<< " --rgw-realm=<name> realm name\n";
242 cout
<< " --realm-id=<id> realm id\n";
243 cout
<< " --realm-new-name=<name> realm new name\n";
244 cout
<< " --rgw-zonegroup=<name> zonegroup name\n";
245 cout
<< " --zonegroup-id=<id> zonegroup id\n";
246 cout
<< " --zonegroup-new-name=<name>\n";
247 cout
<< " zonegroup new name\n";
248 cout
<< " --rgw-zone=<name> name of zone in which radosgw is running\n";
249 cout
<< " --zone-id=<id> zone id\n";
250 cout
<< " --zone-new-name=<name> zone new name\n";
251 cout
<< " --source-zone specify the source zone (for data sync)\n";
252 cout
<< " --default set entity (realm, zonegroup, zone) as default\n";
253 cout
<< " --read-only set zone as read-only (when adding to zonegroup)\n";
254 cout
<< " --placement-id placement id for zonegroup placement commands\n";
255 cout
<< " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
256 cout
<< " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
257 cout
<< " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
258 cout
<< " --endpoints=<list> zone endpoints\n";
259 cout
<< " --index-pool=<pool> placement target index pool\n";
260 cout
<< " --data-pool=<pool> placement target data pool\n";
261 cout
<< " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n";
262 cout
<< " --placement-index-type=<type>\n";
263 cout
<< " placement target index type (normal, indexless, or #id)\n";
264 cout
<< " --compression=<type> placement target compression type (plugin name or empty/none)\n";
265 cout
<< " --tier-type=<type> zone tier type\n";
266 cout
<< " --tier-config=<k>=<v>[,...]\n";
267 cout
<< " set zone tier config keys, values\n";
268 cout
<< " --tier-config-rm=<k>[,...]\n";
269 cout
<< " unset zone tier config keys\n";
270 cout
<< " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
271 cout
<< " --sync-from=[zone-name][,...]\n";
272 cout
<< " set list of zones to sync from\n";
273 cout
<< " --sync-from-rm=[zone-name][,...]\n";
274 cout
<< " remove zones from list of zones to sync from\n";
275 cout
<< " --fix besides checking bucket index, will also fix it\n";
276 cout
<< " --check-objects bucket check: rebuilds bucket index according to\n";
277 cout
<< " actual objects state\n";
278 cout
<< " --format=<format> specify output format for certain operations: xml,\n";
280 cout
<< " --purge-data when specified, user removal will also purge all the\n";
281 cout
<< " user data\n";
282 cout
<< " --purge-keys when specified, subuser removal will also purge all the\n";
283 cout
<< " subuser keys\n";
284 cout
<< " --purge-objects remove a bucket's objects before deleting it\n";
285 cout
<< " (NOTE: required to delete a non-empty bucket)\n";
286 cout
<< " --sync-stats option to 'user stats', update user stats with current\n";
287 cout
<< " stats reported by user's buckets indexes\n";
288 cout
<< " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
289 cout
<< " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
290 cout
<< " --skip-zero-entries log show only dumps entries that don't have zero value\n";
291 cout
<< " in one of the numeric field\n";
292 cout
<< " --infile=<file> specify a file to read in when setting data\n";
293 cout
<< " --state=<state string> specify a state for the opstate set command\n";
294 cout
<< " --replica-log-type replica log type (metadata, data, bucket), required for\n";
295 cout
<< " replica log operations\n";
296 cout
<< " --categories=<list> comma separated list of categories, used in usage show\n";
297 cout
<< " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
298 cout
<< " --yes-i-really-mean-it required for certain operations\n";
299 cout
<< " --warnings-only when specified with bucket limit check, list\n";
300 cout
<< " only buckets nearing or over the current max\n";
301 cout
<< " objects per shard value\n";
302 cout
<< " --bypass-gc when specified with bucket deletion, triggers\n";
303 cout
<< " object deletions by not involving GC\n";
304 cout
<< " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
305 cout
<< " ignores bucket index consistency\n";
307 cout
<< "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
308 cout
<< "\nQuota options:\n";
309 cout
<< " --bucket specified bucket for quota command\n";
310 cout
<< " --max-objects specify max objects (negative value to disable)\n";
311 cout
<< " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
312 cout
<< " --quota-scope scope of quota (bucket, user)\n";
313 cout
<< "\nOrphans search options:\n";
314 cout
<< " --pool data pool to scan for leaked rados objects in\n";
315 cout
<< " --num-shards num of shards to use for keeping the temporary scan info\n";
316 cout
<< " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
317 cout
<< " --job-id set the job id (for orphans find)\n";
318 cout
<< " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
319 cout
<< "\nOrphans list-jobs options:\n";
320 cout
<< " --extra-info provide extra info in job list\n";
321 cout
<< "\nRole options:\n";
322 cout
<< " --role-name name of the role to create\n";
323 cout
<< " --path path to the role\n";
324 cout
<< " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
325 cout
<< " --policy-name name of the policy document\n";
326 cout
<< " --policy-doc permission policy document\n";
327 cout
<< " --path-prefix path prefix for filtering roles\n";
329 generic_client_usage();
349 OPT_BUCKET_LIMIT_CHECK
,
354 OPT_BUCKET_SYNC_STATUS
,
355 OPT_BUCKET_SYNC_INIT
,
357 OPT_BUCKET_SYNC_DISABLE
,
358 OPT_BUCKET_SYNC_ENABLE
,
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
,
438 OPT_DATA_SYNC_STATUS
,
449 OPT_REPLICALOG_UPDATE
,
450 OPT_REPLICALOG_DELETE
,
454 OPT_REALM_GET_DEFAULT
,
456 OPT_REALM_LIST_PERIODS
,
464 OPT_PERIOD_GET_CURRENT
,
470 OPT_GLOBAL_QUOTA_GET
,
471 OPT_GLOBAL_QUOTA_SET
,
472 OPT_GLOBAL_QUOTA_ENABLE
,
473 OPT_GLOBAL_QUOTA_DISABLE
,
481 OPT_ROLE_POLICY_LIST
,
483 OPT_ROLE_POLICY_DELETE
,
491 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
494 // NOTE: please keep the checks in alphabetical order !!!
495 if (strcmp(cmd
, "bi") == 0 ||
496 strcmp(cmd
, "bilog") == 0 ||
497 strcmp(cmd
, "buckets") == 0 ||
498 strcmp(cmd
, "caps") == 0 ||
499 strcmp(cmd
, "data") == 0 ||
500 strcmp(cmd
, "datalog") == 0 ||
501 strcmp(cmd
, "error") == 0 ||
502 strcmp(cmd
, "gc") == 0 ||
503 strcmp(cmd
, "global") == 0 ||
504 strcmp(cmd
, "key") == 0 ||
505 strcmp(cmd
, "log") == 0 ||
506 strcmp(cmd
, "lc") == 0 ||
507 strcmp(cmd
, "mdlog") == 0 ||
508 strcmp(cmd
, "metadata") == 0 ||
509 strcmp(cmd
, "object") == 0 ||
510 strcmp(cmd
, "objects") == 0 ||
511 strcmp(cmd
, "olh") == 0 ||
512 strcmp(cmd
, "opstate") == 0 ||
513 strcmp(cmd
, "orphans") == 0 ||
514 strcmp(cmd
, "period") == 0 ||
515 strcmp(cmd
, "placement") == 0 ||
516 strcmp(cmd
, "pool") == 0 ||
517 strcmp(cmd
, "pools") == 0 ||
518 strcmp(cmd
, "quota") == 0 ||
519 strcmp(cmd
, "realm") == 0 ||
520 strcmp(cmd
, "replicalog") == 0 ||
521 strcmp(cmd
, "role") == 0 ||
522 strcmp(cmd
, "role-policy") == 0 ||
523 strcmp(cmd
, "subuser") == 0 ||
524 strcmp(cmd
, "sync") == 0 ||
525 strcmp(cmd
, "usage") == 0 ||
526 strcmp(cmd
, "user") == 0 ||
527 strcmp(cmd
, "zone") == 0 ||
528 strcmp(cmd
, "zonegroup") == 0 ||
529 strcmp(cmd
, "zonegroups") == 0) {
535 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
537 if (strcmp(cmd
, "reshard") == 0 &&
538 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
542 if (strcmp(cmd
, "bucket") == 0 &&
543 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
548 if (strcmp(cmd
, "policy") == 0)
554 if (strcmp(prev_cmd
, "user") == 0) {
555 if (strcmp(cmd
, "create") == 0)
556 return OPT_USER_CREATE
;
557 if (strcmp(cmd
, "info") == 0)
558 return OPT_USER_INFO
;
559 if (strcmp(cmd
, "modify") == 0)
560 return OPT_USER_MODIFY
;
561 if (strcmp(cmd
, "rm") == 0)
563 if (strcmp(cmd
, "suspend") == 0)
564 return OPT_USER_SUSPEND
;
565 if (strcmp(cmd
, "enable") == 0)
566 return OPT_USER_ENABLE
;
567 if (strcmp(cmd
, "check") == 0)
568 return OPT_USER_CHECK
;
569 if (strcmp(cmd
, "stats") == 0)
570 return OPT_USER_STATS
;
571 if (strcmp(cmd
, "list") == 0)
572 return OPT_USER_LIST
;
573 } else if (strcmp(prev_cmd
, "subuser") == 0) {
574 if (strcmp(cmd
, "create") == 0)
575 return OPT_SUBUSER_CREATE
;
576 if (strcmp(cmd
, "modify") == 0)
577 return OPT_SUBUSER_MODIFY
;
578 if (strcmp(cmd
, "rm") == 0)
579 return OPT_SUBUSER_RM
;
580 } else if (strcmp(prev_cmd
, "key") == 0) {
581 if (strcmp(cmd
, "create") == 0)
582 return OPT_KEY_CREATE
;
583 if (strcmp(cmd
, "rm") == 0)
585 } else if (strcmp(prev_cmd
, "buckets") == 0) {
586 if (strcmp(cmd
, "list") == 0)
587 return OPT_BUCKETS_LIST
;
588 } else if (strcmp(prev_cmd
, "bucket") == 0) {
589 if (strcmp(cmd
, "list") == 0)
590 return OPT_BUCKETS_LIST
;
591 if (strcmp(cmd
, "link") == 0)
592 return OPT_BUCKET_LINK
;
593 if (strcmp(cmd
, "unlink") == 0)
594 return OPT_BUCKET_UNLINK
;
595 if (strcmp(cmd
, "stats") == 0)
596 return OPT_BUCKET_STATS
;
597 if (strcmp(cmd
, "rm") == 0)
598 return OPT_BUCKET_RM
;
599 if (strcmp(cmd
, "rewrite") == 0)
600 return OPT_BUCKET_REWRITE
;
601 if (strcmp(cmd
, "reshard") == 0)
602 return OPT_BUCKET_RESHARD
;
603 if (strcmp(cmd
, "check") == 0)
604 return OPT_BUCKET_CHECK
;
605 if (strcmp(cmd
, "sync") == 0) {
609 if (strcmp(cmd
, "limit") == 0) {
613 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
614 if (strcmp(prev_cmd
, "sync") == 0) {
615 if (strcmp(cmd
, "status") == 0)
616 return OPT_BUCKET_SYNC_STATUS
;
617 if (strcmp(cmd
, "init") == 0)
618 return OPT_BUCKET_SYNC_INIT
;
619 if (strcmp(cmd
, "run") == 0)
620 return OPT_BUCKET_SYNC_RUN
;
621 if (strcmp(cmd
, "disable") == 0)
622 return OPT_BUCKET_SYNC_DISABLE
;
623 if (strcmp(cmd
, "enable") == 0)
624 return OPT_BUCKET_SYNC_ENABLE
;
625 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
626 (strcmp(cmd
, "check") == 0)) {
627 return OPT_BUCKET_LIMIT_CHECK
;
629 } else if (strcmp(prev_cmd
, "log") == 0) {
630 if (strcmp(cmd
, "list") == 0)
632 if (strcmp(cmd
, "show") == 0)
634 if (strcmp(cmd
, "rm") == 0)
636 } else if (strcmp(prev_cmd
, "usage") == 0) {
637 if (strcmp(cmd
, "show") == 0)
638 return OPT_USAGE_SHOW
;
639 if (strcmp(cmd
, "trim") == 0)
640 return OPT_USAGE_TRIM
;
641 } else if (strcmp(prev_cmd
, "caps") == 0) {
642 if (strcmp(cmd
, "add") == 0)
644 if (strcmp(cmd
, "rm") == 0)
646 } else if (strcmp(prev_cmd
, "pool") == 0) {
647 if (strcmp(cmd
, "add") == 0)
649 if (strcmp(cmd
, "rm") == 0)
651 if (strcmp(cmd
, "list") == 0)
652 return OPT_POOLS_LIST
;
653 } else if (strcmp(prev_cmd
, "pools") == 0) {
654 if (strcmp(cmd
, "list") == 0)
655 return OPT_POOLS_LIST
;
656 } else if (strcmp(prev_cmd
, "object") == 0) {
657 if (strcmp(cmd
, "rm") == 0)
658 return OPT_OBJECT_RM
;
659 if (strcmp(cmd
, "unlink") == 0)
660 return OPT_OBJECT_UNLINK
;
661 if (strcmp(cmd
, "stat") == 0)
662 return OPT_OBJECT_STAT
;
663 if (strcmp(cmd
, "rewrite") == 0)
664 return OPT_OBJECT_REWRITE
;
665 } else if (strcmp(prev_cmd
, "objects") == 0) {
666 if (strcmp(cmd
, "expire") == 0)
667 return OPT_OBJECTS_EXPIRE
;
668 } else if (strcmp(prev_cmd
, "olh") == 0) {
669 if (strcmp(cmd
, "get") == 0)
671 if (strcmp(cmd
, "readlog") == 0)
672 return OPT_OLH_READLOG
;
673 } else if (strcmp(prev_cmd
, "bi") == 0) {
674 if (strcmp(cmd
, "get") == 0)
676 if (strcmp(cmd
, "put") == 0)
678 if (strcmp(cmd
, "list") == 0)
680 if (strcmp(cmd
, "purge") == 0)
682 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
683 (strcmp(prev_cmd
, "quota") == 0)) {
684 if (strcmp(cmd
, "get") == 0)
685 return OPT_GLOBAL_QUOTA_GET
;
686 if (strcmp(cmd
, "set") == 0)
687 return OPT_GLOBAL_QUOTA_SET
;
688 if (strcmp(cmd
, "enable") == 0)
689 return OPT_GLOBAL_QUOTA_ENABLE
;
690 if (strcmp(cmd
, "disable") == 0)
691 return OPT_GLOBAL_QUOTA_DISABLE
;
692 } else if (strcmp(prev_cmd
, "period") == 0) {
693 if (strcmp(cmd
, "delete") == 0)
694 return OPT_PERIOD_DELETE
;
695 if (strcmp(cmd
, "get") == 0)
696 return OPT_PERIOD_GET
;
697 if (strcmp(cmd
, "get-current") == 0)
698 return OPT_PERIOD_GET_CURRENT
;
699 if (strcmp(cmd
, "pull") == 0)
700 return OPT_PERIOD_PULL
;
701 if (strcmp(cmd
, "push") == 0)
702 return OPT_PERIOD_PUSH
;
703 if (strcmp(cmd
, "list") == 0)
704 return OPT_PERIOD_LIST
;
705 if (strcmp(cmd
, "update") == 0)
706 return OPT_PERIOD_UPDATE
;
707 if (strcmp(cmd
, "commit") == 0)
708 return OPT_PERIOD_COMMIT
;
709 } else if (strcmp(prev_cmd
, "realm") == 0) {
710 if (strcmp(cmd
, "create") == 0)
711 return OPT_REALM_CREATE
;
712 if (strcmp(cmd
, "delete") == 0)
713 return OPT_REALM_DELETE
;
714 if (strcmp(cmd
, "get") == 0)
715 return OPT_REALM_GET
;
716 if (strcmp(cmd
, "get-default") == 0)
717 return OPT_REALM_GET_DEFAULT
;
718 if (strcmp(cmd
, "list") == 0)
719 return OPT_REALM_LIST
;
720 if (strcmp(cmd
, "list-periods") == 0)
721 return OPT_REALM_LIST_PERIODS
;
722 if (strcmp(cmd
, "remove") == 0)
723 return OPT_REALM_REMOVE
;
724 if (strcmp(cmd
, "rename") == 0)
725 return OPT_REALM_RENAME
;
726 if (strcmp(cmd
, "set") == 0)
727 return OPT_REALM_SET
;
728 if (strcmp(cmd
, "default") == 0)
729 return OPT_REALM_DEFAULT
;
730 if (strcmp(cmd
, "pull") == 0)
731 return OPT_REALM_PULL
;
732 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
733 (strcmp(prev_cmd
, "placement") == 0)) {
734 if (strcmp(cmd
, "add") == 0)
735 return OPT_ZONEGROUP_PLACEMENT_ADD
;
736 if (strcmp(cmd
, "modify") == 0)
737 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
738 if (strcmp(cmd
, "rm") == 0)
739 return OPT_ZONEGROUP_PLACEMENT_RM
;
740 if (strcmp(cmd
, "list") == 0)
741 return OPT_ZONEGROUP_PLACEMENT_LIST
;
742 if (strcmp(cmd
, "default") == 0)
743 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
744 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
745 if (strcmp(cmd
, "add") == 0)
746 return OPT_ZONEGROUP_ADD
;
747 if (strcmp(cmd
, "create")== 0)
748 return OPT_ZONEGROUP_CREATE
;
749 if (strcmp(cmd
, "default") == 0)
750 return OPT_ZONEGROUP_DEFAULT
;
751 if (strcmp(cmd
, "delete") == 0)
752 return OPT_ZONEGROUP_DELETE
;
753 if (strcmp(cmd
, "get") == 0)
754 return OPT_ZONEGROUP_GET
;
755 if (strcmp(cmd
, "modify") == 0)
756 return OPT_ZONEGROUP_MODIFY
;
757 if (strcmp(cmd
, "list") == 0)
758 return OPT_ZONEGROUP_LIST
;
759 if (strcmp(cmd
, "set") == 0)
760 return OPT_ZONEGROUP_SET
;
761 if (strcmp(cmd
, "remove") == 0)
762 return OPT_ZONEGROUP_REMOVE
;
763 if (strcmp(cmd
, "rename") == 0)
764 return OPT_ZONEGROUP_RENAME
;
765 } else if (strcmp(prev_cmd
, "quota") == 0) {
766 if (strcmp(cmd
, "set") == 0)
767 return OPT_QUOTA_SET
;
768 if (strcmp(cmd
, "enable") == 0)
769 return OPT_QUOTA_ENABLE
;
770 if (strcmp(cmd
, "disable") == 0)
771 return OPT_QUOTA_DISABLE
;
772 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
773 if (strcmp(cmd
, "list") == 0)
774 return OPT_ZONEGROUP_LIST
;
775 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
776 (strcmp(prev_cmd
, "placement") == 0)) {
777 if (strcmp(cmd
, "add") == 0)
778 return OPT_ZONE_PLACEMENT_ADD
;
779 if (strcmp(cmd
, "modify") == 0)
780 return OPT_ZONE_PLACEMENT_MODIFY
;
781 if (strcmp(cmd
, "rm") == 0)
782 return OPT_ZONE_PLACEMENT_RM
;
783 if (strcmp(cmd
, "list") == 0)
784 return OPT_ZONE_PLACEMENT_LIST
;
785 } else if (strcmp(prev_cmd
, "zone") == 0) {
786 if (strcmp(cmd
, "delete") == 0)
787 return OPT_ZONE_DELETE
;
788 if (strcmp(cmd
, "create") == 0)
789 return OPT_ZONE_CREATE
;
790 if (strcmp(cmd
, "get") == 0)
792 if (strcmp(cmd
, "set") == 0)
794 if (strcmp(cmd
, "list") == 0)
795 return OPT_ZONE_LIST
;
796 if (strcmp(cmd
, "modify") == 0)
797 return OPT_ZONE_MODIFY
;
798 if (strcmp(cmd
, "rename") == 0)
799 return OPT_ZONE_RENAME
;
800 if (strcmp(cmd
, "default") == 0)
801 return OPT_ZONE_DEFAULT
;
802 } else if (strcmp(prev_cmd
, "zones") == 0) {
803 if (strcmp(cmd
, "list") == 0)
804 return OPT_ZONE_LIST
;
805 } else if (strcmp(prev_cmd
, "gc") == 0) {
806 if (strcmp(cmd
, "list") == 0)
808 if (strcmp(cmd
, "process") == 0)
809 return OPT_GC_PROCESS
;
810 } else if (strcmp(prev_cmd
, "lc") == 0) {
811 if (strcmp(cmd
, "list") == 0)
813 if (strcmp(cmd
, "process") == 0)
814 return OPT_LC_PROCESS
;
815 } else if (strcmp(prev_cmd
, "orphans") == 0) {
816 if (strcmp(cmd
, "find") == 0)
817 return OPT_ORPHANS_FIND
;
818 if (strcmp(cmd
, "finish") == 0)
819 return OPT_ORPHANS_FINISH
;
820 if (strcmp(cmd
, "list-jobs") == 0)
821 return OPT_ORPHANS_LIST_JOBS
;
822 } else if (strcmp(prev_cmd
, "metadata") == 0) {
823 if (strcmp(cmd
, "get") == 0)
824 return OPT_METADATA_GET
;
825 if (strcmp(cmd
, "put") == 0)
826 return OPT_METADATA_PUT
;
827 if (strcmp(cmd
, "rm") == 0)
828 return OPT_METADATA_RM
;
829 if (strcmp(cmd
, "list") == 0)
830 return OPT_METADATA_LIST
;
831 if (strcmp(cmd
, "sync") == 0) {
835 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
836 (strcmp(prev_cmd
, "sync") == 0)) {
837 if (strcmp(cmd
, "status") == 0)
838 return OPT_METADATA_SYNC_STATUS
;
839 if (strcmp(cmd
, "init") == 0)
840 return OPT_METADATA_SYNC_INIT
;
841 if (strcmp(cmd
, "run") == 0)
842 return OPT_METADATA_SYNC_RUN
;
843 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
844 (strcmp(prev_cmd
, "error") == 0)) {
845 if (strcmp(cmd
, "list") == 0)
846 return OPT_SYNC_ERROR_LIST
;
847 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
848 if (strcmp(cmd
, "list") == 0)
849 return OPT_MDLOG_LIST
;
850 if (strcmp(cmd
, "autotrim") == 0)
851 return OPT_MDLOG_AUTOTRIM
;
852 if (strcmp(cmd
, "trim") == 0)
853 return OPT_MDLOG_TRIM
;
854 if (strcmp(cmd
, "fetch") == 0)
855 return OPT_MDLOG_FETCH
;
856 if (strcmp(cmd
, "status") == 0)
857 return OPT_MDLOG_STATUS
;
858 } else if (strcmp(prev_cmd
, "bilog") == 0) {
859 if (strcmp(cmd
, "list") == 0)
860 return OPT_BILOG_LIST
;
861 if (strcmp(cmd
, "trim") == 0)
862 return OPT_BILOG_TRIM
;
863 if (strcmp(cmd
, "status") == 0)
864 return OPT_BILOG_STATUS
;
865 if (strcmp(cmd
, "autotrim") == 0)
866 return OPT_BILOG_AUTOTRIM
;
867 } else if (strcmp(prev_cmd
, "data") == 0) {
868 if (strcmp(cmd
, "sync") == 0) {
872 } else if (strcmp(prev_cmd
, "datalog") == 0) {
873 if (strcmp(cmd
, "list") == 0)
874 return OPT_DATALOG_LIST
;
875 if (strcmp(cmd
, "trim") == 0)
876 return OPT_DATALOG_TRIM
;
877 if (strcmp(cmd
, "status") == 0)
878 return OPT_DATALOG_STATUS
;
879 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
880 (strcmp(prev_cmd
, "sync") == 0)) {
881 if (strcmp(cmd
, "status") == 0)
882 return OPT_DATA_SYNC_STATUS
;
883 if (strcmp(cmd
, "init") == 0)
884 return OPT_DATA_SYNC_INIT
;
885 if (strcmp(cmd
, "run") == 0)
886 return OPT_DATA_SYNC_RUN
;
887 } else if (strcmp(prev_cmd
, "opstate") == 0) {
888 if (strcmp(cmd
, "list") == 0)
889 return OPT_OPSTATE_LIST
;
890 if (strcmp(cmd
, "set") == 0)
891 return OPT_OPSTATE_SET
;
892 if (strcmp(cmd
, "renew") == 0)
893 return OPT_OPSTATE_RENEW
;
894 if (strcmp(cmd
, "rm") == 0)
895 return OPT_OPSTATE_RM
;
896 } else if (strcmp(prev_cmd
, "replicalog") == 0) {
897 if (strcmp(cmd
, "get") == 0)
898 return OPT_REPLICALOG_GET
;
899 if (strcmp(cmd
, "update") == 0)
900 return OPT_REPLICALOG_UPDATE
;
901 if (strcmp(cmd
, "delete") == 0)
902 return OPT_REPLICALOG_DELETE
;
903 } else if (strcmp(prev_cmd
, "sync") == 0) {
904 if (strcmp(cmd
, "status") == 0)
905 return OPT_SYNC_STATUS
;
906 } else if (strcmp(prev_cmd
, "role") == 0) {
907 if (strcmp(cmd
, "create") == 0)
908 return OPT_ROLE_CREATE
;
909 if (strcmp(cmd
, "delete") == 0)
910 return OPT_ROLE_DELETE
;
911 if (strcmp(cmd
, "get") == 0)
913 if (strcmp(cmd
, "modify") == 0)
914 return OPT_ROLE_MODIFY
;
915 if (strcmp(cmd
, "list") == 0)
916 return OPT_ROLE_LIST
;
917 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
918 if (strcmp(cmd
, "put") == 0)
919 return OPT_ROLE_POLICY_PUT
;
920 if (strcmp(cmd
, "list") == 0)
921 return OPT_ROLE_POLICY_LIST
;
922 if (strcmp(cmd
, "get") == 0)
923 return OPT_ROLE_POLICY_GET
;
924 if (strcmp(cmd
, "delete") == 0)
925 return OPT_ROLE_POLICY_DELETE
;
926 } else if (strcmp(prev_cmd
, "reshard") == 0) {
927 if (strcmp(cmd
, "bucket") == 0)
928 return OPT_BUCKET_RESHARD
;
929 if (strcmp(cmd
, "add") == 0)
930 return OPT_RESHARD_ADD
;
931 if (strcmp(cmd
, "list") == 0)
932 return OPT_RESHARD_LIST
;
933 if (strcmp(cmd
, "status") == 0)
934 return OPT_RESHARD_STATUS
;
935 if (strcmp(cmd
, "process") == 0)
936 return OPT_RESHARD_PROCESS
;
937 if (strcmp(cmd
, "cancel") == 0)
938 return OPT_RESHARD_CANCEL
;
944 enum ReplicaLogType
{
945 ReplicaLog_Invalid
= 0,
951 ReplicaLogType
get_replicalog_type(const string
& name
) {
952 if (name
== "md" || name
== "meta" || name
== "metadata")
953 return ReplicaLog_Metadata
;
955 return ReplicaLog_Data
;
956 if (name
== "bucket")
957 return ReplicaLog_Bucket
;
959 return ReplicaLog_Invalid
;
962 BIIndexType
get_bi_index_type(const string
& type_str
) {
963 if (type_str
== "plain")
965 if (type_str
== "instance")
967 if (type_str
== "olh")
973 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
975 bufferlist::iterator iter
= bl
.begin();
976 switch (index_type
) {
980 rgw_bucket_dir_entry entry
;
981 ::decode(entry
, iter
);
982 encode_json("entry", entry
, formatter
);
987 rgw_bucket_olh_entry entry
;
988 ::decode(entry
, iter
);
989 encode_json("entry", entry
, formatter
);
998 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
1000 encode_json("user_info", info
, formatter
);
1001 formatter
->flush(cout
);
1005 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1007 formatter
->open_object_section("role");
1008 formatter
->dump_string("Permission policy", perm_policy
);
1009 formatter
->close_section();
1010 formatter
->flush(cout
);
1013 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1015 formatter
->open_array_section("PolicyNames");
1016 for (const auto& it
: policy_names
) {
1017 formatter
->dump_string("policyname", it
);
1019 formatter
->close_section();
1020 formatter
->flush(cout
);
1023 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1025 formatter
->open_object_section("role");
1026 role
.dump(formatter
);
1027 formatter
->close_section();
1028 formatter
->flush(cout
);
1031 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1033 formatter
->open_array_section("Roles");
1034 for (const auto& it
: roles
) {
1035 formatter
->open_object_section("role");
1037 formatter
->close_section();
1039 formatter
->close_section();
1040 formatter
->flush(cout
);
1043 class StoreDestructor
{
1046 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1047 ~StoreDestructor() {
1048 RGWStoreManager::close_storage(store
);
1052 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1053 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1055 if (!bucket_name
.empty()) {
1056 RGWObjectCtx
obj_ctx(store
);
1058 if (bucket_id
.empty()) {
1059 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1061 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1062 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1065 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1068 bucket
= bucket_info
.bucket
;
1073 static int read_input(const string
& infile
, bufferlist
& bl
)
1076 if (infile
.size()) {
1077 fd
= open(infile
.c_str(), O_RDONLY
);
1080 cerr
<< "error reading input file " << infile
<< std::endl
;
1085 #define READ_CHUNK 8196
1090 char buf
[READ_CHUNK
];
1092 r
= safe_read(fd
, buf
, READ_CHUNK
);
1095 cerr
<< "error while reading input" << std::endl
;
1103 if (infile
.size()) {
1110 static int read_decode_json(const string
& infile
, T
& t
)
1113 int ret
= read_input(infile
, bl
);
1115 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1119 if (!p
.parse(bl
.c_str(), bl
.length())) {
1120 cout
<< "failed to parse JSON" << std::endl
;
1125 decode_json_obj(t
, &p
);
1126 } catch (JSONDecoder::err
& e
) {
1127 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1133 template <class T
, class K
>
1134 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1137 int ret
= read_input(infile
, bl
);
1139 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1143 if (!p
.parse(bl
.c_str(), bl
.length())) {
1144 cout
<< "failed to parse JSON" << std::endl
;
1149 t
.decode_json(&p
, k
);
1150 } catch (JSONDecoder::err
& e
) {
1151 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1157 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1162 if (!date_str
.empty()) {
1163 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1165 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1170 ut
= utime_t(epoch
, nsec
);
1176 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1180 bufferlist::iterator iter
= bl
.begin();
1184 } catch (buffer::error
& err
) {
1188 encode_json(field_name
, t
, f
);
1193 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1196 if (bl
.length() > 0) {
1197 val
.assign(bl
.c_str());
1199 f
->dump_string(field_name
, val
);
1204 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1205 bool have_max_size
, bool have_max_objects
)
1208 case OPT_QUOTA_ENABLE
:
1209 case OPT_GLOBAL_QUOTA_ENABLE
:
1210 quota
.enabled
= true;
1212 // falling through on purpose
1215 case OPT_GLOBAL_QUOTA_SET
:
1216 if (have_max_objects
) {
1217 if (max_objects
< 0) {
1218 quota
.max_objects
= -1;
1220 quota
.max_objects
= max_objects
;
1223 if (have_max_size
) {
1225 quota
.max_size
= -1;
1227 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1231 case OPT_QUOTA_DISABLE
:
1232 case OPT_GLOBAL_QUOTA_DISABLE
:
1233 quota
.enabled
= false;
1238 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1239 const string
& tenant_name
, const string
& bucket_name
,
1240 int64_t max_size
, int64_t max_objects
,
1241 bool have_max_size
, bool have_max_objects
)
1243 RGWBucketInfo bucket_info
;
1244 map
<string
, bufferlist
> attrs
;
1245 RGWObjectCtx
obj_ctx(store
);
1246 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1248 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1252 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1254 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1256 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1262 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1263 bool have_max_size
, bool have_max_objects
)
1265 RGWUserInfo
& user_info
= op_state
.get_user_info();
1267 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1269 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1272 int r
= user
.modify(op_state
, &err
);
1274 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1280 int set_user_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1281 bool have_max_size
, bool have_max_objects
)
1283 RGWUserInfo
& user_info
= op_state
.get_user_info();
1285 set_quota_info(user_info
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1287 op_state
.set_user_quota(user_info
.user_quota
);
1290 int r
= user
.modify(op_state
, &err
);
1292 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1298 static bool bucket_object_check_filter(const string
& name
)
1301 string ns
; /* empty namespace */
1302 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1305 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1307 map
<string
, bufferlist
> attrs
;
1310 RGWObjectCtx
obj_ctx(store
);
1311 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1312 RGWRados::Object::Read
read_op(&op_target
);
1314 read_op
.params
.attrs
= &attrs
;
1315 read_op
.params
.obj_size
= &obj_size
;
1317 int ret
= read_op
.prepare();
1319 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1323 map
<string
, bufferlist
>::iterator iter
;
1324 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1325 if (iter
== attrs
.end()) {
1326 *need_rewrite
= (obj_size
>= min_stripe_size
);
1330 RGWObjManifest manifest
;
1333 bufferlist
& bl
= iter
->second
;
1334 bufferlist::iterator biter
= bl
.begin();
1335 ::decode(manifest
, biter
);
1336 } catch (buffer::error
& err
) {
1337 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1341 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1342 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1343 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1344 RGWObjManifestPart
& part
= oiter
->second
;
1346 if (part
.size
>= min_stripe_size
) {
1347 *need_rewrite
= true;
1351 *need_rewrite
= false;
1357 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1358 f
->open_object_section("object");
1359 f
->open_object_section("key");
1360 f
->dump_string("type", "head");
1361 f
->dump_string("name", key
.name
);
1362 f
->dump_string("instance", key
.instance
);
1368 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1370 f
->dump_string("oid", oid
);
1371 f
->dump_string("locator", locator
);
1374 RGWObjectCtx
obj_ctx(store
);
1376 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1377 RGWRados::Object::Read
read_op(&op_target
);
1379 int ret
= read_op
.prepare();
1380 bool needs_fixing
= (ret
== -ENOENT
);
1382 f
->dump_bool("needs_fixing", needs_fixing
);
1384 string status
= (needs_fixing
? "needs_fixing" : "ok");
1386 if ((needs_fixing
|| remove_bad
) && fix
) {
1387 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1389 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1396 f
->dump_string("status", status
);
1403 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1404 f
->open_object_section("object");
1405 f
->open_object_section("key");
1406 f
->dump_string("type", "tail");
1407 f
->dump_string("name", key
.name
);
1408 f
->dump_string("instance", key
.instance
);
1414 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1416 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1419 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1422 f
->dump_bool("needs_fixing", needs_fixing
);
1423 f
->dump_string("status", status
);
1430 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1431 bool fix
, bool remove_bad
, Formatter
*f
)
1433 if (remove_bad
&& !fix
) {
1434 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1438 RGWBucketInfo bucket_info
;
1442 f
->open_object_section("bucket");
1443 f
->dump_string("bucket", bucket_name
);
1444 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1446 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1452 int max_entries
= 1000;
1456 vector
<rgw_bucket_dir_entry
> result
;
1457 map
<string
, bool> common_prefixes
;
1460 RGWRados::Bucket
target(store
, bucket_info
);
1461 RGWRados::Bucket::List
list_op(&target
);
1465 list_op
.params
.prefix
= prefix
;
1466 list_op
.params
.delim
= delim
;
1467 list_op
.params
.marker
= rgw_obj_key(marker
);
1468 list_op
.params
.ns
= ns
;
1469 list_op
.params
.enforce_ns
= true;
1470 list_op
.params
.list_versions
= true;
1472 f
->open_array_section("check_objects");
1474 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1476 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1480 count
+= result
.size();
1482 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1483 rgw_obj_key key
= iter
->key
;
1484 rgw_obj
obj(bucket
, key
);
1486 if (key
.name
[0] == '_') {
1487 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1490 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1495 } while (truncated
&& count
< max_entries
);
1504 int set_bucket_sync_enabled(RGWRados
*store
, int opt_cmd
, const string
& tenant_name
, const string
& bucket_name
)
1506 RGWBucketInfo bucket_info
;
1507 map
<string
, bufferlist
> attrs
;
1508 RGWObjectCtx
obj_ctx(store
);
1510 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1512 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1516 if (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
) {
1517 bucket_info
.flags
&= ~BUCKET_DATASYNC_DISABLED
;
1518 } else if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1519 bucket_info
.flags
|= BUCKET_DATASYNC_DISABLED
;
1522 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1524 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1528 int shards_num
= bucket_info
.num_shards
? bucket_info
.num_shards
: 1;
1529 int shard_id
= bucket_info
.num_shards
? 0 : -1;
1531 if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1532 r
= store
->stop_bi_log_entries(bucket_info
, -1);
1534 lderr(store
->ctx()) << "ERROR: failed writing stop bilog" << dendl
;
1538 r
= store
->resync_bi_log_entries(bucket_info
, -1);
1540 lderr(store
->ctx()) << "ERROR: failed writing resync bilog" << dendl
;
1545 for (int i
= 0; i
< shards_num
; ++i
, ++shard_id
) {
1546 r
= store
->data_log
->add_entry(bucket_info
.bucket
, shard_id
);
1548 lderr(store
->ctx()) << "ERROR: failed writing data log" << dendl
;
1557 /// search for a matching zone/zonegroup id and return a connection if found
1558 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1559 const RGWZoneGroup
& zonegroup
,
1560 const std::string
& remote
)
1562 boost::optional
<RGWRESTConn
> conn
;
1563 if (remote
== zonegroup
.get_id()) {
1564 conn
.emplace(store
->ctx(), store
, remote
, zonegroup
.endpoints
);
1566 for (const auto& z
: zonegroup
.zones
) {
1567 const auto& zone
= z
.second
;
1568 if (remote
== zone
.id
) {
1569 conn
.emplace(store
->ctx(), store
, remote
, zone
.endpoints
);
1577 /// search each zonegroup for a connection
1578 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1579 const RGWPeriodMap
& period_map
,
1580 const std::string
& remote
)
1582 boost::optional
<RGWRESTConn
> conn
;
1583 for (const auto& zg
: period_map
.zonegroups
) {
1584 conn
= get_remote_conn(store
, zg
.second
, remote
);
1592 // we expect a very small response
1593 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1595 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1596 bufferlist
& in_data
, JSONParser
& parser
)
1602 ceph::bufferlist response
;
1604 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1606 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1607 if (parse_ret
< 0) {
1608 cerr
<< "failed to parse response" << std::endl
;
1614 static int send_to_url(const string
& url
, const string
& access
,
1615 const string
& secret
, req_info
& info
,
1616 bufferlist
& in_data
, JSONParser
& parser
)
1618 if (access
.empty() || secret
.empty()) {
1619 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1627 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1629 bufferlist response
;
1630 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1632 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1633 if (parse_ret
< 0) {
1634 cout
<< "failed to parse response" << std::endl
;
1640 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1641 const string
& access
, const string
& secret
,
1642 req_info
& info
, bufferlist
& in_data
,
1646 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1648 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1651 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1652 string remote
, const string
& url
,
1653 const string
& access
, const string
& secret
,
1656 const string
& master_zone
= period
.get_master_zone();
1657 if (master_zone
.empty()) {
1658 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1661 // are we the period's master zone?
1662 if (store
->get_zone_params().get_id() == master_zone
) {
1663 // read the current period
1664 RGWPeriod current_period
;
1665 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1667 cerr
<< "Error initializing current period: "
1668 << cpp_strerror(-ret
) << std::endl
;
1671 // the master zone can commit locally
1672 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1674 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1679 if (remote
.empty() && url
.empty()) {
1680 // use the new master zone's connection
1681 remote
= master_zone
;
1682 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1684 boost::optional
<RGWRESTConn
> conn
;
1685 RGWRESTConn
*remote_conn
= nullptr;
1686 if (!remote
.empty()) {
1687 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1689 cerr
<< "failed to find a zone or zonegroup for remote "
1690 << remote
<< std::endl
;
1693 remote_conn
= &*conn
;
1696 // push period to the master with an empty period id
1700 req_info
info(g_ceph_context
, &env
);
1701 info
.method
= "POST";
1702 info
.request_uri
= "/admin/realm/period";
1704 // json format into a bufferlist
1705 JSONFormatter
jf(false);
1706 encode_json("period", period
, &jf
);
1711 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1713 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1715 // did we parse an error message?
1716 auto message
= p
.find_obj("Message");
1718 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1723 // decode the response and store it back
1725 decode_json_obj(period
, &p
);
1726 } catch (JSONDecoder::err
& e
) {
1727 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1730 if (period
.get_id().empty()) {
1731 cerr
<< "Period commit got back an empty period id" << std::endl
;
1734 // the master zone gave us back the period that it committed, so it's
1735 // safe to save it as our latest epoch
1736 ret
= period
.store_info(false);
1738 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1739 << cpp_strerror(ret
) << std::endl
;
1742 ret
= period
.set_latest_epoch(period
.get_epoch());
1744 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1747 ret
= period
.reflect();
1749 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1752 realm
.notify_new_period(period
);
1756 static int update_period(const string
& realm_id
, const string
& realm_name
,
1757 const string
& period_id
, const string
& period_epoch
,
1758 bool commit
, const string
& remote
, const string
& url
,
1759 const string
& access
, const string
& secret
,
1760 Formatter
*formatter
, bool force
)
1762 RGWRealm
realm(realm_id
, realm_name
);
1763 int ret
= realm
.init(g_ceph_context
, store
);
1765 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1769 if (!period_epoch
.empty()) {
1770 epoch
= atoi(period_epoch
.c_str());
1772 RGWPeriod
period(period_id
, epoch
);
1773 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1775 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1779 ret
= period
.update();
1781 // Dropping the error message here, as both the ret codes were handled in
1785 ret
= period
.store_info(false);
1787 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1791 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1793 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1797 encode_json("period", period
, formatter
);
1798 formatter
->flush(cout
);
1803 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1804 const string
& bucket_id
, rgw_bucket
& bucket
)
1806 RGWBucketInfo bucket_info
;
1808 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1810 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1817 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1818 const string
& access_key
, const string
& secret_key
,
1819 const string
& realm_id
, const string
& realm_name
,
1820 const string
& period_id
, const string
& period_epoch
,
1824 req_info
info(g_ceph_context
, &env
);
1825 info
.method
= "GET";
1826 info
.request_uri
= "/admin/realm/period";
1828 map
<string
, string
> ¶ms
= info
.args
.get_params();
1829 if (!realm_id
.empty())
1830 params
["realm_id"] = realm_id
;
1831 if (!realm_name
.empty())
1832 params
["realm_name"] = realm_name
;
1833 if (!period_id
.empty())
1834 params
["period_id"] = period_id
;
1835 if (!period_epoch
.empty())
1836 params
["epoch"] = period_epoch
;
1840 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1843 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1846 ret
= period
->init(g_ceph_context
, store
, false);
1848 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1852 decode_json_obj(*period
, &p
);
1853 } catch (JSONDecoder::err
& e
) {
1854 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1857 ret
= period
->store_info(false);
1859 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1861 // store latest epoch (ignore errors)
1862 period
->update_latest_epoch(period
->get_epoch());
1866 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1867 const std::string
& realm_name
,
1868 std::string
* period_id
)
1870 RGWRealm
realm(realm_id
, realm_name
);
1871 int ret
= realm
.init(g_ceph_context
, store
);
1873 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1876 *period_id
= realm
.get_current_period();
1880 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1882 if (!ss
.str().empty()) {
1883 l
.push_back(ss
.str());
1888 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1892 ss
<< setw(tab
) << "" << setw(1);
1897 static void get_md_sync_status(list
<string
>& status
)
1899 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1901 int ret
= sync
.init();
1903 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1907 rgw_meta_sync_status sync_status
;
1908 ret
= sync
.read_sync_status(&sync_status
);
1910 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1915 switch (sync_status
.sync_info
.state
) {
1916 case rgw_meta_sync_info::StateInit
:
1917 status_str
= "init";
1919 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1920 status_str
= "preparing for full sync";
1922 case rgw_meta_sync_info::StateSync
:
1923 status_str
= "syncing";
1926 status_str
= "unknown";
1929 status
.push_back(status_str
);
1931 uint64_t full_total
= 0;
1932 uint64_t full_complete
= 0;
1936 int total_shards
= 0;
1938 for (auto marker_iter
: sync_status
.sync_markers
) {
1939 full_total
+= marker_iter
.second
.total_entries
;
1941 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1943 full_complete
+= marker_iter
.second
.pos
;
1945 full_complete
+= marker_iter
.second
.total_entries
;
1947 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1953 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1956 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1959 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1961 rgw_mdlog_info log_info
;
1962 ret
= sync
.read_log_info(&log_info
);
1964 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1968 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1969 string master_period
= store
->get_current_period_id();
1971 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1973 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1977 map
<int, string
> shards_behind
;
1978 if (sync_status
.sync_info
.period
!= master_period
) {
1979 status
.push_back(string("master is on a different period: master_period=" +
1980 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1982 for (auto local_iter
: sync_status
.sync_markers
) {
1983 int shard_id
= local_iter
.first
;
1984 auto iter
= master_shards_info
.find(shard_id
);
1986 if (iter
== master_shards_info
.end()) {
1988 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
1991 auto master_marker
= iter
->second
.marker
;
1992 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
1993 master_marker
> local_iter
.second
.marker
) {
1994 shards_behind
[shard_id
] = local_iter
.second
.marker
;
1999 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2000 if (total_behind
== 0) {
2001 push_ss(ss
, status
) << "metadata is caught up with master";
2003 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
2005 map
<int, rgw_mdlog_shard_data
> master_pos
;
2006 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
2008 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2010 ceph::real_time oldest
;
2011 for (auto iter
: master_pos
) {
2012 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
2014 if (!shard_data
.entries
.empty()) {
2015 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
2016 if (ceph::real_clock::is_zero(oldest
)) {
2017 oldest
= entry
.timestamp
;
2018 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2019 oldest
= entry
.timestamp
;
2024 if (!ceph::real_clock::is_zero(oldest
)) {
2025 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
2030 flush_ss(ss
, status
);
2033 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
2037 auto ziter
= store
->zone_by_id
.find(source_zone
);
2038 if (ziter
== store
->zone_by_id
.end()) {
2039 push_ss(ss
, status
, tab
) << string("zone not found");
2040 flush_ss(ss
, status
);
2043 RGWZone
& sz
= ziter
->second
;
2045 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
2046 push_ss(ss
, status
, tab
) << string("not syncing from zone");
2047 flush_ss(ss
, status
);
2050 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
2052 int ret
= sync
.init();
2054 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
2055 flush_ss(ss
, status
);
2059 rgw_data_sync_status sync_status
;
2060 ret
= sync
.read_sync_status(&sync_status
);
2061 if (ret
< 0 && ret
!= -ENOENT
) {
2062 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2067 switch (sync_status
.sync_info
.state
) {
2068 case rgw_data_sync_info::StateInit
:
2069 status_str
= "init";
2071 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2072 status_str
= "preparing for full sync";
2074 case rgw_data_sync_info::StateSync
:
2075 status_str
= "syncing";
2078 status_str
= "unknown";
2081 push_ss(ss
, status
, tab
) << status_str
;
2083 uint64_t full_total
= 0;
2084 uint64_t full_complete
= 0;
2088 int total_shards
= 0;
2090 for (auto marker_iter
: sync_status
.sync_markers
) {
2091 full_total
+= marker_iter
.second
.total_entries
;
2093 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2095 full_complete
+= marker_iter
.second
.pos
;
2097 full_complete
+= marker_iter
.second
.total_entries
;
2099 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2104 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2107 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2110 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2112 rgw_datalog_info log_info
;
2113 ret
= sync
.read_log_info(&log_info
);
2115 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2120 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2122 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2124 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2128 map
<int, string
> shards_behind
;
2130 for (auto local_iter
: sync_status
.sync_markers
) {
2131 int shard_id
= local_iter
.first
;
2132 auto iter
= source_shards_info
.find(shard_id
);
2134 if (iter
== source_shards_info
.end()) {
2136 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2139 auto master_marker
= iter
->second
.marker
;
2140 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2141 master_marker
> local_iter
.second
.marker
) {
2142 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2146 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2147 if (total_behind
== 0) {
2148 push_ss(ss
, status
, tab
) << "data is caught up with source";
2150 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2152 map
<int, rgw_datalog_shard_data
> master_pos
;
2153 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2155 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2157 ceph::real_time oldest
;
2158 for (auto iter
: master_pos
) {
2159 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2161 if (!shard_data
.entries
.empty()) {
2162 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2163 if (ceph::real_clock::is_zero(oldest
)) {
2164 oldest
= entry
.timestamp
;
2165 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2166 oldest
= entry
.timestamp
;
2171 if (!ceph::real_clock::is_zero(oldest
)) {
2172 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2177 flush_ss(ss
, status
);
2180 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2184 for (auto e
: entries
) {
2185 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2191 static void sync_status(Formatter
*formatter
)
2193 RGWRealm
& realm
= store
->realm
;
2194 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2195 RGWZone
& zone
= store
->get_zone();
2199 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2200 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2201 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2203 list
<string
> md_status
;
2205 if (store
->is_meta_master()) {
2206 md_status
.push_back("no sync (zone is master)");
2208 get_md_sync_status(md_status
);
2211 tab_dump("metadata sync", width
, md_status
);
2213 list
<string
> data_status
;
2215 for (auto iter
: store
->zone_conn_map
) {
2216 const string
& source_id
= iter
.first
;
2217 string source_str
= "source: ";
2218 string s
= source_str
+ source_id
;
2219 auto siter
= store
->zone_by_id
.find(source_id
);
2220 if (siter
!= store
->zone_by_id
.end()) {
2221 s
+= string(" (") + siter
->second
.name
+ ")";
2223 data_status
.push_back(s
);
2224 get_data_sync_status(source_id
, data_status
, source_str
.size());
2227 tab_dump("data sync", width
, data_status
);
2230 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2233 get_str_list(s
, ",", confs
);
2234 for (auto c
: confs
) {
2235 ssize_t pos
= c
.find("=");
2239 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2244 int check_reshard_bucket_params(RGWRados
*store
,
2245 const string
& bucket_name
,
2246 const string
& tenant
,
2247 const string
& bucket_id
,
2248 bool num_shards_specified
,
2250 int yes_i_really_mean_it
,
2252 RGWBucketInfo
& bucket_info
,
2253 map
<string
, bufferlist
>& attrs
)
2255 if (bucket_name
.empty()) {
2256 cerr
<< "ERROR: bucket not specified" << std::endl
;
2260 if (!num_shards_specified
) {
2261 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2265 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2266 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2270 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2272 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2276 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2278 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2279 cerr
<< "num shards is less or equal to current shards count" << std::endl
2280 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2286 int create_new_bucket_instance(RGWRados
*store
,
2288 const RGWBucketInfo
& bucket_info
,
2289 map
<string
, bufferlist
>& attrs
,
2290 RGWBucketInfo
& new_bucket_info
)
2293 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2294 new_bucket_info
.bucket
.oid
.clear();
2296 new_bucket_info
.num_shards
= new_num_shards
;
2297 new_bucket_info
.objv_tracker
.clear();
2299 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2301 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2305 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2307 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2315 #ifdef BUILDING_FOR_EMBEDDED
2316 extern "C" int cephd_rgw_admin(int argc
, const char **argv
)
2318 int main(int argc
, const char **argv
)
2321 vector
<const char*> args
;
2322 argv_to_vec(argc
, (const char **)argv
, args
);
2325 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2326 CODE_ENVIRONMENT_UTILITY
, 0);
2328 // for region -> zonegroup conversion (must happen before common_init_finish())
2329 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2330 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2333 common_init_finish(g_ceph_context
);
2337 std::string access_key
, secret_key
, user_email
, display_name
;
2338 std::string bucket_name
, pool_name
, object
;
2340 std::string date
, subuser
, access
, format
;
2341 std::string start_date
, end_date
;
2342 std::string key_type_str
;
2343 std::string period_id
, period_epoch
, remote
, url
;
2344 std::string master_zonegroup
, master_zone
;
2345 std::string realm_name
, realm_id
, realm_new_name
;
2346 std::string zone_name
, zone_id
, zone_new_name
;
2347 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2348 std::string api_name
;
2349 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2350 list
<string
> endpoints
;
2352 int sync_from_all_specified
= false;
2353 bool sync_from_all
= false;
2354 list
<string
> sync_from
;
2355 list
<string
> sync_from_rm
;
2356 std::string master_url
;
2358 int set_default
= 0;
2359 bool is_master
= false;
2360 bool is_master_set
= false;
2362 bool read_only
= false;
2363 int is_read_only_set
= false;
2365 int staging
= false;
2366 int key_type
= KEY_TYPE_UNDEFINED
;
2368 uint32_t perm_mask
= 0;
2370 int opt_cmd
= OPT_NO_CMD
;
2372 int gen_access_key
= 0;
2373 int gen_secret_key
= 0;
2374 bool set_perm
= false;
2375 bool set_temp_url_key
= false;
2376 map
<int, string
> temp_url_keys
;
2378 Formatter
*formatter
= NULL
;
2379 int purge_data
= false;
2380 int pretty_format
= false;
2381 int show_log_entries
= true;
2382 int show_log_sum
= true;
2383 int skip_zero_entries
= false; // log show
2384 int purge_keys
= false;
2385 int yes_i_really_mean_it
= false;
2386 int delete_child_objects
= false;
2388 int remove_bad
= false;
2389 int check_head_obj_locator
= false;
2390 int max_buckets
= -1;
2391 bool max_buckets_specified
= false;
2392 map
<string
, bool> categories
;
2394 int check_objects
= false;
2395 RGWUserAdminOpState user_op
;
2396 RGWBucketAdminOpState bucket_op
;
2398 string metadata_key
;
2399 RGWObjVersionTracker objv_tracker
;
2401 string start_marker
;
2403 int max_entries
= -1;
2404 bool max_entries_specified
= false;
2406 bool admin_specified
= false;
2408 bool system_specified
= false;
2410 bool specified_shard_id
= false;
2412 bool specified_daemon_id
= false;
2416 string replica_log_type_str
;
2417 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2420 string object_version
;
2421 string placement_id
;
2423 list
<string
> tags_add
;
2424 list
<string
> tags_rm
;
2426 int64_t max_objects
= -1;
2427 int64_t max_size
= -1;
2428 bool have_max_objects
= false;
2429 bool have_max_size
= false;
2430 int include_all
= false;
2432 int sync_stats
= false;
2433 int bypass_gc
= false;
2434 int warnings_only
= false;
2435 int inconsistent_index
= false;
2437 int verbose
= false;
2439 int extra_info
= false;
2441 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2442 uint64_t max_rewrite_size
= ULLONG_MAX
;
2443 uint64_t min_rewrite_stripe_size
= 0;
2445 BIIndexType bi_index_type
= PlainIdx
;
2449 bool num_shards_specified
= false;
2450 int max_concurrent_ios
= 32;
2451 uint64_t orphan_stale_secs
= (24 * 3600);
2454 std::ostringstream errs
;
2458 string source_zone_name
;
2459 string source_zone
; /* zone id */
2462 bool tier_type_specified
= false;
2464 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2465 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2467 boost::optional
<string
> index_pool
;
2468 boost::optional
<string
> data_pool
;
2469 boost::optional
<string
> data_extra_pool
;
2470 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2471 bool index_type_specified
= false;
2473 boost::optional
<std::string
> compression_type
;
2475 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2476 if (ceph_argparse_double_dash(args
, i
)) {
2478 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2481 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2482 user_id
.from_str(val
);
2483 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2485 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2487 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2489 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2491 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2493 user_op
.user_email_specified
=true;
2494 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2496 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2498 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2500 pool
= rgw_pool(pool_name
);
2501 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2503 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2504 object_version
= val
;
2505 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2507 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2509 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2511 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2513 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2515 if (key_type_str
.compare("swift") == 0) {
2516 key_type
= KEY_TYPE_SWIFT
;
2517 } else if (key_type_str
.compare("s3") == 0) {
2518 key_type
= KEY_TYPE_S3
;
2520 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2524 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2526 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2528 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2530 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2532 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2534 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2536 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2537 admin_specified
= true;
2538 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2539 system_specified
= true;
2540 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2542 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2544 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2546 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2547 if (!errs
.str().empty()) {
2548 cerr
<< errs
.str() << std::endl
;
2551 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2552 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2553 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2554 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2555 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2556 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2557 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2558 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2560 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2563 max_buckets_specified
= true;
2564 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2565 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2566 max_entries_specified
= true;
2568 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2571 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2572 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2574 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2577 have_max_size
= true;
2578 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2579 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2581 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2584 have_max_objects
= true;
2585 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2587 if (end_date
.empty())
2589 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2591 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2593 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2594 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2596 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2599 num_shards_specified
= true;
2600 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2601 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2603 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2606 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2607 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2609 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2612 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2613 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2615 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2618 specified_shard_id
= true;
2619 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2621 specified_daemon_id
= true;
2622 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2624 perm_mask
= rgw_str_to_perm(access
.c_str());
2626 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2627 temp_url_keys
[0] = val
;
2628 set_temp_url_key
= true;
2629 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2630 temp_url_keys
[1] = val
;
2631 set_temp_url_key
= true;
2632 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2634 if (bucket_id
.empty()) {
2635 cerr
<< "bad bucket-id" << std::endl
;
2639 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2641 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2642 string cat_str
= val
;
2643 list
<string
> cat_list
;
2644 list
<string
>::iterator iter
;
2645 get_str_list(cat_str
, cat_list
);
2646 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2647 categories
[*iter
] = true;
2649 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2651 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2653 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2654 delete_child_objects
= purge_data
;
2655 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2657 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2659 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2661 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2663 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2665 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2667 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2669 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2671 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2673 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2675 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2677 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2679 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2681 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2683 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2685 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2687 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2689 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2691 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2693 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2694 replica_log_type_str
= val
;
2695 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2696 if (replica_log_type
== ReplicaLog_Invalid
) {
2697 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2700 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2701 string index_type_str
= val
;
2702 bi_index_type
= get_bi_index_type(index_type_str
);
2703 if (bi_index_type
== InvalidIdx
) {
2704 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2707 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2708 is_master
= (bool)is_master_int
;
2709 is_master_set
= true;
2710 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2712 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2713 read_only
= (bool)read_only_int
;
2714 is_read_only_set
= true;
2715 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2717 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2718 master_zonegroup
= val
;
2719 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2721 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2723 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2725 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2727 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2729 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2731 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2732 realm_new_name
= val
;
2733 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2735 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2736 zonegroup_new_name
= val
;
2737 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2739 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2740 get_str_list(val
, tags
);
2741 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2742 get_str_list(val
, tags_add
);
2743 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2744 get_str_list(val
, tags_rm
);
2745 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2747 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2749 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2750 zone_new_name
= val
;
2751 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2752 get_str_list(val
, endpoints
);
2753 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2754 get_str_list(val
, sync_from
);
2755 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2756 get_str_list(val
, sync_from_rm
);
2757 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2758 sync_from_all
= (bool)tmp_int
;
2759 sync_from_all_specified
= true;
2760 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2761 source_zone_name
= val
;
2762 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2764 tier_type_specified
= true;
2765 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2766 parse_tier_config_param(val
, tier_config_add
);
2767 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2768 parse_tier_config_param(val
, tier_config_rm
);
2769 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2771 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2773 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2774 data_extra_pool
= val
;
2775 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2776 if (val
== "normal") {
2777 placement_index_type
= RGWBIType_Normal
;
2778 } else if (val
== "indexless") {
2779 placement_index_type
= RGWBIType_Indexless
;
2781 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2783 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2787 index_type_specified
= true;
2788 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2789 compression_type
= val
;
2790 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2792 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2794 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2795 assume_role_doc
= val
;
2796 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2798 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2799 perm_policy_doc
= val
;
2800 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2802 } else if (strncmp(*i
, "-", 1) == 0) {
2803 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
2815 const char *prev_cmd
= NULL
;
2816 const char *prev_prev_cmd
= NULL
;
2817 std::vector
<const char*>::iterator i
;
2818 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
2819 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
2821 cerr
<< "unrecognized arg " << *i
<< std::endl
;
2829 prev_prev_cmd
= prev_cmd
;
2833 if (opt_cmd
== OPT_NO_CMD
) {
2838 /* some commands may have an optional extra param */
2839 if (i
!= args
.end()) {
2841 case OPT_METADATA_GET
:
2842 case OPT_METADATA_PUT
:
2843 case OPT_METADATA_RM
:
2844 case OPT_METADATA_LIST
:
2852 if (tenant
.empty()) {
2853 tenant
= user_id
.tenant
;
2855 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
2856 && opt_cmd
!= OPT_ROLE_DELETE
2857 && opt_cmd
!= OPT_ROLE_GET
2858 && opt_cmd
!= OPT_ROLE_MODIFY
2859 && opt_cmd
!= OPT_ROLE_LIST
2860 && opt_cmd
!= OPT_ROLE_POLICY_PUT
2861 && opt_cmd
!= OPT_ROLE_POLICY_LIST
2862 && opt_cmd
!= OPT_ROLE_POLICY_GET
2863 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
2864 && opt_cmd
!= OPT_RESHARD_ADD
2865 && opt_cmd
!= OPT_RESHARD_CANCEL
2866 && opt_cmd
!= OPT_RESHARD_STATUS
) {
2867 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
2870 user_id
.tenant
= tenant
;
2872 /* check key parameter conflict */
2873 if ((!access_key
.empty()) && gen_access_key
) {
2874 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
2877 if ((!secret_key
.empty()) && gen_secret_key
) {
2878 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
2883 // default to pretty json
2884 if (format
.empty()) {
2886 pretty_format
= true;
2889 if (format
== "xml")
2890 formatter
= new XMLFormatter(pretty_format
);
2891 else if (format
== "json")
2892 formatter
= new JSONFormatter(pretty_format
);
2894 cerr
<< "unrecognized format: " << format
<< std::endl
;
2899 realm_name
= g_conf
->rgw_realm
;
2900 zone_name
= g_conf
->rgw_zone
;
2901 zonegroup_name
= g_conf
->rgw_zonegroup
;
2903 RGWStreamFlusher
f(formatter
, cout
);
2905 // not a raw op if 'period update' needs to commit to master
2906 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
2907 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
2908 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
2909 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
2910 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
2911 OPT_ZONEGROUP_REMOVE
,
2912 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
2913 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
2914 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
2915 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
2916 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
2917 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
2918 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
2919 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
2921 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
2923 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
2924 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
2925 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
2926 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
2927 OPT_REALM_LIST_PERIODS
,
2928 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
2929 OPT_REALM_RENAME
, OPT_REALM_SET
,
2930 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
2933 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
2936 if (raw_storage_op
) {
2937 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
2939 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false);
2942 cerr
<< "couldn't init storage provider" << std::endl
;
2946 if (!source_zone_name
.empty()) {
2947 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
2948 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
2949 source_zone
= source_zone_name
;
2953 rgw_user_init(store
);
2954 rgw_bucket_init(store
->meta_mgr
);
2956 StoreDestructor
store_destructor(store
);
2958 if (raw_storage_op
) {
2960 case OPT_PERIOD_DELETE
:
2962 if (period_id
.empty()) {
2963 cerr
<< "missing period id" << std::endl
;
2966 RGWPeriod
period(period_id
);
2967 int ret
= period
.init(g_ceph_context
, store
);
2969 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
2972 ret
= period
.delete_obj();
2974 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
2980 case OPT_PERIOD_GET
:
2983 if (!period_epoch
.empty()) {
2984 epoch
= atoi(period_epoch
.c_str());
2987 RGWRealm
realm(realm_id
, realm_name
);
2988 int ret
= realm
.init(g_ceph_context
, store
);
2990 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
2993 realm_id
= realm
.get_id();
2994 realm_name
= realm
.get_name();
2995 period_id
= RGWPeriod::get_staging_id(realm_id
);
2998 RGWPeriod
period(period_id
, epoch
);
2999 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
3001 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
3004 encode_json("period", period
, formatter
);
3005 formatter
->flush(cout
);
3009 case OPT_PERIOD_GET_CURRENT
:
3011 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3015 formatter
->open_object_section("period_get_current");
3016 encode_json("current_period", period_id
, formatter
);
3017 formatter
->close_section();
3018 formatter
->flush(cout
);
3021 case OPT_PERIOD_LIST
:
3023 list
<string
> periods
;
3024 int ret
= store
->list_periods(periods
);
3026 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
3029 formatter
->open_object_section("periods_list");
3030 encode_json("periods", periods
, formatter
);
3031 formatter
->close_section();
3032 formatter
->flush(cout
);
3036 case OPT_PERIOD_UPDATE
:
3038 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
3039 commit
, remote
, url
, access_key
, secret_key
,
3040 formatter
, yes_i_really_mean_it
);
3046 case OPT_PERIOD_PULL
:
3048 boost::optional
<RGWRESTConn
> conn
;
3049 RGWRESTConn
*remote_conn
= nullptr;
3051 // load current period for endpoints
3052 RGWRealm
realm(realm_id
, realm_name
);
3053 int ret
= realm
.init(g_ceph_context
, store
);
3055 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3058 RGWPeriod
current_period(realm
.get_current_period());
3059 ret
= current_period
.init(g_ceph_context
, store
);
3061 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
3064 if (remote
.empty()) {
3065 // use realm master zone as remote
3066 remote
= current_period
.get_master_zone();
3068 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
3070 cerr
<< "failed to find a zone or zonegroup for remote "
3071 << remote
<< std::endl
;
3074 remote_conn
= &*conn
;
3078 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3079 realm_id
, realm_name
, period_id
, period_epoch
,
3082 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3086 encode_json("period", period
, formatter
);
3087 formatter
->flush(cout
);
3091 case OPT_GLOBAL_QUOTA_GET
:
3092 case OPT_GLOBAL_QUOTA_SET
:
3093 case OPT_GLOBAL_QUOTA_ENABLE
:
3094 case OPT_GLOBAL_QUOTA_DISABLE
:
3096 if (realm_id
.empty()) {
3097 RGWRealm
realm(g_ceph_context
, store
);
3098 if (!realm_name
.empty()) {
3099 // look up realm_id for the given realm_name
3100 int ret
= realm
.read_id(realm_name
, realm_id
);
3102 cerr
<< "ERROR: failed to read realm for " << realm_name
3103 << ": " << cpp_strerror(-ret
) << std::endl
;
3107 // use default realm_id when none is given
3108 int ret
= realm
.read_default_id(realm_id
);
3109 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3110 cerr
<< "ERROR: failed to read default realm: "
3111 << cpp_strerror(-ret
) << std::endl
;
3117 RGWPeriodConfig period_config
;
3118 int ret
= period_config
.read(store
, realm_id
);
3119 if (ret
< 0 && ret
!= -ENOENT
) {
3120 cerr
<< "ERROR: failed to read period config: "
3121 << cpp_strerror(-ret
) << std::endl
;
3125 formatter
->open_object_section("period_config");
3126 if (quota_scope
== "bucket") {
3127 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3128 max_size
, max_objects
,
3129 have_max_size
, have_max_objects
);
3130 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3131 } else if (quota_scope
== "user") {
3132 set_quota_info(period_config
.user_quota
, opt_cmd
,
3133 max_size
, max_objects
,
3134 have_max_size
, have_max_objects
);
3135 encode_json("user quota", period_config
.user_quota
, formatter
);
3136 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3137 // if no scope is given for GET, print both
3138 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3139 encode_json("user quota", period_config
.user_quota
, formatter
);
3141 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3142 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3145 formatter
->close_section();
3147 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3148 // write the modified period config
3149 ret
= period_config
.write(store
, realm_id
);
3151 cerr
<< "ERROR: failed to write period config: "
3152 << cpp_strerror(-ret
) << std::endl
;
3155 if (!realm_id
.empty()) {
3156 cout
<< "Global quota changes saved. Use 'period update' to apply "
3157 "them to the staging period, and 'period commit' to commit the "
3158 "new period." << std::endl
;
3160 cout
<< "Global quota changes saved. They will take effect as "
3161 "the gateways are restarted." << std::endl
;
3165 formatter
->flush(cout
);
3169 case OPT_REALM_CREATE
:
3171 if (realm_name
.empty()) {
3172 cerr
<< "missing realm name" << std::endl
;
3176 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3177 int ret
= realm
.create();
3179 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3184 ret
= realm
.set_as_default();
3186 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3190 encode_json("realm", realm
, formatter
);
3191 formatter
->flush(cout
);
3195 case OPT_REALM_DELETE
:
3197 RGWRealm
realm(realm_id
, realm_name
);
3198 if (realm_name
.empty() && realm_id
.empty()) {
3199 cerr
<< "missing realm name or id" << std::endl
;
3202 int ret
= realm
.init(g_ceph_context
, store
);
3204 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3207 ret
= realm
.delete_obj();
3209 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3217 RGWRealm
realm(realm_id
, realm_name
);
3218 int ret
= realm
.init(g_ceph_context
, store
);
3220 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3221 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3223 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3227 encode_json("realm", realm
, formatter
);
3228 formatter
->flush(cout
);
3232 case OPT_REALM_GET_DEFAULT
:
3234 RGWRealm
realm(g_ceph_context
, store
);
3236 int ret
= realm
.read_default_id(default_id
);
3237 if (ret
== -ENOENT
) {
3238 cout
<< "No default realm is set" << std::endl
;
3240 } else if (ret
< 0) {
3241 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3244 cout
<< "default realm: " << default_id
<< std::endl
;
3247 case OPT_REALM_LIST
:
3249 RGWRealm
realm(g_ceph_context
, store
);
3251 int ret
= realm
.read_default_id(default_id
);
3252 if (ret
< 0 && ret
!= -ENOENT
) {
3253 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3255 list
<string
> realms
;
3256 ret
= store
->list_realms(realms
);
3258 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3261 formatter
->open_object_section("realms_list");
3262 encode_json("default_info", default_id
, formatter
);
3263 encode_json("realms", realms
, formatter
);
3264 formatter
->close_section();
3265 formatter
->flush(cout
);
3269 case OPT_REALM_LIST_PERIODS
:
3271 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3275 list
<string
> periods
;
3276 ret
= store
->list_periods(period_id
, periods
);
3278 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3281 formatter
->open_object_section("realm_periods_list");
3282 encode_json("current_period", period_id
, formatter
);
3283 encode_json("periods", periods
, formatter
);
3284 formatter
->close_section();
3285 formatter
->flush(cout
);
3290 case OPT_REALM_RENAME
:
3292 RGWRealm
realm(realm_id
, realm_name
);
3293 if (realm_new_name
.empty()) {
3294 cerr
<< "missing realm new name" << std::endl
;
3297 if (realm_name
.empty() && realm_id
.empty()) {
3298 cerr
<< "missing realm name or id" << std::endl
;
3301 int ret
= realm
.init(g_ceph_context
, store
);
3303 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3306 ret
= realm
.rename(realm_new_name
);
3308 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3311 cout
<< "Realm name updated. Note that this change only applies to "
3312 "the current cluster, so this command must be run separately "
3313 "on each of the realm's other clusters." << std::endl
;
3318 if (realm_id
.empty() && realm_name
.empty()) {
3319 cerr
<< "no realm name or id provided" << std::endl
;
3322 RGWRealm
realm(realm_id
, realm_name
);
3323 bool new_realm
= false;
3324 int ret
= realm
.init(g_ceph_context
, store
);
3325 if (ret
< 0 && ret
!= -ENOENT
) {
3326 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3328 } else if (ret
== -ENOENT
) {
3331 ret
= read_decode_json(infile
, realm
);
3335 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3336 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3337 realm
.get_name() << std::endl
;
3342 cout
<< "clearing period and epoch for new realm" << std::endl
;
3343 realm
.clear_current_period_and_epoch();
3344 ret
= realm
.create();
3346 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3350 ret
= realm
.update();
3352 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3358 ret
= realm
.set_as_default();
3360 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3363 encode_json("realm", realm
, formatter
);
3364 formatter
->flush(cout
);
3368 case OPT_REALM_DEFAULT
:
3370 RGWRealm
realm(realm_id
, realm_name
);
3371 int ret
= realm
.init(g_ceph_context
, store
);
3373 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3376 ret
= realm
.set_as_default();
3378 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3383 case OPT_REALM_PULL
:
3386 cerr
<< "A --url must be provided." << std::endl
;
3390 req_info
info(g_ceph_context
, &env
);
3391 info
.method
= "GET";
3392 info
.request_uri
= "/admin/realm";
3394 map
<string
, string
> ¶ms
= info
.args
.get_params();
3395 if (!realm_id
.empty())
3396 params
["id"] = realm_id
;
3397 if (!realm_name
.empty())
3398 params
["name"] = realm_name
;
3402 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3404 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3405 if (ret
== -EACCES
) {
3406 cerr
<< "If the realm has been changed on the master zone, the "
3407 "master zone's gateway may need to be restarted to recognize "
3408 "this user." << std::endl
;
3413 realm
.init(g_ceph_context
, store
, false);
3415 decode_json_obj(realm
, &p
);
3416 } catch (JSONDecoder::err
& e
) {
3417 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3421 auto& current_period
= realm
.get_current_period();
3422 if (!current_period
.empty()) {
3423 // pull the latest epoch of the realm's current period
3424 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3425 realm_id
, realm_name
, current_period
, "",
3428 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3432 ret
= realm
.create(false);
3433 if (ret
< 0 && ret
!= -EEXIST
) {
3434 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3435 << cpp_strerror(ret
) << std::endl
;
3437 } else if (ret
==-EEXIST
) {
3438 ret
= realm
.update();
3440 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3441 << cpp_strerror(ret
) << std::endl
;
3446 ret
= realm
.set_as_default();
3448 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3452 encode_json("realm", realm
, formatter
);
3453 formatter
->flush(cout
);
3458 case OPT_ZONEGROUP_ADD
:
3460 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3461 cerr
<< "no zonegroup name or id provided" << std::endl
;
3465 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3466 int ret
= zonegroup
.init(g_ceph_context
, store
);
3468 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3469 << cpp_strerror(-ret
) << std::endl
;
3472 RGWZoneParams
zone(zone_id
, zone_name
);
3473 ret
= zone
.init(g_ceph_context
, store
);
3475 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3478 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3479 zone
.realm_id
= zonegroup
.realm_id
;
3480 ret
= zone
.update();
3482 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
3487 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3488 zone
.tier_config
= tier_config_add
;
3490 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3492 ret
= zonegroup
.add_zone(zone
,
3493 (is_master_set
? &is_master
: NULL
),
3494 (is_read_only_set
? &read_only
: NULL
),
3495 endpoints
, ptier_type
,
3496 psync_from_all
, sync_from
, sync_from_rm
);
3498 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3499 << cpp_strerror(-ret
) << std::endl
;
3503 encode_json("zonegroup", zonegroup
, formatter
);
3504 formatter
->flush(cout
);
3507 case OPT_ZONEGROUP_CREATE
:
3509 if (zonegroup_name
.empty()) {
3510 cerr
<< "Missing zonegroup name" << std::endl
;
3513 RGWRealm
realm(realm_id
, realm_name
);
3514 int ret
= realm
.init(g_ceph_context
, store
);
3516 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3520 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3521 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3522 ret
= zonegroup
.create();
3524 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3529 ret
= zonegroup
.set_as_default();
3531 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3535 encode_json("zonegroup", zonegroup
, formatter
);
3536 formatter
->flush(cout
);
3540 case OPT_ZONEGROUP_DEFAULT
:
3542 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3543 cerr
<< "no zonegroup name or id provided" << std::endl
;
3547 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3548 int ret
= zonegroup
.init(g_ceph_context
, store
);
3550 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3554 ret
= zonegroup
.set_as_default();
3556 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3561 case OPT_ZONEGROUP_DELETE
:
3563 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3564 cerr
<< "no zonegroup name or id provided" << std::endl
;
3567 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3568 int ret
= zonegroup
.init(g_ceph_context
, store
);
3570 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3573 ret
= zonegroup
.delete_obj();
3575 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3580 case OPT_ZONEGROUP_GET
:
3582 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3583 int ret
= zonegroup
.init(g_ceph_context
, store
);
3585 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3589 encode_json("zonegroup", zonegroup
, formatter
);
3590 formatter
->flush(cout
);
3594 case OPT_ZONEGROUP_LIST
:
3596 RGWZoneGroup zonegroup
;
3597 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3599 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3603 list
<string
> zonegroups
;
3604 ret
= store
->list_zonegroups(zonegroups
);
3606 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3609 string default_zonegroup
;
3610 ret
= zonegroup
.read_default_id(default_zonegroup
);
3611 if (ret
< 0 && ret
!= -ENOENT
) {
3612 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3614 formatter
->open_object_section("zonegroups_list");
3615 encode_json("default_info", default_zonegroup
, formatter
);
3616 encode_json("zonegroups", zonegroups
, formatter
);
3617 formatter
->close_section();
3618 formatter
->flush(cout
);
3622 case OPT_ZONEGROUP_MODIFY
:
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(zonegroup_id
, zonegroup_name
);
3632 ret
= zonegroup
.init(g_ceph_context
, store
);
3634 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3638 bool need_update
= false;
3640 if (!master_zone
.empty()) {
3641 zonegroup
.master_zone
= master_zone
;
3645 if (is_master_set
) {
3646 zonegroup
.update_master(is_master
);
3650 if (!endpoints
.empty()) {
3651 zonegroup
.endpoints
= endpoints
;
3655 if (!api_name
.empty()) {
3656 zonegroup
.api_name
= api_name
;
3660 if (!realm_id
.empty()) {
3661 zonegroup
.realm_id
= realm_id
;
3663 } else if (!realm_name
.empty()) {
3664 // get realm id from name
3665 RGWRealm realm
{g_ceph_context
, store
};
3666 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3668 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3675 ret
= zonegroup
.update();
3677 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3683 ret
= zonegroup
.set_as_default();
3685 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3689 encode_json("zonegroup", zonegroup
, formatter
);
3690 formatter
->flush(cout
);
3693 case OPT_ZONEGROUP_SET
:
3695 RGWRealm
realm(realm_id
, realm_name
);
3696 int ret
= realm
.init(g_ceph_context
, store
);
3698 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3702 RGWZoneGroup zonegroup
;
3703 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3705 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3708 ret
= read_decode_json(infile
, zonegroup
);
3712 if (zonegroup
.realm_id
.empty()) {
3713 zonegroup
.realm_id
= realm
.get_id();
3715 ret
= zonegroup
.create();
3716 if (ret
< 0 && ret
!= -EEXIST
) {
3717 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3719 } else if (ret
== -EEXIST
) {
3720 ret
= zonegroup
.update();
3722 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3728 ret
= zonegroup
.set_as_default();
3730 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3734 encode_json("zonegroup", zonegroup
, formatter
);
3735 formatter
->flush(cout
);
3738 case OPT_ZONEGROUP_REMOVE
:
3740 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3741 int ret
= zonegroup
.init(g_ceph_context
, store
);
3743 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3747 if (zone_id
.empty()) {
3748 if (zone_name
.empty()) {
3749 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
3752 // look up zone id by name
3753 for (auto& z
: zonegroup
.zones
) {
3754 if (zone_name
== z
.second
.name
) {
3755 zone_id
= z
.second
.id
;
3759 if (zone_id
.empty()) {
3760 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
3761 << zonegroup
.get_name() << std::endl
;
3766 ret
= zonegroup
.remove_zone(zone_id
);
3768 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
3772 encode_json("zonegroup", zonegroup
, formatter
);
3773 formatter
->flush(cout
);
3776 case OPT_ZONEGROUP_RENAME
:
3778 if (zonegroup_new_name
.empty()) {
3779 cerr
<< " missing zonegroup new name" << std::endl
;
3782 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3783 cerr
<< "no zonegroup name or id provided" << std::endl
;
3786 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3787 int ret
= zonegroup
.init(g_ceph_context
, store
);
3789 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3792 ret
= zonegroup
.rename(zonegroup_new_name
);
3794 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3799 case OPT_ZONEGROUP_PLACEMENT_LIST
:
3801 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3802 int ret
= zonegroup
.init(g_ceph_context
, store
);
3804 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3808 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3809 formatter
->flush(cout
);
3813 case OPT_ZONEGROUP_PLACEMENT_ADD
:
3814 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
3815 case OPT_ZONEGROUP_PLACEMENT_RM
:
3816 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
3818 if (placement_id
.empty()) {
3819 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
3823 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3824 int ret
= zonegroup
.init(g_ceph_context
, store
);
3826 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3830 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
3831 RGWZoneGroupPlacementTarget target
;
3832 target
.name
= placement_id
;
3833 for (auto& t
: tags
) {
3834 target
.tags
.insert(t
);
3836 zonegroup
.placement_targets
[placement_id
] = target
;
3837 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
3838 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
3839 if (!tags
.empty()) {
3840 target
.tags
.clear();
3841 for (auto& t
: tags
) {
3842 target
.tags
.insert(t
);
3845 target
.name
= placement_id
;
3846 for (auto& t
: tags_rm
) {
3847 target
.tags
.erase(t
);
3849 for (auto& t
: tags_add
) {
3850 target
.tags
.insert(t
);
3852 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
3853 zonegroup
.placement_targets
.erase(placement_id
);
3854 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
3855 if (!zonegroup
.placement_targets
.count(placement_id
)) {
3856 cerr
<< "failed to find a zonegroup placement target named '"
3857 << placement_id
<< "'" << std::endl
;
3860 zonegroup
.default_placement
= placement_id
;
3863 zonegroup
.post_process_params();
3864 ret
= zonegroup
.update();
3866 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3870 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3871 formatter
->flush(cout
);
3874 case OPT_ZONE_CREATE
:
3876 if (zone_name
.empty()) {
3877 cerr
<< "zone name not provided" << std::endl
;
3881 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3882 /* if the user didn't provide zonegroup info , create stand alone zone */
3883 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3884 ret
= zonegroup
.init(g_ceph_context
, store
);
3886 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3889 if (realm_id
.empty() && realm_name
.empty()) {
3890 realm_id
= zonegroup
.realm_id
;
3894 RGWZoneParams
zone(zone_id
, zone_name
);
3895 ret
= zone
.init(g_ceph_context
, store
, false);
3897 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3901 zone
.system_key
.id
= access_key
;
3902 zone
.system_key
.key
= secret_key
;
3903 zone
.realm_id
= realm_id
;
3904 zone
.tier_config
= tier_config_add
;
3906 ret
= zone
.create();
3908 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3912 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3913 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3914 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3915 ret
= zonegroup
.add_zone(zone
,
3916 (is_master_set
? &is_master
: NULL
),
3917 (is_read_only_set
? &read_only
: NULL
),
3921 sync_from
, sync_from_rm
);
3923 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
3924 << ": " << cpp_strerror(-ret
) << std::endl
;
3930 ret
= zone
.set_as_default();
3932 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3936 encode_json("zone", zone
, formatter
);
3937 formatter
->flush(cout
);
3941 case OPT_ZONE_DEFAULT
:
3943 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3944 int ret
= zonegroup
.init(g_ceph_context
, store
);
3946 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3948 if (zone_id
.empty() && zone_name
.empty()) {
3949 cerr
<< "no zone name or id provided" << std::endl
;
3952 RGWZoneParams
zone(zone_id
, zone_name
);
3953 ret
= zone
.init(g_ceph_context
, store
);
3955 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3958 ret
= zone
.set_as_default();
3960 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
3965 case OPT_ZONE_DELETE
:
3967 if (zone_id
.empty() && zone_name
.empty()) {
3968 cerr
<< "no zone name or id provided" << std::endl
;
3971 RGWZoneParams
zone(zone_id
, zone_name
);
3972 int ret
= zone
.init(g_ceph_context
, store
);
3974 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3978 list
<string
> zonegroups
;
3979 ret
= store
->list_zonegroups(zonegroups
);
3981 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3985 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
3986 RGWZoneGroup
zonegroup(string(), *iter
);
3987 int ret
= zonegroup
.init(g_ceph_context
, store
);
3989 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
3992 ret
= zonegroup
.remove_zone(zone
.get_id());
3993 if (ret
< 0 && ret
!= -ENOENT
) {
3994 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
3995 << cpp_strerror(-ret
) << std::endl
;
3999 ret
= zone
.delete_obj();
4001 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4008 RGWZoneParams
zone(zone_id
, zone_name
);
4009 int ret
= zone
.init(g_ceph_context
, store
);
4011 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4014 encode_json("zone", zone
, formatter
);
4015 formatter
->flush(cout
);
4020 RGWZoneParams
zone(zone_name
);
4021 int ret
= zone
.init(g_ceph_context
, store
, false);
4027 if (ret
< 0 && ret
!= -ENOENT
) {
4028 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
4032 string orig_id
= zone
.get_id();
4034 ret
= read_decode_json(infile
, zone
);
4039 if(zone
.realm_id
.empty()) {
4040 RGWRealm
realm(realm_id
, realm_name
);
4041 int ret
= realm
.init(g_ceph_context
, store
);
4042 if (ret
< 0 && ret
!= -ENOENT
) {
4043 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4046 zone
.realm_id
= realm
.get_id();
4049 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
4050 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
4054 if (zone
.get_name().empty()) {
4055 zone
.set_name(zone_name
);
4056 if (zone
.get_name().empty()) {
4057 cerr
<< "no zone name specified" << std::endl
;
4062 zone_name
= zone
.get_name();
4064 if (zone
.get_id().empty()) {
4065 zone
.set_id(orig_id
);
4068 if (zone
.get_id().empty()) {
4069 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
4070 if (zone_name
.empty()) {
4071 cerr
<< "missing zone name" << std::endl
;
4074 zone
.set_name(zone_name
);
4075 zone
.set_id(zone_name
);
4078 cerr
<< "zone id " << zone
.get_id();
4079 ret
= zone
.fix_pool_names();
4081 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4084 ret
= zone
.write(false);
4086 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4091 ret
= zone
.set_as_default();
4093 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4097 encode_json("zone", zone
, formatter
);
4098 formatter
->flush(cout
);
4104 int ret
= store
->list_zones(zones
);
4106 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4111 ret
= zone
.init(g_ceph_context
, store
, false);
4113 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4116 string default_zone
;
4117 ret
= zone
.read_default_id(default_zone
);
4118 if (ret
< 0 && ret
!= -ENOENT
) {
4119 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4121 formatter
->open_object_section("zones_list");
4122 encode_json("default_info", default_zone
, formatter
);
4123 encode_json("zones", zones
, formatter
);
4124 formatter
->close_section();
4125 formatter
->flush(cout
);
4129 case OPT_ZONE_MODIFY
:
4131 RGWZoneParams
zone(zone_id
, zone_name
);
4132 int ret
= zone
.init(g_ceph_context
, store
);
4134 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4138 bool need_zone_update
= false;
4139 if (!access_key
.empty()) {
4140 zone
.system_key
.id
= access_key
;
4141 need_zone_update
= true;
4144 if (!secret_key
.empty()) {
4145 zone
.system_key
.key
= secret_key
;
4146 need_zone_update
= true;
4149 if (!realm_id
.empty()) {
4150 zone
.realm_id
= realm_id
;
4151 need_zone_update
= true;
4152 } else if (!realm_name
.empty()) {
4153 // get realm id from name
4154 RGWRealm realm
{g_ceph_context
, store
};
4155 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4157 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4160 need_zone_update
= true;
4163 for (auto add
: tier_config_add
) {
4164 zone
.tier_config
[add
.first
] = add
.second
;
4165 need_zone_update
= true;
4168 for (auto rm
: tier_config_rm
) {
4169 zone
.tier_config
.erase(rm
.first
);
4170 need_zone_update
= true;
4173 if (need_zone_update
) {
4174 ret
= zone
.update();
4176 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4181 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4182 ret
= zonegroup
.init(g_ceph_context
, store
);
4184 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4187 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4189 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4191 ret
= zonegroup
.add_zone(zone
,
4192 (is_master_set
? &is_master
: NULL
),
4193 (is_read_only_set
? &read_only
: NULL
),
4194 endpoints
, ptier_type
,
4195 psync_from_all
, sync_from
, sync_from_rm
);
4197 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4201 ret
= zonegroup
.update();
4203 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4208 ret
= zone
.set_as_default();
4210 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4214 encode_json("zone", zone
, formatter
);
4215 formatter
->flush(cout
);
4218 case OPT_ZONE_RENAME
:
4220 if (zone_new_name
.empty()) {
4221 cerr
<< " missing zone new name" << std::endl
;
4224 if (zone_id
.empty() && zone_name
.empty()) {
4225 cerr
<< "no zonegroup name or id provided" << std::endl
;
4228 RGWZoneParams
zone(zone_id
,zone_name
);
4229 int ret
= zone
.init(g_ceph_context
, store
);
4231 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4234 ret
= zone
.rename(zone_new_name
);
4236 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4240 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4241 ret
= zonegroup
.init(g_ceph_context
, store
);
4243 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4245 ret
= zonegroup
.rename_zone(zone
);
4246 if (ret
< 0 && ret
) {
4247 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4253 case OPT_ZONE_PLACEMENT_ADD
:
4254 case OPT_ZONE_PLACEMENT_MODIFY
:
4255 case OPT_ZONE_PLACEMENT_RM
:
4257 if (placement_id
.empty()) {
4258 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4261 // validate compression type
4262 if (compression_type
&& *compression_type
!= "random"
4263 && !Compressor::get_comp_alg_type(*compression_type
)) {
4264 std::cerr
<< "Unrecognized compression type" << std::endl
;
4268 RGWZoneParams
zone(zone_id
, zone_name
);
4269 int ret
= zone
.init(g_ceph_context
, store
);
4271 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4275 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4276 // pool names are required
4277 if (!index_pool
|| index_pool
->empty() ||
4278 !data_pool
|| data_pool
->empty()) {
4279 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4283 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4285 info
.index_pool
= *index_pool
;
4286 info
.data_pool
= *data_pool
;
4287 if (data_extra_pool
) {
4288 info
.data_extra_pool
= *data_extra_pool
;
4290 if (index_type_specified
) {
4291 info
.index_type
= placement_index_type
;
4293 if (compression_type
) {
4294 info
.compression_type
= *compression_type
;
4296 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4297 auto p
= zone
.placement_pools
.find(placement_id
);
4298 if (p
== zone
.placement_pools
.end()) {
4299 cerr
<< "ERROR: zone placement target '" << placement_id
4300 << "' not found" << std::endl
;
4303 auto& info
= p
->second
;
4304 if (index_pool
&& !index_pool
->empty()) {
4305 info
.index_pool
= *index_pool
;
4307 if (data_pool
&& !data_pool
->empty()) {
4308 info
.data_pool
= *data_pool
;
4310 if (data_extra_pool
) {
4311 info
.data_extra_pool
= *data_extra_pool
;
4313 if (index_type_specified
) {
4314 info
.index_type
= placement_index_type
;
4316 if (compression_type
) {
4317 info
.compression_type
= *compression_type
;
4319 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4320 zone
.placement_pools
.erase(placement_id
);
4323 ret
= zone
.update();
4325 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4329 encode_json("zone", zone
, formatter
);
4330 formatter
->flush(cout
);
4333 case OPT_ZONE_PLACEMENT_LIST
:
4335 RGWZoneParams
zone(zone_id
, zone_name
);
4336 int ret
= zone
.init(g_ceph_context
, store
);
4338 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4341 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4342 formatter
->flush(cout
);
4349 if (!user_id
.empty()) {
4350 user_op
.set_user_id(user_id
);
4351 bucket_op
.set_user_id(user_id
);
4354 if (!display_name
.empty())
4355 user_op
.set_display_name(display_name
);
4357 if (!user_email
.empty())
4358 user_op
.set_user_email(user_email
);
4360 if (!access_key
.empty())
4361 user_op
.set_access_key(access_key
);
4363 if (!secret_key
.empty())
4364 user_op
.set_secret_key(secret_key
);
4366 if (!subuser
.empty())
4367 user_op
.set_subuser(subuser
);
4370 user_op
.set_caps(caps
);
4372 user_op
.set_purge_data(purge_data
);
4375 user_op
.set_purge_keys();
4378 user_op
.set_generate_key();
4381 user_op
.set_gen_secret(); // assume that a key pair should be created
4383 if (max_buckets_specified
)
4384 user_op
.set_max_buckets(max_buckets
);
4386 if (admin_specified
)
4387 user_op
.set_admin(admin
);
4389 if (system_specified
)
4390 user_op
.set_system(system
);
4393 user_op
.set_perm(perm_mask
);
4395 if (set_temp_url_key
) {
4396 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4397 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4398 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4402 if (!op_mask_str
.empty()) {
4404 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4406 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4410 user_op
.set_op_mask(op_mask
);
4413 if (key_type
!= KEY_TYPE_UNDEFINED
)
4414 user_op
.set_key_type(key_type
);
4416 // set suspension operation parameters
4417 if (opt_cmd
== OPT_USER_ENABLE
)
4418 user_op
.set_suspension(false);
4419 else if (opt_cmd
== OPT_USER_SUSPEND
)
4420 user_op
.set_suspension(true);
4422 // RGWUser to use for user operations
4425 if (!user_id
.empty() || !subuser
.empty()) {
4426 ret
= user
.init(store
, user_op
);
4428 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4433 /* populate bucket operation */
4434 bucket_op
.set_bucket_name(bucket_name
);
4435 bucket_op
.set_object(object
);
4436 bucket_op
.set_check_objects(check_objects
);
4437 bucket_op
.set_delete_children(delete_child_objects
);
4438 bucket_op
.set_fix_index(fix
);
4439 bucket_op
.set_max_aio(max_concurrent_ios
);
4441 // required to gather errors from operations
4442 std::string err_msg
;
4444 bool output_user_info
= true;
4449 case OPT_USER_CREATE
:
4450 if (!user_op
.has_existing_user()) {
4451 user_op
.set_generate_key(); // generate a new key by default
4453 ret
= user
.add(user_op
, &err_msg
);
4455 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4456 if (ret
== -ERR_INVALID_TENANT_NAME
)
4461 if (!subuser
.empty()) {
4462 ret
= user
.subusers
.add(user_op
, &err_msg
);
4464 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4470 ret
= user
.remove(user_op
, &err_msg
);
4472 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4476 output_user_info
= false;
4478 case OPT_USER_ENABLE
:
4479 case OPT_USER_SUSPEND
:
4480 case OPT_USER_MODIFY
:
4481 ret
= user
.modify(user_op
, &err_msg
);
4483 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4488 case OPT_SUBUSER_CREATE
:
4489 ret
= user
.subusers
.add(user_op
, &err_msg
);
4491 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4496 case OPT_SUBUSER_MODIFY
:
4497 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4499 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4504 case OPT_SUBUSER_RM
:
4505 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4507 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4513 ret
= user
.caps
.add(user_op
, &err_msg
);
4515 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4521 ret
= user
.caps
.remove(user_op
, &err_msg
);
4523 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4528 case OPT_KEY_CREATE
:
4529 ret
= user
.keys
.add(user_op
, &err_msg
);
4531 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4537 ret
= user
.keys
.remove(user_op
, &err_msg
);
4539 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4543 case OPT_PERIOD_PUSH
:
4546 req_info
info(g_ceph_context
, &env
);
4547 info
.method
= "POST";
4548 info
.request_uri
= "/admin/realm/period";
4550 map
<string
, string
> ¶ms
= info
.args
.get_params();
4551 if (!realm_id
.empty())
4552 params
["realm_id"] = realm_id
;
4553 if (!realm_name
.empty())
4554 params
["realm_name"] = realm_name
;
4555 if (!period_id
.empty())
4556 params
["period_id"] = period_id
;
4557 if (!period_epoch
.empty())
4558 params
["epoch"] = period_epoch
;
4561 RGWPeriod
period(period_id
);
4562 int ret
= period
.init(g_ceph_context
, store
);
4564 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4567 // json format into a bufferlist
4568 JSONFormatter
jf(false);
4569 encode_json("period", period
, &jf
);
4574 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4577 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4582 case OPT_PERIOD_UPDATE
:
4584 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4585 commit
, remote
, url
, access_key
, secret_key
,
4586 formatter
, yes_i_really_mean_it
);
4592 case OPT_PERIOD_COMMIT
:
4594 // read realm and staging period
4595 RGWRealm
realm(realm_id
, realm_name
);
4596 int ret
= realm
.init(g_ceph_context
, store
);
4598 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4601 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4602 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4604 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4607 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4608 yes_i_really_mean_it
);
4610 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4614 encode_json("period", period
, formatter
);
4615 formatter
->flush(cout
);
4619 case OPT_ROLE_CREATE
:
4621 if (role_name
.empty()) {
4622 cerr
<< "ERROR: role name is empty" << std::endl
;
4626 if (assume_role_doc
.empty()) {
4627 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4630 /* The following two calls will be replaced by read_decode_json or something
4631 similar when the code for AWS Policies is in places */
4633 int ret
= read_input(assume_role_doc
, bl
);
4635 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4639 if (!p
.parse(bl
.c_str(), bl
.length())) {
4640 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4643 string trust_policy
= bl
.to_str();
4644 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4645 ret
= role
.create(true);
4649 show_role_info(role
, formatter
);
4652 case OPT_ROLE_DELETE
:
4654 if (role_name
.empty()) {
4655 cerr
<< "ERROR: empty role name" << std::endl
;
4658 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4659 ret
= role
.delete_obj();
4663 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4668 if (role_name
.empty()) {
4669 cerr
<< "ERROR: empty role name" << std::endl
;
4672 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4677 show_role_info(role
, formatter
);
4680 case OPT_ROLE_MODIFY
:
4682 if (role_name
.empty()) {
4683 cerr
<< "ERROR: role name is empty" << std::endl
;
4687 if (assume_role_doc
.empty()) {
4688 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4692 /* The following two calls will be replaced by read_decode_json or something
4693 similar when the code for AWS Policies is in place */
4695 int ret
= read_input(assume_role_doc
, bl
);
4697 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4701 if (!p
.parse(bl
.c_str(), bl
.length())) {
4702 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4705 string trust_policy
= bl
.to_str();
4706 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4711 role
.update_trust_policy(trust_policy
);
4712 ret
= role
.update();
4716 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4721 vector
<RGWRole
> result
;
4722 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4726 show_roles_info(result
, formatter
);
4729 case OPT_ROLE_POLICY_PUT
:
4731 if (role_name
.empty()) {
4732 cerr
<< "role name is empty" << std::endl
;
4736 if (policy_name
.empty()) {
4737 cerr
<< "policy name is empty" << std::endl
;
4741 if (perm_policy_doc
.empty()) {
4742 cerr
<< "permission policy document is empty" << std::endl
;
4746 /* The following two calls will be replaced by read_decode_json or something
4747 similar, when code for AWS Policies is in place.*/
4749 int ret
= read_input(perm_policy_doc
, bl
);
4751 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4755 if (!p
.parse(bl
.c_str(), bl
.length())) {
4756 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
4760 perm_policy
= bl
.c_str();
4762 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4767 role
.set_perm_policy(policy_name
, perm_policy
);
4768 ret
= role
.update();
4772 cout
<< "Permission policy attached successfully" << std::endl
;
4775 case OPT_ROLE_POLICY_LIST
:
4777 if (role_name
.empty()) {
4778 cerr
<< "ERROR: Role name is empty" << std::endl
;
4781 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4786 std::vector
<string
> policy_names
= role
.get_role_policy_names();
4787 show_policy_names(policy_names
, formatter
);
4790 case OPT_ROLE_POLICY_GET
:
4792 if (role_name
.empty()) {
4793 cerr
<< "ERROR: role name is empty" << std::endl
;
4797 if (policy_name
.empty()) {
4798 cerr
<< "ERROR: policy name is empty" << std::endl
;
4801 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4802 int ret
= role
.get();
4807 ret
= role
.get_role_policy(policy_name
, perm_policy
);
4811 show_perm_policy(perm_policy
, formatter
);
4814 case OPT_ROLE_POLICY_DELETE
:
4816 if (role_name
.empty()) {
4817 cerr
<< "ERROR: role name is empty" << std::endl
;
4821 if (policy_name
.empty()) {
4822 cerr
<< "ERROR: policy name is empty" << std::endl
;
4825 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4830 ret
= role
.delete_policy(policy_name
);
4834 ret
= role
.update();
4838 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
4839 << role_name
<< std::endl
;
4843 output_user_info
= false;
4846 // output the result of a user operation
4847 if (output_user_info
) {
4848 ret
= user
.info(info
, &err_msg
);
4850 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
4853 show_user_info(info
, formatter
);
4856 if (opt_cmd
== OPT_POLICY
) {
4857 if (format
== "xml") {
4858 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
4860 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4864 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
4866 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4872 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
4874 std::list
<std::string
> user_ids
;
4875 metadata_key
= "user";
4880 if (! user_id
.empty()) {
4881 user_ids
.push_back(user_id
.id
);
4883 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4886 /* list users in groups of max-keys, then perform user-bucket
4887 * limit-check on each group */
4888 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
4890 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
4891 << cpp_strerror(-ret
) << std::endl
;
4896 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
4898 if (ret
< 0 && ret
!= -ENOENT
) {
4899 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
4900 << cpp_strerror(-ret
) << std::endl
;
4903 /* ok, do the limit checks for this group */
4905 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4911 } while (truncated
);
4912 store
->meta_mgr
->list_keys_complete(handle
);
4915 } /* OPT_BUCKET_LIMIT_CHECK */
4917 if (opt_cmd
== OPT_BUCKETS_LIST
) {
4918 if (bucket_name
.empty()) {
4919 RGWBucketAdminOp::info(store
, bucket_op
, f
);
4921 RGWBucketInfo bucket_info
;
4922 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
4924 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
4927 formatter
->open_array_section("entries");
4930 if (max_entries
< 0)
4935 vector
<rgw_bucket_dir_entry
> result
;
4936 map
<string
, bool> common_prefixes
;
4939 RGWRados::Bucket
target(store
, bucket_info
);
4940 RGWRados::Bucket::List
list_op(&target
);
4942 list_op
.params
.prefix
= prefix
;
4943 list_op
.params
.delim
= delim
;
4944 list_op
.params
.marker
= rgw_obj_key(marker
);
4945 list_op
.params
.ns
= ns
;
4946 list_op
.params
.enforce_ns
= false;
4947 list_op
.params
.list_versions
= true;
4950 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
4952 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
4956 count
+= result
.size();
4958 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
4959 rgw_bucket_dir_entry
& entry
= *iter
;
4960 encode_json("entry", entry
, formatter
);
4962 formatter
->flush(cout
);
4963 } while (truncated
&& count
< max_entries
);
4965 formatter
->close_section();
4966 formatter
->flush(cout
);
4967 } /* have bucket_name */
4968 } /* OPT_BUCKETS_LIST */
4970 if (opt_cmd
== OPT_BUCKET_STATS
) {
4971 bucket_op
.set_fetch_stats(true);
4973 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
4975 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4980 if (opt_cmd
== OPT_BUCKET_LINK
) {
4981 bucket_op
.set_bucket_id(bucket_id
);
4983 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
4985 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4990 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
4991 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
4993 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
4998 if (opt_cmd
== OPT_LOG_LIST
) {
5000 if (date
.size() && date
.size() != 10) {
5001 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
5006 formatter
->open_array_section("logs");
5008 int r
= store
->log_list_init(date
, &h
);
5013 cerr
<< "log list: error " << r
<< std::endl
;
5018 int r
= store
->log_list_next(h
, &name
);
5022 cerr
<< "log list: error " << r
<< std::endl
;
5025 formatter
->dump_string("object", name
);
5028 formatter
->close_section();
5029 formatter
->flush(cout
);
5033 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5034 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5035 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5041 if (!object
.empty()) {
5051 if (opt_cmd
== OPT_LOG_SHOW
) {
5054 int r
= store
->log_show_init(oid
, &h
);
5056 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5061 formatter
->open_object_section("log");
5063 struct rgw_log_entry entry
;
5065 // peek at first entry to get bucket metadata
5066 r
= store
->log_show_next(h
, &entry
);
5068 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5071 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5072 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5073 formatter
->dump_string("bucket", entry
.bucket
);
5075 uint64_t agg_time
= 0;
5076 uint64_t agg_bytes_sent
= 0;
5077 uint64_t agg_bytes_received
= 0;
5078 uint64_t total_entries
= 0;
5080 if (show_log_entries
)
5081 formatter
->open_array_section("log_entries");
5084 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5086 agg_time
+= total_time
;
5087 agg_bytes_sent
+= entry
.bytes_sent
;
5088 agg_bytes_received
+= entry
.bytes_received
;
5091 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5092 entry
.bytes_received
== 0)
5095 if (show_log_entries
) {
5097 rgw_format_ops_log_entry(entry
, formatter
);
5098 formatter
->flush(cout
);
5101 r
= store
->log_show_next(h
, &entry
);
5105 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5108 if (show_log_entries
)
5109 formatter
->close_section();
5112 formatter
->open_object_section("log_sum");
5113 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5114 formatter
->dump_int("bytes_received", agg_bytes_received
);
5115 formatter
->dump_int("total_time", agg_time
);
5116 formatter
->dump_int("total_entries", total_entries
);
5117 formatter
->close_section();
5119 formatter
->close_section();
5120 formatter
->flush(cout
);
5123 if (opt_cmd
== OPT_LOG_RM
) {
5124 int r
= store
->log_remove(oid
);
5126 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5132 if (opt_cmd
== OPT_POOL_ADD
) {
5133 if (pool_name
.empty()) {
5134 cerr
<< "need to specify pool to add!" << std::endl
;
5139 int ret
= store
->add_bucket_placement(pool
);
5141 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5144 if (opt_cmd
== OPT_POOL_RM
) {
5145 if (pool_name
.empty()) {
5146 cerr
<< "need to specify pool to remove!" << std::endl
;
5151 int ret
= store
->remove_bucket_placement(pool
);
5153 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5156 if (opt_cmd
== OPT_POOLS_LIST
) {
5157 set
<rgw_pool
> pools
;
5158 int ret
= store
->list_placement_set(pools
);
5160 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5164 formatter
->open_array_section("pools");
5165 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5166 formatter
->open_object_section("pool");
5167 formatter
->dump_string("name", siter
->to_str());
5168 formatter
->close_section();
5170 formatter
->close_section();
5171 formatter
->flush(cout
);
5175 if (opt_cmd
== OPT_USAGE_SHOW
) {
5176 uint64_t start_epoch
= 0;
5177 uint64_t end_epoch
= (uint64_t)-1;
5181 if (!start_date
.empty()) {
5182 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5184 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5188 if (!end_date
.empty()) {
5189 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5191 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5197 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5198 show_log_entries
, show_log_sum
, &categories
,
5201 cerr
<< "ERROR: failed to show usage" << std::endl
;
5206 if (opt_cmd
== OPT_USAGE_TRIM
) {
5207 if (user_id
.empty() && !yes_i_really_mean_it
) {
5208 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5209 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5213 uint64_t start_epoch
= 0;
5214 uint64_t end_epoch
= (uint64_t)-1;
5217 if (!start_date
.empty()) {
5218 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5220 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5225 if (!end_date
.empty()) {
5226 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5228 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5233 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5235 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5240 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5241 if (bucket_name
.empty()) {
5242 cerr
<< "ERROR: bucket not specified" << std::endl
;
5245 if (object
.empty()) {
5246 cerr
<< "ERROR: object not specified" << std::endl
;
5251 if (opt_cmd
== OPT_OLH_GET
) {
5252 RGWBucketInfo bucket_info
;
5253 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5255 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5259 rgw_obj
obj(bucket
, object
);
5260 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5262 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5265 encode_json("olh", olh
, formatter
);
5266 formatter
->flush(cout
);
5269 if (opt_cmd
== OPT_OLH_READLOG
) {
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
;
5276 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5279 RGWObjectCtx
rctx(store
);
5280 rgw_obj
obj(bucket
, object
);
5284 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5289 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5291 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5294 formatter
->open_object_section("result");
5295 encode_json("is_truncated", is_truncated
, formatter
);
5296 encode_json("log", log
, formatter
);
5297 formatter
->close_section();
5298 formatter
->flush(cout
);
5301 if (opt_cmd
== OPT_BI_GET
) {
5302 RGWBucketInfo bucket_info
;
5303 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5305 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5308 rgw_obj
obj(bucket
, object
);
5309 if (!object_version
.empty()) {
5310 obj
.key
.set_instance(object_version
);
5313 rgw_cls_bi_entry entry
;
5315 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5317 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5321 encode_json("entry", entry
, formatter
);
5322 formatter
->flush(cout
);
5325 if (opt_cmd
== OPT_BI_PUT
) {
5326 RGWBucketInfo bucket_info
;
5327 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5329 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5333 rgw_cls_bi_entry entry
;
5334 cls_rgw_obj_key key
;
5335 ret
= read_decode_json(infile
, entry
, &key
);
5340 rgw_obj
obj(bucket
, key
);
5342 ret
= store
->bi_put(bucket
, obj
, entry
);
5344 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5349 if (opt_cmd
== OPT_BI_LIST
) {
5350 if (bucket_name
.empty()) {
5351 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5354 RGWBucketInfo bucket_info
;
5355 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5357 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5361 list
<rgw_cls_bi_entry
> entries
;
5363 if (max_entries
< 0) {
5367 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5369 formatter
->open_array_section("entries");
5371 for (int i
= 0; i
< max_shards
; i
++) {
5372 RGWRados::BucketShard
bs(store
);
5373 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5374 int ret
= bs
.init(bucket
, shard_id
);
5378 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5384 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5386 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5390 list
<rgw_cls_bi_entry
>::iterator iter
;
5391 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5392 rgw_cls_bi_entry
& entry
= *iter
;
5393 encode_json("entry", entry
, formatter
);
5396 formatter
->flush(cout
);
5397 } while (is_truncated
);
5398 formatter
->flush(cout
);
5400 formatter
->close_section();
5401 formatter
->flush(cout
);
5404 if (opt_cmd
== OPT_BI_PURGE
) {
5405 if (bucket_name
.empty()) {
5406 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5409 RGWBucketInfo bucket_info
;
5410 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5412 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5416 RGWBucketInfo cur_bucket_info
;
5417 rgw_bucket cur_bucket
;
5418 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5420 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5424 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5425 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5426 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5430 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5432 for (int i
= 0; i
< max_shards
; i
++) {
5433 RGWRados::BucketShard
bs(store
);
5434 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5435 int ret
= bs
.init(bucket
, shard_id
);
5437 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5441 ret
= store
->bi_remove(bs
);
5443 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5449 if (opt_cmd
== OPT_OBJECT_RM
) {
5450 RGWBucketInfo bucket_info
;
5451 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5453 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5456 rgw_obj_key
key(object
, object_version
);
5457 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5460 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5465 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5466 if (bucket_name
.empty()) {
5467 cerr
<< "ERROR: bucket not specified" << std::endl
;
5470 if (object
.empty()) {
5471 cerr
<< "ERROR: object not specified" << std::endl
;
5475 RGWBucketInfo bucket_info
;
5476 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5478 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5482 rgw_obj
obj(bucket
, object
);
5483 obj
.key
.set_instance(object_version
);
5484 bool need_rewrite
= true;
5485 if (min_rewrite_stripe_size
> 0) {
5486 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5488 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5492 ret
= store
->rewrite_obj(bucket_info
, obj
);
5494 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5498 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5502 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5503 int ret
= store
->process_expire_objects();
5505 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5510 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5511 if (bucket_name
.empty()) {
5512 cerr
<< "ERROR: bucket not specified" << std::endl
;
5516 RGWBucketInfo bucket_info
;
5517 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5519 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5523 uint64_t start_epoch
= 0;
5524 uint64_t end_epoch
= 0;
5526 if (!end_date
.empty()) {
5527 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5529 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5533 if (!start_date
.empty()) {
5534 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5536 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5541 bool is_truncated
= true;
5543 rgw_obj_index_key marker
;
5546 formatter
->open_object_section("result");
5547 formatter
->dump_string("bucket", bucket_name
);
5548 formatter
->open_array_section("objects");
5549 while (is_truncated
) {
5550 map
<string
, rgw_bucket_dir_entry
> result
;
5551 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5552 result
, &is_truncated
, &marker
,
5553 bucket_object_check_filter
);
5555 if (r
< 0 && r
!= -ENOENT
) {
5556 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5562 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5563 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5564 rgw_obj_key key
= iter
->second
.key
;
5565 rgw_bucket_dir_entry
& entry
= iter
->second
;
5567 formatter
->open_object_section("object");
5568 formatter
->dump_string("name", key
.name
);
5569 formatter
->dump_string("instance", key
.instance
);
5570 formatter
->dump_int("size", entry
.meta
.size
);
5571 utime_t
ut(entry
.meta
.mtime
);
5572 ut
.gmtime(formatter
->dump_stream("mtime"));
5574 if ((entry
.meta
.size
< min_rewrite_size
) ||
5575 (entry
.meta
.size
> max_rewrite_size
) ||
5576 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5577 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5578 formatter
->dump_string("status", "Skipped");
5580 rgw_obj
obj(bucket
, key
);
5582 bool need_rewrite
= true;
5583 if (min_rewrite_stripe_size
> 0) {
5584 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5586 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5589 if (!need_rewrite
) {
5590 formatter
->dump_string("status", "Skipped");
5592 r
= store
->rewrite_obj(bucket_info
, obj
);
5594 formatter
->dump_string("status", "Success");
5596 formatter
->dump_string("status", cpp_strerror(-r
));
5600 formatter
->dump_int("flags", entry
.flags
);
5602 formatter
->close_section();
5603 formatter
->flush(cout
);
5606 formatter
->close_section();
5607 formatter
->close_section();
5608 formatter
->flush(cout
);
5611 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5613 RGWBucketInfo bucket_info
;
5614 map
<string
, bufferlist
> attrs
;
5616 int ret
= check_reshard_bucket_params(store
,
5620 num_shards_specified
,
5622 yes_i_really_mean_it
,
5630 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5632 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5633 if (max_entries
< 1) {
5634 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5637 return br
.execute(num_shards
, max_entries
,
5638 verbose
, &cout
, formatter
);
5641 if (opt_cmd
== OPT_RESHARD_ADD
) {
5643 RGWBucketInfo bucket_info
;
5644 map
<string
, bufferlist
> attrs
;
5646 int ret
= check_reshard_bucket_params(store
,
5650 num_shards_specified
,
5652 yes_i_really_mean_it
,
5660 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5662 RGWReshard
reshard(store
);
5663 cls_rgw_reshard_entry entry
;
5664 entry
.time
= real_clock::now();
5665 entry
.tenant
= tenant
;
5666 entry
.bucket_name
= bucket_name
;
5667 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5668 entry
.old_num_shards
= num_source_shards
;
5669 entry
.new_num_shards
= num_shards
;
5671 return reshard
.add(entry
);
5674 if (opt_cmd
== OPT_RESHARD_LIST
) {
5675 list
<cls_rgw_reshard_entry
> entries
;
5678 if (max_entries
< 0) {
5682 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5684 RGWReshard
reshard(store
);
5686 formatter
->open_array_section("reshard");
5687 for (int i
= 0; i
< num_logshards
; i
++) {
5688 bool is_truncated
= true;
5692 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5694 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5697 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5698 cls_rgw_reshard_entry
& entry
= *iter
;
5699 encode_json("entry", entry
, formatter
);
5700 entry
.get_key(&marker
);
5702 count
+= entries
.size();
5703 formatter
->flush(cout
);
5704 } while (is_truncated
&& count
< max_entries
);
5706 if (count
>= max_entries
) {
5711 formatter
->close_section();
5712 formatter
->flush(cout
);
5717 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5718 if (bucket_name
.empty()) {
5719 cerr
<< "ERROR: bucket not specified" << std::endl
;
5724 RGWBucketInfo bucket_info
;
5725 map
<string
, bufferlist
> attrs
;
5726 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5728 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5732 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5733 list
<cls_rgw_bucket_instance_entry
> status
;
5734 int r
= br
.get_status(&status
);
5736 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5740 encode_json("status", status
, formatter
);
5741 formatter
->flush(cout
);
5744 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5745 RGWReshard
reshard(store
, true, &cout
);
5747 int ret
= reshard
.process_all_logshards();
5749 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
5754 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
5755 RGWReshard
reshard(store
);
5757 if (bucket_name
.empty()) {
5758 cerr
<< "ERROR: bucket not specified" << std::endl
;
5761 cls_rgw_reshard_entry entry
;
5762 //entry.tenant = tenant;
5763 entry
.bucket_name
= bucket_name
;
5764 //entry.bucket_id = bucket_id;
5765 int ret
= reshard
.get(entry
);
5767 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5771 /* TBD stop running resharding */
5773 ret
=reshard
.remove(entry
);
5775 cerr
<< "Error removing bucket " << bucket_name
<< " for resharding queue: " << cpp_strerror(-ret
) <<
5781 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
5782 RGWBucketInfo bucket_info
;
5783 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5785 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5788 list
<rgw_obj_index_key
> oid_list
;
5789 rgw_obj_key
key(object
, object_version
);
5790 rgw_obj_index_key index_key
;
5791 key
.get_index_key(&index_key
);
5792 oid_list
.push_back(index_key
);
5793 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
5795 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
5800 if (opt_cmd
== OPT_OBJECT_STAT
) {
5801 RGWBucketInfo bucket_info
;
5802 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5804 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5807 rgw_obj
obj(bucket
, object
);
5808 obj
.key
.set_instance(object_version
);
5811 map
<string
, bufferlist
> attrs
;
5812 RGWObjectCtx
obj_ctx(store
);
5813 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
5814 RGWRados::Object::Read
read_op(&op_target
);
5816 read_op
.params
.attrs
= &attrs
;
5817 read_op
.params
.obj_size
= &obj_size
;
5819 ret
= read_op
.prepare();
5821 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
5824 formatter
->open_object_section("object_metadata");
5825 formatter
->dump_string("name", object
);
5826 formatter
->dump_unsigned("size", obj_size
);
5828 map
<string
, bufferlist
>::iterator iter
;
5829 map
<string
, bufferlist
> other_attrs
;
5830 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5831 bufferlist
& bl
= iter
->second
;
5832 bool handled
= false;
5833 if (iter
->first
== RGW_ATTR_MANIFEST
) {
5834 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
5835 } else if (iter
->first
== RGW_ATTR_ACL
) {
5836 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
5837 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
5838 handled
= dump_string("tag", bl
, formatter
);
5839 } else if (iter
->first
== RGW_ATTR_ETAG
) {
5840 handled
= dump_string("etag", bl
, formatter
);
5844 other_attrs
[iter
->first
] = bl
;
5847 formatter
->open_object_section("attrs");
5848 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
5849 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
5851 formatter
->close_section();
5852 formatter
->close_section();
5853 formatter
->flush(cout
);
5856 if (opt_cmd
== OPT_BUCKET_CHECK
) {
5857 if (check_head_obj_locator
) {
5858 if (bucket_name
.empty()) {
5859 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
5862 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
5864 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
5868 if (opt_cmd
== OPT_BUCKET_RM
) {
5869 if (inconsistent_index
== false) {
5870 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
5872 if (!yes_i_really_mean_it
) {
5873 cerr
<< "using --inconsistent_index can corrupt the bucket index " << std::endl
5874 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5877 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
5881 if (opt_cmd
== OPT_GC_LIST
) {
5884 formatter
->open_array_section("entries");
5887 list
<cls_rgw_gc_obj_info
> result
;
5888 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
5890 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5895 list
<cls_rgw_gc_obj_info
>::iterator iter
;
5896 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5897 cls_rgw_gc_obj_info
& info
= *iter
;
5898 formatter
->open_object_section("chain_info");
5899 formatter
->dump_string("tag", info
.tag
);
5900 formatter
->dump_stream("time") << info
.time
;
5901 formatter
->open_array_section("objs");
5902 list
<cls_rgw_obj
>::iterator liter
;
5903 cls_rgw_obj_chain
& chain
= info
.chain
;
5904 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
5905 cls_rgw_obj
& obj
= *liter
;
5906 encode_json("obj", obj
, formatter
);
5908 formatter
->close_section(); // objs
5909 formatter
->close_section(); // obj_chain
5910 formatter
->flush(cout
);
5912 } while (truncated
);
5913 formatter
->close_section();
5914 formatter
->flush(cout
);
5917 if (opt_cmd
== OPT_GC_PROCESS
) {
5918 int ret
= store
->process_gc();
5920 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5925 if (opt_cmd
== OPT_LC_LIST
) {
5926 formatter
->open_array_section("lifecycle_list");
5927 map
<string
, int> bucket_lc_map
;
5929 #define MAX_LC_LIST_ENTRIES 100
5930 if (max_entries
< 0) {
5931 max_entries
= MAX_LC_LIST_ENTRIES
;
5934 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
5936 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5939 map
<string
, int>::iterator iter
;
5940 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
5941 formatter
->open_object_section("bucket_lc_info");
5942 formatter
->dump_string("bucket", iter
->first
);
5943 string lc_status
= LC_STATUS
[iter
->second
];
5944 formatter
->dump_string("status", lc_status
);
5945 formatter
->close_section(); // objs
5946 formatter
->flush(cout
);
5947 marker
= iter
->first
;
5949 } while (!bucket_lc_map
.empty());
5951 formatter
->close_section(); //lifecycle list
5952 formatter
->flush(cout
);
5956 if (opt_cmd
== OPT_LC_PROCESS
) {
5957 int ret
= store
->process_lc();
5959 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5964 if (opt_cmd
== OPT_ORPHANS_FIND
) {
5965 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5967 if (job_id
.empty()) {
5968 cerr
<< "ERROR: --job-id not specified" << std::endl
;
5971 if (pool_name
.empty()) {
5972 cerr
<< "ERROR: --pool not specified" << std::endl
;
5976 RGWOrphanSearchInfo info
;
5979 info
.job_name
= job_id
;
5980 info
.num_shards
= num_shards
;
5982 int ret
= search
.init(job_id
, &info
);
5984 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
5993 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
5994 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
5996 if (job_id
.empty()) {
5997 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6000 int ret
= search
.init(job_id
, NULL
);
6002 if (ret
== -ENOENT
) {
6003 cerr
<< "job not found" << std::endl
;
6007 ret
= search
.finish();
6013 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
6014 RGWOrphanStore
orphan_store(store
);
6015 int ret
= orphan_store
.init();
6017 cerr
<< "connection to cluster failed!" << std::endl
;
6021 map
<string
,RGWOrphanSearchState
> m
;
6022 ret
= orphan_store
.list_jobs(m
);
6024 cerr
<< "job list failed" << std::endl
;
6027 formatter
->open_array_section("entries");
6028 for (const auto &it
: m
){
6030 formatter
->dump_string("job-id",it
.first
);
6032 encode_json("orphan_search_state", it
.second
, formatter
);
6035 formatter
->close_section();
6036 formatter
->flush(cout
);
6039 if (opt_cmd
== OPT_USER_CHECK
) {
6040 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6043 if (opt_cmd
== OPT_USER_STATS
) {
6045 if (!bucket_name
.empty()) {
6046 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6048 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
6052 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6054 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
6060 if (user_id
.empty()) {
6061 cerr
<< "ERROR: uid not specified" << std::endl
;
6064 cls_user_header header
;
6065 string user_str
= user_id
.to_str();
6066 int ret
= store
->cls_user_get_header(user_str
, &header
);
6068 if (ret
== -ENOENT
) { /* in case of ENOENT */
6069 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6071 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6076 encode_json("header", header
, formatter
);
6077 formatter
->flush(cout
);
6080 if (opt_cmd
== OPT_METADATA_GET
) {
6081 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6083 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6087 formatter
->flush(cout
);
6090 if (opt_cmd
== OPT_METADATA_PUT
) {
6092 int ret
= read_input(infile
, bl
);
6094 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6097 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6099 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6104 if (opt_cmd
== OPT_METADATA_RM
) {
6105 int ret
= store
->meta_mgr
->remove(metadata_key
);
6107 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6112 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6113 if (opt_cmd
== OPT_USER_LIST
) {
6114 metadata_key
= "user";
6118 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, marker
, &handle
);
6120 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6127 if (max_entries_specified
) {
6128 formatter
->open_object_section("result");
6130 formatter
->open_array_section("keys");
6135 left
= (max_entries_specified
? max_entries
- count
: max
);
6136 ret
= store
->meta_mgr
->list_keys_next(handle
, left
, keys
, &truncated
);
6137 if (ret
< 0 && ret
!= -ENOENT
) {
6138 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6140 } if (ret
!= -ENOENT
) {
6141 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6142 formatter
->dump_string("key", *iter
);
6145 formatter
->flush(cout
);
6147 } while (truncated
&& left
> 0);
6149 formatter
->close_section();
6151 if (max_entries_specified
) {
6152 encode_json("truncated", truncated
, formatter
);
6153 encode_json("count", count
, formatter
);
6155 encode_json("marker", store
->meta_mgr
->get_marker(handle
), formatter
);
6157 formatter
->close_section();
6159 formatter
->flush(cout
);
6161 store
->meta_mgr
->list_keys_complete(handle
);
6164 if (opt_cmd
== OPT_MDLOG_LIST
) {
6165 utime_t start_time
, end_time
;
6167 int ret
= parse_date_str(start_date
, start_time
);
6171 ret
= parse_date_str(end_date
, end_time
);
6175 int i
= (specified_shard_id
? shard_id
: 0);
6177 if (period_id
.empty()) {
6178 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6182 std::cerr
<< "No --period given, using current period="
6183 << period_id
<< std::endl
;
6185 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6187 formatter
->open_array_section("entries");
6188 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6190 list
<cls_log_entry
> entries
;
6193 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6196 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6198 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6202 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6203 cls_log_entry
& entry
= *iter
;
6204 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6206 formatter
->flush(cout
);
6207 } while (truncated
);
6209 meta_log
->complete_list_entries(handle
);
6211 if (specified_shard_id
)
6216 formatter
->close_section();
6217 formatter
->flush(cout
);
6220 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6221 int i
= (specified_shard_id
? shard_id
: 0);
6223 if (period_id
.empty()) {
6224 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6228 std::cerr
<< "No --period given, using current period="
6229 << period_id
<< std::endl
;
6231 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6233 formatter
->open_array_section("entries");
6235 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6236 RGWMetadataLogInfo info
;
6237 meta_log
->get_info(i
, &info
);
6239 ::encode_json("info", info
, formatter
);
6241 if (specified_shard_id
)
6246 formatter
->close_section();
6247 formatter
->flush(cout
);
6250 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6251 // need a full history for purging old mdlog periods
6252 store
->meta_mgr
->init_oldest_log_period();
6254 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6255 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6256 int ret
= http
.set_threaded();
6258 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6262 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6263 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6265 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6270 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6271 utime_t start_time
, end_time
;
6273 if (!specified_shard_id
) {
6274 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6278 int ret
= parse_date_str(start_date
, start_time
);
6282 ret
= parse_date_str(end_date
, end_time
);
6286 if (period_id
.empty()) {
6287 std::cerr
<< "missing --period argument" << std::endl
;
6290 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6292 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6294 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6299 if (opt_cmd
== OPT_SYNC_STATUS
) {
6300 sync_status(formatter
);
6303 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6304 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6306 int ret
= sync
.init();
6308 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6312 rgw_meta_sync_status sync_status
;
6313 ret
= sync
.read_sync_status(&sync_status
);
6315 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6319 formatter
->open_object_section("summary");
6320 encode_json("sync_status", sync_status
, formatter
);
6322 uint64_t full_total
= 0;
6323 uint64_t full_complete
= 0;
6325 for (auto marker_iter
: sync_status
.sync_markers
) {
6326 full_total
+= marker_iter
.second
.total_entries
;
6327 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6328 full_complete
+= marker_iter
.second
.pos
;
6330 full_complete
+= marker_iter
.second
.total_entries
;
6334 formatter
->open_object_section("full_sync");
6335 encode_json("total", full_total
, formatter
);
6336 encode_json("complete", full_complete
, formatter
);
6337 formatter
->close_section();
6338 formatter
->close_section();
6340 formatter
->flush(cout
);
6344 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6345 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6347 int ret
= sync
.init();
6349 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6352 ret
= sync
.init_sync_status();
6354 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6360 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6361 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6363 int ret
= sync
.init();
6365 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6371 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6376 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6377 if (source_zone
.empty()) {
6378 cerr
<< "ERROR: source zone not specified" << std::endl
;
6381 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6383 int ret
= sync
.init();
6385 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6389 rgw_data_sync_status sync_status
;
6390 ret
= sync
.read_sync_status(&sync_status
);
6391 if (ret
< 0 && ret
!= -ENOENT
) {
6392 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6396 formatter
->open_object_section("summary");
6397 encode_json("sync_status", sync_status
, formatter
);
6399 uint64_t full_total
= 0;
6400 uint64_t full_complete
= 0;
6402 for (auto marker_iter
: sync_status
.sync_markers
) {
6403 full_total
+= marker_iter
.second
.total_entries
;
6404 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6405 full_complete
+= marker_iter
.second
.pos
;
6407 full_complete
+= marker_iter
.second
.total_entries
;
6411 formatter
->open_object_section("full_sync");
6412 encode_json("total", full_total
, formatter
);
6413 encode_json("complete", full_complete
, formatter
);
6414 formatter
->close_section();
6415 formatter
->close_section();
6417 formatter
->flush(cout
);
6420 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6421 if (source_zone
.empty()) {
6422 cerr
<< "ERROR: source zone not specified" << std::endl
;
6425 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6427 int ret
= sync
.init();
6429 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6433 ret
= sync
.init_sync_status();
6435 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6440 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6441 if (source_zone
.empty()) {
6442 cerr
<< "ERROR: source zone not specified" << std::endl
;
6445 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6447 int ret
= sync
.init();
6449 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6455 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6460 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6461 if (source_zone
.empty()) {
6462 cerr
<< "ERROR: source zone not specified" << std::endl
;
6465 if (bucket_name
.empty()) {
6466 cerr
<< "ERROR: bucket not specified" << std::endl
;
6470 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6474 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6478 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6481 ret
= sync
.init_sync_status();
6483 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6488 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
6489 if (bucket_name
.empty()) {
6490 cerr
<< "ERROR: bucket not specified" << std::endl
;
6495 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
6499 ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
, true);
6501 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
6505 if (!store
->is_meta_master()) {
6506 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
6507 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
6511 rgw_obj
obj(bucket
, object
);
6512 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
6517 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6518 if (source_zone
.empty()) {
6519 cerr
<< "ERROR: source zone not specified" << std::endl
;
6522 if (bucket_name
.empty()) {
6523 cerr
<< "ERROR: bucket not specified" << std::endl
;
6527 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6531 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6535 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6538 ret
= sync
.read_sync_status();
6540 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6544 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6546 encode_json("sync_status", sync_status
, formatter
);
6547 formatter
->flush(cout
);
6550 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6551 if (source_zone
.empty()) {
6552 cerr
<< "ERROR: source zone not specified" << std::endl
;
6555 if (bucket_name
.empty()) {
6556 cerr
<< "ERROR: bucket not specified" << std::endl
;
6560 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6564 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6568 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6574 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6579 if (opt_cmd
== OPT_BILOG_LIST
) {
6580 if (bucket_name
.empty()) {
6581 cerr
<< "ERROR: bucket not specified" << std::endl
;
6584 RGWBucketInfo bucket_info
;
6585 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6587 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6590 formatter
->open_array_section("entries");
6593 if (max_entries
< 0)
6597 list
<rgw_bi_log_entry
> entries
;
6598 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6600 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6604 count
+= entries
.size();
6606 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6607 rgw_bi_log_entry
& entry
= *iter
;
6608 encode_json("entry", entry
, formatter
);
6612 formatter
->flush(cout
);
6613 } while (truncated
&& count
< max_entries
);
6615 formatter
->close_section();
6616 formatter
->flush(cout
);
6619 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6620 if (max_entries
< 0) {
6625 utime_t start_time
, end_time
;
6627 int ret
= parse_date_str(start_date
, start_time
);
6631 ret
= parse_date_str(end_date
, end_time
);
6639 formatter
->open_array_section("entries");
6641 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6642 formatter
->open_object_section("shard");
6643 encode_json("shard_id", shard_id
, formatter
);
6644 formatter
->open_array_section("entries");
6647 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6650 list
<cls_log_entry
> entries
;
6651 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6652 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6653 if (ret
== -ENOENT
) {
6657 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6661 count
+= entries
.size();
6663 for (auto& cls_entry
: entries
) {
6664 rgw_sync_error_info log_entry
;
6666 auto iter
= cls_entry
.data
.begin();
6668 ::decode(log_entry
, iter
);
6669 } catch (buffer::error
& err
) {
6670 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6673 formatter
->open_object_section("entry");
6674 encode_json("id", cls_entry
.id
, formatter
);
6675 encode_json("section", cls_entry
.section
, formatter
);
6676 encode_json("name", cls_entry
.name
, formatter
);
6677 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
6678 encode_json("info", log_entry
, formatter
);
6679 formatter
->close_section();
6680 formatter
->flush(cout
);
6682 } while (truncated
&& count
< max_entries
);
6684 formatter
->close_section();
6685 formatter
->close_section();
6687 if (specified_shard_id
) {
6692 formatter
->close_section();
6693 formatter
->flush(cout
);
6696 if (opt_cmd
== OPT_BILOG_TRIM
) {
6697 if (bucket_name
.empty()) {
6698 cerr
<< "ERROR: bucket not specified" << std::endl
;
6701 RGWBucketInfo bucket_info
;
6702 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6704 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6707 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
6709 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6714 if (opt_cmd
== OPT_BILOG_STATUS
) {
6715 if (bucket_name
.empty()) {
6716 cerr
<< "ERROR: bucket not specified" << std::endl
;
6719 RGWBucketInfo bucket_info
;
6720 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6722 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6725 map
<int, string
> markers
;
6726 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
6728 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
6731 formatter
->open_object_section("entries");
6732 encode_json("markers", markers
, formatter
);
6733 formatter
->close_section();
6734 formatter
->flush(cout
);
6737 if (opt_cmd
== OPT_BILOG_AUTOTRIM
) {
6738 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6739 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6740 int ret
= http
.set_threaded();
6742 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6746 rgw::BucketTrimConfig config
;
6747 configure_bucket_trim(store
->ctx(), config
);
6749 rgw::BucketTrimManager
trim(store
, config
);
6752 cerr
<< "trim manager init failed with " << cpp_strerror(ret
) << std::endl
;
6755 ret
= crs
.run(trim
.create_admin_bucket_trim_cr(&http
));
6757 cerr
<< "automated bilog trim failed with " << cpp_strerror(ret
) << std::endl
;
6762 if (opt_cmd
== OPT_DATALOG_LIST
) {
6763 formatter
->open_array_section("entries");
6766 if (max_entries
< 0)
6769 utime_t start_time
, end_time
;
6771 int ret
= parse_date_str(start_date
, start_time
);
6775 ret
= parse_date_str(end_date
, end_time
);
6779 RGWDataChangesLog
*log
= store
->data_log
;
6780 RGWDataChangesLog::LogMarker marker
;
6783 list
<rgw_data_change_log_entry
> entries
;
6784 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
6786 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6790 count
+= entries
.size();
6792 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6793 rgw_data_change_log_entry
& entry
= *iter
;
6795 encode_json("entry", entry
.entry
, formatter
);
6797 encode_json("entry", entry
, formatter
);
6800 formatter
->flush(cout
);
6801 } while (truncated
&& count
< max_entries
);
6803 formatter
->close_section();
6804 formatter
->flush(cout
);
6807 if (opt_cmd
== OPT_DATALOG_STATUS
) {
6808 RGWDataChangesLog
*log
= store
->data_log
;
6809 int i
= (specified_shard_id
? shard_id
: 0);
6811 formatter
->open_array_section("entries");
6812 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
6813 list
<cls_log_entry
> entries
;
6815 RGWDataChangesLogInfo info
;
6816 log
->get_info(i
, &info
);
6818 ::encode_json("info", info
, formatter
);
6820 if (specified_shard_id
)
6824 formatter
->close_section();
6825 formatter
->flush(cout
);
6828 if (opt_cmd
== OPT_DATALOG_TRIM
) {
6829 utime_t start_time
, end_time
;
6831 int ret
= parse_date_str(start_date
, start_time
);
6835 ret
= parse_date_str(end_date
, end_time
);
6839 RGWDataChangesLog
*log
= store
->data_log
;
6840 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6842 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
6847 if (opt_cmd
== OPT_OPSTATE_LIST
) {
6848 RGWOpState
oc(store
);
6853 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
6854 list
<cls_statelog_entry
> entries
;
6856 formatter
->open_array_section("entries");
6858 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
6860 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
6861 oc
.finish_list_entries(handle
);
6865 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6866 oc
.dump_entry(*iter
, formatter
);
6869 formatter
->flush(cout
);
6871 formatter
->close_section();
6872 formatter
->flush(cout
);
6873 oc
.finish_list_entries(handle
);
6876 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
6877 RGWOpState
oc(store
);
6879 RGWOpState::OpState state
;
6880 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6881 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6884 if (state_str
.empty()) {
6885 cerr
<< "ERROR: state was not specified" << std::endl
;
6888 int ret
= oc
.state_from_str(state_str
, &state
);
6890 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
6894 if (opt_cmd
== OPT_OPSTATE_SET
) {
6895 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
6897 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6901 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
6903 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
6908 if (opt_cmd
== OPT_OPSTATE_RM
) {
6909 RGWOpState
oc(store
);
6911 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6912 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6915 ret
= oc
.remove_entry(client_id
, op_id
, object
);
6917 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6922 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
6923 opt_cmd
== OPT_REPLICALOG_DELETE
) {
6924 if (replica_log_type_str
.empty()) {
6925 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
6930 if (opt_cmd
== OPT_REPLICALOG_GET
) {
6931 RGWReplicaBounds bounds
;
6932 if (replica_log_type
== ReplicaLog_Metadata
) {
6933 if (!specified_shard_id
) {
6934 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6938 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6939 int ret
= logger
.get_bounds(shard_id
, bounds
);
6942 } else if (replica_log_type
== ReplicaLog_Data
) {
6943 if (!specified_shard_id
) {
6944 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
6947 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6948 int ret
= logger
.get_bounds(shard_id
, bounds
);
6951 } else if (replica_log_type
== ReplicaLog_Bucket
) {
6952 if (bucket_name
.empty()) {
6953 cerr
<< "ERROR: bucket not specified" << std::endl
;
6956 RGWBucketInfo bucket_info
;
6957 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6959 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6963 RGWReplicaBucketLogger
logger(store
);
6964 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
6967 } else { // shouldn't get here
6970 encode_json("bounds", bounds
, formatter
);
6971 formatter
->flush(cout
);
6975 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
6976 if (replica_log_type
== ReplicaLog_Metadata
) {
6977 if (!specified_shard_id
) {
6978 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6981 if (!specified_daemon_id
) {
6982 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6985 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
6986 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
6989 } else if (replica_log_type
== ReplicaLog_Data
) {
6990 if (!specified_shard_id
) {
6991 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
6994 if (!specified_daemon_id
) {
6995 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
6998 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
6999 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
7002 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7003 if (bucket_name
.empty()) {
7004 cerr
<< "ERROR: bucket not specified" << std::endl
;
7007 RGWBucketInfo bucket_info
;
7008 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7010 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7014 RGWReplicaBucketLogger
logger(store
);
7015 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
7021 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
7022 if (marker
.empty()) {
7023 cerr
<< "ERROR: marker was not specified" <<std::endl
;
7026 utime_t time
= ceph_clock_now();
7027 if (!date
.empty()) {
7028 ret
= parse_date_str(date
, time
);
7030 cerr
<< "ERROR: failed to parse start date" << std::endl
;
7034 list
<RGWReplicaItemMarker
> entries
;
7035 int ret
= read_decode_json(infile
, entries
);
7037 cerr
<< "ERROR: failed to decode entries" << std::endl
;
7040 RGWReplicaBounds bounds
;
7041 if (replica_log_type
== ReplicaLog_Metadata
) {
7042 if (!specified_shard_id
) {
7043 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7047 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7048 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7050 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7053 } else if (replica_log_type
== ReplicaLog_Data
) {
7054 if (!specified_shard_id
) {
7055 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7058 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7059 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7061 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7064 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7065 if (bucket_name
.empty()) {
7066 cerr
<< "ERROR: bucket not specified" << std::endl
;
7069 RGWBucketInfo bucket_info
;
7070 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7072 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7076 RGWReplicaBucketLogger
logger(store
);
7077 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
7079 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7085 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7088 if (bucket_name
.empty() && user_id
.empty()) {
7089 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7093 if (!bucket_name
.empty()) {
7094 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7095 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7098 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7099 max_size
, max_objects
, have_max_size
, have_max_objects
);
7100 } else if (!user_id
.empty()) {
7101 if (quota_scope
== "bucket") {
7102 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7103 } else if (quota_scope
== "user") {
7104 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7106 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;