]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/gfs2/glock.c
[AFS]: Fix VLocation record update wakeup
[linux-2.6-omap-h63xx.git] / fs / gfs2 / glock.c
index 5341e03b873f6fb04d9f3912f773ea07111afb47..12accb08fe02d3e701fa49e79d9e1a1c7519f495 100644 (file)
@@ -20,6 +20,8 @@
 #include <linux/list.h>
 #include <linux/lm_interface.h>
 #include <linux/wait.h>
+#include <linux/module.h>
+#include <linux/rwsem.h>
 #include <asm/uaccess.h>
 
 #include "gfs2.h"
 #include "super.h"
 #include "util.h"
 
-struct greedy {
-       struct gfs2_holder gr_gh;
-       struct delayed_work gr_work;
-};
-
 struct gfs2_gl_hash_bucket {
         struct hlist_head hb_list;
 };
@@ -48,6 +45,9 @@ typedef void (*glock_examiner) (struct gfs2_glock * gl);
 static int gfs2_dump_lockstate(struct gfs2_sbd *sdp);
 static int dump_glock(struct gfs2_glock *gl);
 static int dump_inode(struct gfs2_inode *ip);
+static void gfs2_glock_xmote_th(struct gfs2_holder *gh);
+static void gfs2_glock_drop_th(struct gfs2_glock *gl);
+static DECLARE_RWSEM(gfs2_umount_flush_sem);
 
 #define GFS2_GL_HASH_SHIFT      15
 #define GFS2_GL_HASH_SIZE       (1 << GFS2_GL_HASH_SHIFT)
@@ -213,30 +213,6 @@ out:
        return rv;
 }
 
-/**
- * queue_empty - check to see if a glock's queue is empty
- * @gl: the glock
- * @head: the head of the queue to check
- *
- * This function protects the list in the event that a process already
- * has a holder on the list and is adding a second holder for itself.
- * The glmutex lock is what generally prevents processes from working
- * on the same glock at once, but the special case of adding a second
- * holder for yourself ("recursive" locking) doesn't involve locking
- * glmutex, making the spin lock necessary.
- *
- * Returns: 1 if the queue is empty
- */
-
-static inline int queue_empty(struct gfs2_glock *gl, struct list_head *head)
-{
-       int empty;
-       spin_lock(&gl->gl_spin);
-       empty = list_empty(head);
-       spin_unlock(&gl->gl_spin);
-       return empty;
-}
-
 /**
  * search_bucket() - Find struct gfs2_glock by lock number
  * @bucket: the bucket to search
@@ -396,10 +372,6 @@ void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags,
        gh->gh_flags = flags;
        gh->gh_error = 0;
        gh->gh_iflags = 0;
-
-       if (gh->gh_state == LM_ST_EXCLUSIVE)
-               gh->gh_flags |= GL_LOCAL_EXCL;
-
        gfs2_glock_hold(gl);
 }
 
@@ -417,9 +389,6 @@ void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder *
 {
        gh->gh_state = state;
        gh->gh_flags = flags;
-       if (gh->gh_state == LM_ST_EXCLUSIVE)
-               gh->gh_flags |= GL_LOCAL_EXCL;
-
        gh->gh_iflags &= 1 << HIF_ALLOCED;
        gh->gh_ip = (unsigned long)__builtin_return_address(0);
 }
@@ -516,7 +485,7 @@ static int rq_mutex(struct gfs2_holder *gh)
        list_del_init(&gh->gh_list);
        /*  gh->gh_error never examined.  */
        set_bit(GLF_LOCK, &gl->gl_flags);
-       clear_bit(HIF_WAIT, &gh->gh_flags);
+       clear_bit(HIF_WAIT, &gh->gh_iflags);
        smp_mb();
        wake_up_bit(&gh->gh_iflags, HIF_WAIT);
 
