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"
47 #include "rgw_http_client_curl.h"
51 #define dout_context g_ceph_context
52 #define dout_subsys ceph_subsys_rgw
54 #define SECRET_KEY_LEN 40
55 #define PUBLIC_ID_LEN 20
57 static RGWRados
*store
= NULL
;
61 cout
<< "usage: radosgw-admin <cmd> [options...]" << std::endl
;
62 cout
<< "commands:\n";
63 cout
<< " user create create a new user\n" ;
64 cout
<< " user modify modify user\n";
65 cout
<< " user info get user info\n";
66 cout
<< " user rm remove user\n";
67 cout
<< " user suspend suspend a user\n";
68 cout
<< " user enable re-enable user after suspension\n";
69 cout
<< " user check check user info\n";
70 cout
<< " user stats show user stats as accounted by quota subsystem\n";
71 cout
<< " user list list users\n";
72 cout
<< " caps add add user capabilities\n";
73 cout
<< " caps rm remove user capabilities\n";
74 cout
<< " subuser create create a new subuser\n" ;
75 cout
<< " subuser modify modify subuser\n";
76 cout
<< " subuser rm remove subuser\n";
77 cout
<< " key create create access key\n";
78 cout
<< " key rm remove access key\n";
79 cout
<< " bucket list list buckets\n";
80 cout
<< " bucket limit check show bucket sharding stats\n";
81 cout
<< " bucket link link bucket to specified user\n";
82 cout
<< " bucket unlink unlink bucket from specified user\n";
83 cout
<< " bucket stats returns bucket statistics\n";
84 cout
<< " bucket rm remove bucket\n";
85 cout
<< " bucket check check bucket index\n";
86 cout
<< " bucket reshard reshard bucket\n";
87 cout
<< " bucket sync disable disable bucket sync\n";
88 cout
<< " bucket sync enable enable bucket sync\n";
89 cout
<< " bi get retrieve bucket index object entries\n";
90 cout
<< " bi put store bucket index object entries\n";
91 cout
<< " bi list list raw bucket index entries\n";
92 cout
<< " object rm remove object\n";
93 cout
<< " object stat stat an object for its metadata\n";
94 cout
<< " object unlink unlink object from bucket index\n";
95 cout
<< " objects expire run expired objects cleanup\n";
96 cout
<< " period delete delete a period\n";
97 cout
<< " period get get period info\n";
98 cout
<< " period get-current get current period info\n";
99 cout
<< " period pull pull a period\n";
100 cout
<< " period push push a period\n";
101 cout
<< " period list list all periods\n";
102 cout
<< " period update update the staging period\n";
103 cout
<< " period commit commit the staging period\n";
104 cout
<< " quota set set quota params\n";
105 cout
<< " quota enable enable quota\n";
106 cout
<< " quota disable disable quota\n";
107 cout
<< " global quota get view global quota params\n";
108 cout
<< " global quota set set global quota params\n";
109 cout
<< " global quota enable enable a global quota\n";
110 cout
<< " global quota disable disable a global quota\n";
111 cout
<< " realm create create a new realm\n";
112 cout
<< " realm delete delete a realm\n";
113 cout
<< " realm get show realm info\n";
114 cout
<< " realm get-default get default realm name\n";
115 cout
<< " realm list list realms\n";
116 cout
<< " realm list-periods list all realm periods\n";
117 cout
<< " realm remove remove a zonegroup from the realm\n";
118 cout
<< " realm rename rename a realm\n";
119 cout
<< " realm set set realm info (requires infile)\n";
120 cout
<< " realm default set realm as default\n";
121 cout
<< " realm pull pull a realm and its current period\n";
122 cout
<< " zonegroup add add a zone to a zonegroup\n";
123 cout
<< " zonegroup create create a new zone group info\n";
124 cout
<< " zonegroup default set default zone group\n";
125 cout
<< " zonegroup delete delete a zone group info\n";
126 cout
<< " zonegroup get show zone group info\n";
127 cout
<< " zonegroup modify modify an existing zonegroup\n";
128 cout
<< " zonegroup set set zone group info (requires infile)\n";
129 cout
<< " zonegroup remove remove a zone from a zonegroup\n";
130 cout
<< " zonegroup rename rename a zone group\n";
131 cout
<< " zonegroup list list all zone groups set on this cluster\n";
132 cout
<< " zonegroup placement list list zonegroup's placement targets\n";
133 cout
<< " zonegroup placement add add a placement target id to a zonegroup\n";
134 cout
<< " zonegroup placement modify modify a placement target of a specific zonegroup\n";
135 cout
<< " zonegroup placement rm remove a placement target from a zonegroup\n";
136 cout
<< " zonegroup placement default set a zonegroup's default placement target\n";
137 cout
<< " zone create create a new zone\n";
138 cout
<< " zone delete delete a zone\n";
139 cout
<< " zone get show zone cluster params\n";
140 cout
<< " zone modify modify an existing zone\n";
141 cout
<< " zone set set zone cluster params (requires infile)\n";
142 cout
<< " zone list list all zones set on this cluster\n";
143 cout
<< " zone rename rename a zone\n";
144 cout
<< " zone placement list list zone's placement targets\n";
145 cout
<< " zone placement add add a zone placement target\n";
146 cout
<< " zone placement modify modify a zone placement target\n";
147 cout
<< " zone placement rm remove a zone placement target\n";
148 cout
<< " pool add add an existing pool for data placement\n";
149 cout
<< " pool rm remove an existing pool from data placement set\n";
150 cout
<< " pools list list placement active set\n";
151 cout
<< " policy read bucket/object policy\n";
152 cout
<< " log list list log objects\n";
153 cout
<< " log show dump a log from specific object or (bucket + date\n";
154 cout
<< " + bucket-id)\n";
155 cout
<< " (NOTE: required to specify formatting of date\n";
156 cout
<< " to \"YYYY-MM-DD-hh\")\n";
157 cout
<< " log rm remove log object\n";
158 cout
<< " usage show show usage (by user, date range)\n";
159 cout
<< " usage trim trim usage (by user, date range)\n";
160 cout
<< " gc list dump expired garbage collection objects (specify\n";
161 cout
<< " --include-all to list all entries, including unexpired)\n";
162 cout
<< " gc process manually process garbage\n";
163 cout
<< " lc list list all bucket lifecycle progress\n";
164 cout
<< " lc process manually process lifecycle\n";
165 cout
<< " metadata get get metadata info\n";
166 cout
<< " metadata put put metadata info\n";
167 cout
<< " metadata rm remove metadata info\n";
168 cout
<< " metadata list list metadata info\n";
169 cout
<< " mdlog list list metadata log\n";
170 cout
<< " mdlog trim trim metadata log (use start-date, end-date or\n";
171 cout
<< " start-marker, end-marker)\n";
172 cout
<< " mdlog status read metadata log status\n";
173 cout
<< " bilog list list bucket index log\n";
174 cout
<< " bilog trim trim bucket index log (use start-marker, end-marker)\n";
175 cout
<< " datalog list list data log\n";
176 cout
<< " datalog trim trim data log\n";
177 cout
<< " datalog status read data log status\n";
178 cout
<< " opstate list list stateful operations entries (use client_id,\n";
179 cout
<< " op_id, object)\n";
180 cout
<< " opstate set set state on an entry (use client_id, op_id, object, state)\n";
181 cout
<< " opstate renew renew state on an entry (use client_id, op_id, object)\n";
182 cout
<< " opstate rm remove entry (use client_id, op_id, object)\n";
183 cout
<< " replicalog get get replica metadata log entry\n";
184 cout
<< " replicalog update update replica metadata log entry\n";
185 cout
<< " replicalog delete delete replica metadata log entry\n";
186 cout
<< " orphans find init and run search for leaked rados objects (use job-id, pool)\n";
187 cout
<< " orphans finish clean up search for leaked rados objects\n";
188 cout
<< " orphans list-jobs list the current job-ids for orphans search\n";
189 cout
<< " role create create a AWS role for use with STS\n";
190 cout
<< " role delete delete a role\n";
191 cout
<< " role get get a role\n";
192 cout
<< " role list list roles with specified path prefix\n";
193 cout
<< " role modify modify the assume role policy of an existing role\n";
194 cout
<< " role-policy put add/update permission policy to role\n";
195 cout
<< " role-policy list list policies attached to a role\n";
196 cout
<< " role-policy get get the specified inline policy document embedded with the given role\n";
197 cout
<< " role-policy delete delete policy attached to a role\n";
198 cout
<< " reshard add schedule a resharding of a bucket\n";
199 cout
<< " reshard list list all bucket resharding or scheduled to be reshared\n";
200 cout
<< " reshard process process of scheduled reshard jobs\n";
201 cout
<< " reshard cancel cancel resharding a bucket\n";
202 cout
<< " sync error list list sync error\n";
203 cout
<< " sync error trim trim sync error\n";
204 cout
<< "options:\n";
205 cout
<< " --tenant=<tenant> tenant name\n";
206 cout
<< " --uid=<id> user id\n";
207 cout
<< " --subuser=<name> subuser name\n";
208 cout
<< " --access-key=<key> S3 access key\n";
209 cout
<< " --email=<email>\n";
210 cout
<< " --secret/--secret-key=<key>\n";
211 cout
<< " specify secret key\n";
212 cout
<< " --gen-access-key generate random access key (for S3)\n";
213 cout
<< " --gen-secret generate random secret key\n";
214 cout
<< " --key-type=<type> key type, options are: swift, s3\n";
215 cout
<< " --temp-url-key[-2]=<key> temp url key\n";
216 cout
<< " --access=<access> Set access permissions for sub-user, should be one\n";
217 cout
<< " of read, write, readwrite, full\n";
218 cout
<< " --display-name=<name>\n";
219 cout
<< " --max-buckets max number of buckets for a user\n";
220 cout
<< " --admin set the admin flag on the user\n";
221 cout
<< " --system set the system flag on the user\n";
222 cout
<< " --bucket=<bucket>\n";
223 cout
<< " --pool=<pool>\n";
224 cout
<< " --object=<object>\n";
225 cout
<< " --date=<date>\n";
226 cout
<< " --start-date=<date>\n";
227 cout
<< " --end-date=<date>\n";
228 cout
<< " --bucket-id=<bucket-id>\n";
229 cout
<< " --shard-id=<shard-id> optional for mdlog list\n";
230 cout
<< " required for: \n";
231 cout
<< " mdlog trim\n";
232 cout
<< " replica mdlog get/delete\n";
233 cout
<< " replica datalog get/delete\n";
234 cout
<< " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
235 cout
<< " --remote=<remote> zone or zonegroup id of remote gateway\n";
236 cout
<< " --period=<id> period id\n";
237 cout
<< " --epoch=<number> period epoch\n";
238 cout
<< " --commit commit the period during 'period update'\n";
239 cout
<< " --staging get staging period info\n";
240 cout
<< " --master set as master\n";
241 cout
<< " --master-url master url\n";
242 cout
<< " --master-zonegroup=<id> master zonegroup id\n";
243 cout
<< " --master-zone=<id> master zone id\n";
244 cout
<< " --rgw-realm=<name> realm name\n";
245 cout
<< " --realm-id=<id> realm id\n";
246 cout
<< " --realm-new-name=<name> realm new name\n";
247 cout
<< " --rgw-zonegroup=<name> zonegroup name\n";
248 cout
<< " --zonegroup-id=<id> zonegroup id\n";
249 cout
<< " --zonegroup-new-name=<name>\n";
250 cout
<< " zonegroup new name\n";
251 cout
<< " --rgw-zone=<name> name of zone in which radosgw is running\n";
252 cout
<< " --zone-id=<id> zone id\n";
253 cout
<< " --zone-new-name=<name> zone new name\n";
254 cout
<< " --source-zone specify the source zone (for data sync)\n";
255 cout
<< " --default set entity (realm, zonegroup, zone) as default\n";
256 cout
<< " --read-only set zone as read-only (when adding to zonegroup)\n";
257 cout
<< " --placement-id placement id for zonegroup placement commands\n";
258 cout
<< " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
259 cout
<< " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
260 cout
<< " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
261 cout
<< " --endpoints=<list> zone endpoints\n";
262 cout
<< " --index-pool=<pool> placement target index pool\n";
263 cout
<< " --data-pool=<pool> placement target data pool\n";
264 cout
<< " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n";
265 cout
<< " --placement-index-type=<type>\n";
266 cout
<< " placement target index type (normal, indexless, or #id)\n";
267 cout
<< " --compression=<type> placement target compression type (plugin name or empty/none)\n";
268 cout
<< " --tier-type=<type> zone tier type\n";
269 cout
<< " --tier-config=<k>=<v>[,...]\n";
270 cout
<< " set zone tier config keys, values\n";
271 cout
<< " --tier-config-rm=<k>[,...]\n";
272 cout
<< " unset zone tier config keys\n";
273 cout
<< " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
274 cout
<< " --sync-from=[zone-name][,...]\n";
275 cout
<< " set list of zones to sync from\n";
276 cout
<< " --sync-from-rm=[zone-name][,...]\n";
277 cout
<< " remove zones from list of zones to sync from\n";
278 cout
<< " --fix besides checking bucket index, will also fix it\n";
279 cout
<< " --check-objects bucket check: rebuilds bucket index according to\n";
280 cout
<< " actual objects state\n";
281 cout
<< " --format=<format> specify output format for certain operations: xml,\n";
283 cout
<< " --purge-data when specified, user removal will also purge all the\n";
284 cout
<< " user data\n";
285 cout
<< " --purge-keys when specified, subuser removal will also purge all the\n";
286 cout
<< " subuser keys\n";
287 cout
<< " --purge-objects remove a bucket's objects before deleting it\n";
288 cout
<< " (NOTE: required to delete a non-empty bucket)\n";
289 cout
<< " --sync-stats option to 'user stats', update user stats with current\n";
290 cout
<< " stats reported by user's buckets indexes\n";
291 cout
<< " --reset-stats option to 'user stats', reset stats in accordance with user buckets\n";
292 cout
<< " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
293 cout
<< " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
294 cout
<< " --skip-zero-entries log show only dumps entries that don't have zero value\n";
295 cout
<< " in one of the numeric field\n";
296 cout
<< " --infile=<file> specify a file to read in when setting data\n";
297 cout
<< " --state=<state string> specify a state for the opstate set command\n";
298 cout
<< " --replica-log-type replica log type (metadata, data, bucket), required for\n";
299 cout
<< " replica log operations\n";
300 cout
<< " --categories=<list> comma separated list of categories, used in usage show\n";
301 cout
<< " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
302 cout
<< " --yes-i-really-mean-it required for certain operations\n";
303 cout
<< " --warnings-only when specified with bucket limit check, list\n";
304 cout
<< " only buckets nearing or over the current max\n";
305 cout
<< " objects per shard value\n";
306 cout
<< " --bypass-gc when specified with bucket deletion, triggers\n";
307 cout
<< " object deletions by not involving GC\n";
308 cout
<< " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
309 cout
<< " ignores bucket index consistency\n";
311 cout
<< "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
312 cout
<< "\nQuota options:\n";
313 cout
<< " --bucket specified bucket for quota command\n";
314 cout
<< " --max-objects specify max objects (negative value to disable)\n";
315 cout
<< " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
316 cout
<< " --quota-scope scope of quota (bucket, user)\n";
317 cout
<< "\nOrphans search options:\n";
318 cout
<< " --pool data pool to scan for leaked rados objects in\n";
319 cout
<< " --num-shards num of shards to use for keeping the temporary scan info\n";
320 cout
<< " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
321 cout
<< " --job-id set the job id (for orphans find)\n";
322 cout
<< " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
323 cout
<< "\nOrphans list-jobs options:\n";
324 cout
<< " --extra-info provide extra info in job list\n";
325 cout
<< "\nRole options:\n";
326 cout
<< " --role-name name of the role to create\n";
327 cout
<< " --path path to the role\n";
328 cout
<< " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
329 cout
<< " --policy-name name of the policy document\n";
330 cout
<< " --policy-doc permission policy document\n";
331 cout
<< " --path-prefix path prefix for filtering roles\n";
333 generic_client_usage();
353 OPT_BUCKET_LIMIT_CHECK
,
358 OPT_BUCKET_SYNC_STATUS
,
359 OPT_BUCKET_SYNC_INIT
,
361 OPT_BUCKET_SYNC_DISABLE
,
362 OPT_BUCKET_SYNC_ENABLE
,
395 OPT_ORPHANS_LIST_JOBS
,
397 OPT_ZONEGROUP_CREATE
,
398 OPT_ZONEGROUP_DEFAULT
,
399 OPT_ZONEGROUP_DELETE
,
401 OPT_ZONEGROUP_MODIFY
,
404 OPT_ZONEGROUP_REMOVE
,
405 OPT_ZONEGROUP_RENAME
,
406 OPT_ZONEGROUP_PLACEMENT_ADD
,
407 OPT_ZONEGROUP_PLACEMENT_MODIFY
,
408 OPT_ZONEGROUP_PLACEMENT_RM
,
409 OPT_ZONEGROUP_PLACEMENT_LIST
,
410 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
419 OPT_ZONE_PLACEMENT_ADD
,
420 OPT_ZONE_PLACEMENT_MODIFY
,
421 OPT_ZONE_PLACEMENT_RM
,
422 OPT_ZONE_PLACEMENT_LIST
,
429 OPT_METADATA_SYNC_STATUS
,
430 OPT_METADATA_SYNC_INIT
,
431 OPT_METADATA_SYNC_RUN
,
443 OPT_DATA_SYNC_STATUS
,
454 OPT_REPLICALOG_UPDATE
,
455 OPT_REPLICALOG_DELETE
,
459 OPT_REALM_GET_DEFAULT
,
461 OPT_REALM_LIST_PERIODS
,
469 OPT_PERIOD_GET_CURRENT
,
475 OPT_GLOBAL_QUOTA_GET
,
476 OPT_GLOBAL_QUOTA_SET
,
477 OPT_GLOBAL_QUOTA_ENABLE
,
478 OPT_GLOBAL_QUOTA_DISABLE
,
486 OPT_ROLE_POLICY_LIST
,
488 OPT_ROLE_POLICY_DELETE
,
496 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
499 // NOTE: please keep the checks in alphabetical order !!!
500 if (strcmp(cmd
, "bi") == 0 ||
501 strcmp(cmd
, "bilog") == 0 ||
502 strcmp(cmd
, "buckets") == 0 ||
503 strcmp(cmd
, "caps") == 0 ||
504 strcmp(cmd
, "data") == 0 ||
505 strcmp(cmd
, "datalog") == 0 ||
506 strcmp(cmd
, "error") == 0 ||
507 strcmp(cmd
, "gc") == 0 ||
508 strcmp(cmd
, "global") == 0 ||
509 strcmp(cmd
, "key") == 0 ||
510 strcmp(cmd
, "log") == 0 ||
511 strcmp(cmd
, "lc") == 0 ||
512 strcmp(cmd
, "mdlog") == 0 ||
513 strcmp(cmd
, "metadata") == 0 ||
514 strcmp(cmd
, "object") == 0 ||
515 strcmp(cmd
, "objects") == 0 ||
516 strcmp(cmd
, "olh") == 0 ||
517 strcmp(cmd
, "opstate") == 0 ||
518 strcmp(cmd
, "orphans") == 0 ||
519 strcmp(cmd
, "period") == 0 ||
520 strcmp(cmd
, "placement") == 0 ||
521 strcmp(cmd
, "pool") == 0 ||
522 strcmp(cmd
, "pools") == 0 ||
523 strcmp(cmd
, "quota") == 0 ||
524 strcmp(cmd
, "realm") == 0 ||
525 strcmp(cmd
, "replicalog") == 0 ||
526 strcmp(cmd
, "role") == 0 ||
527 strcmp(cmd
, "role-policy") == 0 ||
528 strcmp(cmd
, "subuser") == 0 ||
529 strcmp(cmd
, "sync") == 0 ||
530 strcmp(cmd
, "usage") == 0 ||
531 strcmp(cmd
, "user") == 0 ||
532 strcmp(cmd
, "zone") == 0 ||
533 strcmp(cmd
, "zonegroup") == 0 ||
534 strcmp(cmd
, "zonegroups") == 0) {
540 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
542 if (strcmp(cmd
, "reshard") == 0 &&
543 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
547 if (strcmp(cmd
, "bucket") == 0 &&
548 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
553 if (strcmp(cmd
, "policy") == 0)
559 if (strcmp(prev_cmd
, "user") == 0) {
560 if (strcmp(cmd
, "create") == 0)
561 return OPT_USER_CREATE
;
562 if (strcmp(cmd
, "info") == 0)
563 return OPT_USER_INFO
;
564 if (strcmp(cmd
, "modify") == 0)
565 return OPT_USER_MODIFY
;
566 if (strcmp(cmd
, "rm") == 0)
568 if (strcmp(cmd
, "suspend") == 0)
569 return OPT_USER_SUSPEND
;
570 if (strcmp(cmd
, "enable") == 0)
571 return OPT_USER_ENABLE
;
572 if (strcmp(cmd
, "check") == 0)
573 return OPT_USER_CHECK
;
574 if (strcmp(cmd
, "stats") == 0)
575 return OPT_USER_STATS
;
576 if (strcmp(cmd
, "list") == 0)
577 return OPT_USER_LIST
;
578 } else if (strcmp(prev_cmd
, "subuser") == 0) {
579 if (strcmp(cmd
, "create") == 0)
580 return OPT_SUBUSER_CREATE
;
581 if (strcmp(cmd
, "modify") == 0)
582 return OPT_SUBUSER_MODIFY
;
583 if (strcmp(cmd
, "rm") == 0)
584 return OPT_SUBUSER_RM
;
585 } else if (strcmp(prev_cmd
, "key") == 0) {
586 if (strcmp(cmd
, "create") == 0)
587 return OPT_KEY_CREATE
;
588 if (strcmp(cmd
, "rm") == 0)
590 } else if (strcmp(prev_cmd
, "buckets") == 0) {
591 if (strcmp(cmd
, "list") == 0)
592 return OPT_BUCKETS_LIST
;
593 } else if (strcmp(prev_cmd
, "bucket") == 0) {
594 if (strcmp(cmd
, "list") == 0)
595 return OPT_BUCKETS_LIST
;
596 if (strcmp(cmd
, "link") == 0)
597 return OPT_BUCKET_LINK
;
598 if (strcmp(cmd
, "unlink") == 0)
599 return OPT_BUCKET_UNLINK
;
600 if (strcmp(cmd
, "stats") == 0)
601 return OPT_BUCKET_STATS
;
602 if (strcmp(cmd
, "rm") == 0)
603 return OPT_BUCKET_RM
;
604 if (strcmp(cmd
, "rewrite") == 0)
605 return OPT_BUCKET_REWRITE
;
606 if (strcmp(cmd
, "reshard") == 0)
607 return OPT_BUCKET_RESHARD
;
608 if (strcmp(cmd
, "check") == 0)
609 return OPT_BUCKET_CHECK
;
610 if (strcmp(cmd
, "sync") == 0) {
614 if (strcmp(cmd
, "limit") == 0) {
618 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
619 if (strcmp(prev_cmd
, "sync") == 0) {
620 if (strcmp(cmd
, "status") == 0)
621 return OPT_BUCKET_SYNC_STATUS
;
622 if (strcmp(cmd
, "init") == 0)
623 return OPT_BUCKET_SYNC_INIT
;
624 if (strcmp(cmd
, "run") == 0)
625 return OPT_BUCKET_SYNC_RUN
;
626 if (strcmp(cmd
, "disable") == 0)
627 return OPT_BUCKET_SYNC_DISABLE
;
628 if (strcmp(cmd
, "enable") == 0)
629 return OPT_BUCKET_SYNC_ENABLE
;
630 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
631 (strcmp(cmd
, "check") == 0)) {
632 return OPT_BUCKET_LIMIT_CHECK
;
634 } else if (strcmp(prev_cmd
, "log") == 0) {
635 if (strcmp(cmd
, "list") == 0)
637 if (strcmp(cmd
, "show") == 0)
639 if (strcmp(cmd
, "rm") == 0)
641 } else if (strcmp(prev_cmd
, "usage") == 0) {
642 if (strcmp(cmd
, "show") == 0)
643 return OPT_USAGE_SHOW
;
644 if (strcmp(cmd
, "trim") == 0)
645 return OPT_USAGE_TRIM
;
646 } else if (strcmp(prev_cmd
, "caps") == 0) {
647 if (strcmp(cmd
, "add") == 0)
649 if (strcmp(cmd
, "rm") == 0)
651 } else if (strcmp(prev_cmd
, "pool") == 0) {
652 if (strcmp(cmd
, "add") == 0)
654 if (strcmp(cmd
, "rm") == 0)
656 if (strcmp(cmd
, "list") == 0)
657 return OPT_POOLS_LIST
;
658 } else if (strcmp(prev_cmd
, "pools") == 0) {
659 if (strcmp(cmd
, "list") == 0)
660 return OPT_POOLS_LIST
;
661 } else if (strcmp(prev_cmd
, "object") == 0) {
662 if (strcmp(cmd
, "rm") == 0)
663 return OPT_OBJECT_RM
;
664 if (strcmp(cmd
, "unlink") == 0)
665 return OPT_OBJECT_UNLINK
;
666 if (strcmp(cmd
, "stat") == 0)
667 return OPT_OBJECT_STAT
;
668 if (strcmp(cmd
, "rewrite") == 0)
669 return OPT_OBJECT_REWRITE
;
670 } else if (strcmp(prev_cmd
, "objects") == 0) {
671 if (strcmp(cmd
, "expire") == 0)
672 return OPT_OBJECTS_EXPIRE
;
673 } else if (strcmp(prev_cmd
, "olh") == 0) {
674 if (strcmp(cmd
, "get") == 0)
676 if (strcmp(cmd
, "readlog") == 0)
677 return OPT_OLH_READLOG
;
678 } else if (strcmp(prev_cmd
, "bi") == 0) {
679 if (strcmp(cmd
, "get") == 0)
681 if (strcmp(cmd
, "put") == 0)
683 if (strcmp(cmd
, "list") == 0)
685 if (strcmp(cmd
, "purge") == 0)
687 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
688 (strcmp(prev_cmd
, "quota") == 0)) {
689 if (strcmp(cmd
, "get") == 0)
690 return OPT_GLOBAL_QUOTA_GET
;
691 if (strcmp(cmd
, "set") == 0)
692 return OPT_GLOBAL_QUOTA_SET
;
693 if (strcmp(cmd
, "enable") == 0)
694 return OPT_GLOBAL_QUOTA_ENABLE
;
695 if (strcmp(cmd
, "disable") == 0)
696 return OPT_GLOBAL_QUOTA_DISABLE
;
697 } else if (strcmp(prev_cmd
, "period") == 0) {
698 if (strcmp(cmd
, "delete") == 0)
699 return OPT_PERIOD_DELETE
;
700 if (strcmp(cmd
, "get") == 0)
701 return OPT_PERIOD_GET
;
702 if (strcmp(cmd
, "get-current") == 0)
703 return OPT_PERIOD_GET_CURRENT
;
704 if (strcmp(cmd
, "pull") == 0)
705 return OPT_PERIOD_PULL
;
706 if (strcmp(cmd
, "push") == 0)
707 return OPT_PERIOD_PUSH
;
708 if (strcmp(cmd
, "list") == 0)
709 return OPT_PERIOD_LIST
;
710 if (strcmp(cmd
, "update") == 0)
711 return OPT_PERIOD_UPDATE
;
712 if (strcmp(cmd
, "commit") == 0)
713 return OPT_PERIOD_COMMIT
;
714 } else if (strcmp(prev_cmd
, "realm") == 0) {
715 if (strcmp(cmd
, "create") == 0)
716 return OPT_REALM_CREATE
;
717 if (strcmp(cmd
, "delete") == 0)
718 return OPT_REALM_DELETE
;
719 if (strcmp(cmd
, "get") == 0)
720 return OPT_REALM_GET
;
721 if (strcmp(cmd
, "get-default") == 0)
722 return OPT_REALM_GET_DEFAULT
;
723 if (strcmp(cmd
, "list") == 0)
724 return OPT_REALM_LIST
;
725 if (strcmp(cmd
, "list-periods") == 0)
726 return OPT_REALM_LIST_PERIODS
;
727 if (strcmp(cmd
, "remove") == 0)
728 return OPT_REALM_REMOVE
;
729 if (strcmp(cmd
, "rename") == 0)
730 return OPT_REALM_RENAME
;
731 if (strcmp(cmd
, "set") == 0)
732 return OPT_REALM_SET
;
733 if (strcmp(cmd
, "default") == 0)
734 return OPT_REALM_DEFAULT
;
735 if (strcmp(cmd
, "pull") == 0)
736 return OPT_REALM_PULL
;
737 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
738 (strcmp(prev_cmd
, "placement") == 0)) {
739 if (strcmp(cmd
, "add") == 0)
740 return OPT_ZONEGROUP_PLACEMENT_ADD
;
741 if (strcmp(cmd
, "modify") == 0)
742 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
743 if (strcmp(cmd
, "rm") == 0)
744 return OPT_ZONEGROUP_PLACEMENT_RM
;
745 if (strcmp(cmd
, "list") == 0)
746 return OPT_ZONEGROUP_PLACEMENT_LIST
;
747 if (strcmp(cmd
, "default") == 0)
748 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
749 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
750 if (strcmp(cmd
, "add") == 0)
751 return OPT_ZONEGROUP_ADD
;
752 if (strcmp(cmd
, "create")== 0)
753 return OPT_ZONEGROUP_CREATE
;
754 if (strcmp(cmd
, "default") == 0)
755 return OPT_ZONEGROUP_DEFAULT
;
756 if (strcmp(cmd
, "delete") == 0)
757 return OPT_ZONEGROUP_DELETE
;
758 if (strcmp(cmd
, "get") == 0)
759 return OPT_ZONEGROUP_GET
;
760 if (strcmp(cmd
, "modify") == 0)
761 return OPT_ZONEGROUP_MODIFY
;
762 if (strcmp(cmd
, "list") == 0)
763 return OPT_ZONEGROUP_LIST
;
764 if (strcmp(cmd
, "set") == 0)
765 return OPT_ZONEGROUP_SET
;
766 if (strcmp(cmd
, "remove") == 0)
767 return OPT_ZONEGROUP_REMOVE
;
768 if (strcmp(cmd
, "rename") == 0)
769 return OPT_ZONEGROUP_RENAME
;
770 } else if (strcmp(prev_cmd
, "quota") == 0) {
771 if (strcmp(cmd
, "set") == 0)
772 return OPT_QUOTA_SET
;
773 if (strcmp(cmd
, "enable") == 0)
774 return OPT_QUOTA_ENABLE
;
775 if (strcmp(cmd
, "disable") == 0)
776 return OPT_QUOTA_DISABLE
;
777 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
778 if (strcmp(cmd
, "list") == 0)
779 return OPT_ZONEGROUP_LIST
;
780 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
781 (strcmp(prev_cmd
, "placement") == 0)) {
782 if (strcmp(cmd
, "add") == 0)
783 return OPT_ZONE_PLACEMENT_ADD
;
784 if (strcmp(cmd
, "modify") == 0)
785 return OPT_ZONE_PLACEMENT_MODIFY
;
786 if (strcmp(cmd
, "rm") == 0)
787 return OPT_ZONE_PLACEMENT_RM
;
788 if (strcmp(cmd
, "list") == 0)
789 return OPT_ZONE_PLACEMENT_LIST
;
790 } else if (strcmp(prev_cmd
, "zone") == 0) {
791 if (strcmp(cmd
, "delete") == 0)
792 return OPT_ZONE_DELETE
;
793 if (strcmp(cmd
, "create") == 0)
794 return OPT_ZONE_CREATE
;
795 if (strcmp(cmd
, "get") == 0)
797 if (strcmp(cmd
, "set") == 0)
799 if (strcmp(cmd
, "list") == 0)
800 return OPT_ZONE_LIST
;
801 if (strcmp(cmd
, "modify") == 0)
802 return OPT_ZONE_MODIFY
;
803 if (strcmp(cmd
, "rename") == 0)
804 return OPT_ZONE_RENAME
;
805 if (strcmp(cmd
, "default") == 0)
806 return OPT_ZONE_DEFAULT
;
807 } else if (strcmp(prev_cmd
, "zones") == 0) {
808 if (strcmp(cmd
, "list") == 0)
809 return OPT_ZONE_LIST
;
810 } else if (strcmp(prev_cmd
, "gc") == 0) {
811 if (strcmp(cmd
, "list") == 0)
813 if (strcmp(cmd
, "process") == 0)
814 return OPT_GC_PROCESS
;
815 } else if (strcmp(prev_cmd
, "lc") == 0) {
816 if (strcmp(cmd
, "list") == 0)
818 if (strcmp(cmd
, "process") == 0)
819 return OPT_LC_PROCESS
;
820 } else if (strcmp(prev_cmd
, "orphans") == 0) {
821 if (strcmp(cmd
, "find") == 0)
822 return OPT_ORPHANS_FIND
;
823 if (strcmp(cmd
, "finish") == 0)
824 return OPT_ORPHANS_FINISH
;
825 if (strcmp(cmd
, "list-jobs") == 0)
826 return OPT_ORPHANS_LIST_JOBS
;
827 } else if (strcmp(prev_cmd
, "metadata") == 0) {
828 if (strcmp(cmd
, "get") == 0)
829 return OPT_METADATA_GET
;
830 if (strcmp(cmd
, "put") == 0)
831 return OPT_METADATA_PUT
;
832 if (strcmp(cmd
, "rm") == 0)
833 return OPT_METADATA_RM
;
834 if (strcmp(cmd
, "list") == 0)
835 return OPT_METADATA_LIST
;
836 if (strcmp(cmd
, "sync") == 0) {
840 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
841 (strcmp(prev_cmd
, "sync") == 0)) {
842 if (strcmp(cmd
, "status") == 0)
843 return OPT_METADATA_SYNC_STATUS
;
844 if (strcmp(cmd
, "init") == 0)
845 return OPT_METADATA_SYNC_INIT
;
846 if (strcmp(cmd
, "run") == 0)
847 return OPT_METADATA_SYNC_RUN
;
848 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
849 (strcmp(prev_cmd
, "error") == 0)) {
850 if (strcmp(cmd
, "list") == 0)
851 return OPT_SYNC_ERROR_LIST
;
852 if (strcmp(cmd
, "trim") == 0)
853 return OPT_SYNC_ERROR_TRIM
;
854 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
855 if (strcmp(cmd
, "list") == 0)
856 return OPT_MDLOG_LIST
;
857 if (strcmp(cmd
, "autotrim") == 0)
858 return OPT_MDLOG_AUTOTRIM
;
859 if (strcmp(cmd
, "trim") == 0)
860 return OPT_MDLOG_TRIM
;
861 if (strcmp(cmd
, "fetch") == 0)
862 return OPT_MDLOG_FETCH
;
863 if (strcmp(cmd
, "status") == 0)
864 return OPT_MDLOG_STATUS
;
865 } else if (strcmp(prev_cmd
, "bilog") == 0) {
866 if (strcmp(cmd
, "list") == 0)
867 return OPT_BILOG_LIST
;
868 if (strcmp(cmd
, "trim") == 0)
869 return OPT_BILOG_TRIM
;
870 if (strcmp(cmd
, "status") == 0)
871 return OPT_BILOG_STATUS
;
872 if (strcmp(cmd
, "autotrim") == 0)
873 return OPT_BILOG_AUTOTRIM
;
874 } else if (strcmp(prev_cmd
, "data") == 0) {
875 if (strcmp(cmd
, "sync") == 0) {
879 } else if (strcmp(prev_cmd
, "datalog") == 0) {
880 if (strcmp(cmd
, "list") == 0)
881 return OPT_DATALOG_LIST
;
882 if (strcmp(cmd
, "trim") == 0)
883 return OPT_DATALOG_TRIM
;
884 if (strcmp(cmd
, "status") == 0)
885 return OPT_DATALOG_STATUS
;
886 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
887 (strcmp(prev_cmd
, "sync") == 0)) {
888 if (strcmp(cmd
, "status") == 0)
889 return OPT_DATA_SYNC_STATUS
;
890 if (strcmp(cmd
, "init") == 0)
891 return OPT_DATA_SYNC_INIT
;
892 if (strcmp(cmd
, "run") == 0)
893 return OPT_DATA_SYNC_RUN
;
894 } else if (strcmp(prev_cmd
, "opstate") == 0) {
895 if (strcmp(cmd
, "list") == 0)
896 return OPT_OPSTATE_LIST
;
897 if (strcmp(cmd
, "set") == 0)
898 return OPT_OPSTATE_SET
;
899 if (strcmp(cmd
, "renew") == 0)
900 return OPT_OPSTATE_RENEW
;
901 if (strcmp(cmd
, "rm") == 0)
902 return OPT_OPSTATE_RM
;
903 } else if (strcmp(prev_cmd
, "replicalog") == 0) {
904 if (strcmp(cmd
, "get") == 0)
905 return OPT_REPLICALOG_GET
;
906 if (strcmp(cmd
, "update") == 0)
907 return OPT_REPLICALOG_UPDATE
;
908 if (strcmp(cmd
, "delete") == 0)
909 return OPT_REPLICALOG_DELETE
;
910 } else if (strcmp(prev_cmd
, "sync") == 0) {
911 if (strcmp(cmd
, "status") == 0)
912 return OPT_SYNC_STATUS
;
913 } else if (strcmp(prev_cmd
, "role") == 0) {
914 if (strcmp(cmd
, "create") == 0)
915 return OPT_ROLE_CREATE
;
916 if (strcmp(cmd
, "delete") == 0)
917 return OPT_ROLE_DELETE
;
918 if (strcmp(cmd
, "get") == 0)
920 if (strcmp(cmd
, "modify") == 0)
921 return OPT_ROLE_MODIFY
;
922 if (strcmp(cmd
, "list") == 0)
923 return OPT_ROLE_LIST
;
924 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
925 if (strcmp(cmd
, "put") == 0)
926 return OPT_ROLE_POLICY_PUT
;
927 if (strcmp(cmd
, "list") == 0)
928 return OPT_ROLE_POLICY_LIST
;
929 if (strcmp(cmd
, "get") == 0)
930 return OPT_ROLE_POLICY_GET
;
931 if (strcmp(cmd
, "delete") == 0)
932 return OPT_ROLE_POLICY_DELETE
;
933 } else if (strcmp(prev_cmd
, "reshard") == 0) {
934 if (strcmp(cmd
, "bucket") == 0)
935 return OPT_BUCKET_RESHARD
;
936 if (strcmp(cmd
, "add") == 0)
937 return OPT_RESHARD_ADD
;
938 if (strcmp(cmd
, "list") == 0)
939 return OPT_RESHARD_LIST
;
940 if (strcmp(cmd
, "status") == 0)
941 return OPT_RESHARD_STATUS
;
942 if (strcmp(cmd
, "process") == 0)
943 return OPT_RESHARD_PROCESS
;
944 if (strcmp(cmd
, "cancel") == 0)
945 return OPT_RESHARD_CANCEL
;
951 enum ReplicaLogType
{
952 ReplicaLog_Invalid
= 0,
958 ReplicaLogType
get_replicalog_type(const string
& name
) {
959 if (name
== "md" || name
== "meta" || name
== "metadata")
960 return ReplicaLog_Metadata
;
962 return ReplicaLog_Data
;
963 if (name
== "bucket")
964 return ReplicaLog_Bucket
;
966 return ReplicaLog_Invalid
;
969 BIIndexType
get_bi_index_type(const string
& type_str
) {
970 if (type_str
== "plain")
972 if (type_str
== "instance")
974 if (type_str
== "olh")
980 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
982 bufferlist::iterator iter
= bl
.begin();
983 switch (index_type
) {
987 rgw_bucket_dir_entry entry
;
988 ::decode(entry
, iter
);
989 encode_json("entry", entry
, formatter
);
994 rgw_bucket_olh_entry entry
;
995 ::decode(entry
, iter
);
996 encode_json("entry", entry
, formatter
);
1005 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
1007 encode_json("user_info", info
, formatter
);
1008 formatter
->flush(cout
);
1012 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1014 formatter
->open_object_section("role");
1015 formatter
->dump_string("Permission policy", perm_policy
);
1016 formatter
->close_section();
1017 formatter
->flush(cout
);
1020 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1022 formatter
->open_array_section("PolicyNames");
1023 for (const auto& it
: policy_names
) {
1024 formatter
->dump_string("policyname", it
);
1026 formatter
->close_section();
1027 formatter
->flush(cout
);
1030 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1032 formatter
->open_object_section("role");
1033 role
.dump(formatter
);
1034 formatter
->close_section();
1035 formatter
->flush(cout
);
1038 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1040 formatter
->open_array_section("Roles");
1041 for (const auto& it
: roles
) {
1042 formatter
->open_object_section("role");
1044 formatter
->close_section();
1046 formatter
->close_section();
1047 formatter
->flush(cout
);
1050 class StoreDestructor
{
1053 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1054 ~StoreDestructor() {
1055 RGWStoreManager::close_storage(store
);
1059 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1060 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1062 if (!bucket_name
.empty()) {
1063 RGWObjectCtx
obj_ctx(store
);
1065 if (bucket_id
.empty()) {
1066 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1068 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1069 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1072 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1075 bucket
= bucket_info
.bucket
;
1080 static int read_input(const string
& infile
, bufferlist
& bl
)
1083 if (infile
.size()) {
1084 fd
= open(infile
.c_str(), O_RDONLY
);
1087 cerr
<< "error reading input file " << infile
<< std::endl
;
1092 #define READ_CHUNK 8196
1097 char buf
[READ_CHUNK
];
1099 r
= safe_read(fd
, buf
, READ_CHUNK
);
1102 cerr
<< "error while reading input" << std::endl
;
1110 if (infile
.size()) {
1117 static int read_decode_json(const string
& infile
, T
& t
)
1120 int ret
= read_input(infile
, bl
);
1122 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1126 if (!p
.parse(bl
.c_str(), bl
.length())) {
1127 cout
<< "failed to parse JSON" << std::endl
;
1132 decode_json_obj(t
, &p
);
1133 } catch (JSONDecoder::err
& e
) {
1134 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1140 template <class T
, class K
>
1141 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1144 int ret
= read_input(infile
, bl
);
1146 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1150 if (!p
.parse(bl
.c_str(), bl
.length())) {
1151 cout
<< "failed to parse JSON" << std::endl
;
1156 t
.decode_json(&p
, k
);
1157 } catch (JSONDecoder::err
& e
) {
1158 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1164 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1169 if (!date_str
.empty()) {
1170 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1172 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1177 ut
= utime_t(epoch
, nsec
);
1183 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1187 bufferlist::iterator iter
= bl
.begin();
1191 } catch (buffer::error
& err
) {
1195 encode_json(field_name
, t
, f
);
1200 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1203 if (bl
.length() > 0) {
1204 val
.assign(bl
.c_str());
1206 f
->dump_string(field_name
, val
);
1211 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1212 bool have_max_size
, bool have_max_objects
)
1215 case OPT_QUOTA_ENABLE
:
1216 case OPT_GLOBAL_QUOTA_ENABLE
:
1217 quota
.enabled
= true;
1219 // falling through on purpose
1222 case OPT_GLOBAL_QUOTA_SET
:
1223 if (have_max_objects
) {
1224 if (max_objects
< 0) {
1225 quota
.max_objects
= -1;
1227 quota
.max_objects
= max_objects
;
1230 if (have_max_size
) {
1232 quota
.max_size
= -1;
1234 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1238 case OPT_QUOTA_DISABLE
:
1239 case OPT_GLOBAL_QUOTA_DISABLE
:
1240 quota
.enabled
= false;
1245 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1246 const string
& tenant_name
, const string
& bucket_name
,
1247 int64_t max_size
, int64_t max_objects
,
1248 bool have_max_size
, bool have_max_objects
)
1250 RGWBucketInfo bucket_info
;
1251 map
<string
, bufferlist
> attrs
;
1252 RGWObjectCtx
obj_ctx(store
);
1253 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1255 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1259 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1261 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1263 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1269 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1270 bool have_max_size
, bool have_max_objects
)
1272 RGWUserInfo
& user_info
= op_state
.get_user_info();
1274 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1276 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1279 int r
= user
.modify(op_state
, &err
);
1281 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1287 int set_user_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1288 bool have_max_size
, bool have_max_objects
)
1290 RGWUserInfo
& user_info
= op_state
.get_user_info();
1292 set_quota_info(user_info
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1294 op_state
.set_user_quota(user_info
.user_quota
);
1297 int r
= user
.modify(op_state
, &err
);
1299 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1305 static bool bucket_object_check_filter(const string
& name
)
1308 string ns
; /* empty namespace */
1309 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1312 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1314 map
<string
, bufferlist
> attrs
;
1317 RGWObjectCtx
obj_ctx(store
);
1318 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1319 RGWRados::Object::Read
read_op(&op_target
);
1321 read_op
.params
.attrs
= &attrs
;
1322 read_op
.params
.obj_size
= &obj_size
;
1324 int ret
= read_op
.prepare();
1326 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1330 map
<string
, bufferlist
>::iterator iter
;
1331 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1332 if (iter
== attrs
.end()) {
1333 *need_rewrite
= (obj_size
>= min_stripe_size
);
1337 RGWObjManifest manifest
;
1340 bufferlist
& bl
= iter
->second
;
1341 bufferlist::iterator biter
= bl
.begin();
1342 ::decode(manifest
, biter
);
1343 } catch (buffer::error
& err
) {
1344 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1348 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1349 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1350 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1351 RGWObjManifestPart
& part
= oiter
->second
;
1353 if (part
.size
>= min_stripe_size
) {
1354 *need_rewrite
= true;
1358 *need_rewrite
= false;
1364 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1365 f
->open_object_section("object");
1366 f
->open_object_section("key");
1367 f
->dump_string("type", "head");
1368 f
->dump_string("name", key
.name
);
1369 f
->dump_string("instance", key
.instance
);
1375 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1377 f
->dump_string("oid", oid
);
1378 f
->dump_string("locator", locator
);
1381 RGWObjectCtx
obj_ctx(store
);
1383 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1384 RGWRados::Object::Read
read_op(&op_target
);
1386 int ret
= read_op
.prepare();
1387 bool needs_fixing
= (ret
== -ENOENT
);
1389 f
->dump_bool("needs_fixing", needs_fixing
);
1391 string status
= (needs_fixing
? "needs_fixing" : "ok");
1393 if ((needs_fixing
|| remove_bad
) && fix
) {
1394 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1396 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1403 f
->dump_string("status", status
);
1410 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1411 f
->open_object_section("object");
1412 f
->open_object_section("key");
1413 f
->dump_string("type", "tail");
1414 f
->dump_string("name", key
.name
);
1415 f
->dump_string("instance", key
.instance
);
1421 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1423 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1426 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1429 f
->dump_bool("needs_fixing", needs_fixing
);
1430 f
->dump_string("status", status
);
1437 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1438 bool fix
, bool remove_bad
, Formatter
*f
)
1440 if (remove_bad
&& !fix
) {
1441 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1445 RGWBucketInfo bucket_info
;
1449 f
->open_object_section("bucket");
1450 f
->dump_string("bucket", bucket_name
);
1451 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1453 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1459 int max_entries
= 1000;
1463 vector
<rgw_bucket_dir_entry
> result
;
1464 map
<string
, bool> common_prefixes
;
1467 RGWRados::Bucket
target(store
, bucket_info
);
1468 RGWRados::Bucket::List
list_op(&target
);
1472 list_op
.params
.prefix
= prefix
;
1473 list_op
.params
.delim
= delim
;
1474 list_op
.params
.marker
= rgw_obj_key(marker
);
1475 list_op
.params
.ns
= ns
;
1476 list_op
.params
.enforce_ns
= true;
1477 list_op
.params
.list_versions
= true;
1479 f
->open_array_section("check_objects");
1481 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1483 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1487 count
+= result
.size();
1489 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1490 rgw_obj_key key
= iter
->key
;
1491 rgw_obj
obj(bucket
, key
);
1493 if (key
.name
[0] == '_') {
1494 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1497 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1502 } while (truncated
&& count
< max_entries
);
1511 int set_bucket_sync_enabled(RGWRados
*store
, int opt_cmd
, const string
& tenant_name
, const string
& bucket_name
)
1513 RGWBucketInfo bucket_info
;
1514 map
<string
, bufferlist
> attrs
;
1515 RGWObjectCtx
obj_ctx(store
);
1517 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1519 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1523 if (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
) {
1524 bucket_info
.flags
&= ~BUCKET_DATASYNC_DISABLED
;
1525 } else if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1526 bucket_info
.flags
|= BUCKET_DATASYNC_DISABLED
;
1529 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1531 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1535 int shards_num
= bucket_info
.num_shards
? bucket_info
.num_shards
: 1;
1536 int shard_id
= bucket_info
.num_shards
? 0 : -1;
1538 if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1539 r
= store
->stop_bi_log_entries(bucket_info
, -1);
1541 lderr(store
->ctx()) << "ERROR: failed writing stop bilog" << dendl
;
1545 r
= store
->resync_bi_log_entries(bucket_info
, -1);
1547 lderr(store
->ctx()) << "ERROR: failed writing resync bilog" << dendl
;
1552 for (int i
= 0; i
< shards_num
; ++i
, ++shard_id
) {
1553 r
= store
->data_log
->add_entry(bucket_info
.bucket
, shard_id
);
1555 lderr(store
->ctx()) << "ERROR: failed writing data log" << dendl
;
1564 /// search for a matching zone/zonegroup id and return a connection if found
1565 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1566 const RGWZoneGroup
& zonegroup
,
1567 const std::string
& remote
)
1569 boost::optional
<RGWRESTConn
> conn
;
1570 if (remote
== zonegroup
.get_id()) {
1571 conn
.emplace(store
->ctx(), store
, remote
, zonegroup
.endpoints
);
1573 for (const auto& z
: zonegroup
.zones
) {
1574 const auto& zone
= z
.second
;
1575 if (remote
== zone
.id
) {
1576 conn
.emplace(store
->ctx(), store
, remote
, zone
.endpoints
);
1584 /// search each zonegroup for a connection
1585 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1586 const RGWPeriodMap
& period_map
,
1587 const std::string
& remote
)
1589 boost::optional
<RGWRESTConn
> conn
;
1590 for (const auto& zg
: period_map
.zonegroups
) {
1591 conn
= get_remote_conn(store
, zg
.second
, remote
);
1599 // we expect a very small response
1600 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1602 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1603 bufferlist
& in_data
, JSONParser
& parser
)
1609 ceph::bufferlist response
;
1611 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1613 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1614 if (parse_ret
< 0) {
1615 cerr
<< "failed to parse response" << std::endl
;
1621 static int send_to_url(const string
& url
, const string
& access
,
1622 const string
& secret
, req_info
& info
,
1623 bufferlist
& in_data
, JSONParser
& parser
)
1625 if (access
.empty() || secret
.empty()) {
1626 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1634 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1636 bufferlist response
;
1637 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1639 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1640 if (parse_ret
< 0) {
1641 cout
<< "failed to parse response" << std::endl
;
1647 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1648 const string
& access
, const string
& secret
,
1649 req_info
& info
, bufferlist
& in_data
,
1653 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1655 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1658 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1659 string remote
, const string
& url
,
1660 const string
& access
, const string
& secret
,
1663 const string
& master_zone
= period
.get_master_zone();
1664 if (master_zone
.empty()) {
1665 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1668 // are we the period's master zone?
1669 if (store
->get_zone_params().get_id() == master_zone
) {
1670 // read the current period
1671 RGWPeriod current_period
;
1672 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1674 cerr
<< "Error initializing current period: "
1675 << cpp_strerror(-ret
) << std::endl
;
1678 // the master zone can commit locally
1679 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1681 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1686 if (remote
.empty() && url
.empty()) {
1687 // use the new master zone's connection
1688 remote
= master_zone
;
1689 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1691 boost::optional
<RGWRESTConn
> conn
;
1692 RGWRESTConn
*remote_conn
= nullptr;
1693 if (!remote
.empty()) {
1694 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1696 cerr
<< "failed to find a zone or zonegroup for remote "
1697 << remote
<< std::endl
;
1700 remote_conn
= &*conn
;
1703 // push period to the master with an empty period id
1707 req_info
info(g_ceph_context
, &env
);
1708 info
.method
= "POST";
1709 info
.request_uri
= "/admin/realm/period";
1711 // json format into a bufferlist
1712 JSONFormatter
jf(false);
1713 encode_json("period", period
, &jf
);
1718 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1720 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1722 // did we parse an error message?
1723 auto message
= p
.find_obj("Message");
1725 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1730 // decode the response and store it back
1732 decode_json_obj(period
, &p
);
1733 } catch (JSONDecoder::err
& e
) {
1734 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1737 if (period
.get_id().empty()) {
1738 cerr
<< "Period commit got back an empty period id" << std::endl
;
1741 // the master zone gave us back the period that it committed, so it's
1742 // safe to save it as our latest epoch
1743 ret
= period
.store_info(false);
1745 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1746 << cpp_strerror(ret
) << std::endl
;
1749 ret
= period
.set_latest_epoch(period
.get_epoch());
1751 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1754 ret
= period
.reflect();
1756 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1759 realm
.notify_new_period(period
);
1763 static int update_period(const string
& realm_id
, const string
& realm_name
,
1764 const string
& period_id
, const string
& period_epoch
,
1765 bool commit
, const string
& remote
, const string
& url
,
1766 const string
& access
, const string
& secret
,
1767 Formatter
*formatter
, bool force
)
1769 RGWRealm
realm(realm_id
, realm_name
);
1770 int ret
= realm
.init(g_ceph_context
, store
);
1772 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1776 if (!period_epoch
.empty()) {
1777 epoch
= atoi(period_epoch
.c_str());
1779 RGWPeriod
period(period_id
, epoch
);
1780 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1782 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1786 ret
= period
.update();
1788 // Dropping the error message here, as both the ret codes were handled in
1792 ret
= period
.store_info(false);
1794 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1798 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1800 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1804 encode_json("period", period
, formatter
);
1805 formatter
->flush(cout
);
1810 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1811 const string
& bucket_id
, rgw_bucket
& bucket
)
1813 RGWBucketInfo bucket_info
;
1815 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1817 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1824 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1825 const string
& access_key
, const string
& secret_key
,
1826 const string
& realm_id
, const string
& realm_name
,
1827 const string
& period_id
, const string
& period_epoch
,
1831 req_info
info(g_ceph_context
, &env
);
1832 info
.method
= "GET";
1833 info
.request_uri
= "/admin/realm/period";
1835 map
<string
, string
> ¶ms
= info
.args
.get_params();
1836 if (!realm_id
.empty())
1837 params
["realm_id"] = realm_id
;
1838 if (!realm_name
.empty())
1839 params
["realm_name"] = realm_name
;
1840 if (!period_id
.empty())
1841 params
["period_id"] = period_id
;
1842 if (!period_epoch
.empty())
1843 params
["epoch"] = period_epoch
;
1847 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1850 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1853 ret
= period
->init(g_ceph_context
, store
, false);
1855 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1859 decode_json_obj(*period
, &p
);
1860 } catch (JSONDecoder::err
& e
) {
1861 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1864 ret
= period
->store_info(false);
1866 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1868 // store latest epoch (ignore errors)
1869 period
->update_latest_epoch(period
->get_epoch());
1873 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1874 const std::string
& realm_name
,
1875 std::string
* period_id
)
1877 RGWRealm
realm(realm_id
, realm_name
);
1878 int ret
= realm
.init(g_ceph_context
, store
);
1880 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1883 *period_id
= realm
.get_current_period();
1887 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1889 if (!ss
.str().empty()) {
1890 l
.push_back(ss
.str());
1895 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1899 ss
<< setw(tab
) << "" << setw(1);
1904 static void get_md_sync_status(list
<string
>& status
)
1906 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1908 int ret
= sync
.init();
1910 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1914 rgw_meta_sync_status sync_status
;
1915 ret
= sync
.read_sync_status(&sync_status
);
1917 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1922 switch (sync_status
.sync_info
.state
) {
1923 case rgw_meta_sync_info::StateInit
:
1924 status_str
= "init";
1926 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1927 status_str
= "preparing for full sync";
1929 case rgw_meta_sync_info::StateSync
:
1930 status_str
= "syncing";
1933 status_str
= "unknown";
1936 status
.push_back(status_str
);
1938 uint64_t full_total
= 0;
1939 uint64_t full_complete
= 0;
1943 int total_shards
= 0;
1945 for (auto marker_iter
: sync_status
.sync_markers
) {
1946 full_total
+= marker_iter
.second
.total_entries
;
1948 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1950 full_complete
+= marker_iter
.second
.pos
;
1952 full_complete
+= marker_iter
.second
.total_entries
;
1954 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1960 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1963 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1966 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1968 rgw_mdlog_info log_info
;
1969 ret
= sync
.read_log_info(&log_info
);
1971 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1975 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1976 string master_period
= store
->get_current_period_id();
1978 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1980 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1984 map
<int, string
> shards_behind
;
1985 if (sync_status
.sync_info
.period
!= master_period
) {
1986 status
.push_back(string("master is on a different period: master_period=" +
1987 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1989 for (auto local_iter
: sync_status
.sync_markers
) {
1990 int shard_id
= local_iter
.first
;
1991 auto iter
= master_shards_info
.find(shard_id
);
1993 if (iter
== master_shards_info
.end()) {
1995 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
1998 auto master_marker
= iter
->second
.marker
;
1999 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
2000 master_marker
> local_iter
.second
.marker
) {
2001 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2006 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2007 if (total_behind
== 0) {
2008 push_ss(ss
, status
) << "metadata is caught up with master";
2010 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
2012 map
<int, rgw_mdlog_shard_data
> master_pos
;
2013 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
2015 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2017 ceph::real_time oldest
;
2018 for (auto iter
: master_pos
) {
2019 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
2021 if (!shard_data
.entries
.empty()) {
2022 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
2023 if (ceph::real_clock::is_zero(oldest
)) {
2024 oldest
= entry
.timestamp
;
2025 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2026 oldest
= entry
.timestamp
;
2031 if (!ceph::real_clock::is_zero(oldest
)) {
2032 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
2037 flush_ss(ss
, status
);
2040 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
2044 auto ziter
= store
->zone_by_id
.find(source_zone
);
2045 if (ziter
== store
->zone_by_id
.end()) {
2046 push_ss(ss
, status
, tab
) << string("zone not found");
2047 flush_ss(ss
, status
);
2050 RGWZone
& sz
= ziter
->second
;
2052 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
2053 push_ss(ss
, status
, tab
) << string("not syncing from zone");
2054 flush_ss(ss
, status
);
2057 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
2059 int ret
= sync
.init();
2061 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
2062 flush_ss(ss
, status
);
2066 rgw_data_sync_status sync_status
;
2067 ret
= sync
.read_sync_status(&sync_status
);
2068 if (ret
< 0 && ret
!= -ENOENT
) {
2069 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2074 switch (sync_status
.sync_info
.state
) {
2075 case rgw_data_sync_info::StateInit
:
2076 status_str
= "init";
2078 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2079 status_str
= "preparing for full sync";
2081 case rgw_data_sync_info::StateSync
:
2082 status_str
= "syncing";
2085 status_str
= "unknown";
2088 push_ss(ss
, status
, tab
) << status_str
;
2090 uint64_t full_total
= 0;
2091 uint64_t full_complete
= 0;
2095 int total_shards
= 0;
2097 for (auto marker_iter
: sync_status
.sync_markers
) {
2098 full_total
+= marker_iter
.second
.total_entries
;
2100 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2102 full_complete
+= marker_iter
.second
.pos
;
2104 full_complete
+= marker_iter
.second
.total_entries
;
2106 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2111 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2114 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2117 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2119 rgw_datalog_info log_info
;
2120 ret
= sync
.read_log_info(&log_info
);
2122 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2127 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2129 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2131 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2135 map
<int, string
> shards_behind
;
2137 for (auto local_iter
: sync_status
.sync_markers
) {
2138 int shard_id
= local_iter
.first
;
2139 auto iter
= source_shards_info
.find(shard_id
);
2141 if (iter
== source_shards_info
.end()) {
2143 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2146 auto master_marker
= iter
->second
.marker
;
2147 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2148 master_marker
> local_iter
.second
.marker
) {
2149 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2153 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2154 if (total_behind
== 0) {
2155 push_ss(ss
, status
, tab
) << "data is caught up with source";
2157 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2159 map
<int, rgw_datalog_shard_data
> master_pos
;
2160 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2162 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2164 ceph::real_time oldest
;
2165 for (auto iter
: master_pos
) {
2166 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2168 if (!shard_data
.entries
.empty()) {
2169 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2170 if (ceph::real_clock::is_zero(oldest
)) {
2171 oldest
= entry
.timestamp
;
2172 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2173 oldest
= entry
.timestamp
;
2178 if (!ceph::real_clock::is_zero(oldest
)) {
2179 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2184 flush_ss(ss
, status
);
2187 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2191 for (auto e
: entries
) {
2192 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2198 static void sync_status(Formatter
*formatter
)
2200 RGWRealm
& realm
= store
->realm
;
2201 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2202 RGWZone
& zone
= store
->get_zone();
2206 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2207 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2208 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2210 list
<string
> md_status
;
2212 if (store
->is_meta_master()) {
2213 md_status
.push_back("no sync (zone is master)");
2215 get_md_sync_status(md_status
);
2218 tab_dump("metadata sync", width
, md_status
);
2220 list
<string
> data_status
;
2222 for (auto iter
: store
->zone_conn_map
) {
2223 const string
& source_id
= iter
.first
;
2224 string source_str
= "source: ";
2225 string s
= source_str
+ source_id
;
2226 auto siter
= store
->zone_by_id
.find(source_id
);
2227 if (siter
!= store
->zone_by_id
.end()) {
2228 s
+= string(" (") + siter
->second
.name
+ ")";
2230 data_status
.push_back(s
);
2231 get_data_sync_status(source_id
, data_status
, source_str
.size());
2234 tab_dump("data sync", width
, data_status
);
2237 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2240 get_str_list(s
, ",", confs
);
2241 for (auto c
: confs
) {
2242 ssize_t pos
= c
.find("=");
2246 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2251 int check_reshard_bucket_params(RGWRados
*store
,
2252 const string
& bucket_name
,
2253 const string
& tenant
,
2254 const string
& bucket_id
,
2255 bool num_shards_specified
,
2257 int yes_i_really_mean_it
,
2259 RGWBucketInfo
& bucket_info
,
2260 map
<string
, bufferlist
>& attrs
)
2262 if (bucket_name
.empty()) {
2263 cerr
<< "ERROR: bucket not specified" << std::endl
;
2267 if (!num_shards_specified
) {
2268 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2272 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2273 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2277 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2279 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2283 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2285 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2286 cerr
<< "num shards is less or equal to current shards count" << std::endl
2287 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2293 int create_new_bucket_instance(RGWRados
*store
,
2295 const RGWBucketInfo
& bucket_info
,
2296 map
<string
, bufferlist
>& attrs
,
2297 RGWBucketInfo
& new_bucket_info
)
2300 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2301 new_bucket_info
.bucket
.oid
.clear();
2303 new_bucket_info
.num_shards
= new_num_shards
;
2304 new_bucket_info
.objv_tracker
.clear();
2306 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2308 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2312 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2314 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2322 #ifdef BUILDING_FOR_EMBEDDED
2323 extern "C" int cephd_rgw_admin(int argc
, const char **argv
)
2325 int main(int argc
, const char **argv
)
2328 vector
<const char*> args
;
2329 argv_to_vec(argc
, (const char **)argv
, args
);
2332 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2333 CODE_ENVIRONMENT_UTILITY
, 0);
2335 // for region -> zonegroup conversion (must happen before common_init_finish())
2336 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2337 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2340 common_init_finish(g_ceph_context
);
2344 std::string access_key
, secret_key
, user_email
, display_name
;
2345 std::string bucket_name
, pool_name
, object
;
2347 std::string date
, subuser
, access
, format
;
2348 std::string start_date
, end_date
;
2349 std::string key_type_str
;
2350 std::string period_id
, period_epoch
, remote
, url
;
2351 std::string master_zonegroup
, master_zone
;
2352 std::string realm_name
, realm_id
, realm_new_name
;
2353 std::string zone_name
, zone_id
, zone_new_name
;
2354 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2355 std::string api_name
;
2356 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2357 list
<string
> endpoints
;
2359 int sync_from_all_specified
= false;
2360 bool sync_from_all
= false;
2361 list
<string
> sync_from
;
2362 list
<string
> sync_from_rm
;
2363 std::string master_url
;
2365 int set_default
= 0;
2366 bool is_master
= false;
2367 bool is_master_set
= false;
2369 bool read_only
= false;
2370 int is_read_only_set
= false;
2372 int staging
= false;
2373 int key_type
= KEY_TYPE_UNDEFINED
;
2375 uint32_t perm_mask
= 0;
2377 int opt_cmd
= OPT_NO_CMD
;
2379 int gen_access_key
= 0;
2380 int gen_secret_key
= 0;
2381 bool set_perm
= false;
2382 bool set_temp_url_key
= false;
2383 map
<int, string
> temp_url_keys
;
2385 Formatter
*formatter
= NULL
;
2386 int purge_data
= false;
2387 int pretty_format
= false;
2388 int show_log_entries
= true;
2389 int show_log_sum
= true;
2390 int skip_zero_entries
= false; // log show
2391 int purge_keys
= false;
2392 int yes_i_really_mean_it
= false;
2393 int delete_child_objects
= false;
2395 int remove_bad
= false;
2396 int check_head_obj_locator
= false;
2397 int max_buckets
= -1;
2398 bool max_buckets_specified
= false;
2399 map
<string
, bool> categories
;
2401 int check_objects
= false;
2402 RGWUserAdminOpState user_op
;
2403 RGWBucketAdminOpState bucket_op
;
2405 string metadata_key
;
2406 RGWObjVersionTracker objv_tracker
;
2408 string start_marker
;
2410 int max_entries
= -1;
2411 bool max_entries_specified
= false;
2413 bool admin_specified
= false;
2415 bool system_specified
= false;
2417 bool specified_shard_id
= false;
2419 bool specified_daemon_id
= false;
2423 string replica_log_type_str
;
2424 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2427 string object_version
;
2428 string placement_id
;
2430 list
<string
> tags_add
;
2431 list
<string
> tags_rm
;
2433 int64_t max_objects
= -1;
2434 int64_t max_size
= -1;
2435 bool have_max_objects
= false;
2436 bool have_max_size
= false;
2437 int include_all
= false;
2439 int sync_stats
= false;
2440 int reset_stats
= false;
2441 int bypass_gc
= false;
2442 int warnings_only
= false;
2443 int inconsistent_index
= false;
2445 int verbose
= false;
2447 int extra_info
= false;
2449 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2450 uint64_t max_rewrite_size
= ULLONG_MAX
;
2451 uint64_t min_rewrite_stripe_size
= 0;
2453 BIIndexType bi_index_type
= PlainIdx
;
2457 bool num_shards_specified
= false;
2458 int max_concurrent_ios
= 32;
2459 uint64_t orphan_stale_secs
= (24 * 3600);
2462 std::ostringstream errs
;
2466 string source_zone_name
;
2467 string source_zone
; /* zone id */
2470 bool tier_type_specified
= false;
2472 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2473 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2475 boost::optional
<string
> index_pool
;
2476 boost::optional
<string
> data_pool
;
2477 boost::optional
<string
> data_extra_pool
;
2478 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2479 bool index_type_specified
= false;
2481 boost::optional
<std::string
> compression_type
;
2483 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2484 if (ceph_argparse_double_dash(args
, i
)) {
2486 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2489 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2490 user_id
.from_str(val
);
2491 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2493 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2495 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2497 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2499 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2501 user_op
.user_email_specified
=true;
2502 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2504 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2506 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2508 pool
= rgw_pool(pool_name
);
2509 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2511 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2512 object_version
= val
;
2513 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2515 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2517 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2519 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2521 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2523 if (key_type_str
.compare("swift") == 0) {
2524 key_type
= KEY_TYPE_SWIFT
;
2525 } else if (key_type_str
.compare("s3") == 0) {
2526 key_type
= KEY_TYPE_S3
;
2528 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2532 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2534 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2536 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2538 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2540 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2542 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2544 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2545 admin_specified
= true;
2546 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2547 system_specified
= true;
2548 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2550 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2552 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2554 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2555 if (!errs
.str().empty()) {
2556 cerr
<< errs
.str() << std::endl
;
2559 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2560 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2561 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2562 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2563 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2564 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2565 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2566 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2568 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2571 max_buckets_specified
= true;
2572 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2573 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2574 max_entries_specified
= true;
2576 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2579 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2580 max_size
= strict_si_cast
<int64_t>(val
.c_str(), &err
);
2582 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2585 have_max_size
= true;
2586 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2587 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2589 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2592 have_max_objects
= true;
2593 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2595 if (end_date
.empty())
2597 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2599 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2601 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2602 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2604 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2607 num_shards_specified
= true;
2608 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2609 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2611 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2614 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2615 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2617 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2620 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2621 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2623 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2626 specified_shard_id
= true;
2627 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2629 specified_daemon_id
= true;
2630 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2632 perm_mask
= rgw_str_to_perm(access
.c_str());
2634 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2635 temp_url_keys
[0] = val
;
2636 set_temp_url_key
= true;
2637 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2638 temp_url_keys
[1] = val
;
2639 set_temp_url_key
= true;
2640 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2642 if (bucket_id
.empty()) {
2643 cerr
<< "bad bucket-id" << std::endl
;
2647 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2649 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2650 string cat_str
= val
;
2651 list
<string
> cat_list
;
2652 list
<string
>::iterator iter
;
2653 get_str_list(cat_str
, cat_list
);
2654 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2655 categories
[*iter
] = true;
2657 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2659 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2661 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2662 delete_child_objects
= purge_data
;
2663 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2665 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2667 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2669 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2671 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2673 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2675 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2677 } else if (ceph_argparse_binary_flag(args
, i
, &reset_stats
, NULL
, "--reset-stats", (char*)NULL
)) {
2679 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2681 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2683 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2685 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2687 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2689 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2691 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2693 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2695 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2697 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2699 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2701 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2703 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2704 replica_log_type_str
= val
;
2705 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2706 if (replica_log_type
== ReplicaLog_Invalid
) {
2707 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2710 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2711 string index_type_str
= val
;
2712 bi_index_type
= get_bi_index_type(index_type_str
);
2713 if (bi_index_type
== InvalidIdx
) {
2714 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2717 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2718 is_master
= (bool)is_master_int
;
2719 is_master_set
= true;
2720 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2722 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2723 read_only
= (bool)read_only_int
;
2724 is_read_only_set
= true;
2725 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2727 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2728 master_zonegroup
= val
;
2729 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2731 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2733 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2735 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2737 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2739 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2741 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2742 realm_new_name
= val
;
2743 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2745 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2746 zonegroup_new_name
= val
;
2747 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2749 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2750 get_str_list(val
, tags
);
2751 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2752 get_str_list(val
, tags_add
);
2753 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2754 get_str_list(val
, tags_rm
);
2755 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2757 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2759 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2760 zone_new_name
= val
;
2761 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2762 get_str_list(val
, endpoints
);
2763 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2764 get_str_list(val
, sync_from
);
2765 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2766 get_str_list(val
, sync_from_rm
);
2767 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2768 sync_from_all
= (bool)tmp_int
;
2769 sync_from_all_specified
= true;
2770 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2771 source_zone_name
= val
;
2772 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2774 tier_type_specified
= true;
2775 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2776 parse_tier_config_param(val
, tier_config_add
);
2777 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2778 parse_tier_config_param(val
, tier_config_rm
);
2779 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2781 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2783 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2784 data_extra_pool
= val
;
2785 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2786 if (val
== "normal") {
2787 placement_index_type
= RGWBIType_Normal
;
2788 } else if (val
== "indexless") {
2789 placement_index_type
= RGWBIType_Indexless
;
2791 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2793 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2797 index_type_specified
= true;
2798 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2799 compression_type
= val
;
2800 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2802 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2804 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2805 assume_role_doc
= val
;
2806 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2808 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2809 perm_policy_doc
= val
;
2810 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2812 } else if (strncmp(*i
, "-", 1) == 0) {
2813 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
2825 const char *prev_cmd
= NULL
;
2826 const char *prev_prev_cmd
= NULL
;
2827 std::vector
<const char*>::iterator i
;
2828 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
2829 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
2831 cerr
<< "unrecognized arg " << *i
<< std::endl
;
2839 prev_prev_cmd
= prev_cmd
;
2843 if (opt_cmd
== OPT_NO_CMD
) {
2848 /* some commands may have an optional extra param */
2849 if (i
!= args
.end()) {
2851 case OPT_METADATA_GET
:
2852 case OPT_METADATA_PUT
:
2853 case OPT_METADATA_RM
:
2854 case OPT_METADATA_LIST
:
2862 if (tenant
.empty()) {
2863 tenant
= user_id
.tenant
;
2865 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
2866 && opt_cmd
!= OPT_ROLE_DELETE
2867 && opt_cmd
!= OPT_ROLE_GET
2868 && opt_cmd
!= OPT_ROLE_MODIFY
2869 && opt_cmd
!= OPT_ROLE_LIST
2870 && opt_cmd
!= OPT_ROLE_POLICY_PUT
2871 && opt_cmd
!= OPT_ROLE_POLICY_LIST
2872 && opt_cmd
!= OPT_ROLE_POLICY_GET
2873 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
2874 && opt_cmd
!= OPT_RESHARD_ADD
2875 && opt_cmd
!= OPT_RESHARD_CANCEL
2876 && opt_cmd
!= OPT_RESHARD_STATUS
) {
2877 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
2880 user_id
.tenant
= tenant
;
2882 /* check key parameter conflict */
2883 if ((!access_key
.empty()) && gen_access_key
) {
2884 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
2887 if ((!secret_key
.empty()) && gen_secret_key
) {
2888 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
2893 // default to pretty json
2894 if (format
.empty()) {
2896 pretty_format
= true;
2899 if (format
== "xml")
2900 formatter
= new XMLFormatter(pretty_format
);
2901 else if (format
== "json")
2902 formatter
= new JSONFormatter(pretty_format
);
2904 cerr
<< "unrecognized format: " << format
<< std::endl
;
2909 realm_name
= g_conf
->rgw_realm
;
2910 zone_name
= g_conf
->rgw_zone
;
2911 zonegroup_name
= g_conf
->rgw_zonegroup
;
2913 RGWStreamFlusher
f(formatter
, cout
);
2915 // not a raw op if 'period update' needs to commit to master
2916 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
2917 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
2918 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
2919 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
2920 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
2921 OPT_ZONEGROUP_REMOVE
,
2922 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
2923 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
2924 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
2925 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
2926 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
2927 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
2928 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
2929 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
2931 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
2933 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
2934 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
2935 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
2936 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
2937 OPT_REALM_LIST_PERIODS
,
2938 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
2939 OPT_REALM_RENAME
, OPT_REALM_SET
,
2940 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
2943 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
2946 if (raw_storage_op
) {
2947 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
2949 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false);
2952 cerr
<< "couldn't init storage provider" << std::endl
;
2956 if (!source_zone_name
.empty()) {
2957 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
2958 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
2959 source_zone
= source_zone_name
;
2963 rgw_user_init(store
);
2964 rgw_bucket_init(store
->meta_mgr
);
2966 struct rgw_curl_setup
{
2968 rgw::curl::setup_curl(boost::none
);
2971 rgw::curl::cleanup_curl();
2975 StoreDestructor
store_destructor(store
);
2977 if (raw_storage_op
) {
2979 case OPT_PERIOD_DELETE
:
2981 if (period_id
.empty()) {
2982 cerr
<< "missing period id" << std::endl
;
2985 RGWPeriod
period(period_id
);
2986 int ret
= period
.init(g_ceph_context
, store
);
2988 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
2991 ret
= period
.delete_obj();
2993 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
2999 case OPT_PERIOD_GET
:
3002 if (!period_epoch
.empty()) {
3003 epoch
= atoi(period_epoch
.c_str());
3006 RGWRealm
realm(realm_id
, realm_name
);
3007 int ret
= realm
.init(g_ceph_context
, store
);
3009 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
3012 realm_id
= realm
.get_id();
3013 realm_name
= realm
.get_name();
3014 period_id
= RGWPeriod::get_staging_id(realm_id
);
3017 RGWPeriod
period(period_id
, epoch
);
3018 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
3020 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
3023 encode_json("period", period
, formatter
);
3024 formatter
->flush(cout
);
3028 case OPT_PERIOD_GET_CURRENT
:
3030 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3034 formatter
->open_object_section("period_get_current");
3035 encode_json("current_period", period_id
, formatter
);
3036 formatter
->close_section();
3037 formatter
->flush(cout
);
3040 case OPT_PERIOD_LIST
:
3042 list
<string
> periods
;
3043 int ret
= store
->list_periods(periods
);
3045 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
3048 formatter
->open_object_section("periods_list");
3049 encode_json("periods", periods
, formatter
);
3050 formatter
->close_section();
3051 formatter
->flush(cout
);
3055 case OPT_PERIOD_UPDATE
:
3057 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
3058 commit
, remote
, url
, access_key
, secret_key
,
3059 formatter
, yes_i_really_mean_it
);
3065 case OPT_PERIOD_PULL
:
3067 boost::optional
<RGWRESTConn
> conn
;
3068 RGWRESTConn
*remote_conn
= nullptr;
3070 // load current period for endpoints
3071 RGWRealm
realm(realm_id
, realm_name
);
3072 int ret
= realm
.init(g_ceph_context
, store
);
3074 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3077 RGWPeriod
current_period(realm
.get_current_period());
3078 ret
= current_period
.init(g_ceph_context
, store
);
3080 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
3083 if (remote
.empty()) {
3084 // use realm master zone as remote
3085 remote
= current_period
.get_master_zone();
3087 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
3089 cerr
<< "failed to find a zone or zonegroup for remote "
3090 << remote
<< std::endl
;
3093 remote_conn
= &*conn
;
3097 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3098 realm_id
, realm_name
, period_id
, period_epoch
,
3101 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3105 encode_json("period", period
, formatter
);
3106 formatter
->flush(cout
);
3110 case OPT_GLOBAL_QUOTA_GET
:
3111 case OPT_GLOBAL_QUOTA_SET
:
3112 case OPT_GLOBAL_QUOTA_ENABLE
:
3113 case OPT_GLOBAL_QUOTA_DISABLE
:
3115 if (realm_id
.empty()) {
3116 RGWRealm
realm(g_ceph_context
, store
);
3117 if (!realm_name
.empty()) {
3118 // look up realm_id for the given realm_name
3119 int ret
= realm
.read_id(realm_name
, realm_id
);
3121 cerr
<< "ERROR: failed to read realm for " << realm_name
3122 << ": " << cpp_strerror(-ret
) << std::endl
;
3126 // use default realm_id when none is given
3127 int ret
= realm
.read_default_id(realm_id
);
3128 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3129 cerr
<< "ERROR: failed to read default realm: "
3130 << cpp_strerror(-ret
) << std::endl
;
3136 RGWPeriodConfig period_config
;
3137 int ret
= period_config
.read(store
, realm_id
);
3138 if (ret
< 0 && ret
!= -ENOENT
) {
3139 cerr
<< "ERROR: failed to read period config: "
3140 << cpp_strerror(-ret
) << std::endl
;
3144 formatter
->open_object_section("period_config");
3145 if (quota_scope
== "bucket") {
3146 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3147 max_size
, max_objects
,
3148 have_max_size
, have_max_objects
);
3149 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3150 } else if (quota_scope
== "user") {
3151 set_quota_info(period_config
.user_quota
, opt_cmd
,
3152 max_size
, max_objects
,
3153 have_max_size
, have_max_objects
);
3154 encode_json("user quota", period_config
.user_quota
, formatter
);
3155 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3156 // if no scope is given for GET, print both
3157 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3158 encode_json("user quota", period_config
.user_quota
, formatter
);
3160 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3161 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3164 formatter
->close_section();
3166 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3167 // write the modified period config
3168 ret
= period_config
.write(store
, realm_id
);
3170 cerr
<< "ERROR: failed to write period config: "
3171 << cpp_strerror(-ret
) << std::endl
;
3174 if (!realm_id
.empty()) {
3175 cout
<< "Global quota changes saved. Use 'period update' to apply "
3176 "them to the staging period, and 'period commit' to commit the "
3177 "new period." << std::endl
;
3179 cout
<< "Global quota changes saved. They will take effect as "
3180 "the gateways are restarted." << std::endl
;
3184 formatter
->flush(cout
);
3188 case OPT_REALM_CREATE
:
3190 if (realm_name
.empty()) {
3191 cerr
<< "missing realm name" << std::endl
;
3195 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3196 int ret
= realm
.create();
3198 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3203 ret
= realm
.set_as_default();
3205 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3209 encode_json("realm", realm
, formatter
);
3210 formatter
->flush(cout
);
3214 case OPT_REALM_DELETE
:
3216 RGWRealm
realm(realm_id
, realm_name
);
3217 if (realm_name
.empty() && realm_id
.empty()) {
3218 cerr
<< "missing realm name or id" << std::endl
;
3221 int ret
= realm
.init(g_ceph_context
, store
);
3223 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3226 ret
= realm
.delete_obj();
3228 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3236 RGWRealm
realm(realm_id
, realm_name
);
3237 int ret
= realm
.init(g_ceph_context
, store
);
3239 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3240 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3242 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3246 encode_json("realm", realm
, formatter
);
3247 formatter
->flush(cout
);
3251 case OPT_REALM_GET_DEFAULT
:
3253 RGWRealm
realm(g_ceph_context
, store
);
3255 int ret
= realm
.read_default_id(default_id
);
3256 if (ret
== -ENOENT
) {
3257 cout
<< "No default realm is set" << std::endl
;
3259 } else if (ret
< 0) {
3260 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3263 cout
<< "default realm: " << default_id
<< std::endl
;
3266 case OPT_REALM_LIST
:
3268 RGWRealm
realm(g_ceph_context
, store
);
3270 int ret
= realm
.read_default_id(default_id
);
3271 if (ret
< 0 && ret
!= -ENOENT
) {
3272 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3274 list
<string
> realms
;
3275 ret
= store
->list_realms(realms
);
3277 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3280 formatter
->open_object_section("realms_list");
3281 encode_json("default_info", default_id
, formatter
);
3282 encode_json("realms", realms
, formatter
);
3283 formatter
->close_section();
3284 formatter
->flush(cout
);
3288 case OPT_REALM_LIST_PERIODS
:
3290 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3294 list
<string
> periods
;
3295 ret
= store
->list_periods(period_id
, periods
);
3297 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3300 formatter
->open_object_section("realm_periods_list");
3301 encode_json("current_period", period_id
, formatter
);
3302 encode_json("periods", periods
, formatter
);
3303 formatter
->close_section();
3304 formatter
->flush(cout
);
3309 case OPT_REALM_RENAME
:
3311 RGWRealm
realm(realm_id
, realm_name
);
3312 if (realm_new_name
.empty()) {
3313 cerr
<< "missing realm new name" << std::endl
;
3316 if (realm_name
.empty() && realm_id
.empty()) {
3317 cerr
<< "missing realm name or id" << std::endl
;
3320 int ret
= realm
.init(g_ceph_context
, store
);
3322 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3325 ret
= realm
.rename(realm_new_name
);
3327 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3330 cout
<< "Realm name updated. Note that this change only applies to "
3331 "the current cluster, so this command must be run separately "
3332 "on each of the realm's other clusters." << std::endl
;
3337 if (realm_id
.empty() && realm_name
.empty()) {
3338 cerr
<< "no realm name or id provided" << std::endl
;
3341 RGWRealm
realm(realm_id
, realm_name
);
3342 bool new_realm
= false;
3343 int ret
= realm
.init(g_ceph_context
, store
);
3344 if (ret
< 0 && ret
!= -ENOENT
) {
3345 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3347 } else if (ret
== -ENOENT
) {
3350 ret
= read_decode_json(infile
, realm
);
3354 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3355 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3356 realm
.get_name() << std::endl
;
3361 cout
<< "clearing period and epoch for new realm" << std::endl
;
3362 realm
.clear_current_period_and_epoch();
3363 ret
= realm
.create();
3365 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3369 ret
= realm
.update();
3371 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3377 ret
= realm
.set_as_default();
3379 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3382 encode_json("realm", realm
, formatter
);
3383 formatter
->flush(cout
);
3387 case OPT_REALM_DEFAULT
:
3389 RGWRealm
realm(realm_id
, realm_name
);
3390 int ret
= realm
.init(g_ceph_context
, store
);
3392 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3395 ret
= realm
.set_as_default();
3397 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3402 case OPT_REALM_PULL
:
3405 cerr
<< "A --url must be provided." << std::endl
;
3409 req_info
info(g_ceph_context
, &env
);
3410 info
.method
= "GET";
3411 info
.request_uri
= "/admin/realm";
3413 map
<string
, string
> ¶ms
= info
.args
.get_params();
3414 if (!realm_id
.empty())
3415 params
["id"] = realm_id
;
3416 if (!realm_name
.empty())
3417 params
["name"] = realm_name
;
3421 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3423 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3424 if (ret
== -EACCES
) {
3425 cerr
<< "If the realm has been changed on the master zone, the "
3426 "master zone's gateway may need to be restarted to recognize "
3427 "this user." << std::endl
;
3432 realm
.init(g_ceph_context
, store
, false);
3434 decode_json_obj(realm
, &p
);
3435 } catch (JSONDecoder::err
& e
) {
3436 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3440 auto& current_period
= realm
.get_current_period();
3441 if (!current_period
.empty()) {
3442 // pull the latest epoch of the realm's current period
3443 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3444 realm_id
, realm_name
, current_period
, "",
3447 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3451 ret
= realm
.create(false);
3452 if (ret
< 0 && ret
!= -EEXIST
) {
3453 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3454 << cpp_strerror(ret
) << std::endl
;
3456 } else if (ret
==-EEXIST
) {
3457 ret
= realm
.update();
3459 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3460 << cpp_strerror(ret
) << std::endl
;
3465 ret
= realm
.set_as_default();
3467 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3471 encode_json("realm", realm
, formatter
);
3472 formatter
->flush(cout
);
3477 case OPT_ZONEGROUP_ADD
:
3479 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3480 cerr
<< "no zonegroup name or id provided" << std::endl
;
3484 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3485 int ret
= zonegroup
.init(g_ceph_context
, store
);
3487 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3488 << cpp_strerror(-ret
) << std::endl
;
3491 RGWZoneParams
zone(zone_id
, zone_name
);
3492 ret
= zone
.init(g_ceph_context
, store
);
3494 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3497 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3498 zone
.realm_id
= zonegroup
.realm_id
;
3499 ret
= zone
.update();
3501 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
3506 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3507 zone
.tier_config
= tier_config_add
;
3509 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3511 ret
= zonegroup
.add_zone(zone
,
3512 (is_master_set
? &is_master
: NULL
),
3513 (is_read_only_set
? &read_only
: NULL
),
3514 endpoints
, ptier_type
,
3515 psync_from_all
, sync_from
, sync_from_rm
);
3517 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3518 << cpp_strerror(-ret
) << std::endl
;
3522 encode_json("zonegroup", zonegroup
, formatter
);
3523 formatter
->flush(cout
);
3526 case OPT_ZONEGROUP_CREATE
:
3528 if (zonegroup_name
.empty()) {
3529 cerr
<< "Missing zonegroup name" << std::endl
;
3532 RGWRealm
realm(realm_id
, realm_name
);
3533 int ret
= realm
.init(g_ceph_context
, store
);
3535 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3539 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3540 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3541 ret
= zonegroup
.create();
3543 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3548 ret
= zonegroup
.set_as_default();
3550 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3554 encode_json("zonegroup", zonegroup
, formatter
);
3555 formatter
->flush(cout
);
3559 case OPT_ZONEGROUP_DEFAULT
:
3561 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3562 cerr
<< "no zonegroup name or id provided" << std::endl
;
3566 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3567 int ret
= zonegroup
.init(g_ceph_context
, store
);
3569 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3573 ret
= zonegroup
.set_as_default();
3575 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3580 case OPT_ZONEGROUP_DELETE
:
3582 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3583 cerr
<< "no zonegroup name or id provided" << std::endl
;
3586 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3587 int ret
= zonegroup
.init(g_ceph_context
, store
);
3589 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3592 ret
= zonegroup
.delete_obj();
3594 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3599 case OPT_ZONEGROUP_GET
:
3601 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3602 int ret
= zonegroup
.init(g_ceph_context
, store
);
3604 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3608 encode_json("zonegroup", zonegroup
, formatter
);
3609 formatter
->flush(cout
);
3613 case OPT_ZONEGROUP_LIST
:
3615 RGWZoneGroup zonegroup
;
3616 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3618 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3622 list
<string
> zonegroups
;
3623 ret
= store
->list_zonegroups(zonegroups
);
3625 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3628 string default_zonegroup
;
3629 ret
= zonegroup
.read_default_id(default_zonegroup
);
3630 if (ret
< 0 && ret
!= -ENOENT
) {
3631 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3633 formatter
->open_object_section("zonegroups_list");
3634 encode_json("default_info", default_zonegroup
, formatter
);
3635 encode_json("zonegroups", zonegroups
, formatter
);
3636 formatter
->close_section();
3637 formatter
->flush(cout
);
3641 case OPT_ZONEGROUP_MODIFY
:
3643 RGWRealm
realm(realm_id
, realm_name
);
3644 int ret
= realm
.init(g_ceph_context
, store
);
3646 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3650 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3651 ret
= zonegroup
.init(g_ceph_context
, store
);
3653 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3657 bool need_update
= false;
3659 if (!master_zone
.empty()) {
3660 zonegroup
.master_zone
= master_zone
;
3664 if (is_master_set
) {
3665 zonegroup
.update_master(is_master
);
3669 if (!endpoints
.empty()) {
3670 zonegroup
.endpoints
= endpoints
;
3674 if (!api_name
.empty()) {
3675 zonegroup
.api_name
= api_name
;
3679 if (!realm_id
.empty()) {
3680 zonegroup
.realm_id
= realm_id
;
3682 } else if (!realm_name
.empty()) {
3683 // get realm id from name
3684 RGWRealm realm
{g_ceph_context
, store
};
3685 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3687 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3694 ret
= zonegroup
.update();
3696 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3702 ret
= zonegroup
.set_as_default();
3704 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3708 encode_json("zonegroup", zonegroup
, formatter
);
3709 formatter
->flush(cout
);
3712 case OPT_ZONEGROUP_SET
:
3714 RGWRealm
realm(realm_id
, realm_name
);
3715 int ret
= realm
.init(g_ceph_context
, store
);
3717 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3721 RGWZoneGroup zonegroup
;
3722 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3724 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3727 ret
= read_decode_json(infile
, zonegroup
);
3731 if (zonegroup
.realm_id
.empty()) {
3732 zonegroup
.realm_id
= realm
.get_id();
3734 ret
= zonegroup
.create();
3735 if (ret
< 0 && ret
!= -EEXIST
) {
3736 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3738 } else if (ret
== -EEXIST
) {
3739 ret
= zonegroup
.update();
3741 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3747 ret
= zonegroup
.set_as_default();
3749 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3753 encode_json("zonegroup", zonegroup
, formatter
);
3754 formatter
->flush(cout
);
3757 case OPT_ZONEGROUP_REMOVE
:
3759 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3760 int ret
= zonegroup
.init(g_ceph_context
, store
);
3762 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3766 if (zone_id
.empty()) {
3767 if (zone_name
.empty()) {
3768 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
3771 // look up zone id by name
3772 for (auto& z
: zonegroup
.zones
) {
3773 if (zone_name
== z
.second
.name
) {
3774 zone_id
= z
.second
.id
;
3778 if (zone_id
.empty()) {
3779 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
3780 << zonegroup
.get_name() << std::endl
;
3785 ret
= zonegroup
.remove_zone(zone_id
);
3787 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
3791 encode_json("zonegroup", zonegroup
, formatter
);
3792 formatter
->flush(cout
);
3795 case OPT_ZONEGROUP_RENAME
:
3797 if (zonegroup_new_name
.empty()) {
3798 cerr
<< " missing zonegroup new name" << std::endl
;
3801 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3802 cerr
<< "no zonegroup name or id provided" << std::endl
;
3805 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3806 int ret
= zonegroup
.init(g_ceph_context
, store
);
3808 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3811 ret
= zonegroup
.rename(zonegroup_new_name
);
3813 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3818 case OPT_ZONEGROUP_PLACEMENT_LIST
:
3820 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3821 int ret
= zonegroup
.init(g_ceph_context
, store
);
3823 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3827 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3828 formatter
->flush(cout
);
3832 case OPT_ZONEGROUP_PLACEMENT_ADD
:
3833 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
3834 case OPT_ZONEGROUP_PLACEMENT_RM
:
3835 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
3837 if (placement_id
.empty()) {
3838 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
3842 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3843 int ret
= zonegroup
.init(g_ceph_context
, store
);
3845 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3849 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
3850 RGWZoneGroupPlacementTarget target
;
3851 target
.name
= placement_id
;
3852 for (auto& t
: tags
) {
3853 target
.tags
.insert(t
);
3855 zonegroup
.placement_targets
[placement_id
] = target
;
3856 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
3857 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
3858 if (!tags
.empty()) {
3859 target
.tags
.clear();
3860 for (auto& t
: tags
) {
3861 target
.tags
.insert(t
);
3864 target
.name
= placement_id
;
3865 for (auto& t
: tags_rm
) {
3866 target
.tags
.erase(t
);
3868 for (auto& t
: tags_add
) {
3869 target
.tags
.insert(t
);
3871 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
3872 zonegroup
.placement_targets
.erase(placement_id
);
3873 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
3874 if (!zonegroup
.placement_targets
.count(placement_id
)) {
3875 cerr
<< "failed to find a zonegroup placement target named '"
3876 << placement_id
<< "'" << std::endl
;
3879 zonegroup
.default_placement
= placement_id
;
3882 zonegroup
.post_process_params();
3883 ret
= zonegroup
.update();
3885 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3889 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
3890 formatter
->flush(cout
);
3893 case OPT_ZONE_CREATE
:
3895 if (zone_name
.empty()) {
3896 cerr
<< "zone name not provided" << std::endl
;
3900 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3901 /* if the user didn't provide zonegroup info , create stand alone zone */
3902 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3903 ret
= zonegroup
.init(g_ceph_context
, store
);
3905 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3908 if (realm_id
.empty() && realm_name
.empty()) {
3909 realm_id
= zonegroup
.realm_id
;
3913 RGWZoneParams
zone(zone_id
, zone_name
);
3914 ret
= zone
.init(g_ceph_context
, store
, false);
3916 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3920 zone
.system_key
.id
= access_key
;
3921 zone
.system_key
.key
= secret_key
;
3922 zone
.realm_id
= realm_id
;
3923 zone
.tier_config
= tier_config_add
;
3925 ret
= zone
.create();
3927 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3931 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
3932 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3933 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3934 ret
= zonegroup
.add_zone(zone
,
3935 (is_master_set
? &is_master
: NULL
),
3936 (is_read_only_set
? &read_only
: NULL
),
3940 sync_from
, sync_from_rm
);
3942 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
3943 << ": " << cpp_strerror(-ret
) << std::endl
;
3949 ret
= zone
.set_as_default();
3951 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3955 encode_json("zone", zone
, formatter
);
3956 formatter
->flush(cout
);
3960 case OPT_ZONE_DEFAULT
:
3962 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3963 int ret
= zonegroup
.init(g_ceph_context
, store
);
3965 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
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 ret
= zone
.init(g_ceph_context
, store
);
3974 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3977 ret
= zone
.set_as_default();
3979 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
3984 case OPT_ZONE_DELETE
:
3986 if (zone_id
.empty() && zone_name
.empty()) {
3987 cerr
<< "no zone name or id provided" << std::endl
;
3990 RGWZoneParams
zone(zone_id
, zone_name
);
3991 int ret
= zone
.init(g_ceph_context
, store
);
3993 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3997 list
<string
> zonegroups
;
3998 ret
= store
->list_zonegroups(zonegroups
);
4000 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
4004 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
4005 RGWZoneGroup
zonegroup(string(), *iter
);
4006 int ret
= zonegroup
.init(g_ceph_context
, store
);
4008 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4011 ret
= zonegroup
.remove_zone(zone
.get_id());
4012 if (ret
< 0 && ret
!= -ENOENT
) {
4013 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
4014 << cpp_strerror(-ret
) << std::endl
;
4018 ret
= zone
.delete_obj();
4020 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4027 RGWZoneParams
zone(zone_id
, zone_name
);
4028 int ret
= zone
.init(g_ceph_context
, store
);
4030 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4033 encode_json("zone", zone
, formatter
);
4034 formatter
->flush(cout
);
4039 RGWZoneParams
zone(zone_name
);
4040 int ret
= zone
.init(g_ceph_context
, store
, false);
4046 if (ret
< 0 && ret
!= -ENOENT
) {
4047 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
4051 string orig_id
= zone
.get_id();
4053 ret
= read_decode_json(infile
, zone
);
4058 if(zone
.realm_id
.empty()) {
4059 RGWRealm
realm(realm_id
, realm_name
);
4060 int ret
= realm
.init(g_ceph_context
, store
);
4061 if (ret
< 0 && ret
!= -ENOENT
) {
4062 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4065 zone
.realm_id
= realm
.get_id();
4068 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
4069 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
4073 if (zone
.get_name().empty()) {
4074 zone
.set_name(zone_name
);
4075 if (zone
.get_name().empty()) {
4076 cerr
<< "no zone name specified" << std::endl
;
4081 zone_name
= zone
.get_name();
4083 if (zone
.get_id().empty()) {
4084 zone
.set_id(orig_id
);
4087 if (zone
.get_id().empty()) {
4088 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
4089 if (zone_name
.empty()) {
4090 cerr
<< "missing zone name" << std::endl
;
4093 zone
.set_name(zone_name
);
4094 zone
.set_id(zone_name
);
4097 cerr
<< "zone id " << zone
.get_id();
4098 ret
= zone
.fix_pool_names();
4100 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4103 ret
= zone
.write(false);
4105 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4110 ret
= zone
.set_as_default();
4112 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4116 encode_json("zone", zone
, formatter
);
4117 formatter
->flush(cout
);
4123 int ret
= store
->list_zones(zones
);
4125 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4130 ret
= zone
.init(g_ceph_context
, store
, false);
4132 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4135 string default_zone
;
4136 ret
= zone
.read_default_id(default_zone
);
4137 if (ret
< 0 && ret
!= -ENOENT
) {
4138 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4140 formatter
->open_object_section("zones_list");
4141 encode_json("default_info", default_zone
, formatter
);
4142 encode_json("zones", zones
, formatter
);
4143 formatter
->close_section();
4144 formatter
->flush(cout
);
4148 case OPT_ZONE_MODIFY
:
4150 RGWZoneParams
zone(zone_id
, zone_name
);
4151 int ret
= zone
.init(g_ceph_context
, store
);
4153 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4157 bool need_zone_update
= false;
4158 if (!access_key
.empty()) {
4159 zone
.system_key
.id
= access_key
;
4160 need_zone_update
= true;
4163 if (!secret_key
.empty()) {
4164 zone
.system_key
.key
= secret_key
;
4165 need_zone_update
= true;
4168 if (!realm_id
.empty()) {
4169 zone
.realm_id
= realm_id
;
4170 need_zone_update
= true;
4171 } else if (!realm_name
.empty()) {
4172 // get realm id from name
4173 RGWRealm realm
{g_ceph_context
, store
};
4174 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4176 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4179 need_zone_update
= true;
4182 for (auto add
: tier_config_add
) {
4183 zone
.tier_config
[add
.first
] = add
.second
;
4184 need_zone_update
= true;
4187 for (auto rm
: tier_config_rm
) {
4188 zone
.tier_config
.erase(rm
.first
);
4189 need_zone_update
= true;
4192 if (need_zone_update
) {
4193 ret
= zone
.update();
4195 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4200 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4201 ret
= zonegroup
.init(g_ceph_context
, store
);
4203 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4206 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4208 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4210 ret
= zonegroup
.add_zone(zone
,
4211 (is_master_set
? &is_master
: NULL
),
4212 (is_read_only_set
? &read_only
: NULL
),
4213 endpoints
, ptier_type
,
4214 psync_from_all
, sync_from
, sync_from_rm
);
4216 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4220 ret
= zonegroup
.update();
4222 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4227 ret
= zone
.set_as_default();
4229 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4233 encode_json("zone", zone
, formatter
);
4234 formatter
->flush(cout
);
4237 case OPT_ZONE_RENAME
:
4239 if (zone_new_name
.empty()) {
4240 cerr
<< " missing zone new name" << std::endl
;
4243 if (zone_id
.empty() && zone_name
.empty()) {
4244 cerr
<< "no zonegroup name or id provided" << std::endl
;
4247 RGWZoneParams
zone(zone_id
,zone_name
);
4248 int ret
= zone
.init(g_ceph_context
, store
);
4250 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4253 ret
= zone
.rename(zone_new_name
);
4255 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4259 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4260 ret
= zonegroup
.init(g_ceph_context
, store
);
4262 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4264 ret
= zonegroup
.rename_zone(zone
);
4265 if (ret
< 0 && ret
) {
4266 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4272 case OPT_ZONE_PLACEMENT_ADD
:
4273 case OPT_ZONE_PLACEMENT_MODIFY
:
4274 case OPT_ZONE_PLACEMENT_RM
:
4276 if (placement_id
.empty()) {
4277 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4280 // validate compression type
4281 if (compression_type
&& *compression_type
!= "random"
4282 && !Compressor::get_comp_alg_type(*compression_type
)) {
4283 std::cerr
<< "Unrecognized compression type" << std::endl
;
4287 RGWZoneParams
zone(zone_id
, zone_name
);
4288 int ret
= zone
.init(g_ceph_context
, store
);
4290 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4294 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4295 // pool names are required
4296 if (!index_pool
|| index_pool
->empty() ||
4297 !data_pool
|| data_pool
->empty()) {
4298 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4302 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4304 info
.index_pool
= *index_pool
;
4305 info
.data_pool
= *data_pool
;
4306 if (data_extra_pool
) {
4307 info
.data_extra_pool
= *data_extra_pool
;
4309 if (index_type_specified
) {
4310 info
.index_type
= placement_index_type
;
4312 if (compression_type
) {
4313 info
.compression_type
= *compression_type
;
4315 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4316 auto p
= zone
.placement_pools
.find(placement_id
);
4317 if (p
== zone
.placement_pools
.end()) {
4318 cerr
<< "ERROR: zone placement target '" << placement_id
4319 << "' not found" << std::endl
;
4322 auto& info
= p
->second
;
4323 if (index_pool
&& !index_pool
->empty()) {
4324 info
.index_pool
= *index_pool
;
4326 if (data_pool
&& !data_pool
->empty()) {
4327 info
.data_pool
= *data_pool
;
4329 if (data_extra_pool
) {
4330 info
.data_extra_pool
= *data_extra_pool
;
4332 if (index_type_specified
) {
4333 info
.index_type
= placement_index_type
;
4335 if (compression_type
) {
4336 info
.compression_type
= *compression_type
;
4338 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4339 zone
.placement_pools
.erase(placement_id
);
4342 ret
= zone
.update();
4344 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4348 encode_json("zone", zone
, formatter
);
4349 formatter
->flush(cout
);
4352 case OPT_ZONE_PLACEMENT_LIST
:
4354 RGWZoneParams
zone(zone_id
, zone_name
);
4355 int ret
= zone
.init(g_ceph_context
, store
);
4357 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4360 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4361 formatter
->flush(cout
);
4368 if (!user_id
.empty()) {
4369 user_op
.set_user_id(user_id
);
4370 bucket_op
.set_user_id(user_id
);
4373 if (!display_name
.empty())
4374 user_op
.set_display_name(display_name
);
4376 if (!user_email
.empty())
4377 user_op
.set_user_email(user_email
);
4379 if (!access_key
.empty())
4380 user_op
.set_access_key(access_key
);
4382 if (!secret_key
.empty())
4383 user_op
.set_secret_key(secret_key
);
4385 if (!subuser
.empty())
4386 user_op
.set_subuser(subuser
);
4389 user_op
.set_caps(caps
);
4391 user_op
.set_purge_data(purge_data
);
4394 user_op
.set_purge_keys();
4397 user_op
.set_generate_key();
4400 user_op
.set_gen_secret(); // assume that a key pair should be created
4402 if (max_buckets_specified
)
4403 user_op
.set_max_buckets(max_buckets
);
4405 if (admin_specified
)
4406 user_op
.set_admin(admin
);
4408 if (system_specified
)
4409 user_op
.set_system(system
);
4412 user_op
.set_perm(perm_mask
);
4414 if (set_temp_url_key
) {
4415 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4416 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4417 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4421 if (!op_mask_str
.empty()) {
4423 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4425 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4429 user_op
.set_op_mask(op_mask
);
4432 if (key_type
!= KEY_TYPE_UNDEFINED
)
4433 user_op
.set_key_type(key_type
);
4435 // set suspension operation parameters
4436 if (opt_cmd
== OPT_USER_ENABLE
)
4437 user_op
.set_suspension(false);
4438 else if (opt_cmd
== OPT_USER_SUSPEND
)
4439 user_op
.set_suspension(true);
4441 // RGWUser to use for user operations
4444 if (!user_id
.empty() || !subuser
.empty()) {
4445 ret
= user
.init(store
, user_op
);
4447 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4452 /* populate bucket operation */
4453 bucket_op
.set_bucket_name(bucket_name
);
4454 bucket_op
.set_object(object
);
4455 bucket_op
.set_check_objects(check_objects
);
4456 bucket_op
.set_delete_children(delete_child_objects
);
4457 bucket_op
.set_fix_index(fix
);
4458 bucket_op
.set_max_aio(max_concurrent_ios
);
4460 // required to gather errors from operations
4461 std::string err_msg
;
4463 bool output_user_info
= true;
4468 case OPT_USER_CREATE
:
4469 if (!user_op
.has_existing_user()) {
4470 user_op
.set_generate_key(); // generate a new key by default
4472 ret
= user
.add(user_op
, &err_msg
);
4474 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4475 if (ret
== -ERR_INVALID_TENANT_NAME
)
4480 if (!subuser
.empty()) {
4481 ret
= user
.subusers
.add(user_op
, &err_msg
);
4483 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4489 ret
= user
.remove(user_op
, &err_msg
);
4491 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4495 output_user_info
= false;
4497 case OPT_USER_ENABLE
:
4498 case OPT_USER_SUSPEND
:
4499 case OPT_USER_MODIFY
:
4500 ret
= user
.modify(user_op
, &err_msg
);
4502 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4507 case OPT_SUBUSER_CREATE
:
4508 ret
= user
.subusers
.add(user_op
, &err_msg
);
4510 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4515 case OPT_SUBUSER_MODIFY
:
4516 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4518 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4523 case OPT_SUBUSER_RM
:
4524 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4526 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4532 ret
= user
.caps
.add(user_op
, &err_msg
);
4534 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4540 ret
= user
.caps
.remove(user_op
, &err_msg
);
4542 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4547 case OPT_KEY_CREATE
:
4548 ret
= user
.keys
.add(user_op
, &err_msg
);
4550 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4556 ret
= user
.keys
.remove(user_op
, &err_msg
);
4558 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4562 case OPT_PERIOD_PUSH
:
4565 req_info
info(g_ceph_context
, &env
);
4566 info
.method
= "POST";
4567 info
.request_uri
= "/admin/realm/period";
4569 map
<string
, string
> ¶ms
= info
.args
.get_params();
4570 if (!realm_id
.empty())
4571 params
["realm_id"] = realm_id
;
4572 if (!realm_name
.empty())
4573 params
["realm_name"] = realm_name
;
4574 if (!period_id
.empty())
4575 params
["period_id"] = period_id
;
4576 if (!period_epoch
.empty())
4577 params
["epoch"] = period_epoch
;
4580 RGWPeriod
period(period_id
);
4581 int ret
= period
.init(g_ceph_context
, store
);
4583 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4586 // json format into a bufferlist
4587 JSONFormatter
jf(false);
4588 encode_json("period", period
, &jf
);
4593 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4596 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4601 case OPT_PERIOD_UPDATE
:
4603 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4604 commit
, remote
, url
, access_key
, secret_key
,
4605 formatter
, yes_i_really_mean_it
);
4611 case OPT_PERIOD_COMMIT
:
4613 // read realm and staging period
4614 RGWRealm
realm(realm_id
, realm_name
);
4615 int ret
= realm
.init(g_ceph_context
, store
);
4617 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4620 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4621 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4623 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4626 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4627 yes_i_really_mean_it
);
4629 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4633 encode_json("period", period
, formatter
);
4634 formatter
->flush(cout
);
4638 case OPT_ROLE_CREATE
:
4640 if (role_name
.empty()) {
4641 cerr
<< "ERROR: role name is empty" << std::endl
;
4645 if (assume_role_doc
.empty()) {
4646 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4649 /* The following two calls will be replaced by read_decode_json or something
4650 similar when the code for AWS Policies is in places */
4652 int ret
= read_input(assume_role_doc
, bl
);
4654 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4658 if (!p
.parse(bl
.c_str(), bl
.length())) {
4659 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4662 string trust_policy
= bl
.to_str();
4663 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4664 ret
= role
.create(true);
4668 show_role_info(role
, formatter
);
4671 case OPT_ROLE_DELETE
:
4673 if (role_name
.empty()) {
4674 cerr
<< "ERROR: empty role name" << std::endl
;
4677 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4678 ret
= role
.delete_obj();
4682 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4687 if (role_name
.empty()) {
4688 cerr
<< "ERROR: empty role name" << std::endl
;
4691 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4696 show_role_info(role
, formatter
);
4699 case OPT_ROLE_MODIFY
:
4701 if (role_name
.empty()) {
4702 cerr
<< "ERROR: role name is empty" << std::endl
;
4706 if (assume_role_doc
.empty()) {
4707 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4711 /* The following two calls will be replaced by read_decode_json or something
4712 similar when the code for AWS Policies is in place */
4714 int ret
= read_input(assume_role_doc
, bl
);
4716 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4720 if (!p
.parse(bl
.c_str(), bl
.length())) {
4721 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4724 string trust_policy
= bl
.to_str();
4725 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4730 role
.update_trust_policy(trust_policy
);
4731 ret
= role
.update();
4735 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4740 vector
<RGWRole
> result
;
4741 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4745 show_roles_info(result
, formatter
);
4748 case OPT_ROLE_POLICY_PUT
:
4750 if (role_name
.empty()) {
4751 cerr
<< "role name is empty" << std::endl
;
4755 if (policy_name
.empty()) {
4756 cerr
<< "policy name is empty" << std::endl
;
4760 if (perm_policy_doc
.empty()) {
4761 cerr
<< "permission policy document is empty" << std::endl
;
4765 /* The following two calls will be replaced by read_decode_json or something
4766 similar, when code for AWS Policies is in place.*/
4768 int ret
= read_input(perm_policy_doc
, bl
);
4770 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4774 if (!p
.parse(bl
.c_str(), bl
.length())) {
4775 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
4779 perm_policy
= bl
.c_str();
4781 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4786 role
.set_perm_policy(policy_name
, perm_policy
);
4787 ret
= role
.update();
4791 cout
<< "Permission policy attached successfully" << std::endl
;
4794 case OPT_ROLE_POLICY_LIST
:
4796 if (role_name
.empty()) {
4797 cerr
<< "ERROR: Role name is empty" << std::endl
;
4800 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4805 std::vector
<string
> policy_names
= role
.get_role_policy_names();
4806 show_policy_names(policy_names
, formatter
);
4809 case OPT_ROLE_POLICY_GET
:
4811 if (role_name
.empty()) {
4812 cerr
<< "ERROR: role name is empty" << std::endl
;
4816 if (policy_name
.empty()) {
4817 cerr
<< "ERROR: policy name is empty" << std::endl
;
4820 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4821 int ret
= role
.get();
4826 ret
= role
.get_role_policy(policy_name
, perm_policy
);
4830 show_perm_policy(perm_policy
, formatter
);
4833 case OPT_ROLE_POLICY_DELETE
:
4835 if (role_name
.empty()) {
4836 cerr
<< "ERROR: role name is empty" << std::endl
;
4840 if (policy_name
.empty()) {
4841 cerr
<< "ERROR: policy name is empty" << std::endl
;
4844 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4849 ret
= role
.delete_policy(policy_name
);
4853 ret
= role
.update();
4857 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
4858 << role_name
<< std::endl
;
4862 output_user_info
= false;
4865 // output the result of a user operation
4866 if (output_user_info
) {
4867 ret
= user
.info(info
, &err_msg
);
4869 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
4872 show_user_info(info
, formatter
);
4875 if (opt_cmd
== OPT_POLICY
) {
4876 if (format
== "xml") {
4877 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
4879 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4883 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
4885 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
4891 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
4893 std::list
<std::string
> user_ids
;
4894 metadata_key
= "user";
4899 if (! user_id
.empty()) {
4900 user_ids
.push_back(user_id
.id
);
4902 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4905 /* list users in groups of max-keys, then perform user-bucket
4906 * limit-check on each group */
4907 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
4909 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
4910 << cpp_strerror(-ret
) << std::endl
;
4915 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
4917 if (ret
< 0 && ret
!= -ENOENT
) {
4918 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
4919 << cpp_strerror(-ret
) << std::endl
;
4922 /* ok, do the limit checks for this group */
4924 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
4930 } while (truncated
);
4931 store
->meta_mgr
->list_keys_complete(handle
);
4934 } /* OPT_BUCKET_LIMIT_CHECK */
4936 if (opt_cmd
== OPT_BUCKETS_LIST
) {
4937 if (bucket_name
.empty()) {
4938 RGWBucketAdminOp::info(store
, bucket_op
, f
);
4940 RGWBucketInfo bucket_info
;
4941 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
4943 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
4946 formatter
->open_array_section("entries");
4949 if (max_entries
< 0)
4954 vector
<rgw_bucket_dir_entry
> result
;
4955 map
<string
, bool> common_prefixes
;
4958 RGWRados::Bucket
target(store
, bucket_info
);
4959 RGWRados::Bucket::List
list_op(&target
);
4961 list_op
.params
.prefix
= prefix
;
4962 list_op
.params
.delim
= delim
;
4963 list_op
.params
.marker
= rgw_obj_key(marker
);
4964 list_op
.params
.ns
= ns
;
4965 list_op
.params
.enforce_ns
= false;
4966 list_op
.params
.list_versions
= true;
4969 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
4971 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
4975 count
+= result
.size();
4977 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
4978 rgw_bucket_dir_entry
& entry
= *iter
;
4979 encode_json("entry", entry
, formatter
);
4981 formatter
->flush(cout
);
4982 } while (truncated
&& count
< max_entries
);
4984 formatter
->close_section();
4985 formatter
->flush(cout
);
4986 } /* have bucket_name */
4987 } /* OPT_BUCKETS_LIST */
4989 if (opt_cmd
== OPT_BUCKET_STATS
) {
4990 bucket_op
.set_fetch_stats(true);
4992 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
4994 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
4999 if (opt_cmd
== OPT_BUCKET_LINK
) {
5000 bucket_op
.set_bucket_id(bucket_id
);
5002 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
5004 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
5009 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
5010 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
5012 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
5017 if (opt_cmd
== OPT_LOG_LIST
) {
5019 if (date
.size() && date
.size() != 10) {
5020 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
5025 formatter
->open_array_section("logs");
5027 int r
= store
->log_list_init(date
, &h
);
5032 cerr
<< "log list: error " << r
<< std::endl
;
5037 int r
= store
->log_list_next(h
, &name
);
5041 cerr
<< "log list: error " << r
<< std::endl
;
5044 formatter
->dump_string("object", name
);
5047 formatter
->close_section();
5048 formatter
->flush(cout
);
5052 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5053 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5054 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5060 if (!object
.empty()) {
5070 if (opt_cmd
== OPT_LOG_SHOW
) {
5073 int r
= store
->log_show_init(oid
, &h
);
5075 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5080 formatter
->open_object_section("log");
5082 struct rgw_log_entry entry
;
5084 // peek at first entry to get bucket metadata
5085 r
= store
->log_show_next(h
, &entry
);
5087 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5090 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5091 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5092 formatter
->dump_string("bucket", entry
.bucket
);
5094 uint64_t agg_time
= 0;
5095 uint64_t agg_bytes_sent
= 0;
5096 uint64_t agg_bytes_received
= 0;
5097 uint64_t total_entries
= 0;
5099 if (show_log_entries
)
5100 formatter
->open_array_section("log_entries");
5103 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5105 agg_time
+= total_time
;
5106 agg_bytes_sent
+= entry
.bytes_sent
;
5107 agg_bytes_received
+= entry
.bytes_received
;
5110 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5111 entry
.bytes_received
== 0)
5114 if (show_log_entries
) {
5116 rgw_format_ops_log_entry(entry
, formatter
);
5117 formatter
->flush(cout
);
5120 r
= store
->log_show_next(h
, &entry
);
5124 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5127 if (show_log_entries
)
5128 formatter
->close_section();
5131 formatter
->open_object_section("log_sum");
5132 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5133 formatter
->dump_int("bytes_received", agg_bytes_received
);
5134 formatter
->dump_int("total_time", agg_time
);
5135 formatter
->dump_int("total_entries", total_entries
);
5136 formatter
->close_section();
5138 formatter
->close_section();
5139 formatter
->flush(cout
);
5142 if (opt_cmd
== OPT_LOG_RM
) {
5143 int r
= store
->log_remove(oid
);
5145 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5151 if (opt_cmd
== OPT_POOL_ADD
) {
5152 if (pool_name
.empty()) {
5153 cerr
<< "need to specify pool to add!" << std::endl
;
5158 int ret
= store
->add_bucket_placement(pool
);
5160 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5163 if (opt_cmd
== OPT_POOL_RM
) {
5164 if (pool_name
.empty()) {
5165 cerr
<< "need to specify pool to remove!" << std::endl
;
5170 int ret
= store
->remove_bucket_placement(pool
);
5172 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5175 if (opt_cmd
== OPT_POOLS_LIST
) {
5176 set
<rgw_pool
> pools
;
5177 int ret
= store
->list_placement_set(pools
);
5179 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5183 formatter
->open_array_section("pools");
5184 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5185 formatter
->open_object_section("pool");
5186 formatter
->dump_string("name", siter
->to_str());
5187 formatter
->close_section();
5189 formatter
->close_section();
5190 formatter
->flush(cout
);
5194 if (opt_cmd
== OPT_USAGE_SHOW
) {
5195 uint64_t start_epoch
= 0;
5196 uint64_t end_epoch
= (uint64_t)-1;
5200 if (!start_date
.empty()) {
5201 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5203 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5207 if (!end_date
.empty()) {
5208 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5210 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5216 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5217 show_log_entries
, show_log_sum
, &categories
,
5220 cerr
<< "ERROR: failed to show usage" << std::endl
;
5225 if (opt_cmd
== OPT_USAGE_TRIM
) {
5226 if (user_id
.empty() && !yes_i_really_mean_it
) {
5227 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5228 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5232 uint64_t start_epoch
= 0;
5233 uint64_t end_epoch
= (uint64_t)-1;
5236 if (!start_date
.empty()) {
5237 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5239 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5244 if (!end_date
.empty()) {
5245 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5247 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5252 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5254 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5259 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5260 if (bucket_name
.empty()) {
5261 cerr
<< "ERROR: bucket not specified" << std::endl
;
5264 if (object
.empty()) {
5265 cerr
<< "ERROR: object not specified" << std::endl
;
5270 if (opt_cmd
== OPT_OLH_GET
) {
5271 RGWBucketInfo bucket_info
;
5272 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5274 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5278 rgw_obj
obj(bucket
, object
);
5279 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5281 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5284 encode_json("olh", olh
, formatter
);
5285 formatter
->flush(cout
);
5288 if (opt_cmd
== OPT_OLH_READLOG
) {
5289 RGWBucketInfo bucket_info
;
5290 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5292 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5295 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5298 RGWObjectCtx
rctx(store
);
5299 rgw_obj
obj(bucket
, object
);
5303 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5308 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5310 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5313 formatter
->open_object_section("result");
5314 encode_json("is_truncated", is_truncated
, formatter
);
5315 encode_json("log", log
, formatter
);
5316 formatter
->close_section();
5317 formatter
->flush(cout
);
5320 if (opt_cmd
== OPT_BI_GET
) {
5321 RGWBucketInfo bucket_info
;
5322 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5324 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5327 rgw_obj
obj(bucket
, object
);
5328 if (!object_version
.empty()) {
5329 obj
.key
.set_instance(object_version
);
5332 rgw_cls_bi_entry entry
;
5334 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5336 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5340 encode_json("entry", entry
, formatter
);
5341 formatter
->flush(cout
);
5344 if (opt_cmd
== OPT_BI_PUT
) {
5345 RGWBucketInfo bucket_info
;
5346 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5348 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5352 rgw_cls_bi_entry entry
;
5353 cls_rgw_obj_key key
;
5354 ret
= read_decode_json(infile
, entry
, &key
);
5359 rgw_obj
obj(bucket
, key
);
5361 ret
= store
->bi_put(bucket
, obj
, entry
);
5363 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5368 if (opt_cmd
== OPT_BI_LIST
) {
5369 if (bucket_name
.empty()) {
5370 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5373 RGWBucketInfo bucket_info
;
5374 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5376 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5380 list
<rgw_cls_bi_entry
> entries
;
5382 if (max_entries
< 0) {
5386 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5388 formatter
->open_array_section("entries");
5390 for (int i
= 0; i
< max_shards
; i
++) {
5391 RGWRados::BucketShard
bs(store
);
5392 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5393 int ret
= bs
.init(bucket
, shard_id
);
5397 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5403 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5405 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5409 list
<rgw_cls_bi_entry
>::iterator iter
;
5410 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5411 rgw_cls_bi_entry
& entry
= *iter
;
5412 encode_json("entry", entry
, formatter
);
5415 formatter
->flush(cout
);
5416 } while (is_truncated
);
5417 formatter
->flush(cout
);
5419 formatter
->close_section();
5420 formatter
->flush(cout
);
5423 if (opt_cmd
== OPT_BI_PURGE
) {
5424 if (bucket_name
.empty()) {
5425 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5428 RGWBucketInfo bucket_info
;
5429 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5431 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5435 RGWBucketInfo cur_bucket_info
;
5436 rgw_bucket cur_bucket
;
5437 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5439 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5443 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5444 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5445 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5449 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5451 for (int i
= 0; i
< max_shards
; i
++) {
5452 RGWRados::BucketShard
bs(store
);
5453 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5454 int ret
= bs
.init(bucket
, shard_id
);
5456 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5460 ret
= store
->bi_remove(bs
);
5462 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5468 if (opt_cmd
== OPT_OBJECT_RM
) {
5469 RGWBucketInfo bucket_info
;
5470 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5472 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5475 rgw_obj_key
key(object
, object_version
);
5476 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5479 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5484 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5485 if (bucket_name
.empty()) {
5486 cerr
<< "ERROR: bucket not specified" << std::endl
;
5489 if (object
.empty()) {
5490 cerr
<< "ERROR: object not specified" << std::endl
;
5494 RGWBucketInfo bucket_info
;
5495 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5497 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5501 rgw_obj
obj(bucket
, object
);
5502 obj
.key
.set_instance(object_version
);
5503 bool need_rewrite
= true;
5504 if (min_rewrite_stripe_size
> 0) {
5505 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5507 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5511 ret
= store
->rewrite_obj(bucket_info
, obj
);
5513 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5517 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5521 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5522 int ret
= store
->process_expire_objects();
5524 cerr
<< "ERROR: process_expire_objects() processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5529 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5530 if (bucket_name
.empty()) {
5531 cerr
<< "ERROR: bucket not specified" << std::endl
;
5535 RGWBucketInfo bucket_info
;
5536 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5538 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5542 uint64_t start_epoch
= 0;
5543 uint64_t end_epoch
= 0;
5545 if (!end_date
.empty()) {
5546 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5548 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5552 if (!start_date
.empty()) {
5553 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5555 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5560 bool is_truncated
= true;
5562 rgw_obj_index_key marker
;
5565 formatter
->open_object_section("result");
5566 formatter
->dump_string("bucket", bucket_name
);
5567 formatter
->open_array_section("objects");
5568 while (is_truncated
) {
5569 map
<string
, rgw_bucket_dir_entry
> result
;
5570 int r
= store
->cls_bucket_list(bucket_info
, RGW_NO_SHARD
, marker
, prefix
, 1000, true,
5571 result
, &is_truncated
, &marker
,
5572 bucket_object_check_filter
);
5574 if (r
< 0 && r
!= -ENOENT
) {
5575 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5581 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5582 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5583 rgw_obj_key key
= iter
->second
.key
;
5584 rgw_bucket_dir_entry
& entry
= iter
->second
;
5586 formatter
->open_object_section("object");
5587 formatter
->dump_string("name", key
.name
);
5588 formatter
->dump_string("instance", key
.instance
);
5589 formatter
->dump_int("size", entry
.meta
.size
);
5590 utime_t
ut(entry
.meta
.mtime
);
5591 ut
.gmtime(formatter
->dump_stream("mtime"));
5593 if ((entry
.meta
.size
< min_rewrite_size
) ||
5594 (entry
.meta
.size
> max_rewrite_size
) ||
5595 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5596 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5597 formatter
->dump_string("status", "Skipped");
5599 rgw_obj
obj(bucket
, key
);
5601 bool need_rewrite
= true;
5602 if (min_rewrite_stripe_size
> 0) {
5603 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5605 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5608 if (!need_rewrite
) {
5609 formatter
->dump_string("status", "Skipped");
5611 r
= store
->rewrite_obj(bucket_info
, obj
);
5613 formatter
->dump_string("status", "Success");
5615 formatter
->dump_string("status", cpp_strerror(-r
));
5619 formatter
->dump_int("flags", entry
.flags
);
5621 formatter
->close_section();
5622 formatter
->flush(cout
);
5625 formatter
->close_section();
5626 formatter
->close_section();
5627 formatter
->flush(cout
);
5630 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5632 RGWBucketInfo bucket_info
;
5633 map
<string
, bufferlist
> attrs
;
5635 int ret
= check_reshard_bucket_params(store
,
5639 num_shards_specified
,
5641 yes_i_really_mean_it
,
5649 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5651 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5652 if (max_entries
< 1) {
5653 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5656 return br
.execute(num_shards
, max_entries
,
5657 verbose
, &cout
, formatter
);
5660 if (opt_cmd
== OPT_RESHARD_ADD
) {
5662 RGWBucketInfo bucket_info
;
5663 map
<string
, bufferlist
> attrs
;
5665 int ret
= check_reshard_bucket_params(store
,
5669 num_shards_specified
,
5671 yes_i_really_mean_it
,
5679 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5681 RGWReshard
reshard(store
);
5682 cls_rgw_reshard_entry entry
;
5683 entry
.time
= real_clock::now();
5684 entry
.tenant
= tenant
;
5685 entry
.bucket_name
= bucket_name
;
5686 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5687 entry
.old_num_shards
= num_source_shards
;
5688 entry
.new_num_shards
= num_shards
;
5690 return reshard
.add(entry
);
5693 if (opt_cmd
== OPT_RESHARD_LIST
) {
5694 list
<cls_rgw_reshard_entry
> entries
;
5697 if (max_entries
< 0) {
5701 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5703 RGWReshard
reshard(store
);
5705 formatter
->open_array_section("reshard");
5706 for (int i
= 0; i
< num_logshards
; i
++) {
5707 bool is_truncated
= true;
5711 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5713 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5716 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5717 cls_rgw_reshard_entry
& entry
= *iter
;
5718 encode_json("entry", entry
, formatter
);
5719 entry
.get_key(&marker
);
5721 count
+= entries
.size();
5722 formatter
->flush(cout
);
5723 } while (is_truncated
&& count
< max_entries
);
5725 if (count
>= max_entries
) {
5730 formatter
->close_section();
5731 formatter
->flush(cout
);
5736 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5737 if (bucket_name
.empty()) {
5738 cerr
<< "ERROR: bucket not specified" << std::endl
;
5743 RGWBucketInfo bucket_info
;
5744 map
<string
, bufferlist
> attrs
;
5745 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5747 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5751 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5752 list
<cls_rgw_bucket_instance_entry
> status
;
5753 int r
= br
.get_status(&status
);
5755 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5759 encode_json("status", status
, formatter
);
5760 formatter
->flush(cout
);
5763 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5764 RGWReshard
reshard(store
, true, &cout
);
5766 int ret
= reshard
.process_all_logshards();
5768 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
5773 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
5774 if (bucket_name
.empty()) {
5775 cerr
<< "ERROR: bucket not specified" << std::endl
;
5780 RGWBucketInfo bucket_info
;
5781 map
<string
, bufferlist
> attrs
;
5782 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5784 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5788 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5789 int ret
= br
.cancel();
5791 if (ret
== -EBUSY
) {
5792 cerr
<< "There is ongoing resharding, please retry after " << g_conf
->rgw_reshard_bucket_lock_duration
<<
5793 " seconds " << std::endl
;
5795 cerr
<< "Error canceling bucket " << bucket_name
<< " resharding: " << cpp_strerror(-ret
) <<
5800 RGWReshard
reshard(store
);
5802 cls_rgw_reshard_entry entry
;
5803 //entry.tenant = tenant;
5804 entry
.bucket_name
= bucket_name
;
5805 //entry.bucket_id = bucket_id;
5807 ret
= reshard
.remove(entry
);
5808 if (ret
< 0 && ret
!= -ENOENT
) {
5809 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5814 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
5815 RGWBucketInfo bucket_info
;
5816 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5818 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5821 list
<rgw_obj_index_key
> oid_list
;
5822 rgw_obj_key
key(object
, object_version
);
5823 rgw_obj_index_key index_key
;
5824 key
.get_index_key(&index_key
);
5825 oid_list
.push_back(index_key
);
5826 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
5828 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
5833 if (opt_cmd
== OPT_OBJECT_STAT
) {
5834 RGWBucketInfo bucket_info
;
5835 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5837 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5840 rgw_obj
obj(bucket
, object
);
5841 obj
.key
.set_instance(object_version
);
5844 map
<string
, bufferlist
> attrs
;
5845 RGWObjectCtx
obj_ctx(store
);
5846 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
5847 RGWRados::Object::Read
read_op(&op_target
);
5849 read_op
.params
.attrs
= &attrs
;
5850 read_op
.params
.obj_size
= &obj_size
;
5852 ret
= read_op
.prepare();
5854 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
5857 formatter
->open_object_section("object_metadata");
5858 formatter
->dump_string("name", object
);
5859 formatter
->dump_unsigned("size", obj_size
);
5861 map
<string
, bufferlist
>::iterator iter
;
5862 map
<string
, bufferlist
> other_attrs
;
5863 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5864 bufferlist
& bl
= iter
->second
;
5865 bool handled
= false;
5866 if (iter
->first
== RGW_ATTR_MANIFEST
) {
5867 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
5868 } else if (iter
->first
== RGW_ATTR_ACL
) {
5869 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
5870 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
5871 handled
= dump_string("tag", bl
, formatter
);
5872 } else if (iter
->first
== RGW_ATTR_ETAG
) {
5873 handled
= dump_string("etag", bl
, formatter
);
5877 other_attrs
[iter
->first
] = bl
;
5880 formatter
->open_object_section("attrs");
5881 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
5882 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
5884 formatter
->close_section();
5885 formatter
->close_section();
5886 formatter
->flush(cout
);
5889 if (opt_cmd
== OPT_BUCKET_CHECK
) {
5890 if (check_head_obj_locator
) {
5891 if (bucket_name
.empty()) {
5892 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
5895 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
5897 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
5901 if (opt_cmd
== OPT_BUCKET_RM
) {
5902 if (inconsistent_index
== false) {
5903 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
5905 if (!yes_i_really_mean_it
) {
5906 cerr
<< "using --inconsistent_index can corrupt the bucket index " << std::endl
5907 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5910 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
5914 if (opt_cmd
== OPT_GC_LIST
) {
5917 formatter
->open_array_section("entries");
5920 list
<cls_rgw_gc_obj_info
> result
;
5921 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
5923 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5928 list
<cls_rgw_gc_obj_info
>::iterator iter
;
5929 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5930 cls_rgw_gc_obj_info
& info
= *iter
;
5931 formatter
->open_object_section("chain_info");
5932 formatter
->dump_string("tag", info
.tag
);
5933 formatter
->dump_stream("time") << info
.time
;
5934 formatter
->open_array_section("objs");
5935 list
<cls_rgw_obj
>::iterator liter
;
5936 cls_rgw_obj_chain
& chain
= info
.chain
;
5937 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
5938 cls_rgw_obj
& obj
= *liter
;
5939 encode_json("obj", obj
, formatter
);
5941 formatter
->close_section(); // objs
5942 formatter
->close_section(); // obj_chain
5943 formatter
->flush(cout
);
5945 } while (truncated
);
5946 formatter
->close_section();
5947 formatter
->flush(cout
);
5950 if (opt_cmd
== OPT_GC_PROCESS
) {
5951 int ret
= store
->process_gc();
5953 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5958 if (opt_cmd
== OPT_LC_LIST
) {
5959 formatter
->open_array_section("lifecycle_list");
5960 map
<string
, int> bucket_lc_map
;
5962 #define MAX_LC_LIST_ENTRIES 100
5963 if (max_entries
< 0) {
5964 max_entries
= MAX_LC_LIST_ENTRIES
;
5967 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
5969 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
5972 map
<string
, int>::iterator iter
;
5973 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
5974 formatter
->open_object_section("bucket_lc_info");
5975 formatter
->dump_string("bucket", iter
->first
);
5976 string lc_status
= LC_STATUS
[iter
->second
];
5977 formatter
->dump_string("status", lc_status
);
5978 formatter
->close_section(); // objs
5979 formatter
->flush(cout
);
5980 marker
= iter
->first
;
5982 } while (!bucket_lc_map
.empty());
5984 formatter
->close_section(); //lifecycle list
5985 formatter
->flush(cout
);
5989 if (opt_cmd
== OPT_LC_PROCESS
) {
5990 int ret
= store
->process_lc();
5992 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
5997 if (opt_cmd
== OPT_ORPHANS_FIND
) {
5998 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6000 if (job_id
.empty()) {
6001 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6004 if (pool_name
.empty()) {
6005 cerr
<< "ERROR: --pool not specified" << std::endl
;
6009 RGWOrphanSearchInfo info
;
6012 info
.job_name
= job_id
;
6013 info
.num_shards
= num_shards
;
6015 int ret
= search
.init(job_id
, &info
);
6017 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
6026 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
6027 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6029 if (job_id
.empty()) {
6030 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6033 int ret
= search
.init(job_id
, NULL
);
6035 if (ret
== -ENOENT
) {
6036 cerr
<< "job not found" << std::endl
;
6040 ret
= search
.finish();
6046 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
6047 RGWOrphanStore
orphan_store(store
);
6048 int ret
= orphan_store
.init();
6050 cerr
<< "connection to cluster failed!" << std::endl
;
6054 map
<string
,RGWOrphanSearchState
> m
;
6055 ret
= orphan_store
.list_jobs(m
);
6057 cerr
<< "job list failed" << std::endl
;
6060 formatter
->open_array_section("entries");
6061 for (const auto &it
: m
){
6063 formatter
->dump_string("job-id",it
.first
);
6065 encode_json("orphan_search_state", it
.second
, formatter
);
6068 formatter
->close_section();
6069 formatter
->flush(cout
);
6072 if (opt_cmd
== OPT_USER_CHECK
) {
6073 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6076 if (opt_cmd
== OPT_USER_STATS
) {
6077 if (user_id
.empty()) {
6078 cerr
<< "ERROR: uid not specified" << std::endl
;
6082 string user_str
= user_id
.to_str();
6084 if (!bucket_name
.empty()){
6085 cerr
<< "ERROR: recalculate doesn't work on buckets" << std::endl
;
6088 ret
= store
->cls_user_reset_stats(user_str
);
6090 cerr
<< "ERROR: could not clear user stats: " << cpp_strerror(-ret
) << std::endl
;
6096 if (!bucket_name
.empty()) {
6097 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6099 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
6103 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6105 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
6111 cls_user_header header
;
6112 int ret
= store
->cls_user_get_header(user_str
, &header
);
6114 if (ret
== -ENOENT
) { /* in case of ENOENT */
6115 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6117 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6122 encode_json("header", header
, formatter
);
6123 formatter
->flush(cout
);
6126 if (opt_cmd
== OPT_METADATA_GET
) {
6127 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6129 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6133 formatter
->flush(cout
);
6136 if (opt_cmd
== OPT_METADATA_PUT
) {
6138 int ret
= read_input(infile
, bl
);
6140 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6143 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6145 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6150 if (opt_cmd
== OPT_METADATA_RM
) {
6151 int ret
= store
->meta_mgr
->remove(metadata_key
);
6153 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6158 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6159 if (opt_cmd
== OPT_USER_LIST
) {
6160 metadata_key
= "user";
6164 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, marker
, &handle
);
6166 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6173 if (max_entries_specified
) {
6174 formatter
->open_object_section("result");
6176 formatter
->open_array_section("keys");
6181 left
= (max_entries_specified
? max_entries
- count
: max
);
6182 ret
= store
->meta_mgr
->list_keys_next(handle
, left
, keys
, &truncated
);
6183 if (ret
< 0 && ret
!= -ENOENT
) {
6184 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6186 } if (ret
!= -ENOENT
) {
6187 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6188 formatter
->dump_string("key", *iter
);
6191 formatter
->flush(cout
);
6193 } while (truncated
&& left
> 0);
6195 formatter
->close_section();
6197 if (max_entries_specified
) {
6198 encode_json("truncated", truncated
, formatter
);
6199 encode_json("count", count
, formatter
);
6201 encode_json("marker", store
->meta_mgr
->get_marker(handle
), formatter
);
6203 formatter
->close_section();
6205 formatter
->flush(cout
);
6207 store
->meta_mgr
->list_keys_complete(handle
);
6210 if (opt_cmd
== OPT_MDLOG_LIST
) {
6211 utime_t start_time
, end_time
;
6213 int ret
= parse_date_str(start_date
, start_time
);
6217 ret
= parse_date_str(end_date
, end_time
);
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");
6234 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6236 list
<cls_log_entry
> entries
;
6239 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6242 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6244 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6248 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6249 cls_log_entry
& entry
= *iter
;
6250 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6252 formatter
->flush(cout
);
6253 } while (truncated
);
6255 meta_log
->complete_list_entries(handle
);
6257 if (specified_shard_id
)
6262 formatter
->close_section();
6263 formatter
->flush(cout
);
6266 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6267 int i
= (specified_shard_id
? shard_id
: 0);
6269 if (period_id
.empty()) {
6270 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6274 std::cerr
<< "No --period given, using current period="
6275 << period_id
<< std::endl
;
6277 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6279 formatter
->open_array_section("entries");
6281 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6282 RGWMetadataLogInfo info
;
6283 meta_log
->get_info(i
, &info
);
6285 ::encode_json("info", info
, formatter
);
6287 if (specified_shard_id
)
6292 formatter
->close_section();
6293 formatter
->flush(cout
);
6296 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6297 // need a full history for purging old mdlog periods
6298 store
->meta_mgr
->init_oldest_log_period();
6300 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6301 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6302 int ret
= http
.set_threaded();
6304 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6308 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6309 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6311 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6316 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6317 utime_t start_time
, end_time
;
6319 if (!specified_shard_id
) {
6320 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6324 int ret
= parse_date_str(start_date
, start_time
);
6328 ret
= parse_date_str(end_date
, end_time
);
6332 if (period_id
.empty()) {
6333 std::cerr
<< "missing --period argument" << std::endl
;
6336 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6338 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6340 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6345 if (opt_cmd
== OPT_SYNC_STATUS
) {
6346 sync_status(formatter
);
6349 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6350 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6352 int ret
= sync
.init();
6354 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6358 rgw_meta_sync_status sync_status
;
6359 ret
= sync
.read_sync_status(&sync_status
);
6361 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6365 formatter
->open_object_section("summary");
6366 encode_json("sync_status", sync_status
, formatter
);
6368 uint64_t full_total
= 0;
6369 uint64_t full_complete
= 0;
6371 for (auto marker_iter
: sync_status
.sync_markers
) {
6372 full_total
+= marker_iter
.second
.total_entries
;
6373 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6374 full_complete
+= marker_iter
.second
.pos
;
6376 full_complete
+= marker_iter
.second
.total_entries
;
6380 formatter
->open_object_section("full_sync");
6381 encode_json("total", full_total
, formatter
);
6382 encode_json("complete", full_complete
, formatter
);
6383 formatter
->close_section();
6384 formatter
->close_section();
6386 formatter
->flush(cout
);
6390 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6391 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6393 int ret
= sync
.init();
6395 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6398 ret
= sync
.init_sync_status();
6400 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6406 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6407 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6409 int ret
= sync
.init();
6411 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6417 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6422 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6423 if (source_zone
.empty()) {
6424 cerr
<< "ERROR: source zone not specified" << std::endl
;
6427 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6429 int ret
= sync
.init();
6431 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6435 rgw_data_sync_status sync_status
;
6436 ret
= sync
.read_sync_status(&sync_status
);
6437 if (ret
< 0 && ret
!= -ENOENT
) {
6438 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6442 formatter
->open_object_section("summary");
6443 encode_json("sync_status", sync_status
, formatter
);
6445 uint64_t full_total
= 0;
6446 uint64_t full_complete
= 0;
6448 for (auto marker_iter
: sync_status
.sync_markers
) {
6449 full_total
+= marker_iter
.second
.total_entries
;
6450 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6451 full_complete
+= marker_iter
.second
.pos
;
6453 full_complete
+= marker_iter
.second
.total_entries
;
6457 formatter
->open_object_section("full_sync");
6458 encode_json("total", full_total
, formatter
);
6459 encode_json("complete", full_complete
, formatter
);
6460 formatter
->close_section();
6461 formatter
->close_section();
6463 formatter
->flush(cout
);
6466 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6467 if (source_zone
.empty()) {
6468 cerr
<< "ERROR: source zone not specified" << std::endl
;
6472 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6474 int ret
= sync
.init();
6476 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6480 ret
= sync
.init_sync_status();
6482 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6487 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6488 if (source_zone
.empty()) {
6489 cerr
<< "ERROR: source zone not specified" << std::endl
;
6493 RGWSyncModuleInstanceRef sync_module
;
6494 int ret
= store
->get_sync_modules_manager()->create_instance(g_ceph_context
, store
->get_zone().tier_type
,
6495 store
->get_zone_params().tier_config
, &sync_module
);
6497 lderr(cct
) << "ERROR: failed to init sync module instance, ret=" << ret
<< dendl
;
6501 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
, sync_module
);
6505 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6511 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6516 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6517 if (source_zone
.empty()) {
6518 cerr
<< "ERROR: source zone not specified" << std::endl
;
6521 if (bucket_name
.empty()) {
6522 cerr
<< "ERROR: bucket not specified" << std::endl
;
6526 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6530 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6534 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6537 ret
= sync
.init_sync_status();
6539 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6544 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
6545 if (bucket_name
.empty()) {
6546 cerr
<< "ERROR: bucket not specified" << std::endl
;
6551 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
6555 ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
, true);
6557 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
6561 if (!store
->is_meta_master()) {
6562 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
6563 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
6567 rgw_obj
obj(bucket
, object
);
6568 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
6573 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6574 if (source_zone
.empty()) {
6575 cerr
<< "ERROR: source zone not specified" << std::endl
;
6578 if (bucket_name
.empty()) {
6579 cerr
<< "ERROR: bucket not specified" << std::endl
;
6583 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6587 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6591 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6594 ret
= sync
.read_sync_status();
6596 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6600 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6602 encode_json("sync_status", sync_status
, formatter
);
6603 formatter
->flush(cout
);
6606 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6607 if (source_zone
.empty()) {
6608 cerr
<< "ERROR: source zone not specified" << std::endl
;
6611 if (bucket_name
.empty()) {
6612 cerr
<< "ERROR: bucket not specified" << std::endl
;
6616 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6620 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6624 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6630 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6635 if (opt_cmd
== OPT_BILOG_LIST
) {
6636 if (bucket_name
.empty()) {
6637 cerr
<< "ERROR: bucket not specified" << std::endl
;
6640 RGWBucketInfo bucket_info
;
6641 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6643 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6646 formatter
->open_array_section("entries");
6649 if (max_entries
< 0)
6653 list
<rgw_bi_log_entry
> entries
;
6654 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6656 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6660 count
+= entries
.size();
6662 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6663 rgw_bi_log_entry
& entry
= *iter
;
6664 encode_json("entry", entry
, formatter
);
6668 formatter
->flush(cout
);
6669 } while (truncated
&& count
< max_entries
);
6671 formatter
->close_section();
6672 formatter
->flush(cout
);
6675 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6676 if (max_entries
< 0) {
6681 utime_t start_time
, end_time
;
6683 int ret
= parse_date_str(start_date
, start_time
);
6687 ret
= parse_date_str(end_date
, end_time
);
6695 formatter
->open_array_section("entries");
6697 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6698 formatter
->open_object_section("shard");
6699 encode_json("shard_id", shard_id
, formatter
);
6700 formatter
->open_array_section("entries");
6703 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6706 list
<cls_log_entry
> entries
;
6707 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6708 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6709 if (ret
== -ENOENT
) {
6713 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6717 count
+= entries
.size();
6719 for (auto& cls_entry
: entries
) {
6720 rgw_sync_error_info log_entry
;
6722 auto iter
= cls_entry
.data
.begin();
6724 ::decode(log_entry
, iter
);
6725 } catch (buffer::error
& err
) {
6726 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
6729 formatter
->open_object_section("entry");
6730 encode_json("id", cls_entry
.id
, formatter
);
6731 encode_json("section", cls_entry
.section
, formatter
);
6732 encode_json("name", cls_entry
.name
, formatter
);
6733 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
6734 encode_json("info", log_entry
, formatter
);
6735 formatter
->close_section();
6736 formatter
->flush(cout
);
6738 } while (truncated
&& count
< max_entries
);
6740 formatter
->close_section();
6741 formatter
->close_section();
6743 if (specified_shard_id
) {
6748 formatter
->close_section();
6749 formatter
->flush(cout
);
6752 if (opt_cmd
== OPT_SYNC_ERROR_TRIM
) {
6753 utime_t start_time
, end_time
;
6754 int ret
= parse_date_str(start_date
, start_time
);
6758 ret
= parse_date_str(end_date
, end_time
);
6766 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6767 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6768 ret
= store
->time_log_trim(oid
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6769 if (ret
< 0 && ret
!= -ENODATA
) {
6770 cerr
<< "ERROR: sync error trim: " << cpp_strerror(-ret
) << std::endl
;
6773 if (specified_shard_id
) {
6779 if (opt_cmd
== OPT_BILOG_TRIM
) {
6780 if (bucket_name
.empty()) {
6781 cerr
<< "ERROR: bucket not specified" << std::endl
;
6784 RGWBucketInfo bucket_info
;
6785 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6787 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6790 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
6792 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6797 if (opt_cmd
== OPT_BILOG_STATUS
) {
6798 if (bucket_name
.empty()) {
6799 cerr
<< "ERROR: bucket not specified" << std::endl
;
6802 RGWBucketInfo bucket_info
;
6803 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6805 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6808 map
<int, string
> markers
;
6809 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
6811 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
6814 formatter
->open_object_section("entries");
6815 encode_json("markers", markers
, formatter
);
6816 formatter
->close_section();
6817 formatter
->flush(cout
);
6820 if (opt_cmd
== OPT_BILOG_AUTOTRIM
) {
6821 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6822 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6823 int ret
= http
.set_threaded();
6825 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6829 rgw::BucketTrimConfig config
;
6830 configure_bucket_trim(store
->ctx(), config
);
6832 rgw::BucketTrimManager
trim(store
, config
);
6835 cerr
<< "trim manager init failed with " << cpp_strerror(ret
) << std::endl
;
6838 ret
= crs
.run(trim
.create_admin_bucket_trim_cr(&http
));
6840 cerr
<< "automated bilog trim failed with " << cpp_strerror(ret
) << std::endl
;
6845 if (opt_cmd
== OPT_DATALOG_LIST
) {
6846 formatter
->open_array_section("entries");
6849 if (max_entries
< 0)
6852 utime_t start_time
, end_time
;
6854 int ret
= parse_date_str(start_date
, start_time
);
6858 ret
= parse_date_str(end_date
, end_time
);
6862 RGWDataChangesLog
*log
= store
->data_log
;
6863 RGWDataChangesLog::LogMarker marker
;
6866 list
<rgw_data_change_log_entry
> entries
;
6867 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
6869 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6873 count
+= entries
.size();
6875 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6876 rgw_data_change_log_entry
& entry
= *iter
;
6878 encode_json("entry", entry
.entry
, formatter
);
6880 encode_json("entry", entry
, formatter
);
6883 formatter
->flush(cout
);
6884 } while (truncated
&& count
< max_entries
);
6886 formatter
->close_section();
6887 formatter
->flush(cout
);
6890 if (opt_cmd
== OPT_DATALOG_STATUS
) {
6891 RGWDataChangesLog
*log
= store
->data_log
;
6892 int i
= (specified_shard_id
? shard_id
: 0);
6894 formatter
->open_array_section("entries");
6895 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
6896 list
<cls_log_entry
> entries
;
6898 RGWDataChangesLogInfo info
;
6899 log
->get_info(i
, &info
);
6901 ::encode_json("info", info
, formatter
);
6903 if (specified_shard_id
)
6907 formatter
->close_section();
6908 formatter
->flush(cout
);
6911 if (opt_cmd
== OPT_DATALOG_TRIM
) {
6912 utime_t start_time
, end_time
;
6914 int ret
= parse_date_str(start_date
, start_time
);
6918 ret
= parse_date_str(end_date
, end_time
);
6922 RGWDataChangesLog
*log
= store
->data_log
;
6923 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6925 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
6930 if (opt_cmd
== OPT_OPSTATE_LIST
) {
6931 RGWOpState
oc(store
);
6936 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
6937 list
<cls_statelog_entry
> entries
;
6939 formatter
->open_array_section("entries");
6941 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
6943 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
6944 oc
.finish_list_entries(handle
);
6948 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6949 oc
.dump_entry(*iter
, formatter
);
6952 formatter
->flush(cout
);
6954 formatter
->close_section();
6955 formatter
->flush(cout
);
6956 oc
.finish_list_entries(handle
);
6959 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
6960 RGWOpState
oc(store
);
6962 RGWOpState::OpState state
;
6963 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6964 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6967 if (state_str
.empty()) {
6968 cerr
<< "ERROR: state was not specified" << std::endl
;
6971 int ret
= oc
.state_from_str(state_str
, &state
);
6973 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
6977 if (opt_cmd
== OPT_OPSTATE_SET
) {
6978 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
6980 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
6984 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
6986 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
6991 if (opt_cmd
== OPT_OPSTATE_RM
) {
6992 RGWOpState
oc(store
);
6994 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
6995 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
6998 ret
= oc
.remove_entry(client_id
, op_id
, object
);
7000 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
7005 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
7006 opt_cmd
== OPT_REPLICALOG_DELETE
) {
7007 if (replica_log_type_str
.empty()) {
7008 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
7013 if (opt_cmd
== OPT_REPLICALOG_GET
) {
7014 RGWReplicaBounds bounds
;
7015 if (replica_log_type
== ReplicaLog_Metadata
) {
7016 if (!specified_shard_id
) {
7017 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7021 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7022 int ret
= logger
.get_bounds(shard_id
, bounds
);
7025 } else if (replica_log_type
== ReplicaLog_Data
) {
7026 if (!specified_shard_id
) {
7027 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7030 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7031 int ret
= logger
.get_bounds(shard_id
, bounds
);
7034 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7035 if (bucket_name
.empty()) {
7036 cerr
<< "ERROR: bucket not specified" << std::endl
;
7039 RGWBucketInfo bucket_info
;
7040 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7042 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7046 RGWReplicaBucketLogger
logger(store
);
7047 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
7050 } else { // shouldn't get here
7053 encode_json("bounds", bounds
, formatter
);
7054 formatter
->flush(cout
);
7058 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
7059 if (replica_log_type
== ReplicaLog_Metadata
) {
7060 if (!specified_shard_id
) {
7061 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
7064 if (!specified_daemon_id
) {
7065 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
7068 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7069 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
7072 } else if (replica_log_type
== ReplicaLog_Data
) {
7073 if (!specified_shard_id
) {
7074 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
7077 if (!specified_daemon_id
) {
7078 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
7081 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7082 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
7085 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7086 if (bucket_name
.empty()) {
7087 cerr
<< "ERROR: bucket not specified" << std::endl
;
7090 RGWBucketInfo bucket_info
;
7091 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7093 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7097 RGWReplicaBucketLogger
logger(store
);
7098 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
7104 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
7105 if (marker
.empty()) {
7106 cerr
<< "ERROR: marker was not specified" <<std::endl
;
7109 utime_t time
= ceph_clock_now();
7110 if (!date
.empty()) {
7111 ret
= parse_date_str(date
, time
);
7113 cerr
<< "ERROR: failed to parse start date" << std::endl
;
7117 list
<RGWReplicaItemMarker
> entries
;
7118 int ret
= read_decode_json(infile
, entries
);
7120 cerr
<< "ERROR: failed to decode entries" << std::endl
;
7123 RGWReplicaBounds bounds
;
7124 if (replica_log_type
== ReplicaLog_Metadata
) {
7125 if (!specified_shard_id
) {
7126 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7130 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7131 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7133 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7136 } else if (replica_log_type
== ReplicaLog_Data
) {
7137 if (!specified_shard_id
) {
7138 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7141 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7142 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7144 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7147 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7148 if (bucket_name
.empty()) {
7149 cerr
<< "ERROR: bucket not specified" << std::endl
;
7152 RGWBucketInfo bucket_info
;
7153 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7155 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7159 RGWReplicaBucketLogger
logger(store
);
7160 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
7162 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7168 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7171 if (bucket_name
.empty() && user_id
.empty()) {
7172 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7176 if (!bucket_name
.empty()) {
7177 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7178 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7181 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7182 max_size
, max_objects
, have_max_size
, have_max_objects
);
7183 } else if (!user_id
.empty()) {
7184 if (quota_scope
== "bucket") {
7185 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7186 } else if (quota_scope
== "user") {
7187 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7189 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;