mds: redo choose_loner/drop_loner

Still need a simple_excl() with a try_choose_loner() check, and something
in simple_eval.
This commit is contained in:
Sage Weil 2009-01-16 09:07:15 -08:00
parent 547b4e1967
commit e4c8ef0dc0
4 changed files with 40 additions and 49 deletions

View File

@ -479,8 +479,9 @@ public:
// client caps
int loner_cap;
bool choose_loner() {
assert(loner_cap < 0);
bool try_choose_loner() {
if (loner_cap >= 0)
return true;
if (!mds_caps_wanted.empty())
return false;
@ -503,6 +504,21 @@ public:
}
return false;
}
bool try_drop_loner() {
if (loner_cap < 0)
return true;
int other_allowed = get_caps_allowed(false);
Capability *cap = get_client_cap(loner_cap);
if (!cap ||
(cap->issued() & ~other_allowed) == 0) {
loner_cap = -1;
return true;
}
return false;
}
int count_nonstale_caps() {
int n = 0;
@ -560,6 +576,9 @@ public:
cap->rdcaps_item.remove_myself();
containing_realm->remove_cap(client, cap);
if (client == loner_cap)
loner_cap = -1;
delete cap;
client_caps.erase(client);
if (client_caps.empty()) {

View File

@ -464,9 +464,6 @@ void Locker::eval_gather(SimpleLock *lock)
return;
}
if (in && lock->get_state() != LOCK_EXCL)
in->loner_cap = -1;
switch (lock->get_state()) {
// to mixed
case LOCK_TSYN_MIX:
@ -492,6 +489,9 @@ void Locker::eval_gather(SimpleLock *lock)
lock->get_parent()->auth_unpin(lock);
}
if (in)
in->try_drop_loner();
lock->set_state(next);
lock->finish_waiters(SimpleLock::WAIT_STABLE|SimpleLock::WAIT_WR|SimpleLock::WAIT_RD|SimpleLock::WAIT_XLOCK);
@ -531,7 +531,6 @@ void Locker::eval(SimpleLock *lock)
}
// ------------------
// rdlock
@ -2158,7 +2157,8 @@ bool Locker::simple_sync(SimpleLock *lock)
lock->encode_locked_state(data);
send_lock_message(lock, LOCK_AC_SYNC, data);
}
if (in)
in->try_drop_loner();
lock->set_state(LOCK_SYNC);
lock->finish_waiters(SimpleLock::WAIT_RD|SimpleLock::WAIT_STABLE);
return true;
@ -2224,8 +2224,9 @@ void Locker::simple_lock(SimpleLock *lock)
if (gather) {
lock->get_parent()->auth_pin(lock);
} else {
if (in)
in->try_drop_loner();
lock->set_state(LOCK_LOCK);
in->loner_cap = -1;
lock->finish_waiters(FileLock::WAIT_XLOCK|FileLock::WAIT_WR|FileLock::WAIT_STABLE);
}
}
@ -2591,6 +2592,9 @@ bool Locker::scatter_scatter_fastpath(ScatterLock *lock)
lock->encode_locked_state(data);
send_lock_message(lock, LOCK_AC_SCATTER, data);
}
((CInode *)lock->get_parent())->try_drop_loner();
lock->set_state(LOCK_MIX);
lock->finish_waiters(ScatterLock::WAIT_WR|ScatterLock::WAIT_STABLE);
return true;
@ -2671,6 +2675,8 @@ void Locker::scatter_tempsync(ScatterLock *lock)
}
// do tempsync
((CInode *)lock->get_parent())->try_drop_loner();
lock->set_state(LOCK_TSYN);
lock->finish_waiters(ScatterLock::WAIT_RD|ScatterLock::WAIT_STABLE);
}
@ -2984,10 +2990,10 @@ void Locker::file_eval(FileLock *lock)
!lock->is_rdlocked() &&
!lock->is_waiter_for(SimpleLock::WAIT_WR) &&
((wanted & (CEPH_CAP_GWR|CEPH_CAP_GWRBUFFER)) || in->inode.is_dir()) &&
in->choose_loner()) {
in->try_choose_loner()) {
dout(7) << "file_eval stable, bump to loner " << *lock
<< " on " << *lock->get_parent() << dendl;
file_loner(lock);
file_excl(lock);
}
// * -> mixed?
@ -3080,15 +3086,15 @@ void Locker::file_mixed(FileLock *lock)
if (gather)
lock->get_parent()->auth_pin(lock);
else {
in->try_drop_loner();
lock->set_state(LOCK_MIX);
in->loner_cap = -1;
issue_caps(in);
}
}
}
void Locker::file_loner(FileLock *lock)
void Locker::file_excl(FileLock *lock)
{
CInode *in = (CInode*)lock->get_parent();
dout(7) << "file_loner " << *lock << " on " << *lock->get_parent() << dendl;

View File

@ -102,21 +102,14 @@ public:
// simple
public:
void try_simple_eval(SimpleLock *lock);
void simple_eval_gather(SimpleLock *lock);
bool simple_rdlock_try(SimpleLock *lock, Context *con);
protected:
void simple_eval(SimpleLock *lock);
void handle_simple_lock(SimpleLock *lock, MLock *m);
bool simple_sync(SimpleLock *lock);
void simple_lock(SimpleLock *lock);
void simple_xlock(SimpleLock *lock);
bool simple_rdlock_start(SimpleLock *lock, MDRequest *mut);
void simple_rdlock_finish(SimpleLock *lock, Mutation *mut);
bool simple_wrlock_force(SimpleLock *lock, Mutation *mut);
bool simple_wrlock_start(SimpleLock *lock, MDRequest *mut);
void simple_wrlock_finish(SimpleLock *lock, Mutation *mut);
bool simple_xlock_start(SimpleLock *lock, MDRequest *mut);
void simple_xlock_finish(SimpleLock *lock, Mutation *mut);
public:
bool dentry_can_rdlock_trace(vector<CDentry*>& trace);
@ -127,32 +120,16 @@ public:
public:
void try_scatter_eval(ScatterLock *lock);
void scatter_eval(ScatterLock *lock); // public for MDCache::adjust_subtree_auth()
void scatter_eval_gather(ScatterLock *lock);
void scatter_tick();
void scatter_nudge(ScatterLock *lock, Context *c);
protected:
bool scatter_lock_fastpath(ScatterLock *lock); // called by LogSegment::try_to_expire
void scatter_lock(ScatterLock *lock, bool nowait=false); // called by LogSegment::try_to_expire
void handle_scatter_lock(ScatterLock *lock, MLock *m);
void _scatter_replica_lock(ScatterLock *lock, int auth);
void scatter_sync(ScatterLock *lock);
bool scatter_scatter_fastpath(ScatterLock *lock);
void scatter_scatter(ScatterLock *lock, bool nowait=false);
void scatter_tempsync(ScatterLock *lock);
bool scatter_rdlock_start(ScatterLock *lock, MDRequest *mut);
void scatter_rdlock_finish(ScatterLock *lock, Mutation *mut);
public:
bool scatter_wrlock_try(ScatterLock *lock, Mutation *mut, bool initiate);
protected:
bool scatter_wrlock_start(ScatterLock *lock, MDRequest *mut);
public:
void scatter_wrlock_finish(ScatterLock *lock, Mutation *mut);
protected:
bool scatter_xlock_start(ScatterLock *lock, MDRequest *mut);
void scatter_xlock_finish(ScatterLock *lock, Mutation *mut);
void scatter_writebehind(ScatterLock *lock);
class C_Locker_ScatterWB : public Context {
@ -182,23 +159,12 @@ protected:
// file
public:
void file_eval_gather(ScatterLock *lock);
void try_file_eval(ScatterLock *lock);
void file_eval(ScatterLock *lock);
protected:
void handle_file_lock(ScatterLock *lock, MLock *m);
bool file_sync(ScatterLock *lock);
void file_lock(ScatterLock *lock);
void file_mixed(ScatterLock *lock);
void file_loner(ScatterLock *lock);
bool file_rdlock_try(ScatterLock *lock, Context *con);
bool file_rdlock_start(ScatterLock *lock, MDRequest *mut);
void file_rdlock_finish(ScatterLock *lock, Mutation *mut);
bool file_wrlock_force(ScatterLock *lock, Mutation *mut);
bool file_wrlock_start(ScatterLock *lock, MDRequest *mut);
void file_wrlock_finish(ScatterLock *lock, Mutation *mut);
bool file_xlock_start(ScatterLock *lock, MDRequest *mut);
void file_xlock_finish(ScatterLock *lock, Mutation *mut);
void file_excl(ScatterLock *lock);
xlist<ScatterLock*> updated_filelocks;
public:

View File

@ -3500,7 +3500,7 @@ void MDCache::process_reconnected_caps()
in->loner_cap = -1;
if (issued & ((CEPH_CAP_GRDCACHE|CEPH_CAP_GWRBUFFER) << CEPH_CAP_SFILE)) {
in->filelock.set_state(LOCK_EXCL);
in->choose_loner();
in->try_choose_loner();
} else {
in->filelock.set_state(LOCK_MIX);
}