/
osd_types.cc
5076 lines (4686 loc) · 133 KB
/
osd_types.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
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2011 New Dream Network
* Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
*
* Author: Loic Dachary <loic@dachary.org>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "osd_types.h"
#include "include/ceph_features.h"
extern "C" {
#include "crush/hash.h"
}
#include "PG.h"
#include "OSDMap.h"
#include "PGBackend.h"
const char *ceph_osd_flag_name(unsigned flag)
{
switch (flag) {
case CEPH_OSD_FLAG_ACK: return "ack";
case CEPH_OSD_FLAG_ONNVRAM: return "onnvram";
case CEPH_OSD_FLAG_ONDISK: return "ondisk";
case CEPH_OSD_FLAG_RETRY: return "retry";
case CEPH_OSD_FLAG_READ: return "read";
case CEPH_OSD_FLAG_WRITE: return "write";
case CEPH_OSD_FLAG_ORDERSNAP: return "ordersnap";
case CEPH_OSD_FLAG_PEERSTAT_OLD: return "peerstat_old";
case CEPH_OSD_FLAG_BALANCE_READS: return "balance_reads";
case CEPH_OSD_FLAG_PARALLELEXEC: return "parallelexec";
case CEPH_OSD_FLAG_PGOP: return "pgop";
case CEPH_OSD_FLAG_EXEC: return "exec";
case CEPH_OSD_FLAG_EXEC_PUBLIC: return "exec_public";
case CEPH_OSD_FLAG_LOCALIZE_READS: return "localize_reads";
case CEPH_OSD_FLAG_RWORDERED: return "rwordered";
case CEPH_OSD_FLAG_IGNORE_CACHE: return "ignore_cache";
case CEPH_OSD_FLAG_SKIPRWLOCKS: return "skiprwlocks";
case CEPH_OSD_FLAG_IGNORE_OVERLAY: return "ignore_overlay";
case CEPH_OSD_FLAG_FLUSH: return "flush";
case CEPH_OSD_FLAG_MAP_SNAP_CLONE: return "map_snap_clone";
case CEPH_OSD_FLAG_ENFORCE_SNAPC: return "enforce_snapc";
case CEPH_OSD_FLAG_REDIRECTED: return "redirected";
case CEPH_OSD_FLAG_KNOWN_REDIR: return "known_if_redirected";
default: return "???";
}
}
string ceph_osd_flag_string(unsigned flags)
{
string s;
for (unsigned i=0; i<32; ++i) {
if (flags & (1u<<i)) {
if (s.length())
s += "+";
s += ceph_osd_flag_name(1u << i);
}
}
if (s.length())
return s;
return string("-");
}
const char * ceph_osd_op_flag_name(unsigned flag)
{
const char *name;
switch(flag) {
case CEPH_OSD_OP_FLAG_EXCL:
name = "excl";
break;
case CEPH_OSD_OP_FLAG_FAILOK:
name = "failok";
break;
case CEPH_OSD_OP_FLAG_FADVISE_RANDOM:
name = "fadvise_random";
break;
case CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL:
name = "fadvise_sequential";
break;
case CEPH_OSD_OP_FLAG_FADVISE_WILLNEED:
name = "favise_willneed";
break;
case CEPH_OSD_OP_FLAG_FADVISE_DONTNEED:
name = "fadvise_dontneed";
break;
case CEPH_OSD_OP_FLAG_FADVISE_NOCACHE:
name = "fadvise_nocache";
break;
default:
name = "???";
};
return name;
}
string ceph_osd_op_flag_string(unsigned flags)
{
string s;
for (unsigned i=0; i<31; ++i) {
if (flags & (1u<<i)) {
if (s.length())
s += "+";
s += ceph_osd_op_flag_name(1u << i);
}
}
if (s.length())
return s;
return string("-");
}
void pg_shard_t::encode(bufferlist &bl) const
{
ENCODE_START(1, 1, bl);
::encode(osd, bl);
::encode(shard, bl);
ENCODE_FINISH(bl);
}
void pg_shard_t::decode(bufferlist::iterator &bl)
{
DECODE_START(1, bl);
::decode(osd, bl);
::decode(shard, bl);
DECODE_FINISH(bl);
}
ostream &operator<<(ostream &lhs, const pg_shard_t &rhs)
{
if (rhs.is_undefined())
return lhs << "?";
if (rhs.shard == shard_id_t::NO_SHARD)
return lhs << rhs.osd;
return lhs << rhs.osd << '(' << (unsigned)(rhs.shard) << ')';
}
// -- osd_reqid_t --
void osd_reqid_t::encode(bufferlist &bl) const
{
ENCODE_START(2, 2, bl);
::encode(name, bl);
::encode(tid, bl);
::encode(inc, bl);
ENCODE_FINISH(bl);
}
void osd_reqid_t::decode(bufferlist::iterator &bl)
{
DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
::decode(name, bl);
::decode(tid, bl);
::decode(inc, bl);
DECODE_FINISH(bl);
}
void osd_reqid_t::dump(Formatter *f) const
{
f->dump_stream("name") << name;
f->dump_int("inc", inc);
f->dump_unsigned("tid", tid);
}
void osd_reqid_t::generate_test_instances(list<osd_reqid_t*>& o)
{
o.push_back(new osd_reqid_t);
o.push_back(new osd_reqid_t(entity_name_t::CLIENT(123), 1, 45678));
}
// -- object_locator_t --
void object_locator_t::encode(bufferlist& bl) const
{
// verify that nobody's corrupted the locator
assert(hash == -1 || key.empty());
__u8 encode_compat = 3;
ENCODE_START(6, encode_compat, bl);
::encode(pool, bl);
int32_t preferred = -1; // tell old code there is no preferred osd (-1).
::encode(preferred, bl);
::encode(key, bl);
::encode(nspace, bl);
::encode(hash, bl);
if (hash != -1)
encode_compat = MAX(encode_compat, 6); // need to interpret the hash
ENCODE_FINISH_NEW_COMPAT(bl, encode_compat);
}
void object_locator_t::decode(bufferlist::iterator& p)
{
DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, p);
if (struct_v < 2) {
int32_t op;
::decode(op, p);
pool = op;
int16_t pref;
::decode(pref, p);
} else {
::decode(pool, p);
int32_t preferred;
::decode(preferred, p);
}
::decode(key, p);
if (struct_v >= 5)
::decode(nspace, p);
if (struct_v >= 6)
::decode(hash, p);
else
hash = -1;
DECODE_FINISH(p);
// verify that nobody's corrupted the locator
assert(hash == -1 || key.empty());
}
void object_locator_t::dump(Formatter *f) const
{
f->dump_int("pool", pool);
f->dump_string("key", key);
f->dump_string("namespace", nspace);
f->dump_int("hash", hash);
}
void object_locator_t::generate_test_instances(list<object_locator_t*>& o)
{
o.push_back(new object_locator_t);
o.push_back(new object_locator_t(123));
o.push_back(new object_locator_t(123, 876));
o.push_back(new object_locator_t(1, "n2"));
o.push_back(new object_locator_t(1234, "", "key"));
o.push_back(new object_locator_t(12, "n1", "key2"));
}
// -- request_redirect_t --
void request_redirect_t::encode(bufferlist& bl) const
{
ENCODE_START(1, 1, bl);
::encode(redirect_locator, bl);
::encode(redirect_object, bl);
::encode(osd_instructions, bl);
ENCODE_FINISH(bl);
}
void request_redirect_t::decode(bufferlist::iterator& bl)
{
DECODE_START(1, bl);
::decode(redirect_locator, bl);
::decode(redirect_object, bl);
::decode(osd_instructions, bl);
DECODE_FINISH(bl);
}
void request_redirect_t::dump(Formatter *f) const
{
f->dump_string("object", redirect_object);
f->open_object_section("locator");
redirect_locator.dump(f);
f->close_section(); // locator
}
void request_redirect_t::generate_test_instances(list<request_redirect_t*>& o)
{
object_locator_t loc(1, "redir_obj");
o.push_back(new request_redirect_t());
o.push_back(new request_redirect_t(loc, 0));
o.push_back(new request_redirect_t(loc, "redir_obj"));
o.push_back(new request_redirect_t(loc));
}
void objectstore_perf_stat_t::dump(Formatter *f) const
{
f->dump_unsigned("commit_latency_ms", filestore_commit_latency);
f->dump_unsigned("apply_latency_ms", filestore_apply_latency);
}
void objectstore_perf_stat_t::encode(bufferlist &bl) const
{
ENCODE_START(1, 1, bl);
::encode(filestore_commit_latency, bl);
::encode(filestore_apply_latency, bl);
ENCODE_FINISH(bl);
}
void objectstore_perf_stat_t::decode(bufferlist::iterator &bl)
{
DECODE_START(1, bl);
::decode(filestore_commit_latency, bl);
::decode(filestore_apply_latency, bl);
DECODE_FINISH(bl);
}
void objectstore_perf_stat_t::generate_test_instances(std::list<objectstore_perf_stat_t*>& o)
{
o.push_back(new objectstore_perf_stat_t());
o.push_back(new objectstore_perf_stat_t());
o.back()->filestore_commit_latency = 20;
o.back()->filestore_apply_latency = 30;
}
// -- osd_stat_t --
void osd_stat_t::dump(Formatter *f) const
{
f->dump_unsigned("kb", kb);
f->dump_unsigned("kb_used", kb_used);
f->dump_unsigned("kb_avail", kb_avail);
f->open_array_section("hb_in");
for (vector<int>::const_iterator p = hb_in.begin(); p != hb_in.end(); ++p)
f->dump_int("osd", *p);
f->close_section();
f->open_array_section("hb_out");
for (vector<int>::const_iterator p = hb_out.begin(); p != hb_out.end(); ++p)
f->dump_int("osd", *p);
f->close_section();
f->dump_int("snap_trim_queue_len", snap_trim_queue_len);
f->dump_int("num_snap_trimming", num_snap_trimming);
f->open_object_section("op_queue_age_hist");
op_queue_age_hist.dump(f);
f->close_section();
f->open_object_section("fs_perf_stat");
fs_perf_stat.dump(f);
f->close_section();
}
void osd_stat_t::encode(bufferlist &bl) const
{
ENCODE_START(4, 2, bl);
::encode(kb, bl);
::encode(kb_used, bl);
::encode(kb_avail, bl);
::encode(snap_trim_queue_len, bl);
::encode(num_snap_trimming, bl);
::encode(hb_in, bl);
::encode(hb_out, bl);
::encode(op_queue_age_hist, bl);
::encode(fs_perf_stat, bl);
ENCODE_FINISH(bl);
}
void osd_stat_t::decode(bufferlist::iterator &bl)
{
DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl);
::decode(kb, bl);
::decode(kb_used, bl);
::decode(kb_avail, bl);
::decode(snap_trim_queue_len, bl);
::decode(num_snap_trimming, bl);
::decode(hb_in, bl);
::decode(hb_out, bl);
if (struct_v >= 3)
::decode(op_queue_age_hist, bl);
if (struct_v >= 4)
::decode(fs_perf_stat, bl);
DECODE_FINISH(bl);
}
void osd_stat_t::generate_test_instances(std::list<osd_stat_t*>& o)
{
o.push_back(new osd_stat_t);
o.push_back(new osd_stat_t);
o.back()->kb = 1;
o.back()->kb_used = 2;
o.back()->kb_avail = 3;
o.back()->hb_in.push_back(5);
o.back()->hb_in.push_back(6);
o.back()->hb_out = o.back()->hb_in;
o.back()->hb_out.push_back(7);
o.back()->snap_trim_queue_len = 8;
o.back()->num_snap_trimming = 99;
}
// -- pg_t --
int pg_t::print(char *o, int maxlen) const
{
if (preferred() >= 0)
return snprintf(o, maxlen, "%llu.%xp%d", (unsigned long long)pool(), ps(), preferred());
else
return snprintf(o, maxlen, "%llu.%x", (unsigned long long)pool(), ps());
}
bool pg_t::parse(const char *s)
{
uint64_t ppool;
uint32_t pseed;
int32_t pref;
int r = sscanf(s, "%llu.%xp%d", (long long unsigned *)&ppool, &pseed, &pref);
if (r < 2)
return false;
m_pool = ppool;
m_seed = pseed;
if (r == 3)
m_preferred = pref;
else
m_preferred = -1;
return true;
}
bool spg_t::parse(const char *s)
{
pgid.set_preferred(-1);
shard = shard_id_t::NO_SHARD;
uint64_t ppool;
uint32_t pseed;
int32_t pref;
uint32_t pshard;
int r = sscanf(s, "%llu.%x", (long long unsigned *)&ppool, &pseed);
if (r < 2)
return false;
pgid.set_pool(ppool);
pgid.set_ps(pseed);
const char *p = strchr(s, 'p');
if (p) {
r = sscanf(p, "p%d", &pref);
if (r == 1) {
pgid.set_preferred(pref);
} else {
return false;
}
}
p = strchr(s, 's');
if (p) {
r = sscanf(p, "s%d", &pshard);
if (r == 1) {
shard = shard_id_t(pshard);
} else {
return false;
}
}
return true;
}
ostream& operator<<(ostream& out, const spg_t &pg)
{
out << pg.pgid;
if (!pg.is_no_shard())
out << "s" << (unsigned)pg.shard;
return out;
}
pg_t pg_t::get_ancestor(unsigned old_pg_num) const
{
int old_bits = pg_pool_t::calc_bits_of(old_pg_num);
int old_mask = (1 << old_bits) - 1;
pg_t ret = *this;
ret.m_seed = ceph_stable_mod(m_seed, old_pg_num, old_mask);
return ret;
}
bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t> *children) const
{
assert(m_seed < old_pg_num);
if (new_pg_num <= old_pg_num)
return false;
bool split = false;
if (true) {
int old_bits = pg_pool_t::calc_bits_of(old_pg_num);
int old_mask = (1 << old_bits) - 1;
for (int n = 1; ; n++) {
int next_bit = (n << (old_bits-1));
unsigned s = next_bit | m_seed;
if (s < old_pg_num || s == m_seed)
continue;
if (s >= new_pg_num)
break;
if ((unsigned)ceph_stable_mod(s, old_pg_num, old_mask) == m_seed) {
split = true;
if (children)
children->insert(pg_t(s, m_pool, m_preferred));
}
}
}
if (false) {
// brute force
int old_bits = pg_pool_t::calc_bits_of(old_pg_num);
int old_mask = (1 << old_bits) - 1;
for (unsigned x = old_pg_num; x < new_pg_num; ++x) {
unsigned o = ceph_stable_mod(x, old_pg_num, old_mask);
if (o == m_seed) {
split = true;
children->insert(pg_t(x, m_pool, m_preferred));
}
}
}
return split;
}
unsigned pg_t::get_split_bits(unsigned pg_num) const {
if (pg_num == 1)
return 0;
assert(pg_num > 1);
// Find unique p such that pg_num \in [2^(p-1), 2^p)
unsigned p = pg_pool_t::calc_bits_of(pg_num);
assert(p); // silence coverity #751330
if ((m_seed % (1<<(p-1))) < (pg_num % (1<<(p-1))))
return p;
else
return p - 1;
}
pg_t pg_t::get_parent() const
{
unsigned bits = pg_pool_t::calc_bits_of(m_seed);
assert(bits);
pg_t retval = *this;
retval.m_seed &= ~((~0)<<(bits - 1));
return retval;
}
void pg_t::dump(Formatter *f) const
{
f->dump_unsigned("pool", m_pool);
f->dump_unsigned("seed", m_seed);
f->dump_int("preferred_osd", m_preferred);
}
void pg_t::generate_test_instances(list<pg_t*>& o)
{
o.push_back(new pg_t);
o.push_back(new pg_t(1, 2, -1));
o.push_back(new pg_t(13123, 3, -1));
o.push_back(new pg_t(131223, 4, 23));
}
ostream& operator<<(ostream& out, const pg_t &pg)
{
out << pg.pool() << '.';
out << hex << pg.ps() << dec;
if (pg.preferred() >= 0)
out << 'p' << pg.preferred();
//out << "=" << hex << (__uint64_t)pg << dec;
return out;
}
// -- coll_t --
bool coll_t::is_temp(spg_t& pgid) const
{
const char *cstr(str.c_str());
if (!pgid.parse(cstr))
return false;
const char *tmp_start = strchr(cstr, '_');
if (!tmp_start)
return false;
if (strncmp(tmp_start, "_TEMP", 5) == 0)
return true;
return false;
}
bool coll_t::is_pg(spg_t& pgid, snapid_t& snap) const
{
const char *cstr(str.c_str());
if (!pgid.parse(cstr))
return false;
const char *snap_start = strchr(cstr, '_');
if (!snap_start)
return false;
if (strncmp(snap_start, "_head", 5) == 0) {
snap = CEPH_NOSNAP;
} else {
errno = 0;
snap = strtoull(snap_start+1, 0, 16);
if (errno)
return false;
}
return true;
}
bool coll_t::is_pg_prefix(spg_t& pgid) const
{
const char *cstr(str.c_str());
if (!pgid.parse(cstr))
return false;
const char *snap_start = strchr(cstr, '_');
if (!snap_start)
return false;
return true;
}
bool coll_t::is_removal(uint64_t *seq, spg_t *pgid) const
{
if (str.substr(0, 11) != string("FORREMOVAL_"))
return false;
stringstream ss(str.substr(11));
ss >> *seq;
char sep;
ss >> sep;
assert(sep == '_');
string pgid_str;
ss >> pgid_str;
if (!pgid->parse(pgid_str.c_str())) {
assert(0);
return false;
}
return true;
}
void coll_t::encode(bufferlist& bl) const
{
__u8 struct_v = 3;
::encode(struct_v, bl);
::encode(str, bl);
}
void coll_t::decode(bufferlist::iterator& bl)
{
__u8 struct_v;
::decode(struct_v, bl);
switch (struct_v) {
case 1: {
spg_t pgid;
snapid_t snap;
::decode(pgid, bl);
::decode(snap, bl);
// infer the type
if (pgid == spg_t() && snap == 0)
str = "meta";
else
str = pg_and_snap_to_str(pgid, snap);
break;
}
case 2: {
__u8 type;
spg_t pgid;
snapid_t snap;
::decode(type, bl);
::decode(pgid, bl);
::decode(snap, bl);
switch (type) {
case 0:
str = "meta";
break;
case 1:
str = "temp";
break;
case 2:
str = pg_and_snap_to_str(pgid, snap);
break;
default: {
ostringstream oss;
oss << "coll_t::decode(): can't understand type " << type;
throw std::domain_error(oss.str());
}
}
break;
}
case 3:
::decode(str, bl);
break;
default: {
ostringstream oss;
oss << "coll_t::decode(): don't know how to decode version "
<< struct_v;
throw std::domain_error(oss.str());
}
}
}
void coll_t::dump(Formatter *f) const
{
f->dump_string("name", str);
}
void coll_t::generate_test_instances(list<coll_t*>& o)
{
o.push_back(new coll_t);
o.push_back(new coll_t("meta"));
o.push_back(new coll_t("temp"));
o.push_back(new coll_t("foo"));
o.push_back(new coll_t("bar"));
}
// ---
std::string pg_vector_string(const vector<int32_t> &a)
{
ostringstream oss;
oss << "[";
for (vector<int32_t>::const_iterator i = a.begin(); i != a.end(); ++i) {
if (i != a.begin())
oss << ",";
if (*i != CRUSH_ITEM_NONE)
oss << *i;
else
oss << "NONE";
}
oss << "]";
return oss.str();
}
std::string pg_state_string(int state)
{
ostringstream oss;
if (state & PG_STATE_STALE)
oss << "stale+";
if (state & PG_STATE_CREATING)
oss << "creating+";
if (state & PG_STATE_ACTIVE)
oss << "active+";
if (state & PG_STATE_ACTIVATING)
oss << "activating+";
if (state & PG_STATE_CLEAN)
oss << "clean+";
if (state & PG_STATE_RECOVERY_WAIT)
oss << "recovery_wait+";
if (state & PG_STATE_RECOVERING)
oss << "recovering+";
if (state & PG_STATE_DOWN)
oss << "down+";
if (state & PG_STATE_REPLAY)
oss << "replay+";
if (state & PG_STATE_SPLITTING)
oss << "splitting+";
if (state & PG_STATE_UNDERSIZED)
oss << "undersized+";
if (state & PG_STATE_DEGRADED)
oss << "degraded+";
if (state & PG_STATE_REMAPPED)
oss << "remapped+";
if (state & PG_STATE_SCRUBBING)
oss << "scrubbing+";
if (state & PG_STATE_DEEP_SCRUB)
oss << "deep+";
if (state & PG_STATE_SCRUBQ)
oss << "scrubq+";
if (state & PG_STATE_INCONSISTENT)
oss << "inconsistent+";
if (state & PG_STATE_PEERING)
oss << "peering+";
if (state & PG_STATE_REPAIR)
oss << "repair+";
if ((state & PG_STATE_BACKFILL_WAIT) &&
!(state &PG_STATE_BACKFILL))
oss << "wait_backfill+";
if (state & PG_STATE_BACKFILL)
oss << "backfilling+";
if (state & PG_STATE_BACKFILL_TOOFULL)
oss << "backfill_toofull+";
if (state & PG_STATE_INCOMPLETE)
oss << "incomplete+";
if (state & PG_STATE_PEERED)
oss << "peered+";
string ret(oss.str());
if (ret.length() > 0)
ret.resize(ret.length() - 1);
else
ret = "inactive";
return ret;
}
int pg_string_state(const std::string& state)
{
int type;
if (state == "active")
type = PG_STATE_ACTIVE;
else if (state == "clean")
type = PG_STATE_CLEAN;
else if (state == "down")
type = PG_STATE_DOWN;
else if (state == "replay")
type = PG_STATE_REPLAY;
else if (state == "splitting")
type = PG_STATE_SPLITTING;
else if (state == "scrubbing")
type = PG_STATE_SCRUBBING;
else if (state == "scrubq")
type = PG_STATE_SCRUBQ;
else if (state == "degraded")
type = PG_STATE_DEGRADED;
else if (state == "inconsistent")
type = PG_STATE_INCONSISTENT;
else if (state == "peering")
type = PG_STATE_PEERING;
else if (state == "repair")
type = PG_STATE_REPAIR;
else if (state == "recovering")
type = PG_STATE_RECOVERING;
else if (state == "backfill_wait")
type = PG_STATE_BACKFILL_WAIT;
else if (state == "incomplete")
type = PG_STATE_INCOMPLETE;
else if (state == "stale")
type = PG_STATE_STALE;
else if (state == "remapped")
type = PG_STATE_REMAPPED;
else if (state == "deep_scrub")
type = PG_STATE_DEEP_SCRUB;
else if (state == "backfill")
type = PG_STATE_BACKFILL;
else if (state == "backfill_toofull")
type = PG_STATE_BACKFILL_TOOFULL;
else if (state == "recovery_wait")
type = PG_STATE_RECOVERY_WAIT;
else if (state == "undersized")
type = PG_STATE_UNDERSIZED;
else
type = -1;
return type;
}
// -- eversion_t --
string eversion_t::get_key_name() const
{
char key[40];
snprintf(
key, sizeof(key), "%010u.%020llu", epoch, (long long unsigned)version);
return string(key);
}
// -- pool_snap_info_t --
void pool_snap_info_t::dump(Formatter *f) const
{
f->dump_unsigned("snapid", snapid);
f->dump_stream("stamp") << stamp;
f->dump_string("name", name);
}
void pool_snap_info_t::encode(bufferlist& bl, uint64_t features) const
{
if ((features & CEPH_FEATURE_PGPOOL3) == 0) {
__u8 struct_v = 1;
::encode(struct_v, bl);
::encode(snapid, bl);
::encode(stamp, bl);
::encode(name, bl);
return;
}
ENCODE_START(2, 2, bl);
::encode(snapid, bl);
::encode(stamp, bl);
::encode(name, bl);
ENCODE_FINISH(bl);
}
void pool_snap_info_t::decode(bufferlist::iterator& bl)
{
DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
::decode(snapid, bl);
::decode(stamp, bl);
::decode(name, bl);
DECODE_FINISH(bl);
}
void pool_snap_info_t::generate_test_instances(list<pool_snap_info_t*>& o)
{
o.push_back(new pool_snap_info_t);
o.push_back(new pool_snap_info_t);
o.back()->snapid = 1;
o.back()->stamp = utime_t(1, 2);
o.back()->name = "foo";
}
// -- pg_pool_t --
void pg_pool_t::dump(Formatter *f) const
{
f->dump_unsigned("flags", get_flags());
f->dump_string("flags_names", get_flags_string());
f->dump_int("type", get_type());
f->dump_int("size", get_size());
f->dump_int("min_size", get_min_size());
f->dump_int("crush_ruleset", get_crush_ruleset());
f->dump_int("object_hash", get_object_hash());
f->dump_int("pg_num", get_pg_num());
f->dump_int("pg_placement_num", get_pgp_num());
f->dump_unsigned("crash_replay_interval", get_crash_replay_interval());
f->dump_stream("last_change") << get_last_change();
f->dump_stream("last_force_op_resend") << get_last_force_op_resend();
f->dump_unsigned("auid", get_auid());
f->dump_string("snap_mode", is_pool_snaps_mode() ? "pool" : "selfmanaged");
f->dump_unsigned("snap_seq", get_snap_seq());
f->dump_unsigned("snap_epoch", get_snap_epoch());
f->open_array_section("pool_snaps");
for (map<snapid_t, pool_snap_info_t>::const_iterator p = snaps.begin(); p != snaps.end(); ++p) {
f->open_object_section("pool_snap_info");
p->second.dump(f);
f->close_section();
}
f->close_section();
f->dump_stream("removed_snaps") << removed_snaps;
f->dump_int("quota_max_bytes", quota_max_bytes);
f->dump_int("quota_max_objects", quota_max_objects);
f->open_array_section("tiers");
for (set<uint64_t>::const_iterator p = tiers.begin(); p != tiers.end(); ++p)
f->dump_int("pool_id", *p);
f->close_section();
f->dump_int("tier_of", tier_of);
f->dump_int("read_tier", read_tier);
f->dump_int("write_tier", write_tier);
f->dump_string("cache_mode", get_cache_mode_name());
f->dump_unsigned("target_max_bytes", target_max_bytes);
f->dump_unsigned("target_max_objects", target_max_objects);
f->dump_unsigned("cache_target_dirty_ratio_micro",
cache_target_dirty_ratio_micro);
f->dump_unsigned("cache_target_full_ratio_micro",
cache_target_full_ratio_micro);
f->dump_unsigned("cache_min_flush_age", cache_min_flush_age);
f->dump_unsigned("cache_min_evict_age", cache_min_evict_age);
f->dump_string("erasure_code_profile", erasure_code_profile);
f->open_object_section("hit_set_params");
hit_set_params.dump(f);
f->close_section(); // hit_set_params
f->dump_unsigned("hit_set_period", hit_set_period);
f->dump_unsigned("hit_set_count", hit_set_count);
f->dump_unsigned("min_read_recency_for_promote", min_read_recency_for_promote);
f->dump_unsigned("stripe_width", get_stripe_width());
f->dump_unsigned("expected_num_objects", expected_num_objects);
}
void pg_pool_t::convert_to_pg_shards(const vector<int> &from, set<pg_shard_t>* to) const {
for (size_t i = 0; i < from.size(); ++i) {
if (from[i] != CRUSH_ITEM_NONE) {
to->insert(
pg_shard_t(
from[i],
ec_pool() ? shard_id_t(i) : shard_id_t::NO_SHARD));
}
}
}
int pg_pool_t::calc_bits_of(int t)
{
int b = 0;
while (t > 0) {
t = t >> 1;
++b;
}
return b;
}
void pg_pool_t::calc_pg_masks()
{
pg_num_mask = (1 << calc_bits_of(pg_num-1)) - 1;
pgp_num_mask = (1 << calc_bits_of(pgp_num-1)) - 1;
}
unsigned pg_pool_t::get_pg_num_divisor(pg_t pgid) const
{
if (pg_num == pg_num_mask + 1)
return pg_num; // power-of-2 split
unsigned mask = pg_num_mask >> 1;
if ((pgid.ps() & mask) < (pg_num & mask))
return pg_num_mask + 1; // smaller bin size (already split)
else
return (pg_num_mask + 1) >> 1; // bigger bin (not yet split)
}
/*
* we have two snap modes:
* - pool global snaps
* - snap existence/non-existence defined by snaps[] and snap_seq
* - user managed snaps
* - removal governed by removed_snaps
*
* we know which mode we're using based on whether removed_snaps is empty.
*/
bool pg_pool_t::is_pool_snaps_mode() const
{
return removed_snaps.empty() && get_snap_seq() > 0;
}
bool pg_pool_t::is_unmanaged_snaps_mode() const
{
return removed_snaps.size() && get_snap_seq() > 0;
}
bool pg_pool_t::is_removed_snap(snapid_t s) const
{
if (is_pool_snaps_mode())
return s <= get_snap_seq() && snaps.count(s) == 0;
else
return removed_snaps.contains(s);
}
/*
* build set of known-removed sets from either pool snaps or