[GFS2] Tidy up locking code

As per Jan Engelhardt's second email, this removes some unused code,
and fixes up indenting in various places.

Cc: Jan Engelhardt <jengelh@linux01.gwdg.de>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
This commit is contained in:
Steven Whitehouse 2006-09-04 09:49:55 -04:00
parent e9fc2aa091
commit 5029996547
7 changed files with 47 additions and 113 deletions

View File

@ -300,8 +300,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number,
/* If this glock protects actual on-disk data or metadata blocks, /* If this glock protects actual on-disk data or metadata blocks,
create a VFS inode to manage the pages/buffers holding them. */ create a VFS inode to manage the pages/buffers holding them. */
if (glops == &gfs2_inode_glops || if (glops == &gfs2_inode_glops || glops == &gfs2_rgrp_glops) {
glops == &gfs2_rgrp_glops) {
gl->gl_aspace = gfs2_aspace_get(sdp); gl->gl_aspace = gfs2_aspace_get(sdp);
if (!gl->gl_aspace) { if (!gl->gl_aspace) {
error = -ENOMEM; error = -ENOMEM;
@ -820,13 +819,11 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret)
if (!gh) if (!gh)
gl->gl_stamp = jiffies; gl->gl_stamp = jiffies;
else if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) { else if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) {
spin_lock(&gl->gl_spin); spin_lock(&gl->gl_spin);
list_del_init(&gh->gh_list); list_del_init(&gh->gh_list);
gh->gh_error = -EIO; gh->gh_error = -EIO;
spin_unlock(&gl->gl_spin); spin_unlock(&gl->gl_spin);
} else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) { } else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) {
spin_lock(&gl->gl_spin); spin_lock(&gl->gl_spin);
list_del_init(&gh->gh_list); list_del_init(&gh->gh_list);
@ -842,7 +839,7 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret)
spin_unlock(&gl->gl_spin); spin_unlock(&gl->gl_spin);
if (ret & LM_OUT_CANCELED) if (ret & LM_OUT_CANCELED)
handle_callback(gl, LM_ST_UNLOCKED); /* Lame */ handle_callback(gl, LM_ST_UNLOCKED);
} else if (ret & LM_OUT_CANCELED) { } else if (ret & LM_OUT_CANCELED) {
spin_lock(&gl->gl_spin); spin_lock(&gl->gl_spin);
@ -916,11 +913,8 @@ void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags)
gfs2_assert_warn(sdp, state != LM_ST_UNLOCKED); gfs2_assert_warn(sdp, state != LM_ST_UNLOCKED);
gfs2_assert_warn(sdp, state != gl->gl_state); gfs2_assert_warn(sdp, state != gl->gl_state);
if (gl->gl_state == LM_ST_EXCLUSIVE) { if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
if (glops->go_sync) glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);
glops->go_sync(gl,
DIO_METADATA | DIO_DATA | DIO_RELEASE);
}
gfs2_glock_hold(gl); gfs2_glock_hold(gl);
gl->gl_req_bh = xmote_bh; gl->gl_req_bh = xmote_bh;
@ -1006,10 +1000,8 @@ void gfs2_glock_drop_th(struct gfs2_glock *gl)
gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders)); gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
gfs2_assert_warn(sdp, gl->gl_state != LM_ST_UNLOCKED); gfs2_assert_warn(sdp, gl->gl_state != LM_ST_UNLOCKED);
if (gl->gl_state == LM_ST_EXCLUSIVE) { if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
if (glops->go_sync) glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);
glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);
}
gfs2_glock_hold(gl); gfs2_glock_hold(gl);
gl->gl_req_bh = drop_bh; gl->gl_req_bh = drop_bh;
@ -1041,9 +1033,8 @@ static void do_cancels(struct gfs2_holder *gh)
while (gl->gl_req_gh != gh && while (gl->gl_req_gh != gh &&
!test_bit(HIF_HOLDER, &gh->gh_iflags) && !test_bit(HIF_HOLDER, &gh->gh_iflags) &&
!list_empty(&gh->gh_list)) { !list_empty(&gh->gh_list)) {
if (gl->gl_req_bh && if (gl->gl_req_bh && !(gl->gl_req_gh &&
!(gl->gl_req_gh && (gl->gl_req_gh->gh_flags & GL_NOCANCEL))) {
(gl->gl_req_gh->gh_flags & GL_NOCANCEL))) {
spin_unlock(&gl->gl_spin); spin_unlock(&gl->gl_spin);
gfs2_lm_cancel(gl->gl_sbd, gl->gl_lock); gfs2_lm_cancel(gl->gl_sbd, gl->gl_lock);
msleep(100); msleep(100);
@ -1323,10 +1314,8 @@ static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state,
spin_lock(&gl->gl_spin); spin_lock(&gl->gl_spin);
if (test_bit(GLF_LOCK, &gl->gl_flags) || if (test_bit(GLF_LOCK, &gl->gl_flags) || !list_empty(&gl->gl_holders) ||
!list_empty(&gl->gl_holders) || !list_empty(&gl->gl_waiters1) || !list_empty(&gl->gl_waiters2) ||
!list_empty(&gl->gl_waiters1) ||
!list_empty(&gl->gl_waiters2) ||
!list_empty(&gl->gl_waiters3) || !list_empty(&gl->gl_waiters3) ||
relaxed_state_ok(gl->gl_state, state, flags)) { relaxed_state_ok(gl->gl_state, state, flags)) {
spin_unlock(&gl->gl_spin); spin_unlock(&gl->gl_spin);
@ -1690,19 +1679,6 @@ void gfs2_lvb_unhold(struct gfs2_glock *gl)
gfs2_glock_put(gl); gfs2_glock_put(gl);
} }
#if 0
void gfs2_lvb_sync(struct gfs2_glock *gl)
{
gfs2_glmutex_lock(gl);
gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count));
if (!gfs2_assert_warn(gl->gl_sbd, gfs2_glock_is_held_excl(gl)))
gfs2_lm_sync_lvb(gl->gl_sbd, gl->gl_lock, gl->gl_lvb);
gfs2_glmutex_unlock(gl);
}
#endif /* 0 */
static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name, static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
unsigned int state) unsigned int state)
{ {
@ -1813,8 +1789,7 @@ static int demote_ok(struct gfs2_glock *gl)
if (test_bit(GLF_STICKY, &gl->gl_flags)) if (test_bit(GLF_STICKY, &gl->gl_flags))
demote = 0; demote = 0;
else if (test_bit(GLF_PREFETCH, &gl->gl_flags)) else if (test_bit(GLF_PREFETCH, &gl->gl_flags))
demote = time_after_eq(jiffies, demote = time_after_eq(jiffies, gl->gl_stamp +
gl->gl_stamp +
gfs2_tune_get(sdp, gt_prefetch_secs) * HZ); gfs2_tune_get(sdp, gt_prefetch_secs) * HZ);
else if (glops->go_demote_ok) else if (glops->go_demote_ok)
demote = glops->go_demote_ok(gl); demote = glops->go_demote_ok(gl);
@ -1872,8 +1847,7 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp)
if (gfs2_glmutex_trylock(gl)) { if (gfs2_glmutex_trylock(gl)) {
if (queue_empty(gl, &gl->gl_holders) && if (queue_empty(gl, &gl->gl_holders) &&
gl->gl_state != LM_ST_UNLOCKED && gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl))
demote_ok(gl))
handle_callback(gl, LM_ST_UNLOCKED); handle_callback(gl, LM_ST_UNLOCKED);
gfs2_glmutex_unlock(gl); gfs2_glmutex_unlock(gl);
} }
@ -2036,8 +2010,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait)
cont = 0; cont = 0;
for (x = 0; x < GFS2_GL_HASH_SIZE; x++) for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
if (examine_bucket(clear_glock, sdp, if (examine_bucket(clear_glock, sdp, &sdp->sd_gl_hash[x]))
&sdp->sd_gl_hash[x]))
cont = 1; cont = 1;
if (!wait || !cont) if (!wait || !cont)

