Skip to contentSkip to conversation

bcachefs: Merge the condition to avoid additional invocation

PATCH New Alan Huang 1 participant 1 message Sep 25, 2024

lore
Share & tools
lore

Alan Huang

author
#0 lore raw

PATCH v2 1/1 bcachefs: Merge the condition to avoid additional invocation

If the lock has been acquired and unlocked, we don't have to do clear and wakeup again, though harmless since we hold the intent lock. Merge the condition might be clearer.

---
Only the title is changed in this version.

The original one is "bcachefs: Remove the second call to these function"

 fs/bcachefs/six.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/bcachefs/six.c +5 -5
index b3583c50ef04..8fb44a5d1406 100644
@@ -491,8 +491,12 @@ static int six_lock_slowpath(struct six_lock *lock, enum six_lock_type type,
 				list_del(&wait->list);
 			raw_spin_unlock(&lock->wait_lock);
 
-			if (unlikely(acquired))
+			if (unlikely(acquired)) {
 				do_six_unlock_type(lock, type);
+			} else if (type == SIX_LOCK_write) {
+				six_clear_bitmask(lock, SIX_LOCK_HELD_write);
+				six_lock_wakeup(lock, atomic_read(&lock->state), SIX_LOCK_read);
+			}
 			break;
 		}
 
@@ -501,10 +505,6 @@ static int six_lock_slowpath(struct six_lock *lock, enum six_lock_type type,
 
 	__set_current_state(TASK_RUNNING);
 out:
-	if (ret && type == SIX_LOCK_write) {
-		six_clear_bitmask(lock, SIX_LOCK_HELD_write);
-		six_lock_wakeup(lock, atomic_read(&lock->state), SIX_LOCK_read);
-	}
 	trace_contention_end(lock, 0);
 
 	return ret;
Signature · 1 line
2.45.2