Skip to contentSkip to conversation

ceph: unlock dangling spinlock in try_flush_caps

PATCH Applied Jeff Layton 3 participants 3 messages Oct 19, 2017 – Oct 20, 2017 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: unlock dangling spinlock in try_flush_caps

From: Jeff Layton <[email protected]>

sparose warns:
fs/ceph/caps.c:2042:9: warning: context imbalance in 'try_flush_caps' - wrong count at exit

We need to exit this function with the lock unlocked, but a couple of cases leave it locked.

---
 fs/ceph/caps.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ceph/caps.c +4 -1
index 157fe59fbabe..1978a8cb1cb1 100644
@@ -1991,6 +1991,7 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
 retry:
 	spin_lock(&ci->i_ceph_lock);
 	if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
+		spin_unlock(&ci->i_ceph_lock);
 		dout("try_flush_caps skipping %p I_NOFLUSH set\n", inode);
 		goto out;
 	}
@@ -2008,8 +2009,10 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
 			mutex_lock(&session->s_mutex);
 			goto retry;
 		}
-		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
+		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) {
+			spin_unlock(&ci->i_ceph_lock);
 			goto out;
+		}
 
 		flushing = __mark_caps_flushing(inode, session, true,
 						&flush_tid, &oldest_flush_tid);
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 44 lines · Jeff Layton

From: Jeff Layton <[email protected]>

sparose warns:
fs/ceph/caps.c:2042:9: warning: context imbalance in 'try_flush_caps' - wrong count at exit

We need to exit this function with the lock unlocked, but a couple of cases leave it locked.

---
fs/ceph/caps.c | 5 ++++-

1 file changed, 4 insertions(+), 1 deletion(-)
fs/ceph/caps.c +0 -0
index 157fe59fbabe..1978a8cb1cb1 100644
@@ -1991,6 +1991,7 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)

retry:

	spin_lock(&ci->i_ceph_lock);
	if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
fs/ceph/caps.c +1 -0
+		spin_unlock(&ci->i_ceph_lock);
		dout("try_flush_caps skipping %p I_NOFLUSH set\n", inode);
		goto out;
	}
fs/ceph/caps.c +3 -1
@@ -2008,8 +2009,10 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
 			mutex_lock(&session->s_mutex);
 			goto retry;
 		}
-		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
+		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) {
+			spin_unlock(&ci->i_ceph_lock);
 			goto out;
+		}
 
 		flushing = __mark_caps_flushing(inode, session, true,
 						&flush_tid, &oldest_flush_tid);
Signature · 1 line
2.13.6

good catch

maintainer Applied
#2 lore raw
In reply to Jeff Layton
Quoted 28 lines · Jeff Layton

From: Jeff Layton <[email protected]>

sparose warns:
fs/ceph/caps.c:2042:9: warning: context imbalance in 'try_flush_caps' - wrong count at exit

We need to exit this function with the lock unlocked, but a couple of cases leave it locked.

---
 fs/ceph/caps.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ceph/caps.c +1 -0
index 157fe59fbabe..1978a8cb1cb1 100644
@@ -1991,6 +1991,7 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
 retry:
        spin_lock(&ci->i_ceph_lock);
        if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
+               spin_unlock(&ci->i_ceph_lock);
                dout("try_flush_caps skipping %p I_NOFLUSH set\n", inode);
                goto out;
        }
@@ -2008,8 +2009,10 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
                        mutex_lock(&session->s_mutex);

fs/ceph/caps.c static int try_flush_caps(struct inode *inode, u64 *ptid) · line 2018

Quoted 10 lines
fs/ceph/caps.c +3 -1
                        goto retry;
                }
-               if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
+               if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) {
+                       spin_unlock(&ci->i_ceph_lock);
                        goto out;
+               }
 
                flushing = __mark_caps_flushing(inode, session, true,
                                                &flush_tid, &oldest_flush_tid);

Applied.

Thanks,

Ilya