View File

@ -51,17 +51,17 @@ static inline int gfs2_glock_is_locked_by_me(struct gfs2_glock *gl)
static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl) static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl)
{ {
return (gl->gl_state == LM_ST_EXCLUSIVE); return gl->gl_state == LM_ST_EXCLUSIVE;
} }
static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl) static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl)
{ {
return (gl->gl_state == LM_ST_DEFERRED); return gl->gl_state == LM_ST_DEFERRED;
} }
static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl) static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl)
{ {
return (gl->gl_state == LM_ST_SHARED); return gl->gl_state == LM_ST_SHARED;
} }
static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl) static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl)

View File

@ -124,10 +124,8 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
lm_lock_t **lockp) lm_lock_t **lockp)
{ {
int error; int error = -EIO;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
error = sdp->sd_lockstruct.ls_ops->lm_get_lock( error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
sdp->sd_lockstruct.ls_lockspace, name, lockp); sdp->sd_lockstruct.ls_lockspace, name, lockp);
return error; return error;
@ -143,12 +141,9 @@ unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock,
unsigned int cur_state, unsigned int req_state, unsigned int cur_state, unsigned int req_state,
unsigned int flags) unsigned int flags)
{ {
int ret; int ret = 0;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
ret = 0; ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state,
else
ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock,
cur_state,
req_state, flags); req_state, flags);
return ret; return ret;
} }
@ -156,10 +151,8 @@ unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock,
unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock,
unsigned int cur_state) unsigned int cur_state)
{ {
int ret; int ret = 0;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
ret = 0;
else
ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state); ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state);
return ret; return ret;
} }
@ -172,10 +165,8 @@ void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock)
int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp)
{ {
int error; int error = -EIO;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp); error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
return error; return error;
} }
@ -186,50 +177,33 @@ void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb)
sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb);
} }
#if 0
void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb)
{
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb);
}
#endif /* 0 */
int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, struct file_lock *fl) struct file *file, struct file_lock *fl)
{ {
int error; int error = -EIO;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
error = sdp->sd_lockstruct.ls_ops->lm_plock_get( error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
sdp->sd_lockstruct.ls_lockspace, sdp->sd_lockstruct.ls_lockspace, name, file, fl);
name, file, fl);
return error; return error;
} }
int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, int cmd, struct file_lock *fl) struct file *file, int cmd, struct file_lock *fl)
{ {
int error; int error = -EIO;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
error = sdp->sd_lockstruct.ls_ops->lm_plock( error = sdp->sd_lockstruct.ls_ops->lm_plock(
sdp->sd_lockstruct.ls_lockspace, sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
name, file, cmd, fl);
return error; return error;
} }
int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, struct file_lock *fl) struct file *file, struct file_lock *fl)
{ {
int error; int error = -EIO;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
error = sdp->sd_lockstruct.ls_ops->lm_punlock( error = sdp->sd_lockstruct.ls_ops->lm_punlock(
sdp->sd_lockstruct.ls_lockspace, sdp->sd_lockstruct.ls_lockspace, name, file, fl);
name, file, fl);
return error; return error;
} }

