struct ldlm_namespace *ns = lock->l_resource->lr_namespace;
LASSERT(lock->l_resource->lr_type != LDLM_FLOCK);
list_del_init(&lock->l_lru);
+ LASSERT(ns->ns_nr_unused > 0);
ns->ns_nr_unused--;
- LASSERT(ns->ns_nr_unused >= 0);
rc = 1;
}
return rc;
}
lock->l_destroyed = 1;
- if (lock->l_export && lock->l_export->exp_lock_hash)
+ if (lock->l_export && lock->l_export->exp_lock_hash &&
+ !hlist_unhashed(&lock->l_exp_hash))
lustre_hash_del(lock->l_export->exp_lock_hash,
&lock->l_remote_handle, &lock->l_exp_hash);
CFS_INIT_LIST_HEAD(&lock->l_cache_locks_list);
lu_ref_init(&lock->l_reference);
lu_ref_add(&lock->l_reference, "hash", lock);
+ lock->l_callback_timeout = 0;
RETURN(lock);
}
lock_res(oldres);
lock_res_nested(newres, LRT_NEW);
} else {
- lock_res(newres);
+ lock_res(newres);
lock_res_nested(oldres, LRT_NEW);
}
LASSERT(memcmp(new_resid, &oldres->lr_name,
lock = ldlm_handle2lock(lockh);
if (lock != NULL) {
lock_res_and_lock(lock);
- if (!(lock->l_flags & LDLM_FL_CBPENDING)) {
+ if (lock->l_readers != 0 || lock->l_writers != 0 ||
+ !(lock->l_flags & LDLM_FL_CBPENDING)) {
ldlm_lock_addref_internal_nolock(lock, mode);
result = 0;
}
LDLM_LOCK_GET(lock); /* dropped by bl thread */
ldlm_lock_remove_from_lru(lock);
unlock_res_and_lock(lock);
+
+ if (lock->l_flags & LDLM_FL_FAIL_LOC)
+ OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE);
+
if ((lock->l_flags & LDLM_FL_ATOMIC_CB) ||
ldlm_bl_to_thread_lock(ns, NULL, lock) != 0)
ldlm_handle_bl_callback(ns, NULL, lock);
* reference, put it on the LRU. */
ldlm_lock_add_to_lru(lock);
unlock_res_and_lock(lock);
+
+ if (lock->l_flags & LDLM_FL_FAIL_LOC)
+ OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE);
+
/* Call ldlm_cancel_lru() only if EARLY_CANCEL and LRU RESIZE
* are not supported by the server, otherwise, it is done on
* enqueue. */
static struct ldlm_lock *search_queue(struct list_head *queue,
ldlm_mode_t *mode,
ldlm_policy_data_t *policy,
- struct ldlm_lock *old_lock, int flags)
+ struct ldlm_lock *old_lock,
+ int flags, int unref)
{
struct ldlm_lock *lock;
struct list_head *tmp;
if (lock->l_flags & LDLM_FL_CBPENDING &&
!(flags & LDLM_FL_CBPENDING))
continue;
- if (lock->l_flags & LDLM_FL_CBPENDING &&
+ if (!unref && lock->l_flags & LDLM_FL_CBPENDING &&
lock->l_readers == 0 && lock->l_writers == 0)
continue;
policy->l_inodebits.bits))
continue;
- if (lock->l_destroyed || (lock->l_flags & LDLM_FL_FAILED))
+ if (!unref &&
+ (lock->l_destroyed || (lock->l_flags & LDLM_FL_FAILED)))
continue;
if ((flags & LDLM_FL_LOCAL_ONLY) &&
return NULL;
}
-void ldlm_lock_allow_match(struct ldlm_lock *lock)
+void ldlm_lock_allow_match_locked(struct ldlm_lock *lock)
{
- lock_res_and_lock(lock);
lock->l_flags |= LDLM_FL_LVB_READY;
cfs_waitq_signal(&lock->l_waitq);
- unlock_res_and_lock(lock);
}
-/**
- * Checks if requested extent lock is compatible with another owned lock.
- *
- * Checks if \a lock is compatible with a read or write lock
- * (specified by \a rw) for an extent [\a start , \a end].
- *
- * \param lock the already owned lock
- * \param rw OBD_BRW_READ if requested for reading,
- * OBD_BRW_WRITE if requested for writing
- * \param start start of the requested extent
- * \param end end of the requested extent
- * \param cookie transparent parameter for passing locking context
- *
- * \post result == 1, *cookie == context, appropriate lock is referenced
- *
- * \retval 1 owned lock is reused for the request
- * \retval 0 no lock reused for the request
- *
- * \see ldlm_lock_fast_release
- */
-int ldlm_lock_fast_match(struct ldlm_lock *lock, int rw,
- obd_off start, obd_off end,
- void **cookie)
+void ldlm_lock_allow_match(struct ldlm_lock *lock)
{
- LASSERT(rw == OBD_BRW_READ || rw == OBD_BRW_WRITE);
-
- if (!lock)
- return 0;
-
lock_res_and_lock(lock);
- /* check if granted mode is compatible */
- if (rw == OBD_BRW_WRITE &&
- !(lock->l_granted_mode & (LCK_PW|LCK_GROUP)))
- goto no_match;
-
- /* does the lock cover the region we would like to access? */
- if ((lock->l_policy_data.l_extent.start > start) ||
- (lock->l_policy_data.l_extent.end < end))
- goto no_match;
-
- /* if we received a blocking callback and the lock is no longer
- * referenced, don't use it */
- if ((lock->l_flags & LDLM_FL_CBPENDING) &&
- !lock->l_writers && !lock->l_readers)
- goto no_match;
-
- ldlm_lock_addref_internal_nolock(lock, rw == OBD_BRW_WRITE ?
- LCK_PW : LCK_PR);
+ ldlm_lock_allow_match_locked(lock);
unlock_res_and_lock(lock);
- *cookie = (void *)lock;
- return 1; /* avoid using rc for stack relief */
-
-no_match:
- unlock_res_and_lock(lock);
- return 0;
-}
-
-/**
- * Releases a reference to a lock taken in a "fast" way.
- *
- * Releases a read or write (specified by \a rw) lock
- * referenced by \a cookie.
- *
- * \param rw OBD_BRW_READ if requested for reading,
- * OBD_BRW_WRITE if requested for writing
- * \param cookie transparent parameter for passing locking context
- *
- * \post appropriate lock is dereferenced
- *
- * \see ldlm_lock_fast_lock
- */
-void ldlm_lock_fast_release(void *cookie, int rw)
-{
- struct ldlm_lock *lock = (struct ldlm_lock *)cookie;
-
- LASSERT(lock != NULL);
- LASSERT(rw == OBD_BRW_READ || rw == OBD_BRW_WRITE);
- LASSERT(rw == OBD_BRW_READ ||
- (lock->l_granted_mode & (LCK_PW | LCK_GROUP)));
- ldlm_lock_decref_internal(lock, rw == OBD_BRW_WRITE ? LCK_PW : LCK_PR);
}
/* Can be called in two ways:
ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, int flags,
const struct ldlm_res_id *res_id, ldlm_type_t type,
ldlm_policy_data_t *policy, ldlm_mode_t mode,
- struct lustre_handle *lockh)
+ struct lustre_handle *lockh, int unref)
{
struct ldlm_resource *res;
struct ldlm_lock *lock, *old_lock = NULL;
LDLM_RESOURCE_ADDREF(res);
lock_res(res);
- lock = search_queue(&res->lr_granted, &mode, policy, old_lock, flags);
+ lock = search_queue(&res->lr_granted, &mode, policy, old_lock,
+ flags, unref);
if (lock != NULL)
GOTO(out, rc = 1);
if (flags & LDLM_FL_BLOCK_GRANTED)
GOTO(out, rc = 0);
- lock = search_queue(&res->lr_converting, &mode, policy, old_lock,flags);
+ lock = search_queue(&res->lr_converting, &mode, policy, old_lock,
+ flags, unref);
if (lock != NULL)
GOTO(out, rc = 1);
- lock = search_queue(&res->lr_waiting, &mode, policy, old_lock, flags);
+ lock = search_queue(&res->lr_waiting, &mode, policy, old_lock,
+ flags, unref);
if (lock != NULL)
GOTO(out, rc = 1);
struct ldlm_interval *node = NULL;
ENTRY;
- do_gettimeofday(&lock->l_enqueued_time);
+ lock->l_last_activity = cfs_time_current_sec();
/* policies are not executed on the client or during replay */
if ((*flags & (LDLM_FL_HAS_INTENT|LDLM_FL_REPLAY)) == LDLM_FL_HAS_INTENT
&& !local && ns->ns_policy) {
*/
void ldlm_lock_downgrade(struct ldlm_lock *lock, int new_mode)
{
+ struct ldlm_namespace *ns;
ENTRY;
LASSERT(lock->l_granted_mode & (LCK_PW | LCK_EX));
lock_res_and_lock(lock);
ldlm_resource_unlink_lock(lock);
+ /*
+ * Remove the lock from pool as it will be added again in
+ * ldlm_grant_lock() called below.
+ */
+ ns = lock->l_resource->lr_namespace;
+ ldlm_pool_del(&ns->ns_pool, lock);
+
lock->l_req_mode = new_mode;
ldlm_grant_lock(lock, NULL);
unlock_res_and_lock(lock);
node = NULL;
}
}
+
+ /*
+ * Remove old lock from the pool before adding the lock with new
+ * mode below in ->policy()
+ */
+ ldlm_pool_del(&ns->ns_pool, lock);
/* If this is a local resource, put it on the appropriate list. */
if (ns_is_client(res->lr_namespace)) {
lock->l_resource->lr_name.name[1],
lock->l_resource->lr_name.name[2]);
CDEBUG(level, " Req mode: %s, grant mode: %s, rc: %u, read: %d, "
- "write: %d flags: %#x\n", ldlm_lockname[lock->l_req_mode],
+ "write: %d flags: "LPX64"\n", ldlm_lockname[lock->l_req_mode],
ldlm_lockname[lock->l_granted_mode],
atomic_read(&lock->l_refc), lock->l_readers, lock->l_writers,
lock->l_flags);
libcfs_debug_vmsg2(cdls, data->msg_subsys, level,data->msg_file,
data->msg_fn, data->msg_line, fmt, args,
" ns: \?\? lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
- "res: \?\? rrc=\?\? type: \?\?\? flags: %x remote: "
- LPX64" expref: %d pid: %u\n", lock,
+ "res: \?\? rrc=\?\? type: \?\?\? flags: "LPX64" remote: "
+ LPX64" expref: %d pid: %u timeout: %lu\n", lock,
lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
lock->l_readers, lock->l_writers,
ldlm_lockname[lock->l_granted_mode],
lock->l_flags, lock->l_remote_handle.cookie,
lock->l_export ?
atomic_read(&lock->l_export->exp_refcount) : -99,
- lock->l_pid);
+ lock->l_pid, lock->l_callback_timeout);
va_end(args);
return;
}
data->msg_fn, data->msg_line, fmt, args,
" ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
"res: "LPU64"/"LPU64" rrc: %d type: %s ["LPU64"->"LPU64
- "] (req "LPU64"->"LPU64") flags: %x remote: "LPX64
- " expref: %d pid: %u\n",
+ "] (req "LPU64"->"LPU64") flags: "LPX64" remote: "LPX64
+ " expref: %d pid: %u timeout %lu\n",
lock->l_resource->lr_namespace->ns_name, lock,
lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
lock->l_readers, lock->l_writers,
lock->l_flags, lock->l_remote_handle.cookie,
lock->l_export ?
atomic_read(&lock->l_export->exp_refcount) : -99,
- lock->l_pid);
+ lock->l_pid, lock->l_callback_timeout);
break;
case LDLM_FLOCK:
data->msg_fn, data->msg_line, fmt, args,
" ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
"res: "LPU64"/"LPU64" rrc: %d type: %s pid: %d "
- "["LPU64"->"LPU64"] flags: %x remote: "LPX64
- " expref: %d pid: %u\n",
+ "["LPU64"->"LPU64"] flags: "LPX64" remote: "LPX64
+ " expref: %d pid: %u timeout: %lu\n",
lock->l_resource->lr_namespace->ns_name, lock,
lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
lock->l_readers, lock->l_writers,
lock->l_flags, lock->l_remote_handle.cookie,
lock->l_export ?
atomic_read(&lock->l_export->exp_refcount) : -99,
- lock->l_pid);
+ lock->l_pid, lock->l_callback_timeout);
break;
case LDLM_IBITS:
data->msg_fn, data->msg_line, fmt, args,
" ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
"res: "LPU64"/"LPU64" bits "LPX64" rrc: %d type: %s "
- "flags: %x remote: "LPX64" expref: %d "
- "pid %u\n",
+ "flags: "LPX64" remote: "LPX64" expref: %d "
+ "pid: %u timeout: %lu\n",
lock->l_resource->lr_namespace->ns_name,
lock, lock->l_handle.h_cookie,
atomic_read (&lock->l_refc),
lock->l_flags, lock->l_remote_handle.cookie,
lock->l_export ?
atomic_read(&lock->l_export->exp_refcount) : -99,
- lock->l_pid);
+ lock->l_pid, lock->l_callback_timeout);
break;
default:
libcfs_debug_vmsg2(cdls, data->msg_subsys, level,data->msg_file,
data->msg_fn, data->msg_line, fmt, args,
" ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
- "res: "LPU64"/"LPU64" rrc: %d type: %s flags: %x "
- "remote: "LPX64" expref: %d pid: %u\n",
+ "res: "LPU64"/"LPU64" rrc: %d type: %s flags: "LPX64" "
+ "remote: "LPX64" expref: %d pid: %u timeout %lu\n",
lock->l_resource->lr_namespace->ns_name,
lock, lock->l_handle.h_cookie,
atomic_read (&lock->l_refc),
lock->l_flags, lock->l_remote_handle.cookie,
lock->l_export ?
atomic_read(&lock->l_export->exp_refcount) : -99,
- lock->l_pid);
+ lock->l_pid, lock->l_callback_timeout);
break;
}
va_end(args);