1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
27 #include "MDBalancer.h"
29 #include "ScrubStack.h"
31 #include "SnapClient.h"
40 #include "include/ceph_fs.h"
41 #include "include/filepath.h"
42 #include "include/util.h"
44 #include "msg/Message.h"
45 #include "msg/Messenger.h"
47 #include "common/MemoryModel.h"
48 #include "common/errno.h"
49 #include "common/perf_counters.h"
50 #include "common/safe_io.h"
52 #include "osdc/Journaler.h"
53 #include "osdc/Filer.h"
55 #include "events/ESubtreeMap.h"
56 #include "events/EUpdate.h"
57 #include "events/ESlaveUpdate.h"
58 #include "events/EImportFinish.h"
59 #include "events/EFragment.h"
60 #include "events/ECommitted.h"
61 #include "events/ESessions.h"
63 #include "messages/MGenericMessage.h"
65 #include "messages/MMDSResolve.h"
66 #include "messages/MMDSResolveAck.h"
67 #include "messages/MMDSCacheRejoin.h"
69 #include "messages/MDiscover.h"
70 #include "messages/MDiscoverReply.h"
72 //#include "messages/MInodeUpdate.h"
73 #include "messages/MDirUpdate.h"
74 #include "messages/MCacheExpire.h"
76 #include "messages/MInodeFileCaps.h"
78 #include "messages/MLock.h"
79 #include "messages/MDentryLink.h"
80 #include "messages/MDentryUnlink.h"
82 #include "messages/MMDSFindIno.h"
83 #include "messages/MMDSFindInoReply.h"
85 #include "messages/MMDSOpenIno.h"
86 #include "messages/MMDSOpenInoReply.h"
88 #include "messages/MClientRequest.h"
89 #include "messages/MClientCaps.h"
90 #include "messages/MClientSnap.h"
91 #include "messages/MClientQuota.h"
93 #include "messages/MMDSSlaveRequest.h"
95 #include "messages/MMDSFragmentNotify.h"
97 #include "messages/MGatherCaps.h"
101 #include "common/Timer.h"
103 #include "perfglue/heap_profiler.h"
107 #include "common/config.h"
108 #include "include/assert.h"
110 #define dout_context g_ceph_context
111 #define dout_subsys ceph_subsys_mds
113 #define dout_prefix _prefix(_dout, mds)
114 static ostream
& _prefix(std::ostream
*_dout
, MDSRank
*mds
) {
115 return *_dout
<< "mds." << mds
->get_nodeid() << ".cache ";
118 set
<int> SimpleLock::empty_gather_set
;
122 * All non-I/O contexts that require a reference
123 * to an MDCache instance descend from this.
125 class MDCacheContext
: public virtual MDSInternalContextBase
{
128 MDSRank
*get_mds() override
130 assert(mdcache
!= NULL
);
134 explicit MDCacheContext(MDCache
*mdc_
) : mdcache(mdc_
) {}
139 * Only for contexts called back from an I/O completion
141 * Note: duplication of members wrt MDCacheContext, because
142 * it'ls the lesser of two evils compared with introducing
143 * yet another piece of (multiple) inheritance.
145 class MDCacheIOContext
: public virtual MDSIOContextBase
{
148 MDSRank
*get_mds() override
150 assert(mdcache
!= NULL
);
154 explicit MDCacheIOContext(MDCache
*mdc_
) : mdcache(mdc_
) {}
157 class MDCacheLogContext
: public virtual MDSLogContextBase
{
160 MDSRank
*get_mds() override
162 assert(mdcache
!= NULL
);
166 explicit MDCacheLogContext(MDCache
*mdc_
) : mdcache(mdc_
) {}
169 MDCache::MDCache(MDSRank
*m
, PurgeQueue
&purge_queue_
) :
171 filer(m
->objecter
, m
->finisher
),
172 exceeded_size_limit(false),
174 stray_manager(m
, purge_queue_
)
176 migrator
.reset(new Migrator(mds
, this));
182 for (int i
= 0; i
< NUM_STRAY
; ++i
) {
186 num_inodes_with_caps
= 0;
188 max_dir_commit_size
= g_conf
->mds_dir_max_commit_size
?
189 (g_conf
->mds_dir_max_commit_size
<< 20) :
190 (0.9 *(g_conf
->osd_max_write_size
<< 20));
192 discover_last_tid
= 0;
193 open_ino_last_tid
= 0;
194 find_ino_peer_last_tid
= 0;
198 client_lease_durations
[0] = 5.0;
199 client_lease_durations
[1] = 30.0;
200 client_lease_durations
[2] = 300.0;
202 resolves_pending
= false;
203 rejoins_pending
= false;
204 cap_imports_num_opening
= 0;
206 opening_root
= open
= false;
207 lru
.lru_set_midpoint(cache_mid());
209 bottom_lru
.lru_set_midpoint(0);
211 decayrate
.set_halflife(g_conf
->mds_decay_halflife
);
213 did_shutdown_log_cap
= false;
219 g_ceph_context
->get_perfcounters_collection()->remove(logger
.get());
225 void MDCache::log_stat()
227 mds
->logger
->set(l_mds_inode_max
, cache_limit_inodes() == 0 ? INT_MAX
: cache_limit_inodes());
228 mds
->logger
->set(l_mds_inodes
, lru
.lru_get_size());
229 mds
->logger
->set(l_mds_inodes_pinned
, lru
.lru_get_num_pinned());
230 mds
->logger
->set(l_mds_inodes_top
, lru
.lru_get_top());
231 mds
->logger
->set(l_mds_inodes_bottom
, lru
.lru_get_bot());
232 mds
->logger
->set(l_mds_inodes_pin_tail
, lru
.lru_get_pintail());
233 mds
->logger
->set(l_mds_inodes_with_caps
, num_inodes_with_caps
);
234 mds
->logger
->set(l_mds_caps
, Capability::count());
240 bool MDCache::shutdown()
242 if (lru
.lru_get_size() > 0) {
243 dout(7) << "WARNING: mdcache shutdown with non-empty cache" << dendl
;
252 // ====================================================================
253 // some inode functions
255 void MDCache::add_inode(CInode
*in
)
257 // add to lru, inode map
258 assert(inode_map
.count(in
->vino()) == 0); // should be no dup inos!
259 inode_map
[ in
->vino() ] = in
;
261 if (in
->ino() < MDS_INO_SYSTEM_BASE
) {
262 if (in
->ino() == MDS_INO_ROOT
)
264 else if (in
->ino() == MDS_INO_MDSDIR(mds
->get_nodeid()))
266 else if (in
->is_stray()) {
267 if (MDS_INO_STRAY_OWNER(in
->ino()) == mds
->get_nodeid()) {
268 strays
[MDS_INO_STRAY_INDEX(in
->ino())] = in
;
272 base_inodes
.insert(in
);
275 if (cache_toofull()) {
276 exceeded_size_limit
= true;
280 void MDCache::remove_inode(CInode
*o
)
282 dout(14) << "remove_inode " << *o
<< dendl
;
284 if (o
->get_parent_dn()) {
285 // FIXME: multiple parents?
286 CDentry
*dn
= o
->get_parent_dn();
287 assert(!dn
->is_dirty());
288 dn
->dir
->unlink_inode(dn
); // leave dentry ... FIXME?
293 if (o
->is_dirty_parent())
294 o
->clear_dirty_parent();
296 o
->clear_scatter_dirty();
298 o
->item_open_file
.remove_myself();
300 if (o
->state_test(CInode::STATE_QUEUEDEXPORTPIN
))
301 export_pin_queue
.erase(o
);
303 // remove from inode map
304 inode_map
.erase(o
->vino());
306 if (o
->ino() < MDS_INO_SYSTEM_BASE
) {
307 if (o
== root
) root
= 0;
308 if (o
== myin
) myin
= 0;
310 if (MDS_INO_STRAY_OWNER(o
->ino()) == mds
->get_nodeid()) {
311 strays
[MDS_INO_STRAY_INDEX(o
->ino())] = 0;
315 base_inodes
.erase(o
);
319 assert(o
->get_num_ref() == 0);
323 file_layout_t
MDCache::gen_default_file_layout(const MDSMap
&mdsmap
)
325 file_layout_t result
= file_layout_t::get_default();
326 result
.pool_id
= mdsmap
.get_first_data_pool();
330 file_layout_t
MDCache::gen_default_log_layout(const MDSMap
&mdsmap
)
332 file_layout_t result
= file_layout_t::get_default();
333 result
.pool_id
= mdsmap
.get_metadata_pool();
334 if (g_conf
->mds_log_segment_size
> 0) {
335 result
.object_size
= g_conf
->mds_log_segment_size
;
336 result
.stripe_unit
= g_conf
->mds_log_segment_size
;
341 void MDCache::init_layouts()
343 default_file_layout
= gen_default_file_layout(*(mds
->mdsmap
));
344 default_log_layout
= gen_default_log_layout(*(mds
->mdsmap
));
347 void MDCache::create_unlinked_system_inode(CInode
*in
, inodeno_t ino
,
351 in
->inode
.version
= 1;
352 in
->inode
.xattr_version
= 1;
353 in
->inode
.mode
= 0500 | mode
;
357 in
->inode
.btime
= ceph_clock_now();
359 in
->inode
.truncate_size
= -1ull;
360 in
->inode
.change_attr
= 0;
361 in
->inode
.export_pin
= MDS_RANK_NONE
;
363 memset(&in
->inode
.dir_layout
, 0, sizeof(in
->inode
.dir_layout
));
364 if (in
->inode
.is_dir()) {
365 in
->inode
.dir_layout
.dl_dir_hash
= g_conf
->mds_default_dir_hash
;
366 ++in
->inode
.rstat
.rsubdirs
;
368 in
->inode
.layout
= default_file_layout
;
369 ++in
->inode
.rstat
.rfiles
;
371 in
->inode
.accounted_rstat
= in
->inode
.rstat
;
375 in
->inode_auth
= mds_authority_t(mds
->get_nodeid(), CDIR_AUTH_UNKNOWN
);
377 in
->inode_auth
= mds_authority_t(mds_rank_t(in
->ino() - MDS_INO_MDSDIR_OFFSET
), CDIR_AUTH_UNKNOWN
);
378 in
->open_snaprealm(); // empty snaprealm
379 assert(!in
->snaprealm
->parent
); // created its own
380 in
->snaprealm
->srnode
.seq
= 1;
384 CInode
*MDCache::create_system_inode(inodeno_t ino
, int mode
)
386 dout(0) << "creating system inode with ino:" << ino
<< dendl
;
387 CInode
*in
= new CInode(this);
388 create_unlinked_system_inode(in
, ino
, mode
);
393 CInode
*MDCache::create_root_inode()
395 CInode
*i
= create_system_inode(MDS_INO_ROOT
, S_IFDIR
|0755);
396 i
->inode
.uid
= g_conf
->mds_root_ino_uid
;
397 i
->inode
.gid
= g_conf
->mds_root_ino_gid
;
398 i
->inode
.layout
= default_file_layout
;
399 i
->inode
.layout
.pool_id
= mds
->mdsmap
->get_first_data_pool();
403 void MDCache::create_empty_hierarchy(MDSGather
*gather
)
406 CInode
*root
= create_root_inode();
408 // force empty root dir
409 CDir
*rootdir
= root
->get_or_open_dirfrag(this, frag_t());
410 adjust_subtree_auth(rootdir
, mds
->get_nodeid());
411 rootdir
->dir_rep
= CDir::REP_ALL
; //NONE;
413 rootdir
->fnode
.accounted_fragstat
= rootdir
->fnode
.fragstat
;
414 rootdir
->fnode
.accounted_rstat
= rootdir
->fnode
.rstat
;
416 root
->inode
.dirstat
= rootdir
->fnode
.fragstat
;
417 root
->inode
.rstat
= rootdir
->fnode
.rstat
;
418 ++root
->inode
.rstat
.rsubdirs
;
419 root
->inode
.accounted_rstat
= root
->inode
.rstat
;
421 rootdir
->mark_complete();
422 rootdir
->mark_dirty(rootdir
->pre_dirty(), mds
->mdlog
->get_current_segment());
423 rootdir
->commit(0, gather
->new_sub());
425 root
->store(gather
->new_sub());
428 void MDCache::create_mydir_hierarchy(MDSGather
*gather
)
431 CInode
*my
= create_system_inode(MDS_INO_MDSDIR(mds
->get_nodeid()), S_IFDIR
);
433 CDir
*mydir
= my
->get_or_open_dirfrag(this, frag_t());
434 adjust_subtree_auth(mydir
, mds
->get_nodeid());
436 LogSegment
*ls
= mds
->mdlog
->get_current_segment();
439 for (int i
= 0; i
< NUM_STRAY
; ++i
) {
440 CInode
*stray
= create_system_inode(MDS_INO_STRAY(mds
->get_nodeid(), i
), S_IFDIR
);
441 CDir
*straydir
= stray
->get_or_open_dirfrag(this, frag_t());
443 name
<< "stray" << i
;
444 CDentry
*sdn
= mydir
->add_primary_dentry(name
.str(), stray
);
445 sdn
->_mark_dirty(mds
->mdlog
->get_current_segment());
447 stray
->inode
.dirstat
= straydir
->fnode
.fragstat
;
449 mydir
->fnode
.rstat
.add(stray
->inode
.rstat
);
450 mydir
->fnode
.fragstat
.nsubdirs
++;
452 straydir
->mark_complete();
453 straydir
->mark_dirty(straydir
->pre_dirty(), ls
);
454 straydir
->commit(0, gather
->new_sub());
455 stray
->_mark_dirty_parent(ls
, true);
456 stray
->store_backtrace(gather
->new_sub());
459 mydir
->fnode
.accounted_fragstat
= mydir
->fnode
.fragstat
;
460 mydir
->fnode
.accounted_rstat
= mydir
->fnode
.rstat
;
462 myin
->inode
.dirstat
= mydir
->fnode
.fragstat
;
463 myin
->inode
.rstat
= mydir
->fnode
.rstat
;
464 ++myin
->inode
.rstat
.rsubdirs
;
465 myin
->inode
.accounted_rstat
= myin
->inode
.rstat
;
467 mydir
->mark_complete();
468 mydir
->mark_dirty(mydir
->pre_dirty(), ls
);
469 mydir
->commit(0, gather
->new_sub());
471 myin
->store(gather
->new_sub());
474 struct C_MDC_CreateSystemFile
: public MDCacheLogContext
{
478 MDSInternalContextBase
*fin
;
479 C_MDC_CreateSystemFile(MDCache
*c
, MutationRef
& mu
, CDentry
*d
, version_t v
, MDSInternalContextBase
*f
) :
480 MDCacheLogContext(c
), mut(mu
), dn(d
), dpv(v
), fin(f
) {}
481 void finish(int r
) override
{
482 mdcache
->_create_system_file_finish(mut
, dn
, dpv
, fin
);
486 void MDCache::_create_system_file(CDir
*dir
, const char *name
, CInode
*in
, MDSInternalContextBase
*fin
)
488 dout(10) << "_create_system_file " << name
<< " in " << *dir
<< dendl
;
489 CDentry
*dn
= dir
->add_null_dentry(name
);
491 dn
->push_projected_linkage(in
);
492 version_t dpv
= dn
->pre_dirty();
495 if (in
->inode
.is_dir()) {
496 in
->inode
.rstat
.rsubdirs
= 1;
498 mdir
= in
->get_or_open_dirfrag(this, frag_t());
499 mdir
->mark_complete();
502 in
->inode
.rstat
.rfiles
= 1;
503 in
->inode
.version
= dn
->pre_dirty();
505 SnapRealm
*realm
= dir
->get_inode()->find_snaprealm();
506 dn
->first
= in
->first
= realm
->get_newest_seq() + 1;
508 MutationRef
mut(new MutationImpl());
510 // force some locks. hacky.
511 mds
->locker
->wrlock_force(&dir
->inode
->filelock
, mut
);
512 mds
->locker
->wrlock_force(&dir
->inode
->nestlock
, mut
);
514 mut
->ls
= mds
->mdlog
->get_current_segment();
515 EUpdate
*le
= new EUpdate(mds
->mdlog
, "create system file");
516 mds
->mdlog
->start_entry(le
);
518 if (!in
->is_mdsdir()) {
519 predirty_journal_parents(mut
, &le
->metablob
, in
, dir
, PREDIRTY_PRIMARY
|PREDIRTY_DIR
, 1);
520 le
->metablob
.add_primary_dentry(dn
, in
, true);
522 predirty_journal_parents(mut
, &le
->metablob
, in
, dir
, PREDIRTY_DIR
, 1);
523 journal_dirty_inode(mut
.get(), &le
->metablob
, in
);
524 dn
->push_projected_linkage(in
->ino(), in
->d_type());
525 le
->metablob
.add_remote_dentry(dn
, true, in
->ino(), in
->d_type());
526 le
->metablob
.add_root(true, in
);
529 le
->metablob
.add_new_dir(mdir
); // dirty AND complete AND new
531 mds
->mdlog
->submit_entry(le
, new C_MDC_CreateSystemFile(this, mut
, dn
, dpv
, fin
));
535 void MDCache::_create_system_file_finish(MutationRef
& mut
, CDentry
*dn
, version_t dpv
, MDSInternalContextBase
*fin
)
537 dout(10) << "_create_system_file_finish " << *dn
<< dendl
;
539 dn
->pop_projected_linkage();
540 dn
->mark_dirty(dpv
, mut
->ls
);
542 CInode
*in
= dn
->get_linkage()->get_inode();
544 in
->mark_dirty(in
->inode
.version
+ 1, mut
->ls
);
546 if (in
->inode
.is_dir()) {
547 CDir
*dir
= in
->get_dirfrag(frag_t());
549 dir
->mark_dirty(1, mut
->ls
);
550 dir
->mark_new(mut
->ls
);
554 mds
->locker
->drop_locks(mut
.get());
559 //if (dir && MDS_INO_IS_MDSDIR(in->ino()))
560 //migrator->export_dir(dir, (int)in->ino() - MDS_INO_MDSDIR_OFFSET);
565 struct C_MDS_RetryOpenRoot
: public MDSInternalContext
{
567 explicit C_MDS_RetryOpenRoot(MDCache
*c
) : MDSInternalContext(c
->mds
), cache(c
) {}
568 void finish(int r
) override
{
570 // If we can't open root, something disastrous has happened: mark
571 // this rank damaged for operator intervention. Note that
572 // it is not okay to call suicide() here because we are in
573 // a Finisher callback.
574 cache
->mds
->damaged();
575 ceph_abort(); // damaged should never return
582 void MDCache::open_root_inode(MDSInternalContextBase
*c
)
584 if (mds
->get_nodeid() == mds
->mdsmap
->get_root()) {
586 in
= create_system_inode(MDS_INO_ROOT
, S_IFDIR
|0755); // initially inaccurate!
589 discover_base_ino(MDS_INO_ROOT
, c
, mds
->mdsmap
->get_root());
593 void MDCache::open_mydir_inode(MDSInternalContextBase
*c
)
595 MDSGatherBuilder
gather(g_ceph_context
);
597 CInode
*in
= create_system_inode(MDS_INO_MDSDIR(mds
->get_nodeid()), S_IFDIR
|0755); // initially inaccurate!
598 in
->fetch(gather
.new_sub());
600 gather
.set_finisher(c
);
604 void MDCache::open_root()
606 dout(10) << "open_root" << dendl
;
609 open_root_inode(new C_MDS_RetryOpenRoot(this));
612 if (mds
->get_nodeid() == mds
->mdsmap
->get_root()) {
613 assert(root
->is_auth());
614 CDir
*rootdir
= root
->get_or_open_dirfrag(this, frag_t());
616 if (!rootdir
->is_subtree_root())
617 adjust_subtree_auth(rootdir
, mds
->get_nodeid());
618 if (!rootdir
->is_complete()) {
619 rootdir
->fetch(new C_MDS_RetryOpenRoot(this));
623 assert(!root
->is_auth());
624 CDir
*rootdir
= root
->get_dirfrag(frag_t());
626 open_remote_dirfrag(root
, frag_t(), new C_MDS_RetryOpenRoot(this));
632 CInode
*in
= create_system_inode(MDS_INO_MDSDIR(mds
->get_nodeid()), S_IFDIR
|0755); // initially inaccurate!
633 in
->fetch(new C_MDS_RetryOpenRoot(this));
636 CDir
*mydir
= myin
->get_or_open_dirfrag(this, frag_t());
638 adjust_subtree_auth(mydir
, mds
->get_nodeid());
643 void MDCache::populate_mydir()
646 CDir
*mydir
= myin
->get_or_open_dirfrag(this, frag_t());
649 dout(10) << "populate_mydir " << *mydir
<< dendl
;
651 if (!mydir
->is_complete()) {
652 mydir
->fetch(new C_MDS_RetryOpenRoot(this));
656 if (mydir
->get_version() == 0 && mydir
->state_test(CDir::STATE_BADFRAG
)) {
657 // A missing dirfrag, we will recreate it. Before that, we must dirty
658 // it before dirtying any of the strays we create within it.
659 mds
->clog
->warn() << "fragment " << mydir
->dirfrag() << " was unreadable, "
661 LogSegment
*ls
= mds
->mdlog
->get_current_segment();
662 mydir
->state_clear(CDir::STATE_BADFRAG
);
663 mydir
->mark_complete();
664 mydir
->mark_dirty(mydir
->pre_dirty(), ls
);
667 // open or create stray
668 uint64_t num_strays
= 0;
669 for (int i
= 0; i
< NUM_STRAY
; ++i
) {
671 name
<< "stray" << i
;
672 CDentry
*straydn
= mydir
->lookup(name
.str());
674 // allow for older fs's with stray instead of stray0
675 if (straydn
== NULL
&& i
== 0)
676 straydn
= mydir
->lookup("stray");
678 if (!straydn
|| !straydn
->get_linkage()->get_inode()) {
679 _create_system_file(mydir
, name
.str().c_str(), create_system_inode(MDS_INO_STRAY(mds
->get_nodeid(), i
), S_IFDIR
),
680 new C_MDS_RetryOpenRoot(this));
685 // we make multiple passes through this method; make sure we only pin each stray once.
686 if (!strays
[i
]->state_test(CInode::STATE_STRAYPINNED
)) {
687 strays
[i
]->get(CInode::PIN_STRAY
);
688 strays
[i
]->state_set(CInode::STATE_STRAYPINNED
);
689 strays
[i
]->get_stickydirs();
691 dout(20) << " stray num " << i
<< " is " << *strays
[i
] << dendl
;
695 strays
[i
]->dirfragtree
.get_leaves(ls
);
696 for (list
<frag_t
>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
698 CDir
*dir
= strays
[i
]->get_dirfrag(fg
);
700 dir
= strays
[i
]->get_or_open_dirfrag(this, fg
);
703 // DamageTable applies special handling to strays: it will
704 // have damaged() us out if one is damaged.
705 assert(!dir
->state_test(CDir::STATE_BADFRAG
));
707 if (dir
->get_version() == 0) {
708 dir
->fetch(new C_MDS_RetryOpenRoot(this));
712 if (dir
->get_frag_size() > 0)
713 num_strays
+= dir
->get_frag_size();
717 stray_manager
.set_num_strays(num_strays
);
720 dout(10) << "populate_mydir done" << dendl
;
723 mds
->queue_waiters(waiting_for_open
);
728 void MDCache::open_foreign_mdsdir(inodeno_t ino
, MDSInternalContextBase
*fin
)
730 discover_base_ino(ino
, fin
, mds_rank_t(ino
& (MAX_MDS
-1)));
733 CDir
*MDCache::get_stray_dir(CInode
*in
)
736 in
->name_stray_dentry(straydname
);
738 CInode
*strayi
= get_stray();
740 frag_t fg
= strayi
->pick_dirfrag(straydname
);
741 CDir
*straydir
= strayi
->get_dirfrag(fg
);
746 CDentry
*MDCache::get_or_create_stray_dentry(CInode
*in
)
748 CDir
*straydir
= get_stray_dir(in
);
750 in
->name_stray_dentry(straydname
);
751 CDentry
*straydn
= straydir
->lookup(straydname
);
753 straydn
= straydir
->add_null_dentry(straydname
);
756 assert(straydn
->get_projected_linkage()->is_null());
759 straydn
->state_set(CDentry::STATE_STRAY
);
765 MDSCacheObject
*MDCache::get_object(MDSCacheObjectInfo
&info
)
769 return get_inode(info
.ino
, info
.snapid
);
772 CDir
*dir
= get_dirfrag(info
.dirfrag
);
775 if (info
.dname
.length())
776 return dir
->lookup(info
.dname
, info
.snapid
);
784 // ====================================================================
785 // subtree management
787 void MDCache::list_subtrees(list
<CDir
*>& ls
)
789 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
792 ls
.push_back(p
->first
);
796 * adjust the dir_auth of a subtree.
797 * merge with parent and/or child subtrees, if is it appropriate.
798 * merge can ONLY happen if both parent and child have unambiguous auth.
800 void MDCache::adjust_subtree_auth(CDir
*dir
, mds_authority_t auth
)
802 dout(7) << "adjust_subtree_auth " << dir
->get_dir_auth() << " -> " << auth
803 << " on " << *dir
<< dendl
;
808 if (dir
->inode
->is_base()) {
809 root
= dir
; // bootstrap hack.
810 if (subtrees
.count(root
) == 0) {
812 root
->get(CDir::PIN_SUBTREE
);
815 root
= get_subtree_root(dir
); // subtree root
818 assert(subtrees
.count(root
));
819 dout(7) << " current root is " << *root
<< dendl
;
822 // i am already a subtree.
823 dir
->set_dir_auth(auth
);
825 // i am a new subtree.
826 dout(10) << " new subtree at " << *dir
<< dendl
;
827 assert(subtrees
.count(dir
) == 0);
828 subtrees
[dir
]; // create empty subtree bounds list for me.
829 dir
->get(CDir::PIN_SUBTREE
);
832 dir
->set_dir_auth(auth
);
834 // move items nested beneath me, under me.
835 set
<CDir
*>::iterator p
= subtrees
[root
].begin();
836 while (p
!= subtrees
[root
].end()) {
837 set
<CDir
*>::iterator next
= p
;
839 if (get_subtree_root((*p
)->get_parent_dir()) == dir
) {
841 dout(10) << " claiming child bound " << **p
<< dendl
;
842 subtrees
[dir
].insert(*p
);
843 subtrees
[root
].erase(p
);
848 // i am a bound of the parent subtree.
849 subtrees
[root
].insert(dir
);
851 // i am now the subtree root.
854 // adjust recursive pop counters
855 if (dir
->is_auth()) {
856 utime_t now
= ceph_clock_now();
857 CDir
*p
= dir
->get_parent_dir();
859 p
->pop_auth_subtree
.sub(now
, decayrate
, dir
->pop_auth_subtree
);
860 if (p
->is_subtree_root()) break;
861 p
= p
->inode
->get_parent_dir();
870 void MDCache::try_subtree_merge(CDir
*dir
)
872 dout(7) << "try_subtree_merge " << *dir
<< dendl
;
873 assert(subtrees
.count(dir
));
874 set
<CDir
*> oldbounds
= subtrees
[dir
];
876 set
<CInode
*> to_eval
;
877 // try merge at my root
878 try_subtree_merge_at(dir
, &to_eval
);
880 // try merge at my old bounds
881 for (auto bound
: oldbounds
)
882 try_subtree_merge_at(bound
, &to_eval
);
884 if (!(mds
->is_any_replay() || mds
->is_resolve())) {
885 for(auto in
: to_eval
)
886 eval_subtree_root(in
);
890 class C_MDC_SubtreeMergeWB
: public MDCacheLogContext
{
894 C_MDC_SubtreeMergeWB(MDCache
*mdc
, CInode
*i
, MutationRef
& m
) : MDCacheLogContext(mdc
), in(i
), mut(m
) {}
895 void finish(int r
) override
{
896 mdcache
->subtree_merge_writebehind_finish(in
, mut
);
900 void MDCache::try_subtree_merge_at(CDir
*dir
, set
<CInode
*> *to_eval
)
902 dout(10) << "try_subtree_merge_at " << *dir
<< dendl
;
903 assert(subtrees
.count(dir
));
905 // merge with parent?
907 if (!dir
->inode
->is_base())
908 parent
= get_subtree_root(dir
->get_parent_dir());
910 if (parent
!= dir
&& // we have a parent,
911 parent
->dir_auth
== dir
->dir_auth
&& // auth matches,
912 dir
->dir_auth
.second
== CDIR_AUTH_UNKNOWN
&& // auth is unambiguous,
913 !dir
->state_test(CDir::STATE_EXPORTBOUND
) && // not an exportbound,
914 !dir
->state_test(CDir::STATE_AUXSUBTREE
)) { // not aux subtree
915 // merge with parent.
916 dout(10) << " subtree merge at " << *dir
<< dendl
;
917 dir
->set_dir_auth(CDIR_AUTH_DEFAULT
);
919 // move our bounds under the parent
920 for (set
<CDir
*>::iterator p
= subtrees
[dir
].begin();
921 p
!= subtrees
[dir
].end();
923 subtrees
[parent
].insert(*p
);
925 // we are no longer a subtree or bound
926 dir
->put(CDir::PIN_SUBTREE
);
928 subtrees
[parent
].erase(dir
);
930 // adjust popularity?
931 if (dir
->is_auth()) {
932 utime_t now
= ceph_clock_now();
933 CDir
*p
= dir
->get_parent_dir();
935 p
->pop_auth_subtree
.add(now
, decayrate
, dir
->pop_auth_subtree
);
936 if (p
->is_subtree_root()) break;
937 p
= p
->inode
->get_parent_dir();
941 if (to_eval
&& dir
->get_inode()->is_auth())
942 to_eval
->insert(dir
->get_inode());
948 void MDCache::subtree_merge_writebehind_finish(CInode
*in
, MutationRef
& mut
)
950 dout(10) << "subtree_merge_writebehind_finish on " << in
<< dendl
;
951 in
->pop_and_dirty_projected_inode(mut
->ls
);
954 mds
->locker
->drop_locks(mut
.get());
957 in
->auth_unpin(this);
960 void MDCache::eval_subtree_root(CInode
*diri
)
962 // evaluate subtree inode filelock?
963 // (we should scatter the filelock on subtree bounds)
964 assert(diri
->is_auth());
965 mds
->locker
->try_eval(diri
, CEPH_LOCK_IFILE
| CEPH_LOCK_INEST
);
969 void MDCache::adjust_bounded_subtree_auth(CDir
*dir
, set
<CDir
*>& bounds
, mds_authority_t auth
)
971 dout(7) << "adjust_bounded_subtree_auth " << dir
->get_dir_auth() << " -> " << auth
973 << " bounds " << bounds
979 if (dir
->ino() == MDS_INO_ROOT
) {
980 root
= dir
; // bootstrap hack.
981 if (subtrees
.count(root
) == 0) {
983 root
->get(CDir::PIN_SUBTREE
);
986 root
= get_subtree_root(dir
); // subtree root
989 assert(subtrees
.count(root
));
990 dout(7) << " current root is " << *root
<< dendl
;
992 mds_authority_t oldauth
= dir
->authority();
995 // i am already a subtree.
996 dir
->set_dir_auth(auth
);
998 // i am a new subtree.
999 dout(10) << " new subtree at " << *dir
<< dendl
;
1000 assert(subtrees
.count(dir
) == 0);
1001 subtrees
[dir
]; // create empty subtree bounds list for me.
1002 dir
->get(CDir::PIN_SUBTREE
);
1005 dir
->set_dir_auth(auth
);
1007 // move items nested beneath me, under me.
1008 set
<CDir
*>::iterator p
= subtrees
[root
].begin();
1009 while (p
!= subtrees
[root
].end()) {
1010 set
<CDir
*>::iterator next
= p
;
1012 if (get_subtree_root((*p
)->get_parent_dir()) == dir
) {
1014 dout(10) << " claiming child bound " << **p
<< dendl
;
1015 subtrees
[dir
].insert(*p
);
1016 subtrees
[root
].erase(p
);
1021 // i am a bound of the parent subtree.
1022 subtrees
[root
].insert(dir
);
1024 // i am now the subtree root.
1028 set
<CInode
*> to_eval
;
1030 // verify/adjust bounds.
1031 // - these may be new, or
1032 // - beneath existing ambiguous bounds (which will be collapsed),
1033 // - but NOT beneath unambiguous bounds.
1034 for (set
<CDir
*>::iterator p
= bounds
.begin();
1040 if (subtrees
[dir
].count(bound
) == 0) {
1041 if (get_subtree_root(bound
) == dir
) {
1042 dout(10) << " new bound " << *bound
<< ", adjusting auth back to old " << oldauth
<< dendl
;
1043 adjust_subtree_auth(bound
, oldauth
); // otherwise, adjust at bound.
1046 dout(10) << " want bound " << *bound
<< dendl
;
1047 CDir
*t
= get_subtree_root(bound
->get_parent_dir());
1048 if (subtrees
[t
].count(bound
) == 0) {
1050 dout(10) << " new bound " << *bound
<< dendl
;
1051 adjust_subtree_auth(bound
, t
->authority());
1053 // make sure it's nested beneath ambiguous subtree(s)
1055 while (subtrees
[dir
].count(t
) == 0)
1056 t
= get_subtree_root(t
->get_parent_dir());
1057 dout(10) << " swallowing intervening subtree at " << *t
<< dendl
;
1058 adjust_subtree_auth(t
, auth
);
1059 try_subtree_merge_at(t
, &to_eval
);
1060 t
= get_subtree_root(bound
->get_parent_dir());
1061 if (t
== dir
) break;
1066 dout(10) << " already have bound " << *bound
<< dendl
;
1069 // merge stray bounds?
1070 while (!subtrees
[dir
].empty()) {
1071 set
<CDir
*> copy
= subtrees
[dir
];
1072 for (set
<CDir
*>::iterator p
= copy
.begin(); p
!= copy
.end(); ++p
) {
1073 if (bounds
.count(*p
) == 0) {
1075 dout(10) << " swallowing extra subtree at " << *stray
<< dendl
;
1076 adjust_subtree_auth(stray
, auth
);
1077 try_subtree_merge_at(stray
, &to_eval
);
1080 // swallowing subtree may add new subtree bounds
1081 if (copy
== subtrees
[dir
])
1085 // bound should now match.
1086 verify_subtree_bounds(dir
, bounds
);
1090 if (!(mds
->is_any_replay() || mds
->is_resolve())) {
1091 for(auto in
: to_eval
)
1092 eval_subtree_root(in
);
1098 * return a set of CDir*'s that correspond to the given bound set. Only adjust
1099 * fragmentation as necessary to get an equivalent bounding set. That is, only
1100 * split if one of our frags spans the provided bounding set. Never merge.
1102 void MDCache::get_force_dirfrag_bound_set(vector
<dirfrag_t
>& dfs
, set
<CDir
*>& bounds
)
1104 dout(10) << "get_force_dirfrag_bound_set " << dfs
<< dendl
;
1107 map
<inodeno_t
, fragset_t
> byino
;
1108 for (vector
<dirfrag_t
>::iterator p
= dfs
.begin(); p
!= dfs
.end(); ++p
)
1109 byino
[p
->ino
].insert(p
->frag
);
1110 dout(10) << " by ino: " << byino
<< dendl
;
1112 for (map
<inodeno_t
,fragset_t
>::iterator p
= byino
.begin(); p
!= byino
.end(); ++p
) {
1113 CInode
*diri
= get_inode(p
->first
);
1116 dout(10) << " checking fragset " << p
->second
.get() << " on " << *diri
<< dendl
;
1119 for (set
<frag_t
>::iterator q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
)
1120 tmpdft
.force_to_leaf(g_ceph_context
, *q
);
1122 for (set
<frag_t
>::iterator q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
1125 diri
->dirfragtree
.get_leaves_under(fg
, fgls
);
1128 frag_t approx_fg
= diri
->dirfragtree
[fg
.value()];
1130 tmpdft
.get_leaves_under(approx_fg
, ls
);
1131 for (list
<frag_t
>::iterator r
= ls
.begin(); r
!= ls
.end(); ++r
) {
1132 if (p
->second
.get().count(*r
) == 0) {
1133 // not bound, so the resolve message is from auth MDS of the dirfrag
1134 force_dir_fragment(diri
, *r
);
1139 fgls
.push_back(approx_fg
);
1141 diri
->dirfragtree
.get_leaves_under(fg
, fgls
);
1143 dout(10) << " frag " << fg
<< " contains " << fgls
<< dendl
;
1144 for (list
<frag_t
>::iterator r
= fgls
.begin(); r
!= fgls
.end(); ++r
) {
1145 CDir
*dir
= diri
->get_dirfrag(*r
);
1153 void MDCache::adjust_bounded_subtree_auth(CDir
*dir
, vector
<dirfrag_t
>& bound_dfs
, mds_authority_t auth
)
1155 dout(7) << "adjust_bounded_subtree_auth " << dir
->get_dir_auth() << " -> " << auth
1156 << " on " << *dir
<< " bound_dfs " << bound_dfs
<< dendl
;
1159 get_force_dirfrag_bound_set(bound_dfs
, bounds
);
1160 adjust_bounded_subtree_auth(dir
, bounds
, auth
);
1163 void MDCache::map_dirfrag_set(list
<dirfrag_t
>& dfs
, set
<CDir
*>& result
)
1165 dout(10) << "map_dirfrag_set " << dfs
<< dendl
;
1168 map
<inodeno_t
, fragset_t
> ino_fragset
;
1169 for (list
<dirfrag_t
>::iterator p
= dfs
.begin(); p
!= dfs
.end(); ++p
)
1170 ino_fragset
[p
->ino
].insert(p
->frag
);
1173 for (map
<inodeno_t
, fragset_t
>::iterator p
= ino_fragset
.begin();
1174 p
!= ino_fragset
.end();
1176 CInode
*in
= get_inode(p
->first
);
1180 list
<frag_t
> fglist
;
1181 for (set
<frag_t
>::iterator q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
)
1182 in
->dirfragtree
.get_leaves_under(*q
, fglist
);
1184 dout(15) << "map_dirfrag_set " << p
->second
<< " -> " << fglist
1185 << " on " << *in
<< dendl
;
1187 for (list
<frag_t
>::iterator q
= fglist
.begin(); q
!= fglist
.end(); ++q
) {
1188 CDir
*dir
= in
->get_dirfrag(*q
);
1197 CDir
*MDCache::get_subtree_root(CDir
*dir
)
1199 // find the underlying dir that delegates (or is about to delegate) auth
1201 if (dir
->is_subtree_root())
1203 dir
= dir
->get_inode()->get_parent_dir();
1209 CDir
*MDCache::get_projected_subtree_root(CDir
*dir
)
1211 // find the underlying dir that delegates (or is about to delegate) auth
1213 if (dir
->is_subtree_root())
1215 dir
= dir
->get_inode()->get_projected_parent_dir();
1221 void MDCache::remove_subtree(CDir
*dir
)
1223 dout(10) << "remove_subtree " << *dir
<< dendl
;
1224 assert(subtrees
.count(dir
));
1225 assert(subtrees
[dir
].empty());
1226 subtrees
.erase(dir
);
1227 dir
->put(CDir::PIN_SUBTREE
);
1228 if (dir
->get_parent_dir()) {
1229 CDir
*p
= get_subtree_root(dir
->get_parent_dir());
1230 assert(subtrees
[p
].count(dir
));
1231 subtrees
[p
].erase(dir
);
1235 void MDCache::get_subtree_bounds(CDir
*dir
, set
<CDir
*>& bounds
)
1237 assert(subtrees
.count(dir
));
1238 bounds
= subtrees
[dir
];
1241 void MDCache::get_wouldbe_subtree_bounds(CDir
*dir
, set
<CDir
*>& bounds
)
1243 if (subtrees
.count(dir
)) {
1244 // just copy them, dir is a subtree.
1245 get_subtree_bounds(dir
, bounds
);
1248 CDir
*root
= get_subtree_root(dir
);
1249 for (set
<CDir
*>::iterator p
= subtrees
[root
].begin();
1250 p
!= subtrees
[root
].end();
1254 t
= t
->get_parent_dir();
1265 void MDCache::verify_subtree_bounds(CDir
*dir
, const set
<CDir
*>& bounds
)
1267 // for debugging only.
1268 assert(subtrees
.count(dir
));
1269 if (bounds
!= subtrees
[dir
]) {
1270 dout(0) << "verify_subtree_bounds failed" << dendl
;
1271 set
<CDir
*> b
= bounds
;
1272 for (auto &cd
: subtrees
[dir
]) {
1273 if (bounds
.count(cd
)) {
1277 dout(0) << " missing bound " << *cd
<< dendl
;
1279 for (const auto &cd
: b
)
1280 dout(0) << " extra bound " << *cd
<< dendl
;
1282 assert(bounds
== subtrees
[dir
]);
1285 void MDCache::verify_subtree_bounds(CDir
*dir
, const list
<dirfrag_t
>& bounds
)
1287 // for debugging only.
1288 assert(subtrees
.count(dir
));
1290 // make sure that any bounds i do have are properly noted as such.
1292 for (const auto &fg
: bounds
) {
1293 CDir
*bd
= get_dirfrag(fg
);
1295 if (subtrees
[dir
].count(bd
) == 0) {
1296 dout(0) << "verify_subtree_bounds failed: extra bound " << *bd
<< dendl
;
1300 assert(failed
== 0);
1303 void MDCache::project_subtree_rename(CInode
*diri
, CDir
*olddir
, CDir
*newdir
)
1305 dout(10) << "project_subtree_rename " << *diri
<< " from " << *olddir
1306 << " to " << *newdir
<< dendl
;
1307 projected_subtree_renames
[diri
].push_back(pair
<CDir
*,CDir
*>(olddir
, newdir
));
1310 void MDCache::adjust_subtree_after_rename(CInode
*diri
, CDir
*olddir
, bool pop
)
1312 dout(10) << "adjust_subtree_after_rename " << *diri
<< " from " << *olddir
<< dendl
;
1316 CDir
*newdir
= diri
->get_parent_dir();
1319 map
<CInode
*,list
<pair
<CDir
*,CDir
*> > >::iterator p
= projected_subtree_renames
.find(diri
);
1320 assert(p
!= projected_subtree_renames
.end());
1321 assert(!p
->second
.empty());
1322 assert(p
->second
.front().first
== olddir
);
1323 assert(p
->second
.front().second
== newdir
);
1324 p
->second
.pop_front();
1325 if (p
->second
.empty())
1326 projected_subtree_renames
.erase(p
);
1331 // make sure subtree dirfrags are at the front of the list
1332 diri
->get_subtree_dirfrags(dfls
);
1333 diri
->get_nested_dirfrags(dfls
);
1334 for (list
<CDir
*>::iterator p
= dfls
.begin(); p
!= dfls
.end(); ++p
) {
1337 dout(10) << "dirfrag " << *dir
<< dendl
;
1338 CDir
*oldparent
= get_subtree_root(olddir
);
1339 dout(10) << " old parent " << *oldparent
<< dendl
;
1340 CDir
*newparent
= get_subtree_root(newdir
);
1341 dout(10) << " new parent " << *newparent
<< dendl
;
1343 if (oldparent
== newparent
) {
1344 dout(10) << "parent unchanged for " << *dir
<< " at " << *oldparent
<< dendl
;
1348 if (dir
->is_subtree_root()) {
1349 // children are fine. change parent.
1350 dout(10) << "moving " << *dir
<< " from " << *oldparent
<< " to " << *newparent
<< dendl
;
1351 assert(subtrees
[oldparent
].count(dir
));
1352 subtrees
[oldparent
].erase(dir
);
1353 assert(subtrees
.count(newparent
));
1354 subtrees
[newparent
].insert(dir
);
1355 // caller is responsible for 'eval diri'
1356 try_subtree_merge_at(dir
, NULL
);
1360 // see if any old bounds move to the new parent.
1362 for (set
<CDir
*>::iterator p
= subtrees
[oldparent
].begin();
1363 p
!= subtrees
[oldparent
].end();
1366 CDir
*broot
= get_subtree_root(bound
->get_parent_dir());
1367 if (broot
!= oldparent
) {
1368 assert(broot
== newparent
);
1369 tomove
.push_back(bound
);
1372 for (list
<CDir
*>::iterator p
= tomove
.begin(); p
!= tomove
.end(); ++p
) {
1374 dout(10) << "moving bound " << *bound
<< " from " << *oldparent
<< " to " << *newparent
<< dendl
;
1375 subtrees
[oldparent
].erase(bound
);
1376 subtrees
[newparent
].insert(bound
);
1380 if (oldparent
->authority() != newparent
->authority()) {
1381 adjust_subtree_auth(dir
, oldparent
->authority());
1382 // caller is responsible for 'eval diri'
1383 try_subtree_merge_at(dir
, NULL
);
1392 void MDCache::get_fullauth_subtrees(set
<CDir
*>& s
)
1394 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
1395 p
!= subtrees
.end();
1397 CDir
*root
= p
->first
;
1398 if (root
->is_full_dir_auth())
1402 void MDCache::get_auth_subtrees(set
<CDir
*>& s
)
1404 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
1405 p
!= subtrees
.end();
1407 CDir
*root
= p
->first
;
1408 if (root
->is_auth())
1416 int MDCache::num_subtrees()
1418 return subtrees
.size();
1421 int MDCache::num_subtrees_fullauth()
1424 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
1425 p
!= subtrees
.end();
1427 CDir
*root
= p
->first
;
1428 if (root
->is_full_dir_auth())
1434 int MDCache::num_subtrees_fullnonauth()
1437 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
1438 p
!= subtrees
.end();
1440 CDir
*root
= p
->first
;
1441 if (root
->is_full_dir_nonauth())
1449 // ===================================
1450 // journal and snap/cow helpers
1454 * find first inode in cache that follows given snapid. otherwise, return current.
1456 CInode
*MDCache::pick_inode_snap(CInode
*in
, snapid_t follows
)
1458 dout(10) << "pick_inode_snap follows " << follows
<< " on " << *in
<< dendl
;
1459 assert(in
->last
== CEPH_NOSNAP
);
1461 SnapRealm
*realm
= in
->find_snaprealm();
1462 const set
<snapid_t
>& snaps
= realm
->get_snaps();
1463 dout(10) << " realm " << *realm
<< " " << *realm
->inode
<< dendl
;
1464 dout(10) << " snaps " << snaps
<< dendl
;
1469 for (set
<snapid_t
>::const_iterator p
= snaps
.upper_bound(follows
); // first item > follows
1472 CInode
*t
= get_inode(in
->ino(), *p
);
1475 dout(10) << "pick_inode_snap snap " << *p
<< " found " << *in
<< dendl
;
1484 * note: i'm currently cheating wrt dirty and inode.version on cow
1485 * items. instead of doing a full dir predirty, i just take the
1486 * original item's version, and set the dirty flag (via
1487 * mutation::add_cow_{inode,dentry}() and mutation::apply(). that
1488 * means a special case in the dir commit clean sweep assertions.
1491 CInode
*MDCache::cow_inode(CInode
*in
, snapid_t last
)
1493 assert(last
>= in
->first
);
1495 SnapRealm
*realm
= in
->find_snaprealm();
1496 const set
<snapid_t
>& snaps
= realm
->get_snaps();
1498 // make sure snap inode's last match existing snapshots.
1499 // MDCache::pick_inode_snap() requires this.
1500 snapid_t last_snap
= last
;
1501 if (snaps
.count(last
) == 0) {
1502 set
<snapid_t
>::const_iterator p
= snaps
.upper_bound(last
);
1503 if (p
!= snaps
.begin()) {
1505 if (*p
>= in
->first
)
1510 CInode
*oldin
= new CInode(this, true, in
->first
, last_snap
);
1511 oldin
->inode
= *in
->get_previous_projected_inode();
1512 oldin
->symlink
= in
->symlink
;
1513 oldin
->xattrs
= *in
->get_previous_projected_xattrs();
1514 oldin
->inode
.trim_client_ranges(last
);
1516 if (in
->first
< in
->oldest_snap
)
1517 in
->oldest_snap
= in
->first
;
1521 dout(10) << "cow_inode " << *in
<< " to " << *oldin
<< dendl
;
1524 if (in
->last
!= CEPH_NOSNAP
) {
1525 CInode
*head_in
= get_inode(in
->ino());
1527 if (head_in
->split_need_snapflush(oldin
, in
)) {
1528 oldin
->client_snap_caps
= in
->client_snap_caps
;
1529 for (compact_map
<int,set
<client_t
> >::iterator p
= in
->client_snap_caps
.begin();
1530 p
!= in
->client_snap_caps
.end();
1532 SimpleLock
*lock
= oldin
->get_lock(p
->first
);
1534 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
1535 oldin
->auth_pin(lock
);
1536 lock
->set_state(LOCK_SNAP_SYNC
); // gathering
1537 lock
->get_wrlock(true);
1545 for (map
<client_t
,Capability
*>::iterator p
= in
->client_caps
.begin();
1546 p
!= in
->client_caps
.end();
1548 client_t client
= p
->first
;
1549 Capability
*cap
= p
->second
;
1550 int issued
= cap
->issued();
1551 if ((issued
& CEPH_CAP_ANY_WR
) &&
1552 cap
->client_follows
< last
) {
1554 for (int i
= 0; i
< num_cinode_locks
; i
++) {
1555 if (issued
& cinode_lock_info
[i
].wr_caps
) {
1556 int lockid
= cinode_lock_info
[i
].lock
;
1557 SimpleLock
*lock
= oldin
->get_lock(lockid
);
1559 oldin
->client_snap_caps
[lockid
].insert(client
);
1560 oldin
->auth_pin(lock
);
1561 lock
->set_state(LOCK_SNAP_SYNC
); // gathering
1562 lock
->get_wrlock(true);
1563 dout(10) << " client." << client
<< " cap " << ccap_string(issued
& cinode_lock_info
[i
].wr_caps
)
1564 << " wrlock lock " << *lock
<< " on " << *oldin
<< dendl
;
1567 cap
->client_follows
= last
;
1569 // we need snapflushes for any intervening snaps
1570 dout(10) << " snaps " << snaps
<< dendl
;
1571 for (set
<snapid_t
>::const_iterator q
= snaps
.lower_bound(oldin
->first
);
1572 q
!= snaps
.end() && *q
<= last
;
1574 in
->add_need_snapflush(oldin
, *q
, client
);
1577 dout(10) << " ignoring client." << client
<< " cap follows " << cap
->client_follows
<< dendl
;
1584 void MDCache::journal_cow_dentry(MutationImpl
*mut
, EMetaBlob
*metablob
,
1585 CDentry
*dn
, snapid_t follows
,
1586 CInode
**pcow_inode
, CDentry::linkage_t
*dnl
)
1589 dout(10) << "journal_cow_dentry got null CDentry, returning" << dendl
;
1592 dout(10) << "journal_cow_dentry follows " << follows
<< " on " << *dn
<< dendl
;
1593 assert(dn
->is_auth());
1595 // nothing to cow on a null dentry, fix caller
1597 dnl
= dn
->get_projected_linkage();
1598 assert(!dnl
->is_null());
1600 if (dnl
->is_primary() && dnl
->get_inode()->is_multiversion()) {
1601 // multiversion inode.
1602 CInode
*in
= dnl
->get_inode();
1603 SnapRealm
*realm
= NULL
;
1605 if (in
->get_projected_parent_dn() != dn
) {
1606 assert(follows
== CEPH_NOSNAP
);
1607 realm
= dn
->dir
->inode
->find_snaprealm();
1608 snapid_t dir_follows
= realm
->get_newest_snap();
1610 if (dir_follows
+1 > dn
->first
) {
1611 snapid_t oldfirst
= dn
->first
;
1612 dn
->first
= dir_follows
+1;
1613 if (realm
->has_snaps_in_range(oldfirst
, dir_follows
)) {
1614 CDentry
*olddn
= dn
->dir
->add_remote_dentry(dn
->name
, in
->ino(), in
->d_type(),
1615 oldfirst
, dir_follows
);
1617 dout(10) << " olddn " << *olddn
<< dendl
;
1618 metablob
->add_remote_dentry(olddn
, true);
1619 mut
->add_cow_dentry(olddn
);
1620 // FIXME: adjust link count here? hmm.
1622 if (dir_follows
+1 > in
->first
)
1623 in
->cow_old_inode(dir_follows
, false);
1627 if (in
->snaprealm
) {
1628 realm
= in
->snaprealm
;
1629 follows
= realm
->get_newest_seq();
1631 follows
= dir_follows
;
1633 realm
= in
->find_snaprealm();
1634 if (follows
== CEPH_NOSNAP
)
1635 follows
= realm
->get_newest_seq();
1639 if (follows
< in
->first
) {
1640 dout(10) << "journal_cow_dentry follows " << follows
<< " < first on " << *in
<< dendl
;
1644 if (!realm
->has_snaps_in_range(in
->first
, follows
)) {
1645 dout(10) << "journal_cow_dentry no snapshot follows " << follows
<< " on " << *in
<< dendl
;
1646 in
->first
= follows
+ 1;
1650 in
->cow_old_inode(follows
, false);
1653 SnapRealm
*realm
= dn
->dir
->inode
->find_snaprealm();
1654 if (follows
== CEPH_NOSNAP
)
1655 follows
= realm
->get_newest_seq();
1658 if (follows
< dn
->first
) {
1659 dout(10) << "journal_cow_dentry follows " << follows
<< " < first on " << *dn
<< dendl
;
1663 // update dn.first before adding old dentry to cdir's map
1664 snapid_t oldfirst
= dn
->first
;
1665 dn
->first
= follows
+1;
1667 CInode
*in
= dnl
->is_primary() ? dnl
->get_inode() : NULL
;
1669 if (!realm
->has_snaps_in_range(oldfirst
, follows
)) {
1670 dout(10) << "journal_cow_dentry no snapshot follows " << follows
<< " on " << *dn
<< dendl
;
1672 in
->first
= follows
+1;
1676 dout(10) << " dn " << *dn
<< dendl
;
1678 CInode
*oldin
= cow_inode(in
, follows
);
1679 mut
->add_cow_inode(oldin
);
1681 *pcow_inode
= oldin
;
1682 CDentry
*olddn
= dn
->dir
->add_primary_dentry(dn
->name
, oldin
, oldfirst
, oldin
->last
);
1683 oldin
->inode
.version
= olddn
->pre_dirty();
1684 dout(10) << " olddn " << *olddn
<< dendl
;
1685 bool need_snapflush
= !oldin
->client_snap_caps
.empty();
1687 mut
->ls
->open_files
.push_back(&oldin
->item_open_file
);
1688 metablob
->add_primary_dentry(olddn
, 0, true, false, false, need_snapflush
);
1689 mut
->add_cow_dentry(olddn
);
1691 assert(dnl
->is_remote());
1692 CDentry
*olddn
= dn
->dir
->add_remote_dentry(dn
->name
, dnl
->get_remote_ino(), dnl
->get_remote_d_type(),
1695 dout(10) << " olddn " << *olddn
<< dendl
;
1696 metablob
->add_remote_dentry(olddn
, true);
1697 mut
->add_cow_dentry(olddn
);
1703 void MDCache::journal_cow_inode(MutationRef
& mut
, EMetaBlob
*metablob
,
1704 CInode
*in
, snapid_t follows
,
1705 CInode
**pcow_inode
)
1707 dout(10) << "journal_cow_inode follows " << follows
<< " on " << *in
<< dendl
;
1708 CDentry
*dn
= in
->get_projected_parent_dn();
1709 journal_cow_dentry(mut
.get(), metablob
, dn
, follows
, pcow_inode
);
1712 void MDCache::journal_dirty_inode(MutationImpl
*mut
, EMetaBlob
*metablob
, CInode
*in
, snapid_t follows
)
1714 if (in
->is_base()) {
1715 metablob
->add_root(true, in
, in
->get_projected_inode());
1717 if (follows
== CEPH_NOSNAP
&& in
->last
!= CEPH_NOSNAP
)
1718 follows
= in
->first
- 1;
1719 CDentry
*dn
= in
->get_projected_parent_dn();
1720 if (!dn
->get_projected_linkage()->is_null()) // no need to cow a null dentry
1721 journal_cow_dentry(mut
, metablob
, dn
, follows
);
1722 if (in
->get_projected_inode()->is_backtrace_updated()) {
1723 bool dirty_pool
= in
->get_projected_inode()->layout
.pool_id
!=
1724 in
->get_previous_projected_inode()->layout
.pool_id
;
1725 metablob
->add_primary_dentry(dn
, in
, true, true, dirty_pool
);
1727 metablob
->add_primary_dentry(dn
, in
, true);
1734 // nested ---------------------------------------------------------------
1736 void MDCache::project_rstat_inode_to_frag(CInode
*cur
, CDir
*parent
, snapid_t first
,
1737 int linkunlink
, SnapRealm
*prealm
)
1739 CDentry
*parentdn
= cur
->get_projected_parent_dn();
1740 inode_t
*curi
= cur
->get_projected_inode();
1742 if (cur
->first
> first
)
1745 dout(10) << "projected_rstat_inode_to_frag first " << first
<< " linkunlink " << linkunlink
1746 << " " << *cur
<< dendl
;
1747 dout(20) << " frag head is [" << parent
->first
<< ",head] " << dendl
;
1748 dout(20) << " inode update is [" << first
<< "," << cur
->last
<< "]" << dendl
;
1751 * FIXME. this incompletely propagates rstats to _old_ parents
1752 * (i.e. shortly after a directory rename). but we need full
1753 * blown hard link backpointers to make this work properly...
1755 snapid_t floor
= parentdn
->first
;
1756 dout(20) << " floor of " << floor
<< " from parent dn " << *parentdn
<< dendl
;
1759 prealm
= parent
->inode
->find_snaprealm();
1760 const set
<snapid_t
> snaps
= prealm
->get_snaps();
1762 if (cur
->last
!= CEPH_NOSNAP
) {
1763 assert(cur
->dirty_old_rstats
.empty());
1764 set
<snapid_t
>::const_iterator q
= snaps
.lower_bound(MAX(first
, floor
));
1765 if (q
== snaps
.end() || *q
> cur
->last
)
1769 if (cur
->last
>= floor
) {
1771 if (cur
->state_test(CInode::STATE_AMBIGUOUSAUTH
) && cur
->is_auth()) {
1772 // rename src inode is not projected in the slave rename prep case. so we should
1773 // avoid updateing the inode.
1774 assert(linkunlink
< 0);
1775 assert(cur
->is_frozen_inode());
1778 _project_rstat_inode_to_frag(*curi
, MAX(first
, floor
), cur
->last
, parent
,
1779 linkunlink
, update
);
1782 if (g_conf
->mds_snap_rstat
) {
1783 for (compact_set
<snapid_t
>::iterator p
= cur
->dirty_old_rstats
.begin();
1784 p
!= cur
->dirty_old_rstats
.end();
1786 old_inode_t
& old
= cur
->old_inodes
[*p
];
1787 snapid_t ofirst
= MAX(old
.first
, floor
);
1788 set
<snapid_t
>::const_iterator q
= snaps
.lower_bound(ofirst
);
1789 if (q
== snaps
.end() || *q
> *p
)
1792 _project_rstat_inode_to_frag(old
.inode
, ofirst
, *p
, parent
, 0, false);
1795 cur
->dirty_old_rstats
.clear();
1799 void MDCache::_project_rstat_inode_to_frag(inode_t
& inode
, snapid_t ofirst
, snapid_t last
,
1800 CDir
*parent
, int linkunlink
, bool update_inode
)
1802 dout(10) << "_project_rstat_inode_to_frag [" << ofirst
<< "," << last
<< "]" << dendl
;
1803 dout(20) << " inode rstat " << inode
.rstat
<< dendl
;
1804 dout(20) << " inode accounted_rstat " << inode
.accounted_rstat
<< dendl
;
1806 if (linkunlink
== 0) {
1807 delta
.add(inode
.rstat
);
1808 delta
.sub(inode
.accounted_rstat
);
1809 } else if (linkunlink
< 0) {
1810 delta
.sub(inode
.accounted_rstat
);
1812 delta
.add(inode
.rstat
);
1814 dout(20) << " delta " << delta
<< dendl
;
1817 inode
.accounted_rstat
= inode
.rstat
;
1819 while (last
>= ofirst
) {
1821 * pick fnode version to update. at each iteration, we want to
1822 * pick a segment ending in 'last' to update. split as necessary
1823 * to make that work. then, adjust first up so that we only
1824 * update one segment at a time. then loop to cover the whole
1825 * [ofirst,last] interval.
1827 nest_info_t
*prstat
;
1829 fnode_t
*pf
= parent
->get_projected_fnode();
1830 if (last
== CEPH_NOSNAP
) {
1831 if (g_conf
->mds_snap_rstat
)
1832 first
= MAX(ofirst
, parent
->first
);
1834 first
= parent
->first
;
1835 prstat
= &pf
->rstat
;
1836 dout(20) << " projecting to head [" << first
<< "," << last
<< "] " << *prstat
<< dendl
;
1838 if (first
> parent
->first
&&
1839 !(pf
->rstat
== pf
->accounted_rstat
)) {
1840 dout(10) << " target snapped and not fully accounted, cow to dirty_old_rstat ["
1841 << parent
->first
<< "," << (first
-1) << "] "
1842 << " " << *prstat
<< "/" << pf
->accounted_rstat
1844 parent
->dirty_old_rstat
[first
-1].first
= parent
->first
;
1845 parent
->dirty_old_rstat
[first
-1].rstat
= pf
->rstat
;
1846 parent
->dirty_old_rstat
[first
-1].accounted_rstat
= pf
->accounted_rstat
;
1848 parent
->first
= first
;
1849 } else if (!g_conf
->mds_snap_rstat
) {
1850 // drop snapshots' rstats
1852 } else if (last
>= parent
->first
) {
1853 first
= parent
->first
;
1854 parent
->dirty_old_rstat
[last
].first
= first
;
1855 parent
->dirty_old_rstat
[last
].rstat
= pf
->rstat
;
1856 parent
->dirty_old_rstat
[last
].accounted_rstat
= pf
->accounted_rstat
;
1857 prstat
= &parent
->dirty_old_rstat
[last
].rstat
;
1858 dout(10) << " projecting to newly split dirty_old_fnode [" << first
<< "," << last
<< "] "
1859 << " " << *prstat
<< "/" << pf
->accounted_rstat
<< dendl
;
1861 // be careful, dirty_old_rstat is a _sparse_ map.
1862 // sorry, this is ugly.
1865 // find any intersection with last
1866 compact_map
<snapid_t
,old_rstat_t
>::iterator p
= parent
->dirty_old_rstat
.lower_bound(last
);
1867 if (p
== parent
->dirty_old_rstat
.end()) {
1868 dout(20) << " no dirty_old_rstat with last >= last " << last
<< dendl
;
1869 if (!parent
->dirty_old_rstat
.empty() && parent
->dirty_old_rstat
.rbegin()->first
>= first
) {
1870 dout(20) << " last dirty_old_rstat ends at " << parent
->dirty_old_rstat
.rbegin()->first
<< dendl
;
1871 first
= parent
->dirty_old_rstat
.rbegin()->first
+1;
1874 // *p last is >= last
1875 if (p
->second
.first
<= last
) {
1876 // *p intersects [first,last]
1877 if (p
->second
.first
< first
) {
1878 dout(10) << " splitting off left bit [" << p
->second
.first
<< "," << first
-1 << "]" << dendl
;
1879 parent
->dirty_old_rstat
[first
-1] = p
->second
;
1880 p
->second
.first
= first
;
1882 if (p
->second
.first
> first
)
1883 first
= p
->second
.first
;
1884 if (last
< p
->first
) {
1885 dout(10) << " splitting off right bit [" << last
+1 << "," << p
->first
<< "]" << dendl
;
1886 parent
->dirty_old_rstat
[last
] = p
->second
;
1887 p
->second
.first
= last
+1;
1890 // *p is to the _right_ of [first,last]
1891 p
= parent
->dirty_old_rstat
.lower_bound(first
);
1892 // new *p last is >= first
1893 if (p
->second
.first
<= last
&& // new *p isn't also to the right, and
1894 p
->first
>= first
) { // it intersects our first bit,
1895 dout(10) << " staying to the right of [" << p
->second
.first
<< "," << p
->first
<< "]..." << dendl
;
1898 dout(10) << " projecting to new dirty_old_rstat [" << first
<< "," << last
<< "]" << dendl
;
1901 dout(20) << " projecting to dirty_old_rstat [" << first
<< "," << last
<< "]" << dendl
;
1902 parent
->dirty_old_rstat
[last
].first
= first
;
1903 prstat
= &parent
->dirty_old_rstat
[last
].rstat
;
1907 dout(20) << " project to [" << first
<< "," << last
<< "] " << *prstat
<< dendl
;
1908 assert(last
>= first
);
1911 inode
.accounted_rstat
= inode
.rstat
;
1912 dout(20) << " result [" << first
<< "," << last
<< "] " << *prstat
<< " " << *parent
<< dendl
;
1918 void MDCache::project_rstat_frag_to_inode(nest_info_t
& rstat
, nest_info_t
& accounted_rstat
,
1919 snapid_t ofirst
, snapid_t last
,
1920 CInode
*pin
, bool cow_head
)
1922 dout(10) << "project_rstat_frag_to_inode [" << ofirst
<< "," << last
<< "]" << dendl
;
1923 dout(20) << " frag rstat " << rstat
<< dendl
;
1924 dout(20) << " frag accounted_rstat " << accounted_rstat
<< dendl
;
1925 nest_info_t delta
= rstat
;
1926 delta
.sub(accounted_rstat
);
1927 dout(20) << " delta " << delta
<< dendl
;
1929 while (last
>= ofirst
) {
1932 if (last
== pin
->last
) {
1933 pi
= pin
->get_projected_inode();
1934 first
= MAX(ofirst
, pin
->first
);
1935 if (first
> pin
->first
) {
1936 old_inode_t
& old
= pin
->cow_old_inode(first
-1, cow_head
);
1937 dout(20) << " cloned old_inode rstat is " << old
.inode
.rstat
<< dendl
;
1940 if (last
>= pin
->first
) {
1942 pin
->cow_old_inode(last
, cow_head
);
1944 // our life is easier here because old_inodes is not sparse
1945 // (although it may not begin at snapid 1)
1946 compact_map
<snapid_t
,old_inode_t
>::iterator p
= pin
->old_inodes
.lower_bound(last
);
1947 if (p
== pin
->old_inodes
.end()) {
1948 dout(10) << " no old_inode <= " << last
<< ", done." << dendl
;
1951 first
= p
->second
.first
;
1953 dout(10) << " oldest old_inode is [" << first
<< "," << p
->first
<< "], done." << dendl
;
1954 //assert(p == pin->old_inodes.begin());
1957 if (p
->first
> last
) {
1958 dout(10) << " splitting right old_inode [" << first
<< "," << p
->first
<< "] to ["
1959 << (last
+1) << "," << p
->first
<< "]" << dendl
;
1960 pin
->old_inodes
[last
] = p
->second
;
1961 p
->second
.first
= last
+1;
1962 pin
->dirty_old_rstats
.insert(p
->first
);
1965 if (first
< ofirst
) {
1966 dout(10) << " splitting left old_inode [" << first
<< "," << last
<< "] to ["
1967 << first
<< "," << ofirst
-1 << "]" << dendl
;
1968 pin
->old_inodes
[ofirst
-1] = pin
->old_inodes
[last
];
1969 pin
->dirty_old_rstats
.insert(ofirst
-1);
1970 pin
->old_inodes
[last
].first
= first
= ofirst
;
1972 pi
= &pin
->old_inodes
[last
].inode
;
1973 pin
->dirty_old_rstats
.insert(last
);
1975 dout(20) << " projecting to [" << first
<< "," << last
<< "] " << pi
->rstat
<< dendl
;
1976 pi
->rstat
.add(delta
);
1977 dout(20) << " result [" << first
<< "," << last
<< "] " << pi
->rstat
<< dendl
;
1983 void MDCache::broadcast_quota_to_client(CInode
*in
)
1985 if (!in
->is_auth() || in
->is_frozen())
1988 inode_t
*i
= in
->get_projected_inode();
1990 if (!i
->quota
.is_enable())
1993 for (map
<client_t
,Capability
*>::iterator it
= in
->client_caps
.begin();
1994 it
!= in
->client_caps
.end();
1996 Session
*session
= mds
->get_session(it
->first
);
1997 if (!session
|| !session
->connection
||
1998 !session
->connection
->has_feature(CEPH_FEATURE_MDS_QUOTA
))
2001 Capability
*cap
= it
->second
;
2002 if (cap
->last_rbytes
== i
->rstat
.rbytes
&&
2003 cap
->last_rsize
== i
->rstat
.rsize())
2006 if (i
->quota
.max_files
> 0) {
2007 if (i
->rstat
.rsize() >= i
->quota
.max_files
)
2010 if ((abs(cap
->last_rsize
- i
->quota
.max_files
) >> 4) <
2011 abs(cap
->last_rsize
- i
->rstat
.rsize()))
2015 if (i
->quota
.max_bytes
> 0) {
2016 if (i
->rstat
.rbytes
> i
->quota
.max_bytes
- (i
->quota
.max_bytes
>> 3))
2019 if ((abs(cap
->last_rbytes
- i
->quota
.max_bytes
) >> 4) <
2020 abs(cap
->last_rbytes
- i
->rstat
.rbytes
))
2027 cap
->last_rsize
= i
->rstat
.rsize();
2028 cap
->last_rbytes
= i
->rstat
.rbytes
;
2030 MClientQuota
*msg
= new MClientQuota();
2031 msg
->ino
= in
->ino();
2032 msg
->rstat
= i
->rstat
;
2033 msg
->quota
= i
->quota
;
2034 mds
->send_message_client_counted(msg
, session
->connection
);
2036 for (const auto &it
: in
->get_replicas()) {
2037 MGatherCaps
*msg
= new MGatherCaps
;
2038 msg
->ino
= in
->ino();
2039 mds
->send_message_mds(msg
, it
.first
);
2044 * NOTE: we _have_ to delay the scatter if we are called during a
2045 * rejoin, because we can't twiddle locks between when the
2046 * rejoin_(weak|strong) is received and when we send the rejoin_ack.
2047 * normally, this isn't a problem: a recover mds doesn't twiddle locks
2048 * (no requests), and a survivor acks immediately. _except_ that
2049 * during rejoin_(weak|strong) processing, we may complete a lock
2050 * gather, and do a scatter_writebehind.. and we _can't_ twiddle the
2051 * scatterlock state in that case or the lock states will get out of
2052 * sync between the auth and replica.
2054 * the simple solution is to never do the scatter here. instead, put
2055 * the scatterlock on a list if it isn't already wrlockable. this is
2056 * probably the best plan anyway, since we avoid too many
2057 * scatters/locks under normal usage.
2060 * some notes on dirlock/nestlock scatterlock semantics:
2062 * the fragstat (dirlock) will never be updated without
2063 * dirlock+nestlock wrlock held by the caller.
2065 * the rstat (nestlock) _may_ get updated without a wrlock when nested
2066 * data is pushed up the tree. this could be changed with some
2067 * restructuring here, but in its current form we ensure that the
2068 * fragstat+rstat _always_ reflect an accurrate summation over the dir
2069 * frag, which is nice. and, we only need to track frags that need to
2070 * be nudged (and not inodes with pending rstat changes that need to
2071 * be pushed into the frag). a consequence of this is that the
2072 * accounted_rstat on scatterlock sync may not match our current
2073 * rstat. this is normal and expected.
2075 void MDCache::predirty_journal_parents(MutationRef mut
, EMetaBlob
*blob
,
2076 CInode
*in
, CDir
*parent
,
2077 int flags
, int linkunlink
,
2080 bool primary_dn
= flags
& PREDIRTY_PRIMARY
;
2081 bool do_parent_mtime
= flags
& PREDIRTY_DIR
;
2082 bool shallow
= flags
& PREDIRTY_SHALLOW
;
2084 assert(mds
->mdlog
->entry_is_open());
2086 // make sure stamp is set
2087 if (mut
->get_mds_stamp() == utime_t())
2088 mut
->set_mds_stamp(ceph_clock_now());
2093 dout(10) << "predirty_journal_parents"
2094 << (do_parent_mtime
? " do_parent_mtime":"")
2095 << " linkunlink=" << linkunlink
2096 << (primary_dn
? " primary_dn":" remote_dn")
2097 << (shallow
? " SHALLOW":"")
2098 << " follows " << cfollows
2099 << " " << *in
<< dendl
;
2103 parent
= in
->get_projected_parent_dn()->get_dir();
2106 if (flags
== 0 && linkunlink
== 0) {
2107 dout(10) << " no flags/linkunlink, just adding dir context to blob(s)" << dendl
;
2108 blob
->add_dir_context(parent
);
2112 // build list of inodes to wrlock, dirty, and update
2115 CDentry
*parentdn
= NULL
;
2118 //assert(cur->is_auth() || !primary_dn); // this breaks the rename auth twiddle hack
2119 assert(parent
->is_auth());
2121 // opportunistically adjust parent dirfrag
2122 CInode
*pin
= parent
->get_inode();
2125 mut
->auth_pin(parent
);
2126 mut
->add_projected_fnode(parent
);
2128 fnode_t
*pf
= parent
->project_fnode();
2129 pf
->version
= parent
->pre_dirty();
2131 if (do_parent_mtime
|| linkunlink
) {
2132 assert(mut
->wrlocks
.count(&pin
->filelock
));
2133 assert(mut
->wrlocks
.count(&pin
->nestlock
));
2134 assert(cfollows
== CEPH_NOSNAP
);
2136 // update stale fragstat/rstat?
2137 parent
->resync_accounted_fragstat();
2138 parent
->resync_accounted_rstat();
2140 if (do_parent_mtime
) {
2141 pf
->fragstat
.mtime
= mut
->get_op_stamp();
2142 pf
->fragstat
.change_attr
++;
2143 dout(10) << "predirty_journal_parents bumping change_attr to " << pf
->fragstat
.change_attr
<< " on " << parent
<< dendl
;
2144 if (pf
->fragstat
.mtime
> pf
->rstat
.rctime
) {
2145 dout(10) << "predirty_journal_parents updating mtime on " << *parent
<< dendl
;
2146 pf
->rstat
.rctime
= pf
->fragstat
.mtime
;
2148 dout(10) << "predirty_journal_parents updating mtime UNDERWATER on " << *parent
<< dendl
;
2152 dout(10) << "predirty_journal_parents updating size on " << *parent
<< dendl
;
2154 pf
->fragstat
.nsubdirs
+= linkunlink
;
2155 //pf->rstat.rsubdirs += linkunlink;
2157 pf
->fragstat
.nfiles
+= linkunlink
;
2158 //pf->rstat.rfiles += linkunlink;
2165 // don't update parent this pass
2166 } else if (!linkunlink
&& !(pin
->nestlock
.can_wrlock(-1) &&
2167 pin
->versionlock
.can_wrlock())) {
2168 dout(20) << " unwritable parent nestlock " << pin
->nestlock
2169 << ", marking dirty rstat on " << *cur
<< dendl
;
2170 cur
->mark_dirty_rstat();
2172 // if we don't hold a wrlock reference on this nestlock, take one,
2173 // because we are about to write into the dirfrag fnode and that needs
2174 // to commit before the lock can cycle.
2176 assert(pin
->nestlock
.get_num_wrlocks() || mut
->is_slave());
2179 if (mut
->wrlocks
.count(&pin
->nestlock
) == 0) {
2180 dout(10) << " taking wrlock on " << pin
->nestlock
<< " on " << *pin
<< dendl
;
2181 mds
->locker
->wrlock_force(&pin
->nestlock
, mut
);
2184 // now we can project the inode rstat diff the dirfrag
2185 SnapRealm
*prealm
= pin
->find_snaprealm();
2187 snapid_t follows
= cfollows
;
2188 if (follows
== CEPH_NOSNAP
)
2189 follows
= prealm
->get_newest_seq();
2191 snapid_t first
= follows
+1;
2193 // first, if the frag is stale, bring it back in sync.
2194 parent
->resync_accounted_rstat();
2196 // now push inode rstats into frag
2197 project_rstat_inode_to_frag(cur
, parent
, first
, linkunlink
, prealm
);
2198 cur
->clear_dirty_rstat();
2202 if (!pin
->is_auth() || (!mut
->is_auth_pinned(pin
) && !pin
->can_auth_pin())) {
2203 dout(10) << "predirty_journal_parents !auth or ambig or can't authpin on " << *pin
<< dendl
;
2207 // delay propagating until later?
2208 if (!stop
&& !first
&&
2209 g_conf
->mds_dirstat_min_interval
> 0) {
2210 double since_last_prop
= mut
->get_mds_stamp() - pin
->last_dirstat_prop
;
2211 if (since_last_prop
< g_conf
->mds_dirstat_min_interval
) {
2212 dout(10) << "predirty_journal_parents last prop " << since_last_prop
2213 << " < " << g_conf
->mds_dirstat_min_interval
2214 << ", stopping" << dendl
;
2217 dout(10) << "predirty_journal_parents last prop " << since_last_prop
<< " ago, continuing" << dendl
;
2221 // can cast only because i'm passing nowait=true in the sole user
2222 MDRequestRef mdmut
= static_cast<MDRequestImpl
*>(mut
.get());
2224 mut
->wrlocks
.count(&pin
->nestlock
) == 0 &&
2225 (!pin
->versionlock
.can_wrlock() || // make sure we can take versionlock, too
2227 !mds
->locker
->wrlock_start(&pin
->nestlock
, mdmut
, true)
2228 )) { // ** do not initiate.. see above comment **
2229 dout(10) << "predirty_journal_parents can't wrlock one of " << pin
->versionlock
<< " or " << pin
->nestlock
2230 << " on " << *pin
<< dendl
;
2234 dout(10) << "predirty_journal_parents stop. marking nestlock on " << *pin
<< dendl
;
2235 mds
->locker
->mark_updated_scatterlock(&pin
->nestlock
);
2236 mut
->ls
->dirty_dirfrag_nest
.push_back(&pin
->item_dirty_dirfrag_nest
);
2237 mut
->add_updated_lock(&pin
->nestlock
);
2238 if (do_parent_mtime
|| linkunlink
) {
2239 mds
->locker
->mark_updated_scatterlock(&pin
->filelock
);
2240 mut
->ls
->dirty_dirfrag_dir
.push_back(&pin
->item_dirty_dirfrag_dir
);
2241 mut
->add_updated_lock(&pin
->filelock
);
2245 if (!mut
->wrlocks
.count(&pin
->versionlock
))
2246 mds
->locker
->local_wrlock_grab(&pin
->versionlock
, mut
);
2248 assert(mut
->wrlocks
.count(&pin
->nestlock
) ||
2251 pin
->last_dirstat_prop
= mut
->get_mds_stamp();
2255 mut
->add_projected_inode(pin
);
2256 lsi
.push_front(pin
);
2258 pin
->pre_cow_old_inode(); // avoid cow mayhem!
2260 inode_t
*pi
= pin
->project_inode();
2261 pi
->version
= pin
->pre_dirty();
2264 if (do_parent_mtime
|| linkunlink
) {
2265 dout(20) << "predirty_journal_parents add_delta " << pf
->fragstat
<< dendl
;
2266 dout(20) << "predirty_journal_parents - " << pf
->accounted_fragstat
<< dendl
;
2267 bool touched_mtime
= false, touched_chattr
= false;
2268 pi
->dirstat
.add_delta(pf
->fragstat
, pf
->accounted_fragstat
, &touched_mtime
, &touched_chattr
);
2269 pf
->accounted_fragstat
= pf
->fragstat
;
2271 pi
->mtime
= pi
->ctime
= pi
->dirstat
.mtime
;
2273 pi
->change_attr
= pi
->dirstat
.change_attr
;
2274 dout(20) << "predirty_journal_parents gives " << pi
->dirstat
<< " on " << *pin
<< dendl
;
2276 if (parent
->get_frag() == frag_t()) { // i.e., we are the only frag
2277 if (pi
->dirstat
.size() < 0)
2278 assert(!"negative dirstat size" == g_conf
->mds_verify_scatter
);
2279 if (pi
->dirstat
.size() != pf
->fragstat
.size()) {
2280 mds
->clog
->error() << "unmatched fragstat size on single dirfrag "
2281 << parent
->dirfrag() << ", inode has " << pi
->dirstat
2282 << ", dirfrag has " << pf
->fragstat
;
2284 // trust the dirfrag for now
2285 pi
->dirstat
= pf
->fragstat
;
2287 assert(!"unmatched fragstat size" == g_conf
->mds_verify_scatter
);
2293 * the rule here is to follow the _oldest_ parent with dirty rstat
2294 * data. if we don't propagate all data, we add ourselves to the
2295 * nudge list. that way all rstat data will (eventually) get
2296 * pushed up the tree.
2298 * actually, no. for now, silently drop rstats for old parents. we need
2299 * hard link backpointers to do the above properly.
2305 parentdn
= pin
->get_projected_parent_dn();
2309 dout(10) << "predirty_journal_parents frag->inode on " << *parent
<< dendl
;
2311 // first, if the frag is stale, bring it back in sync.
2312 parent
->resync_accounted_rstat();
2314 if (g_conf
->mds_snap_rstat
) {
2315 for (compact_map
<snapid_t
,old_rstat_t
>::iterator p
= parent
->dirty_old_rstat
.begin();
2316 p
!= parent
->dirty_old_rstat
.end();
2318 project_rstat_frag_to_inode(p
->second
.rstat
, p
->second
.accounted_rstat
, p
->second
.first
,
2319 p
->first
, pin
, true);//false);
2321 parent
->dirty_old_rstat
.clear();
2322 project_rstat_frag_to_inode(pf
->rstat
, pf
->accounted_rstat
, parent
->first
, CEPH_NOSNAP
, pin
, true);//false);
2324 pf
->accounted_rstat
= pf
->rstat
;
2326 if (parent
->get_frag() == frag_t()) { // i.e., we are the only frag
2327 if (pi
->rstat
.rbytes
!= pf
->rstat
.rbytes
) {
2328 mds
->clog
->error() << "unmatched rstat rbytes on single dirfrag "
2329 << parent
->dirfrag() << ", inode has " << pi
->rstat
2330 << ", dirfrag has " << pf
->rstat
;
2332 // trust the dirfrag for now
2333 pi
->rstat
= pf
->rstat
;
2335 assert(!"unmatched rstat rbytes" == g_conf
->mds_verify_scatter
);
2339 parent
->check_rstats();
2340 broadcast_quota_to_client(pin
);
2343 parent
= parentdn
->get_dir();
2345 do_parent_mtime
= false;
2350 // now, stick it in the blob
2352 assert(parent
->is_auth());
2353 blob
->add_dir_context(parent
);
2354 blob
->add_dir(parent
, true);
2355 for (list
<CInode
*>::iterator p
= lsi
.begin();
2359 journal_dirty_inode(mut
.get(), blob
, cur
);
2368 // ===================================
2373 * some handlers for master requests with slaves. we need to make
2374 * sure slaves journal commits before we forget we mastered them and
2375 * remove them from the uncommitted_masters map (used during recovery
2376 * to commit|abort slaves).
2378 struct C_MDC_CommittedMaster
: public MDCacheLogContext
{
2380 C_MDC_CommittedMaster(MDCache
*s
, metareqid_t r
) : MDCacheLogContext(s
), reqid(r
) {}
2381 void finish(int r
) override
{
2382 mdcache
->_logged_master_commit(reqid
);
2386 void MDCache::log_master_commit(metareqid_t reqid
)
2388 dout(10) << "log_master_commit " << reqid
<< dendl
;
2389 uncommitted_masters
[reqid
].committing
= true;
2390 mds
->mdlog
->start_submit_entry(new ECommitted(reqid
),
2391 new C_MDC_CommittedMaster(this, reqid
));
2394 void MDCache::_logged_master_commit(metareqid_t reqid
)
2396 dout(10) << "_logged_master_commit " << reqid
<< dendl
;
2397 assert(uncommitted_masters
.count(reqid
));
2398 uncommitted_masters
[reqid
].ls
->uncommitted_masters
.erase(reqid
);
2399 mds
->queue_waiters(uncommitted_masters
[reqid
].waiters
);
2400 uncommitted_masters
.erase(reqid
);
2405 void MDCache::committed_master_slave(metareqid_t r
, mds_rank_t from
)
2407 dout(10) << "committed_master_slave mds." << from
<< " on " << r
<< dendl
;
2408 assert(uncommitted_masters
.count(r
));
2409 uncommitted_masters
[r
].slaves
.erase(from
);
2410 if (!uncommitted_masters
[r
].recovering
&& uncommitted_masters
[r
].slaves
.empty())
2411 log_master_commit(r
);
2414 void MDCache::logged_master_update(metareqid_t reqid
)
2416 dout(10) << "logged_master_update " << reqid
<< dendl
;
2417 assert(uncommitted_masters
.count(reqid
));
2418 uncommitted_masters
[reqid
].safe
= true;
2419 if (pending_masters
.count(reqid
)) {
2420 pending_masters
.erase(reqid
);
2421 if (pending_masters
.empty())
2422 process_delayed_resolve();
2427 * Master may crash after receiving all slaves' commit acks, but before journalling
2428 * the final commit. Slaves may crash after journalling the slave commit, but before
2429 * sending commit ack to the master. Commit masters with no uncommitted slave when
2432 void MDCache::finish_committed_masters()
2434 for (map
<metareqid_t
, umaster
>::iterator p
= uncommitted_masters
.begin();
2435 p
!= uncommitted_masters
.end();
2437 p
->second
.recovering
= false;
2438 if (!p
->second
.committing
&& p
->second
.slaves
.empty()) {
2439 dout(10) << "finish_committed_masters " << p
->first
<< dendl
;
2440 log_master_commit(p
->first
);
2446 * at end of resolve... we must journal a commit|abort for all slave
2447 * updates, before moving on.
2449 * this is so that the master can safely journal ECommitted on ops it
2450 * masters when it reaches up:active (all other recovering nodes must
2451 * complete resolve before that happens).
2453 struct C_MDC_SlaveCommit
: public MDCacheLogContext
{
2456 C_MDC_SlaveCommit(MDCache
*c
, int f
, metareqid_t r
) : MDCacheLogContext(c
), from(f
), reqid(r
) {}
2457 void finish(int r
) override
{
2458 mdcache
->_logged_slave_commit(from
, reqid
);
2462 void MDCache::_logged_slave_commit(mds_rank_t from
, metareqid_t reqid
)
2464 dout(10) << "_logged_slave_commit from mds." << from
<< " " << reqid
<< dendl
;
2467 MMDSSlaveRequest
*req
= new MMDSSlaveRequest(reqid
, 0, MMDSSlaveRequest::OP_COMMITTED
);
2468 mds
->send_message_mds(req
, from
);
2476 // ====================================================================
2477 // import map, recovery
2479 void MDCache::_move_subtree_map_bound(dirfrag_t df
, dirfrag_t oldparent
, dirfrag_t newparent
,
2480 map
<dirfrag_t
,vector
<dirfrag_t
> >& subtrees
)
2482 if (subtrees
.count(oldparent
)) {
2483 vector
<dirfrag_t
>& v
= subtrees
[oldparent
];
2484 dout(10) << " removing " << df
<< " from " << oldparent
<< " bounds " << v
<< dendl
;
2485 for (vector
<dirfrag_t
>::iterator it
= v
.begin(); it
!= v
.end(); ++it
)
2491 if (subtrees
.count(newparent
)) {
2492 vector
<dirfrag_t
>& v
= subtrees
[newparent
];
2493 dout(10) << " adding " << df
<< " to " << newparent
<< " bounds " << v
<< dendl
;
2498 ESubtreeMap
*MDCache::create_subtree_map()
2500 dout(10) << "create_subtree_map " << num_subtrees() << " subtrees, "
2501 << num_subtrees_fullauth() << " fullauth"
2506 ESubtreeMap
*le
= new ESubtreeMap();
2507 mds
->mdlog
->_start_entry(le
);
2509 map
<dirfrag_t
, CDir
*> dirs_to_add
;
2512 CDir
* mydir
= myin
->get_dirfrag(frag_t());
2513 dirs_to_add
[mydir
->dirfrag()] = mydir
;
2516 // include all auth subtrees, and their bounds.
2517 // and a spanning tree to tie it to the root.
2518 for (map
<CDir
*, set
<CDir
*> >::iterator p
= subtrees
.begin();
2519 p
!= subtrees
.end();
2521 CDir
*dir
= p
->first
;
2523 // journal subtree as "ours" if we are
2526 // me, !me (may be importing and ambiguous!)
2530 if (dir
->get_dir_auth().first
!= mds
->get_nodeid())
2533 if (migrator
->is_ambiguous_import(dir
->dirfrag()) ||
2534 my_ambiguous_imports
.count(dir
->dirfrag())) {
2535 dout(15) << " ambig subtree " << *dir
<< dendl
;
2536 le
->ambiguous_subtrees
.insert(dir
->dirfrag());
2538 dout(15) << " subtree " << *dir
<< dendl
;
2541 dirs_to_add
[dir
->dirfrag()] = dir
;
2542 le
->subtrees
[dir
->dirfrag()].clear();
2546 for (set
<CDir
*>::iterator q
= p
->second
.begin();
2547 q
!= p
->second
.end();
2550 dout(15) << " subtree bound " << *bound
<< dendl
;
2551 dirs_to_add
[bound
->dirfrag()] = bound
;
2552 le
->subtrees
[dir
->dirfrag()].push_back(bound
->dirfrag());
2556 // apply projected renames
2557 for (map
<CInode
*,list
<pair
<CDir
*,CDir
*> > >::iterator p
= projected_subtree_renames
.begin();
2558 p
!= projected_subtree_renames
.end();
2560 for (list
<pair
<CDir
*,CDir
*> >::iterator q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
2561 CInode
*diri
= p
->first
;
2562 CDir
*olddir
= q
->first
;
2563 CDir
*newdir
= q
->second
;
2564 dout(10) << " adjusting for projected rename of " << *diri
<< " to " << *newdir
<< dendl
;
2567 diri
->get_dirfrags(dfls
);
2568 for (list
<CDir
*>::iterator p
= dfls
.begin(); p
!= dfls
.end(); ++p
) {
2570 dout(10) << "dirfrag " << dir
->dirfrag() << " " << *dir
<< dendl
;
2571 CDir
*oldparent
= get_projected_subtree_root(olddir
);
2572 dout(10) << " old parent " << oldparent
->dirfrag() << " " << *oldparent
<< dendl
;
2573 CDir
*newparent
= get_projected_subtree_root(newdir
);
2574 dout(10) << " new parent " << newparent
->dirfrag() << " " << *newparent
<< dendl
;
2576 if (oldparent
== newparent
) {
2577 dout(10) << "parent unchanged for " << dir
->dirfrag() << " at "
2578 << oldparent
->dirfrag() << dendl
;
2582 if (dir
->is_subtree_root()) {
2583 if (le
->subtrees
.count(newparent
->dirfrag()) &&
2584 oldparent
->get_dir_auth() != newparent
->get_dir_auth())
2585 dirs_to_add
[dir
->dirfrag()] = dir
;
2586 // children are fine. change parent.
2587 _move_subtree_map_bound(dir
->dirfrag(), oldparent
->dirfrag(), newparent
->dirfrag(),
2592 if (oldparent
->get_dir_auth() != newparent
->get_dir_auth()) {
2593 dout(10) << " creating subtree for " << dir
->dirfrag() << dendl
;
2594 // if oldparent is auth, subtree is mine; include it.
2595 if (le
->subtrees
.count(oldparent
->dirfrag())) {
2596 dirs_to_add
[dir
->dirfrag()] = dir
;
2597 le
->subtrees
[dir
->dirfrag()].clear();
2599 // if newparent is auth, subtree is a new bound
2600 if (le
->subtrees
.count(newparent
->dirfrag())) {
2601 dirs_to_add
[dir
->dirfrag()] = dir
;
2602 le
->subtrees
[newparent
->dirfrag()].push_back(dir
->dirfrag()); // newparent is auth; new bound
2607 // see if any old bounds move to the new parent.
2608 for (set
<CDir
*>::iterator p
= subtrees
[oldparent
].begin();
2609 p
!= subtrees
[oldparent
].end();
2612 if (dir
->contains(bound
->get_parent_dir()))
2613 _move_subtree_map_bound(bound
->dirfrag(), oldparent
->dirfrag(), newparent
->dirfrag(),
2621 // simplify the journaled map. our in memory map may have more
2622 // subtrees than needed due to migrations that are just getting
2623 // started or just completing. but on replay, the "live" map will
2624 // be simple and we can do a straight comparison.
2625 for (map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator p
= le
->subtrees
.begin(); p
!= le
->subtrees
.end(); ++p
) {
2626 if (le
->ambiguous_subtrees
.count(p
->first
))
2629 while (i
< p
->second
.size()) {
2630 dirfrag_t b
= p
->second
[i
];
2631 if (le
->subtrees
.count(b
) &&
2632 le
->ambiguous_subtrees
.count(b
) == 0) {
2633 vector
<dirfrag_t
>& bb
= le
->subtrees
[b
];
2634 dout(10) << "simplify: " << p
->first
<< " swallowing " << b
<< " with bounds " << bb
<< dendl
;
2635 for (vector
<dirfrag_t
>::iterator r
= bb
.begin(); r
!= bb
.end(); ++r
)
2636 p
->second
.push_back(*r
);
2637 dirs_to_add
.erase(b
);
2638 le
->subtrees
.erase(b
);
2639 p
->second
.erase(p
->second
.begin() + i
);
2646 for (auto p
: dirs_to_add
) {
2647 CDir
*dir
= p
.second
;
2648 le
->metablob
.add_dir_context(dir
, EMetaBlob::TO_ROOT
);
2649 le
->metablob
.add_dir(dir
, false);
2652 dout(15) << " subtrees " << le
->subtrees
<< dendl
;
2653 dout(15) << " ambiguous_subtrees " << le
->ambiguous_subtrees
<< dendl
;
2655 //le->metablob.print(cout);
2656 le
->expire_pos
= mds
->mdlog
->journaler
->get_expire_pos();
2660 void MDCache::dump_resolve_status(Formatter
*f
) const
2662 f
->open_object_section("resolve_status");
2663 f
->dump_stream("resolve_gather") << resolve_gather
;
2664 f
->dump_stream("resolve_ack_gather") << resolve_gather
;
2668 void MDCache::resolve_start(MDSInternalContext
*resolve_done_
)
2670 dout(10) << "resolve_start" << dendl
;
2671 assert(!resolve_done
);
2672 resolve_done
.reset(resolve_done_
);
2674 if (mds
->mdsmap
->get_root() != mds
->get_nodeid()) {
2675 // if we don't have the root dir, adjust it to UNKNOWN. during
2676 // resolve we want mds0 to explicit claim the portion of it that
2677 // it owns, so that anything beyond its bounds get left as
2679 CDir
*rootdir
= root
->get_dirfrag(frag_t());
2681 adjust_subtree_auth(rootdir
, CDIR_AUTH_UNKNOWN
);
2683 resolve_gather
= recovery_set
;
2686 void MDCache::send_resolves()
2688 send_slave_resolves();
2689 if (!resolve_ack_gather
.empty()) {
2690 dout(10) << "send_resolves still waiting for resolve ack from ("
2691 << resolve_ack_gather
<< ")" << dendl
;
2694 if (!need_resolve_rollback
.empty()) {
2695 dout(10) << "send_resolves still waiting for rollback to commit on ("
2696 << need_resolve_rollback
<< ")" << dendl
;
2699 send_subtree_resolves();
2702 void MDCache::send_slave_resolves()
2704 dout(10) << "send_slave_resolves" << dendl
;
2706 map
<mds_rank_t
, MMDSResolve
*> resolves
;
2708 if (mds
->is_resolve()) {
2709 for (map
<mds_rank_t
, map
<metareqid_t
, MDSlaveUpdate
*> >::iterator p
= uncommitted_slave_updates
.begin();
2710 p
!= uncommitted_slave_updates
.end();
2712 resolves
[p
->first
] = new MMDSResolve
;
2713 for (map
<metareqid_t
, MDSlaveUpdate
*>::iterator q
= p
->second
.begin();
2714 q
!= p
->second
.end();
2716 dout(10) << " including uncommitted " << q
->first
<< dendl
;
2717 resolves
[p
->first
]->add_slave_request(q
->first
, false);
2721 set
<mds_rank_t
> resolve_set
;
2722 mds
->mdsmap
->get_mds_set(resolve_set
, MDSMap::STATE_RESOLVE
);
2723 for (ceph::unordered_map
<metareqid_t
, MDRequestRef
>::iterator p
= active_requests
.begin();
2724 p
!= active_requests
.end();
2726 MDRequestRef
& mdr
= p
->second
;
2727 if (!mdr
->is_slave())
2729 if (!mdr
->slave_did_prepare() && !mdr
->committing
) {
2732 mds_rank_t master
= mdr
->slave_to_mds
;
2733 if (resolve_set
.count(master
) || is_ambiguous_slave_update(p
->first
, master
)) {
2734 dout(10) << " including uncommitted " << *mdr
<< dendl
;
2735 if (!resolves
.count(master
))
2736 resolves
[master
] = new MMDSResolve
;
2737 if (!mdr
->committing
&&
2738 mdr
->has_more() && mdr
->more()->is_inode_exporter
) {
2739 // re-send cap exports
2740 CInode
*in
= mdr
->more()->rename_inode
;
2741 map
<client_t
, Capability::Export
> cap_map
;
2742 in
->export_client_caps(cap_map
);
2744 ::encode(in
->ino(), bl
);
2745 ::encode(cap_map
, bl
);
2746 resolves
[master
]->add_slave_request(p
->first
, bl
);
2748 resolves
[master
]->add_slave_request(p
->first
, mdr
->committing
);
2754 for (map
<mds_rank_t
, MMDSResolve
*>::iterator p
= resolves
.begin();
2755 p
!= resolves
.end();
2757 dout(10) << "sending slave resolve to mds." << p
->first
<< dendl
;
2758 mds
->send_message_mds(p
->second
, p
->first
);
2759 resolve_ack_gather
.insert(p
->first
);
2763 void MDCache::send_subtree_resolves()
2765 dout(10) << "send_subtree_resolves" << dendl
;
2767 if (migrator
->is_exporting() || migrator
->is_importing()) {
2768 dout(7) << "send_subtree_resolves waiting, imports/exports still in progress" << dendl
;
2769 migrator
->show_importing();
2770 migrator
->show_exporting();
2771 resolves_pending
= true;
2775 map
<mds_rank_t
, MMDSResolve
*> resolves
;
2776 for (set
<mds_rank_t
>::iterator p
= recovery_set
.begin();
2777 p
!= recovery_set
.end();
2779 if (*p
== mds
->get_nodeid())
2781 if (mds
->is_resolve() || mds
->mdsmap
->is_resolve(*p
))
2782 resolves
[*p
] = new MMDSResolve
;
2785 map
<dirfrag_t
, vector
<dirfrag_t
> > my_subtrees
;
2786 map
<dirfrag_t
, vector
<dirfrag_t
> > my_ambig_imports
;
2789 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
2790 p
!= subtrees
.end();
2792 CDir
*dir
= p
->first
;
2794 // only our subtrees
2795 if (dir
->authority().first
!= mds
->get_nodeid())
2798 if (mds
->is_resolve() && my_ambiguous_imports
.count(dir
->dirfrag()))
2799 continue; // we'll add it below
2801 if (migrator
->is_ambiguous_import(dir
->dirfrag())) {
2802 // ambiguous (mid-import)
2804 get_subtree_bounds(dir
, bounds
);
2805 vector
<dirfrag_t
> dfls
;
2806 for (set
<CDir
*>::iterator q
= bounds
.begin(); q
!= bounds
.end(); ++q
)
2807 dfls
.push_back((*q
)->dirfrag());
2809 my_ambig_imports
[dir
->dirfrag()] = dfls
;
2810 dout(10) << " ambig " << dir
->dirfrag() << " " << dfls
<< dendl
;
2813 for (map
<mds_rank_t
, MMDSResolve
*>::iterator q
= resolves
.begin();
2814 q
!= resolves
.end();
2816 resolves
[q
->first
]->add_subtree(dir
->dirfrag());
2818 vector
<dirfrag_t
> dfls
;
2819 for (set
<CDir
*>::iterator q
= subtrees
[dir
].begin();
2820 q
!= subtrees
[dir
].end();
2823 dfls
.push_back(bound
->dirfrag());
2826 my_subtrees
[dir
->dirfrag()] = dfls
;
2827 dout(10) << " claim " << dir
->dirfrag() << " " << dfls
<< dendl
;
2832 for (map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator p
= my_ambiguous_imports
.begin();
2833 p
!= my_ambiguous_imports
.end();
2835 my_ambig_imports
[p
->first
] = p
->second
;
2836 dout(10) << " ambig " << p
->first
<< " " << p
->second
<< dendl
;
2839 // simplify the claimed subtree.
2840 for (auto p
= my_subtrees
.begin(); p
!= my_subtrees
.end(); ++p
) {
2842 while (i
< p
->second
.size()) {
2843 dirfrag_t b
= p
->second
[i
];
2844 if (my_subtrees
.count(b
)) {
2845 vector
<dirfrag_t
>& bb
= my_subtrees
[b
];
2846 dout(10) << " simplify: " << p
->first
<< " swallowing " << b
<< " with bounds " << bb
<< dendl
;
2847 for (vector
<dirfrag_t
>::iterator r
= bb
.begin(); r
!= bb
.end(); ++r
)
2848 p
->second
.push_back(*r
);
2849 my_subtrees
.erase(b
);
2850 p
->second
.erase(p
->second
.begin() + i
);
2858 for (map
<mds_rank_t
, MMDSResolve
*>::iterator p
= resolves
.begin();
2859 p
!= resolves
.end();
2861 MMDSResolve
* m
= p
->second
;
2862 m
->subtrees
= my_subtrees
;
2863 m
->ambiguous_imports
= my_ambig_imports
;
2864 dout(10) << "sending subtee resolve to mds." << p
->first
<< dendl
;
2865 mds
->send_message_mds(m
, p
->first
);
2867 resolves_pending
= false;
2870 void MDCache::handle_mds_failure(mds_rank_t who
)
2872 dout(7) << "handle_mds_failure mds." << who
<< dendl
;
2874 dout(1) << "handle_mds_failure mds." << who
<< " : recovery peers are " << recovery_set
<< dendl
;
2876 resolve_gather
.insert(who
);
2877 discard_delayed_resolve(who
);
2878 ambiguous_slave_updates
.erase(who
);
2880 rejoin_gather
.insert(who
);
2881 rejoin_sent
.erase(who
); // i need to send another
2882 rejoin_ack_sent
.erase(who
); // i need to send another
2883 rejoin_ack_gather
.erase(who
); // i'll need/get another.
2885 dout(10) << " resolve_gather " << resolve_gather
<< dendl
;
2886 dout(10) << " resolve_ack_gather " << resolve_ack_gather
<< dendl
;
2887 dout(10) << " rejoin_sent " << rejoin_sent
<< dendl
;
2888 dout(10) << " rejoin_gather " << rejoin_gather
<< dendl
;
2889 dout(10) << " rejoin_ack_gather " << rejoin_ack_gather
<< dendl
;
2892 // tell the migrator too.
2893 migrator
->handle_mds_failure_or_stop(who
);
2895 // tell the balancer too.
2896 mds
->balancer
->handle_mds_failure(who
);
2898 // clean up any requests slave to/from this node
2899 list
<MDRequestRef
> finish
;
2900 for (ceph::unordered_map
<metareqid_t
, MDRequestRef
>::iterator p
= active_requests
.begin();
2901 p
!= active_requests
.end();
2903 MDRequestRef
& mdr
= p
->second
;
2904 // slave to the failed node?
2905 if (mdr
->slave_to_mds
== who
) {
2906 if (mdr
->slave_did_prepare()) {
2907 dout(10) << " slave request " << *mdr
<< " uncommitted, will resolve shortly" << dendl
;
2908 if (is_ambiguous_slave_update(p
->first
, mdr
->slave_to_mds
))
2909 remove_ambiguous_slave_update(p
->first
, mdr
->slave_to_mds
);
2911 if (!mdr
->more()->waiting_on_slave
.empty()) {
2912 assert(mdr
->more()->srcdn_auth_mds
== mds
->get_nodeid());
2913 // will rollback, no need to wait
2914 if (mdr
->slave_request
) {
2915 mdr
->slave_request
->put();
2916 mdr
->slave_request
= 0;
2918 mdr
->more()->waiting_on_slave
.clear();
2920 } else if (!mdr
->committing
) {
2921 dout(10) << " slave request " << *mdr
<< " has no prepare, finishing up" << dendl
;
2922 if (mdr
->slave_request
|| mdr
->slave_rolling_back())
2923 mdr
->aborted
= true;
2925 finish
.push_back(mdr
);
2929 if (mdr
->is_slave() && mdr
->slave_did_prepare()) {
2930 if (mdr
->more()->waiting_on_slave
.count(who
)) {
2931 assert(mdr
->more()->srcdn_auth_mds
== mds
->get_nodeid());
2932 dout(10) << " slave request " << *mdr
<< " no longer need rename notity ack from mds."
2934 mdr
->more()->waiting_on_slave
.erase(who
);
2935 if (mdr
->more()->waiting_on_slave
.empty() && mdr
->slave_request
)
2936 mds
->queue_waiter(new C_MDS_RetryRequest(this, mdr
));
2939 if (mdr
->more()->srcdn_auth_mds
== who
&&
2940 mds
->mdsmap
->is_clientreplay_or_active_or_stopping(mdr
->slave_to_mds
)) {
2941 // rename srcdn's auth mds failed, resolve even I'm a survivor.
2942 dout(10) << " slave request " << *mdr
<< " uncommitted, will resolve shortly" << dendl
;
2943 add_ambiguous_slave_update(p
->first
, mdr
->slave_to_mds
);
2945 } else if (mdr
->slave_request
) {
2946 MMDSSlaveRequest
*slave_req
= mdr
->slave_request
;
2947 // FIXME: Slave rename request can arrive after we notice mds failure.
2948 // This can cause mds to crash (does not affect integrity of FS).
2949 if (slave_req
->get_op() == MMDSSlaveRequest::OP_RENAMEPREP
&&
2950 slave_req
->srcdn_auth
== who
)
2951 slave_req
->mark_interrupted();
2954 // failed node is slave?
2955 if (mdr
->is_master() && !mdr
->committing
) {
2956 if (mdr
->more()->srcdn_auth_mds
== who
) {
2957 dout(10) << " master request " << *mdr
<< " waiting for rename srcdn's auth mds."
2958 << who
<< " to recover" << dendl
;
2959 assert(mdr
->more()->witnessed
.count(who
) == 0);
2960 if (mdr
->more()->is_ambiguous_auth
)
2961 mdr
->clear_ambiguous_auth();
2962 // rename srcdn's auth mds failed, all witnesses will rollback
2963 mdr
->more()->witnessed
.clear();
2964 pending_masters
.erase(p
->first
);
2967 if (mdr
->more()->witnessed
.count(who
)) {
2968 mds_rank_t srcdn_auth
= mdr
->more()->srcdn_auth_mds
;
2969 if (srcdn_auth
>= 0 && mdr
->more()->waiting_on_slave
.count(srcdn_auth
)) {
2970 dout(10) << " master request " << *mdr
<< " waiting for rename srcdn's auth mds."
2971 << mdr
->more()->srcdn_auth_mds
<< " to reply" << dendl
;
2972 // waiting for the slave (rename srcdn's auth mds), delay sending resolve ack
2973 // until either the request is committing or the slave also fails.
2974 assert(mdr
->more()->waiting_on_slave
.size() == 1);
2975 pending_masters
.insert(p
->first
);
2977 dout(10) << " master request " << *mdr
<< " no longer witnessed by slave mds."
2978 << who
<< " to recover" << dendl
;
2979 if (srcdn_auth
>= 0)
2980 assert(mdr
->more()->witnessed
.count(srcdn_auth
) == 0);
2982 // discard this peer's prepare (if any)
2983 mdr
->more()->witnessed
.erase(who
);
2987 if (mdr
->more()->waiting_on_slave
.count(who
)) {
2988 dout(10) << " master request " << *mdr
<< " waiting for slave mds." << who
2989 << " to recover" << dendl
;
2990 // retry request when peer recovers
2991 mdr
->more()->waiting_on_slave
.erase(who
);
2992 if (mdr
->more()->waiting_on_slave
.empty())
2993 mds
->wait_for_active_peer(who
, new C_MDS_RetryRequest(this, mdr
));
2996 if (mdr
->locking
&& mdr
->locking_target_mds
== who
)
2997 mdr
->finish_locking(mdr
->locking
);
3001 for (map
<metareqid_t
, umaster
>::iterator p
= uncommitted_masters
.begin();
3002 p
!= uncommitted_masters
.end();
3004 // The failed MDS may have already committed the slave update
3005 if (p
->second
.slaves
.count(who
)) {
3006 p
->second
.recovering
= true;
3007 p
->second
.slaves
.erase(who
);
3011 while (!finish
.empty()) {
3012 dout(10) << "cleaning up slave request " << *finish
.front() << dendl
;
3013 request_finish(finish
.front());
3017 kick_find_ino_peers(who
);
3018 kick_open_ino_peers(who
);
3020 for (map
<dirfrag_t
,fragment_info_t
>::iterator p
= fragments
.begin();
3021 p
!= fragments
.end(); ) {
3022 dirfrag_t df
= p
->first
;
3023 fragment_info_t
& info
= p
->second
;
3025 if (info
.is_fragmenting())
3027 dout(10) << "cancelling fragment " << df
<< " bit " << info
.bits
<< dendl
;
3029 info
.dirs
.swap(dirs
);
3030 fragments
.erase(df
);
3031 fragment_unmark_unfreeze_dirs(dirs
);
3034 // MDCache::shutdown_export_strays() always exports strays to mds.0
3035 if (who
== mds_rank_t(0))
3036 shutdown_exported_strays
.clear();
3042 * handle_mds_recovery - called on another node's transition
3043 * from resolve -> active.
3045 void MDCache::handle_mds_recovery(mds_rank_t who
)
3047 dout(7) << "handle_mds_recovery mds." << who
<< dendl
;
3049 // exclude all discover waiters. kick_discovers() will do the job
3050 static const uint64_t i_mask
= CInode::WAIT_ANY_MASK
& ~CInode::WAIT_DIR
;
3051 static const uint64_t d_mask
= CDir::WAIT_ANY_MASK
& ~CDir::WAIT_DENTRY
;
3053 list
<MDSInternalContextBase
*> waiters
;
3055 // wake up any waiters in their subtrees
3056 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
3057 p
!= subtrees
.end();
3059 CDir
*dir
= p
->first
;
3061 if (dir
->authority().first
!= who
||
3062 dir
->authority().second
== mds
->get_nodeid())
3064 assert(!dir
->is_auth());
3070 while (!q
.empty()) {
3071 CDir
*d
= q
.front();
3073 d
->take_waiting(d_mask
, waiters
);
3075 // inode waiters too
3076 for (CDir::map_t::iterator p
= d
->items
.begin();
3077 p
!= d
->items
.end();
3079 CDentry
*dn
= p
->second
;
3080 CDentry::linkage_t
*dnl
= dn
->get_linkage();
3081 if (dnl
->is_primary()) {
3082 dnl
->get_inode()->take_waiting(i_mask
, waiters
);
3086 dnl
->get_inode()->get_dirfrags(ls
);
3087 for (list
<CDir
*>::iterator p
= ls
.begin();
3091 if (!subdir
->is_subtree_root())
3092 q
.push_back(subdir
);
3099 kick_open_ino_peers(who
);
3100 kick_find_ino_peers(who
);
3103 mds
->queue_waiters(waiters
);
3106 void MDCache::set_recovery_set(set
<mds_rank_t
>& s
)
3108 dout(7) << "set_recovery_set " << s
<< dendl
;
3114 * during resolve state, we share resolves to determine who
3115 * is authoritative for which trees. we expect to get an resolve
3116 * from _everyone_ in the recovery_set (the mds cluster at the time of
3117 * the first failure).
3119 * This functions puts the passed message before returning
3121 void MDCache::handle_resolve(MMDSResolve
*m
)
3123 dout(7) << "handle_resolve from " << m
->get_source() << dendl
;
3124 mds_rank_t from
= mds_rank_t(m
->get_source().num());
3126 if (mds
->get_state() < MDSMap::STATE_RESOLVE
) {
3127 if (mds
->get_want_state() == CEPH_MDS_STATE_RESOLVE
) {
3128 mds
->wait_for_resolve(new C_MDS_RetryMessage(mds
, m
));
3131 // wait until we reach the resolve stage!
3136 discard_delayed_resolve(from
);
3138 // ambiguous slave requests?
3139 if (!m
->slave_requests
.empty()) {
3140 if (mds
->is_clientreplay() || mds
->is_active() || mds
->is_stopping()) {
3141 for (auto p
= m
->slave_requests
.begin(); p
!= m
->slave_requests
.end(); ++p
) {
3142 if (uncommitted_masters
.count(p
->first
) && !uncommitted_masters
[p
->first
].safe
) {
3143 assert(!p
->second
.committing
);
3144 pending_masters
.insert(p
->first
);
3148 if (!pending_masters
.empty()) {
3149 dout(10) << " still have pending updates, delay processing slave resolve" << dendl
;
3150 delayed_resolve
[from
] = m
;
3155 MMDSResolveAck
*ack
= new MMDSResolveAck
;
3156 for (auto p
= m
->slave_requests
.begin(); p
!= m
->slave_requests
.end(); ++p
) {
3157 if (uncommitted_masters
.count(p
->first
)) { //mds->sessionmap.have_completed_request(p->first)) {
3159 if (p
->second
.committing
) {
3160 // already committing, waiting for the OP_COMMITTED slave reply
3161 dout(10) << " already committing slave request " << *p
<< " noop "<< dendl
;
3163 dout(10) << " ambiguous slave request " << *p
<< " will COMMIT" << dendl
;
3164 ack
->add_commit(p
->first
);
3166 uncommitted_masters
[p
->first
].slaves
.insert(from
); // wait for slave OP_COMMITTED before we log ECommitted
3168 if (p
->second
.inode_caps
.length() > 0) {
3169 // slave wants to export caps (rename)
3170 assert(mds
->is_resolve());
3173 map
<client_t
,Capability::Export
> cap_exports
;
3174 bufferlist::iterator q
= p
->second
.inode_caps
.begin();
3176 ::decode(cap_exports
, q
);
3178 assert(get_inode(ino
));
3180 for (map
<client_t
,Capability::Export
>::iterator q
= cap_exports
.begin();
3181 q
!= cap_exports
.end();
3183 Capability::Import
& im
= rejoin_imported_caps
[from
][ino
][q
->first
];
3184 im
.cap_id
= ++last_cap_id
; // assign a new cap ID
3186 im
.mseq
= q
->second
.mseq
;
3189 // will process these caps in rejoin stage
3190 rejoin_slave_exports
[ino
].first
= from
;
3191 rejoin_slave_exports
[ino
].second
.swap(cap_exports
);
3193 // send information of imported caps back to slave
3194 ::encode(rejoin_imported_caps
[from
][ino
], ack
->commit
[p
->first
]);
3198 dout(10) << " ambiguous slave request " << *p
<< " will ABORT" << dendl
;
3199 assert(!p
->second
.committing
);
3200 ack
->add_abort(p
->first
);
3203 mds
->send_message(ack
, m
->get_connection());
3208 if (!resolve_ack_gather
.empty() || !need_resolve_rollback
.empty()) {
3209 dout(10) << "delay processing subtree resolve" << dendl
;
3210 delayed_resolve
[from
] = m
;
3214 bool survivor
= false;
3215 // am i a surviving ambiguous importer?
3216 if (mds
->is_clientreplay() || mds
->is_active() || mds
->is_stopping()) {
3218 // check for any import success/failure (from this node)
3219 map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator p
= my_ambiguous_imports
.begin();
3220 while (p
!= my_ambiguous_imports
.end()) {
3221 map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator next
= p
;
3223 CDir
*dir
= get_dirfrag(p
->first
);
3225 dout(10) << "checking ambiguous import " << *dir
<< dendl
;
3226 if (migrator
->is_importing(dir
->dirfrag()) &&
3227 migrator
->get_import_peer(dir
->dirfrag()) == from
) {
3228 assert(migrator
->get_import_state(dir
->dirfrag()) == Migrator::IMPORT_ACKING
);
3230 // check if sender claims the subtree
3231 bool claimed_by_sender
= false;
3232 for (map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator q
= m
->subtrees
.begin();
3233 q
!= m
->subtrees
.end();
3235 // an ambiguous import won't race with a refragmentation; it's appropriate to force here.
3236 CDir
*base
= get_force_dirfrag(q
->first
, false);
3237 if (!base
|| !base
->contains(dir
))
3238 continue; // base not dir or an ancestor of dir, clearly doesn't claim dir.
3242 get_force_dirfrag_bound_set(q
->second
, bounds
);
3243 for (set
<CDir
*>::iterator p
= bounds
.begin(); p
!= bounds
.end(); ++p
) {
3245 if (bound
->contains(dir
)) {
3246 inside
= false; // nope, bound is dir or parent of dir, not inside.
3251 claimed_by_sender
= true;
3254 my_ambiguous_imports
.erase(p
); // no longer ambiguous.
3255 if (claimed_by_sender
) {
3256 dout(7) << "ambiguous import failed on " << *dir
<< dendl
;
3257 migrator
->import_reverse(dir
);
3259 dout(7) << "ambiguous import succeeded on " << *dir
<< dendl
;
3260 migrator
->import_finish(dir
, true);
3267 // update my dir_auth values
3268 // need to do this on recoverying nodes _and_ bystanders (to resolve ambiguous
3269 // migrations between other nodes)
3270 for (map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator pi
= m
->subtrees
.begin();
3271 pi
!= m
->subtrees
.end();
3273 dout(10) << "peer claims " << pi
->first
<< " bounds " << pi
->second
<< dendl
;
3274 CDir
*dir
= get_force_dirfrag(pi
->first
, !survivor
);
3277 adjust_bounded_subtree_auth(dir
, pi
->second
, from
);
3278 try_subtree_merge(dir
);
3283 // note ambiguous imports too
3284 for (map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator pi
= m
->ambiguous_imports
.begin();
3285 pi
!= m
->ambiguous_imports
.end();
3287 dout(10) << "noting ambiguous import on " << pi
->first
<< " bounds " << pi
->second
<< dendl
;
3288 other_ambiguous_imports
[from
][pi
->first
].swap( pi
->second
);
3291 // did i get them all?
3292 resolve_gather
.erase(from
);
3294 maybe_resolve_finish();
3299 void MDCache::process_delayed_resolve()
3301 dout(10) << "process_delayed_resolve" << dendl
;
3302 map
<mds_rank_t
, MMDSResolve
*> tmp
;
3303 tmp
.swap(delayed_resolve
);
3304 for (map
<mds_rank_t
, MMDSResolve
*>::iterator p
= tmp
.begin(); p
!= tmp
.end(); ++p
)
3305 handle_resolve(p
->second
);
3308 void MDCache::discard_delayed_resolve(mds_rank_t who
)
3310 if (delayed_resolve
.count(who
)) {
3311 delayed_resolve
[who
]->put();
3312 delayed_resolve
.erase(who
);
3316 void MDCache::maybe_resolve_finish()
3318 assert(resolve_ack_gather
.empty());
3319 assert(need_resolve_rollback
.empty());
3321 if (!resolve_gather
.empty()) {
3322 dout(10) << "maybe_resolve_finish still waiting for resolves ("
3323 << resolve_gather
<< ")" << dendl
;
3327 dout(10) << "maybe_resolve_finish got all resolves+resolve_acks, done." << dendl
;
3328 disambiguate_my_imports();
3329 finish_committed_masters();
3332 assert(mds
->is_resolve());
3333 trim_unlinked_inodes();
3334 recalc_auth_bits(false);
3335 resolve_done
.release()->complete(0);
3337 maybe_send_pending_rejoins();
3341 /* This functions puts the passed message before returning */
3342 void MDCache::handle_resolve_ack(MMDSResolveAck
*ack
)
3344 dout(10) << "handle_resolve_ack " << *ack
<< " from " << ack
->get_source() << dendl
;
3345 mds_rank_t from
= mds_rank_t(ack
->get_source().num());
3347 if (!resolve_ack_gather
.count(from
) ||
3348 mds
->mdsmap
->get_state(from
) < MDSMap::STATE_RESOLVE
) {
3353 if (ambiguous_slave_updates
.count(from
)) {
3354 assert(mds
->mdsmap
->is_clientreplay_or_active_or_stopping(from
));
3355 assert(mds
->is_clientreplay() || mds
->is_active() || mds
->is_stopping());
3358 for (map
<metareqid_t
, bufferlist
>::iterator p
= ack
->commit
.begin();
3359 p
!= ack
->commit
.end();
3361 dout(10) << " commit on slave " << p
->first
<< dendl
;
3363 if (ambiguous_slave_updates
.count(from
)) {
3364 remove_ambiguous_slave_update(p
->first
, from
);
3368 if (mds
->is_resolve()) {
3370 MDSlaveUpdate
*su
= get_uncommitted_slave_update(p
->first
, from
);
3374 mds
->mdlog
->start_submit_entry(new ESlaveUpdate(mds
->mdlog
, "unknown", p
->first
, from
,
3375 ESlaveUpdate::OP_COMMIT
, su
->origop
),
3376 new C_MDC_SlaveCommit(this, from
, p
->first
));
3377 mds
->mdlog
->flush();
3379 finish_uncommitted_slave_update(p
->first
, from
);
3381 MDRequestRef mdr
= request_get(p
->first
);
3382 // information about master imported caps
3383 if (p
->second
.length() > 0)
3384 mdr
->more()->inode_import
.claim(p
->second
);
3386 assert(mdr
->slave_request
== 0); // shouldn't be doing anything!
3387 request_finish(mdr
);
3391 for (vector
<metareqid_t
>::iterator p
= ack
->abort
.begin();
3392 p
!= ack
->abort
.end();
3394 dout(10) << " abort on slave " << *p
<< dendl
;
3396 if (mds
->is_resolve()) {
3397 MDSlaveUpdate
*su
= get_uncommitted_slave_update(*p
, from
);
3400 // perform rollback (and journal a rollback entry)
3401 // note: this will hold up the resolve a bit, until the rollback entries journal.
3402 MDRequestRef null_ref
;
3403 switch (su
->origop
) {
3404 case ESlaveUpdate::LINK
:
3405 mds
->server
->do_link_rollback(su
->rollback
, from
, null_ref
);
3407 case ESlaveUpdate::RENAME
:
3408 mds
->server
->do_rename_rollback(su
->rollback
, from
, null_ref
);
3410 case ESlaveUpdate::RMDIR
:
3411 mds
->server
->do_rmdir_rollback(su
->rollback
, from
, null_ref
);
3417 MDRequestRef mdr
= request_get(*p
);
3418 mdr
->aborted
= true;
3419 if (mdr
->slave_request
) {
3420 if (mdr
->slave_did_prepare()) // journaling slave prepare ?
3421 add_rollback(*p
, from
);
3423 request_finish(mdr
);
3428 if (!ambiguous_slave_updates
.count(from
))
3429 resolve_ack_gather
.erase(from
);
3430 if (resolve_ack_gather
.empty() && need_resolve_rollback
.empty()) {
3431 send_subtree_resolves();
3432 process_delayed_resolve();
3438 void MDCache::add_uncommitted_slave_update(metareqid_t reqid
, mds_rank_t master
, MDSlaveUpdate
*su
)
3440 assert(uncommitted_slave_updates
[master
].count(reqid
) == 0);
3441 uncommitted_slave_updates
[master
][reqid
] = su
;
3442 for(set
<CInode
*>::iterator p
= su
->olddirs
.begin(); p
!= su
->olddirs
.end(); ++p
)
3443 uncommitted_slave_rename_olddir
[*p
]++;
3444 for(set
<CInode
*>::iterator p
= su
->unlinked
.begin(); p
!= su
->unlinked
.end(); ++p
)
3445 uncommitted_slave_unlink
[*p
]++;
3448 void MDCache::finish_uncommitted_slave_update(metareqid_t reqid
, mds_rank_t master
)
3450 assert(uncommitted_slave_updates
[master
].count(reqid
));
3451 MDSlaveUpdate
* su
= uncommitted_slave_updates
[master
][reqid
];
3453 uncommitted_slave_updates
[master
].erase(reqid
);
3454 if (uncommitted_slave_updates
[master
].empty())
3455 uncommitted_slave_updates
.erase(master
);
3456 // discard the non-auth subtree we renamed out of
3457 for(set
<CInode
*>::iterator p
= su
->olddirs
.begin(); p
!= su
->olddirs
.end(); ++p
) {
3459 map
<CInode
*, int>::iterator it
= uncommitted_slave_rename_olddir
.find(diri
);
3460 assert(it
!= uncommitted_slave_rename_olddir
.end());
3462 if (it
->second
== 0) {
3463 uncommitted_slave_rename_olddir
.erase(it
);
3465 diri
->get_dirfrags(ls
);
3466 for (list
<CDir
*>::iterator q
= ls
.begin(); q
!= ls
.end(); ++q
) {
3467 CDir
*root
= get_subtree_root(*q
);
3468 if (root
->get_dir_auth() == CDIR_AUTH_UNDEF
) {
3469 try_trim_non_auth_subtree(root
);
3475 assert(it
->second
> 0);
3477 // removed the inodes that were unlinked by slave update
3478 for(set
<CInode
*>::iterator p
= su
->unlinked
.begin(); p
!= su
->unlinked
.end(); ++p
) {
3480 map
<CInode
*, int>::iterator it
= uncommitted_slave_unlink
.find(in
);
3481 assert(it
!= uncommitted_slave_unlink
.end());
3483 if (it
->second
== 0) {
3484 uncommitted_slave_unlink
.erase(it
);
3485 if (!in
->get_projected_parent_dn())
3486 mds
->mdcache
->remove_inode_recursive(in
);
3488 assert(it
->second
> 0);
3493 MDSlaveUpdate
* MDCache::get_uncommitted_slave_update(metareqid_t reqid
, mds_rank_t master
)
3496 MDSlaveUpdate
* su
= NULL
;
3497 if (uncommitted_slave_updates
.count(master
) &&
3498 uncommitted_slave_updates
[master
].count(reqid
)) {
3499 su
= uncommitted_slave_updates
[master
][reqid
];
3505 void MDCache::finish_rollback(metareqid_t reqid
) {
3506 assert(need_resolve_rollback
.count(reqid
));
3507 if (mds
->is_resolve())
3508 finish_uncommitted_slave_update(reqid
, need_resolve_rollback
[reqid
]);
3509 need_resolve_rollback
.erase(reqid
);
3510 if (resolve_ack_gather
.empty() && need_resolve_rollback
.empty()) {
3511 send_subtree_resolves();
3512 process_delayed_resolve();
3516 void MDCache::disambiguate_other_imports()
3518 dout(10) << "disambiguate_other_imports" << dendl
;
3520 bool recovering
= !(mds
->is_clientreplay() || mds
->is_active() || mds
->is_stopping());
3521 // other nodes' ambiguous imports
3522 for (map
<mds_rank_t
, map
<dirfrag_t
, vector
<dirfrag_t
> > >::iterator p
= other_ambiguous_imports
.begin();
3523 p
!= other_ambiguous_imports
.end();
3525 mds_rank_t who
= p
->first
;
3526 dout(10) << "ambiguous imports for mds." << who
<< dendl
;
3528 for (map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator q
= p
->second
.begin();
3529 q
!= p
->second
.end();
3531 dout(10) << " ambiguous import " << q
->first
<< " bounds " << q
->second
<< dendl
;
3532 // an ambiguous import will not race with a refragmentation; it's appropriate to force here.
3533 CDir
*dir
= get_force_dirfrag(q
->first
, recovering
);
3536 if (dir
->is_ambiguous_auth() || // works for me_ambig or if i am a surviving bystander
3537 dir
->authority() == CDIR_AUTH_UNDEF
) { // resolving
3538 dout(10) << " mds." << who
<< " did import " << *dir
<< dendl
;
3539 adjust_bounded_subtree_auth(dir
, q
->second
, who
);
3540 try_subtree_merge(dir
);
3542 dout(10) << " mds." << who
<< " did not import " << *dir
<< dendl
;
3546 other_ambiguous_imports
.clear();
3549 void MDCache::disambiguate_my_imports()
3551 dout(10) << "disambiguate_my_imports" << dendl
;
3553 if (!mds
->is_resolve()) {
3554 assert(my_ambiguous_imports
.empty());
3558 disambiguate_other_imports();
3560 // my ambiguous imports
3561 mds_authority_t
me_ambig(mds
->get_nodeid(), mds
->get_nodeid());
3562 while (!my_ambiguous_imports
.empty()) {
3563 map
<dirfrag_t
, vector
<dirfrag_t
> >::iterator q
= my_ambiguous_imports
.begin();
3565 CDir
*dir
= get_dirfrag(q
->first
);
3568 if (dir
->authority() != me_ambig
) {
3569 dout(10) << "ambiguous import auth known, must not be me " << *dir
<< dendl
;
3570 cancel_ambiguous_import(dir
);
3572 mds
->mdlog
->start_submit_entry(new EImportFinish(dir
, false));
3574 // subtree may have been swallowed by another node claiming dir
3576 CDir
*root
= get_subtree_root(dir
);
3578 dout(10) << " subtree root is " << *root
<< dendl
;
3579 assert(root
->dir_auth
.first
!= mds
->get_nodeid()); // no us!
3580 try_trim_non_auth_subtree(root
);
3582 dout(10) << "ambiguous import auth unclaimed, must be me " << *dir
<< dendl
;
3583 finish_ambiguous_import(q
->first
);
3584 mds
->mdlog
->start_submit_entry(new EImportFinish(dir
, true));
3587 assert(my_ambiguous_imports
.empty());
3588 mds
->mdlog
->flush();
3590 // verify all my subtrees are unambiguous!
3591 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
3592 p
!= subtrees
.end();
3594 CDir
*dir
= p
->first
;
3595 if (dir
->is_ambiguous_dir_auth()) {
3596 dout(0) << "disambiguate_imports uh oh, dir_auth is still ambiguous for " << *dir
<< dendl
;
3598 assert(!dir
->is_ambiguous_dir_auth());
3605 void MDCache::add_ambiguous_import(dirfrag_t base
, const vector
<dirfrag_t
>& bounds
)
3607 assert(my_ambiguous_imports
.count(base
) == 0);
3608 my_ambiguous_imports
[base
] = bounds
;
3612 void MDCache::add_ambiguous_import(CDir
*base
, const set
<CDir
*>& bounds
)
3615 vector
<dirfrag_t
> binos
;
3616 for (set
<CDir
*>::iterator p
= bounds
.begin();
3619 binos
.push_back((*p
)->dirfrag());
3621 // note: this can get called twice if the exporter fails during recovery
3622 if (my_ambiguous_imports
.count(base
->dirfrag()))
3623 my_ambiguous_imports
.erase(base
->dirfrag());
3625 add_ambiguous_import(base
->dirfrag(), binos
);
3628 void MDCache::cancel_ambiguous_import(CDir
*dir
)
3630 dirfrag_t df
= dir
->dirfrag();
3631 assert(my_ambiguous_imports
.count(df
));
3632 dout(10) << "cancel_ambiguous_import " << df
3633 << " bounds " << my_ambiguous_imports
[df
]
3636 my_ambiguous_imports
.erase(df
);
3639 void MDCache::finish_ambiguous_import(dirfrag_t df
)
3641 assert(my_ambiguous_imports
.count(df
));
3642 vector
<dirfrag_t
> bounds
;
3643 bounds
.swap(my_ambiguous_imports
[df
]);
3644 my_ambiguous_imports
.erase(df
);
3646 dout(10) << "finish_ambiguous_import " << df
3647 << " bounds " << bounds
3649 CDir
*dir
= get_dirfrag(df
);
3652 // adjust dir_auth, import maps
3653 adjust_bounded_subtree_auth(dir
, bounds
, mds
->get_nodeid());
3654 try_subtree_merge(dir
);
3657 void MDCache::remove_inode_recursive(CInode
*in
)
3659 dout(10) << "remove_inode_recursive " << *in
<< dendl
;
3661 in
->get_dirfrags(ls
);
3662 list
<CDir
*>::iterator p
= ls
.begin();
3663 while (p
!= ls
.end()) {
3664 CDir
*subdir
= *p
++;
3666 dout(10) << " removing dirfrag " << subdir
<< dendl
;
3667 CDir::map_t::iterator q
= subdir
->items
.begin();
3668 while (q
!= subdir
->items
.end()) {
3669 CDentry
*dn
= q
->second
;
3671 CDentry::linkage_t
*dnl
= dn
->get_linkage();
3672 if (dnl
->is_primary()) {
3673 CInode
*tin
= dnl
->get_inode();
3674 subdir
->unlink_inode(dn
, false);
3675 remove_inode_recursive(tin
);
3677 subdir
->remove_dentry(dn
);
3680 if (subdir
->is_subtree_root())
3681 remove_subtree(subdir
);
3682 in
->close_dirfrag(subdir
->dirfrag().frag
);
3687 bool MDCache::expire_recursive(
3689 map
<mds_rank_t
, MCacheExpire
*>& expiremap
)
3691 assert(!in
->is_auth());
3693 dout(10) << __func__
<< ":" << *in
<< dendl
;
3695 // Recurse into any dirfrags beneath this inode
3697 in
->get_dirfrags(ls
);
3698 for (auto subdir
: ls
) {
3699 if (!in
->is_mdsdir() && subdir
->is_subtree_root()) {
3700 dout(10) << __func__
<< ": stray still has subtree " << *in
<< dendl
;
3704 for (auto &it
: subdir
->items
) {
3705 CDentry
*dn
= it
.second
;
3706 CDentry::linkage_t
*dnl
= dn
->get_linkage();
3707 if (dnl
->is_primary()) {
3708 CInode
*tin
= dnl
->get_inode();
3710 /* Remote strays with linkage (i.e. hardlinks) should not be
3711 * expired, because they may be the target of
3712 * a rename() as the owning MDS shuts down */
3713 if (!tin
->is_stray() && tin
->inode
.nlink
) {
3714 dout(10) << __func__
<< ": stray still has linkage " << *tin
<< dendl
;
3718 const bool abort
= expire_recursive(tin
, expiremap
);
3723 if (dn
->lru_is_expireable()) {
3724 trim_dentry(dn
, expiremap
);
3726 dout(10) << __func__
<< ": stray dn is not expireable " << *dn
<< dendl
;
3735 void MDCache::trim_unlinked_inodes()
3737 dout(7) << "trim_unlinked_inodes" << dendl
;
3739 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator p
= inode_map
.begin();
3740 p
!= inode_map
.end();
3742 CInode
*in
= p
->second
;
3743 if (in
->get_parent_dn() == NULL
&& !in
->is_base()) {
3744 dout(7) << " will trim from " << *in
<< dendl
;
3748 for (list
<CInode
*>::iterator p
= q
.begin(); p
!= q
.end(); ++p
)
3749 remove_inode_recursive(*p
);
3752 /** recalc_auth_bits()
3753 * once subtree auth is disambiguated, we need to adjust all the
3754 * auth and dirty bits in our cache before moving on.
3756 void MDCache::recalc_auth_bits(bool replay
)
3758 dout(7) << "recalc_auth_bits " << (replay
? "(replay)" : "") << dendl
;
3761 root
->inode_auth
.first
= mds
->mdsmap
->get_root();
3762 bool auth
= mds
->get_nodeid() == root
->inode_auth
.first
;
3764 root
->state_set(CInode::STATE_AUTH
);
3766 root
->state_clear(CInode::STATE_AUTH
);
3768 root
->state_set(CInode::STATE_REJOINING
);
3772 set
<CInode
*> subtree_inodes
;
3773 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
3774 p
!= subtrees
.end();
3776 if (p
->first
->dir_auth
.first
== mds
->get_nodeid())
3777 subtree_inodes
.insert(p
->first
->inode
);
3780 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
3781 p
!= subtrees
.end();
3783 if (p
->first
->inode
->is_mdsdir()) {
3784 CInode
*in
= p
->first
->inode
;
3785 bool auth
= in
->ino() == MDS_INO_MDSDIR(mds
->get_nodeid());
3787 in
->state_set(CInode::STATE_AUTH
);
3789 in
->state_clear(CInode::STATE_AUTH
);
3791 in
->state_set(CInode::STATE_REJOINING
);
3795 list
<CDir
*> dfq
; // dirfrag queue
3796 dfq
.push_back(p
->first
);
3798 bool auth
= p
->first
->authority().first
== mds
->get_nodeid();
3799 dout(10) << " subtree auth=" << auth
<< " for " << *p
->first
<< dendl
;
3801 while (!dfq
.empty()) {
3802 CDir
*dir
= dfq
.front();
3807 dir
->state_set(CDir::STATE_AUTH
);
3809 dir
->state_clear(CDir::STATE_AUTH
);
3811 // close empty non-auth dirfrag
3812 if (!dir
->is_subtree_root() && dir
->get_num_any() == 0) {
3813 dir
->inode
->close_dirfrag(dir
->get_frag());
3816 dir
->state_set(CDir::STATE_REJOINING
);
3817 dir
->state_clear(CDir::STATE_COMPLETE
);
3818 if (dir
->is_dirty())
3823 // dentries in this dir
3824 for (CDir::map_t::iterator q
= dir
->items
.begin();
3825 q
!= dir
->items
.end();
3828 CDentry
*dn
= q
->second
;
3829 CDentry::linkage_t
*dnl
= dn
->get_linkage();
3831 dn
->state_set(CDentry::STATE_AUTH
);
3833 dn
->state_clear(CDentry::STATE_AUTH
);
3835 dn
->state_set(CDentry::STATE_REJOINING
);
3841 if (dnl
->is_primary()) {
3843 CInode
*in
= dnl
->get_inode();
3845 in
->state_set(CInode::STATE_AUTH
);
3847 in
->state_clear(CInode::STATE_AUTH
);
3849 in
->state_set(CInode::STATE_REJOINING
);
3852 if (in
->is_dirty_parent())
3853 in
->clear_dirty_parent();
3854 // avoid touching scatterlocks for our subtree roots!
3855 if (subtree_inodes
.count(in
) == 0)
3856 in
->clear_scatter_dirty();
3861 in
->get_nested_dirfrags(dfq
);
3873 // ===========================================================================
3877 * notes on scatterlock recovery:
3879 * - recovering inode replica sends scatterlock data for any subtree
3880 * roots (the only ones that are possibly dirty).
3882 * - surviving auth incorporates any provided scatterlock data. any
3883 * pending gathers are then finished, as with the other lock types.
3885 * that takes care of surviving auth + (recovering replica)*.
3887 * - surviving replica sends strong_inode, which includes current
3888 * scatterlock state, AND any dirty scatterlock data. this
3889 * provides the recovering auth with everything it might need.
3891 * - recovering auth must pick initial scatterlock state based on
3892 * (weak|strong) rejoins.
3893 * - always assimilate scatterlock data (it can't hurt)
3894 * - any surviving replica in SCATTER state -> SCATTER. otherwise, SYNC.
3895 * - include base inode in ack for all inodes that saw scatterlock content
3897 * also, for scatter gather,
3899 * - auth increments {frag,r}stat.version on completion of any gather.
3901 * - auth incorporates changes in a gather _only_ if the version
3904 * - replica discards changes any time the scatterlock syncs, and
3908 void MDCache::dump_rejoin_status(Formatter
*f
) const
3910 f
->open_object_section("rejoin_status");
3911 f
->dump_stream("rejoin_gather") << rejoin_gather
;
3912 f
->dump_stream("rejoin_ack_gather") << rejoin_ack_gather
;
3913 f
->dump_unsigned("num_opening_inodes", cap_imports_num_opening
);
3917 void MDCache::rejoin_start(MDSInternalContext
*rejoin_done_
)
3919 dout(10) << "rejoin_start" << dendl
;
3920 assert(!rejoin_done
);
3921 rejoin_done
.reset(rejoin_done_
);
3923 rejoin_gather
= recovery_set
;
3924 // need finish opening cap inodes before sending cache rejoins
3925 rejoin_gather
.insert(mds
->get_nodeid());
3926 process_imported_caps();
3932 * this initiates rejoin. it shoudl be called before we get any
3933 * rejoin or rejoin_ack messages (or else mdsmap distribution is broken).
3935 * we start out by sending rejoins to everyone in the recovery set.
3937 * if we are rejoin, send for all regions in our cache.
3938 * if we are active|stopping, send only to nodes that are are rejoining.
3940 void MDCache::rejoin_send_rejoins()
3942 dout(10) << "rejoin_send_rejoins with recovery_set " << recovery_set
<< dendl
;
3944 if (rejoin_gather
.count(mds
->get_nodeid())) {
3945 dout(7) << "rejoin_send_rejoins still processing imported caps, delaying" << dendl
;
3946 rejoins_pending
= true;
3949 if (!resolve_gather
.empty()) {
3950 dout(7) << "rejoin_send_rejoins still waiting for resolves ("
3951 << resolve_gather
<< ")" << dendl
;
3952 rejoins_pending
= true;
3956 assert(!migrator
->is_importing());
3957 assert(!migrator
->is_exporting());
3959 if (!mds
->is_rejoin()) {
3960 disambiguate_other_imports();
3963 map
<mds_rank_t
, MMDSCacheRejoin
*> rejoins
;
3966 // if i am rejoining, send a rejoin to everyone.
3967 // otherwise, just send to others who are rejoining.
3968 for (set
<mds_rank_t
>::iterator p
= recovery_set
.begin();
3969 p
!= recovery_set
.end();
3971 if (*p
== mds
->get_nodeid()) continue; // nothing to myself!
3972 if (rejoin_sent
.count(*p
)) continue; // already sent a rejoin to this node!
3973 if (mds
->is_rejoin())
3974 rejoins
[*p
] = new MMDSCacheRejoin(MMDSCacheRejoin::OP_WEAK
);
3975 else if (mds
->mdsmap
->is_rejoin(*p
))
3976 rejoins
[*p
] = new MMDSCacheRejoin(MMDSCacheRejoin::OP_STRONG
);
3979 if (mds
->is_rejoin()) {
3980 map
<client_t
, set
<mds_rank_t
> > client_exports
;
3981 for (auto p
= cap_exports
.begin(); p
!= cap_exports
.end(); ++p
) {
3982 assert(cap_export_targets
.count(p
->first
));
3983 mds_rank_t target
= cap_export_targets
[p
->first
];
3984 if (rejoins
.count(target
) == 0)
3986 rejoins
[target
]->cap_exports
[p
->first
] = p
->second
;
3987 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
)
3988 client_exports
[q
->first
].insert(target
);
3990 for (map
<client_t
, set
<mds_rank_t
> >::iterator p
= client_exports
.begin();
3991 p
!= client_exports
.end();
3993 entity_inst_t inst
= mds
->sessionmap
.get_inst(entity_name_t::CLIENT(p
->first
.v
));
3994 for (set
<mds_rank_t
>::iterator q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
)
3995 rejoins
[*q
]->client_map
[p
->first
] = inst
;
4000 // check all subtrees
4001 for (map
<CDir
*, set
<CDir
*> >::iterator p
= subtrees
.begin();
4002 p
!= subtrees
.end();
4004 CDir
*dir
= p
->first
;
4005 assert(dir
->is_subtree_root());
4006 if (dir
->is_ambiguous_dir_auth()) {
4007 // exporter is recovering, importer is survivor.
4008 assert(rejoins
.count(dir
->authority().first
));
4009 assert(!rejoins
.count(dir
->authority().second
));
4015 continue; // skip my own regions!
4017 mds_rank_t auth
= dir
->get_dir_auth().first
;
4019 if (rejoins
.count(auth
) == 0)
4020 continue; // don't care about this node's subtrees
4022 rejoin_walk(dir
, rejoins
[auth
]);
4025 // rejoin root inodes, too
4026 for (map
<mds_rank_t
, MMDSCacheRejoin
*>::iterator p
= rejoins
.begin();
4029 if (mds
->is_rejoin()) {
4031 if (p
->first
== 0 && root
) {
4032 p
->second
->add_weak_inode(root
->vino());
4033 if (root
->is_dirty_scattered()) {
4034 dout(10) << " sending scatterlock state on root " << *root
<< dendl
;
4035 p
->second
->add_scatterlock_state(root
);
4038 if (CInode
*in
= get_inode(MDS_INO_MDSDIR(p
->first
))) {
4040 p
->second
->add_weak_inode(in
->vino());
4044 if (p
->first
== 0 && root
) {
4045 p
->second
->add_strong_inode(root
->vino(),
4046 root
->get_replica_nonce(),
4047 root
->get_caps_wanted(),
4048 root
->filelock
.get_state(),
4049 root
->nestlock
.get_state(),
4050 root
->dirfragtreelock
.get_state());
4051 root
->state_set(CInode::STATE_REJOINING
);
4052 if (root
->is_dirty_scattered()) {
4053 dout(10) << " sending scatterlock state on root " << *root
<< dendl
;
4054 p
->second
->add_scatterlock_state(root
);
4058 if (CInode
*in
= get_inode(MDS_INO_MDSDIR(p
->first
))) {
4059 p
->second
->add_strong_inode(in
->vino(),
4060 in
->get_replica_nonce(),
4061 in
->get_caps_wanted(),
4062 in
->filelock
.get_state(),
4063 in
->nestlock
.get_state(),
4064 in
->dirfragtreelock
.get_state());
4065 in
->state_set(CInode::STATE_REJOINING
);
4070 if (!mds
->is_rejoin()) {
4071 // i am survivor. send strong rejoin.
4072 // note request remote_auth_pins, xlocks
4073 for (ceph::unordered_map
<metareqid_t
, MDRequestRef
>::iterator p
= active_requests
.begin();
4074 p
!= active_requests
.end();
4076 MDRequestRef
& mdr
= p
->second
;
4077 if (mdr
->is_slave())
4080 for (map
<MDSCacheObject
*,mds_rank_t
>::iterator q
= mdr
->remote_auth_pins
.begin();
4081 q
!= mdr
->remote_auth_pins
.end();
4083 if (!q
->first
->is_auth()) {
4084 assert(q
->second
== q
->first
->authority().first
);
4085 if (rejoins
.count(q
->second
) == 0) continue;
4086 MMDSCacheRejoin
*rejoin
= rejoins
[q
->second
];
4088 dout(15) << " " << *mdr
<< " authpin on " << *q
->first
<< dendl
;
4089 MDSCacheObjectInfo i
;
4090 q
->first
->set_object_info(i
);
4092 rejoin
->add_inode_authpin(vinodeno_t(i
.ino
, i
.snapid
), mdr
->reqid
, mdr
->attempt
);
4094 rejoin
->add_dentry_authpin(i
.dirfrag
, i
.dname
, i
.snapid
, mdr
->reqid
, mdr
->attempt
);
4096 if (mdr
->has_more() && mdr
->more()->is_remote_frozen_authpin
&&
4097 mdr
->more()->rename_inode
== q
->first
)
4098 rejoin
->add_inode_frozen_authpin(vinodeno_t(i
.ino
, i
.snapid
),
4099 mdr
->reqid
, mdr
->attempt
);
4103 for (set
<SimpleLock
*>::iterator q
= mdr
->xlocks
.begin();
4104 q
!= mdr
->xlocks
.end();
4106 if (!(*q
)->get_parent()->is_auth()) {
4107 mds_rank_t who
= (*q
)->get_parent()->authority().first
;
4108 if (rejoins
.count(who
) == 0) continue;
4109 MMDSCacheRejoin
*rejoin
= rejoins
[who
];
4111 dout(15) << " " << *mdr
<< " xlock on " << **q
<< " " << *(*q
)->get_parent() << dendl
;
4112 MDSCacheObjectInfo i
;
4113 (*q
)->get_parent()->set_object_info(i
);
4115 rejoin
->add_inode_xlock(vinodeno_t(i
.ino
, i
.snapid
), (*q
)->get_type(),
4116 mdr
->reqid
, mdr
->attempt
);
4118 rejoin
->add_dentry_xlock(i
.dirfrag
, i
.dname
, i
.snapid
,
4119 mdr
->reqid
, mdr
->attempt
);
4123 for (map
<SimpleLock
*, mds_rank_t
>::iterator q
= mdr
->remote_wrlocks
.begin();
4124 q
!= mdr
->remote_wrlocks
.end();
4126 mds_rank_t who
= q
->second
;
4127 if (rejoins
.count(who
) == 0) continue;
4128 MMDSCacheRejoin
*rejoin
= rejoins
[who
];
4130 dout(15) << " " << *mdr
<< " wrlock on " << q
->second
4131 << " " << q
->first
->get_parent() << dendl
;
4132 MDSCacheObjectInfo i
;
4133 q
->first
->get_parent()->set_object_info(i
);
4135 rejoin
->add_inode_wrlock(vinodeno_t(i
.ino
, i
.snapid
), q
->first
->get_type(),
4136 mdr
->reqid
, mdr
->attempt
);
4141 // send the messages
4142 for (map
<mds_rank_t
,MMDSCacheRejoin
*>::iterator p
= rejoins
.begin();
4145 assert(rejoin_sent
.count(p
->first
) == 0);
4146 assert(rejoin_ack_gather
.count(p
->first
) == 0);
4147 rejoin_sent
.insert(p
->first
);
4148 rejoin_ack_gather
.insert(p
->first
);
4149 mds
->send_message_mds(p
->second
, p
->first
);
4151 rejoin_ack_gather
.insert(mds
->get_nodeid()); // we need to complete rejoin_gather_finish, too
4152 rejoins_pending
= false;
4155 if (mds
->is_rejoin() && rejoins
.empty()) {
4156 dout(10) << "nothing to rejoin" << dendl
;
4157 rejoin_gather_finish();
4163 * rejoin_walk - build rejoin declarations for a subtree
4165 * @param dir subtree root
4166 * @param rejoin rejoin message
4168 * from a rejoining node:
4170 * weak dentries (w/ connectivity)
4172 * from a surviving node:
4174 * strong dentries (no connectivity!)
4177 void MDCache::rejoin_walk(CDir
*dir
, MMDSCacheRejoin
*rejoin
)
4179 dout(10) << "rejoin_walk " << *dir
<< dendl
;
4181 list
<CDir
*> nested
; // finish this dir, then do nested items
4183 if (mds
->is_rejoin()) {
4185 rejoin
->add_weak_dirfrag(dir
->dirfrag());
4186 for (CDir::map_t::iterator p
= dir
->items
.begin();
4187 p
!= dir
->items
.end();
4189 CDentry
*dn
= p
->second
;
4190 CDentry::linkage_t
*dnl
= dn
->get_linkage();
4191 dout(15) << " add_weak_primary_dentry " << *dn
<< dendl
;
4192 assert(dnl
->is_primary());
4193 CInode
*in
= dnl
->get_inode();
4194 assert(dnl
->get_inode()->is_dir());
4195 rejoin
->add_weak_primary_dentry(dir
->ino(), dn
->name
.c_str(), dn
->first
, dn
->last
, in
->ino());
4196 in
->get_nested_dirfrags(nested
);
4197 if (in
->is_dirty_scattered()) {
4198 dout(10) << " sending scatterlock state on " << *in
<< dendl
;
4199 rejoin
->add_scatterlock_state(in
);
4204 dout(15) << " add_strong_dirfrag " << *dir
<< dendl
;
4205 rejoin
->add_strong_dirfrag(dir
->dirfrag(), dir
->get_replica_nonce(), dir
->get_dir_rep());
4206 dir
->state_set(CDir::STATE_REJOINING
);
4208 for (CDir::map_t::iterator p
= dir
->items
.begin();
4209 p
!= dir
->items
.end();
4211 CDentry
*dn
= p
->second
;
4212 CDentry::linkage_t
*dnl
= dn
->get_linkage();
4213 dout(15) << " add_strong_dentry " << *dn
<< dendl
;
4214 rejoin
->add_strong_dentry(dir
->dirfrag(), dn
->name
, dn
->first
, dn
->last
,
4215 dnl
->is_primary() ? dnl
->get_inode()->ino():inodeno_t(0),
4216 dnl
->is_remote() ? dnl
->get_remote_ino():inodeno_t(0),
4217 dnl
->is_remote() ? dnl
->get_remote_d_type():0,
4218 dn
->get_replica_nonce(),
4219 dn
->lock
.get_state());
4220 dn
->state_set(CDentry::STATE_REJOINING
);
4221 if (dnl
->is_primary()) {
4222 CInode
*in
= dnl
->get_inode();
4223 dout(15) << " add_strong_inode " << *in
<< dendl
;
4224 rejoin
->add_strong_inode(in
->vino(),
4225 in
->get_replica_nonce(),
4226 in
->get_caps_wanted(),
4227 in
->filelock
.get_state(),
4228 in
->nestlock
.get_state(),
4229 in
->dirfragtreelock
.get_state());
4230 in
->state_set(CInode::STATE_REJOINING
);
4231 in
->get_nested_dirfrags(nested
);
4232 if (in
->is_dirty_scattered()) {
4233 dout(10) << " sending scatterlock state on " << *in
<< dendl
;
4234 rejoin
->add_scatterlock_state(in
);
4240 // recurse into nested dirs
4241 for (list
<CDir
*>::iterator p
= nested
.begin();
4244 rejoin_walk(*p
, rejoin
);
4250 * - reply with the lockstate
4252 * if i am active|stopping,
4253 * - remove source from replica list for everything not referenced here.
4254 * This function puts the passed message before returning.
4256 void MDCache::handle_cache_rejoin(MMDSCacheRejoin
*m
)
4258 dout(7) << "handle_cache_rejoin " << *m
<< " from " << m
->get_source()
4259 << " (" << m
->get_payload().length() << " bytes)"
4263 case MMDSCacheRejoin::OP_WEAK
:
4264 handle_cache_rejoin_weak(m
);
4266 case MMDSCacheRejoin::OP_STRONG
:
4267 handle_cache_rejoin_strong(m
);
4269 case MMDSCacheRejoin::OP_ACK
:
4270 handle_cache_rejoin_ack(m
);
4281 * handle_cache_rejoin_weak
4284 * - is recovering from their journal.
4285 * - may have incorrect (out of date) inode contents
4286 * - will include weak dirfrag if sender is dirfrag auth and parent inode auth is recipient
4288 * if the sender didn't trim_non_auth(), they
4289 * - may have incorrect (out of date) dentry/inode linkage
4290 * - may have deleted/purged inodes
4291 * and i may have to go to disk to get accurate inode contents. yuck.
4292 * This functions DOES NOT put the passed message before returning
4294 void MDCache::handle_cache_rejoin_weak(MMDSCacheRejoin
*weak
)
4296 mds_rank_t from
= mds_rank_t(weak
->get_source().num());
4298 // possible response(s)
4299 MMDSCacheRejoin
*ack
= 0; // if survivor
4300 set
<vinodeno_t
> acked_inodes
; // if survivor
4301 set
<SimpleLock
*> gather_locks
; // if survivor
4302 bool survivor
= false; // am i a survivor?
4304 if (mds
->is_clientreplay() || mds
->is_active() || mds
->is_stopping()) {
4306 dout(10) << "i am a surivivor, and will ack immediately" << dendl
;
4307 ack
= new MMDSCacheRejoin(MMDSCacheRejoin::OP_ACK
);
4309 map
<inodeno_t
,map
<client_t
,Capability::Import
> > imported_caps
;
4311 // check cap exports
4312 for (auto p
= weak
->cap_exports
.begin(); p
!= weak
->cap_exports
.end(); ++p
) {
4313 CInode
*in
= get_inode(p
->first
);
4314 assert(!in
|| in
->is_auth());
4315 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
4316 dout(10) << " claiming cap import " << p
->first
<< " client." << q
->first
<< " on " << *in
<< dendl
;
4317 Capability
*cap
= rejoin_import_cap(in
, q
->first
, q
->second
, from
);
4318 Capability::Import
& im
= imported_caps
[p
->first
][q
->first
];
4320 im
.cap_id
= cap
->get_cap_id();
4321 im
.issue_seq
= cap
->get_last_seq();
4322 im
.mseq
= cap
->get_mseq();
4327 mds
->locker
->eval(in
, CEPH_CAP_LOCKS
, true);
4330 ::encode(imported_caps
, ack
->imported_caps
);
4332 assert(mds
->is_rejoin());
4334 // we may have already received a strong rejoin from the sender.
4335 rejoin_scour_survivor_replicas(from
, NULL
, acked_inodes
, gather_locks
);
4336 assert(gather_locks
.empty());
4338 // check cap exports.
4339 rejoin_client_map
.insert(weak
->client_map
.begin(), weak
->client_map
.end());
4341 for (auto p
= weak
->cap_exports
.begin(); p
!= weak
->cap_exports
.end(); ++p
) {
4342 CInode
*in
= get_inode(p
->first
);
4343 assert(in
&& in
->is_auth());
4345 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
4346 dout(10) << " claiming cap import " << p
->first
<< " client." << q
->first
<< dendl
;
4347 cap_imports
[p
->first
][q
->first
][from
] = q
->second
;
4352 // assimilate any potentially dirty scatterlock state
4353 for (map
<inodeno_t
,MMDSCacheRejoin::lock_bls
>::iterator p
= weak
->inode_scatterlocks
.begin();
4354 p
!= weak
->inode_scatterlocks
.end();
4356 CInode
*in
= get_inode(p
->first
);
4358 in
->decode_lock_state(CEPH_LOCK_IFILE
, p
->second
.file
);
4359 in
->decode_lock_state(CEPH_LOCK_INEST
, p
->second
.nest
);
4360 in
->decode_lock_state(CEPH_LOCK_IDFT
, p
->second
.dft
);
4362 rejoin_potential_updated_scatterlocks
.insert(in
);
4365 // recovering peer may send incorrect dirfrags here. we need to
4366 // infer which dirfrag they meant. the ack will include a
4367 // strong_dirfrag that will set them straight on the fragmentation.
4370 set
<CDir
*> dirs_to_share
;
4371 for (set
<dirfrag_t
>::iterator p
= weak
->weak_dirfrags
.begin();
4372 p
!= weak
->weak_dirfrags
.end();
4374 CInode
*diri
= get_inode(p
->ino
);
4376 dout(0) << " missing dir ino " << p
->ino
<< dendl
;
4380 if (diri
->dirfragtree
.is_leaf(p
->frag
)) {
4381 ls
.push_back(p
->frag
);
4383 diri
->dirfragtree
.get_leaves_under(p
->frag
, ls
);
4385 ls
.push_back(diri
->dirfragtree
[p
->frag
.value()]);
4387 for (list
<frag_t
>::iterator q
= ls
.begin(); q
!= ls
.end(); ++q
) {
4389 CDir
*dir
= diri
->get_dirfrag(fg
);
4391 dout(0) << " missing dir for " << p
->frag
<< " (which maps to " << fg
<< ") on " << *diri
<< dendl
;
4395 if (dirs_to_share
.count(dir
)) {
4396 dout(10) << " already have " << p
->frag
<< " -> " << fg
<< " " << *dir
<< dendl
;
4398 dirs_to_share
.insert(dir
);
4399 unsigned nonce
= dir
->add_replica(from
);
4400 dout(10) << " have " << p
->frag
<< " -> " << fg
<< " " << *dir
<< dendl
;
4402 ack
->add_strong_dirfrag(dir
->dirfrag(), nonce
, dir
->dir_rep
);
4403 ack
->add_dirfrag_base(dir
);
4409 for (map
<inodeno_t
,map
<string_snap_t
,MMDSCacheRejoin::dn_weak
> >::iterator p
= weak
->weak
.begin();
4410 p
!= weak
->weak
.end();
4412 CInode
*diri
= get_inode(p
->first
);
4414 dout(0) << " missing dir ino " << p
->first
<< dendl
;
4419 for (map
<string_snap_t
,MMDSCacheRejoin::dn_weak
>::iterator q
= p
->second
.begin();
4420 q
!= p
->second
.end();
4422 // locate proper dirfrag.
4423 // optimize for common case (one dirfrag) to avoid dirs_to_share set check
4424 frag_t fg
= diri
->pick_dirfrag(q
->first
.name
);
4425 if (!dir
|| dir
->get_frag() != fg
) {
4426 dir
= diri
->get_dirfrag(fg
);
4428 dout(0) << " missing dir frag " << fg
<< " on " << *diri
<< dendl
;
4430 assert(dirs_to_share
.count(dir
));
4434 CDentry
*dn
= dir
->lookup(q
->first
.name
, q
->first
.snapid
);
4436 CDentry::linkage_t
*dnl
= dn
->get_linkage();
4437 assert(dnl
->is_primary());
4439 if (survivor
&& dn
->is_replica(from
))
4440 dentry_remove_replica(dn
, from
, gather_locks
);
4441 unsigned dnonce
= dn
->add_replica(from
);
4442 dout(10) << " have " << *dn
<< dendl
;
4444 ack
->add_strong_dentry(dir
->dirfrag(), dn
->name
, dn
->first
, dn
->last
,
4445 dnl
->get_inode()->ino(), inodeno_t(0), 0,
4446 dnonce
, dn
->lock
.get_replica_state());
4449 CInode
*in
= dnl
->get_inode();
4452 if (survivor
&& in
->is_replica(from
))
4453 inode_remove_replica(in
, from
, true, gather_locks
);
4454 unsigned inonce
= in
->add_replica(from
);
4455 dout(10) << " have " << *in
<< dendl
;
4457 // scatter the dirlock, just in case?
4458 if (!survivor
&& in
->is_dir() && in
->has_subtree_root_dirfrag())
4459 in
->filelock
.set_state(LOCK_MIX
);
4462 acked_inodes
.insert(in
->vino());
4463 ack
->add_inode_base(in
, mds
->mdsmap
->get_up_features());
4465 in
->_encode_locks_state_for_rejoin(bl
, from
);
4466 ack
->add_inode_locks(in
, inonce
, bl
);
4471 // weak base inodes? (root, stray, etc.)
4472 for (set
<vinodeno_t
>::iterator p
= weak
->weak_inodes
.begin();
4473 p
!= weak
->weak_inodes
.end();
4475 CInode
*in
= get_inode(*p
);
4476 assert(in
); // hmm fixme wrt stray?
4477 if (survivor
&& in
->is_replica(from
))
4478 inode_remove_replica(in
, from
, true, gather_locks
);
4479 unsigned inonce
= in
->add_replica(from
);
4480 dout(10) << " have base " << *in
<< dendl
;
4483 acked_inodes
.insert(in
->vino());
4484 ack
->add_inode_base(in
, mds
->mdsmap
->get_up_features());
4486 in
->_encode_locks_state_for_rejoin(bl
, from
);
4487 ack
->add_inode_locks(in
, inonce
, bl
);
4491 assert(rejoin_gather
.count(from
));
4492 rejoin_gather
.erase(from
);
4494 // survivor. do everything now.
4495 for (map
<inodeno_t
,MMDSCacheRejoin::lock_bls
>::iterator p
= weak
->inode_scatterlocks
.begin();
4496 p
!= weak
->inode_scatterlocks
.end();
4498 CInode
*in
= get_inode(p
->first
);
4500 dout(10) << " including base inode (due to potential scatterlock update) " << *in
<< dendl
;
4501 acked_inodes
.insert(in
->vino());
4502 ack
->add_inode_base(in
, mds
->mdsmap
->get_up_features());
4505 rejoin_scour_survivor_replicas(from
, ack
, acked_inodes
, gather_locks
);
4506 mds
->send_message(ack
, weak
->get_connection());
4508 for (set
<SimpleLock
*>::iterator p
= gather_locks
.begin(); p
!= gather_locks
.end(); ++p
) {
4509 if (!(*p
)->is_stable())
4510 mds
->locker
->eval_gather(*p
);
4514 if (rejoin_gather
.empty()) {
4515 rejoin_gather_finish();
4517 dout(7) << "still need rejoin from (" << rejoin_gather
<< ")" << dendl
;
4522 class C_MDC_RejoinGatherFinish
: public MDCacheContext
{
4524 explicit C_MDC_RejoinGatherFinish(MDCache
*c
) : MDCacheContext(c
) {}
4525 void finish(int r
) override
{
4526 mdcache
->rejoin_gather_finish();
4531 * rejoin_scour_survivor_replica - remove source from replica list on unmentioned objects
4533 * all validated replicas are acked with a strong nonce, etc. if that isn't in the
4534 * ack, the replica dne, and we can remove it from our replica maps.
4536 void MDCache::rejoin_scour_survivor_replicas(mds_rank_t from
, MMDSCacheRejoin
*ack
,
4537 set
<vinodeno_t
>& acked_inodes
,
4538 set
<SimpleLock
*>& gather_locks
)
4540 dout(10) << "rejoin_scour_survivor_replicas from mds." << from
<< dendl
;
4542 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator p
= inode_map
.begin();
4543 p
!= inode_map
.end();
4545 CInode
*in
= p
->second
;
4548 if (in
->is_auth() &&
4549 in
->is_replica(from
) &&
4550 (ack
== NULL
|| acked_inodes
.count(p
->second
->vino()) == 0)) {
4551 inode_remove_replica(in
, from
, false, gather_locks
);
4552 dout(10) << " rem " << *in
<< dendl
;
4555 if (!in
->is_dir()) continue;
4558 in
->get_dirfrags(dfs
);
4559 for (list
<CDir
*>::iterator p
= dfs
.begin();
4563 if (!dir
->is_auth())
4566 if (dir
->is_replica(from
) &&
4567 (ack
== NULL
|| ack
->strong_dirfrags
.count(dir
->dirfrag()) == 0)) {
4568 dir
->remove_replica(from
);
4569 dout(10) << " rem " << *dir
<< dendl
;
4573 for (CDir::map_t::iterator p
= dir
->items
.begin();
4574 p
!= dir
->items
.end();
4576 CDentry
*dn
= p
->second
;
4578 if (dn
->is_replica(from
) &&
4580 ack
->strong_dentries
.count(dir
->dirfrag()) == 0 ||
4581 ack
->strong_dentries
[dir
->dirfrag()].count(string_snap_t(dn
->name
, dn
->last
)) == 0)) {
4582 dentry_remove_replica(dn
, from
, gather_locks
);
4583 dout(10) << " rem " << *dn
<< dendl
;
4591 CInode
*MDCache::rejoin_invent_inode(inodeno_t ino
, snapid_t last
)
4593 CInode
*in
= new CInode(this, true, 1, last
);
4594 in
->inode
.ino
= ino
;
4595 in
->state_set(CInode::STATE_REJOINUNDEF
);
4597 rejoin_undef_inodes
.insert(in
);
4598 dout(10) << " invented " << *in
<< dendl
;
4602 CDir
*MDCache::rejoin_invent_dirfrag(dirfrag_t df
)
4604 CInode
*in
= get_inode(df
.ino
);
4606 in
= rejoin_invent_inode(df
.ino
, CEPH_NOSNAP
);
4607 if (!in
->is_dir()) {
4608 assert(in
->state_test(CInode::STATE_REJOINUNDEF
));
4609 in
->inode
.mode
= S_IFDIR
;
4610 in
->inode
.dir_layout
.dl_dir_hash
= g_conf
->mds_default_dir_hash
;
4612 CDir
*dir
= in
->get_or_open_dirfrag(this, df
.frag
);
4613 dir
->state_set(CDir::STATE_REJOINUNDEF
);
4614 rejoin_undef_dirfrags
.insert(dir
);
4615 dout(10) << " invented " << *dir
<< dendl
;
4619 /* This functions DOES NOT put the passed message before returning */
4620 void MDCache::handle_cache_rejoin_strong(MMDSCacheRejoin
*strong
)
4622 mds_rank_t from
= mds_rank_t(strong
->get_source().num());
4624 // only a recovering node will get a strong rejoin.
4625 assert(mds
->is_rejoin());
4627 // assimilate any potentially dirty scatterlock state
4628 for (map
<inodeno_t
,MMDSCacheRejoin::lock_bls
>::iterator p
= strong
->inode_scatterlocks
.begin();
4629 p
!= strong
->inode_scatterlocks
.end();
4631 CInode
*in
= get_inode(p
->first
);
4633 in
->decode_lock_state(CEPH_LOCK_IFILE
, p
->second
.file
);
4634 in
->decode_lock_state(CEPH_LOCK_INEST
, p
->second
.nest
);
4635 in
->decode_lock_state(CEPH_LOCK_IDFT
, p
->second
.dft
);
4636 rejoin_potential_updated_scatterlocks
.insert(in
);
4639 rejoin_unlinked_inodes
[from
].clear();
4641 // surviving peer may send incorrect dirfrag here (maybe they didn't
4642 // get the fragment notify, or maybe we rolled back?). we need to
4643 // infer the right frag and get them with the program. somehow.
4644 // we don't normally send ACK.. so we'll need to bundle this with
4645 // MISSING or something.
4647 // strong dirfrags/dentries.
4648 // also process auth_pins, xlocks.
4649 for (map
<dirfrag_t
, MMDSCacheRejoin::dirfrag_strong
>::iterator p
= strong
->strong_dirfrags
.begin();
4650 p
!= strong
->strong_dirfrags
.end();
4652 CInode
*diri
= get_inode(p
->first
.ino
);
4654 diri
= rejoin_invent_inode(p
->first
.ino
, CEPH_NOSNAP
);
4655 CDir
*dir
= diri
->get_dirfrag(p
->first
.frag
);
4656 bool refragged
= false;
4658 dout(10) << " have " << *dir
<< dendl
;
4660 if (diri
->state_test(CInode::STATE_REJOINUNDEF
))
4661 dir
= rejoin_invent_dirfrag(dirfrag_t(diri
->ino(), frag_t()));
4662 else if (diri
->dirfragtree
.is_leaf(p
->first
.frag
))
4663 dir
= rejoin_invent_dirfrag(p
->first
);
4666 dir
->add_replica(from
, p
->second
.nonce
);
4667 dir
->dir_rep
= p
->second
.dir_rep
;
4669 dout(10) << " frag " << p
->first
<< " doesn't match dirfragtree " << *diri
<< dendl
;
4671 diri
->dirfragtree
.get_leaves_under(p
->first
.frag
, ls
);
4673 ls
.push_back(diri
->dirfragtree
[p
->first
.frag
.value()]);
4674 dout(10) << " maps to frag(s) " << ls
<< dendl
;
4675 for (list
<frag_t
>::iterator q
= ls
.begin(); q
!= ls
.end(); ++q
) {
4676 CDir
*dir
= diri
->get_dirfrag(*q
);
4678 dir
= rejoin_invent_dirfrag(dirfrag_t(diri
->ino(), *q
));
4680 dout(10) << " have(approx) " << *dir
<< dendl
;
4681 dir
->add_replica(from
, p
->second
.nonce
);
4682 dir
->dir_rep
= p
->second
.dir_rep
;
4687 map
<string_snap_t
,MMDSCacheRejoin::dn_strong
>& dmap
= strong
->strong_dentries
[p
->first
];
4688 for (map
<string_snap_t
,MMDSCacheRejoin::dn_strong
>::iterator q
= dmap
.begin();
4693 dn
= dir
->lookup(q
->first
.name
, q
->first
.snapid
);
4695 frag_t fg
= diri
->pick_dirfrag(q
->first
.name
);
4696 dir
= diri
->get_dirfrag(fg
);
4698 dn
= dir
->lookup(q
->first
.name
, q
->first
.snapid
);
4701 if (q
->second
.is_remote()) {
4702 dn
= dir
->add_remote_dentry(q
->first
.name
, q
->second
.remote_ino
, q
->second
.remote_d_type
,
4703 q
->second
.first
, q
->first
.snapid
);
4704 } else if (q
->second
.is_null()) {
4705 dn
= dir
->add_null_dentry(q
->first
.name
, q
->second
.first
, q
->first
.snapid
);
4707 CInode
*in
= get_inode(q
->second
.ino
, q
->first
.snapid
);
4708 if (!in
) in
= rejoin_invent_inode(q
->second
.ino
, q
->first
.snapid
);
4709 dn
= dir
->add_primary_dentry(q
->first
.name
, in
, q
->second
.first
, q
->first
.snapid
);
4711 dout(10) << " invented " << *dn
<< dendl
;
4713 CDentry::linkage_t
*dnl
= dn
->get_linkage();
4716 if (strong
->authpinned_dentries
.count(p
->first
) &&
4717 strong
->authpinned_dentries
[p
->first
].count(q
->first
)) {
4718 for (list
<MMDSCacheRejoin::slave_reqid
>::iterator r
= strong
->authpinned_dentries
[p
->first
][q
->first
].begin();
4719 r
!= strong
->authpinned_dentries
[p
->first
][q
->first
].end();
4721 dout(10) << " dn authpin by " << *r
<< " on " << *dn
<< dendl
;
4723 // get/create slave mdrequest
4725 if (have_request(r
->reqid
))
4726 mdr
= request_get(r
->reqid
);
4728 mdr
= request_start_slave(r
->reqid
, r
->attempt
, strong
);
4734 if (strong
->xlocked_dentries
.count(p
->first
) &&
4735 strong
->xlocked_dentries
[p
->first
].count(q
->first
)) {
4736 MMDSCacheRejoin::slave_reqid r
= strong
->xlocked_dentries
[p
->first
][q
->first
];
4737 dout(10) << " dn xlock by " << r
<< " on " << *dn
<< dendl
;
4738 MDRequestRef mdr
= request_get(r
.reqid
); // should have this from auth_pin above.
4739 assert(mdr
->is_auth_pinned(dn
));
4740 if (!mdr
->xlocks
.count(&dn
->versionlock
)) {
4741 assert(dn
->versionlock
.can_xlock_local());
4742 dn
->versionlock
.get_xlock(mdr
, mdr
->get_client());
4743 mdr
->xlocks
.insert(&dn
->versionlock
);
4744 mdr
->locks
.insert(&dn
->versionlock
);
4746 if (dn
->lock
.is_stable())
4747 dn
->auth_pin(&dn
->lock
);
4748 dn
->lock
.set_state(LOCK_XLOCK
);
4749 dn
->lock
.get_xlock(mdr
, mdr
->get_client());
4750 mdr
->xlocks
.insert(&dn
->lock
);
4751 mdr
->locks
.insert(&dn
->lock
);
4754 dn
->add_replica(from
, q
->second
.nonce
);
4755 dout(10) << " have " << *dn
<< dendl
;
4757 if (dnl
->is_primary()) {
4758 if (q
->second
.is_primary()) {
4759 if (vinodeno_t(q
->second
.ino
, q
->first
.snapid
) != dnl
->get_inode()->vino()) {
4760 // the survivor missed MDentryUnlink+MDentryLink messages ?
4761 assert(strong
->strong_inodes
.count(dnl
->get_inode()->vino()) == 0);
4762 CInode
*in
= get_inode(q
->second
.ino
, q
->first
.snapid
);
4764 assert(in
->get_parent_dn());
4765 rejoin_unlinked_inodes
[from
].insert(in
);
4766 dout(7) << " sender has primary dentry but wrong inode" << dendl
;
4769 // the survivor missed MDentryLink message ?
4770 assert(strong
->strong_inodes
.count(dnl
->get_inode()->vino()) == 0);
4771 dout(7) << " sender doesn't have primay dentry" << dendl
;
4774 if (q
->second
.is_primary()) {
4775 // the survivor missed MDentryUnlink message ?
4776 CInode
*in
= get_inode(q
->second
.ino
, q
->first
.snapid
);
4778 assert(in
->get_parent_dn());
4779 rejoin_unlinked_inodes
[from
].insert(in
);
4780 dout(7) << " sender has primary dentry but we don't" << dendl
;
4786 for (map
<vinodeno_t
, MMDSCacheRejoin::inode_strong
>::iterator p
= strong
->strong_inodes
.begin();
4787 p
!= strong
->strong_inodes
.end();
4789 CInode
*in
= get_inode(p
->first
);
4791 in
->add_replica(from
, p
->second
.nonce
);
4792 dout(10) << " have " << *in
<< dendl
;
4794 MMDSCacheRejoin::inode_strong
&is
= p
->second
;
4797 if (is
.caps_wanted
) {
4798 in
->mds_caps_wanted
[from
] = is
.caps_wanted
;
4799 dout(15) << " inode caps_wanted " << ccap_string(is
.caps_wanted
)
4800 << " on " << *in
<< dendl
;
4804 // infer state from replica state:
4805 // * go to MIX if they might have wrlocks
4806 // * go to LOCK if they are LOCK (just bc identify_files_to_recover might start twiddling filelock)
4807 in
->filelock
.infer_state_from_strong_rejoin(is
.filelock
, !in
->is_dir()); // maybe also go to LOCK
4808 in
->nestlock
.infer_state_from_strong_rejoin(is
.nestlock
, false);
4809 in
->dirfragtreelock
.infer_state_from_strong_rejoin(is
.dftlock
, false);
4812 if (strong
->authpinned_inodes
.count(in
->vino())) {
4813 for (list
<MMDSCacheRejoin::slave_reqid
>::iterator r
= strong
->authpinned_inodes
[in
->vino()].begin();
4814 r
!= strong
->authpinned_inodes
[in
->vino()].end();
4816 dout(10) << " inode authpin by " << *r
<< " on " << *in
<< dendl
;
4818 // get/create slave mdrequest
4820 if (have_request(r
->reqid
))
4821 mdr
= request_get(r
->reqid
);
4823 mdr
= request_start_slave(r
->reqid
, r
->attempt
, strong
);
4824 if (strong
->frozen_authpin_inodes
.count(in
->vino())) {
4825 assert(!in
->get_num_auth_pins());
4826 mdr
->freeze_auth_pin(in
);
4828 assert(!in
->is_frozen_auth_pin());
4834 if (strong
->xlocked_inodes
.count(in
->vino())) {
4835 for (map
<int,MMDSCacheRejoin::slave_reqid
>::iterator q
= strong
->xlocked_inodes
[in
->vino()].begin();
4836 q
!= strong
->xlocked_inodes
[in
->vino()].end();
4838 SimpleLock
*lock
= in
->get_lock(q
->first
);
4839 dout(10) << " inode xlock by " << q
->second
<< " on " << *lock
<< " on " << *in
<< dendl
;
4840 MDRequestRef mdr
= request_get(q
->second
.reqid
); // should have this from auth_pin above.
4841 assert(mdr
->is_auth_pinned(in
));
4842 if (!mdr
->xlocks
.count(&in
->versionlock
)) {
4843 assert(in
->versionlock
.can_xlock_local());
4844 in
->versionlock
.get_xlock(mdr
, mdr
->get_client());
4845 mdr
->xlocks
.insert(&in
->versionlock
);
4846 mdr
->locks
.insert(&in
->versionlock
);
4848 if (lock
->is_stable())
4850 lock
->set_state(LOCK_XLOCK
);
4851 if (lock
== &in
->filelock
)
4853 lock
->get_xlock(mdr
, mdr
->get_client());
4854 mdr
->xlocks
.insert(lock
);
4855 mdr
->locks
.insert(lock
);
4860 for (map
<vinodeno_t
, map
<int, list
<MMDSCacheRejoin::slave_reqid
> > >::iterator p
= strong
->wrlocked_inodes
.begin();
4861 p
!= strong
->wrlocked_inodes
.end();
4863 CInode
*in
= get_inode(p
->first
);
4864 for (map
<int, list
<MMDSCacheRejoin::slave_reqid
> >::iterator q
= p
->second
.begin();
4865 q
!= p
->second
.end();
4867 SimpleLock
*lock
= in
->get_lock(q
->first
);
4868 for (list
<MMDSCacheRejoin::slave_reqid
>::iterator r
= q
->second
.begin();
4869 r
!= q
->second
.end();
4871 dout(10) << " inode wrlock by " << *r
<< " on " << *lock
<< " on " << *in
<< dendl
;
4872 MDRequestRef mdr
= request_get(r
->reqid
); // should have this from auth_pin above.
4874 assert(mdr
->is_auth_pinned(in
));
4875 lock
->set_state(LOCK_MIX
);
4876 if (lock
== &in
->filelock
)
4878 lock
->get_wrlock(true);
4879 mdr
->wrlocks
.insert(lock
);
4880 mdr
->locks
.insert(lock
);
4886 assert(rejoin_gather
.count(from
));
4887 rejoin_gather
.erase(from
);
4888 if (rejoin_gather
.empty()) {
4889 rejoin_gather_finish();
4891 dout(7) << "still need rejoin from (" << rejoin_gather
<< ")" << dendl
;
4895 /* This functions DOES NOT put the passed message before returning */
4896 void MDCache::handle_cache_rejoin_ack(MMDSCacheRejoin
*ack
)
4898 dout(7) << "handle_cache_rejoin_ack from " << ack
->get_source() << dendl
;
4899 mds_rank_t from
= mds_rank_t(ack
->get_source().num());
4901 // for sending cache expire message
4902 set
<CInode
*> isolated_inodes
;
4903 set
<CInode
*> refragged_inodes
;
4906 for (map
<dirfrag_t
, MMDSCacheRejoin::dirfrag_strong
>::iterator p
= ack
->strong_dirfrags
.begin();
4907 p
!= ack
->strong_dirfrags
.end();
4909 // we may have had incorrect dir fragmentation; refragment based
4910 // on what they auth tells us.
4911 CDir
*dir
= get_dirfrag(p
->first
);
4913 dir
= get_force_dirfrag(p
->first
, false);
4915 refragged_inodes
.insert(dir
->get_inode());
4918 CInode
*diri
= get_inode(p
->first
.ino
);
4920 // barebones inode; the full inode loop below will clean up.
4921 diri
= new CInode(this, false);
4922 diri
->inode
.ino
= p
->first
.ino
;
4923 diri
->inode
.mode
= S_IFDIR
;
4924 diri
->inode
.dir_layout
.dl_dir_hash
= g_conf
->mds_default_dir_hash
;
4926 if (MDS_INO_MDSDIR(from
) == p
->first
.ino
) {
4927 diri
->inode_auth
= mds_authority_t(from
, CDIR_AUTH_UNKNOWN
);
4928 dout(10) << " add inode " << *diri
<< dendl
;
4930 diri
->inode_auth
= CDIR_AUTH_DEFAULT
;
4931 isolated_inodes
.insert(diri
);
4932 dout(10) << " unconnected dirfrag " << p
->first
<< dendl
;
4935 // barebones dirfrag; the full dirfrag loop below will clean up.
4936 dir
= diri
->add_dirfrag(new CDir(diri
, p
->first
.frag
, this, false));
4937 if (MDS_INO_MDSDIR(from
) == p
->first
.ino
||
4938 (dir
->authority() != CDIR_AUTH_UNDEF
&&
4939 dir
->authority().first
!= from
))
4940 adjust_subtree_auth(dir
, from
);
4941 dout(10) << " add dirfrag " << *dir
<< dendl
;
4944 dir
->set_replica_nonce(p
->second
.nonce
);
4945 dir
->state_clear(CDir::STATE_REJOINING
);
4946 dout(10) << " got " << *dir
<< dendl
;
4949 map
<string_snap_t
,MMDSCacheRejoin::dn_strong
>& dmap
= ack
->strong_dentries
[p
->first
];
4950 for (map
<string_snap_t
,MMDSCacheRejoin::dn_strong
>::iterator q
= dmap
.begin();
4953 CDentry
*dn
= dir
->lookup(q
->first
.name
, q
->first
.snapid
);
4955 dn
= dir
->add_null_dentry(q
->first
.name
, q
->second
.first
, q
->first
.snapid
);
4957 CDentry::linkage_t
*dnl
= dn
->get_linkage();
4959 assert(dn
->last
== q
->first
.snapid
);
4960 if (dn
->first
!= q
->second
.first
) {
4961 dout(10) << " adjust dn.first " << dn
->first
<< " -> " << q
->second
.first
<< " on " << *dn
<< dendl
;
4962 dn
->first
= q
->second
.first
;
4965 // may have bad linkage if we missed dentry link/unlink messages
4966 if (dnl
->is_primary()) {
4967 CInode
*in
= dnl
->get_inode();
4968 if (!q
->second
.is_primary() ||
4969 vinodeno_t(q
->second
.ino
, q
->first
.snapid
) != in
->vino()) {
4970 dout(10) << " had bad linkage for " << *dn
<< ", unlinking " << *in
<< dendl
;
4971 dir
->unlink_inode(dn
);
4973 } else if (dnl
->is_remote()) {
4974 if (!q
->second
.is_remote() ||
4975 q
->second
.remote_ino
!= dnl
->get_remote_ino() ||
4976 q
->second
.remote_d_type
!= dnl
->get_remote_d_type()) {
4977 dout(10) << " had bad linkage for " << *dn
<< dendl
;
4978 dir
->unlink_inode(dn
);
4981 if (!q
->second
.is_null())
4982 dout(10) << " had bad linkage for " << *dn
<< dendl
;
4985 // hmm, did we have the proper linkage here?
4986 if (dnl
->is_null() && !q
->second
.is_null()) {
4987 if (q
->second
.is_remote()) {
4988 dn
->dir
->link_remote_inode(dn
, q
->second
.remote_ino
, q
->second
.remote_d_type
);
4990 CInode
*in
= get_inode(q
->second
.ino
, q
->first
.snapid
);
4992 // barebones inode; assume it's dir, the full inode loop below will clean up.
4993 in
= new CInode(this, false, q
->second
.first
, q
->first
.snapid
);
4994 in
->inode
.ino
= q
->second
.ino
;
4995 in
->inode
.mode
= S_IFDIR
;
4996 in
->inode
.dir_layout
.dl_dir_hash
= g_conf
->mds_default_dir_hash
;
4998 dout(10) << " add inode " << *in
<< dendl
;
4999 } else if (in
->get_parent_dn()) {
5000 dout(10) << " had bad linkage for " << *(in
->get_parent_dn())
5001 << ", unlinking " << *in
<< dendl
;
5002 in
->get_parent_dir()->unlink_inode(in
->get_parent_dn());
5004 dn
->dir
->link_primary_inode(dn
, in
);
5005 isolated_inodes
.erase(in
);
5009 dn
->set_replica_nonce(q
->second
.nonce
);
5010 dn
->lock
.set_state_rejoin(q
->second
.lock
, rejoin_waiters
);
5011 dn
->state_clear(CDentry::STATE_REJOINING
);
5012 dout(10) << " got " << *dn
<< dendl
;
5016 for (set
<CInode
*>::iterator p
= refragged_inodes
.begin();
5017 p
!= refragged_inodes
.end();
5020 (*p
)->get_nested_dirfrags(ls
);
5021 for (list
<CDir
*>::iterator q
= ls
.begin(); q
!= ls
.end(); ++q
) {
5022 if ((*q
)->is_auth() || ack
->strong_dirfrags
.count((*q
)->dirfrag()))
5024 assert((*q
)->get_num_any() == 0);
5025 (*p
)->close_dirfrag((*q
)->get_frag());
5030 for (map
<dirfrag_t
, bufferlist
>::iterator p
= ack
->dirfrag_bases
.begin();
5031 p
!= ack
->dirfrag_bases
.end();
5033 CDir
*dir
= get_dirfrag(p
->first
);
5035 bufferlist::iterator q
= p
->second
.begin();
5036 dir
->_decode_base(q
);
5037 dout(10) << " got dir replica " << *dir
<< dendl
;
5041 bufferlist::iterator p
= ack
->inode_base
.begin();
5048 ::decode(basebl
, p
);
5049 CInode
*in
= get_inode(ino
, last
);
5051 bufferlist::iterator q
= basebl
.begin();
5052 in
->_decode_base(q
);
5053 dout(10) << " got inode base " << *in
<< dendl
;
5057 p
= ack
->inode_locks
.begin();
5058 //dout(10) << "inode_locks len " << ack->inode_locks.length() << " is " << ack->inode_locks << dendl;
5067 ::decode(lockbl
, p
);
5069 CInode
*in
= get_inode(ino
, last
);
5071 in
->set_replica_nonce(nonce
);
5072 bufferlist::iterator q
= lockbl
.begin();
5073 in
->_decode_locks_rejoin(q
, rejoin_waiters
, rejoin_eval_locks
);
5074 in
->state_clear(CInode::STATE_REJOINING
);
5075 dout(10) << " got inode locks " << *in
<< dendl
;
5078 // FIXME: This can happen if entire subtree, together with the inode subtree root
5079 // belongs to, were trimmed between sending cache rejoin and receiving rejoin ack.
5080 assert(isolated_inodes
.empty());
5082 map
<inodeno_t
,map
<client_t
,Capability::Import
> > peer_imported
;
5083 bufferlist::iterator bp
= ack
->imported_caps
.begin();
5084 ::decode(peer_imported
, bp
);
5086 for (map
<inodeno_t
,map
<client_t
,Capability::Import
> >::iterator p
= peer_imported
.begin();
5087 p
!= peer_imported
.end();
5089 assert(cap_exports
.count(p
->first
));
5090 assert(cap_export_targets
.count(p
->first
));
5091 assert(cap_export_targets
[p
->first
] == from
);
5092 for (map
<client_t
,Capability::Import
>::iterator q
= p
->second
.begin();
5093 q
!= p
->second
.end();
5095 assert(cap_exports
[p
->first
].count(q
->first
));
5097 dout(10) << " exporting caps for client." << q
->first
<< " ino " << p
->first
<< dendl
;
5098 Session
*session
= mds
->sessionmap
.get_session(entity_name_t::CLIENT(q
->first
.v
));
5101 // mark client caps stale.
5102 MClientCaps
*m
= new MClientCaps(CEPH_CAP_OP_EXPORT
, p
->first
, 0,
5103 cap_exports
[p
->first
][q
->first
].capinfo
.cap_id
, 0,
5104 mds
->get_osd_epoch_barrier());
5105 m
->set_cap_peer(q
->second
.cap_id
, q
->second
.issue_seq
, q
->second
.mseq
,
5106 (q
->second
.cap_id
> 0 ? from
: -1), 0);
5107 mds
->send_message_client_counted(m
, session
);
5109 cap_exports
[p
->first
].erase(q
->first
);
5111 assert(cap_exports
[p
->first
].empty());
5115 assert(rejoin_ack_gather
.count(from
));
5116 rejoin_ack_gather
.erase(from
);
5117 if (mds
->is_rejoin()) {
5119 if (rejoin_gather
.empty()) {
5120 // eval unstable scatter locks after all wrlocks are rejoined.
5121 while (!rejoin_eval_locks
.empty()) {
5122 SimpleLock
*lock
= rejoin_eval_locks
.front();
5123 rejoin_eval_locks
.pop_front();
5124 if (!lock
->is_stable())
5125 mds
->locker
->eval_gather(lock
);
5129 if (rejoin_gather
.empty() && // make sure we've gotten our FULL inodes, too.
5130 rejoin_ack_gather
.empty()) {
5131 // finally, kickstart past snap parent opens
5132 open_snap_parents();
5134 dout(7) << "still need rejoin from (" << rejoin_gather
<< ")"
5135 << ", rejoin_ack from (" << rejoin_ack_gather
<< ")" << dendl
;
5139 mds
->queue_waiters(rejoin_waiters
);
5144 * rejoin_trim_undef_inodes() -- remove REJOINUNDEF flagged inodes
5146 * FIXME: wait, can this actually happen? a survivor should generate cache trim
5147 * messages that clean these guys up...
5149 void MDCache::rejoin_trim_undef_inodes()
5151 dout(10) << "rejoin_trim_undef_inodes" << dendl
;
5153 while (!rejoin_undef_inodes
.empty()) {
5154 set
<CInode
*>::iterator p
= rejoin_undef_inodes
.begin();
5156 rejoin_undef_inodes
.erase(p
);
5158 in
->clear_replica_map();
5160 // close out dirfrags
5163 in
->get_dirfrags(dfls
);
5164 for (list
<CDir
*>::iterator p
= dfls
.begin();
5168 dir
->clear_replica_map();
5170 for (CDir::map_t::iterator p
= dir
->items
.begin();
5171 p
!= dir
->items
.end();
5173 CDentry
*dn
= p
->second
;
5174 dn
->clear_replica_map();
5176 dout(10) << " trimming " << *dn
<< dendl
;
5177 dir
->remove_dentry(dn
);
5180 dout(10) << " trimming " << *dir
<< dendl
;
5181 in
->close_dirfrag(dir
->dirfrag().frag
);
5185 CDentry
*dn
= in
->get_parent_dn();
5187 dn
->clear_replica_map();
5188 dout(10) << " trimming " << *dn
<< dendl
;
5189 dn
->dir
->remove_dentry(dn
);
5191 dout(10) << " trimming " << *in
<< dendl
;
5196 assert(rejoin_undef_inodes
.empty());
5199 void MDCache::rejoin_gather_finish()
5201 dout(10) << "rejoin_gather_finish" << dendl
;
5202 assert(mds
->is_rejoin());
5204 if (open_undef_inodes_dirfrags())
5207 if (process_imported_caps())
5210 choose_lock_states_and_reconnect_caps();
5212 identify_files_to_recover();
5215 // signal completion of fetches, rejoin_gather_finish, etc.
5216 assert(rejoin_ack_gather
.count(mds
->get_nodeid()));
5217 rejoin_ack_gather
.erase(mds
->get_nodeid());
5219 // did we already get our acks too?
5220 if (rejoin_ack_gather
.empty()) {
5221 // finally, kickstart past snap parent opens
5222 open_snap_parents();
5226 class C_MDC_RejoinOpenInoFinish
: public MDCacheContext
{
5229 C_MDC_RejoinOpenInoFinish(MDCache
*c
, inodeno_t i
) : MDCacheContext(c
), ino(i
) {}
5230 void finish(int r
) override
{
5231 mdcache
->rejoin_open_ino_finish(ino
, r
);
5235 void MDCache::rejoin_open_ino_finish(inodeno_t ino
, int ret
)
5237 dout(10) << "open_caps_inode_finish ino " << ino
<< " ret " << ret
<< dendl
;
5240 cap_imports_missing
.insert(ino
);
5241 } else if (ret
== mds
->get_nodeid()) {
5242 assert(get_inode(ino
));
5244 auto p
= cap_imports
.find(ino
);
5245 assert(p
!= cap_imports
.end());
5246 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
5247 assert(q
->second
.count(MDS_RANK_NONE
));
5248 assert(q
->second
.size() == 1);
5249 rejoin_export_caps(p
->first
, q
->first
, q
->second
[MDS_RANK_NONE
], ret
);
5251 cap_imports
.erase(p
);
5254 assert(cap_imports_num_opening
> 0);
5255 cap_imports_num_opening
--;
5257 if (cap_imports_num_opening
== 0) {
5258 if (rejoin_gather
.empty())
5259 rejoin_gather_finish();
5260 else if (rejoin_gather
.count(mds
->get_nodeid()))
5261 process_imported_caps();
5265 class C_MDC_RejoinSessionsOpened
: public MDCacheLogContext
{
5267 map
<client_t
,entity_inst_t
> client_map
;
5268 map
<client_t
,uint64_t> sseqmap
;
5270 C_MDC_RejoinSessionsOpened(MDCache
*c
, map
<client_t
,entity_inst_t
>& cm
) :
5271 MDCacheLogContext(c
), client_map(cm
) {}
5272 void finish(int r
) override
{
5274 mdcache
->rejoin_open_sessions_finish(client_map
, sseqmap
);
5278 void MDCache::rejoin_open_sessions_finish(map
<client_t
,entity_inst_t
> client_map
,
5279 map
<client_t
,uint64_t>& sseqmap
)
5281 dout(10) << "rejoin_open_sessions_finish" << dendl
;
5282 mds
->server
->finish_force_open_sessions(client_map
, sseqmap
);
5283 if (rejoin_gather
.empty())
5284 rejoin_gather_finish();
5287 bool MDCache::process_imported_caps()
5289 dout(10) << "process_imported_caps" << dendl
;
5291 for (auto p
= cap_imports
.begin(); p
!= cap_imports
.end(); ++p
) {
5292 CInode
*in
= get_inode(p
->first
);
5294 assert(in
->is_auth());
5295 cap_imports_missing
.erase(p
->first
);
5298 if (cap_imports_missing
.count(p
->first
) > 0)
5301 cap_imports_num_opening
++;
5302 dout(10) << " opening missing ino " << p
->first
<< dendl
;
5303 open_ino(p
->first
, (int64_t)-1, new C_MDC_RejoinOpenInoFinish(this, p
->first
), false);
5306 if (cap_imports_num_opening
> 0)
5309 // called by rejoin_gather_finish() ?
5310 if (rejoin_gather
.count(mds
->get_nodeid()) == 0) {
5311 // if sessions for imported caps are all open ?
5312 for (map
<client_t
,entity_inst_t
>::iterator p
= rejoin_client_map
.begin();
5313 p
!= rejoin_client_map
.end();
5315 if (!mds
->sessionmap
.have_session(entity_name_t::CLIENT(p
->first
.v
))) {
5316 C_MDC_RejoinSessionsOpened
*finish
= new C_MDC_RejoinSessionsOpened(this, rejoin_client_map
);
5317 version_t pv
= mds
->server
->prepare_force_open_sessions(rejoin_client_map
, finish
->sseqmap
);
5318 ESessions
*le
= new ESessions(pv
, rejoin_client_map
);
5319 mds
->mdlog
->start_submit_entry(le
, finish
);
5320 mds
->mdlog
->flush();
5321 rejoin_client_map
.clear();
5325 rejoin_client_map
.clear();
5327 // process caps that were exported by slave rename
5328 for (map
<inodeno_t
,pair
<mds_rank_t
,map
<client_t
,Capability::Export
> > >::iterator p
= rejoin_slave_exports
.begin();
5329 p
!= rejoin_slave_exports
.end();
5331 CInode
*in
= get_inode(p
->first
);
5333 for (map
<client_t
,Capability::Export
>::iterator q
= p
->second
.second
.begin();
5334 q
!= p
->second
.second
.end();
5336 Session
*session
= mds
->sessionmap
.get_session(entity_name_t::CLIENT(q
->first
.v
));
5339 Capability
*cap
= in
->get_client_cap(q
->first
);
5341 cap
= in
->add_client_cap(q
->first
, session
);
5342 cap
->merge(q
->second
, true);
5344 Capability::Import
& im
= rejoin_imported_caps
[p
->second
.first
][p
->first
][q
->first
];
5345 assert(cap
->get_last_seq() == im
.issue_seq
);
5346 assert(cap
->get_mseq() == im
.mseq
);
5347 cap
->set_cap_id(im
.cap_id
);
5348 // send cap import because we assigned a new cap ID
5349 do_cap_import(session
, in
, cap
, q
->second
.cap_id
, q
->second
.seq
, q
->second
.mseq
- 1,
5350 p
->second
.first
, CEPH_CAP_FLAG_AUTH
);
5353 rejoin_slave_exports
.clear();
5354 rejoin_imported_caps
.clear();
5356 // process cap imports
5357 // ino -> client -> frommds -> capex
5358 for (auto p
= cap_imports
.begin(); p
!= cap_imports
.end(); ) {
5359 CInode
*in
= get_inode(p
->first
);
5361 dout(10) << " still missing ino " << p
->first
5362 << ", will try again after replayed client requests" << dendl
;
5366 assert(in
->is_auth());
5367 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
5368 Session
*session
= mds
->sessionmap
.get_session(entity_name_t::CLIENT(q
->first
.v
));
5370 for (auto r
= q
->second
.begin(); r
!= q
->second
.end(); ++r
) {
5371 Capability
*cap
= in
->reconnect_cap(q
->first
, r
->second
, session
);
5372 add_reconnected_cap(q
->first
, in
->ino(), r
->second
);
5373 if (r
->first
>= 0) {
5374 if (cap
->get_last_seq() == 0) // don't increase mseq if cap already exists
5376 do_cap_import(session
, in
, cap
, r
->second
.capinfo
.cap_id
, 0, 0, r
->first
, 0);
5378 Capability::Import
& im
= rejoin_imported_caps
[r
->first
][p
->first
][q
->first
];
5379 im
.cap_id
= cap
->get_cap_id();
5380 im
.issue_seq
= cap
->get_last_seq();
5381 im
.mseq
= cap
->get_mseq();
5385 cap_imports
.erase(p
++); // remove and move on
5390 rejoin_gather
.erase(mds
->get_nodeid());
5391 maybe_send_pending_rejoins();
5393 if (rejoin_gather
.empty() && rejoin_ack_gather
.count(mds
->get_nodeid()))
5394 rejoin_gather_finish();
5399 void MDCache::check_realm_past_parents(SnapRealm
*realm
, bool reconnect
)
5401 // are this realm's parents fully open?
5402 if (realm
->have_past_parents_open()) {
5403 dout(10) << " have past snap parents for realm " << *realm
5404 << " on " << *realm
->inode
<< dendl
;
5406 // finish off client snaprealm reconnects?
5407 auto p
= reconnected_snaprealms
.find(realm
->inode
->ino());
5408 if (p
!= reconnected_snaprealms
.end()) {
5409 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
)
5410 finish_snaprealm_reconnect(q
->first
, realm
, q
->second
);
5411 reconnected_snaprealms
.erase(p
);
5415 if (!missing_snap_parents
.count(realm
->inode
)) {
5416 dout(10) << " MISSING past snap parents for realm " << *realm
5417 << " on " << *realm
->inode
<< dendl
;
5418 realm
->inode
->get(CInode::PIN_OPENINGSNAPPARENTS
);
5419 missing_snap_parents
[realm
->inode
].size(); // just to get it into the map!
5421 dout(10) << " (already) MISSING past snap parents for realm " << *realm
5422 << " on " << *realm
->inode
<< dendl
;
5427 void MDCache::rebuild_need_snapflush(CInode
*head_in
, SnapRealm
*realm
,
5428 client_t client
, snapid_t snap_follows
)
5430 dout(10) << "rebuild_need_snapflush " << snap_follows
<< " on " << *head_in
<< dendl
;
5432 const set
<snapid_t
>& snaps
= realm
->get_snaps();
5433 snapid_t follows
= snap_follows
;
5436 CInode
*in
= pick_inode_snap(head_in
, follows
);
5439 dout(10) << " need snapflush from client." << client
<< " on " << *in
<< dendl
;
5441 /* TODO: we can check the reconnected/flushing caps to find
5442 * which locks need gathering */
5443 for (int i
= 0; i
< num_cinode_locks
; i
++) {
5444 int lockid
= cinode_lock_info
[i
].lock
;
5445 SimpleLock
*lock
= in
->get_lock(lockid
);
5447 in
->client_snap_caps
[lockid
].insert(client
);
5449 lock
->set_state(LOCK_SNAP_SYNC
);
5450 lock
->get_wrlock(true);
5453 for (auto p
= snaps
.lower_bound(in
->first
);
5454 p
!= snaps
.end() && *p
<= in
->last
;
5456 head_in
->add_need_snapflush(in
, *p
, client
);
5464 * choose lock states based on reconnected caps
5466 void MDCache::choose_lock_states_and_reconnect_caps()
5468 dout(10) << "choose_lock_states_and_reconnect_caps" << dendl
;
5470 map
<client_t
,MClientSnap
*> splits
;
5472 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator i
= inode_map
.begin();
5473 i
!= inode_map
.end();
5475 CInode
*in
= i
->second
;
5477 if (in
->last
!= CEPH_NOSNAP
)
5480 if (in
->is_auth() && !in
->is_base() && in
->inode
.is_dirty_rstat())
5481 in
->mark_dirty_rstat();
5483 auto p
= reconnected_caps
.find(in
->ino());
5486 if (p
!= reconnected_caps
.end()) {
5487 for (const auto &it
: p
->second
)
5488 dirty_caps
|= it
.second
.dirty_caps
;
5490 in
->choose_lock_states(dirty_caps
);
5491 dout(15) << " chose lock states on " << *in
<< dendl
;
5493 SnapRealm
*realm
= in
->find_snaprealm();
5495 check_realm_past_parents(realm
, realm
== in
->snaprealm
);
5497 if (p
!= reconnected_caps
.end()) {
5498 bool missing_snap_parent
= false;
5499 // also, make sure client's cap is in the correct snaprealm.
5500 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
5501 if (q
->second
.snap_follows
> 0 && q
->second
.snap_follows
< in
->first
- 1) {
5502 if (realm
->have_past_parents_open()) {
5503 rebuild_need_snapflush(in
, realm
, q
->first
, q
->second
.snap_follows
);
5505 missing_snap_parent
= true;
5509 if (q
->second
.realm_ino
== realm
->inode
->ino()) {
5510 dout(15) << " client." << q
->first
<< " has correct realm " << q
->second
.realm_ino
<< dendl
;
5512 dout(15) << " client." << q
->first
<< " has wrong realm " << q
->second
.realm_ino
5513 << " != " << realm
->inode
->ino() << dendl
;
5514 if (realm
->have_past_parents_open()) {
5515 // ok, include in a split message _now_.
5516 prepare_realm_split(realm
, q
->first
, in
->ino(), splits
);
5518 // send the split later.
5519 missing_snap_parent
= true;
5523 if (missing_snap_parent
)
5524 missing_snap_parents
[realm
->inode
].insert(in
);
5531 void MDCache::prepare_realm_split(SnapRealm
*realm
, client_t client
, inodeno_t ino
,
5532 map
<client_t
,MClientSnap
*>& splits
)
5535 if (splits
.count(client
) == 0) {
5536 splits
[client
] = snap
= new MClientSnap(CEPH_SNAP_OP_SPLIT
);
5537 snap
->head
.split
= realm
->inode
->ino();
5538 realm
->build_snap_trace(snap
->bl
);
5540 for (set
<SnapRealm
*>::iterator p
= realm
->open_children
.begin();
5541 p
!= realm
->open_children
.end();
5543 snap
->split_realms
.push_back((*p
)->inode
->ino());
5546 snap
= splits
[client
];
5547 snap
->split_inos
.push_back(ino
);
5550 void MDCache::send_snaps(map
<client_t
,MClientSnap
*>& splits
)
5552 dout(10) << "send_snaps" << dendl
;
5554 for (map
<client_t
,MClientSnap
*>::iterator p
= splits
.begin();
5557 Session
*session
= mds
->sessionmap
.get_session(entity_name_t::CLIENT(p
->first
.v
));
5559 dout(10) << " client." << p
->first
5560 << " split " << p
->second
->head
.split
5561 << " inos " << p
->second
->split_inos
5563 mds
->send_message_client_counted(p
->second
, session
);
5565 dout(10) << " no session for client." << p
->first
<< dendl
;
5574 * remove any items from logsegment open_file lists that don't have
5577 void MDCache::clean_open_file_lists()
5579 dout(10) << "clean_open_file_lists" << dendl
;
5581 for (map
<uint64_t,LogSegment
*>::iterator p
= mds
->mdlog
->segments
.begin();
5582 p
!= mds
->mdlog
->segments
.end();
5584 LogSegment
*ls
= p
->second
;
5586 elist
<CInode
*>::iterator q
= ls
->open_files
.begin(member_offset(CInode
, item_open_file
));
5590 if (in
->last
== CEPH_NOSNAP
) {
5591 if (!in
->is_any_caps_wanted()) {
5592 dout(10) << " unlisting unwanted/capless inode " << *in
<< dendl
;
5593 in
->item_open_file
.remove_myself();
5595 } else if (in
->last
!= CEPH_NOSNAP
) {
5596 if (in
->client_snap_caps
.empty()) {
5597 dout(10) << " unlisting flushed snap inode " << *in
<< dendl
;
5598 in
->item_open_file
.remove_myself();
5607 Capability
* MDCache::rejoin_import_cap(CInode
*in
, client_t client
, const cap_reconnect_t
& icr
, mds_rank_t frommds
)
5609 dout(10) << "rejoin_import_cap for client." << client
<< " from mds." << frommds
5610 << " on " << *in
<< dendl
;
5611 Session
*session
= mds
->sessionmap
.get_session(entity_name_t::CLIENT(client
.v
));
5613 dout(10) << " no session for client." << client
<< dendl
;
5617 Capability
*cap
= in
->reconnect_cap(client
, icr
, session
);
5620 if (cap
->get_last_seq() == 0) // don't increase mseq if cap already exists
5622 do_cap_import(session
, in
, cap
, icr
.capinfo
.cap_id
, 0, 0, frommds
, 0);
5628 void MDCache::export_remaining_imported_caps()
5630 dout(10) << "export_remaining_imported_caps" << dendl
;
5632 stringstream warn_str
;
5634 for (auto p
= cap_imports
.begin(); p
!= cap_imports
.end(); ++p
) {
5635 warn_str
<< " ino " << p
->first
<< "\n";
5636 for (auto q
= p
->second
.begin(); q
!= p
->second
.end(); ++q
) {
5637 Session
*session
= mds
->sessionmap
.get_session(entity_name_t::CLIENT(q
->first
.v
));
5639 // mark client caps stale.
5640 MClientCaps
*stale
= new MClientCaps(CEPH_CAP_OP_EXPORT
, p
->first
, 0, 0, 0, mds
->get_osd_epoch_barrier());
5641 stale
->set_cap_peer(0, 0, 0, -1, 0);
5642 mds
->send_message_client_counted(stale
, q
->first
);
5646 mds
->heartbeat_reset();
5649 for (map
<inodeno_t
, list
<MDSInternalContextBase
*> >::iterator p
= cap_reconnect_waiters
.begin();
5650 p
!= cap_reconnect_waiters
.end();
5652 mds
->queue_waiters(p
->second
);
5654 cap_imports
.clear();
5655 cap_reconnect_waiters
.clear();
5657 if (warn_str
.peek() != EOF
) {
5658 mds
->clog
->warn() << "failed to reconnect caps for missing inodes:";
5659 mds
->clog
->warn(warn_str
);
5663 void MDCache::try_reconnect_cap(CInode
*in
, Session
*session
)
5665 client_t client
= session
->info
.get_client();
5666 const cap_reconnect_t
*rc
= get_replay_cap_reconnect(in
->ino(), client
);
5668 in
->reconnect_cap(client
, *rc
, session
);
5669 dout(10) << "try_reconnect_cap client." << client
5670 << " reconnect wanted " << ccap_string(rc
->capinfo
.wanted
)
5671 << " issue " << ccap_string(rc
->capinfo
.issued
)
5672 << " on " << *in
<< dendl
;
5673 remove_replay_cap_reconnect(in
->ino(), client
);
5675 if (in
->is_replicated()) {
5676 mds
->locker
->try_eval(in
, CEPH_CAP_LOCKS
);
5679 auto p
= reconnected_caps
.find(in
->ino());
5680 if (p
!= reconnected_caps
.end()) {
5681 auto q
= p
->second
.find(client
);
5682 if (q
!= p
->second
.end())
5683 dirty_caps
= q
->second
.dirty_caps
;
5685 in
->choose_lock_states(dirty_caps
);
5686 dout(15) << " chose lock states on " << *in
<< dendl
;
5689 map
<inodeno_t
, list
<MDSInternalContextBase
*> >::iterator it
=
5690 cap_reconnect_waiters
.find(in
->ino());
5691 if (it
!= cap_reconnect_waiters
.end()) {
5692 mds
->queue_waiters(it
->second
);
5693 cap_reconnect_waiters
.erase(it
);
5701 // cap imports and delayed snap parent opens
5703 void MDCache::do_cap_import(Session
*session
, CInode
*in
, Capability
*cap
,
5704 uint64_t p_cap_id
, ceph_seq_t p_seq
, ceph_seq_t p_mseq
,
5705 int peer
, int p_flags
)
5707 client_t client
= session
->info
.inst
.name
.num();
5708 SnapRealm
*realm
= in
->find_snaprealm();
5709 if (realm
->have_past_parents_open()) {
5710 dout(10) << "do_cap_import " << session
->info
.inst
.name
<< " mseq " << cap
->get_mseq() << " on " << *in
<< dendl
;
5711 if (cap
->get_last_seq() == 0) // reconnected cap
5712 cap
->inc_last_seq();
5713 cap
->set_last_issue();
5714 cap
->set_last_issue_stamp(ceph_clock_now());
5716 MClientCaps
*reap
= new MClientCaps(CEPH_CAP_OP_IMPORT
,
5718 realm
->inode
->ino(),
5719 cap
->get_cap_id(), cap
->get_last_seq(),
5720 cap
->pending(), cap
->wanted(), 0,
5721 cap
->get_mseq(), mds
->get_osd_epoch_barrier());
5722 in
->encode_cap_message(reap
, cap
);
5723 realm
->build_snap_trace(reap
->snapbl
);
5724 reap
->set_cap_peer(p_cap_id
, p_seq
, p_mseq
, peer
, p_flags
);
5725 mds
->send_message_client_counted(reap
, session
);
5727 dout(10) << "do_cap_import missing past snap parents, delaying " << session
->info
.inst
.name
<< " mseq "
5728 << cap
->get_mseq() << " on " << *in
<< dendl
;
5730 cap
->inc_suppress();
5731 delayed_imported_caps
[client
].insert(in
);
5732 missing_snap_parents
[in
].size();
5736 void MDCache::do_delayed_cap_imports()
5738 dout(10) << "do_delayed_cap_imports" << dendl
;
5740 assert(delayed_imported_caps
.empty());
5743 struct C_MDC_OpenSnapParents
: public MDCacheContext
{
5744 explicit C_MDC_OpenSnapParents(MDCache
*c
) : MDCacheContext(c
) {}
5745 void finish(int r
) override
{
5746 mdcache
->open_snap_parents();
5750 void MDCache::open_snap_parents()
5752 dout(10) << "open_snap_parents" << dendl
;
5754 map
<client_t
,MClientSnap
*> splits
;
5755 MDSGatherBuilder
gather(g_ceph_context
);
5757 auto p
= missing_snap_parents
.begin();
5758 while (p
!= missing_snap_parents
.end()) {
5759 CInode
*in
= p
->first
;
5760 assert(in
->snaprealm
);
5761 if (in
->snaprealm
->open_parents(gather
.new_sub())) {
5762 dout(10) << " past parents now open on " << *in
<< dendl
;
5764 for (CInode
*child
: p
->second
) {
5765 auto q
= reconnected_caps
.find(child
->ino());
5766 assert(q
!= reconnected_caps
.end());
5767 for (auto r
= q
->second
.begin(); r
!= q
->second
.end(); ++r
) {
5768 if (r
->second
.snap_follows
> 0 && r
->second
.snap_follows
< in
->first
- 1) {
5769 rebuild_need_snapflush(child
, in
->snaprealm
, r
->first
, r
->second
.snap_follows
);
5771 // make sure client's cap is in the correct snaprealm.
5772 if (r
->second
.realm_ino
!= in
->ino()) {
5773 prepare_realm_split(in
->snaprealm
, r
->first
, child
->ino(), splits
);
5778 missing_snap_parents
.erase(p
++);
5780 in
->put(CInode::PIN_OPENINGSNAPPARENTS
);
5782 // finish off client snaprealm reconnects?
5783 map
<inodeno_t
,map
<client_t
,snapid_t
> >::iterator q
= reconnected_snaprealms
.find(in
->ino());
5784 if (q
!= reconnected_snaprealms
.end()) {
5785 for (map
<client_t
,snapid_t
>::iterator r
= q
->second
.begin();
5786 r
!= q
->second
.end();
5788 finish_snaprealm_reconnect(r
->first
, in
->snaprealm
, r
->second
);
5789 reconnected_snaprealms
.erase(q
);
5792 dout(10) << " opening past parents on " << *in
<< dendl
;
5799 if (gather
.has_subs()) {
5800 dout(10) << "open_snap_parents - waiting for "
5801 << gather
.num_subs_remaining() << dendl
;
5802 gather
.set_finisher(new C_MDC_OpenSnapParents(this));
5805 if (!reconnected_snaprealms
.empty()) {
5806 stringstream warn_str
;
5807 for (map
<inodeno_t
,map
<client_t
,snapid_t
> >::iterator p
= reconnected_snaprealms
.begin();
5808 p
!= reconnected_snaprealms
.end();
5810 warn_str
<< " unconnected snaprealm " << p
->first
<< "\n";
5811 for (map
<client_t
,snapid_t
>::iterator q
= p
->second
.begin();
5812 q
!= p
->second
.end();
5814 warn_str
<< " client." << q
->first
<< " snapid " << q
->second
<< "\n";
5816 mds
->clog
->warn() << "open_snap_parents has:";
5817 mds
->clog
->warn(warn_str
);
5819 assert(rejoin_waiters
.empty());
5820 assert(missing_snap_parents
.empty());
5821 dout(10) << "open_snap_parents - all open" << dendl
;
5822 do_delayed_cap_imports();
5824 assert(rejoin_done
);
5825 rejoin_done
.release()->complete(0);
5826 reconnected_caps
.clear();
5830 bool MDCache::open_undef_inodes_dirfrags()
5832 dout(10) << "open_undef_inodes_dirfrags "
5833 << rejoin_undef_inodes
.size() << " inodes "
5834 << rejoin_undef_dirfrags
.size() << " dirfrags" << dendl
;
5836 set
<CDir
*> fetch_queue
= rejoin_undef_dirfrags
;
5838 for (set
<CInode
*>::iterator p
= rejoin_undef_inodes
.begin();
5839 p
!= rejoin_undef_inodes
.end();
5842 assert(!in
->is_base());
5843 fetch_queue
.insert(in
->get_parent_dir());
5846 if (fetch_queue
.empty())
5849 MDSGatherBuilder
gather(g_ceph_context
, new C_MDC_RejoinGatherFinish(this));
5850 for (set
<CDir
*>::iterator p
= fetch_queue
.begin();
5851 p
!= fetch_queue
.end();
5854 CInode
*diri
= dir
->get_inode();
5855 if (diri
->state_test(CInode::STATE_REJOINUNDEF
))
5857 if (dir
->state_test(CDir::STATE_REJOINUNDEF
))
5858 assert(diri
->dirfragtree
.is_leaf(dir
->get_frag()));
5859 dir
->fetch(gather
.new_sub());
5861 assert(gather
.has_subs());
5866 void MDCache::opened_undef_inode(CInode
*in
) {
5867 dout(10) << "opened_undef_inode " << *in
<< dendl
;
5868 rejoin_undef_inodes
.erase(in
);
5870 // FIXME: re-hash dentries if necessary
5871 assert(in
->inode
.dir_layout
.dl_dir_hash
== g_conf
->mds_default_dir_hash
);
5872 if (in
->has_dirfrags() && !in
->dirfragtree
.is_leaf(frag_t())) {
5873 CDir
*dir
= in
->get_dirfrag(frag_t());
5875 rejoin_undef_dirfrags
.erase(dir
);
5876 in
->force_dirfrags();
5878 in
->get_dirfrags(ls
);
5879 for (list
<CDir
*>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
)
5880 rejoin_undef_dirfrags
.insert(*p
);
5885 void MDCache::finish_snaprealm_reconnect(client_t client
, SnapRealm
*realm
, snapid_t seq
)
5887 if (seq
< realm
->get_newest_seq()) {
5888 dout(10) << "finish_snaprealm_reconnect client." << client
<< " has old seq " << seq
<< " < "
5889 << realm
->get_newest_seq()
5890 << " on " << *realm
<< dendl
;
5892 Session
*session
= mds
->sessionmap
.get_session(entity_name_t::CLIENT(client
.v
));
5894 MClientSnap
*snap
= new MClientSnap(CEPH_SNAP_OP_UPDATE
);
5895 realm
->build_snap_trace(snap
->bl
);
5896 mds
->send_message_client_counted(snap
, session
);
5898 dout(10) << " ...or not, no session for this client!" << dendl
;
5901 dout(10) << "finish_snaprealm_reconnect client." << client
<< " up to date"
5902 << " on " << *realm
<< dendl
;
5908 void MDCache::rejoin_send_acks()
5910 dout(7) << "rejoin_send_acks" << dendl
;
5913 for (map
<mds_rank_t
, set
<CInode
*> >::iterator p
= rejoin_unlinked_inodes
.begin();
5914 p
!= rejoin_unlinked_inodes
.end();
5916 for (set
<CInode
*>::iterator q
= p
->second
.begin();
5917 q
!= p
->second
.end();
5920 dout(7) << " unlinked inode " << *in
<< dendl
;
5922 if (!in
->is_replica(p
->first
))
5925 CDentry
*dn
= in
->get_parent_dn();
5926 if (dn
->is_replica(p
->first
))
5928 dn
->add_replica(p
->first
);
5929 CDir
*dir
= dn
->get_dir();
5930 if (dir
->is_replica(p
->first
))
5932 dir
->add_replica(p
->first
);
5933 in
= dir
->get_inode();
5934 if (in
->is_replica(p
->first
))
5936 in
->add_replica(p
->first
);
5942 rejoin_unlinked_inodes
.clear();
5944 // send acks to everyone in the recovery set
5945 map
<mds_rank_t
,MMDSCacheRejoin
*> acks
;
5946 for (set
<mds_rank_t
>::iterator p
= recovery_set
.begin();
5947 p
!= recovery_set
.end();
5949 if (rejoin_ack_sent
.count(*p
))
5951 acks
[*p
] = new MMDSCacheRejoin(MMDSCacheRejoin::OP_ACK
);
5954 rejoin_ack_sent
= recovery_set
;
5957 for (map
<CDir
*,set
<CDir
*> >::iterator p
= subtrees
.begin();
5958 p
!= subtrees
.end();
5960 CDir
*dir
= p
->first
;
5961 if (!dir
->is_auth())
5963 dout(10) << "subtree " << *dir
<< dendl
;
5965 // auth items in this subtree
5969 while (!dq
.empty()) {
5970 CDir
*dir
= dq
.front();
5974 for (auto &r
: dir
->get_replicas()) {
5975 auto it
= acks
.find(r
.first
);
5976 if (it
== acks
.end())
5978 it
->second
->add_strong_dirfrag(dir
->dirfrag(), ++r
.second
, dir
->dir_rep
);
5979 it
->second
->add_dirfrag_base(dir
);
5982 for (CDir::map_t::iterator q
= dir
->items
.begin();
5983 q
!= dir
->items
.end();
5985 CDentry
*dn
= q
->second
;
5986 CDentry::linkage_t
*dnl
= dn
->get_linkage();
5990 if (dnl
->is_primary())
5991 in
= dnl
->get_inode();
5994 for (auto &r
: dn
->get_replicas()) {
5995 auto it
= acks
.find(r
.first
);
5996 if (it
== acks
.end())
5998 it
->second
->add_strong_dentry(dir
->dirfrag(), dn
->name
, dn
->first
, dn
->last
,
5999 dnl
->is_primary() ? dnl
->get_inode()->ino():inodeno_t(0),
6000 dnl
->is_remote() ? dnl
->get_remote_ino():inodeno_t(0),
6001 dnl
->is_remote() ? dnl
->get_remote_d_type():0,
6003 dn
->lock
.get_replica_state());
6004 // peer missed MDentrylink message ?
6005 if (in
&& !in
->is_replica(r
.first
))
6006 in
->add_replica(r
.first
);
6012 for (auto &r
: in
->get_replicas()) {
6013 auto it
= acks
.find(r
.first
);
6014 if (it
== acks
.end())
6016 it
->second
->add_inode_base(in
, mds
->mdsmap
->get_up_features());
6018 in
->_encode_locks_state_for_rejoin(bl
, r
.first
);
6019 it
->second
->add_inode_locks(in
, ++r
.second
, bl
);
6022 // subdirs in this subtree?
6023 in
->get_nested_dirfrags(dq
);
6029 if (root
&& root
->is_auth())
6030 for (auto &r
: root
->get_replicas()) {
6031 auto it
= acks
.find(r
.first
);
6032 if (it
== acks
.end())
6034 it
->second
->add_inode_base(root
, mds
->mdsmap
->get_up_features());
6036 root
->_encode_locks_state_for_rejoin(bl
, r
.first
);
6037 it
->second
->add_inode_locks(root
, ++r
.second
, bl
);
6040 for (auto &r
: myin
->get_replicas()) {
6041 auto it
= acks
.find(r
.first
);
6042 if (it
== acks
.end())
6044 it
->second
->add_inode_base(myin
, mds
->mdsmap
->get_up_features());
6046 myin
->_encode_locks_state_for_rejoin(bl
, r
.first
);
6047 it
->second
->add_inode_locks(myin
, ++r
.second
, bl
);
6050 // include inode base for any inodes whose scatterlocks may have updated
6051 for (set
<CInode
*>::iterator p
= rejoin_potential_updated_scatterlocks
.begin();
6052 p
!= rejoin_potential_updated_scatterlocks
.end();
6055 for (const auto &r
: in
->get_replicas()) {
6056 auto it
= acks
.find(r
.first
);
6057 if (it
== acks
.end())
6059 it
->second
->add_inode_base(in
, mds
->mdsmap
->get_up_features());
6064 for (auto p
= acks
.begin(); p
!= acks
.end(); ++p
) {
6065 ::encode(rejoin_imported_caps
[p
->first
], p
->second
->imported_caps
);
6066 mds
->send_message_mds(p
->second
, p
->first
);
6069 rejoin_imported_caps
.clear();
6072 class C_MDC_ReIssueCaps
: public MDCacheContext
{
6075 C_MDC_ReIssueCaps(MDCache
*mdc
, CInode
*i
) :
6076 MDCacheContext(mdc
), in(i
)
6078 in
->get(CInode::PIN_PTRWAITER
);
6080 void finish(int r
) override
{
6081 if (!mdcache
->mds
->locker
->eval(in
, CEPH_CAP_LOCKS
))
6082 mdcache
->mds
->locker
->issue_caps(in
);
6083 in
->put(CInode::PIN_PTRWAITER
);
6087 void MDCache::reissue_all_caps()
6089 dout(10) << "reissue_all_caps" << dendl
;
6091 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator p
= inode_map
.begin();
6092 p
!= inode_map
.end();
6094 CInode
*in
= p
->second
;
6095 if (in
->is_head() && in
->is_any_caps()) {
6096 // called by MDSRank::active_start(). There shouldn't be any frozen subtree.
6097 if (in
->is_frozen_inode()) {
6098 in
->add_waiter(CInode::WAIT_UNFREEZE
, new C_MDC_ReIssueCaps(this, in
));
6101 if (!mds
->locker
->eval(in
, CEPH_CAP_LOCKS
))
6102 mds
->locker
->issue_caps(in
);
6108 // ===============================================================================
6110 struct C_MDC_QueuedCow
: public MDCacheContext
{
6113 C_MDC_QueuedCow(MDCache
*mdc
, CInode
*i
, MutationRef
& m
) :
6114 MDCacheContext(mdc
), in(i
), mut(m
) {}
6115 void finish(int r
) override
{
6116 mdcache
->_queued_file_recover_cow(in
, mut
);
6121 void MDCache::queue_file_recover(CInode
*in
)
6123 dout(10) << "queue_file_recover " << *in
<< dendl
;
6124 assert(in
->is_auth());
6128 SnapRealm *realm = in->find_snaprealm();
6129 set<snapid_t> s = realm->get_snaps();
6130 while (!s.empty() && *s.begin() < in->first)
6132 while (!s.empty() && *s.rbegin() > in->last)
6133 s.erase(*s.rbegin());
6134 dout(10) << " snaps in [" << in->first << "," << in->last << "] are " << s << dendl;
6136 inode_t *pi = in->project_inode();
6137 pi->version = in->pre_dirty();
6139 auto mut(std::make_shared<MutationImpl>());
6140 mut->ls = mds->mdlog->get_current_segment();
6141 EUpdate *le = new EUpdate(mds->mdlog, "queue_file_recover cow");
6142 mds->mdlog->start_entry(le);
6143 predirty_journal_parents(mut, &le->metablob, in, 0, PREDIRTY_PRIMARY);
6145 s.erase(*s.begin());
6146 while (!s.empty()) {
6147 snapid_t snapid = *s.begin();
6148 CInode *cow_inode = 0;
6149 journal_cow_inode(mut, &le->metablob, in, snapid-1, &cow_inode);
6151 recovery_queue.enqueue(cow_inode);
6152 s.erase(*s.begin());
6155 in->parent->first = in->first;
6156 le->metablob.add_primary_dentry(in->parent, in, true);
6157 mds->mdlog->submit_entry(le, new C_MDC_QueuedCow(this, in, mut));
6158 mds->mdlog->flush();
6162 recovery_queue
.enqueue(in
);
6165 void MDCache::_queued_file_recover_cow(CInode
*in
, MutationRef
& mut
)
6167 in
->pop_and_dirty_projected_inode(mut
->ls
);
6169 mds
->locker
->drop_locks(mut
.get());
6175 * called after recovery to recover file sizes for previously opened (for write)
6176 * files. that is, those where max_size > size.
6178 void MDCache::identify_files_to_recover()
6180 dout(10) << "identify_files_to_recover" << dendl
;
6181 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator p
= inode_map
.begin();
6182 p
!= inode_map
.end();
6184 CInode
*in
= p
->second
;
6188 if (in
->last
!= CEPH_NOSNAP
)
6191 // Only normal files need file size recovery
6192 if (!in
->is_file()) {
6196 bool recover
= false;
6197 for (map
<client_t
,client_writeable_range_t
>::iterator p
= in
->inode
.client_ranges
.begin();
6198 p
!= in
->inode
.client_ranges
.end();
6200 Capability
*cap
= in
->get_client_cap(p
->first
);
6202 dout(10) << " client." << p
->first
<< " has range " << p
->second
<< " but no cap on " << *in
<< dendl
;
6209 if (in
->filelock
.is_stable()) {
6210 in
->auth_pin(&in
->filelock
);
6212 assert(in
->filelock
.get_state() == LOCK_XLOCKSNAP
);
6214 in
->filelock
.set_state(LOCK_PRE_SCAN
);
6215 rejoin_recover_q
.push_back(in
);
6217 rejoin_check_q
.push_back(in
);
6222 void MDCache::start_files_to_recover()
6224 for (CInode
*in
: rejoin_check_q
) {
6225 if (in
->filelock
.get_state() == LOCK_XLOCKSNAP
)
6226 mds
->locker
->issue_caps(in
);
6227 mds
->locker
->check_inode_max_size(in
);
6229 rejoin_check_q
.clear();
6230 for (CInode
*in
: rejoin_recover_q
) {
6231 mds
->locker
->file_recover(&in
->filelock
);
6233 if (!rejoin_recover_q
.empty()) {
6234 rejoin_recover_q
.clear();
6239 void MDCache::do_file_recover()
6241 recovery_queue
.advance();
6244 // ===============================================================================
6247 // ----------------------------
6250 class C_MDC_RetryTruncate
: public MDCacheContext
{
6254 C_MDC_RetryTruncate(MDCache
*c
, CInode
*i
, LogSegment
*l
) :
6255 MDCacheContext(c
), in(i
), ls(l
) {}
6256 void finish(int r
) override
{
6257 mdcache
->_truncate_inode(in
, ls
);
6261 void MDCache::truncate_inode(CInode
*in
, LogSegment
*ls
)
6263 inode_t
*pi
= in
->get_projected_inode();
6264 dout(10) << "truncate_inode "
6265 << pi
->truncate_from
<< " -> " << pi
->truncate_size
6269 ls
->truncating_inodes
.insert(in
);
6270 in
->get(CInode::PIN_TRUNCATING
);
6273 if (!in
->client_need_snapflush
.empty() &&
6274 (in
->get_caps_issued() & CEPH_CAP_FILE_BUFFER
)) {
6275 assert(in
->filelock
.is_xlocked());
6276 in
->filelock
.set_xlock_snap_sync(new C_MDC_RetryTruncate(this, in
, ls
));
6277 mds
->locker
->issue_caps(in
);
6281 _truncate_inode(in
, ls
);
6284 struct C_IO_MDC_TruncateFinish
: public MDCacheIOContext
{
6287 C_IO_MDC_TruncateFinish(MDCache
*c
, CInode
*i
, LogSegment
*l
) :
6288 MDCacheIOContext(c
), in(i
), ls(l
) {}
6289 void finish(int r
) override
{
6290 assert(r
== 0 || r
== -ENOENT
);
6291 mdcache
->truncate_inode_finish(in
, ls
);
6295 void MDCache::_truncate_inode(CInode
*in
, LogSegment
*ls
)
6297 inode_t
*pi
= &in
->inode
;
6298 dout(10) << "_truncate_inode "
6299 << pi
->truncate_from
<< " -> " << pi
->truncate_size
6300 << " on " << *in
<< dendl
;
6302 assert(pi
->is_truncating());
6303 assert(pi
->truncate_size
< (1ULL << 63));
6304 assert(pi
->truncate_from
< (1ULL << 63));
6305 assert(pi
->truncate_size
< pi
->truncate_from
);
6308 SnapRealm
*realm
= in
->find_snaprealm();
6309 SnapContext nullsnap
;
6310 const SnapContext
*snapc
;
6312 dout(10) << " realm " << *realm
<< dendl
;
6313 snapc
= &realm
->get_snap_context();
6315 dout(10) << " NO realm, using null context" << dendl
;
6317 assert(in
->last
== CEPH_NOSNAP
);
6319 dout(10) << "_truncate_inode snapc " << snapc
<< " on " << *in
<< dendl
;
6320 filer
.truncate(in
->inode
.ino
, &in
->inode
.layout
, *snapc
,
6321 pi
->truncate_size
, pi
->truncate_from
-pi
->truncate_size
,
6322 pi
->truncate_seq
, ceph::real_time::min(), 0,
6323 new C_OnFinisher(new C_IO_MDC_TruncateFinish(this, in
, ls
),
6327 struct C_MDC_TruncateLogged
: public MDCacheLogContext
{
6330 C_MDC_TruncateLogged(MDCache
*m
, CInode
*i
, MutationRef
& mu
) :
6331 MDCacheLogContext(m
), in(i
), mut(mu
) {}
6332 void finish(int r
) override
{
6333 mdcache
->truncate_inode_logged(in
, mut
);
6337 void MDCache::truncate_inode_finish(CInode
*in
, LogSegment
*ls
)
6339 dout(10) << "truncate_inode_finish " << *in
<< dendl
;
6341 set
<CInode
*>::iterator p
= ls
->truncating_inodes
.find(in
);
6342 assert(p
!= ls
->truncating_inodes
.end());
6343 ls
->truncating_inodes
.erase(p
);
6346 inode_t
*pi
= in
->project_inode();
6347 pi
->version
= in
->pre_dirty();
6348 pi
->truncate_from
= 0;
6349 pi
->truncate_pending
--;
6351 MutationRef
mut(new MutationImpl());
6352 mut
->ls
= mds
->mdlog
->get_current_segment();
6353 mut
->add_projected_inode(in
);
6355 EUpdate
*le
= new EUpdate(mds
->mdlog
, "truncate finish");
6356 mds
->mdlog
->start_entry(le
);
6357 CDentry
*dn
= in
->get_projected_parent_dn();
6358 le
->metablob
.add_dir_context(dn
->get_dir());
6359 le
->metablob
.add_primary_dentry(dn
, in
, true);
6360 le
->metablob
.add_truncate_finish(in
->ino(), ls
->seq
);
6362 journal_dirty_inode(mut
.get(), &le
->metablob
, in
);
6363 mds
->mdlog
->submit_entry(le
, new C_MDC_TruncateLogged(this, in
, mut
));
6365 // flush immediately if there are readers/writers waiting
6366 if (in
->is_waiter_for(CInode::WAIT_TRUNC
) ||
6367 (in
->get_caps_wanted() & (CEPH_CAP_FILE_RD
|CEPH_CAP_FILE_WR
)))
6368 mds
->mdlog
->flush();
6371 void MDCache::truncate_inode_logged(CInode
*in
, MutationRef
& mut
)
6373 dout(10) << "truncate_inode_logged " << *in
<< dendl
;
6375 mds
->locker
->drop_locks(mut
.get());
6378 in
->put(CInode::PIN_TRUNCATING
);
6379 in
->auth_unpin(this);
6381 list
<MDSInternalContextBase
*> waiters
;
6382 in
->take_waiting(CInode::WAIT_TRUNC
, waiters
);
6383 mds
->queue_waiters(waiters
);
6387 void MDCache::add_recovered_truncate(CInode
*in
, LogSegment
*ls
)
6389 dout(20) << "add_recovered_truncate " << *in
<< " in log segment "
6390 << ls
->seq
<< "/" << ls
->offset
<< dendl
;
6391 ls
->truncating_inodes
.insert(in
);
6392 in
->get(CInode::PIN_TRUNCATING
);
6395 void MDCache::remove_recovered_truncate(CInode
*in
, LogSegment
*ls
)
6397 dout(20) << "remove_recovered_truncate " << *in
<< " in log segment "
6398 << ls
->seq
<< "/" << ls
->offset
<< dendl
;
6399 // if we have the logseg the truncate started in, it must be in our list.
6400 set
<CInode
*>::iterator p
= ls
->truncating_inodes
.find(in
);
6401 assert(p
!= ls
->truncating_inodes
.end());
6402 ls
->truncating_inodes
.erase(p
);
6403 in
->put(CInode::PIN_TRUNCATING
);
6406 void MDCache::start_recovered_truncates()
6408 dout(10) << "start_recovered_truncates" << dendl
;
6409 for (map
<uint64_t,LogSegment
*>::iterator p
= mds
->mdlog
->segments
.begin();
6410 p
!= mds
->mdlog
->segments
.end();
6412 LogSegment
*ls
= p
->second
;
6413 for (set
<CInode
*>::iterator q
= ls
->truncating_inodes
.begin();
6414 q
!= ls
->truncating_inodes
.end();
6419 if (!in
->client_need_snapflush
.empty() &&
6420 (in
->get_caps_issued() & CEPH_CAP_FILE_BUFFER
)) {
6421 assert(in
->filelock
.is_stable());
6422 in
->filelock
.set_state(LOCK_XLOCKDONE
);
6423 in
->auth_pin(&in
->filelock
);
6424 in
->filelock
.set_xlock_snap_sync(new C_MDC_RetryTruncate(this, in
, ls
));
6425 // start_files_to_recover will revoke caps
6428 _truncate_inode(in
, ls
);
6438 // ================================================================================
6441 void MDCache::trim_lru(uint64_t count
, map
<mds_rank_t
, MCacheExpire
*> &expiremap
)
6443 bool is_standby_replay
= mds
->is_standby_replay();
6444 std::vector
<CDentry
*> unexpirables
;
6445 uint64_t trimmed
= 0;
6447 dout(7) << "trim_lru trimming " << count
6448 << " items from LRU"
6449 << " size=" << lru
.lru_get_size()
6450 << " mid=" << lru
.lru_get_top()
6451 << " pintail=" << lru
.lru_get_pintail()
6452 << " pinned=" << lru
.lru_get_num_pinned()
6456 CDentry
*dn
= static_cast<CDentry
*>(bottom_lru
.lru_expire());
6459 if (trim_dentry(dn
, expiremap
)) {
6460 unexpirables
.push_back(dn
);
6466 for (auto &dn
: unexpirables
) {
6467 bottom_lru
.lru_insert_mid(dn
);
6469 unexpirables
.clear();
6471 // trim dentries from the LRU until count is reached
6472 while (cache_toofull() || count
> 0) {
6473 CDentry
*dn
= static_cast<CDentry
*>(lru
.lru_expire());
6477 if ((is_standby_replay
&& dn
->get_linkage()->inode
&&
6478 dn
->get_linkage()->inode
->item_open_file
.is_on_list())) {
6479 unexpirables
.push_back(dn
);
6480 } else if (trim_dentry(dn
, expiremap
)) {
6481 unexpirables
.push_back(dn
);
6484 if (count
> 0) count
--;
6488 for (auto &dn
: unexpirables
) {
6489 lru
.lru_insert_mid(dn
);
6491 unexpirables
.clear();
6493 dout(7) << "trim_lru trimmed " << trimmed
<< " items" << dendl
;
6497 * note: only called while MDS is active or stopping... NOT during recovery.
6498 * however, we may expire a replica whose authority is recovering.
6500 * @param count is number of dentries to try to expire
6502 bool MDCache::trim(uint64_t count
)
6504 uint64_t used
= cache_size();
6505 uint64_t limit
= cache_limit_memory();
6506 map
<mds_rank_t
, MCacheExpire
*> expiremap
;
6508 dout(7) << "trim bytes_used=" << bytes2str(used
)
6509 << " limit=" << bytes2str(limit
)
6510 << " reservation=" << cache_reservation()
6511 << "% count=" << count
<< dendl
;
6513 // process delayed eval_stray()
6514 stray_manager
.advance_delayed();
6516 trim_lru(count
, expiremap
);
6518 // trim non-auth, non-bound subtrees
6519 for (auto p
= subtrees
.begin(); p
!= subtrees
.end();) {
6520 CDir
*dir
= p
->first
;
6522 CInode
*diri
= dir
->get_inode();
6523 if (dir
->is_auth()) {
6524 if (!diri
->is_auth() && !diri
->is_base() &&
6525 dir
->get_num_head_items() == 0) {
6526 if (dir
->state_test(CDir::STATE_EXPORTING
) ||
6527 !(mds
->is_active() || mds
->is_stopping()) ||
6528 dir
->is_freezing() || dir
->is_frozen())
6531 migrator
->export_empty_import(dir
);
6534 if (!diri
->is_auth()) {
6535 if (dir
->get_num_ref() > 1) // only subtree pin
6538 diri
->get_subtree_dirfrags(ls
);
6539 if (diri
->get_num_ref() > (int)ls
.size()) // only pinned by subtrees
6542 // don't trim subtree root if its auth MDS is recovering.
6543 // This simplify the cache rejoin code.
6544 if (dir
->is_subtree_root() &&
6545 rejoin_ack_gather
.count(dir
->get_dir_auth().first
))
6547 trim_dirfrag(dir
, 0, expiremap
);
6553 if (mds
->is_stopping() && root
) {
6555 root
->get_dirfrags(ls
);
6556 for (list
<CDir
*>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
6558 if (dir
->get_num_ref() == 1) // subtree pin
6559 trim_dirfrag(dir
, 0, expiremap
);
6561 if (root
->get_num_ref() == 0)
6562 trim_inode(0, root
, 0, expiremap
);
6565 std::set
<mds_rank_t
> stopping
;
6566 mds
->mdsmap
->get_mds_set(stopping
, MDSMap::STATE_STOPPING
);
6567 stopping
.erase(mds
->get_nodeid());
6568 for (auto rank
: stopping
) {
6569 CInode
* mdsdir_in
= get_inode(MDS_INO_MDSDIR(rank
));
6573 if (expiremap
.count(rank
) == 0) {
6574 expiremap
[rank
] = new MCacheExpire(mds
->get_nodeid());
6577 dout(20) << __func__
<< ": try expiring " << *mdsdir_in
<< " for stopping mds." << mds
<< dendl
;
6579 const bool aborted
= expire_recursive(mdsdir_in
, expiremap
);
6581 dout(20) << __func__
<< ": successfully expired mdsdir" << dendl
;
6583 mdsdir_in
->get_dirfrags(ls
);
6584 for (auto dir
: ls
) {
6585 if (dir
->get_num_ref() == 1) // subtree pin
6586 trim_dirfrag(dir
, dir
, expiremap
);
6588 if (mdsdir_in
->get_num_ref() == 0)
6589 trim_inode(NULL
, mdsdir_in
, NULL
, expiremap
);
6591 dout(20) << __func__
<< ": some unexpirable contents in mdsdir" << dendl
;
6595 // Other rank's base inodes (when I'm stopping)
6596 if (mds
->is_stopping()) {
6597 for (set
<CInode
*>::iterator p
= base_inodes
.begin();
6598 p
!= base_inodes
.end(); ++p
) {
6599 if (MDS_INO_MDSDIR_OWNER((*p
)->ino()) != mds
->get_nodeid()) {
6600 dout(20) << __func__
<< ": maybe trimming base: " << *(*p
) << dendl
;
6601 if ((*p
)->get_num_ref() == 0) {
6602 trim_inode(NULL
, *p
, NULL
, expiremap
);
6608 // send any expire messages
6609 send_expire_messages(expiremap
);
6614 void MDCache::send_expire_messages(map
<mds_rank_t
, MCacheExpire
*>& expiremap
)
6617 for (map
<mds_rank_t
, MCacheExpire
*>::iterator it
= expiremap
.begin();
6618 it
!= expiremap
.end();
6620 if (mds
->is_cluster_degraded() &&
6621 (mds
->mdsmap
->get_state(it
->first
) < MDSMap::STATE_REJOIN
||
6622 (mds
->mdsmap
->get_state(it
->first
) == MDSMap::STATE_REJOIN
&&
6623 rejoin_sent
.count(it
->first
) == 0))) {
6627 dout(7) << "sending cache_expire to " << it
->first
<< dendl
;
6628 mds
->send_message_mds(it
->second
, it
->first
);
6633 bool MDCache::trim_dentry(CDentry
*dn
, map
<mds_rank_t
, MCacheExpire
*>& expiremap
)
6635 dout(12) << "trim_dentry " << *dn
<< dendl
;
6637 CDentry::linkage_t
*dnl
= dn
->get_linkage();
6639 CDir
*dir
= dn
->get_dir();
6642 CDir
*con
= get_subtree_root(dir
);
6644 dout(12) << " in container " << *con
<< dendl
;
6646 dout(12) << " no container; under a not-yet-linked dir" << dendl
;
6647 assert(dn
->is_auth());
6650 // If replica dentry is not readable, it's likely we will receive
6651 // MDentryLink/MDentryUnlink message soon (It's possible we first
6652 // receive a MDentryUnlink message, then MDentryLink message)
6653 // MDentryLink message only replicates an inode, so we should
6654 // avoid trimming the inode's parent dentry. This is because that
6655 // unconnected replicas are problematic for subtree migration.
6656 if (!dn
->is_auth() && !dn
->lock
.can_read(-1) &&
6657 !dn
->get_dir()->get_inode()->is_stray())
6660 // adjust the dir state
6661 // NOTE: we can safely remove a clean, null dentry without effecting
6662 // directory completeness.
6663 // (check this _before_ we unlink the inode, below!)
6664 bool clear_complete
= false;
6665 if (!(dnl
->is_null() && dn
->is_clean()))
6666 clear_complete
= true;
6668 // unlink the dentry
6669 if (dnl
->is_remote()) {
6671 dir
->unlink_inode(dn
, false);
6672 } else if (dnl
->is_primary()) {
6673 // expire the inode, too.
6674 CInode
*in
= dnl
->get_inode();
6676 if (trim_inode(dn
, in
, con
, expiremap
))
6677 return true; // purging stray instead of trimming
6679 assert(dnl
->is_null());
6682 if (!dn
->is_auth()) {
6683 // notify dentry authority.
6684 mds_authority_t auth
= dn
->authority();
6686 for (int p
=0; p
<2; p
++) {
6687 mds_rank_t a
= auth
.first
;
6688 if (p
) a
= auth
.second
;
6689 if (a
< 0 || (p
== 1 && auth
.second
== auth
.first
)) break;
6690 if (mds
->get_nodeid() == auth
.second
&&
6691 con
->is_importing()) break; // don't send any expire while importing.
6692 if (a
== mds
->get_nodeid()) continue; // on export, ignore myself.
6694 dout(12) << " sending expire to mds." << a
<< " on " << *dn
<< dendl
;
6695 assert(a
!= mds
->get_nodeid());
6696 if (expiremap
.count(a
) == 0)
6697 expiremap
[a
] = new MCacheExpire(mds
->get_nodeid());
6698 expiremap
[a
]->add_dentry(con
->dirfrag(), dir
->dirfrag(), dn
->name
, dn
->last
, dn
->get_replica_nonce());
6703 if (dn
->last
== CEPH_NOSNAP
&& dir
->is_auth())
6704 dir
->add_to_bloom(dn
);
6705 dir
->remove_dentry(dn
);
6708 dir
->state_clear(CDir::STATE_COMPLETE
);
6710 if (mds
->logger
) mds
->logger
->inc(l_mds_inodes_expired
);
6715 void MDCache::trim_dirfrag(CDir
*dir
, CDir
*con
, map
<mds_rank_t
, MCacheExpire
*>& expiremap
)
6717 dout(15) << "trim_dirfrag " << *dir
<< dendl
;
6719 if (dir
->is_subtree_root()) {
6720 assert(!dir
->is_auth() ||
6721 (!dir
->is_replicated() && dir
->inode
->is_base()));
6722 remove_subtree(dir
); // remove from subtree map
6724 assert(dir
->get_num_ref() == 0);
6726 CInode
*in
= dir
->get_inode();
6728 if (!dir
->is_auth()) {
6729 mds_authority_t auth
= dir
->authority();
6731 // was this an auth delegation? (if so, slightly modified container)
6733 if (dir
->is_subtree_root()) {
6734 dout(12) << " subtree root, container is " << *dir
<< dendl
;
6736 condf
= dir
->dirfrag();
6738 condf
= con
->dirfrag();
6741 for (int p
=0; p
<2; p
++) {
6742 mds_rank_t a
= auth
.first
;
6743 if (p
) a
= auth
.second
;
6744 if (a
< 0 || (p
== 1 && auth
.second
== auth
.first
)) break;
6745 if (mds
->get_nodeid() == auth
.second
&&
6746 con
->is_importing()) break; // don't send any expire while importing.
6747 if (a
== mds
->get_nodeid()) continue; // on export, ignore myself.
6749 dout(12) << " sending expire to mds." << a
<< " on " << *dir
<< dendl
;
6750 assert(a
!= mds
->get_nodeid());
6751 if (expiremap
.count(a
) == 0)
6752 expiremap
[a
] = new MCacheExpire(mds
->get_nodeid());
6753 expiremap
[a
]->add_dir(condf
, dir
->dirfrag(), dir
->replica_nonce
);
6757 in
->close_dirfrag(dir
->dirfrag().frag
);
6761 * Try trimming an inode from the cache
6763 * @return true if the inode is still in cache, else false if it was trimmed
6765 bool MDCache::trim_inode(CDentry
*dn
, CInode
*in
, CDir
*con
, map
<mds_rank_t
, MCacheExpire
*>& expiremap
)
6767 dout(15) << "trim_inode " << *in
<< dendl
;
6768 assert(in
->get_num_ref() == 0);
6771 // If replica inode's dirfragtreelock is not readable, it's likely
6772 // some dirfrags of the inode are being fragmented and we will receive
6773 // MMDSFragmentNotify soon. MMDSFragmentNotify only replicates the new
6774 // dirfrags, so we should avoid trimming these dirfrags' parent inode.
6775 // This is because that unconnected replicas are problematic for
6776 // subtree migration.
6778 if (!in
->is_auth() && !in
->dirfragtreelock
.can_read(-1))
6783 in
->get_dirfrags(dfls
);
6784 for (list
<CDir
*>::iterator p
= dfls
.begin(); p
!= dfls
.end(); ++p
) {
6786 assert(!dir
->is_subtree_root());
6787 trim_dirfrag(dir
, con
? con
:dir
, expiremap
); // if no container (e.g. root dirfrag), use *p
6792 if (in
->is_auth()) {
6793 // eval stray after closing dirfrags
6794 if (dn
&& !dn
->state_test(CDentry::STATE_PURGING
)) {
6795 maybe_eval_stray(in
);
6796 if (dn
->state_test(CDentry::STATE_PURGING
) || dn
->get_num_ref() > 0)
6800 mds_authority_t auth
= in
->authority();
6804 df
= con
->dirfrag();
6806 df
= dirfrag_t(0,frag_t()); // must be a root or stray inode.
6808 for (int p
=0; p
<2; p
++) {
6809 mds_rank_t a
= auth
.first
;
6810 if (p
) a
= auth
.second
;
6811 if (a
< 0 || (p
== 1 && auth
.second
== auth
.first
)) break;
6812 if (con
&& mds
->get_nodeid() == auth
.second
&&
6813 con
->is_importing()) break; // don't send any expire while importing.
6814 if (a
== mds
->get_nodeid()) continue; // on export, ignore myself.
6816 dout(12) << " sending expire to mds." << a
<< " on " << *in
<< dendl
;
6817 assert(a
!= mds
->get_nodeid());
6818 if (expiremap
.count(a
) == 0)
6819 expiremap
[a
] = new MCacheExpire(mds
->get_nodeid());
6820 expiremap
[a
]->add_inode(df
, in
->vino(), in
->get_replica_nonce());
6825 if (in->is_auth()) {
6826 if (in->hack_accessed)
6827 mds->logger->inc("outt");
6829 mds->logger->inc("outut");
6830 mds->logger->fset("oututl", ceph_clock_now() - in->hack_load_stamp);
6837 dn
->get_dir()->unlink_inode(dn
, false);
6844 * trim_non_auth - remove any non-auth items from our cache
6846 * this reduces the amount of non-auth metadata in our cache, reducing the
6847 * load incurred by the rejoin phase.
6849 * the only non-auth items that remain are those that are needed to
6850 * attach our own subtrees to the root.
6852 * when we are done, all dentries will be in the top bit of the lru.
6854 * why we have to do this:
6855 * we may not have accurate linkage for non-auth items. which means we will
6856 * know which subtree it falls into, and can not be sure to declare it to the
6857 * correct authority.
6859 void MDCache::trim_non_auth()
6861 dout(7) << "trim_non_auth" << dendl
;
6863 // temporarily pin all subtree roots
6864 for (map
<CDir
*, set
<CDir
*> >::iterator p
= subtrees
.begin();
6865 p
!= subtrees
.end();
6867 p
->first
->get(CDir::PIN_SUBTREETEMP
);
6869 list
<CDentry
*> auth_list
;
6871 // trim non-auth items from the lru
6874 if (bottom_lru
.lru_get_size() > 0)
6875 dn
= static_cast<CDentry
*>(bottom_lru
.lru_expire());
6876 if (!dn
&& lru
.lru_get_size() > 0)
6877 dn
= static_cast<CDentry
*>(lru
.lru_expire());
6881 CDentry::linkage_t
*dnl
= dn
->get_linkage();
6883 if (dn
->is_auth()) {
6884 // add back into lru (at the top)
6885 auth_list
.push_back(dn
);
6887 if (dnl
->is_remote() && dnl
->get_inode() && !dnl
->get_inode()->is_auth())
6888 dn
->unlink_remote(dnl
);
6890 // non-auth. expire.
6891 CDir
*dir
= dn
->get_dir();
6894 // unlink the dentry
6895 dout(10) << " removing " << *dn
<< dendl
;
6896 if (dnl
->is_remote()) {
6897 dir
->unlink_inode(dn
, false);
6899 else if (dnl
->is_primary()) {
6900 CInode
*in
= dnl
->get_inode();
6901 dout(10) << " removing " << *in
<< dendl
;
6903 in
->get_dirfrags(ls
);
6904 for (list
<CDir
*>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
6906 assert(!subdir
->is_subtree_root());
6907 in
->close_dirfrag(subdir
->dirfrag().frag
);
6909 dir
->unlink_inode(dn
, false);
6913 assert(dnl
->is_null());
6916 assert(!dir
->has_bloom());
6917 dir
->remove_dentry(dn
);
6918 // adjust the dir state
6919 dir
->state_clear(CDir::STATE_COMPLETE
); // dir incomplete!
6920 // close empty non-auth dirfrag
6921 if (!dir
->is_subtree_root() && dir
->get_num_any() == 0)
6922 dir
->inode
->close_dirfrag(dir
->get_frag());
6926 for (auto dn
: auth_list
) {
6927 if (dn
->state_test(CDentry::STATE_BOTTOMLRU
))
6928 bottom_lru
.lru_insert_mid(dn
);
6930 lru
.lru_insert_top(dn
);
6933 // move everything in the pintail to the top bit of the lru.
6934 lru
.lru_touch_entire_pintail();
6936 // unpin all subtrees
6937 for (map
<CDir
*, set
<CDir
*> >::iterator p
= subtrees
.begin();
6938 p
!= subtrees
.end();
6940 p
->first
->put(CDir::PIN_SUBTREETEMP
);
6942 if (lru
.lru_get_size() == 0 &&
6943 bottom_lru
.lru_get_size() == 0) {
6944 // root, stray, etc.?
6945 ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator p
= inode_map
.begin();
6946 while (p
!= inode_map
.end()) {
6947 ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator next
= p
;
6949 CInode
*in
= p
->second
;
6950 if (!in
->is_auth()) {
6952 in
->get_dirfrags(ls
);
6953 for (list
<CDir
*>::iterator p
= ls
.begin();
6956 dout(10) << " removing " << **p
<< dendl
;
6957 assert((*p
)->get_num_ref() == 1); // SUBTREE
6958 remove_subtree((*p
));
6959 in
->close_dirfrag((*p
)->dirfrag().frag
);
6961 dout(10) << " removing " << *in
<< dendl
;
6962 assert(!in
->get_parent_dn());
6963 assert(in
->get_num_ref() == 0);
6974 * Recursively trim the subtree rooted at directory to remove all
6975 * CInodes/CDentrys/CDirs that aren't links to remote MDSes, or ancestors
6976 * of those links. This is used to clear invalid data out of the cache.
6977 * Note that it doesn't clear the passed-in directory, since that's not
6980 bool MDCache::trim_non_auth_subtree(CDir
*dir
)
6982 dout(10) << "trim_non_auth_subtree(" << dir
<< ") " << *dir
<< dendl
;
6984 bool keep_dir
= !can_trim_non_auth_dirfrag(dir
);
6986 CDir::map_t::iterator j
= dir
->begin();
6987 CDir::map_t::iterator i
= j
;
6988 while (j
!= dir
->end()) {
6990 CDentry
*dn
= i
->second
;
6991 dout(10) << "trim_non_auth_subtree(" << dir
<< ") Checking dentry " << dn
<< dendl
;
6992 CDentry::linkage_t
*dnl
= dn
->get_linkage();
6993 if (dnl
->is_primary()) { // check for subdirectories, etc
6994 CInode
*in
= dnl
->get_inode();
6995 bool keep_inode
= false;
6997 list
<CDir
*> subdirs
;
6998 in
->get_dirfrags(subdirs
);
6999 for (list
<CDir
*>::iterator subdir
= subdirs
.begin();
7000 subdir
!= subdirs
.end();
7002 if ((*subdir
)->is_subtree_root()) {
7004 dout(10) << "trim_non_auth_subtree(" << dir
<< ") keeping " << **subdir
<< dendl
;
7006 if (trim_non_auth_subtree(*subdir
))
7009 in
->close_dirfrag((*subdir
)->get_frag());
7010 dir
->state_clear(CDir::STATE_COMPLETE
); // now incomplete!
7016 if (!keep_inode
) { // remove it!
7017 dout(20) << "trim_non_auth_subtree(" << dir
<< ") removing inode " << in
<< " with dentry" << dn
<< dendl
;
7018 dir
->unlink_inode(dn
, false);
7020 assert(!dir
->has_bloom());
7021 dir
->remove_dentry(dn
);
7023 dout(20) << "trim_non_auth_subtree(" << dir
<< ") keeping inode " << in
<< " with dentry " << dn
<<dendl
;
7024 dn
->state_clear(CDentry::STATE_AUTH
);
7025 in
->state_clear(CInode::STATE_AUTH
);
7027 } else if (keep_dir
&& dnl
->is_null()) { // keep null dentry for slave rollback
7028 dout(20) << "trim_non_auth_subtree(" << dir
<< ") keeping dentry " << dn
<<dendl
;
7029 } else { // just remove it
7030 dout(20) << "trim_non_auth_subtree(" << dir
<< ") removing dentry " << dn
<< dendl
;
7031 if (dnl
->is_remote())
7032 dir
->unlink_inode(dn
, false);
7033 dir
->remove_dentry(dn
);
7036 dir
->state_clear(CDir::STATE_AUTH
);
7038 * We've now checked all our children and deleted those that need it.
7039 * Now return to caller, and tell them if *we're* a keeper.
7041 return keep_dir
|| dir
->get_num_any();
7045 * during replay, when we determine a subtree is no longer ours, we
7046 * try to trim it from our cache. because subtrees must be connected
7047 * to the root, the fact that we can trim this tree may mean that our
7048 * children or parents can also be trimmed.
7050 void MDCache::try_trim_non_auth_subtree(CDir
*dir
)
7052 dout(10) << "try_trim_nonauth_subtree " << *dir
<< dendl
;
7054 // can we now trim child subtrees?
7056 get_subtree_bounds(dir
, bounds
);
7057 for (set
<CDir
*>::iterator p
= bounds
.begin(); p
!= bounds
.end(); ++p
) {
7059 if (bd
->get_dir_auth().first
!= mds
->get_nodeid() && // we are not auth
7060 bd
->get_num_any() == 0 && // and empty
7061 can_trim_non_auth_dirfrag(bd
)) {
7062 CInode
*bi
= bd
->get_inode();
7063 dout(10) << " closing empty non-auth child subtree " << *bd
<< dendl
;
7066 bi
->close_dirfrag(bd
->get_frag());
7070 if (trim_non_auth_subtree(dir
)) {
7072 try_subtree_merge(dir
);
7074 // can we trim this subtree (and possibly our ancestors) too?
7076 CInode
*diri
= dir
->get_inode();
7077 if (diri
->is_base()) {
7078 if (!diri
->is_root() && diri
->authority().first
!= mds
->get_nodeid()) {
7079 dout(10) << " closing empty non-auth subtree " << *dir
<< dendl
;
7080 remove_subtree(dir
);
7082 diri
->close_dirfrag(dir
->get_frag());
7084 dout(10) << " removing " << *diri
<< dendl
;
7085 assert(!diri
->get_parent_dn());
7086 assert(diri
->get_num_ref() == 0);
7092 CDir
*psub
= get_subtree_root(diri
->get_parent_dir());
7093 dout(10) << " parent subtree is " << *psub
<< dendl
;
7094 if (psub
->get_dir_auth().first
== mds
->get_nodeid())
7095 break; // we are auth, keep.
7097 dout(10) << " closing empty non-auth subtree " << *dir
<< dendl
;
7098 remove_subtree(dir
);
7100 diri
->close_dirfrag(dir
->get_frag());
7102 dout(10) << " parent subtree also non-auth: " << *psub
<< dendl
;
7103 if (trim_non_auth_subtree(psub
))
7112 void MDCache::standby_trim_segment(LogSegment
*ls
)
7114 ls
->new_dirfrags
.clear_list();
7115 ls
->open_files
.clear_list();
7117 while (!ls
->dirty_dirfrags
.empty()) {
7118 CDir
*dir
= ls
->dirty_dirfrags
.front();
7121 while (!ls
->dirty_inodes
.empty()) {
7122 CInode
*in
= ls
->dirty_inodes
.front();
7125 while (!ls
->dirty_dentries
.empty()) {
7126 CDentry
*dn
= ls
->dirty_dentries
.front();
7129 while (!ls
->dirty_parent_inodes
.empty()) {
7130 CInode
*in
= ls
->dirty_parent_inodes
.front();
7131 in
->clear_dirty_parent();
7133 while (!ls
->dirty_dirfrag_dir
.empty()) {
7134 CInode
*in
= ls
->dirty_dirfrag_dir
.front();
7135 in
->filelock
.remove_dirty();
7137 while (!ls
->dirty_dirfrag_nest
.empty()) {
7138 CInode
*in
= ls
->dirty_dirfrag_nest
.front();
7139 in
->nestlock
.remove_dirty();
7141 while (!ls
->dirty_dirfrag_dirfragtree
.empty()) {
7142 CInode
*in
= ls
->dirty_dirfrag_dirfragtree
.front();
7143 in
->dirfragtreelock
.remove_dirty();
7147 /* This function DOES put the passed message before returning */
7148 void MDCache::handle_cache_expire(MCacheExpire
*m
)
7150 mds_rank_t from
= mds_rank_t(m
->get_from());
7152 dout(7) << "cache_expire from mds." << from
<< dendl
;
7154 if (mds
->get_state() < MDSMap::STATE_REJOIN
) {
7159 set
<SimpleLock
*> gather_locks
;
7161 for (map
<dirfrag_t
,MCacheExpire::realm
>::iterator p
= m
->realms
.begin();
7162 p
!= m
->realms
.end();
7165 if (p
->first
.ino
> 0) {
7166 CInode
*expired_inode
= get_inode(p
->first
.ino
);
7167 assert(expired_inode
); // we had better have this.
7168 CDir
*parent_dir
= expired_inode
->get_approx_dirfrag(p
->first
.frag
);
7171 int export_state
= -1;
7172 if (parent_dir
->is_auth() && parent_dir
->is_exporting()) {
7173 export_state
= migrator
->get_export_state(parent_dir
);
7174 assert(export_state
>= 0);
7177 if (!parent_dir
->is_auth() ||
7178 (export_state
!= -1 &&
7179 ((export_state
== Migrator::EXPORT_WARNING
&&
7180 migrator
->export_has_warned(parent_dir
,from
)) ||
7181 export_state
== Migrator::EXPORT_EXPORTING
||
7182 export_state
== Migrator::EXPORT_LOGGINGFINISH
||
7183 (export_state
== Migrator::EXPORT_NOTIFYING
&&
7184 !migrator
->export_has_notified(parent_dir
,from
))))) {
7187 dout(7) << "delaying nonauth|warned expires for " << *parent_dir
<< dendl
;
7188 assert(parent_dir
->is_frozen_tree_root());
7190 // make a message container
7191 if (delayed_expire
[parent_dir
].count(from
) == 0)
7192 delayed_expire
[parent_dir
][from
] = new MCacheExpire(from
);
7194 // merge these expires into it
7195 delayed_expire
[parent_dir
][from
]->add_realm(p
->first
, p
->second
);
7198 assert(export_state
<= Migrator::EXPORT_PREPPING
||
7199 (export_state
== Migrator::EXPORT_WARNING
&&
7200 !migrator
->export_has_warned(parent_dir
, from
)));
7202 dout(7) << "expires for " << *parent_dir
<< dendl
;
7204 dout(7) << "containerless expires (root, stray inodes)" << dendl
;
7208 for (map
<vinodeno_t
,uint32_t>::iterator it
= p
->second
.inodes
.begin();
7209 it
!= p
->second
.inodes
.end();
7211 CInode
*in
= get_inode(it
->first
);
7212 unsigned nonce
= it
->second
;
7215 dout(0) << " inode expire on " << it
->first
<< " from " << from
7216 << ", don't have it" << dendl
;
7219 assert(in
->is_auth());
7220 dout(20) << __func__
<< ": expiring inode " << *in
<< dendl
;
7223 if (nonce
== in
->get_replica_nonce(from
)) {
7224 // remove from our cached_by
7225 dout(7) << " inode expire on " << *in
<< " from mds." << from
7226 << " cached_by was " << in
->get_replicas() << dendl
;
7227 inode_remove_replica(in
, from
, false, gather_locks
);
7230 // this is an old nonce, ignore expire.
7231 dout(7) << " inode expire on " << *in
<< " from mds." << from
7232 << " with old nonce " << nonce
7233 << " (current " << in
->get_replica_nonce(from
) << "), dropping"
7239 for (map
<dirfrag_t
,uint32_t>::iterator it
= p
->second
.dirs
.begin();
7240 it
!= p
->second
.dirs
.end();
7242 CDir
*dir
= get_dirfrag(it
->first
);
7243 unsigned nonce
= it
->second
;
7246 CInode
*diri
= get_inode(it
->first
.ino
);
7248 if (mds
->is_rejoin() &&
7249 rejoin_ack_gather
.count(mds
->get_nodeid()) && // haven't sent rejoin ack yet
7250 !diri
->is_replica(from
)) {
7252 diri
->get_nested_dirfrags(ls
);
7253 dout(7) << " dir expire on dirfrag " << it
->first
<< " from mds." << from
7254 << " while rejoining, inode isn't replicated" << dendl
;
7255 for (list
<CDir
*>::iterator q
= ls
.begin(); q
!= ls
.end(); ++q
) {
7257 if (dir
->is_replica(from
)) {
7258 dout(7) << " dir expire on " << *dir
<< " from mds." << from
<< dendl
;
7259 dir
->remove_replica(from
);
7264 CDir
*other
= diri
->get_approx_dirfrag(it
->first
.frag
);
7266 dout(7) << " dir expire on dirfrag " << it
->first
<< " from mds." << from
7267 << " have " << *other
<< ", mismatched frags, dropping" << dendl
;
7271 dout(0) << " dir expire on " << it
->first
<< " from " << from
7272 << ", don't have it" << dendl
;
7275 dout(20) << __func__
<< ": expiring dirfrag " << *dir
<< dendl
;
7277 assert(dir
->is_auth());
7280 if (nonce
== dir
->get_replica_nonce(from
)) {
7281 // remove from our cached_by
7282 dout(7) << " dir expire on " << *dir
<< " from mds." << from
7283 << " replicas was " << dir
->get_replicas() << dendl
;
7284 dir
->remove_replica(from
);
7287 // this is an old nonce, ignore expire.
7288 dout(7) << " dir expire on " << *dir
<< " from mds." << from
7289 << " with old nonce " << nonce
<< " (current " << dir
->get_replica_nonce(from
)
7290 << "), dropping" << dendl
;
7295 for (map
<dirfrag_t
, map
<pair
<string
,snapid_t
>,uint32_t> >::iterator pd
= p
->second
.dentries
.begin();
7296 pd
!= p
->second
.dentries
.end();
7298 dout(10) << " dn expires in dir " << pd
->first
<< dendl
;
7299 CInode
*diri
= get_inode(pd
->first
.ino
);
7301 CDir
*dir
= diri
->get_dirfrag(pd
->first
.frag
);
7304 dout(0) << " dn expires on " << pd
->first
<< " from " << from
7305 << ", must have refragmented" << dendl
;
7307 assert(dir
->is_auth());
7310 for (map
<pair
<string
,snapid_t
>,uint32_t>::iterator p
= pd
->second
.begin();
7311 p
!= pd
->second
.end();
7313 unsigned nonce
= p
->second
;
7317 dn
= dir
->lookup(p
->first
.first
, p
->first
.second
);
7319 // which dirfrag for this dentry?
7320 CDir
*dir
= diri
->get_dirfrag(diri
->pick_dirfrag(p
->first
.first
));
7322 assert(dir
->is_auth());
7323 dn
= dir
->lookup(p
->first
.first
, p
->first
.second
);
7328 dout(0) << " missing dentry for " << p
->first
.first
<< " snap " << p
->first
.second
<< " in " << *dir
<< dendl
;
7330 dout(0) << " missing dentry for " << p
->first
.first
<< " snap " << p
->first
.second
<< dendl
;
7334 if (nonce
== dn
->get_replica_nonce(from
)) {
7335 dout(7) << " dentry_expire on " << *dn
<< " from mds." << from
<< dendl
;
7336 dentry_remove_replica(dn
, from
, gather_locks
);
7339 dout(7) << " dentry_expire on " << *dn
<< " from mds." << from
7340 << " with old nonce " << nonce
<< " (current " << dn
->get_replica_nonce(from
)
7341 << "), dropping" << dendl
;
7350 for (set
<SimpleLock
*>::iterator p
= gather_locks
.begin(); p
!= gather_locks
.end(); ++p
) {
7351 if (!(*p
)->is_stable())
7352 mds
->locker
->eval_gather(*p
);
7356 void MDCache::process_delayed_expire(CDir
*dir
)
7358 dout(7) << "process_delayed_expire on " << *dir
<< dendl
;
7359 for (map
<mds_rank_t
,MCacheExpire
*>::iterator p
= delayed_expire
[dir
].begin();
7360 p
!= delayed_expire
[dir
].end();
7362 handle_cache_expire(p
->second
);
7363 delayed_expire
.erase(dir
);
7366 void MDCache::discard_delayed_expire(CDir
*dir
)
7368 dout(7) << "discard_delayed_expire on " << *dir
<< dendl
;
7369 for (map
<mds_rank_t
,MCacheExpire
*>::iterator p
= delayed_expire
[dir
].begin();
7370 p
!= delayed_expire
[dir
].end();
7373 delayed_expire
.erase(dir
);
7376 void MDCache::inode_remove_replica(CInode
*in
, mds_rank_t from
, bool rejoin
,
7377 set
<SimpleLock
*>& gather_locks
)
7379 in
->remove_replica(from
);
7380 in
->mds_caps_wanted
.erase(from
);
7382 // note: this code calls _eval more often than it needs to!
7384 if (in
->authlock
.remove_replica(from
)) gather_locks
.insert(&in
->authlock
);
7385 if (in
->linklock
.remove_replica(from
)) gather_locks
.insert(&in
->linklock
);
7386 if (in
->snaplock
.remove_replica(from
)) gather_locks
.insert(&in
->snaplock
);
7387 if (in
->xattrlock
.remove_replica(from
)) gather_locks
.insert(&in
->xattrlock
);
7388 if (in
->flocklock
.remove_replica(from
)) gather_locks
.insert(&in
->flocklock
);
7389 if (in
->policylock
.remove_replica(from
)) gather_locks
.insert(&in
->policylock
);
7391 // If 'rejoin' is true and the scatter lock is in LOCK_MIX_* state.
7392 // Don't remove the recovering mds from lock's gathering list because
7393 // it may hold rejoined wrlocks.
7394 if (in
->dirfragtreelock
.remove_replica(from
, rejoin
)) gather_locks
.insert(&in
->dirfragtreelock
);
7395 if (in
->filelock
.remove_replica(from
, rejoin
)) gather_locks
.insert(&in
->filelock
);
7396 if (in
->nestlock
.remove_replica(from
, rejoin
)) gather_locks
.insert(&in
->nestlock
);
7399 void MDCache::dentry_remove_replica(CDentry
*dn
, mds_rank_t from
, set
<SimpleLock
*>& gather_locks
)
7401 dn
->remove_replica(from
);
7404 if (dn
->lock
.remove_replica(from
))
7405 gather_locks
.insert(&dn
->lock
);
7407 // Replicated strays might now be elegible for purge
7408 CDentry::linkage_t
*dnl
= dn
->get_linkage();
7409 if (dnl
->is_primary()) {
7410 maybe_eval_stray(dnl
->get_inode());
7414 void MDCache::trim_client_leases()
7416 utime_t now
= ceph_clock_now();
7418 dout(10) << "trim_client_leases" << dendl
;
7420 for (int pool
=0; pool
<client_lease_pools
; pool
++) {
7421 int before
= client_leases
[pool
].size();
7422 if (client_leases
[pool
].empty())
7425 while (!client_leases
[pool
].empty()) {
7426 ClientLease
*r
= client_leases
[pool
].front();
7427 if (r
->ttl
> now
) break;
7428 CDentry
*dn
= static_cast<CDentry
*>(r
->parent
);
7429 dout(10) << " expiring client." << r
->client
<< " lease of " << *dn
<< dendl
;
7430 dn
->remove_client_lease(r
, mds
->locker
);
7432 int after
= client_leases
[pool
].size();
7433 dout(10) << "trim_client_leases pool " << pool
<< " trimmed "
7434 << (before
-after
) << " leases, " << after
<< " left" << dendl
;
7439 void MDCache::check_memory_usage()
7441 static MemoryModel
mm(g_ceph_context
);
7442 static MemoryModel::snap last
;
7444 static MemoryModel::snap baseline
= last
;
7446 // check client caps
7447 assert(CInode::count() == inode_map
.size());
7448 double caps_per_inode
= 0.0;
7449 if (CInode::count())
7450 caps_per_inode
= (double)Capability::count() / (double)CInode::count();
7452 dout(2) << "check_memory_usage"
7453 << " total " << last
.get_total()
7454 << ", rss " << last
.get_rss()
7455 << ", heap " << last
.get_heap()
7456 << ", baseline " << baseline
.get_heap()
7457 << ", buffers " << (buffer::get_total_alloc() >> 10)
7458 << ", " << num_inodes_with_caps
<< " / " << CInode::count() << " inodes have caps"
7459 << ", " << Capability::count() << " caps, " << caps_per_inode
<< " caps per inode"
7462 mds
->update_mlogger();
7463 mds
->mlogger
->set(l_mdm_rss
, last
.get_rss());
7464 mds
->mlogger
->set(l_mdm_heap
, last
.get_heap());
7466 if (cache_toofull()) {
7467 last_recall_state
= ceph_clock_now();
7468 mds
->server
->recall_client_state();
7471 // If the cache size had exceeded its limit, but we're back in bounds
7472 // now, free any unused pool memory so that our memory usage isn't
7473 // permanently bloated.
7474 if (exceeded_size_limit
&& !cache_toofull()) {
7475 // Only do this once we are back in bounds: otherwise the releases would
7476 // slow down whatever process caused us to exceed bounds to begin with
7477 if (ceph_using_tcmalloc()) {
7478 dout(2) << "check_memory_usage: releasing unused space from tcmalloc"
7480 ceph_heap_release_free_memory();
7482 exceeded_size_limit
= false;
7488 // =========================================================================================
7491 class C_MDC_ShutdownCheck
: public MDCacheContext
{
7493 explicit C_MDC_ShutdownCheck(MDCache
*m
) : MDCacheContext(m
) {}
7494 void finish(int) override
{
7495 mdcache
->shutdown_check();
7499 void MDCache::shutdown_check()
7501 dout(0) << "shutdown_check at " << ceph_clock_now() << dendl
;
7504 char old_val
[32] = { 0 };
7506 g_conf
->get_val("debug_mds", &o
, sizeof(old_val
));
7507 g_conf
->set_val("debug_mds", "10");
7508 g_conf
->apply_changes(NULL
);
7510 g_conf
->set_val("debug_mds", old_val
);
7511 g_conf
->apply_changes(NULL
);
7512 mds
->timer
.add_event_after(g_conf
->mds_shutdown_check
, new C_MDC_ShutdownCheck(this));
7515 dout(0) << "lru size now " << lru
.lru_get_size() << "/" << bottom_lru
.lru_get_size() << dendl
;
7516 dout(0) << "log len " << mds
->mdlog
->get_num_events() << dendl
;
7519 if (mds
->objecter
->is_active()) {
7520 dout(0) << "objecter still active" << dendl
;
7521 mds
->objecter
->dump_active();
7526 void MDCache::shutdown_start()
7528 dout(2) << "shutdown_start" << dendl
;
7530 if (g_conf
->mds_shutdown_check
)
7531 mds
->timer
.add_event_after(g_conf
->mds_shutdown_check
, new C_MDC_ShutdownCheck(this));
7533 // g_conf->debug_mds = 10;
7538 bool MDCache::shutdown_pass()
7540 dout(7) << "shutdown_pass" << dendl
;
7542 if (mds
->is_stopped()) {
7543 dout(7) << " already shut down" << dendl
;
7550 if (!shutdown_export_strays()) {
7551 dout(7) << "waiting for strays to migrate" << dendl
;
7555 // drop our reference to our stray dir inode
7556 for (int i
= 0; i
< NUM_STRAY
; ++i
) {
7558 strays
[i
]->state_test(CInode::STATE_STRAYPINNED
)) {
7559 strays
[i
]->state_clear(CInode::STATE_STRAYPINNED
);
7560 strays
[i
]->put(CInode::PIN_STRAY
);
7561 strays
[i
]->put_stickydirs();
7567 dout(5) << "lru size now " << lru
.lru_get_size() << "/" << bottom_lru
.lru_get_size() << dendl
;
7570 int num_auth_subtree
= 0;
7571 if (!subtrees
.empty() &&
7572 mds
->get_nodeid() != 0 &&
7573 migrator
->get_export_queue_size() == 0) {
7574 dout(7) << "looking for subtrees to export to mds0" << dendl
;
7576 for (map
<CDir
*, set
<CDir
*> >::iterator it
= subtrees
.begin();
7577 it
!= subtrees
.end();
7579 CDir
*dir
= it
->first
;
7580 if (dir
->get_inode()->is_mdsdir())
7582 if (dir
->is_auth()) {
7584 if (dir
->is_frozen() ||
7585 dir
->is_freezing() ||
7586 dir
->is_ambiguous_dir_auth() ||
7587 dir
->state_test(CDir::STATE_EXPORTING
))
7592 for (list
<CDir
*>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
7594 mds_rank_t dest
= dir
->get_inode()->authority().first
;
7595 if (dest
> 0 && !mds
->mdsmap
->is_active(dest
))
7597 dout(7) << "sending " << *dir
<< " back to mds." << dest
<< dendl
;
7598 migrator
->export_dir_nicely(dir
, dest
);
7602 if (num_auth_subtree
> 0) {
7603 dout(7) << "still have " << num_auth_subtree
<< " auth subtrees" << dendl
;
7608 // close out any sessions (and open files!) before we try to trim the log, etc.
7609 if (mds
->sessionmap
.have_unclosed_sessions()) {
7610 if (!mds
->server
->terminating_sessions
)
7611 mds
->server
->terminate_sessions();
7615 CDir
*mydir
= myin
? myin
->get_dirfrag(frag_t()) : NULL
;
7616 if (mydir
&& !mydir
->is_subtree_root())
7619 // subtrees map not empty yet?
7620 if (subtrees
.size() > (mydir
? 1 : 0)) {
7621 dout(7) << "still have " << num_subtrees() << " subtrees" << dendl
;
7623 migrator
->show_importing();
7624 migrator
->show_exporting();
7625 if (!migrator
->is_importing() && !migrator
->is_exporting())
7629 assert(!migrator
->is_exporting());
7630 assert(!migrator
->is_importing());
7632 // flush what we can from the log
7633 mds
->mdlog
->trim(0);
7634 if (mds
->mdlog
->get_num_segments() > 1) {
7635 dout(7) << "still >1 segments, waiting for log to trim" << dendl
;
7639 if ((myin
&& myin
->is_auth_pinned()) ||
7640 (mydir
&& mydir
->is_auth_pinned())) {
7641 dout(7) << "still have auth pinned objects" << dendl
;
7645 // (only do this once!)
7646 if (!mds
->mdlog
->is_capped()) {
7647 dout(7) << "capping the log" << dendl
;
7652 if (!mds
->mdlog
->empty()) {
7653 dout(7) << "waiting for log to flush.. " << mds
->mdlog
->get_num_events()
7654 << " in " << mds
->mdlog
->get_num_segments() << " segments" << dendl
;
7658 if (!did_shutdown_log_cap
) {
7659 // flush journal header
7660 dout(7) << "writing header for (now-empty) journal" << dendl
;
7661 assert(mds
->mdlog
->empty());
7662 mds
->mdlog
->write_head(0);
7663 // NOTE: filer active checker below will block us until this completes.
7664 did_shutdown_log_cap
= true;
7669 if (mds
->objecter
->is_active()) {
7670 dout(7) << "objecter still active" << dendl
;
7671 mds
->objecter
->dump_active();
7675 // trim what we can from the cache
7676 if (lru
.lru_get_size() > 0 || bottom_lru
.lru_get_size() > 0) {
7677 dout(7) << "there's still stuff in the cache: " << lru
.lru_get_size() << "/" << bottom_lru
.lru_get_size() << dendl
;
7683 // make mydir subtree go away
7685 if (mydir
->get_num_ref() > 1) { // subtree pin
7686 dout(7) << "there's still reference to mydir " << *mydir
<< dendl
;
7691 remove_subtree(mydir
);
7692 myin
->close_dirfrag(mydir
->get_frag());
7694 assert(subtrees
.empty());
7700 dout(2) << "shutdown done." << dendl
;
7704 bool MDCache::shutdown_export_strays()
7706 if (mds
->get_nodeid() == 0)
7709 dout(10) << "shutdown_export_strays" << dendl
;
7711 bool mds0_active
= mds
->mdsmap
->is_active(mds_rank_t(0));
7716 for (int i
= 0; i
< NUM_STRAY
; ++i
) {
7720 strays
[i
]->get_dirfrags(dfs
);
7723 for (std::list
<CDir
*>::iterator dfs_i
= dfs
.begin();
7724 dfs_i
!= dfs
.end(); ++dfs_i
)
7728 if (!dir
->is_complete()) {
7735 for (CDir::map_t::iterator p
= dir
->items
.begin();
7736 p
!= dir
->items
.end();
7738 CDentry
*dn
= p
->second
;
7739 CDentry::linkage_t
*dnl
= dn
->get_linkage();
7746 if (dn
->state_test(CDentry::STATE_PURGING
)) {
7747 // Don't try to migrate anything that is actually
7748 // being purged right now
7752 if (shutdown_exported_strays
.count(dnl
->get_inode()->ino()) == 0) {
7753 shutdown_exported_strays
.insert(dnl
->get_inode()->ino());
7754 stray_manager
.migrate_stray(dn
, mds_rank_t(0)); // send to root!
7756 dout(10) << "already exporting " << *dn
<< dendl
;
7764 // ========= messaging ==============
7766 /* This function DOES put the passed message before returning */
7767 void MDCache::dispatch(Message
*m
)
7769 switch (m
->get_type()) {
7772 case MSG_MDS_RESOLVE
:
7773 handle_resolve(static_cast<MMDSResolve
*>(m
));
7775 case MSG_MDS_RESOLVEACK
:
7776 handle_resolve_ack(static_cast<MMDSResolveAck
*>(m
));
7780 case MSG_MDS_CACHEREJOIN
:
7781 handle_cache_rejoin(static_cast<MMDSCacheRejoin
*>(m
));
7784 case MSG_MDS_DISCOVER
:
7785 handle_discover(static_cast<MDiscover
*>(m
));
7787 case MSG_MDS_DISCOVERREPLY
:
7788 handle_discover_reply(static_cast<MDiscoverReply
*>(m
));
7791 case MSG_MDS_DIRUPDATE
:
7792 handle_dir_update(static_cast<MDirUpdate
*>(m
));
7795 case MSG_MDS_CACHEEXPIRE
:
7796 handle_cache_expire(static_cast<MCacheExpire
*>(m
));
7799 case MSG_MDS_DENTRYLINK
:
7800 handle_dentry_link(static_cast<MDentryLink
*>(m
));
7802 case MSG_MDS_DENTRYUNLINK
:
7803 handle_dentry_unlink(static_cast<MDentryUnlink
*>(m
));
7806 case MSG_MDS_FRAGMENTNOTIFY
:
7807 handle_fragment_notify(static_cast<MMDSFragmentNotify
*>(m
));
7810 case MSG_MDS_FINDINO
:
7811 handle_find_ino(static_cast<MMDSFindIno
*>(m
));
7813 case MSG_MDS_FINDINOREPLY
:
7814 handle_find_ino_reply(static_cast<MMDSFindInoReply
*>(m
));
7817 case MSG_MDS_OPENINO
:
7818 handle_open_ino(static_cast<MMDSOpenIno
*>(m
));
7820 case MSG_MDS_OPENINOREPLY
:
7821 handle_open_ino_reply(static_cast<MMDSOpenInoReply
*>(m
));
7825 derr
<< "cache unknown message " << m
->get_type() << dendl
;
7826 assert(0 == "cache unknown message");
7830 MDSInternalContextBase
*MDCache::_get_waiter(MDRequestRef
& mdr
, Message
*req
, MDSInternalContextBase
*fin
)
7833 dout(20) << "_get_waiter retryrequest" << dendl
;
7834 return new C_MDS_RetryRequest(this, mdr
);
7836 dout(20) << "_get_waiter retrymessage" << dendl
;
7837 return new C_MDS_RetryMessage(mds
, req
);
7843 int MDCache::path_traverse(MDRequestRef
& mdr
, Message
*req
, MDSInternalContextBase
*fin
, // who
7844 const filepath
& path
, // what
7845 vector
<CDentry
*> *pdnvec
, // result
7849 bool discover
= (onfail
== MDS_TRAVERSE_DISCOVER
);
7850 bool null_okay
= (onfail
== MDS_TRAVERSE_DISCOVERXLOCK
);
7851 bool forward
= (onfail
== MDS_TRAVERSE_FORWARD
);
7853 assert(mdr
|| req
|| fin
);
7854 assert(!forward
|| mdr
|| req
); // forward requires a request
7856 snapid_t snapid
= CEPH_NOSNAP
;
7858 mdr
->snapid
= snapid
;
7860 client_t client
= (mdr
&& mdr
->reqid
.name
.is_client()) ? mdr
->reqid
.name
.num() : -1;
7862 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse
);
7864 dout(7) << "traverse: opening base ino " << path
.get_ino() << " snap " << snapid
<< dendl
;
7865 CInode
*cur
= get_inode(path
.get_ino());
7867 if (MDS_INO_IS_MDSDIR(path
.get_ino()))
7868 open_foreign_mdsdir(path
.get_ino(), _get_waiter(mdr
, req
, fin
));
7870 //ceph_abort(); // hrm.. broken
7875 if (cur
->state_test(CInode::STATE_PURGING
))
7878 // make sure snaprealm are open...
7879 if (mdr
&& cur
->snaprealm
&& !cur
->snaprealm
->is_open() &&
7880 !cur
->snaprealm
->open_parents(_get_waiter(mdr
, req
, fin
))) {
7891 while (depth
< path
.depth()) {
7892 dout(12) << "traverse: path seg depth " << depth
<< " '" << path
[depth
]
7893 << "' snapid " << snapid
<< dendl
;
7895 if (!cur
->is_dir()) {
7896 dout(7) << "traverse: " << *cur
<< " not a dir " << dendl
;
7900 // walk into snapdir?
7901 if (path
[depth
].length() == 0) {
7902 dout(10) << "traverse: snapdir" << dendl
;
7905 snapid
= CEPH_SNAPDIR
;
7906 mdr
->snapid
= snapid
;
7910 // walk thru snapdir?
7911 if (snapid
== CEPH_SNAPDIR
) {
7914 SnapRealm
*realm
= cur
->find_snaprealm();
7915 snapid
= realm
->resolve_snapname(path
[depth
], cur
->ino());
7916 dout(10) << "traverse: snap " << path
[depth
] << " -> " << snapid
<< dendl
;
7919 mdr
->snapid
= snapid
;
7925 frag_t fg
= cur
->pick_dirfrag(path
[depth
]);
7926 CDir
*curdir
= cur
->get_dirfrag(fg
);
7928 if (cur
->is_auth()) {
7929 // parent dir frozen_dir?
7930 if (cur
->is_frozen()) {
7931 dout(7) << "traverse: " << *cur
<< " is frozen, waiting" << dendl
;
7932 cur
->add_waiter(CDir::WAIT_UNFREEZE
, _get_waiter(mdr
, req
, fin
));
7935 curdir
= cur
->get_or_open_dirfrag(this, fg
);
7938 dout(10) << "traverse: need dirfrag " << fg
<< ", doing discover from " << *cur
<< dendl
;
7939 discover_path(cur
, snapid
, path
.postfixpath(depth
), _get_waiter(mdr
, req
, fin
),
7941 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse_discover
);
7947 #ifdef MDS_VERIFY_FRAGSTAT
7948 if (curdir
->is_complete())
7949 curdir
->verify_fragstat();
7954 if (curdir->is_frozen()) {
7956 // FIXME: traverse is allowed?
7957 dout(7) << "traverse: " << *curdir << " is frozen, waiting" << dendl;
7958 curdir->add_waiter(CDir::WAIT_UNFREEZE, _get_waiter(mdr, req, fin));
7959 if (onfinish) delete onfinish;
7964 // Before doing dirfrag->dn lookup, compare with DamageTable's
7965 // record of which dentries were unreadable
7966 if (mds
->damage_table
.is_dentry_damaged(curdir
, path
[depth
], snapid
)) {
7967 dout(4) << "traverse: stopped lookup at damaged dentry "
7968 << *curdir
<< "/" << path
[depth
] << " snap=" << snapid
<< dendl
;
7973 CDentry
*dn
= curdir
->lookup(path
[depth
], snapid
);
7974 CDentry::linkage_t
*dnl
= dn
? dn
->get_projected_linkage() : 0;
7976 // null and last_bit and xlocked by me?
7977 if (dnl
&& dnl
->is_null() && null_okay
) {
7978 dout(10) << "traverse: hit null dentry at tail of traverse, succeeding" << dendl
;
7980 pdnvec
->push_back(dn
);
7987 dn
->lock
.is_xlocked() &&
7988 dn
->lock
.get_xlock_by() != mdr
&&
7989 !dn
->lock
.can_read(client
) &&
7990 (dnl
->is_null() || forward
)) {
7991 dout(10) << "traverse: xlocked dentry at " << *dn
<< dendl
;
7992 dn
->lock
.add_waiter(SimpleLock::WAIT_RD
, _get_waiter(mdr
, req
, fin
));
7993 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse_lock
);
7994 mds
->mdlog
->flush();
7998 // can we conclude ENOENT?
7999 if (dnl
&& dnl
->is_null()) {
8000 if (dn
->lock
.can_read(client
) ||
8001 (dn
->lock
.is_xlocked() && dn
->lock
.get_xlock_by() == mdr
)) {
8002 dout(10) << "traverse: miss on null+readable dentry " << path
[depth
] << " " << *dn
<< dendl
;
8004 if (depth
== path
.depth() - 1)
8005 pdnvec
->push_back(dn
);
8007 pdnvec
->clear(); // do not confuse likes of rdlock_path_pin_ref();
8011 dout(10) << "miss on dentry " << *dn
<< ", can't read due to lock" << dendl
;
8012 dn
->lock
.add_waiter(SimpleLock::WAIT_RD
, _get_waiter(mdr
, req
, fin
));
8017 if (dnl
&& !dnl
->is_null()) {
8018 CInode
*in
= dnl
->get_inode();
8020 // do we have inode?
8022 assert(dnl
->is_remote());
8024 in
= get_inode(dnl
->get_remote_ino());
8026 dout(7) << "linking in remote in " << *in
<< dendl
;
8027 dn
->link_remote(dnl
, in
);
8029 dout(7) << "remote link to " << dnl
->get_remote_ino() << ", which i don't have" << dendl
;
8030 assert(mdr
); // we shouldn't hit non-primary dentries doing a non-mdr traversal!
8031 if (mds
->damage_table
.is_remote_damaged(dnl
->get_remote_ino())) {
8032 dout(4) << "traverse: remote dentry points to damaged ino "
8036 open_remote_dentry(dn
, true, _get_waiter(mdr
, req
, fin
),
8037 (null_okay
&& depth
== path
.depth() - 1));
8038 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse_remote_ino
);
8044 // make sure snaprealm are open...
8045 if (mdr
&& cur
->snaprealm
&& !cur
->snaprealm
->is_open() &&
8046 !cur
->snaprealm
->open_parents(_get_waiter(mdr
, req
, fin
))) {
8050 // add to trace, continue.
8053 pdnvec
->push_back(dn
);
8061 // MISS. dentry doesn't exist.
8062 dout(12) << "traverse: miss on dentry " << path
[depth
] << " in " << *curdir
<< dendl
;
8064 if (curdir
->is_auth()) {
8066 if (curdir
->is_complete() ||
8067 (snapid
== CEPH_NOSNAP
&&
8068 curdir
->has_bloom() &&
8069 !curdir
->is_in_bloom(path
[depth
]))){
8072 // instantiate a null dn?
8073 if (depth
< path
.depth()-1){
8074 dout(20) << " didn't traverse full path; not returning pdnvec" << dendl
;
8077 ceph_abort(); // should have fallen out in ->is_null() check above
8078 } else if (curdir
->is_frozen()) {
8079 dout(20) << " not adding null to frozen dir " << dendl
;
8080 } else if (snapid
< CEPH_MAXSNAP
) {
8081 dout(20) << " not adding null for snapid " << snapid
<< dendl
;
8083 // create a null dentry
8084 dn
= curdir
->add_null_dentry(path
[depth
]);
8085 dout(20) << " added null " << *dn
<< dendl
;
8088 pdnvec
->push_back(dn
);
8090 pdnvec
->clear(); // do not confuse likes of rdlock_path_pin_ref();
8095 // Check DamageTable for missing fragments before trying to fetch
8097 if (mds
->damage_table
.is_dirfrag_damaged(curdir
)) {
8098 dout(4) << "traverse: damaged dirfrag " << *curdir
8099 << ", blocking fetch" << dendl
;
8103 // directory isn't complete; reload
8104 dout(7) << "traverse: incomplete dir contents for " << *cur
<< ", fetching" << dendl
;
8106 curdir
->fetch(_get_waiter(mdr
, req
, fin
), path
[depth
]);
8107 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse_dir_fetch
);
8111 // dirfrag/dentry is not mine.
8112 mds_authority_t dauth
= curdir
->authority();
8115 snapid
&& mdr
&& mdr
->client_request
&&
8116 (int)depth
< mdr
->client_request
->get_num_fwd()) {
8117 dout(7) << "traverse: snap " << snapid
<< " and depth " << depth
8118 << " < fwd " << mdr
->client_request
->get_num_fwd()
8119 << ", discovering instead of forwarding" << dendl
;
8123 if ((discover
|| null_okay
)) {
8124 dout(7) << "traverse: discover from " << path
[depth
] << " from " << *curdir
<< dendl
;
8125 discover_path(curdir
, snapid
, path
.postfixpath(depth
), _get_waiter(mdr
, req
, fin
),
8127 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse_discover
);
8132 dout(7) << "traverse: not auth for " << path
<< " in " << *curdir
<< dendl
;
8134 if (curdir
->is_ambiguous_auth()) {
8136 dout(7) << "traverse: waiting for single auth in " << *curdir
<< dendl
;
8137 curdir
->add_waiter(CDir::WAIT_SINGLEAUTH
, _get_waiter(mdr
, req
, fin
));
8141 dout(7) << "traverse: forwarding, not auth for " << *curdir
<< dendl
;
8144 request_forward(mdr
, dauth
.first
);
8146 mds
->forward_message_mds(req
, dauth
.first
);
8148 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse_forward
);
8149 assert(fin
== NULL
);
8154 ceph_abort(); // i shouldn't get here
8158 if (mds
->logger
) mds
->logger
->inc(l_mds_traverse_hit
);
8159 dout(10) << "path_traverse finish on snapid " << snapid
<< dendl
;
8161 assert(mdr
->snapid
== snapid
);
8165 CInode
*MDCache::cache_traverse(const filepath
& fp
)
8167 dout(10) << "cache_traverse " << fp
<< dendl
;
8171 in
= get_inode(fp
.get_ino());
8177 for (unsigned i
= 0; i
< fp
.depth(); i
++) {
8178 const string
& dname
= fp
[i
];
8179 frag_t fg
= in
->pick_dirfrag(dname
);
8180 dout(20) << " " << i
<< " " << dname
<< " frag " << fg
<< " from " << *in
<< dendl
;
8181 CDir
*curdir
= in
->get_dirfrag(fg
);
8184 CDentry
*dn
= curdir
->lookup(dname
, CEPH_NOSNAP
);
8187 in
= dn
->get_linkage()->get_inode();
8191 dout(10) << " got " << *in
<< dendl
;
8197 * open_remote_dir -- open up a remote dirfrag
8199 * @param diri base inode
8200 * @param approxfg approximate fragment.
8201 * @param fin completion callback
8203 void MDCache::open_remote_dirfrag(CInode
*diri
, frag_t approxfg
, MDSInternalContextBase
*fin
)
8205 dout(10) << "open_remote_dir on " << *diri
<< dendl
;
8206 assert(diri
->is_dir());
8207 assert(!diri
->is_auth());
8208 assert(diri
->get_dirfrag(approxfg
) == 0);
8210 discover_dir_frag(diri
, approxfg
, fin
);
8215 * get_dentry_inode - get or open inode
8217 * @param dn the dentry
8218 * @param mdr current request
8220 * will return inode for primary, or link up/open up remote link's inode as necessary.
8221 * If it's not available right now, puts mdr on wait list and returns null.
8223 CInode
*MDCache::get_dentry_inode(CDentry
*dn
, MDRequestRef
& mdr
, bool projected
)
8225 CDentry::linkage_t
*dnl
;
8227 dnl
= dn
->get_projected_linkage();
8229 dnl
= dn
->get_linkage();
8231 assert(!dnl
->is_null());
8233 if (dnl
->is_primary())
8236 assert(dnl
->is_remote());
8237 CInode
*in
= get_inode(dnl
->get_remote_ino());
8239 dout(7) << "get_dentry_inode linking in remote in " << *in
<< dendl
;
8240 dn
->link_remote(dnl
, in
);
8243 dout(10) << "get_dentry_inode on remote dn, opening inode for " << *dn
<< dendl
;
8244 open_remote_dentry(dn
, projected
, new C_MDS_RetryRequest(this, mdr
));
8249 struct C_MDC_OpenRemoteDentry
: public MDCacheContext
{
8252 MDSInternalContextBase
*onfinish
;
8254 C_MDC_OpenRemoteDentry(MDCache
*m
, CDentry
*d
, inodeno_t i
, MDSInternalContextBase
*f
, bool wx
) :
8255 MDCacheContext(m
), dn(d
), ino(i
), onfinish(f
), want_xlocked(wx
) {
8256 dn
->get(MDSCacheObject::PIN_PTRWAITER
);
8258 void finish(int r
) override
{
8259 mdcache
->_open_remote_dentry_finish(dn
, ino
, onfinish
, want_xlocked
, r
);
8260 dn
->put(MDSCacheObject::PIN_PTRWAITER
);
8264 void MDCache::open_remote_dentry(CDentry
*dn
, bool projected
, MDSInternalContextBase
*fin
, bool want_xlocked
)
8266 dout(10) << "open_remote_dentry " << *dn
<< dendl
;
8267 CDentry::linkage_t
*dnl
= projected
? dn
->get_projected_linkage() : dn
->get_linkage();
8268 inodeno_t ino
= dnl
->get_remote_ino();
8269 int64_t pool
= dnl
->get_remote_d_type() == DT_DIR
? mds
->mdsmap
->get_metadata_pool() : -1;
8271 new C_MDC_OpenRemoteDentry(this, dn
, ino
, fin
, want_xlocked
), true, want_xlocked
); // backtrace
8274 void MDCache::_open_remote_dentry_finish(CDentry
*dn
, inodeno_t ino
, MDSInternalContextBase
*fin
,
8275 bool want_xlocked
, int r
)
8278 CDentry::linkage_t
*dnl
= dn
->get_projected_linkage();
8279 if (dnl
->is_remote() && dnl
->get_remote_ino() == ino
) {
8280 dout(0) << "open_remote_dentry_finish bad remote dentry " << *dn
<< dendl
;
8281 dn
->state_set(CDentry::STATE_BADREMOTEINO
);
8284 CDir
*dir
= dn
->get_dir();
8286 dir
->get_inode()->make_path_string(path
);
8287 path
= path
+ "/" + dn
->get_name();
8290 bool fatal
= mds
->damage_table
.notify_remote_damaged(ino
, path
);
8293 ceph_abort(); // unreachable, damaged() respawns us
8299 fin
->complete(r
< 0 ? r
: 0);
8303 void MDCache::make_trace(vector
<CDentry
*>& trace
, CInode
*in
)
8305 // empty trace if we're a base inode
8309 CInode
*parent
= in
->get_parent_inode();
8311 make_trace(trace
, parent
);
8313 CDentry
*dn
= in
->get_parent_dn();
8314 dout(15) << "make_trace adding " << *dn
<< dendl
;
8315 trace
.push_back(dn
);
8319 // -------------------------------------------------------------------------------
8320 // Open inode by inode number
8322 class C_IO_MDC_OpenInoBacktraceFetched
: public MDCacheIOContext
{
8326 C_IO_MDC_OpenInoBacktraceFetched(MDCache
*c
, inodeno_t i
) :
8327 MDCacheIOContext(c
), ino(i
) {}
8328 void finish(int r
) override
{
8329 mdcache
->_open_ino_backtrace_fetched(ino
, bl
, r
);
8333 struct C_MDC_OpenInoTraverseDir
: public MDCacheContext
{
8338 C_MDC_OpenInoTraverseDir(MDCache
*c
, inodeno_t i
, MMDSOpenIno
*m
, bool p
) :
8339 MDCacheContext(c
), ino(i
), msg(m
), parent(p
) {}
8340 void finish(int r
) override
{
8341 if (r
< 0 && !parent
)
8344 mdcache
->handle_open_ino(msg
, r
);
8347 assert(mdcache
->opening_inodes
.count(ino
));
8348 mdcache
->_open_ino_traverse_dir(ino
, mdcache
->opening_inodes
[ino
], r
);
8352 struct C_MDC_OpenInoParentOpened
: public MDCacheContext
{
8355 C_MDC_OpenInoParentOpened(MDCache
*c
, inodeno_t i
) : MDCacheContext(c
), ino(i
) {}
8356 void finish(int r
) override
{
8357 mdcache
->_open_ino_parent_opened(ino
, r
);
8361 void MDCache::_open_ino_backtrace_fetched(inodeno_t ino
, bufferlist
& bl
, int err
)
8363 dout(10) << "_open_ino_backtrace_fetched ino " << ino
<< " errno " << err
<< dendl
;
8365 assert(opening_inodes
.count(ino
));
8366 open_ino_info_t
& info
= opening_inodes
[ino
];
8368 CInode
*in
= get_inode(ino
);
8370 dout(10) << " found cached " << *in
<< dendl
;
8371 open_ino_finish(ino
, info
, in
->authority().first
);
8375 inode_backtrace_t backtrace
;
8378 ::decode(backtrace
, bl
);
8379 } catch (const buffer::error
&decode_exc
) {
8380 derr
<< "corrupt backtrace on ino x0" << std::hex
<< ino
8381 << std::dec
<< ": " << decode_exc
<< dendl
;
8382 open_ino_finish(ino
, info
, -EIO
);
8385 if (backtrace
.pool
!= info
.pool
&& backtrace
.pool
!= -1) {
8386 dout(10) << " old object in pool " << info
.pool
8387 << ", retrying pool " << backtrace
.pool
<< dendl
;
8388 info
.pool
= backtrace
.pool
;
8389 C_IO_MDC_OpenInoBacktraceFetched
*fin
=
8390 new C_IO_MDC_OpenInoBacktraceFetched(this, ino
);
8391 fetch_backtrace(ino
, info
.pool
, fin
->bl
,
8392 new C_OnFinisher(fin
, mds
->finisher
));
8395 } else if (err
== -ENOENT
) {
8396 int64_t meta_pool
= mds
->mdsmap
->get_metadata_pool();
8397 if (info
.pool
!= meta_pool
) {
8398 dout(10) << " no object in pool " << info
.pool
8399 << ", retrying pool " << meta_pool
<< dendl
;
8400 info
.pool
= meta_pool
;
8401 C_IO_MDC_OpenInoBacktraceFetched
*fin
=
8402 new C_IO_MDC_OpenInoBacktraceFetched(this, ino
);
8403 fetch_backtrace(ino
, info
.pool
, fin
->bl
,
8404 new C_OnFinisher(fin
, mds
->finisher
));
8407 err
= 0; // backtrace.ancestors.empty() is checked below
8411 if (backtrace
.ancestors
.empty()) {
8412 dout(10) << " got empty backtrace " << dendl
;
8414 } else if (!info
.ancestors
.empty()) {
8415 if (info
.ancestors
[0] == backtrace
.ancestors
[0]) {
8416 dout(10) << " got same parents " << info
.ancestors
[0] << " 2 times" << dendl
;
8424 dout(0) << " failed to open ino " << ino
<< " err " << err
<< "/" << info
.last_err
<< dendl
;
8426 err
= info
.last_err
;
8427 open_ino_finish(ino
, info
, err
);
8431 dout(10) << " got backtrace " << backtrace
<< dendl
;
8432 info
.ancestors
= backtrace
.ancestors
;
8434 _open_ino_traverse_dir(ino
, info
, 0);
8437 void MDCache::_open_ino_parent_opened(inodeno_t ino
, int ret
)
8439 dout(10) << "_open_ino_parent_opened ino " << ino
<< " ret " << ret
<< dendl
;
8441 assert(opening_inodes
.count(ino
));
8442 open_ino_info_t
& info
= opening_inodes
[ino
];
8444 CInode
*in
= get_inode(ino
);
8446 dout(10) << " found cached " << *in
<< dendl
;
8447 open_ino_finish(ino
, info
, in
->authority().first
);
8451 if (ret
== mds
->get_nodeid()) {
8452 _open_ino_traverse_dir(ino
, info
, 0);
8455 mds_rank_t checked_rank
= mds_rank_t(ret
);
8456 info
.check_peers
= true;
8457 info
.auth_hint
= checked_rank
;
8458 info
.checked
.erase(checked_rank
);
8460 do_open_ino(ino
, info
, ret
);
8464 void MDCache::_open_ino_traverse_dir(inodeno_t ino
, open_ino_info_t
& info
, int ret
)
8466 dout(10) << __func__
<< ": ino " << ino
<< " ret " << ret
<< dendl
;
8468 CInode
*in
= get_inode(ino
);
8470 dout(10) << " found cached " << *in
<< dendl
;
8471 open_ino_finish(ino
, info
, in
->authority().first
);
8476 do_open_ino(ino
, info
, ret
);
8480 mds_rank_t hint
= info
.auth_hint
;
8481 ret
= open_ino_traverse_dir(ino
, NULL
, info
.ancestors
,
8482 info
.discover
, info
.want_xlocked
, &hint
);
8485 if (hint
!= mds
->get_nodeid())
8486 info
.auth_hint
= hint
;
8487 do_open_ino(ino
, info
, ret
);
8490 void MDCache::_open_ino_fetch_dir(inodeno_t ino
, MMDSOpenIno
*m
, CDir
*dir
, bool parent
)
8492 if (dir
->state_test(CDir::STATE_REJOINUNDEF
))
8493 assert(dir
->get_inode()->dirfragtree
.is_leaf(dir
->get_frag()));
8494 dir
->fetch(new C_MDC_OpenInoTraverseDir(this, ino
, m
, parent
));
8497 int MDCache::open_ino_traverse_dir(inodeno_t ino
, MMDSOpenIno
*m
,
8498 vector
<inode_backpointer_t
>& ancestors
,
8499 bool discover
, bool want_xlocked
, mds_rank_t
*hint
)
8501 dout(10) << "open_ino_traverse_dir ino " << ino
<< " " << ancestors
<< dendl
;
8503 for (unsigned i
= 0; i
< ancestors
.size(); i
++) {
8504 CInode
*diri
= get_inode(ancestors
[i
].dirino
);
8507 if (discover
&& MDS_INO_IS_MDSDIR(ancestors
[i
].dirino
)) {
8508 open_foreign_mdsdir(ancestors
[i
].dirino
, new C_MDC_OpenInoTraverseDir(this, ino
, m
, i
== 0));
8514 if (diri
->state_test(CInode::STATE_REJOINUNDEF
)) {
8515 CDir
*dir
= diri
->get_parent_dir();
8516 while (dir
->state_test(CDir::STATE_REJOINUNDEF
) &&
8517 dir
->get_inode()->state_test(CInode::STATE_REJOINUNDEF
))
8518 dir
= dir
->get_inode()->get_parent_dir();
8519 _open_ino_fetch_dir(ino
, m
, dir
, i
== 0);
8523 if (!diri
->is_dir()) {
8524 dout(10) << " " << *diri
<< " is not dir" << dendl
;
8530 string
&name
= ancestors
[i
].dname
;
8531 frag_t fg
= diri
->pick_dirfrag(name
);
8532 CDir
*dir
= diri
->get_dirfrag(fg
);
8534 if (diri
->is_auth()) {
8535 if (diri
->is_frozen()) {
8536 dout(10) << " " << *diri
<< " is frozen, waiting " << dendl
;
8537 diri
->add_waiter(CDir::WAIT_UNFREEZE
, new C_MDC_OpenInoTraverseDir(this, ino
, m
, i
== 0));
8540 dir
= diri
->get_or_open_dirfrag(this, fg
);
8541 } else if (discover
) {
8542 open_remote_dirfrag(diri
, fg
, new C_MDC_OpenInoTraverseDir(this, ino
, m
, i
== 0));
8547 inodeno_t next_ino
= i
> 0 ? ancestors
[i
- 1].dirino
: ino
;
8548 CDentry
*dn
= dir
->lookup(name
);
8549 CDentry::linkage_t
*dnl
= dn
? dn
->get_linkage() : NULL
;
8550 if (dir
->is_auth()) {
8551 if (dnl
&& dnl
->is_primary() &&
8552 dnl
->get_inode()->state_test(CInode::STATE_REJOINUNDEF
)) {
8553 dout(10) << " fetching undef " << *dnl
->get_inode() << dendl
;
8554 _open_ino_fetch_dir(ino
, m
, dir
, i
== 0);
8558 if (!dnl
&& !dir
->is_complete() &&
8559 (!dir
->has_bloom() || dir
->is_in_bloom(name
))) {
8560 dout(10) << " fetching incomplete " << *dir
<< dendl
;
8561 _open_ino_fetch_dir(ino
, m
, dir
, i
== 0);
8565 dout(10) << " no ino " << next_ino
<< " in " << *dir
<< dendl
;
8568 } else if (discover
) {
8570 filepath
path(name
, 0);
8571 discover_path(dir
, CEPH_NOSNAP
, path
, new C_MDC_OpenInoTraverseDir(this, ino
, m
, i
== 0),
8572 (i
== 0 && want_xlocked
));
8575 if (dnl
->is_null() && !dn
->lock
.can_read(-1)) {
8576 dout(10) << " null " << *dn
<< " is not readable, waiting" << dendl
;
8577 dn
->lock
.add_waiter(SimpleLock::WAIT_RD
, new C_MDC_OpenInoTraverseDir(this, ino
, m
, i
== 0));
8580 dout(10) << " no ino " << next_ino
<< " in " << *dir
<< dendl
;
8586 *hint
= dir
? dir
->authority().first
: diri
->authority().first
;
8592 void MDCache::open_ino_finish(inodeno_t ino
, open_ino_info_t
& info
, int ret
)
8594 dout(10) << "open_ino_finish ino " << ino
<< " ret " << ret
<< dendl
;
8596 list
<MDSInternalContextBase
*> waiters
;
8597 waiters
.swap(info
.waiters
);
8598 opening_inodes
.erase(ino
);
8599 finish_contexts(g_ceph_context
, waiters
, ret
);
8602 void MDCache::do_open_ino(inodeno_t ino
, open_ino_info_t
& info
, int err
)
8604 if (err
< 0 && err
!= -EAGAIN
) {
8605 info
.checked
.clear();
8606 info
.checking
= MDS_RANK_NONE
;
8607 info
.check_peers
= true;
8608 info
.fetch_backtrace
= true;
8609 if (info
.discover
) {
8610 info
.discover
= false;
8611 info
.ancestors
.clear();
8613 if (err
!= -ENOENT
&& err
!= -ENOTDIR
)
8614 info
.last_err
= err
;
8617 if (info
.check_peers
|| info
.discover
) {
8618 if (info
.discover
) {
8619 // got backtrace from peer, but failed to find inode. re-check peers
8620 info
.discover
= false;
8621 info
.ancestors
.clear();
8622 info
.checked
.clear();
8624 info
.check_peers
= false;
8625 info
.checking
= MDS_RANK_NONE
;
8626 do_open_ino_peer(ino
, info
);
8627 } else if (info
.fetch_backtrace
) {
8628 info
.check_peers
= true;
8629 info
.fetch_backtrace
= false;
8630 info
.checking
= mds
->get_nodeid();
8631 info
.checked
.clear();
8632 C_IO_MDC_OpenInoBacktraceFetched
*fin
=
8633 new C_IO_MDC_OpenInoBacktraceFetched(this, ino
);
8634 fetch_backtrace(ino
, info
.pool
, fin
->bl
,
8635 new C_OnFinisher(fin
, mds
->finisher
));
8637 assert(!info
.ancestors
.empty());
8638 info
.checking
= mds
->get_nodeid();
8639 open_ino(info
.ancestors
[0].dirino
, mds
->mdsmap
->get_metadata_pool(),
8640 new C_MDC_OpenInoParentOpened(this, ino
), info
.want_replica
);
8644 void MDCache::do_open_ino_peer(inodeno_t ino
, open_ino_info_t
& info
)
8646 set
<mds_rank_t
> all
, active
;
8647 mds
->mdsmap
->get_mds_set(all
);
8648 mds
->mdsmap
->get_clientreplay_or_active_or_stopping_mds_set(active
);
8649 if (mds
->get_state() == MDSMap::STATE_REJOIN
)
8650 mds
->mdsmap
->get_mds_set(active
, MDSMap::STATE_REJOIN
);
8652 dout(10) << "do_open_ino_peer " << ino
<< " active " << active
8653 << " all " << all
<< " checked " << info
.checked
<< dendl
;
8655 mds_rank_t peer
= MDS_RANK_NONE
;
8656 if (info
.auth_hint
>= 0) {
8657 if (active
.count(info
.auth_hint
)) {
8658 peer
= info
.auth_hint
;
8659 info
.auth_hint
= MDS_RANK_NONE
;
8662 for (set
<mds_rank_t
>::iterator p
= active
.begin(); p
!= active
.end(); ++p
)
8663 if (*p
!= mds
->get_nodeid() && info
.checked
.count(*p
) == 0) {
8669 all
.erase(mds
->get_nodeid());
8670 if (all
!= info
.checked
) {
8671 dout(10) << " waiting for more peers to be active" << dendl
;
8673 dout(10) << " all MDS peers have been checked " << dendl
;
8674 do_open_ino(ino
, info
, 0);
8677 info
.checking
= peer
;
8678 vector
<inode_backpointer_t
> *pa
= NULL
;
8679 // got backtrace from peer or backtrace just fetched
8680 if (info
.discover
|| !info
.fetch_backtrace
)
8681 pa
= &info
.ancestors
;
8682 mds
->send_message_mds(new MMDSOpenIno(info
.tid
, ino
, pa
), peer
);
8686 void MDCache::handle_open_ino(MMDSOpenIno
*m
, int err
)
8688 if (mds
->get_state() < MDSMap::STATE_REJOIN
&&
8689 mds
->get_want_state() != CEPH_MDS_STATE_REJOIN
) {
8694 dout(10) << "handle_open_ino " << *m
<< " err " << err
<< dendl
;
8696 inodeno_t ino
= m
->ino
;
8697 MMDSOpenInoReply
*reply
;
8698 CInode
*in
= get_inode(ino
);
8700 dout(10) << " have " << *in
<< dendl
;
8701 reply
= new MMDSOpenInoReply(m
->get_tid(), ino
, mds_rank_t(0));
8702 if (in
->is_auth()) {
8705 CDentry
*pdn
= in
->get_parent_dn();
8708 CInode
*diri
= pdn
->get_dir()->get_inode();
8709 reply
->ancestors
.push_back(inode_backpointer_t(diri
->ino(), pdn
->name
,
8710 in
->inode
.version
));
8714 reply
->hint
= in
->authority().first
;
8716 } else if (err
< 0) {
8717 reply
= new MMDSOpenInoReply(m
->get_tid(), ino
, MDS_RANK_NONE
, err
);
8719 mds_rank_t hint
= MDS_RANK_NONE
;
8720 int ret
= open_ino_traverse_dir(ino
, m
, m
->ancestors
, false, false, &hint
);
8723 reply
= new MMDSOpenInoReply(m
->get_tid(), ino
, hint
, ret
);
8725 m
->get_connection()->send_message(reply
);
8729 void MDCache::handle_open_ino_reply(MMDSOpenInoReply
*m
)
8731 dout(10) << "handle_open_ino_reply " << *m
<< dendl
;
8733 inodeno_t ino
= m
->ino
;
8734 mds_rank_t from
= mds_rank_t(m
->get_source().num());
8735 auto it
= opening_inodes
.find(ino
);
8736 if (it
!= opening_inodes
.end() && it
->second
.checking
== from
) {
8737 open_ino_info_t
& info
= it
->second
;
8738 info
.checking
= MDS_RANK_NONE
;
8739 info
.checked
.insert(from
);
8741 CInode
*in
= get_inode(ino
);
8743 dout(10) << " found cached " << *in
<< dendl
;
8744 open_ino_finish(ino
, info
, in
->authority().first
);
8745 } else if (!m
->ancestors
.empty()) {
8746 dout(10) << " found ino " << ino
<< " on mds." << from
<< dendl
;
8747 if (!info
.want_replica
) {
8748 open_ino_finish(ino
, info
, from
);
8753 info
.ancestors
= m
->ancestors
;
8754 info
.auth_hint
= from
;
8755 info
.checking
= mds
->get_nodeid();
8756 info
.discover
= true;
8757 _open_ino_traverse_dir(ino
, info
, 0);
8758 } else if (m
->error
) {
8759 dout(10) << " error " << m
->error
<< " from mds." << from
<< dendl
;
8760 do_open_ino(ino
, info
, m
->error
);
8762 if (m
->hint
>= 0 && m
->hint
!= mds
->get_nodeid()) {
8763 info
.auth_hint
= m
->hint
;
8764 info
.checked
.erase(m
->hint
);
8766 do_open_ino_peer(ino
, info
);
8772 void MDCache::kick_open_ino_peers(mds_rank_t who
)
8774 dout(10) << "kick_open_ino_peers mds." << who
<< dendl
;
8776 for (map
<inodeno_t
, open_ino_info_t
>::iterator p
= opening_inodes
.begin();
8777 p
!= opening_inodes
.end();
8779 open_ino_info_t
& info
= p
->second
;
8780 if (info
.checking
== who
) {
8781 dout(10) << " kicking ino " << p
->first
<< " who was checking mds." << who
<< dendl
;
8782 info
.checking
= MDS_RANK_NONE
;
8783 do_open_ino_peer(p
->first
, info
);
8784 } else if (info
.checking
== MDS_RANK_NONE
) {
8785 dout(10) << " kicking ino " << p
->first
<< " who was waiting" << dendl
;
8786 do_open_ino_peer(p
->first
, info
);
8791 void MDCache::open_ino(inodeno_t ino
, int64_t pool
, MDSInternalContextBase
* fin
,
8792 bool want_replica
, bool want_xlocked
)
8794 dout(10) << "open_ino " << ino
<< " pool " << pool
<< " want_replica "
8795 << want_replica
<< dendl
;
8797 if (opening_inodes
.count(ino
)) {
8798 open_ino_info_t
& info
= opening_inodes
[ino
];
8800 info
.want_replica
= true;
8801 if (want_xlocked
&& !info
.want_xlocked
) {
8802 if (!info
.ancestors
.empty()) {
8803 CInode
*diri
= get_inode(info
.ancestors
[0].dirino
);
8805 frag_t fg
= diri
->pick_dirfrag(info
.ancestors
[0].dname
);
8806 CDir
*dir
= diri
->get_dirfrag(fg
);
8807 if (dir
&& !dir
->is_auth()) {
8808 filepath
path(info
.ancestors
[0].dname
, 0);
8809 discover_path(dir
, CEPH_NOSNAP
, path
, NULL
, true);
8813 info
.want_xlocked
= true;
8816 info
.waiters
.push_back(fin
);
8818 open_ino_info_t
& info
= opening_inodes
[ino
];
8819 info
.want_replica
= want_replica
;
8820 info
.want_xlocked
= want_xlocked
;
8821 info
.tid
= ++open_ino_last_tid
;
8822 info
.pool
= pool
>= 0 ? pool
: default_file_layout
.pool_id
;
8823 info
.waiters
.push_back(fin
);
8824 do_open_ino(ino
, info
, 0);
8828 /* ---------------------------- */
8831 * search for a given inode on MDS peers. optionally start with the given node.
8835 - recover from mds node failure, recovery
8839 void MDCache::find_ino_peers(inodeno_t ino
, MDSInternalContextBase
*c
, mds_rank_t hint
)
8841 dout(5) << "find_ino_peers " << ino
<< " hint " << hint
<< dendl
;
8842 assert(!have_inode(ino
));
8844 ceph_tid_t tid
= ++find_ino_peer_last_tid
;
8845 find_ino_peer_info_t
& fip
= find_ino_peer
[tid
];
8850 _do_find_ino_peer(fip
);
8853 void MDCache::_do_find_ino_peer(find_ino_peer_info_t
& fip
)
8855 set
<mds_rank_t
> all
, active
;
8856 mds
->mdsmap
->get_mds_set(all
);
8857 mds
->mdsmap
->get_clientreplay_or_active_or_stopping_mds_set(active
);
8859 dout(10) << "_do_find_ino_peer " << fip
.tid
<< " " << fip
.ino
8860 << " active " << active
<< " all " << all
8861 << " checked " << fip
.checked
8864 mds_rank_t m
= MDS_RANK_NONE
;
8865 if (fip
.hint
>= 0) {
8867 fip
.hint
= MDS_RANK_NONE
;
8869 for (set
<mds_rank_t
>::iterator p
= active
.begin(); p
!= active
.end(); ++p
)
8870 if (*p
!= mds
->get_nodeid() &&
8871 fip
.checked
.count(*p
) == 0) {
8876 if (m
== MDS_RANK_NONE
) {
8877 all
.erase(mds
->get_nodeid());
8878 if (all
!= fip
.checked
) {
8879 dout(10) << "_do_find_ino_peer waiting for more peers to be active" << dendl
;
8881 dout(10) << "_do_find_ino_peer failed on " << fip
.ino
<< dendl
;
8882 fip
.fin
->complete(-ESTALE
);
8883 find_ino_peer
.erase(fip
.tid
);
8887 mds
->send_message_mds(new MMDSFindIno(fip
.tid
, fip
.ino
), m
);
8891 void MDCache::handle_find_ino(MMDSFindIno
*m
)
8893 if (mds
->get_state() < MDSMap::STATE_REJOIN
) {
8898 dout(10) << "handle_find_ino " << *m
<< dendl
;
8899 MMDSFindInoReply
*r
= new MMDSFindInoReply(m
->tid
);
8900 CInode
*in
= get_inode(m
->ino
);
8902 in
->make_path(r
->path
);
8903 dout(10) << " have " << r
->path
<< " " << *in
<< dendl
;
8905 m
->get_connection()->send_message(r
);
8910 void MDCache::handle_find_ino_reply(MMDSFindInoReply
*m
)
8912 map
<ceph_tid_t
, find_ino_peer_info_t
>::iterator p
= find_ino_peer
.find(m
->tid
);
8913 if (p
!= find_ino_peer
.end()) {
8914 dout(10) << "handle_find_ino_reply " << *m
<< dendl
;
8915 find_ino_peer_info_t
& fip
= p
->second
;
8918 if (get_inode(fip
.ino
)) {
8919 dout(10) << "handle_find_ino_reply successfully found " << fip
.ino
<< dendl
;
8920 mds
->queue_waiter(fip
.fin
);
8921 find_ino_peer
.erase(p
);
8926 mds_rank_t from
= mds_rank_t(m
->get_source().num());
8927 if (fip
.checking
== from
)
8928 fip
.checking
= MDS_RANK_NONE
;
8929 fip
.checked
.insert(from
);
8931 if (!m
->path
.empty()) {
8933 vector
<CDentry
*> trace
;
8934 MDRequestRef null_ref
;
8935 int r
= path_traverse(null_ref
, m
, NULL
, m
->path
, &trace
, NULL
, MDS_TRAVERSE_DISCOVER
);
8938 dout(0) << "handle_find_ino_reply failed with " << r
<< " on " << m
->path
8939 << ", retrying" << dendl
;
8940 fip
.checked
.clear();
8941 _do_find_ino_peer(fip
);
8944 _do_find_ino_peer(fip
);
8947 dout(10) << "handle_find_ino_reply tid " << m
->tid
<< " dne" << dendl
;
8952 void MDCache::kick_find_ino_peers(mds_rank_t who
)
8954 // find_ino_peers requests we should move on from
8955 for (map
<ceph_tid_t
,find_ino_peer_info_t
>::iterator p
= find_ino_peer
.begin();
8956 p
!= find_ino_peer
.end();
8958 find_ino_peer_info_t
& fip
= p
->second
;
8959 if (fip
.checking
== who
) {
8960 dout(10) << "kicking find_ino_peer " << fip
.tid
<< " who was checking mds." << who
<< dendl
;
8961 fip
.checking
= MDS_RANK_NONE
;
8962 _do_find_ino_peer(fip
);
8963 } else if (fip
.checking
== MDS_RANK_NONE
) {
8964 dout(10) << "kicking find_ino_peer " << fip
.tid
<< " who was waiting" << dendl
;
8965 _do_find_ino_peer(fip
);
8970 /* ---------------------------- */
8972 int MDCache::get_num_client_requests()
8975 for (ceph::unordered_map
<metareqid_t
, MDRequestRef
>::iterator p
= active_requests
.begin();
8976 p
!= active_requests
.end();
8978 MDRequestRef
& mdr
= p
->second
;
8979 if (mdr
->reqid
.name
.is_client() && !mdr
->is_slave())
8985 /* This function takes over the reference to the passed Message */
8986 MDRequestRef
MDCache::request_start(MClientRequest
*req
)
8988 // did we win a forward race against a slave?
8989 if (active_requests
.count(req
->get_reqid())) {
8990 MDRequestRef
& mdr
= active_requests
[req
->get_reqid()];
8992 if (mdr
->is_slave()) {
8993 dout(10) << "request_start already had " << *mdr
<< ", waiting for finish" << dendl
;
8994 mdr
->more()->waiting_for_finish
.push_back(new C_MDS_RetryMessage(mds
, req
));
8996 dout(10) << "request_start already processing " << *mdr
<< ", dropping new msg" << dendl
;
8999 return MDRequestRef();
9002 // register new client request
9003 MDRequestImpl::Params params
;
9004 params
.reqid
= req
->get_reqid();
9005 params
.attempt
= req
->get_num_fwd();
9006 params
.client_req
= req
;
9007 params
.initiated
= req
->get_recv_stamp();
9008 params
.throttled
= req
->get_throttle_stamp();
9009 params
.all_read
= req
->get_recv_complete_stamp();
9010 params
.dispatched
= req
->get_dispatch_stamp();
9013 mds
->op_tracker
.create_request
<MDRequestImpl
,MDRequestImpl::Params
>(params
);
9014 active_requests
[params
.reqid
] = mdr
;
9015 mdr
->set_op_stamp(req
->get_stamp());
9016 dout(7) << "request_start " << *mdr
<< dendl
;
9020 MDRequestRef
MDCache::request_start_slave(metareqid_t ri
, __u32 attempt
, Message
*m
)
9022 int by
= m
->get_source().num();
9023 MDRequestImpl::Params params
;
9025 params
.attempt
= attempt
;
9026 params
.triggering_slave_req
= m
;
9027 params
.slave_to
= by
;
9028 params
.initiated
= m
->get_recv_stamp();
9029 params
.throttled
= m
->get_throttle_stamp();
9030 params
.all_read
= m
->get_recv_complete_stamp();
9031 params
.dispatched
= m
->get_dispatch_stamp();
9033 mds
->op_tracker
.create_request
<MDRequestImpl
,MDRequestImpl::Params
>(params
);
9034 assert(active_requests
.count(mdr
->reqid
) == 0);
9035 active_requests
[mdr
->reqid
] = mdr
;
9036 dout(7) << "request_start_slave " << *mdr
<< " by mds." << by
<< dendl
;
9040 MDRequestRef
MDCache::request_start_internal(int op
)
9042 MDRequestImpl::Params params
;
9043 params
.reqid
.name
= entity_name_t::MDS(mds
->get_nodeid());
9044 params
.reqid
.tid
= mds
->issue_tid();
9045 params
.initiated
= ceph_clock_now();
9046 params
.internal_op
= op
;
9048 mds
->op_tracker
.create_request
<MDRequestImpl
,MDRequestImpl::Params
>(params
);
9050 assert(active_requests
.count(mdr
->reqid
) == 0);
9051 active_requests
[mdr
->reqid
] = mdr
;
9052 dout(7) << "request_start_internal " << *mdr
<< " op " << op
<< dendl
;
9056 MDRequestRef
MDCache::request_get(metareqid_t rid
)
9058 ceph::unordered_map
<metareqid_t
, MDRequestRef
>::iterator p
= active_requests
.find(rid
);
9059 assert(p
!= active_requests
.end());
9060 dout(7) << "request_get " << rid
<< " " << *p
->second
<< dendl
;
9064 void MDCache::request_finish(MDRequestRef
& mdr
)
9066 dout(7) << "request_finish " << *mdr
<< dendl
;
9067 mdr
->mark_event("finishing request");
9070 if (mdr
->has_more() && mdr
->more()->slave_commit
) {
9071 Context
*fin
= mdr
->more()->slave_commit
;
9072 mdr
->more()->slave_commit
= 0;
9075 mdr
->aborted
= false;
9077 mdr
->more()->slave_rolling_back
= true;
9080 mdr
->committing
= true;
9082 fin
->complete(ret
); // this must re-call request_finish.
9086 switch(mdr
->internal_op
) {
9087 case CEPH_MDS_OP_FRAGMENTDIR
:
9088 logger
->inc(l_mdss_ireq_fragmentdir
);
9090 case CEPH_MDS_OP_EXPORTDIR
:
9091 logger
->inc(l_mdss_ireq_exportdir
);
9093 case CEPH_MDS_OP_ENQUEUE_SCRUB
:
9094 logger
->inc(l_mdss_ireq_enqueue_scrub
);
9096 case CEPH_MDS_OP_FLUSH
:
9097 logger
->inc(l_mdss_ireq_flush
);
9099 case CEPH_MDS_OP_REPAIR_FRAGSTATS
:
9100 logger
->inc(l_mdss_ireq_fragstats
);
9102 case CEPH_MDS_OP_REPAIR_INODESTATS
:
9103 logger
->inc(l_mdss_ireq_inodestats
);
9107 request_cleanup(mdr
);
9111 void MDCache::request_forward(MDRequestRef
& mdr
, mds_rank_t who
, int port
)
9113 mdr
->mark_event("forwarding request");
9114 if (mdr
->client_request
&& mdr
->client_request
->get_source().is_client()) {
9115 dout(7) << "request_forward " << *mdr
<< " to mds." << who
<< " req "
9116 << *mdr
->client_request
<< dendl
;
9117 mds
->forward_message_mds(mdr
->client_request
, who
);
9118 mdr
->client_request
= 0;
9119 if (mds
->logger
) mds
->logger
->inc(l_mds_forward
);
9120 } else if (mdr
->internal_op
>= 0) {
9121 dout(10) << "request_forward on internal op; cancelling" << dendl
;
9122 mdr
->internal_op_finish
->complete(-EXDEV
);
9124 dout(7) << "request_forward drop " << *mdr
<< " req " << *mdr
->client_request
9125 << " was from mds" << dendl
;
9127 request_cleanup(mdr
);
9131 void MDCache::dispatch_request(MDRequestRef
& mdr
)
9133 if (mdr
->client_request
) {
9134 mds
->server
->dispatch_client_request(mdr
);
9135 } else if (mdr
->slave_request
) {
9136 mds
->server
->dispatch_slave_request(mdr
);
9138 switch (mdr
->internal_op
) {
9139 case CEPH_MDS_OP_FRAGMENTDIR
:
9140 dispatch_fragment_dir(mdr
);
9142 case CEPH_MDS_OP_EXPORTDIR
:
9143 migrator
->dispatch_export_dir(mdr
, 0);
9145 case CEPH_MDS_OP_ENQUEUE_SCRUB
:
9146 enqueue_scrub_work(mdr
);
9148 case CEPH_MDS_OP_FLUSH
:
9149 flush_dentry_work(mdr
);
9151 case CEPH_MDS_OP_REPAIR_FRAGSTATS
:
9152 repair_dirfrag_stats_work(mdr
);
9154 case CEPH_MDS_OP_REPAIR_INODESTATS
:
9155 repair_inode_stats_work(mdr
);
9164 void MDCache::request_drop_foreign_locks(MDRequestRef
& mdr
)
9166 if (!mdr
->has_more())
9170 // (will implicitly drop remote dn pins)
9171 for (set
<mds_rank_t
>::iterator p
= mdr
->more()->slaves
.begin();
9172 p
!= mdr
->more()->slaves
.end();
9174 MMDSSlaveRequest
*r
= new MMDSSlaveRequest(mdr
->reqid
, mdr
->attempt
,
9175 MMDSSlaveRequest::OP_FINISH
);
9177 if (mdr
->killed
&& !mdr
->committing
) {
9179 } else if (mdr
->more()->srcdn_auth_mds
== *p
&&
9180 mdr
->more()->inode_import
.length() > 0) {
9181 // information about rename imported caps
9182 r
->inode_export
.claim(mdr
->more()->inode_import
);
9185 mds
->send_message_mds(r
, *p
);
9188 /* strip foreign xlocks out of lock lists, since the OP_FINISH drops them
9189 * implicitly. Note that we don't call the finishers -- there shouldn't
9190 * be any on a remote lock and the request finish wakes up all
9191 * the waiters anyway! */
9192 set
<SimpleLock
*>::iterator p
= mdr
->xlocks
.begin();
9193 while (p
!= mdr
->xlocks
.end()) {
9194 if ((*p
)->get_parent()->is_auth())
9197 dout(10) << "request_drop_foreign_locks forgetting lock " << **p
9198 << " on " << *(*p
)->get_parent() << dendl
;
9200 mdr
->locks
.erase(*p
);
9201 mdr
->xlocks
.erase(p
++);
9205 map
<SimpleLock
*, mds_rank_t
>::iterator q
= mdr
->remote_wrlocks
.begin();
9206 while (q
!= mdr
->remote_wrlocks
.end()) {
9207 dout(10) << "request_drop_foreign_locks forgetting remote_wrlock " << *q
->first
9208 << " on mds." << q
->second
9209 << " on " << *(q
->first
)->get_parent() << dendl
;
9210 mdr
->locks
.erase(q
->first
);
9211 mdr
->remote_wrlocks
.erase(q
++);
9214 mdr
->more()->slaves
.clear(); /* we no longer have requests out to them, and
9215 * leaving them in can cause double-notifies as
9216 * this function can get called more than once */
9219 void MDCache::request_drop_non_rdlocks(MDRequestRef
& mdr
)
9221 request_drop_foreign_locks(mdr
);
9222 mds
->locker
->drop_non_rdlocks(mdr
.get());
9225 void MDCache::request_drop_locks(MDRequestRef
& mdr
)
9227 request_drop_foreign_locks(mdr
);
9228 mds
->locker
->drop_locks(mdr
.get());
9231 void MDCache::request_cleanup(MDRequestRef
& mdr
)
9233 dout(15) << "request_cleanup " << *mdr
<< dendl
;
9235 if (mdr
->has_more()) {
9236 if (mdr
->more()->is_ambiguous_auth
)
9237 mdr
->clear_ambiguous_auth();
9238 if (!mdr
->more()->waiting_for_finish
.empty())
9239 mds
->queue_waiters(mdr
->more()->waiting_for_finish
);
9242 request_drop_locks(mdr
);
9244 // drop (local) auth pins
9245 mdr
->drop_local_auth_pins();
9248 for (set
<CInode
*>::iterator p
= mdr
->stickydirs
.begin();
9249 p
!= mdr
->stickydirs
.end();
9251 (*p
)->put_stickydirs();
9253 mds
->locker
->kick_cap_releases(mdr
);
9258 // remove from session
9259 mdr
->item_session_request
.remove_myself();
9262 active_requests
.erase(mdr
->reqid
);
9267 mdr
->mark_event("cleaned up request");
9270 void MDCache::request_kill(MDRequestRef
& mdr
)
9272 // rollback slave requests is tricky. just let the request proceed.
9273 if (mdr
->done_locking
&& mdr
->has_more() &&
9274 (!mdr
->more()->witnessed
.empty() || !mdr
->more()->waiting_on_slave
.empty())) {
9275 dout(10) << "request_kill " << *mdr
<< " -- already started slave requests, no-op" << dendl
;
9277 assert(mdr
->used_prealloc_ino
== 0);
9278 assert(mdr
->prealloc_inos
.empty());
9280 mdr
->session
= NULL
;
9281 mdr
->item_session_request
.remove_myself();
9286 mdr
->mark_event("killing request");
9288 if (mdr
->committing
) {
9289 dout(10) << "request_kill " << *mdr
<< " -- already committing, no-op" << dendl
;
9291 dout(10) << "request_kill " << *mdr
<< dendl
;
9292 request_cleanup(mdr
);
9296 // -------------------------------------------------------------------------------
9299 struct C_MDC_snaprealm_create_finish
: public MDCacheLogContext
{
9303 C_MDC_snaprealm_create_finish(MDCache
*c
, MDRequestRef
& m
,
9304 MutationRef
& mu
, CInode
*i
) :
9305 MDCacheLogContext(c
), mdr(m
), mut(mu
), in(i
) {}
9306 void finish(int r
) override
{
9307 mdcache
->_snaprealm_create_finish(mdr
, mut
, in
);
9311 void MDCache::snaprealm_create(MDRequestRef
& mdr
, CInode
*in
)
9313 dout(10) << "snaprealm_create " << *in
<< dendl
;
9314 assert(!in
->snaprealm
);
9317 if (!mdr
->more()->stid
) {
9318 mds
->snapclient
->prepare_create_realm(in
->ino(), &mdr
->more()->stid
, &mdr
->more()->snapidbl
,
9319 new C_MDS_RetryRequest(this, mdr
));
9323 MutationRef
mut(new MutationImpl());
9324 mut
->ls
= mds
->mdlog
->get_current_segment();
9325 EUpdate
*le
= new EUpdate(mds
->mdlog
, "snaprealm_create");
9326 mds
->mdlog
->start_entry(le
);
9328 le
->metablob
.add_table_transaction(TABLE_SNAP
, mdr
->more()->stid
);
9330 inode_t
*pi
= in
->project_inode();
9331 pi
->version
= in
->pre_dirty();
9332 pi
->rstat
.rsnaprealms
++;
9334 bufferlist::iterator p
= mdr
->more()->snapidbl
.begin();
9338 sr_t
*newsnap
= in
->project_snaprealm(seq
);
9340 newsnap
->last_created
= seq
;
9342 predirty_journal_parents(mut
, &le
->metablob
, in
, 0, PREDIRTY_PRIMARY
);
9343 journal_cow_inode(mut
, &le
->metablob
, in
);
9344 le
->metablob
.add_primary_dentry(in
->get_projected_parent_dn(), in
, true);
9346 mds
->server
->submit_mdlog_entry(le
,
9347 new C_MDC_snaprealm_create_finish(this, mdr
,
9350 mds
->mdlog
->flush();
9354 void MDCache::do_realm_invalidate_and_update_notify(CInode
*in
, int snapop
, bool nosend
)
9356 dout(10) << "do_realm_invalidate_and_update_notify " << *in
->snaprealm
<< " " << *in
<< dendl
;
9358 vector
<inodeno_t
> split_inos
;
9359 vector
<inodeno_t
> split_realms
;
9361 if (snapop
== CEPH_SNAP_OP_SPLIT
) {
9362 // notify clients of update|split
9363 for (elist
<CInode
*>::iterator p
= in
->snaprealm
->inodes_with_caps
.begin(member_offset(CInode
, item_caps
));
9365 split_inos
.push_back((*p
)->ino());
9367 for (set
<SnapRealm
*>::iterator p
= in
->snaprealm
->open_children
.begin();
9368 p
!= in
->snaprealm
->open_children
.end();
9370 split_realms
.push_back((*p
)->inode
->ino());
9374 in
->snaprealm
->build_snap_trace(snapbl
);
9376 set
<SnapRealm
*> past_children
;
9377 map
<client_t
, MClientSnap
*> updates
;
9379 q
.push_back(in
->snaprealm
);
9380 while (!q
.empty()) {
9381 SnapRealm
*realm
= q
.front();
9384 dout(10) << " realm " << *realm
<< " on " << *realm
->inode
<< dendl
;
9385 realm
->invalidate_cached_snaps();
9387 for (map
<client_t
, xlist
<Capability
*>* >::iterator p
= realm
->client_caps
.begin();
9388 p
!= realm
->client_caps
.end();
9390 assert(!p
->second
->empty());
9391 if (!nosend
&& updates
.count(p
->first
) == 0) {
9392 MClientSnap
*update
= new MClientSnap(snapop
);
9393 update
->head
.split
= in
->ino();
9394 update
->split_inos
= split_inos
;
9395 update
->split_realms
= split_realms
;
9396 update
->bl
= snapbl
;
9397 updates
[p
->first
] = update
;
9401 if (snapop
== CEPH_SNAP_OP_UPDATE
|| snapop
== CEPH_SNAP_OP_DESTROY
) {
9402 for (set
<SnapRealm
*>::iterator p
= realm
->open_past_children
.begin();
9403 p
!= realm
->open_past_children
.end();
9405 past_children
.insert(*p
);
9408 // notify for active children, too.
9409 dout(10) << " " << realm
<< " open_children are " << realm
->open_children
<< dendl
;
9410 for (set
<SnapRealm
*>::iterator p
= realm
->open_children
.begin();
9411 p
!= realm
->open_children
.end();
9417 send_snaps(updates
);
9419 // notify past children and their descendants if we update/delete old snapshots
9420 for (set
<SnapRealm
*>::iterator p
= past_children
.begin();
9421 p
!= past_children
.end();
9425 while (!q
.empty()) {
9426 SnapRealm
*realm
= q
.front();
9429 realm
->invalidate_cached_snaps();
9431 for (set
<SnapRealm
*>::iterator p
= realm
->open_children
.begin();
9432 p
!= realm
->open_children
.end();
9434 if (past_children
.count(*p
) == 0)
9438 for (set
<SnapRealm
*>::iterator p
= realm
->open_past_children
.begin();
9439 p
!= realm
->open_past_children
.end();
9441 if (past_children
.count(*p
) == 0) {
9443 past_children
.insert(*p
);
9448 if (snapop
== CEPH_SNAP_OP_DESTROY
) {
9449 // eval stray inodes if we delete snapshot from their past ancestor snaprealm
9450 for (set
<SnapRealm
*>::iterator p
= past_children
.begin();
9451 p
!= past_children
.end();
9453 maybe_eval_stray((*p
)->inode
, true);
9457 void MDCache::_snaprealm_create_finish(MDRequestRef
& mdr
, MutationRef
& mut
, CInode
*in
)
9459 dout(10) << "_snaprealm_create_finish " << *in
<< dendl
;
9462 in
->pop_and_dirty_projected_inode(mut
->ls
);
9464 mds
->locker
->drop_locks(mut
.get());
9467 // tell table we've committed
9468 mds
->snapclient
->commit(mdr
->more()->stid
, mut
->ls
);
9471 bufferlist::iterator p
= mdr
->more()->snapidbl
.begin();
9475 in
->open_snaprealm();
9476 in
->snaprealm
->srnode
.seq
= seq
;
9477 in
->snaprealm
->srnode
.created
= seq
;
9478 bool ok
= in
->snaprealm
->_open_parents(NULL
);
9481 do_realm_invalidate_and_update_notify(in
, CEPH_SNAP_OP_SPLIT
);
9484 static int count = 5;
9486 ceph_abort(); // hack test test **********
9490 mdr
->more()->stid
= 0; // caller will likely need to reuse this
9491 dispatch_request(mdr
);
9495 // -------------------------------------------------------------------------------
9498 struct C_MDC_RetryScanStray
: public MDCacheContext
{
9500 C_MDC_RetryScanStray(MDCache
*c
, dirfrag_t n
) : MDCacheContext(c
), next(n
) { }
9501 void finish(int r
) override
{
9502 mdcache
->scan_stray_dir(next
);
9506 void MDCache::scan_stray_dir(dirfrag_t next
)
9508 dout(10) << "scan_stray_dir " << next
<< dendl
;
9511 for (int i
= 0; i
< NUM_STRAY
; ++i
) {
9512 if (strays
[i
]->ino() < next
.ino
)
9514 strays
[i
]->get_dirfrags(ls
);
9517 for (list
<CDir
*>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
9519 if (dir
->dirfrag() < next
)
9521 if (!dir
->is_complete()) {
9522 dir
->fetch(new C_MDC_RetryScanStray(this, dir
->dirfrag()));
9525 for (CDir::map_t::iterator q
= dir
->items
.begin(); q
!= dir
->items
.end(); ++q
) {
9526 CDentry
*dn
= q
->second
;
9527 dn
->state_set(CDentry::STATE_STRAY
);
9528 CDentry::linkage_t
*dnl
= dn
->get_projected_linkage();
9529 if (dnl
->is_primary()) {
9530 CInode
*in
= dnl
->get_inode();
9531 if (in
->inode
.nlink
== 0)
9532 in
->state_set(CInode::STATE_ORPHAN
);
9533 maybe_eval_stray(in
);
9539 void MDCache::fetch_backtrace(inodeno_t ino
, int64_t pool
, bufferlist
& bl
, Context
*fin
)
9541 object_t oid
= CInode::get_object_name(ino
, frag_t(), "");
9542 mds
->objecter
->getxattr(oid
, object_locator_t(pool
), "parent", CEPH_NOSNAP
, &bl
, 0, fin
);
9549 // ========================================================================================
9553 - for all discovers (except base_inos, e.g. root, stray), waiters are attached
9554 to the parent metadata object in the cache (pinning it).
9556 - all discovers are tracked by tid, so that we can ignore potentially dup replies.
9560 void MDCache::_send_discover(discover_info_t
& d
)
9562 MDiscover
*dis
= new MDiscover(d
.ino
, d
.frag
, d
.snap
, d
.want_path
,
9563 d
.want_base_dir
, d
.want_xlocked
);
9564 dis
->set_tid(d
.tid
);
9565 mds
->send_message_mds(dis
, d
.mds
);
9568 void MDCache::discover_base_ino(inodeno_t want_ino
,
9569 MDSInternalContextBase
*onfinish
,
9572 dout(7) << "discover_base_ino " << want_ino
<< " from mds." << from
<< dendl
;
9573 if (waiting_for_base_ino
[from
].count(want_ino
) == 0) {
9574 discover_info_t
& d
= _create_discover(from
);
9578 waiting_for_base_ino
[from
][want_ino
].push_back(onfinish
);
9582 void MDCache::discover_dir_frag(CInode
*base
,
9584 MDSInternalContextBase
*onfinish
,
9588 from
= base
->authority().first
;
9590 dirfrag_t
df(base
->ino(), approx_fg
);
9591 dout(7) << "discover_dir_frag " << df
9592 << " from mds." << from
<< dendl
;
9594 if (!base
->is_waiting_for_dir(approx_fg
) || !onfinish
) {
9595 discover_info_t
& d
= _create_discover(from
);
9597 d
.ino
= base
->ino();
9599 d
.want_base_dir
= true;
9604 base
->add_dir_waiter(approx_fg
, onfinish
);
9607 struct C_MDC_RetryDiscoverPath
: public MDCacheContext
{
9612 C_MDC_RetryDiscoverPath(MDCache
*c
, CInode
*b
, snapid_t s
, filepath
&p
, mds_rank_t f
) :
9613 MDCacheContext(c
), base(b
), snapid(s
), path(p
), from(f
) {}
9614 void finish(int r
) override
{
9615 mdcache
->discover_path(base
, snapid
, path
, 0, from
);
9619 void MDCache::discover_path(CInode
*base
,
9622 MDSInternalContextBase
*onfinish
,
9627 from
= base
->authority().first
;
9629 dout(7) << "discover_path " << base
->ino() << " " << want_path
<< " snap " << snap
<< " from mds." << from
9630 << (want_xlocked
? " want_xlocked":"")
9633 if (base
->is_ambiguous_auth()) {
9634 dout(10) << " waiting for single auth on " << *base
<< dendl
;
9636 onfinish
= new C_MDC_RetryDiscoverPath(this, base
, snap
, want_path
, from
);
9637 base
->add_waiter(CInode::WAIT_SINGLEAUTH
, onfinish
);
9639 } else if (from
== mds
->get_nodeid()) {
9640 list
<MDSInternalContextBase
*> finished
;
9641 base
->take_waiting(CInode::WAIT_DIR
, finished
);
9642 mds
->queue_waiters(finished
);
9646 frag_t fg
= base
->pick_dirfrag(want_path
[0]);
9647 if ((want_xlocked
&& want_path
.depth() == 1) ||
9648 !base
->is_waiting_for_dir(fg
) || !onfinish
) {
9649 discover_info_t
& d
= _create_discover(from
);
9650 d
.ino
= base
->ino();
9654 d
.want_path
= want_path
;
9655 d
.want_base_dir
= true;
9656 d
.want_xlocked
= want_xlocked
;
9662 base
->add_dir_waiter(fg
, onfinish
);
9665 struct C_MDC_RetryDiscoverPath2
: public MDCacheContext
{
9669 C_MDC_RetryDiscoverPath2(MDCache
*c
, CDir
*b
, snapid_t s
, filepath
&p
) :
9670 MDCacheContext(c
), base(b
), snapid(s
), path(p
) {}
9671 void finish(int r
) override
{
9672 mdcache
->discover_path(base
, snapid
, path
, 0);
9676 void MDCache::discover_path(CDir
*base
,
9679 MDSInternalContextBase
*onfinish
,
9682 mds_rank_t from
= base
->authority().first
;
9684 dout(7) << "discover_path " << base
->dirfrag() << " " << want_path
<< " snap " << snap
<< " from mds." << from
9685 << (want_xlocked
? " want_xlocked":"")
9688 if (base
->is_ambiguous_auth()) {
9689 dout(7) << " waiting for single auth on " << *base
<< dendl
;
9691 onfinish
= new C_MDC_RetryDiscoverPath2(this, base
, snap
, want_path
);
9692 base
->add_waiter(CDir::WAIT_SINGLEAUTH
, onfinish
);
9694 } else if (from
== mds
->get_nodeid()) {
9695 list
<MDSInternalContextBase
*> finished
;
9696 base
->take_sub_waiting(finished
);
9697 mds
->queue_waiters(finished
);
9701 if ((want_xlocked
&& want_path
.depth() == 1) ||
9702 !base
->is_waiting_for_dentry(want_path
[0].c_str(), snap
) || !onfinish
) {
9703 discover_info_t
& d
= _create_discover(from
);
9704 d
.ino
= base
->ino();
9705 d
.pin_base(base
->inode
);
9706 d
.frag
= base
->get_frag();
9708 d
.want_path
= want_path
;
9709 d
.want_base_dir
= false;
9710 d
.want_xlocked
= want_xlocked
;
9716 base
->add_dentry_waiter(want_path
[0], snap
, onfinish
);
9719 void MDCache::kick_discovers(mds_rank_t who
)
9721 for (map
<ceph_tid_t
,discover_info_t
>::iterator p
= discovers
.begin();
9722 p
!= discovers
.end();
9724 if (p
->second
.mds
!= who
)
9726 _send_discover(p
->second
);
9731 /* This function DOES put the passed message before returning */
9732 void MDCache::handle_discover(MDiscover
*dis
)
9734 mds_rank_t whoami
= mds
->get_nodeid();
9735 mds_rank_t from
= mds_rank_t(dis
->get_source().num());
9737 assert(from
!= whoami
);
9739 if (mds
->get_state() <= MDSMap::STATE_REJOIN
) {
9740 if (mds
->get_state() < MDSMap::STATE_REJOIN
&&
9741 mds
->get_want_state() < CEPH_MDS_STATE_REJOIN
) {
9746 // proceed if requester is in the REJOIN stage, the request is from parallel_fetch().
9747 // delay processing request from survivor because we may not yet choose lock states.
9748 if (!mds
->mdsmap
->is_rejoin(from
)) {
9749 dout(0) << "discover_reply not yet active(|still rejoining), delaying" << dendl
;
9750 mds
->wait_for_replay(new C_MDS_RetryMessage(mds
, dis
));
9757 MDiscoverReply
*reply
= new MDiscoverReply(dis
);
9759 snapid_t snapid
= dis
->get_snapid();
9762 if (MDS_INO_IS_BASE(dis
->get_base_ino()) &&
9763 !dis
->wants_base_dir() && dis
->get_want().depth() == 0) {
9765 dout(7) << "handle_discover from mds." << from
9766 << " wants base + " << dis
->get_want().get_path()
9767 << " snap " << snapid
9770 cur
= get_inode(dis
->get_base_ino());
9774 reply
->starts_with
= MDiscoverReply::INODE
;
9775 replicate_inode(cur
, from
, reply
->trace
, mds
->mdsmap
->get_up_features());
9776 dout(10) << "added base " << *cur
<< dendl
;
9779 // there's a base inode
9780 cur
= get_inode(dis
->get_base_ino(), snapid
);
9781 if (!cur
&& snapid
!= CEPH_NOSNAP
) {
9782 cur
= get_inode(dis
->get_base_ino());
9783 if (cur
&& !cur
->is_multiversion())
9784 cur
= NULL
; // nope!
9788 dout(7) << "handle_discover mds." << from
9789 << " don't have base ino " << dis
->get_base_ino() << "." << snapid
9791 if (!dis
->wants_base_dir() && dis
->get_want().depth() > 0)
9792 reply
->set_error_dentry(dis
->get_dentry(0));
9793 reply
->set_flag_error_dir();
9794 } else if (dis
->wants_base_dir()) {
9795 dout(7) << "handle_discover mds." << from
9796 << " wants basedir+" << dis
->get_want().get_path()
9800 dout(7) << "handle_discover mds." << from
9801 << " wants " << dis
->get_want().get_path()
9810 // do some fidgeting to include a dir if they asked for the base dir, or just root.
9811 for (unsigned i
= 0;
9812 cur
&& (i
< dis
->get_want().depth() || dis
->get_want().depth() == 0);
9815 // -- figure out the dir
9817 // is *cur even a dir at all?
9818 if (!cur
->is_dir()) {
9819 dout(7) << *cur
<< " not a dir" << dendl
;
9820 reply
->set_flag_error_dir();
9826 if (dis
->get_want().depth()) {
9828 fg
= cur
->pick_dirfrag(dis
->get_dentry(i
));
9830 // requester explicity specified the frag
9831 assert(dis
->wants_base_dir() || MDS_INO_IS_BASE(dis
->get_base_ino()));
9832 fg
= dis
->get_base_dir_frag();
9833 if (!cur
->dirfragtree
.is_leaf(fg
))
9834 fg
= cur
->dirfragtree
[fg
.value()];
9836 CDir
*curdir
= cur
->get_dirfrag(fg
);
9838 if ((!curdir
&& !cur
->is_auth()) ||
9839 (curdir
&& !curdir
->is_auth())) {
9842 * ONLY set flag if empty!!
9843 * otherwise requester will wake up waiter(s) _and_ continue with discover,
9844 * resulting in duplicate discovers in flight,
9845 * which can wreak havoc when discovering rename srcdn (which may move)
9848 if (reply
->is_empty()) {
9849 // only hint if empty.
9850 // someday this could be better, but right now the waiter logic isn't smart enough.
9854 dout(7) << " not dirfrag auth, setting dir_auth_hint for " << *curdir
<< dendl
;
9855 reply
->set_dir_auth_hint(curdir
->authority().first
);
9857 dout(7) << " dirfrag not open, not inode auth, setting dir_auth_hint for "
9859 reply
->set_dir_auth_hint(cur
->authority().first
);
9862 // note error dentry, if any
9863 // NOTE: important, as it allows requester to issue an equivalent discover
9864 // to whomever we hint at.
9865 if (dis
->get_want().depth() > i
)
9866 reply
->set_error_dentry(dis
->get_dentry(i
));
9872 if (!curdir
) { // open dir?
9873 if (cur
->is_frozen()) {
9874 if (!reply
->is_empty()) {
9875 dout(7) << *cur
<< " is frozen, non-empty reply, stopping" << dendl
;
9878 dout(7) << *cur
<< " is frozen, empty reply, waiting" << dendl
;
9879 cur
->add_waiter(CInode::WAIT_UNFREEZE
, new C_MDS_RetryMessage(mds
, dis
));
9883 curdir
= cur
->get_or_open_dirfrag(this, fg
);
9884 } else if (curdir
->is_frozen_tree() ||
9885 (curdir
->is_frozen_dir() && fragment_are_all_frozen(curdir
))) {
9886 if (!reply
->is_empty()) {
9887 dout(7) << *curdir
<< " is frozen, non-empty reply, stopping" << dendl
;
9890 if (dis
->wants_base_dir() && dis
->get_base_dir_frag() != curdir
->get_frag()) {
9891 dout(7) << *curdir
<< " is frozen, dirfrag mismatch, stopping" << dendl
;
9892 reply
->set_flag_error_dir();
9895 dout(7) << *curdir
<< " is frozen, empty reply, waiting" << dendl
;
9896 curdir
->add_waiter(CDir::WAIT_UNFREEZE
, new C_MDS_RetryMessage(mds
, dis
));
9902 if (curdir
->get_version() == 0) {
9903 // fetch newly opened dir
9904 } else if (reply
->is_empty() && !dis
->wants_base_dir()) {
9905 dout(7) << "handle_discover not adding unwanted base dir " << *curdir
<< dendl
;
9906 // make sure the base frag is correct, though, in there was a refragment since the
9907 // original request was sent.
9908 reply
->set_base_dir_frag(curdir
->get_frag());
9910 assert(!curdir
->is_ambiguous_auth()); // would be frozen.
9911 if (!reply
->trace
.length())
9912 reply
->starts_with
= MDiscoverReply::DIR;
9913 replicate_dir(curdir
, from
, reply
->trace
);
9914 dout(7) << "handle_discover added dir " << *curdir
<< dendl
;
9919 if (curdir
->get_version() == 0) {
9920 // fetch newly opened dir
9921 assert(!curdir
->has_bloom());
9922 } else if (dis
->get_want().depth() > 0) {
9924 dn
= curdir
->lookup(dis
->get_dentry(i
), snapid
);
9930 if (!curdir
->is_complete() &&
9931 (!curdir
->has_bloom() || curdir
->is_in_bloom(dis
->get_dentry(i
)))) {
9933 dout(7) << "incomplete dir contents for " << *curdir
<< ", fetching" << dendl
;
9934 if (reply
->is_empty()) {
9936 curdir
->fetch(new C_MDS_RetryMessage(mds
, dis
),
9937 dis
->wants_base_dir() && curdir
->get_version() == 0);
9941 // initiate fetch, but send what we have so far
9948 dout(7) << "dentry " << dis
->get_dentry(i
) << " dne, returning null in "
9949 << *curdir
<< dendl
;
9950 dn
= curdir
->add_null_dentry(dis
->get_dentry(i
));
9954 // don't add replica to purging dentry/inode
9955 if (dn
->state_test(CDentry::STATE_PURGING
)) {
9956 if (reply
->is_empty())
9957 reply
->set_flag_error_dn(dis
->get_dentry(i
));
9961 CDentry::linkage_t
*dnl
= dn
->get_linkage();
9964 // ...always block on non-tail items (they are unrelated)
9965 // ...allow xlocked tail disocvery _only_ if explicitly requested
9966 bool tailitem
= (dis
->get_want().depth() == 0) || (i
== dis
->get_want().depth() - 1);
9967 if (dn
->lock
.is_xlocked()) {
9968 // is this the last (tail) item in the discover traversal?
9969 if (tailitem
&& dis
->wants_xlocked()) {
9970 dout(7) << "handle_discover allowing discovery of xlocked tail " << *dn
<< dendl
;
9971 } else if (reply
->is_empty()) {
9972 dout(7) << "handle_discover blocking on xlocked " << *dn
<< dendl
;
9973 dn
->lock
.add_waiter(SimpleLock::WAIT_RD
, new C_MDS_RetryMessage(mds
, dis
));
9977 dout(7) << "handle_discover non-empty reply, xlocked tail " << *dn
<< dendl
;
9983 if (dnl
->is_primary() && dnl
->get_inode()->is_frozen_inode()) {
9984 if (tailitem
&& dis
->wants_xlocked()) {
9985 dout(7) << "handle_discover allowing discovery of frozen tail " << *dnl
->get_inode() << dendl
;
9986 } else if (reply
->is_empty()) {
9987 dout(7) << *dnl
->get_inode() << " is frozen, empty reply, waiting" << dendl
;
9988 dnl
->get_inode()->add_waiter(CDir::WAIT_UNFREEZE
, new C_MDS_RetryMessage(mds
, dis
));
9992 dout(7) << *dnl
->get_inode() << " is frozen, non-empty reply, stopping" << dendl
;
9998 if (!reply
->trace
.length())
9999 reply
->starts_with
= MDiscoverReply::DENTRY
;
10000 replicate_dentry(dn
, from
, reply
->trace
);
10001 dout(7) << "handle_discover added dentry " << *dn
<< dendl
;
10003 if (!dnl
->is_primary()) break; // stop on null or remote link.
10006 CInode
*next
= dnl
->get_inode();
10007 assert(next
->is_auth());
10009 replicate_inode(next
, from
, reply
->trace
, mds
->mdsmap
->get_up_features());
10010 dout(7) << "handle_discover added inode " << *next
<< dendl
;
10012 // descend, keep going.
10018 assert(!reply
->is_empty());
10019 dout(7) << "handle_discover sending result back to asker mds." << from
<< dendl
;
10020 mds
->send_message(reply
, dis
->get_connection());
10025 /* This function DOES put the passed message before returning */
10026 void MDCache::handle_discover_reply(MDiscoverReply
*m
)
10029 if (mds->get_state() < MDSMap::STATE_ACTIVE) {
10030 dout(0) << "discover_reply NOT ACTIVE YET" << dendl;
10035 dout(7) << "discover_reply " << *m
<< dendl
;
10036 if (m
->is_flag_error_dir())
10037 dout(7) << " flag error, dir" << dendl
;
10038 if (m
->is_flag_error_dn())
10039 dout(7) << " flag error, dentry = " << m
->get_error_dentry() << dendl
;
10041 list
<MDSInternalContextBase
*> finished
, error
;
10042 mds_rank_t from
= mds_rank_t(m
->get_source().num());
10045 CInode
*cur
= get_inode(m
->get_base_ino());
10046 bufferlist::iterator p
= m
->trace
.begin();
10048 int next
= m
->starts_with
;
10050 // decrement discover counters
10051 if (m
->get_tid()) {
10052 map
<ceph_tid_t
,discover_info_t
>::iterator p
= discovers
.find(m
->get_tid());
10053 if (p
!= discovers
.end()) {
10054 dout(10) << " found tid " << m
->get_tid() << dendl
;
10055 discovers
.erase(p
);
10057 dout(10) << " tid " << m
->get_tid() << " not found, must be dup reply" << dendl
;
10061 // discover may start with an inode
10062 if (!p
.end() && next
== MDiscoverReply::INODE
) {
10063 cur
= add_replica_inode(p
, NULL
, finished
);
10064 dout(7) << "discover_reply got base inode " << *cur
<< dendl
;
10065 assert(cur
->is_base());
10067 next
= MDiscoverReply::DIR;
10070 if (cur
->is_base() &&
10071 waiting_for_base_ino
[from
].count(cur
->ino())) {
10072 finished
.swap(waiting_for_base_ino
[from
][cur
->ino()]);
10073 waiting_for_base_ino
[from
].erase(cur
->ino());
10078 // loop over discover results.
10079 // indexes follow each ([[dir] dentry] inode)
10080 // can start, end with any type.
10085 if (next
== MDiscoverReply::DIR) {
10086 curdir
= add_replica_dir(p
, cur
, mds_rank_t(m
->get_source().num()), finished
);
10087 if (cur
->ino() == m
->get_base_ino() && curdir
->get_frag() != m
->get_base_dir_frag()) {
10088 assert(m
->get_wanted_base_dir());
10089 cur
->take_dir_waiting(m
->get_base_dir_frag(), finished
);
10092 // note: this can only happen our first way around this loop.
10093 if (p
.end() && m
->is_flag_error_dn()) {
10094 fg
= cur
->pick_dirfrag(m
->get_error_dentry());
10095 curdir
= cur
->get_dirfrag(fg
);
10097 curdir
= cur
->get_dirfrag(m
->get_base_dir_frag());
10104 CDentry
*dn
= add_replica_dentry(p
, curdir
, finished
);
10110 cur
= add_replica_inode(p
, dn
, finished
);
10112 next
= MDiscoverReply::DIR;
10116 // or dir_auth hint?
10117 if (m
->is_flag_error_dir() && !cur
->is_dir()) {
10119 cur
->take_waiting(CInode::WAIT_DIR
, error
);
10120 } else if (m
->is_flag_error_dir() || m
->get_dir_auth_hint() != CDIR_AUTH_UNKNOWN
) {
10121 mds_rank_t who
= m
->get_dir_auth_hint();
10122 if (who
== mds
->get_nodeid()) who
= -1;
10124 dout(7) << " dir_auth_hint is " << m
->get_dir_auth_hint() << dendl
;
10127 if (m
->get_wanted_base_dir()) {
10128 frag_t fg
= m
->get_base_dir_frag();
10129 CDir
*dir
= cur
->get_dirfrag(fg
);
10131 if (cur
->is_waiting_for_dir(fg
)) {
10132 if (cur
->is_auth())
10133 cur
->take_waiting(CInode::WAIT_DIR
, finished
);
10134 else if (dir
|| !cur
->dirfragtree
.is_leaf(fg
))
10135 cur
->take_dir_waiting(fg
, finished
);
10137 discover_dir_frag(cur
, fg
, 0, who
);
10139 dout(7) << " doing nothing, nobody is waiting for dir" << dendl
;
10143 if (m
->get_error_dentry().length()) {
10144 frag_t fg
= cur
->pick_dirfrag(m
->get_error_dentry());
10145 CDir
*dir
= cur
->get_dirfrag(fg
);
10147 if (dir
&& dir
->is_waiting_for_dentry(m
->get_error_dentry(), m
->get_wanted_snapid())) {
10148 if (dir
->is_auth() || dir
->lookup(m
->get_error_dentry())) {
10149 dir
->take_dentry_waiting(m
->get_error_dentry(), m
->get_wanted_snapid(),
10150 m
->get_wanted_snapid(), finished
);
10152 filepath
relpath(m
->get_error_dentry(), 0);
10153 discover_path(dir
, m
->get_wanted_snapid(), relpath
, 0, m
->get_wanted_xlocked());
10156 dout(7) << " doing nothing, have dir but nobody is waiting on dentry "
10157 << m
->get_error_dentry() << dendl
;
10159 } else if (m
->is_flag_error_dn()) {
10160 frag_t fg
= cur
->pick_dirfrag(m
->get_error_dentry());
10161 CDir
*dir
= cur
->get_dirfrag(fg
);
10163 if (dir
->is_auth()) {
10164 dir
->take_sub_waiting(finished
);
10166 dir
->take_dentry_waiting(m
->get_error_dentry(), m
->get_wanted_snapid(),
10167 m
->get_wanted_snapid(), error
);
10173 finish_contexts(g_ceph_context
, error
, -ENOENT
); // finish errors directly
10174 mds
->queue_waiters(finished
);
10182 // ----------------------------
10185 CDir
*MDCache::add_replica_dir(bufferlist::iterator
& p
, CInode
*diri
, mds_rank_t from
,
10186 list
<MDSInternalContextBase
*>& finished
)
10191 assert(diri
->ino() == df
.ino
);
10193 // add it (_replica_)
10194 CDir
*dir
= diri
->get_dirfrag(df
.frag
);
10197 // had replica. update w/ new nonce.
10198 dir
->decode_replica(p
);
10199 dout(7) << "add_replica_dir had " << *dir
<< " nonce " << dir
->replica_nonce
<< dendl
;
10201 // force frag to leaf in the diri tree
10202 if (!diri
->dirfragtree
.is_leaf(df
.frag
)) {
10203 dout(7) << "add_replica_dir forcing frag " << df
.frag
<< " to leaf in the fragtree "
10204 << diri
->dirfragtree
<< dendl
;
10205 diri
->dirfragtree
.force_to_leaf(g_ceph_context
, df
.frag
);
10209 dir
= diri
->add_dirfrag( new CDir(diri
, df
.frag
, this, false) );
10210 dir
->decode_replica(p
);
10212 // is this a dir_auth delegation boundary?
10213 if (from
!= diri
->authority().first
||
10214 diri
->is_ambiguous_auth() ||
10216 adjust_subtree_auth(dir
, from
);
10218 dout(7) << "add_replica_dir added " << *dir
<< " nonce " << dir
->replica_nonce
<< dendl
;
10221 diri
->take_dir_waiting(df
.frag
, finished
);
10227 CDentry
*MDCache::add_replica_dentry(bufferlist::iterator
& p
, CDir
*dir
, list
<MDSInternalContextBase
*>& finished
)
10234 CDentry
*dn
= dir
->lookup(name
, last
);
10238 dn
->decode_replica(p
, false);
10239 dout(7) << "add_replica_dentry had " << *dn
<< dendl
;
10241 dn
= dir
->add_null_dentry(name
, 1 /* this will get updated below */, last
);
10242 dn
->decode_replica(p
, true);
10243 dout(7) << "add_replica_dentry added " << *dn
<< dendl
;
10246 dir
->take_dentry_waiting(name
, dn
->first
, dn
->last
, finished
);
10251 CInode
*MDCache::add_replica_inode(bufferlist::iterator
& p
, CDentry
*dn
, list
<MDSInternalContextBase
*>& finished
)
10257 CInode
*in
= get_inode(ino
, last
);
10259 in
= new CInode(this, false, 1, last
);
10260 in
->decode_replica(p
, true);
10262 if (in
->ino() == MDS_INO_ROOT
)
10263 in
->inode_auth
.first
= 0;
10264 else if (in
->is_mdsdir())
10265 in
->inode_auth
.first
= in
->ino() - MDS_INO_MDSDIR_OFFSET
;
10266 dout(10) << "add_replica_inode added " << *in
<< dendl
;
10268 assert(dn
->get_linkage()->is_null());
10269 dn
->dir
->link_primary_inode(dn
, in
);
10272 in
->decode_replica(p
, false);
10273 dout(10) << "add_replica_inode had " << *in
<< dendl
;
10277 if (!dn
->get_linkage()->is_primary() || dn
->get_linkage()->get_inode() != in
)
10278 dout(10) << "add_replica_inode different linkage in dentry " << *dn
<< dendl
;
10285 void MDCache::replicate_stray(CDentry
*straydn
, mds_rank_t who
, bufferlist
& bl
)
10287 uint64_t features
= mds
->mdsmap
->get_up_features();
10288 replicate_inode(get_myin(), who
, bl
, features
);
10289 replicate_dir(straydn
->get_dir()->inode
->get_parent_dn()->get_dir(), who
, bl
);
10290 replicate_dentry(straydn
->get_dir()->inode
->get_parent_dn(), who
, bl
);
10291 replicate_inode(straydn
->get_dir()->inode
, who
, bl
, features
);
10292 replicate_dir(straydn
->get_dir(), who
, bl
);
10293 replicate_dentry(straydn
, who
, bl
);
10296 CDentry
*MDCache::add_replica_stray(bufferlist
&bl
, mds_rank_t from
)
10298 list
<MDSInternalContextBase
*> finished
;
10299 bufferlist::iterator p
= bl
.begin();
10301 CInode
*mdsin
= add_replica_inode(p
, NULL
, finished
);
10302 CDir
*mdsdir
= add_replica_dir(p
, mdsin
, from
, finished
);
10303 CDentry
*straydirdn
= add_replica_dentry(p
, mdsdir
, finished
);
10304 CInode
*strayin
= add_replica_inode(p
, straydirdn
, finished
);
10305 CDir
*straydir
= add_replica_dir(p
, strayin
, from
, finished
);
10306 CDentry
*straydn
= add_replica_dentry(p
, straydir
, finished
);
10307 if (!finished
.empty())
10308 mds
->queue_waiters(finished
);
10314 int MDCache::send_dir_updates(CDir
*dir
, bool bcast
)
10316 // this is an FYI, re: replication
10318 set
<mds_rank_t
> who
;
10320 mds
->get_mds_map()->get_active_mds_set(who
);
10322 for (const auto &p
: dir
->get_replicas()) {
10323 who
.insert(p
.first
);
10327 dout(7) << "sending dir_update on " << *dir
<< " bcast " << bcast
<< " to " << who
<< dendl
;
10330 dir
->inode
->make_path(path
);
10332 mds_rank_t whoami
= mds
->get_nodeid();
10333 for (set
<mds_rank_t
>::iterator it
= who
.begin();
10336 if (*it
== whoami
) continue;
10337 //if (*it == except) continue;
10338 dout(7) << "sending dir_update on " << *dir
<< " to " << *it
<< dendl
;
10340 mds
->send_message_mds(new MDirUpdate(mds
->get_nodeid(),
10352 /* This function DOES put the passed message before returning */
10353 void MDCache::handle_dir_update(MDirUpdate
*m
)
10355 dirfrag_t df
= m
->get_dirfrag();
10356 CDir
*dir
= get_dirfrag(df
);
10358 dout(5) << "dir_update on " << df
<< ", don't have it" << dendl
;
10361 if (m
->should_discover()) {
10363 // this is key to avoid a fragtree update race, among other things.
10364 m
->inc_tried_discover();
10365 vector
<CDentry
*> trace
;
10367 filepath path
= m
->get_path();
10368 dout(5) << "trying discover on dir_update for " << path
<< dendl
;
10369 MDRequestRef null_ref
;
10370 int r
= path_traverse(null_ref
, m
, NULL
, path
, &trace
, &in
, MDS_TRAVERSE_DISCOVER
);
10374 in
->ino() == df
.ino
&&
10375 in
->get_approx_dirfrag(df
.frag
) == NULL
) {
10376 open_remote_dirfrag(in
, df
.frag
, new C_MDS_RetryMessage(mds
, m
));
10385 if (!m
->has_tried_discover()) {
10386 // Update if it already exists. Othwerwise it got updated by discover reply.
10387 dout(5) << "dir_update on " << *dir
<< dendl
;
10388 dir
->dir_rep
= m
->get_dir_rep();
10389 dir
->dir_rep_by
= m
->get_dir_rep_by();
10402 void MDCache::send_dentry_link(CDentry
*dn
, MDRequestRef
& mdr
)
10404 dout(7) << "send_dentry_link " << *dn
<< dendl
;
10406 CDir
*subtree
= get_subtree_root(dn
->get_dir());
10407 for (const auto &p
: dn
->get_replicas()) {
10408 // don't tell (rename) witnesses; they already know
10409 if (mdr
.get() && mdr
->more()->witnessed
.count(p
.first
))
10411 if (mds
->mdsmap
->get_state(p
.first
) < MDSMap::STATE_REJOIN
||
10412 (mds
->mdsmap
->get_state(p
.first
) == MDSMap::STATE_REJOIN
&&
10413 rejoin_gather
.count(p
.first
)))
10415 CDentry::linkage_t
*dnl
= dn
->get_linkage();
10416 MDentryLink
*m
= new MDentryLink(subtree
->dirfrag(), dn
->get_dir()->dirfrag(),
10417 dn
->name
, dnl
->is_primary());
10418 if (dnl
->is_primary()) {
10419 dout(10) << " primary " << *dnl
->get_inode() << dendl
;
10420 replicate_inode(dnl
->get_inode(), p
.first
, m
->bl
,
10421 mds
->mdsmap
->get_up_features());
10422 } else if (dnl
->is_remote()) {
10423 inodeno_t ino
= dnl
->get_remote_ino();
10424 __u8 d_type
= dnl
->get_remote_d_type();
10425 dout(10) << " remote " << ino
<< " " << d_type
<< dendl
;
10426 ::encode(ino
, m
->bl
);
10427 ::encode(d_type
, m
->bl
);
10429 ceph_abort(); // aie, bad caller!
10430 mds
->send_message_mds(m
, p
.first
);
10434 /* This function DOES put the passed message before returning */
10435 void MDCache::handle_dentry_link(MDentryLink
*m
)
10438 CDentry
*dn
= NULL
;
10439 CDir
*dir
= get_dirfrag(m
->get_dirfrag());
10441 dout(7) << "handle_dentry_link don't have dirfrag " << m
->get_dirfrag() << dendl
;
10443 dn
= dir
->lookup(m
->get_dn());
10445 dout(7) << "handle_dentry_link don't have dentry " << *dir
<< " dn " << m
->get_dn() << dendl
;
10447 dout(7) << "handle_dentry_link on " << *dn
<< dendl
;
10448 CDentry::linkage_t
*dnl
= dn
->get_linkage();
10450 assert(!dn
->is_auth());
10451 assert(dnl
->is_null());
10455 bufferlist::iterator p
= m
->bl
.begin();
10456 list
<MDSInternalContextBase
*> finished
;
10458 if (m
->get_is_primary()) {
10460 add_replica_inode(p
, dn
, finished
);
10462 // remote link, easy enough.
10466 ::decode(d_type
, p
);
10467 dir
->link_remote_inode(dn
, ino
, d_type
);
10473 if (!finished
.empty())
10474 mds
->queue_waiters(finished
);
10483 void MDCache::send_dentry_unlink(CDentry
*dn
, CDentry
*straydn
, MDRequestRef
& mdr
)
10485 dout(10) << "send_dentry_unlink " << *dn
<< dendl
;
10486 // share unlink news with replicas
10487 set
<mds_rank_t
> replicas
;
10488 dn
->list_replicas(replicas
);
10490 straydn
->list_replicas(replicas
);
10491 for (set
<mds_rank_t
>::iterator it
= replicas
.begin();
10492 it
!= replicas
.end();
10494 // don't tell (rmdir) witnesses; they already know
10495 if (mdr
.get() && mdr
->more()->witnessed
.count(*it
))
10498 if (mds
->mdsmap
->get_state(*it
) < MDSMap::STATE_REJOIN
||
10499 (mds
->mdsmap
->get_state(*it
) == MDSMap::STATE_REJOIN
&&
10500 rejoin_gather
.count(*it
)))
10503 MDentryUnlink
*unlink
= new MDentryUnlink(dn
->get_dir()->dirfrag(), dn
->name
);
10505 replicate_stray(straydn
, *it
, unlink
->straybl
);
10506 mds
->send_message_mds(unlink
, *it
);
10510 /* This function DOES put the passed message before returning */
10511 void MDCache::handle_dentry_unlink(MDentryUnlink
*m
)
10514 CDentry
*straydn
= NULL
;
10515 if (m
->straybl
.length())
10516 straydn
= add_replica_stray(m
->straybl
, mds_rank_t(m
->get_source().num()));
10518 CDir
*dir
= get_dirfrag(m
->get_dirfrag());
10520 dout(7) << "handle_dentry_unlink don't have dirfrag " << m
->get_dirfrag() << dendl
;
10522 CDentry
*dn
= dir
->lookup(m
->get_dn());
10524 dout(7) << "handle_dentry_unlink don't have dentry " << *dir
<< " dn " << m
->get_dn() << dendl
;
10526 dout(7) << "handle_dentry_unlink on " << *dn
<< dendl
;
10527 CDentry::linkage_t
*dnl
= dn
->get_linkage();
10530 if (dnl
->is_primary()) {
10531 CInode
*in
= dnl
->get_inode();
10532 dn
->dir
->unlink_inode(dn
);
10534 straydn
->dir
->link_primary_inode(straydn
, in
);
10536 // in->first is lazily updated on replica; drag it forward so
10537 // that we always keep it in sync with the dnq
10538 assert(straydn
->first
>= in
->first
);
10539 in
->first
= straydn
->first
;
10541 // update subtree map?
10543 adjust_subtree_after_rename(in
, dir
, false);
10545 // send caps to auth (if we're not already)
10546 if (in
->is_any_caps() &&
10547 !in
->state_test(CInode::STATE_EXPORTINGCAPS
))
10548 migrator
->export_caps(in
);
10553 assert(dnl
->is_remote());
10554 dn
->dir
->unlink_inode(dn
);
10556 assert(dnl
->is_null());
10560 // race with trim_dentry()
10562 assert(straydn
->get_num_ref() == 0);
10563 assert(straydn
->get_linkage()->is_null());
10564 map
<mds_rank_t
, MCacheExpire
*> expiremap
;
10565 trim_dentry(straydn
, expiremap
);
10566 send_expire_messages(expiremap
);
10578 // ===================================================================
10582 // ===================================================================
10587 * adjust_dir_fragments -- adjust fragmentation for a directory
10589 * @param diri directory inode
10590 * @param basefrag base fragment
10591 * @param bits bit adjustment. positive for split, negative for merge.
10593 void MDCache::adjust_dir_fragments(CInode
*diri
, frag_t basefrag
, int bits
,
10594 list
<CDir
*>& resultfrags
,
10595 list
<MDSInternalContextBase
*>& waiters
,
10598 dout(10) << "adjust_dir_fragments " << basefrag
<< " " << bits
10599 << " on " << *diri
<< dendl
;
10601 list
<CDir
*> srcfrags
;
10602 diri
->get_dirfrags_under(basefrag
, srcfrags
);
10604 adjust_dir_fragments(diri
, srcfrags
, basefrag
, bits
, resultfrags
, waiters
, replay
);
10607 CDir
*MDCache::force_dir_fragment(CInode
*diri
, frag_t fg
, bool replay
)
10609 CDir
*dir
= diri
->get_dirfrag(fg
);
10613 dout(10) << "force_dir_fragment " << fg
<< " on " << *diri
<< dendl
;
10615 list
<CDir
*> src
, result
;
10616 list
<MDSInternalContextBase
*> waiters
;
10619 frag_t parent
= diri
->dirfragtree
.get_branch_or_leaf(fg
);
10621 CDir
*pdir
= diri
->get_dirfrag(parent
);
10623 int split
= fg
.bits() - parent
.bits();
10624 dout(10) << " splitting parent by " << split
<< " " << *pdir
<< dendl
;
10625 src
.push_back(pdir
);
10626 adjust_dir_fragments(diri
, src
, parent
, split
, result
, waiters
, replay
);
10627 dir
= diri
->get_dirfrag(fg
);
10629 dout(10) << "force_dir_fragment result " << *dir
<< dendl
;
10633 if (parent
== frag_t())
10635 frag_t last
= parent
;
10636 parent
= parent
.parent();
10637 dout(10) << " " << last
<< " parent is " << parent
<< dendl
;
10641 // hoover up things under fg?
10642 diri
->get_dirfrags_under(fg
, src
);
10644 dout(10) << "force_dir_fragment no frags under " << fg
<< dendl
;
10646 dout(10) << " will combine frags under " << fg
<< ": " << src
<< dendl
;
10647 adjust_dir_fragments(diri
, src
, fg
, 0, result
, waiters
, replay
);
10648 dir
= result
.front();
10649 dout(10) << "force_dir_fragment result " << *dir
<< dendl
;
10653 mds
->queue_waiters(waiters
);
10657 void MDCache::adjust_dir_fragments(CInode
*diri
,
10658 list
<CDir
*>& srcfrags
,
10659 frag_t basefrag
, int bits
,
10660 list
<CDir
*>& resultfrags
,
10661 list
<MDSInternalContextBase
*>& waiters
,
10664 dout(10) << "adjust_dir_fragments " << basefrag
<< " bits " << bits
10665 << " srcfrags " << srcfrags
10666 << " on " << *diri
<< dendl
;
10669 // yuck. we may have discovered the inode while it was being fragmented.
10670 if (!diri
->dirfragtree
.is_leaf(basefrag
))
10671 diri
->dirfragtree
.force_to_leaf(g_ceph_context
, basefrag
);
10674 diri
->dirfragtree
.split(basefrag
, bits
);
10675 dout(10) << " new fragtree is " << diri
->dirfragtree
<< dendl
;
10677 if (srcfrags
.empty())
10681 CDir
*parent_dir
= diri
->get_parent_dir();
10682 CDir
*parent_subtree
= 0;
10684 parent_subtree
= get_subtree_root(parent_dir
);
10688 assert(srcfrags
.size() == 1);
10689 CDir
*dir
= srcfrags
.front();
10691 dir
->split(bits
, resultfrags
, waiters
, replay
);
10693 // did i change the subtree map?
10694 if (dir
->is_subtree_root()) {
10695 // new frags are now separate subtrees
10696 for (list
<CDir
*>::iterator p
= resultfrags
.begin();
10697 p
!= resultfrags
.end();
10699 subtrees
[*p
].clear(); // new frag is now its own subtree
10702 if (parent_subtree
) {
10703 assert(subtrees
[parent_subtree
].count(dir
));
10704 subtrees
[parent_subtree
].erase(dir
);
10705 for (list
<CDir
*>::iterator p
= resultfrags
.begin();
10706 p
!= resultfrags
.end();
10708 assert((*p
)->is_subtree_root());
10709 subtrees
[parent_subtree
].insert(*p
);
10713 // adjust my bounds.
10715 bounds
.swap(subtrees
[dir
]);
10716 subtrees
.erase(dir
);
10717 for (set
<CDir
*>::iterator p
= bounds
.begin();
10720 CDir
*frag
= get_subtree_root((*p
)->get_parent_dir());
10721 subtrees
[frag
].insert(*p
);
10726 // dir has no PIN_SUBTREE; CDir::purge_stolen() drops it.
10727 dir
->dir_auth
= CDIR_AUTH_DEFAULT
;
10730 diri
->close_dirfrag(dir
->get_frag());
10735 // are my constituent bits subtrees? if so, i will be too.
10736 // (it's all or none, actually.)
10737 bool any_subtree
= false;
10738 for (CDir
*dir
: srcfrags
) {
10739 if (dir
->is_subtree_root()) {
10740 any_subtree
= true;
10744 set
<CDir
*> new_bounds
;
10746 for (CDir
*dir
: srcfrags
) {
10747 // this simplifies the code that find subtrees underneath the dirfrag
10748 if (!dir
->is_subtree_root()) {
10749 dir
->state_set(CDir::STATE_AUXSUBTREE
);
10750 adjust_subtree_auth(dir
, mds
->get_nodeid());
10754 for (CDir
*dir
: srcfrags
) {
10755 assert(dir
->is_subtree_root());
10756 dout(10) << " taking srcfrag subtree bounds from " << *dir
<< dendl
;
10757 map
<CDir
*, set
<CDir
*> >::iterator q
= subtrees
.find(dir
);
10758 set
<CDir
*>::iterator r
= q
->second
.begin();
10759 while (r
!= subtrees
[dir
].end()) {
10760 new_bounds
.insert(*r
);
10761 subtrees
[dir
].erase(r
++);
10765 // remove myself as my parent's bound
10766 if (parent_subtree
)
10767 subtrees
[parent_subtree
].erase(dir
);
10772 CDir
*f
= new CDir(diri
, basefrag
, this, srcfrags
.front()->is_auth());
10773 f
->merge(srcfrags
, waiters
, replay
);
10776 assert(f
->is_subtree_root());
10777 subtrees
[f
].swap(new_bounds
);
10778 if (parent_subtree
)
10779 subtrees
[parent_subtree
].insert(f
);
10784 resultfrags
.push_back(f
);
10789 class C_MDC_FragmentFrozen
: public MDSInternalContext
{
10793 C_MDC_FragmentFrozen(MDCache
*m
, MDRequestRef
& r
) :
10794 MDSInternalContext(m
->mds
), mdcache(m
), mdr(r
) {}
10795 void finish(int r
) override
{
10796 mdcache
->fragment_frozen(mdr
, r
);
10800 bool MDCache::can_fragment(CInode
*diri
, list
<CDir
*>& dirs
)
10802 if (is_readonly()) {
10803 dout(7) << "can_fragment: read-only FS, no fragmenting for now" << dendl
;
10806 if (mds
->is_cluster_degraded()) {
10807 dout(7) << "can_fragment: cluster degraded, no fragmenting for now" << dendl
;
10810 if (diri
->get_parent_dir() &&
10811 diri
->get_parent_dir()->get_inode()->is_stray()) {
10812 dout(7) << "can_fragment: i won't merge|split anything in stray" << dendl
;
10815 if (diri
->is_mdsdir() || diri
->is_stray() || diri
->ino() == MDS_INO_CEPH
) {
10816 dout(7) << "can_fragment: i won't fragment the mdsdir or straydir or .ceph" << dendl
;
10820 if (diri
->scrub_is_in_progress()) {
10821 dout(7) << "can_fragment: scrub in progress" << dendl
;
10825 for (list
<CDir
*>::iterator p
= dirs
.begin(); p
!= dirs
.end(); ++p
) {
10827 if (dir
->state_test(CDir::STATE_FRAGMENTING
)) {
10828 dout(7) << "can_fragment: already fragmenting " << *dir
<< dendl
;
10831 if (!dir
->is_auth()) {
10832 dout(7) << "can_fragment: not auth on " << *dir
<< dendl
;
10835 if (dir
->is_bad()) {
10836 dout(7) << "can_fragment: bad dirfrag " << *dir
<< dendl
;
10839 if (dir
->is_frozen() ||
10840 dir
->is_freezing()) {
10841 dout(7) << "can_fragment: can't merge, freezing|frozen. wait for other exports to finish first." << dendl
;
10849 void MDCache::split_dir(CDir
*dir
, int bits
)
10851 dout(7) << __func__
<< " " << *dir
<< " bits " << bits
<< dendl
;
10852 assert(dir
->is_auth());
10853 CInode
*diri
= dir
->inode
;
10856 dirs
.push_back(dir
);
10858 if (!can_fragment(diri
, dirs
)) {
10859 dout(7) << __func__
<< " cannot fragment right now, dropping" << dendl
;
10863 if (dir
->frag
.bits() + bits
> 24) {
10864 dout(7) << __func__
<< " frag bits > 24, dropping" << dendl
;
10868 MDRequestRef mdr
= request_start_internal(CEPH_MDS_OP_FRAGMENTDIR
);
10869 mdr
->more()->fragment_base
= dir
->dirfrag();
10871 assert(fragments
.count(dir
->dirfrag()) == 0);
10872 fragment_info_t
& info
= fragments
[dir
->dirfrag()];
10874 info
.dirs
.push_back(dir
);
10876 info
.last_cum_auth_pins_change
= ceph_clock_now();
10878 fragment_freeze_dirs(dirs
);
10879 // initial mark+complete pass
10880 fragment_mark_and_complete(mdr
);
10883 void MDCache::merge_dir(CInode
*diri
, frag_t frag
)
10885 dout(7) << "merge_dir to " << frag
<< " on " << *diri
<< dendl
;
10888 if (!diri
->get_dirfrags_under(frag
, dirs
)) {
10889 dout(7) << "don't have all frags under " << frag
<< " for " << *diri
<< dendl
;
10893 if (diri
->dirfragtree
.is_leaf(frag
)) {
10894 dout(10) << " " << frag
<< " already a leaf for " << *diri
<< dendl
;
10898 if (!can_fragment(diri
, dirs
))
10901 CDir
*first
= dirs
.front();
10902 int bits
= first
->get_frag().bits() - frag
.bits();
10903 dout(10) << " we are merginb by " << bits
<< " bits" << dendl
;
10905 dirfrag_t
basedirfrag(diri
->ino(), frag
);
10906 MDRequestRef mdr
= request_start_internal(CEPH_MDS_OP_FRAGMENTDIR
);
10907 mdr
->more()->fragment_base
= basedirfrag
;
10909 assert(fragments
.count(basedirfrag
) == 0);
10910 fragment_info_t
& info
= fragments
[basedirfrag
];
10914 info
.last_cum_auth_pins_change
= ceph_clock_now();
10916 fragment_freeze_dirs(dirs
);
10917 // initial mark+complete pass
10918 fragment_mark_and_complete(mdr
);
10921 void MDCache::fragment_freeze_dirs(list
<CDir
*>& dirs
)
10923 for (list
<CDir
*>::iterator p
= dirs
.begin(); p
!= dirs
.end(); ++p
) {
10925 dir
->auth_pin(dir
); // until we mark and complete them
10926 dir
->state_set(CDir::STATE_FRAGMENTING
);
10928 assert(dir
->is_freezing_dir());
10932 class C_MDC_FragmentMarking
: public MDCacheContext
{
10935 C_MDC_FragmentMarking(MDCache
*m
, MDRequestRef
& r
) : MDCacheContext(m
), mdr(r
) {}
10936 void finish(int r
) override
{
10937 mdcache
->fragment_mark_and_complete(mdr
);
10941 void MDCache::fragment_mark_and_complete(MDRequestRef
& mdr
)
10943 dirfrag_t basedirfrag
= mdr
->more()->fragment_base
;
10944 map
<dirfrag_t
,fragment_info_t
>::iterator it
= fragments
.find(basedirfrag
);
10945 if (it
== fragments
.end() || it
->second
.mdr
!= mdr
) {
10946 dout(7) << "fragment_mark_and_complete " << basedirfrag
<< " must have aborted" << dendl
;
10947 request_finish(mdr
);
10951 fragment_info_t
& info
= it
->second
;
10952 CInode
*diri
= info
.dirs
.front()->get_inode();
10953 dout(10) << "fragment_mark_and_complete " << info
.dirs
<< " on " << *diri
<< dendl
;
10955 MDSGatherBuilder
gather(g_ceph_context
);
10957 for (list
<CDir
*>::iterator p
= info
.dirs
.begin();
10958 p
!= info
.dirs
.end();
10963 if (!dir
->is_complete()) {
10964 dout(15) << " fetching incomplete " << *dir
<< dendl
;
10965 dir
->fetch(gather
.new_sub(), true); // ignore authpinnability
10967 } else if (dir
->get_frag() == frag_t()) {
10968 // The COMPLETE flag gets lost if we fragment a new dirfrag, then rollback
10969 // the operation. To avoid CDir::fetch() complaining about missing object,
10970 // we commit new dirfrag first.
10971 if (dir
->state_test(CDir::STATE_CREATING
)) {
10972 dout(15) << " waiting until new dir gets journaled " << *dir
<< dendl
;
10973 dir
->add_waiter(CDir::WAIT_CREATED
, gather
.new_sub());
10975 } else if (dir
->is_new()) {
10976 dout(15) << " committing new " << *dir
<< dendl
;
10977 assert(dir
->is_dirty());
10978 dir
->commit(0, gather
.new_sub(), true);
10985 if (!dir
->state_test(CDir::STATE_DNPINNEDFRAG
)) {
10986 dout(15) << " marking " << *dir
<< dendl
;
10987 for (CDir::map_t::iterator p
= dir
->items
.begin();
10988 p
!= dir
->items
.end();
10990 CDentry
*dn
= p
->second
;
10991 dn
->get(CDentry::PIN_FRAGMENTING
);
10992 assert(!dn
->state_test(CDentry::STATE_FRAGMENTING
));
10993 dn
->state_set(CDentry::STATE_FRAGMENTING
);
10995 dir
->state_set(CDir::STATE_DNPINNEDFRAG
);
10996 dir
->auth_unpin(dir
);
10998 dout(15) << " already marked " << *dir
<< dendl
;
11001 if (gather
.has_subs()) {
11002 gather
.set_finisher(new C_MDC_FragmentMarking(this, mdr
));
11007 for (list
<CDir
*>::iterator p
= info
.dirs
.begin();
11008 p
!= info
.dirs
.end();
11011 if (!dir
->is_frozen_dir()) {
11012 assert(dir
->is_freezing_dir());
11013 dir
->add_waiter(CDir::WAIT_FROZEN
, gather
.new_sub());
11016 if (gather
.has_subs()) {
11017 gather
.set_finisher(new C_MDC_FragmentFrozen(this, mdr
));
11019 // flush log so that request auth_pins are retired
11020 mds
->mdlog
->flush();
11024 fragment_frozen(mdr
, 0);
11027 void MDCache::fragment_unmark_unfreeze_dirs(list
<CDir
*>& dirs
)
11029 dout(10) << "fragment_unmark_unfreeze_dirs " << dirs
<< dendl
;
11030 for (list
<CDir
*>::iterator p
= dirs
.begin(); p
!= dirs
.end(); ++p
) {
11032 dout(10) << " frag " << *dir
<< dendl
;
11034 assert(dir
->state_test(CDir::STATE_FRAGMENTING
));
11035 dir
->state_clear(CDir::STATE_FRAGMENTING
);
11037 if (dir
->state_test(CDir::STATE_DNPINNEDFRAG
)) {
11038 dir
->state_clear(CDir::STATE_DNPINNEDFRAG
);
11040 for (CDir::map_t::iterator p
= dir
->items
.begin();
11041 p
!= dir
->items
.end();
11043 CDentry
*dn
= p
->second
;
11044 assert(dn
->state_test(CDentry::STATE_FRAGMENTING
));
11045 dn
->state_clear(CDentry::STATE_FRAGMENTING
);
11046 dn
->put(CDentry::PIN_FRAGMENTING
);
11049 dir
->auth_unpin(dir
);
11052 dir
->unfreeze_dir();
11056 bool MDCache::fragment_are_all_frozen(CDir
*dir
)
11058 assert(dir
->is_frozen_dir());
11059 map
<dirfrag_t
,fragment_info_t
>::iterator p
;
11060 for (p
= fragments
.lower_bound(dirfrag_t(dir
->ino(), 0));
11061 p
!= fragments
.end() && p
->first
.ino
== dir
->ino();
11063 if (p
->first
.frag
.contains(dir
->get_frag()))
11064 return p
->second
.all_frozen
;
11070 void MDCache::fragment_freeze_inc_num_waiters(CDir
*dir
)
11072 map
<dirfrag_t
,fragment_info_t
>::iterator p
;
11073 for (p
= fragments
.lower_bound(dirfrag_t(dir
->ino(), 0));
11074 p
!= fragments
.end() && p
->first
.ino
== dir
->ino();
11076 if (p
->first
.frag
.contains(dir
->get_frag())) {
11077 p
->second
.num_remote_waiters
++;
11084 void MDCache::find_stale_fragment_freeze()
11086 dout(10) << "find_stale_fragment_freeze" << dendl
;
11087 // see comment in Migrator::find_stale_export_freeze()
11088 utime_t now
= ceph_clock_now();
11089 utime_t cutoff
= now
;
11090 cutoff
-= g_conf
->mds_freeze_tree_timeout
;
11092 for (map
<dirfrag_t
,fragment_info_t
>::iterator p
= fragments
.begin();
11093 p
!= fragments
.end(); ) {
11094 dirfrag_t df
= p
->first
;
11095 fragment_info_t
& info
= p
->second
;
11097 if (info
.all_frozen
)
11100 int total_auth_pins
= 0;
11101 for (list
<CDir
*>::iterator q
= info
.dirs
.begin();
11102 q
!= info
.dirs
.end();
11105 if (!dir
->state_test(CDir::STATE_DNPINNEDFRAG
)) {
11106 total_auth_pins
= -1;
11109 if (dir
->is_frozen_dir())
11111 total_auth_pins
+= dir
->get_auth_pins() + dir
->get_dir_auth_pins();
11113 if (total_auth_pins
< 0)
11115 if (info
.last_cum_auth_pins
!= total_auth_pins
) {
11116 info
.last_cum_auth_pins
= total_auth_pins
;
11117 info
.last_cum_auth_pins_change
= now
;
11120 if (info
.last_cum_auth_pins_change
>= cutoff
)
11122 dir
= info
.dirs
.front();
11123 if (info
.num_remote_waiters
> 0 ||
11124 (!dir
->inode
->is_root() && dir
->get_parent_dir()->is_freezing())) {
11125 dout(10) << " cancel fragmenting " << df
<< " bit " << info
.bits
<< dendl
;
11127 info
.dirs
.swap(dirs
);
11128 fragments
.erase(df
);
11129 fragment_unmark_unfreeze_dirs(dirs
);
11134 class C_MDC_FragmentPrep
: public MDCacheLogContext
{
11137 C_MDC_FragmentPrep(MDCache
*m
, MDRequestRef
& r
) : MDCacheLogContext(m
), mdr(r
) {}
11138 void finish(int r
) override
{
11139 mdcache
->_fragment_logged(mdr
);
11143 class C_MDC_FragmentStore
: public MDCacheContext
{
11146 C_MDC_FragmentStore(MDCache
*m
, MDRequestRef
& r
) : MDCacheContext(m
), mdr(r
) {}
11147 void finish(int r
) override
{
11148 mdcache
->_fragment_stored(mdr
);
11152 class C_MDC_FragmentCommit
: public MDCacheLogContext
{
11153 dirfrag_t basedirfrag
;
11154 list
<CDir
*> resultfrags
;
11156 C_MDC_FragmentCommit(MDCache
*m
, dirfrag_t df
, list
<CDir
*>& l
) :
11157 MDCacheLogContext(m
), basedirfrag(df
), resultfrags(l
) {}
11158 void finish(int r
) override
{
11159 mdcache
->_fragment_committed(basedirfrag
, resultfrags
);
11163 class C_IO_MDC_FragmentFinish
: public MDCacheIOContext
{
11164 dirfrag_t basedirfrag
;
11165 list
<CDir
*> resultfrags
;
11167 C_IO_MDC_FragmentFinish(MDCache
*m
, dirfrag_t f
, list
<CDir
*>& l
) :
11168 MDCacheIOContext(m
), basedirfrag(f
) {
11169 resultfrags
.swap(l
);
11171 void finish(int r
) override
{
11172 assert(r
== 0 || r
== -ENOENT
);
11173 mdcache
->_fragment_finish(basedirfrag
, resultfrags
);
11177 void MDCache::fragment_frozen(MDRequestRef
& mdr
, int r
)
11179 dirfrag_t basedirfrag
= mdr
->more()->fragment_base
;
11180 map
<dirfrag_t
,fragment_info_t
>::iterator it
= fragments
.find(basedirfrag
);
11181 if (it
== fragments
.end() || it
->second
.mdr
!= mdr
) {
11182 dout(7) << "fragment_frozen " << basedirfrag
<< " must have aborted" << dendl
;
11183 request_finish(mdr
);
11188 fragment_info_t
& info
= it
->second
;
11189 dout(10) << "fragment_frozen " << basedirfrag
.frag
<< " by " << info
.bits
11190 << " on " << info
.dirs
.front()->get_inode() << dendl
;
11192 info
.all_frozen
= true;
11193 dispatch_fragment_dir(mdr
);
11196 void MDCache::dispatch_fragment_dir(MDRequestRef
& mdr
)
11198 dirfrag_t basedirfrag
= mdr
->more()->fragment_base
;
11199 map
<dirfrag_t
,fragment_info_t
>::iterator it
= fragments
.find(basedirfrag
);
11200 if (it
== fragments
.end() || it
->second
.mdr
!= mdr
) {
11201 dout(7) << "dispatch_fragment_dir " << basedirfrag
<< " must have aborted" << dendl
;
11202 request_finish(mdr
);
11206 fragment_info_t
& info
= it
->second
;
11207 CInode
*diri
= info
.dirs
.front()->get_inode();
11209 dout(10) << "dispatch_fragment_dir " << basedirfrag
<< " bits " << info
.bits
11210 << " on " << *diri
<< dendl
;
11211 if (!mdr
->aborted
) {
11212 set
<SimpleLock
*> rdlocks
, wrlocks
, xlocks
;
11213 wrlocks
.insert(&diri
->dirfragtreelock
);
11214 // prevent a racing gather on any other scatterlocks too
11215 wrlocks
.insert(&diri
->nestlock
);
11216 wrlocks
.insert(&diri
->filelock
);
11217 if (!mds
->locker
->acquire_locks(mdr
, rdlocks
, wrlocks
, xlocks
, NULL
, NULL
, true))
11222 if (mdr
->aborted
) {
11223 dout(10) << " can't auth_pin " << *diri
<< ", requeuing dir "
11224 << info
.dirs
.front()->dirfrag() << dendl
;
11226 mds
->balancer
->queue_split(info
.dirs
.front(), false);
11228 mds
->balancer
->queue_merge(info
.dirs
.front());
11229 fragment_unmark_unfreeze_dirs(info
.dirs
);
11230 fragments
.erase(it
);
11231 request_finish(mdr
);
11235 mdr
->ls
= mds
->mdlog
->get_current_segment();
11236 EFragment
*le
= new EFragment(mds
->mdlog
, EFragment::OP_PREPARE
, basedirfrag
, info
.bits
);
11237 mds
->mdlog
->start_entry(le
);
11239 for (list
<CDir
*>::iterator p
= info
.dirs
.begin(); p
!= info
.dirs
.end(); ++p
) {
11241 dirfrag_rollback rollback
;
11242 rollback
.fnode
= dir
->fnode
;
11243 le
->add_orig_frag(dir
->get_frag(), &rollback
);
11247 list
<MDSInternalContextBase
*> waiters
;
11248 adjust_dir_fragments(diri
, info
.dirs
, basedirfrag
.frag
, info
.bits
,
11249 info
.resultfrags
, waiters
, false);
11250 if (g_conf
->mds_debug_frag
)
11251 diri
->verify_dirfrags();
11252 mds
->queue_waiters(waiters
);
11254 for (list
<frag_t
>::iterator p
= le
->orig_frags
.begin(); p
!= le
->orig_frags
.end(); ++p
)
11255 assert(!diri
->dirfragtree
.is_leaf(*p
));
11257 le
->metablob
.add_dir_context(*info
.resultfrags
.begin());
11258 for (list
<CDir
*>::iterator p
= info
.resultfrags
.begin();
11259 p
!= info
.resultfrags
.end();
11261 if (diri
->is_auth()) {
11262 le
->metablob
.add_fragmented_dir(*p
, false, false);
11264 (*p
)->state_set(CDir::STATE_DIRTYDFT
);
11265 le
->metablob
.add_fragmented_dir(*p
, false, true);
11270 if (diri
->is_auth()) {
11271 // journal dirfragtree
11272 inode_t
*pi
= diri
->project_inode();
11273 pi
->version
= diri
->pre_dirty();
11274 journal_dirty_inode(mdr
.get(), &le
->metablob
, diri
);
11276 mds
->locker
->mark_updated_scatterlock(&diri
->dirfragtreelock
);
11277 mdr
->ls
->dirty_dirfrag_dirfragtree
.push_back(&diri
->item_dirty_dirfrag_dirfragtree
);
11278 mdr
->add_updated_lock(&diri
->dirfragtreelock
);
11283 mds->locker->mark_updated_scatterlock(&diri->filelock);
11284 mut->ls->dirty_dirfrag_dir.push_back(&diri->item_dirty_dirfrag_dir);
11285 mut->add_updated_lock(&diri->filelock);
11288 mds->locker->mark_updated_scatterlock(&diri->nestlock);
11289 mut->ls->dirty_dirfrag_nest.push_back(&diri->item_dirty_dirfrag_nest);
11290 mut->add_updated_lock(&diri->nestlock);
11293 add_uncommitted_fragment(basedirfrag
, info
.bits
, le
->orig_frags
, mdr
->ls
);
11294 mds
->server
->submit_mdlog_entry(le
, new C_MDC_FragmentPrep(this, mdr
),
11296 mds
->mdlog
->flush();
11299 void MDCache::_fragment_logged(MDRequestRef
& mdr
)
11301 dirfrag_t basedirfrag
= mdr
->more()->fragment_base
;
11302 map
<dirfrag_t
,fragment_info_t
>::iterator it
= fragments
.find(basedirfrag
);
11303 assert(it
!= fragments
.end());
11304 fragment_info_t
&info
= it
->second
;
11305 CInode
*diri
= info
.resultfrags
.front()->get_inode();
11307 dout(10) << "fragment_logged " << basedirfrag
<< " bits " << info
.bits
11308 << " on " << *diri
<< dendl
;
11310 if (diri
->is_auth())
11311 diri
->pop_and_dirty_projected_inode(mdr
->ls
);
11313 mdr
->apply(); // mark scatterlock
11315 // store resulting frags
11316 MDSGatherBuilder
gather(g_ceph_context
, new C_MDC_FragmentStore(this, mdr
));
11318 for (list
<CDir
*>::iterator p
= info
.resultfrags
.begin();
11319 p
!= info
.resultfrags
.end();
11322 dout(10) << " storing result frag " << *dir
<< dendl
;
11324 // freeze and store them too
11325 dir
->auth_pin(this);
11326 dir
->state_set(CDir::STATE_FRAGMENTING
);
11327 dir
->commit(0, gather
.new_sub(), true); // ignore authpinnability
11333 void MDCache::_fragment_stored(MDRequestRef
& mdr
)
11335 dirfrag_t basedirfrag
= mdr
->more()->fragment_base
;
11336 map
<dirfrag_t
,fragment_info_t
>::iterator it
= fragments
.find(basedirfrag
);
11337 assert(it
!= fragments
.end());
11338 fragment_info_t
&info
= it
->second
;
11339 CInode
*diri
= info
.resultfrags
.front()->get_inode();
11341 dout(10) << "fragment_stored " << basedirfrag
<< " bits " << info
.bits
11342 << " on " << *diri
<< dendl
;
11345 CDir
*first
= *info
.resultfrags
.begin();
11346 for (const auto &p
: first
->get_replicas()) {
11347 if (mds
->mdsmap
->get_state(p
.first
) < MDSMap::STATE_REJOIN
||
11348 (mds
->mdsmap
->get_state(p
.first
) == MDSMap::STATE_REJOIN
&&
11349 rejoin_gather
.count(p
.first
)))
11352 MMDSFragmentNotify
*notify
= new MMDSFragmentNotify(basedirfrag
, info
.bits
);
11354 // freshly replicate new dirs to peers
11355 for (list
<CDir
*>::iterator q
= info
.resultfrags
.begin();
11356 q
!= info
.resultfrags
.end();
11358 replicate_dir(*q
, p
.first
, notify
->basebl
);
11360 mds
->send_message_mds(notify
, p
.first
);
11364 EFragment
*le
= new EFragment(mds
->mdlog
, EFragment::OP_COMMIT
, basedirfrag
, info
.bits
);
11365 mds
->mdlog
->start_submit_entry(le
, new C_MDC_FragmentCommit(this, basedirfrag
,
11366 info
.resultfrags
));
11368 mds
->locker
->drop_locks(mdr
.get());
11370 // unfreeze resulting frags
11371 for (list
<CDir
*>::iterator p
= info
.resultfrags
.begin();
11372 p
!= info
.resultfrags
.end();
11375 dout(10) << " result frag " << *dir
<< dendl
;
11377 for (CDir::map_t::iterator p
= dir
->items
.begin();
11378 p
!= dir
->items
.end();
11380 CDentry
*dn
= p
->second
;
11381 assert(dn
->state_test(CDentry::STATE_FRAGMENTING
));
11382 dn
->state_clear(CDentry::STATE_FRAGMENTING
);
11383 dn
->put(CDentry::PIN_FRAGMENTING
);
11387 dir
->unfreeze_dir();
11390 fragments
.erase(it
);
11391 request_finish(mdr
);
11394 void MDCache::_fragment_committed(dirfrag_t basedirfrag
, list
<CDir
*>& resultfrags
)
11396 dout(10) << "fragment_committed " << basedirfrag
<< dendl
;
11397 map
<dirfrag_t
, ufragment
>::iterator it
= uncommitted_fragments
.find(basedirfrag
);
11398 assert(it
!= uncommitted_fragments
.end());
11399 ufragment
&uf
= it
->second
;
11401 // remove old frags
11402 C_GatherBuilder
gather(
11405 new C_IO_MDC_FragmentFinish(this, basedirfrag
, resultfrags
),
11408 SnapContext nullsnapc
;
11409 object_locator_t
oloc(mds
->mdsmap
->get_metadata_pool());
11410 for (list
<frag_t
>::iterator p
= uf
.old_frags
.begin();
11411 p
!= uf
.old_frags
.end();
11413 object_t oid
= CInode::get_object_name(basedirfrag
.ino
, *p
, "");
11414 ObjectOperation op
;
11415 if (*p
== frag_t()) {
11416 // backtrace object
11417 dout(10) << " truncate orphan dirfrag " << oid
<< dendl
;
11421 dout(10) << " removing orphan dirfrag " << oid
<< dendl
;
11424 mds
->objecter
->mutate(oid
, oloc
, op
, nullsnapc
,
11425 ceph::real_clock::now(),
11426 0, gather
.new_sub());
11429 assert(gather
.has_subs());
11433 void MDCache::_fragment_finish(dirfrag_t basedirfrag
, list
<CDir
*>& resultfrags
)
11435 dout(10) << "fragment_finish " << basedirfrag
<< "resultfrags.size="
11436 << resultfrags
.size() << dendl
;
11437 map
<dirfrag_t
, ufragment
>::iterator it
= uncommitted_fragments
.find(basedirfrag
);
11438 assert(it
!= uncommitted_fragments
.end());
11439 ufragment
&uf
= it
->second
;
11441 // unmark & auth_unpin
11442 for (const auto &dir
: resultfrags
) {
11443 dir
->state_clear(CDir::STATE_FRAGMENTING
);
11444 dir
->auth_unpin(this);
11446 // In case the resulting fragments are beyond the split size,
11447 // we might need to split them again right away (they could
11448 // have been taking inserts between unfreezing and getting
11450 mds
->balancer
->maybe_fragment(dir
, false);
11454 if (resultfrags
.size() > 1) {
11455 mds
->logger
->inc(l_mds_dir_split
);
11457 mds
->logger
->inc(l_mds_dir_merge
);
11461 EFragment
*le
= new EFragment(mds
->mdlog
, EFragment::OP_FINISH
, basedirfrag
, uf
.bits
);
11462 mds
->mdlog
->start_submit_entry(le
);
11464 finish_uncommitted_fragment(basedirfrag
, EFragment::OP_FINISH
);
11467 /* This function DOES put the passed message before returning */
11468 void MDCache::handle_fragment_notify(MMDSFragmentNotify
*notify
)
11470 dout(10) << "handle_fragment_notify " << *notify
<< " from " << notify
->get_source() << dendl
;
11472 if (mds
->get_state() < MDSMap::STATE_REJOIN
) {
11477 CInode
*diri
= get_inode(notify
->get_ino());
11479 frag_t base
= notify
->get_basefrag();
11480 int bits
= notify
->get_bits();
11483 if ((bits < 0 && diri->dirfragtree.is_leaf(base)) ||
11484 (bits > 0 && !diri->dirfragtree.is_leaf(base))) {
11485 dout(10) << " dft " << diri->dirfragtree << " state doesn't match " << base << " by " << bits
11486 << ", must have found out during resolve/rejoin? ignoring. " << *diri << dendl;
11493 list
<MDSInternalContextBase
*> waiters
;
11494 list
<CDir
*> resultfrags
;
11495 adjust_dir_fragments(diri
, base
, bits
, resultfrags
, waiters
, false);
11496 if (g_conf
->mds_debug_frag
)
11497 diri
->verify_dirfrags();
11499 for (list
<CDir
*>::iterator p
= resultfrags
.begin(); p
!= resultfrags
.end(); ++p
)
11500 diri
->take_dir_waiting((*p
)->get_frag(), waiters
);
11502 // add new replica dirs values
11503 bufferlist::iterator p
= notify
->basebl
.begin();
11505 add_replica_dir(p
, diri
, mds_rank_t(notify
->get_source().num()), waiters
);
11507 mds
->queue_waiters(waiters
);
11515 void MDCache::add_uncommitted_fragment(dirfrag_t basedirfrag
, int bits
, list
<frag_t
>& old_frags
,
11516 LogSegment
*ls
, bufferlist
*rollback
)
11518 dout(10) << "add_uncommitted_fragment: base dirfrag " << basedirfrag
<< " bits " << bits
<< dendl
;
11519 assert(!uncommitted_fragments
.count(basedirfrag
));
11520 ufragment
& uf
= uncommitted_fragments
[basedirfrag
];
11521 uf
.old_frags
= old_frags
;
11524 ls
->uncommitted_fragments
.insert(basedirfrag
);
11526 uf
.rollback
.swap(*rollback
);
11529 void MDCache::finish_uncommitted_fragment(dirfrag_t basedirfrag
, int op
)
11531 dout(10) << "finish_uncommitted_fragments: base dirfrag " << basedirfrag
11532 << " op " << EFragment::op_name(op
) << dendl
;
11533 map
<dirfrag_t
, ufragment
>::iterator it
= uncommitted_fragments
.find(basedirfrag
);
11534 if (it
!= uncommitted_fragments
.end()) {
11535 ufragment
& uf
= it
->second
;
11536 if (op
!= EFragment::OP_FINISH
&& !uf
.old_frags
.empty()) {
11537 uf
.committed
= true;
11539 uf
.ls
->uncommitted_fragments
.erase(basedirfrag
);
11540 mds
->queue_waiters(uf
.waiters
);
11541 uncommitted_fragments
.erase(it
);
11546 void MDCache::rollback_uncommitted_fragment(dirfrag_t basedirfrag
, list
<frag_t
>& old_frags
)
11548 dout(10) << "rollback_uncommitted_fragment: base dirfrag " << basedirfrag
11549 << " old_frags (" << old_frags
<< ")" << dendl
;
11550 map
<dirfrag_t
, ufragment
>::iterator it
= uncommitted_fragments
.find(basedirfrag
);
11551 if (it
!= uncommitted_fragments
.end()) {
11552 ufragment
& uf
= it
->second
;
11553 if (!uf
.old_frags
.empty()) {
11554 uf
.old_frags
.swap(old_frags
);
11555 uf
.committed
= true;
11557 uf
.ls
->uncommitted_fragments
.erase(basedirfrag
);
11558 uncommitted_fragments
.erase(it
);
11563 void MDCache::rollback_uncommitted_fragments()
11565 dout(10) << "rollback_uncommitted_fragments: " << uncommitted_fragments
.size() << " pending" << dendl
;
11566 for (map
<dirfrag_t
, ufragment
>::iterator p
= uncommitted_fragments
.begin();
11567 p
!= uncommitted_fragments
.end();
11569 ufragment
&uf
= p
->second
;
11570 CInode
*diri
= get_inode(p
->first
.ino
);
11573 if (uf
.committed
) {
11575 diri
->get_dirfrags_under(p
->first
.frag
, frags
);
11576 for (list
<CDir
*>::iterator q
= frags
.begin(); q
!= frags
.end(); ++q
) {
11578 dir
->auth_pin(this);
11579 dir
->state_set(CDir::STATE_FRAGMENTING
);
11581 _fragment_committed(p
->first
, frags
);
11585 dout(10) << " rolling back " << p
->first
<< " refragment by " << uf
.bits
<< " bits" << dendl
;
11587 LogSegment
*ls
= mds
->mdlog
->get_current_segment();
11588 EFragment
*le
= new EFragment(mds
->mdlog
, EFragment::OP_ROLLBACK
, p
->first
, uf
.bits
);
11589 mds
->mdlog
->start_entry(le
);
11590 bool diri_auth
= (diri
->authority() != CDIR_AUTH_UNDEF
);
11592 list
<frag_t
> old_frags
;
11593 diri
->dirfragtree
.get_leaves_under(p
->first
.frag
, old_frags
);
11595 list
<CDir
*> resultfrags
;
11596 if (uf
.old_frags
.empty()) {
11597 // created by old format EFragment
11598 list
<MDSInternalContextBase
*> waiters
;
11599 adjust_dir_fragments(diri
, p
->first
.frag
, -uf
.bits
, resultfrags
, waiters
, true);
11601 bufferlist::iterator bp
= uf
.rollback
.begin();
11602 for (list
<frag_t
>::iterator q
= uf
.old_frags
.begin(); q
!= uf
.old_frags
.end(); ++q
) {
11603 CDir
*dir
= force_dir_fragment(diri
, *q
);
11604 resultfrags
.push_back(dir
);
11606 dirfrag_rollback rollback
;
11607 ::decode(rollback
, bp
);
11609 dir
->set_version(rollback
.fnode
.version
);
11610 dir
->fnode
= rollback
.fnode
;
11612 dir
->_mark_dirty(ls
);
11614 if (!(dir
->fnode
.rstat
== dir
->fnode
.accounted_rstat
)) {
11615 dout(10) << " dirty nestinfo on " << *dir
<< dendl
;
11616 mds
->locker
->mark_updated_scatterlock(&dir
->inode
->nestlock
);
11617 ls
->dirty_dirfrag_nest
.push_back(&dir
->inode
->item_dirty_dirfrag_nest
);
11619 if (!(dir
->fnode
.fragstat
== dir
->fnode
.accounted_fragstat
)) {
11620 dout(10) << " dirty fragstat on " << *dir
<< dendl
;
11621 mds
->locker
->mark_updated_scatterlock(&dir
->inode
->filelock
);
11622 ls
->dirty_dirfrag_dir
.push_back(&dir
->inode
->item_dirty_dirfrag_dir
);
11625 le
->add_orig_frag(dir
->get_frag());
11626 le
->metablob
.add_dir_context(dir
);
11628 le
->metablob
.add_fragmented_dir(dir
, true, false);
11630 dout(10) << " dirty dirfragtree on " << *dir
<< dendl
;
11631 dir
->state_set(CDir::STATE_DIRTYDFT
);
11632 le
->metablob
.add_fragmented_dir(dir
, true, true);
11638 diri
->project_inode()->version
= diri
->pre_dirty();
11639 diri
->pop_and_dirty_projected_inode(ls
); // hacky
11640 le
->metablob
.add_primary_dentry(diri
->get_projected_parent_dn(), diri
, true);
11642 mds
->locker
->mark_updated_scatterlock(&diri
->dirfragtreelock
);
11643 ls
->dirty_dirfrag_dirfragtree
.push_back(&diri
->item_dirty_dirfrag_dirfragtree
);
11646 if (g_conf
->mds_debug_frag
)
11647 diri
->verify_dirfrags();
11649 for (list
<frag_t
>::iterator q
= old_frags
.begin(); q
!= old_frags
.end(); ++q
)
11650 assert(!diri
->dirfragtree
.is_leaf(*q
));
11652 for (list
<CDir
*>::iterator q
= resultfrags
.begin(); q
!= resultfrags
.end(); ++q
) {
11654 dir
->auth_pin(this);
11655 dir
->state_set(CDir::STATE_FRAGMENTING
);
11658 mds
->mdlog
->submit_entry(le
);
11660 uf
.old_frags
.swap(old_frags
);
11661 _fragment_committed(p
->first
, resultfrags
);
11665 void MDCache::force_readonly()
11670 dout(1) << "force file system read-only" << dendl
;
11671 mds
->clog
->warn() << "force file system read-only";
11675 mds
->server
->force_clients_readonly();
11677 // revoke write caps
11678 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator p
= inode_map
.begin();
11679 p
!= inode_map
.end();
11681 CInode
*in
= p
->second
;
11683 mds
->locker
->eval(in
, CEPH_CAP_LOCKS
);
11686 mds
->mdlog
->flush();
11690 // ==============================================================
11693 void MDCache::show_subtrees(int dbl
)
11695 if (g_conf
->mds_thrash_exports
)
11698 //dout(10) << "show_subtrees" << dendl;
11700 if (!g_conf
->subsys
.should_gather(ceph_subsys_mds
, dbl
))
11701 return; // i won't print anything.
11703 if (subtrees
.empty()) {
11704 dout(dbl
) << "show_subtrees - no subtrees" << dendl
;
11709 list
<CDir
*> basefrags
;
11710 for (set
<CInode
*>::iterator p
= base_inodes
.begin();
11711 p
!= base_inodes
.end();
11713 (*p
)->get_dirfrags(basefrags
);
11714 //dout(15) << "show_subtrees, base dirfrags " << basefrags << dendl;
11715 dout(15) << "show_subtrees" << dendl
;
11718 list
<pair
<CDir
*,int> > q
;
11723 for (list
<CDir
*>::iterator p
= basefrags
.begin(); p
!= basefrags
.end(); ++p
)
11724 q
.push_back(pair
<CDir
*,int>(*p
, 0));
11726 set
<CDir
*> subtrees_seen
;
11729 while (!q
.empty()) {
11730 CDir
*dir
= q
.front().first
;
11731 int d
= q
.front().second
;
11734 if (subtrees
.count(dir
) == 0) continue;
11736 subtrees_seen
.insert(dir
);
11738 if (d
> depth
) depth
= d
;
11741 //dout(25) << "saw depth " << d << " " << *dir << dendl;
11742 if (seen
.count(dir
)) dout(0) << "aah, already seen " << *dir
<< dendl
;
11743 assert(seen
.count(dir
) == 0);
11747 if (!subtrees
[dir
].empty()) {
11748 for (set
<CDir
*>::iterator p
= subtrees
[dir
].begin();
11749 p
!= subtrees
[dir
].end();
11751 //dout(25) << " saw sub " << **p << dendl;
11752 q
.push_front(pair
<CDir
*,int>(*p
, d
+1));
11759 for (list
<CDir
*>::iterator p
= basefrags
.begin(); p
!= basefrags
.end(); ++p
)
11760 q
.push_back(pair
<CDir
*,int>(*p
, 0));
11762 while (!q
.empty()) {
11763 CDir
*dir
= q
.front().first
;
11764 int d
= q
.front().second
;
11767 if (subtrees
.count(dir
) == 0) continue;
11770 while ((unsigned)d
< indent
.size())
11774 string pad
= "______________________________________";
11775 pad
.resize(depth
*2+1-indent
.size());
11776 if (!subtrees
[dir
].empty())
11777 pad
[0] = '.'; // parent
11781 if (dir
->is_auth())
11787 if (dir
->get_dir_auth().second
== CDIR_AUTH_UNKNOWN
)
11788 snprintf(s
, sizeof(s
), "%2d ", int(dir
->get_dir_auth().first
));
11790 snprintf(s
, sizeof(s
), "%2d,%2d", int(dir
->get_dir_auth().first
), int(dir
->get_dir_auth().second
));
11793 dout(dbl
) << indent
<< "|_" << pad
<< s
<< " " << auth
<< *dir
<< dendl
;
11795 if (dir
->ino() == MDS_INO_ROOT
)
11796 assert(dir
->inode
== root
);
11797 if (dir
->ino() == MDS_INO_MDSDIR(mds
->get_nodeid()))
11798 assert(dir
->inode
== myin
);
11799 if (dir
->inode
->is_stray() && (MDS_INO_STRAY_OWNER(dir
->ino()) == mds
->get_nodeid()))
11800 assert(strays
[MDS_INO_STRAY_INDEX(dir
->ino())] == dir
->inode
);
11803 if (!subtrees
[dir
].empty()) {
11804 // more at my level?
11805 if (!q
.empty() && q
.front().second
== d
)
11810 for (set
<CDir
*>::iterator p
= subtrees
[dir
].begin();
11811 p
!= subtrees
[dir
].end();
11813 q
.push_front(pair
<CDir
*,int>(*p
, d
+2));
11817 // verify there isn't stray crap in subtree map
11819 for (map
<CDir
*, set
<CDir
*> >::iterator p
= subtrees
.begin();
11820 p
!= subtrees
.end();
11822 if (subtrees_seen
.count(p
->first
)) continue;
11823 dout(10) << "*** stray/lost entry in subtree map: " << *p
->first
<< dendl
;
11830 void MDCache::show_cache()
11832 dout(7) << "show_cache" << dendl
;
11834 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator it
= inode_map
.begin();
11835 it
!= inode_map
.end();
11838 if (!it
->second
->parent
)
11839 dout(7) << " unlinked " << *it
->second
<< dendl
;
11843 it
->second
->get_dirfrags(dfs
);
11844 for (list
<CDir
*>::iterator p
= dfs
.begin(); p
!= dfs
.end(); ++p
) {
11846 dout(7) << " dirfrag " << *dir
<< dendl
;
11848 for (CDir::map_t::iterator p
= dir
->items
.begin();
11849 p
!= dir
->items
.end();
11851 CDentry
*dn
= p
->second
;
11852 dout(7) << " dentry " << *dn
<< dendl
;
11853 CDentry::linkage_t
*dnl
= dn
->get_linkage();
11854 if (dnl
->is_primary() && dnl
->get_inode())
11855 dout(7) << " inode " << *dnl
->get_inode() << dendl
;
11861 int MDCache::cache_status(Formatter
*f
)
11863 f
->open_object_section("cache");
11865 f
->open_object_section("pool");
11866 mempool::get_pool(mempool::mds_co::id
).dump(f
);
11867 f
->close_section();
11869 f
->close_section();
11873 int MDCache::dump_cache(std::string
const &file_name
)
11875 return dump_cache(file_name
.c_str(), NULL
);
11878 int MDCache::dump_cache(Formatter
*f
)
11880 return dump_cache(NULL
, f
);
11883 int MDCache::dump_cache(const string
& dump_root
, int depth
, Formatter
*f
)
11885 return dump_cache(NULL
, f
, dump_root
, depth
);
11889 * Dump the metadata cache, either to a Formatter, if
11890 * provided, else to a plain text file.
11892 int MDCache::dump_cache(const char *fn
, Formatter
*f
,
11893 const string
& dump_root
, int depth
)
11899 f
->open_array_section("inodes");
11903 snprintf(deffn
, sizeof(deffn
), "cachedump.%d.mds%d", (int)mds
->mdsmap
->get_epoch(), int(mds
->get_nodeid()));
11907 dout(1) << "dump_cache to " << fn
<< dendl
;
11909 fd
= ::open(fn
, O_WRONLY
|O_CREAT
|O_EXCL
, 0600);
11911 derr
<< "failed to open " << fn
<< ": " << cpp_strerror(errno
) << dendl
;
11916 for (ceph::unordered_map
<vinodeno_t
,CInode
*>::iterator it
= inode_map
.begin();
11917 it
!= inode_map
.end();
11919 CInode
*in
= it
->second
;
11921 if (!dump_root
.empty()) {
11926 in
->make_path_string(ipath
);
11928 if (dump_root
.length() > ipath
.length() ||
11929 !equal(dump_root
.begin(), dump_root
.end(), ipath
.begin()))
11933 count(ipath
.begin() + dump_root
.length(), ipath
.end(), '/') > depth
)
11938 f
->open_object_section("inode");
11942 ss
<< *in
<< std::endl
;
11943 std::string s
= ss
.str();
11944 r
= safe_write(fd
, s
.c_str(), s
.length());
11951 in
->get_dirfrags(dfs
);
11953 f
->open_array_section("dirfrags");
11955 for (list
<CDir
*>::iterator p
= dfs
.begin(); p
!= dfs
.end(); ++p
) {
11958 f
->open_object_section("dir");
11962 tt
<< " " << *dir
<< std::endl
;
11963 string t
= tt
.str();
11964 r
= safe_write(fd
, t
.c_str(), t
.length());
11971 f
->open_array_section("dentries");
11973 for (CDir::map_t::iterator q
= dir
->items
.begin();
11974 q
!= dir
->items
.end();
11976 CDentry
*dn
= q
->second
;
11978 f
->open_object_section("dentry");
11980 f
->close_section();
11983 uu
<< " " << *dn
<< std::endl
;
11984 string u
= uu
.str();
11985 r
= safe_write(fd
, u
.c_str(), u
.length());
11992 f
->close_section(); //dentries
11994 dir
->check_rstats();
11996 f
->close_section(); //dir
12000 f
->close_section(); // dirfrags
12004 f
->close_section(); // inode
12010 f
->close_section(); // inodes
12019 C_MDS_RetryRequest::C_MDS_RetryRequest(MDCache
*c
, MDRequestRef
& r
)
12020 : MDSInternalContext(c
->mds
), cache(c
), mdr(r
)
12023 void C_MDS_RetryRequest::finish(int r
)
12026 cache
->dispatch_request(mdr
);
12030 class C_MDS_EnqueueScrub
: public Context
12032 Formatter
*formatter
;
12033 Context
*on_finish
;
12035 ScrubHeaderRef header
;
12036 C_MDS_EnqueueScrub(Formatter
*f
, Context
*fin
) :
12037 formatter(f
), on_finish(fin
), header(nullptr) {}
12039 Context
*take_finisher() {
12040 Context
*fin
= on_finish
;
12045 void finish(int r
) override
{
12046 if (r
< 0) { // we failed the lookup or something; dump ourselves
12047 formatter
->open_object_section("results");
12048 formatter
->dump_int("return_code", r
);
12049 formatter
->close_section(); // results
12052 on_finish
->complete(r
);
12056 void MDCache::enqueue_scrub(
12057 const string
& path
,
12058 const std::string
&tag
,
12059 bool force
, bool recursive
, bool repair
,
12060 Formatter
*f
, Context
*fin
)
12062 dout(10) << __func__
<< path
<< dendl
;
12063 MDRequestRef mdr
= request_start_internal(CEPH_MDS_OP_ENQUEUE_SCRUB
);
12064 filepath
fp(path
.c_str());
12065 mdr
->set_filepath(fp
);
12067 C_MDS_EnqueueScrub
*cs
= new C_MDS_EnqueueScrub(f
, fin
);
12068 cs
->header
= std::make_shared
<ScrubHeader
>(
12069 tag
, force
, recursive
, repair
, f
);
12071 mdr
->internal_op_finish
= cs
;
12072 enqueue_scrub_work(mdr
);
12075 void MDCache::enqueue_scrub_work(MDRequestRef
& mdr
)
12077 set
<SimpleLock
*> rdlocks
, wrlocks
, xlocks
;
12078 CInode
*in
= mds
->server
->rdlock_path_pin_ref(mdr
, 0, rdlocks
, true);
12082 // TODO: Remove this restriction
12083 assert(in
->is_auth());
12085 bool locked
= mds
->locker
->acquire_locks(mdr
, rdlocks
, wrlocks
, xlocks
);
12089 C_MDS_EnqueueScrub
*cs
= static_cast<C_MDS_EnqueueScrub
*>(mdr
->internal_op_finish
);
12090 ScrubHeaderRef
&header
= cs
->header
;
12092 // Cannot scrub same dentry twice at same time
12093 if (in
->scrub_infop
&& in
->scrub_infop
->scrub_in_progress
) {
12094 mds
->server
->respond_to_request(mdr
, -EBUSY
);
12100 header
->set_origin(in
);
12102 // only set completion context for non-recursive scrub, because we don't
12103 // want to block asok caller on long running scrub
12104 if (!header
->get_recursive()) {
12105 Context
*fin
= cs
->take_finisher();
12106 mds
->scrubstack
->enqueue_inode_top(in
, header
,
12107 new MDSInternalContextWrapper(mds
, fin
));
12109 mds
->scrubstack
->enqueue_inode_bottom(in
, header
, NULL
);
12111 mds
->server
->respond_to_request(mdr
, 0);
12115 struct C_MDC_RepairDirfragStats
: public MDCacheLogContext
{
12117 C_MDC_RepairDirfragStats(MDCache
*c
, MDRequestRef
& m
) :
12118 MDCacheLogContext(c
), mdr(m
) {}
12119 void finish(int r
) override
{
12121 get_mds()->server
->respond_to_request(mdr
, r
);
12125 void MDCache::repair_dirfrag_stats(CDir
*dir
)
12127 MDRequestRef mdr
= request_start_internal(CEPH_MDS_OP_REPAIR_FRAGSTATS
);
12129 mdr
->internal_op_private
= dir
;
12130 mdr
->internal_op_finish
= new C_MDSInternalNoop
;
12131 repair_dirfrag_stats_work(mdr
);
12134 void MDCache::repair_dirfrag_stats_work(MDRequestRef
& mdr
)
12136 CDir
*dir
= static_cast<CDir
*>(mdr
->internal_op_private
);
12137 dout(10) << __func__
<< " " << *dir
<< dendl
;
12139 if (!dir
->is_auth()) {
12140 mds
->server
->respond_to_request(mdr
, -ESTALE
);
12144 if (!mdr
->is_auth_pinned(dir
) && !dir
->can_auth_pin()) {
12145 dir
->add_waiter(CDir::WAIT_UNFREEZE
, new C_MDS_RetryRequest(this, mdr
));
12147 mds
->locker
->drop_locks(mdr
.get());
12148 mdr
->drop_local_auth_pins();
12149 if (!mdr
->remote_auth_pins
.empty())
12150 mds
->locker
->notify_freeze_waiter(dir
);
12154 mdr
->auth_pin(dir
);
12156 set
<SimpleLock
*> rdlocks
, wrlocks
, xlocks
;
12157 CInode
*diri
= dir
->inode
;
12158 rdlocks
.insert(&diri
->dirfragtreelock
);
12159 wrlocks
.insert(&diri
->nestlock
);
12160 wrlocks
.insert(&diri
->filelock
);
12161 if (!mds
->locker
->acquire_locks(mdr
, rdlocks
, wrlocks
, xlocks
))
12164 if (!dir
->is_complete()) {
12165 dir
->fetch(new C_MDS_RetryRequest(this, mdr
));
12169 frag_info_t frag_info
;
12170 nest_info_t nest_info
;
12171 for (CDir::map_t::iterator it
= dir
->begin(); it
!= dir
->end(); ++it
) {
12172 CDentry
*dn
= it
->second
;
12173 if (dn
->last
!= CEPH_NOSNAP
)
12175 CDentry::linkage_t
*dnl
= dn
->get_projected_linkage();
12176 if (dnl
->is_primary()) {
12177 CInode
*in
= dnl
->get_inode();
12178 nest_info
.add(in
->get_projected_inode()->accounted_rstat
);
12180 frag_info
.nsubdirs
++;
12182 frag_info
.nfiles
++;
12183 } else if (dnl
->is_remote())
12184 frag_info
.nfiles
++;
12187 fnode_t
*pf
= dir
->get_projected_fnode();
12188 bool good_fragstat
= frag_info
.same_sums(pf
->fragstat
);
12189 bool good_rstat
= nest_info
.same_sums(pf
->rstat
);
12190 if (good_fragstat
&& good_rstat
) {
12191 dout(10) << __func__
<< " no corruption found" << dendl
;
12192 mds
->server
->respond_to_request(mdr
, 0);
12196 pf
= dir
->project_fnode();
12197 pf
->version
= dir
->pre_dirty();
12198 mdr
->add_projected_fnode(dir
);
12200 mdr
->ls
= mds
->mdlog
->get_current_segment();
12201 EUpdate
*le
= new EUpdate(mds
->mdlog
, "repair_dirfrag");
12202 mds
->mdlog
->start_entry(le
);
12204 if (!good_fragstat
) {
12205 if (pf
->fragstat
.mtime
> frag_info
.mtime
)
12206 frag_info
.mtime
= pf
->fragstat
.mtime
;
12207 if (pf
->fragstat
.change_attr
> frag_info
.change_attr
)
12208 frag_info
.change_attr
= pf
->fragstat
.change_attr
;
12209 pf
->fragstat
= frag_info
;
12210 mds
->locker
->mark_updated_scatterlock(&diri
->filelock
);
12211 mdr
->ls
->dirty_dirfrag_dir
.push_back(&diri
->item_dirty_dirfrag_dir
);
12212 mdr
->add_updated_lock(&diri
->filelock
);
12216 if (pf
->rstat
.rctime
> nest_info
.rctime
)
12217 nest_info
.rctime
= pf
->rstat
.rctime
;
12218 pf
->rstat
= nest_info
;
12219 mds
->locker
->mark_updated_scatterlock(&diri
->nestlock
);
12220 mdr
->ls
->dirty_dirfrag_nest
.push_back(&diri
->item_dirty_dirfrag_nest
);
12221 mdr
->add_updated_lock(&diri
->nestlock
);
12224 le
->metablob
.add_dir_context(dir
);
12225 le
->metablob
.add_dir(dir
, true);
12227 mds
->mdlog
->submit_entry(le
, new C_MDC_RepairDirfragStats(this, mdr
));
12230 void MDCache::repair_inode_stats(CInode
*diri
)
12232 MDRequestRef mdr
= request_start_internal(CEPH_MDS_OP_REPAIR_INODESTATS
);
12234 mdr
->internal_op_private
= diri
;
12235 mdr
->internal_op_finish
= new C_MDSInternalNoop
;
12236 repair_inode_stats_work(mdr
);
12239 void MDCache::repair_inode_stats_work(MDRequestRef
& mdr
)
12241 CInode
*diri
= static_cast<CInode
*>(mdr
->internal_op_private
);
12242 dout(10) << __func__
<< " " << *diri
<< dendl
;
12244 if (!diri
->is_auth()) {
12245 mds
->server
->respond_to_request(mdr
, -ESTALE
);
12248 if (!diri
->is_dir()) {
12249 mds
->server
->respond_to_request(mdr
, -ENOTDIR
);
12253 set
<SimpleLock
*> rdlocks
, wrlocks
, xlocks
;
12254 std::list
<frag_t
> frags
;
12256 if (mdr
->ls
) // already marked filelock/nestlock dirty ?
12259 rdlocks
.insert(&diri
->dirfragtreelock
);
12260 wrlocks
.insert(&diri
->nestlock
);
12261 wrlocks
.insert(&diri
->filelock
);
12262 if (!mds
->locker
->acquire_locks(mdr
, rdlocks
, wrlocks
, xlocks
))
12265 // Fetch all dirfrags and mark filelock/nestlock dirty. This will tirgger
12266 // the scatter-gather process, which will fix any fragstat/rstat errors.
12267 diri
->dirfragtree
.get_leaves(frags
);
12268 for (list
<frag_t
>::iterator p
= frags
.begin(); p
!= frags
.end(); ++p
) {
12269 CDir
*dir
= diri
->get_dirfrag(*p
);
12271 assert(mdr
->is_auth_pinned(diri
));
12272 dir
= diri
->get_or_open_dirfrag(this, *p
);
12274 if (dir
->get_version() == 0) {
12275 assert(dir
->is_auth());
12276 dir
->fetch(new C_MDS_RetryRequest(this, mdr
));
12281 diri
->state_set(CInode::STATE_REPAIRSTATS
);
12282 mdr
->ls
= mds
->mdlog
->get_current_segment();
12283 mds
->locker
->mark_updated_scatterlock(&diri
->filelock
);
12284 mdr
->ls
->dirty_dirfrag_dir
.push_back(&diri
->item_dirty_dirfrag_dir
);
12285 mds
->locker
->mark_updated_scatterlock(&diri
->nestlock
);
12286 mdr
->ls
->dirty_dirfrag_nest
.push_back(&diri
->item_dirty_dirfrag_nest
);
12288 mds
->locker
->drop_locks(mdr
.get());
12291 // force the scatter-gather process
12292 rdlocks
.insert(&diri
->dirfragtreelock
);
12293 rdlocks
.insert(&diri
->nestlock
);
12294 rdlocks
.insert(&diri
->filelock
);
12296 if (!mds
->locker
->acquire_locks(mdr
, rdlocks
, wrlocks
, xlocks
))
12299 diri
->state_clear(CInode::STATE_REPAIRSTATS
);
12301 frag_info_t dir_info
;
12302 nest_info_t nest_info
;
12303 nest_info
.rsubdirs
++; // it gets one to account for self
12305 diri
->dirfragtree
.get_leaves(frags
);
12306 for (list
<frag_t
>::iterator p
= frags
.begin(); p
!= frags
.end(); ++p
) {
12307 CDir
*dir
= diri
->get_dirfrag(*p
);
12309 assert(dir
->get_version() > 0);
12310 dir_info
.add(dir
->fnode
.accounted_fragstat
);
12311 nest_info
.add(dir
->fnode
.accounted_rstat
);
12314 if (!dir_info
.same_sums(diri
->inode
.dirstat
) ||
12315 !nest_info
.same_sums(diri
->inode
.rstat
)) {
12316 dout(10) << __func__
<< " failed to fix fragstat/rstat on "
12320 mds
->server
->respond_to_request(mdr
, 0);
12323 void MDCache::flush_dentry(const string
& path
, Context
*fin
)
12325 if (is_readonly()) {
12326 dout(10) << __func__
<< ": read-only FS" << dendl
;
12327 fin
->complete(-EROFS
);
12330 dout(10) << "flush_dentry " << path
<< dendl
;
12331 MDRequestRef mdr
= request_start_internal(CEPH_MDS_OP_FLUSH
);
12332 filepath
fp(path
.c_str());
12333 mdr
->set_filepath(fp
);
12334 mdr
->internal_op_finish
= fin
;
12335 flush_dentry_work(mdr
);
12338 class C_FinishIOMDR
: public MDSInternalContextBase
{
12342 MDSRank
*get_mds() override
{ return mds
; }
12344 C_FinishIOMDR(MDSRank
*mds_
, MDRequestRef
& mdr_
) : mds(mds_
), mdr(mdr_
) {}
12345 void finish(int r
) override
{ mds
->server
->respond_to_request(mdr
, r
); }
12348 void MDCache::flush_dentry_work(MDRequestRef
& mdr
)
12350 set
<SimpleLock
*> rdlocks
, wrlocks
, xlocks
;
12351 CInode
*in
= mds
->server
->rdlock_path_pin_ref(mdr
, 0, rdlocks
, true);
12355 // TODO: Is this necessary? Fix it if so
12356 assert(in
->is_auth());
12357 bool locked
= mds
->locker
->acquire_locks(mdr
, rdlocks
, wrlocks
, xlocks
);
12360 in
->flush(new C_FinishIOMDR(mds
, mdr
));
12365 * Initialize performance counters with global perfcounter
12368 void MDCache::register_perfcounters()
12370 PerfCountersBuilder
pcb(g_ceph_context
,
12371 "mds_cache", l_mdc_first
, l_mdc_last
);
12373 /* Stray/purge statistics */
12374 pcb
.add_u64(l_mdc_num_strays
, "num_strays",
12375 "Stray dentries", "stry", PerfCountersBuilder::PRIO_INTERESTING
);
12376 pcb
.add_u64(l_mdc_num_strays_delayed
, "num_strays_delayed", "Stray dentries delayed");
12377 pcb
.add_u64(l_mdc_num_strays_enqueuing
, "num_strays_enqueuing", "Stray dentries enqueuing for purge");
12379 pcb
.add_u64_counter(l_mdc_strays_created
, "strays_created", "Stray dentries created");
12380 pcb
.add_u64_counter(l_mdc_strays_enqueued
, "strays_enqueued",
12381 "Stray dentries enqueued for purge");
12382 pcb
.add_u64_counter(l_mdc_strays_reintegrated
, "strays_reintegrated", "Stray dentries reintegrated");
12383 pcb
.add_u64_counter(l_mdc_strays_migrated
, "strays_migrated", "Stray dentries migrated");
12386 /* Recovery queue statistics */
12387 pcb
.add_u64(l_mdc_num_recovering_processing
, "num_recovering_processing", "Files currently being recovered");
12388 pcb
.add_u64(l_mdc_num_recovering_enqueued
, "num_recovering_enqueued",
12389 "Files waiting for recovery", "recy", PerfCountersBuilder::PRIO_INTERESTING
);
12390 pcb
.add_u64(l_mdc_num_recovering_prioritized
, "num_recovering_prioritized", "Files waiting for recovery with elevated priority");
12391 pcb
.add_u64_counter(l_mdc_recovery_started
, "recovery_started", "File recoveries started");
12392 pcb
.add_u64_counter(l_mdc_recovery_completed
, "recovery_completed",
12393 "File recoveries completed", "recd", PerfCountersBuilder::PRIO_INTERESTING
);
12395 pcb
.add_u64_counter(l_mdss_ireq_enqueue_scrub
, "ireq_enqueue_scrub",
12396 "Internal Request type enqueue scrub");
12397 pcb
.add_u64_counter(l_mdss_ireq_exportdir
, "ireq_exportdir",
12398 "Internal Request type export dir");
12399 pcb
.add_u64_counter(l_mdss_ireq_flush
, "ireq_flush",
12400 "Internal Request type flush");
12401 pcb
.add_u64_counter(l_mdss_ireq_fragmentdir
, "ireq_fragmentdir",
12402 "Internal Request type fragmentdir");
12403 pcb
.add_u64_counter(l_mdss_ireq_fragstats
, "ireq_fragstats",
12404 "Internal Request type frag stats");
12405 pcb
.add_u64_counter(l_mdss_ireq_inodestats
, "ireq_inodestats",
12406 "Internal Request type inode stats");
12408 logger
.reset(pcb
.create_perf_counters());
12409 g_ceph_context
->get_perfcounters_collection()->add(logger
.get());
12410 recovery_queue
.set_logger(logger
.get());
12411 stray_manager
.set_logger(logger
.get());
12414 void MDCache::activate_stray_manager()
12417 stray_manager
.activate();
12420 new MDSInternalContextWrapper(mds
,
12421 new FunctionContext([this](int r
){
12422 stray_manager
.activate();
12430 * Call this when putting references to an inode/dentry or
12431 * when attempting to trim it.
12433 * If this inode is no longer linked by anyone, and this MDS
12434 * rank holds the primary dentry, and that dentry is in a stray
12435 * directory, then give up the dentry to the StrayManager, never
12436 * to be seen again by MDCache.
12438 * @param delay if true, then purgeable inodes are stashed til
12439 * the next trim(), rather than being purged right
12442 void MDCache::maybe_eval_stray(CInode
*in
, bool delay
) {
12443 if (in
->inode
.nlink
> 0 || in
->is_base() || is_readonly() ||
12444 mds
->get_state() <= MDSMap::STATE_REJOIN
)
12447 CDentry
*dn
= in
->get_projected_parent_dn();
12449 if (dn
->state_test(CDentry::STATE_PURGING
)) {
12450 /* We have already entered the purging process, no need
12451 * to re-evaluate me ! */
12455 if (dn
->get_projected_linkage()->is_primary() &&
12456 dn
->get_dir()->get_inode()->is_stray()) {
12457 stray_manager
.eval_stray(dn
, delay
);
12461 void MDCache::clear_dirty_bits_for_stray(CInode
* diri
) {
12462 dout(10) << __func__
<< " " << *diri
<< dendl
;
12463 assert(diri
->get_projected_parent_dir()->inode
->is_stray());
12465 diri
->get_dirfrags(ls
);
12466 for (auto p
: ls
) {
12467 if (p
->is_auth() && !(p
->is_frozen() || p
->is_freezing()))
12468 p
->try_remove_dentries_for_stray();
12470 if (!diri
->snaprealm
) {
12471 if (diri
->is_auth())
12472 diri
->clear_dirty_rstat();
12473 diri
->clear_scatter_dirty();