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>
12 #include <liboath/oath.h>
15 #include "auth/Crypto.h"
16 #include "compressor/Compressor.h"
18 #include "common/armor.h"
19 #include "common/ceph_json.h"
20 #include "common/config.h"
21 #include "common/ceph_argparse.h"
22 #include "common/Formatter.h"
23 #include "common/errno.h"
24 #include "common/safe_io.h"
26 #include "include/util.h"
28 #include "cls/rgw/cls_rgw_types.h"
29 #include "cls/rgw/cls_rgw_client.h"
31 #include "global/global_init.h"
33 #include "include/utime.h"
34 #include "include/str_list.h"
37 #include "rgw_bucket.h"
39 #include "rgw_rados.h"
41 #include "rgw_acl_s3.h"
44 #include "rgw_formats.h"
45 #include "rgw_usage.h"
46 #include "rgw_orphan.h"
48 #include "rgw_sync_log_trim.h"
49 #include "rgw_data_sync.h"
50 #include "rgw_rest_conn.h"
51 #include "rgw_realm_watcher.h"
53 #include "rgw_reshard.h"
54 #include "rgw_http_client_curl.h"
56 #include "rgw_pubsub.h"
57 #include "rgw_sync_module_pubsub.h"
59 #include "services/svc_sync_modules.h"
61 #define dout_context g_ceph_context
62 #define dout_subsys ceph_subsys_rgw
64 #define SECRET_KEY_LEN 40
65 #define PUBLIC_ID_LEN 20
67 static RGWRados
*store
= NULL
;
69 static const DoutPrefixProvider
* dpp() {
70 struct GlobalPrefix
: public DoutPrefixProvider
{
71 CephContext
*get_cct() const override
{ return store
->ctx(); }
72 unsigned get_subsys() const override
{ return dout_subsys
; }
73 std::ostream
& gen_prefix(std::ostream
& out
) const override
{ return out
; }
75 static GlobalPrefix global_dpp
;
81 cout
<< "usage: radosgw-admin <cmd> [options...]" << std::endl
;
82 cout
<< "commands:\n";
83 cout
<< " user create create a new user\n" ;
84 cout
<< " user modify modify user\n";
85 cout
<< " user info get user info\n";
86 cout
<< " user rm remove user\n";
87 cout
<< " user suspend suspend a user\n";
88 cout
<< " user enable re-enable user after suspension\n";
89 cout
<< " user check check user info\n";
90 cout
<< " user stats show user stats as accounted by quota subsystem\n";
91 cout
<< " user list list users\n";
92 cout
<< " caps add add user capabilities\n";
93 cout
<< " caps rm remove user capabilities\n";
94 cout
<< " subuser create create a new subuser\n" ;
95 cout
<< " subuser modify modify subuser\n";
96 cout
<< " subuser rm remove subuser\n";
97 cout
<< " key create create access key\n";
98 cout
<< " key rm remove access key\n";
99 cout
<< " bucket list list buckets (specify --allow-unordered for\n";
100 cout
<< " faster, unsorted listing)\n";
101 cout
<< " bucket limit check show bucket sharding stats\n";
102 cout
<< " bucket link link bucket to specified user\n";
103 cout
<< " bucket unlink unlink bucket from specified user\n";
104 cout
<< " bucket stats returns bucket statistics\n";
105 cout
<< " bucket rm remove bucket\n";
106 cout
<< " bucket check check bucket index\n";
107 cout
<< " bucket reshard reshard bucket\n";
108 cout
<< " bucket rewrite rewrite all objects in the specified bucket\n";
109 cout
<< " bucket sync disable disable bucket sync\n";
110 cout
<< " bucket sync enable enable bucket sync\n";
111 cout
<< " bi get retrieve bucket index object entries\n";
112 cout
<< " bi put store bucket index object entries\n";
113 cout
<< " bi list list raw bucket index entries\n";
114 cout
<< " bi purge purge bucket index entries\n";
115 cout
<< " object rm remove object\n";
116 cout
<< " object put put object\n";
117 cout
<< " object stat stat an object for its metadata\n";
118 cout
<< " object unlink unlink object from bucket index\n";
119 cout
<< " object rewrite rewrite the specified object\n";
120 cout
<< " objects expire run expired objects cleanup\n";
121 cout
<< " objects expire-stale list list stale expired objects (caused by reshard)\n";
122 cout
<< " objects expire-stale rm remove stale expired objects\n";
123 cout
<< " period rm remove a period\n";
124 cout
<< " period get get period info\n";
125 cout
<< " period get-current get current period info\n";
126 cout
<< " period pull pull a period\n";
127 cout
<< " period push push a period\n";
128 cout
<< " period list list all periods\n";
129 cout
<< " period update update the staging period\n";
130 cout
<< " period commit commit the staging period\n";
131 cout
<< " quota set set quota params\n";
132 cout
<< " quota enable enable quota\n";
133 cout
<< " quota disable disable quota\n";
134 cout
<< " global quota get view global quota params\n";
135 cout
<< " global quota set set global quota params\n";
136 cout
<< " global quota enable enable a global quota\n";
137 cout
<< " global quota disable disable a global quota\n";
138 cout
<< " realm create create a new realm\n";
139 cout
<< " realm rm remove a realm\n";
140 cout
<< " realm get show realm info\n";
141 cout
<< " realm get-default get default realm name\n";
142 cout
<< " realm list list realms\n";
143 cout
<< " realm list-periods list all realm periods\n";
144 cout
<< " realm rename rename a realm\n";
145 cout
<< " realm set set realm info (requires infile)\n";
146 cout
<< " realm default set realm as default\n";
147 cout
<< " realm pull pull a realm and its current period\n";
148 cout
<< " zonegroup add add a zone to a zonegroup\n";
149 cout
<< " zonegroup create create a new zone group info\n";
150 cout
<< " zonegroup default set default zone group\n";
151 cout
<< " zonegroup rm remove a zone group info\n";
152 cout
<< " zonegroup get show zone group info\n";
153 cout
<< " zonegroup modify modify an existing zonegroup\n";
154 cout
<< " zonegroup set set zone group info (requires infile)\n";
155 cout
<< " zonegroup rm remove a zone from a zonegroup\n";
156 cout
<< " zonegroup rename rename a zone group\n";
157 cout
<< " zonegroup list list all zone groups set on this cluster\n";
158 cout
<< " zonegroup placement list list zonegroup's placement targets\n";
159 cout
<< " zonegroup placement get get a placement target of a specific zonegroup\n";
160 cout
<< " zonegroup placement add add a placement target id to a zonegroup\n";
161 cout
<< " zonegroup placement modify modify a placement target of a specific zonegroup\n";
162 cout
<< " zonegroup placement rm remove a placement target from a zonegroup\n";
163 cout
<< " zonegroup placement default set a zonegroup's default placement target\n";
164 cout
<< " zone create create a new zone\n";
165 cout
<< " zone rm remove a zone\n";
166 cout
<< " zone get show zone cluster params\n";
167 cout
<< " zone modify modify an existing zone\n";
168 cout
<< " zone set set zone cluster params (requires infile)\n";
169 cout
<< " zone list list all zones set on this cluster\n";
170 cout
<< " zone rename rename a zone\n";
171 cout
<< " zone placement list list zone's placement targets\n";
172 cout
<< " zone placement get get a zone placement target\n";
173 cout
<< " zone placement add add a zone placement target\n";
174 cout
<< " zone placement modify modify a zone placement target\n";
175 cout
<< " zone placement rm remove a zone placement target\n";
176 cout
<< " metadata sync status get metadata sync status\n";
177 cout
<< " metadata sync init init metadata sync\n";
178 cout
<< " metadata sync run run metadata sync\n";
179 cout
<< " data sync status get data sync status of the specified source zone\n";
180 cout
<< " data sync init init data sync for the specified source zone\n";
181 cout
<< " data sync run run data sync for the specified source zone\n";
182 cout
<< " pool add add an existing pool for data placement\n";
183 cout
<< " pool rm remove an existing pool from data placement set\n";
184 cout
<< " pools list list placement active set\n";
185 cout
<< " policy read bucket/object policy\n";
186 cout
<< " log list list log objects\n";
187 cout
<< " log show dump a log from specific object or (bucket + date\n";
188 cout
<< " + bucket-id)\n";
189 cout
<< " (NOTE: required to specify formatting of date\n";
190 cout
<< " to \"YYYY-MM-DD-hh\")\n";
191 cout
<< " log rm remove log object\n";
192 cout
<< " usage show show usage (by user, by bucket, date range)\n";
193 cout
<< " usage trim trim usage (by user, by bucket, date range)\n";
194 cout
<< " usage clear reset all the usage stats for the cluster\n";
195 cout
<< " gc list dump expired garbage collection objects (specify\n";
196 cout
<< " --include-all to list all entries, including unexpired)\n";
197 cout
<< " gc process manually process garbage (specify\n";
198 cout
<< " --include-all to process all entries, including unexpired)\n";
199 cout
<< " lc list list all bucket lifecycle progress\n";
200 cout
<< " lc get get a lifecycle bucket configuration\n";
201 cout
<< " lc process manually process lifecycle\n";
202 cout
<< " lc reshard fix fix LC for a resharded bucket\n";
203 cout
<< " metadata get get metadata info\n";
204 cout
<< " metadata put put metadata info\n";
205 cout
<< " metadata rm remove metadata info\n";
206 cout
<< " metadata list list metadata info\n";
207 cout
<< " mdlog list list metadata log\n";
208 cout
<< " mdlog trim trim metadata log (use start-date, end-date or\n";
209 cout
<< " start-marker, end-marker)\n";
210 cout
<< " mdlog status read metadata log status\n";
211 cout
<< " bilog list list bucket index log\n";
212 cout
<< " bilog trim trim bucket index log (use start-marker, end-marker)\n";
213 cout
<< " datalog list list data log\n";
214 cout
<< " datalog trim trim data log\n";
215 cout
<< " datalog status read data log status\n";
216 cout
<< " orphans find init and run search for leaked rados objects (use job-id, pool)\n";
217 cout
<< " orphans finish clean up search for leaked rados objects\n";
218 cout
<< " orphans list-jobs list the current job-ids for orphans search\n";
219 cout
<< " role create create a AWS role for use with STS\n";
220 cout
<< " role rm remove a role\n";
221 cout
<< " role get get a role\n";
222 cout
<< " role list list roles with specified path prefix\n";
223 cout
<< " role modify modify the assume role policy of an existing role\n";
224 cout
<< " role-policy put add/update permission policy to role\n";
225 cout
<< " role-policy list list policies attached to a role\n";
226 cout
<< " role-policy get get the specified inline policy document embedded with the given role\n";
227 cout
<< " role-policy rm remove policy attached to a role\n";
228 cout
<< " reshard add schedule a resharding of a bucket\n";
229 cout
<< " reshard list list all bucket resharding or scheduled to be resharded\n";
230 cout
<< " reshard status read bucket resharding status\n";
231 cout
<< " reshard process process of scheduled reshard jobs\n";
232 cout
<< " reshard cancel cancel resharding a bucket\n";
233 cout
<< " reshard stale-instances list list stale-instances from bucket resharding\n";
234 cout
<< " reshard stale-instances rm cleanup stale-instances from bucket resharding\n";
235 cout
<< " sync error list list sync error\n";
236 cout
<< " sync error trim trim sync error\n";
237 cout
<< " mfa create create a new MFA TOTP token\n";
238 cout
<< " mfa list list MFA TOTP tokens\n";
239 cout
<< " mfa get show MFA TOTP token\n";
240 cout
<< " mfa remove delete MFA TOTP token\n";
241 cout
<< " mfa check check MFA TOTP token\n";
242 cout
<< " mfa resync re-sync MFA TOTP token\n";
243 cout
<< "options:\n";
244 cout
<< " --tenant=<tenant> tenant name\n";
245 cout
<< " --uid=<id> user id\n";
246 cout
<< " --subuser=<name> subuser name\n";
247 cout
<< " --access-key=<key> S3 access key\n";
248 cout
<< " --email=<email> user's email address\n";
249 cout
<< " --secret/--secret-key=<key>\n";
250 cout
<< " specify secret key\n";
251 cout
<< " --gen-access-key generate random access key (for S3)\n";
252 cout
<< " --gen-secret generate random secret key\n";
253 cout
<< " --key-type=<type> key type, options are: swift, s3\n";
254 cout
<< " --temp-url-key[-2]=<key> temp url key\n";
255 cout
<< " --access=<access> Set access permissions for sub-user, should be one\n";
256 cout
<< " of read, write, readwrite, full\n";
257 cout
<< " --display-name=<name> user's display name\n";
258 cout
<< " --max-buckets max number of buckets for a user\n";
259 cout
<< " --admin set the admin flag on the user\n";
260 cout
<< " --system set the system flag on the user\n";
261 cout
<< " --op-mask set the op mask on the user\n";
262 cout
<< " --bucket=<bucket> Specify the bucket name. Also used by the quota command.\n";
263 cout
<< " --pool=<pool> Specify the pool name. Also used to scan for leaked rados objects.\n";
264 cout
<< " --object=<object> object name\n";
265 cout
<< " --date=<date> date in the format yyyy-mm-dd\n";
266 cout
<< " --start-date=<date> start date in the format yyyy-mm-dd\n";
267 cout
<< " --end-date=<date> end date in the format yyyy-mm-dd\n";
268 cout
<< " --bucket-id=<bucket-id> bucket id\n";
269 cout
<< " --shard-id=<shard-id> optional for: \n";
270 cout
<< " mdlog list\n";
271 cout
<< " data sync status\n";
272 cout
<< " required for: \n";
273 cout
<< " mdlog trim\n";
274 cout
<< " --max-entries=<entries> max entries for listing operations\n";
275 cout
<< " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
276 cout
<< " --remote=<remote> zone or zonegroup id of remote gateway\n";
277 cout
<< " --period=<id> period id\n";
278 cout
<< " --url=<url> url for pushing/pulling period/realm\n";
279 cout
<< " --epoch=<number> period epoch\n";
280 cout
<< " --commit commit the period during 'period update'\n";
281 cout
<< " --staging get staging period info\n";
282 cout
<< " --master set as master\n";
283 cout
<< " --master-zone=<id> master zone id\n";
284 cout
<< " --rgw-realm=<name> realm name\n";
285 cout
<< " --realm-id=<id> realm id\n";
286 cout
<< " --realm-new-name=<name> realm new name\n";
287 cout
<< " --rgw-zonegroup=<name> zonegroup name\n";
288 cout
<< " --zonegroup-id=<id> zonegroup id\n";
289 cout
<< " --zonegroup-new-name=<name>\n";
290 cout
<< " zonegroup new name\n";
291 cout
<< " --rgw-zone=<name> name of zone in which radosgw is running\n";
292 cout
<< " --zone-id=<id> zone id\n";
293 cout
<< " --zone-new-name=<name> zone new name\n";
294 cout
<< " --source-zone specify the source zone (for data sync)\n";
295 cout
<< " --default set entity (realm, zonegroup, zone) as default\n";
296 cout
<< " --read-only set zone as read-only (when adding to zonegroup)\n";
297 cout
<< " --redirect-zone specify zone id to redirect when response is 404 (not found)\n";
298 cout
<< " --placement-id placement id for zonegroup placement commands\n";
299 cout
<< " --storage-class storage class for zonegroup placement commands\n";
300 cout
<< " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
301 cout
<< " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
302 cout
<< " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
303 cout
<< " --endpoints=<list> zone endpoints\n";
304 cout
<< " --index-pool=<pool> placement target index pool\n";
305 cout
<< " --data-pool=<pool> placement target data pool\n";
306 cout
<< " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n";
307 cout
<< " --placement-index-type=<type>\n";
308 cout
<< " placement target index type (normal, indexless, or #id)\n";
309 cout
<< " --compression=<type> placement target compression type (plugin name or empty/none)\n";
310 cout
<< " --tier-type=<type> zone tier type\n";
311 cout
<< " --tier-config=<k>=<v>[,...]\n";
312 cout
<< " set zone tier config keys, values\n";
313 cout
<< " --tier-config-rm=<k>[,...]\n";
314 cout
<< " unset zone tier config keys\n";
315 cout
<< " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
316 cout
<< " --sync-from=[zone-name][,...]\n";
317 cout
<< " set list of zones to sync from\n";
318 cout
<< " --sync-from-rm=[zone-name][,...]\n";
319 cout
<< " remove zones from list of zones to sync from\n";
320 cout
<< " --fix besides checking bucket index, will also fix it\n";
321 cout
<< " --check-objects bucket check: rebuilds bucket index according to\n";
322 cout
<< " actual objects state\n";
323 cout
<< " --format=<format> specify output format for certain operations: xml,\n";
325 cout
<< " --purge-data when specified, user removal will also purge all the\n";
326 cout
<< " user data\n";
327 cout
<< " --purge-keys when specified, subuser removal will also purge all the\n";
328 cout
<< " subuser keys\n";
329 cout
<< " --purge-objects remove a bucket's objects before deleting it\n";
330 cout
<< " (NOTE: required to delete a non-empty bucket)\n";
331 cout
<< " --sync-stats option to 'user stats', update user stats with current\n";
332 cout
<< " stats reported by user's buckets indexes\n";
333 cout
<< " --reset-stats option to 'user stats', reset stats in accordance with user buckets\n";
334 cout
<< " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
335 cout
<< " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
336 cout
<< " --skip-zero-entries log show only dumps entries that don't have zero value\n";
337 cout
<< " in one of the numeric field\n";
338 cout
<< " --infile=<file> specify a file to read in when setting data\n";
339 cout
<< " --categories=<list> comma separated list of categories, used in usage show\n";
340 cout
<< " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
341 cout
<< " --yes-i-really-mean-it required for certain operations\n";
342 cout
<< " --warnings-only when specified with bucket limit check, list\n";
343 cout
<< " only buckets nearing or over the current max\n";
344 cout
<< " objects per shard value\n";
345 cout
<< " --bypass-gc when specified with bucket deletion, triggers\n";
346 cout
<< " object deletions by not involving GC\n";
347 cout
<< " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
348 cout
<< " ignores bucket index consistency\n";
349 cout
<< " --min-rewrite-size min object size for bucket rewrite (default 4M)\n";
350 cout
<< " --max-rewrite-size max object size for bucket rewrite (default ULLONG_MAX)\n";
351 cout
<< " --min-rewrite-stripe-size min stripe size for object rewrite (default 0)\n";
352 cout
<< " --trim-delay-ms time interval in msec to limit the frequency of sync error log entries trimming operations,\n";
353 cout
<< " the trimming process will sleep the specified msec for every 1000 entries trimmed\n";
355 cout
<< "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
356 cout
<< "\nQuota options:\n";
357 cout
<< " --max-objects specify max objects (negative value to disable)\n";
358 cout
<< " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
359 cout
<< " --quota-scope scope of quota (bucket, user)\n";
360 cout
<< "\nOrphans search options:\n";
361 cout
<< " --num-shards num of shards to use for keeping the temporary scan info\n";
362 cout
<< " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
363 cout
<< " --job-id set the job id (for orphans find)\n";
364 cout
<< " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
365 cout
<< " --detail detailed mode, log and stat head objects as well\n";
366 cout
<< "\nOrphans list-jobs options:\n";
367 cout
<< " --extra-info provide extra info in job list\n";
368 cout
<< "\nRole options:\n";
369 cout
<< " --role-name name of the role to create\n";
370 cout
<< " --path path to the role\n";
371 cout
<< " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
372 cout
<< " --policy-name name of the policy document\n";
373 cout
<< " --policy-doc permission policy document\n";
374 cout
<< " --path-prefix path prefix for filtering roles\n";
375 cout
<< "\nMFA options:\n";
376 cout
<< " --totp-serial a string that represents the ID of a TOTP token\n";
377 cout
<< " --totp-seed the secret seed that is used to calculate the TOTP\n";
378 cout
<< " --totp-seconds the time resolution that is being used for TOTP generation\n";
379 cout
<< " --totp-window the number of TOTP tokens that are checked before and after the current token when validating token\n";
380 cout
<< " --totp-pin the valid value of a TOTP token at a certain time\n";
382 generic_client_usage();
402 OPT_BUCKET_LIMIT_CHECK
,
407 OPT_BUCKET_SYNC_STATUS
,
408 OPT_BUCKET_SYNC_MARKERS
,
409 OPT_BUCKET_SYNC_INIT
,
411 OPT_BUCKET_SYNC_DISABLE
,
412 OPT_BUCKET_SYNC_ENABLE
,
432 OPT_OBJECTS_EXPIRE_STALE_LIST
,
433 OPT_OBJECTS_EXPIRE_STALE_RM
,
451 OPT_ORPHANS_LIST_JOBS
,
453 OPT_ZONEGROUP_CREATE
,
454 OPT_ZONEGROUP_DEFAULT
,
455 OPT_ZONEGROUP_DELETE
,
457 OPT_ZONEGROUP_MODIFY
,
460 OPT_ZONEGROUP_REMOVE
,
461 OPT_ZONEGROUP_RENAME
,
462 OPT_ZONEGROUP_PLACEMENT_ADD
,
463 OPT_ZONEGROUP_PLACEMENT_MODIFY
,
464 OPT_ZONEGROUP_PLACEMENT_RM
,
465 OPT_ZONEGROUP_PLACEMENT_LIST
,
466 OPT_ZONEGROUP_PLACEMENT_GET
,
467 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
476 OPT_ZONE_PLACEMENT_ADD
,
477 OPT_ZONE_PLACEMENT_MODIFY
,
478 OPT_ZONE_PLACEMENT_RM
,
479 OPT_ZONE_PLACEMENT_LIST
,
480 OPT_ZONE_PLACEMENT_GET
,
487 OPT_METADATA_SYNC_STATUS
,
488 OPT_METADATA_SYNC_INIT
,
489 OPT_METADATA_SYNC_RUN
,
501 OPT_DATA_SYNC_STATUS
,
506 OPT_DATALOG_AUTOTRIM
,
511 OPT_REALM_GET_DEFAULT
,
513 OPT_REALM_LIST_PERIODS
,
520 OPT_PERIOD_GET_CURRENT
,
526 OPT_GLOBAL_QUOTA_GET
,
527 OPT_GLOBAL_QUOTA_SET
,
528 OPT_GLOBAL_QUOTA_ENABLE
,
529 OPT_GLOBAL_QUOTA_DISABLE
,
537 OPT_ROLE_POLICY_LIST
,
539 OPT_ROLE_POLICY_DELETE
,
551 OPT_RESHARD_STALE_INSTANCES_LIST
,
552 OPT_RESHARD_STALE_INSTANCES_DELETE
,
553 OPT_PUBSUB_TOPICS_LIST
,
554 OPT_PUBSUB_TOPIC_CREATE
,
555 OPT_PUBSUB_TOPIC_GET
,
557 OPT_PUBSUB_NOTIFICATION_CREATE
,
558 OPT_PUBSUB_NOTIFICATION_RM
,
560 OPT_PUBSUB_SUB_CREATE
,
566 static int get_cmd(const char *cmd
, const char *prev_cmd
, const char *prev_prev_cmd
, bool *need_more
)
568 using ceph::util::match_str
;
571 // NOTE: please keep the checks in alphabetical order !!!
572 if (strcmp(cmd
, "bi") == 0 ||
573 strcmp(cmd
, "bilog") == 0 ||
574 strcmp(cmd
, "buckets") == 0 ||
575 strcmp(cmd
, "caps") == 0 ||
576 strcmp(cmd
, "data") == 0 ||
577 strcmp(cmd
, "datalog") == 0 ||
578 strcmp(cmd
, "error") == 0 ||
579 strcmp(cmd
, "event") == 0 ||
580 strcmp(cmd
, "expire-stale") == 0 ||
581 strcmp(cmd
, "gc") == 0 ||
582 strcmp(cmd
, "global") == 0 ||
583 strcmp(cmd
, "key") == 0 ||
584 strcmp(cmd
, "log") == 0 ||
585 strcmp(cmd
, "lc") == 0 ||
586 strcmp(cmd
, "mdlog") == 0 ||
587 strcmp(cmd
, "metadata") == 0 ||
588 strcmp(cmd
, "mfa") == 0 ||
589 strcmp(cmd
, "notification") == 0 ||
590 strcmp(cmd
, "object") == 0 ||
591 strcmp(cmd
, "objects") == 0 ||
592 strcmp(cmd
, "olh") == 0 ||
593 strcmp(cmd
, "orphans") == 0 ||
594 strcmp(cmd
, "period") == 0 ||
595 strcmp(cmd
, "placement") == 0 ||
596 strcmp(cmd
, "pool") == 0 ||
597 strcmp(cmd
, "pools") == 0 ||
598 strcmp(cmd
, "pubsub") == 0 ||
599 strcmp(cmd
, "quota") == 0 ||
600 strcmp(cmd
, "realm") == 0 ||
601 strcmp(cmd
, "role") == 0 ||
602 strcmp(cmd
, "role-policy") == 0 ||
603 strcmp(cmd
, "stale-instances") == 0 ||
604 strcmp(cmd
, "sub") == 0 ||
605 strcmp(cmd
, "subuser") == 0 ||
606 strcmp(cmd
, "sync") == 0 ||
607 strcmp(cmd
, "topic") == 0 ||
608 strcmp(cmd
, "topics") == 0 ||
609 strcmp(cmd
, "usage") == 0 ||
610 strcmp(cmd
, "user") == 0 ||
611 strcmp(cmd
, "zone") == 0 ||
612 strcmp(cmd
, "zonegroup") == 0 ||
613 strcmp(cmd
, "zonegroups") == 0) {
619 * can do both radosgw-admin bucket reshard, and radosgw-admin reshard bucket
621 if (strcmp(cmd
, "reshard") == 0 &&
622 !(prev_cmd
&& strcmp(prev_cmd
, "bucket") == 0)) {
626 if (strcmp(cmd
, "bucket") == 0 &&
627 !(prev_cmd
&& strcmp(prev_cmd
, "reshard") == 0)) {
632 if (strcmp(cmd
, "policy") == 0)
638 if (strcmp(prev_cmd
, "user") == 0) {
639 if (strcmp(cmd
, "create") == 0)
640 return OPT_USER_CREATE
;
641 if (strcmp(cmd
, "info") == 0)
642 return OPT_USER_INFO
;
643 if (strcmp(cmd
, "modify") == 0)
644 return OPT_USER_MODIFY
;
645 if (strcmp(cmd
, "rm") == 0)
647 if (strcmp(cmd
, "suspend") == 0)
648 return OPT_USER_SUSPEND
;
649 if (strcmp(cmd
, "enable") == 0)
650 return OPT_USER_ENABLE
;
651 if (strcmp(cmd
, "check") == 0)
652 return OPT_USER_CHECK
;
653 if (strcmp(cmd
, "stats") == 0)
654 return OPT_USER_STATS
;
655 if (strcmp(cmd
, "list") == 0)
656 return OPT_USER_LIST
;
657 } else if (strcmp(prev_cmd
, "subuser") == 0) {
658 if (strcmp(cmd
, "create") == 0)
659 return OPT_SUBUSER_CREATE
;
660 if (strcmp(cmd
, "modify") == 0)
661 return OPT_SUBUSER_MODIFY
;
662 if (strcmp(cmd
, "rm") == 0)
663 return OPT_SUBUSER_RM
;
664 } else if (strcmp(prev_cmd
, "key") == 0) {
665 if (strcmp(cmd
, "create") == 0)
666 return OPT_KEY_CREATE
;
667 if (strcmp(cmd
, "rm") == 0)
669 } else if (strcmp(prev_cmd
, "buckets") == 0) {
670 if (strcmp(cmd
, "list") == 0)
671 return OPT_BUCKETS_LIST
;
672 } else if (strcmp(prev_cmd
, "bucket") == 0) {
673 if (strcmp(cmd
, "list") == 0)
674 return OPT_BUCKETS_LIST
;
675 if (strcmp(cmd
, "link") == 0)
676 return OPT_BUCKET_LINK
;
677 if (strcmp(cmd
, "unlink") == 0)
678 return OPT_BUCKET_UNLINK
;
679 if (strcmp(cmd
, "stats") == 0)
680 return OPT_BUCKET_STATS
;
681 if (strcmp(cmd
, "rm") == 0)
682 return OPT_BUCKET_RM
;
683 if (strcmp(cmd
, "rewrite") == 0)
684 return OPT_BUCKET_REWRITE
;
685 if (strcmp(cmd
, "reshard") == 0)
686 return OPT_BUCKET_RESHARD
;
687 if (strcmp(cmd
, "check") == 0)
688 return OPT_BUCKET_CHECK
;
689 if (strcmp(cmd
, "sync") == 0) {
693 if (strcmp(cmd
, "limit") == 0) {
697 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "bucket") == 0) {
698 if (strcmp(prev_cmd
, "sync") == 0) {
699 if (strcmp(cmd
, "status") == 0)
700 return OPT_BUCKET_SYNC_STATUS
;
701 if (strcmp(cmd
, "markers") == 0)
702 return OPT_BUCKET_SYNC_MARKERS
;
703 if (strcmp(cmd
, "init") == 0)
704 return OPT_BUCKET_SYNC_INIT
;
705 if (strcmp(cmd
, "run") == 0)
706 return OPT_BUCKET_SYNC_RUN
;
707 if (strcmp(cmd
, "disable") == 0)
708 return OPT_BUCKET_SYNC_DISABLE
;
709 if (strcmp(cmd
, "enable") == 0)
710 return OPT_BUCKET_SYNC_ENABLE
;
711 } else if ((strcmp(prev_cmd
, "limit") == 0) &&
712 (strcmp(cmd
, "check") == 0)) {
713 return OPT_BUCKET_LIMIT_CHECK
;
715 } else if (strcmp(prev_cmd
, "log") == 0) {
716 if (strcmp(cmd
, "list") == 0)
718 if (strcmp(cmd
, "show") == 0)
720 if (strcmp(cmd
, "rm") == 0)
722 } else if (strcmp(prev_cmd
, "usage") == 0) {
723 if (strcmp(cmd
, "show") == 0)
724 return OPT_USAGE_SHOW
;
725 if (strcmp(cmd
, "trim") == 0)
726 return OPT_USAGE_TRIM
;
727 if (strcmp(cmd
, "clear") == 0)
728 return OPT_USAGE_CLEAR
;
729 } else if (strcmp(prev_cmd
, "caps") == 0) {
730 if (strcmp(cmd
, "add") == 0)
732 if (strcmp(cmd
, "rm") == 0)
734 } else if (strcmp(prev_cmd
, "pool") == 0) {
735 if (strcmp(cmd
, "add") == 0)
737 if (strcmp(cmd
, "rm") == 0)
739 if (strcmp(cmd
, "list") == 0)
740 return OPT_POOLS_LIST
;
741 } else if (strcmp(prev_cmd
, "pools") == 0) {
742 if (strcmp(cmd
, "list") == 0)
743 return OPT_POOLS_LIST
;
744 } else if (strcmp(prev_cmd
, "object") == 0) {
745 if (strcmp(cmd
, "put") == 0)
746 return OPT_OBJECT_PUT
;
747 if (strcmp(cmd
, "rm") == 0)
748 return OPT_OBJECT_RM
;
749 if (strcmp(cmd
, "unlink") == 0)
750 return OPT_OBJECT_UNLINK
;
751 if (strcmp(cmd
, "stat") == 0)
752 return OPT_OBJECT_STAT
;
753 if (strcmp(cmd
, "rewrite") == 0)
754 return OPT_OBJECT_REWRITE
;
755 } else if (strcmp(prev_cmd
, "objects") == 0) {
756 if (strcmp(cmd
, "expire") == 0)
757 return OPT_OBJECTS_EXPIRE
;
758 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "objects") == 0) &&
759 (strcmp(prev_cmd
, "expire-stale") == 0)) {
760 if (strcmp(cmd
, "list") == 0)
761 return OPT_OBJECTS_EXPIRE_STALE_LIST
;
762 if (strcmp(cmd
, "rm") == 0)
763 return OPT_OBJECTS_EXPIRE_STALE_RM
;
764 } else if (strcmp(prev_cmd
, "olh") == 0) {
765 if (strcmp(cmd
, "get") == 0)
767 if (strcmp(cmd
, "readlog") == 0)
768 return OPT_OLH_READLOG
;
769 } else if (strcmp(prev_cmd
, "bi") == 0) {
770 if (strcmp(cmd
, "get") == 0)
772 if (strcmp(cmd
, "put") == 0)
774 if (strcmp(cmd
, "list") == 0)
776 if (strcmp(cmd
, "purge") == 0)
778 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "global") == 0) &&
779 (strcmp(prev_cmd
, "quota") == 0)) {
780 if (strcmp(cmd
, "get") == 0)
781 return OPT_GLOBAL_QUOTA_GET
;
782 if (strcmp(cmd
, "set") == 0)
783 return OPT_GLOBAL_QUOTA_SET
;
784 if (strcmp(cmd
, "enable") == 0)
785 return OPT_GLOBAL_QUOTA_ENABLE
;
786 if (strcmp(cmd
, "disable") == 0)
787 return OPT_GLOBAL_QUOTA_DISABLE
;
788 } else if (strcmp(prev_cmd
, "period") == 0) {
789 if (match_str(cmd
, "rm", "delete"))
790 return OPT_PERIOD_DELETE
;
791 if (strcmp(cmd
, "get") == 0)
792 return OPT_PERIOD_GET
;
793 if (strcmp(cmd
, "get-current") == 0)
794 return OPT_PERIOD_GET_CURRENT
;
795 if (strcmp(cmd
, "pull") == 0)
796 return OPT_PERIOD_PULL
;
797 if (strcmp(cmd
, "push") == 0)
798 return OPT_PERIOD_PUSH
;
799 if (strcmp(cmd
, "list") == 0)
800 return OPT_PERIOD_LIST
;
801 if (strcmp(cmd
, "update") == 0)
802 return OPT_PERIOD_UPDATE
;
803 if (strcmp(cmd
, "commit") == 0)
804 return OPT_PERIOD_COMMIT
;
805 } else if (strcmp(prev_cmd
, "realm") == 0) {
806 if (strcmp(cmd
, "create") == 0)
807 return OPT_REALM_CREATE
;
808 if (match_str(cmd
, "rm", "delete"))
809 return OPT_REALM_DELETE
;
810 if (strcmp(cmd
, "get") == 0)
811 return OPT_REALM_GET
;
812 if (strcmp(cmd
, "get-default") == 0)
813 return OPT_REALM_GET_DEFAULT
;
814 if (strcmp(cmd
, "list") == 0)
815 return OPT_REALM_LIST
;
816 if (strcmp(cmd
, "list-periods") == 0)
817 return OPT_REALM_LIST_PERIODS
;
818 if (strcmp(cmd
, "rename") == 0)
819 return OPT_REALM_RENAME
;
820 if (strcmp(cmd
, "set") == 0)
821 return OPT_REALM_SET
;
822 if (strcmp(cmd
, "default") == 0)
823 return OPT_REALM_DEFAULT
;
824 if (strcmp(cmd
, "pull") == 0)
825 return OPT_REALM_PULL
;
826 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zonegroup") == 0) &&
827 (strcmp(prev_cmd
, "placement") == 0)) {
828 if (strcmp(cmd
, "add") == 0)
829 return OPT_ZONEGROUP_PLACEMENT_ADD
;
830 if (strcmp(cmd
, "modify") == 0)
831 return OPT_ZONEGROUP_PLACEMENT_MODIFY
;
832 if (strcmp(cmd
, "rm") == 0)
833 return OPT_ZONEGROUP_PLACEMENT_RM
;
834 if (strcmp(cmd
, "list") == 0)
835 return OPT_ZONEGROUP_PLACEMENT_LIST
;
836 if (strcmp(cmd
, "get") == 0)
837 return OPT_ZONEGROUP_PLACEMENT_GET
;
838 if (strcmp(cmd
, "default") == 0)
839 return OPT_ZONEGROUP_PLACEMENT_DEFAULT
;
840 } else if (strcmp(prev_cmd
, "zonegroup") == 0) {
841 if (strcmp(cmd
, "add") == 0)
842 return OPT_ZONEGROUP_ADD
;
843 if (strcmp(cmd
, "create")== 0)
844 return OPT_ZONEGROUP_CREATE
;
845 if (strcmp(cmd
, "default") == 0)
846 return OPT_ZONEGROUP_DEFAULT
;
847 if (strcmp(cmd
, "delete") == 0)
848 return OPT_ZONEGROUP_DELETE
;
849 if (strcmp(cmd
, "get") == 0)
850 return OPT_ZONEGROUP_GET
;
851 if (strcmp(cmd
, "modify") == 0)
852 return OPT_ZONEGROUP_MODIFY
;
853 if (strcmp(cmd
, "list") == 0)
854 return OPT_ZONEGROUP_LIST
;
855 if (strcmp(cmd
, "set") == 0)
856 return OPT_ZONEGROUP_SET
;
857 if (match_str(cmd
, "rm", "remove"))
858 return OPT_ZONEGROUP_REMOVE
;
859 if (strcmp(cmd
, "rename") == 0)
860 return OPT_ZONEGROUP_RENAME
;
861 } else if (strcmp(prev_cmd
, "quota") == 0) {
862 if (strcmp(cmd
, "set") == 0)
863 return OPT_QUOTA_SET
;
864 if (strcmp(cmd
, "enable") == 0)
865 return OPT_QUOTA_ENABLE
;
866 if (strcmp(cmd
, "disable") == 0)
867 return OPT_QUOTA_DISABLE
;
868 } else if (strcmp(prev_cmd
, "zonegroups") == 0) {
869 if (strcmp(cmd
, "list") == 0)
870 return OPT_ZONEGROUP_LIST
;
871 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "zone") == 0) &&
872 (strcmp(prev_cmd
, "placement") == 0)) {
873 if (strcmp(cmd
, "add") == 0)
874 return OPT_ZONE_PLACEMENT_ADD
;
875 if (strcmp(cmd
, "modify") == 0)
876 return OPT_ZONE_PLACEMENT_MODIFY
;
877 if (strcmp(cmd
, "rm") == 0)
878 return OPT_ZONE_PLACEMENT_RM
;
879 if (strcmp(cmd
, "list") == 0)
880 return OPT_ZONE_PLACEMENT_LIST
;
881 if (strcmp(cmd
, "get") == 0)
882 return OPT_ZONE_PLACEMENT_GET
;
883 } else if (strcmp(prev_cmd
, "zone") == 0) {
884 if (match_str(cmd
, "rm", "delete"))
885 return OPT_ZONE_DELETE
;
886 if (strcmp(cmd
, "create") == 0)
887 return OPT_ZONE_CREATE
;
888 if (strcmp(cmd
, "get") == 0)
890 if (strcmp(cmd
, "set") == 0)
892 if (strcmp(cmd
, "list") == 0)
893 return OPT_ZONE_LIST
;
894 if (strcmp(cmd
, "modify") == 0)
895 return OPT_ZONE_MODIFY
;
896 if (strcmp(cmd
, "rename") == 0)
897 return OPT_ZONE_RENAME
;
898 if (strcmp(cmd
, "default") == 0)
899 return OPT_ZONE_DEFAULT
;
900 } else if (strcmp(prev_cmd
, "zones") == 0) {
901 if (strcmp(cmd
, "list") == 0)
902 return OPT_ZONE_LIST
;
903 } else if (strcmp(prev_cmd
, "gc") == 0) {
904 if (strcmp(cmd
, "list") == 0)
906 if (strcmp(cmd
, "process") == 0)
907 return OPT_GC_PROCESS
;
908 } else if (strcmp(prev_cmd
, "lc") == 0) {
909 if (strcmp(cmd
, "list") == 0)
911 if (strcmp(cmd
, "get") == 0)
913 if (strcmp(cmd
, "process") == 0)
914 return OPT_LC_PROCESS
;
915 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "lc") == 0) &&
916 strcmp(prev_cmd
, "reshard") == 0) {
917 if (strcmp(cmd
, "fix") == 0)
918 return OPT_LC_RESHARD_FIX
;
919 } else if (strcmp(prev_cmd
, "orphans") == 0) {
920 if (strcmp(cmd
, "find") == 0)
921 return OPT_ORPHANS_FIND
;
922 if (strcmp(cmd
, "finish") == 0)
923 return OPT_ORPHANS_FINISH
;
924 if (strcmp(cmd
, "list-jobs") == 0)
925 return OPT_ORPHANS_LIST_JOBS
;
926 } else if (strcmp(prev_cmd
, "metadata") == 0) {
927 if (strcmp(cmd
, "get") == 0)
928 return OPT_METADATA_GET
;
929 if (strcmp(cmd
, "put") == 0)
930 return OPT_METADATA_PUT
;
931 if (strcmp(cmd
, "rm") == 0)
932 return OPT_METADATA_RM
;
933 if (strcmp(cmd
, "list") == 0)
934 return OPT_METADATA_LIST
;
935 if (strcmp(cmd
, "sync") == 0) {
939 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "metadata") == 0) &&
940 (strcmp(prev_cmd
, "sync") == 0)) {
941 if (strcmp(cmd
, "status") == 0)
942 return OPT_METADATA_SYNC_STATUS
;
943 if (strcmp(cmd
, "init") == 0)
944 return OPT_METADATA_SYNC_INIT
;
945 if (strcmp(cmd
, "run") == 0)
946 return OPT_METADATA_SYNC_RUN
;
947 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "sync") == 0) &&
948 (strcmp(prev_cmd
, "error") == 0)) {
949 if (strcmp(cmd
, "list") == 0)
950 return OPT_SYNC_ERROR_LIST
;
951 if (strcmp(cmd
, "trim") == 0)
952 return OPT_SYNC_ERROR_TRIM
;
953 } else if (strcmp(prev_cmd
, "mdlog") == 0) {
954 if (strcmp(cmd
, "list") == 0)
955 return OPT_MDLOG_LIST
;
956 if (strcmp(cmd
, "autotrim") == 0)
957 return OPT_MDLOG_AUTOTRIM
;
958 if (strcmp(cmd
, "trim") == 0)
959 return OPT_MDLOG_TRIM
;
960 if (strcmp(cmd
, "fetch") == 0)
961 return OPT_MDLOG_FETCH
;
962 if (strcmp(cmd
, "status") == 0)
963 return OPT_MDLOG_STATUS
;
964 } else if (strcmp(prev_cmd
, "bilog") == 0) {
965 if (strcmp(cmd
, "list") == 0)
966 return OPT_BILOG_LIST
;
967 if (strcmp(cmd
, "trim") == 0)
968 return OPT_BILOG_TRIM
;
969 if (strcmp(cmd
, "status") == 0)
970 return OPT_BILOG_STATUS
;
971 if (strcmp(cmd
, "autotrim") == 0)
972 return OPT_BILOG_AUTOTRIM
;
973 } else if (strcmp(prev_cmd
, "data") == 0) {
974 if (strcmp(cmd
, "sync") == 0) {
978 } else if (strcmp(prev_cmd
, "datalog") == 0) {
979 if (strcmp(cmd
, "list") == 0)
980 return OPT_DATALOG_LIST
;
981 if (strcmp(cmd
, "autotrim") == 0)
982 return OPT_DATALOG_AUTOTRIM
;
983 if (strcmp(cmd
, "trim") == 0)
984 return OPT_DATALOG_TRIM
;
985 if (strcmp(cmd
, "status") == 0)
986 return OPT_DATALOG_STATUS
;
987 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "data") == 0) &&
988 (strcmp(prev_cmd
, "sync") == 0)) {
989 if (strcmp(cmd
, "status") == 0)
990 return OPT_DATA_SYNC_STATUS
;
991 if (strcmp(cmd
, "init") == 0)
992 return OPT_DATA_SYNC_INIT
;
993 if (strcmp(cmd
, "run") == 0)
994 return OPT_DATA_SYNC_RUN
;
995 } else if (strcmp(prev_cmd
, "sync") == 0) {
996 if (strcmp(cmd
, "status") == 0)
997 return OPT_SYNC_STATUS
;
998 } else if (strcmp(prev_cmd
, "role") == 0) {
999 if (strcmp(cmd
, "create") == 0)
1000 return OPT_ROLE_CREATE
;
1001 if (strcmp(cmd
, "rm") == 0)
1002 return OPT_ROLE_DELETE
;
1003 if (strcmp(cmd
, "get") == 0)
1004 return OPT_ROLE_GET
;
1005 if (strcmp(cmd
, "modify") == 0)
1006 return OPT_ROLE_MODIFY
;
1007 if (strcmp(cmd
, "list") == 0)
1008 return OPT_ROLE_LIST
;
1009 } else if (strcmp(prev_cmd
, "role-policy") == 0) {
1010 if (strcmp(cmd
, "put") == 0)
1011 return OPT_ROLE_POLICY_PUT
;
1012 if (strcmp(cmd
, "list") == 0)
1013 return OPT_ROLE_POLICY_LIST
;
1014 if (strcmp(cmd
, "get") == 0)
1015 return OPT_ROLE_POLICY_GET
;
1016 if (match_str(cmd
, "rm", "delete"))
1017 return OPT_ROLE_POLICY_DELETE
;
1018 } else if (strcmp(prev_cmd
, "reshard") == 0) {
1019 if (strcmp(cmd
, "bucket") == 0)
1020 return OPT_BUCKET_RESHARD
;
1021 if (strcmp(cmd
, "add") == 0)
1022 return OPT_RESHARD_ADD
;
1023 if (strcmp(cmd
, "list") == 0)
1024 return OPT_RESHARD_LIST
;
1025 if (strcmp(cmd
, "status") == 0)
1026 return OPT_RESHARD_STATUS
;
1027 if (strcmp(cmd
, "process") == 0)
1028 return OPT_RESHARD_PROCESS
;
1029 if (strcmp(cmd
, "cancel") == 0)
1030 return OPT_RESHARD_CANCEL
;
1031 } else if (strcmp(prev_cmd
, "mfa") == 0) {
1032 if (strcmp(cmd
, "create") == 0)
1033 return OPT_MFA_CREATE
;
1034 if (strcmp(cmd
, "remove") == 0)
1035 return OPT_MFA_REMOVE
;
1036 if (strcmp(cmd
, "get") == 0)
1038 if (strcmp(cmd
, "list") == 0)
1039 return OPT_MFA_LIST
;
1040 if (strcmp(cmd
, "check") == 0)
1041 return OPT_MFA_CHECK
;
1042 if (strcmp(cmd
, "resync") == 0)
1043 return OPT_MFA_RESYNC
;
1044 } else if ((prev_prev_cmd
&& strcmp(prev_prev_cmd
, "reshard") == 0) &&
1045 (strcmp(prev_cmd
, "stale-instances") == 0)) {
1046 if (strcmp(cmd
, "list") == 0)
1047 return OPT_RESHARD_STALE_INSTANCES_LIST
;
1048 if (match_str(cmd
, "rm", "delete"))
1049 return OPT_RESHARD_STALE_INSTANCES_DELETE
;
1050 } else if (prev_prev_cmd
&& strcmp(prev_prev_cmd
, "pubsub") == 0) {
1051 if (strcmp(prev_cmd
, "topics") == 0) {
1052 if (strcmp(cmd
, "list") == 0)
1053 return OPT_PUBSUB_TOPICS_LIST
;
1054 } else if (strcmp(prev_cmd
, "topic") == 0) {
1055 if (strcmp(cmd
, "create") == 0)
1056 return OPT_PUBSUB_TOPIC_CREATE
;
1057 if (strcmp(cmd
, "get") == 0)
1058 return OPT_PUBSUB_TOPIC_GET
;
1059 if (strcmp(cmd
, "rm") == 0)
1060 return OPT_PUBSUB_TOPIC_RM
;
1061 } else if (strcmp(prev_cmd
, "notification") == 0) {
1062 if (strcmp(cmd
, "create") == 0)
1063 return OPT_PUBSUB_NOTIFICATION_CREATE
;
1064 if (strcmp(cmd
, "rm") == 0)
1065 return OPT_PUBSUB_NOTIFICATION_RM
;
1066 } else if (strcmp(prev_cmd
, "sub") == 0) {
1067 if (strcmp(cmd
, "get") == 0)
1068 return OPT_PUBSUB_SUB_GET
;
1069 if (strcmp(cmd
, "create") == 0)
1070 return OPT_PUBSUB_SUB_CREATE
;
1071 if (strcmp(cmd
, "rm") == 0)
1072 return OPT_PUBSUB_SUB_RM
;
1073 if (strcmp(cmd
, "pull") == 0)
1074 return OPT_PUBSUB_SUB_PULL
;
1075 } else if (strcmp(prev_cmd
, "event") == 0) {
1076 if (strcmp(cmd
, "rm") == 0)
1077 return OPT_PUBSUB_EVENT_RM
;
1083 BIIndexType
get_bi_index_type(const string
& type_str
) {
1084 if (type_str
== "plain")
1085 return BIIndexType::Plain
;
1086 if (type_str
== "instance")
1087 return BIIndexType::Instance
;
1088 if (type_str
== "olh")
1089 return BIIndexType::OLH
;
1091 return BIIndexType::Invalid
;
1094 void dump_bi_entry(bufferlist
& bl
, BIIndexType index_type
, Formatter
*formatter
)
1096 auto iter
= bl
.cbegin();
1097 switch (index_type
) {
1098 case BIIndexType::Plain
:
1099 case BIIndexType::Instance
:
1101 rgw_bucket_dir_entry entry
;
1102 decode(entry
, iter
);
1103 encode_json("entry", entry
, formatter
);
1106 case BIIndexType::OLH
:
1108 rgw_bucket_olh_entry entry
;
1109 decode(entry
, iter
);
1110 encode_json("entry", entry
, formatter
);
1119 static void show_user_info(RGWUserInfo
& info
, Formatter
*formatter
)
1121 encode_json("user_info", info
, formatter
);
1122 formatter
->flush(cout
);
1126 static void show_perm_policy(string perm_policy
, Formatter
* formatter
)
1128 formatter
->open_object_section("role");
1129 formatter
->dump_string("Permission policy", perm_policy
);
1130 formatter
->close_section();
1131 formatter
->flush(cout
);
1134 static void show_policy_names(std::vector
<string
> policy_names
, Formatter
* formatter
)
1136 formatter
->open_array_section("PolicyNames");
1137 for (const auto& it
: policy_names
) {
1138 formatter
->dump_string("policyname", it
);
1140 formatter
->close_section();
1141 formatter
->flush(cout
);
1144 static void show_role_info(RGWRole
& role
, Formatter
* formatter
)
1146 formatter
->open_object_section("role");
1147 role
.dump(formatter
);
1148 formatter
->close_section();
1149 formatter
->flush(cout
);
1152 static void show_roles_info(vector
<RGWRole
>& roles
, Formatter
* formatter
)
1154 formatter
->open_array_section("Roles");
1155 for (const auto& it
: roles
) {
1156 formatter
->open_object_section("role");
1158 formatter
->close_section();
1160 formatter
->close_section();
1161 formatter
->flush(cout
);
1164 static void show_reshard_status(
1165 const list
<cls_rgw_bucket_instance_entry
>& status
, Formatter
*formatter
)
1167 formatter
->open_array_section("status");
1168 for (const auto& entry
: status
) {
1169 formatter
->open_object_section("entry");
1170 formatter
->dump_string("reshard_status", to_string(entry
.reshard_status
));
1171 formatter
->dump_string("new_bucket_instance_id",
1172 entry
.new_bucket_instance_id
);
1173 formatter
->dump_int("num_shards", entry
.num_shards
);
1174 formatter
->close_section();
1176 formatter
->close_section();
1177 formatter
->flush(cout
);
1180 class StoreDestructor
{
1183 explicit StoreDestructor(RGWRados
*_s
) : store(_s
) {}
1184 ~StoreDestructor() {
1185 RGWStoreManager::close_storage(store
);
1186 rgw_http_client_cleanup();
1190 static int init_bucket(const string
& tenant_name
, const string
& bucket_name
, const string
& bucket_id
,
1191 RGWBucketInfo
& bucket_info
, rgw_bucket
& bucket
, map
<string
, bufferlist
> *pattrs
= nullptr)
1193 if (!bucket_name
.empty()) {
1194 auto obj_ctx
= store
->svc
.sysobj
->init_obj_ctx();
1196 if (bucket_id
.empty()) {
1197 r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, nullptr, pattrs
);
1199 string bucket_instance_id
= bucket_name
+ ":" + bucket_id
;
1200 r
= store
->get_bucket_instance_info(obj_ctx
, bucket_instance_id
, bucket_info
, NULL
, pattrs
);
1203 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< std::endl
;
1206 bucket
= bucket_info
.bucket
;
1211 static int read_input(const string
& infile
, bufferlist
& bl
)
1214 if (infile
.size()) {
1215 fd
= open(infile
.c_str(), O_RDONLY
);
1218 cerr
<< "error reading input file " << infile
<< std::endl
;
1223 #define READ_CHUNK 8196
1228 char buf
[READ_CHUNK
];
1230 r
= safe_read(fd
, buf
, READ_CHUNK
);
1233 cerr
<< "error while reading input" << std::endl
;
1241 if (infile
.size()) {
1248 static int read_decode_json(const string
& infile
, T
& t
)
1251 int ret
= read_input(infile
, bl
);
1253 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1257 if (!p
.parse(bl
.c_str(), bl
.length())) {
1258 cout
<< "failed to parse JSON" << std::endl
;
1263 decode_json_obj(t
, &p
);
1264 } catch (JSONDecoder::err
& e
) {
1265 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1271 template <class T
, class K
>
1272 static int read_decode_json(const string
& infile
, T
& t
, K
*k
)
1275 int ret
= read_input(infile
, bl
);
1277 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
1281 if (!p
.parse(bl
.c_str(), bl
.length())) {
1282 cout
<< "failed to parse JSON" << std::endl
;
1287 t
.decode_json(&p
, k
);
1288 } catch (JSONDecoder::err
& e
) {
1289 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1295 static int parse_date_str(const string
& date_str
, utime_t
& ut
)
1300 if (!date_str
.empty()) {
1301 int ret
= utime_t::parse_date(date_str
, &epoch
, &nsec
);
1303 cerr
<< "ERROR: failed to parse date: " << date_str
<< std::endl
;
1308 ut
= utime_t(epoch
, nsec
);
1314 static bool decode_dump(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1318 auto iter
= bl
.cbegin();
1322 } catch (buffer::error
& err
) {
1326 encode_json(field_name
, t
, f
);
1331 static bool dump_string(const char *field_name
, bufferlist
& bl
, Formatter
*f
)
1333 string val
= bl
.to_str();
1334 f
->dump_string(field_name
, val
.c_str() /* hide encoded null termination chars */);
1339 void set_quota_info(RGWQuotaInfo
& quota
, int opt_cmd
, int64_t max_size
, int64_t max_objects
,
1340 bool have_max_size
, bool have_max_objects
)
1343 case OPT_QUOTA_ENABLE
:
1344 case OPT_GLOBAL_QUOTA_ENABLE
:
1345 quota
.enabled
= true;
1347 // falling through on purpose
1350 case OPT_GLOBAL_QUOTA_SET
:
1351 if (have_max_objects
) {
1352 if (max_objects
< 0) {
1353 quota
.max_objects
= -1;
1355 quota
.max_objects
= max_objects
;
1358 if (have_max_size
) {
1360 quota
.max_size
= -1;
1362 quota
.max_size
= rgw_rounded_kb(max_size
) * 1024;
1366 case OPT_QUOTA_DISABLE
:
1367 case OPT_GLOBAL_QUOTA_DISABLE
:
1368 quota
.enabled
= false;
1373 int set_bucket_quota(RGWRados
*store
, int opt_cmd
,
1374 const string
& tenant_name
, const string
& bucket_name
,
1375 int64_t max_size
, int64_t max_objects
,
1376 bool have_max_size
, bool have_max_objects
)
1378 RGWBucketInfo bucket_info
;
1379 map
<string
, bufferlist
> attrs
;
1380 auto obj_ctx
= store
->svc
.sysobj
->init_obj_ctx();
1381 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1383 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1387 set_quota_info(bucket_info
.quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1389 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1391 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1397 int set_user_bucket_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1398 bool have_max_size
, bool have_max_objects
)
1400 RGWUserInfo
& user_info
= op_state
.get_user_info();
1402 set_quota_info(user_info
.bucket_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1404 op_state
.set_bucket_quota(user_info
.bucket_quota
);
1407 int r
= user
.modify(op_state
, &err
);
1409 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1415 int set_user_quota(int opt_cmd
, RGWUser
& user
, RGWUserAdminOpState
& op_state
, int64_t max_size
, int64_t max_objects
,
1416 bool have_max_size
, bool have_max_objects
)
1418 RGWUserInfo
& user_info
= op_state
.get_user_info();
1420 set_quota_info(user_info
.user_quota
, opt_cmd
, max_size
, max_objects
, have_max_size
, have_max_objects
);
1422 op_state
.set_user_quota(user_info
.user_quota
);
1425 int r
= user
.modify(op_state
, &err
);
1427 cerr
<< "ERROR: failed updating user info: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
1433 static bool bucket_object_check_filter(const string
& name
)
1436 string ns
; /* empty namespace */
1437 return rgw_obj_key::oid_to_key_in_ns(name
, &k
, ns
);
1440 int check_min_obj_stripe_size(RGWRados
*store
, RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, uint64_t min_stripe_size
, bool *need_rewrite
)
1442 map
<string
, bufferlist
> attrs
;
1445 RGWObjectCtx
obj_ctx(store
);
1446 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1447 RGWRados::Object::Read
read_op(&op_target
);
1449 read_op
.params
.attrs
= &attrs
;
1450 read_op
.params
.obj_size
= &obj_size
;
1452 int ret
= read_op
.prepare();
1454 lderr(store
->ctx()) << "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << dendl
;
1458 map
<string
, bufferlist
>::iterator iter
;
1459 iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1460 if (iter
== attrs
.end()) {
1461 *need_rewrite
= (obj_size
>= min_stripe_size
);
1465 RGWObjManifest manifest
;
1468 bufferlist
& bl
= iter
->second
;
1469 auto biter
= bl
.cbegin();
1470 decode(manifest
, biter
);
1471 } catch (buffer::error
& err
) {
1472 ldout(store
->ctx(), 0) << "ERROR: failed to decode manifest" << dendl
;
1476 map
<uint64_t, RGWObjManifestPart
>& objs
= manifest
.get_explicit_objs();
1477 map
<uint64_t, RGWObjManifestPart
>::iterator oiter
;
1478 for (oiter
= objs
.begin(); oiter
!= objs
.end(); ++oiter
) {
1479 RGWObjManifestPart
& part
= oiter
->second
;
1481 if (part
.size
>= min_stripe_size
) {
1482 *need_rewrite
= true;
1486 *need_rewrite
= false;
1492 int check_obj_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, bool remove_bad
, Formatter
*f
) {
1493 f
->open_object_section("object");
1494 f
->open_object_section("key");
1495 f
->dump_string("type", "head");
1496 f
->dump_string("name", key
.name
);
1497 f
->dump_string("instance", key
.instance
);
1503 get_obj_bucket_and_oid_loc(obj
, oid
, locator
);
1505 f
->dump_string("oid", oid
);
1506 f
->dump_string("locator", locator
);
1509 RGWObjectCtx
obj_ctx(store
);
1511 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
1512 RGWRados::Object::Read
read_op(&op_target
);
1514 int ret
= read_op
.prepare();
1515 bool needs_fixing
= (ret
== -ENOENT
);
1517 f
->dump_bool("needs_fixing", needs_fixing
);
1519 string status
= (needs_fixing
? "needs_fixing" : "ok");
1521 if ((needs_fixing
|| remove_bad
) && fix
) {
1522 ret
= store
->fix_head_obj_locator(bucket_info
, needs_fixing
, remove_bad
, key
);
1524 cerr
<< "ERROR: fix_head_object_locator() returned ret=" << ret
<< std::endl
;
1531 f
->dump_string("status", status
);
1538 int check_obj_tail_locator_underscore(RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_obj_key
& key
, bool fix
, Formatter
*f
) {
1539 f
->open_object_section("object");
1540 f
->open_object_section("key");
1541 f
->dump_string("type", "tail");
1542 f
->dump_string("name", key
.name
);
1543 f
->dump_string("instance", key
.instance
);
1549 int ret
= store
->fix_tail_obj_locator(bucket_info
, key
, fix
, &needs_fixing
);
1551 cerr
<< "ERROR: fix_tail_object_locator_underscore() returned ret=" << ret
<< std::endl
;
1554 status
= (needs_fixing
&& !fix
? "needs_fixing" : "ok");
1557 f
->dump_bool("needs_fixing", needs_fixing
);
1558 f
->dump_string("status", status
);
1565 int do_check_object_locator(const string
& tenant_name
, const string
& bucket_name
,
1566 bool fix
, bool remove_bad
, Formatter
*f
)
1568 if (remove_bad
&& !fix
) {
1569 cerr
<< "ERROR: can't have remove_bad specified without fix" << std::endl
;
1573 RGWBucketInfo bucket_info
;
1577 f
->open_object_section("bucket");
1578 f
->dump_string("bucket", bucket_name
);
1579 int ret
= init_bucket(tenant_name
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1581 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1587 int max_entries
= 1000;
1591 vector
<rgw_bucket_dir_entry
> result
;
1592 map
<string
, bool> common_prefixes
;
1595 RGWRados::Bucket
target(store
, bucket_info
);
1596 RGWRados::Bucket::List
list_op(&target
);
1600 list_op
.params
.prefix
= prefix
;
1601 list_op
.params
.delim
= delim
;
1602 list_op
.params
.marker
= rgw_obj_key(marker
);
1603 list_op
.params
.ns
= ns
;
1604 list_op
.params
.enforce_ns
= true;
1605 list_op
.params
.list_versions
= true;
1607 f
->open_array_section("check_objects");
1609 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
1611 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
1615 count
+= result
.size();
1617 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
1618 rgw_obj_key key
= iter
->key
;
1619 rgw_obj
obj(bucket
, key
);
1621 if (key
.name
[0] == '_') {
1622 ret
= check_obj_locator_underscore(bucket_info
, obj
, key
, fix
, remove_bad
, f
);
1625 ret
= check_obj_tail_locator_underscore(bucket_info
, obj
, key
, fix
, f
);
1627 cerr
<< "ERROR: check_obj_tail_locator_underscore(): " << cpp_strerror(-ret
) << std::endl
;
1634 } while (truncated
&& count
< max_entries
);
1643 int set_bucket_sync_enabled(RGWRados
*store
, int opt_cmd
, const string
& tenant_name
, const string
& bucket_name
)
1645 RGWBucketInfo bucket_info
;
1646 map
<string
, bufferlist
> attrs
;
1647 auto obj_ctx
= store
->svc
.sysobj
->init_obj_ctx();
1649 int r
= store
->get_bucket_info(obj_ctx
, tenant_name
, bucket_name
, bucket_info
, NULL
, &attrs
);
1651 cerr
<< "could not get bucket info for bucket=" << bucket_name
<< ": " << cpp_strerror(-r
) << std::endl
;
1655 if (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
) {
1656 bucket_info
.flags
&= ~BUCKET_DATASYNC_DISABLED
;
1657 } else if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1658 bucket_info
.flags
|= BUCKET_DATASYNC_DISABLED
;
1661 r
= store
->put_bucket_instance_info(bucket_info
, false, real_time(), &attrs
);
1663 cerr
<< "ERROR: failed writing bucket instance info: " << cpp_strerror(-r
) << std::endl
;
1667 int shards_num
= bucket_info
.num_shards
? bucket_info
.num_shards
: 1;
1668 int shard_id
= bucket_info
.num_shards
? 0 : -1;
1670 if (opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) {
1671 r
= store
->stop_bi_log_entries(bucket_info
, -1);
1673 lderr(store
->ctx()) << "ERROR: failed writing stop bilog" << dendl
;
1677 r
= store
->resync_bi_log_entries(bucket_info
, -1);
1679 lderr(store
->ctx()) << "ERROR: failed writing resync bilog" << dendl
;
1684 for (int i
= 0; i
< shards_num
; ++i
, ++shard_id
) {
1685 r
= store
->data_log
->add_entry(bucket_info
.bucket
, shard_id
);
1687 lderr(store
->ctx()) << "ERROR: failed writing data log" << dendl
;
1696 /// search for a matching zone/zonegroup id and return a connection if found
1697 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1698 const RGWZoneGroup
& zonegroup
,
1699 const std::string
& remote
)
1701 boost::optional
<RGWRESTConn
> conn
;
1702 if (remote
== zonegroup
.get_id()) {
1703 conn
.emplace(store
->ctx(), store
->svc
.zone
, remote
, zonegroup
.endpoints
);
1705 for (const auto& z
: zonegroup
.zones
) {
1706 const auto& zone
= z
.second
;
1707 if (remote
== zone
.id
) {
1708 conn
.emplace(store
->ctx(), store
->svc
.zone
, remote
, zone
.endpoints
);
1716 /// search each zonegroup for a connection
1717 static boost::optional
<RGWRESTConn
> get_remote_conn(RGWRados
*store
,
1718 const RGWPeriodMap
& period_map
,
1719 const std::string
& remote
)
1721 boost::optional
<RGWRESTConn
> conn
;
1722 for (const auto& zg
: period_map
.zonegroups
) {
1723 conn
= get_remote_conn(store
, zg
.second
, remote
);
1731 // we expect a very small response
1732 static constexpr size_t MAX_REST_RESPONSE
= 128 * 1024;
1734 static int send_to_remote_gateway(RGWRESTConn
* conn
, req_info
& info
,
1735 bufferlist
& in_data
, JSONParser
& parser
)
1741 ceph::bufferlist response
;
1743 int ret
= conn
->forward(user
, info
, nullptr, MAX_REST_RESPONSE
, &in_data
, &response
);
1745 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1746 if (parse_ret
< 0) {
1747 cerr
<< "failed to parse response" << std::endl
;
1753 static int send_to_url(const string
& url
, const string
& access
,
1754 const string
& secret
, req_info
& info
,
1755 bufferlist
& in_data
, JSONParser
& parser
)
1757 if (access
.empty() || secret
.empty()) {
1758 cerr
<< "An --access-key and --secret must be provided with --url." << std::endl
;
1766 RGWRESTSimpleRequest
req(g_ceph_context
, info
.method
, url
, NULL
, ¶ms
);
1768 bufferlist response
;
1769 int ret
= req
.forward_request(key
, info
, MAX_REST_RESPONSE
, &in_data
, &response
);
1771 int parse_ret
= parser
.parse(response
.c_str(), response
.length());
1772 if (parse_ret
< 0) {
1773 cout
<< "failed to parse response" << std::endl
;
1779 static int send_to_remote_or_url(RGWRESTConn
*conn
, const string
& url
,
1780 const string
& access
, const string
& secret
,
1781 req_info
& info
, bufferlist
& in_data
,
1785 return send_to_remote_gateway(conn
, info
, in_data
, parser
);
1787 return send_to_url(url
, access
, secret
, info
, in_data
, parser
);
1790 static int commit_period(RGWRealm
& realm
, RGWPeriod
& period
,
1791 string remote
, const string
& url
,
1792 const string
& access
, const string
& secret
,
1795 const string
& master_zone
= period
.get_master_zone();
1796 if (master_zone
.empty()) {
1797 cerr
<< "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl
;
1800 // are we the period's master zone?
1801 if (store
->svc
.zone
->get_zone_params().get_id() == master_zone
) {
1802 // read the current period
1803 RGWPeriod current_period
;
1804 int ret
= current_period
.init(g_ceph_context
, store
->svc
.sysobj
, realm
.get_id());
1806 cerr
<< "Error initializing current period: "
1807 << cpp_strerror(-ret
) << std::endl
;
1810 // the master zone can commit locally
1811 ret
= period
.commit(store
, realm
, current_period
, cerr
, force
);
1813 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1818 if (remote
.empty() && url
.empty()) {
1819 // use the new master zone's connection
1820 remote
= master_zone
;
1821 cout
<< "Sending period to new master zone " << remote
<< std::endl
;
1823 boost::optional
<RGWRESTConn
> conn
;
1824 RGWRESTConn
*remote_conn
= nullptr;
1825 if (!remote
.empty()) {
1826 conn
= get_remote_conn(store
, period
.get_map(), remote
);
1828 cerr
<< "failed to find a zone or zonegroup for remote "
1829 << remote
<< std::endl
;
1832 remote_conn
= &*conn
;
1835 // push period to the master with an empty period id
1839 req_info
info(g_ceph_context
, &env
);
1840 info
.method
= "POST";
1841 info
.request_uri
= "/admin/realm/period";
1843 // json format into a bufferlist
1844 JSONFormatter
jf(false);
1845 encode_json("period", period
, &jf
);
1850 int ret
= send_to_remote_or_url(remote_conn
, url
, access
, secret
, info
, bl
, p
);
1852 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1854 // did we parse an error message?
1855 auto message
= p
.find_obj("Message");
1857 cerr
<< "Reason: " << message
->get_data() << std::endl
;
1862 // decode the response and store it back
1864 decode_json_obj(period
, &p
);
1865 } catch (JSONDecoder::err
& e
) {
1866 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1869 if (period
.get_id().empty()) {
1870 cerr
<< "Period commit got back an empty period id" << std::endl
;
1873 // the master zone gave us back the period that it committed, so it's
1874 // safe to save it as our latest epoch
1875 ret
= period
.store_info(false);
1877 cerr
<< "Error storing committed period " << period
.get_id() << ": "
1878 << cpp_strerror(ret
) << std::endl
;
1881 ret
= period
.set_latest_epoch(period
.get_epoch());
1883 cerr
<< "Error updating period epoch: " << cpp_strerror(ret
) << std::endl
;
1886 ret
= period
.reflect();
1888 cerr
<< "Error updating local objects: " << cpp_strerror(ret
) << std::endl
;
1891 realm
.notify_new_period(period
);
1895 static int update_period(const string
& realm_id
, const string
& realm_name
,
1896 const string
& period_id
, const string
& period_epoch
,
1897 bool commit
, const string
& remote
, const string
& url
,
1898 const string
& access
, const string
& secret
,
1899 Formatter
*formatter
, bool force
)
1901 RGWRealm
realm(realm_id
, realm_name
);
1902 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
1904 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
1908 if (!period_epoch
.empty()) {
1909 epoch
= atoi(period_epoch
.c_str());
1911 RGWPeriod
period(period_id
, epoch
);
1912 ret
= period
.init(g_ceph_context
, store
->svc
.sysobj
, realm
.get_id());
1914 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
1918 ret
= period
.update();
1920 // Dropping the error message here, as both the ret codes were handled in
1924 ret
= period
.store_info(false);
1926 cerr
<< "failed to store period: " << cpp_strerror(-ret
) << std::endl
;
1930 ret
= commit_period(realm
, period
, remote
, url
, access
, secret
, force
);
1932 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
1936 encode_json("period", period
, formatter
);
1937 formatter
->flush(cout
);
1941 static int init_bucket_for_sync(const string
& tenant
, const string
& bucket_name
,
1942 const string
& bucket_id
, rgw_bucket
& bucket
)
1944 RGWBucketInfo bucket_info
;
1946 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
1948 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
1955 static int do_period_pull(RGWRESTConn
*remote_conn
, const string
& url
,
1956 const string
& access_key
, const string
& secret_key
,
1957 const string
& realm_id
, const string
& realm_name
,
1958 const string
& period_id
, const string
& period_epoch
,
1962 req_info
info(g_ceph_context
, &env
);
1963 info
.method
= "GET";
1964 info
.request_uri
= "/admin/realm/period";
1966 map
<string
, string
> ¶ms
= info
.args
.get_params();
1967 if (!realm_id
.empty())
1968 params
["realm_id"] = realm_id
;
1969 if (!realm_name
.empty())
1970 params
["realm_name"] = realm_name
;
1971 if (!period_id
.empty())
1972 params
["period_id"] = period_id
;
1973 if (!period_epoch
.empty())
1974 params
["epoch"] = period_epoch
;
1978 int ret
= send_to_remote_or_url(remote_conn
, url
, access_key
, secret_key
,
1981 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
1984 ret
= period
->init(g_ceph_context
, store
->svc
.sysobj
, false);
1986 cerr
<< "faile to init period " << cpp_strerror(-ret
) << std::endl
;
1990 decode_json_obj(*period
, &p
);
1991 } catch (JSONDecoder::err
& e
) {
1992 cout
<< "failed to decode JSON input: " << e
.message
<< std::endl
;
1995 ret
= period
->store_info(false);
1997 cerr
<< "Error storing period " << period
->get_id() << ": " << cpp_strerror(ret
) << std::endl
;
1999 // store latest epoch (ignore errors)
2000 period
->update_latest_epoch(period
->get_epoch());
2004 static int read_current_period_id(RGWRados
* store
, const std::string
& realm_id
,
2005 const std::string
& realm_name
,
2006 std::string
* period_id
)
2008 RGWRealm
realm(realm_id
, realm_name
);
2009 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
2011 std::cerr
<< "failed to read realm: " << cpp_strerror(-ret
) << std::endl
;
2014 *period_id
= realm
.get_current_period();
2018 void flush_ss(stringstream
& ss
, list
<string
>& l
)
2020 if (!ss
.str().empty()) {
2021 l
.push_back(ss
.str());
2026 stringstream
& push_ss(stringstream
& ss
, list
<string
>& l
, int tab
= 0)
2030 ss
<< setw(tab
) << "" << setw(1);
2035 static void get_md_sync_status(list
<string
>& status
)
2037 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
2039 int ret
= sync
.init();
2041 status
.push_back(string("failed to retrieve sync info: sync.init() failed: ") + cpp_strerror(-ret
));
2045 rgw_meta_sync_status sync_status
;
2046 ret
= sync
.read_sync_status(&sync_status
);
2048 status
.push_back(string("failed to read sync status: ") + cpp_strerror(-ret
));
2053 switch (sync_status
.sync_info
.state
) {
2054 case rgw_meta_sync_info::StateInit
:
2055 status_str
= "init";
2057 case rgw_meta_sync_info::StateBuildingFullSyncMaps
:
2058 status_str
= "preparing for full sync";
2060 case rgw_meta_sync_info::StateSync
:
2061 status_str
= "syncing";
2064 status_str
= "unknown";
2067 status
.push_back(status_str
);
2069 uint64_t full_total
= 0;
2070 uint64_t full_complete
= 0;
2074 int total_shards
= 0;
2075 set
<int> shards_behind_set
;
2077 for (auto marker_iter
: sync_status
.sync_markers
) {
2078 full_total
+= marker_iter
.second
.total_entries
;
2080 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
2082 full_complete
+= marker_iter
.second
.pos
;
2083 int shard_id
= marker_iter
.first
;
2084 shards_behind_set
.insert(shard_id
);
2086 full_complete
+= marker_iter
.second
.total_entries
;
2088 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
) {
2094 push_ss(ss
, status
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2097 push_ss(ss
, status
) << "full sync: " << full_total
- full_complete
<< " entries to sync";
2100 push_ss(ss
, status
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2102 map
<int, RGWMetadataLogInfo
> master_shards_info
;
2103 string master_period
= store
->svc
.zone
->get_current_period_id();
2105 ret
= sync
.read_master_log_shards_info(master_period
, &master_shards_info
);
2107 status
.push_back(string("failed to fetch master sync status: ") + cpp_strerror(-ret
));
2111 map
<int, string
> shards_behind
;
2112 if (sync_status
.sync_info
.period
!= master_period
) {
2113 status
.push_back(string("master is on a different period: master_period=" +
2114 master_period
+ " local_period=" + sync_status
.sync_info
.period
));
2116 for (auto local_iter
: sync_status
.sync_markers
) {
2117 int shard_id
= local_iter
.first
;
2118 auto iter
= master_shards_info
.find(shard_id
);
2120 if (iter
== master_shards_info
.end()) {
2122 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2125 auto master_marker
= iter
->second
.marker
;
2126 if (local_iter
.second
.state
== rgw_meta_sync_marker::SyncState::IncrementalSync
&&
2127 master_marker
> local_iter
.second
.marker
) {
2128 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2129 shards_behind_set
.insert(shard_id
);
2134 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2135 if (total_behind
== 0) {
2136 push_ss(ss
, status
) << "metadata is caught up with master";
2138 push_ss(ss
, status
) << "metadata is behind on " << total_behind
<< " shards";
2140 push_ss(ss
, status
) << "behind shards: " << "[" << shards_behind_set
<< "]";
2142 map
<int, rgw_mdlog_shard_data
> master_pos
;
2143 ret
= sync
.read_master_log_shards_next(sync_status
.sync_info
.period
, shards_behind
, &master_pos
);
2145 derr
<< "ERROR: failed to fetch master next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2147 std::optional
<std::pair
<int, ceph::real_time
>> oldest
;
2149 for (auto iter
: master_pos
) {
2150 rgw_mdlog_shard_data
& shard_data
= iter
.second
;
2152 if (!shard_data
.entries
.empty()) {
2153 rgw_mdlog_entry
& entry
= shard_data
.entries
.front();
2155 oldest
.emplace(iter
.first
, entry
.timestamp
);
2156 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
->second
) {
2157 oldest
.emplace(iter
.first
, entry
.timestamp
);
2163 push_ss(ss
, status
) << "oldest incremental change not applied: "
2164 << oldest
->second
<< " [" << oldest
->first
<< ']';
2169 flush_ss(ss
, status
);
2172 static void get_data_sync_status(const string
& source_zone
, list
<string
>& status
, int tab
)
2178 if (!store
->svc
.zone
->find_zone_by_id(source_zone
, &sz
)) {
2179 push_ss(ss
, status
, tab
) << string("zone not found");
2180 flush_ss(ss
, status
);
2184 if (!store
->svc
.zone
->zone_syncs_from(store
->svc
.zone
->get_zone(), *sz
)) {
2185 push_ss(ss
, status
, tab
) << string("not syncing from zone");
2186 flush_ss(ss
, status
);
2189 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
, nullptr);
2191 int ret
= sync
.init();
2193 push_ss(ss
, status
, tab
) << string("failed to retrieve sync info: ") + cpp_strerror(-ret
);
2194 flush_ss(ss
, status
);
2198 rgw_data_sync_status sync_status
;
2199 ret
= sync
.read_sync_status(&sync_status
);
2200 if (ret
< 0 && ret
!= -ENOENT
) {
2201 push_ss(ss
, status
, tab
) << string("failed read sync status: ") + cpp_strerror(-ret
);
2205 set
<int> recovering_shards
;
2206 ret
= sync
.read_recovering_shards(sync_status
.sync_info
.num_shards
, recovering_shards
);
2207 if (ret
< 0 && ret
!= ENOENT
) {
2208 push_ss(ss
, status
, tab
) << string("failed read recovering shards: ") + cpp_strerror(-ret
);
2213 switch (sync_status
.sync_info
.state
) {
2214 case rgw_data_sync_info::StateInit
:
2215 status_str
= "init";
2217 case rgw_data_sync_info::StateBuildingFullSyncMaps
:
2218 status_str
= "preparing for full sync";
2220 case rgw_data_sync_info::StateSync
:
2221 status_str
= "syncing";
2224 status_str
= "unknown";
2227 push_ss(ss
, status
, tab
) << status_str
;
2229 uint64_t full_total
= 0;
2230 uint64_t full_complete
= 0;
2234 int total_shards
= 0;
2235 set
<int> shards_behind_set
;
2237 for (auto marker_iter
: sync_status
.sync_markers
) {
2238 full_total
+= marker_iter
.second
.total_entries
;
2240 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::FullSync
) {
2242 full_complete
+= marker_iter
.second
.pos
;
2243 int shard_id
= marker_iter
.first
;
2244 shards_behind_set
.insert(shard_id
);
2246 full_complete
+= marker_iter
.second
.total_entries
;
2248 if (marker_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
) {
2253 push_ss(ss
, status
, tab
) << "full sync: " << num_full
<< "/" << total_shards
<< " shards";
2256 push_ss(ss
, status
, tab
) << "full sync: " << full_total
- full_complete
<< " buckets to sync";
2259 push_ss(ss
, status
, tab
) << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards";
2261 map
<int, RGWDataChangesLogInfo
> source_shards_info
;
2263 ret
= sync
.read_source_log_shards_info(&source_shards_info
);
2265 push_ss(ss
, status
, tab
) << string("failed to fetch source sync status: ") + cpp_strerror(-ret
);
2269 map
<int, string
> shards_behind
;
2271 for (auto local_iter
: sync_status
.sync_markers
) {
2272 int shard_id
= local_iter
.first
;
2273 auto iter
= source_shards_info
.find(shard_id
);
2275 if (iter
== source_shards_info
.end()) {
2277 derr
<< "ERROR: could not find remote sync shard status for shard_id=" << shard_id
<< dendl
;
2280 auto master_marker
= iter
->second
.marker
;
2281 if (local_iter
.second
.state
== rgw_data_sync_marker::SyncState::IncrementalSync
&&
2282 master_marker
> local_iter
.second
.marker
) {
2283 shards_behind
[shard_id
] = local_iter
.second
.marker
;
2284 shards_behind_set
.insert(shard_id
);
2288 int total_behind
= shards_behind
.size() + (sync_status
.sync_info
.num_shards
- num_inc
);
2289 int total_recovering
= recovering_shards
.size();
2290 if (total_behind
== 0 && total_recovering
== 0) {
2291 push_ss(ss
, status
, tab
) << "data is caught up with source";
2292 } else if (total_behind
> 0) {
2293 push_ss(ss
, status
, tab
) << "data is behind on " << total_behind
<< " shards";
2295 push_ss(ss
, status
, tab
) << "behind shards: " << "[" << shards_behind_set
<< "]" ;
2297 map
<int, rgw_datalog_shard_data
> master_pos
;
2298 ret
= sync
.read_source_log_shards_next(shards_behind
, &master_pos
);
2300 derr
<< "ERROR: failed to fetch next positions (" << cpp_strerror(-ret
) << ")" << dendl
;
2302 std::optional
<std::pair
<int, ceph::real_time
>> oldest
;
2304 for (auto iter
: master_pos
) {
2305 rgw_datalog_shard_data
& shard_data
= iter
.second
;
2307 if (!shard_data
.entries
.empty()) {
2308 rgw_datalog_entry
& entry
= shard_data
.entries
.front();
2310 oldest
.emplace(iter
.first
, entry
.timestamp
);
2311 } else if (!ceph::real_clock::is_zero(entry
.timestamp
) && entry
.timestamp
< oldest
->second
) {
2312 oldest
.emplace(iter
.first
, entry
.timestamp
);
2318 push_ss(ss
, status
, tab
) << "oldest incremental change not applied: "
2319 << oldest
->second
<< " [" << oldest
->first
<< ']';
2324 if (total_recovering
> 0) {
2325 push_ss(ss
, status
, tab
) << total_recovering
<< " shards are recovering";
2326 push_ss(ss
, status
, tab
) << "recovering shards: " << "[" << recovering_shards
<< "]";
2329 flush_ss(ss
, status
);
2332 static void tab_dump(const string
& header
, int width
, const list
<string
>& entries
)
2336 for (auto e
: entries
) {
2337 cout
<< std::setw(width
) << s
<< std::setw(1) << " " << e
<< std::endl
;
2343 static void sync_status(Formatter
*formatter
)
2345 const RGWRealm
& realm
= store
->svc
.zone
->get_realm();
2346 const RGWZoneGroup
& zonegroup
= store
->svc
.zone
->get_zonegroup();
2347 const RGWZone
& zone
= store
->svc
.zone
->get_zone();
2351 cout
<< std::setw(width
) << "realm" << std::setw(1) << " " << realm
.get_id() << " (" << realm
.get_name() << ")" << std::endl
;
2352 cout
<< std::setw(width
) << "zonegroup" << std::setw(1) << " " << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")" << std::endl
;
2353 cout
<< std::setw(width
) << "zone" << std::setw(1) << " " << zone
.id
<< " (" << zone
.name
<< ")" << std::endl
;
2355 list
<string
> md_status
;
2357 if (store
->svc
.zone
->is_meta_master()) {
2358 md_status
.push_back("no sync (zone is master)");
2360 get_md_sync_status(md_status
);
2363 tab_dump("metadata sync", width
, md_status
);
2365 list
<string
> data_status
;
2367 auto& zone_conn_map
= store
->svc
.zone
->get_zone_conn_map();
2369 for (auto iter
: zone_conn_map
) {
2370 const string
& source_id
= iter
.first
;
2371 string source_str
= "source: ";
2372 string s
= source_str
+ source_id
;
2374 if (store
->svc
.zone
->find_zone_by_id(source_id
, &sz
)) {
2375 s
+= string(" (") + sz
->name
+ ")";
2377 data_status
.push_back(s
);
2378 get_data_sync_status(source_id
, data_status
, source_str
.size());
2381 tab_dump("data sync", width
, data_status
);
2385 int w
; // indent width
2386 std::string_view header
;
2387 indented(int w
, std::string_view header
= "") : w(w
), header(header
) {}
2389 std::ostream
& operator<<(std::ostream
& out
, const indented
& h
) {
2390 return out
<< std::setw(h
.w
) << h
.header
<< std::setw(1) << ' ';
2393 static int remote_bilog_markers(RGWRados
*store
, const RGWZone
& source
,
2394 RGWRESTConn
*conn
, const RGWBucketInfo
& info
,
2395 BucketIndexShardsManager
*markers
)
2397 const auto instance_key
= info
.bucket
.get_key();
2398 const rgw_http_param_pair params
[] = {
2399 { "type" , "bucket-index" },
2400 { "bucket-instance", instance_key
.c_str() },
2401 { "info" , nullptr },
2402 { nullptr, nullptr }
2404 rgw_bucket_index_marker_info result
;
2405 int r
= conn
->get_json_resource("/admin/log/", params
, result
);
2407 lderr(store
->ctx()) << "failed to fetch remote log markers: " << cpp_strerror(r
) << dendl
;
2410 r
= markers
->from_string(result
.max_marker
, -1);
2412 lderr(store
->ctx()) << "failed to decode remote log markers" << dendl
;
2418 static int bucket_source_sync_status(RGWRados
*store
, const RGWZone
& zone
,
2419 const RGWZone
& source
, RGWRESTConn
*conn
,
2420 const RGWBucketInfo
& bucket_info
,
2421 int width
, std::ostream
& out
)
2423 out
<< indented
{width
, "source zone"} << source
.id
<< " (" << source
.name
<< ")\n";
2425 // syncing from this zone?
2426 if (!zone
.syncs_from(source
.name
)) {
2427 out
<< indented
{width
} << "not in sync_from\n";
2430 std::vector
<rgw_bucket_shard_sync_info
> status
;
2431 int r
= rgw_bucket_sync_status(dpp(), store
, source
.id
, bucket_info
, &status
);
2433 lderr(store
->ctx()) << "failed to read bucket sync status: " << cpp_strerror(r
) << dendl
;
2439 uint64_t full_complete
= 0;
2440 const size_t total_shards
= status
.size();
2442 using BucketSyncState
= rgw_bucket_shard_sync_info::SyncState
;
2443 for (size_t shard_id
= 0; shard_id
< total_shards
; shard_id
++) {
2444 auto& m
= status
[shard_id
];
2445 if (m
.state
== BucketSyncState::StateFullSync
) {
2447 full_complete
+= m
.full_marker
.count
;
2448 } else if (m
.state
== BucketSyncState::StateIncrementalSync
) {
2453 out
<< indented
{width
} << "full sync: " << num_full
<< "/" << total_shards
<< " shards\n";
2455 out
<< indented
{width
} << "full sync: " << full_complete
<< " objects completed\n";
2457 out
<< indented
{width
} << "incremental sync: " << num_inc
<< "/" << total_shards
<< " shards\n";
2459 BucketIndexShardsManager remote_markers
;
2460 r
= remote_bilog_markers(store
, source
, conn
, bucket_info
, &remote_markers
);
2462 lderr(store
->ctx()) << "failed to read remote log: " << cpp_strerror(r
) << dendl
;
2466 std::set
<int> shards_behind
;
2467 for (auto& r
: remote_markers
.get()) {
2468 auto shard_id
= r
.first
;
2469 auto& m
= status
[shard_id
];
2470 if (r
.second
.empty()) {
2471 continue; // empty bucket index shard
2473 auto pos
= BucketIndexShardsManager::get_shard_marker(m
.inc_marker
.position
);
2474 if (m
.state
!= BucketSyncState::StateIncrementalSync
|| pos
!= r
.second
) {
2475 shards_behind
.insert(shard_id
);
2478 if (!shards_behind
.empty()) {
2479 out
<< indented
{width
} << "bucket is behind on " << shards_behind
.size() << " shards\n";
2480 out
<< indented
{width
} << "behind shards: [" << shards_behind
<< "]\n" ;
2481 } else if (!num_full
) {
2482 out
<< indented
{width
} << "bucket is caught up with source\n";
2487 static int bucket_sync_status(RGWRados
*store
, const RGWBucketInfo
& info
,
2488 const std::string
& source_zone_id
,
2491 const RGWRealm
& realm
= store
->svc
.zone
->get_realm();
2492 const RGWZoneGroup
& zonegroup
= store
->svc
.zone
->get_zonegroup();
2493 const RGWZone
& zone
= store
->svc
.zone
->get_zone();
2494 constexpr int width
= 15;
2496 out
<< indented
{width
, "realm"} << realm
.get_id() << " (" << realm
.get_name() << ")\n";
2497 out
<< indented
{width
, "zonegroup"} << zonegroup
.get_id() << " (" << zonegroup
.get_name() << ")\n";
2498 out
<< indented
{width
, "zone"} << zone
.id
<< " (" << zone
.name
<< ")\n";
2499 out
<< indented
{width
, "bucket"} << info
.bucket
<< "\n\n";
2501 if (!info
.datasync_flag_enabled()) {
2502 out
<< "Sync is disabled for bucket " << info
.bucket
.name
<< '\n';
2506 auto& zone_conn_map
= store
->svc
.zone
->get_zone_conn_map();
2507 if (!source_zone_id
.empty()) {
2508 auto z
= zonegroup
.zones
.find(source_zone_id
);
2509 if (z
== zonegroup
.zones
.end()) {
2510 lderr(store
->ctx()) << "Source zone not found in zonegroup "
2511 << zonegroup
.get_name() << dendl
;
2514 auto c
= zone_conn_map
.find(source_zone_id
);
2515 if (c
== zone_conn_map
.end()) {
2516 lderr(store
->ctx()) << "No connection to zone " << z
->second
.name
<< dendl
;
2519 return bucket_source_sync_status(store
, zone
, z
->second
, c
->second
,
2523 for (const auto& z
: zonegroup
.zones
) {
2524 auto c
= zone_conn_map
.find(z
.second
.id
);
2525 if (c
!= zone_conn_map
.end()) {
2526 bucket_source_sync_status(store
, zone
, z
.second
, c
->second
,
2533 static void parse_tier_config_param(const string
& s
, map
<string
, string
, ltstr_nocase
>& out
)
2541 confs
.push_back(cur_conf
);
2548 } else if (c
== '}') {
2553 if (!cur_conf
.empty()) {
2554 confs
.push_back(cur_conf
);
2557 for (auto c
: confs
) {
2558 ssize_t pos
= c
.find("=");
2562 out
[c
.substr(0, pos
)] = c
.substr(pos
+ 1);
2567 static int check_pool_support_omap(const rgw_pool
& pool
)
2569 librados::IoCtx io_ctx
;
2570 int ret
= store
->get_rados_handle()->ioctx_create(pool
.to_str().c_str(), io_ctx
);
2572 // the pool may not exist at this moment, we have no way to check if it supports omap.
2576 ret
= io_ctx
.omap_clear("__omap_test_not_exist_oid__");
2577 if (ret
== -EOPNOTSUPP
) {
2585 int check_reshard_bucket_params(RGWRados
*store
,
2586 const string
& bucket_name
,
2587 const string
& tenant
,
2588 const string
& bucket_id
,
2589 bool num_shards_specified
,
2591 int yes_i_really_mean_it
,
2593 RGWBucketInfo
& bucket_info
,
2594 map
<string
, bufferlist
>& attrs
)
2596 if (bucket_name
.empty()) {
2597 cerr
<< "ERROR: bucket not specified" << std::endl
;
2601 if (!num_shards_specified
) {
2602 cerr
<< "ERROR: --num-shards not specified" << std::endl
;
2606 if (num_shards
> (int)store
->get_max_bucket_shards()) {
2607 cerr
<< "ERROR: num_shards too high, max value: " << store
->get_max_bucket_shards() << std::endl
;
2611 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
2613 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
2617 if (bucket_info
.reshard_status
!= CLS_RGW_RESHARD_NOT_RESHARDING
) {
2618 // if in_progress or done then we have an old BucketInfo
2619 cerr
<< "ERROR: the bucket is currently undergoing resharding and "
2620 "cannot be added to the reshard list at this time" << std::endl
;
2624 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
2626 if (num_shards
<= num_source_shards
&& !yes_i_really_mean_it
) {
2627 cerr
<< "num shards is less or equal to current shards count" << std::endl
2628 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
2634 int create_new_bucket_instance(RGWRados
*store
,
2636 const RGWBucketInfo
& bucket_info
,
2637 map
<string
, bufferlist
>& attrs
,
2638 RGWBucketInfo
& new_bucket_info
)
2641 store
->create_bucket_id(&new_bucket_info
.bucket
.bucket_id
);
2642 new_bucket_info
.bucket
.oid
.clear();
2644 new_bucket_info
.num_shards
= new_num_shards
;
2645 new_bucket_info
.objv_tracker
.clear();
2647 int ret
= store
->init_bucket_index(new_bucket_info
, new_bucket_info
.num_shards
);
2649 cerr
<< "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret
) << std::endl
;
2653 ret
= store
->put_bucket_instance_info(new_bucket_info
, true, real_time(), &attrs
);
2655 cerr
<< "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret
) << std::endl
;
2662 static int scan_totp(CephContext
*cct
, ceph::real_time
& now
, rados::cls::otp::otp_info_t
& totp
, vector
<string
>& pins
,
2665 #define MAX_TOTP_SKEW_HOURS (24 * 7)
2666 ceph_assert(pins
.size() == 2);
2668 time_t start_time
= ceph::real_clock::to_time_t(now
);
2669 time_t time_ofs
= 0, time_ofs_abs
= 0;
2670 time_t step_size
= totp
.step_size
;
2671 if (step_size
== 0) {
2672 step_size
= OATH_TOTP_DEFAULT_TIME_STEP_SIZE
;
2677 uint32_t max_skew
= MAX_TOTP_SKEW_HOURS
* 3600;
2679 while (time_ofs_abs
< max_skew
) {
2680 int rc
= oath_totp_validate2(totp
.seed_bin
.c_str(), totp
.seed_bin
.length(),
2687 if (rc
!= OATH_INVALID_OTP
) {
2688 rc
= oath_totp_validate2(totp
.seed_bin
.c_str(), totp
.seed_bin
.length(),
2691 time_ofs
- step_size
, /* smaller time_ofs moves time forward */
2695 if (rc
!= OATH_INVALID_OTP
) {
2696 *pofs
= time_ofs
- step_size
+ step_size
* totp
.window
/ 2;
2697 ldout(cct
, 20) << "found at time=" << start_time
- time_ofs
<< " time_ofs=" << time_ofs
<< dendl
;
2702 time_ofs_abs
= (++count
) * step_size
;
2703 time_ofs
= sign
* time_ofs_abs
;
2709 static int trim_sync_error_log(int shard_id
, const ceph::real_time
& start_time
,
2710 const ceph::real_time
& end_time
,
2711 const string
& start_marker
, const string
& end_marker
,
2714 auto oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
,
2716 // call cls_log_trim() until it returns -ENODATA
2718 int ret
= store
->time_log_trim(oid
, start_time
, end_time
,
2719 start_marker
, end_marker
);
2720 if (ret
== -ENODATA
) {
2727 std::this_thread::sleep_for(std::chrono::milliseconds(delay_ms
));
2733 const string
& get_tier_type(RGWRados
*store
) {
2734 return store
->svc
.zone
->get_zone().tier_type
;
2737 int main(int argc
, const char **argv
)
2739 vector
<const char*> args
;
2740 argv_to_vec(argc
, (const char **)argv
, args
);
2742 cerr
<< argv
[0] << ": -h or --help for usage" << std::endl
;
2745 if (ceph_argparse_need_usage(args
)) {
2750 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
2751 CODE_ENVIRONMENT_UTILITY
, 0);
2753 // for region -> zonegroup conversion (must happen before common_init_finish())
2754 if (!g_conf()->rgw_region
.empty() && g_conf()->rgw_zonegroup
.empty()) {
2755 g_conf().set_val_or_die("rgw_zonegroup", g_conf()->rgw_region
.c_str());
2758 common_init_finish(g_ceph_context
);
2762 std::string access_key
, secret_key
, user_email
, display_name
;
2763 std::string bucket_name
, pool_name
, object
;
2765 std::string date
, subuser
, access
, format
;
2766 std::string start_date
, end_date
;
2767 std::string key_type_str
;
2768 std::string period_id
, period_epoch
, remote
, url
;
2769 std::string master_zone
;
2770 std::string realm_name
, realm_id
, realm_new_name
;
2771 std::string zone_name
, zone_id
, zone_new_name
;
2772 std::string zonegroup_name
, zonegroup_id
, zonegroup_new_name
;
2773 std::string api_name
;
2774 std::string role_name
, path
, assume_role_doc
, policy_name
, perm_policy_doc
, path_prefix
;
2775 std::string redirect_zone
;
2776 bool redirect_zone_set
= false;
2777 list
<string
> endpoints
;
2779 int sync_from_all_specified
= false;
2780 bool sync_from_all
= false;
2781 list
<string
> sync_from
;
2782 list
<string
> sync_from_rm
;
2784 int set_default
= 0;
2785 bool is_master
= false;
2786 bool is_master_set
= false;
2788 bool read_only
= false;
2789 int is_read_only_set
= false;
2791 int staging
= false;
2792 int key_type
= KEY_TYPE_UNDEFINED
;
2794 uint32_t perm_mask
= 0;
2796 int opt_cmd
= OPT_NO_CMD
;
2798 int gen_access_key
= 0;
2799 int gen_secret_key
= 0;
2800 bool set_perm
= false;
2801 bool set_temp_url_key
= false;
2802 map
<int, string
> temp_url_keys
;
2804 Formatter
*formatter
= NULL
;
2805 int purge_data
= false;
2806 int pretty_format
= false;
2807 int show_log_entries
= true;
2808 int show_log_sum
= true;
2809 int skip_zero_entries
= false; // log show
2810 int purge_keys
= false;
2811 int yes_i_really_mean_it
= false;
2812 int delete_child_objects
= false;
2814 int remove_bad
= false;
2815 int check_head_obj_locator
= false;
2816 int max_buckets
= -1;
2817 bool max_buckets_specified
= false;
2818 map
<string
, bool> categories
;
2820 int check_objects
= false;
2821 RGWUserAdminOpState user_op
;
2822 RGWBucketAdminOpState bucket_op
;
2824 string metadata_key
;
2825 RGWObjVersionTracker objv_tracker
;
2827 string start_marker
;
2829 int max_entries
= -1;
2830 bool max_entries_specified
= false;
2832 bool admin_specified
= false;
2834 bool system_specified
= false;
2836 bool specified_shard_id
= false;
2841 string object_version
;
2842 string placement_id
;
2843 string storage_class
;
2845 list
<string
> tags_add
;
2846 list
<string
> tags_rm
;
2848 int64_t max_objects
= -1;
2849 int64_t max_size
= -1;
2850 bool have_max_objects
= false;
2851 bool have_max_size
= false;
2852 int include_all
= false;
2853 int allow_unordered
= false;
2855 int sync_stats
= false;
2856 int reset_stats
= false;
2857 int bypass_gc
= false;
2858 int warnings_only
= false;
2859 int inconsistent_index
= false;
2861 int verbose
= false;
2863 int extra_info
= false;
2865 uint64_t min_rewrite_size
= 4 * 1024 * 1024;
2866 uint64_t max_rewrite_size
= ULLONG_MAX
;
2867 uint64_t min_rewrite_stripe_size
= 0;
2869 BIIndexType bi_index_type
= BIIndexType::Plain
;
2873 bool num_shards_specified
= false;
2874 int max_concurrent_ios
= 32;
2875 uint64_t orphan_stale_secs
= (24 * 3600);
2879 std::ostringstream errs
;
2882 string source_zone_name
;
2883 string source_zone
; /* zone id */
2886 bool tier_type_specified
= false;
2888 map
<string
, string
, ltstr_nocase
> tier_config_add
;
2889 map
<string
, string
, ltstr_nocase
> tier_config_rm
;
2891 boost::optional
<string
> index_pool
;
2892 boost::optional
<string
> data_pool
;
2893 boost::optional
<string
> data_extra_pool
;
2894 RGWBucketIndexType placement_index_type
= RGWBIType_Normal
;
2895 bool index_type_specified
= false;
2897 boost::optional
<std::string
> compression_type
;
2901 string totp_seed_type
= "hex";
2902 vector
<string
> totp_pin
;
2903 int totp_seconds
= 0;
2904 int totp_window
= 0;
2905 int trim_delay_ms
= 0;
2909 string sub_oid_prefix
;
2910 string sub_dest_bucket
;
2911 string sub_push_endpoint
;
2913 rgw::notify::EventTypeList event_types
;
2915 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
2916 if (ceph_argparse_double_dash(args
, i
)) {
2918 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--uid", (char*)NULL
)) {
2919 user_id
.from_str(val
);
2920 if (user_id
.empty()) {
2921 cerr
<< "no value for uid" << std::endl
;
2924 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tenant", (char*)NULL
)) {
2926 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access-key", (char*)NULL
)) {
2928 } else if (ceph_argparse_witharg(args
, i
, &val
, "--subuser", (char*)NULL
)) {
2930 } else if (ceph_argparse_witharg(args
, i
, &val
, "--secret", "--secret-key", (char*)NULL
)) {
2932 } else if (ceph_argparse_witharg(args
, i
, &val
, "-e", "--email", (char*)NULL
)) {
2934 user_op
.user_email_specified
=true;
2935 } else if (ceph_argparse_witharg(args
, i
, &val
, "-n", "--display-name", (char*)NULL
)) {
2937 } else if (ceph_argparse_witharg(args
, i
, &val
, "-b", "--bucket", (char*)NULL
)) {
2939 } else if (ceph_argparse_witharg(args
, i
, &val
, "-p", "--pool", (char*)NULL
)) {
2941 pool
= rgw_pool(pool_name
);
2942 } else if (ceph_argparse_witharg(args
, i
, &val
, "-o", "--object", (char*)NULL
)) {
2944 } else if (ceph_argparse_witharg(args
, i
, &val
, "--object-version", (char*)NULL
)) {
2945 object_version
= val
;
2946 } else if (ceph_argparse_witharg(args
, i
, &val
, "--client-id", (char*)NULL
)) {
2948 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-id", (char*)NULL
)) {
2950 } else if (ceph_argparse_witharg(args
, i
, &val
, "--op-mask", (char*)NULL
)) {
2952 } else if (ceph_argparse_witharg(args
, i
, &val
, "--key-type", (char*)NULL
)) {
2954 if (key_type_str
.compare("swift") == 0) {
2955 key_type
= KEY_TYPE_SWIFT
;
2956 } else if (key_type_str
.compare("s3") == 0) {
2957 key_type
= KEY_TYPE_S3
;
2959 cerr
<< "bad key type: " << key_type_str
<< std::endl
;
2962 } else if (ceph_argparse_witharg(args
, i
, &val
, "--job-id", (char*)NULL
)) {
2964 } else if (ceph_argparse_binary_flag(args
, i
, &gen_access_key
, NULL
, "--gen-access-key", (char*)NULL
)) {
2966 } else if (ceph_argparse_binary_flag(args
, i
, &gen_secret_key
, NULL
, "--gen-secret", (char*)NULL
)) {
2968 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_entries
, NULL
, "--show-log-entries", (char*)NULL
)) {
2970 } else if (ceph_argparse_binary_flag(args
, i
, &show_log_sum
, NULL
, "--show-log-sum", (char*)NULL
)) {
2972 } else if (ceph_argparse_binary_flag(args
, i
, &skip_zero_entries
, NULL
, "--skip-zero-entries", (char*)NULL
)) {
2974 } else if (ceph_argparse_binary_flag(args
, i
, &admin
, NULL
, "--admin", (char*)NULL
)) {
2975 admin_specified
= true;
2976 } else if (ceph_argparse_binary_flag(args
, i
, &system
, NULL
, "--system", (char*)NULL
)) {
2977 system_specified
= true;
2978 } else if (ceph_argparse_binary_flag(args
, i
, &verbose
, NULL
, "--verbose", (char*)NULL
)) {
2980 } else if (ceph_argparse_binary_flag(args
, i
, &staging
, NULL
, "--staging", (char*)NULL
)) {
2982 } else if (ceph_argparse_binary_flag(args
, i
, &commit
, NULL
, "--commit", (char*)NULL
)) {
2984 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-size", (char*)NULL
)) {
2985 min_rewrite_size
= (uint64_t)atoll(val
.c_str());
2986 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-rewrite-size", (char*)NULL
)) {
2987 max_rewrite_size
= (uint64_t)atoll(val
.c_str());
2988 } else if (ceph_argparse_witharg(args
, i
, &val
, "--min-rewrite-stripe-size", (char*)NULL
)) {
2989 min_rewrite_stripe_size
= (uint64_t)atoll(val
.c_str());
2990 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-buckets", (char*)NULL
)) {
2991 max_buckets
= (int)strict_strtol(val
.c_str(), 10, &err
);
2993 cerr
<< "ERROR: failed to parse max buckets: " << err
<< std::endl
;
2996 max_buckets_specified
= true;
2997 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-entries", (char*)NULL
)) {
2998 max_entries
= (int)strict_strtol(val
.c_str(), 10, &err
);
2999 max_entries_specified
= true;
3001 cerr
<< "ERROR: failed to parse max entries: " << err
<< std::endl
;
3004 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-size", (char*)NULL
)) {
3005 max_size
= strict_iec_cast
<long long>(val
.c_str(), &err
);
3007 cerr
<< "ERROR: failed to parse max size: " << err
<< std::endl
;
3010 have_max_size
= true;
3011 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-objects", (char*)NULL
)) {
3012 max_objects
= (int64_t)strict_strtoll(val
.c_str(), 10, &err
);
3014 cerr
<< "ERROR: failed to parse max objects: " << err
<< std::endl
;
3017 have_max_objects
= true;
3018 } else if (ceph_argparse_witharg(args
, i
, &val
, "--date", "--time", (char*)NULL
)) {
3020 if (end_date
.empty())
3022 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-date", "--start-time", (char*)NULL
)) {
3024 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-date", "--end-time", (char*)NULL
)) {
3026 } else if (ceph_argparse_witharg(args
, i
, &val
, "--num-shards", (char*)NULL
)) {
3027 num_shards
= (int)strict_strtol(val
.c_str(), 10, &err
);
3029 cerr
<< "ERROR: failed to parse num shards: " << err
<< std::endl
;
3032 num_shards_specified
= true;
3033 } else if (ceph_argparse_witharg(args
, i
, &val
, "--max-concurrent-ios", (char*)NULL
)) {
3034 max_concurrent_ios
= (int)strict_strtol(val
.c_str(), 10, &err
);
3036 cerr
<< "ERROR: failed to parse max concurrent ios: " << err
<< std::endl
;
3039 } else if (ceph_argparse_witharg(args
, i
, &val
, "--orphan-stale-secs", (char*)NULL
)) {
3040 orphan_stale_secs
= (uint64_t)strict_strtoll(val
.c_str(), 10, &err
);
3042 cerr
<< "ERROR: failed to parse orphan stale secs: " << err
<< std::endl
;
3045 } else if (ceph_argparse_witharg(args
, i
, &val
, "--shard-id", (char*)NULL
)) {
3046 shard_id
= (int)strict_strtol(val
.c_str(), 10, &err
);
3048 cerr
<< "ERROR: failed to parse shard id: " << err
<< std::endl
;
3051 specified_shard_id
= true;
3052 } else if (ceph_argparse_witharg(args
, i
, &val
, "--access", (char*)NULL
)) {
3054 perm_mask
= rgw_str_to_perm(access
.c_str());
3056 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key", (char*)NULL
)) {
3057 temp_url_keys
[0] = val
;
3058 set_temp_url_key
= true;
3059 } else if (ceph_argparse_witharg(args
, i
, &val
, "--temp-url-key2", "--temp-url-key-2", (char*)NULL
)) {
3060 temp_url_keys
[1] = val
;
3061 set_temp_url_key
= true;
3062 } else if (ceph_argparse_witharg(args
, i
, &val
, "--bucket-id", (char*)NULL
)) {
3064 if (bucket_id
.empty()) {
3065 cerr
<< "bad bucket-id" << std::endl
;
3068 } else if (ceph_argparse_witharg(args
, i
, &val
, "--format", (char*)NULL
)) {
3070 } else if (ceph_argparse_witharg(args
, i
, &val
, "--categories", (char*)NULL
)) {
3071 string cat_str
= val
;
3072 list
<string
> cat_list
;
3073 list
<string
>::iterator iter
;
3074 get_str_list(cat_str
, cat_list
);
3075 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
3076 categories
[*iter
] = true;
3078 } else if (ceph_argparse_binary_flag(args
, i
, &delete_child_objects
, NULL
, "--purge-objects", (char*)NULL
)) {
3080 } else if (ceph_argparse_binary_flag(args
, i
, &pretty_format
, NULL
, "--pretty-format", (char*)NULL
)) {
3082 } else if (ceph_argparse_binary_flag(args
, i
, &purge_data
, NULL
, "--purge-data", (char*)NULL
)) {
3083 delete_child_objects
= purge_data
;
3084 } else if (ceph_argparse_binary_flag(args
, i
, &purge_keys
, NULL
, "--purge-keys", (char*)NULL
)) {
3086 } else if (ceph_argparse_binary_flag(args
, i
, &yes_i_really_mean_it
, NULL
, "--yes-i-really-mean-it", (char*)NULL
)) {
3088 } else if (ceph_argparse_binary_flag(args
, i
, &fix
, NULL
, "--fix", (char*)NULL
)) {
3090 } else if (ceph_argparse_binary_flag(args
, i
, &remove_bad
, NULL
, "--remove-bad", (char*)NULL
)) {
3092 } else if (ceph_argparse_binary_flag(args
, i
, &check_head_obj_locator
, NULL
, "--check-head-obj-locator", (char*)NULL
)) {
3094 } else if (ceph_argparse_binary_flag(args
, i
, &check_objects
, NULL
, "--check-objects", (char*)NULL
)) {
3096 } else if (ceph_argparse_binary_flag(args
, i
, &sync_stats
, NULL
, "--sync-stats", (char*)NULL
)) {
3098 } else if (ceph_argparse_binary_flag(args
, i
, &reset_stats
, NULL
, "--reset-stats", (char*)NULL
)) {
3100 } else if (ceph_argparse_binary_flag(args
, i
, &include_all
, NULL
, "--include-all", (char*)NULL
)) {
3102 } else if (ceph_argparse_binary_flag(args
, i
, &allow_unordered
, NULL
, "--allow-unordered", (char*)NULL
)) {
3104 } else if (ceph_argparse_binary_flag(args
, i
, &extra_info
, NULL
, "--extra-info", (char*)NULL
)) {
3106 } else if (ceph_argparse_binary_flag(args
, i
, &bypass_gc
, NULL
, "--bypass-gc", (char*)NULL
)) {
3108 } else if (ceph_argparse_binary_flag(args
, i
, &warnings_only
, NULL
, "--warnings-only", (char*)NULL
)) {
3110 } else if (ceph_argparse_binary_flag(args
, i
, &inconsistent_index
, NULL
, "--inconsistent-index", (char*)NULL
)) {
3112 } else if (ceph_argparse_witharg(args
, i
, &val
, "--caps", (char*)NULL
)) {
3114 } else if (ceph_argparse_witharg(args
, i
, &val
, "-i", "--infile", (char*)NULL
)) {
3116 } else if (ceph_argparse_witharg(args
, i
, &val
, "--metadata-key", (char*)NULL
)) {
3118 } else if (ceph_argparse_witharg(args
, i
, &val
, "--marker", (char*)NULL
)) {
3120 } else if (ceph_argparse_witharg(args
, i
, &val
, "--start-marker", (char*)NULL
)) {
3122 } else if (ceph_argparse_witharg(args
, i
, &val
, "--end-marker", (char*)NULL
)) {
3124 } else if (ceph_argparse_witharg(args
, i
, &val
, "--quota-scope", (char*)NULL
)) {
3126 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-type", (char*)NULL
)) {
3127 string index_type_str
= val
;
3128 bi_index_type
= get_bi_index_type(index_type_str
);
3129 if (bi_index_type
== BIIndexType::Invalid
) {
3130 cerr
<< "ERROR: invalid bucket index entry type" << std::endl
;
3133 } else if (ceph_argparse_binary_flag(args
, i
, &is_master_int
, NULL
, "--master", (char*)NULL
)) {
3134 is_master
= (bool)is_master_int
;
3135 is_master_set
= true;
3136 } else if (ceph_argparse_binary_flag(args
, i
, &set_default
, NULL
, "--default", (char*)NULL
)) {
3138 } else if (ceph_argparse_witharg(args
, i
, &val
, "--redirect-zone", (char*)NULL
)) {
3139 redirect_zone
= val
;
3140 redirect_zone_set
= true;
3141 } else if (ceph_argparse_binary_flag(args
, i
, &read_only_int
, NULL
, "--read-only", (char*)NULL
)) {
3142 read_only
= (bool)read_only_int
;
3143 is_read_only_set
= true;
3144 } else if (ceph_argparse_witharg(args
, i
, &val
, "--master-zone", (char*)NULL
)) {
3146 } else if (ceph_argparse_witharg(args
, i
, &val
, "--period", (char*)NULL
)) {
3148 } else if (ceph_argparse_witharg(args
, i
, &val
, "--epoch", (char*)NULL
)) {
3150 } else if (ceph_argparse_witharg(args
, i
, &val
, "--remote", (char*)NULL
)) {
3152 } else if (ceph_argparse_witharg(args
, i
, &val
, "--url", (char*)NULL
)) {
3154 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-id", (char*)NULL
)) {
3156 } else if (ceph_argparse_witharg(args
, i
, &val
, "--realm-new-name", (char*)NULL
)) {
3157 realm_new_name
= val
;
3158 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-id", (char*)NULL
)) {
3160 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zonegroup-new-name", (char*)NULL
)) {
3161 zonegroup_new_name
= val
;
3162 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-id", (char*)NULL
)) {
3164 } else if (ceph_argparse_witharg(args
, i
, &val
, "--storage-class", (char*)NULL
)) {
3165 storage_class
= val
;
3166 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags", (char*)NULL
)) {
3167 get_str_list(val
, tags
);
3168 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-add", (char*)NULL
)) {
3169 get_str_list(val
, tags_add
);
3170 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tags-rm", (char*)NULL
)) {
3171 get_str_list(val
, tags_rm
);
3172 } else if (ceph_argparse_witharg(args
, i
, &val
, "--api-name", (char*)NULL
)) {
3174 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-id", (char*)NULL
)) {
3176 } else if (ceph_argparse_witharg(args
, i
, &val
, "--zone-new-name", (char*)NULL
)) {
3177 zone_new_name
= val
;
3178 } else if (ceph_argparse_witharg(args
, i
, &val
, "--endpoints", (char*)NULL
)) {
3179 get_str_list(val
, endpoints
);
3180 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from", (char*)NULL
)) {
3181 get_str_list(val
, sync_from
);
3182 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sync-from-rm", (char*)NULL
)) {
3183 get_str_list(val
, sync_from_rm
);
3184 } else if (ceph_argparse_binary_flag(args
, i
, &tmp_int
, NULL
, "--sync-from-all", (char*)NULL
)) {
3185 sync_from_all
= (bool)tmp_int
;
3186 sync_from_all_specified
= true;
3187 } else if (ceph_argparse_witharg(args
, i
, &val
, "--source-zone", (char*)NULL
)) {
3188 source_zone_name
= val
;
3189 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-type", (char*)NULL
)) {
3191 tier_type_specified
= true;
3192 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config", (char*)NULL
)) {
3193 parse_tier_config_param(val
, tier_config_add
);
3194 } else if (ceph_argparse_witharg(args
, i
, &val
, "--tier-config-rm", (char*)NULL
)) {
3195 parse_tier_config_param(val
, tier_config_rm
);
3196 } else if (ceph_argparse_witharg(args
, i
, &val
, "--index-pool", (char*)NULL
)) {
3198 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-pool", (char*)NULL
)) {
3200 } else if (ceph_argparse_witharg(args
, i
, &val
, "--data-extra-pool", (char*)NULL
)) {
3201 data_extra_pool
= val
;
3202 } else if (ceph_argparse_witharg(args
, i
, &val
, "--placement-index-type", (char*)NULL
)) {
3203 if (val
== "normal") {
3204 placement_index_type
= RGWBIType_Normal
;
3205 } else if (val
== "indexless") {
3206 placement_index_type
= RGWBIType_Indexless
;
3208 placement_index_type
= (RGWBucketIndexType
)strict_strtol(val
.c_str(), 10, &err
);
3210 cerr
<< "ERROR: failed to parse index type index: " << err
<< std::endl
;
3214 index_type_specified
= true;
3215 } else if (ceph_argparse_witharg(args
, i
, &val
, "--compression", (char*)NULL
)) {
3216 compression_type
= val
;
3217 } else if (ceph_argparse_witharg(args
, i
, &val
, "--role-name", (char*)NULL
)) {
3219 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path", (char*)NULL
)) {
3221 } else if (ceph_argparse_witharg(args
, i
, &val
, "--assume-role-policy-doc", (char*)NULL
)) {
3222 assume_role_doc
= val
;
3223 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-name", (char*)NULL
)) {
3225 } else if (ceph_argparse_witharg(args
, i
, &val
, "--policy-doc", (char*)NULL
)) {
3226 perm_policy_doc
= val
;
3227 } else if (ceph_argparse_witharg(args
, i
, &val
, "--path-prefix", (char*)NULL
)) {
3229 } else if (ceph_argparse_witharg(args
, i
, &val
, "--totp-serial", (char*)NULL
)) {
3231 } else if (ceph_argparse_witharg(args
, i
, &val
, "--totp-pin", (char*)NULL
)) {
3232 totp_pin
.push_back(val
);
3233 } else if (ceph_argparse_witharg(args
, i
, &val
, "--totp-seed", (char*)NULL
)) {
3235 } else if (ceph_argparse_witharg(args
, i
, &val
, "--totp-seed-type", (char*)NULL
)) {
3236 totp_seed_type
= val
;
3237 } else if (ceph_argparse_witharg(args
, i
, &val
, "--totp-seconds", (char*)NULL
)) {
3238 totp_seconds
= atoi(val
.c_str());
3239 } else if (ceph_argparse_witharg(args
, i
, &val
, "--totp-window", (char*)NULL
)) {
3240 totp_window
= atoi(val
.c_str());
3241 } else if (ceph_argparse_witharg(args
, i
, &val
, "--trim-delay-ms", (char*)NULL
)) {
3242 trim_delay_ms
= atoi(val
.c_str());
3243 } else if (ceph_argparse_witharg(args
, i
, &val
, "--topic", (char*)NULL
)) {
3245 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sub-name", (char*)NULL
)) {
3247 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sub-oid-prefix", (char*)NULL
)) {
3248 sub_oid_prefix
= val
;
3249 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sub-dest-bucket", (char*)NULL
)) {
3250 sub_dest_bucket
= val
;
3251 } else if (ceph_argparse_witharg(args
, i
, &val
, "--sub-push-endpoint", (char*)NULL
)) {
3252 sub_push_endpoint
= val
;
3253 } else if (ceph_argparse_witharg(args
, i
, &val
, "--event-id", (char*)NULL
)) {
3255 } else if (ceph_argparse_witharg(args
, i
, &val
, "--event-type", "--event-types", (char*)NULL
)) {
3256 rgw::notify::from_string_list(val
, event_types
);
3257 } else if (ceph_argparse_binary_flag(args
, i
, &detail
, NULL
, "--detail", (char*)NULL
)) {
3259 } else if (strncmp(*i
, "-", 1) == 0) {
3260 cerr
<< "ERROR: invalid flag " << *i
<< std::endl
;
3272 const char *prev_cmd
= NULL
;
3273 const char *prev_prev_cmd
= NULL
;
3274 std::vector
<const char*>::iterator i
;
3275 for (i
= args
.begin(); i
!= args
.end(); ++i
) {
3276 opt_cmd
= get_cmd(*i
, prev_cmd
, prev_prev_cmd
, &need_more
);
3278 cerr
<< "unrecognized arg " << *i
<< std::endl
;
3285 prev_prev_cmd
= prev_cmd
;
3289 if (opt_cmd
== OPT_NO_CMD
) {
3290 cerr
<< "no command" << std::endl
;
3294 /* some commands may have an optional extra param */
3295 if (i
!= args
.end()) {
3297 case OPT_METADATA_GET
:
3298 case OPT_METADATA_PUT
:
3299 case OPT_METADATA_RM
:
3300 case OPT_METADATA_LIST
:
3308 if (tenant
.empty()) {
3309 tenant
= user_id
.tenant
;
3311 if (user_id
.empty() && opt_cmd
!= OPT_ROLE_CREATE
3312 && opt_cmd
!= OPT_ROLE_DELETE
3313 && opt_cmd
!= OPT_ROLE_GET
3314 && opt_cmd
!= OPT_ROLE_MODIFY
3315 && opt_cmd
!= OPT_ROLE_LIST
3316 && opt_cmd
!= OPT_ROLE_POLICY_PUT
3317 && opt_cmd
!= OPT_ROLE_POLICY_LIST
3318 && opt_cmd
!= OPT_ROLE_POLICY_GET
3319 && opt_cmd
!= OPT_ROLE_POLICY_DELETE
3320 && opt_cmd
!= OPT_RESHARD_ADD
3321 && opt_cmd
!= OPT_RESHARD_CANCEL
3322 && opt_cmd
!= OPT_RESHARD_STATUS
) {
3323 cerr
<< "ERROR: --tenant is set, but there's no user ID" << std::endl
;
3326 user_id
.tenant
= tenant
;
3328 /* check key parameter conflict */
3329 if ((!access_key
.empty()) && gen_access_key
) {
3330 cerr
<< "ERROR: key parameter conflict, --access-key & --gen-access-key" << std::endl
;
3333 if ((!secret_key
.empty()) && gen_secret_key
) {
3334 cerr
<< "ERROR: key parameter conflict, --secret & --gen-secret" << std::endl
;
3339 // default to pretty json
3340 if (format
.empty()) {
3342 pretty_format
= true;
3345 if (format
== "xml")
3346 formatter
= new XMLFormatter(pretty_format
);
3347 else if (format
== "json")
3348 formatter
= new JSONFormatter(pretty_format
);
3350 cerr
<< "unrecognized format: " << format
<< std::endl
;
3354 realm_name
= g_conf()->rgw_realm
;
3355 zone_name
= g_conf()->rgw_zone
;
3356 zonegroup_name
= g_conf()->rgw_zonegroup
;
3358 RGWStreamFlusher
f(formatter
, cout
);
3360 // not a raw op if 'period update' needs to commit to master
3361 bool raw_period_update
= opt_cmd
== OPT_PERIOD_UPDATE
&& !commit
;
3362 std::set
<int> raw_storage_ops_list
= {OPT_ZONEGROUP_ADD
, OPT_ZONEGROUP_CREATE
, OPT_ZONEGROUP_DELETE
,
3363 OPT_ZONEGROUP_GET
, OPT_ZONEGROUP_LIST
,
3364 OPT_ZONEGROUP_SET
, OPT_ZONEGROUP_DEFAULT
,
3365 OPT_ZONEGROUP_RENAME
, OPT_ZONEGROUP_MODIFY
,
3366 OPT_ZONEGROUP_REMOVE
,
3367 OPT_ZONEGROUP_PLACEMENT_ADD
, OPT_ZONEGROUP_PLACEMENT_RM
,
3368 OPT_ZONEGROUP_PLACEMENT_MODIFY
, OPT_ZONEGROUP_PLACEMENT_LIST
,
3369 OPT_ZONEGROUP_PLACEMENT_GET
,
3370 OPT_ZONEGROUP_PLACEMENT_DEFAULT
,
3371 OPT_ZONE_CREATE
, OPT_ZONE_DELETE
,
3372 OPT_ZONE_GET
, OPT_ZONE_SET
, OPT_ZONE_RENAME
,
3373 OPT_ZONE_LIST
, OPT_ZONE_MODIFY
, OPT_ZONE_DEFAULT
,
3374 OPT_ZONE_PLACEMENT_ADD
, OPT_ZONE_PLACEMENT_RM
,
3375 OPT_ZONE_PLACEMENT_MODIFY
, OPT_ZONE_PLACEMENT_LIST
,
3376 OPT_ZONE_PLACEMENT_GET
,
3378 OPT_PERIOD_DELETE
, OPT_PERIOD_GET
,
3380 OPT_PERIOD_GET_CURRENT
, OPT_PERIOD_LIST
,
3381 OPT_GLOBAL_QUOTA_GET
, OPT_GLOBAL_QUOTA_SET
,
3382 OPT_GLOBAL_QUOTA_ENABLE
, OPT_GLOBAL_QUOTA_DISABLE
,
3383 OPT_REALM_DELETE
, OPT_REALM_GET
, OPT_REALM_LIST
,
3384 OPT_REALM_LIST_PERIODS
,
3385 OPT_REALM_GET_DEFAULT
,
3386 OPT_REALM_RENAME
, OPT_REALM_SET
,
3387 OPT_REALM_DEFAULT
, OPT_REALM_PULL
};
3389 std::set
<int> readonly_ops_list
= {
3393 OPT_BUCKET_LIMIT_CHECK
,
3395 OPT_BUCKET_SYNC_STATUS
,
3396 OPT_BUCKET_SYNC_MARKERS
,
3407 OPT_ORPHANS_LIST_JOBS
,
3410 OPT_ZONEGROUP_PLACEMENT_LIST
,
3411 OPT_ZONEGROUP_PLACEMENT_GET
,
3414 OPT_ZONE_PLACEMENT_LIST
,
3415 OPT_ZONE_PLACEMENT_GET
,
3418 OPT_METADATA_SYNC_STATUS
,
3421 OPT_SYNC_ERROR_LIST
,
3424 OPT_DATA_SYNC_STATUS
,
3428 OPT_REALM_GET_DEFAULT
,
3430 OPT_REALM_LIST_PERIODS
,
3432 OPT_PERIOD_GET_CURRENT
,
3434 OPT_GLOBAL_QUOTA_GET
,
3438 OPT_ROLE_POLICY_LIST
,
3439 OPT_ROLE_POLICY_GET
,
3444 bool raw_storage_op
= (raw_storage_ops_list
.find(opt_cmd
) != raw_storage_ops_list
.end() ||
3446 bool need_cache
= readonly_ops_list
.find(opt_cmd
) == readonly_ops_list
.end();
3448 if (raw_storage_op
) {
3449 store
= RGWStoreManager::get_raw_storage(g_ceph_context
);
3451 store
= RGWStoreManager::get_storage(g_ceph_context
, false, false, false, false, false,
3452 need_cache
&& g_conf()->rgw_cache_enabled
);
3455 cerr
<< "couldn't init storage provider" << std::endl
;
3459 if (!source_zone_name
.empty()) {
3460 if (!store
->svc
.zone
->find_zone_id_by_name(source_zone_name
, &source_zone
)) {
3461 cerr
<< "WARNING: cannot find source zone id for name=" << source_zone_name
<< std::endl
;
3462 source_zone
= source_zone_name
;
3466 rgw_user_init(store
);
3467 rgw_bucket_init(store
->meta_mgr
);
3468 rgw_otp_init(store
);
3470 rgw_http_client_init(g_ceph_context
);
3472 struct rgw_curl_setup
{
3474 rgw::curl::setup_curl(boost::none
);
3477 rgw::curl::cleanup_curl();
3483 StoreDestructor
store_destructor(store
);
3485 if (raw_storage_op
) {
3487 case OPT_PERIOD_DELETE
:
3489 if (period_id
.empty()) {
3490 cerr
<< "missing period id" << std::endl
;
3493 RGWPeriod
period(period_id
);
3494 int ret
= period
.init(g_ceph_context
, store
->svc
.sysobj
);
3496 cerr
<< "period.init failed: " << cpp_strerror(-ret
) << std::endl
;
3499 ret
= period
.delete_obj();
3501 cerr
<< "ERROR: couldn't delete period: " << cpp_strerror(-ret
) << std::endl
;
3507 case OPT_PERIOD_GET
:
3510 if (!period_epoch
.empty()) {
3511 epoch
= atoi(period_epoch
.c_str());
3514 RGWRealm
realm(realm_id
, realm_name
);
3515 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
3517 cerr
<< "Error initializing realm " << cpp_strerror(-ret
) << std::endl
;
3520 realm_id
= realm
.get_id();
3521 realm_name
= realm
.get_name();
3522 period_id
= RGWPeriod::get_staging_id(realm_id
);
3525 RGWPeriod
period(period_id
, epoch
);
3526 int ret
= period
.init(g_ceph_context
, store
->svc
.sysobj
, realm_id
, realm_name
);
3528 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
3531 encode_json("period", period
, formatter
);
3532 formatter
->flush(cout
);
3535 case OPT_PERIOD_GET_CURRENT
:
3537 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3541 formatter
->open_object_section("period_get_current");
3542 encode_json("current_period", period_id
, formatter
);
3543 formatter
->close_section();
3544 formatter
->flush(cout
);
3547 case OPT_PERIOD_LIST
:
3549 list
<string
> periods
;
3550 int ret
= store
->svc
.zone
->list_periods(periods
);
3552 cerr
<< "failed to list periods: " << cpp_strerror(-ret
) << std::endl
;
3555 formatter
->open_object_section("periods_list");
3556 encode_json("periods", periods
, formatter
);
3557 formatter
->close_section();
3558 formatter
->flush(cout
);
3561 case OPT_PERIOD_UPDATE
:
3563 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
3564 commit
, remote
, url
, access_key
, secret_key
,
3565 formatter
, yes_i_really_mean_it
);
3571 case OPT_PERIOD_PULL
:
3573 boost::optional
<RGWRESTConn
> conn
;
3574 RGWRESTConn
*remote_conn
= nullptr;
3576 // load current period for endpoints
3577 RGWRealm
realm(realm_id
, realm_name
);
3578 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
3580 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3583 RGWPeriod
current_period(realm
.get_current_period());
3584 ret
= current_period
.init(g_ceph_context
, store
->svc
.sysobj
);
3586 cerr
<< "failed to init current period: " << cpp_strerror(-ret
) << std::endl
;
3589 if (remote
.empty()) {
3590 // use realm master zone as remote
3591 remote
= current_period
.get_master_zone();
3593 conn
= get_remote_conn(store
, current_period
.get_map(), remote
);
3595 cerr
<< "failed to find a zone or zonegroup for remote "
3596 << remote
<< std::endl
;
3599 remote_conn
= &*conn
;
3603 int ret
= do_period_pull(remote_conn
, url
, access_key
, secret_key
,
3604 realm_id
, realm_name
, period_id
, period_epoch
,
3607 cerr
<< "period pull failed: " << cpp_strerror(-ret
) << std::endl
;
3611 encode_json("period", period
, formatter
);
3612 formatter
->flush(cout
);
3615 case OPT_GLOBAL_QUOTA_GET
:
3616 case OPT_GLOBAL_QUOTA_SET
:
3617 case OPT_GLOBAL_QUOTA_ENABLE
:
3618 case OPT_GLOBAL_QUOTA_DISABLE
:
3620 if (realm_id
.empty()) {
3621 RGWRealm
realm(g_ceph_context
, store
->svc
.sysobj
);
3622 if (!realm_name
.empty()) {
3623 // look up realm_id for the given realm_name
3624 int ret
= realm
.read_id(realm_name
, realm_id
);
3626 cerr
<< "ERROR: failed to read realm for " << realm_name
3627 << ": " << cpp_strerror(-ret
) << std::endl
;
3631 // use default realm_id when none is given
3632 int ret
= realm
.read_default_id(realm_id
);
3633 if (ret
< 0 && ret
!= -ENOENT
) { // on ENOENT, use empty realm_id
3634 cerr
<< "ERROR: failed to read default realm: "
3635 << cpp_strerror(-ret
) << std::endl
;
3641 RGWPeriodConfig period_config
;
3642 int ret
= period_config
.read(store
->svc
.sysobj
, realm_id
);
3643 if (ret
< 0 && ret
!= -ENOENT
) {
3644 cerr
<< "ERROR: failed to read period config: "
3645 << cpp_strerror(-ret
) << std::endl
;
3649 formatter
->open_object_section("period_config");
3650 if (quota_scope
== "bucket") {
3651 set_quota_info(period_config
.bucket_quota
, opt_cmd
,
3652 max_size
, max_objects
,
3653 have_max_size
, have_max_objects
);
3654 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3655 } else if (quota_scope
== "user") {
3656 set_quota_info(period_config
.user_quota
, opt_cmd
,
3657 max_size
, max_objects
,
3658 have_max_size
, have_max_objects
);
3659 encode_json("user quota", period_config
.user_quota
, formatter
);
3660 } else if (quota_scope
.empty() && opt_cmd
== OPT_GLOBAL_QUOTA_GET
) {
3661 // if no scope is given for GET, print both
3662 encode_json("bucket quota", period_config
.bucket_quota
, formatter
);
3663 encode_json("user quota", period_config
.user_quota
, formatter
);
3665 cerr
<< "ERROR: invalid quota scope specification. Please specify "
3666 "either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
3669 formatter
->close_section();
3671 if (opt_cmd
!= OPT_GLOBAL_QUOTA_GET
) {
3672 // write the modified period config
3673 ret
= period_config
.write(store
->svc
.sysobj
, realm_id
);
3675 cerr
<< "ERROR: failed to write period config: "
3676 << cpp_strerror(-ret
) << std::endl
;
3679 if (!realm_id
.empty()) {
3680 cout
<< "Global quota changes saved. Use 'period update' to apply "
3681 "them to the staging period, and 'period commit' to commit the "
3682 "new period." << std::endl
;
3684 cout
<< "Global quota changes saved. They will take effect as "
3685 "the gateways are restarted." << std::endl
;
3689 formatter
->flush(cout
);
3692 case OPT_REALM_CREATE
:
3694 if (realm_name
.empty()) {
3695 cerr
<< "missing realm name" << std::endl
;
3699 RGWRealm
realm(realm_name
, g_ceph_context
, store
->svc
.sysobj
);
3700 int ret
= realm
.create();
3702 cerr
<< "ERROR: couldn't create realm " << realm_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
3707 ret
= realm
.set_as_default();
3709 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3713 encode_json("realm", realm
, formatter
);
3714 formatter
->flush(cout
);
3717 case OPT_REALM_DELETE
:
3719 RGWRealm
realm(realm_id
, realm_name
);
3720 if (realm_name
.empty() && realm_id
.empty()) {
3721 cerr
<< "missing realm name or id" << std::endl
;
3724 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
3726 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3729 ret
= realm
.delete_obj();
3731 cerr
<< "ERROR: couldn't : " << cpp_strerror(-ret
) << std::endl
;
3739 RGWRealm
realm(realm_id
, realm_name
);
3740 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
3742 if (ret
== -ENOENT
&& realm_name
.empty() && realm_id
.empty()) {
3743 cerr
<< "missing realm name or id, or default realm not found" << std::endl
;
3745 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3749 encode_json("realm", realm
, formatter
);
3750 formatter
->flush(cout
);
3753 case OPT_REALM_GET_DEFAULT
:
3755 RGWRealm
realm(g_ceph_context
, store
->svc
.sysobj
);
3757 int ret
= realm
.read_default_id(default_id
);
3758 if (ret
== -ENOENT
) {
3759 cout
<< "No default realm is set" << std::endl
;
3761 } else if (ret
< 0) {
3762 cerr
<< "Error reading default realm:" << cpp_strerror(-ret
) << std::endl
;
3765 cout
<< "default realm: " << default_id
<< std::endl
;
3768 case OPT_REALM_LIST
:
3770 RGWRealm
realm(g_ceph_context
, store
->svc
.sysobj
);
3772 int ret
= realm
.read_default_id(default_id
);
3773 if (ret
< 0 && ret
!= -ENOENT
) {
3774 cerr
<< "could not determine default realm: " << cpp_strerror(-ret
) << std::endl
;
3776 list
<string
> realms
;
3777 ret
= store
->svc
.zone
->list_realms(realms
);
3779 cerr
<< "failed to list realms: " << cpp_strerror(-ret
) << std::endl
;
3782 formatter
->open_object_section("realms_list");
3783 encode_json("default_info", default_id
, formatter
);
3784 encode_json("realms", realms
, formatter
);
3785 formatter
->close_section();
3786 formatter
->flush(cout
);
3789 case OPT_REALM_LIST_PERIODS
:
3791 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
3795 list
<string
> periods
;
3796 ret
= store
->svc
.zone
->list_periods(period_id
, periods
);
3798 cerr
<< "list periods failed: " << cpp_strerror(-ret
) << std::endl
;
3801 formatter
->open_object_section("realm_periods_list");
3802 encode_json("current_period", period_id
, formatter
);
3803 encode_json("periods", periods
, formatter
);
3804 formatter
->close_section();
3805 formatter
->flush(cout
);
3809 case OPT_REALM_RENAME
:
3811 RGWRealm
realm(realm_id
, realm_name
);
3812 if (realm_new_name
.empty()) {
3813 cerr
<< "missing realm new name" << std::endl
;
3816 if (realm_name
.empty() && realm_id
.empty()) {
3817 cerr
<< "missing realm name or id" << std::endl
;
3820 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
3822 cerr
<< "realm.init failed: " << cpp_strerror(-ret
) << std::endl
;
3825 ret
= realm
.rename(realm_new_name
);
3827 cerr
<< "realm.rename failed: " << cpp_strerror(-ret
) << std::endl
;
3830 cout
<< "Realm name updated. Note that this change only applies to "
3831 "the current cluster, so this command must be run separately "
3832 "on each of the realm's other clusters." << std::endl
;
3837 if (realm_id
.empty() && realm_name
.empty()) {
3838 cerr
<< "no realm name or id provided" << std::endl
;
3841 RGWRealm
realm(realm_id
, realm_name
);
3842 bool new_realm
= false;
3843 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
3844 if (ret
< 0 && ret
!= -ENOENT
) {
3845 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3847 } else if (ret
== -ENOENT
) {
3850 ret
= read_decode_json(infile
, realm
);
3854 if (!realm_name
.empty() && realm
.get_name() != realm_name
) {
3855 cerr
<< "mismatch between --rgw-realm " << realm_name
<< " and json input file name " <<
3856 realm
.get_name() << std::endl
;
3861 cout
<< "clearing period and epoch for new realm" << std::endl
;
3862 realm
.clear_current_period_and_epoch();
3863 ret
= realm
.create();
3865 cerr
<< "ERROR: couldn't create new realm: " << cpp_strerror(-ret
) << std::endl
;
3869 ret
= realm
.update();
3871 cerr
<< "ERROR: couldn't store realm info: " << cpp_strerror(-ret
) << std::endl
;
3877 ret
= realm
.set_as_default();
3879 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3882 encode_json("realm", realm
, formatter
);
3883 formatter
->flush(cout
);
3887 case OPT_REALM_DEFAULT
:
3889 RGWRealm
realm(realm_id
, realm_name
);
3890 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
3892 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
3895 ret
= realm
.set_as_default();
3897 cerr
<< "failed to set realm as default: " << cpp_strerror(-ret
) << std::endl
;
3902 case OPT_REALM_PULL
:
3905 cerr
<< "A --url must be provided." << std::endl
;
3909 req_info
info(g_ceph_context
, &env
);
3910 info
.method
= "GET";
3911 info
.request_uri
= "/admin/realm";
3913 map
<string
, string
> ¶ms
= info
.args
.get_params();
3914 if (!realm_id
.empty())
3915 params
["id"] = realm_id
;
3916 if (!realm_name
.empty())
3917 params
["name"] = realm_name
;
3921 int ret
= send_to_url(url
, access_key
, secret_key
, info
, bl
, p
);
3923 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
3924 if (ret
== -EACCES
) {
3925 cerr
<< "If the realm has been changed on the master zone, the "
3926 "master zone's gateway may need to be restarted to recognize "
3927 "this user." << std::endl
;
3932 realm
.init(g_ceph_context
, store
->svc
.sysobj
, false);
3934 decode_json_obj(realm
, &p
);
3935 } catch (JSONDecoder::err
& e
) {
3936 cerr
<< "failed to decode JSON response: " << e
.message
<< std::endl
;
3940 auto& current_period
= realm
.get_current_period();
3941 if (!current_period
.empty()) {
3942 // pull the latest epoch of the realm's current period
3943 ret
= do_period_pull(nullptr, url
, access_key
, secret_key
,
3944 realm_id
, realm_name
, current_period
, "",
3947 cerr
<< "could not fetch period " << current_period
<< std::endl
;
3951 ret
= realm
.create(false);
3952 if (ret
< 0 && ret
!= -EEXIST
) {
3953 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3954 << cpp_strerror(ret
) << std::endl
;
3956 } else if (ret
==-EEXIST
) {
3957 ret
= realm
.update();
3959 cerr
<< "Error storing realm " << realm
.get_id() << ": "
3960 << cpp_strerror(ret
) << std::endl
;
3965 ret
= realm
.set_as_default();
3967 cerr
<< "failed to set realm " << realm_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
3971 encode_json("realm", realm
, formatter
);
3972 formatter
->flush(cout
);
3976 case OPT_ZONEGROUP_ADD
:
3978 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
3979 cerr
<< "no zonegroup name or id provided" << std::endl
;
3983 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
3984 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
3986 cerr
<< "failed to initialize zonegroup " << zonegroup_name
<< " id " << zonegroup_id
<< " :"
3987 << cpp_strerror(-ret
) << std::endl
;
3990 RGWZoneParams
zone(zone_id
, zone_name
);
3991 ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
3993 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
3996 if (zone
.realm_id
!= zonegroup
.realm_id
) {
3997 zone
.realm_id
= zonegroup
.realm_id
;
3998 ret
= zone
.update();
4000 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4005 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4007 for (auto a
: tier_config_add
) {
4008 int r
= zone
.tier_config
.set(a
.first
, a
.second
);
4010 cerr
<< "ERROR: failed to set configurable: " << a
<< std::endl
;
4015 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4016 string
*predirect_zone
= (redirect_zone_set
? &redirect_zone
: nullptr);
4018 ret
= zonegroup
.add_zone(zone
,
4019 (is_master_set
? &is_master
: NULL
),
4020 (is_read_only_set
? &read_only
: NULL
),
4021 endpoints
, ptier_type
,
4022 psync_from_all
, sync_from
, sync_from_rm
,
4024 store
->svc
.sync_modules
->get_manager());
4026 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name() << ": "
4027 << cpp_strerror(-ret
) << std::endl
;
4031 encode_json("zonegroup", zonegroup
, formatter
);
4032 formatter
->flush(cout
);
4035 case OPT_ZONEGROUP_CREATE
:
4037 if (zonegroup_name
.empty()) {
4038 cerr
<< "Missing zonegroup name" << std::endl
;
4041 RGWRealm
realm(realm_id
, realm_name
);
4042 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
4044 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4048 RGWZoneGroup
zonegroup(zonegroup_name
, is_master
, g_ceph_context
, store
->svc
.sysobj
, realm
.get_id(), endpoints
);
4049 zonegroup
.api_name
= (api_name
.empty() ? zonegroup_name
: api_name
);
4050 ret
= zonegroup
.create();
4052 cerr
<< "failed to create zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4057 ret
= zonegroup
.set_as_default();
4059 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4063 encode_json("zonegroup", zonegroup
, formatter
);
4064 formatter
->flush(cout
);
4067 case OPT_ZONEGROUP_DEFAULT
:
4069 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
4070 cerr
<< "no zonegroup name or id provided" << std::endl
;
4074 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4075 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4077 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4081 ret
= zonegroup
.set_as_default();
4083 cerr
<< "failed to set zonegroup as default: " << cpp_strerror(-ret
) << std::endl
;
4088 case OPT_ZONEGROUP_DELETE
:
4090 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
4091 cerr
<< "no zonegroup name or id provided" << std::endl
;
4094 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4095 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4097 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4100 ret
= zonegroup
.delete_obj();
4102 cerr
<< "ERROR: couldn't delete zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4107 case OPT_ZONEGROUP_GET
:
4109 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4110 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4112 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4116 encode_json("zonegroup", zonegroup
, formatter
);
4117 formatter
->flush(cout
);
4120 case OPT_ZONEGROUP_LIST
:
4122 RGWZoneGroup zonegroup
;
4123 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
, false);
4125 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4129 list
<string
> zonegroups
;
4130 ret
= store
->svc
.zone
->list_zonegroups(zonegroups
);
4132 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
4135 string default_zonegroup
;
4136 ret
= zonegroup
.read_default_id(default_zonegroup
);
4137 if (ret
< 0 && ret
!= -ENOENT
) {
4138 cerr
<< "could not determine default zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4140 formatter
->open_object_section("zonegroups_list");
4141 encode_json("default_info", default_zonegroup
, formatter
);
4142 encode_json("zonegroups", zonegroups
, formatter
);
4143 formatter
->close_section();
4144 formatter
->flush(cout
);
4147 case OPT_ZONEGROUP_MODIFY
:
4149 RGWRealm
realm(realm_id
, realm_name
);
4150 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
4152 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4156 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4157 ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4159 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4163 bool need_update
= false;
4165 if (!master_zone
.empty()) {
4166 zonegroup
.master_zone
= master_zone
;
4170 if (is_master_set
) {
4171 zonegroup
.update_master(is_master
);
4175 if (!endpoints
.empty()) {
4176 zonegroup
.endpoints
= endpoints
;
4180 if (!api_name
.empty()) {
4181 zonegroup
.api_name
= api_name
;
4185 if (!realm_id
.empty()) {
4186 zonegroup
.realm_id
= realm_id
;
4188 } else if (!realm_name
.empty()) {
4189 // get realm id from name
4190 RGWRealm realm
{g_ceph_context
, store
->svc
.sysobj
};
4191 ret
= realm
.read_id(realm_name
, zonegroup
.realm_id
);
4193 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4200 ret
= zonegroup
.update();
4202 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4208 ret
= zonegroup
.set_as_default();
4210 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4214 encode_json("zonegroup", zonegroup
, formatter
);
4215 formatter
->flush(cout
);
4218 case OPT_ZONEGROUP_SET
:
4220 RGWRealm
realm(realm_id
, realm_name
);
4221 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
4222 bool default_realm_not_exist
= (ret
== -ENOENT
&& realm_id
.empty() && realm_name
.empty());
4224 if (ret
< 0 && !default_realm_not_exist
) {
4225 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4229 RGWZoneGroup zonegroup
;
4230 ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
, false);
4232 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4235 ret
= read_decode_json(infile
, zonegroup
);
4239 if (zonegroup
.realm_id
.empty() && !default_realm_not_exist
) {
4240 zonegroup
.realm_id
= realm
.get_id();
4242 ret
= zonegroup
.create();
4243 if (ret
< 0 && ret
!= -EEXIST
) {
4244 cerr
<< "ERROR: couldn't create zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
4246 } else if (ret
== -EEXIST
) {
4247 ret
= zonegroup
.update();
4249 cerr
<< "ERROR: couldn't store zonegroup info: " << cpp_strerror(-ret
) << std::endl
;
4255 ret
= zonegroup
.set_as_default();
4257 cerr
<< "failed to set zonegroup " << zonegroup_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4261 encode_json("zonegroup", zonegroup
, formatter
);
4262 formatter
->flush(cout
);
4265 case OPT_ZONEGROUP_REMOVE
:
4267 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4268 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4270 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4274 if (zone_id
.empty()) {
4275 if (zone_name
.empty()) {
4276 cerr
<< "no --zone-id or --rgw-zone name provided" << std::endl
;
4279 // look up zone id by name
4280 for (auto& z
: zonegroup
.zones
) {
4281 if (zone_name
== z
.second
.name
) {
4282 zone_id
= z
.second
.id
;
4286 if (zone_id
.empty()) {
4287 cerr
<< "zone name " << zone_name
<< " not found in zonegroup "
4288 << zonegroup
.get_name() << std::endl
;
4293 ret
= zonegroup
.remove_zone(zone_id
);
4295 cerr
<< "failed to remove zone: " << cpp_strerror(-ret
) << std::endl
;
4299 encode_json("zonegroup", zonegroup
, formatter
);
4300 formatter
->flush(cout
);
4303 case OPT_ZONEGROUP_RENAME
:
4305 if (zonegroup_new_name
.empty()) {
4306 cerr
<< " missing zonegroup new name" << std::endl
;
4309 if (zonegroup_id
.empty() && zonegroup_name
.empty()) {
4310 cerr
<< "no zonegroup name or id provided" << std::endl
;
4313 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4314 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4316 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4319 ret
= zonegroup
.rename(zonegroup_new_name
);
4321 cerr
<< "failed to rename zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4326 case OPT_ZONEGROUP_PLACEMENT_LIST
:
4328 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4329 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4331 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4335 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
4336 formatter
->flush(cout
);
4339 case OPT_ZONEGROUP_PLACEMENT_GET
:
4341 if (placement_id
.empty()) {
4342 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4346 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4347 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4349 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4353 auto p
= zonegroup
.placement_targets
.find(placement_id
);
4354 if (p
== zonegroup
.placement_targets
.end()) {
4355 cerr
<< "failed to find a zonegroup placement target named '" << placement_id
<< "'" << std::endl
;
4358 encode_json("placement_targets", p
->second
, formatter
);
4359 formatter
->flush(cout
);
4362 case OPT_ZONEGROUP_PLACEMENT_ADD
:
4363 case OPT_ZONEGROUP_PLACEMENT_MODIFY
:
4364 case OPT_ZONEGROUP_PLACEMENT_RM
:
4365 case OPT_ZONEGROUP_PLACEMENT_DEFAULT
:
4367 if (placement_id
.empty()) {
4368 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4372 rgw_placement_rule rule
;
4373 rule
.from_str(placement_id
);
4375 if (!rule
.storage_class
.empty() && !storage_class
.empty() &&
4376 rule
.storage_class
!= storage_class
) {
4377 cerr
<< "ERROR: provided contradicting storage class configuration" << std::endl
;
4379 } else if (rule
.storage_class
.empty()) {
4380 rule
.storage_class
= storage_class
;
4383 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4384 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4386 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4390 if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_ADD
||
4391 opt_cmd
== OPT_ZONEGROUP_PLACEMENT_MODIFY
) {
4392 RGWZoneGroupPlacementTarget
& target
= zonegroup
.placement_targets
[placement_id
];
4393 if (!tags
.empty()) {
4394 target
.tags
.clear();
4395 for (auto& t
: tags
) {
4396 target
.tags
.insert(t
);
4399 target
.name
= placement_id
;
4400 for (auto& t
: tags_rm
) {
4401 target
.tags
.erase(t
);
4403 for (auto& t
: tags_add
) {
4404 target
.tags
.insert(t
);
4406 target
.storage_classes
.insert(rule
.get_storage_class());
4407 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_RM
) {
4408 zonegroup
.placement_targets
.erase(placement_id
);
4409 } else if (opt_cmd
== OPT_ZONEGROUP_PLACEMENT_DEFAULT
) {
4410 if (!zonegroup
.placement_targets
.count(placement_id
)) {
4411 cerr
<< "failed to find a zonegroup placement target named '"
4412 << placement_id
<< "'" << std::endl
;
4415 zonegroup
.default_placement
= rule
;
4418 zonegroup
.post_process_params();
4419 ret
= zonegroup
.update();
4421 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4425 encode_json("placement_targets", zonegroup
.placement_targets
, formatter
);
4426 formatter
->flush(cout
);
4429 case OPT_ZONE_CREATE
:
4431 if (zone_name
.empty()) {
4432 cerr
<< "zone name not provided" << std::endl
;
4436 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4437 /* if the user didn't provide zonegroup info , create stand alone zone */
4438 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
4439 ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4441 cerr
<< "unable to initialize zonegroup " << zonegroup_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4444 if (realm_id
.empty() && realm_name
.empty()) {
4445 realm_id
= zonegroup
.realm_id
;
4449 RGWZoneParams
zone(zone_id
, zone_name
);
4450 ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
, false);
4452 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4456 zone
.system_key
.id
= access_key
;
4457 zone
.system_key
.key
= secret_key
;
4458 zone
.realm_id
= realm_id
;
4459 for (auto a
: tier_config_add
) {
4460 int r
= zone
.tier_config
.set(a
.first
, a
.second
);
4462 cerr
<< "ERROR: failed to set configurable: " << a
<< std::endl
;
4467 ret
= zone
.create();
4469 cerr
<< "failed to create zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4473 if (!zonegroup_id
.empty() || !zonegroup_name
.empty()) {
4474 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4475 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4476 string
*predirect_zone
= (redirect_zone_set
? &redirect_zone
: nullptr);
4477 ret
= zonegroup
.add_zone(zone
,
4478 (is_master_set
? &is_master
: NULL
),
4479 (is_read_only_set
? &read_only
: NULL
),
4483 sync_from
, sync_from_rm
,
4485 store
->svc
.sync_modules
->get_manager());
4487 cerr
<< "failed to add zone " << zone_name
<< " to zonegroup " << zonegroup
.get_name()
4488 << ": " << cpp_strerror(-ret
) << std::endl
;
4494 ret
= zone
.set_as_default();
4496 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4500 encode_json("zone", zone
, formatter
);
4501 formatter
->flush(cout
);
4504 case OPT_ZONE_DEFAULT
:
4506 RGWZoneGroup
zonegroup(zonegroup_id
,zonegroup_name
);
4507 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4509 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4511 if (zone_id
.empty() && zone_name
.empty()) {
4512 cerr
<< "no zone name or id provided" << std::endl
;
4515 RGWZoneParams
zone(zone_id
, zone_name
);
4516 ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4518 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4521 ret
= zone
.set_as_default();
4523 cerr
<< "failed to set zone as default: " << cpp_strerror(-ret
) << std::endl
;
4528 case OPT_ZONE_DELETE
:
4530 if (zone_id
.empty() && zone_name
.empty()) {
4531 cerr
<< "no zone name or id provided" << std::endl
;
4534 RGWZoneParams
zone(zone_id
, zone_name
);
4535 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4537 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4541 list
<string
> zonegroups
;
4542 ret
= store
->svc
.zone
->list_zonegroups(zonegroups
);
4544 cerr
<< "failed to list zonegroups: " << cpp_strerror(-ret
) << std::endl
;
4548 for (list
<string
>::iterator iter
= zonegroups
.begin(); iter
!= zonegroups
.end(); ++iter
) {
4549 RGWZoneGroup
zonegroup(string(), *iter
);
4550 int ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4552 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4555 ret
= zonegroup
.remove_zone(zone
.get_id());
4556 if (ret
< 0 && ret
!= -ENOENT
) {
4557 cerr
<< "failed to remove zone " << zone_name
<< " from zonegroup " << zonegroup
.get_name() << ": "
4558 << cpp_strerror(-ret
) << std::endl
;
4562 ret
= zone
.delete_obj();
4564 cerr
<< "failed to delete zone " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4571 RGWZoneParams
zone(zone_id
, zone_name
);
4572 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4574 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4577 encode_json("zone", zone
, formatter
);
4578 formatter
->flush(cout
);
4583 RGWZoneParams
zone(zone_name
);
4584 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
, false);
4590 if (ret
< 0 && ret
!= -ENOENT
) {
4591 cerr
<< "zone.read() returned ret=" << ret
<< std::endl
;
4595 string orig_id
= zone
.get_id();
4597 ret
= read_decode_json(infile
, zone
);
4602 if(zone
.realm_id
.empty()) {
4603 RGWRealm
realm(realm_id
, realm_name
);
4604 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
4605 if (ret
< 0 && ret
!= -ENOENT
) {
4606 cerr
<< "failed to init realm: " << cpp_strerror(-ret
) << std::endl
;
4609 zone
.realm_id
= realm
.get_id();
4612 if( !zone_name
.empty() && !zone
.get_name().empty() && zone
.get_name() != zone_name
) {
4613 cerr
<< "Error: zone name" << zone_name
<< " is different than the zone name " << zone
.get_name() << " in the provided json " << std::endl
;
4617 if (zone
.get_name().empty()) {
4618 zone
.set_name(zone_name
);
4619 if (zone
.get_name().empty()) {
4620 cerr
<< "no zone name specified" << std::endl
;
4625 zone_name
= zone
.get_name();
4627 if (zone
.get_id().empty()) {
4628 zone
.set_id(orig_id
);
4631 if (zone
.get_id().empty()) {
4632 cerr
<< "no zone name id the json provided, assuming old format" << std::endl
;
4633 if (zone_name
.empty()) {
4634 cerr
<< "missing zone name" << std::endl
;
4637 zone
.set_name(zone_name
);
4638 zone
.set_id(zone_name
);
4641 cerr
<< "zone id " << zone
.get_id();
4642 ret
= zone
.fix_pool_names();
4644 cerr
<< "ERROR: couldn't fix zone: " << cpp_strerror(-ret
) << std::endl
;
4647 ret
= zone
.write(false);
4649 cerr
<< "ERROR: couldn't create zone: " << cpp_strerror(-ret
) << std::endl
;
4654 ret
= zone
.set_as_default();
4656 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4660 encode_json("zone", zone
, formatter
);
4661 formatter
->flush(cout
);
4667 int ret
= store
->svc
.zone
->list_zones(zones
);
4669 cerr
<< "failed to list zones: " << cpp_strerror(-ret
) << std::endl
;
4674 ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
, false);
4676 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4679 string default_zone
;
4680 ret
= zone
.read_default_id(default_zone
);
4681 if (ret
< 0 && ret
!= -ENOENT
) {
4682 cerr
<< "could not determine default zone: " << cpp_strerror(-ret
) << std::endl
;
4684 formatter
->open_object_section("zones_list");
4685 encode_json("default_info", default_zone
, formatter
);
4686 encode_json("zones", zones
, formatter
);
4687 formatter
->close_section();
4688 formatter
->flush(cout
);
4691 case OPT_ZONE_MODIFY
:
4693 RGWZoneParams
zone(zone_id
, zone_name
);
4694 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4696 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4700 bool need_zone_update
= false;
4701 if (!access_key
.empty()) {
4702 zone
.system_key
.id
= access_key
;
4703 need_zone_update
= true;
4706 if (!secret_key
.empty()) {
4707 zone
.system_key
.key
= secret_key
;
4708 need_zone_update
= true;
4711 if (!realm_id
.empty()) {
4712 zone
.realm_id
= realm_id
;
4713 need_zone_update
= true;
4714 } else if (!realm_name
.empty()) {
4715 // get realm id from name
4716 RGWRealm realm
{g_ceph_context
, store
->svc
.sysobj
};
4717 ret
= realm
.read_id(realm_name
, zone
.realm_id
);
4719 cerr
<< "failed to find realm by name " << realm_name
<< std::endl
;
4722 need_zone_update
= true;
4725 if (tier_config_add
.size() > 0) {
4726 for (auto add
: tier_config_add
) {
4727 int r
= zone
.tier_config
.set(add
.first
, add
.second
);
4729 cerr
<< "ERROR: failed to set configurable: " << add
<< std::endl
;
4733 need_zone_update
= true;
4736 for (auto rm
: tier_config_rm
) {
4737 if (!rm
.first
.empty()) { /* otherwise will remove the entire config */
4738 zone
.tier_config
.erase(rm
.first
);
4739 need_zone_update
= true;
4743 if (need_zone_update
) {
4744 ret
= zone
.update();
4746 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4751 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4752 ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4754 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4757 string
*ptier_type
= (tier_type_specified
? &tier_type
: nullptr);
4759 bool *psync_from_all
= (sync_from_all_specified
? &sync_from_all
: nullptr);
4760 string
*predirect_zone
= (redirect_zone_set
? &redirect_zone
: nullptr);
4762 ret
= zonegroup
.add_zone(zone
,
4763 (is_master_set
? &is_master
: NULL
),
4764 (is_read_only_set
? &read_only
: NULL
),
4765 endpoints
, ptier_type
,
4766 psync_from_all
, sync_from
, sync_from_rm
,
4768 store
->svc
.sync_modules
->get_manager());
4770 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4774 ret
= zonegroup
.update();
4776 cerr
<< "failed to update zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4781 ret
= zone
.set_as_default();
4783 cerr
<< "failed to set zone " << zone_name
<< " as default: " << cpp_strerror(-ret
) << std::endl
;
4787 encode_json("zone", zone
, formatter
);
4788 formatter
->flush(cout
);
4791 case OPT_ZONE_RENAME
:
4793 if (zone_new_name
.empty()) {
4794 cerr
<< " missing zone new name" << std::endl
;
4797 if (zone_id
.empty() && zone_name
.empty()) {
4798 cerr
<< "no zonegroup name or id provided" << std::endl
;
4801 RGWZoneParams
zone(zone_id
,zone_name
);
4802 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4804 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4807 ret
= zone
.rename(zone_new_name
);
4809 cerr
<< "failed to rename zone " << zone_name
<< " to " << zone_new_name
<< ": " << cpp_strerror(-ret
)
4813 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4814 ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4816 cerr
<< "WARNING: failed to initialize zonegroup " << zonegroup_name
<< std::endl
;
4818 ret
= zonegroup
.rename_zone(zone
);
4820 cerr
<< "Error in zonegroup rename for " << zone_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
4826 case OPT_ZONE_PLACEMENT_ADD
:
4827 case OPT_ZONE_PLACEMENT_MODIFY
:
4828 case OPT_ZONE_PLACEMENT_RM
:
4830 if (placement_id
.empty()) {
4831 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4834 // validate compression type
4835 if (compression_type
&& *compression_type
!= "random"
4836 && !Compressor::get_comp_alg_type(*compression_type
)) {
4837 std::cerr
<< "Unrecognized compression type" << std::endl
;
4841 RGWZoneParams
zone(zone_id
, zone_name
);
4842 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4844 cerr
<< "failed to init zone: " << cpp_strerror(-ret
) << std::endl
;
4848 if (opt_cmd
== OPT_ZONE_PLACEMENT_ADD
||
4849 opt_cmd
== OPT_ZONE_PLACEMENT_MODIFY
) {
4850 RGWZoneGroup
zonegroup(zonegroup_id
, zonegroup_name
);
4851 ret
= zonegroup
.init(g_ceph_context
, store
->svc
.sysobj
);
4853 cerr
<< "failed to init zonegroup: " << cpp_strerror(-ret
) << std::endl
;
4857 auto ptiter
= zonegroup
.placement_targets
.find(placement_id
);
4858 if (ptiter
== zonegroup
.placement_targets
.end()) {
4859 cerr
<< "ERROR: placement id '" << placement_id
<< "' is not configured in zonegroup placement targets" << std::endl
;
4863 storage_class
= rgw_placement_rule::get_canonical_storage_class(storage_class
);
4864 if (ptiter
->second
.storage_classes
.find(storage_class
) == ptiter
->second
.storage_classes
.end()) {
4865 cerr
<< "ERROR: storage class '" << storage_class
<< "' is not defined in zonegroup '" << placement_id
<< "' placement target" << std::endl
;
4869 RGWZonePlacementInfo
& info
= zone
.placement_pools
[placement_id
];
4871 string opt_index_pool
= index_pool
.value_or(string());
4872 string opt_data_pool
= data_pool
.value_or(string());
4874 if (!opt_index_pool
.empty()) {
4875 info
.index_pool
= opt_index_pool
;
4878 if (info
.index_pool
.empty()) {
4879 cerr
<< "ERROR: index pool not configured, need to specify --index-pool" << std::endl
;
4883 if (opt_data_pool
.empty()) {
4884 const RGWZoneStorageClass
*porig_sc
{nullptr};
4885 if (info
.storage_classes
.find(storage_class
, &porig_sc
)) {
4886 if (porig_sc
->data_pool
) {
4887 opt_data_pool
= porig_sc
->data_pool
->to_str();
4890 if (opt_data_pool
.empty()) {
4891 cerr
<< "ERROR: data pool not configured, need to specify --data-pool" << std::endl
;
4896 rgw_pool dp
= opt_data_pool
;
4897 info
.storage_classes
.set_storage_class(storage_class
, &dp
, compression_type
.get_ptr());
4899 if (data_extra_pool
) {
4900 info
.data_extra_pool
= *data_extra_pool
;
4902 if (index_type_specified
) {
4903 info
.index_type
= placement_index_type
;
4906 ret
= check_pool_support_omap(info
.get_data_extra_pool());
4908 cerr
<< "ERROR: the data extra (non-ec) pool '" << info
.get_data_extra_pool()
4909 << "' does not support omap" << std::endl
;
4912 } else if (opt_cmd
== OPT_ZONE_PLACEMENT_RM
) {
4913 zone
.placement_pools
.erase(placement_id
);
4916 ret
= zone
.update();
4918 cerr
<< "failed to save zone info: " << cpp_strerror(-ret
) << std::endl
;
4922 encode_json("zone", zone
, formatter
);
4923 formatter
->flush(cout
);
4926 case OPT_ZONE_PLACEMENT_LIST
:
4928 RGWZoneParams
zone(zone_id
, zone_name
);
4929 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4931 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4934 encode_json("placement_pools", zone
.placement_pools
, formatter
);
4935 formatter
->flush(cout
);
4938 case OPT_ZONE_PLACEMENT_GET
:
4940 if (placement_id
.empty()) {
4941 cerr
<< "ERROR: --placement-id not specified" << std::endl
;
4945 RGWZoneParams
zone(zone_id
, zone_name
);
4946 int ret
= zone
.init(g_ceph_context
, store
->svc
.sysobj
);
4948 cerr
<< "unable to initialize zone: " << cpp_strerror(-ret
) << std::endl
;
4951 auto p
= zone
.placement_pools
.find(placement_id
);
4952 if (p
== zone
.placement_pools
.end()) {
4953 cerr
<< "ERROR: zone placement target '" << placement_id
<< "' not found" << std::endl
;
4956 encode_json("placement_pools", p
->second
, formatter
);
4957 formatter
->flush(cout
);
4964 bool non_master_cmd
= (!store
->svc
.zone
->is_meta_master() && !yes_i_really_mean_it
);
4965 std::set
<int> non_master_ops_list
= {OPT_USER_CREATE
, OPT_USER_RM
,
4966 OPT_USER_MODIFY
, OPT_USER_ENABLE
,
4967 OPT_USER_SUSPEND
, OPT_SUBUSER_CREATE
,
4968 OPT_SUBUSER_MODIFY
, OPT_SUBUSER_RM
,
4969 OPT_BUCKET_LINK
, OPT_BUCKET_UNLINK
,
4970 OPT_BUCKET_RESHARD
, OPT_BUCKET_RM
,
4971 OPT_METADATA_PUT
, OPT_METADATA_RM
,
4972 OPT_RESHARD_CANCEL
, OPT_RESHARD_ADD
,
4973 OPT_MFA_CREATE
, OPT_MFA_REMOVE
,
4974 OPT_MFA_RESYNC
, OPT_CAPS_ADD
,
4977 bool print_warning_message
= (non_master_ops_list
.find(opt_cmd
) != non_master_ops_list
.end() &&
4980 if (print_warning_message
) {
4981 cerr
<< "Please run the command on master zone. Performing this operation on non-master zone leads to inconsistent metadata between zones" << std::endl
;
4982 cerr
<< "Are you sure you want to go ahead? (requires --yes-i-really-mean-it)" << std::endl
;
4986 if (!user_id
.empty()) {
4987 user_op
.set_user_id(user_id
);
4988 bucket_op
.set_user_id(user_id
);
4991 if (!display_name
.empty())
4992 user_op
.set_display_name(display_name
);
4994 if (!user_email
.empty())
4995 user_op
.set_user_email(user_email
);
4997 if (!access_key
.empty())
4998 user_op
.set_access_key(access_key
);
5000 if (!secret_key
.empty())
5001 user_op
.set_secret_key(secret_key
);
5003 if (!subuser
.empty())
5004 user_op
.set_subuser(subuser
);
5007 user_op
.set_caps(caps
);
5009 user_op
.set_purge_data(purge_data
);
5012 user_op
.set_purge_keys();
5015 user_op
.set_generate_key();
5018 user_op
.set_gen_secret(); // assume that a key pair should be created
5020 if (max_buckets_specified
)
5021 user_op
.set_max_buckets(max_buckets
);
5023 if (admin_specified
)
5024 user_op
.set_admin(admin
);
5026 if (system_specified
)
5027 user_op
.set_system(system
);
5030 user_op
.set_perm(perm_mask
);
5032 if (set_temp_url_key
) {
5033 map
<int, string
>::iterator iter
= temp_url_keys
.begin();
5034 for (; iter
!= temp_url_keys
.end(); ++iter
) {
5035 user_op
.set_temp_url_key(iter
->second
, iter
->first
);
5039 if (!op_mask_str
.empty()) {
5041 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
5043 cerr
<< "failed to parse op_mask: " << cpp_strerror(-ret
) << std::endl
;
5047 user_op
.set_op_mask(op_mask
);
5050 if (key_type
!= KEY_TYPE_UNDEFINED
)
5051 user_op
.set_key_type(key_type
);
5053 // set suspension operation parameters
5054 if (opt_cmd
== OPT_USER_ENABLE
)
5055 user_op
.set_suspension(false);
5056 else if (opt_cmd
== OPT_USER_SUSPEND
)
5057 user_op
.set_suspension(true);
5059 // RGWUser to use for user operations
5062 if (!(user_id
.empty() && access_key
.empty()) || !subuser
.empty()) {
5063 ret
= user
.init(store
, user_op
);
5065 cerr
<< "user.init failed: " << cpp_strerror(-ret
) << std::endl
;
5070 /* populate bucket operation */
5071 bucket_op
.set_bucket_name(bucket_name
);
5072 bucket_op
.set_object(object
);
5073 bucket_op
.set_check_objects(check_objects
);
5074 bucket_op
.set_delete_children(delete_child_objects
);
5075 bucket_op
.set_fix_index(fix
);
5076 bucket_op
.set_max_aio(max_concurrent_ios
);
5078 // required to gather errors from operations
5079 std::string err_msg
;
5081 bool output_user_info
= true;
5085 if (user_id
.empty() && access_key
.empty()) {
5086 cerr
<< "ERROR: --uid or --access-key required" << std::endl
;
5090 case OPT_USER_CREATE
:
5091 if (!user_op
.has_existing_user()) {
5092 user_op
.set_generate_key(); // generate a new key by default
5094 ret
= user
.add(user_op
, &err_msg
);
5096 cerr
<< "could not create user: " << err_msg
<< std::endl
;
5097 if (ret
== -ERR_INVALID_TENANT_NAME
)
5102 if (!subuser
.empty()) {
5103 ret
= user
.subusers
.add(user_op
, &err_msg
);
5105 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
5111 ret
= user
.remove(user_op
, &err_msg
);
5113 cerr
<< "could not remove user: " << err_msg
<< std::endl
;
5117 output_user_info
= false;
5119 case OPT_USER_ENABLE
:
5120 case OPT_USER_SUSPEND
:
5121 case OPT_USER_MODIFY
:
5122 ret
= user
.modify(user_op
, &err_msg
);
5124 cerr
<< "could not modify user: " << err_msg
<< std::endl
;
5129 case OPT_SUBUSER_CREATE
:
5130 ret
= user
.subusers
.add(user_op
, &err_msg
);
5132 cerr
<< "could not create subuser: " << err_msg
<< std::endl
;
5137 case OPT_SUBUSER_MODIFY
:
5138 ret
= user
.subusers
.modify(user_op
, &err_msg
);
5140 cerr
<< "could not modify subuser: " << err_msg
<< std::endl
;
5145 case OPT_SUBUSER_RM
:
5146 ret
= user
.subusers
.remove(user_op
, &err_msg
);
5148 cerr
<< "could not remove subuser: " << err_msg
<< std::endl
;
5154 ret
= user
.caps
.add(user_op
, &err_msg
);
5156 cerr
<< "could not add caps: " << err_msg
<< std::endl
;
5162 ret
= user
.caps
.remove(user_op
, &err_msg
);
5164 cerr
<< "could not remove caps: " << err_msg
<< std::endl
;
5169 case OPT_KEY_CREATE
:
5170 ret
= user
.keys
.add(user_op
, &err_msg
);
5172 cerr
<< "could not create key: " << err_msg
<< std::endl
;
5178 ret
= user
.keys
.remove(user_op
, &err_msg
);
5180 cerr
<< "could not remove key: " << err_msg
<< std::endl
;
5184 case OPT_PERIOD_PUSH
:
5187 req_info
info(g_ceph_context
, &env
);
5188 info
.method
= "POST";
5189 info
.request_uri
= "/admin/realm/period";
5191 map
<string
, string
> ¶ms
= info
.args
.get_params();
5192 if (!realm_id
.empty())
5193 params
["realm_id"] = realm_id
;
5194 if (!realm_name
.empty())
5195 params
["realm_name"] = realm_name
;
5196 if (!period_id
.empty())
5197 params
["period_id"] = period_id
;
5198 if (!period_epoch
.empty())
5199 params
["epoch"] = period_epoch
;
5202 RGWPeriod
period(period_id
);
5203 int ret
= period
.init(g_ceph_context
, store
->svc
.sysobj
);
5205 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
5208 // json format into a bufferlist
5209 JSONFormatter
jf(false);
5210 encode_json("period", period
, &jf
);
5215 ret
= send_to_remote_or_url(nullptr, url
, access_key
, secret_key
,
5218 cerr
<< "request failed: " << cpp_strerror(-ret
) << std::endl
;
5223 case OPT_PERIOD_UPDATE
:
5225 int ret
= update_period(realm_id
, realm_name
, period_id
, period_epoch
,
5226 commit
, remote
, url
, access_key
, secret_key
,
5227 formatter
, yes_i_really_mean_it
);
5233 case OPT_PERIOD_COMMIT
:
5235 // read realm and staging period
5236 RGWRealm
realm(realm_id
, realm_name
);
5237 int ret
= realm
.init(g_ceph_context
, store
->svc
.sysobj
);
5239 cerr
<< "Error initializing realm: " << cpp_strerror(-ret
) << std::endl
;
5242 RGWPeriod
period(RGWPeriod::get_staging_id(realm
.get_id()), 1);
5243 ret
= period
.init(g_ceph_context
, store
->svc
.sysobj
, realm
.get_id());
5245 cerr
<< "period init failed: " << cpp_strerror(-ret
) << std::endl
;
5248 ret
= commit_period(realm
, period
, remote
, url
, access_key
, secret_key
,
5249 yes_i_really_mean_it
);
5251 cerr
<< "failed to commit period: " << cpp_strerror(-ret
) << std::endl
;
5255 encode_json("period", period
, formatter
);
5256 formatter
->flush(cout
);
5259 case OPT_ROLE_CREATE
:
5261 if (role_name
.empty()) {
5262 cerr
<< "ERROR: role name is empty" << std::endl
;
5266 if (assume_role_doc
.empty()) {
5267 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
5270 bufferlist bl
= bufferlist::static_from_string(assume_role_doc
);
5272 const rgw::IAM::Policy
p(g_ceph_context
, tenant
, bl
);
5273 } catch (rgw::IAM::PolicyParseException
& e
) {
5274 cerr
<< "failed to parse policy: " << e
.what() << std::endl
;
5277 RGWRole
role(g_ceph_context
, store
, role_name
, path
, assume_role_doc
, tenant
);
5278 ret
= role
.create(true);
5282 show_role_info(role
, formatter
);
5285 case OPT_ROLE_DELETE
:
5287 if (role_name
.empty()) {
5288 cerr
<< "ERROR: empty role name" << std::endl
;
5291 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5292 ret
= role
.delete_obj();
5296 cout
<< "role: " << role_name
<< " successfully deleted" << std::endl
;
5301 if (role_name
.empty()) {
5302 cerr
<< "ERROR: empty role name" << std::endl
;
5305 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5310 show_role_info(role
, formatter
);
5313 case OPT_ROLE_MODIFY
:
5315 if (role_name
.empty()) {
5316 cerr
<< "ERROR: role name is empty" << std::endl
;
5320 if (assume_role_doc
.empty()) {
5321 cerr
<< "ERROR: assume role policy document is empty" << std::endl
;
5325 bufferlist bl
= bufferlist::static_from_string(assume_role_doc
);
5327 const rgw::IAM::Policy
p(g_ceph_context
, tenant
, bl
);
5328 } catch (rgw::IAM::PolicyParseException
& e
) {
5329 cerr
<< "failed to parse policy: " << e
.what() << std::endl
;
5333 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5338 role
.update_trust_policy(assume_role_doc
);
5339 ret
= role
.update();
5343 cout
<< "Assume role policy document updated successfully for role: " << role_name
<< std::endl
;
5348 vector
<RGWRole
> result
;
5349 ret
= RGWRole::get_roles_by_path_prefix(store
, g_ceph_context
, path_prefix
, tenant
, result
);
5353 show_roles_info(result
, formatter
);
5356 case OPT_ROLE_POLICY_PUT
:
5358 if (role_name
.empty()) {
5359 cerr
<< "role name is empty" << std::endl
;
5363 if (policy_name
.empty()) {
5364 cerr
<< "policy name is empty" << std::endl
;
5368 if (perm_policy_doc
.empty()) {
5369 cerr
<< "permission policy document is empty" << std::endl
;
5373 bufferlist bl
= bufferlist::static_from_string(perm_policy_doc
);
5375 const rgw::IAM::Policy
p(g_ceph_context
, tenant
, bl
);
5376 } catch (rgw::IAM::PolicyParseException
& e
) {
5377 cerr
<< "failed to parse perm policy: " << e
.what() << std::endl
;
5381 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5386 role
.set_perm_policy(policy_name
, perm_policy_doc
);
5387 ret
= role
.update();
5391 cout
<< "Permission policy attached successfully" << std::endl
;
5394 case OPT_ROLE_POLICY_LIST
:
5396 if (role_name
.empty()) {
5397 cerr
<< "ERROR: Role name is empty" << std::endl
;
5400 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5405 std::vector
<string
> policy_names
= role
.get_role_policy_names();
5406 show_policy_names(policy_names
, formatter
);
5409 case OPT_ROLE_POLICY_GET
:
5411 if (role_name
.empty()) {
5412 cerr
<< "ERROR: role name is empty" << std::endl
;
5416 if (policy_name
.empty()) {
5417 cerr
<< "ERROR: policy name is empty" << std::endl
;
5420 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5421 int ret
= role
.get();
5426 ret
= role
.get_role_policy(policy_name
, perm_policy
);
5430 show_perm_policy(perm_policy
, formatter
);
5433 case OPT_ROLE_POLICY_DELETE
:
5435 if (role_name
.empty()) {
5436 cerr
<< "ERROR: role name is empty" << std::endl
;
5440 if (policy_name
.empty()) {
5441 cerr
<< "ERROR: policy name is empty" << std::endl
;
5444 RGWRole
role(g_ceph_context
, store
, role_name
, tenant
);
5449 ret
= role
.delete_policy(policy_name
);
5453 ret
= role
.update();
5457 cout
<< "Policy: " << policy_name
<< " successfully deleted for role: "
5458 << role_name
<< std::endl
;
5462 output_user_info
= false;
5465 // output the result of a user operation
5466 if (output_user_info
) {
5467 ret
= user
.info(info
, &err_msg
);
5469 cerr
<< "could not fetch user info: " << err_msg
<< std::endl
;
5472 show_user_info(info
, formatter
);
5475 if (opt_cmd
== OPT_POLICY
) {
5476 if (format
== "xml") {
5477 int ret
= RGWBucketAdminOp::dump_s3_policy(store
, bucket_op
, cout
);
5479 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
5483 int ret
= RGWBucketAdminOp::get_policy(store
, bucket_op
, f
);
5485 cerr
<< "ERROR: failed to get policy: " << cpp_strerror(-ret
) << std::endl
;
5491 if (opt_cmd
== OPT_BUCKET_LIMIT_CHECK
) {
5493 std::list
<std::string
> user_ids
;
5494 metadata_key
= "user";
5499 if (! user_id
.empty()) {
5500 user_ids
.push_back(user_id
.id
);
5502 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
5505 /* list users in groups of max-keys, then perform user-bucket
5506 * limit-check on each group */
5507 ret
= store
->meta_mgr
->list_keys_init(metadata_key
, &handle
);
5509 cerr
<< "ERROR: buckets limit check can't get user metadata_key: "
5510 << cpp_strerror(-ret
) << std::endl
;
5515 ret
= store
->meta_mgr
->list_keys_next(handle
, max
, user_ids
,
5517 if (ret
< 0 && ret
!= -ENOENT
) {
5518 cerr
<< "ERROR: buckets limit check lists_keys_next(): "
5519 << cpp_strerror(-ret
) << std::endl
;
5522 /* ok, do the limit checks for this group */
5524 RGWBucketAdminOp::limit_check(store
, bucket_op
, user_ids
, f
,
5530 } while (truncated
);
5531 store
->meta_mgr
->list_keys_complete(handle
);
5534 } /* OPT_BUCKET_LIMIT_CHECK */
5536 if (opt_cmd
== OPT_BUCKETS_LIST
) {
5537 if (bucket_name
.empty()) {
5538 if (!user_id
.empty()) {
5539 if (!user_op
.has_existing_user()) {
5540 cerr
<< "ERROR: could not find user: " << user_id
<< std::endl
;
5544 RGWBucketAdminOp::info(store
, bucket_op
, f
);
5546 RGWBucketInfo bucket_info
;
5547 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5549 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5552 formatter
->open_array_section("entries");
5555 if (max_entries
< 0)
5560 vector
<rgw_bucket_dir_entry
> result
;
5561 map
<string
, bool> common_prefixes
;
5564 RGWRados::Bucket
target(store
, bucket_info
);
5565 RGWRados::Bucket::List
list_op(&target
);
5567 list_op
.params
.prefix
= prefix
;
5568 list_op
.params
.delim
= delim
;
5569 list_op
.params
.marker
= rgw_obj_key(marker
);
5570 list_op
.params
.ns
= ns
;
5571 list_op
.params
.enforce_ns
= false;
5572 list_op
.params
.list_versions
= true;
5573 list_op
.params
.allow_unordered
= bool(allow_unordered
);
5576 ret
= list_op
.list_objects(max_entries
- count
, &result
, &common_prefixes
, &truncated
);
5578 cerr
<< "ERROR: store->list_objects(): " << cpp_strerror(-ret
) << std::endl
;
5582 count
+= result
.size();
5584 for (vector
<rgw_bucket_dir_entry
>::iterator iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
5585 rgw_bucket_dir_entry
& entry
= *iter
;
5586 encode_json("entry", entry
, formatter
);
5588 formatter
->flush(cout
);
5589 } while (truncated
&& count
< max_entries
);
5591 formatter
->close_section();
5592 formatter
->flush(cout
);
5593 } /* have bucket_name */
5594 } /* OPT_BUCKETS_LIST */
5596 if (opt_cmd
== OPT_BUCKET_STATS
) {
5597 bucket_op
.set_fetch_stats(true);
5599 int r
= RGWBucketAdminOp::info(store
, bucket_op
, f
);
5601 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
5606 if (opt_cmd
== OPT_BUCKET_LINK
) {
5607 bucket_op
.set_bucket_id(bucket_id
);
5609 int r
= RGWBucketAdminOp::link(store
, bucket_op
, &err
);
5611 cerr
<< "failure: " << cpp_strerror(-r
) << ": " << err
<< std::endl
;
5616 if (opt_cmd
== OPT_BUCKET_UNLINK
) {
5617 int r
= RGWBucketAdminOp::unlink(store
, bucket_op
);
5619 cerr
<< "failure: " << cpp_strerror(-r
) << std::endl
;
5624 if (opt_cmd
== OPT_LOG_LIST
) {
5626 if (date
.size() && date
.size() != 10) {
5627 cerr
<< "bad date format for '" << date
<< "', expect YYYY-MM-DD" << std::endl
;
5632 formatter
->open_array_section("logs");
5634 int r
= store
->log_list_init(date
, &h
);
5639 cerr
<< "log list: error " << r
<< std::endl
;
5644 int r
= store
->log_list_next(h
, &name
);
5648 cerr
<< "log list: error " << r
<< std::endl
;
5651 formatter
->dump_string("object", name
);
5654 formatter
->close_section();
5655 formatter
->flush(cout
);
5659 if (opt_cmd
== OPT_LOG_SHOW
|| opt_cmd
== OPT_LOG_RM
) {
5660 if (object
.empty() && (date
.empty() || bucket_name
.empty() || bucket_id
.empty())) {
5661 cerr
<< "specify an object or a date, bucket and bucket-id" << std::endl
;
5666 if (!object
.empty()) {
5676 if (opt_cmd
== OPT_LOG_SHOW
) {
5679 int r
= store
->log_show_init(oid
, &h
);
5681 cerr
<< "error opening log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5686 formatter
->open_object_section("log");
5688 struct rgw_log_entry entry
;
5690 // peek at first entry to get bucket metadata
5691 r
= store
->log_show_next(h
, &entry
);
5693 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5696 formatter
->dump_string("bucket_id", entry
.bucket_id
);
5697 formatter
->dump_string("bucket_owner", entry
.bucket_owner
.to_str());
5698 formatter
->dump_string("bucket", entry
.bucket
);
5700 uint64_t agg_time
= 0;
5701 uint64_t agg_bytes_sent
= 0;
5702 uint64_t agg_bytes_received
= 0;
5703 uint64_t total_entries
= 0;
5705 if (show_log_entries
)
5706 formatter
->open_array_section("log_entries");
5709 using namespace std::chrono
;
5710 uint64_t total_time
= duration_cast
<milliseconds
>(entry
.total_time
).count();
5712 agg_time
+= total_time
;
5713 agg_bytes_sent
+= entry
.bytes_sent
;
5714 agg_bytes_received
+= entry
.bytes_received
;
5717 if (skip_zero_entries
&& entry
.bytes_sent
== 0 &&
5718 entry
.bytes_received
== 0)
5721 if (show_log_entries
) {
5723 rgw_format_ops_log_entry(entry
, formatter
);
5724 formatter
->flush(cout
);
5727 r
= store
->log_show_next(h
, &entry
);
5731 cerr
<< "error reading log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5734 if (show_log_entries
)
5735 formatter
->close_section();
5738 formatter
->open_object_section("log_sum");
5739 formatter
->dump_int("bytes_sent", agg_bytes_sent
);
5740 formatter
->dump_int("bytes_received", agg_bytes_received
);
5741 formatter
->dump_int("total_time", agg_time
);
5742 formatter
->dump_int("total_entries", total_entries
);
5743 formatter
->close_section();
5745 formatter
->close_section();
5746 formatter
->flush(cout
);
5749 if (opt_cmd
== OPT_LOG_RM
) {
5750 int r
= store
->log_remove(oid
);
5752 cerr
<< "error removing log " << oid
<< ": " << cpp_strerror(-r
) << std::endl
;
5758 if (opt_cmd
== OPT_POOL_ADD
) {
5759 if (pool_name
.empty()) {
5760 cerr
<< "need to specify pool to add!" << std::endl
;
5764 int ret
= store
->svc
.zone
->add_bucket_placement(pool
);
5766 cerr
<< "failed to add bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5769 if (opt_cmd
== OPT_POOL_RM
) {
5770 if (pool_name
.empty()) {
5771 cerr
<< "need to specify pool to remove!" << std::endl
;
5775 int ret
= store
->svc
.zone
->remove_bucket_placement(pool
);
5777 cerr
<< "failed to remove bucket placement: " << cpp_strerror(-ret
) << std::endl
;
5780 if (opt_cmd
== OPT_POOLS_LIST
) {
5781 set
<rgw_pool
> pools
;
5782 int ret
= store
->svc
.zone
->list_placement_set(pools
);
5784 cerr
<< "could not list placement set: " << cpp_strerror(-ret
) << std::endl
;
5788 formatter
->open_array_section("pools");
5789 for (auto siter
= pools
.begin(); siter
!= pools
.end(); ++siter
) {
5790 formatter
->open_object_section("pool");
5791 formatter
->dump_string("name", siter
->to_str());
5792 formatter
->close_section();
5794 formatter
->close_section();
5795 formatter
->flush(cout
);
5799 if (opt_cmd
== OPT_USAGE_SHOW
) {
5800 uint64_t start_epoch
= 0;
5801 uint64_t end_epoch
= (uint64_t)-1;
5805 if (!start_date
.empty()) {
5806 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5808 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5812 if (!end_date
.empty()) {
5813 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5815 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5821 ret
= RGWUsage::show(store
, user_id
, bucket_name
, start_epoch
, end_epoch
,
5822 show_log_entries
, show_log_sum
, &categories
,
5825 cerr
<< "ERROR: failed to show usage" << std::endl
;
5830 if (opt_cmd
== OPT_USAGE_TRIM
) {
5831 if (user_id
.empty() && bucket_name
.empty() &&
5832 start_date
.empty() && end_date
.empty() && !yes_i_really_mean_it
) {
5833 cerr
<< "usage trim without user/date/bucket specified will remove *all* users data" << std::endl
;
5834 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5838 uint64_t start_epoch
= 0;
5839 uint64_t end_epoch
= (uint64_t)-1;
5842 if (!start_date
.empty()) {
5843 ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
5845 cerr
<< "ERROR: failed to parse start date" << std::endl
;
5850 if (!end_date
.empty()) {
5851 ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
5853 cerr
<< "ERROR: failed to parse end date" << std::endl
;
5858 ret
= RGWUsage::trim(store
, user_id
, bucket_name
, start_epoch
, end_epoch
);
5860 cerr
<< "ERROR: read_usage() returned ret=" << ret
<< std::endl
;
5865 if (opt_cmd
== OPT_USAGE_CLEAR
) {
5866 if (!yes_i_really_mean_it
) {
5867 cerr
<< "usage clear would remove *all* users usage data for all time" << std::endl
;
5868 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
5872 ret
= RGWUsage::clear(store
);
5879 if (opt_cmd
== OPT_OLH_GET
|| opt_cmd
== OPT_OLH_READLOG
) {
5880 if (bucket_name
.empty()) {
5881 cerr
<< "ERROR: bucket not specified" << std::endl
;
5884 if (object
.empty()) {
5885 cerr
<< "ERROR: object not specified" << std::endl
;
5890 if (opt_cmd
== OPT_OLH_GET
) {
5891 RGWBucketInfo bucket_info
;
5892 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5894 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5898 rgw_obj
obj(bucket
, object
);
5899 ret
= store
->get_olh(bucket_info
, obj
, &olh
);
5901 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5904 encode_json("olh", olh
, formatter
);
5905 formatter
->flush(cout
);
5908 if (opt_cmd
== OPT_OLH_READLOG
) {
5909 RGWBucketInfo bucket_info
;
5910 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5912 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5915 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > log
;
5918 RGWObjectCtx
rctx(store
);
5919 rgw_obj
obj(bucket
, object
);
5923 ret
= store
->get_obj_state(&rctx
, bucket_info
, obj
, &state
, false); /* don't follow olh */
5928 ret
= store
->bucket_index_read_olh_log(bucket_info
, *state
, obj
, 0, &log
, &is_truncated
);
5930 cerr
<< "ERROR: failed reading olh: " << cpp_strerror(-ret
) << std::endl
;
5933 formatter
->open_object_section("result");
5934 encode_json("is_truncated", is_truncated
, formatter
);
5935 encode_json("log", log
, formatter
);
5936 formatter
->close_section();
5937 formatter
->flush(cout
);
5940 if (opt_cmd
== OPT_BI_GET
) {
5941 if (bucket_name
.empty()) {
5942 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5945 if (object
.empty()) {
5946 cerr
<< "ERROR: object not specified" << std::endl
;
5949 RGWBucketInfo bucket_info
;
5950 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5952 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5955 rgw_obj
obj(bucket
, object
);
5956 if (!object_version
.empty()) {
5957 obj
.key
.set_instance(object_version
);
5960 rgw_cls_bi_entry entry
;
5962 ret
= store
->bi_get(bucket_info
, obj
, bi_index_type
, &entry
);
5964 cerr
<< "ERROR: bi_get(): " << cpp_strerror(-ret
) << std::endl
;
5968 encode_json("entry", entry
, formatter
);
5969 formatter
->flush(cout
);
5972 if (opt_cmd
== OPT_BI_PUT
) {
5973 if (bucket_name
.empty()) {
5974 cerr
<< "ERROR: bucket name not specified" << std::endl
;
5977 RGWBucketInfo bucket_info
;
5978 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
5980 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
5984 rgw_cls_bi_entry entry
;
5985 cls_rgw_obj_key key
;
5986 ret
= read_decode_json(infile
, entry
, &key
);
5991 rgw_obj
obj(bucket
, key
);
5993 ret
= store
->bi_put(bucket
, obj
, entry
);
5995 cerr
<< "ERROR: bi_put(): " << cpp_strerror(-ret
) << std::endl
;
6000 if (opt_cmd
== OPT_BI_LIST
) {
6001 if (bucket_name
.empty()) {
6002 cerr
<< "ERROR: bucket name not specified" << std::endl
;
6005 RGWBucketInfo bucket_info
;
6006 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6008 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6012 list
<rgw_cls_bi_entry
> entries
;
6014 if (max_entries
< 0) {
6018 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
6020 formatter
->open_array_section("entries");
6022 for (int i
= 0; i
< max_shards
; i
++) {
6023 RGWRados::BucketShard
bs(store
);
6024 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
6025 int ret
= bs
.init(bucket
, shard_id
, nullptr /* no RGWBucketInfo */);
6029 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
6035 ret
= store
->bi_list(bs
, object
, marker
, max_entries
, &entries
, &is_truncated
);
6037 cerr
<< "ERROR: bi_list(): " << cpp_strerror(-ret
) << std::endl
;
6041 list
<rgw_cls_bi_entry
>::iterator iter
;
6042 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
6043 rgw_cls_bi_entry
& entry
= *iter
;
6044 encode_json("entry", entry
, formatter
);
6047 formatter
->flush(cout
);
6048 } while (is_truncated
);
6049 formatter
->flush(cout
);
6051 formatter
->close_section();
6052 formatter
->flush(cout
);
6055 if (opt_cmd
== OPT_BI_PURGE
) {
6056 if (bucket_name
.empty()) {
6057 cerr
<< "ERROR: bucket name not specified" << std::endl
;
6060 RGWBucketInfo bucket_info
;
6061 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6063 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6067 RGWBucketInfo cur_bucket_info
;
6068 rgw_bucket cur_bucket
;
6069 ret
= init_bucket(tenant
, bucket_name
, string(), cur_bucket_info
, cur_bucket
);
6071 cerr
<< "ERROR: could not init current bucket info for bucket_name=" << bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
6075 if (cur_bucket_info
.bucket
.bucket_id
== bucket_info
.bucket
.bucket_id
&& !yes_i_really_mean_it
) {
6076 cerr
<< "specified bucket instance points to a current bucket instance" << std::endl
;
6077 cerr
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
6081 int max_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
6083 for (int i
= 0; i
< max_shards
; i
++) {
6084 RGWRados::BucketShard
bs(store
);
6085 int shard_id
= (bucket_info
.num_shards
> 0 ? i
: -1);
6086 int ret
= bs
.init(bucket
, shard_id
, nullptr /* no RGWBucketInfo */);
6088 cerr
<< "ERROR: bs.init(bucket=" << bucket
<< ", shard=" << shard_id
<< "): " << cpp_strerror(-ret
) << std::endl
;
6092 ret
= store
->bi_remove(bs
);
6094 cerr
<< "ERROR: failed to remove bucket index object: " << cpp_strerror(-ret
) << std::endl
;
6100 if (opt_cmd
== OPT_OBJECT_PUT
) {
6101 if (bucket_name
.empty()) {
6102 cerr
<< "ERROR: bucket not specified" << std::endl
;
6105 if (object
.empty()) {
6106 cerr
<< "ERROR: object not specified" << std::endl
;
6110 RGWDataAccess
data_access(store
);
6111 rgw_obj_key
key(object
, object_version
);
6113 RGWDataAccess::BucketRef b
;
6114 RGWDataAccess::ObjectRef obj
;
6116 int ret
= data_access
.get_bucket(tenant
, bucket_name
, bucket_id
, &b
);
6118 cerr
<< "ERROR: failed to init bucket: " << cpp_strerror(-ret
) << std::endl
;
6122 ret
= b
->get_object(key
, &obj
);
6124 cerr
<< "ERROR: failed to get object: " << cpp_strerror(-ret
) << std::endl
;
6129 ret
= read_input(infile
, bl
);
6131 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6134 map
<string
, bufferlist
> attrs
;
6135 ret
= obj
->put(bl
, attrs
);
6137 cerr
<< "ERROR: put object returned error: " << cpp_strerror(-ret
) << std::endl
;
6141 if (opt_cmd
== OPT_OBJECT_RM
) {
6142 RGWBucketInfo bucket_info
;
6143 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6145 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6148 rgw_obj_key
key(object
, object_version
);
6149 ret
= rgw_remove_object(store
, bucket_info
, bucket
, key
);
6152 cerr
<< "ERROR: object remove returned: " << cpp_strerror(-ret
) << std::endl
;
6157 if (opt_cmd
== OPT_OBJECT_REWRITE
) {
6158 if (bucket_name
.empty()) {
6159 cerr
<< "ERROR: bucket not specified" << std::endl
;
6162 if (object
.empty()) {
6163 cerr
<< "ERROR: object not specified" << std::endl
;
6167 RGWBucketInfo bucket_info
;
6168 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6170 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6174 rgw_obj
obj(bucket
, object
);
6175 obj
.key
.set_instance(object_version
);
6176 bool need_rewrite
= true;
6177 if (min_rewrite_stripe_size
> 0) {
6178 ret
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
6180 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << ret
<< dendl
;
6184 ret
= store
->rewrite_obj(bucket_info
, obj
);
6186 cerr
<< "ERROR: object rewrite returned: " << cpp_strerror(-ret
) << std::endl
;
6190 ldout(store
->ctx(), 20) << "skipped object" << dendl
;
6194 if (opt_cmd
== OPT_OBJECTS_EXPIRE
) {
6195 if (!store
->process_expire_objects()) {
6196 cerr
<< "ERROR: process_expire_objects() processing returned error." << std::endl
;
6201 if (opt_cmd
== OPT_OBJECTS_EXPIRE_STALE_LIST
) {
6202 ret
= RGWBucketAdminOp::fix_obj_expiry(store
, bucket_op
, f
, true);
6204 cerr
<< "ERROR: listing returned " << cpp_strerror(-ret
) << std::endl
;
6209 if (opt_cmd
== OPT_OBJECTS_EXPIRE_STALE_RM
) {
6210 ret
= RGWBucketAdminOp::fix_obj_expiry(store
, bucket_op
, f
, false);
6212 cerr
<< "ERROR: removing returned " << cpp_strerror(-ret
) << std::endl
;
6217 if (opt_cmd
== OPT_BUCKET_REWRITE
) {
6218 if (bucket_name
.empty()) {
6219 cerr
<< "ERROR: bucket not specified" << std::endl
;
6223 RGWBucketInfo bucket_info
;
6224 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6226 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6230 uint64_t start_epoch
= 0;
6231 uint64_t end_epoch
= 0;
6233 if (!end_date
.empty()) {
6234 int ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
6236 cerr
<< "ERROR: failed to parse end date" << std::endl
;
6240 if (!start_date
.empty()) {
6241 int ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
6243 cerr
<< "ERROR: failed to parse start date" << std::endl
;
6248 bool is_truncated
= true;
6250 rgw_obj_index_key marker
;
6253 formatter
->open_object_section("result");
6254 formatter
->dump_string("bucket", bucket_name
);
6255 formatter
->open_array_section("objects");
6256 while (is_truncated
) {
6257 map
<string
, rgw_bucket_dir_entry
> result
;
6259 store
->cls_bucket_list_ordered(bucket_info
, RGW_NO_SHARD
, marker
,
6261 result
, &is_truncated
, &marker
,
6262 bucket_object_check_filter
);
6264 if (r
< 0 && r
!= -ENOENT
) {
6265 cerr
<< "ERROR: failed operation r=" << r
<< std::endl
;
6271 map
<string
, rgw_bucket_dir_entry
>::iterator iter
;
6272 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
6273 rgw_obj_key key
= iter
->second
.key
;
6274 rgw_bucket_dir_entry
& entry
= iter
->second
;
6276 formatter
->open_object_section("object");
6277 formatter
->dump_string("name", key
.name
);
6278 formatter
->dump_string("instance", key
.instance
);
6279 formatter
->dump_int("size", entry
.meta
.size
);
6280 utime_t
ut(entry
.meta
.mtime
);
6281 ut
.gmtime(formatter
->dump_stream("mtime"));
6283 if ((entry
.meta
.size
< min_rewrite_size
) ||
6284 (entry
.meta
.size
> max_rewrite_size
) ||
6285 (start_epoch
> 0 && start_epoch
> (uint64_t)ut
.sec()) ||
6286 (end_epoch
> 0 && end_epoch
< (uint64_t)ut
.sec())) {
6287 formatter
->dump_string("status", "Skipped");
6289 rgw_obj
obj(bucket
, key
);
6291 bool need_rewrite
= true;
6292 if (min_rewrite_stripe_size
> 0) {
6293 r
= check_min_obj_stripe_size(store
, bucket_info
, obj
, min_rewrite_stripe_size
, &need_rewrite
);
6295 ldout(store
->ctx(), 0) << "WARNING: check_min_obj_stripe_size failed, r=" << r
<< dendl
;
6298 if (!need_rewrite
) {
6299 formatter
->dump_string("status", "Skipped");
6301 r
= store
->rewrite_obj(bucket_info
, obj
);
6303 formatter
->dump_string("status", "Success");
6305 formatter
->dump_string("status", cpp_strerror(-r
));
6309 formatter
->dump_int("flags", entry
.flags
);
6311 formatter
->close_section();
6312 formatter
->flush(cout
);
6315 formatter
->close_section();
6316 formatter
->close_section();
6317 formatter
->flush(cout
);
6320 if (opt_cmd
== OPT_BUCKET_RESHARD
) {
6322 RGWBucketInfo bucket_info
;
6323 map
<string
, bufferlist
> attrs
;
6325 int ret
= check_reshard_bucket_params(store
,
6329 num_shards_specified
,
6331 yes_i_really_mean_it
,
6339 RGWBucketReshard
br(store
, bucket_info
, attrs
, nullptr /* no callback */);
6341 #define DEFAULT_RESHARD_MAX_ENTRIES 1000
6342 if (max_entries
< 1) {
6343 max_entries
= DEFAULT_RESHARD_MAX_ENTRIES
;
6346 return br
.execute(num_shards
, max_entries
,
6347 verbose
, &cout
, formatter
);
6350 if (opt_cmd
== OPT_RESHARD_ADD
) {
6352 RGWBucketInfo bucket_info
;
6353 map
<string
, bufferlist
> attrs
;
6355 int ret
= check_reshard_bucket_params(store
,
6359 num_shards_specified
,
6361 yes_i_really_mean_it
,
6369 int num_source_shards
= (bucket_info
.num_shards
> 0 ? bucket_info
.num_shards
: 1);
6371 RGWReshard
reshard(store
);
6372 cls_rgw_reshard_entry entry
;
6373 entry
.time
= real_clock::now();
6374 entry
.tenant
= tenant
;
6375 entry
.bucket_name
= bucket_name
;
6376 entry
.bucket_id
= bucket_info
.bucket
.bucket_id
;
6377 entry
.old_num_shards
= num_source_shards
;
6378 entry
.new_num_shards
= num_shards
;
6380 return reshard
.add(entry
);
6383 if (opt_cmd
== OPT_RESHARD_LIST
) {
6384 list
<cls_rgw_reshard_entry
> entries
;
6387 if (max_entries
< 0) {
6392 store
->ctx()->_conf
.get_val
<uint64_t>("rgw_reshard_num_logs");
6394 RGWReshard
reshard(store
);
6396 formatter
->open_array_section("reshard");
6397 for (int i
= 0; i
< num_logshards
; i
++) {
6398 bool is_truncated
= true;
6402 ret
= reshard
.list(i
, marker
, max_entries
, entries
, &is_truncated
);
6404 cerr
<< "Error listing resharding buckets: " << cpp_strerror(-ret
) << std::endl
;
6407 for (auto iter
=entries
.begin(); iter
!= entries
.end(); ++iter
) {
6408 cls_rgw_reshard_entry
& entry
= *iter
;
6409 encode_json("entry", entry
, formatter
);
6410 entry
.get_key(&marker
);
6412 count
+= entries
.size();
6413 formatter
->flush(cout
);
6414 } while (is_truncated
&& count
< max_entries
);
6416 if (count
>= max_entries
) {
6421 formatter
->close_section();
6422 formatter
->flush(cout
);
6426 if (opt_cmd
== OPT_RESHARD_STATUS
) {
6427 if (bucket_name
.empty()) {
6428 cerr
<< "ERROR: bucket not specified" << std::endl
;
6433 RGWBucketInfo bucket_info
;
6434 map
<string
, bufferlist
> attrs
;
6435 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
6437 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6441 RGWBucketReshard
br(store
, bucket_info
, attrs
, nullptr /* no callback */);
6442 list
<cls_rgw_bucket_instance_entry
> status
;
6443 int r
= br
.get_status(&status
);
6445 cerr
<< "ERROR: could not get resharding status for bucket " <<
6446 bucket_name
<< std::endl
;
6450 show_reshard_status(status
, formatter
);
6453 if (opt_cmd
== OPT_RESHARD_PROCESS
) {
6454 RGWReshard
reshard(store
, true, &cout
);
6456 int ret
= reshard
.process_all_logshards();
6458 cerr
<< "ERROR: failed to process reshard logs, error=" << cpp_strerror(-ret
) << std::endl
;
6463 if (opt_cmd
== OPT_RESHARD_CANCEL
) {
6464 if (bucket_name
.empty()) {
6465 cerr
<< "ERROR: bucket not specified" << std::endl
;
6470 RGWBucketInfo bucket_info
;
6471 map
<string
, bufferlist
> attrs
;
6472 bool bucket_initable
= true;
6473 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
,
6476 if (yes_i_really_mean_it
) {
6477 bucket_initable
= false;
6479 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) <<
6480 "; if you want to cancel the reshard request nonetheless, please "
6481 "use the --yes-i-really-mean-it option" << std::endl
;
6486 if (bucket_initable
) {
6487 // we did not encounter an error, so let's work with the bucket
6488 RGWBucketReshard
br(store
, bucket_info
, attrs
,
6489 nullptr /* no callback */);
6490 int ret
= br
.cancel();
6492 if (ret
== -EBUSY
) {
6493 cerr
<< "There is ongoing resharding, please retry after " <<
6494 store
->ctx()->_conf
.get_val
<uint64_t>(
6495 "rgw_reshard_bucket_lock_duration") <<
6496 " seconds " << std::endl
;
6498 cerr
<< "Error canceling bucket " << bucket_name
<<
6499 " resharding: " << cpp_strerror(-ret
) << std::endl
;
6505 RGWReshard
reshard(store
);
6507 cls_rgw_reshard_entry entry
;
6508 entry
.tenant
= tenant
;
6509 entry
.bucket_name
= bucket_name
;
6510 //entry.bucket_id = bucket_id;
6512 ret
= reshard
.remove(entry
);
6513 if (ret
< 0 && ret
!= -ENOENT
) {
6514 cerr
<< "Error in updating reshard log with bucket " <<
6515 bucket_name
<< ": " << cpp_strerror(-ret
) << std::endl
;
6518 } // OPT_RESHARD_CANCEL
6520 if (opt_cmd
== OPT_OBJECT_UNLINK
) {
6521 RGWBucketInfo bucket_info
;
6522 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6524 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6527 list
<rgw_obj_index_key
> oid_list
;
6528 rgw_obj_key
key(object
, object_version
);
6529 rgw_obj_index_key index_key
;
6530 key
.get_index_key(&index_key
);
6531 oid_list
.push_back(index_key
);
6532 ret
= store
->remove_objs_from_index(bucket_info
, oid_list
);
6534 cerr
<< "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret
) << std::endl
;
6539 if (opt_cmd
== OPT_OBJECT_STAT
) {
6540 RGWBucketInfo bucket_info
;
6541 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
6543 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6546 rgw_obj
obj(bucket
, object
);
6547 obj
.key
.set_instance(object_version
);
6550 map
<string
, bufferlist
> attrs
;
6551 RGWObjectCtx
obj_ctx(store
);
6552 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
6553 RGWRados::Object::Read
read_op(&op_target
);
6555 read_op
.params
.attrs
= &attrs
;
6556 read_op
.params
.obj_size
= &obj_size
;
6558 ret
= read_op
.prepare();
6560 cerr
<< "ERROR: failed to stat object, returned error: " << cpp_strerror(-ret
) << std::endl
;
6563 formatter
->open_object_section("object_metadata");
6564 formatter
->dump_string("name", object
);
6565 formatter
->dump_unsigned("size", obj_size
);
6567 map
<string
, bufferlist
>::iterator iter
;
6568 map
<string
, bufferlist
> other_attrs
;
6569 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
6570 bufferlist
& bl
= iter
->second
;
6571 bool handled
= false;
6572 if (iter
->first
== RGW_ATTR_MANIFEST
) {
6573 handled
= decode_dump
<RGWObjManifest
>("manifest", bl
, formatter
);
6574 } else if (iter
->first
== RGW_ATTR_ACL
) {
6575 handled
= decode_dump
<RGWAccessControlPolicy
>("policy", bl
, formatter
);
6576 } else if (iter
->first
== RGW_ATTR_ID_TAG
) {
6577 handled
= dump_string("tag", bl
, formatter
);
6578 } else if (iter
->first
== RGW_ATTR_ETAG
) {
6579 handled
= dump_string("etag", bl
, formatter
);
6580 } else if (iter
->first
== RGW_ATTR_COMPRESSION
) {
6581 handled
= decode_dump
<RGWCompressionInfo
>("compression", bl
, formatter
);
6582 } else if (iter
->first
== RGW_ATTR_DELETE_AT
) {
6583 handled
= decode_dump
<utime_t
>("delete_at", bl
, formatter
);
6587 other_attrs
[iter
->first
] = bl
;
6590 formatter
->open_object_section("attrs");
6591 for (iter
= other_attrs
.begin(); iter
!= other_attrs
.end(); ++iter
) {
6592 dump_string(iter
->first
.c_str(), iter
->second
, formatter
);
6594 formatter
->close_section();
6595 formatter
->close_section();
6596 formatter
->flush(cout
);
6599 if (opt_cmd
== OPT_BUCKET_CHECK
) {
6600 if (check_head_obj_locator
) {
6601 if (bucket_name
.empty()) {
6602 cerr
<< "ERROR: need to specify bucket name" << std::endl
;
6605 do_check_object_locator(tenant
, bucket_name
, fix
, remove_bad
, formatter
);
6607 RGWBucketAdminOp::check_index(store
, bucket_op
, f
);
6611 if (opt_cmd
== OPT_BUCKET_RM
) {
6612 if (!inconsistent_index
) {
6613 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, true);
6615 if (!yes_i_really_mean_it
) {
6616 cerr
<< "using --inconsistent_index can corrupt the bucket index " << std::endl
6617 << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl
;
6620 RGWBucketAdminOp::remove_bucket(store
, bucket_op
, bypass_gc
, false);
6624 if (opt_cmd
== OPT_GC_LIST
) {
6627 formatter
->open_array_section("entries");
6630 list
<cls_rgw_gc_obj_info
> result
;
6631 int ret
= store
->list_gc_objs(&index
, marker
, 1000, !include_all
, result
, &truncated
);
6633 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
6638 list
<cls_rgw_gc_obj_info
>::iterator iter
;
6639 for (iter
= result
.begin(); iter
!= result
.end(); ++iter
) {
6640 cls_rgw_gc_obj_info
& info
= *iter
;
6641 formatter
->open_object_section("chain_info");
6642 formatter
->dump_string("tag", info
.tag
);
6643 formatter
->dump_stream("time") << info
.time
;
6644 formatter
->open_array_section("objs");
6645 list
<cls_rgw_obj
>::iterator liter
;
6646 cls_rgw_obj_chain
& chain
= info
.chain
;
6647 for (liter
= chain
.objs
.begin(); liter
!= chain
.objs
.end(); ++liter
) {
6648 cls_rgw_obj
& obj
= *liter
;
6649 encode_json("obj", obj
, formatter
);
6651 formatter
->close_section(); // objs
6652 formatter
->close_section(); // obj_chain
6653 formatter
->flush(cout
);
6655 } while (truncated
);
6656 formatter
->close_section();
6657 formatter
->flush(cout
);
6660 if (opt_cmd
== OPT_GC_PROCESS
) {
6661 int ret
= store
->process_gc(!include_all
);
6663 cerr
<< "ERROR: gc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
6668 if (opt_cmd
== OPT_LC_LIST
) {
6669 formatter
->open_array_section("lifecycle_list");
6670 map
<string
, int> bucket_lc_map
;
6672 #define MAX_LC_LIST_ENTRIES 100
6673 if (max_entries
< 0) {
6674 max_entries
= MAX_LC_LIST_ENTRIES
;
6677 int ret
= store
->list_lc_progress(marker
, max_entries
, &bucket_lc_map
);
6679 cerr
<< "ERROR: failed to list objs: " << cpp_strerror(-ret
) << std::endl
;
6682 map
<string
, int>::iterator iter
;
6683 for (iter
= bucket_lc_map
.begin(); iter
!= bucket_lc_map
.end(); ++iter
) {
6684 formatter
->open_object_section("bucket_lc_info");
6685 formatter
->dump_string("bucket", iter
->first
);
6686 string lc_status
= LC_STATUS
[iter
->second
];
6687 formatter
->dump_string("status", lc_status
);
6688 formatter
->close_section(); // objs
6689 formatter
->flush(cout
);
6690 marker
= iter
->first
;
6692 } while (!bucket_lc_map
.empty());
6694 formatter
->close_section(); //lifecycle list
6695 formatter
->flush(cout
);
6699 if (opt_cmd
== OPT_LC_GET
) {
6700 if (bucket_name
.empty()) {
6701 cerr
<< "ERROR: bucket not specified" << std::endl
;
6706 RGWBucketInfo bucket_info
;
6707 map
<string
, bufferlist
> attrs
;
6708 RGWLifecycleConfiguration config
;
6709 ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
, &attrs
);
6711 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
6715 auto aiter
= attrs
.find(RGW_ATTR_LC
);
6716 if (aiter
== attrs
.end()) {
6720 bufferlist::const_iterator iter
{&aiter
->second
};
6722 config
.decode(iter
);
6723 } catch (const buffer::error
& e
) {
6724 cerr
<< "ERROR: decode life cycle config failed" << std::endl
;
6728 encode_json("result", config
, formatter
);
6729 formatter
->flush(cout
);
6732 if (opt_cmd
== OPT_LC_PROCESS
) {
6733 int ret
= store
->process_lc();
6735 cerr
<< "ERROR: lc processing returned error: " << cpp_strerror(-ret
) << std::endl
;
6741 if (opt_cmd
== OPT_LC_RESHARD_FIX
) {
6742 ret
= RGWBucketAdminOp::fix_lc_shards(store
, bucket_op
,f
);
6744 cerr
<< "ERROR: listing stale instances" << cpp_strerror(-ret
) << std::endl
;
6749 if (opt_cmd
== OPT_ORPHANS_FIND
) {
6750 if (!yes_i_really_mean_it
) {
6751 cerr
<< "accidental removal of active objects can not be reversed; "
6752 << "do you really mean it? (requires --yes-i-really-mean-it)"
6757 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6759 if (job_id
.empty()) {
6760 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6763 if (pool_name
.empty()) {
6764 cerr
<< "ERROR: --pool not specified" << std::endl
;
6768 RGWOrphanSearchInfo info
;
6771 info
.job_name
= job_id
;
6772 info
.num_shards
= num_shards
;
6774 int ret
= search
.init(job_id
, &info
, detail
);
6776 cerr
<< "could not init search, ret=" << ret
<< std::endl
;
6785 if (opt_cmd
== OPT_ORPHANS_FINISH
) {
6786 RGWOrphanSearch
search(store
, max_concurrent_ios
, orphan_stale_secs
);
6788 if (job_id
.empty()) {
6789 cerr
<< "ERROR: --job-id not specified" << std::endl
;
6792 int ret
= search
.init(job_id
, NULL
);
6794 if (ret
== -ENOENT
) {
6795 cerr
<< "job not found" << std::endl
;
6799 ret
= search
.finish();
6805 if (opt_cmd
== OPT_ORPHANS_LIST_JOBS
){
6806 RGWOrphanStore
orphan_store(store
);
6807 int ret
= orphan_store
.init();
6809 cerr
<< "connection to cluster failed!" << std::endl
;
6813 map
<string
,RGWOrphanSearchState
> m
;
6814 ret
= orphan_store
.list_jobs(m
);
6816 cerr
<< "job list failed" << std::endl
;
6819 formatter
->open_array_section("entries");
6820 for (const auto &it
: m
){
6822 formatter
->dump_string("job-id",it
.first
);
6824 encode_json("orphan_search_state", it
.second
, formatter
);
6827 formatter
->close_section();
6828 formatter
->flush(cout
);
6831 if (opt_cmd
== OPT_USER_CHECK
) {
6832 check_bad_user_bucket_mapping(store
, user_id
, fix
);
6835 if (opt_cmd
== OPT_USER_STATS
) {
6836 if (user_id
.empty()) {
6837 cerr
<< "ERROR: uid not specified" << std::endl
;
6841 string user_str
= user_id
.to_str();
6843 if (!bucket_name
.empty()) {
6844 cerr
<< "ERROR: --reset-stats does not work on buckets and "
6845 "bucket specified" << std::endl
;
6849 cerr
<< "ERROR: sync-stats includes the reset-stats functionality, "
6850 "so at most one of the two should be specified" << std::endl
;
6853 ret
= store
->cls_user_reset_stats(user_str
);
6855 cerr
<< "ERROR: could not reset user stats: " << cpp_strerror(-ret
) <<
6862 if (!bucket_name
.empty()) {
6863 int ret
= rgw_bucket_sync_user_stats(store
, tenant
, bucket_name
);
6865 cerr
<< "ERROR: could not sync bucket stats: " <<
6866 cpp_strerror(-ret
) << std::endl
;
6870 int ret
= rgw_user_sync_all_stats(store
, user_id
);
6872 cerr
<< "ERROR: could not sync user stats: " <<
6873 cpp_strerror(-ret
) << std::endl
;
6879 cls_user_header header
;
6880 int ret
= store
->cls_user_get_header(user_str
, &header
);
6882 if (ret
== -ENOENT
) { /* in case of ENOENT */
6883 cerr
<< "User has not been initialized or user does not exist" << std::endl
;
6885 cerr
<< "ERROR: can't read user: " << cpp_strerror(ret
) << std::endl
;
6890 encode_json("header", header
, formatter
);
6891 formatter
->flush(cout
);
6894 if (opt_cmd
== OPT_METADATA_GET
) {
6895 int ret
= store
->meta_mgr
->get(metadata_key
, formatter
);
6897 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6901 formatter
->flush(cout
);
6904 if (opt_cmd
== OPT_METADATA_PUT
) {
6906 int ret
= read_input(infile
, bl
);
6908 cerr
<< "ERROR: failed to read input: " << cpp_strerror(-ret
) << std::endl
;
6911 ret
= store
->meta_mgr
->put(metadata_key
, bl
, RGWMetadataHandler::RGWMetadataHandler::APPLY_ALWAYS
);
6913 cerr
<< "ERROR: can't put key: " << cpp_strerror(-ret
) << std::endl
;
6918 if (opt_cmd
== OPT_METADATA_RM
) {
6919 int ret
= store
->meta_mgr
->remove(metadata_key
);
6921 cerr
<< "ERROR: can't remove key: " << cpp_strerror(-ret
) << std::endl
;
6926 if (opt_cmd
== OPT_METADATA_LIST
|| opt_cmd
== OPT_USER_LIST
) {
6927 if (opt_cmd
== OPT_USER_LIST
) {
6928 metadata_key
= "user";
6932 int ret
= store
->meta_mgr
->list_keys_init(metadata_key
, marker
, &handle
);
6934 cerr
<< "ERROR: can't get key: " << cpp_strerror(-ret
) << std::endl
;
6941 if (max_entries_specified
) {
6942 formatter
->open_object_section("result");
6944 formatter
->open_array_section("keys");
6949 left
= (max_entries_specified
? max_entries
- count
: max
);
6950 ret
= store
->meta_mgr
->list_keys_next(handle
, left
, keys
, &truncated
);
6951 if (ret
< 0 && ret
!= -ENOENT
) {
6952 cerr
<< "ERROR: lists_keys_next(): " << cpp_strerror(-ret
) << std::endl
;
6954 } if (ret
!= -ENOENT
) {
6955 for (list
<string
>::iterator iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
6956 formatter
->dump_string("key", *iter
);
6959 formatter
->flush(cout
);
6961 } while (truncated
&& left
> 0);
6963 formatter
->close_section();
6965 if (max_entries_specified
) {
6966 encode_json("truncated", truncated
, formatter
);
6967 encode_json("count", count
, formatter
);
6969 encode_json("marker", store
->meta_mgr
->get_marker(handle
), formatter
);
6971 formatter
->close_section();
6973 formatter
->flush(cout
);
6975 store
->meta_mgr
->list_keys_complete(handle
);
6978 if (opt_cmd
== OPT_MDLOG_LIST
) {
6979 utime_t start_time
, end_time
;
6981 int ret
= parse_date_str(start_date
, start_time
);
6985 ret
= parse_date_str(end_date
, end_time
);
6989 int i
= (specified_shard_id
? shard_id
: 0);
6991 if (period_id
.empty()) {
6992 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
6996 std::cerr
<< "No --period given, using current period="
6997 << period_id
<< std::endl
;
6999 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
7001 formatter
->open_array_section("entries");
7002 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
7004 list
<cls_log_entry
> entries
;
7007 meta_log
->init_list_entries(i
, start_time
.to_real_time(), end_time
.to_real_time(), marker
, &handle
);
7010 int ret
= meta_log
->list_entries(handle
, 1000, entries
, NULL
, &truncated
);
7012 cerr
<< "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret
) << std::endl
;
7016 for (list
<cls_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
7017 cls_log_entry
& entry
= *iter
;
7018 store
->meta_mgr
->dump_log_entry(entry
, formatter
);
7020 formatter
->flush(cout
);
7021 } while (truncated
);
7023 meta_log
->complete_list_entries(handle
);
7025 if (specified_shard_id
)
7030 formatter
->close_section();
7031 formatter
->flush(cout
);
7034 if (opt_cmd
== OPT_MDLOG_STATUS
) {
7035 int i
= (specified_shard_id
? shard_id
: 0);
7037 if (period_id
.empty()) {
7038 int ret
= read_current_period_id(store
, realm_id
, realm_name
, &period_id
);
7042 std::cerr
<< "No --period given, using current period="
7043 << period_id
<< std::endl
;
7045 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
7047 formatter
->open_array_section("entries");
7049 for (; i
< g_ceph_context
->_conf
->rgw_md_log_max_shards
; i
++) {
7050 RGWMetadataLogInfo info
;
7051 meta_log
->get_info(i
, &info
);
7053 ::encode_json("info", info
, formatter
);
7055 if (specified_shard_id
)
7060 formatter
->close_section();
7061 formatter
->flush(cout
);
7064 if (opt_cmd
== OPT_MDLOG_AUTOTRIM
) {
7065 // need a full history for purging old mdlog periods
7066 store
->meta_mgr
->init_oldest_log_period();
7068 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
7069 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
7070 int ret
= http
.start();
7072 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
7076 auto num_shards
= g_conf()->rgw_md_log_max_shards
;
7077 ret
= crs
.run(create_admin_meta_log_trim_cr(dpp(), store
, &http
, num_shards
));
7079 cerr
<< "automated mdlog trim failed with " << cpp_strerror(ret
) << std::endl
;
7084 if (opt_cmd
== OPT_MDLOG_TRIM
) {
7085 utime_t start_time
, end_time
;
7087 if (!specified_shard_id
) {
7088 cerr
<< "ERROR: shard-id must be specified for trim operation" << std::endl
;
7092 int ret
= parse_date_str(start_date
, start_time
);
7096 ret
= parse_date_str(end_date
, end_time
);
7100 if (period_id
.empty()) {
7101 std::cerr
<< "missing --period argument" << std::endl
;
7104 RGWMetadataLog
*meta_log
= store
->meta_mgr
->get_log(period_id
);
7106 // trim until -ENODATA
7108 ret
= meta_log
->trim(shard_id
, start_time
.to_real_time(),
7109 end_time
.to_real_time(), start_marker
, end_marker
);
7111 if (ret
< 0 && ret
!= -ENODATA
) {
7112 cerr
<< "ERROR: meta_log->trim(): " << cpp_strerror(-ret
) << std::endl
;
7117 if (opt_cmd
== OPT_SYNC_STATUS
) {
7118 sync_status(formatter
);
7121 if (opt_cmd
== OPT_METADATA_SYNC_STATUS
) {
7122 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
7124 int ret
= sync
.init();
7126 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7130 rgw_meta_sync_status sync_status
;
7131 ret
= sync
.read_sync_status(&sync_status
);
7133 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
7137 formatter
->open_object_section("summary");
7138 encode_json("sync_status", sync_status
, formatter
);
7140 uint64_t full_total
= 0;
7141 uint64_t full_complete
= 0;
7143 for (auto marker_iter
: sync_status
.sync_markers
) {
7144 full_total
+= marker_iter
.second
.total_entries
;
7145 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
7146 full_complete
+= marker_iter
.second
.pos
;
7148 full_complete
+= marker_iter
.second
.total_entries
;
7152 formatter
->open_object_section("full_sync");
7153 encode_json("total", full_total
, formatter
);
7154 encode_json("complete", full_complete
, formatter
);
7155 formatter
->close_section();
7156 formatter
->close_section();
7158 formatter
->flush(cout
);
7162 if (opt_cmd
== OPT_METADATA_SYNC_INIT
) {
7163 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
7165 int ret
= sync
.init();
7167 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7170 ret
= sync
.init_sync_status();
7172 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
7178 if (opt_cmd
== OPT_METADATA_SYNC_RUN
) {
7179 RGWMetaSyncStatusManager
sync(store
, store
->get_async_rados());
7181 int ret
= sync
.init();
7183 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7189 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
7194 if (opt_cmd
== OPT_DATA_SYNC_STATUS
) {
7195 if (source_zone
.empty()) {
7196 cerr
<< "ERROR: source zone not specified" << std::endl
;
7199 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
, nullptr);
7201 int ret
= sync
.init();
7203 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7207 rgw_data_sync_status sync_status
;
7208 if (specified_shard_id
) {
7209 set
<string
> pending_buckets
;
7210 set
<string
> recovering_buckets
;
7211 rgw_data_sync_marker sync_marker
;
7212 ret
= sync
.read_shard_status(shard_id
, pending_buckets
, recovering_buckets
, &sync_marker
,
7213 max_entries_specified
? max_entries
: 20);
7214 if (ret
< 0 && ret
!= -ENOENT
) {
7215 cerr
<< "ERROR: sync.read_shard_status() returned ret=" << ret
<< std::endl
;
7218 formatter
->open_object_section("summary");
7219 encode_json("shard_id", shard_id
, formatter
);
7220 encode_json("marker", sync_marker
, formatter
);
7221 encode_json("pending_buckets", pending_buckets
, formatter
);
7222 encode_json("recovering_buckets", recovering_buckets
, formatter
);
7223 formatter
->close_section();
7224 formatter
->flush(cout
);
7226 ret
= sync
.read_sync_status(&sync_status
);
7227 if (ret
< 0 && ret
!= -ENOENT
) {
7228 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
7232 formatter
->open_object_section("summary");
7233 encode_json("sync_status", sync_status
, formatter
);
7235 uint64_t full_total
= 0;
7236 uint64_t full_complete
= 0;
7238 for (auto marker_iter
: sync_status
.sync_markers
) {
7239 full_total
+= marker_iter
.second
.total_entries
;
7240 if (marker_iter
.second
.state
== rgw_meta_sync_marker::SyncState::FullSync
) {
7241 full_complete
+= marker_iter
.second
.pos
;
7243 full_complete
+= marker_iter
.second
.total_entries
;
7247 formatter
->open_object_section("full_sync");
7248 encode_json("total", full_total
, formatter
);
7249 encode_json("complete", full_complete
, formatter
);
7250 formatter
->close_section();
7251 formatter
->close_section();
7253 formatter
->flush(cout
);
7257 if (opt_cmd
== OPT_DATA_SYNC_INIT
) {
7258 if (source_zone
.empty()) {
7259 cerr
<< "ERROR: source zone not specified" << std::endl
;
7263 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
, nullptr);
7265 int ret
= sync
.init();
7267 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7271 ret
= sync
.init_sync_status();
7273 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
7278 if (opt_cmd
== OPT_DATA_SYNC_RUN
) {
7279 if (source_zone
.empty()) {
7280 cerr
<< "ERROR: source zone not specified" << std::endl
;
7284 RGWSyncModuleInstanceRef sync_module
;
7285 int ret
= store
->svc
.sync_modules
->get_manager()->create_instance(g_ceph_context
, store
->svc
.zone
->get_zone().tier_type
,
7286 store
->svc
.zone
->get_zone_params().tier_config
, &sync_module
);
7288 lderr(cct
) << "ERROR: failed to init sync module instance, ret=" << ret
<< dendl
;
7292 RGWDataSyncStatusManager
sync(store
, store
->get_async_rados(), source_zone
, nullptr, sync_module
);
7296 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7302 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
7307 if (opt_cmd
== OPT_BUCKET_SYNC_INIT
) {
7308 if (source_zone
.empty()) {
7309 cerr
<< "ERROR: source zone not specified" << std::endl
;
7312 if (bucket_name
.empty()) {
7313 cerr
<< "ERROR: bucket not specified" << std::endl
;
7317 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
7321 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
7325 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7328 ret
= sync
.init_sync_status();
7330 cerr
<< "ERROR: sync.init_sync_status() returned ret=" << ret
<< std::endl
;
7335 if ((opt_cmd
== OPT_BUCKET_SYNC_DISABLE
) || (opt_cmd
== OPT_BUCKET_SYNC_ENABLE
)) {
7336 if (bucket_name
.empty()) {
7337 cerr
<< "ERROR: bucket not specified" << std::endl
;
7342 cerr
<< "could not init realm " << ": " << cpp_strerror(-ret
) << std::endl
;
7346 ret
= period
.init(g_ceph_context
, store
->svc
.sysobj
, realm_id
, realm_name
, true);
7348 cerr
<< "failed to init period " << ": " << cpp_strerror(-ret
) << std::endl
;
7352 if (!store
->svc
.zone
->is_meta_master()) {
7353 cerr
<< "failed to update bucket sync: only allowed on meta master zone " << std::endl
;
7354 cerr
<< period
.get_master_zone() << " | " << period
.get_realm() << std::endl
;
7358 rgw_obj
obj(bucket
, object
);
7359 ret
= set_bucket_sync_enabled(store
, opt_cmd
, tenant
, bucket_name
);
7364 if (opt_cmd
== OPT_BUCKET_SYNC_STATUS
) {
7365 if (bucket_name
.empty()) {
7366 cerr
<< "ERROR: bucket not specified" << std::endl
;
7369 RGWBucketInfo bucket_info
;
7371 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7375 bucket_sync_status(store
, bucket_info
, source_zone
, std::cout
);
7378 if (opt_cmd
== OPT_BUCKET_SYNC_MARKERS
) {
7379 if (source_zone
.empty()) {
7380 cerr
<< "ERROR: source zone not specified" << std::endl
;
7383 if (bucket_name
.empty()) {
7384 cerr
<< "ERROR: bucket not specified" << std::endl
;
7388 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
7392 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
7396 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7399 ret
= sync
.read_sync_status();
7401 cerr
<< "ERROR: sync.read_sync_status() returned ret=" << ret
<< std::endl
;
7405 map
<int, rgw_bucket_shard_sync_info
>& sync_status
= sync
.get_sync_status();
7407 encode_json("sync_status", sync_status
, formatter
);
7408 formatter
->flush(cout
);
7411 if (opt_cmd
== OPT_BUCKET_SYNC_RUN
) {
7412 if (source_zone
.empty()) {
7413 cerr
<< "ERROR: source zone not specified" << std::endl
;
7416 if (bucket_name
.empty()) {
7417 cerr
<< "ERROR: bucket not specified" << std::endl
;
7421 int ret
= init_bucket_for_sync(tenant
, bucket_name
, bucket_id
, bucket
);
7425 RGWBucketSyncStatusManager
sync(store
, source_zone
, bucket
);
7429 cerr
<< "ERROR: sync.init() returned ret=" << ret
<< std::endl
;
7435 cerr
<< "ERROR: sync.run() returned ret=" << ret
<< std::endl
;
7440 if (opt_cmd
== OPT_BILOG_LIST
) {
7441 if (bucket_name
.empty()) {
7442 cerr
<< "ERROR: bucket not specified" << std::endl
;
7445 RGWBucketInfo bucket_info
;
7446 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7448 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7451 formatter
->open_array_section("entries");
7454 if (max_entries
< 0)
7458 list
<rgw_bi_log_entry
> entries
;
7459 ret
= store
->list_bi_log_entries(bucket_info
, shard_id
, marker
, max_entries
- count
, entries
, &truncated
);
7461 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
7465 count
+= entries
.size();
7467 for (list
<rgw_bi_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
7468 rgw_bi_log_entry
& entry
= *iter
;
7469 encode_json("entry", entry
, formatter
);
7473 formatter
->flush(cout
);
7474 } while (truncated
&& count
< max_entries
);
7476 formatter
->close_section();
7477 formatter
->flush(cout
);
7480 if (opt_cmd
== OPT_SYNC_ERROR_LIST
) {
7481 if (max_entries
< 0) {
7486 utime_t start_time
, end_time
;
7488 int ret
= parse_date_str(start_date
, start_time
);
7492 ret
= parse_date_str(end_date
, end_time
);
7500 formatter
->open_array_section("entries");
7502 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
7503 formatter
->open_object_section("shard");
7504 encode_json("shard_id", shard_id
, formatter
);
7505 formatter
->open_array_section("entries");
7508 string oid
= RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX
, shard_id
);
7511 list
<cls_log_entry
> entries
;
7512 ret
= store
->time_log_list(oid
, start_time
.to_real_time(), end_time
.to_real_time(),
7513 max_entries
- count
, entries
, marker
, &marker
, &truncated
);
7514 if (ret
== -ENOENT
) {
7518 cerr
<< "ERROR: store->time_log_list(): " << cpp_strerror(-ret
) << std::endl
;
7522 count
+= entries
.size();
7524 for (auto& cls_entry
: entries
) {
7525 rgw_sync_error_info log_entry
;
7527 auto iter
= cls_entry
.data
.cbegin();
7529 decode(log_entry
, iter
);
7530 } catch (buffer::error
& err
) {
7531 cerr
<< "ERROR: failed to decode log entry" << std::endl
;
7534 formatter
->open_object_section("entry");
7535 encode_json("id", cls_entry
.id
, formatter
);
7536 encode_json("section", cls_entry
.section
, formatter
);
7537 encode_json("name", cls_entry
.name
, formatter
);
7538 encode_json("timestamp", cls_entry
.timestamp
, formatter
);
7539 encode_json("info", log_entry
, formatter
);
7540 formatter
->close_section();
7541 formatter
->flush(cout
);
7543 } while (truncated
&& count
< max_entries
);
7545 formatter
->close_section();
7546 formatter
->close_section();
7548 if (specified_shard_id
) {
7553 formatter
->close_section();
7554 formatter
->flush(cout
);
7557 if (opt_cmd
== OPT_SYNC_ERROR_TRIM
) {
7558 utime_t start_time
, end_time
;
7559 int ret
= parse_date_str(start_date
, start_time
);
7563 ret
= parse_date_str(end_date
, end_time
);
7571 for (; shard_id
< ERROR_LOGGER_SHARDS
; ++shard_id
) {
7572 ret
= trim_sync_error_log(shard_id
, start_time
.to_real_time(),
7573 end_time
.to_real_time(), start_marker
,
7574 end_marker
, trim_delay_ms
);
7576 cerr
<< "ERROR: sync error trim: " << cpp_strerror(-ret
) << std::endl
;
7579 if (specified_shard_id
) {
7585 if (opt_cmd
== OPT_BILOG_TRIM
) {
7586 if (bucket_name
.empty()) {
7587 cerr
<< "ERROR: bucket not specified" << std::endl
;
7590 RGWBucketInfo bucket_info
;
7591 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7593 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7596 ret
= store
->trim_bi_log_entries(bucket_info
, shard_id
, start_marker
, end_marker
);
7598 cerr
<< "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
7603 if (opt_cmd
== OPT_BILOG_STATUS
) {
7604 if (bucket_name
.empty()) {
7605 cerr
<< "ERROR: bucket not specified" << std::endl
;
7608 RGWBucketInfo bucket_info
;
7609 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
7611 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
7614 map
<int, string
> markers
;
7615 ret
= store
->get_bi_log_status(bucket_info
, shard_id
, markers
);
7617 cerr
<< "ERROR: get_bi_log_status(): " << cpp_strerror(-ret
) << std::endl
;
7620 formatter
->open_object_section("entries");
7621 encode_json("markers", markers
, formatter
);
7622 formatter
->close_section();
7623 formatter
->flush(cout
);
7626 if (opt_cmd
== OPT_BILOG_AUTOTRIM
) {
7627 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
7628 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
7629 int ret
= http
.start();
7631 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
7635 rgw::BucketTrimConfig config
;
7636 configure_bucket_trim(store
->ctx(), config
);
7638 rgw::BucketTrimManager
trim(store
, config
);
7641 cerr
<< "trim manager init failed with " << cpp_strerror(ret
) << std::endl
;
7644 ret
= crs
.run(trim
.create_admin_bucket_trim_cr(&http
));
7646 cerr
<< "automated bilog trim failed with " << cpp_strerror(ret
) << std::endl
;
7651 if (opt_cmd
== OPT_DATALOG_LIST
) {
7652 formatter
->open_array_section("entries");
7655 if (max_entries
< 0)
7658 utime_t start_time
, end_time
;
7660 int ret
= parse_date_str(start_date
, start_time
);
7664 ret
= parse_date_str(end_date
, end_time
);
7668 RGWDataChangesLog
*log
= store
->data_log
;
7669 RGWDataChangesLog::LogMarker log_marker
;
7672 list
<rgw_data_change_log_entry
> entries
;
7673 if (specified_shard_id
) {
7674 ret
= log
->list_entries(shard_id
, start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, marker
, NULL
, &truncated
);
7676 ret
= log
->list_entries(start_time
.to_real_time(), end_time
.to_real_time(), max_entries
- count
, entries
, log_marker
, &truncated
);
7679 cerr
<< "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret
) << std::endl
;
7683 count
+= entries
.size();
7685 for (list
<rgw_data_change_log_entry
>::iterator iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
7686 rgw_data_change_log_entry
& entry
= *iter
;
7688 encode_json("entry", entry
.entry
, formatter
);
7690 encode_json("entry", entry
, formatter
);
7693 formatter
->flush(cout
);
7694 } while (truncated
&& count
< max_entries
);
7696 formatter
->close_section();
7697 formatter
->flush(cout
);
7700 if (opt_cmd
== OPT_DATALOG_STATUS
) {
7701 RGWDataChangesLog
*log
= store
->data_log
;
7702 int i
= (specified_shard_id
? shard_id
: 0);
7704 formatter
->open_array_section("entries");
7705 for (; i
< g_ceph_context
->_conf
->rgw_data_log_num_shards
; i
++) {
7706 list
<cls_log_entry
> entries
;
7708 RGWDataChangesLogInfo info
;
7709 log
->get_info(i
, &info
);
7711 ::encode_json("info", info
, formatter
);
7713 if (specified_shard_id
)
7717 formatter
->close_section();
7718 formatter
->flush(cout
);
7721 if (opt_cmd
== OPT_DATALOG_AUTOTRIM
) {
7722 RGWCoroutinesManager
crs(store
->ctx(), store
->get_cr_registry());
7723 RGWHTTPManager
http(store
->ctx(), crs
.get_completion_mgr());
7724 int ret
= http
.start();
7726 cerr
<< "failed to initialize http client with " << cpp_strerror(ret
) << std::endl
;
7730 auto num_shards
= g_conf()->rgw_data_log_num_shards
;
7731 std::vector
<std::string
> markers(num_shards
);
7732 ret
= crs
.run(create_admin_data_log_trim_cr(store
, &http
, num_shards
, markers
));
7734 cerr
<< "automated datalog trim failed with " << cpp_strerror(ret
) << std::endl
;
7739 if (opt_cmd
== OPT_DATALOG_TRIM
) {
7740 utime_t start_time
, end_time
;
7742 int ret
= parse_date_str(start_date
, start_time
);
7746 ret
= parse_date_str(end_date
, end_time
);
7750 if (!specified_shard_id
) {
7751 cerr
<< "ERROR: requires a --shard-id" << std::endl
;
7755 // loop until -ENODATA
7757 auto datalog
= store
->data_log
;
7758 ret
= datalog
->trim_entries(shard_id
, start_time
.to_real_time(),
7759 end_time
.to_real_time(),
7760 start_marker
, end_marker
);
7763 if (ret
< 0 && ret
!= -ENODATA
) {
7764 cerr
<< "ERROR: trim_entries(): " << cpp_strerror(-ret
) << std::endl
;
7769 bool quota_op
= (opt_cmd
== OPT_QUOTA_SET
|| opt_cmd
== OPT_QUOTA_ENABLE
|| opt_cmd
== OPT_QUOTA_DISABLE
);
7772 if (bucket_name
.empty() && user_id
.empty()) {
7773 cerr
<< "ERROR: bucket name or uid is required for quota operation" << std::endl
;
7777 if (!bucket_name
.empty()) {
7778 if (!quota_scope
.empty() && quota_scope
!= "bucket") {
7779 cerr
<< "ERROR: invalid quota scope specification." << std::endl
;
7782 set_bucket_quota(store
, opt_cmd
, tenant
, bucket_name
,
7783 max_size
, max_objects
, have_max_size
, have_max_objects
);
7784 } else if (!user_id
.empty()) {
7785 if (quota_scope
== "bucket") {
7786 return set_user_bucket_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7787 } else if (quota_scope
== "user") {
7788 return set_user_quota(opt_cmd
, user
, user_op
, max_size
, max_objects
, have_max_size
, have_max_objects
);
7790 cerr
<< "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl
;
7796 if (opt_cmd
== OPT_MFA_CREATE
) {
7797 rados::cls::otp::otp_info_t config
;
7799 if (user_id
.empty()) {
7800 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
7804 if (totp_serial
.empty()) {
7805 cerr
<< "ERROR: TOTP device serial number was not provided (via --totp-serial)" << std::endl
;
7809 if (totp_seed
.empty()) {
7810 cerr
<< "ERROR: TOTP device seed was not provided (via --totp-seed)" << std::endl
;
7815 rados::cls::otp::SeedType seed_type
;
7816 if (totp_seed_type
== "hex") {
7817 seed_type
= rados::cls::otp::OTP_SEED_HEX
;
7818 } else if (totp_seed_type
== "base32") {
7819 seed_type
= rados::cls::otp::OTP_SEED_BASE32
;
7821 cerr
<< "ERROR: invalid seed type: " << totp_seed_type
<< std::endl
;
7825 config
.id
= totp_serial
;
7826 config
.seed
= totp_seed
;
7827 config
.seed_type
= seed_type
;
7829 if (totp_seconds
> 0) {
7830 config
.step_size
= totp_seconds
;
7833 if (totp_window
> 0) {
7834 config
.window
= totp_window
;
7837 real_time mtime
= real_clock::now();
7838 string oid
= store
->get_mfa_oid(user_id
);
7840 int ret
= store
->meta_mgr
->mutate(rgw_otp_get_handler(), oid
, mtime
, &objv_tracker
,
7841 MDLOG_STATUS_WRITE
, RGWMetadataHandler::APPLY_ALWAYS
,
7843 return store
->create_mfa(user_id
, config
, &objv_tracker
, mtime
);
7846 cerr
<< "MFA creation failed, error: " << cpp_strerror(-ret
) << std::endl
;
7850 RGWUserInfo
& user_info
= user_op
.get_user_info();
7851 user_info
.mfa_ids
.insert(totp_serial
);
7852 user_op
.set_mfa_ids(user_info
.mfa_ids
);
7854 ret
= user
.modify(user_op
, &err
);
7856 cerr
<< "ERROR: failed storing user info, error: " << err
<< std::endl
;
7861 if (opt_cmd
== OPT_MFA_REMOVE
) {
7862 if (user_id
.empty()) {
7863 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
7867 if (totp_serial
.empty()) {
7868 cerr
<< "ERROR: TOTP device serial number was not provided (via --totp-serial)" << std::endl
;
7872 real_time mtime
= real_clock::now();
7873 string oid
= store
->get_mfa_oid(user_id
);
7875 int ret
= store
->meta_mgr
->mutate(rgw_otp_get_handler(), oid
, mtime
, &objv_tracker
,
7876 MDLOG_STATUS_WRITE
, RGWMetadataHandler::APPLY_ALWAYS
,
7878 return store
->remove_mfa(user_id
, totp_serial
, &objv_tracker
, mtime
);
7881 cerr
<< "MFA removal failed, error: " << cpp_strerror(-ret
) << std::endl
;
7885 RGWUserInfo
& user_info
= user_op
.get_user_info();
7886 user_info
.mfa_ids
.erase(totp_serial
);
7887 user_op
.set_mfa_ids(user_info
.mfa_ids
);
7889 ret
= user
.modify(user_op
, &err
);
7891 cerr
<< "ERROR: failed storing user info, error: " << err
<< std::endl
;
7896 if (opt_cmd
== OPT_MFA_GET
) {
7897 if (user_id
.empty()) {
7898 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
7902 if (totp_serial
.empty()) {
7903 cerr
<< "ERROR: TOTP device serial number was not provided (via --totp-serial)" << std::endl
;
7907 rados::cls::otp::otp_info_t result
;
7908 int ret
= store
->get_mfa(user_id
, totp_serial
, &result
);
7910 if (ret
== -ENOENT
|| ret
== -ENODATA
) {
7911 cerr
<< "MFA serial id not found" << std::endl
;
7913 cerr
<< "MFA retrieval failed, error: " << cpp_strerror(-ret
) << std::endl
;
7917 formatter
->open_object_section("result");
7918 encode_json("entry", result
, formatter
);
7919 formatter
->close_section();
7920 formatter
->flush(cout
);
7923 if (opt_cmd
== OPT_MFA_LIST
) {
7924 if (user_id
.empty()) {
7925 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
7929 list
<rados::cls::otp::otp_info_t
> result
;
7930 int ret
= store
->list_mfa(user_id
, &result
);
7932 cerr
<< "MFA listing failed, error: " << cpp_strerror(-ret
) << std::endl
;
7935 formatter
->open_object_section("result");
7936 encode_json("entries", result
, formatter
);
7937 formatter
->close_section();
7938 formatter
->flush(cout
);
7941 if (opt_cmd
== OPT_MFA_CHECK
) {
7942 if (user_id
.empty()) {
7943 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
7947 if (totp_serial
.empty()) {
7948 cerr
<< "ERROR: TOTP device serial number was not provided (via --totp-serial)" << std::endl
;
7952 if (totp_pin
.empty()) {
7953 cerr
<< "ERROR: TOTP device serial number was not provided (via --totp-pin)" << std::endl
;
7957 list
<rados::cls::otp::otp_info_t
> result
;
7958 int ret
= store
->check_mfa(user_id
, totp_serial
, totp_pin
.front());
7960 cerr
<< "MFA check failed, error: " << cpp_strerror(-ret
) << std::endl
;
7964 cout
<< "ok" << std::endl
;
7967 if (opt_cmd
== OPT_MFA_RESYNC
) {
7968 if (user_id
.empty()) {
7969 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
7973 if (totp_serial
.empty()) {
7974 cerr
<< "ERROR: TOTP device serial number was not provided (via --totp-serial)" << std::endl
;
7978 if (totp_pin
.size() != 2) {
7979 cerr
<< "ERROR: missing two --totp-pin params (--totp-pin=<first> --totp-pin=<second>)" << std::endl
;
7982 rados::cls::otp::otp_info_t config
;
7983 int ret
= store
->get_mfa(user_id
, totp_serial
, &config
);
7985 if (ret
== -ENOENT
|| ret
== -ENODATA
) {
7986 cerr
<< "MFA serial id not found" << std::endl
;
7988 cerr
<< "MFA retrieval failed, error: " << cpp_strerror(-ret
) << std::endl
;
7993 ceph::real_time now
;
7995 ret
= store
->otp_get_current_time(user_id
, &now
);
7997 cerr
<< "ERROR: failed to fetch current time from osd: " << cpp_strerror(-ret
) << std::endl
;
8002 ret
= scan_totp(store
->ctx(), now
, config
, totp_pin
, &time_ofs
);
8004 if (ret
== -ENOENT
) {
8005 cerr
<< "failed to resync, TOTP values not found in range" << std::endl
;
8007 cerr
<< "ERROR: failed to scan for TOTP values: " << cpp_strerror(-ret
) << std::endl
;
8012 config
.time_ofs
= time_ofs
;
8014 /* now update the backend */
8015 real_time mtime
= real_clock::now();
8016 string oid
= store
->get_mfa_oid(user_id
);
8018 ret
= store
->meta_mgr
->mutate(rgw_otp_get_handler(), oid
, mtime
, &objv_tracker
,
8019 MDLOG_STATUS_WRITE
, RGWMetadataHandler::APPLY_ALWAYS
,
8021 return store
->create_mfa(user_id
, config
, &objv_tracker
, mtime
);
8024 cerr
<< "MFA update failed, error: " << cpp_strerror(-ret
) << std::endl
;
8030 if (opt_cmd
== OPT_RESHARD_STALE_INSTANCES_LIST
) {
8031 if (!store
->svc
.zone
->can_reshard() && !yes_i_really_mean_it
) {
8032 cerr
<< "Resharding disabled in a multisite env, stale instances unlikely from resharding" << std::endl
;
8033 cerr
<< "These instances may not be safe to delete." << std::endl
;
8034 cerr
<< "Use --yes-i-really-mean-it to force displaying these instances." << std::endl
;
8038 ret
= RGWBucketAdminOp::list_stale_instances(store
, bucket_op
,f
);
8040 cerr
<< "ERROR: listing stale instances" << cpp_strerror(-ret
) << std::endl
;
8044 if (opt_cmd
== OPT_RESHARD_STALE_INSTANCES_DELETE
) {
8045 if (!store
->svc
.zone
->can_reshard()) {
8046 cerr
<< "Resharding disabled in a multisite env. Stale instances are not safe to be deleted." << std::endl
;
8050 ret
= RGWBucketAdminOp::clear_stale_instances(store
, bucket_op
,f
);
8052 cerr
<< "ERROR: deleting stale instances" << cpp_strerror(-ret
) << std::endl
;
8056 if (opt_cmd
== OPT_PUBSUB_TOPICS_LIST
) {
8057 if (get_tier_type(store
) != "pubsub") {
8058 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8061 if (user_id
.empty()) {
8062 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8065 RGWUserInfo
& user_info
= user_op
.get_user_info();
8067 RGWUserPubSub
ups(store
, user_info
.user_id
);
8071 if (!bucket_name
.empty()) {
8072 rgw_pubsub_bucket_topics result
;
8073 RGWBucketInfo bucket_info
;
8074 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
8076 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
8080 auto b
= ups
.get_bucket(bucket_info
.bucket
);
8081 ret
= b
->get_topics(&result
);
8083 cerr
<< "ERROR: could not get topics: " << cpp_strerror(-ret
) << std::endl
;
8086 encode_json("result", result
, formatter
);
8088 rgw_pubsub_user_topics result
;
8089 int ret
= ups
.get_user_topics(&result
);
8091 cerr
<< "ERROR: could not get topics: " << cpp_strerror(-ret
) << std::endl
;
8094 encode_json("result", result
, formatter
);
8096 formatter
->flush(cout
);
8099 if (opt_cmd
== OPT_PUBSUB_TOPIC_CREATE
) {
8100 if (get_tier_type(store
) != "pubsub") {
8101 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8104 if (topic_name
.empty()) {
8105 cerr
<< "ERROR: topic name was not provided (via --topic)" << std::endl
;
8108 if (user_id
.empty()) {
8109 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8112 RGWUserInfo
& user_info
= user_op
.get_user_info();
8113 RGWUserPubSub
ups(store
, user_info
.user_id
);
8115 ret
= ups
.create_topic(topic_name
);
8117 cerr
<< "ERROR: could not create topic: " << cpp_strerror(-ret
) << std::endl
;
8122 if (opt_cmd
== OPT_PUBSUB_TOPIC_GET
) {
8123 if (get_tier_type(store
) != "pubsub") {
8124 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8127 if (topic_name
.empty()) {
8128 cerr
<< "ERROR: topic name was not provided (via --topic)" << std::endl
;
8131 if (user_id
.empty()) {
8132 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8135 RGWUserInfo
& user_info
= user_op
.get_user_info();
8136 RGWUserPubSub
ups(store
, user_info
.user_id
);
8138 rgw_pubsub_topic_subs topic
;
8139 ret
= ups
.get_topic(topic_name
, &topic
);
8141 cerr
<< "ERROR: could not create topic: " << cpp_strerror(-ret
) << std::endl
;
8144 encode_json("topic", topic
, formatter
);
8145 formatter
->flush(cout
);
8148 if (opt_cmd
== OPT_PUBSUB_NOTIFICATION_CREATE
) {
8149 if (get_tier_type(store
) != "pubsub") {
8150 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8153 if (topic_name
.empty()) {
8154 cerr
<< "ERROR: topic name was not provided (via --topic)" << std::endl
;
8157 if (user_id
.empty()) {
8158 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8161 if (bucket_name
.empty()) {
8162 cerr
<< "ERROR: bucket name was not provided (via --bucket)" << std::endl
;
8165 RGWUserInfo
& user_info
= user_op
.get_user_info();
8166 RGWUserPubSub
ups(store
, user_info
.user_id
);
8170 RGWBucketInfo bucket_info
;
8171 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
8173 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
8177 auto b
= ups
.get_bucket(bucket_info
.bucket
);
8178 ret
= b
->create_notification(topic_name
, event_types
);
8180 cerr
<< "ERROR: could not publish bucket: " << cpp_strerror(-ret
) << std::endl
;
8185 if (opt_cmd
== OPT_PUBSUB_NOTIFICATION_RM
) {
8186 if (get_tier_type(store
) != "pubsub") {
8187 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8190 if (topic_name
.empty()) {
8191 cerr
<< "ERROR: topic name was not provided (via --topic)" << std::endl
;
8194 if (user_id
.empty()) {
8195 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8198 if (bucket_name
.empty()) {
8199 cerr
<< "ERROR: bucket name was not provided (via --bucket)" << std::endl
;
8202 RGWUserInfo
& user_info
= user_op
.get_user_info();
8203 RGWUserPubSub
ups(store
, user_info
.user_id
);
8207 RGWBucketInfo bucket_info
;
8208 int ret
= init_bucket(tenant
, bucket_name
, bucket_id
, bucket_info
, bucket
);
8210 cerr
<< "ERROR: could not init bucket: " << cpp_strerror(-ret
) << std::endl
;
8214 auto b
= ups
.get_bucket(bucket_info
.bucket
);
8215 ret
= b
->remove_notification(topic_name
);
8217 cerr
<< "ERROR: could not publish bucket: " << cpp_strerror(-ret
) << std::endl
;
8222 if (opt_cmd
== OPT_PUBSUB_TOPIC_RM
) {
8223 if (get_tier_type(store
) != "pubsub") {
8224 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8227 if (topic_name
.empty()) {
8228 cerr
<< "ERROR: topic name was not provided (via --topic)" << std::endl
;
8231 if (user_id
.empty()) {
8232 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8235 RGWUserInfo
& user_info
= user_op
.get_user_info();
8236 RGWUserPubSub
ups(store
, user_info
.user_id
);
8238 ret
= ups
.remove_topic(topic_name
);
8240 cerr
<< "ERROR: could not remove topic: " << cpp_strerror(-ret
) << std::endl
;
8245 if (opt_cmd
== OPT_PUBSUB_SUB_GET
) {
8246 if (get_tier_type(store
) != "pubsub") {
8247 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8250 if (user_id
.empty()) {
8251 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8254 if (sub_name
.empty()) {
8255 cerr
<< "ERROR: subscription name was not provided (via --sub-name)" << std::endl
;
8258 RGWUserInfo
& user_info
= user_op
.get_user_info();
8259 RGWUserPubSub
ups(store
, user_info
.user_id
);
8261 rgw_pubsub_sub_config sub_conf
;
8263 auto sub
= ups
.get_sub(sub_name
);
8264 ret
= sub
->get_conf(&sub_conf
);
8266 cerr
<< "ERROR: could not get subscription info: " << cpp_strerror(-ret
) << std::endl
;
8269 encode_json("sub", sub_conf
, formatter
);
8270 formatter
->flush(cout
);
8273 if (opt_cmd
== OPT_PUBSUB_SUB_CREATE
) {
8274 if (get_tier_type(store
) != "pubsub") {
8275 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8278 if (user_id
.empty()) {
8279 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8282 if (sub_name
.empty()) {
8283 cerr
<< "ERROR: subscription name was not provided (via --sub-name)" << std::endl
;
8286 if (topic_name
.empty()) {
8287 cerr
<< "ERROR: topic name was not provided (via --topic)" << std::endl
;
8290 RGWUserInfo
& user_info
= user_op
.get_user_info();
8291 RGWUserPubSub
ups(store
, user_info
.user_id
);
8293 rgw_pubsub_topic_subs topic
;
8294 int ret
= ups
.get_topic(topic_name
, &topic
);
8296 cerr
<< "ERROR: topic not found" << std::endl
;
8300 rgw_pubsub_sub_dest dest_config
;
8301 dest_config
.bucket_name
= sub_dest_bucket
;
8302 dest_config
.oid_prefix
= sub_oid_prefix
;
8303 dest_config
.push_endpoint
= sub_push_endpoint
;
8305 auto psmodule
= static_cast<RGWPSSyncModuleInstance
*>(store
->get_sync_module().get());
8306 auto conf
= psmodule
->get_effective_conf();
8308 if (dest_config
.bucket_name
.empty()) {
8309 dest_config
.bucket_name
= string(conf
["data_bucket_prefix"]) + user_info
.user_id
.to_str() + "-" + topic
.topic
.name
;
8311 if (dest_config
.oid_prefix
.empty()) {
8312 dest_config
.oid_prefix
= conf
["data_oid_prefix"];
8314 auto sub
= ups
.get_sub(sub_name
);
8315 ret
= sub
->subscribe(topic_name
, dest_config
);
8317 cerr
<< "ERROR: could not store subscription info: " << cpp_strerror(-ret
) << std::endl
;
8322 if (opt_cmd
== OPT_PUBSUB_SUB_RM
) {
8323 if (get_tier_type(store
) != "pubsub") {
8324 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8327 if (user_id
.empty()) {
8328 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8331 if (sub_name
.empty()) {
8332 cerr
<< "ERROR: subscription name was not provided (via --sub-name)" << std::endl
;
8335 RGWUserInfo
& user_info
= user_op
.get_user_info();
8336 RGWUserPubSub
ups(store
, user_info
.user_id
);
8338 auto sub
= ups
.get_sub(sub_name
);
8339 ret
= sub
->unsubscribe(topic_name
);
8341 cerr
<< "ERROR: could not get subscription info: " << cpp_strerror(-ret
) << std::endl
;
8346 if (opt_cmd
== OPT_PUBSUB_SUB_PULL
) {
8347 if (get_tier_type(store
) != "pubsub") {
8348 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8351 if (user_id
.empty()) {
8352 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8355 if (sub_name
.empty()) {
8356 cerr
<< "ERROR: subscription name was not provided (via --sub-name)" << std::endl
;
8359 RGWUserInfo
& user_info
= user_op
.get_user_info();
8360 RGWUserPubSub
ups(store
, user_info
.user_id
);
8362 if (!max_entries_specified
) {
8363 max_entries
= RGWUserPubSub::Sub::DEFAULT_MAX_EVENTS
;
8365 auto sub
= ups
.get_sub(sub_name
);
8366 ret
= sub
->list_events(marker
, max_entries
);
8368 cerr
<< "ERROR: could not list events: " << cpp_strerror(-ret
) << std::endl
;
8371 encode_json("result", *sub
, formatter
);
8372 formatter
->flush(cout
);
8375 if (opt_cmd
== OPT_PUBSUB_EVENT_RM
) {
8376 if (get_tier_type(store
) != "pubsub") {
8377 cerr
<< "ERROR: only pubsub tier type supports this command" << std::endl
;
8380 if (user_id
.empty()) {
8381 cerr
<< "ERROR: user id was not provided (via --uid)" << std::endl
;
8384 if (sub_name
.empty()) {
8385 cerr
<< "ERROR: subscription name was not provided (via --sub-name)" << std::endl
;
8388 if (event_id
.empty()) {
8389 cerr
<< "ERROR: event id was not provided (via --event-id)" << std::endl
;
8392 RGWUserInfo
& user_info
= user_op
.get_user_info();
8393 RGWUserPubSub
ups(store
, user_info
.user_id
);
8395 auto sub
= ups
.get_sub(sub_name
);
8396 ret
= sub
->remove_event(event_id
);
8398 cerr
<< "ERROR: could not remove event: " << cpp_strerror(-ret
) << std::endl
;