/*
* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
- * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
#include <linux/sort.h>
#include <linux/jhash.h>
#include <linux/kref.h>
+#include <linux/kallsyms.h>
#include <linux/gfs2_ondisk.h>
-#include <asm/semaphore.h>
#include <asm/uaccess.h>
#include "gfs2.h"
typedef void (*glock_examiner) (struct gfs2_glock * gl);
+static int gfs2_dump_lockstate(struct gfs2_sbd *sdp);
+
/**
* relaxed_state_ok - is a requested lock compatible with the current lock mode?
* @actual: the current state of the lock
if (kref_put(&gl->gl_ref, kill_glock)) {
list_del_init(&gl->gl_list);
write_unlock(&bucket->hb_lock);
+ BUG_ON(spin_is_locked(&gl->gl_spin));
glock_free(gl);
rv = 1;
goto out;
* Returns: NULL, or the struct gfs2_glock with the requested number
*/
-struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp,
- struct lm_lockname *name)
+static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp,
+ struct lm_lockname *name)
{
struct gfs2_gl_hash_bucket *bucket = &sdp->sd_gl_hash[gl_hash(name)];
struct gfs2_glock *gl;
*
*/
-void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags,
+void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags,
struct gfs2_holder *gh)
{
INIT_LIST_HEAD(&gh->gh_list);
gh->gh_gl = gl;
- gh->gh_owner = (flags & GL_NEVER_RECURSE) ? NULL : current;
+ gh->gh_ip = (unsigned long)__builtin_return_address(0);
+ gh->gh_owner = current;
gh->gh_state = state;
gh->gh_flags = flags;
gh->gh_error = 0;
*
*/
-void gfs2_holder_reinit(unsigned int state, int flags, struct gfs2_holder *gh)
+void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder *gh)
{
gh->gh_state = state;
gh->gh_flags = flags;
gh->gh_flags |= GL_LOCAL_EXCL;
gh->gh_iflags &= 1 << HIF_ALLOCED;
+ gh->gh_ip = (unsigned long)__builtin_return_address(0);
}
/**
{
gfs2_glock_put(gh->gh_gl);
gh->gh_gl = NULL;
+ gh->gh_ip = 0;
}
/**
* Returns: the holder structure, NULL on ENOMEM
*/
-struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state,
- int flags, gfp_t gfp_flags)
+static struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl,
+ unsigned int state,
+ int flags, gfp_t gfp_flags)
{
struct gfs2_holder *gh;
gfs2_holder_init(gl, state, flags, gh);
set_bit(HIF_ALLOCED, &gh->gh_iflags);
-
+ gh->gh_ip = (unsigned long)__builtin_return_address(0);
return gh;
}
*
*/
-void gfs2_holder_put(struct gfs2_holder *gh)
+static void gfs2_holder_put(struct gfs2_holder *gh)
{
gfs2_holder_uninit(gh);
kfree(gh);
}
-/**
- * handle_recurse - put other holder structures (marked recursive)
- * into the holders list
- * @gh: the holder structure
- *
- */
-
-static void handle_recurse(struct gfs2_holder *gh)
-{
- struct gfs2_glock *gl = gh->gh_gl;
- struct gfs2_sbd *sdp = gl->gl_sbd;
- struct gfs2_holder *tmp_gh, *safe;
- int found = 0;
-
- if (gfs2_assert_warn(sdp, gh->gh_owner))
- return;
-
- list_for_each_entry_safe(tmp_gh, safe, &gl->gl_waiters3, gh_list) {
- if (tmp_gh->gh_owner != gh->gh_owner)
- continue;
-
- gfs2_assert_warn(sdp,
- test_bit(HIF_RECURSE, &tmp_gh->gh_iflags));
-
- list_move_tail(&tmp_gh->gh_list, &gl->gl_holders);
- tmp_gh->gh_error = 0;
- set_bit(HIF_HOLDER, &tmp_gh->gh_iflags);
-
- complete(&tmp_gh->gh_wait);
-
- found = 1;
- }
-
- gfs2_assert_warn(sdp, found);
-}
-
-/**
- * do_unrecurse - a recursive holder was just dropped of the waiters3 list
- * @gh: the holder
- *
- * If there is only one other recursive holder, clear its HIF_RECURSE bit.
- * If there is more than one, leave them alone.
- *
- */
-
-static void do_unrecurse(struct gfs2_holder *gh)
-{
- struct gfs2_glock *gl = gh->gh_gl;
- struct gfs2_sbd *sdp = gl->gl_sbd;
- struct gfs2_holder *tmp_gh, *last_gh = NULL;
- int found = 0;
-
- if (gfs2_assert_warn(sdp, gh->gh_owner))
- return;
-
- list_for_each_entry(tmp_gh, &gl->gl_waiters3, gh_list) {
- if (tmp_gh->gh_owner != gh->gh_owner)
- continue;
-
- gfs2_assert_warn(sdp,
- test_bit(HIF_RECURSE, &tmp_gh->gh_iflags));
-
- if (found)
- return;
-
- found = 1;
- last_gh = tmp_gh;
- }
-
- if (!gfs2_assert_warn(sdp, found))
- clear_bit(HIF_RECURSE, &last_gh->gh_iflags);
-}
-
/**
* rq_mutex - process a mutex request in the queue
* @gh: the glock holder
struct gfs2_glock *gl = gh->gh_gl;
struct gfs2_sbd *sdp = gl->gl_sbd;
struct gfs2_glock_operations *glops = gl->gl_ops;
- int recurse;
if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) {
if (list_empty(&gl->gl_holders)) {
if (list_empty(&gl->gl_holders)) {
set_bit(HIF_FIRST, &gh->gh_iflags);
set_bit(GLF_LOCK, &gl->gl_flags);
- recurse = 0;
} else {
struct gfs2_holder *next_gh;
if (gh->gh_flags & GL_LOCAL_EXCL)
gh_list);
if (next_gh->gh_flags & GL_LOCAL_EXCL)
return 1;
- recurse = test_bit(HIF_RECURSE, &gh->gh_iflags);
}
list_move_tail(&gh->gh_list, &gl->gl_holders);
gh->gh_error = 0;
set_bit(HIF_HOLDER, &gh->gh_iflags);
- if (recurse)
- handle_recurse(gh);
-
complete(&gh->gh_wait);
return 0;
* @gl: the glock
*
*/
-
static void run_queue(struct gfs2_glock *gl)
{
struct gfs2_holder *gh;
* Returns: 1 if the glock is acquired
*/
-int gfs2_glmutex_trylock(struct gfs2_glock *gl)
+static int gfs2_glmutex_trylock(struct gfs2_glock *gl)
{
int acquired = 1;
spin_lock(&gl->gl_spin);
clear_bit(GLF_LOCK, &gl->gl_flags);
run_queue(gl);
+ BUG_ON(!spin_is_locked(&gl->gl_spin));
spin_unlock(&gl->gl_spin);
}
} else {
spin_unlock(&gl->gl_spin);
- new_gh = gfs2_holder_get(gl, state,
- LM_FLAG_TRY | GL_NEVER_RECURSE,
+ new_gh = gfs2_holder_get(gl, state, LM_FLAG_TRY,
GFP_KERNEL | __GFP_NOFAIL),
set_bit(HIF_DEMOTE, &new_gh->gh_iflags);
set_bit(HIF_DEALLOC, &new_gh->gh_iflags);
spin_lock(&gl->gl_spin);
list_del_init(&gh->gh_list);
gh->gh_error = -EIO;
- if (test_bit(HIF_RECURSE, &gh->gh_iflags))
- do_unrecurse(gh);
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);
gh->gh_error = GLR_CANCELED;
- if (test_bit(HIF_RECURSE, &gh->gh_iflags))
- do_unrecurse(gh);
spin_unlock(&gl->gl_spin);
} else if (relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) {
spin_lock(&gl->gl_spin);
list_del_init(&gh->gh_list);
gh->gh_error = GLR_TRYFAILED;
- if (test_bit(HIF_RECURSE, &gh->gh_iflags))
- do_unrecurse(gh);
spin_unlock(&gl->gl_spin);
} else {
!list_empty(&gh->gh_list)) {
list_del_init(&gh->gh_list);
gh->gh_error = GLR_TRYFAILED;
- if (test_bit(HIF_RECURSE, &gh->gh_iflags))
- do_unrecurse(gh);
run_queue(gl);
spin_unlock(&gl->gl_spin);
return gh->gh_error;
if (gh->gh_error) {
spin_lock(&gl->gl_spin);
list_del_init(&gh->gh_list);
- if (test_and_clear_bit(HIF_RECURSE,
- &gh->gh_iflags))
- do_unrecurse(gh);
spin_unlock(&gl->gl_spin);
}
}
gl->gl_req_gh = NULL;
gl->gl_req_bh = NULL;
clear_bit(GLF_LOCK, &gl->gl_flags);
- if (test_bit(HIF_RECURSE, &gh->gh_iflags))
- handle_recurse(gh);
run_queue(gl);
spin_unlock(&gl->gl_spin);
}
return NULL;
}
-/**
- * recurse_check -
- *
- * Make sure the new holder is compatible with the pre-existing one.
- *
- */
-
-static int recurse_check(struct gfs2_holder *existing, struct gfs2_holder *new,
- unsigned int state)
-{
- struct gfs2_sbd *sdp = existing->gh_gl->gl_sbd;
-
- if (gfs2_assert_warn(sdp, (new->gh_flags & LM_FLAG_ANY) ||
- !(existing->gh_flags & LM_FLAG_ANY)))
- goto fail;
-
- if (gfs2_assert_warn(sdp, (existing->gh_flags & GL_LOCAL_EXCL) ||
- !(new->gh_flags & GL_LOCAL_EXCL)))
- goto fail;
-
- if (gfs2_assert_warn(sdp, relaxed_state_ok(state, new->gh_state,
- new->gh_flags)))
- goto fail;
-
- return 0;
-
- fail:
- set_bit(HIF_ABORTED, &new->gh_iflags);
- return -EINVAL;
-}
-
/**
* add_to_queue - Add a holder to the wait queue (but look for recursion)
* @gh: the holder structure to add
struct gfs2_glock *gl = gh->gh_gl;
struct gfs2_holder *existing;
- if (!gh->gh_owner)
- goto out;
+ BUG_ON(!gh->gh_owner);
existing = find_holder_by_owner(&gl->gl_holders, gh->gh_owner);
if (existing) {
- if (recurse_check(existing, gh, gl->gl_state))
- return;
-
- list_add_tail(&gh->gh_list, &gl->gl_holders);
- set_bit(HIF_HOLDER, &gh->gh_iflags);
-
- gh->gh_error = 0;
- complete(&gh->gh_wait);
-
- return;
+ print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip);
+ print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip);
+ BUG();
}
existing = find_holder_by_owner(&gl->gl_waiters3, gh->gh_owner);
if (existing) {
- if (recurse_check(existing, gh, existing->gh_state))
- return;
-
- set_bit(HIF_RECURSE, &gh->gh_iflags);
- set_bit(HIF_RECURSE, &existing->gh_iflags);
-
- list_add_tail(&gh->gh_list, &gl->gl_waiters3);
-
- return;
+ print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip);
+ print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip);
+ BUG();
}
- out:
if (gh->gh_flags & LM_FLAG_PRIORITY)
list_add(&gh->gh_list, &gl->gl_waiters3);
else
if (!(gh->gh_flags & GL_ASYNC)) {
error = glock_wait_internal(gh);
if (error == GLR_CANCELED) {
- msleep(1000);
+ msleep(100);
goto restart;
}
}
else if (list_empty(&gh->gh_list)) {
if (gh->gh_error == GLR_CANCELED) {
spin_unlock(&gl->gl_spin);
- msleep(1000);
+ msleep(100);
if (gfs2_glock_nq(gh))
return 1;
return 0;
error = glock_wait_internal(gh);
if (error == GLR_CANCELED) {
- msleep(1000);
+ msleep(100);
gh->gh_flags &= ~GL_ASYNC;
error = gfs2_glock_nq(gh);
}
*
*/
-void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags)
+static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state,
+ int flags)
{
struct gfs2_glock_operations *glops = gl->gl_ops;
glops->go_xmote_th(gl, state, flags);
}
-/**
- * gfs2_glock_force_drop - Force a glock to be uncached
- * @gl: the glock
- *
- */
-
-void gfs2_glock_force_drop(struct gfs2_glock *gl)
-{
- struct gfs2_holder gh;
-
- gfs2_holder_init(gl, LM_ST_UNLOCKED, GL_NEVER_RECURSE, &gh);
- set_bit(HIF_DEMOTE, &gh.gh_iflags);
-
- spin_lock(&gl->gl_spin);
- list_add_tail(&gh.gh_list, &gl->gl_waiters2);
- run_queue(gl);
- spin_unlock(&gl->gl_spin);
-
- wait_for_completion(&gh.gh_wait);
- gfs2_holder_uninit(&gh);
-}
-
static void greedy_work(void *data)
{
- struct greedy *gr = (struct greedy *)data;
+ struct greedy *gr = data;
struct gfs2_holder *gh = &gr->gr_gh;
struct gfs2_glock *gl = gh->gh_gl;
struct gfs2_glock_operations *glops = gl->gl_ops;
}
gh = &gr->gr_gh;
- gfs2_holder_init(gl, 0, GL_NEVER_RECURSE, gh);
+ gfs2_holder_init(gl, 0, 0, gh);
set_bit(HIF_GREEDY, &gh->gh_iflags);
INIT_WORK(&gr->gr_work, greedy_work, gr);
return 0;
}
-/**
- * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock
- * @gl: the glock
- * @state: the state we're requesting
- * @flags: the modifier flags
- * @gh: the holder structure
- *
- * Returns: 0, GLR_*, or errno
- */
-
-int gfs2_glock_nq_init(struct gfs2_glock *gl, unsigned int state, int flags,
- struct gfs2_holder *gh)
-{
- int error;
-
- gfs2_holder_init(gl, state, flags, gh);
-
- error = gfs2_glock_nq(gh);
- if (error)
- gfs2_holder_uninit(gh);
-
- return error;
-}
-
/**
* gfs2_glock_dq_uninit - dequeue a holder from a glock and initialize it
* @gh: the holder structure
gfs2_glock_put(gl);
}
+#if 0
void gfs2_lvb_sync(struct gfs2_glock *gl)
{
gfs2_glmutex_lock(gl);
gfs2_glmutex_unlock(gl);
}
+#endif /* 0 */
static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
unsigned int state)
switch (type) {
case LM_CB_NEED_E:
- blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_UNLOCKED);
+ blocking_cb(sdp, data, LM_ST_UNLOCKED);
return;
case LM_CB_NEED_D:
- blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_DEFERRED);
+ blocking_cb(sdp, data, LM_ST_DEFERRED);
return;
case LM_CB_NEED_S:
- blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_SHARED);
+ blocking_cb(sdp, data, LM_ST_SHARED);
return;
case LM_CB_ASYNC: {
- struct lm_async_cb *async = (struct lm_async_cb *)data;
+ struct lm_async_cb *async = data;
struct gfs2_glock *gl;
gl = gfs2_glock_find(sdp, &async->lc_name);
if (!gfs2_assert_warn(sdp, gl->gl_req_bh))
gl->gl_req_bh(gl, async->lc_ret);
gfs2_glock_put(gl);
-
return;
}
if (atomic_read(&ip->i_count))
goto out_unlock;
- gfs2_inode_destroy(ip);
+ gfs2_inode_destroy(ip, 1);
out_unlock:
gfs2_glmutex_unlock(gl);
if (gl->gl_ops == &gfs2_inode_glops) {
struct gfs2_inode *ip = gl->gl_object;
if (ip && !atomic_read(&ip->i_count))
- gfs2_inode_destroy(ip);
+ gfs2_inode_destroy(ip, 1);
}
if (queue_empty(gl, &gl->gl_holders) &&
gl->gl_state != LM_ST_UNLOCKED &&
if (!list_empty(&gl->gl_reclaim)) {
list_del_init(&gl->gl_reclaim);
atomic_dec(&sdp->sd_reclaim_count);
+ spin_unlock(&sdp->sd_reclaim_lock);
released = gfs2_glock_put(gl);
gfs2_assert(sdp, !released);
+ } else {
+ spin_unlock(&sdp->sd_reclaim_lock);
}
- spin_unlock(&sdp->sd_reclaim_lock);
if (gfs2_glmutex_trylock(gl)) {
if (gl->gl_ops == &gfs2_inode_glops) {
struct gfs2_inode *ip = gl->gl_object;
if (ip && !atomic_read(&ip->i_count))
- gfs2_inode_destroy(ip);
+ gfs2_inode_destroy(ip, 1);
}
if (queue_empty(gl, &gl->gl_holders) &&
gl->gl_state != LM_ST_UNLOCKED)
mutex_lock(&sdp->sd_invalidate_inodes_mutex);
invalidate_inodes(sdp->sd_vfs);
mutex_unlock(&sdp->sd_invalidate_inodes_mutex);
- yield();
+ msleep(10);
}
}
if (test_bit(x, &gh->gh_iflags))
printk(" %u", x);
printk(" \n");
+ print_symbol(KERN_INFO " initialized at: %s\n", gh->gh_ip);
error = 0;
*
*/
-int gfs2_dump_lockstate(struct gfs2_sbd *sdp)
+static int gfs2_dump_lockstate(struct gfs2_sbd *sdp)
{
struct gfs2_gl_hash_bucket *bucket;
struct gfs2_glock *gl;