-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjournal.cc
2755 lines (2439 loc) · 78.8 KB
/
journal.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) 2004-2006 Sage Weil <[email protected]>
*
* 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 "common/config.h"
#include "osdc/Journaler.h"
#include "events/ESubtreeMap.h"
#include "events/ESession.h"
#include "events/ESessions.h"
#include "events/EMetaBlob.h"
#include "events/EResetJournal.h"
#include "events/EUpdate.h"
#include "events/ESlaveUpdate.h"
#include "events/EOpen.h"
#include "events/ECommitted.h"
#include "events/EExport.h"
#include "events/EImportStart.h"
#include "events/EImportFinish.h"
#include "events/EFragment.h"
#include "events/ETableClient.h"
#include "events/ETableServer.h"
#include "include/stringify.h"
#include "LogSegment.h"
#include "MDS.h"
#include "MDLog.h"
#include "MDCache.h"
#include "Server.h"
#include "Migrator.h"
#include "Mutation.h"
#include "InoTable.h"
#include "MDSTableClient.h"
#include "MDSTableServer.h"
#include "Locker.h"
#define dout_subsys ceph_subsys_mds
#undef DOUT_COND
#define DOUT_COND(cct, l) (l<=cct->_conf->debug_mds || l <= cct->_conf->debug_mds_log \
|| l <= cct->_conf->debug_mds_log_expire)
#undef dout_prefix
#define dout_prefix *_dout << "mds." << mds->get_nodeid() << ".journal "
// -----------------------
// LogSegment
void LogSegment::try_to_expire(MDS *mds, C_GatherBuilder &gather_bld)
{
set<CDir*> commit;
dout(6) << "LogSegment(" << offset << ").try_to_expire" << dendl;
assert(g_conf->mds_kill_journal_expire_at != 1);
// commit dirs
for (elist<CDir*>::iterator p = new_dirfrags.begin(); !p.end(); ++p) {
dout(20) << " new_dirfrag " << **p << dendl;
assert((*p)->is_auth());
commit.insert(*p);
}
for (elist<CDir*>::iterator p = dirty_dirfrags.begin(); !p.end(); ++p) {
dout(20) << " dirty_dirfrag " << **p << dendl;
assert((*p)->is_auth());
commit.insert(*p);
}
for (elist<CDentry*>::iterator p = dirty_dentries.begin(); !p.end(); ++p) {
dout(20) << " dirty_dentry " << **p << dendl;
assert((*p)->is_auth());
commit.insert((*p)->get_dir());
}
for (elist<CInode*>::iterator p = dirty_inodes.begin(); !p.end(); ++p) {
dout(20) << " dirty_inode " << **p << dendl;
assert((*p)->is_auth());
if ((*p)->is_base()) {
(*p)->store(gather_bld.new_sub());
} else
commit.insert((*p)->get_parent_dn()->get_dir());
}
if (!commit.empty()) {
for (set<CDir*>::iterator p = commit.begin();
p != commit.end();
++p) {
CDir *dir = *p;
assert(dir->is_auth());
if (dir->can_auth_pin()) {
dout(15) << "try_to_expire committing " << *dir << dendl;
dir->commit(0, gather_bld.new_sub());
} else {
dout(15) << "try_to_expire waiting for unfreeze on " << *dir << dendl;
dir->add_waiter(CDir::WAIT_UNFREEZE, gather_bld.new_sub());
}
}
}
// master ops with possibly uncommitted slaves
for (set<metareqid_t>::iterator p = uncommitted_masters.begin();
p != uncommitted_masters.end();
++p) {
dout(10) << "try_to_expire waiting for slaves to ack commit on " << *p << dendl;
mds->mdcache->wait_for_uncommitted_master(*p, gather_bld.new_sub());
}
// uncommitted fragments
for (set<dirfrag_t>::iterator p = uncommitted_fragments.begin();
p != uncommitted_fragments.end();
++p) {
dout(10) << "try_to_expire waiting for uncommitted fragment " << *p << dendl;
mds->mdcache->wait_for_uncommitted_fragment(*p, gather_bld.new_sub());
}
// nudge scatterlocks
for (elist<CInode*>::iterator p = dirty_dirfrag_dir.begin(); !p.end(); ++p) {
CInode *in = *p;
dout(10) << "try_to_expire waiting for dirlock flush on " << *in << dendl;
mds->locker->scatter_nudge(&in->filelock, gather_bld.new_sub());
}
for (elist<CInode*>::iterator p = dirty_dirfrag_dirfragtree.begin(); !p.end(); ++p) {
CInode *in = *p;
dout(10) << "try_to_expire waiting for dirfragtreelock flush on " << *in << dendl;
mds->locker->scatter_nudge(&in->dirfragtreelock, gather_bld.new_sub());
}
for (elist<CInode*>::iterator p = dirty_dirfrag_nest.begin(); !p.end(); ++p) {
CInode *in = *p;
dout(10) << "try_to_expire waiting for nest flush on " << *in << dendl;
mds->locker->scatter_nudge(&in->nestlock, gather_bld.new_sub());
}
assert(g_conf->mds_kill_journal_expire_at != 2);
// open files
if (!open_files.empty()) {
assert(!mds->mdlog->is_capped()); // hmm FIXME
EOpen *le = 0;
LogSegment *ls = mds->mdlog->get_current_segment();
assert(ls != this);
elist<CInode*>::iterator p = open_files.begin(member_offset(CInode, item_open_file));
while (!p.end()) {
CInode *in = *p;
assert(in->last == CEPH_NOSNAP);
++p;
if (in->is_auth() && in->is_any_caps()) {
if (in->is_any_caps_wanted()) {
dout(20) << "try_to_expire requeueing open file " << *in << dendl;
if (!le) {
le = new EOpen(mds->mdlog);
mds->mdlog->start_entry(le);
}
le->add_clean_inode(in);
ls->open_files.push_back(&in->item_open_file);
} else {
// drop inodes that aren't wanted
dout(20) << "try_to_expire not requeueing and delisting unwanted file " << *in << dendl;
in->item_open_file.remove_myself();
}
} else {
/*
* we can get a capless inode here if we replay an open file, the client fails to
* reconnect it, but does REPLAY an open request (that adds it to the logseg). AFAICS
* it's ok for the client to replay an open on a file it doesn't have in it's cache
* anymore.
*
* this makes the mds less sensitive to strict open_file consistency, although it does
* make it easier to miss subtle problems.
*/
dout(20) << "try_to_expire not requeueing and delisting capless file " << *in << dendl;
in->item_open_file.remove_myself();
}
}
if (le) {
mds->mdlog->submit_entry(le, gather_bld.new_sub());
dout(10) << "try_to_expire waiting for open files to rejournal" << dendl;
}
}
assert(g_conf->mds_kill_journal_expire_at != 3);
// backtraces to be stored/updated
for (elist<CInode*>::iterator p = dirty_parent_inodes.begin(); !p.end(); ++p) {
CInode *in = *p;
assert(in->is_auth());
if (in->can_auth_pin()) {
dout(15) << "try_to_expire waiting for storing backtrace on " << *in << dendl;
in->store_backtrace(gather_bld.new_sub());
} else {
dout(15) << "try_to_expire waiting for unfreeze on " << *in << dendl;
in->add_waiter(CInode::WAIT_UNFREEZE, gather_bld.new_sub());
}
}
assert(g_conf->mds_kill_journal_expire_at != 4);
// slave updates
for (elist<MDSlaveUpdate*>::iterator p = slave_updates.begin(member_offset(MDSlaveUpdate,
item));
!p.end(); ++p) {
MDSlaveUpdate *su = *p;
dout(10) << "try_to_expire waiting on slave update " << su << dendl;
assert(su->waiter == 0);
su->waiter = gather_bld.new_sub();
}
// idalloc
if (inotablev > mds->inotable->get_committed_version()) {
dout(10) << "try_to_expire saving inotable table, need " << inotablev
<< ", committed is " << mds->inotable->get_committed_version()
<< " (" << mds->inotable->get_committing_version() << ")"
<< dendl;
mds->inotable->save(gather_bld.new_sub(), inotablev);
}
// sessionmap
if (sessionmapv > mds->sessionmap.committed) {
dout(10) << "try_to_expire saving sessionmap, need " << sessionmapv
<< ", committed is " << mds->sessionmap.committed
<< " (" << mds->sessionmap.committing << ")"
<< dendl;
mds->sessionmap.save(gather_bld.new_sub(), sessionmapv);
}
// pending commit atids
for (map<int, hash_set<version_t> >::iterator p = pending_commit_tids.begin();
p != pending_commit_tids.end();
++p) {
MDSTableClient *client = mds->get_table_client(p->first);
for (hash_set<version_t>::iterator q = p->second.begin();
q != p->second.end();
++q) {
dout(10) << "try_to_expire " << get_mdstable_name(p->first) << " transaction " << *q
<< " pending commit (not yet acked), waiting" << dendl;
assert(!client->has_committed(*q));
client->wait_for_ack(*q, gather_bld.new_sub());
}
}
// table servers
for (map<int, version_t>::iterator p = tablev.begin();
p != tablev.end();
++p) {
MDSTableServer *server = mds->get_table_server(p->first);
if (p->second > server->get_committed_version()) {
dout(10) << "try_to_expire waiting for " << get_mdstable_name(p->first)
<< " to save, need " << p->second << dendl;
server->save(gather_bld.new_sub());
}
}
// truncating
for (set<CInode*>::iterator p = truncating_inodes.begin();
p != truncating_inodes.end();
++p) {
dout(10) << "try_to_expire waiting for truncate of " << **p << dendl;
(*p)->add_waiter(CInode::WAIT_TRUNC, gather_bld.new_sub());
}
// FIXME client requests...?
// audit handling of anchor transactions?
if (gather_bld.has_subs()) {
dout(6) << "LogSegment(" << offset << ").try_to_expire waiting" << dendl;
mds->mdlog->flush();
} else {
assert(g_conf->mds_kill_journal_expire_at != 5);
dout(6) << "LogSegment(" << offset << ").try_to_expire success" << dendl;
}
}
#undef DOUT_COND
#define DOUT_COND(cct, l) (l<=cct->_conf->debug_mds || l <= cct->_conf->debug_mds_log)
// -----------------------
// EMetaBlob
EMetaBlob::EMetaBlob(MDLog *mdlog) : opened_ino(0), renamed_dirino(0),
inotablev(0), sessionmapv(0),
allocated_ino(0),
last_subtree_map(mdlog ? mdlog->get_last_segment_offset() : 0),
my_offset(mdlog ? mdlog->get_write_pos() : 0) //, _segment(0)
{ }
void EMetaBlob::add_dir_context(CDir *dir, int mode)
{
MDS *mds = dir->cache->mds;
list<CDentry*> parents;
// it may be okay not to include the maybe items, if
// - we journaled the maybe child inode in this segment
// - that subtree turns out to be unambiguously auth
list<CDentry*> maybe;
bool maybenot = false;
while (true) {
// already have this dir? (we must always add in order)
if (lump_map.count(dir->dirfrag())) {
dout(20) << "EMetaBlob::add_dir_context(" << dir << ") have lump " << dir->dirfrag() << dendl;
break;
}
// stop at root/stray
CInode *diri = dir->get_inode();
CDentry *parent = diri->get_projected_parent_dn();
if (!parent)
break;
if (mode == TO_AUTH_SUBTREE_ROOT) {
// subtree root?
if (dir->is_subtree_root() && !dir->state_test(CDir::STATE_EXPORTBOUND)) {
if (dir->is_auth() && !dir->is_ambiguous_auth()) {
// it's an auth subtree, we don't need maybe (if any), and we're done.
dout(20) << "EMetaBlob::add_dir_context(" << dir << ") reached unambig auth subtree, don't need " << maybe
<< " at " << *dir << dendl;
maybe.clear();
break;
} else {
dout(20) << "EMetaBlob::add_dir_context(" << dir << ") reached ambig or !auth subtree, need " << maybe
<< " at " << *dir << dendl;
// we need the maybe list after all!
parents.splice(parents.begin(), maybe);
maybenot = false;
}
}
// was the inode journaled in this blob?
if (my_offset && diri->last_journaled == my_offset) {
dout(20) << "EMetaBlob::add_dir_context(" << dir << ") already have diri this blob " << *diri << dendl;
break;
}
// have we journaled this inode since the last subtree map?
if (!maybenot && last_subtree_map && diri->last_journaled >= last_subtree_map) {
dout(20) << "EMetaBlob::add_dir_context(" << dir << ") already have diri in this segment ("
<< diri->last_journaled << " >= " << last_subtree_map << "), setting maybenot flag "
<< *diri << dendl;
maybenot = true;
}
}
if (maybenot) {
dout(25) << "EMetaBlob::add_dir_context(" << dir << ") maybe " << *parent << dendl;
maybe.push_front(parent);
} else {
dout(25) << "EMetaBlob::add_dir_context(" << dir << ") definitely " << *parent << dendl;
parents.push_front(parent);
}
dir = parent->get_dir();
}
parents.splice(parents.begin(), maybe);
dout(20) << "EMetaBlob::add_dir_context final: " << parents << dendl;
for (list<CDentry*>::iterator p = parents.begin(); p != parents.end(); ++p) {
assert((*p)->get_projected_linkage()->is_primary());
add_dentry(*p, false);
}
}
void EMetaBlob::update_segment(LogSegment *ls)
{
// atids?
//for (list<version_t>::iterator p = atids.begin(); p != atids.end(); ++p)
// ls->pending_commit_atids[*p] = ls;
// -> handled directly by AnchorClient
// dirty inode mtimes
// -> handled directly by Server.cc, replay()
// alloc table update?
if (inotablev)
ls->inotablev = inotablev;
if (sessionmapv)
ls->sessionmapv = sessionmapv;
// truncated inodes
// -> handled directly by Server.cc
// client requests
// note the newest request per client
//if (!client_reqs.empty())
// ls->last_client_tid[client_reqs.rbegin()->client] = client_reqs.rbegin()->tid);
}
// EMetaBlob::fullbit
void EMetaBlob::fullbit::encode(bufferlist& bl) const {
ENCODE_START(6, 5, bl);
if (!_enc.length()) {
fullbit copy(dn, dnfirst, dnlast, dnv, inode, dirfragtree, xattrs, symlink,
snapbl, state, &old_inodes);
bl.append(copy._enc);
} else {
bl.append(_enc);
}
ENCODE_FINISH(bl);
}
void EMetaBlob::fullbit::decode(bufferlist::iterator &bl) {
DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl);
::decode(dn, bl);
::decode(dnfirst, bl);
::decode(dnlast, bl);
::decode(dnv, bl);
::decode(inode, bl);
::decode(xattrs, bl);
if (inode.is_symlink())
::decode(symlink, bl);
if (inode.is_dir()) {
::decode(dirfragtree, bl);
::decode(snapbl, bl);
if ((struct_v == 2) || (struct_v == 3)) {
bool dir_layout_exists;
::decode(dir_layout_exists, bl);
if (dir_layout_exists) {
__u8 dir_struct_v;
::decode(dir_struct_v, bl); // default_file_layout version
::decode(inode.layout, bl); // and actual layout, that we care about
}
}
}
if (struct_v >= 6) {
::decode(state, bl);
} else {
bool dirty;
::decode(dirty, bl);
state = dirty ? EMetaBlob::fullbit::STATE_DIRTY : 0;
}
if (struct_v >= 3) {
bool old_inodes_present;
::decode(old_inodes_present, bl);
if (old_inodes_present) {
::decode(old_inodes, bl);
}
}
DECODE_FINISH(bl);
}
void EMetaBlob::fullbit::dump(Formatter *f) const
{
if (_enc.length() && !dn.length()) {
/* if our bufferlist has data but our name is empty, we
* haven't initialized ourselves; do so in order to print members!
* We use const_cast here because the whole point is we aren't
* fully set up and this isn't changing who we "are", just our
* representation.
*/
EMetaBlob::fullbit *me = const_cast<EMetaBlob::fullbit*>(this);
bufferlist encoded;
encode(encoded);
bufferlist::iterator p = encoded.begin();
me->decode(p);
}
f->dump_string("dentry", dn);
f->dump_stream("snapid.first") << dnfirst;
f->dump_stream("snapid.last") << dnlast;
f->dump_int("dentry version", dnv);
f->open_object_section("inode");
inode.dump(f);
f->close_section(); // inode
f->open_array_section("xattrs");
for (map<string, bufferptr>::const_iterator iter = xattrs.begin();
iter != xattrs.end(); ++iter) {
f->dump_string(iter->first.c_str(), iter->second.c_str());
}
f->close_section(); // xattrs
if (inode.is_symlink()) {
f->dump_string("symlink", symlink);
}
if (inode.is_dir()) {
f->dump_stream("frag tree") << dirfragtree;
f->dump_string("has_snapbl", snapbl.length() ? "true" : "false");
if (inode.has_layout()) {
f->open_object_section("file layout policy");
// FIXME
f->dump_string("layout", "the layout exists");
f->close_section(); // file layout policy
}
}
f->dump_string("state", state_string());
if (!old_inodes.empty()) {
f->open_array_section("old inodes");
for (old_inodes_t::const_iterator iter = old_inodes.begin();
iter != old_inodes.end(); ++iter) {
f->open_object_section("inode");
f->dump_int("snapid", iter->first);
iter->second.dump(f);
f->close_section(); // inode
}
f->close_section(); // old inodes
}
}
void EMetaBlob::fullbit::generate_test_instances(list<EMetaBlob::fullbit*>& ls)
{
inode_t inode;
fragtree_t fragtree;
map<string,bufferptr> empty_xattrs;
bufferlist empty_snapbl;
fullbit *sample = new fullbit("/testdn", 0, 0, 0,
inode, fragtree, empty_xattrs, "", empty_snapbl,
false, NULL);
ls.push_back(sample);
}
void EMetaBlob::fullbit::update_inode(MDS *mds, CInode *in)
{
in->inode = inode;
in->xattrs = xattrs;
if (in->inode.is_dir()) {
if (!(in->dirfragtree == dirfragtree)) {
dout(10) << "EMetaBlob::fullbit::update_inode dft " << in->dirfragtree << " -> "
<< dirfragtree << " on " << *in << dendl;
in->dirfragtree = dirfragtree;
in->force_dirfrags();
}
/*
* we can do this before linking hte inode bc the split_at would
* be a no-op.. we have no children (namely open snaprealms) to
* divy up
*/
in->decode_snap_blob(snapbl);
} else if (in->inode.is_symlink()) {
in->symlink = symlink;
}
in->old_inodes = old_inodes;
}
// EMetaBlob::remotebit
void EMetaBlob::remotebit::encode(bufferlist& bl) const
{
ENCODE_START(2, 2, bl);
if (!_enc.length()) {
remotebit copy(dn, dnfirst, dnlast, dnv, ino, d_type, dirty);
bl.append(copy._enc);
} else {
bl.append(_enc);
}
ENCODE_FINISH(bl);
}
void EMetaBlob::remotebit::decode(bufferlist::iterator &bl)
{
DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
::decode(dn, bl);
::decode(dnfirst, bl);
::decode(dnlast, bl);
::decode(dnv, bl);
::decode(ino, bl);
::decode(d_type, bl);
::decode(dirty, bl);
DECODE_FINISH(bl);
}
void EMetaBlob::remotebit::dump(Formatter *f) const
{
if (_enc.length() && !dn.length()) {
/* if our bufferlist has data but our name is empty, we
* haven't initialized ourselves; do so in order to print members!
* We use const_cast here because the whole point is we aren't
* fully set up and this isn't changing who we "are", just our
* representation.
*/
EMetaBlob::remotebit *me = const_cast<EMetaBlob::remotebit*>(this);
bufferlist encoded;
encode(encoded);
bufferlist::iterator p = encoded.begin();
me->decode(p);
}
f->dump_string("dentry", dn);
f->dump_int("snapid.first", dnfirst);
f->dump_int("snapid.last", dnlast);
f->dump_int("dentry version", dnv);
f->dump_int("inodeno", ino);
uint32_t type = DTTOIF(d_type) & S_IFMT; // convert to type entries
string type_string;
switch(type) {
case S_IFREG:
type_string = "file"; break;
case S_IFLNK:
type_string = "symlink"; break;
case S_IFDIR:
type_string = "directory"; break;
default:
assert (0 == "unknown d_type!");
}
f->dump_string("d_type", type_string);
f->dump_string("dirty", dirty ? "true" : "false");
}
void EMetaBlob::remotebit::
generate_test_instances(list<EMetaBlob::remotebit*>& ls)
{
remotebit *remote = new remotebit("/test/dn", 0, 10, 15, 1, IFTODT(S_IFREG), false);
ls.push_back(remote);
}
// EMetaBlob::nullbit
void EMetaBlob::nullbit::encode(bufferlist& bl) const
{
ENCODE_START(2, 2, bl);
if (!_enc.length()) {
nullbit copy(dn, dnfirst, dnlast, dnv, dirty);
bl.append(copy._enc);
} else {
bl.append(_enc);
}
ENCODE_FINISH(bl);
}
void EMetaBlob::nullbit::decode(bufferlist::iterator &bl)
{
DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
::decode(dn, bl);
::decode(dnfirst, bl);
::decode(dnlast, bl);
::decode(dnv, bl);
::decode(dirty, bl);
DECODE_FINISH(bl);
}
void EMetaBlob::nullbit::dump(Formatter *f) const
{
if (_enc.length() && !dn.length()) {
/* if our bufferlist has data but our name is empty, we
* haven't initialized ourselves; do so in order to print members!
* We use const_cast here because the whole point is we aren't
* fully set up and this isn't changing who we "are", just our
* representation.
*/
EMetaBlob::nullbit *me = const_cast<EMetaBlob::nullbit*>(this);
bufferlist encoded;
encode(encoded);
bufferlist::iterator p = encoded.begin();
me->decode(p);
}
f->dump_string("dentry", dn);
f->dump_int("snapid.first", dnfirst);
f->dump_int("snapid.last", dnlast);
f->dump_int("dentry version", dnv);
f->dump_string("dirty", dirty ? "true" : "false");
}
void EMetaBlob::nullbit::generate_test_instances(list<nullbit*>& ls)
{
nullbit *sample = new nullbit("/test/dentry", 0, 10, 15, false);
nullbit *sample2 = new nullbit("/test/dirty", 10, 20, 25, true);
ls.push_back(sample);
ls.push_back(sample2);
}
// EMetaBlob::dirlump
void EMetaBlob::dirlump::encode(bufferlist& bl) const
{
ENCODE_START(2, 2, bl);
::encode(fnode, bl);
::encode(state, bl);
::encode(nfull, bl);
::encode(nremote, bl);
::encode(nnull, bl);
_encode_bits();
::encode(dnbl, bl);
ENCODE_FINISH(bl);
}
void EMetaBlob::dirlump::decode(bufferlist::iterator &bl)
{
DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl)
::decode(fnode, bl);
::decode(state, bl);
::decode(nfull, bl);
::decode(nremote, bl);
::decode(nnull, bl);
::decode(dnbl, bl);
dn_decoded = false; // don't decode bits unless we need them.
DECODE_FINISH(bl);
}
void EMetaBlob::dirlump::dump(Formatter *f) const
{
if (!dn_decoded) {
dirlump *me = const_cast<dirlump*>(this);
me->_decode_bits();
}
f->open_object_section("fnode");
fnode.dump(f);
f->close_section(); // fnode
f->dump_string("state", state_string());
f->dump_int("nfull", nfull);
f->dump_int("nremote", nremote);
f->dump_int("nnull", nnull);
f->open_array_section("full bits");
for (list<std::tr1::shared_ptr<fullbit> >::const_iterator
iter = dfull.begin(); iter != dfull.end(); ++iter) {
f->open_object_section("fullbit");
(*iter)->dump(f);
f->close_section(); // fullbit
}
f->close_section(); // full bits
f->open_array_section("remote bits");
for (list<remotebit>::const_iterator
iter = dremote.begin(); iter != dremote.end(); ++iter) {
f->open_object_section("remotebit");
(*iter).dump(f);
f->close_section(); // remotebit
}
f->close_section(); // remote bits
f->open_array_section("null bits");
for (list<nullbit>::const_iterator
iter = dnull.begin(); iter != dnull.end(); ++iter) {
f->open_object_section("null bit");
(*iter).dump(f);
f->close_section(); // null bit
}
f->close_section(); // null bits
}
void EMetaBlob::dirlump::generate_test_instances(list<dirlump*>& ls)
{
ls.push_back(new dirlump());
}
/**
* EMetaBlob proper
*/
void EMetaBlob::encode(bufferlist& bl) const
{
ENCODE_START(7, 5, bl);
::encode(lump_order, bl);
::encode(lump_map, bl);
::encode(roots, bl);
::encode(table_tids, bl);
::encode(opened_ino, bl);
::encode(allocated_ino, bl);
::encode(used_preallocated_ino, bl);
::encode(preallocated_inos, bl);
::encode(client_name, bl);
::encode(inotablev, bl);
::encode(sessionmapv, bl);
::encode(truncate_start, bl);
::encode(truncate_finish, bl);
::encode(destroyed_inodes, bl);
::encode(client_reqs, bl);
::encode(renamed_dirino, bl);
::encode(renamed_dir_frags, bl);
{
// make MDS use v6 format happy
int64_t i = -1;
bool b = false;
::encode(i, bl);
::encode(b, bl);
}
ENCODE_FINISH(bl);
}
void EMetaBlob::decode(bufferlist::iterator &bl)
{
DECODE_START_LEGACY_COMPAT_LEN(7, 5, 5, bl);
::decode(lump_order, bl);
::decode(lump_map, bl);
if (struct_v >= 4) {
::decode(roots, bl);
} else {
bufferlist rootbl;
::decode(rootbl, bl);
if (rootbl.length()) {
bufferlist::iterator p = rootbl.begin();
roots.push_back(std::tr1::shared_ptr<fullbit>(new fullbit(p)));
}
}
::decode(table_tids, bl);
::decode(opened_ino, bl);
::decode(allocated_ino, bl);
::decode(used_preallocated_ino, bl);
::decode(preallocated_inos, bl);
::decode(client_name, bl);
::decode(inotablev, bl);
::decode(sessionmapv, bl);
::decode(truncate_start, bl);
::decode(truncate_finish, bl);
::decode(destroyed_inodes, bl);
if (struct_v >= 2) {
::decode(client_reqs, bl);
} else {
list<metareqid_t> r;
::decode(r, bl);
while (!r.empty()) {
client_reqs.push_back(pair<metareqid_t,uint64_t>(r.front(), 0));
r.pop_front();
}
}
if (struct_v >= 3) {
::decode(renamed_dirino, bl);
::decode(renamed_dir_frags, bl);
}
if (struct_v >= 6) {
// ignore
int64_t i;
bool b;
::decode(i, bl);
::decode(b, bl);
}
DECODE_FINISH(bl);
}
void EMetaBlob::dump(Formatter *f) const
{
f->open_array_section("lumps");
for (list<dirfrag_t>::const_iterator i = lump_order.begin();
i != lump_order.end(); ++i) {
f->open_object_section("lump");
f->open_object_section("dirfrag");
f->dump_stream("dirfrag") << *i;
f->close_section(); // dirfrag
f->open_object_section("dirlump");
lump_map.at(*i).dump(f);
f->close_section(); // dirlump
f->close_section(); // lump
}
f->close_section(); // lumps
f->open_array_section("roots");
for (list<std::tr1::shared_ptr<fullbit> >::const_iterator i = roots.begin();
i != roots.end(); ++i) {
f->open_object_section("root");
(*i)->dump(f);
f->close_section(); // root
}
f->close_section(); // roots
f->open_array_section("tableclient tranactions");
for (list<pair<__u8,version_t> >::const_iterator i = table_tids.begin();
i != table_tids.end(); ++i) {
f->open_object_section("transaction");
f->dump_int("tid", i->first);
f->dump_int("version", i->second);
f->close_section(); // transaction
}
f->close_section(); // tableclient transactions
f->dump_int("renamed directory inodeno", renamed_dirino);
f->open_array_section("renamed directory fragments");
for (list<frag_t>::const_iterator i = renamed_dir_frags.begin();
i != renamed_dir_frags.end(); ++i) {
f->dump_int("frag", *i);
}
f->close_section(); // renamed directory fragments
f->dump_int("inotable version", inotablev);
f->dump_int("SesionMap version", sessionmapv);
f->dump_int("allocated ino", allocated_ino);
f->dump_stream("preallocated inos") << preallocated_inos;
f->dump_int("used preallocated ino", used_preallocated_ino);
f->open_object_section("client name");
client_name.dump(f);
f->close_section(); // client name
f->open_array_section("inodes starting a truncate");
for(list<inodeno_t>::const_iterator i = truncate_start.begin();
i != truncate_start.end(); ++i) {
f->dump_int("inodeno", *i);
}
f->close_section(); // truncate inodes
f->open_array_section("inodes finishing a truncated");
for(map<inodeno_t,uint64_t>::const_iterator i = truncate_finish.begin();
i != truncate_finish.end(); ++i) {
f->open_object_section("inode+segment");
f->dump_int("inodeno", i->first);
f->dump_int("truncate starting segment", i->second);
f->close_section(); // truncated inode
}
f->close_section(); // truncate finish inodes
f->open_array_section("destroyed inodes");
for(vector<inodeno_t>::const_iterator i = destroyed_inodes.begin();
i != destroyed_inodes.end(); ++i) {
f->dump_int("inodeno", *i);
}
f->close_section(); // destroyed inodes
f->open_array_section("client requests");
for(list<pair<metareqid_t,uint64_t> >::const_iterator i = client_reqs.begin();
i != client_reqs.end(); ++i) {
f->open_object_section("Client request");
f->dump_stream("request ID") << i->first;
f->dump_int("oldest request on client", i->second);
f->close_section(); // request
}
f->close_section(); // client requests
}
void EMetaBlob::generate_test_instances(list<EMetaBlob*>& ls)
{
ls.push_back(new EMetaBlob());
}
void EMetaBlob::replay(MDS *mds, LogSegment *logseg, MDSlaveUpdate *slaveup)
{
dout(10) << "EMetaBlob.replay " << lump_map.size() << " dirlumps by " << client_name << dendl;
assert(logseg);
assert(g_conf->mds_kill_journal_replay_at != 1);
for (list<std::tr1::shared_ptr<fullbit> >::iterator p = roots.begin(); p != roots.end(); ++p) {
CInode *in = mds->mdcache->get_inode((*p)->inode.ino);
bool isnew = in ? false:true;
if (!in)
in = new CInode(mds->mdcache, true);
(*p)->update_inode(mds, in);
if (isnew)
mds->mdcache->add_inode(in);
if ((*p)->is_dirty()) in->_mark_dirty(logseg);
dout(10) << "EMetaBlob.replay " << (isnew ? " added root ":" updated root ") << *in << dendl;
}
CInode *renamed_diri = 0;
CDir *olddir = 0;
if (renamed_dirino) {
renamed_diri = mds->mdcache->get_inode(renamed_dirino);
if (renamed_diri)
dout(10) << "EMetaBlob.replay renamed inode is " << *renamed_diri << dendl;
else
dout(10) << "EMetaBlob.replay don't have renamed ino " << renamed_dirino << dendl;
int nnull = 0;
for (list<dirfrag_t>::iterator lp = lump_order.begin(); lp != lump_order.end(); ++lp) {
dirlump &lump = lump_map[*lp];
if (lump.nnull) {
dout(10) << "EMetaBlob.replay found null dentry in dir " << *lp << dendl;
nnull += lump.nnull;
}
}
assert(nnull <= 1);
}
// keep track of any inodes we unlink and don't relink elsewhere
map<CInode*, CDir*> unlinked;
set<CInode*> linked;
// walk through my dirs (in order!)
for (list<dirfrag_t>::iterator lp = lump_order.begin();
lp != lump_order.end();
++lp) {
dout(10) << "EMetaBlob.replay dir " << *lp << dendl;
dirlump &lump = lump_map[*lp];
// the dir
CDir *dir = mds->mdcache->get_force_dirfrag(*lp);
if (!dir) {
// hmm. do i have the inode?
CInode *diri = mds->mdcache->get_inode((*lp).ino);
if (!diri) {
if (MDS_INO_IS_BASE(lp->ino)) {
diri = mds->mdcache->create_system_inode(lp->ino, S_IFDIR|0755);
dout(10) << "EMetaBlob.replay created base " << *diri << dendl;
} else {
dout(0) << "EMetaBlob.replay missing dir ino " << (*lp).ino << dendl;
assert(0);
}
}
// create the dirfrag
dir = diri->get_or_open_dirfrag(mds->mdcache, (*lp).frag);
if (MDS_INO_IS_BASE(lp->ino))
mds->mdcache->adjust_subtree_auth(dir, CDIR_AUTH_UNKNOWN);
dout(10) << "EMetaBlob.replay added dir " << *dir << dendl;
}
dir->set_version( lump.fnode.version );
dir->fnode = lump.fnode;