mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
lockref: tidy up dead count handling
1. put the dead val into a macro so that it can be used in other places 2. __lockref_is_dead(): - drop the __ suffix, this is not an internal routine - drop the spurious cast, the value is already a signed int - use READ_ONCE to prevent any compile shenanigans 3. provide lockref_is_dead_or_zero() Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://patch.msgid.link/20260724171422.429284-2-mjguzik@gmail.com Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
+1
-1
@@ -1667,7 +1667,7 @@ __dentry_leases_walk(struct ceph_mds_client *mdsc,
|
||||
if (!spin_trylock(&dentry->d_lock))
|
||||
continue;
|
||||
|
||||
if (__lockref_is_dead(&dentry->d_lockref)) {
|
||||
if (lockref_is_dead(&dentry->d_lockref)) {
|
||||
list_del_init(&di->lease_list);
|
||||
goto next;
|
||||
}
|
||||
|
||||
+2
-2
@@ -725,7 +725,7 @@ static bool z_erofs_get_pcluster(struct z_erofs_pcluster *pcl)
|
||||
return true;
|
||||
|
||||
spin_lock(&pcl->lockref.lock);
|
||||
if (__lockref_is_dead(&pcl->lockref)) {
|
||||
if (lockref_is_dead(&pcl->lockref)) {
|
||||
spin_unlock(&pcl->lockref.lock);
|
||||
return false;
|
||||
}
|
||||
@@ -945,7 +945,7 @@ static void z_erofs_put_pcluster(struct erofs_sb_info *sbi,
|
||||
if (lockref_put_or_lock(&pcl->lockref))
|
||||
return;
|
||||
|
||||
DBG_BUGON(__lockref_is_dead(&pcl->lockref));
|
||||
DBG_BUGON(lockref_is_dead(&pcl->lockref));
|
||||
if (!--pcl->lockref.count) {
|
||||
if (try_free && xa_trylock(&sbi->managed_pslots)) {
|
||||
free = __erofs_try_to_release_pcluster(sbi, pcl);
|
||||
|
||||
+3
-3
@@ -2080,7 +2080,7 @@ static void clear_glock(struct gfs2_glock *gl)
|
||||
gfs2_glock_remove_from_lru(gl);
|
||||
|
||||
spin_lock(&gl->gl_lockref.lock);
|
||||
if (!__lockref_is_dead(&gl->gl_lockref)) {
|
||||
if (!lockref_is_dead(&gl->gl_lockref)) {
|
||||
gl->gl_lockref.count++;
|
||||
if (gl->gl_state != LM_ST_UNLOCKED)
|
||||
request_demote(gl, LM_ST_UNLOCKED, 0, false);
|
||||
@@ -2115,7 +2115,7 @@ static void dump_glock_func(struct gfs2_glock *gl)
|
||||
static void withdraw_glock(struct gfs2_glock *gl)
|
||||
{
|
||||
spin_lock(&gl->gl_lockref.lock);
|
||||
if (!__lockref_is_dead(&gl->gl_lockref)) {
|
||||
if (!lockref_is_dead(&gl->gl_lockref)) {
|
||||
/*
|
||||
* We don't want to write back any more dirty data. Unlock the
|
||||
* remaining inode and resource group glocks; this will cause
|
||||
@@ -2483,7 +2483,7 @@ static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi, loff_t n)
|
||||
continue;
|
||||
break;
|
||||
} else {
|
||||
if (__lockref_is_dead(&gl->gl_lockref))
|
||||
if (lockref_is_dead(&gl->gl_lockref))
|
||||
continue;
|
||||
n--;
|
||||
}
|
||||
|
||||
+3
-3
@@ -126,7 +126,7 @@ static void gdlm_ast(void *arg)
|
||||
clear_bit(GLF_BLOCKING, &gl->gl_flags);
|
||||
|
||||
/* If the glock is dead, we only react to a dlm_unlock() reply. */
|
||||
if (__lockref_is_dead(&gl->gl_lockref) &&
|
||||
if (lockref_is_dead(&gl->gl_lockref) &&
|
||||
gl->gl_lksb.sb_status != -DLM_EUNLOCK)
|
||||
return;
|
||||
|
||||
@@ -182,7 +182,7 @@ static void gdlm_bast(void *arg, int mode)
|
||||
{
|
||||
struct gfs2_glock *gl = arg;
|
||||
|
||||
if (__lockref_is_dead(&gl->gl_lockref))
|
||||
if (lockref_is_dead(&gl->gl_lockref))
|
||||
return;
|
||||
|
||||
switch (mode) {
|
||||
@@ -329,7 +329,7 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
|
||||
uint32_t flags = 0;
|
||||
int error;
|
||||
|
||||
BUG_ON(!__lockref_is_dead(&gl->gl_lockref));
|
||||
BUG_ON(!lockref_is_dead(&gl->gl_lockref));
|
||||
|
||||
if (test_bit(GLF_INITIAL, &gl->gl_flags)) {
|
||||
gfs2_glock_free(gl);
|
||||
|
||||
+2
-2
@@ -342,7 +342,7 @@ static void qd_put(struct gfs2_quota_data *qd)
|
||||
if (lockref_put_or_lock(&qd->qd_lockref))
|
||||
return;
|
||||
|
||||
BUG_ON(__lockref_is_dead(&qd->qd_lockref));
|
||||
BUG_ON(lockref_is_dead(&qd->qd_lockref));
|
||||
sdp = qd->qd_sbd;
|
||||
if (unlikely(!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))) {
|
||||
lockref_mark_dead(&qd->qd_lockref);
|
||||
@@ -486,7 +486,7 @@ static bool qd_grab_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
|
||||
qd->qd_sync_gen >= sync_gen)
|
||||
goto out;
|
||||
|
||||
if (__lockref_is_dead(&qd->qd_lockref))
|
||||
if (lockref_is_dead(&qd->qd_lockref))
|
||||
goto out;
|
||||
qd->qd_lockref.count++;
|
||||
|
||||
|
||||
+2
-2
@@ -80,7 +80,7 @@ xfs_buf_stale(
|
||||
|
||||
spin_lock(&bp->b_lockref.lock);
|
||||
atomic_set(&bp->b_lru_ref, 0);
|
||||
if (!__lockref_is_dead(&bp->b_lockref))
|
||||
if (!lockref_is_dead(&bp->b_lockref))
|
||||
list_lru_del_obj(&bp->b_target->bt_lru, &bp->b_lru);
|
||||
spin_unlock(&bp->b_lockref.lock);
|
||||
}
|
||||
@@ -826,7 +826,7 @@ static void
|
||||
xfs_buf_destroy(
|
||||
struct xfs_buf *bp)
|
||||
{
|
||||
ASSERT(__lockref_is_dead(&bp->b_lockref));
|
||||
ASSERT(lockref_is_dead(&bp->b_lockref));
|
||||
ASSERT(!(bp->b_flags & _XBF_DELWRI_Q));
|
||||
|
||||
if (bp->b_pag)
|
||||
|
||||
+2
-2
@@ -128,7 +128,7 @@ xfs_qm_dqpurge(
|
||||
struct xfs_quotainfo *qi = dqp->q_mount->m_quotainfo;
|
||||
|
||||
spin_lock(&dqp->q_lockref.lock);
|
||||
if (dqp->q_lockref.count > 0 || __lockref_is_dead(&dqp->q_lockref)) {
|
||||
if (dqp->q_lockref.count > 0 || lockref_is_dead(&dqp->q_lockref)) {
|
||||
spin_unlock(&dqp->q_lockref.lock);
|
||||
return -EAGAIN;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ xfs_qm_dquot_isolate(
|
||||
* from the LRU, leave it for the freeing task to complete the freeing
|
||||
* process rather than risk it being free from under us here.
|
||||
*/
|
||||
if (__lockref_is_dead(&dqp->q_lockref))
|
||||
if (lockref_is_dead(&dqp->q_lockref))
|
||||
goto out_miss_unlock;
|
||||
|
||||
/*
|
||||
|
||||
+10
-2
@@ -34,6 +34,8 @@ struct lockref {
|
||||
};
|
||||
};
|
||||
|
||||
#define __LOCKREF_DEAD_VAL -128
|
||||
|
||||
/**
|
||||
* lockref_init - Initialize a lockref
|
||||
* @lockref: pointer to lockref structure
|
||||
@@ -55,9 +57,15 @@ void lockref_mark_dead(struct lockref *lockref);
|
||||
bool lockref_get_not_dead(struct lockref *lockref);
|
||||
|
||||
/* Must be called under spinlock for reliable results */
|
||||
static inline bool __lockref_is_dead(const struct lockref *l)
|
||||
static inline bool lockref_is_dead(const struct lockref *l)
|
||||
{
|
||||
return ((int)l->count < 0);
|
||||
return (READ_ONCE(l->count) == __LOCKREF_DEAD_VAL);
|
||||
}
|
||||
|
||||
static inline bool lockref_is_dead_or_zero(const struct lockref *l)
|
||||
{
|
||||
int count = READ_ONCE(l->count);
|
||||
return (count == __LOCKREF_DEAD_VAL || count == 0);
|
||||
}
|
||||
|
||||
#endif /* __LINUX_LOCKREF_H */
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ EXPORT_SYMBOL(lockref_put_or_lock);
|
||||
void lockref_mark_dead(struct lockref *lockref)
|
||||
{
|
||||
assert_spin_locked(&lockref->lock);
|
||||
lockref->count = -128;
|
||||
lockref->count = __LOCKREF_DEAD_VAL;
|
||||
}
|
||||
EXPORT_SYMBOL(lockref_mark_dead);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user