Whamcloud - gitweb
LU-11158 mdt: grow lvb buffer to hold layout
[fs/lustre-release.git] / lustre / ldlm / ldlm_lockd.c
index 3273fdc..5789e8c 100644 (file)
@@ -49,6 +49,11 @@ static int ldlm_num_threads;
 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");
@@ -131,7 +136,7 @@ static DEFINE_SPINLOCK(waiting_locks_spinlock); /* BH lock (timer) */
  * All access to it should be under waiting_locks_spinlock.
  */
 static LIST_HEAD(waiting_locks_list);
-static void waiting_locks_callback(cfs_timer_cb_arg_t unused);
+static void waiting_locks_callback(TIMER_DATA_TYPE unused);
 static CFS_DEFINE_TIMER(waiting_locks_timer, waiting_locks_callback, 0, 0);
 
 enum elt_state {
@@ -303,7 +308,7 @@ static int ldlm_lock_busy(struct ldlm_lock *lock)
 }
 
 /* This is called from within a timer interrupt and cannot schedule */
-static void waiting_locks_callback(cfs_timer_cb_arg_t unused)
+static void waiting_locks_callback(TIMER_DATA_TYPE unused)
 {
        struct ldlm_lock        *lock;
        int                     need_dump = 0;
@@ -633,7 +638,8 @@ static void ldlm_failed_ast(struct ldlm_lock *lock, int rc,
 /**
  * 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)
 {
@@ -692,7 +698,7 @@ static int ldlm_handle_ast_error(struct ldlm_lock *lock,
                        /* 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);
@@ -727,20 +733,24 @@ static int ldlm_cb_interpret(const struct lu_env *env,
                } 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",
@@ -988,8 +998,12 @@ int ldlm_server_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data)
         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.
@@ -1174,6 +1188,7 @@ int ldlm_handle_enqueue0(struct ldlm_namespace *ns,
        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");
@@ -1254,7 +1269,7 @@ int ldlm_handle_enqueue0(struct ldlm_namespace *ns,
        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);
@@ -1302,25 +1317,25 @@ existing_lock:
                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);
@@ -1394,43 +1409,59 @@ existing_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;
                        }
                }
 
@@ -1512,8 +1543,20 @@ int ldlm_handle_convert0(struct ptlrpc_request *req,
                        ldlm_clear_cbpending(lock);
                        lock->l_policy_data.l_inodebits.cancel_bits = 0;
                        ldlm_inodebits_drop(lock, bits & ~new);
-                       lock->l_bl_ast_run = 0;
-                       ldlm_clear_ast_sent(lock);
+                       /* if lock is in a bl_ast list, remove it from the list
+                        * here before reprocessing.
+                        */
+                       if (!list_empty(&lock->l_bl_ast)) {
+                               ldlm_discard_bl_lock(lock);
+                       } else {
+                               /* in this case lock was taken from bl_ast list
+                                * already by ldlm_work_bl_ast_lock() and lock
+                                * must clear only some remaining states.
+                                */
+                               ldlm_clear_ast_sent(lock);
+                               lock->l_bl_ast_run = 0;
+                               ldlm_clear_blocking_lock(lock);
+                       }
                        unlock_res_and_lock(lock);
 
                        ldlm_reprocess_all(lock->l_resource);
@@ -1550,6 +1593,7 @@ int ldlm_request_cancel(struct ptlrpc_request *req,
                        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;
@@ -1591,15 +1635,16 @@ int ldlm_request_cancel(struct ptlrpc_request *req,
                                 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) &&
                    lock->l_blast_sent != 0) {
@@ -1761,6 +1806,21 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
        }
 
        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 */
@@ -1784,21 +1844,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
                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.
@@ -2930,11 +2976,12 @@ static int ldlm_setup(void)
                        .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,
@@ -2971,13 +3018,14 @@ static int ldlm_setup(void)
                        .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,