fs/ceph/caps: make __ceph_remove_cap() static
PATCH v2 2/4 fs/ceph: add helper function ceph_cap_is_removed()
In reply to Max KellermannHaving it as a wrapper allows replacing the implementation, which the next patch will do.
--- fs/ceph/caps.c | 6 ++---- fs/ceph/mds_client.c | 2 +- fs/ceph/super.h | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-)
fs/ceph/caps.c +2 -4
@@ -1128,8 +1128,7 @@ static void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release)struct ceph_mds_client *mdsc;int removed =0 ; -/* 'ci' being NULL means the remove have already occurred */ -if (!ci) { +if (ceph_cap_is_removed (cap)) {doutc (cl,"inode is NULL\n" );return ; }
@@ -1201,8 +1200,7 @@ void ceph_remove_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,struct ceph_inode_info *ci = cap->ci;struct ceph_fs_client *fsc; -/* 'ci' being NULL means the remove have already occurred */ -if (!ci) { +if (ceph_cap_is_removed (cap)) {doutc (mdsc->fsc->client,"inode is NULL\n" );return ; }
fs/ceph/mds_client.c +1 -1
@@ -1902,7 +1902,7 @@ int ceph_iterate_session_caps(struct ceph_mds_session *session,spin_lock (&session->s_cap_lock); p = p->next; -if (!cap->ci) { +if (ceph_cap_is_removed (cap)) {doutc (cl,"finishing cap %p removal\n" , cap);BUG_ON (cap->session != session); cap->session =NULL ;
fs/ceph/super.h +14 -0
@@ -1269,6 +1269,20 @@ extern void ceph_add_cap(struct inode *inode, unsigned issued, unsigned wanted, unsigned cap, unsigned seq, u64 realmino, int flags, struct ceph_cap **new_cap); + +/** +* Determine whether __ceph_remove_cap() has been called on this #cap +* (but the object has not yet been freed because it is protected by +* `ceph_mds_session.s_cap_iterator`). +* +* Caller must lock either `ceph_inode_info.i_ceph_lock` or +* `ceph_mds_session.s_cap_lock`. +*/ +static inline bool ceph_cap_is_removed (const struct ceph_cap *cap) +{ +return !cap->ci; +} +extern void ceph_remove_cap (struct ceph_mds_client *mdsc,struct ceph_cap *cap,bool queue_release);extern void __ceph_remove_caps (struct ceph_inode_info *ci);
Signature · 1 line
2.47.3
PATCH v2 3/4 fs/ceph/caps: mark cap remove with RB_CLEAR_NODE() instead of ci=NULL
In reply to Max Kellermann__ceph_remove_cap() erases the ceph_cap object from the RB tree, thus it seems natural to use RB_CLEAR_NODE() / RB_EMPTY_NODE() for the removal check.
---v1->v2:
- move code to new patch "add helper function ceph_cap_is_removed()"
- add locking documentation to ceph_cap.ci_node
- fix data race by calling RB_CLEAR_NODE() under s_cap_lock
--- fs/ceph/caps.c | 7 +++++-- fs/ceph/super.h | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-)
fs/ceph/caps.c +5 -2
@@ -1157,8 +1157,11 @@ static void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) cap->session =NULL ; removed =1 ; } -/* protect backpointer with s_cap_lock: see iterate_session_caps */ - cap->ci =NULL ; + +/* protect removal marker with both i_ceph_lock and +s_cap_lock, so either one can be used to check for +removal */ +RB_CLEAR_NODE (&cap->ci_node);/* * s_cap_reconnect is protected by s_cap_lock. no one changes
fs/ceph/super.h +14 -2
@@ -203,7 +203,19 @@ struct ceph_fs_client {*/ struct ceph_cap {struct ceph_inode_info *ci; -struct rb_node ci_node;/* per-ci cap tree */ + +/** +* Per-ci cap tree. Protected with +* `ceph_inode_info.i_ceph_lock`. +* +* Clearing this field with RB_CLEAR_NODE() requires holding +* both `ceph_inode_info.i_ceph_lock` and +* `ceph_mds_session->s_cap_lock`. Calling RB_EMPTY_NODE() +* (via ceph_cap_is_removed()) requires holding at least one +* of these. +*/ +struct rb_node ci_node; +struct ceph_mds_session *session;struct list_head session_caps;/* per-session caplist */ u64 cap_id;/* unique cap id (mds provided) */
@@ -1280,7 +1292,7 @@ extern void ceph_add_cap(struct inode *inode,*/ static inline bool ceph_cap_is_removed (const struct ceph_cap *cap) { -return !cap->ci; +return RB_EMPTY_NODE (&cap->ci_node); } extern void ceph_remove_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,
Signature · 1 line
2.47.3
PATCH v2 1/4 fs/ceph/caps: make __ceph_remove_cap() static
It's only used from within caps.c.
--- fs/ceph/caps.c | 2 +- fs/ceph/super.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
fs/ceph/caps.c +1 -1
@@ -1119,7 +1119,7 @@ int ceph_is_any_caps(struct inode *inode)* caller should hold i_ceph_lock. * caller will not hold session s_mutex if called from destroy_inode. */ -void __ceph_remove_cap (struct ceph_cap *cap,bool queue_release) +static void __ceph_remove_cap (struct ceph_cap *cap,bool queue_release) {struct ceph_mds_session *session = cap->session;struct ceph_client *cl = session->s_mdsc->fsc->client;
fs/ceph/super.h +0 -1
@@ -1269,7 +1269,6 @@ extern void ceph_add_cap(struct inode *inode, unsigned issued, unsigned wanted, unsigned cap, unsigned seq, u64 realmino, int flags, struct ceph_cap **new_cap); -extern void __ceph_remove_cap (struct ceph_cap *cap,bool queue_release);extern void ceph_remove_cap (struct ceph_mds_client *mdsc,struct ceph_cap *cap,bool queue_release);extern void __ceph_remove_caps (struct ceph_inode_info *ci);
Signature · 1 line
2.47.3
PATCH v2 4/4 fs/ceph/cap: pass inode pointer around instead of reloading from RAM
All these functions already have a ceph_inode_info pointer, so let's use that instead of letting every function reload it from RAM (i.e. ceph_cap.ci). This eliminates several memory accesses.
--- fs/ceph/caps.c | 56 +++++++++++++++++++++----------------------- fs/ceph/mds_client.c | 2 +- fs/ceph/super.h | 1 + 3 files changed, 29 insertions(+), 30 deletions(-)
fs/ceph/caps.c +27 -29
@@ -785,9 +785,9 @@ void ceph_add_cap(struct inode *inode,* generation of the MDS session (i.e. has not gone 'stale' due to * us losing touch with the mds). */ -static int __cap_is_valid (struct ceph_cap *cap) +static int __cap_is_valid (struct ceph_inode_info *ci,struct ceph_cap *cap) { -struct inode *inode = &cap->ci->netfs.inode; +struct inode *inode = &ci->netfs.inode;struct ceph_client *cl = cap->session->s_mdsc->fsc->client;unsigned long ttl;u32 gen;
@@ -822,7 +822,7 @@ int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented) *implemented =0 ;for (p =rb_first (&ci->i_caps); p; p =rb_next (p)) { cap = rb_entry(p, struct ceph_cap, ci_node); -if (!__cap_is_valid (cap)) +if (!__cap_is_valid (ci, cap))continue ;doutc (cl,"%p %llx.%llx cap %p issued %s\n" , inode,ceph_vinop (inode), cap,ceph_cap_string (cap->issued));
@@ -855,7 +855,7 @@ int __ceph_caps_issued_other(struct ceph_inode_info *ci, struct ceph_cap *ocap) cap = rb_entry(p, struct ceph_cap, ci_node);if (cap == ocap)continue ; -if (!__cap_is_valid (cap)) +if (!__cap_is_valid (ci, cap))continue ; have |= cap->issued; }
@@ -866,9 +866,9 @@ int __ceph_caps_issued_other(struct ceph_inode_info *ci, struct ceph_cap *ocap)* Move a cap to the end of the LRU (oldest caps at list head, newest * at list tail). */ -static void __touch_cap (struct ceph_cap *cap) +static void __touch_cap (struct ceph_inode_info *ci,struct ceph_cap *cap) { -struct inode *inode = &cap->ci->netfs.inode; +struct inode *inode = &ci->netfs.inode;struct ceph_mds_session *s = cap->session;struct ceph_client *cl = s->s_mdsc->fsc->client;
@@ -906,7 +906,7 @@ int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch)for (p =rb_first (&ci->i_caps); p; p =rb_next (p)) { cap = rb_entry(p, struct ceph_cap, ci_node); -if (!__cap_is_valid (cap)) +if (!__cap_is_valid (ci, cap))continue ;if ((cap->issued & mask) == mask) { doutc(cl, "mask %p %llx.%llx cap %p issued %s (mask %s)\n",
@@ -914,7 +914,7 @@ int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch)ceph_cap_string (cap->issued), ceph_cap_string(mask));if (touch) -__touch_cap (cap); +__touch_cap (ci, cap);return 1 ; }
@@ -929,15 +929,15 @@ int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch)struct rb_node *q;/* touch this + preceding caps */ -__touch_cap (cap); +__touch_cap (ci, cap);for (q =rb_first (&ci->i_caps); q != p; q =rb_next (q)) { cap = rb_entry(q, struct ceph_cap, ci_node); -if (!__cap_is_valid (cap)) +if (!__cap_is_valid (ci, cap))continue ;if (cap->issued & mask) -__touch_cap (cap); +__touch_cap (ci, cap); } }return 1 ;
@@ -1091,7 +1091,7 @@ int __ceph_caps_mds_wanted(struct ceph_inode_info *ci, bool check)for (p =rb_first (&ci->i_caps); p; p =rb_next (p)) { cap = rb_entry(p, struct ceph_cap, ci_node); -if (check && !__cap_is_valid (cap)) +if (check && !__cap_is_valid (ci, cap))continue ;if (cap == ci->i_auth_cap) mds_wanted |= cap->mds_wanted;
@@ -1119,11 +1119,10 @@ int ceph_is_any_caps(struct inode *inode)* caller should hold i_ceph_lock. * caller will not hold session s_mutex if called from destroy_inode. */ -static void __ceph_remove_cap (struct ceph_cap *cap,bool queue_release) +static void __ceph_remove_cap (struct ceph_inode_info *ci,struct ceph_cap *cap,bool queue_release) {struct ceph_mds_session *session = cap->session;struct ceph_client *cl = session->s_mdsc->fsc->client; -struct ceph_inode_info *ci = cap->ci;struct inode *inode = &ci->netfs.inode;struct ceph_mds_client *mdsc;int removed =0 ;
@@ -1198,9 +1197,9 @@ static void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) }void ceph_remove_cap (struct ceph_mds_client *mdsc,struct ceph_cap *cap, +struct ceph_inode_info *ci,bool queue_release) { -struct ceph_inode_info *ci = cap->ci;struct ceph_fs_client *fsc;if (ceph_cap_is_removed (cap)) {
@@ -1216,7 +1215,7 @@ void ceph_remove_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap, !fsc->blocklisted && !ceph_inode_is_shutdown(&ci->netfs.inode)); -__ceph_remove_cap (cap, queue_release); +__ceph_remove_cap (ci, cap, queue_release); }struct cap_msg_args {
@@ -1376,7 +1375,7 @@ void __ceph_remove_caps(struct ceph_inode_info *ci)while (p) { struct ceph_cap *cap = rb_entry(p, struct ceph_cap, ci_node); p =rb_next (p); -ceph_remove_cap (mdsc, cap, true); +ceph_remove_cap (mdsc, cap, ci, true); }spin_unlock (&ci->i_ceph_lock); }
@@ -1389,11 +1388,10 @@ void __ceph_remove_caps(struct ceph_inode_info *ci)* Make note of max_size reported/requested from mds, revoked caps * that have now been implemented. */ -static void __prep_cap (struct cap_msg_args *arg,struct ceph_cap *cap, +static void __prep_cap (struct cap_msg_args *arg,struct ceph_inode_info *ci,struct ceph_cap *cap,int op,int flags,int used,int want,int retain,int flushing,u64 flush_tid,u64 oldest_flush_tid) { -struct ceph_inode_info *ci = cap->ci;struct inode *inode = &ci->netfs.inode;struct ceph_client *cl =ceph_inode_to_client (inode);int held, revoking;
@@ -2211,7 +2209,7 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags)if (want & ~cap->mds_wanted) {if (want & ~(cap->mds_wanted | cap->issued)) goto ack; -if (!__cap_is_valid (cap)) +if (!__cap_is_valid (ci, cap)) goto ack; }
@@ -2253,7 +2251,7 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags) mds = cap->mds;/* remember mds, so we don't repeat */ -__prep_cap (&arg, cap,CEPH_CAP_OP_UPDATE , mflags, cap_used, +__prep_cap (&arg, ci, cap,CEPH_CAP_OP_UPDATE , mflags, cap_used, want, retain, flushing, flush_tid, oldest_flush_tid);spin_unlock (&ci->i_ceph_lock);
@@ -2315,7 +2313,7 @@ static int try_flush_caps(struct inode *inode, u64 *ptid) flush_tid =__mark_caps_flushing (inode, session, true, &oldest_flush_tid); -__prep_cap (&arg, cap,CEPH_CAP_OP_FLUSH ,CEPH_CLIENT_CAPS_SYNC , +__prep_cap (&arg, ci, cap,CEPH_CAP_OP_FLUSH ,CEPH_CLIENT_CAPS_SYNC ,__ceph_caps_used (ci),__ceph_caps_wanted (ci), (cap->issued | cap->implemented), flushing, flush_tid, oldest_flush_tid);
@@ -2609,7 +2607,7 @@ static void __kick_flushing_caps(struct ceph_mds_client *mdsc,doutc (cl,"%p %llx.%llx cap %p tid %llu %s\n" , inode,ceph_vinop (inode), cap, cf->tid,ceph_cap_string (cf->caps)); - __prep_cap(&arg, cap, CEPH_CAP_OP_FLUSH, + __prep_cap(&arg, ci, cap, CEPH_CAP_OP_FLUSH, (cf->tid < last_snap_flush ? CEPH_CLIENT_CAPS_PENDING_CAPSNAP : 0), __ceph_caps_used(ci),
@@ -4107,7 +4105,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex, goto out_unlock;if (target <0 ) { -ceph_remove_cap (mdsc, cap, false); +ceph_remove_cap (mdsc, cap, ci, false); goto out_unlock; }
@@ -4144,7 +4142,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,change_auth_cap_ses (ci, tcap->session); } } -ceph_remove_cap (mdsc, cap, false); +ceph_remove_cap (mdsc, cap, ci, false); goto out_unlock; }else if (tsession) {/* add placeholder for the export target */
@@ -4161,7 +4159,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,spin_unlock (&mdsc->cap_dirty_lock); } -ceph_remove_cap (mdsc, cap, false); +ceph_remove_cap (mdsc, cap, ci, false); goto out_unlock; }
@@ -4277,7 +4275,7 @@ static void handle_cap_import(struct ceph_mds_client *mdsc, inode,ceph_vinop (inode), peer, ocap->seq, ocap->mseq, mds, piseq, pmseq); } -ceph_remove_cap (mdsc, ocap, (ph->flags &CEPH_CAP_FLAG_RELEASE )); +ceph_remove_cap (mdsc, ocap, ci, (ph->flags &CEPH_CAP_FLAG_RELEASE )); } *old_issued = issued;
@@ -4874,7 +4872,7 @@ int ceph_encode_inode_release(void **p, struct inode *inode, drop &= ~(used | dirty); cap =__get_cap_for_mds (ci, mds); -if (cap &&__cap_is_valid (cap)) { +if (cap &&__cap_is_valid (ci, cap)) { unless &= cap->issued;if (unless) {if (unless &CEPH_CAP_AUTH_EXCL )
@@ -5033,7 +5031,7 @@ int ceph_purge_inode_cap(struct inode *inode, struct ceph_cap *cap, bool *invali cap, ci, inode, ceph_vinop(inode)); is_auth = (cap == ci->i_auth_cap); -__ceph_remove_cap (cap, false); +__ceph_remove_cap (ci, cap, false);if (is_auth) {struct ceph_cap_flush *cf;
fs/ceph/mds_client.c +1 -1
@@ -2258,7 +2258,7 @@ static int trim_caps_cb(struct inode *inode, int mds, void *arg)if (oissued) {/* we aren't the only cap.. just remove us */ -ceph_remove_cap (mdsc, cap, true); +ceph_remove_cap (mdsc, cap, ci, true); (*remaining)--; }else {struct dentry *dentry;
fs/ceph/super.h +1 -0
@@ -1296,6 +1296,7 @@ static inline bool ceph_cap_is_removed(const struct ceph_cap *cap) }extern void ceph_remove_cap (struct ceph_mds_client *mdsc,struct ceph_cap *cap, +struct ceph_inode_info *ci,bool queue_release);extern void __ceph_remove_caps (struct ceph_inode_info *ci); extern void ceph_put_cap(struct ceph_mds_client *mdsc,
Signature · 1 line
2.47.3
Re: [PATCH v2 2/4] fs/ceph: add helper function ceph_cap_is_removed()
In reply to Max Kellermann--
Alex Markuze
Re: [PATCH v2 3/4] fs/ceph/caps: mark cap remove with RB_CLEAR_NODE() instead of ci=NULL
In reply to Max Kellermann--
Alex Markuze
Re: [PATCH v2 4/4] fs/ceph/cap: pass inode pointer around instead of reloading from RAM
In reply to Max Kellermann--
Alex Markuze