Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1 | /* |
| 2 | * GPL HEADER START |
| 3 | * |
| 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 only, |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License version 2 for more details (a copy is included |
| 14 | * in the LICENSE file that accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * version 2 along with this program; If not, see |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | * |
| 32 | * lustre/ptlrpc/import.c |
| 33 | * |
| 34 | * Author: Mike Shaver <shaver@clusterfs.com> |
| 35 | */ |
| 36 | |
| 37 | #define DEBUG_SUBSYSTEM S_RPC |
| 38 | |
Greg Kroah-Hartman | e27db14 | 2014-07-11 22:29:36 -0700 | [diff] [blame] | 39 | #include "../include/obd_support.h" |
| 40 | #include "../include/lustre_ha.h" |
| 41 | #include "../include/lustre_net.h" |
| 42 | #include "../include/lustre_import.h" |
| 43 | #include "../include/lustre_export.h" |
| 44 | #include "../include/obd.h" |
| 45 | #include "../include/obd_cksum.h" |
| 46 | #include "../include/obd_class.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 47 | |
| 48 | #include "ptlrpc_internal.h" |
| 49 | |
| 50 | struct ptlrpc_connect_async_args { |
| 51 | __u64 pcaa_peer_committed; |
| 52 | int pcaa_initial_connect; |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * Updates import \a imp current state to provided \a state value |
| 57 | * Helper function. Must be called under imp_lock. |
| 58 | */ |
| 59 | static void __import_set_state(struct obd_import *imp, |
| 60 | enum lustre_imp_state state) |
| 61 | { |
Andriy Skulysh | 502cb58 | 2015-03-25 22:07:07 -0400 | [diff] [blame] | 62 | switch (state) { |
| 63 | case LUSTRE_IMP_CLOSED: |
| 64 | case LUSTRE_IMP_NEW: |
| 65 | case LUSTRE_IMP_DISCON: |
| 66 | case LUSTRE_IMP_CONNECTING: |
| 67 | break; |
| 68 | case LUSTRE_IMP_REPLAY_WAIT: |
| 69 | imp->imp_replay_state = LUSTRE_IMP_REPLAY_LOCKS; |
| 70 | break; |
| 71 | default: |
| 72 | imp->imp_replay_state = LUSTRE_IMP_REPLAY; |
| 73 | } |
| 74 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 75 | imp->imp_state = state; |
| 76 | imp->imp_state_hist[imp->imp_state_hist_idx].ish_state = state; |
| 77 | imp->imp_state_hist[imp->imp_state_hist_idx].ish_time = |
Arnd Bergmann | 74e489a | 2015-09-27 16:45:18 -0400 | [diff] [blame] | 78 | ktime_get_real_seconds(); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 79 | imp->imp_state_hist_idx = (imp->imp_state_hist_idx + 1) % |
| 80 | IMP_STATE_HIST_LEN; |
| 81 | } |
| 82 | |
| 83 | /* A CLOSED import should remain so. */ |
Kristina Martsenko | 532118c | 2013-11-11 21:35:03 +0200 | [diff] [blame] | 84 | #define IMPORT_SET_STATE_NOLOCK(imp, state) \ |
| 85 | do { \ |
| 86 | if (imp->imp_state != LUSTRE_IMP_CLOSED) { \ |
| 87 | CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n", \ |
| 88 | imp, obd2cli_tgt(imp->imp_obd), \ |
| 89 | ptlrpc_import_state_name(imp->imp_state), \ |
| 90 | ptlrpc_import_state_name(state)); \ |
| 91 | __import_set_state(imp, state); \ |
| 92 | } \ |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 93 | } while (0) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 94 | |
| 95 | #define IMPORT_SET_STATE(imp, state) \ |
| 96 | do { \ |
| 97 | spin_lock(&imp->imp_lock); \ |
| 98 | IMPORT_SET_STATE_NOLOCK(imp, state); \ |
| 99 | spin_unlock(&imp->imp_lock); \ |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 100 | } while (0) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 101 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 102 | static int ptlrpc_connect_interpret(const struct lu_env *env, |
| 103 | struct ptlrpc_request *request, |
Greg Donald | aff9d8e | 2014-08-21 11:07:42 -0500 | [diff] [blame] | 104 | void *data, int rc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 105 | int ptlrpc_import_recovery_state_machine(struct obd_import *imp); |
| 106 | |
| 107 | /* Only this function is allowed to change the import state when it is |
| 108 | * CLOSED. I would rather refcount the import and free it after |
| 109 | * disconnection like we do with exports. To do that, the client_obd |
| 110 | * will need to save the peer info somewhere other than in the import, |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 111 | * though. |
| 112 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 113 | int ptlrpc_init_import(struct obd_import *imp) |
| 114 | { |
| 115 | spin_lock(&imp->imp_lock); |
| 116 | |
| 117 | imp->imp_generation++; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 118 | imp->imp_state = LUSTRE_IMP_NEW; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 119 | |
| 120 | spin_unlock(&imp->imp_lock); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | EXPORT_SYMBOL(ptlrpc_init_import); |
| 125 | |
| 126 | #define UUID_STR "_UUID" |
Shraddha Barke | 9dd7d42 | 2015-10-08 01:36:06 +0530 | [diff] [blame] | 127 | static void deuuidify(char *uuid, const char *prefix, char **uuid_start, |
| 128 | int *uuid_len) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 129 | { |
| 130 | *uuid_start = !prefix || strncmp(uuid, prefix, strlen(prefix)) |
| 131 | ? uuid : uuid + strlen(prefix); |
| 132 | |
| 133 | *uuid_len = strlen(*uuid_start); |
| 134 | |
| 135 | if (*uuid_len < strlen(UUID_STR)) |
| 136 | return; |
| 137 | |
| 138 | if (!strncmp(*uuid_start + *uuid_len - strlen(UUID_STR), |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 139 | UUID_STR, strlen(UUID_STR))) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 140 | *uuid_len -= strlen(UUID_STR); |
| 141 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Returns true if import was FULL, false if import was already not |
| 145 | * connected. |
| 146 | * @imp - import to be disconnected |
| 147 | * @conn_cnt - connection count (epoch) of the request that timed out |
| 148 | * and caused the disconnection. In some cases, multiple |
| 149 | * inflight requests can fail to a single target (e.g. OST |
| 150 | * bulk requests) and if one has already caused a reconnection |
| 151 | * (increasing the import->conn_cnt) the older failure should |
| 152 | * not also cause a reconnection. If zero it forces a reconnect. |
| 153 | */ |
| 154 | int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt) |
| 155 | { |
| 156 | int rc = 0; |
| 157 | |
| 158 | spin_lock(&imp->imp_lock); |
| 159 | |
| 160 | if (imp->imp_state == LUSTRE_IMP_FULL && |
| 161 | (conn_cnt == 0 || conn_cnt == imp->imp_conn_cnt)) { |
| 162 | char *target_start; |
| 163 | int target_len; |
| 164 | |
| 165 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, |
| 166 | &target_start, &target_len); |
| 167 | |
| 168 | if (imp->imp_replayable) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 169 | LCONSOLE_WARN("%s: Connection to %.*s (at %s) was lost; in progress operations using this service will wait for recovery to complete\n", |
| 170 | imp->imp_obd->obd_name, target_len, target_start, |
| 171 | libcfs_nid2str(imp->imp_connection->c_peer.nid)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 172 | } else { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 173 | LCONSOLE_ERROR_MSG(0x166, "%s: Connection to %.*s (at %s) was lost; in progress operations using this service will fail\n", |
| 174 | imp->imp_obd->obd_name, |
| 175 | target_len, target_start, |
| 176 | libcfs_nid2str(imp->imp_connection->c_peer.nid)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 177 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 178 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON); |
| 179 | spin_unlock(&imp->imp_lock); |
| 180 | |
| 181 | if (obd_dump_on_timeout) |
| 182 | libcfs_debug_dumplog(); |
| 183 | |
| 184 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_DISCON); |
| 185 | rc = 1; |
| 186 | } else { |
| 187 | spin_unlock(&imp->imp_lock); |
| 188 | CDEBUG(D_HA, "%s: import %p already %s (conn %u, was %u): %s\n", |
| 189 | imp->imp_client->cli_name, imp, |
| 190 | (imp->imp_state == LUSTRE_IMP_FULL && |
| 191 | imp->imp_conn_cnt > conn_cnt) ? |
| 192 | "reconnected" : "not connected", imp->imp_conn_cnt, |
| 193 | conn_cnt, ptlrpc_import_state_name(imp->imp_state)); |
| 194 | } |
| 195 | |
| 196 | return rc; |
| 197 | } |
| 198 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 199 | /* |
| 200 | * This acts as a barrier; all existing requests are rejected, and |
| 201 | * no new requests will be accepted until the import is valid again. |
| 202 | */ |
| 203 | void ptlrpc_deactivate_import(struct obd_import *imp) |
| 204 | { |
Maxime Lorrillere | 441fda8 | 2015-08-17 14:04:49 +0200 | [diff] [blame] | 205 | CDEBUG(D_HA, "setting import %s INVALID\n", obd2cli_tgt(imp->imp_obd)); |
| 206 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 207 | spin_lock(&imp->imp_lock); |
Maxime Lorrillere | 441fda8 | 2015-08-17 14:04:49 +0200 | [diff] [blame] | 208 | imp->imp_invalid = 1; |
| 209 | imp->imp_generation++; |
| 210 | spin_unlock(&imp->imp_lock); |
| 211 | |
| 212 | ptlrpc_abort_inflight(imp); |
| 213 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_INACTIVE); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 214 | } |
| 215 | EXPORT_SYMBOL(ptlrpc_deactivate_import); |
| 216 | |
| 217 | static unsigned int |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 218 | ptlrpc_inflight_deadline(struct ptlrpc_request *req, time64_t now) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 219 | { |
| 220 | long dl; |
| 221 | |
| 222 | if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting) || |
| 223 | (req->rq_phase == RQ_PHASE_BULK) || |
| 224 | (req->rq_phase == RQ_PHASE_NEW))) |
| 225 | return 0; |
| 226 | |
| 227 | if (req->rq_timedout) |
| 228 | return 0; |
| 229 | |
| 230 | if (req->rq_phase == RQ_PHASE_NEW) |
| 231 | dl = req->rq_sent; |
| 232 | else |
| 233 | dl = req->rq_deadline; |
| 234 | |
| 235 | if (dl <= now) |
| 236 | return 0; |
| 237 | |
| 238 | return dl - now; |
| 239 | } |
| 240 | |
| 241 | static unsigned int ptlrpc_inflight_timeout(struct obd_import *imp) |
| 242 | { |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 243 | time64_t now = ktime_get_real_seconds(); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 244 | struct list_head *tmp, *n; |
| 245 | struct ptlrpc_request *req; |
| 246 | unsigned int timeout = 0; |
| 247 | |
| 248 | spin_lock(&imp->imp_lock); |
| 249 | list_for_each_safe(tmp, n, &imp->imp_sending_list) { |
| 250 | req = list_entry(tmp, struct ptlrpc_request, rq_list); |
| 251 | timeout = max(ptlrpc_inflight_deadline(req, now), timeout); |
| 252 | } |
| 253 | spin_unlock(&imp->imp_lock); |
| 254 | return timeout; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * This function will invalidate the import, if necessary, then block |
| 259 | * for all the RPC completions, and finally notify the obd to |
| 260 | * invalidate its state (ie cancel locks, clear pending requests, |
| 261 | * etc). |
| 262 | */ |
| 263 | void ptlrpc_invalidate_import(struct obd_import *imp) |
| 264 | { |
| 265 | struct list_head *tmp, *n; |
| 266 | struct ptlrpc_request *req; |
| 267 | struct l_wait_info lwi; |
| 268 | unsigned int timeout; |
| 269 | int rc; |
| 270 | |
| 271 | atomic_inc(&imp->imp_inval_count); |
| 272 | |
| 273 | if (!imp->imp_invalid || imp->imp_obd->obd_no_recov) |
| 274 | ptlrpc_deactivate_import(imp); |
| 275 | |
Andriy Skulysh | cca8fca | 2014-06-22 21:32:10 -0400 | [diff] [blame] | 276 | CFS_FAIL_TIMEOUT(OBD_FAIL_MGS_CONNECT_NET, 3 * cfs_fail_val / 2); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 277 | LASSERT(imp->imp_invalid); |
| 278 | |
| 279 | /* Wait forever until inflight == 0. We really can't do it another |
| 280 | * way because in some cases we need to wait for very long reply |
| 281 | * unlink. We can't do anything before that because there is really |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 282 | * no guarantee that some rdma transfer is not in progress right now. |
| 283 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 284 | do { |
| 285 | /* Calculate max timeout for waiting on rpcs to error |
| 286 | * out. Use obd_timeout if calculated value is smaller |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 287 | * than it. |
| 288 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 289 | if (!OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK)) { |
| 290 | timeout = ptlrpc_inflight_timeout(imp); |
| 291 | timeout += timeout / 3; |
| 292 | |
| 293 | if (timeout == 0) |
| 294 | timeout = obd_timeout; |
| 295 | } else { |
| 296 | /* decrease the interval to increase race condition */ |
| 297 | timeout = 1; |
| 298 | } |
| 299 | |
Greg Donald | 1d8cb70 | 2014-08-25 20:07:19 -0500 | [diff] [blame] | 300 | CDEBUG(D_RPCTRACE, |
| 301 | "Sleeping %d sec for inflight to error out\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 302 | timeout); |
| 303 | |
| 304 | /* Wait for all requests to error out and call completion |
| 305 | * callbacks. Cap it at obd_timeout -- these should all |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 306 | * have been locally cancelled by ptlrpc_abort_inflight. |
| 307 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 308 | lwi = LWI_TIMEOUT_INTERVAL( |
| 309 | cfs_timeout_cap(cfs_time_seconds(timeout)), |
| 310 | (timeout > 1)?cfs_time_seconds(1):cfs_time_seconds(1)/2, |
| 311 | NULL, NULL); |
| 312 | rc = l_wait_event(imp->imp_recovery_waitq, |
| 313 | (atomic_read(&imp->imp_inflight) == 0), |
| 314 | &lwi); |
| 315 | if (rc) { |
| 316 | const char *cli_tgt = obd2cli_tgt(imp->imp_obd); |
| 317 | |
| 318 | CERROR("%s: rc = %d waiting for callback (%d != 0)\n", |
| 319 | cli_tgt, rc, |
| 320 | atomic_read(&imp->imp_inflight)); |
| 321 | |
| 322 | spin_lock(&imp->imp_lock); |
| 323 | if (atomic_read(&imp->imp_inflight) == 0) { |
| 324 | int count = atomic_read(&imp->imp_unregistering); |
| 325 | |
| 326 | /* We know that "unregistering" rpcs only can |
| 327 | * survive in sending or delaying lists (they |
| 328 | * maybe waiting for long reply unlink in |
| 329 | * sluggish nets). Let's check this. If there |
| 330 | * is no inflight and unregistering != 0, this |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 331 | * is bug. |
| 332 | */ |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 333 | LASSERTF(count == 0, "Some RPCs are still unregistering: %d\n", |
| 334 | count); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 335 | |
| 336 | /* Let's save one loop as soon as inflight have |
| 337 | * dropped to zero. No new inflights possible at |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 338 | * this point. |
| 339 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 340 | rc = 0; |
| 341 | } else { |
| 342 | list_for_each_safe(tmp, n, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 343 | &imp->imp_sending_list) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 344 | req = list_entry(tmp, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 345 | struct ptlrpc_request, |
| 346 | rq_list); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 347 | DEBUG_REQ(D_ERROR, req, |
| 348 | "still on sending list"); |
| 349 | } |
| 350 | list_for_each_safe(tmp, n, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 351 | &imp->imp_delayed_list) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 352 | req = list_entry(tmp, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 353 | struct ptlrpc_request, |
| 354 | rq_list); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 355 | DEBUG_REQ(D_ERROR, req, |
| 356 | "still on delayed list"); |
| 357 | } |
| 358 | |
Vitaly Fertman | 81ea39e | 2016-06-20 16:55:34 -0400 | [diff] [blame] | 359 | CERROR("%s: Unregistering RPCs found (%d). Network is sluggish? Waiting them to error out.\n", |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 360 | cli_tgt, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 361 | atomic_read(&imp-> |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 362 | imp_unregistering)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 363 | } |
| 364 | spin_unlock(&imp->imp_lock); |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 365 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 366 | } while (rc != 0); |
| 367 | |
| 368 | /* |
| 369 | * Let's additionally check that no new rpcs added to import in |
| 370 | * "invalidate" state. |
| 371 | */ |
| 372 | LASSERT(atomic_read(&imp->imp_inflight) == 0); |
| 373 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_INVALIDATE); |
| 374 | sptlrpc_import_flush_all_ctx(imp); |
| 375 | |
| 376 | atomic_dec(&imp->imp_inval_count); |
| 377 | wake_up_all(&imp->imp_recovery_waitq); |
| 378 | } |
| 379 | EXPORT_SYMBOL(ptlrpc_invalidate_import); |
| 380 | |
| 381 | /* unset imp_invalid */ |
| 382 | void ptlrpc_activate_import(struct obd_import *imp) |
| 383 | { |
| 384 | struct obd_device *obd = imp->imp_obd; |
| 385 | |
| 386 | spin_lock(&imp->imp_lock); |
Hongchao Zhang | 0b291b9 | 2014-04-27 13:06:29 -0400 | [diff] [blame] | 387 | if (imp->imp_deactive != 0) { |
| 388 | spin_unlock(&imp->imp_lock); |
| 389 | return; |
| 390 | } |
| 391 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 392 | imp->imp_invalid = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 393 | spin_unlock(&imp->imp_lock); |
| 394 | obd_import_event(obd, imp, IMP_EVENT_ACTIVE); |
| 395 | } |
| 396 | EXPORT_SYMBOL(ptlrpc_activate_import); |
| 397 | |
Andriy Skulysh | cca8fca | 2014-06-22 21:32:10 -0400 | [diff] [blame] | 398 | static void ptlrpc_pinger_force(struct obd_import *imp) |
| 399 | { |
| 400 | CDEBUG(D_HA, "%s: waking up pinger s:%s\n", obd2cli_tgt(imp->imp_obd), |
| 401 | ptlrpc_import_state_name(imp->imp_state)); |
| 402 | |
| 403 | spin_lock(&imp->imp_lock); |
| 404 | imp->imp_force_verify = 1; |
| 405 | spin_unlock(&imp->imp_lock); |
| 406 | |
| 407 | if (imp->imp_state != LUSTRE_IMP_CONNECTING) |
| 408 | ptlrpc_pinger_wake_up(); |
| 409 | } |
| 410 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 411 | void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt) |
| 412 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 413 | LASSERT(!imp->imp_dlm_fake); |
| 414 | |
| 415 | if (ptlrpc_set_import_discon(imp, conn_cnt)) { |
| 416 | if (!imp->imp_replayable) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 417 | CDEBUG(D_HA, "import %s@%s for %s not replayable, auto-deactivating\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 418 | obd2cli_tgt(imp->imp_obd), |
| 419 | imp->imp_connection->c_remote_uuid.uuid, |
| 420 | imp->imp_obd->obd_name); |
| 421 | ptlrpc_deactivate_import(imp); |
| 422 | } |
| 423 | |
Andriy Skulysh | cca8fca | 2014-06-22 21:32:10 -0400 | [diff] [blame] | 424 | ptlrpc_pinger_force(imp); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 425 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 426 | } |
| 427 | EXPORT_SYMBOL(ptlrpc_fail_import); |
| 428 | |
| 429 | int ptlrpc_reconnect_import(struct obd_import *imp) |
| 430 | { |
Andriy Skulysh | cca8fca | 2014-06-22 21:32:10 -0400 | [diff] [blame] | 431 | struct l_wait_info lwi; |
| 432 | int secs = cfs_time_seconds(obd_timeout); |
| 433 | int rc; |
| 434 | |
| 435 | ptlrpc_pinger_force(imp); |
| 436 | |
| 437 | CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", |
| 438 | obd2cli_tgt(imp->imp_obd), secs); |
| 439 | |
| 440 | lwi = LWI_TIMEOUT(secs, NULL, NULL); |
| 441 | rc = l_wait_event(imp->imp_recovery_waitq, |
| 442 | !ptlrpc_import_in_recovery(imp), &lwi); |
| 443 | CDEBUG(D_HA, "%s: recovery finished s:%s\n", obd2cli_tgt(imp->imp_obd), |
| 444 | ptlrpc_import_state_name(imp->imp_state)); |
| 445 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 446 | } |
| 447 | EXPORT_SYMBOL(ptlrpc_reconnect_import); |
| 448 | |
| 449 | /** |
| 450 | * Connection on import \a imp is changed to another one (if more than one is |
| 451 | * present). We typically chose connection that we have not tried to connect to |
| 452 | * the longest |
| 453 | */ |
| 454 | static int import_select_connection(struct obd_import *imp) |
| 455 | { |
| 456 | struct obd_import_conn *imp_conn = NULL, *conn; |
| 457 | struct obd_export *dlmexp; |
| 458 | char *target_start; |
| 459 | int target_len, tried_all = 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 460 | |
| 461 | spin_lock(&imp->imp_lock); |
| 462 | |
| 463 | if (list_empty(&imp->imp_conn_list)) { |
| 464 | CERROR("%s: no connections available\n", |
| 465 | imp->imp_obd->obd_name); |
| 466 | spin_unlock(&imp->imp_lock); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 467 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | list_for_each_entry(conn, &imp->imp_conn_list, oic_item) { |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 471 | CDEBUG(D_HA, "%s: connect to NID %s last attempt %llu\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 472 | imp->imp_obd->obd_name, |
| 473 | libcfs_nid2str(conn->oic_conn->c_peer.nid), |
| 474 | conn->oic_last_attempt); |
| 475 | |
| 476 | /* If we have not tried this connection since |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 477 | * the last successful attempt, go with this one |
| 478 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 479 | if ((conn->oic_last_attempt == 0) || |
| 480 | cfs_time_beforeq_64(conn->oic_last_attempt, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 481 | imp->imp_last_success_conn)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 482 | imp_conn = conn; |
| 483 | tried_all = 0; |
| 484 | break; |
| 485 | } |
| 486 | |
| 487 | /* If all of the connections have already been tried |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 488 | * since the last successful connection; just choose the |
| 489 | * least recently used |
| 490 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 491 | if (!imp_conn) |
| 492 | imp_conn = conn; |
| 493 | else if (cfs_time_before_64(conn->oic_last_attempt, |
| 494 | imp_conn->oic_last_attempt)) |
| 495 | imp_conn = conn; |
| 496 | } |
| 497 | |
| 498 | /* if not found, simply choose the current one */ |
| 499 | if (!imp_conn || imp->imp_force_reconnect) { |
| 500 | LASSERT(imp->imp_conn_current); |
| 501 | imp_conn = imp->imp_conn_current; |
| 502 | tried_all = 0; |
| 503 | } |
| 504 | LASSERT(imp_conn->oic_conn); |
| 505 | |
| 506 | /* If we've tried everything, and we're back to the beginning of the |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 507 | * list, increase our timeout and try again. It will be reset when |
| 508 | * we do finally connect. (FIXME: really we should wait for all network |
| 509 | * state associated with the last connection attempt to drain before |
| 510 | * trying to reconnect on it.) |
| 511 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 512 | if (tried_all && (imp->imp_conn_list.next == &imp_conn->oic_item)) { |
| 513 | struct adaptive_timeout *at = &imp->imp_at.iat_net_latency; |
Mike Rapoport | 50ffcb7 | 2015-10-13 16:03:40 +0300 | [diff] [blame] | 514 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 515 | if (at_get(at) < CONNECTION_SWITCH_MAX) { |
| 516 | at_measured(at, at_get(at) + CONNECTION_SWITCH_INC); |
| 517 | if (at_get(at) > CONNECTION_SWITCH_MAX) |
| 518 | at_reset(at, CONNECTION_SWITCH_MAX); |
| 519 | } |
| 520 | LASSERT(imp_conn->oic_last_attempt); |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 521 | CDEBUG(D_HA, "%s: tried all connections, increasing latency to %ds\n", |
| 522 | imp->imp_obd->obd_name, at_get(at)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | imp_conn->oic_last_attempt = cfs_time_current_64(); |
| 526 | |
| 527 | /* switch connection, don't mind if it's same as the current one */ |
Markus Elfring | a5cb888 | 2015-07-14 09:35:42 +0200 | [diff] [blame] | 528 | ptlrpc_connection_put(imp->imp_connection); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 529 | imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); |
| 530 | |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 531 | dlmexp = class_conn2export(&imp->imp_dlm_handle); |
Markus Elfring | a5cb888 | 2015-07-14 09:35:42 +0200 | [diff] [blame] | 532 | ptlrpc_connection_put(dlmexp->exp_connection); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 533 | dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); |
| 534 | class_export_put(dlmexp); |
| 535 | |
| 536 | if (imp->imp_conn_current != imp_conn) { |
| 537 | if (imp->imp_conn_current) { |
| 538 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, |
| 539 | &target_start, &target_len); |
| 540 | |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 541 | CDEBUG(D_HA, "%s: Connection changing to %.*s (at %s)\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 542 | imp->imp_obd->obd_name, |
| 543 | target_len, target_start, |
| 544 | libcfs_nid2str(imp_conn->oic_conn->c_peer.nid)); |
| 545 | } |
| 546 | |
| 547 | imp->imp_conn_current = imp_conn; |
| 548 | } |
| 549 | |
| 550 | CDEBUG(D_HA, "%s: import %p using connection %s/%s\n", |
| 551 | imp->imp_obd->obd_name, imp, imp_conn->oic_uuid.uuid, |
| 552 | libcfs_nid2str(imp_conn->oic_conn->c_peer.nid)); |
| 553 | |
| 554 | spin_unlock(&imp->imp_lock); |
| 555 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 556 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* |
| 560 | * must be called under imp_lock |
| 561 | */ |
| 562 | static int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno) |
| 563 | { |
| 564 | struct ptlrpc_request *req; |
| 565 | struct list_head *tmp; |
| 566 | |
Hongchao Zhang | 63d4257 | 2014-02-28 21:16:37 -0500 | [diff] [blame] | 567 | /* The requests in committed_list always have smaller transnos than |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 568 | * the requests in replay_list |
| 569 | */ |
Hongchao Zhang | 63d4257 | 2014-02-28 21:16:37 -0500 | [diff] [blame] | 570 | if (!list_empty(&imp->imp_committed_list)) { |
| 571 | tmp = imp->imp_committed_list.next; |
| 572 | req = list_entry(tmp, struct ptlrpc_request, rq_replay_list); |
| 573 | *transno = req->rq_transno; |
| 574 | if (req->rq_transno == 0) { |
| 575 | DEBUG_REQ(D_ERROR, req, |
| 576 | "zero transno in committed_list"); |
| 577 | LBUG(); |
| 578 | } |
| 579 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 580 | } |
Hongchao Zhang | 63d4257 | 2014-02-28 21:16:37 -0500 | [diff] [blame] | 581 | if (!list_empty(&imp->imp_replay_list)) { |
| 582 | tmp = imp->imp_replay_list.next; |
| 583 | req = list_entry(tmp, struct ptlrpc_request, rq_replay_list); |
| 584 | *transno = req->rq_transno; |
| 585 | if (req->rq_transno == 0) { |
| 586 | DEBUG_REQ(D_ERROR, req, "zero transno in replay_list"); |
| 587 | LBUG(); |
| 588 | } |
| 589 | return 1; |
| 590 | } |
| 591 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /** |
| 595 | * Attempt to (re)connect import \a imp. This includes all preparations, |
| 596 | * initializing CONNECT RPC request and passing it to ptlrpcd for |
| 597 | * actual sending. |
| 598 | * Returns 0 on success or error code. |
| 599 | */ |
| 600 | int ptlrpc_connect_import(struct obd_import *imp) |
| 601 | { |
| 602 | struct obd_device *obd = imp->imp_obd; |
| 603 | int initial_connect = 0; |
| 604 | int set_transno = 0; |
| 605 | __u64 committed_before_reconnect = 0; |
| 606 | struct ptlrpc_request *request; |
| 607 | char *bufs[] = { NULL, |
| 608 | obd2cli_tgt(imp->imp_obd), |
| 609 | obd->obd_uuid.uuid, |
| 610 | (char *)&imp->imp_dlm_handle, |
| 611 | (char *)&imp->imp_connect_data }; |
| 612 | struct ptlrpc_connect_async_args *aa; |
| 613 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 614 | |
| 615 | spin_lock(&imp->imp_lock); |
| 616 | if (imp->imp_state == LUSTRE_IMP_CLOSED) { |
| 617 | spin_unlock(&imp->imp_lock); |
| 618 | CERROR("can't connect to a closed import\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 619 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 620 | } else if (imp->imp_state == LUSTRE_IMP_FULL) { |
| 621 | spin_unlock(&imp->imp_lock); |
| 622 | CERROR("already connected\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 623 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 624 | } else if (imp->imp_state == LUSTRE_IMP_CONNECTING) { |
| 625 | spin_unlock(&imp->imp_lock); |
| 626 | CERROR("already connecting\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 627 | return -EALREADY; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CONNECTING); |
| 631 | |
| 632 | imp->imp_conn_cnt++; |
| 633 | imp->imp_resend_replay = 0; |
| 634 | |
| 635 | if (!lustre_handle_is_used(&imp->imp_remote_handle)) |
| 636 | initial_connect = 1; |
| 637 | else |
| 638 | committed_before_reconnect = imp->imp_peer_committed_transno; |
| 639 | |
| 640 | set_transno = ptlrpc_first_transno(imp, |
| 641 | &imp->imp_connect_data.ocd_transno); |
| 642 | spin_unlock(&imp->imp_lock); |
| 643 | |
| 644 | rc = import_select_connection(imp); |
| 645 | if (rc) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 646 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 647 | |
Alexandr Terekhov | 5bcfab1 | 2014-05-31 18:20:39 +0300 | [diff] [blame] | 648 | rc = sptlrpc_import_sec_adapt(imp, NULL, NULL); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 649 | if (rc) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 650 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 651 | |
| 652 | /* Reset connect flags to the originally requested flags, in case |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 653 | * the server is updated on-the-fly we will get the new features. |
| 654 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 655 | imp->imp_connect_data.ocd_connect_flags = imp->imp_connect_flags_orig; |
| 656 | /* Reset ocd_version each time so the server knows the exact versions */ |
| 657 | imp->imp_connect_data.ocd_version = LUSTRE_VERSION_CODE; |
| 658 | imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT; |
| 659 | imp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18; |
| 660 | |
| 661 | rc = obd_reconnect(NULL, imp->imp_obd->obd_self_export, obd, |
| 662 | &obd->obd_uuid, &imp->imp_connect_data, NULL); |
| 663 | if (rc) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 664 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 665 | |
| 666 | request = ptlrpc_request_alloc(imp, &RQF_MDS_CONNECT); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 667 | if (!request) { |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 668 | rc = -ENOMEM; |
| 669 | goto out; |
| 670 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 671 | |
| 672 | rc = ptlrpc_request_bufs_pack(request, LUSTRE_OBD_VERSION, |
| 673 | imp->imp_connect_op, bufs, NULL); |
| 674 | if (rc) { |
| 675 | ptlrpc_request_free(request); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 676 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /* Report the rpc service time to the server so that it knows how long |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 680 | * to wait for clients to join recovery |
| 681 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 682 | lustre_msg_set_service_time(request->rq_reqmsg, |
| 683 | at_timeout2est(request->rq_timeout)); |
| 684 | |
| 685 | /* The amount of time we give the server to process the connect req. |
| 686 | * import_select_connection will increase the net latency on |
| 687 | * repeated reconnect attempts to cover slow networks. |
| 688 | * We override/ignore the server rpc completion estimate here, |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 689 | * which may be large if this is a reconnect attempt |
| 690 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 691 | request->rq_timeout = INITIAL_CONNECT_TIMEOUT; |
| 692 | lustre_msg_set_timeout(request->rq_reqmsg, request->rq_timeout); |
| 693 | |
| 694 | lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER); |
| 695 | |
Nathaniel Clark | 3d2b8f5 | 2016-06-09 22:35:17 -0400 | [diff] [blame] | 696 | request->rq_no_resend = 1; |
| 697 | request->rq_no_delay = 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 698 | request->rq_send_state = LUSTRE_IMP_CONNECTING; |
| 699 | /* Allow a slightly larger reply for future growth compatibility */ |
| 700 | req_capsule_set_size(&request->rq_pill, &RMF_CONNECT_DATA, RCL_SERVER, |
| 701 | sizeof(struct obd_connect_data)+16*sizeof(__u64)); |
| 702 | ptlrpc_request_set_replen(request); |
| 703 | request->rq_interpret_reply = ptlrpc_connect_interpret; |
| 704 | |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 705 | CLASSERT(sizeof(*aa) <= sizeof(request->rq_async_args)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 706 | aa = ptlrpc_req_async_args(request); |
Joe Perches | ec83e61 | 2013-10-13 20:22:03 -0700 | [diff] [blame] | 707 | memset(aa, 0, sizeof(*aa)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 708 | |
| 709 | aa->pcaa_peer_committed = committed_before_reconnect; |
| 710 | aa->pcaa_initial_connect = initial_connect; |
| 711 | |
| 712 | if (aa->pcaa_initial_connect) { |
| 713 | spin_lock(&imp->imp_lock); |
| 714 | imp->imp_replayable = 1; |
| 715 | spin_unlock(&imp->imp_lock); |
| 716 | lustre_msg_add_op_flags(request->rq_reqmsg, |
| 717 | MSG_CONNECT_INITIAL); |
| 718 | } |
| 719 | |
| 720 | if (set_transno) |
| 721 | lustre_msg_add_op_flags(request->rq_reqmsg, |
| 722 | MSG_CONNECT_TRANSNO); |
| 723 | |
| 724 | DEBUG_REQ(D_RPCTRACE, request, "(re)connect request (timeout %d)", |
| 725 | request->rq_timeout); |
Olaf Weber | c5c4c6f | 2015-09-14 18:41:35 -0400 | [diff] [blame] | 726 | ptlrpcd_add_req(request); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 727 | rc = 0; |
| 728 | out: |
Olaf Weber | c5c4c6f | 2015-09-14 18:41:35 -0400 | [diff] [blame] | 729 | if (rc != 0) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 730 | IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 731 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 732 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 733 | } |
| 734 | EXPORT_SYMBOL(ptlrpc_connect_import); |
| 735 | |
| 736 | static void ptlrpc_maybe_ping_import_soon(struct obd_import *imp) |
| 737 | { |
| 738 | int force_verify; |
| 739 | |
| 740 | spin_lock(&imp->imp_lock); |
| 741 | force_verify = imp->imp_force_verify != 0; |
| 742 | spin_unlock(&imp->imp_lock); |
| 743 | |
| 744 | if (force_verify) |
| 745 | ptlrpc_pinger_wake_up(); |
| 746 | } |
| 747 | |
| 748 | static int ptlrpc_busy_reconnect(int rc) |
| 749 | { |
| 750 | return (rc == -EBUSY) || (rc == -EAGAIN); |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * interpret_reply callback for connect RPCs. |
| 755 | * Looks into returned status of connect operation and decides |
| 756 | * what to do with the import - i.e enter recovery, promote it to |
| 757 | * full state for normal operations of disconnect it due to an error. |
| 758 | */ |
| 759 | static int ptlrpc_connect_interpret(const struct lu_env *env, |
| 760 | struct ptlrpc_request *request, |
| 761 | void *data, int rc) |
| 762 | { |
| 763 | struct ptlrpc_connect_async_args *aa = data; |
| 764 | struct obd_import *imp = request->rq_import; |
| 765 | struct client_obd *cli = &imp->imp_obd->u.cli; |
| 766 | struct lustre_handle old_hdl; |
| 767 | __u64 old_connect_flags; |
| 768 | int msg_flags; |
| 769 | struct obd_connect_data *ocd; |
| 770 | struct obd_export *exp; |
| 771 | int ret; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 772 | |
| 773 | spin_lock(&imp->imp_lock); |
| 774 | if (imp->imp_state == LUSTRE_IMP_CLOSED) { |
| 775 | imp->imp_connect_tried = 1; |
| 776 | spin_unlock(&imp->imp_lock); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 777 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | if (rc) { |
| 781 | /* if this reconnect to busy export - not need select new target |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 782 | * for connecting |
| 783 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 784 | imp->imp_force_reconnect = ptlrpc_busy_reconnect(rc); |
| 785 | spin_unlock(&imp->imp_lock); |
| 786 | ptlrpc_maybe_ping_import_soon(imp); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 787 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 788 | } |
| 789 | spin_unlock(&imp->imp_lock); |
| 790 | |
| 791 | LASSERT(imp->imp_conn_current); |
| 792 | |
| 793 | msg_flags = lustre_msg_get_op_flags(request->rq_repmsg); |
| 794 | |
| 795 | ret = req_capsule_get_size(&request->rq_pill, &RMF_CONNECT_DATA, |
| 796 | RCL_SERVER); |
| 797 | /* server replied obd_connect_data is always bigger */ |
| 798 | ocd = req_capsule_server_sized_get(&request->rq_pill, |
| 799 | &RMF_CONNECT_DATA, ret); |
| 800 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 801 | if (!ocd) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 802 | CERROR("%s: no connect data from server\n", |
| 803 | imp->imp_obd->obd_name); |
| 804 | rc = -EPROTO; |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 805 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | spin_lock(&imp->imp_lock); |
| 809 | |
| 810 | /* All imports are pingable */ |
| 811 | imp->imp_pingable = 1; |
| 812 | imp->imp_force_reconnect = 0; |
| 813 | imp->imp_force_verify = 0; |
| 814 | |
| 815 | imp->imp_connect_data = *ocd; |
| 816 | |
| 817 | CDEBUG(D_HA, "%s: connect to target with instance %u\n", |
| 818 | imp->imp_obd->obd_name, ocd->ocd_instance); |
| 819 | exp = class_conn2export(&imp->imp_dlm_handle); |
| 820 | |
| 821 | spin_unlock(&imp->imp_lock); |
| 822 | |
| 823 | /* check that server granted subset of flags we asked for. */ |
| 824 | if ((ocd->ocd_connect_flags & imp->imp_connect_flags_orig) != |
| 825 | ocd->ocd_connect_flags) { |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 826 | CERROR("%s: Server didn't granted asked subset of flags: asked=%#llx grranted=%#llx\n", |
Greg Donald | 1d8cb70 | 2014-08-25 20:07:19 -0500 | [diff] [blame] | 827 | imp->imp_obd->obd_name, imp->imp_connect_flags_orig, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 828 | ocd->ocd_connect_flags); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 829 | rc = -EPROTO; |
| 830 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | if (!exp) { |
| 834 | /* This could happen if export is cleaned during the |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 835 | * connect attempt |
| 836 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 837 | CERROR("%s: missing export after connect\n", |
| 838 | imp->imp_obd->obd_name); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 839 | rc = -ENODEV; |
| 840 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 841 | } |
| 842 | old_connect_flags = exp_connect_flags(exp); |
| 843 | exp->exp_connect_data = *ocd; |
| 844 | imp->imp_obd->obd_self_export->exp_connect_data = *ocd; |
| 845 | class_export_put(exp); |
| 846 | |
| 847 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_OCD); |
| 848 | |
| 849 | if (aa->pcaa_initial_connect) { |
| 850 | spin_lock(&imp->imp_lock); |
| 851 | if (msg_flags & MSG_CONNECT_REPLAYABLE) { |
| 852 | imp->imp_replayable = 1; |
| 853 | spin_unlock(&imp->imp_lock); |
| 854 | CDEBUG(D_HA, "connected to replayable target: %s\n", |
| 855 | obd2cli_tgt(imp->imp_obd)); |
| 856 | } else { |
| 857 | imp->imp_replayable = 0; |
| 858 | spin_unlock(&imp->imp_lock); |
| 859 | } |
| 860 | |
| 861 | /* if applies, adjust the imp->imp_msg_magic here |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 862 | * according to reply flags |
| 863 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 864 | |
| 865 | imp->imp_remote_handle = |
| 866 | *lustre_msg_get_handle(request->rq_repmsg); |
| 867 | |
| 868 | /* Initial connects are allowed for clients with non-random |
| 869 | * uuids when servers are in recovery. Simply signal the |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 870 | * servers replay is complete and wait in REPLAY_WAIT. |
| 871 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 872 | if (msg_flags & MSG_CONNECT_RECOVERING) { |
| 873 | CDEBUG(D_HA, "connect to %s during recovery\n", |
| 874 | obd2cli_tgt(imp->imp_obd)); |
| 875 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS); |
| 876 | } else { |
| 877 | IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL); |
| 878 | ptlrpc_activate_import(imp); |
| 879 | } |
| 880 | |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 881 | rc = 0; |
| 882 | goto finish; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /* Determine what recovery state to move the import to. */ |
Julia Lawall | 2b241d3 | 2015-08-29 19:30:12 +0200 | [diff] [blame] | 886 | if (msg_flags & MSG_CONNECT_RECONNECT) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 887 | memset(&old_hdl, 0, sizeof(old_hdl)); |
| 888 | if (!memcmp(&old_hdl, lustre_msg_get_handle(request->rq_repmsg), |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 889 | sizeof(old_hdl))) { |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 890 | LCONSOLE_WARN("Reconnect to %s (at @%s) failed due bad handle %#llx\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 891 | obd2cli_tgt(imp->imp_obd), |
| 892 | imp->imp_connection->c_remote_uuid.uuid, |
| 893 | imp->imp_dlm_handle.cookie); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 894 | rc = -ENOTCONN; |
| 895 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | if (memcmp(&imp->imp_remote_handle, |
| 899 | lustre_msg_get_handle(request->rq_repmsg), |
| 900 | sizeof(imp->imp_remote_handle))) { |
| 901 | int level = msg_flags & MSG_CONNECT_RECOVERING ? |
| 902 | D_HA : D_WARNING; |
| 903 | |
| 904 | /* Bug 16611/14775: if server handle have changed, |
| 905 | * that means some sort of disconnection happened. |
| 906 | * If the server is not in recovery, that also means it |
| 907 | * already erased all of our state because of previous |
| 908 | * eviction. If it is in recovery - we are safe to |
| 909 | * participate since we can reestablish all of our state |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 910 | * with server again |
| 911 | */ |
Julia Lawall | 2b241d3 | 2015-08-29 19:30:12 +0200 | [diff] [blame] | 912 | if ((msg_flags & MSG_CONNECT_RECOVERING)) { |
Hema Prathaban | b533ff4 | 2014-08-31 16:30:56 +0530 | [diff] [blame] | 913 | CDEBUG(level, "%s@%s changed server handle from %#llx to %#llx but is still in recovery\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 914 | obd2cli_tgt(imp->imp_obd), |
| 915 | imp->imp_connection->c_remote_uuid.uuid, |
| 916 | imp->imp_remote_handle.cookie, |
| 917 | lustre_msg_get_handle( |
| 918 | request->rq_repmsg)->cookie); |
| 919 | } else { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 920 | LCONSOLE_WARN("Evicted from %s (at %s) after server handle changed from %#llx to %#llx\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 921 | obd2cli_tgt(imp->imp_obd), |
| 922 | imp->imp_connection-> \ |
| 923 | c_remote_uuid.uuid, |
| 924 | imp->imp_remote_handle.cookie, |
| 925 | lustre_msg_get_handle( |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 926 | request->rq_repmsg)->cookie); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 927 | } |
| 928 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 929 | imp->imp_remote_handle = |
| 930 | *lustre_msg_get_handle(request->rq_repmsg); |
| 931 | |
Julia Lawall | 2b241d3 | 2015-08-29 19:30:12 +0200 | [diff] [blame] | 932 | if (!(msg_flags & MSG_CONNECT_RECOVERING)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 933 | IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 934 | rc = 0; |
| 935 | goto finish; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | } else { |
| 939 | CDEBUG(D_HA, "reconnected to %s@%s after partition\n", |
| 940 | obd2cli_tgt(imp->imp_obd), |
| 941 | imp->imp_connection->c_remote_uuid.uuid); |
| 942 | } |
| 943 | |
| 944 | if (imp->imp_invalid) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 945 | CDEBUG(D_HA, "%s: reconnected but import is invalid; marking evicted\n", |
| 946 | imp->imp_obd->obd_name); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 947 | IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); |
Julia Lawall | 2b241d3 | 2015-08-29 19:30:12 +0200 | [diff] [blame] | 948 | } else if (msg_flags & MSG_CONNECT_RECOVERING) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 949 | CDEBUG(D_HA, "%s: reconnected to %s during replay\n", |
| 950 | imp->imp_obd->obd_name, |
| 951 | obd2cli_tgt(imp->imp_obd)); |
| 952 | |
| 953 | spin_lock(&imp->imp_lock); |
| 954 | imp->imp_resend_replay = 1; |
| 955 | spin_unlock(&imp->imp_lock); |
| 956 | |
Andriy Skulysh | 502cb58 | 2015-03-25 22:07:07 -0400 | [diff] [blame] | 957 | IMPORT_SET_STATE(imp, imp->imp_replay_state); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 958 | } else { |
| 959 | IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER); |
| 960 | } |
Julia Lawall | 2b241d3 | 2015-08-29 19:30:12 +0200 | [diff] [blame] | 961 | } else if ((msg_flags & MSG_CONNECT_RECOVERING) && !imp->imp_invalid) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 962 | LASSERT(imp->imp_replayable); |
| 963 | imp->imp_remote_handle = |
| 964 | *lustre_msg_get_handle(request->rq_repmsg); |
| 965 | imp->imp_last_replay_transno = 0; |
| 966 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY); |
| 967 | } else { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 968 | DEBUG_REQ(D_HA, request, "%s: evicting (reconnect/recover flags not set: %x)", |
| 969 | imp->imp_obd->obd_name, msg_flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 970 | imp->imp_remote_handle = |
| 971 | *lustre_msg_get_handle(request->rq_repmsg); |
| 972 | IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); |
| 973 | } |
| 974 | |
| 975 | /* Sanity checks for a reconnected import. */ |
| 976 | if (!(imp->imp_replayable) != !(msg_flags & MSG_CONNECT_REPLAYABLE)) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 977 | CERROR("imp_replayable flag does not match server after reconnect. We should LBUG right here.\n"); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | if (lustre_msg_get_last_committed(request->rq_repmsg) > 0 && |
| 981 | lustre_msg_get_last_committed(request->rq_repmsg) < |
| 982 | aa->pcaa_peer_committed) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 983 | CERROR("%s went back in time (transno %lld was previously committed, server now claims %lld)! See https://bugzilla.lustre.org/show_bug.cgi?id=9646\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 984 | obd2cli_tgt(imp->imp_obd), aa->pcaa_peer_committed, |
| 985 | lustre_msg_get_last_committed(request->rq_repmsg)); |
| 986 | } |
| 987 | |
| 988 | finish: |
| 989 | rc = ptlrpc_import_recovery_state_machine(imp); |
| 990 | if (rc != 0) { |
| 991 | if (rc == -ENOTCONN) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 992 | CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery; invalidating and reconnecting\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 993 | obd2cli_tgt(imp->imp_obd), |
| 994 | imp->imp_connection->c_remote_uuid.uuid); |
| 995 | ptlrpc_connect_import(imp); |
| 996 | imp->imp_connect_tried = 1; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 997 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 998 | } |
| 999 | } else { |
Andreas Dilger | 35e4581 | 2016-04-27 18:21:07 -0400 | [diff] [blame] | 1000 | static bool warned; |
| 1001 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1002 | spin_lock(&imp->imp_lock); |
| 1003 | list_del(&imp->imp_conn_current->oic_item); |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 1004 | list_add(&imp->imp_conn_current->oic_item, &imp->imp_conn_list); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1005 | imp->imp_last_success_conn = |
| 1006 | imp->imp_conn_current->oic_last_attempt; |
| 1007 | |
| 1008 | spin_unlock(&imp->imp_lock); |
| 1009 | |
Fan Yong | f261f48 | 2014-08-15 12:48:09 -0400 | [diff] [blame] | 1010 | if ((imp->imp_connect_flags_orig & OBD_CONNECT_IBITS) && |
| 1011 | !(ocd->ocd_connect_flags & OBD_CONNECT_IBITS)) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1012 | LCONSOLE_WARN("%s: MDS %s does not support ibits lock, either very old or invalid: requested %llx, replied %llx\n", |
Fan Yong | f261f48 | 2014-08-15 12:48:09 -0400 | [diff] [blame] | 1013 | imp->imp_obd->obd_name, |
| 1014 | imp->imp_connection->c_remote_uuid.uuid, |
| 1015 | imp->imp_connect_flags_orig, |
| 1016 | ocd->ocd_connect_flags); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1017 | rc = -EPROTO; |
| 1018 | goto out; |
Fan Yong | f261f48 | 2014-08-15 12:48:09 -0400 | [diff] [blame] | 1019 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1020 | |
Andreas Dilger | 35e4581 | 2016-04-27 18:21:07 -0400 | [diff] [blame] | 1021 | if (!warned && (ocd->ocd_connect_flags & OBD_CONNECT_VERSION) && |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1022 | (ocd->ocd_version > LUSTRE_VERSION_CODE + |
| 1023 | LUSTRE_VERSION_OFFSET_WARN || |
| 1024 | ocd->ocd_version < LUSTRE_VERSION_CODE - |
| 1025 | LUSTRE_VERSION_OFFSET_WARN)) { |
| 1026 | /* Sigh, some compilers do not like #ifdef in the middle |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1027 | * of macro arguments |
| 1028 | */ |
Andreas Dilger | 35e4581 | 2016-04-27 18:21:07 -0400 | [diff] [blame] | 1029 | const char *older = "older than client. Consider upgrading server"; |
| 1030 | const char *newer = "newer than client. Consider recompiling application"; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1031 | |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1032 | LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) is much %s (%s)\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1033 | obd2cli_tgt(imp->imp_obd), |
| 1034 | OBD_OCD_VERSION_MAJOR(ocd->ocd_version), |
| 1035 | OBD_OCD_VERSION_MINOR(ocd->ocd_version), |
| 1036 | OBD_OCD_VERSION_PATCH(ocd->ocd_version), |
| 1037 | OBD_OCD_VERSION_FIX(ocd->ocd_version), |
| 1038 | ocd->ocd_version > LUSTRE_VERSION_CODE ? |
| 1039 | newer : older, LUSTRE_VERSION_STRING); |
Andreas Dilger | 35e4581 | 2016-04-27 18:21:07 -0400 | [diff] [blame] | 1040 | warned = true; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0) |
| 1044 | /* Check if server has LU-1252 fix applied to not always swab |
| 1045 | * the IR MNE entries. Do this only once per connection. This |
| 1046 | * fixup is version-limited, because we don't want to carry the |
| 1047 | * OBD_CONNECT_MNE_SWAB flag around forever, just so long as we |
| 1048 | * need interop with unpatched 2.2 servers. For newer servers, |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1049 | * the client will do MNE swabbing only as needed. LU-1644 |
| 1050 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1051 | if (unlikely((ocd->ocd_connect_flags & OBD_CONNECT_VERSION) && |
| 1052 | !(ocd->ocd_connect_flags & OBD_CONNECT_MNE_SWAB) && |
| 1053 | OBD_OCD_VERSION_MAJOR(ocd->ocd_version) == 2 && |
| 1054 | OBD_OCD_VERSION_MINOR(ocd->ocd_version) == 2 && |
| 1055 | OBD_OCD_VERSION_PATCH(ocd->ocd_version) < 55 && |
| 1056 | strcmp(imp->imp_obd->obd_type->typ_name, |
| 1057 | LUSTRE_MGC_NAME) == 0)) |
| 1058 | imp->imp_need_mne_swab = 1; |
| 1059 | else /* clear if server was upgraded since last connect */ |
| 1060 | imp->imp_need_mne_swab = 0; |
| 1061 | #else |
| 1062 | #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab" |
| 1063 | #endif |
| 1064 | |
| 1065 | if (ocd->ocd_connect_flags & OBD_CONNECT_CKSUM) { |
| 1066 | /* We sent to the server ocd_cksum_types with bits set |
| 1067 | * for algorithms we understand. The server masked off |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1068 | * the checksum types it doesn't support |
| 1069 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1070 | if ((ocd->ocd_cksum_types & |
| 1071 | cksum_types_supported_client()) == 0) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1072 | LCONSOLE_WARN("The negotiation of the checksum algorithm to use with server %s failed (%x/%x), disabling checksums\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1073 | obd2cli_tgt(imp->imp_obd), |
| 1074 | ocd->ocd_cksum_types, |
| 1075 | cksum_types_supported_client()); |
| 1076 | cli->cl_checksum = 0; |
| 1077 | cli->cl_supp_cksum_types = OBD_CKSUM_ADLER; |
| 1078 | } else { |
| 1079 | cli->cl_supp_cksum_types = ocd->ocd_cksum_types; |
| 1080 | } |
| 1081 | } else { |
| 1082 | /* The server does not support OBD_CONNECT_CKSUM. |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1083 | * Enforce ADLER for backward compatibility |
| 1084 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1085 | cli->cl_supp_cksum_types = OBD_CKSUM_ADLER; |
| 1086 | } |
Hema Prathaban | b533ff4 | 2014-08-31 16:30:56 +0530 | [diff] [blame] | 1087 | cli->cl_cksum_type = cksum_type_select(cli->cl_supp_cksum_types); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1088 | |
| 1089 | if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) |
| 1090 | cli->cl_max_pages_per_rpc = |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1091 | min(ocd->ocd_brw_size >> PAGE_SHIFT, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1092 | cli->cl_max_pages_per_rpc); |
| 1093 | else if (imp->imp_connect_op == MDS_CONNECT || |
| 1094 | imp->imp_connect_op == MGS_CONNECT) |
| 1095 | cli->cl_max_pages_per_rpc = 1; |
| 1096 | |
| 1097 | /* Reset ns_connect_flags only for initial connect. It might be |
| 1098 | * changed in while using FS and if we reset it in reconnect |
| 1099 | * this leads to losing user settings done before such as |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1100 | * disable lru_resize, etc. |
| 1101 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1102 | if (old_connect_flags != exp_connect_flags(exp) || |
| 1103 | aa->pcaa_initial_connect) { |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 1104 | CDEBUG(D_HA, "%s: Resetting ns_connect_flags to server flags: %#llx\n", |
| 1105 | imp->imp_obd->obd_name, ocd->ocd_connect_flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1106 | imp->imp_obd->obd_namespace->ns_connect_flags = |
| 1107 | ocd->ocd_connect_flags; |
| 1108 | imp->imp_obd->obd_namespace->ns_orig_connect_flags = |
| 1109 | ocd->ocd_connect_flags; |
| 1110 | } |
| 1111 | |
| 1112 | if ((ocd->ocd_connect_flags & OBD_CONNECT_AT) && |
| 1113 | (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V2)) |
| 1114 | /* We need a per-message support flag, because |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1115 | * a. we don't know if the incoming connect reply |
| 1116 | * supports AT or not (in reply_in_callback) |
| 1117 | * until we unpack it. |
| 1118 | * b. failovered server means export and flags are gone |
| 1119 | * (in ptlrpc_send_reply). |
| 1120 | * Can only be set when we know AT is supported at |
| 1121 | * both ends |
| 1122 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1123 | imp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT; |
| 1124 | else |
| 1125 | imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT; |
| 1126 | |
| 1127 | if ((ocd->ocd_connect_flags & OBD_CONNECT_FULL20) && |
| 1128 | (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V2)) |
| 1129 | imp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18; |
| 1130 | else |
| 1131 | imp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18; |
| 1132 | |
| 1133 | LASSERT((cli->cl_max_pages_per_rpc <= PTLRPC_MAX_BRW_PAGES) && |
| 1134 | (cli->cl_max_pages_per_rpc > 0)); |
| 1135 | } |
| 1136 | |
| 1137 | out: |
| 1138 | imp->imp_connect_tried = 1; |
| 1139 | |
| 1140 | if (rc != 0) { |
| 1141 | IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON); |
| 1142 | if (rc == -EACCES) { |
| 1143 | /* |
| 1144 | * Give up trying to reconnect |
| 1145 | * EACCES means client has no permission for connection |
| 1146 | */ |
| 1147 | imp->imp_obd->obd_no_recov = 1; |
| 1148 | ptlrpc_deactivate_import(imp); |
| 1149 | } |
| 1150 | |
| 1151 | if (rc == -EPROTO) { |
| 1152 | struct obd_connect_data *ocd; |
| 1153 | |
| 1154 | /* reply message might not be ready */ |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 1155 | if (!request->rq_repmsg) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1156 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1157 | |
| 1158 | ocd = req_capsule_server_get(&request->rq_pill, |
| 1159 | &RMF_CONNECT_DATA); |
| 1160 | if (ocd && |
| 1161 | (ocd->ocd_connect_flags & OBD_CONNECT_VERSION) && |
| 1162 | (ocd->ocd_version != LUSTRE_VERSION_CODE)) { |
Kristina Martsenko | 532118c | 2013-11-11 21:35:03 +0200 | [diff] [blame] | 1163 | /* |
| 1164 | * Actually servers are only supposed to refuse |
| 1165 | * connection from liblustre clients, so we |
| 1166 | * should never see this from VFS context |
| 1167 | */ |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1168 | LCONSOLE_ERROR_MSG(0x16a, "Server %s version (%d.%d.%d.%d) refused connection from this client with an incompatible version (%s). Client must be recompiled\n", |
| 1169 | obd2cli_tgt(imp->imp_obd), |
| 1170 | OBD_OCD_VERSION_MAJOR(ocd->ocd_version), |
| 1171 | OBD_OCD_VERSION_MINOR(ocd->ocd_version), |
| 1172 | OBD_OCD_VERSION_PATCH(ocd->ocd_version), |
| 1173 | OBD_OCD_VERSION_FIX(ocd->ocd_version), |
| 1174 | LUSTRE_VERSION_STRING); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1175 | ptlrpc_deactivate_import(imp); |
| 1176 | IMPORT_SET_STATE(imp, LUSTRE_IMP_CLOSED); |
| 1177 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1178 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | ptlrpc_maybe_ping_import_soon(imp); |
| 1182 | |
| 1183 | CDEBUG(D_HA, "recovery of %s on %s failed (%d)\n", |
| 1184 | obd2cli_tgt(imp->imp_obd), |
| 1185 | (char *)imp->imp_connection->c_remote_uuid.uuid, rc); |
| 1186 | } |
| 1187 | |
| 1188 | wake_up_all(&imp->imp_recovery_waitq); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1189 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * interpret callback for "completed replay" RPCs. |
| 1194 | * \see signal_completed_replay |
| 1195 | */ |
| 1196 | static int completed_replay_interpret(const struct lu_env *env, |
| 1197 | struct ptlrpc_request *req, |
Greg Donald | aff9d8e | 2014-08-21 11:07:42 -0500 | [diff] [blame] | 1198 | void *data, int rc) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1199 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1200 | atomic_dec(&req->rq_import->imp_replay_inflight); |
| 1201 | if (req->rq_status == 0 && |
| 1202 | !req->rq_import->imp_vbr_failed) { |
| 1203 | ptlrpc_import_recovery_state_machine(req->rq_import); |
| 1204 | } else { |
| 1205 | if (req->rq_import->imp_vbr_failed) { |
| 1206 | CDEBUG(D_WARNING, |
| 1207 | "%s: version recovery fails, reconnecting\n", |
| 1208 | req->rq_import->imp_obd->obd_name); |
| 1209 | } else { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1210 | CDEBUG(D_HA, "%s: LAST_REPLAY message error: %d, reconnecting\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1211 | req->rq_import->imp_obd->obd_name, |
| 1212 | req->rq_status); |
| 1213 | } |
| 1214 | ptlrpc_connect_import(req->rq_import); |
| 1215 | } |
| 1216 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1217 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | /** |
| 1221 | * Let server know that we have no requests to replay anymore. |
| 1222 | * Achieved by just sending a PING request |
| 1223 | */ |
| 1224 | static int signal_completed_replay(struct obd_import *imp) |
| 1225 | { |
| 1226 | struct ptlrpc_request *req; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1227 | |
| 1228 | if (unlikely(OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_FINISH_REPLAY))) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1229 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1230 | |
| 1231 | LASSERT(atomic_read(&imp->imp_replay_inflight) == 0); |
| 1232 | atomic_inc(&imp->imp_replay_inflight); |
| 1233 | |
| 1234 | req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING, LUSTRE_OBD_VERSION, |
| 1235 | OBD_PING); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 1236 | if (!req) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1237 | atomic_dec(&imp->imp_replay_inflight); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1238 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | ptlrpc_request_set_replen(req); |
| 1242 | req->rq_send_state = LUSTRE_IMP_REPLAY_WAIT; |
| 1243 | lustre_msg_add_flags(req->rq_reqmsg, |
| 1244 | MSG_LOCK_REPLAY_DONE | MSG_REQ_REPLAY_DONE); |
| 1245 | if (AT_OFF) |
| 1246 | req->rq_timeout *= 3; |
| 1247 | req->rq_interpret_reply = completed_replay_interpret; |
| 1248 | |
Olaf Weber | c5c4c6f | 2015-09-14 18:41:35 -0400 | [diff] [blame] | 1249 | ptlrpcd_add_req(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1250 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * In kernel code all import invalidation happens in its own |
| 1255 | * separate thread, so that whatever application happened to encounter |
| 1256 | * a problem could still be killed or otherwise continue |
| 1257 | */ |
| 1258 | static int ptlrpc_invalidate_import_thread(void *data) |
| 1259 | { |
| 1260 | struct obd_import *imp = data; |
| 1261 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1262 | unshare_fs_struct(); |
| 1263 | |
| 1264 | CDEBUG(D_HA, "thread invalidate import %s to %s@%s\n", |
| 1265 | imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), |
| 1266 | imp->imp_connection->c_remote_uuid.uuid); |
| 1267 | |
| 1268 | ptlrpc_invalidate_import(imp); |
| 1269 | |
| 1270 | if (obd_dump_on_eviction) { |
| 1271 | CERROR("dump the log upon eviction\n"); |
| 1272 | libcfs_debug_dumplog(); |
| 1273 | } |
| 1274 | |
| 1275 | IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER); |
| 1276 | ptlrpc_import_recovery_state_machine(imp); |
| 1277 | |
| 1278 | class_import_put(imp); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1279 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | /** |
| 1283 | * This is the state machine for client-side recovery on import. |
| 1284 | * |
Masanari Iida | b6da17f | 2014-02-08 00:30:40 +0900 | [diff] [blame] | 1285 | * Typically we have two possibly paths. If we came to server and it is not |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1286 | * in recovery, we just enter IMP_EVICTED state, invalidate our import |
| 1287 | * state and reconnect from scratch. |
| 1288 | * If we came to server that is in recovery, we enter IMP_REPLAY import state. |
| 1289 | * We go through our list of requests to replay and send them to server one by |
| 1290 | * one. |
| 1291 | * After sending all request from the list we change import state to |
| 1292 | * IMP_REPLAY_LOCKS and re-request all the locks we believe we have from server |
| 1293 | * and also all the locks we don't yet have and wait for server to grant us. |
| 1294 | * After that we send a special "replay completed" request and change import |
| 1295 | * state to IMP_REPLAY_WAIT. |
| 1296 | * Upon receiving reply to that "replay completed" RPC we enter IMP_RECOVER |
| 1297 | * state and resend all requests from sending list. |
| 1298 | * After that we promote import to FULL state and send all delayed requests |
| 1299 | * and import is fully operational after that. |
| 1300 | * |
| 1301 | */ |
| 1302 | int ptlrpc_import_recovery_state_machine(struct obd_import *imp) |
| 1303 | { |
| 1304 | int rc = 0; |
| 1305 | int inflight; |
| 1306 | char *target_start; |
| 1307 | int target_len; |
| 1308 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1309 | if (imp->imp_state == LUSTRE_IMP_EVICTED) { |
| 1310 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, |
| 1311 | &target_start, &target_len); |
| 1312 | /* Don't care about MGC eviction */ |
| 1313 | if (strcmp(imp->imp_obd->obd_type->typ_name, |
| 1314 | LUSTRE_MGC_NAME) != 0) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1315 | LCONSOLE_ERROR_MSG(0x167, "%s: This client was evicted by %.*s; in progress operations using this service will fail.\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1316 | imp->imp_obd->obd_name, target_len, |
| 1317 | target_start); |
| 1318 | } |
| 1319 | CDEBUG(D_HA, "evicted from %s@%s; invalidating\n", |
| 1320 | obd2cli_tgt(imp->imp_obd), |
| 1321 | imp->imp_connection->c_remote_uuid.uuid); |
| 1322 | /* reset vbr_failed flag upon eviction */ |
| 1323 | spin_lock(&imp->imp_lock); |
| 1324 | imp->imp_vbr_failed = 0; |
| 1325 | spin_unlock(&imp->imp_lock); |
| 1326 | |
| 1327 | { |
Greg Kroah-Hartman | 68b636b | 2013-08-04 08:56:42 +0800 | [diff] [blame] | 1328 | struct task_struct *task; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1329 | /* bug 17802: XXX client_disconnect_export vs connect request |
Frank Zago | 9c37966 | 2016-03-02 17:02:02 -0500 | [diff] [blame] | 1330 | * race. if client is evicted at this time, we start |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1331 | * invalidate thread without reference to import and import can |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1332 | * be freed at same time. |
| 1333 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1334 | class_import_get(imp); |
| 1335 | task = kthread_run(ptlrpc_invalidate_import_thread, imp, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 1336 | "ll_imp_inval"); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1337 | if (IS_ERR(task)) { |
| 1338 | class_import_put(imp); |
| 1339 | CERROR("error starting invalidate thread: %d\n", rc); |
| 1340 | rc = PTR_ERR(task); |
| 1341 | } else { |
| 1342 | rc = 0; |
| 1343 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1344 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (imp->imp_state == LUSTRE_IMP_REPLAY) { |
| 1349 | CDEBUG(D_HA, "replay requested by %s\n", |
| 1350 | obd2cli_tgt(imp->imp_obd)); |
| 1351 | rc = ptlrpc_replay_next(imp, &inflight); |
| 1352 | if (inflight == 0 && |
| 1353 | atomic_read(&imp->imp_replay_inflight) == 0) { |
| 1354 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS); |
| 1355 | rc = ldlm_replay_locks(imp); |
| 1356 | if (rc) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1357 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1358 | } |
| 1359 | rc = 0; |
| 1360 | } |
| 1361 | |
| 1362 | if (imp->imp_state == LUSTRE_IMP_REPLAY_LOCKS) { |
| 1363 | if (atomic_read(&imp->imp_replay_inflight) == 0) { |
| 1364 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_WAIT); |
| 1365 | rc = signal_completed_replay(imp); |
| 1366 | if (rc) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1367 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1368 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | if (imp->imp_state == LUSTRE_IMP_REPLAY_WAIT) { |
| 1372 | if (atomic_read(&imp->imp_replay_inflight) == 0) { |
| 1373 | IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER); |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | if (imp->imp_state == LUSTRE_IMP_RECOVER) { |
| 1378 | CDEBUG(D_HA, "reconnected to %s@%s\n", |
| 1379 | obd2cli_tgt(imp->imp_obd), |
| 1380 | imp->imp_connection->c_remote_uuid.uuid); |
| 1381 | |
| 1382 | rc = ptlrpc_resend(imp); |
| 1383 | if (rc) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1384 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1385 | IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL); |
| 1386 | ptlrpc_activate_import(imp); |
| 1387 | |
| 1388 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, |
| 1389 | &target_start, &target_len); |
| 1390 | LCONSOLE_INFO("%s: Connection restored to %.*s (at %s)\n", |
| 1391 | imp->imp_obd->obd_name, |
| 1392 | target_len, target_start, |
| 1393 | libcfs_nid2str(imp->imp_connection->c_peer.nid)); |
| 1394 | } |
| 1395 | |
| 1396 | if (imp->imp_state == LUSTRE_IMP_FULL) { |
| 1397 | wake_up_all(&imp->imp_recovery_waitq); |
| 1398 | ptlrpc_wake_delayed(imp); |
| 1399 | } |
| 1400 | |
| 1401 | out: |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1402 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) |
| 1406 | { |
| 1407 | struct ptlrpc_request *req; |
| 1408 | int rq_opc, rc = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1409 | |
Andreas Dilger | 88291a7 | 2014-04-27 13:06:33 -0400 | [diff] [blame] | 1410 | if (imp->imp_obd->obd_force) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1411 | goto set_state; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1412 | |
| 1413 | switch (imp->imp_connect_op) { |
Andreas Dilger | 88291a7 | 2014-04-27 13:06:33 -0400 | [diff] [blame] | 1414 | case OST_CONNECT: |
| 1415 | rq_opc = OST_DISCONNECT; |
| 1416 | break; |
| 1417 | case MDS_CONNECT: |
| 1418 | rq_opc = MDS_DISCONNECT; |
| 1419 | break; |
| 1420 | case MGS_CONNECT: |
| 1421 | rq_opc = MGS_DISCONNECT; |
| 1422 | break; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1423 | default: |
Andreas Dilger | 88291a7 | 2014-04-27 13:06:33 -0400 | [diff] [blame] | 1424 | rc = -EINVAL; |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1425 | CERROR("%s: don't know how to disconnect from %s (connect_op %d): rc = %d\n", |
Andreas Dilger | 88291a7 | 2014-04-27 13:06:33 -0400 | [diff] [blame] | 1426 | imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), |
| 1427 | imp->imp_connect_op, rc); |
| 1428 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | if (ptlrpc_import_in_recovery(imp)) { |
| 1432 | struct l_wait_info lwi; |
Greg Kroah-Hartman | b2d201b | 2014-07-12 00:45:51 -0700 | [diff] [blame] | 1433 | long timeout; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1434 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1435 | if (AT_OFF) { |
| 1436 | if (imp->imp_server_timeout) |
| 1437 | timeout = cfs_time_seconds(obd_timeout / 2); |
| 1438 | else |
| 1439 | timeout = cfs_time_seconds(obd_timeout); |
| 1440 | } else { |
| 1441 | int idx = import_at_get_index(imp, |
| 1442 | imp->imp_client->cli_request_portal); |
| 1443 | timeout = cfs_time_seconds( |
| 1444 | at_get(&imp->imp_at.iat_service_estimate[idx])); |
| 1445 | } |
| 1446 | |
| 1447 | lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), |
| 1448 | back_to_sleep, LWI_ON_SIGNAL_NOOP, NULL); |
| 1449 | rc = l_wait_event(imp->imp_recovery_waitq, |
| 1450 | !ptlrpc_import_in_recovery(imp), &lwi); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | spin_lock(&imp->imp_lock); |
| 1454 | if (imp->imp_state != LUSTRE_IMP_FULL) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1455 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1456 | spin_unlock(&imp->imp_lock); |
| 1457 | |
| 1458 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_DISCONNECT, |
| 1459 | LUSTRE_OBD_VERSION, rq_opc); |
| 1460 | if (req) { |
| 1461 | /* We are disconnecting, do not retry a failed DISCONNECT rpc if |
| 1462 | * it fails. We can get through the above with a down server |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1463 | * if the client doesn't know the server is gone yet. |
| 1464 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1465 | req->rq_no_resend = 1; |
| 1466 | |
| 1467 | /* We want client umounts to happen quickly, no matter the |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1468 | * server state... |
| 1469 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1470 | req->rq_timeout = min_t(int, req->rq_timeout, |
| 1471 | INITIAL_CONNECT_TIMEOUT); |
| 1472 | |
| 1473 | IMPORT_SET_STATE(imp, LUSTRE_IMP_CONNECTING); |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 1474 | req->rq_send_state = LUSTRE_IMP_CONNECTING; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1475 | ptlrpc_request_set_replen(req); |
| 1476 | rc = ptlrpc_queue_wait(req); |
| 1477 | ptlrpc_req_finished(req); |
| 1478 | } |
| 1479 | |
| 1480 | set_state: |
| 1481 | spin_lock(&imp->imp_lock); |
| 1482 | out: |
| 1483 | if (noclose) |
| 1484 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON); |
| 1485 | else |
| 1486 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED); |
| 1487 | memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle)); |
| 1488 | spin_unlock(&imp->imp_lock); |
| 1489 | |
Andreas Dilger | 88291a7 | 2014-04-27 13:06:33 -0400 | [diff] [blame] | 1490 | if (rc == -ETIMEDOUT || rc == -ENOTCONN || rc == -ESHUTDOWN) |
| 1491 | rc = 0; |
| 1492 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1493 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1494 | } |
| 1495 | EXPORT_SYMBOL(ptlrpc_disconnect_import); |
| 1496 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1497 | /* Adaptive Timeout utils */ |
| 1498 | extern unsigned int at_min, at_max, at_history; |
| 1499 | |
| 1500 | /* Bin into timeslices using AT_BINS bins. |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1501 | * This gives us a max of the last binlimit*AT_BINS secs without the storage, |
| 1502 | * but still smoothing out a return to normalcy from a slow response. |
| 1503 | * (E.g. remember the maximum latency in each minute of the last 4 minutes.) |
| 1504 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1505 | int at_measured(struct adaptive_timeout *at, unsigned int val) |
| 1506 | { |
| 1507 | unsigned int old = at->at_current; |
Arnd Bergmann | 0ac0478 | 2015-09-27 16:45:19 -0400 | [diff] [blame] | 1508 | time64_t now = ktime_get_real_seconds(); |
| 1509 | long binlimit = max_t(long, at_history / AT_BINS, 1); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1510 | |
| 1511 | LASSERT(at); |
| 1512 | CDEBUG(D_OTHER, "add %u to %p time=%lu v=%u (%u %u %u %u)\n", |
Arnd Bergmann | 0ac0478 | 2015-09-27 16:45:19 -0400 | [diff] [blame] | 1513 | val, at, (long)(now - at->at_binstart), at->at_current, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1514 | at->at_hist[0], at->at_hist[1], at->at_hist[2], at->at_hist[3]); |
| 1515 | |
| 1516 | if (val == 0) |
| 1517 | /* 0's don't count, because we never want our timeout to |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1518 | * drop to 0, and because 0 could mean an error |
| 1519 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1520 | return 0; |
| 1521 | |
| 1522 | spin_lock(&at->at_lock); |
| 1523 | |
| 1524 | if (unlikely(at->at_binstart == 0)) { |
| 1525 | /* Special case to remove default from history */ |
| 1526 | at->at_current = val; |
| 1527 | at->at_worst_ever = val; |
| 1528 | at->at_worst_time = now; |
| 1529 | at->at_hist[0] = val; |
| 1530 | at->at_binstart = now; |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 1531 | } else if (now - at->at_binstart < binlimit) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1532 | /* in bin 0 */ |
| 1533 | at->at_hist[0] = max(val, at->at_hist[0]); |
| 1534 | at->at_current = max(val, at->at_current); |
| 1535 | } else { |
| 1536 | int i, shift; |
| 1537 | unsigned int maxv = val; |
| 1538 | /* move bins over */ |
Arnd Bergmann | 0ac0478 | 2015-09-27 16:45:19 -0400 | [diff] [blame] | 1539 | shift = (u32)(now - at->at_binstart) / binlimit; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1540 | LASSERT(shift > 0); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 1541 | for (i = AT_BINS - 1; i >= 0; i--) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1542 | if (i >= shift) { |
| 1543 | at->at_hist[i] = at->at_hist[i - shift]; |
| 1544 | maxv = max(maxv, at->at_hist[i]); |
| 1545 | } else { |
| 1546 | at->at_hist[i] = 0; |
| 1547 | } |
| 1548 | } |
| 1549 | at->at_hist[0] = val; |
| 1550 | at->at_current = maxv; |
| 1551 | at->at_binstart += shift * binlimit; |
| 1552 | } |
| 1553 | |
| 1554 | if (at->at_current > at->at_worst_ever) { |
| 1555 | at->at_worst_ever = at->at_current; |
| 1556 | at->at_worst_time = now; |
| 1557 | } |
| 1558 | |
| 1559 | if (at->at_flags & AT_FLG_NOHIST) |
| 1560 | /* Only keep last reported val; keeping the rest of the history |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 1561 | * for debugfs only |
| 1562 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1563 | at->at_current = val; |
| 1564 | |
| 1565 | if (at_max > 0) |
| 1566 | at->at_current = min(at->at_current, at_max); |
| 1567 | at->at_current = max(at->at_current, at_min); |
| 1568 | |
| 1569 | if (at->at_current != old) |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1570 | CDEBUG(D_OTHER, "AT %p change: old=%u new=%u delta=%d (val=%u) hist %u %u %u %u\n", |
| 1571 | at, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1572 | old, at->at_current, at->at_current - old, val, |
| 1573 | at->at_hist[0], at->at_hist[1], at->at_hist[2], |
| 1574 | at->at_hist[3]); |
| 1575 | |
| 1576 | /* if we changed, report the old value */ |
| 1577 | old = (at->at_current != old) ? old : 0; |
| 1578 | |
| 1579 | spin_unlock(&at->at_lock); |
| 1580 | return old; |
| 1581 | } |
| 1582 | |
| 1583 | /* Find the imp_at index for a given portal; assign if space available */ |
| 1584 | int import_at_get_index(struct obd_import *imp, int portal) |
| 1585 | { |
| 1586 | struct imp_at *at = &imp->imp_at; |
| 1587 | int i; |
| 1588 | |
| 1589 | for (i = 0; i < IMP_AT_MAX_PORTALS; i++) { |
| 1590 | if (at->iat_portal[i] == portal) |
| 1591 | return i; |
| 1592 | if (at->iat_portal[i] == 0) |
| 1593 | /* unused */ |
| 1594 | break; |
| 1595 | } |
| 1596 | |
| 1597 | /* Not found in list, add it under a lock */ |
| 1598 | spin_lock(&imp->imp_lock); |
| 1599 | |
| 1600 | /* Check unused under lock */ |
| 1601 | for (; i < IMP_AT_MAX_PORTALS; i++) { |
| 1602 | if (at->iat_portal[i] == portal) |
| 1603 | goto out; |
| 1604 | if (at->iat_portal[i] == 0) |
| 1605 | /* unused */ |
| 1606 | break; |
| 1607 | } |
| 1608 | |
| 1609 | /* Not enough portals? */ |
| 1610 | LASSERT(i < IMP_AT_MAX_PORTALS); |
| 1611 | |
| 1612 | at->iat_portal[i] = portal; |
| 1613 | out: |
| 1614 | spin_unlock(&imp->imp_lock); |
| 1615 | return i; |
| 1616 | } |