Whamcloud - gitweb
LU-14552 ptlrpc: NULL pointer dereference in ptlrpc_watchdog_fire
[fs/lustre-release.git] / lustre / ldlm / ldlm_lib.c
index 74d769b..b0eea47 100644 (file)
@@ -541,7 +541,7 @@ int client_obd_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
        if (lustre_cfg_buf(lcfg, 4)) {
                __u32 refnet = libcfs_str2net(lustre_cfg_string(lcfg, 4));
 
-               if (refnet == LNET_NIDNET(LNET_NID_ANY)) {
+               if (refnet == LNET_NET_ANY) {
                        rc = -EINVAL;
                        CERROR("%s: bad mount option 'network=%s': rc = %d\n",
                               obd->obd_name, lustre_cfg_string(lcfg, 4),
@@ -578,10 +578,12 @@ int client_obd_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                                                LDLM_NAMESPACE_CLIENT,
                                                LDLM_NAMESPACE_GREEDY,
                                                ns_type);
-       if (obd->obd_namespace == NULL) {
-               CERROR("Unable to create client namespace - %s\n",
-                      obd->obd_name);
-               GOTO(err_import, rc = -ENOMEM);
+       if (IS_ERR(obd->obd_namespace)) {
+               rc = PTR_ERR(obd->obd_namespace);
+               CERROR("%s: unable to create client namespace: rc = %d\n",
+                      obd->obd_name, rc);
+               obd->obd_namespace = NULL;
+               GOTO(err_import, rc);
        }
 
        RETURN(rc);
@@ -595,8 +597,8 @@ err:
                OBD_FREE(cli->cl_mod_tag_bitmap,
                         BITS_TO_LONGS(OBD_MAX_RIF_MAX) * sizeof(long));
        cli->cl_mod_tag_bitmap = NULL;
-       RETURN(rc);
 
+       RETURN(rc);
 }
 EXPORT_SYMBOL(client_obd_setup);
 
@@ -840,7 +842,7 @@ static inline int target_check_recovery_timer(struct obd_device *target)
        if (!target->obd_recovering || target->obd_recovery_start == 0)
                return 0;
 
-       remaining = hrtimer_expires_remaining(&target->obd_recovery_timer);
+       remaining = hrtimer_get_remaining(&target->obd_recovery_timer);
        timeout = ktime_divns(remaining, NSEC_PER_SEC);
        if (timeout > -30)
                return 0;
@@ -908,7 +910,7 @@ static int target_handle_reconnect(struct lustre_handle *conn,
                GOTO(out_already, rc);
        }
 
-       remaining = hrtimer_expires_remaining(&target->obd_recovery_timer);
+       remaining = hrtimer_get_remaining(&target->obd_recovery_timer);
        timeout = ktime_divns(remaining, NSEC_PER_SEC);
        if (timeout > 0) {
                LCONSOLE_WARN("%s: Client %s (at %s) reconnected, waiting for %d clients in recovery for %lld:%.02lld\n",
@@ -1341,7 +1343,7 @@ no_export:
        } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1 &&
                   rc != EALREADY) {
                if (!strstr(cluuid.uuid, "mdt"))
-                       LCONSOLE_WARN("%s: Rejecting reconnect from the known client %s (at %s) because it is indicating it is a new client",
+                       LCONSOLE_WARN("%s: Rejecting reconnect from the known client %s (at %s) because it is indicating it is a new client\n",
                                      target->obd_name, cluuid.uuid,
                                      libcfs_nid2str(req->rq_peer.nid));
                GOTO(out, rc = -EALREADY);
@@ -1402,7 +1404,7 @@ no_export:
                        known =
                           atomic_read(&target->obd_max_recoverable_clients);
                        stale = target->obd_stale_clients;
-                       remaining = hrtimer_expires_remaining(timer);
+                       remaining = hrtimer_get_remaining(timer);
                        left = ktime_divns(remaining, NSEC_PER_SEC);
 
                        if (ktime_to_ns(remaining) > 0) {
@@ -1594,6 +1596,18 @@ int target_handle_disconnect(struct ptlrpc_request *req)
        if (rc)
                RETURN(rc);
 
+       /* In case of target disconnect, updating sec ctx immediately is
+        * required in order to record latest sequence number used.
+        * Sequence is normally updated on export destroy, but this event
+        * can occur too late, ie after a new target connect request has
+        * been processed.
+        * Maintaining correct sequence when client connection becomes idle
+        * ensures that GSS does not erroneously consider requests as replays.
+        */
+       rc = sptlrpc_export_update_ctx(req->rq_export);
+       if (rc)
+               RETURN(rc);
+
        /* Keep the rq_export around so we can send the reply. */
        req->rq_status = obd_disconnect(class_export_get(req->rq_export));
 
@@ -1908,7 +1922,7 @@ static void extend_recovery_timer(struct obd_device *obd, timeout_t dr_timeout,
        }
        LASSERT(obd->obd_recovery_start != 0);
 
-       left_ns = hrtimer_expires_remaining(&obd->obd_recovery_timer);
+       left_ns = hrtimer_get_remaining(&obd->obd_recovery_timer);
        left = ktime_divns(left_ns, NSEC_PER_SEC);
 
        if (extend) {
@@ -2061,7 +2075,7 @@ static int check_for_next_transno(struct lu_target *lut)
                req_transno = lustre_msg_get_transno(req->rq_reqmsg);
        }
 
-       if (tdtd != NULL)
+       if (!obd->obd_abort_recov_mdt && tdtd)
                update_transno = distribute_txn_get_next_transno(tdtd);
 
        connected = atomic_read(&obd->obd_connected_clients);
@@ -2081,7 +2095,7 @@ static int check_for_next_transno(struct lu_target *lut)
        } else if (obd->obd_recovery_expired) {
                CDEBUG(D_HA, "waking for expired recovery\n");
                wake_up = 1;
-       } else if (tdtd != NULL && req != NULL &&
+       } else if (!obd->obd_abort_recov_mdt && tdtd && req &&
                   is_req_replayed_by_update(req)) {
                LASSERTF(req_transno < next_transno,
                         "req_transno %llu next_transno%llu\n", req_transno,
@@ -2193,7 +2207,7 @@ repeat:
                 * left in the queue
                 */
                spin_lock(&obd->obd_recovery_task_lock);
-               if (lut->lut_tdtd != NULL) {
+               if (!obd->obd_abort_recov_mdt && lut->lut_tdtd) {
                        next_update_transno =
                                distribute_txn_get_next_transno(lut->lut_tdtd);
 
@@ -2266,8 +2280,7 @@ repeat:
                /** evict exports which didn't finish recovery yet */
                class_disconnect_stale_exports(obd, exp_finished);
                return 1;
-       } else if (obd->obd_recovery_expired &&
-                  obd->obd_recovery_timeout < obd->obd_recovery_time_hard) {
+       } else if (obd->obd_recovery_expired) {
                obd->obd_recovery_expired = 0;
 
                /** If some clients died being recovered, evict them */
@@ -2421,7 +2434,7 @@ static int check_for_recovery_ready(struct lu_target *lut)
                        return 0;
        }
 
-       if (lut->lut_tdtd != NULL) {
+       if (!obd->obd_abort_recov_mdt && lut->lut_tdtd != NULL) {
                if (!lut->lut_tdtd->tdtd_replay_ready &&
                    !obd->obd_abort_recovery && !obd->obd_stopping) {
                        /*
@@ -2473,7 +2486,7 @@ static __u64 get_next_transno(struct lu_target *lut, int *type)
        if (type != NULL)
                *type = REQUEST_RECOVERY;
 
-       if (tdtd == NULL)
+       if (!tdtd || obd->obd_abort_recov_mdt)
                RETURN(transno);
 
        update_transno = distribute_txn_get_next_transno(tdtd);
@@ -2702,6 +2715,7 @@ static int target_recovery_thread(void *arg)
 
        thread->t_env = env;
        thread->t_id = -1; /* force filter_iobuf_get/put to use local buffers */
+       thread->t_task = current;
        env->le_ctx.lc_thread = thread;
        tgt_io_thread_init(thread); /* init thread_big_cache for IO requests */
 
@@ -2739,6 +2753,11 @@ static int target_recovery_thread(void *arg)
                LASSERT(trd->trd_processing_task == current->pid);
                DEBUG_REQ(D_HA, req, "processing lock from %s:",
                          libcfs_nid2str(req->rq_peer.nid));
+               if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_LOCK_REPLAY)) {
+                       req->rq_status = -ENODEV;
+                       target_request_copy_put(req);
+                       continue;
+               }
                handle_recovery_req(thread, req,
                                    trd->trd_recovery_handler);
                target_request_copy_put(req);