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> Specify the bucket name. Also used by the quota command.\n";
223 cout
<< " --pool=<pool> Specify the pool name. Also used to scan for leaked rados objects.\n";
224 cout
<< " --object=<object> object name\n";
225 cout
<< " --date=<date> date in the format yyyy-mm-dd\n";
226 cout
<< " --start-date=<date> start date in the format yyyy-mm-dd\n";
227 cout
<< " --end-date=<date> end date in the format yyyy-mm-dd\n";
228 cout
<< " --bucket-id=<bucket-id> bucket id\n";
229 cout
<< " --shard-id=<shard-id> optional for: \n";
230 cout
<< " mdlog list\n";
231 cout
<< " data sync status\n";
232 cout
<< " required for: \n";
233 cout
<< " mdlog trim\n";
234 cout
<< " replica mdlog get/delete\n";
235 cout
<< " replica datalog get/delete\n";
236 cout
<< " --max-entries=<entries> max entries for listing operations\n";
237 cout
<< " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
238 cout
<< " --remote=<remote> zone or zonegroup id of remote gateway\n";
239 cout
<< " --period=<id> period id\n";
240 cout
<< " --epoch=<number> period epoch\n";
241 cout
<< " --commit commit the period during 'period update'\n";
242 cout
<< " --staging get staging period info\n";
243 cout
<< " --master set as master\n";
244 cout
<< " --master-url master url\n";
245 cout
<< " --master-zonegroup=<id> master zonegroup id\n";
246 cout
<< " --master-zone=<id> master zone id\n";
247 cout
<< " --rgw-realm=<name> realm name\n";
248 cout
<< " --realm-id=<id> realm id\n";
249 cout
<< " --realm-new-name=<name> realm new name\n";
250 cout
<< " --rgw-zonegroup=<name> zonegroup name\n";
251 cout
<< " --zonegroup-id=<id> zonegroup id\n";
252 cout
<< " --zonegroup-new-name=<name>\n";
253 cout
<< " zonegroup new name\n";
254 cout
<< " --rgw-zone=<name> name of zone in which radosgw is running\n";
255 cout
<< " --zone-id=<id> zone id\n";
256 cout
<< " --zone-new-name=<name> zone new name\n";
257 cout
<< " --source-zone specify the source zone (for data sync)\n";
258 cout
<< " --default set entity (realm, zonegroup, zone) as default\n";
259 cout
<< " --read-only set zone as read-only (when adding to zonegroup)\n";
260 cout
<< " --placement-id placement id for zonegroup placement commands\n";
261 cout
<< " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
262 cout
<< " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
263 cout
<< " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
264 cout
<< " --endpoints=<list> zone endpoints\n";
265 cout
<< " --index-pool=<pool> placement target index pool\n";
266 cout
<< " --data-pool=<pool> placement target data pool\n";
267 cout
<< " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n";
268 cout
<< " --placement-index-type=<type>\n";
269 cout
<< " placement target index type (normal, indexless, or #id)\n";
270 cout
<< " --compression=<type> placement target compression type (plugin name or empty/none)\n";
271 cout
<< " --tier-type=<type> zone tier type\n";
272 cout
<< " --tier-config=<k>=<v>[,...]\n";
273 cout
<< " set zone tier config keys, values\n";
274 cout
<< " --tier-config-rm=<k>[,...]\n";
275 cout
<< " unset zone tier config keys\n";
276 cout
<< " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
277 cout
<< " --sync-from=[zone-name][,...]\n";
278 cout
<< " set list of zones to sync from\n";
279 cout
<< " --sync-from-rm=[zone-name][,...]\n";
280 cout
<< " remove zones from list of zones to sync from\n";
281 cout
<< " --fix besides checking bucket index, will also fix it\n";
282 cout
<< " --check-objects bucket check: rebuilds bucket index according to\n";
283 cout
<< " actual objects state\n";
284 cout
<< " --format=<format> specify output format for certain operations: xml,\n";
286 cout
<< " --purge-data when specified, user removal will also purge all the\n";
287 cout
<< " user data\n";
288 cout
<< " --purge-keys when specified, subuser removal will also purge all the\n";
289 cout
<< " subuser keys\n";
290 cout
<< " --purge-objects remove a bucket's objects before deleting it\n";
291 cout
<< " (NOTE: required to delete a non-empty bucket)\n";
292 cout
<< " --sync-stats option to 'user stats', update user stats with current\n";
293 cout
<< " stats reported by user's buckets indexes\n";
294 cout
<< " --reset-stats option to 'user stats', reset stats in accordance with user buckets\n";
295 cout
<< " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
296 cout
<< " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
297 cout
<< " --skip-zero-entries log show only dumps entries that don't have zero value\n";
298 cout
<< " in one of the numeric field\n";
299 cout
<< " --infile=<file> specify a file to read in when setting data\n";
300 cout
<< " --state=<state string> specify a state for the opstate set command\n";
301 cout
<< " --replica-log-type replica log type (metadata, data, bucket), required for\n";
302 cout
<< " replica log operations\n";
303 cout
<< " --categories=<list> comma separated list of categories, used in usage show\n";
304 cout
<< " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
305 cout
<< " --yes-i-really-mean-it required for certain operations\n";
306 cout
<< " --warnings-only when specified with bucket limit check, list\n";
307 cout
<< " only buckets nearing or over the current max\n";
308 cout
<< " objects per shard value\n";
309 cout
<< " --bypass-gc when specified with bucket deletion, triggers\n";
310 cout
<< " object deletions by not involving GC\n";
311 cout
<< " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
312 cout
<< " ignores bucket index consistency\n";
314 cout
<< "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
315 cout
<< "\nQuota options:\n";
316 cout
<< " --bucket specified bucket for quota command\n";
317 cout
<< " --max-objects specify max objects (negative value to disable)\n";
318 cout
<< " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
319 cout
<< " --quota-scope scope of quota (bucket, user)\n";
320 cout
<< "\nOrphans search options:\n";
321 cout
<< " --pool data pool to scan for leaked rados objects in\n";
322 cout
<< " --num-shards num of shards to use for keeping the temporary scan info\n";
323 cout
<< " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
324 cout
<< " --job-id set the job id (for orphans find)\n";
325 cout
<< " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
326 cout
<< "\nOrphans list-jobs options:\n";
327 cout
<< " --extra-info provide extra info in job list\n";
328 cout
<< "\nRole options:\n";
329 cout
<< " --role-name name of the role to create\n";
330 cout
<< " --path path to the role\n";
331 cout
<< " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
332 cout
<< " --policy-name name of the policy document\n";
333 cout
<< " --policy-doc permission policy document\n";
334 cout
<< " --path-prefix path prefix for filtering roles\n";
336 generic_client_usage();
356 OPT_BUCKET_LIMIT_CHECK
,
361 OPT_BUCKET_SYNC_STATUS
,
362 OPT_BUCKET_SYNC_MARKERS
,
363 OPT_BUCKET_SYNC_INIT
,
365 OPT_BUCKET_SYNC_DISABLE
,
366 OPT_BUCKET_SYNC_ENABLE
,
399 OPT_ORPHANS_LIST_JOBS
,
401 OPT_ZONEGROUP_CREATE
,
402 OPT_ZONEGROUP_DEFAULT
,
403 OPT_ZONEGROUP_DELETE
,
405 OPT_ZONEGROUP_MODIFY
,
408 OPT_ZONEGROUP_REMOVE
,
409 OPT_ZONEGROUP_RENAME
,
410 OPT_ZONEGROUP_PLACEMENT_ADD
,
411 OPT_ZONEGROUP_PLACEMENT_MODIFY
,
412 OPT_ZONEGROUP_PLACEMENT_RM
,
413 OPT_ZONEGROUP_PLACEMENT_LIST
,
414 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
423 OPT_ZONE_PLACEMENT_ADD
,
424 OPT_ZONE_PLACEMENT_MODIFY
,
425 OPT_ZONE_PLACEMENT_RM
,
426 OPT_ZONE_PLACEMENT_LIST
,
433 OPT_METADATA_SYNC_STATUS
,
434 OPT_METADATA_SYNC_INIT
,
435 OPT_METADATA_SYNC_RUN
,
447 OPT_DATA_SYNC_STATUS
,
458 OPT_REPLICALOG_UPDATE
,
459 OPT_REPLICALOG_DELETE
,
463 OPT_REALM_GET_DEFAULT
,
465 OPT_REALM_LIST_PERIODS
,
473 OPT_PERIOD_GET_CURRENT
,
479 OPT_GLOBAL_QUOTA_GET
,
480 OPT_GLOBAL_QUOTA_SET
,
481 OPT_GLOBAL_QUOTA_ENABLE
,
482 OPT_GLOBAL_QUOTA_DISABLE
,
490 OPT_ROLE_POLICY_LIST
,
492 OPT_ROLE_POLICY_DELETE
,
500 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
503 // NOTE: please keep the checks in alphabetical order !!!
504 if (strcmp(cmd
, "bi") == 0 ||
505 strcmp(cmd
, "bilog") == 0 ||
506 strcmp(cmd
, "buckets") == 0 ||
507 strcmp(cmd
, "caps") == 0 ||
508 strcmp(cmd
, "data") == 0 ||
509 strcmp(cmd
, "datalog") == 0 ||
510 strcmp(cmd
, "error") == 0 ||
511 strcmp(cmd
, "gc") == 0 ||
512 strcmp(cmd
, "global") == 0 ||
513 strcmp(cmd
, "key") == 0 ||
514 strcmp(cmd
, "log") == 0 ||
515 strcmp(cmd
, "lc") == 0 ||
516 strcmp(cmd
, "mdlog") == 0 ||
517 strcmp(cmd
, "metadata") == 0 ||
518 strcmp(cmd
, "object") == 0 ||
519 strcmp(cmd
, "objects") == 0 ||
520 strcmp(cmd
, "olh") == 0 ||
521 strcmp(cmd
, "opstate") == 0 ||
522 strcmp(cmd
, "orphans") == 0 ||
523 strcmp(cmd
, "period") == 0 ||
524 strcmp(cmd
, "placement") == 0 ||
525 strcmp(cmd
, "pool") == 0 ||
526 strcmp(cmd
, "pools") == 0 ||
527 strcmp(cmd
, "quota") == 0 ||
528 strcmp(cmd
, "realm") == 0 ||
529 strcmp(cmd
, "replicalog") == 0 ||
530 strcmp(cmd
, "role") == 0 ||
531 strcmp(cmd
, "role-policy") == 0 ||
532 strcmp(cmd
, "subuser") == 0 ||
533 strcmp(cmd
, "sync") == 0 ||
534 strcmp(cmd
, "usage") == 0 ||
535 strcmp(cmd
, "user") == 0 ||
536 strcmp(cmd
, "zone") == 0 ||
537 strcmp(cmd
, "zonegroup") == 0 ||
538 strcmp(cmd
, "zonegroups") == 0) {
544 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
546 if (strcmp(cmd
, "reshard") == 0 &&
547 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
551 if (strcmp(cmd
, "bucket") == 0 &&
552 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
557 if (strcmp(cmd
, "policy") == 0)
563 if (strcmp(prev_cmd
, "user") == 0) {
564 if (strcmp(cmd
, "create") == 0)
565 return OPT_USER_CREATE
;
566 if (strcmp(cmd
, "info") == 0)
567 return OPT_USER_INFO
;
568 if (strcmp(cmd
, "modify") == 0)
569 return OPT_USER_MODIFY
;
570 if (strcmp(cmd
, "rm") == 0)
572 if (strcmp(cmd
, "suspend") == 0)
573 return OPT_USER_SUSPEND
;
574 if (strcmp(cmd
, "enable") == 0)
575 return OPT_USER_ENABLE
;
576 if (strcmp(cmd
, "check") == 0)
577 return OPT_USER_CHECK
;
578 if (strcmp(cmd
, "stats") == 0)
579 return OPT_USER_STATS
;
580 if (strcmp(cmd
, "list") == 0)
581 return OPT_USER_LIST
;
582 } else if (strcmp(prev_cmd
, "subuser") == 0) {
583 if (strcmp(cmd
, "create") == 0)
584 return OPT_SUBUSER_CREATE
;
585 if (strcmp(cmd
, "modify") == 0)
586 return OPT_SUBUSER_MODIFY
;
587 if (strcmp(cmd
, "rm") == 0)
588 return OPT_SUBUSER_RM
;
589 } else if (strcmp(prev_cmd
, "key") == 0) {
590 if (strcmp(cmd
, "create") == 0)
591 return OPT_KEY_CREATE
;
592 if (strcmp(cmd
, "rm") == 0)
594 } else if (strcmp(prev_cmd
, "buckets") == 0) {
595 if (strcmp(cmd
, "list") == 0)
596 return OPT_BUCKETS_LIST
;
597 } else if (strcmp(prev_cmd
, "bucket") == 0) {
598 if (strcmp(cmd
, "list") == 0)
599 return OPT_BUCKETS_LIST
;
600 if (strcmp(cmd
, "link") == 0)
601 return OPT_BUCKET_LINK
;
602 if (strcmp(cmd
, "unlink") == 0)
603 return OPT_BUCKET_UNLINK
;
604 if (strcmp(cmd
, "stats") == 0)
605 return OPT_BUCKET_STATS
;
606 if (strcmp(cmd
, "rm") == 0)
607 return OPT_BUCKET_RM
;
608 if (strcmp(cmd
, "rewrite") == 0)
609 return OPT_BUCKET_REWRITE
;
610 if (strcmp(cmd
, "reshard") == 0)
611 return OPT_BUCKET_RESHARD
;
612 if (strcmp(cmd
, "check") == 0)
613 return OPT_BUCKET_CHECK
;
614 if (strcmp(cmd
, "sync") == 0) {
618 if (strcmp(cmd
, "limit") == 0) {
622 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
623 if (strcmp(prev_cmd
, "sync") == 0) {
624 if (strcmp(cmd
, "status") == 0)
625 return OPT_BUCKET_SYNC_STATUS
;
626 if (strcmp(cmd
, "markers") == 0)
627 return OPT_BUCKET_SYNC_MARKERS
;
628 if (strcmp(cmd
, "init") == 0)
629 return OPT_BUCKET_SYNC_INIT
;
630 if (strcmp(cmd
, "run") == 0)
631 return OPT_BUCKET_SYNC_RUN
;
632 if (strcmp(cmd
, "disable") == 0)
633 return OPT_BUCKET_SYNC_DISABLE
;
634 if (strcmp(cmd
, "enable") == 0)
635 return OPT_BUCKET_SYNC_ENABLE
;
636 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
637 (strcmp(cmd
, "check") == 0)) {
638 return OPT_BUCKET_LIMIT_CHECK
;
640 } else if (strcmp(prev_cmd
, "log") == 0) {
641 if (strcmp(cmd
, "list") == 0)
643 if (strcmp(cmd
, "show") == 0)
645 if (strcmp(cmd
, "rm") == 0)
647 } else if (strcmp(prev_cmd
, "usage") == 0) {
648 if (strcmp(cmd
, "show") == 0)
649 return OPT_USAGE_SHOW
;
650 if (strcmp(cmd
, "trim") == 0)
651 return OPT_USAGE_TRIM
;
652 } else if (strcmp(prev_cmd
, "caps") == 0) {
653 if (strcmp(cmd
, "add") == 0)
655 if (strcmp(cmd
, "rm") == 0)
657 } else if (strcmp(prev_cmd
, "pool") == 0) {
658 if (strcmp(cmd
, "add") == 0)
660 if (strcmp(cmd
, "rm") == 0)
662 if (strcmp(cmd
, "list") == 0)
663 return OPT_POOLS_LIST
;
664 } else if (strcmp(prev_cmd
, "pools") == 0) {
665 if (strcmp(cmd
, "list") == 0)
666 return OPT_POOLS_LIST
;
667 } else if (strcmp(prev_cmd
, "object") == 0) {
668 if (strcmp(cmd
, "rm") == 0)
669 return OPT_OBJECT_RM
;
670 if (strcmp(cmd
, "unlink") == 0)
671 return OPT_OBJECT_UNLINK
;
672 if (strcmp(cmd
, "stat") == 0)
673 return OPT_OBJECT_STAT
;
674 if (strcmp(cmd
, "rewrite") == 0)
675 return OPT_OBJECT_REWRITE
;
676 } else if (strcmp(prev_cmd
, "objects") == 0) {
677 if (strcmp(cmd
, "expire") == 0)
678 return OPT_OBJECTS_EXPIRE
;
679 } else if (strcmp(prev_cmd
, "olh") == 0) {
680 if (strcmp(cmd
, "get") == 0)
682 if (strcmp(cmd
, "readlog") == 0)
683 return OPT_OLH_READLOG
;
684 } else if (strcmp(prev_cmd
, "bi") == 0) {
685 if (strcmp(cmd
, "get") == 0)
687 if (strcmp(cmd
, "put") == 0)
689 if (strcmp(cmd
, "list") == 0)
691 if (strcmp(cmd
, "purge") == 0)
693 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
694 (strcmp(prev_cmd
, "quota") == 0)) {
695 if (strcmp(cmd
, "get") == 0)
696 return OPT_GLOBAL_QUOTA_GET
;
697 if (strcmp(cmd
, "set") == 0)
698 return OPT_GLOBAL_QUOTA_SET
;
699 if (strcmp(cmd
, "enable") == 0)
700 return OPT_GLOBAL_QUOTA_ENABLE
;
701 if (strcmp(cmd
, "disable") == 0)
702 return OPT_GLOBAL_QUOTA_DISABLE
;
703 } else if (strcmp(prev_cmd
, "period") == 0) {
704 if (strcmp(cmd
, "delete") == 0)
705 return OPT_PERIOD_DELETE
;
706 if (strcmp(cmd
, "get") == 0)
707 return OPT_PERIOD_GET
;
708 if (strcmp(cmd
, "get-current") == 0)
709 return OPT_PERIOD_GET_CURRENT
;
710 if (strcmp(cmd
, "pull") == 0)
711 return OPT_PERIOD_PULL
;
712 if (strcmp(cmd
, "push") == 0)
713 return OPT_PERIOD_PUSH
;
714 if (strcmp(cmd
, "list") == 0)
715 return OPT_PERIOD_LIST
;
716 if (strcmp(cmd
, "update") == 0)
717 return OPT_PERIOD_UPDATE
;
718 if (strcmp(cmd
, "commit") == 0)
719 return OPT_PERIOD_COMMIT
;
720 } else if (strcmp(prev_cmd
, "realm") == 0) {
721 if (strcmp(cmd
, "create") == 0)
722 return OPT_REALM_CREATE
;
723 if (strcmp(cmd
, "delete") == 0)
724 return OPT_REALM_DELETE
;
725 if (strcmp(cmd
, "get") == 0)
726 return OPT_REALM_GET
;
727 if (strcmp(cmd
, "get-default") == 0)
728 return OPT_REALM_GET_DEFAULT
;
729 if (strcmp(cmd
, "list") == 0)
730 return OPT_REALM_LIST
;
731 if (strcmp(cmd
, "list-periods") == 0)
732 return OPT_REALM_LIST_PERIODS
;
733 if (strcmp(cmd
, "remove") == 0)
734 return OPT_REALM_REMOVE
;
735 if (strcmp(cmd
, "rename") == 0)
736 return OPT_REALM_RENAME
;
737 if (strcmp(cmd
, "set") == 0)
738 return OPT_REALM_SET
;
739 if (strcmp(cmd
, "default") == 0)
740 return OPT_REALM_DEFAULT
;
741 if (strcmp(cmd
, "pull") == 0)
742 return OPT_REALM_PULL
;
743 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
744 (strcmp(prev_cmd
, "placement") == 0)) {
745 if (strcmp(cmd
, "add") == 0)
746 return OPT_ZONEGROUP_PLACEMENT_ADD
;
747 if (strcmp(cmd
, "modify") == 0)
748 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
749 if (strcmp(cmd
, "rm") == 0)
750 return OPT_ZONEGROUP_PLACEMENT_RM
;
751 if (strcmp(cmd
, "list") == 0)
752 return OPT_ZONEGROUP_PLACEMENT_LIST
;
753 if (strcmp(cmd
, "default") == 0)
754 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
755 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
756 if (strcmp(cmd
, "add") == 0)
757 return OPT_ZONEGROUP_ADD
;
758 if (strcmp(cmd
, "create")== 0)
759 return OPT_ZONEGROUP_CREATE
;
760 if (strcmp(cmd
, "default") == 0)
761 return OPT_ZONEGROUP_DEFAULT
;
762 if (strcmp(cmd
, "delete") == 0)
763 return OPT_ZONEGROUP_DELETE
;
764 if (strcmp(cmd
, "get") == 0)
765 return OPT_ZONEGROUP_GET
;
766 if (strcmp(cmd
, "modify") == 0)
767 return OPT_ZONEGROUP_MODIFY
;
768 if (strcmp(cmd
, "list") == 0)
769 return OPT_ZONEGROUP_LIST
;
770 if (strcmp(cmd
, "set") == 0)
771 return OPT_ZONEGROUP_SET
;
772 if (strcmp(cmd
, "remove") == 0)
773 return OPT_ZONEGROUP_REMOVE
;
774 if (strcmp(cmd
, "rename") == 0)
775 return OPT_ZONEGROUP_RENAME
;
776 } else if (strcmp(prev_cmd
, "quota") == 0) {
777 if (strcmp(cmd
, "set") == 0)
778 return OPT_QUOTA_SET
;
779 if (strcmp(cmd
, "enable") == 0)
780 return OPT_QUOTA_ENABLE
;
781 if (strcmp(cmd
, "disable") == 0)
782 return OPT_QUOTA_DISABLE
;
783 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
784 if (strcmp(cmd
, "list") == 0)
785 return OPT_ZONEGROUP_LIST
;
786 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
787 (strcmp(prev_cmd
, "placement") == 0)) {
788 if (strcmp(cmd
, "add") == 0)
789 return OPT_ZONE_PLACEMENT_ADD
;
790 if (strcmp(cmd
, "modify") == 0)
791 return OPT_ZONE_PLACEMENT_MODIFY
;
792 if (strcmp(cmd
, "rm") == 0)
793 return OPT_ZONE_PLACEMENT_RM
;
794 if (strcmp(cmd
, "list") == 0)
795 return OPT_ZONE_PLACEMENT_LIST
;
796 } else if (strcmp(prev_cmd
, "zone") == 0) {
797 if (strcmp(cmd
, "delete") == 0)
798 return OPT_ZONE_DELETE
;
799 if (strcmp(cmd
, "create") == 0)
800 return OPT_ZONE_CREATE
;
801 if (strcmp(cmd
, "get") == 0)
803 if (strcmp(cmd
, "set") == 0)
805 if (strcmp(cmd
, "list") == 0)
806 return OPT_ZONE_LIST
;
807 if (strcmp(cmd
, "modify") == 0)
808 return OPT_ZONE_MODIFY
;
809 if (strcmp(cmd
, "rename") == 0)
810 return OPT_ZONE_RENAME
;
811 if (strcmp(cmd
, "default") == 0)
812 return OPT_ZONE_DEFAULT
;
813 } else if (strcmp(prev_cmd
, "zones") == 0) {
814 if (strcmp(cmd
, "list") == 0)
815 return OPT_ZONE_LIST
;
816 } else if (strcmp(prev_cmd
, "gc") == 0) {
817 if (strcmp(cmd
, "list") == 0)
819 if (strcmp(cmd
, "process") == 0)
820 return OPT_GC_PROCESS
;
821 } else if (strcmp(prev_cmd
, "lc") == 0) {
822 if (strcmp(cmd
, "list") == 0)
824 if (strcmp(cmd
, "process") == 0)
825 return OPT_LC_PROCESS
;
826 } else if (strcmp(prev_cmd
, "orphans") == 0) {
827 if (strcmp(cmd
, "find") == 0)
828 return OPT_ORPHANS_FIND
;
829 if (strcmp(cmd
, "finish") == 0)
830 return OPT_ORPHANS_FINISH
;
831 if (strcmp(cmd
, "list-jobs") == 0)
832 return OPT_ORPHANS_LIST_JOBS
;
833 } else if (strcmp(prev_cmd
, "metadata") == 0) {
834 if (strcmp(cmd
, "get") == 0)
835 return OPT_METADATA_GET
;
836 if (strcmp(cmd
, "put") == 0)
837 return OPT_METADATA_PUT
;
838 if (strcmp(cmd
, "rm") == 0)
839 return OPT_METADATA_RM
;
840 if (strcmp(cmd
, "list") == 0)
841 return OPT_METADATA_LIST
;
842 if (strcmp(cmd
, "sync") == 0) {
846 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
847 (strcmp(prev_cmd
, "sync") == 0)) {
848 if (strcmp(cmd
, "status") == 0)
849 return OPT_METADATA_SYNC_STATUS
;
850 if (strcmp(cmd
, "init") == 0)
851 return OPT_METADATA_SYNC_INIT
;
852 if (strcmp(cmd
, "run") == 0)
853 return OPT_METADATA_SYNC_RUN
;
854 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
855 (strcmp(prev_cmd
, "error") == 0)) {
856 if (strcmp(cmd
, "list") == 0)
857 return OPT_SYNC_ERROR_LIST
;
858 if (strcmp(cmd
, "trim") == 0)
859 return OPT_SYNC_ERROR_TRIM
;
860 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
861 if (strcmp(cmd
, "list") == 0)
862 return OPT_MDLOG_LIST
;
863 if (strcmp(cmd
, "autotrim") == 0)
864 return OPT_MDLOG_AUTOTRIM
;
865 if (strcmp(cmd
, "trim") == 0)
866 return OPT_MDLOG_TRIM
;
867 if (strcmp(cmd
, "fetch") == 0)
868 return OPT_MDLOG_FETCH
;
869 if (strcmp(cmd
, "status") == 0)
870 return OPT_MDLOG_STATUS
;
871 } else if (strcmp(prev_cmd
, "bilog") == 0) {
872 if (strcmp(cmd
, "list") == 0)
873 return OPT_BILOG_LIST
;
874 if (strcmp(cmd
, "trim") == 0)
875 return OPT_BILOG_TRIM
;
876 if (strcmp(cmd
, "status") == 0)
877 return OPT_BILOG_STATUS
;
878 if (strcmp(cmd
, "autotrim") == 0)
879 return OPT_BILOG_AUTOTRIM
;
880 } else if (strcmp(prev_cmd
, "data") == 0) {
881 if (strcmp(cmd
, "sync") == 0) {
885 } else if (strcmp(prev_cmd
, "datalog") == 0) {
886 if (strcmp(cmd
, "list") == 0)
887 return OPT_DATALOG_LIST
;
888 if (strcmp(cmd
, "trim") == 0)
889 return OPT_DATALOG_TRIM
;
890 if (strcmp(cmd
, "status") == 0)
891 return OPT_DATALOG_STATUS
;
892 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
893 (strcmp(prev_cmd
, "sync") == 0)) {
894 if (strcmp(cmd
, "status") == 0)
895 return OPT_DATA_SYNC_STATUS
;
896 if (strcmp(cmd
, "init") == 0)
897 return OPT_DATA_SYNC_INIT
;
898 if (strcmp(cmd
, "run") == 0)
899 return OPT_DATA_SYNC_RUN
;
900 } else if (strcmp(prev_cmd
, "opstate") == 0) {
901 if (strcmp(cmd
, "list") == 0)
902 return OPT_OPSTATE_LIST
;
903 if (strcmp(cmd
, "set") == 0)
904 return OPT_OPSTATE_SET
;
905 if (strcmp(cmd
, "renew") == 0)
906 return OPT_OPSTATE_RENEW
;
907 if (strcmp(cmd
, "rm") == 0)
908 return OPT_OPSTATE_RM
;
909 } else if (strcmp(prev_cmd
, "replicalog") == 0) {
910 if (strcmp(cmd
, "get") == 0)
911 return OPT_REPLICALOG_GET
;
912 if (strcmp(cmd
, "update") == 0)
913 return OPT_REPLICALOG_UPDATE
;
914 if (strcmp(cmd
, "delete") == 0)
915 return OPT_REPLICALOG_DELETE
;
916 } else if (strcmp(prev_cmd
, "sync") == 0) {
917 if (strcmp(cmd
, "status") == 0)
918 return OPT_SYNC_STATUS
;
919 } else if (strcmp(prev_cmd
, "role") == 0) {
920 if (strcmp(cmd
, "create") == 0)
921 return OPT_ROLE_CREATE
;
922 if (strcmp(cmd
, "delete") == 0)
923 return OPT_ROLE_DELETE
;
924 if (strcmp(cmd
, "get") == 0)
926 if (strcmp(cmd
, "modify") == 0)
927 return OPT_ROLE_MODIFY
;
928 if (strcmp(cmd
, "list") == 0)
929 return OPT_ROLE_LIST
;
930 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
931 if (strcmp(cmd
, "put") == 0)
932 return OPT_ROLE_POLICY_PUT
;
933 if (strcmp(cmd
, "list") == 0)
934 return OPT_ROLE_POLICY_LIST
;
935 if (strcmp(cmd
, "get") == 0)
936 return OPT_ROLE_POLICY_GET
;
937 if (strcmp(cmd
, "delete") == 0)
938 return OPT_ROLE_POLICY_DELETE
;
939 } else if (strcmp(prev_cmd
, "reshard") == 0) {
940 if (strcmp(cmd
, "bucket") == 0)
941 return OPT_BUCKET_RESHARD
;
942 if (strcmp(cmd
, "add") == 0)
943 return OPT_RESHARD_ADD
;
944 if (strcmp(cmd
, "list") == 0)
945 return OPT_RESHARD_LIST
;
946 if (strcmp(cmd
, "status") == 0)
947 return OPT_RESHARD_STATUS
;
948 if (strcmp(cmd
, "process") == 0)
949 return OPT_RESHARD_PROCESS
;
950 if (strcmp(cmd
, "cancel") == 0)
951 return OPT_RESHARD_CANCEL
;
957 enum ReplicaLogType
{
958 ReplicaLog_Invalid
= 0,
964 ReplicaLogType
get_replicalog_type(const string
& name
) {
965 if (name
== "md" || name
== "meta" || name
== "metadata")
966 return ReplicaLog_Metadata
;
968 return ReplicaLog_Data
;
969 if (name
== "bucket")
970 return ReplicaLog_Bucket
;
972 return ReplicaLog_Invalid
;
975 BIIndexType
get_bi_index_type(const string
& type_str
) {
976 if (type_str
== "plain")
978 if (type_str
== "instance")
980 if (type_str
== "olh")
986 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
988 bufferlist::iterator iter
= bl
.begin();
989 switch (index_type
) {
993 rgw_bucket_dir_entry entry
;
994 ::decode(entry
, iter
);
995 encode_json("entry", entry
, formatter
);
1000 rgw_bucket_olh_entry entry
;
1001 ::decode(entry
, iter
);
1002 encode_json("entry", entry
, formatter
);
1011 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
1013 encode_json("user_info", info
, formatter
);
1014 formatter
->flush(cout
);
1018 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1020 formatter
->open_object_section("role");
1021 formatter
->dump_string("Permission policy", perm_policy
);
1022 formatter
->close_section();
1023 formatter
->flush(cout
);
1026 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1028 formatter
->open_array_section("PolicyNames");
1029 for (const auto& it
: policy_names
) {
1030 formatter
->dump_string("policyname", it
);
1032 formatter
->close_section();
1033 formatter
->flush(cout
);
1036 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1038 formatter
->open_object_section("role");
1039 role
.dump(formatter
);
1040 formatter
->close_section();
1041 formatter
->flush(cout
);
1044 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1046 formatter
->open_array_section("Roles");
1047 for (const auto& it
: roles
) {
1048 formatter
->open_object_section("role");
1050 formatter
->close_section();
1052 formatter
->close_section();
1053 formatter
->flush(cout
);
1056 class StoreDestructor
{
1059 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1060 ~StoreDestructor() {
1061 RGWStoreManager::close_storage(store
);
1065 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1066 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1068 if (!bucket_name
.empty()) {
1069 RGWObjectCtx
obj_ctx(store
);
1071 if (bucket_id
.empty()) {
1072 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1074 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1075 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1078 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1081 bucket
= bucket_info
.bucket
;
1086 static int read_input(const string
& infile
, bufferlist
& bl
)
1089 if (infile
.size()) {
1090 fd
= open(infile
.c_str(), O_RDONLY
);
1093 cerr
<< "error reading input file " << infile
<< std::endl
;
1098 #define READ_CHUNK 8196
1103 char buf
[READ_CHUNK
];
1105 r
= safe_read(fd
, buf
, READ_CHUNK
);
1108 cerr
<< "error while reading input" << std::endl
;
1116 if (infile
.size()) {
1123 static int read_decode_json(const string
& infile
, T
& t
)
1126 int ret
= read_input(infile
, bl
);
1128 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1132 if (!p
.parse(bl
.c_str(), bl
.length())) {
1133 cout
<< "failed to parse JSON" << std::endl
;
1138 decode_json_obj(t
, &p
);
1139 } catch (JSONDecoder::err
& e
) {
1140 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1146 template <class T
, class K
>
1147 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1150 int ret
= read_input(infile
, bl
);
1152 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1156 if (!p
.parse(bl
.c_str(), bl
.length())) {
1157 cout
<< "failed to parse JSON" << std::endl
;
1162 t
.decode_json(&p
, k
);
1163 } catch (JSONDecoder::err
& e
) {
1164 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1170 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1175 if (!date_str
.empty()) {
1176 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1178 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1183 ut
= utime_t(epoch
, nsec
);
1189 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1193 bufferlist::iterator iter
= bl
.begin();
1197 } catch (buffer::error
& err
) {
1201 encode_json(field_name
, t
, f
);
1206 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1209 if (bl
.length() > 0) {
1210 val
.assign(bl
.c_str());
1212 f
->dump_string(field_name
, val
);
1217 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1218 bool have_max_size
, bool have_max_objects
)
1221 case OPT_QUOTA_ENABLE
:
1222 case OPT_GLOBAL_QUOTA_ENABLE
:
1223 quota
.enabled
= true;
1225 // falling through on purpose
1228 case OPT_GLOBAL_QUOTA_SET
:
1229 if (have_max_objects
) {
1230 if (max_objects
< 0) {
1231 quota
.max_objects
= -1;
1233 quota
.max_objects
= max_objects
;
1236 if (have_max_size
) {
1238 quota
.max_size
= -1;
1240 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1244 case OPT_QUOTA_DISABLE
:
1245 case OPT_GLOBAL_QUOTA_DISABLE
:
1246 quota
.enabled
= false;
1251 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1252 const string
& tenant_name
, const string
& bucket_name
,
1253 int64_t max_size
, int64_t max_objects
,
1254 bool have_max_size
, bool have_max_objects
)
1256 RGWBucketInfo bucket_info
;
1257 map
<string
, bufferlist
> attrs
;
1258 RGWObjectCtx
obj_ctx(store
);
1259 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1261 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1265 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1267 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1269 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1275 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1276 bool have_max_size
, bool have_max_objects
)
1278 RGWUserInfo
& user_info
= op_state
.get_user_info();
1280 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1282 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1285 int r
= user
.modify(op_state
, &err
);
1287 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1293 int set_user_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1294 bool have_max_size
, bool have_max_objects
)
1296 RGWUserInfo
& user_info
= op_state
.get_user_info();
1298 set_quota_info(user_info
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1300 op_state
.set_user_quota(user_info
.user_quota
);
1303 int r
= user
.modify(op_state
, &err
);
1305 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1311 static bool bucket_object_check_filter(const string
& name
)
1314 string ns
; /* empty namespace */
1315 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1318 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1320 map
<string
, bufferlist
> attrs
;
1323 RGWObjectCtx
obj_ctx(store
);
1324 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1325 RGWRados::Object::Read
read_op(&op_target
);
1327 read_op
.params
.attrs
= &attrs
;
1328 read_op
.params
.obj_size
= &obj_size
;
1330 int ret
= read_op
.prepare();
1332 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1336 map
<string
, bufferlist
>::iterator iter
;
1337 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1338 if (iter
== attrs
.end()) {
1339 *need_rewrite
= (obj_size
>= min_stripe_size
);
1343 RGWObjManifest manifest
;
1346 bufferlist
& bl
= iter
->second
;
1347 bufferlist::iterator biter
= bl
.begin();
1348 ::decode(manifest
, biter
);
1349 } catch (buffer::error
& err
) {
1350 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1354 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1355 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1356 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1357 RGWObjManifestPart
& part
= oiter
->second
;
1359 if (part
.size
>= min_stripe_size
) {
1360 *need_rewrite
= true;
1364 *need_rewrite
= false;
1370 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1371 f
->open_object_section("object");
1372 f
->open_object_section("key");
1373 f
->dump_string("type", "head");
1374 f
->dump_string("name", key
.name
);
1375 f
->dump_string("instance", key
.instance
);
1381 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1383 f
->dump_string("oid", oid
);
1384 f
->dump_string("locator", locator
);
1387 RGWObjectCtx
obj_ctx(store
);
1389 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1390 RGWRados::Object::Read
read_op(&op_target
);
1392 int ret
= read_op
.prepare();
1393 bool needs_fixing
= (ret
== -ENOENT
);
1395 f
->dump_bool("needs_fixing", needs_fixing
);
1397 string status
= (needs_fixing
? "needs_fixing" : "ok");
1399 if ((needs_fixing
|| remove_bad
) && fix
) {
1400 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1402 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1409 f
->dump_string("status", status
);
1416 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1417 f
->open_object_section("object");
1418 f
->open_object_section("key");
1419 f
->dump_string("type", "tail");
1420 f
->dump_string("name", key
.name
);
1421 f
->dump_string("instance", key
.instance
);
1427 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1429 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1432 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1435 f
->dump_bool("needs_fixing", needs_fixing
);
1436 f
->dump_string("status", status
);
1443 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1444 bool fix
, bool remove_bad
, Formatter
*f
)
1446 if (remove_bad
&& !fix
) {
1447 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1451 RGWBucketInfo bucket_info
;
1455 f
->open_object_section("bucket");
1456 f
->dump_string("bucket", bucket_name
);
1457 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1459 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1465 int max_entries
= 1000;
1469 vector
<rgw_bucket_dir_entry
> result
;
1470 map
<string
, bool> common_prefixes
;
1473 RGWRados::Bucket
target(store
, bucket_info
);
1474 RGWRados::Bucket::List
list_op(&target
);
1478 list_op
.params
.prefix
= prefix
;
1479 list_op
.params
.delim
= delim
;
1480 list_op
.params
.marker
= rgw_obj_key(marker
);
1481 list_op
.params
.ns
= ns
;
1482 list_op
.params
.enforce_ns
= true;
1483 list_op
.params
.list_versions
= true;
1485 f
->open_array_section("check_objects");
1487 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1489 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1493 count
+= result
.size();
1495 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1496 rgw_obj_key key
= iter
->key
;
1497 rgw_obj
obj(bucket
, key
);
1499 if (key
.name
[0] == '_') {
1500 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1503 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1508 } while (truncated
&& count
< max_entries
);
1517 int set_bucket_sync_enabled(RGWRados
*store
, int opt_cmd
, const string
& tenant_name
, const string
& bucket_name
)
1519 RGWBucketInfo bucket_info
;
1520 map
<string
, bufferlist
> attrs
;
1521 RGWObjectCtx
obj_ctx(store
);
1523 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1525 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1529 if (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
) {
1530 bucket_info
.flags
&= ~BUCKET_DATASYNC_DISABLED
;
1531 } else if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1532 bucket_info
.flags
|= BUCKET_DATASYNC_DISABLED
;
1535 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1537 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1541 int shards_num
= bucket_info
.num_shards
? bucket_info
.num_shards
: 1;
1542 int shard_id
= bucket_info
.num_shards
? 0 : -1;
1544 if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1545 r
= store
->stop_bi_log_entries(bucket_info
, -1);
1547 lderr(store
->ctx()) << "ERROR: failed writing stop bilog" << dendl
;
1551 r
= store
->resync_bi_log_entries(bucket_info
, -1);
1553 lderr(store
->ctx()) << "ERROR: failed writing resync bilog" << dendl
;
1558 for (int i
= 0; i
< shards_num
; ++i
, ++shard_id
) {
1559 r
= store
->data_log
->add_entry(bucket_info
.bucket
, shard_id
);
1561 lderr(store
->ctx()) << "ERROR: failed writing data log" << dendl
;
1570 /// search for a matching zone/zonegroup id and return a connection if found
1571 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1572 const RGWZoneGroup
& zonegroup
,
1573 const std::string
& remote
)
1575 boost::optional
<RGWRESTConn
> conn
;
1576 if (remote
== zonegroup
.get_id()) {
1577 conn
.emplace(store
->ctx(), store
, remote
, zonegroup
.endpoints
);
1579 for (const auto& z
: zonegroup
.zones
) {
1580 const auto& zone
= z
.second
;
1581 if (remote
== zone
.id
) {
1582 conn
.emplace(store
->ctx(), store
, remote
, zone
.endpoints
);
1590 /// search each zonegroup for a connection
1591 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1592 const RGWPeriodMap
& period_map
,
1593 const std::string
& remote
)
1595 boost::optional
<RGWRESTConn
> conn
;
1596 for (const auto& zg
: period_map
.zonegroups
) {
1597 conn
= get_remote_conn(store
, zg
.second
, remote
);
1605 // we expect a very small response
1606 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1608 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1609 bufferlist
& in_data
, JSONParser
& parser
)
1615 ceph::bufferlist response
;
1617 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1619 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1620 if (parse_ret
< 0) {
1621 cerr
<< "failed to parse response" << std::endl
;
1627 static int send_to_url(const string
& url
, const string
& access
,
1628 const string
& secret
, req_info
& info
,
1629 bufferlist
& in_data
, JSONParser
& parser
)
1631 if (access
.empty() || secret
.empty()) {
1632 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1640 RGWRESTSimpleRequest
req(g_ceph_context
, url
, NULL
, ¶ms
);
1642 bufferlist response
;
1643 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1645 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1646 if (parse_ret
< 0) {
1647 cout
<< "failed to parse response" << std::endl
;
1653 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1654 const string
& access
, const string
& secret
,
1655 req_info
& info
, bufferlist
& in_data
,
1659 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1661 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1664 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1665 string remote
, const string
& url
,
1666 const string
& access
, const string
& secret
,
1669 const string
& master_zone
= period
.get_master_zone();
1670 if (master_zone
.empty()) {
1671 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1674 // are we the period's master zone?
1675 if (store
->get_zone_params().get_id() == master_zone
) {
1676 // read the current period
1677 RGWPeriod current_period
;
1678 int ret
= current_period
.init(g_ceph_context
, store
, realm
.get_id());
1680 cerr
<< "Error initializing current period: "
1681 << cpp_strerror(-ret
) << std::endl
;
1684 // the master zone can commit locally
1685 ret
= period
.commit(realm
, current_period
, cerr
, force
);
1687 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1692 if (remote
.empty() && url
.empty()) {
1693 // use the new master zone's connection
1694 remote
= master_zone
;
1695 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1697 boost::optional
<RGWRESTConn
> conn
;
1698 RGWRESTConn
*remote_conn
= nullptr;
1699 if (!remote
.empty()) {
1700 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1702 cerr
<< "failed to find a zone or zonegroup for remote "
1703 << remote
<< std::endl
;
1706 remote_conn
= &*conn
;
1709 // push period to the master with an empty period id
1713 req_info
info(g_ceph_context
, &env
);
1714 info
.method
= "POST";
1715 info
.request_uri
= "/admin/realm/period";
1717 // json format into a bufferlist
1718 JSONFormatter
jf(false);
1719 encode_json("period", period
, &jf
);
1724 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1726 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1728 // did we parse an error message?
1729 auto message
= p
.find_obj("Message");
1731 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1736 // decode the response and store it back
1738 decode_json_obj(period
, &p
);
1739 } catch (JSONDecoder::err
& e
) {
1740 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1743 if (period
.get_id().empty()) {
1744 cerr
<< "Period commit got back an empty period id" << std::endl
;
1747 // the master zone gave us back the period that it committed, so it's
1748 // safe to save it as our latest epoch
1749 ret
= period
.store_info(false);
1751 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1752 << cpp_strerror(ret
) << std::endl
;
1755 ret
= period
.set_latest_epoch(period
.get_epoch());
1757 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1760 ret
= period
.reflect();
1762 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1765 realm
.notify_new_period(period
);
1769 static int update_period(const string
& realm_id
, const string
& realm_name
,
1770 const string
& period_id
, const string
& period_epoch
,
1771 bool commit
, const string
& remote
, const string
& url
,
1772 const string
& access
, const string
& secret
,
1773 Formatter
*formatter
, bool force
)
1775 RGWRealm
realm(realm_id
, realm_name
);
1776 int ret
= realm
.init(g_ceph_context
, store
);
1778 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1782 if (!period_epoch
.empty()) {
1783 epoch
= atoi(period_epoch
.c_str());
1785 RGWPeriod
period(period_id
, epoch
);
1786 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
1788 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1792 ret
= period
.update();
1794 // Dropping the error message here, as both the ret codes were handled in
1798 ret
= period
.store_info(false);
1800 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1804 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1806 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1810 encode_json("period", period
, formatter
);
1811 formatter
->flush(cout
);
1816 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1817 const string
& bucket_id
, rgw_bucket
& bucket
)
1819 RGWBucketInfo bucket_info
;
1821 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1823 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1830 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1831 const string
& access_key
, const string
& secret_key
,
1832 const string
& realm_id
, const string
& realm_name
,
1833 const string
& period_id
, const string
& period_epoch
,
1837 req_info
info(g_ceph_context
, &env
);
1838 info
.method
= "GET";
1839 info
.request_uri
= "/admin/realm/period";
1841 map
<string
, string
> ¶ms
= info
.args
.get_params();
1842 if (!realm_id
.empty())
1843 params
["realm_id"] = realm_id
;
1844 if (!realm_name
.empty())
1845 params
["realm_name"] = realm_name
;
1846 if (!period_id
.empty())
1847 params
["period_id"] = period_id
;
1848 if (!period_epoch
.empty())
1849 params
["epoch"] = period_epoch
;
1853 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1856 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1859 ret
= period
->init(g_ceph_context
, store
, false);
1861 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1865 decode_json_obj(*period
, &p
);
1866 } catch (JSONDecoder::err
& e
) {
1867 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1870 ret
= period
->store_info(false);
1872 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1874 // store latest epoch (ignore errors)
1875 period
->update_latest_epoch(period
->get_epoch());
1879 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
1880 const std::string
& realm_name
,
1881 std::string
* period_id
)
1883 RGWRealm
realm(realm_id
, realm_name
);
1884 int ret
= realm
.init(g_ceph_context
, store
);
1886 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
1889 *period_id
= realm
.get_current_period();
1893 void flush_ss(stringstream
& ss
, list
<string
>& l
)
1895 if (!ss
.str().empty()) {
1896 l
.push_back(ss
.str());
1901 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
1905 ss
<< setw(tab
) << "" << setw(1);
1910 static void get_md_sync_status(list
<string
>& status
)
1912 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
1914 int ret
= sync
.init();
1916 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
1920 rgw_meta_sync_status sync_status
;
1921 ret
= sync
.read_sync_status(&sync_status
);
1923 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
1928 switch (sync_status
.sync_info
.state
) {
1929 case rgw_meta_sync_info::StateInit
:
1930 status_str
= "init";
1932 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
1933 status_str
= "preparing for full sync";
1935 case rgw_meta_sync_info::StateSync
:
1936 status_str
= "syncing";
1939 status_str
= "unknown";
1942 status
.push_back(status_str
);
1944 uint64_t full_total
= 0;
1945 uint64_t full_complete
= 0;
1949 int total_shards
= 0;
1950 set
<int> shards_behind_set
;
1952 for (auto marker_iter
: sync_status
.sync_markers
) {
1953 full_total
+= marker_iter
.second
.total_entries
;
1955 int shard_id
= marker_iter
.first
;
1956 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
1958 full_complete
+= marker_iter
.second
.pos
;
1959 shards_behind_set
.insert(shard_id
);
1961 full_complete
+= marker_iter
.second
.total_entries
;
1963 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
1969 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
1972 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
1975 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
1977 rgw_mdlog_info log_info
;
1978 ret
= sync
.read_log_info(&log_info
);
1980 status
.push_back(string("failed to fetch local sync status: ") + cpp_strerror(-ret
));
1984 map
<int, RGWMetadataLogInfo
> master_shards_info
;
1985 string master_period
= store
->get_current_period_id();
1987 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
1989 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
1993 map
<int, string
> shards_behind
;
1994 if (sync_status
.sync_info
.period
!= master_period
) {
1995 status
.push_back(string("master is on a different period: master_period=" +
1996 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
1998 for (auto local_iter
: sync_status
.sync_markers
) {
1999 int shard_id
= local_iter
.first
;
2000 auto iter
= master_shards_info
.find(shard_id
);
2002 if (iter
== master_shards_info
.end()) {
2004 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2007 auto master_marker
= iter
->second
.marker
;
2008 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
2009 master_marker
> local_iter
.second
.marker
) {
2010 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2011 shards_behind_set
.insert(shard_id
);
2016 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2017 if (total_behind
== 0) {
2018 push_ss(ss
, status
) << "metadata is caught up with master";
2020 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
2022 push_ss(ss
, status
) << "behind shards: " << "[" << shards_behind_set
<< "]";
2024 map
<int, rgw_mdlog_shard_data
> master_pos
;
2025 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
2027 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2029 ceph::real_time oldest
;
2030 for (auto iter
: master_pos
) {
2031 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
2033 if (!shard_data
.entries
.empty()) {
2034 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
2035 if (ceph::real_clock::is_zero(oldest
)) {
2036 oldest
= entry
.timestamp
;
2037 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2038 oldest
= entry
.timestamp
;
2043 if (!ceph::real_clock::is_zero(oldest
)) {
2044 push_ss(ss
, status
) << "oldest incremental change not applied: " << oldest
;
2049 flush_ss(ss
, status
);
2052 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
2056 auto ziter
= store
->zone_by_id
.find(source_zone
);
2057 if (ziter
== store
->zone_by_id
.end()) {
2058 push_ss(ss
, status
, tab
) << string("zone not found");
2059 flush_ss(ss
, status
);
2062 RGWZone
& sz
= ziter
->second
;
2064 if (!store
->zone_syncs_from(store
->get_zone(), sz
)) {
2065 push_ss(ss
, status
, tab
) << string("not syncing from zone");
2066 flush_ss(ss
, status
);
2069 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
2071 int ret
= sync
.init();
2073 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
2074 flush_ss(ss
, status
);
2078 rgw_data_sync_status sync_status
;
2079 ret
= sync
.read_sync_status(&sync_status
);
2080 if (ret
< 0 && ret
!= -ENOENT
) {
2081 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2085 set
<int> recovering_shards
;
2086 ret
= sync
.read_recovering_shards(sync_status
.sync_info
.num_shards
, recovering_shards
);
2087 if (ret
< 0 && ret
!= ENOENT
) {
2088 push_ss(ss
, status
, tab
) << string("failed read recovering shards: ") + cpp_strerror(-ret
);
2093 switch (sync_status
.sync_info
.state
) {
2094 case rgw_data_sync_info::StateInit
:
2095 status_str
= "init";
2097 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2098 status_str
= "preparing for full sync";
2100 case rgw_data_sync_info::StateSync
:
2101 status_str
= "syncing";
2104 status_str
= "unknown";
2107 push_ss(ss
, status
, tab
) << status_str
;
2109 uint64_t full_total
= 0;
2110 uint64_t full_complete
= 0;
2114 int total_shards
= 0;
2115 set
<int> shards_behind_set
;
2117 for (auto marker_iter
: sync_status
.sync_markers
) {
2118 int shard_id
= marker_iter
.first
;
2119 full_total
+= marker_iter
.second
.total_entries
;
2121 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2123 full_complete
+= marker_iter
.second
.pos
;
2124 shards_behind_set
.insert(shard_id
);
2126 full_complete
+= marker_iter
.second
.total_entries
;
2128 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2133 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2136 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2139 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2141 rgw_datalog_info log_info
;
2142 ret
= sync
.read_log_info(&log_info
);
2144 push_ss(ss
, status
, tab
) << string("failed to fetch local sync status: ") + cpp_strerror(-ret
);
2149 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2151 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2153 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2157 map
<int, string
> shards_behind
;
2159 for (auto local_iter
: sync_status
.sync_markers
) {
2160 int shard_id
= local_iter
.first
;
2161 auto iter
= source_shards_info
.find(shard_id
);
2163 if (iter
== source_shards_info
.end()) {
2165 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2168 auto master_marker
= iter
->second
.marker
;
2169 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2170 master_marker
> local_iter
.second
.marker
) {
2171 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2172 shards_behind_set
.insert(shard_id
);
2176 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2177 int total_recovering
= recovering_shards
.size();
2178 if (total_behind
== 0 && total_recovering
== 0) {
2179 push_ss(ss
, status
, tab
) << "data is caught up with source";
2180 } else if (total_behind
> 0) {
2181 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2183 push_ss(ss
, status
, tab
) << "behind shards: " << "[" << shards_behind_set
<< "]" ;
2185 map
<int, rgw_datalog_shard_data
> master_pos
;
2186 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2188 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2190 ceph::real_time oldest
;
2191 for (auto iter
: master_pos
) {
2192 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2194 if (!shard_data
.entries
.empty()) {
2195 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2196 if (ceph::real_clock::is_zero(oldest
)) {
2197 oldest
= entry
.timestamp
;
2198 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
) {
2199 oldest
= entry
.timestamp
;
2204 if (!ceph::real_clock::is_zero(oldest
)) {
2205 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: " << oldest
;
2210 if (total_recovering
> 0) {
2211 push_ss(ss
, status
, tab
) << total_recovering
<< " shards are recovering";
2212 push_ss(ss
, status
, tab
) << "recovering shards: " << "[" << recovering_shards
<< "]";
2215 flush_ss(ss
, status
);
2218 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2222 for (auto e
: entries
) {
2223 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2229 static void sync_status(Formatter
*formatter
)
2231 RGWRealm
& realm
= store
->realm
;
2232 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2233 RGWZone
& zone
= store
->get_zone();
2237 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2238 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2239 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2241 list
<string
> md_status
;
2243 if (store
->is_meta_master()) {
2244 md_status
.push_back("no sync (zone is master)");
2246 get_md_sync_status(md_status
);
2249 tab_dump("metadata sync", width
, md_status
);
2251 list
<string
> data_status
;
2253 for (auto iter
: store
->zone_conn_map
) {
2254 const string
& source_id
= iter
.first
;
2255 string source_str
= "source: ";
2256 string s
= source_str
+ source_id
;
2257 auto siter
= store
->zone_by_id
.find(source_id
);
2258 if (siter
!= store
->zone_by_id
.end()) {
2259 s
+= string(" (") + siter
->second
.name
+ ")";
2261 data_status
.push_back(s
);
2262 get_data_sync_status(source_id
, data_status
, source_str
.size());
2265 tab_dump("data sync", width
, data_status
);
2269 int w
; // indent width
2270 boost::string_view header
;
2271 indented(int w
, boost::string_view header
= "") : w(w
), header(header
) {}
2273 std::ostream
& operator<<(std::ostream
& out
, const indented
& h
) {
2274 return out
<< std::setw(h
.w
) << h
.header
<< std::setw(1) << ' ';
2277 static int remote_bilog_markers(RGWRados
*store
, const RGWZone
& source
,
2278 RGWRESTConn
*conn
, const RGWBucketInfo
& info
,
2279 BucketIndexShardsManager
*markers
)
2281 const auto instance_key
= info
.bucket
.get_key();
2282 const rgw_http_param_pair params
[] = {
2283 { "type" , "bucket-index" },
2284 { "bucket-instance", instance_key
.c_str() },
2285 { "info" , nullptr },
2286 { nullptr, nullptr }
2288 rgw_bucket_index_marker_info result
;
2289 int r
= conn
->get_json_resource("/admin/log/", params
, result
);
2291 lderr(store
->ctx()) << "failed to fetch remote log markers: " << cpp_strerror(r
) << dendl
;
2294 r
= markers
->from_string(result
.max_marker
, -1);
2296 lderr(store
->ctx()) << "failed to decode remote log markers" << dendl
;
2302 static int bucket_source_sync_status(RGWRados
*store
, const RGWZone
& zone
,
2303 const RGWZone
& source
, RGWRESTConn
*conn
,
2304 const RGWBucketInfo
& bucket_info
,
2305 int width
, std::ostream
& out
)
2307 out
<< indented
{width
, "source zone"} << source
.id
<< " (" << source
.name
<< ")\n";
2309 // syncing from this zone?
2310 if (!zone
.syncs_from(source
.id
)) {
2311 out
<< indented
{width
} << "not in sync_from\n";
2314 std::vector
<rgw_bucket_shard_sync_info
> status
;
2315 int r
= rgw_bucket_sync_status(store
, source
.id
, bucket_info
, &status
);
2317 lderr(store
->ctx()) << "failed to read bucket sync status: " << cpp_strerror(r
) << dendl
;
2323 uint64_t full_complete
= 0;
2324 const int total_shards
= status
.size();
2326 using BucketSyncState
= rgw_bucket_shard_sync_info::SyncState
;
2327 for (size_t shard_id
= 0; shard_id
< total_shards
; shard_id
++) {
2328 auto& m
= status
[shard_id
];
2329 if (m
.state
== BucketSyncState::StateFullSync
) {
2331 full_complete
+= m
.full_marker
.count
;
2332 } else if (m
.state
== BucketSyncState::StateIncrementalSync
) {
2337 out
<< indented
{width
} << "full sync: " << num_full
<< "/" << total_shards
<< " shards\n";
2339 out
<< indented
{width
} << "full sync: " << full_complete
<< " objects completed\n";
2341 out
<< indented
{width
} << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards\n";
2343 BucketIndexShardsManager remote_markers
;
2344 r
= remote_bilog_markers(store
, source
, conn
, bucket_info
, &remote_markers
);
2346 lderr(store
->ctx()) << "failed to read remote log: " << cpp_strerror(r
) << dendl
;
2350 std::set
<int> shards_behind
;
2351 for (auto& r
: remote_markers
.get()) {
2352 auto shard_id
= r
.first
;
2353 auto& m
= status
[shard_id
];
2354 if (r
.second
.empty()) {
2355 continue; // empty bucket index shard
2357 auto pos
= BucketIndexShardsManager::get_shard_marker(m
.inc_marker
.position
);
2358 if (m
.state
!= BucketSyncState::StateIncrementalSync
|| pos
!= r
.second
) {
2359 shards_behind
.insert(shard_id
);
2362 if (shards_behind
.empty()) {
2363 out
<< indented
{width
} << "bucket is caught up with source\n";
2365 out
<< indented
{width
} << "bucket is behind on " << shards_behind
.size() << " shards\n";
2366 out
<< indented
{width
} << "behind shards: [" << shards_behind
<< "]\n" ;
2371 static int bucket_sync_status(RGWRados
*store
, const RGWBucketInfo
& info
,
2372 const std::string
& source_zone_id
,
2375 RGWRealm
& realm
= store
->realm
;
2376 RGWZoneGroup
& zonegroup
= store
->get_zonegroup();
2377 RGWZone
& zone
= store
->get_zone();
2378 constexpr int width
= 15;
2380 out
<< indented
{width
, "realm"} << realm
.get_id() << " (" << realm
.get_name() << ")\n";
2381 out
<< indented
{width
, "zonegroup"} << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")\n";
2382 out
<< indented
{width
, "zone"} << zone
.id
<< " (" << zone
.name
<< ")\n";
2383 out
<< indented
{width
, "bucket"} << info
.bucket
<< "\n\n";
2385 if (!info
.datasync_flag_enabled()) {
2386 out
<< "Sync is disabled for bucket " << info
.bucket
.name
<< '\n';
2390 if (!source_zone_id
.empty()) {
2391 auto z
= zonegroup
.zones
.find(source_zone_id
);
2392 if (z
== zonegroup
.zones
.end()) {
2393 lderr(store
->ctx()) << "Source zone not found in zonegroup "
2394 << zonegroup
.get_name() << dendl
;
2397 auto c
= store
->zone_conn_map
.find(source_zone_id
);
2398 if (c
== store
->zone_conn_map
.end()) {
2399 lderr(store
->ctx()) << "No connection to zone " << z
->second
.name
<< dendl
;
2402 return bucket_source_sync_status(store
, zone
, z
->second
, c
->second
,
2406 for (const auto& z
: zonegroup
.zones
) {
2407 auto c
= store
->zone_conn_map
.find(z
.second
.id
);
2408 if (c
!= store
->zone_conn_map
.end()) {
2409 bucket_source_sync_status(store
, zone
, z
.second
, c
->second
,
2416 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2419 get_str_list(s
, ",", confs
);
2420 for (auto c
: confs
) {
2421 ssize_t pos
= c
.find("=");
2425 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2430 int check_reshard_bucket_params(RGWRados
*store
,
2431 const string
& bucket_name
,
2432 const string
& tenant
,
2433 const string
& bucket_id
,
2434 bool num_shards_specified
,
2436 int yes_i_really_mean_it
,
2438 RGWBucketInfo
& bucket_info
,
2439 map
<string
, bufferlist
>& attrs
)
2441 if (bucket_name
.empty()) {
2442 cerr
<< "ERROR: bucket not specified" << std::endl
;
2446 if (!num_shards_specified
) {
2447 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2451 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2452 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2456 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2458 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2462 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2464 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2465 cerr
<< "num shards is less or equal to current shards count" << std::endl
2466 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2472 int create_new_bucket_instance(RGWRados
*store
,
2474 const RGWBucketInfo
& bucket_info
,
2475 map
<string
, bufferlist
>& attrs
,
2476 RGWBucketInfo
& new_bucket_info
)
2479 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2480 new_bucket_info
.bucket
.oid
.clear();
2482 new_bucket_info
.num_shards
= new_num_shards
;
2483 new_bucket_info
.objv_tracker
.clear();
2485 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2487 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2491 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2493 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2501 int main(int argc
, const char **argv
)
2503 vector
<const char*> args
;
2504 argv_to_vec(argc
, (const char **)argv
, args
);
2507 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2508 CODE_ENVIRONMENT_UTILITY
, 0);
2510 // for region -> zonegroup conversion (must happen before common_init_finish())
2511 if (!g_conf
->rgw_region
.empty() && g_conf
->rgw_zonegroup
.empty()) {
2512 g_conf
->set_val_or_die("rgw_zonegroup", g_conf
->rgw_region
.c_str());
2515 common_init_finish(g_ceph_context
);
2519 std::string access_key
, secret_key
, user_email
, display_name
;
2520 std::string bucket_name
, pool_name
, object
;
2522 std::string date
, subuser
, access
, format
;
2523 std::string start_date
, end_date
;
2524 std::string key_type_str
;
2525 std::string period_id
, period_epoch
, remote
, url
;
2526 std::string master_zonegroup
, master_zone
;
2527 std::string realm_name
, realm_id
, realm_new_name
;
2528 std::string zone_name
, zone_id
, zone_new_name
;
2529 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2530 std::string api_name
;
2531 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2532 list
<string
> endpoints
;
2534 int sync_from_all_specified
= false;
2535 bool sync_from_all
= false;
2536 list
<string
> sync_from
;
2537 list
<string
> sync_from_rm
;
2538 std::string master_url
;
2540 int set_default
= 0;
2541 bool is_master
= false;
2542 bool is_master_set
= false;
2544 bool read_only
= false;
2545 int is_read_only_set
= false;
2547 int staging
= false;
2548 int key_type
= KEY_TYPE_UNDEFINED
;
2550 uint32_t perm_mask
= 0;
2552 int opt_cmd
= OPT_NO_CMD
;
2554 int gen_access_key
= 0;
2555 int gen_secret_key
= 0;
2556 bool set_perm
= false;
2557 bool set_temp_url_key
= false;
2558 map
<int, string
> temp_url_keys
;
2560 Formatter
*formatter
= NULL
;
2561 int purge_data
= false;
2562 int pretty_format
= false;
2563 int show_log_entries
= true;
2564 int show_log_sum
= true;
2565 int skip_zero_entries
= false; // log show
2566 int purge_keys
= false;
2567 int yes_i_really_mean_it
= false;
2568 int delete_child_objects
= false;
2570 int remove_bad
= false;
2571 int check_head_obj_locator
= false;
2572 int max_buckets
= -1;
2573 bool max_buckets_specified
= false;
2574 map
<string
, bool> categories
;
2576 int check_objects
= false;
2577 RGWUserAdminOpState user_op
;
2578 RGWBucketAdminOpState bucket_op
;
2580 string metadata_key
;
2581 RGWObjVersionTracker objv_tracker
;
2583 string start_marker
;
2585 int max_entries
= -1;
2586 bool max_entries_specified
= false;
2588 bool admin_specified
= false;
2590 bool system_specified
= false;
2592 bool specified_shard_id
= false;
2594 bool specified_daemon_id
= false;
2598 string replica_log_type_str
;
2599 ReplicaLogType replica_log_type
= ReplicaLog_Invalid
;
2602 string object_version
;
2603 string placement_id
;
2605 list
<string
> tags_add
;
2606 list
<string
> tags_rm
;
2608 int64_t max_objects
= -1;
2609 int64_t max_size
= -1;
2610 bool have_max_objects
= false;
2611 bool have_max_size
= false;
2612 int include_all
= false;
2614 int sync_stats
= false;
2615 int reset_stats
= false;
2616 int bypass_gc
= false;
2617 int warnings_only
= false;
2618 int inconsistent_index
= false;
2620 int verbose
= false;
2622 int extra_info
= false;
2624 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2625 uint64_t max_rewrite_size
= ULLONG_MAX
;
2626 uint64_t min_rewrite_stripe_size
= 0;
2628 BIIndexType bi_index_type
= PlainIdx
;
2632 bool num_shards_specified
= false;
2633 int max_concurrent_ios
= 32;
2634 uint64_t orphan_stale_secs
= (24 * 3600);
2637 std::ostringstream errs
;
2641 string source_zone_name
;
2642 string source_zone
; /* zone id */
2645 bool tier_type_specified
= false;
2647 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2648 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2650 boost::optional
<string
> index_pool
;
2651 boost::optional
<string
> data_pool
;
2652 boost::optional
<string
> data_extra_pool
;
2653 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2654 bool index_type_specified
= false;
2656 boost::optional
<std::string
> compression_type
;
2658 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2659 if (ceph_argparse_double_dash(args
, i
)) {
2661 } else if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
2664 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2665 user_id
.from_str(val
);
2666 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2668 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2670 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2672 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2674 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2676 user_op
.user_email_specified
=true;
2677 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2679 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2681 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2683 pool
= rgw_pool(pool_name
);
2684 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2686 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2687 object_version
= val
;
2688 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2690 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2692 } else if (ceph_argparse_witharg(args
, i
, &val
, "--state", (char*)NULL
)) {
2694 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2696 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2698 if (key_type_str
.compare("swift") == 0) {
2699 key_type
= KEY_TYPE_SWIFT
;
2700 } else if (key_type_str
.compare("s3") == 0) {
2701 key_type
= KEY_TYPE_S3
;
2703 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2707 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2709 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2711 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2713 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show_log_entries", (char*)NULL
)) {
2715 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show_log_sum", (char*)NULL
)) {
2717 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip_zero_entries", (char*)NULL
)) {
2719 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2720 admin_specified
= true;
2721 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2722 system_specified
= true;
2723 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2725 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2727 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2729 } else if (ceph_argparse_witharg(args
, i
, &tmp
, errs
, "-a", "--auth-uid", (char*)NULL
)) {
2730 if (!errs
.str().empty()) {
2731 cerr
<< errs
.str() << std::endl
;
2734 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2735 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2736 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2737 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2738 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2739 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2740 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2741 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2743 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2746 max_buckets_specified
= true;
2747 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2748 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2749 max_entries_specified
= true;
2751 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
2754 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
2755 max_size
= strict_iecstrtoll(val
.c_str(), &err
);
2757 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
2760 have_max_size
= true;
2761 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
2762 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
2764 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
2767 have_max_objects
= true;
2768 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
2770 if (end_date
.empty())
2772 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
2774 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
2776 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
2777 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
2779 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
2782 num_shards_specified
= true;
2783 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
2784 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
2786 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
2789 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
2790 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
2792 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
2795 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
2796 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
2798 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
2801 specified_shard_id
= true;
2802 } else if (ceph_argparse_witharg(args
, i
, &val
, "--daemon-id", (char*)NULL
)) {
2804 specified_daemon_id
= true;
2805 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
2807 perm_mask
= rgw_str_to_perm(access
.c_str());
2809 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
2810 temp_url_keys
[0] = val
;
2811 set_temp_url_key
= true;
2812 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
2813 temp_url_keys
[1] = val
;
2814 set_temp_url_key
= true;
2815 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
2817 if (bucket_id
.empty()) {
2818 cerr
<< "bad bucket-id" << std::endl
;
2822 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
2824 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
2825 string cat_str
= val
;
2826 list
<string
> cat_list
;
2827 list
<string
>::iterator iter
;
2828 get_str_list(cat_str
, cat_list
);
2829 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
2830 categories
[*iter
] = true;
2832 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
2834 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
2836 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
2837 delete_child_objects
= purge_data
;
2838 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
2840 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
2842 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
2844 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
2846 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
2848 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
2850 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
2852 } else if (ceph_argparse_binary_flag(args
, i
, &reset_stats
, NULL
, "--reset-stats", (char*)NULL
)) {
2854 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
2856 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
2858 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
2860 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
2862 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
2864 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
2866 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
2868 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
2870 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
2872 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
2874 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
2876 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
2878 } else if (ceph_argparse_witharg(args
, i
, &val
, "--replica-log-type", (char*)NULL
)) {
2879 replica_log_type_str
= val
;
2880 replica_log_type
= get_replicalog_type(replica_log_type_str
);
2881 if (replica_log_type
== ReplicaLog_Invalid
) {
2882 cerr
<< "ERROR: invalid replica log type" << std::endl
;
2885 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
2886 string index_type_str
= val
;
2887 bi_index_type
= get_bi_index_type(index_type_str
);
2888 if (bi_index_type
== InvalidIdx
) {
2889 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
2892 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
2893 is_master
= (bool)is_master_int
;
2894 is_master_set
= true;
2895 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
2897 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
2898 read_only
= (bool)read_only_int
;
2899 is_read_only_set
= true;
2900 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-url", (char*)NULL
)) {
2902 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zonegroup", (char*)NULL
)) {
2903 master_zonegroup
= val
;
2904 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
2906 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
2908 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
2910 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
2912 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
2914 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
2916 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
2917 realm_new_name
= val
;
2918 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
2920 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
2921 zonegroup_new_name
= val
;
2922 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
2924 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
2925 get_str_list(val
, tags
);
2926 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
2927 get_str_list(val
, tags_add
);
2928 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
2929 get_str_list(val
, tags_rm
);
2930 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
2932 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
2934 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
2935 zone_new_name
= val
;
2936 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
2937 get_str_list(val
, endpoints
);
2938 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
2939 get_str_list(val
, sync_from
);
2940 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
2941 get_str_list(val
, sync_from_rm
);
2942 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
2943 sync_from_all
= (bool)tmp_int
;
2944 sync_from_all_specified
= true;
2945 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
2946 source_zone_name
= val
;
2947 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
2949 tier_type_specified
= true;
2950 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
2951 parse_tier_config_param(val
, tier_config_add
);
2952 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
2953 parse_tier_config_param(val
, tier_config_rm
);
2954 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
2956 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
2958 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
2959 data_extra_pool
= val
;
2960 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
2961 if (val
== "normal") {
2962 placement_index_type
= RGWBIType_Normal
;
2963 } else if (val
== "indexless") {
2964 placement_index_type
= RGWBIType_Indexless
;
2966 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
2968 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
2972 index_type_specified
= true;
2973 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
2974 compression_type
= val
;
2975 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
2977 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
2979 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
2980 assume_role_doc
= val
;
2981 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
2983 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
2984 perm_policy_doc
= val
;
2985 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
2987 } else if (strncmp(*i
, "-", 1) == 0) {
2988 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
3000 const char *prev_cmd
= NULL
;
3001 const char *prev_prev_cmd
= NULL
;
3002 std::vector
<const char*>::iterator i
;
3003 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
3004 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
3006 cerr
<< "unrecognized arg " << *i
<< std::endl
;
3014 prev_prev_cmd
= prev_cmd
;
3018 if (opt_cmd
== OPT_NO_CMD
) {
3023 /* some commands may have an optional extra param */
3024 if (i
!= args
.end()) {
3026 case OPT_METADATA_GET
:
3027 case OPT_METADATA_PUT
:
3028 case OPT_METADATA_RM
:
3029 case OPT_METADATA_LIST
:
3037 if (tenant
.empty()) {
3038 tenant
= user_id
.tenant
;
3040 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
3041 && opt_cmd
!= OPT_ROLE_DELETE
3042 && opt_cmd
!= OPT_ROLE_GET
3043 && opt_cmd
!= OPT_ROLE_MODIFY
3044 && opt_cmd
!= OPT_ROLE_LIST
3045 && opt_cmd
!= OPT_ROLE_POLICY_PUT
3046 && opt_cmd
!= OPT_ROLE_POLICY_LIST
3047 && opt_cmd
!= OPT_ROLE_POLICY_GET
3048 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
3049 && opt_cmd
!= OPT_RESHARD_ADD
3050 && opt_cmd
!= OPT_RESHARD_CANCEL
3051 && opt_cmd
!= OPT_RESHARD_STATUS
) {
3052 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
3055 user_id
.tenant
= tenant
;
3057 /* check key parameter conflict */
3058 if ((!access_key
.empty()) && gen_access_key
) {
3059 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
3062 if ((!secret_key
.empty()) && gen_secret_key
) {
3063 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
3068 // default to pretty json
3069 if (format
.empty()) {
3071 pretty_format
= true;
3074 if (format
== "xml")
3075 formatter
= new XMLFormatter(pretty_format
);
3076 else if (format
== "json")
3077 formatter
= new JSONFormatter(pretty_format
);
3079 cerr
<< "unrecognized format: " << format
<< std::endl
;
3084 realm_name
= g_conf
->rgw_realm
;
3085 zone_name
= g_conf
->rgw_zone
;
3086 zonegroup_name
= g_conf
->rgw_zonegroup
;
3088 RGWStreamFlusher
f(formatter
, cout
);
3090 // not a raw op if 'period update' needs to commit to master
3091 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
3092 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
3093 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
3094 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
3095 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
3096 OPT_ZONEGROUP_REMOVE
,
3097 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
3098 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
3099 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
3100 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
3101 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
3102 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
3103 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
3104 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
3106 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
3108 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
3109 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
3110 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
3111 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
3112 OPT_REALM_LIST_PERIODS
,
3113 OPT_REALM_GET_DEFAULT
, OPT_REALM_REMOVE
,
3114 OPT_REALM_RENAME
, OPT_REALM_SET
,
3115 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
3117 std::set
<int> readonly_ops_list
= {
3121 OPT_BUCKET_LIMIT_CHECK
,
3123 OPT_BUCKET_SYNC_STATUS
,
3134 OPT_ORPHANS_LIST_JOBS
,
3137 OPT_ZONEGROUP_PLACEMENT_LIST
,
3140 OPT_ZONE_PLACEMENT_LIST
,
3143 OPT_METADATA_SYNC_STATUS
,
3146 OPT_SYNC_ERROR_LIST
,
3149 OPT_DATA_SYNC_STATUS
,
3155 OPT_REALM_GET_DEFAULT
,
3157 OPT_REALM_LIST_PERIODS
,
3159 OPT_PERIOD_GET_CURRENT
,
3161 OPT_GLOBAL_QUOTA_GET
,
3165 OPT_ROLE_POLICY_LIST
,
3166 OPT_ROLE_POLICY_GET
,
3171 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
3173 bool need_cache
= readonly_ops_list
.find(opt_cmd
) == readonly_ops_list
.end();
3175 if (raw_storage_op
) {
3176 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
3178 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false,
3179 need_cache
&& g_conf
->rgw_cache_enabled
);
3182 cerr
<< "couldn't init storage provider" << std::endl
;
3186 if (!source_zone_name
.empty()) {
3187 if (!store
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
3188 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
3189 source_zone
= source_zone_name
;
3193 rgw_user_init(store
);
3194 rgw_bucket_init(store
->meta_mgr
);
3196 struct rgw_curl_setup
{
3198 rgw::curl::setup_curl(boost::none
);
3201 rgw::curl::cleanup_curl();
3205 StoreDestructor
store_destructor(store
);
3207 if (raw_storage_op
) {
3209 case OPT_PERIOD_DELETE
:
3211 if (period_id
.empty()) {
3212 cerr
<< "missing period id" << std::endl
;
3215 RGWPeriod
period(period_id
);
3216 int ret
= period
.init(g_ceph_context
, store
);
3218 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
3221 ret
= period
.delete_obj();
3223 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
3229 case OPT_PERIOD_GET
:
3232 if (!period_epoch
.empty()) {
3233 epoch
= atoi(period_epoch
.c_str());
3236 RGWRealm
realm(realm_id
, realm_name
);
3237 int ret
= realm
.init(g_ceph_context
, store
);
3239 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
3242 realm_id
= realm
.get_id();
3243 realm_name
= realm
.get_name();
3244 period_id
= RGWPeriod::get_staging_id(realm_id
);
3247 RGWPeriod
period(period_id
, epoch
);
3248 int ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
);
3250 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
3253 encode_json("period", period
, formatter
);
3254 formatter
->flush(cout
);
3258 case OPT_PERIOD_GET_CURRENT
:
3260 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3264 formatter
->open_object_section("period_get_current");
3265 encode_json("current_period", period_id
, formatter
);
3266 formatter
->close_section();
3267 formatter
->flush(cout
);
3270 case OPT_PERIOD_LIST
:
3272 list
<string
> periods
;
3273 int ret
= store
->list_periods(periods
);
3275 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
3278 formatter
->open_object_section("periods_list");
3279 encode_json("periods", periods
, formatter
);
3280 formatter
->close_section();
3281 formatter
->flush(cout
);
3285 case OPT_PERIOD_UPDATE
:
3287 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
3288 commit
, remote
, url
, access_key
, secret_key
,
3289 formatter
, yes_i_really_mean_it
);
3295 case OPT_PERIOD_PULL
:
3297 boost::optional
<RGWRESTConn
> conn
;
3298 RGWRESTConn
*remote_conn
= nullptr;
3300 // load current period for endpoints
3301 RGWRealm
realm(realm_id
, realm_name
);
3302 int ret
= realm
.init(g_ceph_context
, store
);
3304 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3307 RGWPeriod
current_period(realm
.get_current_period());
3308 ret
= current_period
.init(g_ceph_context
, store
);
3310 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
3313 if (remote
.empty()) {
3314 // use realm master zone as remote
3315 remote
= current_period
.get_master_zone();
3317 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
3319 cerr
<< "failed to find a zone or zonegroup for remote "
3320 << remote
<< std::endl
;
3323 remote_conn
= &*conn
;
3327 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3328 realm_id
, realm_name
, period_id
, period_epoch
,
3331 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3335 encode_json("period", period
, formatter
);
3336 formatter
->flush(cout
);
3340 case OPT_GLOBAL_QUOTA_GET
:
3341 case OPT_GLOBAL_QUOTA_SET
:
3342 case OPT_GLOBAL_QUOTA_ENABLE
:
3343 case OPT_GLOBAL_QUOTA_DISABLE
:
3345 if (realm_id
.empty()) {
3346 RGWRealm
realm(g_ceph_context
, store
);
3347 if (!realm_name
.empty()) {
3348 // look up realm_id for the given realm_name
3349 int ret
= realm
.read_id(realm_name
, realm_id
);
3351 cerr
<< "ERROR: failed to read realm for " << realm_name
3352 << ": " << cpp_strerror(-ret
) << std::endl
;
3356 // use default realm_id when none is given
3357 int ret
= realm
.read_default_id(realm_id
);
3358 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3359 cerr
<< "ERROR: failed to read default realm: "
3360 << cpp_strerror(-ret
) << std::endl
;
3366 RGWPeriodConfig period_config
;
3367 int ret
= period_config
.read(store
, realm_id
);
3368 if (ret
< 0 && ret
!= -ENOENT
) {
3369 cerr
<< "ERROR: failed to read period config: "
3370 << cpp_strerror(-ret
) << std::endl
;
3374 formatter
->open_object_section("period_config");
3375 if (quota_scope
== "bucket") {
3376 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3377 max_size
, max_objects
,
3378 have_max_size
, have_max_objects
);
3379 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3380 } else if (quota_scope
== "user") {
3381 set_quota_info(period_config
.user_quota
, opt_cmd
,
3382 max_size
, max_objects
,
3383 have_max_size
, have_max_objects
);
3384 encode_json("user quota", period_config
.user_quota
, formatter
);
3385 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3386 // if no scope is given for GET, print both
3387 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3388 encode_json("user quota", period_config
.user_quota
, formatter
);
3390 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3391 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3394 formatter
->close_section();
3396 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3397 // write the modified period config
3398 ret
= period_config
.write(store
, realm_id
);
3400 cerr
<< "ERROR: failed to write period config: "
3401 << cpp_strerror(-ret
) << std::endl
;
3404 if (!realm_id
.empty()) {
3405 cout
<< "Global quota changes saved. Use 'period update' to apply "
3406 "them to the staging period, and 'period commit' to commit the "
3407 "new period." << std::endl
;
3409 cout
<< "Global quota changes saved. They will take effect as "
3410 "the gateways are restarted." << std::endl
;
3414 formatter
->flush(cout
);
3418 case OPT_REALM_CREATE
:
3420 if (realm_name
.empty()) {
3421 cerr
<< "missing realm name" << std::endl
;
3425 RGWRealm
realm(realm_name
, g_ceph_context
, store
);
3426 int ret
= realm
.create();
3428 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3433 ret
= realm
.set_as_default();
3435 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3439 encode_json("realm", realm
, formatter
);
3440 formatter
->flush(cout
);
3444 case OPT_REALM_DELETE
:
3446 RGWRealm
realm(realm_id
, realm_name
);
3447 if (realm_name
.empty() && realm_id
.empty()) {
3448 cerr
<< "missing realm name or id" << std::endl
;
3451 int ret
= realm
.init(g_ceph_context
, store
);
3453 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3456 ret
= realm
.delete_obj();
3458 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3466 RGWRealm
realm(realm_id
, realm_name
);
3467 int ret
= realm
.init(g_ceph_context
, store
);
3469 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3470 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3472 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3476 encode_json("realm", realm
, formatter
);
3477 formatter
->flush(cout
);
3481 case OPT_REALM_GET_DEFAULT
:
3483 RGWRealm
realm(g_ceph_context
, store
);
3485 int ret
= realm
.read_default_id(default_id
);
3486 if (ret
== -ENOENT
) {
3487 cout
<< "No default realm is set" << std::endl
;
3489 } else if (ret
< 0) {
3490 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3493 cout
<< "default realm: " << default_id
<< std::endl
;
3496 case OPT_REALM_LIST
:
3498 RGWRealm
realm(g_ceph_context
, store
);
3500 int ret
= realm
.read_default_id(default_id
);
3501 if (ret
< 0 && ret
!= -ENOENT
) {
3502 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3504 list
<string
> realms
;
3505 ret
= store
->list_realms(realms
);
3507 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3510 formatter
->open_object_section("realms_list");
3511 encode_json("default_info", default_id
, formatter
);
3512 encode_json("realms", realms
, formatter
);
3513 formatter
->close_section();
3514 formatter
->flush(cout
);
3518 case OPT_REALM_LIST_PERIODS
:
3520 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3524 list
<string
> periods
;
3525 ret
= store
->list_periods(period_id
, periods
);
3527 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3530 formatter
->open_object_section("realm_periods_list");
3531 encode_json("current_period", period_id
, formatter
);
3532 encode_json("periods", periods
, formatter
);
3533 formatter
->close_section();
3534 formatter
->flush(cout
);
3539 case OPT_REALM_RENAME
:
3541 RGWRealm
realm(realm_id
, realm_name
);
3542 if (realm_new_name
.empty()) {
3543 cerr
<< "missing realm new name" << std::endl
;
3546 if (realm_name
.empty() && realm_id
.empty()) {
3547 cerr
<< "missing realm name or id" << std::endl
;
3550 int ret
= realm
.init(g_ceph_context
, store
);
3552 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3555 ret
= realm
.rename(realm_new_name
);
3557 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3560 cout
<< "Realm name updated. Note that this change only applies to "
3561 "the current cluster, so this command must be run separately "
3562 "on each of the realm's other clusters." << std::endl
;
3567 if (realm_id
.empty() && realm_name
.empty()) {
3568 cerr
<< "no realm name or id provided" << std::endl
;
3571 RGWRealm
realm(realm_id
, realm_name
);
3572 bool new_realm
= false;
3573 int ret
= realm
.init(g_ceph_context
, store
);
3574 if (ret
< 0 && ret
!= -ENOENT
) {
3575 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3577 } else if (ret
== -ENOENT
) {
3580 ret
= read_decode_json(infile
, realm
);
3584 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3585 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3586 realm
.get_name() << std::endl
;
3591 cout
<< "clearing period and epoch for new realm" << std::endl
;
3592 realm
.clear_current_period_and_epoch();
3593 ret
= realm
.create();
3595 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3599 ret
= realm
.update();
3601 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3607 ret
= realm
.set_as_default();
3609 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3612 encode_json("realm", realm
, formatter
);
3613 formatter
->flush(cout
);
3617 case OPT_REALM_DEFAULT
:
3619 RGWRealm
realm(realm_id
, realm_name
);
3620 int ret
= realm
.init(g_ceph_context
, store
);
3622 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3625 ret
= realm
.set_as_default();
3627 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3632 case OPT_REALM_PULL
:
3635 cerr
<< "A --url must be provided." << std::endl
;
3639 req_info
info(g_ceph_context
, &env
);
3640 info
.method
= "GET";
3641 info
.request_uri
= "/admin/realm";
3643 map
<string
, string
> ¶ms
= info
.args
.get_params();
3644 if (!realm_id
.empty())
3645 params
["id"] = realm_id
;
3646 if (!realm_name
.empty())
3647 params
["name"] = realm_name
;
3651 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3653 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3654 if (ret
== -EACCES
) {
3655 cerr
<< "If the realm has been changed on the master zone, the "
3656 "master zone's gateway may need to be restarted to recognize "
3657 "this user." << std::endl
;
3662 realm
.init(g_ceph_context
, store
, false);
3664 decode_json_obj(realm
, &p
);
3665 } catch (JSONDecoder::err
& e
) {
3666 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3670 auto& current_period
= realm
.get_current_period();
3671 if (!current_period
.empty()) {
3672 // pull the latest epoch of the realm's current period
3673 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3674 realm_id
, realm_name
, current_period
, "",
3677 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3681 ret
= realm
.create(false);
3682 if (ret
< 0 && ret
!= -EEXIST
) {
3683 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3684 << cpp_strerror(ret
) << std::endl
;
3686 } else if (ret
==-EEXIST
) {
3687 ret
= realm
.update();
3689 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3690 << cpp_strerror(ret
) << std::endl
;
3695 ret
= realm
.set_as_default();
3697 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3701 encode_json("realm", realm
, formatter
);
3702 formatter
->flush(cout
);
3707 case OPT_ZONEGROUP_ADD
:
3709 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3710 cerr
<< "no zonegroup name or id provided" << std::endl
;
3714 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3715 int ret
= zonegroup
.init(g_ceph_context
, store
);
3717 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3718 << cpp_strerror(-ret
) << std::endl
;
3721 RGWZoneParams
zone(zone_id
, zone_name
);
3722 ret
= zone
.init(g_ceph_context
, store
);
3724 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3727 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3728 zone
.realm_id
= zonegroup
.realm_id
;
3729 ret
= zone
.update();
3731 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
3736 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
3737 zone
.tier_config
= tier_config_add
;
3739 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
3741 ret
= zonegroup
.add_zone(zone
,
3742 (is_master_set
? &is_master
: NULL
),
3743 (is_read_only_set
? &read_only
: NULL
),
3744 endpoints
, ptier_type
,
3745 psync_from_all
, sync_from
, sync_from_rm
);
3747 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
3748 << cpp_strerror(-ret
) << std::endl
;
3752 encode_json("zonegroup", zonegroup
, formatter
);
3753 formatter
->flush(cout
);
3756 case OPT_ZONEGROUP_CREATE
:
3758 if (zonegroup_name
.empty()) {
3759 cerr
<< "Missing zonegroup name" << std::endl
;
3762 RGWRealm
realm(realm_id
, realm_name
);
3763 int ret
= realm
.init(g_ceph_context
, store
);
3765 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3769 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
, realm
.get_id(), endpoints
);
3770 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
3771 ret
= zonegroup
.create();
3773 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3778 ret
= zonegroup
.set_as_default();
3780 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3784 encode_json("zonegroup", zonegroup
, formatter
);
3785 formatter
->flush(cout
);
3789 case OPT_ZONEGROUP_DEFAULT
:
3791 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3792 cerr
<< "no zonegroup name or id provided" << std::endl
;
3796 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3797 int ret
= zonegroup
.init(g_ceph_context
, store
);
3799 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3803 ret
= zonegroup
.set_as_default();
3805 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
3810 case OPT_ZONEGROUP_DELETE
:
3812 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3813 cerr
<< "no zonegroup name or id provided" << std::endl
;
3816 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3817 int ret
= zonegroup
.init(g_ceph_context
, store
);
3819 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3822 ret
= zonegroup
.delete_obj();
3824 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3829 case OPT_ZONEGROUP_GET
:
3831 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3832 int ret
= zonegroup
.init(g_ceph_context
, store
);
3834 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3838 encode_json("zonegroup", zonegroup
, formatter
);
3839 formatter
->flush(cout
);
3843 case OPT_ZONEGROUP_LIST
:
3845 RGWZoneGroup zonegroup
;
3846 int ret
= zonegroup
.init(g_ceph_context
, store
, false);
3848 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3852 list
<string
> zonegroups
;
3853 ret
= store
->list_zonegroups(zonegroups
);
3855 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
3858 string default_zonegroup
;
3859 ret
= zonegroup
.read_default_id(default_zonegroup
);
3860 if (ret
< 0 && ret
!= -ENOENT
) {
3861 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3863 formatter
->open_object_section("zonegroups_list");
3864 encode_json("default_info", default_zonegroup
, formatter
);
3865 encode_json("zonegroups", zonegroups
, formatter
);
3866 formatter
->close_section();
3867 formatter
->flush(cout
);
3871 case OPT_ZONEGROUP_MODIFY
:
3873 RGWRealm
realm(realm_id
, realm_name
);
3874 int ret
= realm
.init(g_ceph_context
, store
);
3876 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3880 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3881 ret
= zonegroup
.init(g_ceph_context
, store
);
3883 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3887 bool need_update
= false;
3889 if (!master_zone
.empty()) {
3890 zonegroup
.master_zone
= master_zone
;
3894 if (is_master_set
) {
3895 zonegroup
.update_master(is_master
);
3899 if (!endpoints
.empty()) {
3900 zonegroup
.endpoints
= endpoints
;
3904 if (!api_name
.empty()) {
3905 zonegroup
.api_name
= api_name
;
3909 if (!realm_id
.empty()) {
3910 zonegroup
.realm_id
= realm_id
;
3912 } else if (!realm_name
.empty()) {
3913 // get realm id from name
3914 RGWRealm realm
{g_ceph_context
, store
};
3915 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
3917 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
3924 ret
= zonegroup
.update();
3926 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3932 ret
= zonegroup
.set_as_default();
3934 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3938 encode_json("zonegroup", zonegroup
, formatter
);
3939 formatter
->flush(cout
);
3942 case OPT_ZONEGROUP_SET
:
3944 RGWRealm
realm(realm_id
, realm_name
);
3945 int ret
= realm
.init(g_ceph_context
, store
);
3946 bool default_realm_not_exist
= (ret
== -ENOENT
&& realm_id
.empty() && realm_name
.empty());
3948 if (ret
< 0 && !default_realm_not_exist
) {
3949 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3953 RGWZoneGroup zonegroup
;
3954 ret
= zonegroup
.init(g_ceph_context
, store
, false);
3956 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3959 ret
= read_decode_json(infile
, zonegroup
);
3963 if (zonegroup
.realm_id
.empty() && !default_realm_not_exist
) {
3964 zonegroup
.realm_id
= realm
.get_id();
3966 ret
= zonegroup
.create();
3967 if (ret
< 0 && ret
!= -EEXIST
) {
3968 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3970 } else if (ret
== -EEXIST
) {
3971 ret
= zonegroup
.update();
3973 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
3979 ret
= zonegroup
.set_as_default();
3981 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3985 encode_json("zonegroup", zonegroup
, formatter
);
3986 formatter
->flush(cout
);
3989 case OPT_ZONEGROUP_REMOVE
:
3991 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
3992 int ret
= zonegroup
.init(g_ceph_context
, store
);
3994 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
3998 if (zone_id
.empty()) {
3999 if (zone_name
.empty()) {
4000 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
4003 // look up zone id by name
4004 for (auto& z
: zonegroup
.zones
) {
4005 if (zone_name
== z
.second
.name
) {
4006 zone_id
= z
.second
.id
;
4010 if (zone_id
.empty()) {
4011 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
4012 << zonegroup
.get_name() << std::endl
;
4017 ret
= zonegroup
.remove_zone(zone_id
);
4019 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
4023 encode_json("zonegroup", zonegroup
, formatter
);
4024 formatter
->flush(cout
);
4027 case OPT_ZONEGROUP_RENAME
:
4029 if (zonegroup_new_name
.empty()) {
4030 cerr
<< " missing zonegroup new name" << std::endl
;
4033 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
4034 cerr
<< "no zonegroup name or id provided" << std::endl
;
4037 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4038 int ret
= zonegroup
.init(g_ceph_context
, store
);
4040 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4043 ret
= zonegroup
.rename(zonegroup_new_name
);
4045 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4050 case OPT_ZONEGROUP_PLACEMENT_LIST
:
4052 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4053 int ret
= zonegroup
.init(g_ceph_context
, store
);
4055 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4059 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
4060 formatter
->flush(cout
);
4064 case OPT_ZONEGROUP_PLACEMENT_ADD
:
4065 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
4066 case OPT_ZONEGROUP_PLACEMENT_RM
:
4067 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
4069 if (placement_id
.empty()) {
4070 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4074 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4075 int ret
= zonegroup
.init(g_ceph_context
, store
);
4077 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4081 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
) {
4082 RGWZoneGroupPlacementTarget target
;
4083 target
.name
= placement_id
;
4084 for (auto& t
: tags
) {
4085 target
.tags
.insert(t
);
4087 zonegroup
.placement_targets
[placement_id
] = target
;
4088 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
4089 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
4090 if (!tags
.empty()) {
4091 target
.tags
.clear();
4092 for (auto& t
: tags
) {
4093 target
.tags
.insert(t
);
4096 target
.name
= placement_id
;
4097 for (auto& t
: tags_rm
) {
4098 target
.tags
.erase(t
);
4100 for (auto& t
: tags_add
) {
4101 target
.tags
.insert(t
);
4103 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
4104 zonegroup
.placement_targets
.erase(placement_id
);
4105 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
4106 if (!zonegroup
.placement_targets
.count(placement_id
)) {
4107 cerr
<< "failed to find a zonegroup placement target named '"
4108 << placement_id
<< "'" << std::endl
;
4111 zonegroup
.default_placement
= placement_id
;
4114 zonegroup
.post_process_params();
4115 ret
= zonegroup
.update();
4117 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4121 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
4122 formatter
->flush(cout
);
4125 case OPT_ZONE_CREATE
:
4127 if (zone_name
.empty()) {
4128 cerr
<< "zone name not provided" << std::endl
;
4132 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4133 /* if the user didn't provide zonegroup info , create stand alone zone */
4134 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
4135 ret
= zonegroup
.init(g_ceph_context
, store
);
4137 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4140 if (realm_id
.empty() && realm_name
.empty()) {
4141 realm_id
= zonegroup
.realm_id
;
4145 RGWZoneParams
zone(zone_id
, zone_name
);
4146 ret
= zone
.init(g_ceph_context
, store
, false);
4148 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4152 zone
.system_key
.id
= access_key
;
4153 zone
.system_key
.key
= secret_key
;
4154 zone
.realm_id
= realm_id
;
4155 zone
.tier_config
= tier_config_add
;
4157 ret
= zone
.create();
4159 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4163 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
4164 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4165 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4166 ret
= zonegroup
.add_zone(zone
,
4167 (is_master_set
? &is_master
: NULL
),
4168 (is_read_only_set
? &read_only
: NULL
),
4172 sync_from
, sync_from_rm
);
4174 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
4175 << ": " << cpp_strerror(-ret
) << std::endl
;
4181 ret
= zone
.set_as_default();
4183 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4187 encode_json("zone", zone
, formatter
);
4188 formatter
->flush(cout
);
4192 case OPT_ZONE_DEFAULT
:
4194 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
4195 int ret
= zonegroup
.init(g_ceph_context
, store
);
4197 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4199 if (zone_id
.empty() && zone_name
.empty()) {
4200 cerr
<< "no zone name or id provided" << std::endl
;
4203 RGWZoneParams
zone(zone_id
, zone_name
);
4204 ret
= zone
.init(g_ceph_context
, store
);
4206 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4209 ret
= zone
.set_as_default();
4211 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
4216 case OPT_ZONE_DELETE
:
4218 if (zone_id
.empty() && zone_name
.empty()) {
4219 cerr
<< "no zone name or id provided" << std::endl
;
4222 RGWZoneParams
zone(zone_id
, zone_name
);
4223 int ret
= zone
.init(g_ceph_context
, store
);
4225 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4229 list
<string
> zonegroups
;
4230 ret
= store
->list_zonegroups(zonegroups
);
4232 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
4236 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
4237 RGWZoneGroup
zonegroup(string(), *iter
);
4238 int ret
= zonegroup
.init(g_ceph_context
, store
);
4240 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4243 ret
= zonegroup
.remove_zone(zone
.get_id());
4244 if (ret
< 0 && ret
!= -ENOENT
) {
4245 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
4246 << cpp_strerror(-ret
) << std::endl
;
4250 ret
= zone
.delete_obj();
4252 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4259 RGWZoneParams
zone(zone_id
, zone_name
);
4260 int ret
= zone
.init(g_ceph_context
, store
);
4262 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4265 encode_json("zone", zone
, formatter
);
4266 formatter
->flush(cout
);
4271 RGWZoneParams
zone(zone_name
);
4272 int ret
= zone
.init(g_ceph_context
, store
, false);
4278 if (ret
< 0 && ret
!= -ENOENT
) {
4279 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
4283 string orig_id
= zone
.get_id();
4285 ret
= read_decode_json(infile
, zone
);
4290 if(zone
.realm_id
.empty()) {
4291 RGWRealm
realm(realm_id
, realm_name
);
4292 int ret
= realm
.init(g_ceph_context
, store
);
4293 if (ret
< 0 && ret
!= -ENOENT
) {
4294 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4297 zone
.realm_id
= realm
.get_id();
4300 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
4301 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
4305 if (zone
.get_name().empty()) {
4306 zone
.set_name(zone_name
);
4307 if (zone
.get_name().empty()) {
4308 cerr
<< "no zone name specified" << std::endl
;
4313 zone_name
= zone
.get_name();
4315 if (zone
.get_id().empty()) {
4316 zone
.set_id(orig_id
);
4319 if (zone
.get_id().empty()) {
4320 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
4321 if (zone_name
.empty()) {
4322 cerr
<< "missing zone name" << std::endl
;
4325 zone
.set_name(zone_name
);
4326 zone
.set_id(zone_name
);
4329 cerr
<< "zone id " << zone
.get_id();
4330 ret
= zone
.fix_pool_names();
4332 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4335 ret
= zone
.write(false);
4337 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4342 ret
= zone
.set_as_default();
4344 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4348 encode_json("zone", zone
, formatter
);
4349 formatter
->flush(cout
);
4355 int ret
= store
->list_zones(zones
);
4357 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4362 ret
= zone
.init(g_ceph_context
, store
, false);
4364 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4367 string default_zone
;
4368 ret
= zone
.read_default_id(default_zone
);
4369 if (ret
< 0 && ret
!= -ENOENT
) {
4370 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4372 formatter
->open_object_section("zones_list");
4373 encode_json("default_info", default_zone
, formatter
);
4374 encode_json("zones", zones
, formatter
);
4375 formatter
->close_section();
4376 formatter
->flush(cout
);
4380 case OPT_ZONE_MODIFY
:
4382 RGWZoneParams
zone(zone_id
, zone_name
);
4383 int ret
= zone
.init(g_ceph_context
, store
);
4385 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4389 bool need_zone_update
= false;
4390 if (!access_key
.empty()) {
4391 zone
.system_key
.id
= access_key
;
4392 need_zone_update
= true;
4395 if (!secret_key
.empty()) {
4396 zone
.system_key
.key
= secret_key
;
4397 need_zone_update
= true;
4400 if (!realm_id
.empty()) {
4401 zone
.realm_id
= realm_id
;
4402 need_zone_update
= true;
4403 } else if (!realm_name
.empty()) {
4404 // get realm id from name
4405 RGWRealm realm
{g_ceph_context
, store
};
4406 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4408 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4411 need_zone_update
= true;
4414 for (auto add
: tier_config_add
) {
4415 zone
.tier_config
[add
.first
] = add
.second
;
4416 need_zone_update
= true;
4419 for (auto rm
: tier_config_rm
) {
4420 zone
.tier_config
.erase(rm
.first
);
4421 need_zone_update
= true;
4424 if (need_zone_update
) {
4425 ret
= zone
.update();
4427 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4432 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4433 ret
= zonegroup
.init(g_ceph_context
, store
);
4435 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4438 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4440 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4442 ret
= zonegroup
.add_zone(zone
,
4443 (is_master_set
? &is_master
: NULL
),
4444 (is_read_only_set
? &read_only
: NULL
),
4445 endpoints
, ptier_type
,
4446 psync_from_all
, sync_from
, sync_from_rm
);
4448 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4452 ret
= zonegroup
.update();
4454 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4459 ret
= zone
.set_as_default();
4461 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4465 encode_json("zone", zone
, formatter
);
4466 formatter
->flush(cout
);
4469 case OPT_ZONE_RENAME
:
4471 if (zone_new_name
.empty()) {
4472 cerr
<< " missing zone new name" << std::endl
;
4475 if (zone_id
.empty() && zone_name
.empty()) {
4476 cerr
<< "no zonegroup name or id provided" << std::endl
;
4479 RGWZoneParams
zone(zone_id
,zone_name
);
4480 int ret
= zone
.init(g_ceph_context
, store
);
4482 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4485 ret
= zone
.rename(zone_new_name
);
4487 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4491 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4492 ret
= zonegroup
.init(g_ceph_context
, store
);
4494 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4496 ret
= zonegroup
.rename_zone(zone
);
4497 if (ret
< 0 && ret
) {
4498 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4504 case OPT_ZONE_PLACEMENT_ADD
:
4505 case OPT_ZONE_PLACEMENT_MODIFY
:
4506 case OPT_ZONE_PLACEMENT_RM
:
4508 if (placement_id
.empty()) {
4509 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4512 // validate compression type
4513 if (compression_type
&& *compression_type
!= "random"
4514 && !Compressor::get_comp_alg_type(*compression_type
)) {
4515 std::cerr
<< "Unrecognized compression type" << std::endl
;
4519 RGWZoneParams
zone(zone_id
, zone_name
);
4520 int ret
= zone
.init(g_ceph_context
, store
);
4522 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4526 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
) {
4527 // pool names are required
4528 if (!index_pool
|| index_pool
->empty() ||
4529 !data_pool
|| data_pool
->empty()) {
4530 cerr
<< "ERROR: need to specify both --index-pool and --data-pool" << std::endl
;
4534 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4536 info
.index_pool
= *index_pool
;
4537 info
.data_pool
= *data_pool
;
4538 if (data_extra_pool
) {
4539 info
.data_extra_pool
= *data_extra_pool
;
4541 if (index_type_specified
) {
4542 info
.index_type
= placement_index_type
;
4544 if (compression_type
) {
4545 info
.compression_type
= *compression_type
;
4547 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4548 auto p
= zone
.placement_pools
.find(placement_id
);
4549 if (p
== zone
.placement_pools
.end()) {
4550 cerr
<< "ERROR: zone placement target '" << placement_id
4551 << "' not found" << std::endl
;
4554 auto& info
= p
->second
;
4555 if (index_pool
&& !index_pool
->empty()) {
4556 info
.index_pool
= *index_pool
;
4558 if (data_pool
&& !data_pool
->empty()) {
4559 info
.data_pool
= *data_pool
;
4561 if (data_extra_pool
) {
4562 info
.data_extra_pool
= *data_extra_pool
;
4564 if (index_type_specified
) {
4565 info
.index_type
= placement_index_type
;
4567 if (compression_type
) {
4568 info
.compression_type
= *compression_type
;
4570 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4571 zone
.placement_pools
.erase(placement_id
);
4574 ret
= zone
.update();
4576 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4580 encode_json("zone", zone
, formatter
);
4581 formatter
->flush(cout
);
4584 case OPT_ZONE_PLACEMENT_LIST
:
4586 RGWZoneParams
zone(zone_id
, zone_name
);
4587 int ret
= zone
.init(g_ceph_context
, store
);
4589 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4592 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4593 formatter
->flush(cout
);
4600 if (!user_id
.empty()) {
4601 user_op
.set_user_id(user_id
);
4602 bucket_op
.set_user_id(user_id
);
4605 if (!display_name
.empty())
4606 user_op
.set_display_name(display_name
);
4608 if (!user_email
.empty())
4609 user_op
.set_user_email(user_email
);
4611 if (!access_key
.empty())
4612 user_op
.set_access_key(access_key
);
4614 if (!secret_key
.empty())
4615 user_op
.set_secret_key(secret_key
);
4617 if (!subuser
.empty())
4618 user_op
.set_subuser(subuser
);
4621 user_op
.set_caps(caps
);
4623 user_op
.set_purge_data(purge_data
);
4626 user_op
.set_purge_keys();
4629 user_op
.set_generate_key();
4632 user_op
.set_gen_secret(); // assume that a key pair should be created
4634 if (max_buckets_specified
)
4635 user_op
.set_max_buckets(max_buckets
);
4637 if (admin_specified
)
4638 user_op
.set_admin(admin
);
4640 if (system_specified
)
4641 user_op
.set_system(system
);
4644 user_op
.set_perm(perm_mask
);
4646 if (set_temp_url_key
) {
4647 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
4648 for (; iter
!= temp_url_keys
.end(); ++iter
) {
4649 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
4653 if (!op_mask_str
.empty()) {
4655 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
4657 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
4661 user_op
.set_op_mask(op_mask
);
4664 if (key_type
!= KEY_TYPE_UNDEFINED
)
4665 user_op
.set_key_type(key_type
);
4667 // set suspension operation parameters
4668 if (opt_cmd
== OPT_USER_ENABLE
)
4669 user_op
.set_suspension(false);
4670 else if (opt_cmd
== OPT_USER_SUSPEND
)
4671 user_op
.set_suspension(true);
4673 // RGWUser to use for user operations
4676 if (!user_id
.empty() || !subuser
.empty()) {
4677 ret
= user
.init(store
, user_op
);
4679 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
4684 /* populate bucket operation */
4685 bucket_op
.set_bucket_name(bucket_name
);
4686 bucket_op
.set_object(object
);
4687 bucket_op
.set_check_objects(check_objects
);
4688 bucket_op
.set_delete_children(delete_child_objects
);
4689 bucket_op
.set_fix_index(fix
);
4690 bucket_op
.set_max_aio(max_concurrent_ios
);
4692 // required to gather errors from operations
4693 std::string err_msg
;
4695 bool output_user_info
= true;
4700 case OPT_USER_CREATE
:
4701 if (!user_op
.has_existing_user()) {
4702 user_op
.set_generate_key(); // generate a new key by default
4704 ret
= user
.add(user_op
, &err_msg
);
4706 cerr
<< "could not create user: " << err_msg
<< std::endl
;
4707 if (ret
== -ERR_INVALID_TENANT_NAME
)
4712 if (!subuser
.empty()) {
4713 ret
= user
.subusers
.add(user_op
, &err_msg
);
4715 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4721 ret
= user
.remove(user_op
, &err_msg
);
4723 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
4727 output_user_info
= false;
4729 case OPT_USER_ENABLE
:
4730 case OPT_USER_SUSPEND
:
4731 case OPT_USER_MODIFY
:
4732 ret
= user
.modify(user_op
, &err_msg
);
4734 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
4739 case OPT_SUBUSER_CREATE
:
4740 ret
= user
.subusers
.add(user_op
, &err_msg
);
4742 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
4747 case OPT_SUBUSER_MODIFY
:
4748 ret
= user
.subusers
.modify(user_op
, &err_msg
);
4750 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
4755 case OPT_SUBUSER_RM
:
4756 ret
= user
.subusers
.remove(user_op
, &err_msg
);
4758 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
4764 ret
= user
.caps
.add(user_op
, &err_msg
);
4766 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
4772 ret
= user
.caps
.remove(user_op
, &err_msg
);
4774 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
4779 case OPT_KEY_CREATE
:
4780 ret
= user
.keys
.add(user_op
, &err_msg
);
4782 cerr
<< "could not create key: " << err_msg
<< std::endl
;
4788 ret
= user
.keys
.remove(user_op
, &err_msg
);
4790 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
4794 case OPT_PERIOD_PUSH
:
4797 req_info
info(g_ceph_context
, &env
);
4798 info
.method
= "POST";
4799 info
.request_uri
= "/admin/realm/period";
4801 map
<string
, string
> ¶ms
= info
.args
.get_params();
4802 if (!realm_id
.empty())
4803 params
["realm_id"] = realm_id
;
4804 if (!realm_name
.empty())
4805 params
["realm_name"] = realm_name
;
4806 if (!period_id
.empty())
4807 params
["period_id"] = period_id
;
4808 if (!period_epoch
.empty())
4809 params
["epoch"] = period_epoch
;
4812 RGWPeriod
period(period_id
);
4813 int ret
= period
.init(g_ceph_context
, store
);
4815 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4818 // json format into a bufferlist
4819 JSONFormatter
jf(false);
4820 encode_json("period", period
, &jf
);
4825 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
4828 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
4833 case OPT_PERIOD_UPDATE
:
4835 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
4836 commit
, remote
, url
, access_key
, secret_key
,
4837 formatter
, yes_i_really_mean_it
);
4843 case OPT_PERIOD_COMMIT
:
4845 // read realm and staging period
4846 RGWRealm
realm(realm_id
, realm_name
);
4847 int ret
= realm
.init(g_ceph_context
, store
);
4849 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
4852 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
4853 ret
= period
.init(g_ceph_context
, store
, realm
.get_id());
4855 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
4858 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
4859 yes_i_really_mean_it
);
4861 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
4865 encode_json("period", period
, formatter
);
4866 formatter
->flush(cout
);
4870 case OPT_ROLE_CREATE
:
4872 if (role_name
.empty()) {
4873 cerr
<< "ERROR: role name is empty" << std::endl
;
4877 if (assume_role_doc
.empty()) {
4878 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4881 /* The following two calls will be replaced by read_decode_json or something
4882 similar when the code for AWS Policies is in places */
4884 int ret
= read_input(assume_role_doc
, bl
);
4886 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4890 if (!p
.parse(bl
.c_str(), bl
.length())) {
4891 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4894 string trust_policy
= bl
.to_str();
4895 RGWRole
role(g_ceph_context
, store
, role_name
, path
, trust_policy
, tenant
);
4896 ret
= role
.create(true);
4900 show_role_info(role
, formatter
);
4903 case OPT_ROLE_DELETE
:
4905 if (role_name
.empty()) {
4906 cerr
<< "ERROR: empty role name" << std::endl
;
4909 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4910 ret
= role
.delete_obj();
4914 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
4919 if (role_name
.empty()) {
4920 cerr
<< "ERROR: empty role name" << std::endl
;
4923 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4928 show_role_info(role
, formatter
);
4931 case OPT_ROLE_MODIFY
:
4933 if (role_name
.empty()) {
4934 cerr
<< "ERROR: role name is empty" << std::endl
;
4938 if (assume_role_doc
.empty()) {
4939 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
4943 /* The following two calls will be replaced by read_decode_json or something
4944 similar when the code for AWS Policies is in place */
4946 int ret
= read_input(assume_role_doc
, bl
);
4948 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
4952 if (!p
.parse(bl
.c_str(), bl
.length())) {
4953 cout
<< "ERROR: failed to parse JSON: " << assume_role_doc
<< std::endl
;
4956 string trust_policy
= bl
.to_str();
4957 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
4962 role
.update_trust_policy(trust_policy
);
4963 ret
= role
.update();
4967 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
4972 vector
<RGWRole
> result
;
4973 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
4977 show_roles_info(result
, formatter
);
4980 case OPT_ROLE_POLICY_PUT
:
4982 if (role_name
.empty()) {
4983 cerr
<< "role name is empty" << std::endl
;
4987 if (policy_name
.empty()) {
4988 cerr
<< "policy name is empty" << std::endl
;
4992 if (perm_policy_doc
.empty()) {
4993 cerr
<< "permission policy document is empty" << std::endl
;
4997 /* The following two calls will be replaced by read_decode_json or something
4998 similar, when code for AWS Policies is in place.*/
5000 int ret
= read_input(perm_policy_doc
, bl
);
5002 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
5006 if (!p
.parse(bl
.c_str(), bl
.length())) {
5007 cout
<< "ERROR: failed to parse JSON: " << std::endl
;
5011 perm_policy
= bl
.c_str();
5013 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5018 role
.set_perm_policy(policy_name
, perm_policy
);
5019 ret
= role
.update();
5023 cout
<< "Permission policy attached successfully" << std::endl
;
5026 case OPT_ROLE_POLICY_LIST
:
5028 if (role_name
.empty()) {
5029 cerr
<< "ERROR: Role name is empty" << std::endl
;
5032 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5037 std::vector
<string
> policy_names
= role
.get_role_policy_names();
5038 show_policy_names(policy_names
, formatter
);
5041 case OPT_ROLE_POLICY_GET
:
5043 if (role_name
.empty()) {
5044 cerr
<< "ERROR: role name is empty" << std::endl
;
5048 if (policy_name
.empty()) {
5049 cerr
<< "ERROR: policy name is empty" << std::endl
;
5052 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5053 int ret
= role
.get();
5058 ret
= role
.get_role_policy(policy_name
, perm_policy
);
5062 show_perm_policy(perm_policy
, formatter
);
5065 case OPT_ROLE_POLICY_DELETE
:
5067 if (role_name
.empty()) {
5068 cerr
<< "ERROR: role name is empty" << std::endl
;
5072 if (policy_name
.empty()) {
5073 cerr
<< "ERROR: policy name is empty" << std::endl
;
5076 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5081 ret
= role
.delete_policy(policy_name
);
5085 ret
= role
.update();
5089 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
5090 << role_name
<< std::endl
;
5094 output_user_info
= false;
5097 // output the result of a user operation
5098 if (output_user_info
) {
5099 ret
= user
.info(info
, &err_msg
);
5101 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
5104 show_user_info(info
, formatter
);
5107 if (opt_cmd
== OPT_POLICY
) {
5108 if (format
== "xml") {
5109 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
5111 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
5115 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
5117 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
5123 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
5125 std::list
<std::string
> user_ids
;
5126 metadata_key
= "user";
5131 if (! user_id
.empty()) {
5132 user_ids
.push_back(user_id
.id
);
5134 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
5137 /* list users in groups of max-keys, then perform user-bucket
5138 * limit-check on each group */
5139 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
5141 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
5142 << cpp_strerror(-ret
) << std::endl
;
5147 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
5149 if (ret
< 0 && ret
!= -ENOENT
) {
5150 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
5151 << cpp_strerror(-ret
) << std::endl
;
5154 /* ok, do the limit checks for this group */
5156 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
5162 } while (truncated
);
5163 store
->meta_mgr
->list_keys_complete(handle
);
5166 } /* OPT_BUCKET_LIMIT_CHECK */
5168 if (opt_cmd
== OPT_BUCKETS_LIST
) {
5169 if (bucket_name
.empty()) {
5170 RGWBucketAdminOp::info(store
, bucket_op
, f
);
5172 RGWBucketInfo bucket_info
;
5173 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5175 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5178 formatter
->open_array_section("entries");
5181 if (max_entries
< 0)
5186 vector
<rgw_bucket_dir_entry
> result
;
5187 map
<string
, bool> common_prefixes
;
5190 RGWRados::Bucket
target(store
, bucket_info
);
5191 RGWRados::Bucket::List
list_op(&target
);
5193 list_op
.params
.prefix
= prefix
;
5194 list_op
.params
.delim
= delim
;
5195 list_op
.params
.marker
= rgw_obj_key(marker
);
5196 list_op
.params
.ns
= ns
;
5197 list_op
.params
.enforce_ns
= false;
5198 list_op
.params
.list_versions
= true;
5201 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
5203 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
5207 count
+= result
.size();
5209 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5210 rgw_bucket_dir_entry
& entry
= *iter
;
5211 encode_json("entry", entry
, formatter
);
5213 formatter
->flush(cout
);
5214 } while (truncated
&& count
< max_entries
);
5216 formatter
->close_section();
5217 formatter
->flush(cout
);
5218 } /* have bucket_name */
5219 } /* OPT_BUCKETS_LIST */
5221 if (opt_cmd
== OPT_BUCKET_STATS
) {
5222 bucket_op
.set_fetch_stats(true);
5224 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
5226 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
5231 if (opt_cmd
== OPT_BUCKET_LINK
) {
5232 bucket_op
.set_bucket_id(bucket_id
);
5234 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
5236 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
5241 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
5242 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
5244 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
5249 if (opt_cmd
== OPT_LOG_LIST
) {
5251 if (date
.size() && date
.size() != 10) {
5252 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
5257 formatter
->open_array_section("logs");
5259 int r
= store
->log_list_init(date
, &h
);
5264 cerr
<< "log list: error " << r
<< std::endl
;
5269 int r
= store
->log_list_next(h
, &name
);
5273 cerr
<< "log list: error " << r
<< std::endl
;
5276 formatter
->dump_string("object", name
);
5279 formatter
->close_section();
5280 formatter
->flush(cout
);
5284 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5285 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5286 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5292 if (!object
.empty()) {
5302 if (opt_cmd
== OPT_LOG_SHOW
) {
5305 int r
= store
->log_show_init(oid
, &h
);
5307 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5312 formatter
->open_object_section("log");
5314 struct rgw_log_entry entry
;
5316 // peek at first entry to get bucket metadata
5317 r
= store
->log_show_next(h
, &entry
);
5319 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5322 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5323 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5324 formatter
->dump_string("bucket", entry
.bucket
);
5326 uint64_t agg_time
= 0;
5327 uint64_t agg_bytes_sent
= 0;
5328 uint64_t agg_bytes_received
= 0;
5329 uint64_t total_entries
= 0;
5331 if (show_log_entries
)
5332 formatter
->open_array_section("log_entries");
5335 uint64_t total_time
= entry
.total_time
.sec() * 1000000LL + entry
.total_time
.usec();
5337 agg_time
+= total_time
;
5338 agg_bytes_sent
+= entry
.bytes_sent
;
5339 agg_bytes_received
+= entry
.bytes_received
;
5342 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5343 entry
.bytes_received
== 0)
5346 if (show_log_entries
) {
5348 rgw_format_ops_log_entry(entry
, formatter
);
5349 formatter
->flush(cout
);
5352 r
= store
->log_show_next(h
, &entry
);
5356 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5359 if (show_log_entries
)
5360 formatter
->close_section();
5363 formatter
->open_object_section("log_sum");
5364 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5365 formatter
->dump_int("bytes_received", agg_bytes_received
);
5366 formatter
->dump_int("total_time", agg_time
);
5367 formatter
->dump_int("total_entries", total_entries
);
5368 formatter
->close_section();
5370 formatter
->close_section();
5371 formatter
->flush(cout
);
5374 if (opt_cmd
== OPT_LOG_RM
) {
5375 int r
= store
->log_remove(oid
);
5377 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5383 if (opt_cmd
== OPT_POOL_ADD
) {
5384 if (pool_name
.empty()) {
5385 cerr
<< "need to specify pool to add!" << std::endl
;
5390 int ret
= store
->add_bucket_placement(pool
);
5392 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5395 if (opt_cmd
== OPT_POOL_RM
) {
5396 if (pool_name
.empty()) {
5397 cerr
<< "need to specify pool to remove!" << std::endl
;
5402 int ret
= store
->remove_bucket_placement(pool
);
5404 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5407 if (opt_cmd
== OPT_POOLS_LIST
) {
5408 set
<rgw_pool
> pools
;
5409 int ret
= store
->list_placement_set(pools
);
5411 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5415 formatter
->open_array_section("pools");
5416 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5417 formatter
->open_object_section("pool");
5418 formatter
->dump_string("name", siter
->to_str());
5419 formatter
->close_section();
5421 formatter
->close_section();
5422 formatter
->flush(cout
);
5426 if (opt_cmd
== OPT_USAGE_SHOW
) {
5427 uint64_t start_epoch
= 0;
5428 uint64_t end_epoch
= (uint64_t)-1;
5432 if (!start_date
.empty()) {
5433 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5435 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5439 if (!end_date
.empty()) {
5440 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5442 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5448 ret
= RGWUsage::show(store
, user_id
, start_epoch
, end_epoch
,
5449 show_log_entries
, show_log_sum
, &categories
,
5452 cerr
<< "ERROR: failed to show usage" << std::endl
;
5457 if (opt_cmd
== OPT_USAGE_TRIM
) {
5458 if (user_id
.empty() && !yes_i_really_mean_it
) {
5459 cerr
<< "usage trim without user specified will remove *all* users data" << std::endl
;
5460 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5464 uint64_t start_epoch
= 0;
5465 uint64_t end_epoch
= (uint64_t)-1;
5468 if (!start_date
.empty()) {
5469 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5471 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5476 if (!end_date
.empty()) {
5477 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5479 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5484 ret
= RGWUsage::trim(store
, user_id
, start_epoch
, end_epoch
);
5486 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5491 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5492 if (bucket_name
.empty()) {
5493 cerr
<< "ERROR: bucket not specified" << std::endl
;
5496 if (object
.empty()) {
5497 cerr
<< "ERROR: object not specified" << std::endl
;
5502 if (opt_cmd
== OPT_OLH_GET
) {
5503 RGWBucketInfo bucket_info
;
5504 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5506 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5510 rgw_obj
obj(bucket
, object
);
5511 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5513 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5516 encode_json("olh", olh
, formatter
);
5517 formatter
->flush(cout
);
5520 if (opt_cmd
== OPT_OLH_READLOG
) {
5521 RGWBucketInfo bucket_info
;
5522 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5524 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5527 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5530 RGWObjectCtx
rctx(store
);
5531 rgw_obj
obj(bucket
, object
);
5535 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5540 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5542 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5545 formatter
->open_object_section("result");
5546 encode_json("is_truncated", is_truncated
, formatter
);
5547 encode_json("log", log
, formatter
);
5548 formatter
->close_section();
5549 formatter
->flush(cout
);
5552 if (opt_cmd
== OPT_BI_GET
) {
5553 RGWBucketInfo bucket_info
;
5554 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5556 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5559 rgw_obj
obj(bucket
, object
);
5560 if (!object_version
.empty()) {
5561 obj
.key
.set_instance(object_version
);
5564 rgw_cls_bi_entry entry
;
5566 ret
= store
->bi_get(bucket
, obj
, bi_index_type
, &entry
);
5568 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5572 encode_json("entry", entry
, formatter
);
5573 formatter
->flush(cout
);
5576 if (opt_cmd
== OPT_BI_PUT
) {
5577 RGWBucketInfo bucket_info
;
5578 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5580 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5584 rgw_cls_bi_entry entry
;
5585 cls_rgw_obj_key key
;
5586 ret
= read_decode_json(infile
, entry
, &key
);
5591 rgw_obj
obj(bucket
, key
);
5593 ret
= store
->bi_put(bucket
, obj
, entry
);
5595 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
5600 if (opt_cmd
== OPT_BI_LIST
) {
5601 if (bucket_name
.empty()) {
5602 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5605 RGWBucketInfo bucket_info
;
5606 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5608 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5612 list
<rgw_cls_bi_entry
> entries
;
5614 if (max_entries
< 0) {
5618 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5620 formatter
->open_array_section("entries");
5622 for (int i
= 0; i
< max_shards
; i
++) {
5623 RGWRados::BucketShard
bs(store
);
5624 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5625 int ret
= bs
.init(bucket
, shard_id
);
5629 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5635 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
5637 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
5641 list
<rgw_cls_bi_entry
>::iterator iter
;
5642 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
5643 rgw_cls_bi_entry
& entry
= *iter
;
5644 encode_json("entry", entry
, formatter
);
5647 formatter
->flush(cout
);
5648 } while (is_truncated
);
5649 formatter
->flush(cout
);
5651 formatter
->close_section();
5652 formatter
->flush(cout
);
5655 if (opt_cmd
== OPT_BI_PURGE
) {
5656 if (bucket_name
.empty()) {
5657 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5660 RGWBucketInfo bucket_info
;
5661 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5663 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5667 RGWBucketInfo cur_bucket_info
;
5668 rgw_bucket cur_bucket
;
5669 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
5671 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
5675 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
5676 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
5677 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5681 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5683 for (int i
= 0; i
< max_shards
; i
++) {
5684 RGWRados::BucketShard
bs(store
);
5685 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
5686 int ret
= bs
.init(bucket
, shard_id
);
5688 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
5692 ret
= store
->bi_remove(bs
);
5694 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
5700 if (opt_cmd
== OPT_OBJECT_RM
) {
5701 RGWBucketInfo bucket_info
;
5702 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5704 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5707 rgw_obj_key
key(object
, object_version
);
5708 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
5711 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
5716 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
5717 if (bucket_name
.empty()) {
5718 cerr
<< "ERROR: bucket not specified" << std::endl
;
5721 if (object
.empty()) {
5722 cerr
<< "ERROR: object not specified" << std::endl
;
5726 RGWBucketInfo bucket_info
;
5727 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5729 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5733 rgw_obj
obj(bucket
, object
);
5734 obj
.key
.set_instance(object_version
);
5735 bool need_rewrite
= true;
5736 if (min_rewrite_stripe_size
> 0) {
5737 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5739 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
5743 ret
= store
->rewrite_obj(bucket_info
, obj
);
5745 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
5749 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
5753 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
5754 if (!store
->process_expire_objects()) {
5755 cerr
<< "ERROR: process_expire_objects() processing returned error." << std::endl
;
5760 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
5761 if (bucket_name
.empty()) {
5762 cerr
<< "ERROR: bucket not specified" << std::endl
;
5766 RGWBucketInfo bucket_info
;
5767 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5769 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5773 uint64_t start_epoch
= 0;
5774 uint64_t end_epoch
= 0;
5776 if (!end_date
.empty()) {
5777 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5779 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5783 if (!start_date
.empty()) {
5784 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5786 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5791 bool is_truncated
= true;
5793 rgw_obj_index_key marker
;
5796 formatter
->open_object_section("result");
5797 formatter
->dump_string("bucket", bucket_name
);
5798 formatter
->open_array_section("objects");
5799 while (is_truncated
) {
5800 map
<string
, rgw_bucket_dir_entry
> result
;
5802 store
->cls_bucket_list_ordered(bucket_info
, RGW_NO_SHARD
, marker
,
5804 result
, &is_truncated
, &marker
,
5805 bucket_object_check_filter
);
5807 if (r
< 0 && r
!= -ENOENT
) {
5808 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
5814 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
5815 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5816 rgw_obj_key key
= iter
->second
.key
;
5817 rgw_bucket_dir_entry
& entry
= iter
->second
;
5819 formatter
->open_object_section("object");
5820 formatter
->dump_string("name", key
.name
);
5821 formatter
->dump_string("instance", key
.instance
);
5822 formatter
->dump_int("size", entry
.meta
.size
);
5823 utime_t
ut(entry
.meta
.mtime
);
5824 ut
.gmtime(formatter
->dump_stream("mtime"));
5826 if ((entry
.meta
.size
< min_rewrite_size
) ||
5827 (entry
.meta
.size
> max_rewrite_size
) ||
5828 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
5829 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
5830 formatter
->dump_string("status", "Skipped");
5832 rgw_obj
obj(bucket
, key
);
5834 bool need_rewrite
= true;
5835 if (min_rewrite_stripe_size
> 0) {
5836 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
5838 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
5841 if (!need_rewrite
) {
5842 formatter
->dump_string("status", "Skipped");
5844 r
= store
->rewrite_obj(bucket_info
, obj
);
5846 formatter
->dump_string("status", "Success");
5848 formatter
->dump_string("status", cpp_strerror(-r
));
5852 formatter
->dump_int("flags", entry
.flags
);
5854 formatter
->close_section();
5855 formatter
->flush(cout
);
5858 formatter
->close_section();
5859 formatter
->close_section();
5860 formatter
->flush(cout
);
5863 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
5865 RGWBucketInfo bucket_info
;
5866 map
<string
, bufferlist
> attrs
;
5868 int ret
= check_reshard_bucket_params(store
,
5872 num_shards_specified
,
5874 yes_i_really_mean_it
,
5882 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5884 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
5885 if (max_entries
< 1) {
5886 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
5889 return br
.execute(num_shards
, max_entries
,
5890 verbose
, &cout
, formatter
);
5893 if (opt_cmd
== OPT_RESHARD_ADD
) {
5895 RGWBucketInfo bucket_info
;
5896 map
<string
, bufferlist
> attrs
;
5898 int ret
= check_reshard_bucket_params(store
,
5902 num_shards_specified
,
5904 yes_i_really_mean_it
,
5912 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
5914 RGWReshard
reshard(store
);
5915 cls_rgw_reshard_entry entry
;
5916 entry
.time
= real_clock::now();
5917 entry
.tenant
= tenant
;
5918 entry
.bucket_name
= bucket_name
;
5919 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
5920 entry
.old_num_shards
= num_source_shards
;
5921 entry
.new_num_shards
= num_shards
;
5923 return reshard
.add(entry
);
5926 if (opt_cmd
== OPT_RESHARD_LIST
) {
5927 list
<cls_rgw_reshard_entry
> entries
;
5930 if (max_entries
< 0) {
5934 int num_logshards
= store
->ctx()->_conf
->rgw_reshard_num_logs
;
5936 RGWReshard
reshard(store
);
5938 formatter
->open_array_section("reshard");
5939 for (int i
= 0; i
< num_logshards
; i
++) {
5940 bool is_truncated
= true;
5944 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
5946 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
5949 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
5950 cls_rgw_reshard_entry
& entry
= *iter
;
5951 encode_json("entry", entry
, formatter
);
5952 entry
.get_key(&marker
);
5954 count
+= entries
.size();
5955 formatter
->flush(cout
);
5956 } while (is_truncated
&& count
< max_entries
);
5958 if (count
>= max_entries
) {
5963 formatter
->close_section();
5964 formatter
->flush(cout
);
5969 if (opt_cmd
== OPT_RESHARD_STATUS
) {
5970 if (bucket_name
.empty()) {
5971 cerr
<< "ERROR: bucket not specified" << std::endl
;
5976 RGWBucketInfo bucket_info
;
5977 map
<string
, bufferlist
> attrs
;
5978 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
5980 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5984 RGWBucketReshard
br(store
, bucket_info
, attrs
);
5985 list
<cls_rgw_bucket_instance_entry
> status
;
5986 int r
= br
.get_status(&status
);
5988 cerr
<< "ERROR: could not get resharding status for bucket " << bucket_name
<< std::endl
;
5992 encode_json("status", status
, formatter
);
5993 formatter
->flush(cout
);
5996 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
5997 RGWReshard
reshard(store
, true, &cout
);
5999 int ret
= reshard
.process_all_logshards();
6001 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
6006 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
6007 if (bucket_name
.empty()) {
6008 cerr
<< "ERROR: bucket not specified" << std::endl
;
6013 RGWBucketInfo bucket_info
;
6014 map
<string
, bufferlist
> attrs
;
6015 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
6017 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6021 RGWBucketReshard
br(store
, bucket_info
, attrs
);
6022 int ret
= br
.cancel();
6024 if (ret
== -EBUSY
) {
6025 cerr
<< "There is ongoing resharding, please retry after " << g_conf
->rgw_reshard_bucket_lock_duration
<<
6026 " seconds " << std::endl
;
6028 cerr
<< "Error canceling bucket " << bucket_name
<< " resharding: " << cpp_strerror(-ret
) <<
6033 RGWReshard
reshard(store
);
6035 cls_rgw_reshard_entry entry
;
6036 //entry.tenant = tenant;
6037 entry
.bucket_name
= bucket_name
;
6038 //entry.bucket_id = bucket_id;
6040 ret
= reshard
.remove(entry
);
6041 if (ret
< 0 && ret
!= -ENOENT
) {
6042 cerr
<< "Error in getting bucket " << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
6047 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
6048 RGWBucketInfo bucket_info
;
6049 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6051 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6054 list
<rgw_obj_index_key
> oid_list
;
6055 rgw_obj_key
key(object
, object_version
);
6056 rgw_obj_index_key index_key
;
6057 key
.get_index_key(&index_key
);
6058 oid_list
.push_back(index_key
);
6059 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
6061 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
6066 if (opt_cmd
== OPT_OBJECT_STAT
) {
6067 RGWBucketInfo bucket_info
;
6068 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6070 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6073 rgw_obj
obj(bucket
, object
);
6074 obj
.key
.set_instance(object_version
);
6077 map
<string
, bufferlist
> attrs
;
6078 RGWObjectCtx
obj_ctx(store
);
6079 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
6080 RGWRados::Object::Read
read_op(&op_target
);
6082 read_op
.params
.attrs
= &attrs
;
6083 read_op
.params
.obj_size
= &obj_size
;
6085 ret
= read_op
.prepare();
6087 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
6090 formatter
->open_object_section("object_metadata");
6091 formatter
->dump_string("name", object
);
6092 formatter
->dump_unsigned("size", obj_size
);
6094 map
<string
, bufferlist
>::iterator iter
;
6095 map
<string
, bufferlist
> other_attrs
;
6096 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
6097 bufferlist
& bl
= iter
->second
;
6098 bool handled
= false;
6099 if (iter
->first
== RGW_ATTR_MANIFEST
) {
6100 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
6101 } else if (iter
->first
== RGW_ATTR_ACL
) {
6102 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
6103 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
6104 handled
= dump_string("tag", bl
, formatter
);
6105 } else if (iter
->first
== RGW_ATTR_ETAG
) {
6106 handled
= dump_string("etag", bl
, formatter
);
6110 other_attrs
[iter
->first
] = bl
;
6113 formatter
->open_object_section("attrs");
6114 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
6115 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
6117 formatter
->close_section();
6118 formatter
->close_section();
6119 formatter
->flush(cout
);
6122 if (opt_cmd
== OPT_BUCKET_CHECK
) {
6123 if (check_head_obj_locator
) {
6124 if (bucket_name
.empty()) {
6125 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
6128 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
6130 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
6134 if (opt_cmd
== OPT_BUCKET_RM
) {
6135 if (inconsistent_index
== false) {
6136 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
6138 if (!yes_i_really_mean_it
) {
6139 cerr
<< "using --inconsistent_index can corrupt the bucket index " << std::endl
6140 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
6143 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
6147 if (opt_cmd
== OPT_GC_LIST
) {
6150 formatter
->open_array_section("entries");
6153 list
<cls_rgw_gc_obj_info
> result
;
6154 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
6156 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
6161 list
<cls_rgw_gc_obj_info
>::iterator iter
;
6162 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
6163 cls_rgw_gc_obj_info
& info
= *iter
;
6164 formatter
->open_object_section("chain_info");
6165 formatter
->dump_string("tag", info
.tag
);
6166 formatter
->dump_stream("time") << info
.time
;
6167 formatter
->open_array_section("objs");
6168 list
<cls_rgw_obj
>::iterator liter
;
6169 cls_rgw_obj_chain
& chain
= info
.chain
;
6170 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
6171 cls_rgw_obj
& obj
= *liter
;
6172 encode_json("obj", obj
, formatter
);
6174 formatter
->close_section(); // objs
6175 formatter
->close_section(); // obj_chain
6176 formatter
->flush(cout
);
6178 } while (truncated
);
6179 formatter
->close_section();
6180 formatter
->flush(cout
);
6183 if (opt_cmd
== OPT_GC_PROCESS
) {
6184 int ret
= store
->process_gc();
6186 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
6191 if (opt_cmd
== OPT_LC_LIST
) {
6192 formatter
->open_array_section("lifecycle_list");
6193 map
<string
, int> bucket_lc_map
;
6195 #define MAX_LC_LIST_ENTRIES 100
6196 if (max_entries
< 0) {
6197 max_entries
= MAX_LC_LIST_ENTRIES
;
6200 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
6202 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
6205 map
<string
, int>::iterator iter
;
6206 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
6207 formatter
->open_object_section("bucket_lc_info");
6208 formatter
->dump_string("bucket", iter
->first
);
6209 string lc_status
= LC_STATUS
[iter
->second
];
6210 formatter
->dump_string("status", lc_status
);
6211 formatter
->close_section(); // objs
6212 formatter
->flush(cout
);
6213 marker
= iter
->first
;
6215 } while (!bucket_lc_map
.empty());
6217 formatter
->close_section(); //lifecycle list
6218 formatter
->flush(cout
);
6222 if (opt_cmd
== OPT_LC_PROCESS
) {
6223 int ret
= store
->process_lc();
6225 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
6230 if (opt_cmd
== OPT_ORPHANS_FIND
) {
6231 if (!yes_i_really_mean_it
) {
6232 cerr
<< "accidental removal of active objects can not be reversed; "
6233 << "do you really mean it? (requires --yes-i-really-mean-it)"
6238 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6240 if (job_id
.empty()) {
6241 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6244 if (pool_name
.empty()) {
6245 cerr
<< "ERROR: --pool not specified" << std::endl
;
6249 RGWOrphanSearchInfo info
;
6252 info
.job_name
= job_id
;
6253 info
.num_shards
= num_shards
;
6255 int ret
= search
.init(job_id
, &info
);
6257 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
6266 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
6267 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6269 if (job_id
.empty()) {
6270 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6273 int ret
= search
.init(job_id
, NULL
);
6275 if (ret
== -ENOENT
) {
6276 cerr
<< "job not found" << std::endl
;
6280 ret
= search
.finish();
6286 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
6287 RGWOrphanStore
orphan_store(store
);
6288 int ret
= orphan_store
.init();
6290 cerr
<< "connection to cluster failed!" << std::endl
;
6294 map
<string
,RGWOrphanSearchState
> m
;
6295 ret
= orphan_store
.list_jobs(m
);
6297 cerr
<< "job list failed" << std::endl
;
6300 formatter
->open_array_section("entries");
6301 for (const auto &it
: m
){
6303 formatter
->dump_string("job-id",it
.first
);
6305 encode_json("orphan_search_state", it
.second
, formatter
);
6308 formatter
->close_section();
6309 formatter
->flush(cout
);
6312 if (opt_cmd
== OPT_USER_CHECK
) {
6313 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6316 if (opt_cmd
== OPT_USER_STATS
) {
6317 if (user_id
.empty()) {
6318 cerr
<< "ERROR: uid not specified" << std::endl
;
6322 string user_str
= user_id
.to_str();
6324 if (!bucket_name
.empty()){
6325 cerr
<< "ERROR: recalculate doesn't work on buckets" << std::endl
;
6328 ret
= store
->cls_user_reset_stats(user_str
);
6330 cerr
<< "ERROR: could not clear user stats: " << cpp_strerror(-ret
) << std::endl
;
6336 if (!bucket_name
.empty()) {
6337 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6339 cerr
<< "ERROR: could not sync bucket stats: " << cpp_strerror(-ret
) << std::endl
;
6343 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6345 cerr
<< "ERROR: failed to sync user stats: " << cpp_strerror(-ret
) << std::endl
;
6351 cls_user_header header
;
6352 int ret
= store
->cls_user_get_header(user_str
, &header
);
6354 if (ret
== -ENOENT
) { /* in case of ENOENT */
6355 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6357 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6362 encode_json("header", header
, formatter
);
6363 formatter
->flush(cout
);
6366 if (opt_cmd
== OPT_METADATA_GET
) {
6367 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6369 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6373 formatter
->flush(cout
);
6376 if (opt_cmd
== OPT_METADATA_PUT
) {
6378 int ret
= read_input(infile
, bl
);
6380 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6383 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::APPLY_ALWAYS
);
6385 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6390 if (opt_cmd
== OPT_METADATA_RM
) {
6391 int ret
= store
->meta_mgr
->remove(metadata_key
);
6393 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6398 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6399 if (opt_cmd
== OPT_USER_LIST
) {
6400 metadata_key
= "user";
6404 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, marker
, &handle
);
6406 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6413 if (max_entries_specified
) {
6414 formatter
->open_object_section("result");
6416 formatter
->open_array_section("keys");
6421 left
= (max_entries_specified
? max_entries
- count
: max
);
6422 ret
= store
->meta_mgr
->list_keys_next(handle
, left
, keys
, &truncated
);
6423 if (ret
< 0 && ret
!= -ENOENT
) {
6424 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6426 } if (ret
!= -ENOENT
) {
6427 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6428 formatter
->dump_string("key", *iter
);
6431 formatter
->flush(cout
);
6433 } while (truncated
&& left
> 0);
6435 formatter
->close_section();
6437 if (max_entries_specified
) {
6438 encode_json("truncated", truncated
, formatter
);
6439 encode_json("count", count
, formatter
);
6441 encode_json("marker", store
->meta_mgr
->get_marker(handle
), formatter
);
6443 formatter
->close_section();
6445 formatter
->flush(cout
);
6447 store
->meta_mgr
->list_keys_complete(handle
);
6450 if (opt_cmd
== OPT_MDLOG_LIST
) {
6451 utime_t start_time
, end_time
;
6453 int ret
= parse_date_str(start_date
, start_time
);
6457 ret
= parse_date_str(end_date
, end_time
);
6461 int i
= (specified_shard_id
? shard_id
: 0);
6463 if (period_id
.empty()) {
6464 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6468 std::cerr
<< "No --period given, using current period="
6469 << period_id
<< std::endl
;
6471 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6473 formatter
->open_array_section("entries");
6474 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6476 list
<cls_log_entry
> entries
;
6479 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
6482 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
6484 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
6488 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6489 cls_log_entry
& entry
= *iter
;
6490 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
6492 formatter
->flush(cout
);
6493 } while (truncated
);
6495 meta_log
->complete_list_entries(handle
);
6497 if (specified_shard_id
)
6502 formatter
->close_section();
6503 formatter
->flush(cout
);
6506 if (opt_cmd
== OPT_MDLOG_STATUS
) {
6507 int i
= (specified_shard_id
? shard_id
: 0);
6509 if (period_id
.empty()) {
6510 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6514 std::cerr
<< "No --period given, using current period="
6515 << period_id
<< std::endl
;
6517 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6519 formatter
->open_array_section("entries");
6521 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
6522 RGWMetadataLogInfo info
;
6523 meta_log
->get_info(i
, &info
);
6525 ::encode_json("info", info
, formatter
);
6527 if (specified_shard_id
)
6532 formatter
->close_section();
6533 formatter
->flush(cout
);
6536 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
6537 // need a full history for purging old mdlog periods
6538 store
->meta_mgr
->init_oldest_log_period();
6540 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
6541 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
6542 int ret
= http
.set_threaded();
6544 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
6548 auto num_shards
= g_conf
->rgw_md_log_max_shards
;
6549 ret
= crs
.run(create_admin_meta_log_trim_cr(store
, &http
, num_shards
));
6551 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
6556 if (opt_cmd
== OPT_MDLOG_TRIM
) {
6557 utime_t start_time
, end_time
;
6559 if (!specified_shard_id
) {
6560 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
6564 int ret
= parse_date_str(start_date
, start_time
);
6568 ret
= parse_date_str(end_date
, end_time
);
6572 if (period_id
.empty()) {
6573 std::cerr
<< "missing --period argument" << std::endl
;
6576 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
6578 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
6580 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
6585 if (opt_cmd
== OPT_SYNC_STATUS
) {
6586 sync_status(formatter
);
6589 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
6590 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6592 int ret
= sync
.init();
6594 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6598 rgw_meta_sync_status sync_status
;
6599 ret
= sync
.read_sync_status(&sync_status
);
6601 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6605 formatter
->open_object_section("summary");
6606 encode_json("sync_status", sync_status
, formatter
);
6608 uint64_t full_total
= 0;
6609 uint64_t full_complete
= 0;
6611 for (auto marker_iter
: sync_status
.sync_markers
) {
6612 full_total
+= marker_iter
.second
.total_entries
;
6613 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6614 full_complete
+= marker_iter
.second
.pos
;
6616 full_complete
+= marker_iter
.second
.total_entries
;
6620 formatter
->open_object_section("full_sync");
6621 encode_json("total", full_total
, formatter
);
6622 encode_json("complete", full_complete
, formatter
);
6623 formatter
->close_section();
6624 formatter
->close_section();
6626 formatter
->flush(cout
);
6630 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
6631 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6633 int ret
= sync
.init();
6635 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6638 ret
= sync
.init_sync_status();
6640 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6646 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
6647 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
6649 int ret
= sync
.init();
6651 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6657 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6662 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
6663 if (source_zone
.empty()) {
6664 cerr
<< "ERROR: source zone not specified" << std::endl
;
6667 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6669 int ret
= sync
.init();
6671 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6675 rgw_data_sync_status sync_status
;
6676 if (specified_shard_id
) {
6677 set
<string
> pending_buckets
;
6678 set
<string
> recovering_buckets
;
6679 rgw_data_sync_marker sync_marker
;
6680 ret
= sync
.read_shard_status(shard_id
, pending_buckets
, recovering_buckets
, &sync_marker
,
6681 max_entries_specified
? max_entries
: 20);
6682 if (ret
< 0 && ret
!= -ENOENT
) {
6683 cerr
<< "ERROR: sync.read_shard_status() returned ret=" << ret
<< std::endl
;
6686 formatter
->open_object_section("summary");
6687 encode_json("shard_id", shard_id
, formatter
);
6688 encode_json("marker", sync_marker
, formatter
);
6689 encode_json("pending_buckets", pending_buckets
, formatter
);
6690 encode_json("recovering_buckets", recovering_buckets
, formatter
);
6691 formatter
->close_section();
6692 formatter
->flush(cout
);
6694 ret
= sync
.read_sync_status(&sync_status
);
6695 if (ret
< 0 && ret
!= -ENOENT
) {
6696 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6700 formatter
->open_object_section("summary");
6701 encode_json("sync_status", sync_status
, formatter
);
6703 uint64_t full_total
= 0;
6704 uint64_t full_complete
= 0;
6706 for (auto marker_iter
: sync_status
.sync_markers
) {
6707 full_total
+= marker_iter
.second
.total_entries
;
6708 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
6709 full_complete
+= marker_iter
.second
.pos
;
6711 full_complete
+= marker_iter
.second
.total_entries
;
6715 formatter
->open_object_section("full_sync");
6716 encode_json("total", full_total
, formatter
);
6717 encode_json("complete", full_complete
, formatter
);
6718 formatter
->close_section();
6719 formatter
->close_section();
6721 formatter
->flush(cout
);
6725 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
6726 if (source_zone
.empty()) {
6727 cerr
<< "ERROR: source zone not specified" << std::endl
;
6731 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
);
6733 int ret
= sync
.init();
6735 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6739 ret
= sync
.init_sync_status();
6741 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6746 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
6747 if (source_zone
.empty()) {
6748 cerr
<< "ERROR: source zone not specified" << std::endl
;
6752 RGWSyncModuleInstanceRef sync_module
;
6753 int ret
= store
->get_sync_modules_manager()->create_instance(g_ceph_context
, store
->get_zone().tier_type
,
6754 store
->get_zone_params().tier_config
, &sync_module
);
6756 lderr(cct
) << "ERROR: failed to init sync module instance, ret=" << ret
<< dendl
;
6760 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
, sync_module
);
6764 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6770 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6775 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
6776 if (source_zone
.empty()) {
6777 cerr
<< "ERROR: source zone not specified" << std::endl
;
6780 if (bucket_name
.empty()) {
6781 cerr
<< "ERROR: bucket not specified" << std::endl
;
6785 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6789 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6793 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6796 ret
= sync
.init_sync_status();
6798 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
6803 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
6804 if (bucket_name
.empty()) {
6805 cerr
<< "ERROR: bucket not specified" << std::endl
;
6810 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
6814 ret
= period
.init(g_ceph_context
, store
, realm_id
, realm_name
, true);
6816 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
6820 if (!store
->is_meta_master()) {
6821 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
6822 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
6826 rgw_obj
obj(bucket
, object
);
6827 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
6832 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
6833 if (bucket_name
.empty()) {
6834 cerr
<< "ERROR: bucket not specified" << std::endl
;
6837 RGWBucketInfo bucket_info
;
6839 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6843 bucket_sync_status(store
, bucket_info
, source_zone
, std::cout
);
6846 if (opt_cmd
== OPT_BUCKET_SYNC_MARKERS
) {
6847 if (source_zone
.empty()) {
6848 cerr
<< "ERROR: source zone not specified" << std::endl
;
6851 if (bucket_name
.empty()) {
6852 cerr
<< "ERROR: bucket not specified" << std::endl
;
6856 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6860 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6864 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6867 ret
= sync
.read_sync_status();
6869 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
6873 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
6875 encode_json("sync_status", sync_status
, formatter
);
6876 formatter
->flush(cout
);
6879 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
6880 if (source_zone
.empty()) {
6881 cerr
<< "ERROR: source zone not specified" << std::endl
;
6884 if (bucket_name
.empty()) {
6885 cerr
<< "ERROR: bucket not specified" << std::endl
;
6889 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
6893 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
6897 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
6903 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
6908 if (opt_cmd
== OPT_BILOG_LIST
) {
6909 if (bucket_name
.empty()) {
6910 cerr
<< "ERROR: bucket not specified" << std::endl
;
6913 RGWBucketInfo bucket_info
;
6914 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6916 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6919 formatter
->open_array_section("entries");
6922 if (max_entries
< 0)
6926 list
<rgw_bi_log_entry
> entries
;
6927 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
6929 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
6933 count
+= entries
.size();
6935 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6936 rgw_bi_log_entry
& entry
= *iter
;
6937 encode_json("entry", entry
, formatter
);
6941 formatter
->flush(cout
);
6942 } while (truncated
&& count
< max_entries
);
6944 formatter
->close_section();
6945 formatter
->flush(cout
);
6948 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
6949 if (max_entries
< 0) {
6954 utime_t start_time
, end_time
;
6956 int ret
= parse_date_str(start_date
, start_time
);
6960 ret
= parse_date_str(end_date
, end_time
);
6968 formatter
->open_array_section("entries");
6970 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
6971 formatter
->open_object_section("shard");
6972 encode_json("shard_id", shard_id
, formatter
);
6973 formatter
->open_array_section("entries");
6976 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
6979 list
<cls_log_entry
> entries
;
6980 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
6981 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
6982 if (ret
== -ENOENT
) {
6986 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
6990 count
+= entries
.size();
6992 for (auto& cls_entry
: entries
) {
6993 rgw_sync_error_info log_entry
;
6995 auto iter
= cls_entry
.data
.begin();
6997 ::decode(log_entry
, iter
);
6998 } catch (buffer::error
& err
) {
6999 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
7002 formatter
->open_object_section("entry");
7003 encode_json("id", cls_entry
.id
, formatter
);
7004 encode_json("section", cls_entry
.section
, formatter
);
7005 encode_json("name", cls_entry
.name
, formatter
);
7006 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
7007 encode_json("info", log_entry
, formatter
);
7008 formatter
->close_section();
7009 formatter
->flush(cout
);
7011 } while (truncated
&& count
< max_entries
);
7013 formatter
->close_section();
7014 formatter
->close_section();
7016 if (specified_shard_id
) {
7021 formatter
->close_section();
7022 formatter
->flush(cout
);
7025 if (opt_cmd
== OPT_SYNC_ERROR_TRIM
) {
7026 utime_t start_time
, end_time
;
7027 int ret
= parse_date_str(start_date
, start_time
);
7031 ret
= parse_date_str(end_date
, end_time
);
7039 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
7040 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
7041 ret
= store
->time_log_trim(oid
, start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
7042 if (ret
< 0 && ret
!= -ENODATA
) {
7043 cerr
<< "ERROR: sync error trim: " << cpp_strerror(-ret
) << std::endl
;
7046 if (specified_shard_id
) {
7052 if (opt_cmd
== OPT_BILOG_TRIM
) {
7053 if (bucket_name
.empty()) {
7054 cerr
<< "ERROR: bucket not specified" << std::endl
;
7057 RGWBucketInfo bucket_info
;
7058 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7060 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7063 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
7065 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
7070 if (opt_cmd
== OPT_BILOG_STATUS
) {
7071 if (bucket_name
.empty()) {
7072 cerr
<< "ERROR: bucket not specified" << std::endl
;
7075 RGWBucketInfo bucket_info
;
7076 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7078 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7081 map
<int, string
> markers
;
7082 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
7084 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
7087 formatter
->open_object_section("entries");
7088 encode_json("markers", markers
, formatter
);
7089 formatter
->close_section();
7090 formatter
->flush(cout
);
7093 if (opt_cmd
== OPT_BILOG_AUTOTRIM
) {
7094 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
7095 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
7096 int ret
= http
.set_threaded();
7098 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
7102 rgw::BucketTrimConfig config
;
7103 configure_bucket_trim(store
->ctx(), config
);
7105 rgw::BucketTrimManager
trim(store
, config
);
7108 cerr
<< "trim manager init failed with " << cpp_strerror(ret
) << std::endl
;
7111 ret
= crs
.run(trim
.create_admin_bucket_trim_cr(&http
));
7113 cerr
<< "automated bilog trim failed with " << cpp_strerror(ret
) << std::endl
;
7118 if (opt_cmd
== OPT_DATALOG_LIST
) {
7119 formatter
->open_array_section("entries");
7122 if (max_entries
< 0)
7125 utime_t start_time
, end_time
;
7127 int ret
= parse_date_str(start_date
, start_time
);
7131 ret
= parse_date_str(end_date
, end_time
);
7135 RGWDataChangesLog
*log
= store
->data_log
;
7136 RGWDataChangesLog::LogMarker marker
;
7139 list
<rgw_data_change_log_entry
> entries
;
7140 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, &truncated
);
7142 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
7146 count
+= entries
.size();
7148 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
7149 rgw_data_change_log_entry
& entry
= *iter
;
7151 encode_json("entry", entry
.entry
, formatter
);
7153 encode_json("entry", entry
, formatter
);
7156 formatter
->flush(cout
);
7157 } while (truncated
&& count
< max_entries
);
7159 formatter
->close_section();
7160 formatter
->flush(cout
);
7163 if (opt_cmd
== OPT_DATALOG_STATUS
) {
7164 RGWDataChangesLog
*log
= store
->data_log
;
7165 int i
= (specified_shard_id
? shard_id
: 0);
7167 formatter
->open_array_section("entries");
7168 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
7169 list
<cls_log_entry
> entries
;
7171 RGWDataChangesLogInfo info
;
7172 log
->get_info(i
, &info
);
7174 ::encode_json("info", info
, formatter
);
7176 if (specified_shard_id
)
7180 formatter
->close_section();
7181 formatter
->flush(cout
);
7184 if (opt_cmd
== OPT_DATALOG_TRIM
) {
7185 utime_t start_time
, end_time
;
7187 int ret
= parse_date_str(start_date
, start_time
);
7191 ret
= parse_date_str(end_date
, end_time
);
7195 RGWDataChangesLog
*log
= store
->data_log
;
7196 ret
= log
->trim_entries(start_time
.to_real_time(), end_time
.to_real_time(), start_marker
, end_marker
);
7198 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
7203 if (opt_cmd
== OPT_OPSTATE_LIST
) {
7204 RGWOpState
oc(store
);
7209 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
7210 list
<cls_statelog_entry
> entries
;
7212 formatter
->open_array_section("entries");
7214 int ret
= oc
.list_entries(handle
, max
, entries
, &done
);
7216 cerr
<< "oc.list_entries returned " << cpp_strerror(-ret
) << std::endl
;
7217 oc
.finish_list_entries(handle
);
7221 for (list
<cls_statelog_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
7222 oc
.dump_entry(*iter
, formatter
);
7225 formatter
->flush(cout
);
7227 formatter
->close_section();
7228 formatter
->flush(cout
);
7229 oc
.finish_list_entries(handle
);
7232 if (opt_cmd
== OPT_OPSTATE_SET
|| opt_cmd
== OPT_OPSTATE_RENEW
) {
7233 RGWOpState
oc(store
);
7235 RGWOpState::OpState state
;
7236 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
7237 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
7240 if (state_str
.empty()) {
7241 cerr
<< "ERROR: state was not specified" << std::endl
;
7244 int ret
= oc
.state_from_str(state_str
, &state
);
7246 cerr
<< "ERROR: invalid state: " << state_str
<< std::endl
;
7250 if (opt_cmd
== OPT_OPSTATE_SET
) {
7251 ret
= oc
.set_state(client_id
, op_id
, object
, state
);
7253 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
7257 ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
7259 cerr
<< "ERROR: failed to renew state: " << cpp_strerror(-ret
) << std::endl
;
7264 if (opt_cmd
== OPT_OPSTATE_RM
) {
7265 RGWOpState
oc(store
);
7267 if (object
.empty() || client_id
.empty() || op_id
.empty()) {
7268 cerr
<< "ERROR: need to specify client_id, op_id, and object" << std::endl
;
7271 ret
= oc
.remove_entry(client_id
, op_id
, object
);
7273 cerr
<< "ERROR: failed to set state: " << cpp_strerror(-ret
) << std::endl
;
7278 if (opt_cmd
== OPT_REPLICALOG_GET
|| opt_cmd
== OPT_REPLICALOG_UPDATE
||
7279 opt_cmd
== OPT_REPLICALOG_DELETE
) {
7280 if (replica_log_type_str
.empty()) {
7281 cerr
<< "ERROR: need to specify --replica-log-type=<metadata | data | bucket>" << std::endl
;
7286 if (opt_cmd
== OPT_REPLICALOG_GET
) {
7287 RGWReplicaBounds bounds
;
7288 if (replica_log_type
== ReplicaLog_Metadata
) {
7289 if (!specified_shard_id
) {
7290 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7294 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7295 int ret
= logger
.get_bounds(shard_id
, bounds
);
7298 } else if (replica_log_type
== ReplicaLog_Data
) {
7299 if (!specified_shard_id
) {
7300 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7303 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7304 int ret
= logger
.get_bounds(shard_id
, bounds
);
7307 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7308 if (bucket_name
.empty()) {
7309 cerr
<< "ERROR: bucket not specified" << std::endl
;
7312 RGWBucketInfo bucket_info
;
7313 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7315 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7319 RGWReplicaBucketLogger
logger(store
);
7320 ret
= logger
.get_bounds(bucket
, shard_id
, bounds
);
7323 } else { // shouldn't get here
7326 encode_json("bounds", bounds
, formatter
);
7327 formatter
->flush(cout
);
7331 if (opt_cmd
== OPT_REPLICALOG_DELETE
) {
7332 if (replica_log_type
== ReplicaLog_Metadata
) {
7333 if (!specified_shard_id
) {
7334 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
7337 if (!specified_daemon_id
) {
7338 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
7341 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7342 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
7345 } else if (replica_log_type
== ReplicaLog_Data
) {
7346 if (!specified_shard_id
) {
7347 cerr
<< "ERROR: shard-id must be specified for delete operation" << std::endl
;
7350 if (!specified_daemon_id
) {
7351 cerr
<< "ERROR: daemon-id must be specified for delete operation" << std::endl
;
7354 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7355 int ret
= logger
.delete_bound(shard_id
, daemon_id
, false);
7358 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7359 if (bucket_name
.empty()) {
7360 cerr
<< "ERROR: bucket not specified" << std::endl
;
7363 RGWBucketInfo bucket_info
;
7364 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7366 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7370 RGWReplicaBucketLogger
logger(store
);
7371 ret
= logger
.delete_bound(bucket
, shard_id
, daemon_id
, false);
7377 if (opt_cmd
== OPT_REPLICALOG_UPDATE
) {
7378 if (marker
.empty()) {
7379 cerr
<< "ERROR: marker was not specified" <<std::endl
;
7382 utime_t time
= ceph_clock_now();
7383 if (!date
.empty()) {
7384 ret
= parse_date_str(date
, time
);
7386 cerr
<< "ERROR: failed to parse start date" << std::endl
;
7390 list
<RGWReplicaItemMarker
> entries
;
7391 int ret
= read_decode_json(infile
, entries
);
7393 cerr
<< "ERROR: failed to decode entries" << std::endl
;
7396 RGWReplicaBounds bounds
;
7397 if (replica_log_type
== ReplicaLog_Metadata
) {
7398 if (!specified_shard_id
) {
7399 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7403 RGWReplicaObjectLogger
logger(store
, pool
, META_REPLICA_LOG_OBJ_PREFIX
);
7404 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7406 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7409 } else if (replica_log_type
== ReplicaLog_Data
) {
7410 if (!specified_shard_id
) {
7411 cerr
<< "ERROR: shard-id must be specified for get operation" << std::endl
;
7414 RGWReplicaObjectLogger
logger(store
, pool
, DATA_REPLICA_LOG_OBJ_PREFIX
);
7415 int ret
= logger
.update_bound(shard_id
, daemon_id
, marker
, time
, &entries
);
7417 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7420 } else if (replica_log_type
== ReplicaLog_Bucket
) {
7421 if (bucket_name
.empty()) {
7422 cerr
<< "ERROR: bucket not specified" << std::endl
;
7425 RGWBucketInfo bucket_info
;
7426 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7428 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7432 RGWReplicaBucketLogger
logger(store
);
7433 ret
= logger
.update_bound(bucket
, shard_id
, daemon_id
, marker
, time
, &entries
);
7435 cerr
<< "ERROR: failed to update bounds: " << cpp_strerror(-ret
) << std::endl
;
7441 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7444 if (bucket_name
.empty() && user_id
.empty()) {
7445 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7449 if (!bucket_name
.empty()) {
7450 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7451 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7454 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7455 max_size
, max_objects
, have_max_size
, have_max_objects
);
7456 } else if (!user_id
.empty()) {
7457 if (quota_scope
== "bucket") {
7458 set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7459 } else if (quota_scope
== "user") {
7460 set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7462 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;