[Ocfs2-commits] mfasheh commits r1873 - trunk/fs/ocfs2/dlm
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Mon Jan 31 21:32:25 CST 2005
Author: mfasheh
Date: 2005-01-31 21:32:23 -0600 (Mon, 31 Jan 2005)
New Revision: 1873
Modified:
trunk/fs/ocfs2/dlm/dlmlock.c
trunk/fs/ocfs2/dlm/dlmmod.c
trunk/fs/ocfs2/dlm/dlmmod.h
Log:
* Don't queue new locks when NOQUEUE is specified.
* Instead of fixing the above bug twice, factor out identical code into a
common function.
* remove dlm_wait_on_lockres as there was only one caller it it was trivial
to change him to use __dlm_wait_on_lockres instead.
Modified: trunk/fs/ocfs2/dlm/dlmlock.c
===================================================================
--- trunk/fs/ocfs2/dlm/dlmlock.c 2005-01-31 23:52:37 UTC (rev 1872)
+++ trunk/fs/ocfs2/dlm/dlmlock.c 2005-02-01 03:32:23 UTC (rev 1873)
@@ -54,6 +54,36 @@
dlm_lock_resource *res,
dlm_lock *lock, int flags);
+/* Tell us whether we can grant a new lock request.
+ * locking:
+ * caller needs: res->spinlock
+ * taken: none
+ * held on exit: none
+ * returns: 1 if the lock can be granted, 0 otherwise.
+ */
+static int dlm_can_grant_new_lock(dlm_lock_resource *res,
+ dlm_lock *lock)
+{
+ struct list_head *iter;
+ dlm_lock *tmplock;
+
+ list_for_each(iter, &res->granted) {
+ tmplock = list_entry(iter, dlm_lock, list);
+
+ if (!dlm_lock_compatible(tmplock->type, lock->type))
+ return 0;
+ }
+
+ list_for_each(iter, &res->converting) {
+ tmplock = list_entry(iter, dlm_lock, list);
+
+ if (!dlm_lock_compatible(tmplock->type, lock->type))
+ return 0;
+ }
+
+ return 1;
+}
+
/* performs lock creation at the lockres master site
* locking:
* caller needs: none
@@ -64,8 +94,6 @@
dlm_status dlmlock_master(dlm_ctxt *dlm, dlm_lock_resource *res,
dlm_lock *lock, int flags)
{
- struct list_head *iter;
- dlm_lock *tmplock;
int call_ast = 0;
dlm_status status = DLM_NORMAL;
@@ -76,50 +104,33 @@
dlmprintk("type=%d\n", lock->type);
- /* this will effectively spin_lock(&res->spinlock) */
- dlm_wait_on_lockres(res);
- res->state |= DLM_LOCK_RES_IN_PROGRESS;
+ spin_lock(&res->spinlock);
+ __dlm_wait_on_lockres(res);
- /* for NOQUEUE request, unless we get
- * lock right away, return DLM_NOTQUEUED */
- if (flags & LKM_NOQUEUE)
- status = DLM_NOTQUEUED;
-
- list_for_each(iter, &res->granted) {
- tmplock = list_entry(iter, dlm_lock, list);
- if (!dlm_lock_compatible(tmplock->type, lock->type)) {
+ if (dlm_can_grant_new_lock(res, lock)) {
+ /* got it right away */
+ lock->lksb->status = DLM_NORMAL;
+ status = DLM_NORMAL;
+ list_add_tail(&lock->list, &res->granted);
+ call_ast = 1;
+ } else {
+ /* for NOQUEUE request, unless we get the
+ * lock right away, return DLM_NOTQUEUED */
+ if (flags & LKM_NOQUEUE)
+ status = DLM_NOTQUEUED;
+ else
list_add_tail(&lock->list, &res->blocked);
- goto done;
- }
}
- list_for_each(iter, &res->converting) {
- tmplock = list_entry(iter, dlm_lock, list);
- if (!dlm_lock_compatible(tmplock->type, lock->type)) {
- list_add_tail(&lock->list, &res->blocked);
- goto done;
- }
- }
-
- /* got it right away */
- lock->lksb->status = DLM_NORMAL;
- status = DLM_NORMAL;
- list_add_tail(&lock->list, &res->granted);
- call_ast = 1;
-
-done:
- res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
spin_unlock(&res->spinlock);
wake_up(&res->wq);
- dlm_kick_thread(dlm, res);
-
- if (call_ast) {
-#warning fix all ast calling!!!
+ if (call_ast)
if (dlm_do_ast(dlm, res, lock) < 0)
dlmprintk0("eek\n");
- }
+ dlm_kick_thread(dlm, res);
+
return status;
}
@@ -226,12 +237,10 @@
dlm_ctxt *dlm = data;
dlm_create_lock *create = (dlm_create_lock *)msg->buf;
dlm_lock_resource *res;
- dlm_lock *newlock = NULL, *tmplock;
+ dlm_lock *newlock;
dlm_lockstatus *lksb = NULL;
dlm_status status = DLM_NORMAL;
struct qstr lockname;
- struct list_head *iter;
- int call_ast = 0;
DLM_ASSERT(dlm);
@@ -275,48 +284,10 @@
if (!res)
goto leave;
- /* found lock resource */
- status = DLM_NORMAL;
- spin_lock(&res->spinlock);
newlock->lockres = res;
- /* for NOQUEUE request, unless we get
- * lock right away, return DLM_NOTQUEUED */
- if (create->flags & LKM_NOQUEUE)
- status = DLM_NOTQUEUED;
+ status = dlmlock_master(dlm, res, newlock, create->flags);
- /* see if any granted locks are blocking us */
- list_for_each(iter, &res->granted) {
- tmplock = list_entry(iter, dlm_lock, list);
- if (!dlm_lock_compatible(tmplock->type, newlock->type)) {
- list_add_tail(&newlock->list, &res->blocked);
- goto blocked;
- }
- }
- list_for_each(iter, &res->converting) {
- tmplock = list_entry(iter, dlm_lock, list);
- if (!dlm_lock_compatible(tmplock->type, newlock->type)){
- list_add_tail(&newlock->list, &res->blocked);
- goto blocked;
- }
- }
-
- /* got it right away */
- newlock->lksb->status = DLM_NORMAL;
- status = DLM_NORMAL;
- list_add_tail(&newlock->list, &res->granted);
- call_ast = 1;
-
-blocked:
- spin_unlock(&res->spinlock);
-
-#warning fix all ast calling!!!
- if (call_ast)
- if (dlm_do_ast(dlm, res, newlock) < 0)
- dlmprintk0("eek\n");
-
- dlm_kick_thread(dlm, res);
-
leave:
if (status != DLM_NORMAL) {
if (newlock)
Modified: trunk/fs/ocfs2/dlm/dlmmod.c
===================================================================
--- trunk/fs/ocfs2/dlm/dlmmod.c 2005-01-31 23:52:37 UTC (rev 1872)
+++ trunk/fs/ocfs2/dlm/dlmmod.c 2005-02-01 03:32:23 UTC (rev 1873)
@@ -675,29 +675,7 @@
res->state |= DLM_LOCK_RES_IN_PROGRESS;
}
-
-
-
/* will exit holding res->spinlock, but may drop in function */
-void dlm_wait_on_lockres(dlm_lock_resource *res)
-{
- DECLARE_WAITQUEUE(wait, current);
-
- add_wait_queue(&res->wq, &wait);
-repeat:
- set_current_state(TASK_UNINTERRUPTIBLE);
-
- spin_lock(&res->spinlock);
- if (res->state & DLM_LOCK_RES_IN_PROGRESS) {
- spin_unlock(&res->spinlock);
- schedule();
- goto repeat;
- }
- remove_wait_queue(&res->wq, &wait);
- current->state = TASK_RUNNING;
-}
-
-/* will exit holding res->spinlock, but may drop in function */
void __dlm_wait_on_lockres(dlm_lock_resource *res)
{
DECLARE_WAITQUEUE(wait, current);
Modified: trunk/fs/ocfs2/dlm/dlmmod.h
===================================================================
--- trunk/fs/ocfs2/dlm/dlmmod.h 2005-01-31 23:52:37 UTC (rev 1872)
+++ trunk/fs/ocfs2/dlm/dlmmod.h 2005-02-01 03:32:23 UTC (rev 1873)
@@ -587,14 +587,12 @@
int dlm_assert_master_handler(net_msg *msg, u32 len, void *data);
dlm_lock_resource * __dlm_lookup_lock(dlm_ctxt *dlm, struct qstr *lockname);
void dlm_init_lockres(dlm_lock_resource *res, struct qstr *lockname);
-void dlm_wait_on_lockres(dlm_lock_resource *res);
void dlm_dump_everything(void);
void dlm_dump_dlm(dlm_ctxt *dlm);
int dlm_lock_owner_broadcast(dlm_ctxt *dlm, dlm_lock_resource *res);
int dlm_lock_owner_broadcast(dlm_ctxt *dlm, dlm_lock_resource *res);
-void dlm_wait_on_lockres(dlm_lock_resource *res);
void __dlm_wait_on_lockres(dlm_lock_resource *res);
More information about the Ocfs2-commits
mailing list