View File

@ -16,9 +16,9 @@ int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent);
void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp); void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp);
void gfs2_lm_unmount(struct gfs2_sbd *sdp); void gfs2_lm_unmount(struct gfs2_sbd *sdp);
int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
__attribute__ ((format(printf, 2, 3))); __attribute__ ((format(printf, 2, 3)));
int gfs2_lm_get_lock(struct gfs2_sbd *sdp, int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct lm_lockname *name, lm_lock_t **lockp); lm_lock_t **lockp);
void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock); void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock);
unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock,
unsigned int cur_state, unsigned int req_state, unsigned int cur_state, unsigned int req_state,
@ -28,16 +28,13 @@ unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock,
void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock); void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock);
int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp); int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp);
void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb); void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb);
int gfs2_lm_plock_get(struct gfs2_sbd *sdp, int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct lm_lockname *name, struct file *file, struct file_lock *fl);
struct file *file, struct file_lock *fl); int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
int gfs2_lm_plock(struct gfs2_sbd *sdp, struct file *file, int cmd, struct file_lock *fl);
struct lm_lockname *name, int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, int cmd, struct file_lock *fl); struct file *file, struct file_lock *fl);
int gfs2_lm_punlock(struct gfs2_sbd *sdp, void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
struct lm_lockname *name, unsigned int message);
struct file *file, struct file_lock *fl);
void gfs2_lm_recovery_done(struct gfs2_sbd *sdp,
unsigned int jid, unsigned int message);
#endif /* __LM_DOT_H__ */ #endif /* __LM_DOT_H__ */

View File

@ -260,8 +260,6 @@ struct lm_lockstruct {
int ls_flags; int ls_flags;
}; };
void __init gfs2_init_lmh(void);
/* /*
* Lock module bottom interface. A lock module makes itself available to GFS * Lock module bottom interface. A lock module makes itself available to GFS
* with these functions. * with these functions.

View File

@ -27,8 +27,8 @@ struct lmh_wrapper {
/* List of registered low-level locking protocols. A file system selects one /* List of registered low-level locking protocols. A file system selects one
of them by name at mount time, e.g. lock_nolock, lock_dlm. */ of them by name at mount time, e.g. lock_nolock, lock_dlm. */
static struct list_head lmh_list; static LIST_HEAD(lmh_list);
static struct mutex lmh_lock; static DEFINE_MUTEX(lmh_lock);
/** /**
* gfs2_register_lockproto - Register a low-level locking protocol * gfs2_register_lockproto - Register a low-level locking protocol
@ -180,12 +180,6 @@ void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct)
mutex_unlock(&lmh_lock); mutex_unlock(&lmh_lock);
} }
void __init gfs2_init_lmh(void)
{
mutex_init(&lmh_lock);
INIT_LIST_HEAD(&lmh_list);
}
EXPORT_SYMBOL_GPL(gfs2_register_lockproto); EXPORT_SYMBOL_GPL(gfs2_register_lockproto);
EXPORT_SYMBOL_GPL(gfs2_unregister_lockproto); EXPORT_SYMBOL_GPL(gfs2_unregister_lockproto);

View File

@ -65,8 +65,6 @@ static int __init init_gfs2_fs(void)
{ {
int error; int error;
gfs2_init_lmh();
error = gfs2_sys_init(); error = gfs2_sys_init();
if (error) if (error)
return error; return error;