#include <linux/obd_support.h>
#include <linux/obd_class.h>
#include <linux/lustre_lib.h>
-#include <portals/list.h>
+#include <libcfs/list.h>
#else
#include <liblustre.h>
#endif
static struct list_head ldlm_flock_waitq = LIST_HEAD_INIT(ldlm_flock_waitq);
+int ldlm_flock_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
+ void *data, int flag);
+
/**
* list_for_remaining_safe - iterate over the remaining entries in a list
* and safeguard against removal of a list entry.
LDLM_DEBUG(lock, "ldlm_flock_destroy(mode: %d, flags: 0x%x)",
mode, flags);
+ LASSERT(list_empty(&lock->l_flock_waitq));
list_del_init(&lock->l_res_link);
if (flags == LDLM_FL_WAIT_NOREPROC) {
/* client side - set a flag to prevent sending a CANCEL */
struct ldlm_lock *new = req;
struct ldlm_lock *new2 = NULL;
ldlm_mode_t mode = req->l_req_mode;
+ int local = ns->ns_client;
int added = (mode == LCK_NL);
int overlaps = 0;
ENTRY;
- CDEBUG(D_DLMTRACE, "flags %#x pid %u mode %u start "LPU64" end "LPU64
- "\n", *flags, new->l_policy_data.l_flock.pid, mode,
- req->l_policy_data.l_flock.start,
+ CDEBUG(D_DLMTRACE, "flags %#x pid %u mode %u start "LPU64" end "
+ LPU64"\n", *flags, (unsigned int)new->l_policy_data.l_flock.pid,
+ mode, req->l_policy_data.l_flock.start,
req->l_policy_data.l_flock.end);
*err = ELDLM_OK;
- /* No blocking ASTs are sent for Posix file & record locks */
- req->l_blocking_ast = NULL;
+ if (local) {
+ /* No blocking ASTs are sent to the clients for
+ * Posix file & record locks */
+ req->l_blocking_ast = NULL;
+ } else {
+ /* Called on the server for lock cancels. */
+ req->l_blocking_ast = ldlm_flock_blocking_ast;
+ }
if ((*flags == LDLM_FL_WAIT_NOREPROC) || (mode == LCK_NL)) {
/* This loop determines where this processes locks start
}
}
} else {
+ lockmode_verify(mode);
+
/* This loop determines if there are existing locks
* that conflict with the new lock request. */
list_for_each(tmp, &res->lr_granted) {
/* locks are compatible, overlap doesn't matter */
if (lockmode_compat(lock->l_granted_mode, mode))
continue;
-
+
if (!ldlm_flocks_overlap(lock, req))
continue;
RETURN(LDLM_ITER_STOP);
}
+ /* In case we had slept on this lock request take it off of the
+ * deadlock detection waitq. */
+ list_del_init(&req->l_flock_waitq);
+
/* Scan the locks owned by this process that overlap this request.
* We may have to merge or split existing locks. */
break;
}
+ /* At this point we're granting the lock request. */
+ req->l_granted_mode = req->l_req_mode;
+
/* Add req to the granted queue before calling ldlm_reprocess_all(). */
if (!added) {
- req->l_granted_mode = req->l_req_mode;
list_del_init(&req->l_res_link);
/* insert new lock before ownlocks in list. */
ldlm_resource_add_lock(res, ownlocks, req);
if (added)
ldlm_flock_destroy(req, mode, *flags);
- ldlm_resource_dump(res);
+ ldlm_resource_dump(D_OTHER, res);
RETURN(LDLM_ITER_CONTINUE);
}
{
struct ldlm_lock *lock;
struct lustre_handle lockh;
- int rc;
ENTRY;
lock = ((struct ldlm_flock_wait_data *)data)->fwd_lock;
+
+ /* take lock off the deadlock detection waitq. */
+ list_del_init(&lock->l_flock_waitq);
+
+ /* client side - set flag to prevent lock from being put on lru list */
+ lock->l_flags |= LDLM_FL_CBPENDING;
+
ldlm_lock_decref_internal(lock, lock->l_req_mode);
ldlm_lock2handle(lock, &lockh);
- rc = ldlm_cli_cancel(&lockh);
- CDEBUG(D_DLMTRACE, "ldlm_cli_cancel: %d\n", rc);
+ ldlm_cli_cancel(&lockh);
EXIT;
}
LASSERT(flags != LDLM_FL_WAIT_NOREPROC);
- if (flags == 0) {
- wake_up(&lock->l_waitq);
- RETURN(0);
- }
-
if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
LDLM_FL_BLOCK_CONV)))
goto granted;
LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, "
"sleeping");
- ldlm_lock_dump(D_OTHER, lock, 0);
-
+ ldlm_lock_dump(D_DLMTRACE, lock, 0);
fwd.fwd_lock = lock;
obd = class_exp2obd(lock->l_conn_export);
spin_unlock_irqrestore(&imp->imp_lock, irqflags);
}
- lwi = LWI_TIMEOUT_INTR(0,NULL,ldlm_flock_interrupted_wait,&fwd);
+ lwi = LWI_TIMEOUT_INTR(0, NULL, ldlm_flock_interrupted_wait, &fwd);
/* Go to sleep until the lock is granted. */
rc = l_wait_event(lock->l_waitq,
((lock->l_req_mode == lock->l_granted_mode) ||
lock->l_destroyed), &lwi);
- if (rc) {
- LDLM_DEBUG(lock, "client-side enqueue waking up: failed (%d)",
- rc);
- RETURN(rc);
- }
-
- LASSERT(!(lock->l_destroyed));
-
+ LDLM_DEBUG(lock, "client-side enqueue waking up: rc = %d", rc);
+ RETURN(rc);
+
granted:
- LDLM_DEBUG(lock, "client-side enqueue waking up");
+ LDLM_DEBUG(lock, "client-side enqueue granted");
ns = lock->l_resource->lr_namespace;
l_lock(&ns->ns_lock);
- /* take data off of deadlock detection waitq. */
+ /* take lock off the deadlock detection waitq. */
list_del_init(&lock->l_flock_waitq);
/* ldlm_lock_enqueue() has already placed lock on the granted list. */
getlk->fl_start = lock->l_policy_data.l_flock.start;
getlk->fl_end = lock->l_policy_data.l_flock.end;
} else {
+ int noreproc = LDLM_FL_WAIT_NOREPROC;
+
/* We need to reprocess the lock to do merges or splits
- * with existing locks owne by this process. */
- flags = LDLM_FL_WAIT_NOREPROC;
- ldlm_process_flock_lock(lock, &flags, 1, &err);
+ * with existing locks owned by this process. */
+ ldlm_process_flock_lock(lock, &noreproc, 1, &err);
+ if (flags == 0)
+ wake_up(&lock->l_waitq);
}
l_unlock(&ns->ns_lock);
RETURN(0);
}
+
+int ldlm_flock_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
+ void *data, int flag)
+{
+ struct ldlm_namespace *ns;
+ ENTRY;
+
+ LASSERT(lock);
+ LASSERT(flag == LDLM_CB_CANCELING);
+
+ ns = lock->l_resource->lr_namespace;
+
+ /* take lock off the deadlock detection waitq. */
+ l_lock(&ns->ns_lock);
+ list_del_init(&lock->l_flock_waitq);
+ l_unlock(&ns->ns_lock);
+ RETURN(0);
+}