* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2010, 2016, Intel Corporation.
+ * Copyright (c) 2010, 2017, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
module_param(ldlm_num_threads, int, 0444);
MODULE_PARM_DESC(ldlm_num_threads, "number of DLM service threads to start");
+static unsigned int ldlm_cpu_bind = 1;
+module_param(ldlm_cpu_bind, uint, 0444);
+MODULE_PARM_DESC(ldlm_cpu_bind,
+ "bind DLM service threads to particular CPU partitions");
+
static char *ldlm_cpts;
module_param(ldlm_cpts, charp, 0444);
MODULE_PARM_DESC(ldlm_cpts, "CPU partitions ldlm threads should run on");
* All access to it should be under waiting_locks_spinlock.
*/
static LIST_HEAD(waiting_locks_list);
-static void waiting_locks_callback(unsigned long unused);
-static DEFINE_TIMER(waiting_locks_timer, waiting_locks_callback, 0, 0);
+static void waiting_locks_callback(TIMER_DATA_TYPE unused);
+static CFS_DEFINE_TIMER(waiting_locks_timer, waiting_locks_callback, 0, 0);
enum elt_state {
ELT_STOPPED,
static int expired_lock_dump;
static LIST_HEAD(expired_lock_list);
+static int ldlm_lock_busy(struct ldlm_lock *lock);
+static int ldlm_add_waiting_lock(struct ldlm_lock *lock, time64_t timeout);
+static int __ldlm_add_waiting_lock(struct ldlm_lock *lock, time64_t seconds);
+
static inline int have_expired_locks(void)
{
int need_to_run;
export = class_export_lock_get(lock->l_export, lock);
spin_unlock_bh(&waiting_locks_spinlock);
- spin_lock_bh(&export->exp_bl_list_lock);
- list_del_init(&lock->l_exp_list);
- spin_unlock_bh(&export->exp_bl_list_lock);
-
- do_dump++;
- class_fail_export(export);
+ /* Check if we need to prolong timeout */
+ if (!OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT) &&
+ lock->l_callback_timeout != 0 && /* not AST error */
+ ldlm_lock_busy(lock)) {
+ LDLM_DEBUG(lock, "prolong the busy lock");
+ lock_res_and_lock(lock);
+ ldlm_add_waiting_lock(lock,
+ ldlm_bl_timeout(lock) >> 1);
+ unlock_res_and_lock(lock);
+ } else {
+ spin_lock_bh(&export->exp_bl_list_lock);
+ list_del_init(&lock->l_exp_list);
+ spin_unlock_bh(&export->exp_bl_list_lock);
+
+ LDLM_ERROR(lock,
+ "lock callback timer expired after %llds: evicting client at %s ",
+ ktime_get_real_seconds() -
+ lock->l_blast_sent,
+ obd_export_nid2str(export));
+ ldlm_lock_to_ns(lock)->ns_timeouts++;
+ do_dump++;
+ class_fail_export(export);
+ }
class_export_lock_put(export, lock);
-
/* release extra ref grabbed by ldlm_add_waiting_lock()
* or ldlm_failed_ast() */
LDLM_LOCK_RELEASE(lock);
RETURN(0);
}
-static int ldlm_add_waiting_lock(struct ldlm_lock *lock);
-static int __ldlm_add_waiting_lock(struct ldlm_lock *lock, time64_t seconds);
-
/**
* Check if there is a request in the export request list
* which prevents the lock canceling.
if (lock->l_export == NULL)
return 0;
- spin_lock_bh(&lock->l_export->exp_rpc_lock);
+ spin_lock(&lock->l_export->exp_rpc_lock);
list_for_each_entry(req, &lock->l_export->exp_hp_rpcs,
rq_exp_list) {
if (req->rq_ops->hpreq_lock_match) {
break;
}
}
- spin_unlock_bh(&lock->l_export->exp_rpc_lock);
+ spin_unlock(&lock->l_export->exp_rpc_lock);
RETURN(match);
}
/* This is called from within a timer interrupt and cannot schedule */
-static void waiting_locks_callback(unsigned long unused)
+static void waiting_locks_callback(TIMER_DATA_TYPE unused)
{
struct ldlm_lock *lock;
int need_dump = 0;
lock->l_req_mode == LCK_GROUP)
break;
- /* Check if we need to prolong timeout */
- if (!OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT) &&
- ldlm_lock_busy(lock)) {
- int cont = 1;
-
- if (lock->l_pending_chain.next == &waiting_locks_list)
- cont = 0;
-
- LDLM_LOCK_GET(lock);
-
- spin_unlock_bh(&waiting_locks_spinlock);
- LDLM_DEBUG(lock, "prolong the busy lock");
- ldlm_refresh_waiting_lock(lock,
- ldlm_bl_timeout(lock) >> 1);
- spin_lock_bh(&waiting_locks_spinlock);
-
- if (!cont) {
- LDLM_LOCK_RELEASE(lock);
- break;
- }
-
- LDLM_LOCK_RELEASE(lock);
- continue;
- }
- ldlm_lock_to_ns(lock)->ns_timeouts++;
- LDLM_ERROR(lock, "lock callback timer expired after %llds: "
- "evicting client at %s ",
- ktime_get_real_seconds() - lock->l_last_activity,
- libcfs_nid2str(
- lock->l_export->exp_connection->c_peer.nid));
-
/* no needs to take an extra ref on the lock since it was in
* the waiting_locks_list and ldlm_add_waiting_lock()
* already grabbed a ref */
obd_stale_export_adjust(lock->l_export);
}
-static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
+static int ldlm_add_waiting_lock(struct ldlm_lock *lock, time64_t timeout)
{
- time64_t timeout = ldlm_bl_timeout(lock);
int ret;
/* NB: must be called with hold of lock_res_and_lock() */
}
ldlm_set_waited(lock);
- lock->l_last_activity = ktime_get_real_seconds();
+ lock->l_blast_sent = ktime_get_real_seconds();
ret = __ldlm_add_waiting_lock(lock, timeout);
if (ret) {
/* grab ref on the lock if it has been added to the
/* the lock was not in any list, grab an extra ref before adding
* the lock to the expired list */
LDLM_LOCK_GET(lock);
+ lock->l_callback_timeout = 0; /* differentiate it from expired locks */
list_add(&lock->l_pending_chain, &expired_lock_list);
wake_up(&expired_lock_wait_queue);
spin_unlock_bh(&waiting_locks_spinlock);
/**
* Perform lock cleanup if AST reply came with error.
*/
-static int ldlm_handle_ast_error(struct ldlm_lock *lock,
+static int ldlm_handle_ast_error(const struct lu_env *env,
+ struct ldlm_lock *lock,
struct ptlrpc_request *req, int rc,
const char *ast_type)
{
/* update lvbo to return proper attributes.
* see bug 23174 */
ldlm_resource_getref(res);
- ldlm_lvbo_update(res, lock, NULL, 1);
+ ldlm_lvbo_update(env, res, lock, NULL, 1);
ldlm_resource_putref(res);
}
ldlm_lock_cancel(lock);
}
static int ldlm_cb_interpret(const struct lu_env *env,
- struct ptlrpc_request *req, void *data, int rc)
+ struct ptlrpc_request *req, void *args, int rc)
{
- struct ldlm_cb_async_args *ca = data;
- struct ldlm_lock *lock = ca->ca_lock;
- struct ldlm_cb_set_arg *arg = ca->ca_set_arg;
- ENTRY;
+ struct ldlm_cb_async_args *ca = args;
+ struct ldlm_lock *lock = ca->ca_lock;
+ struct ldlm_cb_set_arg *arg = ca->ca_set_arg;
- LASSERT(lock != NULL);
+ ENTRY;
+
+ LASSERT(lock != NULL);
switch (arg->type) {
case LDLM_GL_CALLBACK:
* -ELDLM_NO_LOCK_DATA when inode is cleared. LU-274
*/
if (unlikely(arg->gl_interpret_reply)) {
- rc = arg->gl_interpret_reply(env, req, data, rc);
+ rc = arg->gl_interpret_reply(env, req, args, rc);
} else if (rc == -ELDLM_NO_LOCK_DATA) {
LDLM_DEBUG(lock, "lost race - client has a lock but no "
"inode");
- ldlm_lvbo_update(lock->l_resource, lock, NULL, 1);
+ ldlm_lvbo_update(env, lock->l_resource, lock, NULL, 1);
} else if (rc != 0) {
- rc = ldlm_handle_ast_error(lock, req, rc, "glimpse");
+ rc = ldlm_handle_ast_error(env, lock, req,
+ rc, "glimpse");
} else {
- rc = ldlm_lvbo_update(lock->l_resource, lock, req, 1);
+ rc = ldlm_lvbo_update(env, lock->l_resource,
+ lock, req, 1);
}
break;
case LDLM_BL_CALLBACK:
if (rc != 0)
- rc = ldlm_handle_ast_error(lock, req, rc, "blocking");
+ rc = ldlm_handle_ast_error(env, lock, req,
+ rc, "blocking");
break;
case LDLM_CP_CALLBACK:
if (rc != 0)
- rc = ldlm_handle_ast_error(lock, req, rc, "completion");
+ rc = ldlm_handle_ast_error(env, lock, req,
+ rc, "completion");
break;
default:
LDLM_ERROR(lock, "invalid opcode for lock callback %d",
RETURN_EXIT;
}
- spin_lock_bh(&lock->l_export->exp_rpc_lock);
+ spin_lock(&lock->l_export->exp_rpc_lock);
list_for_each_entry(req, &lock->l_export->exp_hp_rpcs,
rq_exp_list) {
/* Do not process requests that were not yet added to there
req->rq_ops->hpreq_lock_match(req, lock))
ptlrpc_nrs_req_hp_move(req);
}
- spin_unlock_bh(&lock->l_export->exp_rpc_lock);
+ spin_unlock(&lock->l_export->exp_rpc_lock);
EXIT;
}
req->rq_no_resend = 1;
} else {
LASSERT(lock->l_granted_mode == lock->l_req_mode);
- ldlm_add_waiting_lock(lock);
+ ldlm_add_waiting_lock(lock, ldlm_bl_timeout(lock));
unlock_res_and_lock(lock);
/* Do not resend after lock callback timeout */
if (AT_OFF)
req->rq_timeout = ldlm_get_rq_timeout();
- lock->l_last_activity = ktime_get_real_seconds();
-
if (lock->l_export && lock->l_export->exp_nid_stats &&
lock->l_export->exp_nid_stats->nid_ldlm_stats)
lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
ldlm_lock2desc(lock, &body->lock_desc);
if (lvb_len > 0) {
void *lvb = req_capsule_client_get(&req->rq_pill, &RMF_DLM_LVB);
+ const struct lu_env *env = NULL;
+
+ if (req->rq_svc_thread)
+ env = req->rq_svc_thread->t_env;
- lvb_len = ldlm_lvbo_fill(lock, lvb, lvb_len);
+ lvb_len = ldlm_lvbo_fill(env, lock, lvb, &lvb_len);
if (lvb_len < 0) {
/* We still need to send the RPC to wake up the blocked
* enqueue thread on the client.
}
}
- lock->l_last_activity = ktime_get_real_seconds();
-
LDLM_DEBUG(lock, "server preparing completion AST");
ptlrpc_request_set_replen(req);
lock_res_and_lock(lock);
} else {
/* start the lock-timeout clock */
- ldlm_add_waiting_lock(lock);
+ ldlm_add_waiting_lock(lock, ldlm_bl_timeout(lock));
/* Do not resend after lock callback timeout */
req->rq_delay_limit = ldlm_bl_timeout(lock);
req->rq_resend_cb = ldlm_update_resend;
ca->ca_set_arg = arg;
ca->ca_lock = lock;
- /* server namespace, doesn't need lock */
- req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER,
- ldlm_lvbo_size(lock));
- ptlrpc_request_set_replen(req);
-
- req->rq_send_state = LUSTRE_IMP_FULL;
- /* ptlrpc_request_alloc_pack already set timeout */
- if (AT_OFF)
- req->rq_timeout = ldlm_get_rq_timeout();
+ /* server namespace, doesn't need lock */
+ req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER,
+ ldlm_lvbo_size(lock));
+ ptlrpc_request_set_replen(req);
- lock->l_last_activity = ktime_get_real_seconds();
+ req->rq_send_state = LUSTRE_IMP_FULL;
+ /* ptlrpc_request_alloc_pack already set timeout */
+ if (AT_OFF)
+ req->rq_timeout = ldlm_get_rq_timeout();
req->rq_interpret_reply = ldlm_cb_interpret;
- if (lock->l_export && lock->l_export->exp_nid_stats &&
- lock->l_export->exp_nid_stats->nid_ldlm_stats)
- lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
- LDLM_GL_CALLBACK - LDLM_FIRST_OPC);
+ if (lock->l_export && lock->l_export->exp_nid_stats) {
+ struct nid_stat *nid_stats = lock->l_export->exp_nid_stats;
+
+ lprocfs_counter_incr(nid_stats->nid_ldlm_stats,
+ LDLM_GL_CALLBACK - LDLM_FIRST_OPC);
+ }
rc = ldlm_ast_fini(req, arg, lock, 0);
void *cookie = NULL;
int rc = 0;
struct ldlm_resource *res = NULL;
+ const struct lu_env *env = req->rq_svc_thread->t_env;
ENTRY;
LDLM_DEBUG_NOLOCK("server-side enqueue handler START");
res = lock->l_resource;
if (!(flags & LDLM_FL_REPLAY)) {
/* non-replayed lock, delayed lvb init may need to be done */
- rc = ldlm_lvbo_init(res);
+ rc = ldlm_lvbo_init(env, res);
if (rc < 0) {
LDLM_DEBUG(lock, "delayed lvb init failed (rc %d)", rc);
GOTO(out, rc);
req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB,
RCL_SERVER, ldlm_lvbo_size(lock));
- if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR))
- GOTO(out, rc = -ENOMEM);
+ if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR))
+ GOTO(out, rc = -ENOMEM);
- rc = req_capsule_server_pack(&req->rq_pill);
- if (rc)
- GOTO(out, rc);
- }
+ rc = req_capsule_server_pack(&req->rq_pill);
+ if (rc)
+ GOTO(out, rc);
+ }
- err = ldlm_lock_enqueue(ns, &lock, cookie, &flags);
+ err = ldlm_lock_enqueue(env, ns, &lock, cookie, &flags);
if (err) {
if ((int)err < 0)
rc = (int)err;
GOTO(out, err);
}
- dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
+ dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
- ldlm_lock2desc(lock, &dlm_rep->lock_desc);
- ldlm_lock2handle(lock, &dlm_rep->lock_handle);
+ ldlm_lock2desc(lock, &dlm_rep->lock_desc);
+ ldlm_lock2handle(lock, &dlm_rep->lock_handle);
if (lock && lock->l_resource->lr_type == LDLM_EXTENT)
OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_BL_EVICT, 6);
LDLM_ERROR(lock, "lock on destroyed export %p", req->rq_export);
rc = -ENOTCONN;
} else if (ldlm_is_ast_sent(lock)) {
+ /* fill lock desc for possible lock convert */
+ if (lock->l_blocking_lock &&
+ lock->l_resource->lr_type == LDLM_IBITS) {
+ struct ldlm_lock *bl_lock = lock->l_blocking_lock;
+ struct ldlm_lock_desc *rep_desc = &dlm_rep->lock_desc;
+
+ LDLM_DEBUG(lock,
+ "save blocking bits %llx in granted lock",
+ bl_lock->l_policy_data.l_inodebits.bits);
+ /* If lock is blocked then save blocking ibits
+ * in returned lock policy for the possible lock
+ * convert on a client.
+ */
+ rep_desc->l_policy_data.l_inodebits.cancel_bits =
+ bl_lock->l_policy_data.l_inodebits.bits;
+ }
dlm_rep->lock_flags |= ldlm_flags_to_wire(LDLM_FL_AST_SENT);
if (lock->l_granted_mode == lock->l_req_mode) {
/*
unlock_res_and_lock(lock);
ldlm_lock_cancel(lock);
lock_res_and_lock(lock);
- } else
- ldlm_add_waiting_lock(lock);
+ } else {
+ ldlm_add_waiting_lock(lock,
+ ldlm_bl_timeout(lock));
+ }
}
}
unlock_res_and_lock(lock);
LDLM_DEBUG(lock, "server-side enqueue handler, sending reply"
"(err=%d, rc=%d)", err, rc);
- if (rc == 0) {
- if (req_capsule_has_field(&req->rq_pill, &RMF_DLM_LVB,
- RCL_SERVER) &&
- ldlm_lvbo_size(lock) > 0) {
- void *buf;
- int buflen;
-
- buf = req_capsule_server_get(&req->rq_pill,
- &RMF_DLM_LVB);
- LASSERTF(buf != NULL, "req %p, lock %p\n",
- req, lock);
- buflen = req_capsule_get_size(&req->rq_pill,
- &RMF_DLM_LVB, RCL_SERVER);
- /* non-replayed lock, delayed lvb init may
- * need to be occur now */
- if ((buflen > 0) && !(flags & LDLM_FL_REPLAY)) {
- buflen = ldlm_lvbo_fill(lock, buf,
- buflen);
- if (buflen >= 0)
- req_capsule_shrink(
+ if (rc == 0 &&
+ req_capsule_has_field(&req->rq_pill, &RMF_DLM_LVB,
+ RCL_SERVER) &&
+ ldlm_lvbo_size(lock) > 0) {
+ void *buf;
+ int buflen;
+
+retry:
+ buf = req_capsule_server_get(&req->rq_pill,
+ &RMF_DLM_LVB);
+ LASSERTF(buf != NULL, "req %p, lock %p\n", req, lock);
+ buflen = req_capsule_get_size(&req->rq_pill,
+ &RMF_DLM_LVB, RCL_SERVER);
+ /* non-replayed lock, delayed lvb init may
+ * need to be occur now
+ */
+ if ((buflen > 0) && !(flags & LDLM_FL_REPLAY)) {
+ int rc2;
+
+ rc2 = ldlm_lvbo_fill(env, lock, buf, &buflen);
+ if (rc2 >= 0) {
+ req_capsule_shrink(&req->rq_pill,
+ &RMF_DLM_LVB,
+ rc2, RCL_SERVER);
+ } else if (rc2 == -ERANGE) {
+ rc2 = req_capsule_server_grow(
&req->rq_pill,
- &RMF_DLM_LVB,
- buflen, RCL_SERVER);
- else
- rc = buflen;
- } else if (flags & LDLM_FL_REPLAY) {
- /* no LVB resend upon replay */
- if (buflen > 0)
+ &RMF_DLM_LVB, buflen);
+ if (!rc2) {
+ goto retry;
+ } else {
+ /* if we can't grow the buffer,
+ * it's ok to return empty lvb
+ * to client.
+ */
req_capsule_shrink(
&req->rq_pill,
- &RMF_DLM_LVB,
- 0, RCL_SERVER);
- else
- rc = buflen;
+ &RMF_DLM_LVB, 0,
+ RCL_SERVER);
+ }
} else {
- rc = buflen;
+ rc = rc2;
}
+ } else if (flags & LDLM_FL_REPLAY) {
+ /* no LVB resend upon replay */
+ if (buflen > 0)
+ req_capsule_shrink(&req->rq_pill,
+ &RMF_DLM_LVB,
+ 0, RCL_SERVER);
+ else
+ rc = buflen;
+ } else {
+ rc = buflen;
}
}
}
}
- if (!err && dlm_req->lock_desc.l_resource.lr_type != LDLM_FLOCK)
- ldlm_reprocess_all(lock->l_resource);
+ if (!err && !ldlm_is_cbpending(lock) &&
+ dlm_req->lock_desc.l_resource.lr_type != LDLM_FLOCK)
+ ldlm_reprocess_all(lock->l_resource);
- LDLM_LOCK_RELEASE(lock);
- }
+ LDLM_LOCK_RELEASE(lock);
+ }
- LDLM_DEBUG_NOLOCK("server-side enqueue handler END (lock %p, rc %d)",
- lock, rc);
+ LDLM_DEBUG_NOLOCK("server-side enqueue handler END (lock %p, rc %d)",
+ lock, rc);
return rc;
}
-/**
- * Old-style LDLM main entry point for server code enqueue.
+/* Clear the blocking lock, the race is possible between ldlm_handle_convert0()
+ * and ldlm_work_bl_ast_lock(), so this is done under lock with check for NULL.
*/
-int ldlm_handle_enqueue(struct ptlrpc_request *req,
- ldlm_completion_callback completion_callback,
- ldlm_blocking_callback blocking_callback,
- ldlm_glimpse_callback glimpse_callback)
+void ldlm_clear_blocking_lock(struct ldlm_lock *lock)
{
- struct ldlm_request *dlm_req;
- struct ldlm_callback_suite cbs = {
- .lcs_completion = completion_callback,
- .lcs_blocking = blocking_callback,
- .lcs_glimpse = glimpse_callback
- };
- int rc;
+ if (lock->l_blocking_lock) {
+ LDLM_LOCK_RELEASE(lock->l_blocking_lock);
+ lock->l_blocking_lock = NULL;
+ }
+}
- dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
- if (dlm_req != NULL) {
- rc = ldlm_handle_enqueue0(req->rq_export->exp_obd->obd_namespace,
- req, dlm_req, &cbs);
- } else {
- rc = -EFAULT;
- }
- return rc;
+/* A lock can be converted to new ibits or mode and should be considered
+ * as new lock. Clear all states related to a previous blocking AST
+ * processing so new conflicts will cause new blocking ASTs.
+ *
+ * This is used during lock convert below and lock downgrade to COS mode in
+ * ldlm_lock_mode_downgrade().
+ */
+void ldlm_clear_blocking_data(struct ldlm_lock *lock)
+{
+ ldlm_clear_ast_sent(lock);
+ lock->l_bl_ast_run = 0;
+ ldlm_clear_blocking_lock(lock);
}
/**
* Main LDLM entry point for server code to process lock conversion requests.
*/
int ldlm_handle_convert0(struct ptlrpc_request *req,
- const struct ldlm_request *dlm_req)
+ const struct ldlm_request *dlm_req)
{
- struct ldlm_reply *dlm_rep;
- struct ldlm_lock *lock;
- int rc;
- ENTRY;
+ struct obd_export *exp = req->rq_export;
+ struct ldlm_reply *dlm_rep;
+ struct ldlm_lock *lock;
+ int rc;
- if (req->rq_export && req->rq_export->exp_nid_stats &&
- req->rq_export->exp_nid_stats->nid_ldlm_stats)
- lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
- LDLM_CONVERT - LDLM_FIRST_OPC);
+ ENTRY;
- rc = req_capsule_server_pack(&req->rq_pill);
- if (rc)
- RETURN(rc);
+ if (exp && exp->exp_nid_stats && exp->exp_nid_stats->nid_ldlm_stats)
+ lprocfs_counter_incr(exp->exp_nid_stats->nid_ldlm_stats,
+ LDLM_CONVERT - LDLM_FIRST_OPC);
- dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
- dlm_rep->lock_flags = dlm_req->lock_flags;
+ rc = req_capsule_server_pack(&req->rq_pill);
+ if (rc)
+ RETURN(rc);
- lock = ldlm_handle2lock(&dlm_req->lock_handle[0]);
- if (!lock) {
- req->rq_status = LUSTRE_EINVAL;
- } else {
- void *res = NULL;
+ dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
+ dlm_rep->lock_flags = dlm_req->lock_flags;
- LDLM_DEBUG(lock, "server-side convert handler START");
+ lock = ldlm_handle2lock(&dlm_req->lock_handle[0]);
+ if (lock) {
+ __u64 bits;
+ __u64 new;
- res = ldlm_lock_convert(lock, dlm_req->lock_desc.l_req_mode,
- &dlm_rep->lock_flags);
- if (res) {
- if (ldlm_del_waiting_lock(lock))
- LDLM_DEBUG(lock, "converted waiting lock");
- req->rq_status = 0;
- } else {
- req->rq_status = LUSTRE_EDEADLK;
- }
- }
+ bits = lock->l_policy_data.l_inodebits.bits;
+ new = dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
+ LDLM_DEBUG(lock, "server-side convert handler START");
- if (lock) {
- if (!req->rq_status)
- ldlm_reprocess_all(lock->l_resource);
- LDLM_DEBUG(lock, "server-side convert handler END");
- LDLM_LOCK_PUT(lock);
- } else
- LDLM_DEBUG_NOLOCK("server-side convert handler END");
+ if (ldlm_is_cancel(lock)) {
+ LDLM_ERROR(lock, "convert on canceled lock!");
+ rc = ELDLM_NO_LOCK_DATA;
+ } else if (dlm_req->lock_desc.l_req_mode !=
+ lock->l_granted_mode) {
+ LDLM_ERROR(lock, "lock mode differs!");
+ rc = ELDLM_NO_LOCK_DATA;
+ } else if (bits == new) {
+ /* This can be valid situation if CONVERT RPCs are
+ * re-ordered. Just finish silently */
+ LDLM_DEBUG(lock, "lock is converted already!");
+ rc = ELDLM_OK;
+ } else {
+ lock_res_and_lock(lock);
+ if (ldlm_is_waited(lock))
+ ldlm_del_waiting_lock(lock);
- RETURN(0);
-}
+ ldlm_clear_cbpending(lock);
+ lock->l_policy_data.l_inodebits.cancel_bits = 0;
+ ldlm_inodebits_drop(lock, bits & ~new);
-/**
- * Old-style main LDLM entry point for server code to process lock conversion
- * requests.
- */
-int ldlm_handle_convert(struct ptlrpc_request *req)
-{
- int rc;
- struct ldlm_request *dlm_req;
+ ldlm_clear_blocking_data(lock);
+ unlock_res_and_lock(lock);
- dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
- if (dlm_req != NULL) {
- rc = ldlm_handle_convert0(req, dlm_req);
- } else {
- CERROR ("Can't unpack dlm_req\n");
- rc = -EFAULT;
- }
- return rc;
+ ldlm_reprocess_all(lock->l_resource);
+ rc = ELDLM_OK;
+ }
+
+ if (rc == ELDLM_OK) {
+ dlm_rep->lock_handle = lock->l_remote_handle;
+ ldlm_ibits_policy_local_to_wire(&lock->l_policy_data,
+ &dlm_rep->lock_desc.l_policy_data);
+ }
+
+ LDLM_DEBUG(lock, "server-side convert handler END, rc = %d",
+ rc);
+ LDLM_LOCK_PUT(lock);
+ } else {
+ rc = ELDLM_NO_LOCK_DATA;
+ LDLM_DEBUG_NOLOCK("server-side convert handler END, rc = %d",
+ rc);
+ }
+
+ req->rq_status = rc;
+
+ RETURN(0);
}
/**
const struct ldlm_request *dlm_req,
int first, enum lustre_at_flags flags)
{
+ const struct lu_env *env = req->rq_svc_thread->t_env;
struct ldlm_resource *res, *pres = NULL;
struct ldlm_lock *lock;
int i, count, done = 0;
LDLM_RESOURCE_DELREF(pres);
ldlm_resource_putref(pres);
}
- if (res != NULL) {
- ldlm_resource_getref(res);
- LDLM_RESOURCE_ADDREF(res);
+ if (res != NULL) {
+ ldlm_resource_getref(res);
+ LDLM_RESOURCE_ADDREF(res);
if (!ldlm_is_discard_data(lock))
- ldlm_lvbo_update(res, lock, NULL, 1);
- }
- pres = res;
- }
+ ldlm_lvbo_update(env, res, lock,
+ NULL, 1);
+ }
+ pres = res;
+ }
- if ((flags & LATF_STATS) && ldlm_is_ast_sent(lock)) {
+ if ((flags & LATF_STATS) && ldlm_is_ast_sent(lock) &&
+ lock->l_blast_sent != 0) {
time64_t delay = ktime_get_real_seconds() -
- lock->l_last_activity;
+ lock->l_blast_sent;
LDLM_DEBUG(lock, "server cancels blocked lock after %llds",
(s64)delay);
at_measured(&lock->l_export->exp_bl_lock_at, delay);
LDLM_DEBUG(lock, "client blocking AST callback handler");
lock_res_and_lock(lock);
+
+ /* set bits to cancel for this lock for possible lock convert */
+ if (ns_is_client(ns) && (lock->l_resource->lr_type == LDLM_IBITS)) {
+ /* Lock description contains policy of blocking lock,
+ * and its cancel_bits is used to pass conflicting bits.
+ * NOTE: ld can be NULL or can be not NULL but zeroed if
+ * passed from ldlm_bl_thread_blwi(), check below used bits
+ * in ld to make sure it is valid description.
+ */
+ if (ld && ld->l_policy_data.l_inodebits.bits)
+ lock->l_policy_data.l_inodebits.cancel_bits =
+ ld->l_policy_data.l_inodebits.cancel_bits;
+ /* if there is no valid ld and lock is cbpending already
+ * then cancel_bits should be kept, otherwise it is zeroed.
+ */
+ else if (!ldlm_is_cbpending(lock))
+ lock->l_policy_data.l_inodebits.cancel_bits = 0;
+ }
ldlm_set_cbpending(lock);
if (ldlm_is_cancel_on_block(lock))
}
lock_res_and_lock(lock);
+
+ if (!ldlm_res_eq(&dlm_req->lock_desc.l_resource.lr_name,
+ &lock->l_resource->lr_name)) {
+ ldlm_resource_unlink_lock(lock);
+ unlock_res_and_lock(lock);
+ rc = ldlm_lock_change_resource(ns, lock,
+ &dlm_req->lock_desc.l_resource.lr_name);
+ if (rc < 0) {
+ LDLM_ERROR(lock, "Failed to allocate resource");
+ GOTO(out, rc);
+ }
+ LDLM_DEBUG(lock, "completion AST, new resource");
+ lock_res_and_lock(lock);
+ }
+
if (ldlm_is_destroyed(lock) ||
lock->l_granted_mode == lock->l_req_mode) {
/* bug 11300: the lock has already been granted */
LDLM_DEBUG(lock, "completion AST, new policy data");
}
- ldlm_resource_unlink_lock(lock);
- if (memcmp(&dlm_req->lock_desc.l_resource.lr_name,
- &lock->l_resource->lr_name,
- sizeof(lock->l_resource->lr_name)) != 0) {
- unlock_res_and_lock(lock);
- rc = ldlm_lock_change_resource(ns, lock,
- &dlm_req->lock_desc.l_resource.lr_name);
- if (rc < 0) {
- LDLM_ERROR(lock, "Failed to allocate resource");
- GOTO(out, rc);
- }
- LDLM_DEBUG(lock, "completion AST, new resource");
- CERROR("change resource!\n");
- lock_res_and_lock(lock);
- }
+ ldlm_resource_unlink_lock(lock);
if (dlm_req->lock_flags & LDLM_FL_AST_SENT) {
/* BL_AST locks are not needed in LRU.
!lock->l_readers && !lock->l_writers &&
ktime_after(ktime_get(),
ktime_add(lock->l_last_used,
- ktime_set(10, 0)))) {
+ ktime_set(ns->ns_dirty_age_limit, 0)))) {
unlock_res_and_lock(lock);
if (ldlm_bl_to_thread_lock(ns, NULL, lock))
ldlm_handle_bl_callback(ns, NULL, lock);
rc = ldlm_handle_setinfo(req);
ldlm_callback_reply(req, rc);
RETURN(0);
- case LLOG_ORIGIN_HANDLE_CREATE:
- req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
- if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
- RETURN(0);
- rc = llog_origin_handle_open(req);
- ldlm_callback_reply(req, rc);
- RETURN(0);
- case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
- req_capsule_set(&req->rq_pill,
- &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
- if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
- RETURN(0);
- rc = llog_origin_handle_next_block(req);
- ldlm_callback_reply(req, rc);
- RETURN(0);
- case LLOG_ORIGIN_HANDLE_READ_HEADER:
- req_capsule_set(&req->rq_pill,
- &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
- if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
- RETURN(0);
- rc = llog_origin_handle_read_header(req);
- ldlm_callback_reply(req, rc);
- RETURN(0);
- case LLOG_ORIGIN_HANDLE_CLOSE:
- if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
- RETURN(0);
- rc = llog_origin_handle_close(req);
- ldlm_callback_reply(req, rc);
- RETURN(0);
default:
CERROR("unknown opcode %u\n",
lustre_msg_get_opc(req->rq_reqmsg));
*/
static int ldlm_cancel_handler(struct ptlrpc_request *req)
{
- int rc;
- ENTRY;
+ int rc;
- /* Requests arrive in sender's byte order. The ptlrpc service
- * handler has already checked and, if necessary, byte-swapped the
- * incoming request message body, but I am responsible for the
- * message buffers. */
+ ENTRY;
- req_capsule_init(&req->rq_pill, req, RCL_SERVER);
+ /* Requests arrive in sender's byte order. The ptlrpc service
+ * handler has already checked and, if necessary, byte-swapped the
+ * incoming request message body, but I am responsible for the
+ * message buffers. */
- if (req->rq_export == NULL) {
- struct ldlm_request *dlm_req;
+ req_capsule_init(&req->rq_pill, req, RCL_SERVER);
- CERROR("%s from %s arrived at %lu with bad export cookie "
- "%llu\n",
- ll_opcode2str(lustre_msg_get_opc(req->rq_reqmsg)),
- libcfs_nid2str(req->rq_peer.nid),
- req->rq_arrival_time.tv_sec,
- lustre_msg_get_handle(req->rq_reqmsg)->cookie);
-
- if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_CANCEL) {
- req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
- dlm_req = req_capsule_client_get(&req->rq_pill,
- &RMF_DLM_REQ);
- if (dlm_req != NULL)
- ldlm_lock_dump_handle(D_ERROR,
- &dlm_req->lock_handle[0]);
- }
- ldlm_callback_reply(req, -ENOTCONN);
- RETURN(0);
- }
+ if (req->rq_export == NULL) {
+ struct ldlm_request *dlm_req;
- switch (lustre_msg_get_opc(req->rq_reqmsg)) {
+ CERROR("%s from %s arrived at %lu with bad export cookie "
+ "%llu\n",
+ ll_opcode2str(lustre_msg_get_opc(req->rq_reqmsg)),
+ libcfs_nid2str(req->rq_peer.nid),
+ req->rq_arrival_time.tv_sec,
+ lustre_msg_get_handle(req->rq_reqmsg)->cookie);
+
+ if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_CANCEL) {
+ req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
+ dlm_req = req_capsule_client_get(&req->rq_pill,
+ &RMF_DLM_REQ);
+ if (dlm_req != NULL)
+ ldlm_lock_dump_handle(D_ERROR,
+ &dlm_req->lock_handle[0]);
+ }
+ ldlm_callback_reply(req, -ENOTCONN);
+ RETURN(0);
+ }
- /* XXX FIXME move this back to mds/handler.c, bug 249 */
- case LDLM_CANCEL:
- req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
- CDEBUG(D_INODE, "cancel\n");
+ switch (lustre_msg_get_opc(req->rq_reqmsg)) {
+ /* XXX FIXME move this back to mds/handler.c, bug 249 */
+ case LDLM_CANCEL:
+ req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
+ CDEBUG(D_INODE, "cancel\n");
if (CFS_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_NET) ||
CFS_FAIL_CHECK(OBD_FAIL_PTLRPC_CANCEL_RESEND) ||
CFS_FAIL_CHECK(OBD_FAIL_LDLM_BL_EVICT))
RETURN(0);
- rc = ldlm_handle_cancel(req);
- if (rc)
- break;
- RETURN(0);
- default:
- CERROR("invalid opcode %d\n",
- lustre_msg_get_opc(req->rq_reqmsg));
- req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
- ldlm_callback_reply(req, -EINVAL);
- }
+ rc = ldlm_handle_cancel(req);
+ break;
+ case LDLM_CONVERT:
+ {
+ struct ldlm_request *dlm_req;
- RETURN(0);
+ req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
+ CDEBUG(D_INODE, "convert\n");
+
+ dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
+ if (dlm_req == NULL) {
+ CDEBUG(D_INFO, "bad request buffer for cancel\n");
+ rc = ldlm_callback_reply(req, -EPROTO);
+ } else {
+ req->rq_status = ldlm_handle_convert0(req, dlm_req);
+ rc = ptlrpc_reply(req);
+ }
+ break;
+ }
+ default:
+ CERROR("invalid opcode %d\n",
+ lustre_msg_get_opc(req->rq_reqmsg));
+ req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
+ rc = ldlm_callback_reply(req, -EINVAL);
+ }
+
+ RETURN(rc);
}
static int ldlm_cancel_hpreq_lock_match(struct ptlrpc_request *req,
- struct ldlm_lock *lock)
+ struct ldlm_lock *lock)
{
- struct ldlm_request *dlm_req;
- struct lustre_handle lockh;
- int rc = 0;
- int i;
- ENTRY;
-
- dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
- if (dlm_req == NULL)
- RETURN(0);
+ struct ldlm_request *dlm_req;
+ struct lustre_handle lockh;
+ int rc = 0;
+ int i;
- ldlm_lock2handle(lock, &lockh);
- for (i = 0; i < dlm_req->lock_count; i++) {
- if (lustre_handle_equal(&dlm_req->lock_handle[i],
- &lockh)) {
- DEBUG_REQ(D_RPCTRACE, req,
- "Prio raised by lock %#llx.", lockh.cookie);
+ ENTRY;
- rc = 1;
- break;
- }
- }
+ dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
+ if (dlm_req == NULL)
+ RETURN(0);
- RETURN(rc);
+ ldlm_lock2handle(lock, &lockh);
+ for (i = 0; i < dlm_req->lock_count; i++) {
+ if (lustre_handle_equal(&dlm_req->lock_handle[i],
+ &lockh)) {
+ DEBUG_REQ(D_RPCTRACE, req,
+ "Prio raised by lock %#llx.", lockh.cookie);
+ rc = 1;
+ break;
+ }
+ }
+ RETURN(rc);
}
static int ldlm_cancel_hpreq_check(struct ptlrpc_request *req)
{
- struct ldlm_request *dlm_req;
- int rc = 0;
- int i;
- ENTRY;
+ struct ldlm_request *dlm_req;
+ int rc = 0;
+ int i;
- /* no prolong in recovery */
- if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
- RETURN(0);
+ ENTRY;
- dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
- if (dlm_req == NULL)
- RETURN(-EFAULT);
+ /* no prolong in recovery */
+ if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
+ RETURN(0);
- for (i = 0; i < dlm_req->lock_count; i++) {
- struct ldlm_lock *lock;
+ dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
+ if (dlm_req == NULL)
+ RETURN(-EFAULT);
- lock = ldlm_handle2lock(&dlm_req->lock_handle[i]);
- if (lock == NULL)
- continue;
+ for (i = 0; i < dlm_req->lock_count; i++) {
+ struct ldlm_lock *lock;
+
+ lock = ldlm_handle2lock(&dlm_req->lock_handle[i]);
+ if (lock == NULL)
+ continue;
rc = ldlm_is_ast_sent(lock) ? 1 : 0;
- if (rc)
- LDLM_DEBUG(lock, "hpreq cancel lock");
- LDLM_LOCK_PUT(lock);
+ if (rc)
+ LDLM_DEBUG(lock, "hpreq cancel/convert lock");
+ LDLM_LOCK_PUT(lock);
- if (rc)
- break;
- }
+ if (rc)
+ break;
+ }
- RETURN(rc);
+ RETURN(rc);
}
static struct ptlrpc_hpreq_ops ldlm_cancel_hpreq_ops = {
- .hpreq_lock_match = ldlm_cancel_hpreq_lock_match,
+ .hpreq_lock_match = ldlm_cancel_hpreq_lock_match,
.hpreq_check = ldlm_cancel_hpreq_check,
.hpreq_fini = NULL,
};
static int ldlm_hpreq_handler(struct ptlrpc_request *req)
{
- ENTRY;
+ ENTRY;
- req_capsule_init(&req->rq_pill, req, RCL_SERVER);
+ req_capsule_init(&req->rq_pill, req, RCL_SERVER);
- if (req->rq_export == NULL)
- RETURN(0);
+ if (req->rq_export == NULL)
+ RETURN(0);
- if (LDLM_CANCEL == lustre_msg_get_opc(req->rq_reqmsg)) {
- req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
- req->rq_ops = &ldlm_cancel_hpreq_ops;
- }
- RETURN(0);
+ if (LDLM_CANCEL == lustre_msg_get_opc(req->rq_reqmsg)) {
+ req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
+ req->rq_ops = &ldlm_cancel_hpreq_ops;
+ } else if (LDLM_CONVERT == lustre_msg_get_opc(req->rq_reqmsg)) {
+ req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
+ req->rq_ops = &ldlm_cancel_hpreq_ops;
+ }
+ RETURN(0);
}
static int ldlm_revoke_lock_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
if (!ldlm_svc_kset)
GOTO(out, -ENOMEM);
-#ifdef CONFIG_PROC_FS
- rc = ldlm_proc_setup();
+ rc = ldlm_debugfs_setup();
if (rc != 0)
GOTO(out, rc);
-#endif /* CONFIG_PROC_FS */
memset(&conf, 0, sizeof(conf));
conf = (typeof(conf)) {
.tc_nthrs_base = LDLM_NTHRS_BASE,
.tc_nthrs_max = LDLM_NTHRS_MAX,
.tc_nthrs_user = ldlm_num_threads,
- .tc_cpu_affinity = 1,
+ .tc_cpu_bind = ldlm_cpu_bind,
.tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD,
},
.psc_cpt = {
.cc_pattern = ldlm_cpts,
+ .cc_affinity = true,
},
.psc_ops = {
.so_req_handler = ldlm_callback_handler,
};
ldlm_state->ldlm_cb_service = \
ptlrpc_register_service(&conf, ldlm_svc_kset,
- ldlm_svc_proc_dir);
+ ldlm_svc_debugfs_dir);
if (IS_ERR(ldlm_state->ldlm_cb_service)) {
CERROR("failed to start service\n");
rc = PTR_ERR(ldlm_state->ldlm_cb_service);
.tc_nthrs_base = LDLM_NTHRS_BASE,
.tc_nthrs_max = LDLM_NTHRS_MAX,
.tc_nthrs_user = ldlm_num_threads,
- .tc_cpu_affinity = 1,
+ .tc_cpu_bind = ldlm_cpu_bind,
.tc_ctx_tags = LCT_MD_THREAD | \
LCT_DT_THREAD | \
LCT_CL_THREAD,
},
.psc_cpt = {
.cc_pattern = ldlm_cpts,
+ .cc_affinity = true,
},
.psc_ops = {
.so_req_handler = ldlm_cancel_handler,
};
ldlm_state->ldlm_cancel_service = \
ptlrpc_register_service(&conf, ldlm_svc_kset,
- ldlm_svc_proc_dir);
+ ldlm_svc_debugfs_dir);
if (IS_ERR(ldlm_state->ldlm_cancel_service)) {
CERROR("failed to start service\n");
rc = PTR_ERR(ldlm_state->ldlm_cancel_service);
kobject_put(ldlm_kobj);
}
- ldlm_proc_cleanup();
+ ldlm_debugfs_cleanup();
#ifdef HAVE_SERVER_SUPPORT
if (expired_lock_thread_state != ELT_STOPPED) {
ldlm_lock_slab = kmem_cache_create("ldlm_locks",
sizeof(struct ldlm_lock), 0,
- SLAB_HWCACHE_ALIGN | SLAB_DESTROY_BY_RCU, NULL);
+ SLAB_HWCACHE_ALIGN, NULL);
if (ldlm_lock_slab == NULL)
goto out_resource;