-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
rgw_admin.cc
5812 lines (5208 loc) · 180 KB
/
rgw_admin.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include <errno.h>
#include <iostream>
#include <sstream>
#include <string>
#include "auth/Crypto.h"
#include "common/armor.h"
#include "common/ceph_json.h"
#include "common/config.h"
#include "common/ceph_argparse.h"
#include "common/Formatter.h"
#include "common/errno.h"
#include "common/safe_io.h"
#include "global/global_init.h"
#include "include/utime.h"
#include "include/str_list.h"
#include "rgw_user.h"
#include "rgw_bucket.h"
#include "rgw_rados.h"
#include "rgw_acl.h"
#include "rgw_acl_s3.h"
#include "rgw_lc.h"
#include "rgw_log.h"
#include "rgw_formats.h"
#include "rgw_usage.h"
#include "rgw_replica_log.h"
#include "rgw_orphan.h"
#include "rgw_sync.h"
#include "rgw_data_sync.h"
#include "rgw_rest_conn.h"
#include "rgw_realm_watcher.h"
using namespace std;
#define dout_subsys ceph_subsys_rgw
#define SECRET_KEY_LEN 40
#define PUBLIC_ID_LEN 20
static RGWRados *store = NULL;
void _usage()
{
cout << "usage: radosgw-admin <cmd> [options...]" << std::endl;
cout << "commands:\n";
cout << " user create create a new user\n" ;
cout << " user modify modify user\n";
cout << " user info get user info\n";
cout << " user rm remove user\n";
cout << " user suspend suspend a user\n";
cout << " user enable re-enable user after suspension\n";
cout << " user check check user info\n";
cout << " user stats show user stats as accounted by quota subsystem\n";
cout << " user list list users\n";
cout << " caps add add user capabilities\n";
cout << " caps rm remove user capabilities\n";
cout << " subuser create create a new subuser\n" ;
cout << " subuser modify modify subuser\n";
cout << " subuser rm remove subuser\n";
cout << " key create create access key\n";
cout << " key rm remove access key\n";
cout << " bucket list list buckets\n";
cout << " bucket link link bucket to specified user\n";
cout << " bucket unlink unlink bucket from specified user\n";
cout << " bucket stats returns bucket statistics\n";
cout << " bucket rm remove bucket\n";
cout << " bucket check check bucket index\n";
cout << " object rm remove object\n";
cout << " object unlink unlink object from bucket index\n";
cout << " objects expire run expired objects cleanup\n";
cout << " period prepare prepare a new period\n";
cout << " period delete delete a period\n";
cout << " period get get period info\n";
cout << " period get-current get current period info\n";
cout << " period pull pull a period\n";
cout << " period push push a period\n";
cout << " period list list all periods\n";
cout << " period update update the staging period\n";
cout << " period commit commit the staging period\n";
cout << " quota set set quota params\n";
cout << " quota enable enable quota\n";
cout << " quota disable disable quota\n";
cout << " realm create create a new realm\n";
cout << " realm delete delete a realm\n";
cout << " realm get show realm info\n";
cout << " realm get-default get default realm name\n";
cout << " realm list list realms\n";
cout << " realm list-periods list all realm periods\n";
cout << " realm remove remove a zonegroup from the realm\n";
cout << " realm rename rename a realm\n";
cout << " realm set set realm info (requires infile)\n";
cout << " realm default set realm as default\n";
cout << " realm pull pull a realm and its current period\n";
cout << " zonegroup add add a zone to a zonegroup\n";
cout << " zonegroup create create a new zone group info\n";
cout << " zonegroup default set default zone group\n";
cout << " zonegroup delete delete a zone group info\n";
cout << " zonegroup get show zone group info\n";
cout << " zonegroup modify modify an existing zonegroup\n";
cout << " zonegroup set set zone group info (requires infile)\n";
cout << " zonegroup remove remove a zone from a zonegroup\n";
cout << " zonegroup rename rename a zone group\n";
cout << " zonegroup list list all zone groups set on this cluster\n";
cout << " zonegroup-map get show zonegroup-map\n";
cout << " zonegroup-map set set zonegroup-map (requires infile)\n";
cout << " zone create create a new zone\n";
cout << " zone delete delete a zone\n";
cout << " zone get show zone cluster params\n";
cout << " zone modify modify an existing zone\n";
cout << " zone set set zone cluster params (requires infile)\n";
cout << " zone list list all zones set on this cluster\n";
cout << " zone rename rename a zone\n";
cout << " pool add add an existing pool for data placement\n";
cout << " pool rm remove an existing pool from data placement set\n";
cout << " pools list list placement active set\n";
cout << " policy read bucket/object policy\n";
cout << " log list list log objects\n";
cout << " log show dump a log from specific object or (bucket + date\n";
cout << " + bucket-id)\n";
cout << " (NOTE: required to specify formatting of date\n";
cout << " to \"YYYY-MM-DD-hh\")\n";
cout << " log rm remove log object\n";
cout << " usage show show usage (by user, date range)\n";
cout << " usage trim trim usage (by user, date range)\n";
cout << " gc list dump expired garbage collection objects (specify\n";
cout << " --include-all to list all entries, including unexpired)\n";
cout << " gc process manually process garbage\n";
cout << " lc list list all bucket lifecycle progress\n";
cout << " lc process manually process lifecycle\n";
cout << " metadata get get metadata info\n";
cout << " metadata put put metadata info\n";
cout << " metadata rm remove metadata info\n";
cout << " metadata list list metadata info\n";
cout << " mdlog list list metadata log\n";
cout << " mdlog trim trim metadata log (use start-date, end-date or\n";
cout << " start-marker, end-marker)\n";
cout << " mdlog status read metadata log status\n";
cout << " bilog list list bucket index log\n";
cout << " bilog trim trim bucket index log (use start-marker, end-marker)\n";
cout << " datalog list list data log\n";
cout << " datalog trim trim data log\n";
cout << " datalog status read data log status\n";
cout << " opstate list list stateful operations entries (use client_id,\n";
cout << " op_id, object)\n";
cout << " opstate set set state on an entry (use client_id, op_id, object, state)\n";
cout << " opstate renew renew state on an entry (use client_id, op_id, object)\n";
cout << " opstate rm remove entry (use client_id, op_id, object)\n";
cout << " replicalog get get replica metadata log entry\n";
cout << " replicalog update update replica metadata log entry\n";
cout << " replicalog delete delete replica metadata log entry\n";
cout << " orphans find init and run search for leaked rados objects (use job-id, pool)\n";
cout << " orphans finish clean up search for leaked rados objects\n";
cout << " orphans list-jobs list the current job-ids for orphans search\n";
cout << "options:\n";
cout << " --tenant=<tenant> tenant name\n";
cout << " --uid=<id> user id\n";
cout << " --subuser=<name> subuser name\n";
cout << " --access-key=<key> S3 access key\n";
cout << " --email=<email>\n";
cout << " --secret/--secret-key=<key>\n";
cout << " specify secret key\n";
cout << " --gen-access-key generate random access key (for S3)\n";
cout << " --gen-secret generate random secret key\n";
cout << " --key-type=<type> key type, options are: swift, s3\n";
cout << " --temp-url-key[-2]=<key> temp url key\n";
cout << " --access=<access> Set access permissions for sub-user, should be one\n";
cout << " of read, write, readwrite, full\n";
cout << " --display-name=<name>\n";
cout << " --max_buckets max number of buckets for a user\n";
cout << " --admin set the admin flag on the user\n";
cout << " --system set the system flag on the user\n";
cout << " --bucket=<bucket>\n";
cout << " --pool=<pool>\n";
cout << " --object=<object>\n";
cout << " --date=<date>\n";
cout << " --start-date=<date>\n";
cout << " --end-date=<date>\n";
cout << " --bucket-id=<bucket-id>\n";
cout << " --shard-id=<shard-id> optional for mdlog list\n";
cout << " required for: \n";
cout << " mdlog trim\n";
cout << " replica mdlog get/delete\n";
cout << " replica datalog get/delete\n";
cout << " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
cout << " --remote=<remote> zone or zonegroup id of remote gateway\n";
cout << " --period=<id> period id\n";
cout << " --epoch=<number> period epoch\n";
cout << " --commit commit the period during 'period update'\n";
cout << " --staging get staging period info\n";
cout << " --master set as master\n";
cout << " --master-url master url\n";
cout << " --master-zonegroup=<id> master zonegroup id\n";
cout << " --master-zone=<id> master zone id\n";
cout << " --rgw-realm=<name> realm name\n";
cout << " --realm-id=<id> realm id\n";
cout << " --realm-new-name=<name> realm new name\n";
cout << " --rgw-zonegroup=<name> zonegroup name\n";
cout << " --zonegroup-id=<id> zonegroup id\n";
cout << " --rgw-zone=<name> name of zone in which radosgw is running\n";
cout << " --zone-id=<id> zone id\n";
cout << " --zone-new-name=<name> zone new name\n";
cout << " --source-zone specify the source zone (for data sync)\n";
cout << " --default set entity (realm, zonegroup, zone) as default\n";
cout << " --read-only set zone as read-only (when adding to zonegroup)\n";
cout << " --endpoints=<list> zone endpoints\n";
cout << " --fix besides checking bucket index, will also fix it\n";
cout << " --check-objects bucket check: rebuilds bucket index according to\n";
cout << " actual objects state\n";
cout << " --format=<format> specify output format for certain operations: xml,\n";
cout << " json\n";
cout << " --purge-data when specified, user removal will also purge all the\n";
cout << " user data\n";
cout << " --purge-keys when specified, subuser removal will also purge all the\n";
cout << " subuser keys\n";
cout << " --purge-objects remove a bucket's objects before deleting it\n";
cout << " (NOTE: required to delete a non-empty bucket)\n";
cout << " --sync-stats option to 'user stats', update user stats with current\n";
cout << " stats reported by user's buckets indexes\n";
cout << " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
cout << " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
cout << " --skip-zero-entries log show only dumps entries that don't have zero value\n";
cout << " in one of the numeric field\n";
cout << " --infile=<file> specify a file to read in when setting data\n";
cout << " --state=<state string> specify a state for the opstate set command\n";
cout << " --replica-log-type replica log type (metadata, data, bucket), required for\n";
cout << " replica log operations\n";
cout << " --categories=<list> comma separated list of categories, used in usage show\n";
cout << " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\"\n";
cout << " --yes-i-really-mean-it required for certain operations\n";
cout << " --reset-regions reset regionmap when regionmap update\n";
cout << " --bypass-gc when specified with bucket deletion, triggers\n";
cout << " object deletions by not involving GC\n";
cout << " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
cout << " ignores bucket index consistency\n";
cout << "\n";
cout << "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
cout << "\nQuota options:\n";
cout << " --bucket specified bucket for quota command\n";
cout << " --max-objects specify max objects (negative value to disable)\n";
cout << " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
cout << " --quota-scope scope of quota (bucket, user)\n";
cout << "\nOrphans search options:\n";
cout << " --pool data pool to scan for leaked rados objects in\n";
cout << " --num-shards num of shards to use for keeping the temporary scan info\n";
cout << " --job-id set the job id (for orphans find)\n";
cout << " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n";
cout << "\nOrphans list-jobs options:\n";
cout << " --extra-info provide extra info in job list\n";
cout << "\n";
generic_client_usage();
}
int usage()
{
_usage();
return 1;
}
enum {
OPT_NO_CMD = 0,
OPT_USER_CREATE,
OPT_USER_INFO,
OPT_USER_MODIFY,
OPT_USER_RM,
OPT_USER_SUSPEND,
OPT_USER_ENABLE,
OPT_USER_CHECK,
OPT_USER_STATS,
OPT_USER_LIST,
OPT_SUBUSER_CREATE,
OPT_SUBUSER_MODIFY,
OPT_SUBUSER_RM,
OPT_KEY_CREATE,
OPT_KEY_RM,
OPT_BUCKETS_LIST,
OPT_BUCKET_LINK,
OPT_BUCKET_UNLINK,
OPT_BUCKET_STATS,
OPT_BUCKET_CHECK,
OPT_BUCKET_SYNC_STATUS,
OPT_BUCKET_SYNC_INIT,
OPT_BUCKET_SYNC_RUN,
OPT_BUCKET_RM,
OPT_BUCKET_REWRITE,
OPT_POLICY,
OPT_POOL_ADD,
OPT_POOL_RM,
OPT_POOLS_LIST,
OPT_LOG_LIST,
OPT_LOG_SHOW,
OPT_LOG_RM,
OPT_USAGE_SHOW,
OPT_USAGE_TRIM,
OPT_OBJECT_RM,
OPT_OBJECT_UNLINK,
OPT_OBJECT_STAT,
OPT_OBJECT_REWRITE,
OPT_OBJECTS_EXPIRE,
OPT_BI_GET,
OPT_BI_PUT,
OPT_BI_LIST,
OPT_OLH_GET,
OPT_OLH_READLOG,
OPT_QUOTA_SET,
OPT_QUOTA_ENABLE,
OPT_QUOTA_DISABLE,
OPT_GC_LIST,
OPT_GC_PROCESS,
OPT_LC_LIST,
OPT_LC_PROCESS,
OPT_ORPHANS_FIND,
OPT_ORPHANS_FINISH,
OPT_ORPHANS_LIST_JOBS,
OPT_ZONEGROUP_ADD,
OPT_ZONEGROUP_CREATE,
OPT_ZONEGROUP_DEFAULT,
OPT_ZONEGROUP_DELETE,
OPT_ZONEGROUP_GET,
OPT_ZONEGROUP_MODIFY,
OPT_ZONEGROUP_SET,
OPT_ZONEGROUP_LIST,
OPT_ZONEGROUP_REMOVE,
OPT_ZONEGROUP_RENAME,
OPT_ZONEGROUPMAP_GET,
OPT_ZONEGROUPMAP_SET,
OPT_ZONEGROUPMAP_UPDATE,
OPT_ZONE_CREATE,
OPT_ZONE_DELETE,
OPT_ZONE_GET,
OPT_ZONE_MODIFY,
OPT_ZONE_SET,
OPT_ZONE_LIST,
OPT_ZONE_RENAME,
OPT_ZONE_DEFAULT,
OPT_CAPS_ADD,
OPT_CAPS_RM,
OPT_METADATA_GET,
OPT_METADATA_PUT,
OPT_METADATA_RM,
OPT_METADATA_LIST,
OPT_METADATA_SYNC_STATUS,
OPT_METADATA_SYNC_INIT,
OPT_METADATA_SYNC_RUN,
OPT_MDLOG_LIST,
OPT_MDLOG_TRIM,
OPT_MDLOG_FETCH,
OPT_MDLOG_STATUS,
OPT_SYNC_ERROR_LIST,
OPT_BILOG_LIST,
OPT_BILOG_TRIM,
OPT_BILOG_STATUS,
OPT_DATA_SYNC_STATUS,
OPT_DATA_SYNC_INIT,
OPT_DATA_SYNC_RUN,
OPT_DATALOG_LIST,
OPT_DATALOG_STATUS,
OPT_DATALOG_TRIM,
OPT_OPSTATE_LIST,
OPT_OPSTATE_SET,
OPT_OPSTATE_RENEW,
OPT_OPSTATE_RM,
OPT_REPLICALOG_GET,
OPT_REPLICALOG_UPDATE,
OPT_REPLICALOG_DELETE,
OPT_REALM_CREATE,
OPT_REALM_DELETE,
OPT_REALM_GET,
OPT_REALM_GET_DEFAULT,
OPT_REALM_LIST,
OPT_REALM_LIST_PERIODS,
OPT_REALM_REMOVE,
OPT_REALM_RENAME,
OPT_REALM_SET,
OPT_REALM_DEFAULT,
OPT_REALM_PULL,
OPT_PERIOD_PREPARE,
OPT_PERIOD_DELETE,
OPT_PERIOD_GET,
OPT_PERIOD_GET_CURRENT,
OPT_PERIOD_PULL,
OPT_PERIOD_PUSH,
OPT_PERIOD_LIST,
OPT_PERIOD_UPDATE,
OPT_PERIOD_COMMIT,
OPT_SYNC_STATUS,
};
static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_cmd, bool *need_more)
{
*need_more = false;
// NOTE: please keep the checks in alphabetical order !!!
if (strcmp(cmd, "bi") == 0 ||
strcmp(cmd, "bilog") == 0 ||
strcmp(cmd, "bucket") == 0 ||
strcmp(cmd, "buckets") == 0 ||
strcmp(cmd, "caps") == 0 ||
strcmp(cmd, "data") == 0 ||
strcmp(cmd, "datalog") == 0 ||
strcmp(cmd, "error") == 0 ||
strcmp(cmd, "gc") == 0 ||
strcmp(cmd, "key") == 0 ||
strcmp(cmd, "log") == 0 ||
strcmp(cmd, "lc") == 0 ||
strcmp(cmd, "mdlog") == 0 ||
strcmp(cmd, "metadata") == 0 ||
strcmp(cmd, "object") == 0 ||
strcmp(cmd, "objects") == 0 ||
strcmp(cmd, "olh") == 0 ||
strcmp(cmd, "opstate") == 0 ||
strcmp(cmd, "orphans") == 0 ||
strcmp(cmd, "period") == 0 ||
strcmp(cmd, "pool") == 0 ||
strcmp(cmd, "pools") == 0 ||
strcmp(cmd, "quota") == 0 ||
strcmp(cmd, "realm") == 0 ||
strcmp(cmd, "region") == 0 ||
strcmp(cmd, "region-map") == 0 ||
strcmp(cmd, "regionmap") == 0 ||
strcmp(cmd, "replicalog") == 0 ||
strcmp(cmd, "subuser") == 0 ||
strcmp(cmd, "sync") == 0 ||
strcmp(cmd, "usage") == 0 ||
strcmp(cmd, "user") == 0 ||
strcmp(cmd, "zone") == 0 ||
strcmp(cmd, "zonegroup") == 0 ||
strcmp(cmd, "zonegroups") == 0 ||
strcmp(cmd, "zonegroup-map") == 0 ||
strcmp(cmd, "zonegroupmap") == 0 )
{
*need_more = true;
return 0;
}
if (strcmp(cmd, "policy") == 0)
return OPT_POLICY;
if (!prev_cmd)
return -EINVAL;
if (strcmp(prev_cmd, "user") == 0) {
if (strcmp(cmd, "create") == 0)
return OPT_USER_CREATE;
if (strcmp(cmd, "info") == 0)
return OPT_USER_INFO;
if (strcmp(cmd, "modify") == 0)
return OPT_USER_MODIFY;
if (strcmp(cmd, "rm") == 0)
return OPT_USER_RM;
if (strcmp(cmd, "suspend") == 0)
return OPT_USER_SUSPEND;
if (strcmp(cmd, "enable") == 0)
return OPT_USER_ENABLE;
if (strcmp(cmd, "check") == 0)
return OPT_USER_CHECK;
if (strcmp(cmd, "stats") == 0)
return OPT_USER_STATS;
if (strcmp(cmd, "list") == 0)
return OPT_USER_LIST;
} else if (strcmp(prev_cmd, "subuser") == 0) {
if (strcmp(cmd, "create") == 0)
return OPT_SUBUSER_CREATE;
if (strcmp(cmd, "modify") == 0)
return OPT_SUBUSER_MODIFY;
if (strcmp(cmd, "rm") == 0)
return OPT_SUBUSER_RM;
} else if (strcmp(prev_cmd, "key") == 0) {
if (strcmp(cmd, "create") == 0)
return OPT_KEY_CREATE;
if (strcmp(cmd, "rm") == 0)
return OPT_KEY_RM;
} else if (strcmp(prev_cmd, "buckets") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_BUCKETS_LIST;
} else if (strcmp(prev_cmd, "bucket") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_BUCKETS_LIST;
if (strcmp(cmd, "link") == 0)
return OPT_BUCKET_LINK;
if (strcmp(cmd, "unlink") == 0)
return OPT_BUCKET_UNLINK;
if (strcmp(cmd, "stats") == 0)
return OPT_BUCKET_STATS;
if (strcmp(cmd, "rm") == 0)
return OPT_BUCKET_RM;
if (strcmp(cmd, "rewrite") == 0)
return OPT_BUCKET_REWRITE;
if (strcmp(cmd, "check") == 0)
return OPT_BUCKET_CHECK;
if (strcmp(cmd, "sync") == 0) {
*need_more = true;
return 0;
}
} else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "bucket") == 0) &&
(strcmp(prev_cmd, "sync") == 0)) {
if (strcmp(cmd, "status") == 0)
return OPT_BUCKET_SYNC_STATUS;
if (strcmp(cmd, "init") == 0)
return OPT_BUCKET_SYNC_INIT;
if (strcmp(cmd, "run") == 0)
return OPT_BUCKET_SYNC_RUN;
} else if (strcmp(prev_cmd, "log") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_LOG_LIST;
if (strcmp(cmd, "show") == 0)
return OPT_LOG_SHOW;
if (strcmp(cmd, "rm") == 0)
return OPT_LOG_RM;
} else if (strcmp(prev_cmd, "usage") == 0) {
if (strcmp(cmd, "show") == 0)
return OPT_USAGE_SHOW;
if (strcmp(cmd, "trim") == 0)
return OPT_USAGE_TRIM;
} else if (strcmp(prev_cmd, "caps") == 0) {
if (strcmp(cmd, "add") == 0)
return OPT_CAPS_ADD;
if (strcmp(cmd, "rm") == 0)
return OPT_CAPS_RM;
} else if (strcmp(prev_cmd, "pool") == 0) {
if (strcmp(cmd, "add") == 0)
return OPT_POOL_ADD;
if (strcmp(cmd, "rm") == 0)
return OPT_POOL_RM;
if (strcmp(cmd, "list") == 0)
return OPT_POOLS_LIST;
} else if (strcmp(prev_cmd, "pools") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_POOLS_LIST;
} else if (strcmp(prev_cmd, "object") == 0) {
if (strcmp(cmd, "rm") == 0)
return OPT_OBJECT_RM;
if (strcmp(cmd, "unlink") == 0)
return OPT_OBJECT_UNLINK;
if (strcmp(cmd, "stat") == 0)
return OPT_OBJECT_STAT;
if (strcmp(cmd, "rewrite") == 0)
return OPT_OBJECT_REWRITE;
} else if (strcmp(prev_cmd, "objects") == 0) {
if (strcmp(cmd, "expire") == 0)
return OPT_OBJECTS_EXPIRE;
} else if (strcmp(prev_cmd, "olh") == 0) {
if (strcmp(cmd, "get") == 0)
return OPT_OLH_GET;
if (strcmp(cmd, "readlog") == 0)
return OPT_OLH_READLOG;
} else if (strcmp(prev_cmd, "bi") == 0) {
if (strcmp(cmd, "get") == 0)
return OPT_BI_GET;
if (strcmp(cmd, "put") == 0)
return OPT_BI_PUT;
if (strcmp(cmd, "list") == 0)
return OPT_BI_LIST;
} else if (strcmp(prev_cmd, "period") == 0) {
if (strcmp(cmd, "prepare") == 0)
return OPT_PERIOD_PREPARE;
if (strcmp(cmd, "delete") == 0)
return OPT_PERIOD_DELETE;
if (strcmp(cmd, "get") == 0)
return OPT_PERIOD_GET;
if (strcmp(cmd, "get-current") == 0)
return OPT_PERIOD_GET_CURRENT;
if (strcmp(cmd, "pull") == 0)
return OPT_PERIOD_PULL;
if (strcmp(cmd, "push") == 0)
return OPT_PERIOD_PUSH;
if (strcmp(cmd, "list") == 0)
return OPT_PERIOD_LIST;
if (strcmp(cmd, "update") == 0)
return OPT_PERIOD_UPDATE;
if (strcmp(cmd, "commit") == 0)
return OPT_PERIOD_COMMIT;
} else if (strcmp(prev_cmd, "realm") == 0) {
if (strcmp(cmd, "create") == 0)
return OPT_REALM_CREATE;
if (strcmp(cmd, "delete") == 0)
return OPT_REALM_DELETE;
if (strcmp(cmd, "get") == 0)
return OPT_REALM_GET;
if (strcmp(cmd, "get-default") == 0)
return OPT_REALM_GET_DEFAULT;
if (strcmp(cmd, "list") == 0)
return OPT_REALM_LIST;
if (strcmp(cmd, "list-periods") == 0)
return OPT_REALM_LIST_PERIODS;
if (strcmp(cmd, "remove") == 0)
return OPT_REALM_REMOVE;
if (strcmp(cmd, "rename") == 0)
return OPT_REALM_RENAME;
if (strcmp(cmd, "set") == 0)
return OPT_REALM_SET;
if (strcmp(cmd, "default") == 0)
return OPT_REALM_DEFAULT;
if (strcmp(cmd, "pull") == 0)
return OPT_REALM_PULL;
} else if (strcmp(prev_cmd, "zonegroup") == 0 ||
strcmp(prev_cmd, "region") == 0) {
if (strcmp(cmd, "add") == 0)
return OPT_ZONEGROUP_ADD;
if (strcmp(cmd, "create")== 0)
return OPT_ZONEGROUP_CREATE;
if (strcmp(cmd, "default") == 0)
return OPT_ZONEGROUP_DEFAULT;
if (strcmp(cmd, "delete") == 0)
return OPT_ZONEGROUP_DELETE;
if (strcmp(cmd, "get") == 0)
return OPT_ZONEGROUP_GET;
if (strcmp(cmd, "modify") == 0)
return OPT_ZONEGROUP_MODIFY;
if (strcmp(cmd, "list") == 0)
return OPT_ZONEGROUP_LIST;
if (strcmp(cmd, "set") == 0)
return OPT_ZONEGROUP_SET;
if (strcmp(cmd, "remove") == 0)
return OPT_ZONEGROUP_REMOVE;
if (strcmp(cmd, "rename") == 0)
return OPT_ZONEGROUP_RENAME;
} else if (strcmp(prev_cmd, "quota") == 0) {
if (strcmp(cmd, "set") == 0)
return OPT_QUOTA_SET;
if (strcmp(cmd, "enable") == 0)
return OPT_QUOTA_ENABLE;
if (strcmp(cmd, "disable") == 0)
return OPT_QUOTA_DISABLE;
} else if (strcmp(prev_cmd, "zonegroups") == 0 ||
strcmp(prev_cmd, "regions") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_ZONEGROUP_LIST;
} else if (strcmp(prev_cmd, "zonegroup-map") == 0 ||
strcmp(prev_cmd, "zonegroupmap") == 0 ||
strcmp(prev_cmd, "region-map") == 0 ||
strcmp(prev_cmd, "regionmap") == 0) {
if (strcmp(cmd, "get") == 0)
return OPT_ZONEGROUPMAP_GET;
if (strcmp(cmd, "set") == 0)
return OPT_ZONEGROUPMAP_SET;
if (strcmp(cmd, "update") == 0)
return OPT_ZONEGROUPMAP_UPDATE;
} else if (strcmp(prev_cmd, "zone") == 0) {
if (strcmp(cmd, "delete") == 0)
return OPT_ZONE_DELETE;
if (strcmp(cmd, "create") == 0)
return OPT_ZONE_CREATE;
if (strcmp(cmd, "get") == 0)
return OPT_ZONE_GET;
if (strcmp(cmd, "set") == 0)
return OPT_ZONE_SET;
if (strcmp(cmd, "list") == 0)
return OPT_ZONE_LIST;
if (strcmp(cmd, "modify") == 0)
return OPT_ZONE_MODIFY;
if (strcmp(cmd, "rename") == 0)
return OPT_ZONE_RENAME;
if (strcmp(cmd, "default") == 0)
return OPT_ZONE_DEFAULT;
} else if (strcmp(prev_cmd, "zones") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_ZONE_LIST;
} else if (strcmp(prev_cmd, "gc") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_GC_LIST;
if (strcmp(cmd, "process") == 0)
return OPT_GC_PROCESS;
} else if (strcmp(prev_cmd, "lc") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_LC_LIST;
if (strcmp(cmd, "process") == 0)
return OPT_LC_PROCESS;
} else if (strcmp(prev_cmd, "orphans") == 0) {
if (strcmp(cmd, "find") == 0)
return OPT_ORPHANS_FIND;
if (strcmp(cmd, "finish") == 0)
return OPT_ORPHANS_FINISH;
if (strcmp(cmd, "list-jobs") == 0)
return OPT_ORPHANS_LIST_JOBS;
} else if (strcmp(prev_cmd, "metadata") == 0) {
if (strcmp(cmd, "get") == 0)
return OPT_METADATA_GET;
if (strcmp(cmd, "put") == 0)
return OPT_METADATA_PUT;
if (strcmp(cmd, "rm") == 0)
return OPT_METADATA_RM;
if (strcmp(cmd, "list") == 0)
return OPT_METADATA_LIST;
if (strcmp(cmd, "sync") == 0) {
*need_more = true;
return 0;
}
} else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "metadata") == 0) &&
(strcmp(prev_cmd, "sync") == 0)) {
if (strcmp(cmd, "status") == 0)
return OPT_METADATA_SYNC_STATUS;
if (strcmp(cmd, "init") == 0)
return OPT_METADATA_SYNC_INIT;
if (strcmp(cmd, "run") == 0)
return OPT_METADATA_SYNC_RUN;
} else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "sync") == 0) &&
(strcmp(prev_cmd, "error") == 0)) {
if (strcmp(cmd, "list") == 0)
return OPT_SYNC_ERROR_LIST;
} else if (strcmp(prev_cmd, "mdlog") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_MDLOG_LIST;
if (strcmp(cmd, "trim") == 0)
return OPT_MDLOG_TRIM;
if (strcmp(cmd, "fetch") == 0)
return OPT_MDLOG_FETCH;
if (strcmp(cmd, "status") == 0)
return OPT_MDLOG_STATUS;
} else if (strcmp(prev_cmd, "bilog") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_BILOG_LIST;
if (strcmp(cmd, "trim") == 0)
return OPT_BILOG_TRIM;
if (strcmp(cmd, "status") == 0)
return OPT_BILOG_STATUS;
} else if (strcmp(prev_cmd, "data") == 0) {
if (strcmp(cmd, "sync") == 0) {
*need_more = true;
return 0;
}
} else if (strcmp(prev_cmd, "datalog") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_DATALOG_LIST;
if (strcmp(cmd, "trim") == 0)
return OPT_DATALOG_TRIM;
if (strcmp(cmd, "status") == 0)
return OPT_DATALOG_STATUS;
} else if ((prev_prev_cmd && strcmp(prev_prev_cmd, "data") == 0) &&
(strcmp(prev_cmd, "sync") == 0)) {
if (strcmp(cmd, "status") == 0)
return OPT_DATA_SYNC_STATUS;
if (strcmp(cmd, "init") == 0)
return OPT_DATA_SYNC_INIT;
if (strcmp(cmd, "run") == 0)
return OPT_DATA_SYNC_RUN;
} else if (strcmp(prev_cmd, "opstate") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_OPSTATE_LIST;
if (strcmp(cmd, "set") == 0)
return OPT_OPSTATE_SET;
if (strcmp(cmd, "renew") == 0)
return OPT_OPSTATE_RENEW;
if (strcmp(cmd, "rm") == 0)
return OPT_OPSTATE_RM;
} else if (strcmp(prev_cmd, "replicalog") == 0) {
if (strcmp(cmd, "get") == 0)
return OPT_REPLICALOG_GET;
if (strcmp(cmd, "update") == 0)
return OPT_REPLICALOG_UPDATE;
if (strcmp(cmd, "delete") == 0)
return OPT_REPLICALOG_DELETE;
} else if (strcmp(prev_cmd, "sync") == 0) {
if (strcmp(cmd, "status") == 0)
return OPT_SYNC_STATUS;
}
return -EINVAL;
}
enum ReplicaLogType {
ReplicaLog_Invalid = 0,
ReplicaLog_Metadata,
ReplicaLog_Data,
ReplicaLog_Bucket,
};
ReplicaLogType get_replicalog_type(const string& name) {
if (name == "md" || name == "meta" || name == "metadata")
return ReplicaLog_Metadata;
if (name == "data")
return ReplicaLog_Data;
if (name == "bucket")
return ReplicaLog_Bucket;
return ReplicaLog_Invalid;
}
BIIndexType get_bi_index_type(const string& type_str) {
if (type_str == "plain")
return PlainIdx;
if (type_str == "instance")
return InstanceIdx;
if (type_str == "olh")
return OLHIdx;
return InvalidIdx;
}
void dump_bi_entry(bufferlist& bl, BIIndexType index_type, Formatter *formatter)
{
bufferlist::iterator iter = bl.begin();
switch (index_type) {
case PlainIdx:
case InstanceIdx:
{
rgw_bucket_dir_entry entry;
::decode(entry, iter);
encode_json("entry", entry, formatter);
}
break;
case OLHIdx:
{
rgw_bucket_olh_entry entry;
::decode(entry, iter);
encode_json("entry", entry, formatter);
}
break;
default:
assert(0);
break;
}
}
static void show_user_info(RGWUserInfo& info, Formatter *formatter)
{
encode_json("user_info", info, formatter);
formatter->flush(cout);
cout << std::endl;
}
static void dump_bucket_usage(map<RGWObjCategory, RGWStorageStats>& stats, Formatter *formatter)
{
map<RGWObjCategory, RGWStorageStats>::iterator iter;
formatter->open_object_section("usage");
for (iter = stats.begin(); iter != stats.end(); ++iter) {
RGWStorageStats& s = iter->second;
const char *cat_name = rgw_obj_category_name(iter->first);
formatter->open_object_section(cat_name);
formatter->dump_int("size", s.size);
formatter->dump_int("size_actual", s.size_rounded);
formatter->dump_int("size_kb", rgw_rounded_kb(s.size));
formatter->dump_int("size_kb_actual", rgw_rounded_kb(s.size_rounded));
formatter->dump_int("num_objects", s.num_objects);
formatter->close_section();
formatter->flush(cout);
}
formatter->close_section();
}
int bucket_stats(rgw_bucket& bucket, int shard_id, Formatter *formatter)
{
RGWBucketInfo bucket_info;
real_time mtime;
RGWObjectCtx obj_ctx(store);
int r = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, bucket_info, &mtime);
if (r < 0)
return r;
map<RGWObjCategory, RGWStorageStats> stats;
string bucket_ver, master_ver;
string max_marker;
int ret = store->get_bucket_stats(bucket, shard_id, &bucket_ver, &master_ver, stats, &max_marker);
if (ret < 0) {
cerr << "error getting bucket stats ret=" << ret << std::endl;
return ret;
}
formatter->open_object_section("stats");
formatter->dump_string("bucket", bucket.name);
formatter->dump_string("pool", bucket.data_pool);
formatter->dump_string("index_pool", bucket.index_pool);
formatter->dump_string("id", bucket.bucket_id);
formatter->dump_string("marker", bucket.marker);
::encode_json("owner", bucket_info.owner, formatter);
formatter->dump_int("mtime", utime_t(mtime));
formatter->dump_string("ver", bucket_ver);
formatter->dump_string("master_ver", master_ver);
formatter->dump_string("max_marker", max_marker);
dump_bucket_usage(stats, formatter);
formatter->close_section();
return 0;
}
class StoreDestructor {
RGWRados *store;
public:
explicit StoreDestructor(RGWRados *_s) : store(_s) {}
~StoreDestructor() {
RGWStoreManager::close_storage(store);
}
};
static int init_bucket(const string& tenant_name, const string& bucket_name, const string& bucket_id,
RGWBucketInfo& bucket_info, rgw_bucket& bucket)
{
if (!bucket_name.empty()) {
RGWObjectCtx obj_ctx(store);
int r;
if (bucket_id.empty()) {
r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL);
} else {
string bucket_instance_id = bucket_name + ":" + bucket_id;
r = store->get_bucket_instance_info(obj_ctx, bucket_instance_id, bucket_info, NULL, NULL);
}
if (r < 0) {
cerr << "could not get bucket info for bucket=" << bucket_name << std::endl;
return r;
}
bucket = bucket_info.bucket;
}
return 0;
}
static int read_input(const string& infile, bufferlist& bl)
{
int fd = 0;
if (infile.size()) {
fd = open(infile.c_str(), O_RDONLY);
if (fd < 0) {
int err = -errno;
cerr << "error reading input file " << infile << std::endl;
return err;
}
}
#define READ_CHUNK 8196
int r;
int err;
do {
char buf[READ_CHUNK];
r = safe_read(fd, buf, READ_CHUNK);
if (r < 0) {
err = -errno;
cerr << "error while reading input" << std::endl;
goto out;
}
bl.append(buf, r);
} while (r > 0);
err = 0;
out:
if (infile.size()) {
close(fd);
}
return err;
}
template <class T>
static int read_decode_json(const string& infile, T& t)
{
bufferlist bl;
int ret = read_input(infile, bl);
if (ret < 0) {
cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl;
return ret;
}
JSONParser p;
if (!p.parse(bl.c_str(), bl.length())) {
cout << "failed to parse JSON" << std::endl;
return -EINVAL;
}
try {
decode_json_obj(t, &p);
} catch (JSONDecoder::err& e) {
cout << "failed to decode JSON input: " << e.message << std::endl;
return -EINVAL;
}
return 0;
}
template <class T, class K>
static int read_decode_json(const string& infile, T& t, K *k)
{
bufferlist bl;
int ret = read_input(infile, bl);
if (ret < 0) {
cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl;
return ret;
}
JSONParser p;
if (!p.parse(bl.c_str(), bl.length())) {
cout << "failed to parse JSON" << std::endl;
return -EINVAL;
}
try {
t.decode_json(&p, k);
} catch (JSONDecoder::err& e) {
cout << "failed to decode JSON input: " << e.message << std::endl;
return -EINVAL;
}
return 0;
}
static int parse_date_str(const string& date_str, utime_t& ut)
{
uint64_t epoch = 0;
uint64_t nsec = 0;