Whamcloud - gitweb
LU-13356 client: don't use OBD_CONNECT_MNE_SWAB
[fs/lustre-release.git] / lustre / ldlm / ldlm_lib.c
index 2688d07..4943301 100644 (file)
@@ -271,13 +271,13 @@ static int osc_on_mdt(char *obdname)
  * 3 - inactive-on-startup
  * 4 - restrictive net
  */
-int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
+int client_obd_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
-       struct client_obd *cli = &obddev->u.cli;
+       struct client_obd *cli = &obd->u.cli;
        struct obd_import *imp;
        struct obd_uuid server_uuid;
        int rq_portal, rp_portal, connect_op;
-       const char *name = obddev->obd_type->typ_name;
+       const char *name = obd->obd_type->typ_name;
        enum ldlm_ns_type ns_type = LDLM_NS_TYPE_UNKNOWN;
        char *cli_name = lustre_cfg_buf(lcfg, 0);
        struct ptlrpc_connection fake_conn = { .c_self = 0,
@@ -378,7 +378,7 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
         * ptlrpc_connect_interpret().
         */
        client_adjust_max_dirty(cli);
-       INIT_LIST_HEAD(&cli->cl_cache_waiters);
+       init_waitqueue_head(&cli->cl_cache_waiters);
        INIT_LIST_HEAD(&cli->cl_loi_ready_list);
        INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list);
        INIT_LIST_HEAD(&cli->cl_loi_write_list);
@@ -434,7 +434,7 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
         */
        cli->cl_max_pages_per_rpc = PTLRPC_MAX_BRW_PAGES;
 
-       cli->cl_max_short_io_bytes = OBD_MAX_SHORT_IO_BYTES;
+       cli->cl_max_short_io_bytes = OBD_DEF_SHORT_IO_BYTES;
 
        /*
         * set cl_chunkbits default value to PAGE_SHIFT,
@@ -451,7 +451,7 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
        } else if (cfs_totalram_pages() >> (20 - PAGE_SHIFT) <= 512 /* MB */) {
                cli->cl_max_rpcs_in_flight = 4;
        } else {
-               if (osc_on_mdt(obddev->obd_name))
+               if (osc_on_mdt(obd->obd_name))
                        cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_MAX;
                else
                        cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_DEFAULT;
@@ -482,12 +482,12 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
        }
 
        ptlrpc_init_client(rq_portal, rp_portal, name,
-                          &obddev->obd_ldlm_client);
+                          &obd->obd_ldlm_client);
 
-       imp = class_new_import(obddev);
+       imp = class_new_import(obd);
        if (imp == NULL)
                GOTO(err_ldlm, rc = -ENOENT);
-       imp->imp_client = &obddev->obd_ldlm_client;
+       imp->imp_client = &obd->obd_ldlm_client;
        imp->imp_connect_op = connect_op;
        memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
               LUSTRE_CFG_BUFLEN(lcfg, 1));
@@ -499,7 +499,7 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
                if (refnet == LNET_NIDNET(LNET_NID_ANY)) {
                        rc = -EINVAL;
                        CERROR("%s: bad mount option 'network=%s': rc = %d\n",
-                              obddev->obd_name, lustre_cfg_string(lcfg, 4),
+                              obd->obd_name, lustre_cfg_string(lcfg, 4),
                               rc);
                        GOTO(err_import, rc);
                }
@@ -521,7 +521,7 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
        if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
                if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
                        CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
-                              name, obddev->obd_name,
+                              name, obd->obd_name,
                               cli->cl_target_uuid.uuid);
                        spin_lock(&imp->imp_lock);
                        imp->imp_deactive = 1;
@@ -529,13 +529,13 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
                }
        }
 
