misc fixes for mds
cover misc fixes for mds
From: "Yan, Zheng" <[email protected]>
These patches are also in:
git://github.com/ukernel/ceph.git wip-mds
These patches together with my kernel patches have been tested for about two weeks. They passed several 48+ hours stress tests, no request hang was found.
Regards
Yan, Zheng
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/6 mds: fix cap revoke confirmation
From: "Yan, Zheng" <[email protected]>
There are several issues in the Capability::confirm_receipt()
1. when receiving a client caps message with 'seq == last_sent', it doesn't mean we finish revoking caps. The client can send caps message that only flushes dirty metadata.
2. When receiving a client caps message with 'seq == N', we should forget pending revocations whose seq numbers are less than N. This is because, when revoking caps, we create a revoke_info structure and set its seq number to 'last_sent', then increase the 'last_sent'.
3. When client actively releases caps (by request), the code only works for the 'seq == last_sent' case. If there are pending revocations, we should update them as if the release message is received before we revoke the corresponding caps.
--- src/mds/Capability.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
src/mds/Capability.h +5 -3
@@ -171,14 +171,16 @@ public: }void confirm_receipt (ceph_seq_t seq,unsigned caps) {if (seq == last_sent) { - _pending = caps; _revokes.clear (); _issued = caps; +// don't add bits + _pending &= caps; }else {// can i forget any revocations? -while (!_revokes.empty () && - _revokes.front ().seq <= seq) +while (!_revokes.empty () && _revokes.front ().seq < seq) _revokes.pop_front (); +if (!_revokes.empty () && _revokes.front ().seq == seq) + _revokes.begin ()->before = caps;_calc_issued (); }//check_rdcaps_list();
Signature · 1 line
1.8.1.4
PATCH 2/6 mds: revoke GSHARED cap when finishing xlock
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
If lock state is LOCK_XLOCKDONE, the xlocker can have GSHARED cap. So when finishing xlock, we may need to revoke the GSHARED cap.
In most cases Locker::_finish_xlock() directly set lock state to LOCK_LOCK or LOCK_EXCL, which hides the issue. If 'num_rdlock > 0' or 'num_wrlock > 0' when finishing xlock, the issue reveals. (lock get stuck in LOCK_XLOCKDONE forever)
The fix is always call Locker::_finish_xlock() when xlock count reaches zero. _finish_xlock() checks if it can change lock state to LOCK_EXCL immediately. If not, it uses Locker::eval_gather() to transit lock state.
Another change of this patch is avoid changing lock state to LOCK_LOCK directly. because lock in LOCK_XLOCK_DONE state allows GSHARED cap, lock in LOCK_LOCK state does not.
--- src/mds/Locker.cc | 57 +++++++++++++++++++++++++------------------------------ src/mds/Locker.h | 2 +- 2 files changed, 27 insertions(+), 32 deletions(-)
src/mds/Locker.cc +26 -31
@@ -546,9 +546,7 @@ void Locker::cancel_locking(Mutation *mut, set<CInode*> *pneed_issue) 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); + _finish_xlock(lock, -1, &need_issue); if (need_issue) pneed_issue->insert(static_cast<CInode *>(lock->get_parent())); }
@@ -1458,19 +1456,29 @@ bool Locker::xlock_start(SimpleLock *lock, MDRequest *mut) } } -void Locker::_finish_xlock(SimpleLock *lock, bool *pneed_issue) +void Locker::_finish_xlock(SimpleLock *lock, client_t xlocker, bool *pneed_issue) { assert(!lock->is_stable()); - if (lock->get_type() != CEPH_LOCK_DN && (static_cast<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); + if (lock->get_num_rdlocks() == 0 && + lock->get_num_wrlocks() == 0 && + lock->get_num_client_lease() == 0 && + lock->get_type() != CEPH_LOCK_DN) { + CInode *in = static_cast<CInode*>(lock->get_parent()); + client_t loner = in->get_target_loner(); + if (loner >= 0 && (xlocker < 0 || xlocker == loner)) { + lock->set_state(LOCK_EXCL); + lock->get_parent()->auth_unpin(lock); + lock->finish_waiters(SimpleLock::WAIT_STABLE|SimpleLock::WAIT_WR|SimpleLock::WAIT_RD); + if (lock->get_cap_shift()) + *pneed_issue = true; + if (lock->get_parent()->is_auth() && + lock->is_stable()) + try_eval(lock, pneed_issue); + return; + } + } + // the xlocker may have CEPH_CAP_GSHARED, need to revoke it if next state is LOCK_LOCK + eval_gather(lock, true, pneed_issue); } void Locker::xlock_finish(SimpleLock *lock, Mutation *mut, bool *pneed_issue)
@@ -1481,6 +1489,8 @@ void Locker::xlock_finish(SimpleLock *lock, Mutation *mut, bool *pneed_issue) dout(10) << "xlock_finish on " << *lock << " " << *lock->get_parent() << dendl; + client_t xlocker = lock->get_xlock_by_client(); + // drop ref lock->put_xlock(); assert(mut);
@@ -1508,24 +1518,9 @@ void Locker::xlock_finish(SimpleLock *lock, Mutation *mut, bool *pneed_issue) SimpleLock::WAIT_WR | SimpleLock::WAIT_RD, 0); } else { - if (lock->get_num_xlocks() == 0 && - lock->get_num_rdlocks() == 0 && - lock->get_num_wrlocks() == 0 && - lock->get_num_client_lease() == 0) { - _finish_xlock(lock, &do_issue); - } - - // others waiting? - lock->finish_waiters(SimpleLock::WAIT_STABLE | - SimpleLock::WAIT_WR | - SimpleLock::WAIT_RD, 0); + if (lock->get_num_xlocks() == 0) + _finish_xlock(lock, xlocker, &do_issue); } - - // eval? - if (!lock->is_stable()) - eval_gather(lock, false, &do_issue); - else if (lock->get_parent()->is_auth()) - try_eval(lock, &do_issue); if (do_issue) { CInode *in = static_cast<CInode*>(lock->get_parent());
src/mds/Locker.h +1 -1
@@ -143,7 +143,7 @@ public:void remote_wrlock_finish (SimpleLock *lock,int target,Mutation *mut);bool xlock_start (SimpleLock *lock,MDRequest *mut); -void _finish_xlock (SimpleLock *lock,bool *pneed_issue); +void _finish_xlock (SimpleLock *lock,client_t xlocker,bool *pneed_issue);void xlock_finish (SimpleLock *lock,Mutation *mut,bool *pneed_issue);void xlock_export (SimpleLock *lock,Mutation *mut);
Signature · 1 line
1.8.1.4
PATCH 3/6 mds: remove "type != CEPH_LOCK_DN" check in Locker::cancel_locking()
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
For acquiring/cancelling xlock, the lock state transitions for dentry lock and other types of locks are the same. So I think the "type != CEPH_LOCK_DN" check doesn't make sense.
--- src/mds/Locker.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
src/mds/Locker.cc +5 -7
@@ -543,13 +543,11 @@ void Locker::cancel_locking(Mutation *mut, set<CInode*> *pneed_issue) dout(10) << "cancel_locking " << *lock << " on " << *mut << dendl; 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, -1, &need_issue); - if (need_issue) - pneed_issue->insert(static_cast<CInode *>(lock->get_parent())); - } + bool need_issue = false; + if (lock->get_state() == LOCK_PREXLOCK) + _finish_xlock(lock, -1, &need_issue); + if (need_issue) + pneed_issue->insert(static_cast<CInode *>(lock->get_parent())); } mut->finish_locking(lock); }
Signature · 1 line
1.8.1.4
PATCH 4/6 mds: handle "state == LOCK_LOCK_XLOCK" when cancelling xlock
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
If we find lock state is LOCK_LOCK_XLOCK when cancelling xlock, set lock state to LOCK_XLOCK_DONE and call Locker::eval_gather(). This makes sure the lock will eventually transit to a stable state. (LOCK_XLOCK_DONE's next state is stable)
--- src/mds/Locker.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
src/mds/Locker.cc +10 -2
@@ -544,8 +544,13 @@ void Locker::cancel_locking(Mutation *mut, set<CInode*> *pneed_issue) if (lock->get_parent()->is_auth()) { bool need_issue = false; - if (lock->get_state() == LOCK_PREXLOCK) + if (lock->get_state() == LOCK_PREXLOCK) { _finish_xlock(lock, -1, &need_issue); + } else if (lock->get_state() == LOCK_LOCK_XLOCK && + lock->get_num_xlocks() == 0) { + lock->set_state(LOCK_XLOCKDONE); + eval_gather(lock, true, &need_issue); + } if (need_issue) pneed_issue->insert(static_cast<CInode *>(lock->get_parent())); }
@@ -1516,8 +1521,11 @@ void Locker::xlock_finish(SimpleLock *lock, Mutation *mut, bool *pneed_issue) SimpleLock::WAIT_WR | SimpleLock::WAIT_RD, 0); } else { - if (lock->get_num_xlocks() == 0) + if (lock->get_num_xlocks() == 0) { + if (lock->get_state() == LOCK_LOCK_XLOCK) + lock->set_state(LOCK_XLOCKDONE); _finish_xlock(lock, xlocker, &do_issue); + } } if (do_issue) {
Signature · 1 line
1.8.1.4
PATCH 5/6 mds: change LOCK_SCAN to unstable state
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
commit 0071b8e75b (mds: stay in SCAN state in file_eval) makes Locker::file_eval() ignore lock in LOCK_SCAN state. If there is no request changes the lock state, the lock can be stuck in LOCK_SCAN state forever. This can cause client read/write hang because lock in LOCK_SCAN state does not allow Frw caps.
The fix is change LOCK_SCAN to a unstable state. Thank to the CInode::STATE_RECOVERING check in Locker::eval_gather(), the lock stays in the SCAN state while file is being recovering. The lock will transit to a stable state once the recovery finishes.
--- src/mds/Locker.cc | 18 +++++------------- src/mds/MDCache.cc | 1 + src/mds/locks.c | 3 +-- src/mds/locks.h | 1 - 4 files changed, 7 insertions(+), 16 deletions(-)
src/mds/Locker.cc +5 -13
@@ -3441,7 +3441,6 @@ bool Locker::simple_sync(SimpleLock *lock, bool *need_issue) switch (lock->get_state()) { case LOCK_MIX: lock->set_state(LOCK_MIX_SYNC); break; - case LOCK_SCAN: case LOCK_LOCK: lock->set_state(LOCK_LOCK_SYNC); break; case LOCK_XSYN: lock->set_state(LOCK_XSYN_SYNC); break; case LOCK_EXCL: lock->set_state(LOCK_EXCL_SYNC); break;
@@ -3518,7 +3517,6 @@ void Locker::simple_excl(SimpleLock *lock, bool *need_issue) in = static_cast<CInode *>(lock->get_parent()); switch (lock->get_state()) { - case LOCK_SCAN: case LOCK_LOCK: lock->set_state(LOCK_LOCK_EXCL); break; case LOCK_SYNC: lock->set_state(LOCK_SYNC_EXCL); break; case LOCK_XSYN: lock->set_state(LOCK_XSYN_EXCL); break;
@@ -3577,7 +3575,6 @@ void Locker::simple_lock(SimpleLock *lock, bool *need_issue) int old_state = lock->get_state(); switch (lock->get_state()) { - case LOCK_SCAN: lock->set_state(LOCK_SCAN_LOCK); break; case LOCK_SYNC: lock->set_state(LOCK_SYNC_LOCK); break; case LOCK_XSYN: file_excl(static_cast<ScatterLock*>(lock), need_issue);
@@ -4163,10 +4160,6 @@ void Locker::file_eval(ScatterLock *lock, bool *need_issue) if (lock->get_parent()->is_freezing_or_frozen()) return; - // wait for scan - if (lock->get_state() == LOCK_SCAN) - return; - // excl -> *? if (lock->get_state() == LOCK_EXCL) { dout(20) << " is excl" << dendl;
@@ -4353,7 +4346,6 @@ void Locker::file_excl(ScatterLock *lock, bool *need_issue) switch (lock->get_state()) { case LOCK_SYNC: lock->set_state(LOCK_SYNC_EXCL); break; case LOCK_MIX: lock->set_state(LOCK_MIX_EXCL); break; - case LOCK_SCAN: case LOCK_LOCK: lock->set_state(LOCK_LOCK_EXCL); break; case LOCK_XSYN: lock->set_state(LOCK_XSYN_EXCL); break; default: assert(0);
@@ -4464,12 +4456,12 @@ void Locker::file_recover(ScatterLock *lock) issue_caps(in); gather++; } - if (gather) { - lock->get_parent()->auth_pin(lock); - } else { - lock->set_state(LOCK_SCAN); + + lock->set_state(LOCK_SCAN); + if (gather) + in->state_set(CInode::STATE_NEEDSRECOVER); + else mds->mdcache->queue_file_recover(in); - } }
src/mds/MDCache.cc +1 -0
@@ -5718,6 +5718,7 @@ void MDCache::identify_files_to_recover(vector<CInode*>& recover_q, vector<CInod } if (recover) { + in->auth_pin(&in->filelock); in->filelock.set_state(LOCK_PRE_SCAN); recover_q.push_back(in);
src/mds/locks.c +1 -2
@@ -122,8 +122,7 @@ const struct sm_state_t filelock[LOCK_MAX] = { [LOCK_EXCL_XSYN] = { LOCK_XSYN, false, LOCK_LOCK, 0, 0, XCL, 0, 0, 0, 0, 0,CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0 }, [LOCK_PRE_SCAN] = { LOCK_SCAN, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, - [LOCK_SCAN] = { 0, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, - [LOCK_SCAN_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, + [LOCK_SCAN] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, };const struct sm_t sm_filelock = {
src/mds/locks.h +0 -1
@@ -86,7 +86,6 @@ enum {LOCK_PRE_SCAN ,LOCK_SCAN , -LOCK_SCAN_LOCK , LOCK_SNAP_SYNC,
Signature · 1 line
1.8.1.4
PATCH 6/6 mds: don't issue caps while session is stale
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
Locker::issue_caps() does not issue new caps to stale client, CInode::encode_inodestat() should have the same logical.
--- src/mds/CInode.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/mds/CInode.cc +3 -1
@@ -2733,10 +2733,12 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session, // 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 = session->is_stale() || + (realm && dir_realm && realm != dir_realm) || is_frozen() || state_test(CInode::STATE_EXPORTINGCAPS); if (no_caps) dout(20) << "encode_inodestat no caps" + << (session->is_stale()?", session stale ":"") << ((realm && dir_realm && realm != dir_realm)?", snaprealm differs ":"") << (state_test(CInode::STATE_EXPORTINGCAPS)?", exporting caps":"") << (is_frozen()?", frozen inode":"") << dendl;
Signature · 1 line
1.8.1.4
PATCH 1/3 ceph: introduce i_truncate_mutex
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
I encountered below deadlock when running fsstress
wmtruncate work truncate MDS
--------------- ------------------ --------------------------
lock i_mutex
<- truncate file
lock i_mutex (blocked)
<- revoking Fcb (filelock to MIX)
send request ->
handle request (xlock filelock)
At the initial time, there are some dirty pages in the page cache. When the kclient receives the truncate message, it reduces inode size and creates some 'out of i_size' dirty pages. wmtruncate work can't truncate these dirty pages because it's blocked by the i_mutex. Later when the kclient receives the cap message that revokes Fcb caps, It can't flush all dirty pages because writepages() only flushes dirty pages within the inode size.
When the MDS handles the 'truncate' request from kclient, it waits for the filelock to become stable. But the filelock is stuck in unstable state because it can't finish revoking kclient's Fcb caps.
The truncate pagecache locking has already caused lots of trouble for use. I think it's time simplify it by introducing a new mutex. We use the new mutex to prevent concurrent truncate_inode_pages(). There is no need to worry about race between buffered write and truncate_inode_pages(), because our "get caps" mechanism prevents them from concurrent execution.
--- fs/ceph/caps.c | 4 ---- fs/ceph/file.c | 8 +++++++- fs/ceph/inode.c | 39 ++++++++++++++++++++++----------------- fs/ceph/super.h | 1 + 4 files changed, 30 insertions(+), 22 deletions(-)
fs/ceph/caps.c +0 -4
@@ -2072,11 +2072,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,/* finish pending truncate */ while (ci->i_truncate_pending) {spin_unlock (&ci->i_ceph_lock); -if (!(need &CEPH_CAP_FILE_WR )) -mutex_lock (&inode->i_mutex);__ceph_do_pending_vmtruncate (inode); -if (!(need &CEPH_CAP_FILE_WR )) -mutex_unlock (&inode->i_mutex);spin_lock (&ci->i_ceph_lock); }
fs/ceph/file.c +7 -1
@@ -769,6 +769,13 @@ retry_snap: written =ceph_sync_write (file, iov->iov_base, count, pos, &iocb->ki_pos); }else { +/* +* No need to acquire the i_truncate_mutex. Because +* the MDS revokes Fwb caps before sending truncate +* message to us. We can't get Fwb cap while there +* are pending vmtruncate. So write and vmtruncate +* can not run at the same time +*/ written =generic_file_buffered_write (iocb, iov, nr_segs, pos, &iocb->ki_pos, count,0 );
@@ -822,7 +829,6 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int whence)int ret;mutex_lock (&inode->i_mutex); -__ceph_do_pending_vmtruncate (inode);if (whence ==SEEK_END || whence ==SEEK_DATA || whence ==SEEK_HOLE ) { ret =ceph_do_getattr (inode,CEPH_STAT_CAP_SIZE );
fs/ceph/inode.c +22 -17
@@ -344,6 +344,7 @@ struct inode *ceph_alloc_inode(struct super_block *sb)for (i =0 ; i <CEPH_FILE_MODE_NUM ; i++) ci->i_nr_by_mode[i] =0 ; +mutex_init (&ci->i_truncate_mutex); ci->i_truncate_seq =0 ; ci->i_truncate_size =0 ; ci->i_truncate_pending =0 ;
@@ -455,16 +456,20 @@ int ceph_fill_file_size(struct inode *inode, int issued,dout ("truncate_seq %u -> %u\n" , ci->i_truncate_seq, truncate_seq); ci->i_truncate_seq = truncate_seq; + +/* the MDS should have revoked these caps */ +WARN_ON_ONCE (issued & (CEPH_CAP_FILE_EXCL | +CEPH_CAP_FILE_RD | +CEPH_CAP_FILE_WR | +CEPH_CAP_FILE_LAZYIO ));/* * If we hold relevant caps, or in the case where we're * not the only client referencing this file and we * don't hold those caps, then we need to check whether * the file is either opened or mmaped */ -if ((issued & (CEPH_CAP_FILE_CACHE |CEPH_CAP_FILE_RD | -CEPH_CAP_FILE_WR |CEPH_CAP_FILE_BUFFER | -CEPH_CAP_FILE_EXCL | -CEPH_CAP_FILE_LAZYIO )) || +if ((issued & (CEPH_CAP_FILE_CACHE | +CEPH_CAP_FILE_BUFFER )) ||mapping_mapped (inode->i_mapping) ||__ceph_caps_file_wanted (ci)) { ci->i_truncate_pending++;
@@ -1419,18 +1424,20 @@ static void ceph_invalidate_work(struct work_struct *work)u32 orig_gen;int check =0 ; +mutex_lock (&ci->i_truncate_mutex);spin_lock (&ci->i_ceph_lock);dout ("invalidate_pages %p gen %d revoking %d\n" , inode, ci->i_rdcache_gen, ci->i_rdcache_revoking);if (ci->i_rdcache_revoking != ci->i_rdcache_gen) {/* nevermind! */ spin_unlock (&ci->i_ceph_lock); +mutex_unlock (&ci->i_truncate_mutex); goto out; } orig_gen = ci->i_rdcache_gen;spin_unlock (&ci->i_ceph_lock); -truncate_inode_pages (&inode->i_data,0 ); +truncate_inode_pages (inode->i_mapping,0 );spin_lock (&ci->i_ceph_lock); if (orig_gen == ci->i_rdcache_gen &&
@@ -1445,6 +1452,7 @@ static void ceph_invalidate_work(struct work_struct *work) ci->i_rdcache_revoking); }spin_unlock (&ci->i_ceph_lock); +mutex_unlock (&ci->i_truncate_mutex);if (check)ceph_check_caps (ci,0 ,NULL );
@@ -1465,16 +1473,7 @@ static void ceph_vmtruncate_work(struct work_struct *work)struct inode *inode = &ci->vfs_inode;dout ("vmtruncate_work %p\n" , inode); -if (!mutex_trylock (&inode->i_mutex)) { -/* -* the i_mutex can be hold by a writer who is waiting for -* caps. wake up waiters, they will do pending vmtruncate. -*/ -wake_up_all (&ci->i_cap_wq); -mutex_lock (&inode->i_mutex); - }__ceph_do_pending_vmtruncate (inode); -mutex_unlock (&inode->i_mutex);iput (inode); }
@@ -1507,11 +1506,13 @@ void __ceph_do_pending_vmtruncate(struct inode *inode)u64 to;int wrbuffer_refs, finish =0 ; +mutex_lock (&ci->i_truncate_mutex); retry:spin_lock (&ci->i_ceph_lock);if (ci->i_truncate_pending ==0 ) {dout ("__do_pending_vmtruncate %p none pending\n" , inode);spin_unlock (&ci->i_ceph_lock); +mutex_unlock (&ci->i_truncate_mutex);return ; }
@@ -1528,6 +1529,9 @@ retry: goto retry; } +/* there should be no reader or writer */ +WARN_ON_ONCE (ci->i_rd_ref || ci->i_wr_ref); + to = ci->i_truncate_size; wrbuffer_refs = ci->i_wrbuffer_ref; dout("__do_pending_vmtruncate %p (%d) to %lld\n", inode,
@@ -1545,6 +1549,8 @@ retry:if (!finish) goto retry; +mutex_unlock (&ci->i_truncate_mutex); +if (wrbuffer_refs ==0 )ceph_check_caps (ci,CHECK_CAPS_AUTHONLY ,NULL );
@@ -1593,8 +1599,6 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)if (ceph_snap (inode) !=CEPH_NOSNAP )return -EROFS ; -__ceph_do_pending_vmtruncate (inode); - err =inode_change_ok (inode, attr);if (err !=0 )return err;
@@ -1775,7 +1779,8 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr) ceph_cap_string(dirtied), mask);ceph_mdsc_put_request (req); -__ceph_do_pending_vmtruncate (inode); +if (mask &CEPH_SETATTR_SIZE ) +__ceph_do_pending_vmtruncate (inode);return err; out:spin_unlock (&ci->i_ceph_lock);
fs/ceph/super.h +1 -0
@@ -288,6 +288,7 @@ struct ceph_inode_info {int i_nr_by_mode[CEPH_FILE_MODE_NUM ];/* open file counts */ +struct mutex i_truncate_mutex;u32 i_truncate_seq;/* last truncate to smaller size */ u64 i_truncate_size;/* and the size we last truncated down to */ int i_truncate_pending;/* still need to call vmtruncate */
Signature · 1 line
1.8.1.4
PATCH 2/3 ceph: fix request max size
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
ceph_check_caps() requests new max size only when there is Fw cap. If we call check_max_size() while there is no Fw cap. It updates i_wanted_max_size and calls ceph_check_caps(), but ceph_check_caps() does nothing. Later when Fw cap is issued, we call check_max_size() again. But i_wanted_max_size is equal to 'endoff' at this time, so check_max_size() doesn't call ceph_check_caps() and we end up with waiting for the new max size forever.
The fix is duplicate ceph_check_caps()'s "request max size" code in check_max_size(), and make try_get_cap_refs() wait for the Fw cap before retry requesting new max size.
This patch also removes the "endoff > (inode->i_size << 1)" check in check_max_size(). It's useless because there is no corresponding logical in ceph_check_caps().
--- fs/ceph/caps.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
fs/ceph/caps.c +11 -7
@@ -2076,11 +2076,13 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,spin_lock (&ci->i_ceph_lock); } -if (need &CEPH_CAP_FILE_WR ) { + have =__ceph_caps_issued (ci, &implemented); + +if (have & need &CEPH_CAP_FILE_WR ) {if (endoff >=0 && endoff > (loff_t )ci->i_max_size) {dout ("get_cap_refs %p endoff %llu > maxsize %llu\n" , inode, endoff, ci->i_max_size); -if (endoff > ci->i_wanted_max_size) { +if (endoff > ci->i_requested_max_size) { *check_max =1 ; ret =1 ; }
@@ -2095,7 +2097,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, goto out; } } - have =__ceph_caps_issued (ci, &implemented);if ((have & need) == need) {/*
@@ -2137,14 +2138,17 @@ static void check_max_size(struct inode *inode, loff_t endoff)/* do we need to explicitly request a larger max_size? */ spin_lock (&ci->i_ceph_lock); -if ((endoff >= ci->i_max_size || - endoff > (inode->i_size <<1 )) && - endoff > ci->i_wanted_max_size) { +if (endoff >= ci->i_max_size && endoff > ci->i_wanted_max_size) {dout ("write %p at large endoff %llu, req max_size\n" , inode, endoff); ci->i_wanted_max_size = endoff; - check =1 ; } +/* duplicate ceph_check_caps()'s logical */ +if (ci->i_auth_cap && + (ci->i_auth_cap->issued &CEPH_CAP_FILE_WR ) && + ci->i_wanted_max_size > ci->i_max_size && + ci->i_wanted_max_size > ci->i_requested_max_size) + check =1 ;spin_unlock (&ci->i_ceph_lock);if (check)ceph_check_caps (ci,CHECK_CAPS_AUTHONLY ,NULL );
Signature · 1 line
1.8.1.4
PATCH 3/3 ceph: rework trim caps code
In reply to Yan, ZhengFrom: "Yan, Zheng" <[email protected]>
The trim caps code that handles SESSION_RECALL_STATE message has two issues. First, it uses d_prune_aliases() to prune dentries. This confuses our 'dir complete' check, because d_prune_aliases() unhashes dentries before calling our d_prune() callback. Second, it only prune dentries, inodes with zero reference are still in the icache unless there is memory pressure.
The fix is adding d_delete() and drop_inode() VFS callback. VFS calls our d_delete()/drop_inode() callback when a dentry/inode's last reference is dropped. If true is returned, VFS drop the dentry/inode from the cache. When handling SESSION_RECALL_STATE message, we mark inode with CEPH_I_TRIMCAPS flag. Our callbacks check the flag and session->s_trim_caps to decide if VFS should drop a dentry/inode. To trim an inode, we just need to reference dentries associated with the inode, then release them.
--- fs/ceph/caps.c | 30 ++++++++++++++++++++++++++++++ fs/ceph/dir.c | 12 ++++++++++++ fs/ceph/inode.c | 11 +++++++++++ fs/ceph/mds_client.c | 37 ++++++++++++++++++++++++++++++------- fs/ceph/mds_client.h | 4 ++-- fs/ceph/super.c | 1 + fs/ceph/super.h | 3 +++ 7 files changed, 89 insertions(+), 9 deletions(-)
fs/ceph/caps.c +30 -0
@@ -882,6 +882,36 @@ int __ceph_caps_mds_wanted(struct ceph_inode_info *ci) }/* +* Used by ceph_d_delete()/ceph_drop_inode(). check if we should drop +* the inode. +*/ +int ceph_trim_caps (struct ceph_inode_info *ci,int drop_inode) +{ +struct ceph_cap *cap; +struct rb_node *p; +int ret =0 ; + +if (!spin_trylock (&ci->i_ceph_lock)) +return 0 ; + +if (ci->i_ceph_flags &CEPH_I_TRIMCAPS ) { +for (p =rb_first (&ci->i_caps); p; p =rb_next (p)) { + cap = rb_entry(p, struct ceph_cap, ci_node); +if (atomic_read (&cap->session->s_trim_caps) <=0 ) +continue ; +if (drop_inode) +atomic_dec (&cap->session->s_trim_caps); + ret =1 ; + } +if (!ret) + ci->i_ceph_flags &= ~CEPH_I_TRIMCAPS ; + } + +spin_unlock (&ci->i_ceph_lock); +return ret; +} + +/* * called under i_ceph_lock */ static int __ceph_is_any_caps (struct ceph_inode_info *ci)
fs/ceph/dir.c +12 -0
@@ -1043,6 +1043,17 @@ static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags)return valid; } +static int ceph_d_delete (const struct dentry *dentry) +{ +if (dentry->d_inode) { +struct ceph_inode_info *ci =ceph_inode (dentry->d_inode); +/* need trim caps? */ +if (ci->i_ceph_flags &CEPH_I_TRIMCAPS ) +return ceph_trim_caps (ci, false); + } +return 0 ; +} +/* * Release our ceph_dentry_info. */
@@ -1300,6 +1311,7 @@ const struct inode_operations ceph_dir_iops = {const struct dentry_operations ceph_dentry_ops = { .d_revalidate = ceph_d_revalidate, + .d_delete = ceph_d_delete, .d_release = ceph_d_release, .d_prune = ceph_d_prune, };
fs/ceph/inode.c +11 -0
@@ -431,6 +431,17 @@ void ceph_destroy_inode(struct inode *inode)call_rcu (&inode->i_rcu, ceph_i_callback); } +int ceph_drop_inode (struct inode *inode) +{ +struct ceph_inode_info *ci =ceph_inode (inode); +int ret =generic_drop_inode (inode); + +/* need trim caps? */ +if (!ret && (ci->i_ceph_flags &CEPH_I_TRIMCAPS )) + ret =ceph_trim_caps (ci, true); + +return ret ; +}/* * Helpers to fill in size, ctime, mtime, and atime. We have to be
fs/ceph/mds_client.c +30 -7
@@ -435,7 +435,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, s->s_renew_seq =0 ;INIT_LIST_HEAD (&s->s_caps); s->s_nr_caps =0 ; - s->s_trim_caps =0 ; +atomic_set (&s->s_trim_caps,0 );atomic_set (&s->s_ref,1 );INIT_LIST_HEAD (&s->s_waiting);INIT_LIST_HEAD (&s->s_unsafe);
@@ -1207,9 +1207,10 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) {struct ceph_mds_session *session = arg;struct ceph_inode_info *ci =ceph_inode (inode); +struct dentry *dentry;int used, oissued, mine; -if (session->s_trim_caps <=0 ) +if (atomic_read (&session->s_trim_caps) <=0 )return -1 ;spin_lock (&ci->i_ceph_lock);
@@ -1225,16 +1226,39 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg)if ((used & ~oissued) & mine) goto out;/* we need these caps */ - session->s_trim_caps--;if (oissued) {/* we aren't the only cap.. just remove us */ __queue_cap_release (session,ceph_ino (inode), cap->cap_id, cap->mseq, cap->issue_seq);__ceph_remove_cap (cap); +atomic_dec (&session->s_trim_caps); }else {/* try to drop referring dentries */ + ci->i_ceph_flags |=CEPH_I_TRIMCAPS ;spin_unlock (&ci->i_ceph_lock); -d_prune_aliases (inode); +/* +* can't use d_prune_aliases(), because it unhashes dentries +* before calling ceph_d_prune(). +*/ +restart: +spin_lock (&inode->i_lock); +hlist_for_each_entry (dentry, &inode->i_dentry, d_alias) { +spin_lock (&dentry->d_lock); +if (!dentry->d_count) { +dget_dlock (dentry); +spin_unlock (&dentry->d_lock); +spin_unlock (&inode->i_lock); +/* +* our d_delete callback returns true when +* CEPH_I_TRIMCAPS is set. This makes VFS +* drop the dentry. +*/ +dput (dentry); + goto restart; + } +spin_unlock (&dentry->d_lock); + } +spin_unlock (&inode->i_lock);dout ("trim_caps_cb %p cap %p pruned, count now %d\n" , inode, cap,atomic_read (&inode->i_count));return 0 ;
@@ -1257,12 +1281,11 @@ static int trim_caps(struct ceph_mds_client *mdsc,dout ("trim_caps mds%d start: %d / %d, trim %d\n" , session->s_mds, session->s_nr_caps, max_caps, trim_caps);if (trim_caps >0 ) { - session->s_trim_caps = trim_caps; +atomic_set (&session->s_trim_caps, trim_caps);iterate_session_caps (session, trim_caps_cb, session);dout ("trim_caps mds%d done: %d / %d, trimmed %d\n" , session->s_mds, session->s_nr_caps, max_caps, - trim_caps - session->s_trim_caps); - session->s_trim_caps =0 ; + trim_caps -atomic_read (&session->s_trim_caps)); }return 0 ; }
fs/ceph/mds_client.h +2 -2
@@ -130,8 +130,8 @@ struct ceph_mds_session {/* protected by s_cap_lock */ spinlock_t s_cap_lock;struct list_head s_caps;/* all caps issued by this session */ -int s_nr_caps, s_trim_caps; -int s_num_cap_releases; +int s_nr_caps, s_num_cap_releases; +atomic_t s_trim_caps;struct list_head s_cap_releases;/* waiting cap_release messages */ struct list_head s_cap_releases_done;/* ready to send */ struct ceph_cap *s_cap_iterator;
fs/ceph/super.c +1 -0
@@ -655,6 +655,7 @@ static const struct super_operations ceph_super_ops = { .alloc_inode = ceph_alloc_inode, .destroy_inode = ceph_destroy_inode, .write_inode = ceph_write_inode, + .drop_inode = ceph_drop_inode, .sync_fs = ceph_sync_fs, .put_super = ceph_put_super, .show_options = ceph_show_options,
fs/ceph/super.h +3 -0
@@ -421,6 +421,7 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,/* * Ceph inode. */ +#define CEPH_I_TRIMCAPS 1/* trim caps when possible */ #define CEPH_I_NODELAY 4/* do not delay cap release */ #define CEPH_I_FLUSH 8/* do not delay flush of dirty metadata */ #define CEPH_I_NOFLUSH 16/* do not flush dirty caps */
@@ -487,6 +488,7 @@ extern int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented);extern int __ceph_caps_issued_mask (struct ceph_inode_info *ci,int mask,int t);extern int __ceph_caps_issued_other (struct ceph_inode_info *ci,struct ceph_cap *cap); +extern int ceph_trim_caps (struct ceph_inode_info *ci,int drop_inode);static inline int ceph_caps_issued (struct ceph_inode_info *ci) {
@@ -675,6 +677,7 @@ extern const struct inode_operations ceph_file_iops;extern struct inode *ceph_alloc_inode (struct super_block *sb);extern void ceph_destroy_inode (struct inode *inode); +extern int ceph_drop_inode (struct inode *inode);extern struct inode *ceph_get_inode (struct super_block *sb,struct ceph_vino vino);
Signature · 1 line
1.8.1.4
Re: [PATCH 3/3] ceph: rework trim caps code
Did this patch get dropped on purpose? I also don't see it in our testing branch.
-Greg
Software Engineer #42 @ http://inktank.com | http://ceph.com
Quoted 266 lines · Zheng
From: "Yan, Zheng" <[email protected]>
The trim caps code that handles
SESSION_RECALL_STATEmessage has two issues. First, it usesd_prune_aliases()to prune dentries. This confuses our 'dir complete' check, becaused_prune_aliases()unhashes dentries before calling ourd_prune()callback. Second, it only prune dentries, inodes with zero reference are still in the icache unless there is memory pressure.The fix is adding
d_delete()anddrop_inode()VFS callback. VFS calls our d_delete()/drop_inode() callback when a dentry/inode's last reference is dropped. If true is returned, VFS drop the dentry/inode from the cache. When handlingSESSION_RECALL_STATEmessage, we mark inode withCEPH_I_TRIMCAPSflag. Our callbacks check the flag andsession->s_trim_capsto decide if VFS should drop a dentry/inode. To trim an inode, we just need to reference dentries associated with the inode, then release them.Signed-off-by Yan, Zheng <[email protected]>--- fs/ceph/caps.c | 30 ++++++++++++++++++++++++++++++ fs/ceph/dir.c | 12 ++++++++++++ fs/ceph/inode.c | 11 +++++++++++ fs/ceph/mds_client.c | 37 ++++++++++++++++++++++++++++++------- fs/ceph/mds_client.h | 4 ++-- fs/ceph/super.c | 1 + fs/ceph/super.h | 3 +++ 7 files changed, 89 insertions(+), 9 deletions(-)fs/ceph/caps.c +30
-0@@ -882,6 +882,36 @@ int __ceph_caps_mds_wanted(struct ceph_inode_info *ci) }/* +* Used by ceph_d_delete()/ceph_drop_inode(). check if we should drop +* the inode. +*/ +int ceph_trim_caps (struct ceph_inode_info *ci,int drop_inode) +{ +struct ceph_cap *cap; +struct rb_node *p; +int ret =0 ; + +if (!spin_trylock (&ci->i_ceph_lock)) +return 0 ; + +if (ci->i_ceph_flags &CEPH_I_TRIMCAPS ) { +for (p =rb_first (&ci->i_caps); p; p =rb_next (p)) { + cap = rb_entry(p, struct ceph_cap, ci_node); +if (atomic_read (&cap->session->s_trim_caps) <=0 ) +continue ; +if (drop_inode) +atomic_dec (&cap->session->s_trim_caps); + ret =1 ; + } +if (!ret) + ci->i_ceph_flags &= ~CEPH_I_TRIMCAPS ; + } + +spin_unlock (&ci->i_ceph_lock); +return ret; +} + +/* * called under i_ceph_lock */ static int __ceph_is_any_caps (struct ceph_inode_info *ci)fs/ceph/dir.c +12
-0@@ -1043,6 +1043,17 @@ static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags)return valid; } +static int ceph_d_delete (const struct dentry *dentry) +{ +if (dentry->d_inode) { +struct ceph_inode_info *ci =ceph_inode (dentry->d_inode); +/* need trim caps? */ +if (ci->i_ceph_flags &CEPH_I_TRIMCAPS ) +return ceph_trim_caps (ci, false); + } +return 0 ; +} +/* * Release our ceph_dentry_info. */ @@ -1300,6 +1311,7 @@ const struct inode_operations ceph_dir_iops = {const struct dentry_operations ceph_dentry_ops = { .d_revalidate = ceph_d_revalidate, + .d_delete = ceph_d_delete, .d_release = ceph_d_release, .d_prune = ceph_d_prune, };fs/ceph/inode.c +11
-0@@ -431,6 +431,17 @@ void ceph_destroy_inode(struct inode *inode)call_rcu (&inode->i_rcu, ceph_i_callback); } +int ceph_drop_inode (struct inode *inode) +{ +struct ceph_inode_info *ci =ceph_inode (inode); +int ret =generic_drop_inode (inode); + +/* need trim caps? */ +if (!ret && (ci->i_ceph_flags &CEPH_I_TRIMCAPS )) + ret =ceph_trim_caps (ci, true); + +return ret ; +}/* * Helpers to fill in size, ctime, mtime, and atime. We have to be fs/ceph/mds_client.c +30
-7@@ -435,7 +435,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, s->s_renew_seq =0 ;INIT_LIST_HEAD (&s->s_caps); s->s_nr_caps =0 ; - s->s_trim_caps =0 ; +atomic_set (&s->s_trim_caps,0 );atomic_set (&s->s_ref,1 );INIT_LIST_HEAD (&s->s_waiting);INIT_LIST_HEAD (&s->s_unsafe);@@ -1207,9 +1207,10 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) {struct ceph_mds_session *session = arg;struct ceph_inode_info *ci =ceph_inode (inode); +struct dentry *dentry;int used, oissued, mine; -if (session->s_trim_caps <=0 ) +if (atomic_read (&session->s_trim_caps) <=0 )return -1 ;spin_lock (&ci->i_ceph_lock);@@ -1225,16 +1226,39 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg)if ((used & ~oissued) & mine) goto out;/* we need these caps */ - session->s_trim_caps--;if (oissued) {/* we aren't the only cap.. just remove us */ __queue_cap_release (session,ceph_ino (inode), cap->cap_id, cap->mseq, cap->issue_seq);__ceph_remove_cap (cap); +atomic_dec (&session->s_trim_caps); }else {/* try to drop referring dentries */ + ci->i_ceph_flags |=CEPH_I_TRIMCAPS ;spin_unlock (&ci->i_ceph_lock); -d_prune_aliases (inode); +/* +* can't use d_prune_aliases(), because it unhashes dentries +* before calling ceph_d_prune(). +*/ +restart: +spin_lock (&inode->i_lock); +hlist_for_each_entry (dentry, &inode->i_dentry, d_alias) { +spin_lock (&dentry->d_lock); +if (!dentry->d_count) { +dget_dlock (dentry); +spin_unlock (&dentry->d_lock); +spin_unlock (&inode->i_lock); +/* +* our d_delete callback returns true when +* CEPH_I_TRIMCAPS is set. This makes VFS +* drop the dentry. +*/ +dput (dentry); + goto restart; + } +spin_unlock (&dentry->d_lock); + } +spin_unlock (&inode->i_lock);dout ("trim_caps_cb %p cap %p pruned, count now %d\n" , inode, cap,atomic_read (&inode->i_count));return 0 ;@@ -1257,12 +1281,11 @@ static int trim_caps(struct ceph_mds_client *mdsc,dout ("trim_caps mds%d start: %d / %d, trim %d\n" , session->s_mds, session->s_nr_caps, max_caps, trim_caps);if (trim_caps >0 ) { - session->s_trim_caps = trim_caps; +atomic_set (&session->s_trim_caps, trim_caps);iterate_session_caps (session, trim_caps_cb, session);dout ("trim_caps mds%d done: %d / %d, trimmed %d\n" , session->s_mds, session->s_nr_caps, max_caps, - trim_caps - session->s_trim_caps); - session->s_trim_caps =0 ; + trim_caps -atomic_read (&session->s_trim_caps)); }return 0 ; }fs/ceph/mds_client.h +2
-2@@ -130,8 +130,8 @@ struct ceph_mds_session {/* protected by s_cap_lock */ spinlock_t s_cap_lock;struct list_head s_caps;/* all caps issued by this session */ -int s_nr_caps, s_trim_caps; -int s_num_cap_releases; +int s_nr_caps, s_num_cap_releases; +atomic_t s_trim_caps;struct list_head s_cap_releases;/* waiting cap_release messages */ struct list_head s_cap_releases_done;/* ready to send */ struct ceph_cap *s_cap_iterator;fs/ceph/super.c +1
-0@@ -655,6 +655,7 @@ static const struct super_operations ceph_super_ops = { .alloc_inode = ceph_alloc_inode, .destroy_inode = ceph_destroy_inode, .write_inode = ceph_write_inode, + .drop_inode = ceph_drop_inode, .sync_fs = ceph_sync_fs, .put_super = ceph_put_super, .show_options = ceph_show_options,fs/ceph/super.h +3
-1@@ -421,6 +421,7 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,/* * Ceph inode. */ +#define CEPH_I_TRIMCAPS 1/* trim caps when possible */ #define CEPH_I_NODELAY 4/* do not delay cap release */ #define CEPH_I_FLUSH 8/* do not delay flush of dirty metadata */ #define CEPH_I_NOFLUSH 16/* do not flush dirty caps */ @@ -487,6 +488,7 @@ extern int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented);extern int __ceph_caps_issued_mask (struct ceph_inode_info *ci,int mask,int t);extern int __ceph_caps_issued_other (struct ceph_inode_info *ci,struct ceph_cap *cap); +extern int ceph_trim_caps (struct ceph_inode_info *ci,int drop_inode);static inline int ceph_caps_issued (struct ceph_inode_info *ci) {@@ -675,6 +677,7 @@ extern const struct inode_operations ceph_file_iops;extern struct inode *ceph_alloc_inode (struct super_block *sb);extern void ceph_destroy_inode (struct inode *inode); +extern int ceph_drop_inode (struct inode *inode);extern struct inode *ceph_get_inode (struct super_block *sb,struct ceph_vino vino); --1.8.1.4
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ceph: rework trim caps code
Quoted 2 lines · Gregory Farnum
Did this patch get dropped on purpose? I also don't see it in our testing branch.
We fixed d_prune to be less lame instead. That patch is waiting for Al's attention on -fsdevel.
sage
Quoted 273 lines
-Greg
Software Engineer #42 @ http://inktank.com | http://ceph.comQuoted 266 lines · Zheng
From: "Yan, Zheng" <[email protected]>
The trim caps code that handles
SESSION_RECALL_STATEmessage has two issues. First, it usesd_prune_aliases()to prune dentries. This confuses our 'dir complete' check, becaused_prune_aliases()unhashes dentries before calling ourd_prune()callback. Second, it only prune dentries, inodes with zero reference are still in the icache unless there is memory pressure.The fix is adding
d_delete()anddrop_inode()VFS callback. VFS calls our d_delete()/drop_inode() callback when a dentry/inode's last reference is dropped. If true is returned, VFS drop the dentry/inode from the cache. When handlingSESSION_RECALL_STATEmessage, we mark inode withCEPH_I_TRIMCAPSflag. Our callbacks check the flag andsession->s_trim_capsto decide if VFS should drop a dentry/inode. To trim an inode, we just need to reference dentries associated with the inode, then release them.Signed-off-by Yan, Zheng <[email protected]>--- fs/ceph/caps.c | 30 ++++++++++++++++++++++++++++++ fs/ceph/dir.c | 12 ++++++++++++ fs/ceph/inode.c | 11 +++++++++++ fs/ceph/mds_client.c | 37 ++++++++++++++++++++++++++++++------- fs/ceph/mds_client.h | 4 ++-- fs/ceph/super.c | 1 + fs/ceph/super.h | 3 +++ 7 files changed, 89 insertions(+), 9 deletions(-)fs/ceph/caps.c +30
-0@@ -882,6 +882,36 @@ int __ceph_caps_mds_wanted(struct ceph_inode_info *ci) }/* +* Used by ceph_d_delete()/ceph_drop_inode(). check if we should drop +* the inode. +*/ +int ceph_trim_caps (struct ceph_inode_info *ci,int drop_inode) +{ +struct ceph_cap *cap; +struct rb_node *p; +int ret =0 ; + +if (!spin_trylock (&ci->i_ceph_lock)) +return 0 ; + +if (ci->i_ceph_flags &CEPH_I_TRIMCAPS ) { +for (p =rb_first (&ci->i_caps); p; p =rb_next (p)) { + cap = rb_entry(p, struct ceph_cap, ci_node); +if (atomic_read (&cap->session->s_trim_caps) <=0 ) +continue ; +if (drop_inode) +atomic_dec (&cap->session->s_trim_caps); + ret =1 ; + } +if (!ret) + ci->i_ceph_flags &= ~CEPH_I_TRIMCAPS ; + } + +spin_unlock (&ci->i_ceph_lock); +return ret; +} + +/* * called under i_ceph_lock */ static int __ceph_is_any_caps (struct ceph_inode_info *ci)fs/ceph/dir.c +12
-0@@ -1043,6 +1043,17 @@ static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags)return valid; } +static int ceph_d_delete (const struct dentry *dentry) +{ +if (dentry->d_inode) { +struct ceph_inode_info *ci =ceph_inode (dentry->d_inode); +/* need trim caps? */ +if (ci->i_ceph_flags &CEPH_I_TRIMCAPS ) +return ceph_trim_caps (ci, false); + } +return 0 ; +} +/* * Release our ceph_dentry_info. */ @@ -1300,6 +1311,7 @@ const struct inode_operations ceph_dir_iops = {const struct dentry_operations ceph_dentry_ops = { .d_revalidate = ceph_d_revalidate, + .d_delete = ceph_d_delete, .d_release = ceph_d_release, .d_prune = ceph_d_prune, };fs/ceph/inode.c +11
-0@@ -431,6 +431,17 @@ void ceph_destroy_inode(struct inode *inode)call_rcu (&inode->i_rcu, ceph_i_callback); } +int ceph_drop_inode (struct inode *inode) +{ +struct ceph_inode_info *ci =ceph_inode (inode); +int ret =generic_drop_inode (inode); + +/* need trim caps? */ +if (!ret && (ci->i_ceph_flags &CEPH_I_TRIMCAPS )) + ret =ceph_trim_caps (ci, true); + +return ret ; +}/* * Helpers to fill in size, ctime, mtime, and atime. We have to be fs/ceph/mds_client.c +30
-7@@ -435,7 +435,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, s->s_renew_seq =0 ;INIT_LIST_HEAD (&s->s_caps); s->s_nr_caps =0 ; - s->s_trim_caps =0 ; +atomic_set (&s->s_trim_caps,0 );atomic_set (&s->s_ref,1 );INIT_LIST_HEAD (&s->s_waiting);INIT_LIST_HEAD (&s->s_unsafe);@@ -1207,9 +1207,10 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) {struct ceph_mds_session *session = arg;struct ceph_inode_info *ci =ceph_inode (inode); +struct dentry *dentry;int used, oissued, mine; -if (session->s_trim_caps <=0 ) +if (atomic_read (&session->s_trim_caps) <=0 )return -1 ;spin_lock (&ci->i_ceph_lock);@@ -1225,16 +1226,39 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg)if ((used & ~oissued) & mine) goto out;/* we need these caps */ - session->s_trim_caps--;if (oissued) {/* we aren't the only cap.. just remove us */ __queue_cap_release (session,ceph_ino (inode), cap->cap_id, cap->mseq, cap->issue_seq);__ceph_remove_cap (cap); +atomic_dec (&session->s_trim_caps); }else {/* try to drop referring dentries */ + ci->i_ceph_flags |=CEPH_I_TRIMCAPS ;spin_unlock (&ci->i_ceph_lock); -d_prune_aliases (inode); +/* +* can't use d_prune_aliases(), because it unhashes dentries +* before calling ceph_d_prune(). +*/ +restart: +spin_lock (&inode->i_lock); +hlist_for_each_entry (dentry, &inode->i_dentry, d_alias) { +spin_lock (&dentry->d_lock); +if (!dentry->d_count) { +dget_dlock (dentry); +spin_unlock (&dentry->d_lock); +spin_unlock (&inode->i_lock); +/* +* our d_delete callback returns true when +* CEPH_I_TRIMCAPS is set. This makes VFS +* drop the dentry. +*/ +dput (dentry); + goto restart; + } +spin_unlock (&dentry->d_lock); + } +spin_unlock (&inode->i_lock);dout ("trim_caps_cb %p cap %p pruned, count now %d\n" , inode, cap,atomic_read (&inode->i_count));return 0 ;@@ -1257,12 +1281,11 @@ static int trim_caps(struct ceph_mds_client *mdsc,dout ("trim_caps mds%d start: %d / %d, trim %d\n" , session->s_mds, session->s_nr_caps, max_caps, trim_caps);if (trim_caps >0 ) { - session->s_trim_caps = trim_caps; +atomic_set (&session->s_trim_caps, trim_caps);iterate_session_caps (session, trim_caps_cb, session);dout ("trim_caps mds%d done: %d / %d, trimmed %d\n" , session->s_mds, session->s_nr_caps, max_caps, - trim_caps - session->s_trim_caps); - session->s_trim_caps =0 ; + trim_caps -atomic_read (&session->s_trim_caps)); }return 0 ; }fs/ceph/mds_client.h +2
-2@@ -130,8 +130,8 @@ struct ceph_mds_session {/* protected by s_cap_lock */ spinlock_t s_cap_lock;struct list_head s_caps;/* all caps issued by this session */ -int s_nr_caps, s_trim_caps; -int s_num_cap_releases; +int s_nr_caps, s_num_cap_releases; +atomic_t s_trim_caps;struct list_head s_cap_releases;/* waiting cap_release messages */ struct list_head s_cap_releases_done;/* ready to send */ struct ceph_cap *s_cap_iterator;fs/ceph/super.c +1
-0@@ -655,6 +655,7 @@ static const struct super_operations ceph_super_ops = { .alloc_inode = ceph_alloc_inode, .destroy_inode = ceph_destroy_inode, .write_inode = ceph_write_inode, + .drop_inode = ceph_drop_inode, .sync_fs = ceph_sync_fs, .put_super = ceph_put_super, .show_options = ceph_show_options,fs/ceph/super.h +3
-1@@ -421,6 +421,7 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,/* * Ceph inode. */ +#define CEPH_I_TRIMCAPS 1/* trim caps when possible */ #define CEPH_I_NODELAY 4/* do not delay cap release */ #define CEPH_I_FLUSH 8/* do not delay flush of dirty metadata */ #define CEPH_I_NOFLUSH 16/* do not flush dirty caps */ @@ -487,6 +488,7 @@ extern int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented);extern int __ceph_caps_issued_mask (struct ceph_inode_info *ci,int mask,int t);extern int __ceph_caps_issued_other (struct ceph_inode_info *ci,struct ceph_cap *cap); +extern int ceph_trim_caps (struct ceph_inode_info *ci,int drop_inode);static inline int ceph_caps_issued (struct ceph_inode_info *ci) {@@ -675,6 +677,7 @@ extern const struct inode_operations ceph_file_iops;extern struct inode *ceph_alloc_inode (struct super_block *sb);extern void ceph_destroy_inode (struct inode *inode); +extern int ceph_drop_inode (struct inode *inode);extern struct inode *ceph_get_inode (struct super_block *sb,struct ceph_vino vino); --1.8.1.4
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html