Various fixes for MDS
cover Various fixes for MDS
From: "Yan, Zheng" <[email protected]>
This patch series fix various issues I encountered when running 3 MDS. I test this patch series by runing fsstress on two clients, using the same test directory. The MDS and clients could survived overnight test at times.
This patch series are also in:
git://github.com/ukernel/ceph.git wip-mds
PATCH 1/29 mds: don't renew revoking lease
From: "Yan, Zheng" <[email protected]>
MDS may receives lease renew request while lease is being revoked, just ignore the renew request.
--- src/mds/Locker.cc | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
src/mds/Locker.cc +14 -12
@@ -2914,18 +2914,20 @@ void Locker::handle_client_lease(MClientLease *m) case CEPH_MDS_LEASE_RENEW: { - dout(7) << "handle_client_lease client." << client - << " renew on " << *dn << dendl; - int pool = 1; // fixme.. do something smart! - m->h.duration_ms = (int)(1000 * mdcache->client_lease_durations[pool]); - m->h.seq = ++l->seq; - m->clear_payload(); - - utime_t now = ceph_clock_now(g_ceph_context); - now += mdcache->client_lease_durations[pool]; - mdcache->touch_client_lease(l, pool, now); - - mds->send_message_client_counted(m, m->get_connection()); + dout(7) << "handle_client_lease client." << client << " renew on " << *dn + << (!dn->lock.can_lease(client)?", revoking lease":"") << dendl; + if (dn->lock.can_lease(client)) { + int pool = 1; // fixme.. do something smart! + m->h.duration_ms = (int)(1000 * mdcache->client_lease_durations[pool]); + m->h.seq = ++l->seq; + m->clear_payload(); + + utime_t now = ceph_clock_now(g_ceph_context); + now += mdcache->client_lease_durations[pool]; + mdcache->touch_client_lease(l, pool, now); + + mds->send_message_client_counted(m, m->get_connection()); + } } break;
Signature · 1 line
1.7.11.7
PATCH 2/29 mds: fix Locker::simple_eval()
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Locker::simple_eval() checks if the loner wants CEPH_CAP_GEXCL to decide if it should change the lock to EXCL state, but it checks if CEPH_CAP_GEXCL is issued to the loner to decide if it should change the lock to SYNC state. So if the loner wants CEPH_CAP_GEXCL, but doesn't have CEPH_CAP_GEXCL, Locker::simple_eval() will keep switching the lock state.
--- src/mds/Locker.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
src/mds/Locker.cc +3 -5
@@ -3250,11 +3250,10 @@ void Locker::simple_eval(SimpleLock *lock, bool *need_issue) return; CInode *in = 0; - int wanted = 0, issued = 0; + int wanted = 0; if (lock->get_type() != CEPH_LOCK_DN) { in = (CInode*)lock->get_parent(); - wanted = in->get_caps_wanted(NULL, NULL, lock->get_cap_shift()); - issued = in->get_caps_issued(NULL, NULL, NULL, lock->get_cap_shift()); + in->get_caps_wanted(&wanted, NULL, lock->get_cap_shift()); } // -> excl?
@@ -3270,8 +3269,7 @@ void Locker::simple_eval(SimpleLock *lock, bool *need_issue) else if (lock->get_state() != LOCK_SYNC && !lock->is_xlocked() && !lock->is_wrlocked() && - ((!(issued & CEPH_CAP_GEXCL) && - !lock->is_waiter_for(SimpleLock::WAIT_WR)) || + ((!(wanted & CEPH_CAP_GEXCL) && !lock->is_waiter_for(SimpleLock::WAIT_WR)) || (lock->get_state() == LOCK_EXCL && in && in->get_target_loner() < 0))) { dout(7) << "simple_eval stable, syncing " << *lock << " on " << *lock->get_parent() << dendl;
Signature · 1 line
1.7.11.7
PATCH 3/29 mds: don't trigger assertion when discover races with rename
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Discover reply that adds replica dentry and inode can race with rename if slave request for rename sends discover and waits, but waked up by reply for different discover.
--- src/mds/CDentry.cc | 17 ++++++----------- src/mds/MDCache.cc | 5 ++--- 2 files changed, 8 insertions(+), 14 deletions(-)
src/mds/CDentry.cc +6 -11
@@ -439,23 +439,18 @@ void CDentry::decode_replica(bufferlist::iterator& p, bool is_new) inodeno_t rino; unsigned char rdtype; + __s32 ls; ::decode(rino, p); ::decode(rdtype, p); - if (rino) { - if (linkage.is_null()) - dir->link_remote_inode(this, rino, rdtype); - else - assert(linkage.is_remote() && linkage.remote_ino == rino); - } - - __s32 ls; ::decode(ls, p); - if (is_new) + + if (is_new) { + if (rino) + dir->link_remote_inode(this, rino, rdtype); lock.set_state(ls); + } } - - // ---------------------------- // locking
src/mds/MDCache.cc +2 -3
@@ -9150,12 +9150,11 @@ CInode *MDCache::add_replica_inode(bufferlist::iterator& p, CDentry *dn, list<Co } else { in->decode_replica(p, false); dout(10) << "add_replica_inode had " << *in << dendl; - assert(!dn || dn->get_linkage()->get_inode() == in); } if (dn) { - assert(dn->get_linkage()->is_primary()); - assert(dn->get_linkage()->get_inode() == in); + if (!dn->get_linkage()->is_primary() || dn->get_linkage()->get_inode() != in) + dout(10) << "add_replica_inode different linkage in dentry " << *dn << dendl; dn->get_dir()->take_ino_waiting(in->ino(), finished); }
Signature · 1 line
1.7.11.7
PATCH 4/29 mds: xlock stray dentry when handling rename or unlink
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
This prevents MDS from reintegrating stray before rename/unlink finishes
--- src/mds/Server.cc | 2 ++ 1 file changed, 2 insertions(+)
src/mds/Server.cc +2 -0
@@ -4536,6 +4536,7 @@ void Server::handle_client_unlink(MDRequest *mdr) if (straydn) { wrlocks.insert(&straydn->get_dir()->inode->filelock); wrlocks.insert(&straydn->get_dir()->inode->nestlock); + xlocks.insert(&straydn->lock); } if (in->is_dir()) rdlocks.insert(&in->filelock); // to verify it's empty
@@ -5300,6 +5301,7 @@ void Server::handle_client_rename(MDRequest *mdr) if (straydn) { wrlocks.insert(&straydn->get_dir()->inode->filelock); wrlocks.insert(&straydn->get_dir()->inode->nestlock); + xlocks.insert(&straydn->lock); } // xlock versionlock on dentries if there are witnesses.
Signature · 1 line
1.7.11.7
PATCH 5/29 mds: don't journal null dentry for overwrited remote linkage
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Server::_rename_prepare() adds null dest dentry to the EMetaBlob if the rename operation overwrites a remote linkage. This is incorrect because null dentry are processed after primary and remote dentries during journal replay. The erroneous null dentry makes the dentry of rename destination disappear.
--- src/mds/Server.cc | 4 ---- 1 file changed, 4 deletions(-)
src/mds/Server.cc +0 -4
@@ -5794,10 +5794,6 @@ void Server::_rename_prepare(MDRequest *mdr, CEPH_NOSNAP, 0, destdnl); metablob->add_primary_dentry(oldin->get_projected_parent_dn(), true, oldin); } - if (destdn->is_auth()) { - // auth for dn, not targeti - metablob->add_null_dentry(destdn, true); - } } }
Signature · 1 line
1.7.11.7
PATCH 6/29 mds: use null dentry to find old parent of renamed directory
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
When replaying an directory rename operation, MDS need to find old parent of the renamed directory to adjust auth subtree. Current code searchs the cache to find the old parent, it does not work if the renamed directory inode is not in the cache. EMetaBlob for directory rename contains at most one null dentry, so MDS can use null dentry to find old parent of the renamed directory. If there is no null dentry in the EMetaBlob, the MDS was witness of the rename operation and there is not auth subtree underneath the renamed directory.
--- src/mds/Server.cc | 11 ++++++----- src/mds/journal.cc | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 15 deletions(-)
src/mds/Server.cc +6 -5
@@ -5616,10 +5616,10 @@ void Server::_rename_prepare(MDRequest *mdr, // nested beneath. bool force_journal = false; while (srci->is_dir()) { - // if we are auth for srci and exporting it, have any _any_ open dirfrags, we - // will (soon) have auth subtrees here. - if (srci->is_auth() && !destdn->is_auth() && srci->has_dirfrags()) { - dout(10) << " we are exporting srci, and have open dirfrags, will force journal" << dendl; + // if we are auth for srci and exporting it, force journal because we need create + // auth subtrees here during journal replay. + if (srci->is_auth() && !destdn->is_auth()) { + dout(10) << " we are exporting srci, will force journal" << dendl; force_journal = true; break; }
@@ -5720,7 +5720,8 @@ void Server::_rename_prepare(MDRequest *mdr, srci->get_dirfrags(ls); for (list<CDir*>::iterator p = ls.begin(); p != ls.end(); ++p) { CDir *dir = *p; - metablob->renamed_dir_frags.push_back(dir->get_frag()); + if (!dir->is_auth()) + metablob->renamed_dir_frags.push_back(dir->get_frag()); } dout(10) << " noting renamed dir open frags " << metablob->renamed_dir_frags << dendl; }
src/mds/journal.cc +28 -10
@@ -442,6 +442,16 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg) dout(10) << "EMetaBlob.replay renamed inode is " << *renamed_diri << dendl; else dout(10) << "EMetaBlob.replay don't have renamed ino " << renamed_dirino << dendl; + + int nnull = 0; + for (list<dirfrag_t>::iterator lp = lump_order.begin(); lp != lump_order.end(); ++lp) { + dirlump &lump = lump_map[*lp]; + if (lump.nnull) { + dout(10) << "EMetaBlob.replay found null dentry in dir " << *lp << dendl; + nnull += lump.nnull; + } + } + assert(nnull <= 1); } // keep track of any inodes we unlink and don't relink elsewhere
@@ -622,8 +632,6 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg) dout(10) << "EMetaBlob.replay unlinking " << *dn << dendl; if (dn->get_linkage()->is_primary()) unlinked.insert(dn->get_linkage()->get_inode()); - if (dn->get_linkage()->get_inode() == renamed_diri) - olddir = dir; dir->unlink_inode(dn); } dn->set_version(p->dnv);
@@ -631,24 +639,34 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg) dout(10) << "EMetaBlob.replay had " << *dn << dendl; assert(dn->last == p->dnlast); } + olddir = dir; } } if (renamed_dirino) { - if (olddir) { - assert(renamed_diri); + if (renamed_diri) { + assert(olddir); + } else { + // we imported a diri we haven't seen before + renamed_diri = mds->mdcache->get_inode(renamed_dirino); + assert(renamed_diri); // it was in the metablob + } + + if (renamed_diri->authority().first != mds->whoami && + olddir && olddir->authority().first == mds->whoami) { + list<frag_t> leaves; + renamed_diri->dirfragtree.get_leaves(leaves); + for (list<frag_t>::iterator p = leaves.begin(); p != leaves.end(); ++p) + renamed_diri->get_or_open_dirfrag(mds->mdcache, *p); + } + + if (renamed_diri && olddir) { mds->mdcache->adjust_subtree_after_rename(renamed_diri, olddir, false); // see if we can discard the subtree we renamed out of CDir *root = mds->mdcache->get_subtree_root(olddir); if (root->get_dir_auth() == CDIR_AUTH_UNDEF) mds->mdcache->try_trim_non_auth_subtree(root); - - } else { - // we imported a diri we haven't seen before - assert(!renamed_diri); - renamed_diri = mds->mdcache->get_inode(renamed_dirino); - assert(renamed_diri); // it was in the metablob } // if we are the srci importer, we'll also have some dirfrags we have to open up...
Signature · 1 line
1.7.11.7
PATCH 7/29 mds: don't trim ambiguous imports in MDCache::trim_non_auth_subtree
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Trimming ambiguous imports in MDCache::trim_non_auth_subtree() confuses MDCache::disambiguate_imports() and causes infinite loop.
--- src/mds/MDCache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/mds/MDCache.cc +1 -1
@@ -5802,7 +5802,7 @@ bool MDCache::trim_non_auth_subtree(CDir *dir) for (list<CDir*>::iterator subdir = subdirs.begin(); subdir != subdirs.end(); ++subdir) { - if ((*subdir)->is_subtree_root()) { + if ((*subdir)->is_subtree_root() || my_ambiguous_imports.count((*subdir)->dirfrag())) { keep_inode = true; dout(10) << "trim_non_auth_subtree(" << dir << ") subdir " << *subdir << "is kept!" << dendl; }
Signature · 1 line
1.7.11.7
PATCH 8/29 mds: only export directory fragments in stray to their auth MDS
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
--- src/mds/Migrator.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
src/mds/Migrator.cc +1 -2
@@ -642,12 +642,11 @@ void Migrator::export_dir(CDir *dir, int dest) } if (!dir->inode->is_base() && dir->get_parent_dir()->get_inode()->is_stray() && - dir->get_parent_dir()->get_parent_dir()->ino() == MDS_INO_MDSDIR(mds->get_nodeid())) { + dir->get_parent_dir()->get_parent_dir()->ino() != MDS_INO_MDSDIR(dest)) { dout(7) << "i won't export anything in stray" << dendl; return; } - if (dir->is_frozen() || dir->is_freezing()) { dout(7) << " can't export, freezing|frozen. wait for other exports to finish first." << dendl;
Signature · 1 line
1.7.11.7
PATCH 9/29 mds: mark rename inode as ambiguous auth on all involved MDS
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
When handling cross authority rename, the master first sends OP_RENAMEPREP slave requests to witness MDS, then sends OP_RENAMEPREP slave request to the rename inode's auth MDS after getting all witness MDS' acknowledgments. Before receiving the OP_RENAMEPREP slave request, the rename inode's auth MDS may change lock state of the rename inode and send lock messages to witness MDS. But the witness MDS may already received the OP_RENAMEPREP slave request and changed the source inode's authority. So the witness MDS send lock acknowledgment message to wrong MDS and trigger assertion.
The fix is, firstly the master marks rename inode as ambiguous and send a message to ask the rename inode's auth MDS to mark the inode as ambiguous, then send OP_RENAMEPREP slave requests to the witness MDS, finally send OP_RENAMEPREP slave request to the rename inode's auth MDS after getting all witness MDS' acknowledgments.
--- src/mds/CInode.cc | 14 ++++++++ src/mds/CInode.h | 6 +++- src/mds/MDCache.cc | 6 ++++ src/mds/Mutation.cc | 16 +++++++++ src/mds/Mutation.h | 8 ++++- src/mds/Server.cc | 98 +++++++++++++++++++++++++++++++++-------------------- src/mds/Server.h | 2 +- 7 files changed, 110 insertions(+), 40 deletions(-)
src/mds/CInode.cc +14 -0
@@ -1932,6 +1932,20 @@ void CInode::unfreeze_auth_pin() } } +void CInode::clear_ambiguous_auth(list<Context*>& finished) +{ + assert(state_test(CInode::STATE_AMBIGUOUSAUTH)); + state_clear(CInode::STATE_AMBIGUOUSAUTH); + take_waiting(CInode::WAIT_SINGLEAUTH, finished); +} + +void CInode::clear_ambiguous_auth() +{ + list<Context*> finished; + clear_ambiguous_auth(finished); + mdcache->mds->queue_waiters(finished); +} + // auth_pins bool CInode::can_auth_pin() { if (is_freezing_inode() || is_frozen_inode() || is_frozen_auth_pin())
src/mds/CInode.h +5 -1
@@ -525,7 +525,11 @@ private: return state_test(STATE_AMBIGUOUSAUTH) || MDSCacheObject::is_ambiguous_auth(); } - +void set_ambiguous_auth () { +state_set (STATE_AMBIGUOUSAUTH ); + } + void clear_ambiguous_auth(list<Context*>& finished); +void clear_ambiguous_auth (); inodeno_t ino() const { return inode.ino; } vinodeno_t vino() const { return vinodeno_t(inode.ino, last); }
src/mds/MDCache.cc +6 -0
@@ -2616,6 +2616,9 @@ void MDCache::handle_mds_failure(int who) p->second->more()->waiting_on_slave.erase(who); mds->wait_for_active_peer(who, new C_MDS_RetryRequest(this, p->second)); } + + if (p->second->more()->prepared_inode_exporter == who) + p->second->more()->prepared_inode_exporter = -1; } }
@@ -7607,6 +7610,9 @@ void MDCache::request_cleanup(MDRequest *mdr) // drop (local) auth pins mdr->drop_local_auth_pins(); + if (mdr->ambiguous_auth_inode) + mdr->clear_ambiguous_auth(mdr->ambiguous_auth_inode); + // drop stickydirs for (set<CInode*>::iterator p = mdr->stickydirs.begin(); p != mdr->stickydirs.end();
src/mds/Mutation.cc +16 -0
@@ -106,6 +106,22 @@ void Mutation::unfreeze_auth_pin(CInode *inode) auth_pin_freeze = NULL; } +void Mutation::set_ambiguous_auth(CInode *inode) +{ + if (!ambiguous_auth_inode) { + inode->set_ambiguous_auth(); + ambiguous_auth_inode = inode; + } else + assert(ambiguous_auth_inode == inode); +} + +void Mutation::clear_ambiguous_auth(CInode *inode) +{ + assert(ambiguous_auth_inode == inode); + ambiguous_auth_inode->clear_ambiguous_auth(); + ambiguous_auth_inode = NULL; +} + bool Mutation::can_auth_pin(MDSCacheObject *object) { return object->can_auth_pin() || (is_auth_pinned(object) && object == auth_pin_freeze);
src/mds/Mutation.h +7 -1
@@ -51,6 +51,7 @@ struct Mutation { set< MDSCacheObject* > remote_auth_pins; set< MDSCacheObject* > auth_pins;CInode *auth_pin_freeze; +CInode * ambiguous_auth_inode;// held locks set< SimpleLock* > rdlocks; // always local.
@@ -83,6 +84,7 @@ struct Mutation {ls (0 ),slave_to_mds (-1 ),auth_pin_freeze (NULL ), +ambiguous_auth_inode (NULL ),locking (NULL ), done_locking(false), committing(false), aborted(false), killed(false) { } Mutation(metareqid_t ri, __u32 att=0, int slave_to=-1)
@@ -90,6 +92,7 @@ struct Mutation {ls (0 ),slave_to_mds (slave_to),auth_pin_freeze (NULL ), +ambiguous_auth_inode (NULL ),locking (NULL ), done_locking(false), committing(false), aborted(false), killed(false) { } virtual ~Mutation() {
@@ -127,6 +130,8 @@ struct Mutation {void unfreeze_auth_pin (CInode *inode);bool can_auth_pin (MDSCacheObject *object);void drop_local_auth_pins (); +void set_ambiguous_auth (CInode *inode); +void clear_ambiguous_auth (CInode *inode);void add_projected_inode (CInode *in);void pop_and_dirty_projected_inodes ();void add_projected_fnode (CDir *dir);
@@ -209,6 +214,7 @@ struct MDRequest : public Mutation {version_t inode_import_v;CInode * destdn_was_remote_inode;bool was_link_merge; +int prepared_inode_exporter;// has asked auth of srci to mark srci as ambiguous auth map<client_t,entity_inst_t> imported_client_map; map<client_t,uint64_t> sseq_map;
@@ -228,7 +234,7 @@ struct MDRequest : public Mutation { More() :src_reanchor_atid (0 ),dst_reanchor_atid (0 ),inode_import_v (0 ),destdn_was_remote_inode (0 ),was_link_merge (false), -flock_was_waiting (false), +prepared_inode_exporter (-1 ),flock_was_waiting (false),stid (0 ), slave_commit(0) { } } *_more;
src/mds/Server.cc +61 -37
197 lines not on this page · raw message
src/mds/Server.h +1 -1
@@ -214,7 +214,7 @@ public:void _rmsnap_finish (MDRequest *mdr,CInode *diri,snapid_t snapid);// helpers -void _rename_prepare_witness (MDRequest *mdr,int who, + void _rename_prepare_witness(MDRequest *mdr, int who, set<int> &witnesse,CDentry *srcdn,CDentry *destdn,CDentry *straydn);version_t _rename_prepare_import (MDRequest *mdr,CDentry *srcdn,bufferlist *client_map_bl); void _rename_prepare(MDRequest *mdr,
Signature · 1 line
1.7.11.7
PATCH 10/29 mds: skip frozen inode when assimilating dirty inodes' rstat
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
CDir::assimilate_dirty_rstat_inodes() may encounter frozen inodes that are being renamed. Skip these frozen inodes because assimilating inode's rstat require auth pinning the inode.
--- src/mds/CDir.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
src/mds/CDir.cc +11 -2
@@ -1022,6 +1022,9 @@ void CDir::assimilate_dirty_rstat_inodes() for (elist<CInode*>::iterator p = dirty_rstat_inodes.begin_use_current(); !p.end(); ++p) { CInode *in = *p; + if (in->is_frozen()) + continue; + inode_t *pi = in->project_inode(); pi->version = in->pre_dirty();
@@ -1040,16 +1043,22 @@ void CDir::assimilate_dirty_rstat_inodes_finish(Mutation *mut, EMetaBlob *blob) elist<CInode*>::iterator p = dirty_rstat_inodes.begin_use_current(); while (!p.end()) { CInode *in = *p; - CDentry *dn = in->get_projected_parent_dn(); ++p; + if (in->is_frozen()) + continue; + + CDentry *dn = in->get_projected_parent_dn(); + mut->auth_pin(in); mut->add_projected_inode(in); in->clear_dirty_rstat(); blob->add_primary_dentry(dn, true, in); } - assert(dirty_rstat_inodes.empty()); + + if (!dirty_rstat_inodes.empty()) + inode->mdcache->mds->locker->mark_updated_scatterlock(&inode->nestlock); }
Signature · 1 line
1.7.11.7
PATCH 11/29 mds: fix anchor table commit race
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Anchor table updates for a given inode is fully serialized on client side. But due to network latency, two commit requests from different clients can arrive to anchor server out of order. The anchor table gets corrupted if updates are committed in wrong order.
The fix is track on-going anchor updates for individual inode and delay processing commit requests that arrive out of order.
--- src/mds/AnchorServer.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++-- src/mds/AnchorServer.h | 13 +++++++++- src/mds/MDSTableServer.cc | 4 +++- src/mds/MDSTableServer.h | 2 +- src/mds/SnapServer.cc | 3 ++- src/mds/SnapServer.h | 2 +- 6 files changed, 78 insertions(+), 7 deletions(-)
src/mds/AnchorServer.cc +59 -2
@@ -142,12 +142,13 @@ void AnchorServer::_prepare(bufferlist &bl, uint64_t reqid, int bymds) } inc(ino); pending_create[version] = ino; // so we can undo + pending_ops[ino].push_back(pair<version_t, Context*>(version, NULL)); break; - case TABLE_OP_DESTROY: version++; pending_destroy[version] = ino; + pending_ops[ino].push_back(pair<version_t, Context*>(version, NULL)); break; case TABLE_OP_UPDATE:
@@ -155,6 +156,7 @@ void AnchorServer::_prepare(bufferlist &bl, uint64_t reqid, int bymds) version++; pending_update[version].first = ino; pending_update[version].second = trace; + pending_ops[ino].push_back(pair<version_t, Context*>(version, NULL)); break; default:
@@ -163,8 +165,56 @@ void AnchorServer::_prepare(bufferlist &bl, uint64_t reqid, int bymds) //dump(); } -void AnchorServer::_commit(version_t tid) +bool AnchorServer::check_pending(version_t tid, MMDSTableRequest *req, list<Context *>& finished) +{ + inodeno_t ino; + if (pending_create.count(tid)) + ino = pending_create[tid]; + else if (pending_destroy.count(tid)) + ino = pending_destroy[tid]; + else if (pending_update.count(tid)) + ino = pending_update[tid].first; + else + assert(0); + + assert(pending_ops.count(ino)); + list< pair<version_t, Context*> >& pending = pending_ops[ino]; + list< pair<version_t, Context*> >::iterator p = pending.begin(); + if (p->first == tid) { + assert(p->second == NULL); + } else { + while (p != pending.end()) { + if (p->first == tid) + break; + p++; + } + assert(p != pending.end()); + assert(p->second == NULL); + // not the earliest pending operation, wait if it's a commit + if (req) { + p->second = new C_MDS_RetryMessage(mds, req); + return false; + } + } + + pending.erase(p); + if (pending.empty()) { + pending_ops.erase(ino); + } else { + for (p = pending.begin(); p != pending.end() && p->second; p++) { + finished.push_back(p->second); + p->second = NULL; + } + } + return true; +} + +bool AnchorServer::_commit(version_t tid, MMDSTableRequest *req) { + list<Context *> finished; + if (!check_pending(tid, req, finished)) + return false; + if (pending_create.count(tid)) { dout(7) << "commit " << tid << " create " << pending_create[tid] << dendl; pending_create.erase(tid);
@@ -206,10 +256,16 @@ void AnchorServer::_commit(version_t tid) // bump version. version++; //dump(); + + mds->queue_waiters(finished); + return true; } void AnchorServer::_rollback(version_t tid) { + list<Context *> finished; + check_pending(tid, NULL, finished); + if (pending_create.count(tid)) { inodeno_t ino = pending_create[tid]; dout(7) << "rollback " << tid << " create " << ino << dendl;
@@ -234,6 +290,7 @@ void AnchorServer::_rollback(version_t tid) // bump version. version++; //dump(); + mds->queue_waiters(finished); } /* This function DOES put the passed message before returning */
src/mds/AnchorServer.h +12 -1
@@ -30,6 +30,7 @@ class AnchorServer : public MDSTableServer { map<version_t, inodeno_t> pending_create; map<version_t, inodeno_t> pending_destroy; map<version_t, pair<inodeno_t, vector<Anchor> > > pending_update; + map<inodeno_t, list<pair<version_t, Context*> > > pending_ops;void reset_state (); void encode_server_state(bufferlist& bl) {
@@ -47,17 +48,27 @@ class AnchorServer : public MDSTableServer { ::decode(pending_create, p); ::decode(pending_destroy, p); ::decode(pending_update, p); + + map<version_t, inodeno_t> sort; + sort.insert (pending_create.begin (), pending_create.end ()); + sort.insert (pending_destroy.begin (), pending_destroy.end ()); + for (map<version_t, pair<inodeno_t, vector<Anchor> > >::iterator p = pending_update.begin(); + p != pending_update.end (); p++) + sort[p->first] = p->second.first; + for (map<version_t, inodeno_t>::iterator p = sort.begin(); p != sort.end(); p++) + pending_ops[p->second].push_back(pair<version_t, Context*>(p->first, NULL)); }bool add (inodeno_t ino,inodeno_t dirino,__u32 dn_hash,bool replace); void inc(inodeno_t ino, int ref=1); void dec(inodeno_t ino, int ref=1); + bool check_pending(version_t tid, MMDSTableRequest *req, list<Context *>& finished);void dump ();// server bits void _prepare(bufferlist &bl, uint64_t reqid, int bymds); -void _commit (version_t tid); + bool _commit(version_t tid, MMDSTableRequest *req=NULL);void _rollback (version_t tid);void handle_query (MMDSTableRequest *m); };
src/mds/MDSTableServer.cc +3 -1
@@ -82,7 +82,9 @@ void MDSTableServer::handle_commit(MMDSTableRequest *req) assert(g_conf->mds_kill_mdstable_at != 5); - _commit(tid); + if (!_commit(tid, req)) + return; + _note_commit(tid); mds->mdlog->start_submit_entry(new ETableServer(table, TABLESERVER_OP_COMMIT, 0, -1, tid, version));
src/mds/MDSTableServer.h +1 -1
@@ -78,7 +78,7 @@ private: public: virtual void handle_query(MMDSTableRequest *m) = 0; virtual void _prepare(bufferlist &bl, uint64_t reqid, int bymds) = 0; - virtual void _commit(version_t tid) = 0; + virtual bool _commit(version_t tid, MMDSTableRequest *req=NULL) = 0; virtual void _rollback(version_t tid) = 0; virtual void _server_update(bufferlist& bl) { assert(0); }
src/mds/SnapServer.cc +2 -1
@@ -101,7 +101,7 @@ bool SnapServer::_is_prepared(version_t tid) pending_destroy.count(tid); } -void SnapServer::_commit(version_t tid) +bool SnapServer::_commit(version_t tid, MMDSTableRequest *req) { if (pending_create.count(tid)) { dout(7) << "commit " << tid << " create " << pending_create[tid] << dendl;
@@ -134,6 +134,7 @@ void SnapServer::_commit(version_t tid) // bump version. version++; //dump(); + return true; } void SnapServer::_rollback(version_t tid)
src/mds/SnapServer.h +1 -1
@@ -70,7 +70,7 @@ public:// server bits void _prepare(bufferlist &bl, uint64_t reqid, int bymds);bool _is_prepared (version_t tid); -void _commit (version_t tid); + bool _commit(version_t tid, MMDSTableRequest *req=NULL);void _rollback (version_t tid); void _server_update(bufferlist& bl);void handle_query (MMDSTableRequest *m);
Signature · 1 line
1.7.11.7
PATCH 12/29 mds: fix on-going two phrase commits tracking
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
The slaves for two phrase commit should be mdr->more()->witnessed instead of mdr->more()->slaves. mdr->more()->slaves includes MDS for remote auth pin and lock
--- src/mds/Server.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
src/mds/Server.cc +9 -9
@@ -4076,11 +4076,11 @@ void Server::_link_remote(MDRequest *mdr, bool inc, CDentry *dn, CInode *targeti EUpdate *le = new EUpdate(mdlog, inc ? "link_remote":"unlink_remote"); mdlog->start_entry(le); le->metablob.add_client_req(mdr->reqid, mdr->client_request->get_oldest_client_tid()); - if (!mdr->more()->slaves.empty()) { - dout(20) << " noting uncommitted_slaves " << mdr->more()->slaves << dendl; + if (!mdr->more()->witnessed.empty()) { + dout(20) << " noting uncommitted_slaves " << mdr->more()->witnessed << dendl; le->reqid = mdr->reqid; le->had_slaves = true; - mds->mdcache->add_uncommitted_master(mdr->reqid, mdr->ls, mdr->more()->slaves); + mds->mdcache->add_uncommitted_master(mdr->reqid, mdr->ls, mdr->more()->witnessed); } if (inc) {
@@ -4655,11 +4655,11 @@ void Server::_unlink_local(MDRequest *mdr, CDentry *dn, CDentry *straydn) EUpdate *le = new EUpdate(mdlog, "unlink_local"); mdlog->start_entry(le); le->metablob.add_client_req(mdr->reqid, mdr->client_request->get_oldest_client_tid()); - if (!mdr->more()->slaves.empty()) { - dout(20) << " noting uncommitted_slaves " << mdr->more()->slaves << dendl; + if (!mdr->more()->witnessed.empty()) { + dout(20) << " noting uncommitted_slaves " << mdr->more()->witnessed << dendl; le->reqid = mdr->reqid; le->had_slaves = true; - mds->mdcache->add_uncommitted_master(mdr->reqid, mdr->ls, mdr->more()->slaves); + mds->mdcache->add_uncommitted_master(mdr->reqid, mdr->ls, mdr->more()->witnessed); } if (straydn) {
@@ -5493,13 +5493,13 @@ void Server::handle_client_rename(MDRequest *mdr) EUpdate *le = new EUpdate(mdlog, "rename"); mdlog->start_entry(le); le->metablob.add_client_req(mdr->reqid, mdr->client_request->get_oldest_client_tid()); - if (!mdr->more()->slaves.empty()) { - dout(20) << " noting uncommitted_slaves " << mdr->more()->slaves << dendl; + if (!mdr->more()->witnessed.empty()) { + dout(20) << " noting uncommitted_slaves " << mdr->more()->witnessed << dendl; le->reqid = mdr->reqid; le->had_slaves = true; - mds->mdcache->add_uncommitted_master(mdr->reqid, mdr->ls, mdr->more()->slaves); + mds->mdcache->add_uncommitted_master(mdr->reqid, mdr->ls, mdr->more()->witnessed); } _rename_prepare(mdr, &le->metablob, &le->client_map, srcdn, destdn, straydn);
Signature · 1 line
1.7.11.7
PATCH 13/29 mds: indroduce DROPLOCKS slave request
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
In some rare case, Locker::acquire_locks() drops all acquired locks in order to auth pin new objects. But Locker::drop_locks only drops explicitly acquired remote locks, does not drop objects' version locks that were implicitly acquired on remote MDS. These leftover locks break locking order when re-acquiring _locks and may cause dead lock.
The fix is indroduce DROPLOCKS slave request which drops all acquired lock on remote MDS.
--- src/mds/Locker.cc | 30 +++++++++++++++++++++++++++--- src/mds/Server.cc | 6 ++++++ src/messages/MMDSSlaveRequest.h | 4 ++++ 3 files changed, 37 insertions(+), 3 deletions(-)
src/mds/Locker.cc +27 -3
@@ -483,16 +483,31 @@ void Locker::_drop_rdlocks(Mutation *mut, set<CInode*> *pneed_issue) void Locker::_drop_non_rdlocks(Mutation *mut, set<CInode*> *pneed_issue) { + set<int> slaves; + while (!mut->xlocks.empty()) { + SimpleLock *lock = *mut->xlocks.begin(); + MDSCacheObject *p = lock->get_parent(); + if (!p->is_auth()) { + assert(lock->get_sm()->can_remote_xlock); + slaves.insert(p->authority().first); + lock->put_xlock(); + mut->locks.erase(lock); + mut->xlocks.erase(lock); + continue; + } bool ni = false; - MDSCacheObject *p = (*mut->xlocks.begin())->get_parent(); - xlock_finish(*mut->xlocks.begin(), mut, &ni); + xlock_finish(lock, mut, &ni); if (ni) pneed_issue->insert((CInode*)p); } + while (!mut->remote_wrlocks.empty()) { - remote_wrlock_finish(mut->remote_wrlocks.begin()->first, mut->remote_wrlocks.begin()->second, mut); + slaves.insert(mut->remote_wrlocks.begin()->second); + mut->locks.erase(mut->remote_wrlocks.begin()->first); + mut->remote_wrlocks.erase(mut->remote_wrlocks.begin()); } + while (!mut->wrlocks.empty()) { bool ni = false; MDSCacheObject *p = (*mut->wrlocks.begin())->get_parent();
@@ -500,6 +515,15 @@ void Locker::_drop_non_rdlocks(Mutation *mut, set<CInode*> *pneed_issue) if (ni) pneed_issue->insert((CInode*)p); } + + for (set<int>::iterator p = slaves.begin(); p != slaves.end(); p++) { + if (mds->mdsmap->get_state(*p) >= MDSMap::STATE_REJOIN) { + dout(10) << "_drop_non_rdlocks dropping remote locks on mds." << *p << dendl; + MMDSSlaveRequest *slavereq = new MMDSSlaveRequest(mut->reqid, mut->attempt, + MMDSSlaveRequest::OP_DROPLOCKS); + mds->send_message_mds(slavereq, *p); + } + } } void Locker::cancel_locking(Mutation *mut, set<CInode*> *pneed_issue)
src/mds/Server.cc +6 -0
@@ -1455,6 +1455,12 @@ void Server::dispatch_slave_request(MDRequest *mdr) } break; + case MMDSSlaveRequest::OP_DROPLOCKS: + mds->locker->drop_locks(mdr); + mdr->slave_request->put(); + mdr->slave_request = 0; + break; + case MMDSSlaveRequest::OP_AUTHPIN: handle_slave_auth_pin(mdr); break;
src/messages/MMDSSlaveRequest.h +4 -0
@@ -41,6 +41,8 @@ class MMDSSlaveRequest : public Message {static const int OP_RMDIRPREP =10 ;static const int OP_RMDIRPREPACK =-10 ; +static const int OP_DROPLOCKS =11 ; +static const int OP_FINISH =17 ;static const int OP_COMMITTED =-18 ;
@@ -73,6 +75,8 @@ class MMDSSlaveRequest : public Message {case OP_RMDIRPREP :return "rmdir_prep" ;case OP_RMDIRPREPACK :return "rmdir_prep_ack" ; +case OP_DROPLOCKS :return "drop_locks" ; +case OP_ABORT :return "abort" ;//case OP_COMMIT: return "commit";
Signature · 1 line
1.7.11.7
PATCH 14/29 mds: fix lock state transition check
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Locker::simple_excl() and Locker::scatter_mix() miss is_rdlocked check; Locker::file_excl() miss is_rdlocked check and is_wrlocked check.
--- src/mds/Locker.cc | 9 +++++++++ 1 file changed, 9 insertions(+)
src/mds/Locker.cc +9 -0
@@ -3408,6 +3408,8 @@ void Locker::simple_excl(SimpleLock *lock, bool *need_issue) } int gather = 0; + if (lock->is_rdlocked()) + gather++; if (lock->is_wrlocked()) gather++; if (lock->is_xlocked())
@@ -4167,6 +4169,8 @@ void Locker::scatter_mix(ScatterLock *lock, bool *need_issue) } int gather = 0; + if (lock->is_rdlocked()) + gather++; if (in->is_replicated()) { if (lock->get_state() != LOCK_EXCL_MIX && // EXCL replica is already LOCK lock->get_state() != LOCK_XSYN_EXCL) { // XSYN replica is already LOCK; ** FIXME here too!
@@ -4237,6 +4241,11 @@ void Locker::file_excl(ScatterLock *lock, bool *need_issue) } int gather = 0; + if (lock->is_rdlocked()) + gather++; + if (lock->is_wrlocked()) + gather++; + if (in->is_replicated() && lock->get_state() != LOCK_LOCK_EXCL && lock->get_state() != LOCK_XSYN_EXCL) { // if we were lock, replicas are already lock.
Signature · 1 line
1.7.11.7
PATCH 15/29 mds: remove unnecessary is_xlocked check
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Locker::foo_eval() is always called for stable locks, so no need to check if the lock is xlocked.
--- src/mds/Locker.cc | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
src/mds/Locker.cc +4 -17
@@ -3291,7 +3291,6 @@ void Locker::simple_eval(SimpleLock *lock, bool *need_issue) // stable -> sync? else if (lock->get_state() != LOCK_SYNC && - !lock->is_xlocked() && !lock->is_wrlocked() && ((!(wanted & CEPH_CAP_GEXCL) && !lock->is_waiter_for(SimpleLock::WAIT_WR)) || (lock->get_state() == LOCK_EXCL && in && in->get_target_loner() < 0))) {
@@ -3334,8 +3333,6 @@ bool Locker::simple_sync(SimpleLock *lock, bool *need_issue) int gather = 0; if (lock->is_wrlocked()) gather++; - if (lock->is_xlocked()) - gather++; if (lock->get_parent()->is_replicated() && old_state == LOCK_MIX) { send_lock_message(lock, LOCK_AC_SYNC);
@@ -3412,9 +3409,7 @@ void Locker::simple_excl(SimpleLock *lock, bool *need_issue) gather++; if (lock->is_wrlocked()) gather++; - if (lock->is_xlocked()) - gather++; - + if (lock->get_parent()->is_replicated() && lock->get_state() != LOCK_LOCK_EXCL && lock->get_state() != LOCK_XSYN_EXCL) {
@@ -3695,7 +3690,6 @@ void Locker::scatter_eval(ScatterLock *lock, bool *need_issue) } if (!lock->is_rdlocked() && - !lock->is_xlocked() && lock->get_state() != LOCK_MIX && lock->get_scatter_wanted()) { dout(10) << "scatter_eval scatter_wanted, bump to mix " << *lock
@@ -3706,8 +3700,7 @@ void Locker::scatter_eval(ScatterLock *lock, bool *need_issue) if (lock->get_type() == CEPH_LOCK_INEST) { // in general, we want to keep INEST writable at all times. - if (!lock->is_rdlocked() && - !lock->is_xlocked()) { + if (!lock->is_rdlocked()) { if (lock->get_parent()->is_replicated()) { if (lock->get_state() != LOCK_MIX) scatter_mix(lock, need_issue);
@@ -3723,7 +3716,6 @@ void Locker::scatter_eval(ScatterLock *lock, bool *need_issue) if (!in->has_subtree_root_dirfrag() || in->is_base()) { // i _should_ be sync. if (!lock->is_wrlocked() && - !lock->is_xlocked() && lock->get_state() != LOCK_SYNC) { dout(10) << "scatter_eval no wrlocks|xlocks, not subtree root inode, syncing" << dendl; simple_sync(lock, need_issue);
@@ -3909,8 +3901,6 @@ void Locker::scatter_tempsync(ScatterLock *lock, bool *need_issue) int gather = 0; if (lock->is_wrlocked()) gather++; - if (lock->is_xlocked()) - gather++; if (lock->get_cap_shift() && in->is_head() &&
@@ -4044,8 +4034,7 @@ void Locker::file_eval(ScatterLock *lock, bool *need_issue) assert(lock->get_parent()->is_auth()); assert(lock->is_stable()); - if (lock->is_xlocked() || - lock->get_parent()->is_freezing_or_frozen()) + if (lock->get_parent()->is_freezing_or_frozen()) return; // excl -> *?
@@ -4297,9 +4286,7 @@ void Locker::file_xsyn(SimpleLock *lock, bool *need_issue) int gather = 0; if (lock->is_wrlocked()) gather++; - if (lock->is_xlocked()) - gather++; - + if (in->is_head() && in->issued_caps_need_gather(lock)) { if (need_issue)
Signature · 1 line
1.7.11.7
PATCH 16/29 mds: don't defer processing caps if inode is auth pinned
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
We should not defer processing caps if the inode is auth pinned by MDRequest, because the MDRequest may change lock state of the inode later and wait for the deferred caps.
--- src/mds/Locker.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
src/mds/Locker.cc +4 -5
@@ -2199,12 +2199,11 @@ bool Locker::should_defer_client_cap_frozen(CInode *in) * Currently, a request wait if anything locked is freezing (can't * auth_pin), which would avoid any deadlock with cap release. Thus @in * _MUST_ be in the lock/auth_pin set. + * + * auth_pins==0 implies no unstable lock and not auth pinnned by + * client request, otherwise continue even it's freezing. */ - return (in->is_freezing() && (in->filelock.is_stable() && - in->authlock.is_stable() && - in->xattrlock.is_stable() && - in->linklock.is_stable())) || // continue if freezing and lock is unstable - in->is_frozen(); + return (in->is_freezing() && in->get_num_auth_pins() == 0) || in->is_frozen(); } /*
Signature · 1 line
1.7.11.7
PATCH 17/29 mds: call maybe_eval_stray after removing a replica dentry
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
MDCache::handle_cache_expire() processes dentries after inodes, so the MDCache::maybe_eval_stray() in MDCache::inode_remove_replica() always fails to remove stray inode because MDCache::eval_stray() checks if the stray inode's dentry is replicated.
--- src/mds/MDCache.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
src/mds/MDCache.cc +4 -2
@@ -6120,9 +6120,11 @@ void MDCache::dentry_remove_replica(CDentry *dn, int from) // fix lock if (dn->lock.remove_replica(from)) mds->locker->eval_gather(&dn->lock); -} - + CDentry::linkage_t *dnl = dn->get_projected_linkage(); + if (dnl->is_primary()) + maybe_eval_stray(dnl->get_inode()); +} void MDCache::trim_client_leases() {
Signature · 1 line
1.7.11.7
PATCH 18/29 mds: fix rename inode exportor check
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Use "srcdn->is_auth() && destdnl->is_primary()" to check if the MDS is inode exportor of rename operation is not reliable, This is because OP_FINISH slave request may race with subtree import. The fix is use a variable in MDRequest to indicate if the MDS is inode exportor.
--- src/mds/Mutation.h | 4 ++-- src/mds/Server.cc | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
src/mds/Mutation.h +2 -2
@@ -213,7 +213,7 @@ struct MDRequest : public Mutation {bufferlist inode_import;version_t inode_import_v;CInode * destdn_was_remote_inode; -bool was_link_merge; +bool was_inode_exportor;int prepared_inode_exporter;// has asked auth of srci to mark srci as ambiguous auth map<client_t,entity_inst_t> imported_client_map;
@@ -233,7 +233,7 @@ struct MDRequest : public Mutation { More() :src_reanchor_atid (0 ),dst_reanchor_atid (0 ),inode_import_v (0 ), -destdn_was_remote_inode (0 ),was_link_merge (false), +destdn_was_remote_inode (0 ),was_inode_exportor (false),prepared_inode_exporter (-1 ),flock_was_waiting (false),stid (0 ), slave_commit(0) { }
src/mds/Server.cc +2 -1
@@ -6261,6 +6261,7 @@ void Server::_logged_slave_rename(MDRequest *mdr, // remove mdr auth pin mdr->auth_unpin(srcdnl->get_inode()); + mdr->more()->was_inode_exportor = true; dout(10) << " exported srci " << *srcdnl->get_inode() << dendl; }
@@ -6299,7 +6300,7 @@ void Server::_commit_slave_rename(MDRequest *mdr, int r, // unfreeze+singleauth inode // hmm, do i really need to delay this? - if (srcdn->is_auth() && destdnl->is_primary()) { + if (mdr->more()->was_inode_exportor) { CInode *in = destdnl->get_inode();
Signature · 1 line
1.7.11.7
PATCH 19/29 mds: disable concurrent remote locking
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Current code allows multiple MDRequests to concurrently acquire a remote lock. But a lock ACK message wakes all requests because they were all put to the same waiting queue. One request gets the lock, the rest requests will re-send the OP_WRLOCK/OPWRLOCK slave requests and trigger assertion on remote MDS. The fix is disable concurrently acquiring remote lock, send OP_WRLOCK/OPWRLOCK slave request only if there is no on-going slave request.
--- src/mds/Locker.cc | 54 ++++++++++++++++++++++++++++++++---------------------- src/mds/Server.cc | 2 ++ 2 files changed, 34 insertions(+), 22 deletions(-)
src/mds/Locker.cc +32 -22
@@ -532,14 +532,18 @@ void Locker::cancel_locking(Mutation *mut, set<CInode*> *pneed_issue) assert(lock); dout(10) << "cancel_locking " << *lock << " on " << *mut << dendl; - if (lock->get_type() != CEPH_LOCK_DN) { - bool need_issue = false; - if (lock->get_state() == LOCK_PREXLOCK) - _finish_xlock(lock, &need_issue); - if (lock->is_stable()) - eval(lock, &need_issue); - if (need_issue) - pneed_issue->insert((CInode *)lock->get_parent()); + if (lock->get_parent()->is_auth()) { + if (lock->get_type() != CEPH_LOCK_DN) { + bool need_issue = false; + if (lock->get_state() == LOCK_PREXLOCK) + _finish_xlock(lock, &need_issue); + if (lock->is_stable()) + eval(lock, &need_issue); + if (need_issue) + pneed_issue->insert((CInode *)lock->get_parent()); + } + } else { + lock->finish_waiters(SimpleLock::WAIT_REMOTEXLOCK); } mut->finish_locking(lock); }
@@ -1314,14 +1318,17 @@ void Locker::remote_wrlock_start(SimpleLock *lock, int target, MDRequest *mut) new C_MDS_RetryRequest(mdcache, mut)); return; } - + // send lock request - mut->more()->slaves.insert(target); - MMDSSlaveRequest *r = new MMDSSlaveRequest(mut->reqid, mut->attempt, - MMDSSlaveRequest::OP_WRLOCK); - r->set_lock_type(lock->get_type()); - lock->get_parent()->set_object_info(r->get_object_info()); - mds->send_message_mds(r, target); + if (!lock->is_waiter_for(SimpleLock::WAIT_REMOTEXLOCK)) { + mut->start_locking(lock); + mut->more()->slaves.insert(target); + MMDSSlaveRequest *r = new MMDSSlaveRequest(mut->reqid, mut->attempt, + MMDSSlaveRequest::OP_WRLOCK); + r->set_lock_type(lock->get_type()); + lock->get_parent()->set_object_info(r->get_object_info()); + mds->send_message_mds(r, target); + } // wait lock->add_waiter(SimpleLock::WAIT_REMOTEXLOCK, new C_MDS_RetryRequest(mdcache, mut));
@@ -1398,13 +1405,16 @@ bool Locker::xlock_start(SimpleLock *lock, MDRequest *mut) } // send lock request - int auth = lock->get_parent()->authority().first; - mut->more()->slaves.insert(auth); - MMDSSlaveRequest *r = new MMDSSlaveRequest(mut->reqid, mut->attempt, - MMDSSlaveRequest::OP_XLOCK); - r->set_lock_type(lock->get_type()); - lock->get_parent()->set_object_info(r->get_object_info()); - mds->send_message_mds(r, auth); + if (!lock->is_waiter_for(SimpleLock::WAIT_REMOTEXLOCK)) { + mut->start_locking(lock); + int auth = lock->get_parent()->authority().first; + mut->more()->slaves.insert(auth); + MMDSSlaveRequest *r = new MMDSSlaveRequest(mut->reqid, mut->attempt, + MMDSSlaveRequest::OP_XLOCK); + r->set_lock_type(lock->get_type()); + lock->get_parent()->set_object_info(r->get_object_info()); + mds->send_message_mds(r, auth); + } // wait lock->add_waiter(SimpleLock::WAIT_REMOTEXLOCK, new C_MDS_RetryRequest(mdcache, mut));
src/mds/Server.cc +2 -0
@@ -1324,6 +1324,7 @@ void Server::handle_slave_request_reply(MMDSSlaveRequest *m) dout(10) << "got remote xlock on " << *lock << " on " << *lock->get_parent() << dendl; mdr->xlocks.insert(lock); mdr->locks.insert(lock); + mdr->finish_locking(lock); lock->get_xlock(mdr, mdr->get_client()); lock->finish_waiters(SimpleLock::WAIT_REMOTEXLOCK); }
@@ -1338,6 +1339,7 @@ void Server::handle_slave_request_reply(MMDSSlaveRequest *m) dout(10) << "got remote wrlock on " << *lock << " on " << *lock->get_parent() << dendl; mdr->remote_wrlocks[lock] = from; mdr->locks.insert(lock); + mdr->finish_locking(lock); lock->finish_waiters(SimpleLock::WAIT_REMOTEXLOCK); } break;
Signature · 1 line
1.7.11.7
PATCH 20/29 mds: forbid creating file in deleted directory
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
--- src/mds/CInode.cc | 5 ++++- src/mds/CInode.h | 2 ++ src/mds/Server.cc | 13 ++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-)
src/mds/CInode.cc +4 -1
@@ -245,7 +245,10 @@ void CInode::print(ostream& out) out << *this; } - +bool CInode::is_in_stray() +{ + return !is_base() && get_projected_parent_dir()->inode->is_stray(); +} void CInode::add_need_snapflush(CInode *snapin, snapid_t snapid, client_t client) {
src/mds/CInode.h +2 -0
@@ -520,6 +520,8 @@ private:bool is_head () {return last ==CEPH_NOSNAP ; } +bool is_in_stray (); +// note: this overloads MDSCacheObject bool is_ambiguous_auth () { return state_test(STATE_AMBIGUOUSAUTH) ||
src/mds/Server.cc +12 -1
@@ -2633,6 +2633,13 @@ void Server::handle_client_openc(MDRequest *mdr) reply_request(mdr, -EROFS); return; } + + CInode *diri = dn->get_dir()->get_inode(); + if (diri->is_in_stray()) { + reply_request(mdr, -ENOENT); + return; + } + // set layout ceph_file_layout layout; if (dir_layout)
@@ -2669,7 +2676,6 @@ void Server::handle_client_openc(MDRequest *mdr) return; } - CInode *diri = dn->get_dir()->get_inode(); rdlocks.insert(&diri->authlock); if (!mds->locker->acquire_locks(mdr, rdlocks, wrlocks, xlocks)) return;
@@ -5123,6 +5129,11 @@ void Server::handle_client_rename(MDRequest *mdr) CDir *destdir = destdn->get_dir(); assert(destdir->is_auth()); + if (destdir->get_inode()->is_in_stray()) { + reply_request(mdr, -ENOENT); + return; + } + int r = mdcache->path_traverse(mdr, NULL, NULL, srcpath, &srctrace, NULL, MDS_TRAVERSE_DISCOVER); if (r > 0) return; // delayed
Signature · 1 line
1.7.11.7
PATCH 21/29 mds: keep dentry lock in sync state as much as possible
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Unlike locks of other types, dentry lock in unreadable state can block path traverse, so it should be in sync state as much as possible. there are two rare cases that dentry lock is not set to sync state: the dentry becomes replicated; finishing xlock but the dentry is freezing.
In commit efbca31d, I tried fixing the issue that unreadable replica dentry blocks path traverse by modifying MDCache::path_traverse(), but it does not work. This patch also reverts that change.
--- src/mds/CDentry.h | 3 +++ src/mds/Locker.cc | 5 ++++- src/mds/MDCache.cc | 6 +----- src/mds/Migrator.cc | 3 +++ 4 files changed, 11 insertions(+), 6 deletions(-)
src/mds/CDentry.h +3 -0
@@ -301,6 +301,9 @@ public:// -- replication void encode_replica(int mds, bufferlist& bl) { +if (!is_replicated ()) + lock.replicate_relax (); +__u32 nonce =add_replica (mds); ::encode(nonce, bl); ::encode(first, bl);
src/mds/Locker.cc +4 -1
@@ -1425,13 +1425,16 @@ bool Locker::xlock_start(SimpleLock *lock, MDRequest *mut) void Locker::_finish_xlock(SimpleLock *lock, bool *pneed_issue) { assert(!lock->is_stable()); - lock->get_parent()->auth_unpin(lock); if (lock->get_type() != CEPH_LOCK_DN && ((CInode*)lock->get_parent())->get_loner() >= 0) lock->set_state(LOCK_EXCL); else lock->set_state(LOCK_LOCK); + if (lock->get_type() == CEPH_LOCK_DN && lock->get_parent()->is_replicated() && + !lock->is_waiter_for(SimpleLock::WAIT_WR)) + simple_sync(lock, pneed_issue); if (lock->get_cap_shift()) *pneed_issue = true; + lock->get_parent()->auth_unpin(lock); } void Locker::xlock_finish(SimpleLock *lock, Mutation *mut, bool *pneed_issue)
src/mds/MDCache.cc +1 -5
@@ -6735,14 +6735,10 @@ int MDCache::path_traverse(MDRequest *mdr, Message *req, Context *fin, // wh (dn->lock.is_xlocked() && dn->lock.get_xlock_by() == mdr)) { dout(10) << "traverse: miss on null+readable dentry " << path[depth] << " " << *dn << dendl; return -ENOENT; - } else if (curdir->is_auth()) { + } else { dout(10) << "miss on dentry " << *dn << ", can't read due to lock" << dendl; dn->lock.add_waiter(SimpleLock::WAIT_RD, _get_waiter(mdr, req, fin)); return 1; - } else { - // non-auth and can not read, treat this as no dentry - dn = NULL; - dnl = NULL; } }
src/mds/Migrator.cc +3 -0
@@ -1135,6 +1135,9 @@ int Migrator::encode_export_dir(bufferlist& exportbl, CDentry *dn = it->second; CInode *in = dn->get_linkage()->get_inode(); + if (!dn->is_replicated()) + dn->lock.replicate_relax(); + num_exported++; // -- dentry
Signature · 1 line
1.7.11.7
PATCH 22/29 mds: fix replica state for LOCK_MIX_LOCK
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
LOCK_MIX_LOCK state is for gathering local locks and caps, so replica state should be LOCK_MIX.
--- src/mds/locks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/mds/locks.c +2 -2
@@ -64,7 +64,7 @@ static const struct sm_state_t scatterlock[LOCK_MAX] = { [LOCK_LOCK] = { 0, false, LOCK_LOCK, AUTH, 0, REQ, AUTH,0, 0, ANY, 0,0,0,0 }, [LOCK_SYNC_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, AUTH, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, - [LOCK_MIX_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, + [LOCK_MIX_LOCK] = { LOCK_LOCK, false, LOCK_MIX, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX_LOCK2] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_TSYN_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 },
@@ -98,7 +98,7 @@ const struct sm_state_t filelock[LOCK_MAX] = { [LOCK_LOCK] = { 0, false, LOCK_LOCK, AUTH, 0, REQ, AUTH,0, 0, 0, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,0 }, [LOCK_SYNC_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, AUTH, 0, REQ, 0, 0, 0, 0, CEPH_CAP_GCACHE,0,0,CEPH_CAP_GCACHE }, [LOCK_EXCL_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, XCL, 0, 0, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,CEPH_CAP_GCACHE }, - [LOCK_MIX_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, AUTH, 0, REQ, 0, 0, 0, 0, 0,0,0,0 }, + [LOCK_MIX_LOCK] = { LOCK_LOCK, false, LOCK_MIX, AUTH, 0, REQ, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX_LOCK2] = { LOCK_LOCK, false, LOCK_LOCK, AUTH, 0, REQ, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_PREXLOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, XCL, 0, 0, 0, 0, ANY, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,0 },
Signature · 1 line
1.7.11.7
PATCH 23/29 mds: fix cap mask for ifile lock
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
ifile lock has 8 cap bits, should its cap mask should be 0xff
--- src/mds/SimpleLock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/mds/SimpleLock.h +1 -1
@@ -273,7 +273,7 @@ public: } int get_cap_mask() const {switch (get_type ()) { -case CEPH_LOCK_IFILE :return 0xf ; +case CEPH_LOCK_IFILE :return 0xff ;default :return 0x3 ; } }
Signature · 1 line
1.7.11.7
PATCH 24/29 mds: rdlock prepended dest trace when handling rename
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
rdlock prepended dest trace to prevent them from being xlocked by someone else.
--- src/mds/Server.cc | 1 + 1 file changed, 1 insertion(+)
src/mds/Server.cc +1 -0
@@ -5228,6 +5228,7 @@ void Server::handle_client_rename(MDRequest *mdr) while (destbase != srcbase) { desttrace.insert(desttrace.begin(), destbase->get_projected_parent_dn()); + rdlocks.insert(&desttrace[0]->lock); dout(10) << "rename prepending desttrace with " << *desttrace[0] << dendl; destbase = destbase->get_projected_parent_dn()->get_dir()->get_inode(); }
Signature · 1 line
1.7.11.7
PATCH 25/29 mds: check null context in CDir::fetch()
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
--- src/mds/CDir.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
src/mds/CDir.cc +5 -2
@@ -1351,8 +1351,11 @@ void CDir::fetch(Context *c, const string& want_dn, bool ignore_authpinnability) assert(!is_complete()); if (!can_auth_pin() && !ignore_authpinnability) { - dout(7) << "fetch waiting for authpinnable" << dendl; - add_waiter(WAIT_UNFREEZE, c); + if (c) { + dout(7) << "fetch waiting for authpinnable" << dendl; + add_waiter(WAIT_UNFREEZE, c); + } else + dout(7) << "fetch not authpinnable and no context" << dendl; return; }
Signature · 1 line
1.7.11.7
PATCH 26/29 mds: drop locks when opening remote dentry
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Opening remote dentry while holding locks may cause dead lock. For example, 'discover' is blocked by a xlocked dentry, the request holding the xlock is blocked by the locks hold by the readdir request.
--- src/mds/Server.cc | 2 ++ 1 file changed, 2 insertions(+)
src/mds/Server.cc +2 -0
@@ -2901,6 +2901,8 @@ void Server::handle_client_readdir(MDRequest *mdr) break; } + mds->locker->drop_locks(mdr); + mdr->drop_local_auth_pins(); mdcache->open_remote_dentry(dn, dnp, new C_MDS_RetryRequest(mdcache, mdr)); return; }
Signature · 1 line
1.7.11.7
PATCH 27/29 mds: check if stray dentry is needed
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
The necessity of stray dentry can change before the request acquires all locks.
--- src/mds/Server.cc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
src/mds/Server.cc +16 -10
@@ -4531,11 +4531,14 @@ void Server::handle_client_unlink(MDRequest *mdr) // -- create stray dentry? -- CDentry *straydn = mdr->straydn; - if (dnl->is_primary() && !straydn) { - straydn = mdcache->get_or_create_stray_dentry(dnl->get_inode()); - mdr->pin(straydn); - mdr->straydn = straydn; - } + if (dnl->is_primary()) { + if (!straydn) { + straydn = mdcache->get_or_create_stray_dentry(dnl->get_inode()); + mdr->pin(straydn); + mdr->straydn = straydn; + } + } else if (straydn) + straydn = NULL; if (straydn) dout(10) << " straydn is " << *straydn << dendl;
@@ -5274,11 +5277,14 @@ void Server::handle_client_rename(MDRequest *mdr) // -- create stray dentry? -- CDentry *straydn = mdr->straydn; - if (destdnl->is_primary() && !linkmerge && !straydn) { - straydn = mdcache->get_or_create_stray_dentry(destdnl->get_inode()); - mdr->pin(straydn); - mdr->straydn = straydn; - } + if (destdnl->is_primary() && !linkmerge) { + if (!straydn) { + straydn = mdcache->get_or_create_stray_dentry(destdnl->get_inode()); + mdr->pin(straydn); + mdr->straydn = straydn; + } + } else if (straydn) + straydn = NULL; if (straydn) dout(10) << " straydn is " << *straydn << dendl;
Signature · 1 line
1.7.11.7
PATCH 28/29 mds: don't issue caps while inode is exporting caps
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
If issue caps while inode is exporting caps, the client will drop the caps soon when it receives the CAP_OP_EXPORT message, but the client will not receive corresponding CAP_OP_IMPORT message.
Except open file request, it's OK to not issue caps for client requests. If an non-auth MDS receives open file request but it can't issue caps, forward the request to auth MDS.
--- src/mds/CInode.cc | 10 ++++++---- src/mds/Server.cc | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-)
src/mds/CInode.cc +6 -4
@@ -2604,17 +2604,19 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session, { int client = session->inst.name.num(); assert(snapid); - assert(session->connection); bool valid = true; // do not issue caps if inode differs from readdir snaprealm SnapRealm *realm = find_snaprealm(); - bool no_caps = (realm && dir_realm && realm != dir_realm); + bool no_caps = (realm && dir_realm && realm != dir_realm) || + is_frozen() || state_test(CInode::STATE_EXPORTINGCAPS); if (no_caps) - dout(20) << "encode_inodestat realm=" << realm << " snaprealm " << snaprealm - << " no_caps=" << no_caps << dendl; + dout(20) << "encode_inodestat no caps" + << ((realm && dir_realm && realm != dir_realm)?", snaprealm differs ":"") + << (state_test(CInode::STATE_EXPORTINGCAPS)?", exporting caps":"") + << (is_frozen()?", frozen inode":"") << dendl; // pick a version! inode_t *oi = &inode;
src/mds/Server.cc +15 -7
@@ -1936,14 +1936,14 @@ CInode* Server::rdlock_path_pin_ref(MDRequest *mdr, int n, want_auth = true; if (want_auth) { + if (ref->is_ambiguous_auth()) { + dout(10) << "waiting for single auth on " << *ref << dendl; + ref->add_waiter(CInode::WAIT_SINGLEAUTH, new C_MDS_RetryRequest(mdcache, mdr)); + return 0; + } if (!ref->is_auth()) { - if (ref->is_ambiguous_auth()) { - dout(10) << "waiting for single auth on " << *ref << dendl; - ref->add_waiter(CInode::WAIT_SINGLEAUTH, new C_MDS_RetryRequest(mdcache, mdr)); - } else { - dout(10) << "fw to auth for " << *ref << dendl; - mdcache->request_forward(mdr, ref->authority().first); - } + dout(10) << "fw to auth for " << *ref << dendl; + mdcache->request_forward(mdr, ref->authority().first); return 0; }
@@ -2435,6 +2435,14 @@ void Server::handle_client_open(MDRequest *mdr) if (!cur) return; + if (cur->is_frozen() || cur->state_test(CInode::STATE_EXPORTINGCAPS)) { + assert(!need_auth); + mdr->done_locking = false; + CInode *cur = rdlock_path_pin_ref(mdr, 0, rdlocks, true); + if (!cur) + return; + } + if (mdr->snapid != CEPH_NOSNAP && mdr->client_request->may_write()) { reply_request(mdr, -EROFS); return;
Signature · 1 line
1.7.11.7
PATCH 29/29 mds: optimize C_MDC_RetryOpenRemoteIno
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
When opening remote inode, C_MDC_RetryOpenRemoteIno is used as onfinish context for discovering remote inode. When it is called, the MDS may already have the inode.
--- src/mds/MDCache.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
src/mds/MDCache.cc +5 -1
@@ -7049,7 +7049,11 @@ public: C_MDC_RetryOpenRemoteIno(MDCache *mdc, inodeno_t i, Context *c, bool wx) : mdcache(mdc), ino(i), want_xlocked(wx), onfinish(c) {} void finish(int r) { - mdcache->open_remote_ino(ino, onfinish, want_xlocked); + if (mdcache->get_inode(ino)) { + onfinish->finish(0); + delete onfinish; + } else + mdcache->open_remote_ino(ino, onfinish, want_xlocked); } };
Signature · 1 line
1.7.11.7
Hi Yan,
I reviewed these on the plane last night and they look good. There was one small cleanup I pushed on top of wip-mds (in ceph.git). I'll run this through our (still limited) fs suite and then merge into master.
Thanks!
sage
Quoted 11 lines · Zheng
From: "Yan, Zheng" <[email protected]>
This patch series fix various issues I encountered when running 3 MDS. I test this patch series by runing fsstress on two clients, using the same test directory. The MDS and clients could survived overnight test at times.
This patch series are also in:
git://github.com/ukernel/ceph.gitwip-mds