-       obddev->obd_namespace = ldlm_namespace_new(obddev, obddev->obd_name,
-                                                  LDLM_NAMESPACE_CLIENT,
-                                                  LDLM_NAMESPACE_GREEDY,
-                                                  ns_type);
-       if (obddev->obd_namespace == NULL) {
+       obd->obd_namespace = ldlm_namespace_new(obd, obd->obd_name,
+                                               LDLM_NAMESPACE_CLIENT,
+                                               LDLM_NAMESPACE_GREEDY,
+                                               ns_type);
+       if (obd->obd_namespace == NULL) {
                CERROR("Unable to create client namespace - %s\n",
-                      obddev->obd_name);
+                      obd->obd_name);
                GOTO(err_import, rc = -ENOMEM);
        }
 
@@ -555,17 +555,17 @@ err:
 }
 EXPORT_SYMBOL(client_obd_setup);
 
-int client_obd_cleanup(struct obd_device *obddev)
+int client_obd_cleanup(struct obd_device *obd)
 {
-       struct client_obd *cli = &obddev->u.cli;
+       struct client_obd *cli = &obd->u.cli;
 
        ENTRY;
 
-       ldlm_namespace_free_post(obddev->obd_namespace);
-       obddev->obd_namespace = NULL;
+       ldlm_namespace_free_post(obd->obd_namespace);
+       obd->obd_namespace = NULL;
 
-       obd_cleanup_client_import(obddev);
-       LASSERT(obddev->u.cli.cl_import == NULL);
+       obd_cleanup_client_import(obd);
+       LASSERT(obd->u.cli.cl_import == NULL);
 
        ldlm_put_ref();
 
@@ -1138,8 +1138,8 @@ int target_handle_connect(struct ptlrpc_request *req)
                                OBD_CONNECT_MDS_MDS) != 0;
 
                /*
-                * OBD_CONNECT_MNE_SWAB is defined as OBD_CONNECT_MDS_MDS
-                * for Imperative Recovery connection from MGC to MGS.
+                * OBD_CONNECT_MNE_SWAB is removed at 2.14
+                * Checking OBD_CONNECT_FID can be removed in the future.
                 *
                 * Via check OBD_CONNECT_FID, we can distinguish whether
                 * the OBD_CONNECT_MDS_MDS/OBD_CONNECT_MNE_SWAB is from
@@ -1176,7 +1176,7 @@ int target_handle_connect(struct ptlrpc_request *req)
        if (obd_uuid_equals(&cluuid, &target->obd_uuid))
                goto dont_check_exports;
 
-       export = cfs_hash_lookup(target->obd_uuid_hash, &cluuid);
+       export = obd_uuid_lookup(target, &cluuid);
        if (!export)
                goto no_export;
 
@@ -1244,6 +1244,10 @@ int target_handle_connect(struct ptlrpc_request *req)
                rc = -EALREADY;
                class_export_put(export);
                export = NULL;
+       } else if (OBD_FAIL_PRECHECK(OBD_FAIL_TGT_RECOVERY_CONNECT) &&
+                  !lw_client) {
+               spin_unlock(&export->exp_lock);
+               rc = -EAGAIN;
        } else {
                export->exp_connecting = 1;
                spin_unlock(&export->exp_lock);
@@ -1684,9 +1688,8 @@ static void target_finish_recovery(struct lu_target *lut)
 static void abort_req_replay_queue(struct obd_device *obd)
 {
        struct ptlrpc_request *req, *n;
-       struct list_head abort_list;
+       LIST_HEAD(abort_list);
 
-       INIT_LIST_HEAD(&abort_list);
        spin_lock(&obd->obd_recovery_task_lock);
        list_splice_init(&obd->obd_req_replay_queue, &abort_list);
        spin_unlock(&obd->obd_recovery_task_lock);
@@ -1705,9 +1708,8 @@ static void abort_req_replay_queue(struct obd_device *obd)
 static void abort_lock_replay_queue(struct obd_device *obd)
 {
        struct ptlrpc_request *req, *n;
-       struct list_head abort_list;
+       LIST_HEAD(abort_list);
 
-       INIT_LIST_HEAD(&abort_list);
        spin_lock(&obd->obd_recovery_task_lock);
        list_splice_init(&obd->obd_lock_replay_queue, &abort_list);
        spin_unlock(&obd->obd_recovery_task_lock);
@@ -1734,9 +1736,8 @@ static void abort_lock_replay_queue(struct obd_device *obd)
 void target_cleanup_recovery(struct obd_device *obd)
 {
        struct ptlrpc_request *req, *n;
-       struct list_head clean_list;
+       LIST_HEAD(clean_list);
 
-       INIT_LIST_HEAD(&clean_list);
        spin_lock(&obd->obd_dev_lock);
        if (!obd->obd_recovering) {
                spin_unlock(&obd->obd_dev_lock);
@@ -1830,7 +1831,8 @@ static void extend_recovery_timer(struct obd_device *obd, time_t dr_timeout,
        time_t left;
 
        spin_lock(&obd->obd_dev_lock);
-       if (!obd->obd_recovering || obd->obd_abort_recovery) {
+       if (!obd->obd_recovering || obd->obd_abort_recovery ||
+           obd->obd_stopping) {
                spin_unlock(&obd->obd_dev_lock);
                return;
        }
@@ -1890,40 +1892,40 @@ check_and_start_recovery_timer(struct obd_device *obd,
                               struct ptlrpc_request *req,
                               int new_client)
 {
-       time_t service_time = lustre_msg_get_service_time(req->rq_reqmsg);
+       timeout_t service_timeout = lustre_msg_get_service_timeout(req->rq_reqmsg);
        struct obd_device_target *obt = &obd->u.obt;
 
-       if (!new_client && service_time)
+       if (!new_client && service_timeout)
                /*
                 * Teach server about old server's estimates, as first guess
                 * at how long new requests will take.
                 */
                at_measured(&req->rq_rqbd->rqbd_svcpt->scp_at_estimate,
-                           service_time);
+                           service_timeout);
 
        target_start_recovery_timer(obd);
 
        /*
         * Convert the service time to RPC timeout,
-        * and reuse service_time to limit stack usage.
+        * and reuse service_timeout to limit stack usage.
         */