@@ -536,7 +505,6 @@ static int rq_promote(struct gfs2_holder *gh)
 {
        struct gfs2_glock *gl = gh->gh_gl;
        struct gfs2_sbd *sdp = gl->gl_sbd;
-       const struct gfs2_glock_operations *glops = gl->gl_ops;
 
        if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) {
                if (list_empty(&gl->gl_holders)) {
@@ -551,7 +519,7 @@ static int rq_promote(struct gfs2_holder *gh)
                                gfs2_reclaim_glock(sdp);
                        }
 
-                       glops->go_xmote_th(gl, gh->gh_state, gh->gh_flags);
+                       gfs2_glock_xmote_th(gh);
                        spin_lock(&gl->gl_spin);
                }
                return 1;
@@ -562,11 +530,11 @@ static int rq_promote(struct gfs2_holder *gh)
                set_bit(GLF_LOCK, &gl->gl_flags);
        } else {
                struct gfs2_holder *next_gh;
-               if (gh->gh_flags & GL_LOCAL_EXCL)
+               if (gh->gh_state == LM_ST_EXCLUSIVE)
                        return 1;
                next_gh = list_entry(gl->gl_holders.next, struct gfs2_holder,
                                     gh_list);
-               if (next_gh->gh_flags & GL_LOCAL_EXCL)
+               if (next_gh->gh_state == LM_ST_EXCLUSIVE)
                         return 1;
        }
 
@@ -589,7 +557,6 @@ static int rq_promote(struct gfs2_holder *gh)
 static int rq_demote(struct gfs2_holder *gh)
 {
        struct gfs2_glock *gl = gh->gh_gl;
-       const struct gfs2_glock_operations *glops = gl->gl_ops;
 
        if (!list_empty(&gl->gl_holders))
                return 1;
@@ -607,9 +574,9 @@ static int rq_demote(struct gfs2_holder *gh)
 
                if (gh->gh_state == LM_ST_UNLOCKED ||
                    gl->gl_state != LM_ST_EXCLUSIVE)
-                       glops->go_drop_th(gl);
+                       gfs2_glock_drop_th(gl);
                else
-                       glops->go_xmote_th(gl, gh->gh_state, gh->gh_flags);
+                       gfs2_glock_xmote_th(gh);
 
                spin_lock(&gl->gl_spin);
        }
@@ -617,30 +584,6 @@ static int rq_demote(struct gfs2_holder *gh)
        return 0;
 }
 
-/**
- * rq_greedy - process a queued request to drop greedy status
- * @gh: the glock holder
- *
- * Returns: 1 if the queue is blocked
- */
-
-static int rq_greedy(struct gfs2_holder *gh)
-{
-       struct gfs2_glock *gl = gh->gh_gl;
-
-       list_del_init(&gh->gh_list);
-       /*  gh->gh_error never examined.  */
-       clear_bit(GLF_GREEDY, &gl->gl_flags);
-       spin_unlock(&gl->gl_spin);
-
-       gfs2_holder_uninit(gh);
-       kfree(container_of(gh, struct greedy, gr_gh));
-
-       spin_lock(&gl->gl_spin);
-
-       return 0;
-}
-
 /**
  * run_queue - process holder structures on a glock
  * @gl: the glock
@@ -671,8 +614,6 @@ static void run_queue(struct gfs2_glock *gl)
 
                        if (test_bit(HIF_DEMOTE, &gh->gh_iflags))
                                blocked = rq_demote(gh);
-                       else if (test_bit(HIF_GREEDY, &gh->gh_iflags))
-                               blocked = rq_greedy(gh);
                        else
                                gfs2_assert_warn(gl->gl_sbd, 0);
 
@@ -852,7 +793,7 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret)
        int op_done = 1;
 
        gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
-       gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
+       gfs2_assert_warn(sdp, list_empty(&gl->gl_holders));
        gfs2_assert_warn(sdp, !(ret & LM_OUT_ASYNC));
 
        state_change(gl, ret & LM_OUT_ST_MASK);
@@ -947,23 +888,26 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret)
  *
  */
 
