Skip to content

Commit

Permalink
[GFS2] Tidy up locking code
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Steven Whitehouse committed Sep 4, 2006
1 parent e9fc2aa commit 5029996
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 113 deletions.
53 changes: 13 additions & 40 deletions fs/gfs2/glock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
create a VFS inode to manage the pages/buffers holding them. */
if (glops == &gfs2_inode_glops ||
glops == &gfs2_rgrp_glops) {
if (glops == &gfs2_inode_glops || glops == &gfs2_rgrp_glops) {
gl->gl_aspace = gfs2_aspace_get(sdp);
if (!gl->gl_aspace) {
error = -ENOMEM;
Expand Down Expand Up @@ -820,13 +819,11 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret)

if (!gh)
gl->gl_stamp = jiffies;

else if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) {
spin_lock(&gl->gl_spin);
list_del_init(&gh->gh_list);
gh->gh_error = -EIO;
spin_unlock(&gl->gl_spin);

} else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) {
spin_lock(&gl->gl_spin);
list_del_init(&gh->gh_list);
Expand All @@ -842,7 +839,7 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret)
spin_unlock(&gl->gl_spin);

if (ret & LM_OUT_CANCELED)
handle_callback(gl, LM_ST_UNLOCKED); /* Lame */
handle_callback(gl, LM_ST_UNLOCKED);

} else if (ret & LM_OUT_CANCELED) {
spin_lock(&gl->gl_spin);
Expand Down Expand Up @@ -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 != gl->gl_state);

if (gl->gl_state == LM_ST_EXCLUSIVE) {
if (glops->go_sync)
glops->go_sync(gl,
DIO_METADATA | DIO_DATA | DIO_RELEASE);
}
if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);

gfs2_glock_hold(gl);
gl->gl_req_bh = xmote_bh;
Expand Down Expand Up @@ -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, gl->gl_state != LM_ST_UNLOCKED);

if (gl->gl_state == LM_ST_EXCLUSIVE) {
if (glops->go_sync)
glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);
}
if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);

gfs2_glock_hold(gl);
gl->gl_req_bh = drop_bh;
Expand Down Expand Up @@ -1041,9 +1033,8 @@ static void do_cancels(struct gfs2_holder *gh)
while (gl->gl_req_gh != gh &&
!test_bit(HIF_HOLDER, &gh->gh_iflags) &&
!list_empty(&gh->gh_list)) {
if (gl->gl_req_bh &&
!(gl->gl_req_gh &&
(gl->gl_req_gh->gh_flags & GL_NOCANCEL))) {
if (gl->gl_req_bh && !(gl->gl_req_gh &&
(gl->gl_req_gh->gh_flags & GL_NOCANCEL))) {
spin_unlock(&gl->gl_spin);
gfs2_lm_cancel(gl->gl_sbd, gl->gl_lock);
msleep(100);
Expand Down Expand Up @@ -1323,10 +1314,8 @@ static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state,

spin_lock(&gl->gl_spin);

if (test_bit(GLF_LOCK, &gl->gl_flags) ||
!list_empty(&gl->gl_holders) ||
!list_empty(&gl->gl_waiters1) ||
!list_empty(&gl->gl_waiters2) ||
if (test_bit(GLF_LOCK, &gl->gl_flags) || !list_empty(&gl->gl_holders) ||
!list_empty(&gl->gl_waiters1) || !list_empty(&gl->gl_waiters2) ||
!list_empty(&gl->gl_waiters3) ||
relaxed_state_ok(gl->gl_state, state, flags)) {
spin_unlock(&gl->gl_spin);
Expand Down Expand Up @@ -1690,19 +1679,6 @@ void gfs2_lvb_unhold(struct gfs2_glock *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,
unsigned int state)
{
Expand Down Expand Up @@ -1813,8 +1789,7 @@ static int demote_ok(struct gfs2_glock *gl)
if (test_bit(GLF_STICKY, &gl->gl_flags))
demote = 0;
else if (test_bit(GLF_PREFETCH, &gl->gl_flags))
demote = time_after_eq(jiffies,
gl->gl_stamp +
demote = time_after_eq(jiffies, gl->gl_stamp +
gfs2_tune_get(sdp, gt_prefetch_secs) * HZ);
else if (glops->go_demote_ok)
demote = glops->go_demote_ok(gl);
Expand Down Expand Up @@ -1872,8 +1847,7 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp)

if (gfs2_glmutex_trylock(gl)) {
if (queue_empty(gl, &gl->gl_holders) &&
gl->gl_state != LM_ST_UNLOCKED &&
demote_ok(gl))
gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl))
handle_callback(gl, LM_ST_UNLOCKED);
gfs2_glmutex_unlock(gl);
}
Expand Down Expand Up @@ -2036,8 +2010,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait)
cont = 0;

for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
if (examine_bucket(clear_glock, sdp,
&sdp->sd_gl_hash[x]))
if (examine_bucket(clear_glock, sdp, &sdp->sd_gl_hash[x]))
cont = 1;

if (!wait || !cont)
Expand Down
6 changes: 3 additions & 3 deletions fs/gfs2/glock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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)
{
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)
{
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)
Expand Down
62 changes: 18 additions & 44 deletions fs/gfs2/lm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
lm_lock_t **lockp)
{
int error;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
int error = -EIO;
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
sdp->sd_lockstruct.ls_lockspace, name, lockp);
return error;
Expand All @@ -143,23 +141,18 @@ unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock,
unsigned int cur_state, unsigned int req_state,
unsigned int flags)
{
int ret;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
ret = 0;
else
ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock,
cur_state,
int ret = 0;
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state,
req_state, flags);
return ret;
}

unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock,
unsigned int cur_state)
{
int ret;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
ret = 0;
else
int ret = 0;
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state);
return ret;
}
Expand All @@ -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 error;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
int error = -EIO;
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
return error;
}
Expand All @@ -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);
}

#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,
struct file *file, struct file_lock *fl)
{
int error;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
int error = -EIO;
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
sdp->sd_lockstruct.ls_lockspace,
name, file, fl);
sdp->sd_lockstruct.ls_lockspace, name, file, fl);
return error;
}

int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, int cmd, struct file_lock *fl)
{
int error;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
int error = -EIO;
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = sdp->sd_lockstruct.ls_ops->lm_plock(
sdp->sd_lockstruct.ls_lockspace,
name, file, cmd, fl);
sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
return error;
}

int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, struct file_lock *fl)
{
int error;
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = -EIO;
else
int error = -EIO;
if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
error = sdp->sd_lockstruct.ls_ops->lm_punlock(
sdp->sd_lockstruct.ls_lockspace,
name, file, fl);
sdp->sd_lockstruct.ls_lockspace, name, file, fl);
return error;
}

Expand Down
25 changes: 11 additions & 14 deletions fs/gfs2/lm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_unmount(struct gfs2_sbd *sdp);
int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
int gfs2_lm_get_lock(struct gfs2_sbd *sdp,
struct lm_lockname *name, lm_lock_t **lockp);
__attribute__ ((format(printf, 2, 3)));
int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
lm_lock_t **lockp);
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 cur_state, unsigned int req_state,
Expand All @@ -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);
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);
int gfs2_lm_plock_get(struct gfs2_sbd *sdp,
struct lm_lockname *name,
struct file *file, struct file_lock *fl);
int gfs2_lm_plock(struct gfs2_sbd *sdp,
struct lm_lockname *name,
struct file *file, int cmd, struct file_lock *fl);
int gfs2_lm_punlock(struct gfs2_sbd *sdp,
struct lm_lockname *name,
struct file *file, struct file_lock *fl);
void gfs2_lm_recovery_done(struct gfs2_sbd *sdp,
unsigned int jid, unsigned int message);
int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, struct file_lock *fl);
int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
struct file *file, int cmd, struct file_lock *fl);
int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
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__ */
2 changes: 0 additions & 2 deletions fs/gfs2/lm_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ struct lm_lockstruct {
int ls_flags;
};

void __init gfs2_init_lmh(void);

/*
* Lock module bottom interface. A lock module makes itself available to GFS
* with these functions.
Expand Down
10 changes: 2 additions & 8 deletions fs/gfs2/locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ struct lmh_wrapper {
/* 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. */

static struct list_head lmh_list;
static struct mutex lmh_lock;
static LIST_HEAD(lmh_list);
static DEFINE_MUTEX(lmh_lock);

/**
* gfs2_register_lockproto - Register a low-level locking protocol
Expand Down Expand Up @@ -180,12 +180,6 @@ void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct)
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_unregister_lockproto);

2 changes: 0 additions & 2 deletions fs/gfs2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ static int __init init_gfs2_fs(void)
{
int error;

gfs2_init_lmh();

error = gfs2_sys_init();
if (error)
return error;
Expand Down

0 comments on commit 5029996

Please sign in to comment.