-       service_time = at_est2timeout(service_time);
+       service_timeout = at_est2timeout(service_timeout);
 
        if (OBD_FAIL_CHECK(OBD_FAIL_TGT_SLUGGISH_NET) &&
-           service_time < at_extra)
-               service_time = at_extra;
+           service_timeout < at_extra)
+               service_timeout = at_extra;
 
        /*
-        * We expect other clients to timeout within service_time, then try
+        * We expect other clients to timeout within service_timeout, then try
         * to reconnect, then try the failover server.  The max delay between
         * connect attempts is SWITCH_MAX + SWITCH_INC + INITIAL.
         */
-       service_time += 2 * INITIAL_CONNECT_TIMEOUT;
+       service_timeout += 2 * INITIAL_CONNECT_TIMEOUT;
 
        LASSERT(obt->obt_magic == OBT_MAGIC);
-       service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
-       if (service_time > obd->obd_recovery_timeout && !new_client)
-               extend_recovery_timer(obd, service_time, false);
+       service_timeout += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
+       if (service_timeout > obd->obd_recovery_timeout && !new_client)
+               extend_recovery_timer(obd, service_timeout, false);
 }
 
 /** Health checking routines */
@@ -2113,11 +2115,13 @@ repeat:
                         * yet, let's wait those threads stopped
                         */
                        if (next_update_transno == 0) {
+                               spin_unlock(&obd->obd_recovery_task_lock);
                                wait_event_idle(
                                        tdtd->tdtd_recovery_threads_waitq,
                                        atomic_read(&tdtd->tdtd_recovery_threads_count)
                                        == 0);
 
+                               spin_lock(&obd->obd_recovery_task_lock);
                                next_update_transno =
                                        distribute_txn_get_next_transno(
                                                                lut->lut_tdtd);
@@ -2173,7 +2177,8 @@ repeat:
                /** evict exports which didn't finish recovery yet */
                class_disconnect_stale_exports(obd, exp_finished);
                return 1;
-       } else if (obd->obd_recovery_expired) {
+       } else if (obd->obd_recovery_expired &&
+                  obd->obd_recovery_timeout < obd->obd_recovery_time_hard) {
                obd->obd_recovery_expired = 0;
 
                /** If some clients died being recovered, evict them */
@@ -2272,14 +2277,15 @@ static void handle_recovery_req(struct ptlrpc_thread *thread,
 
        /* don't reset timer for final stage */
        if (!exp_finished(req->rq_export)) {
-               time_t to = obd_timeout;
+               timeout_t timeout = obd_timeout;
 
                /**
-                * Add request timeout to the recovery time so next request from
+                * Add request @timeout to the recovery time so next request from
                 * this client may come in recovery time
                 */
                if (!AT_OFF) {
                        struct ptlrpc_service_part *svcpt;
+                       timeout_t est_timeout;
 
                        svcpt = req->rq_rqbd->rqbd_svcpt;
                        /*
@@ -2289,18 +2295,19 @@ static void handle_recovery_req(struct ptlrpc_thread *thread,
                         * use the maxium timeout here for waiting the client
                         * sending the next req
                         */
-                       to = max_t(time_t,
-                                  at_est2timeout(at_get(&svcpt->scp_at_estimate)),
-                                  lustre_msg_get_timeout(req->rq_reqmsg));
+                       est_timeout = at_get(&svcpt->scp_at_estimate);
+                       timeout = max_t(timeout_t, at_est2timeout(est_timeout),
+                                       lustre_msg_get_timeout(req->rq_reqmsg));
                        /*
                         * Add 2 net_latency, one for balance rq_deadline
                         * (see ptl_send_rpc), one for resend the req to server,
                         * Note: client will pack net_latency in replay req
                         * (see ptlrpc_replay_req)
                         */
-                       to += 2 * lustre_msg_get_service_time(req->rq_reqmsg);
+                       timeout += 2 * lustre_msg_get_service_timeout(req->rq_reqmsg);
                }
-               extend_recovery_timer(class_exp2obd(req->rq_export), to, true);
+               extend_recovery_timer(class_exp2obd(req->rq_export), timeout,
+                                     true);
        }
        EXIT;
 }
@@ -2327,7 +2334,7 @@ static int check_for_recovery_ready(struct lu_target *lut)
 
        if (lut->lut_tdtd != NULL) {
                if (!lut->lut_tdtd->tdtd_replay_ready &&
-                   !obd->obd_abort_recovery) {
+                   !obd->obd_abort_recovery && !obd->obd_stopping) {
                        /*
                         * Let's extend recovery timer, in case the recovery
                         * timer expired, and some clients got evicted
@@ -2502,7 +2509,7 @@ static void replay_request_or_update(struct lu_env *env,
                                continue;
                        }
 
-                       LASSERT(trd->trd_processing_task == current_pid());
+                       LASSERT(trd->trd_processing_task == current->pid);
                        DEBUG_REQ(D_HA, req, "processing x%llu t%lld from %s",
                                  req->rq_xid,
                                  lustre_msg_get_transno(req->rq_reqmsg),
@@ -2603,8 +2610,8 @@ static int target_recovery_thread(void *arg)
        tgt_io_thread_init(thread); /* init thread_big_cache for IO requests */
 
        CDEBUG(D_HA, "%s: started recovery thread pid %d\n", obd->obd_name,
-              current_pid());
-       trd->trd_processing_task = current_pid();
+              current->pid);
+       trd->trd_processing_task = current->pid;
 
        spin_lock(&obd->obd_dev_lock);
        obd->obd_recovering = 1;
@@ -2633,7 +2640,7 @@ static int target_recovery_thread(void *arg)
        CDEBUG(D_INFO, "2: lock replay stage - %d clients\n",
               atomic_read(&obd->obd_lock_replay_clients));
        while ((req = target_next_replay_lock(lut))) {
-               LASSERT(trd->trd_processing_task == current_pid());
+               LASSERT(trd->trd_processing_task == current->pid);
                DEBUG_REQ(D_HA, req, "processing lock from %s:",
                          libcfs_nid2str(req->rq_peer.nid));
                handle_recovery_req(thread, req,
@@ -2661,7 +2668,7 @@ static int target_recovery_thread(void *arg)
        target_cancel_recovery_timer(obd);
        spin_unlock(&obd->obd_recovery_task_lock);
        while ((req = target_next_final_ping(obd))) {
-               LASSERT(trd->trd_processing_task == current_pid());
+               LASSERT(trd->trd_processing_task == current->pid);
                DEBUG_REQ(D_HA, req, "processing final ping from %s:",
                          libcfs_nid2str(req->rq_peer.nid));
                handle_recovery_req(thread, req,
@@ -2842,7 +2849,7 @@ int target_queue_recovery_request(struct ptlrpc_request *req,
 
        ENTRY;
 
-       if (obd->obd_recovery_data.trd_processing_task == current_pid()) {
+       if (obd->obd_recovery_data.trd_processing_task == current->pid) {
                /* Processing the queue right now, don't re-add. */
                RETURN(1);
        }
@@ -2856,8 +2863,8 @@ int target_queue_recovery_request(struct ptlrpc_request *req,
                                cfs_fail_val = 0;
                                wake_up(&cfs_race_waitq);
 
-                               set_current_state(TASK_INTERRUPTIBLE);
-                               schedule_timeout(cfs_time_seconds(1));
+                               schedule_timeout_interruptible(
+                                       cfs_time_seconds(1));
                        }
                }
 
@@ -3298,16 +3305,6 @@ void ldlm_dump_export_locks(struct obd_export *exp)
 #endif
 
 #ifdef HAVE_SERVER_SUPPORT
-static int target_bulk_timeout(void *data)
-{
-       ENTRY;
-       /*
-        * We don't fail the connection here, because having the export
-        * killed makes the (vital) call to commitrw very sad.
-        */
-       RETURN(1);
-}
-
 static inline const char *bulk2type(struct ptlrpc_request *req)
 {
        if (req->rq_bulk_read)
@@ -3322,7 +3319,6 @@ int target_bulk_io(struct obd_export *exp, struct ptlrpc_bulk_desc *desc)
        struct ptlrpc_request *req = desc->bd_req;
        time64_t start = ktime_get_seconds();
        time64_t deadline;
-       struct l_wait_info lwi;
        int rc = 0;
 
        ENTRY;
@@ -3367,20 +3363,19 @@ int target_bulk_io(struct obd_export *exp, struct ptlrpc_bulk_desc *desc)
 
        do {
                time64_t timeoutl = deadline - ktime_get_seconds();
-               long timeout_jiffies = timeoutl <= 0 ?
-                                      1 : cfs_time_seconds(timeoutl);
                time64_t rq_deadline;
 
-               lwi = LWI_TIMEOUT_INTERVAL(timeout_jiffies,
-                                          cfs_time_seconds(1),
-                                          target_bulk_timeout, desc);
-               rc = l_wait_event(desc->bd_waitq,
-                                 !ptlrpc_server_bulk_active(desc) ||
-                                 exp->exp_failed ||
-                                 exp->exp_conn_cnt >
-                                 lustre_msg_get_conn_cnt(req->rq_reqmsg),
-                                 &lwi);
-               LASSERT(rc == 0 || rc == -ETIMEDOUT);
+               while (timeoutl >= 0 &&
+                      wait_event_idle_timeout(
+                              desc->bd_waitq,
+                              !ptlrpc_server_bulk_active(desc) ||
+                              exp->exp_failed ||
+                              exp->exp_conn_cnt >
+                              lustre_msg_get_conn_cnt(req->rq_reqmsg),
+                              timeoutl ? cfs_time_seconds(1) : 1) == 0)
+                       timeoutl -= 1;
+               rc = timeoutl < 0 ? -ETIMEDOUT : 0;
+
                /* Wait again if we changed rq_deadline. */
                rq_deadline = READ_ONCE(req->rq_deadline);
                deadline = start + bulk_timeout;