-void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags)
+void gfs2_glock_xmote_th(struct gfs2_holder *gh)
 {
+       struct gfs2_glock *gl = gh->gh_gl;
        struct gfs2_sbd *sdp = gl->gl_sbd;
+       int flags = gh->gh_flags;
+       unsigned state = gh->gh_state;
        const struct gfs2_glock_operations *glops = gl->gl_ops;
        int lck_flags = flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB |
                                 LM_FLAG_NOEXP | LM_FLAG_ANY |
                                 LM_FLAG_PRIORITY);
        unsigned int lck_ret;
 
+       if (glops->go_xmote_th)
+               glops->go_xmote_th(gl);
+
        gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
-       gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
+       gfs2_assert_warn(sdp, list_empty(&gl->gl_holders));
        gfs2_assert_warn(sdp, state != LM_ST_UNLOCKED);
        gfs2_assert_warn(sdp, state != gl->gl_state);
 
-       if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
-               glops->go_sync(gl);
-
        gfs2_glock_hold(gl);
        gl->gl_req_bh = xmote_bh;
 
@@ -995,7 +939,7 @@ static void drop_bh(struct gfs2_glock *gl, unsigned int ret)
        struct gfs2_holder *gh = gl->gl_req_gh;
 
        gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
-       gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
+       gfs2_assert_warn(sdp, list_empty(&gl->gl_holders));
        gfs2_assert_warn(sdp, !ret);
 
        state_change(gl, LM_ST_UNLOCKED);
@@ -1010,9 +954,6 @@ static void drop_bh(struct gfs2_glock *gl, unsigned int ret)
                spin_unlock(&gl->gl_spin);
        }
 
-       if (glops->go_drop_bh)
-               glops->go_drop_bh(gl);
-
        spin_lock(&gl->gl_spin);
        gl->gl_req_gh = NULL;
        gl->gl_req_bh = NULL;
@@ -1032,19 +973,19 @@ static void drop_bh(struct gfs2_glock *gl, unsigned int ret)
  *
  */
 
-void gfs2_glock_drop_th(struct gfs2_glock *gl)
+static void gfs2_glock_drop_th(struct gfs2_glock *gl)
 {
        struct gfs2_sbd *sdp = gl->gl_sbd;
        const struct gfs2_glock_operations *glops = gl->gl_ops;
        unsigned int ret;
 
+       if (glops->go_drop_th)
+               glops->go_drop_th(gl);
+
        gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
-       gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
+       gfs2_assert_warn(sdp, list_empty(&gl->gl_holders));
        gfs2_assert_warn(sdp, gl->gl_state != LM_ST_UNLOCKED);
 
-       if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
-               glops->go_sync(gl);
-
        gfs2_glock_hold(gl);
        gl->gl_req_bh = drop_bh;
 
@@ -1336,68 +1277,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
        spin_unlock(&gl->gl_spin);
 }
 
-static void greedy_work(struct work_struct *work)
-{
-       struct greedy *gr = container_of(work, struct greedy, gr_work.work);
-       struct gfs2_holder *gh = &gr->gr_gh;
-       struct gfs2_glock *gl = gh->gh_gl;
-       const struct gfs2_glock_operations *glops = gl->gl_ops;
-
-       clear_bit(GLF_SKIP_WAITERS2, &gl->gl_flags);
-
-       if (glops->go_greedy)
-               glops->go_greedy(gl);
-
-       spin_lock(&gl->gl_spin);
-
-       if (list_empty(&gl->gl_waiters2)) {
-               clear_bit(GLF_GREEDY, &gl->gl_flags);
-               spin_unlock(&gl->gl_spin);
-               gfs2_holder_uninit(gh);
-               kfree(gr);
-       } else {
-               gfs2_glock_hold(gl);
-               list_add_tail(&gh->gh_list, &gl->gl_waiters2);
-               run_queue(gl);
-               spin_unlock(&gl->gl_spin);
-               gfs2_glock_put(gl);
-       }
-}
-
-/**
- * gfs2_glock_be_greedy -
- * @gl:
- * @time:
- *
- * Returns: 0 if go_greedy will be called, 1 otherwise
- */
-
-int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time)
-{
-       struct greedy *gr;
-       struct gfs2_holder *gh;
-
-       if (!time || gl->gl_sbd->sd_args.ar_localcaching ||
-           test_and_set_bit(GLF_GREEDY, &gl->gl_flags))
-               return 1;
-
-       gr = kmalloc(sizeof(struct greedy), GFP_KERNEL);
-       if (!gr) {
-               clear_bit(GLF_GREEDY, &gl->gl_flags);
-               return 1;
-       }
-       gh = &gr->gr_gh;
-
-       gfs2_holder_init(gl, 0, 0, gh);
-       set_bit(HIF_GREEDY, &gh->gh_iflags);
-       INIT_DELAYED_WORK(&gr->gr_work, greedy_work);
-
-       set_bit(GLF_SKIP_WAITERS2, &gl->gl_flags);
-       schedule_delayed_work(&gr->gr_work, time);
-
-       return 0;
-}
-
 /**
  * gfs2_glock_dq_uninit - dequeue a holder from a glock and initialize it
  * @gh: the holder structure
@@ -1456,10 +1335,7 @@ static int glock_compare(const void *arg_a, const void *arg_b)
                return 1;
        if (a->ln_number < b->ln_number)
                return -1;
-       if (gh_a->gh_state == LM_ST_SHARED && gh_b->gh_state == LM_ST_EXCLUSIVE)
-               return 1;
-       if (!(gh_a->gh_flags & GL_LOCAL_EXCL) && (gh_b->gh_flags & GL_LOCAL_EXCL))
-               return 1;
+       BUG_ON(gh_a->gh_gl->gl_ops->go_type == gh_b->gh_gl->gl_ops->go_type);
        return 0;
 }
 
@@ -1661,8 +1537,6 @@ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
        if (!gl)
                return;
 
-       if (gl->gl_ops->go_callback)
-               gl->gl_ops->go_callback(gl, state);
        handle_callback(gl, state);
 
        spin_lock(&gl->gl_spin);
@@ -1704,12 +1578,14 @@ void gfs2_glock_cb(void *cb_data, unsigned int type, void *data)
                struct lm_async_cb *async = data;
                struct gfs2_glock *gl;
 
+               down_read(&gfs2_umount_flush_sem);
                gl = gfs2_glock_find(sdp, &async->lc_name);
                if (gfs2_assert_warn(sdp, gl))
                        return;
                if (!gfs2_assert_warn(sdp, gl->gl_req_bh))
                        gl->gl_req_bh(gl, async->lc_ret);
                gfs2_glock_put(gl);
+               up_read(&gfs2_umount_flush_sem);
                return;
        }
 
@@ -1799,7 +1675,7 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp)
        atomic_inc(&sdp->sd_reclaimed);
 
        if (gfs2_glmutex_trylock(gl)) {
-               if (queue_empty(gl, &gl->gl_holders) &&
+               if (list_empty(&gl->gl_holders) &&
                    gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl))
                        handle_callback(gl, LM_ST_UNLOCKED);
                gfs2_glmutex_unlock(gl);
@@ -1863,7 +1739,7 @@ static void scan_glock(struct gfs2_glock *gl)
                return;
 
        if (gfs2_glmutex_trylock(gl)) {
-               if (queue_empty(gl, &gl->gl_holders) &&
+               if (list_empty(&gl->gl_holders) &&
                    gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl))
                        goto out_schedule;
                gfs2_glmutex_unlock(gl);
@@ -1912,7 +1788,7 @@ static void clear_glock(struct gfs2_glock *gl)
        }
 
        if (gfs2_glmutex_trylock(gl)) {
-               if (queue_empty(gl, &gl->gl_holders) &&
+               if (list_empty(&gl->gl_holders) &&
                    gl->gl_state != LM_ST_UNLOCKED)
                        handle_callback(gl, LM_ST_UNLOCKED);
                gfs2_glmutex_unlock(gl);
@@ -1954,7 +1830,9 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait)
                        t = jiffies;
                }
 
+               down_write(&gfs2_umount_flush_sem);
                invalidate_inodes(sdp->sd_vfs);
+               up_write(&gfs2_umount_flush_sem);
                msleep(10);
        }
 }