1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Mike Shaver <shaver@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_RPC
25 # include <liblustre.h>
28 #include <linux/obd_support.h>
29 #include <linux/lustre_ha.h>
30 #include <linux/lustre_net.h>
31 #include <linux/lustre_import.h>
32 #include <linux/lustre_export.h>
33 #include <linux/obd.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_sec.h>
37 #include "ptlrpc_internal.h"
39 struct ptlrpc_connect_async_args {
40 __u64 pcaa_peer_committed;
41 int pcaa_initial_connect;
44 /* A CLOSED import should remain so. */
45 #define IMPORT_SET_STATE_NOLOCK(imp, state) \
47 if (imp->imp_state != LUSTRE_IMP_CLOSED) { \
48 CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n", \
49 imp, imp->imp_target_uuid.uuid, \
50 ptlrpc_import_state_name(imp->imp_state), \
51 ptlrpc_import_state_name(state)); \
52 imp->imp_state = state; \
56 #define IMPORT_SET_STATE(imp, state) \
58 unsigned long flags; \
60 spin_lock_irqsave(&imp->imp_lock, flags); \
61 IMPORT_SET_STATE_NOLOCK(imp, state); \
62 spin_unlock_irqrestore(&imp->imp_lock, flags); \
66 static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
68 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
70 /* Only this function is allowed to change the import state when it is
71 * CLOSED. I would rather refcount the import and free it after
72 * disconnection like we do with exports. To do that, the client_obd
73 * will need to save the peer info somewhere other than in the import,
75 int ptlrpc_init_import(struct obd_import *imp)
79 spin_lock_irqsave(&imp->imp_lock, flags);
81 imp->imp_generation++;
82 imp->imp_state = LUSTRE_IMP_NEW;
84 spin_unlock_irqrestore(&imp->imp_lock, flags);
89 /* Returns true if import was FULL, false if import was already not
92 int ptlrpc_set_import_discon(struct obd_import *imp)
97 spin_lock_irqsave(&imp->imp_lock, flags);
99 if (imp->imp_state == LUSTRE_IMP_FULL) {
100 CWARN("%s: connection lost to %s@%s\n",
101 imp->imp_obd->obd_name,
102 imp->imp_target_uuid.uuid,
103 imp->imp_connection->c_remote_uuid.uuid);
104 ptlrpc_deactivate_timeouts();
105 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
106 spin_unlock_irqrestore(&imp->imp_lock, flags);
107 obd_import_event(imp->imp_obd, imp, IMP_EVENT_DISCON);
110 spin_unlock_irqrestore(&imp->imp_lock, flags);
111 CDEBUG(D_HA, "%p %s: import already not connected: %s\n",
112 imp,imp->imp_client->cli_name,
113 ptlrpc_import_state_name(imp->imp_state));
120 * This acts as a barrier; all existing requests are rejected, and
121 * no new requests will be accepted until the import is valid again.
123 void ptlrpc_deactivate_import(struct obd_import *imp)
128 spin_lock_irqsave(&imp->imp_lock, flags);
129 CDEBUG(D_HA, "setting import %s INVALID\n",
130 imp->imp_target_uuid.uuid);
131 imp->imp_invalid = 1;
132 imp->imp_generation++;
133 spin_unlock_irqrestore(&imp->imp_lock, flags);
135 ptlrpc_abort_inflight(imp);
136 obd_import_event(imp->imp_obd, imp, IMP_EVENT_INACTIVE);
140 * This function will invalidate the import, if necessary, then block
141 * for all the RPC completions, and finally notify the obd to
142 * invalidate its state (ie cancel locks, clear pending requests,
145 * in_rpc: true if this is called while processing an rpc, like
146 * CONNECT. It will allow for one RPC to be inflight while
147 * waiting for requests to complete. Ugly, yes, but I don't see an
148 * cleaner way right now.
150 void ptlrpc_invalidate_import(struct obd_import *imp, int in_rpc)
152 struct l_wait_info lwi;
153 unsigned long timeout;
157 if (!imp->imp_invalid)
158 ptlrpc_deactivate_import(imp);
160 LASSERT(imp->imp_invalid);
165 /* wait for all requests to error out and call completion
167 if (imp->imp_server_timeout)
168 timeout = obd_timeout / 2;
170 timeout = obd_timeout;
171 timeout = MAX(timeout * HZ, 1);
172 lwi = LWI_TIMEOUT_INTR(timeout, NULL, NULL, NULL);
173 rc = l_wait_event(imp->imp_recovery_waitq,
174 (atomic_read(&imp->imp_inflight) == inflight),
178 CERROR("%s: rc = %d waiting for callback (%d != %d)\n",
179 imp->imp_target_uuid.uuid, rc,
180 atomic_read(&imp->imp_inflight), !!in_rpc);
182 obd_import_event(imp->imp_obd, imp, IMP_EVENT_INVALIDATE);
185 void ptlrpc_activate_import(struct obd_import *imp)
187 struct obd_device *obd = imp->imp_obd;
190 spin_lock_irqsave(&imp->imp_lock, flags);
191 imp->imp_invalid = 0;
192 spin_unlock_irqrestore(&imp->imp_lock, flags);
194 obd_import_event(obd, imp, IMP_EVENT_ACTIVE);
195 ptlrpc_activate_timeouts();
198 void ptlrpc_fail_import(struct obd_import *imp, int generation)
202 LASSERT (!imp->imp_dlm_fake);
204 if (ptlrpc_set_import_discon(imp)) {
207 if (!imp->imp_replayable) {
208 CDEBUG(D_HA, "import %s@%s for %s not replayable, "
209 "auto-deactivating\n",
210 imp->imp_target_uuid.uuid,
211 imp->imp_connection->c_remote_uuid.uuid,
212 imp->imp_obd->obd_name);
213 ptlrpc_deactivate_import(imp);
216 CDEBUG(D_HA, "%s: waking up pinger\n",
217 imp->imp_target_uuid.uuid);
219 spin_lock_irqsave(&imp->imp_lock, flags);
220 imp->imp_force_verify = 1;
221 spin_unlock_irqrestore(&imp->imp_lock, flags);
223 ptlrpc_pinger_wake_up();
228 #define ATTEMPT_TOO_SOON(last) \
229 ((last) && ((long)(jiffies - (last)) <= (long)(obd_timeout * 2 * HZ)))
231 static int import_select_connection(struct obd_import *imp)
233 struct obd_import_conn *imp_conn, *tmp;
234 struct obd_export *dlmexp;
238 spin_lock(&imp->imp_lock);
240 if (list_empty(&imp->imp_conn_list)) {
241 CERROR("no available connections on imp %p@%s\n",
242 imp, imp->imp_obd->obd_name);
243 spin_unlock(&imp->imp_lock);
247 list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
248 if (!ATTEMPT_TOO_SOON(imp_conn->oic_last_attempt)) {
254 /* if not found, simply choose the current one */
256 CWARN("obd %s imp 0x%p: all connections have been "
257 "tried recently\n", imp->imp_obd->obd_name, imp);
258 LASSERT(imp->imp_conn_current);
259 imp_conn = imp->imp_conn_current;
261 LASSERT(imp_conn->oic_conn);
263 imp_conn->oic_last_attempt = jiffies;
265 /* move the items ahead of the selected one to list tail */
267 tmp= list_entry(imp->imp_conn_list.next,
268 struct obd_import_conn, oic_item);
271 list_del(&tmp->oic_item);
272 list_add_tail(&tmp->oic_item, &imp->imp_conn_list);
275 /* switch connection if we chose a new one */
276 if (imp->imp_connection != imp_conn->oic_conn) {
277 if (imp->imp_connection) {
278 ptlrpcs_sec_invalidate_cache(imp->imp_sec);
279 ptlrpc_put_connection(imp->imp_connection);
281 imp->imp_connection =
282 ptlrpc_connection_addref(imp_conn->oic_conn);
285 dlmexp = class_conn2export(&imp->imp_dlm_handle);
286 LASSERT(dlmexp != NULL);
287 if (dlmexp->exp_connection)
288 ptlrpc_put_connection(imp->imp_connection);
289 dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
290 class_export_put(dlmexp);
292 imp->imp_conn_current = imp_conn;
293 CWARN("obd %s imp 0x%p: select conn %s\n",
294 imp->imp_obd->obd_name, imp,
295 imp_conn->oic_uuid.uuid);
296 spin_unlock(&imp->imp_lock);
302 * must be called under imp_lock
304 int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno)
306 struct ptlrpc_request *req;
307 struct list_head *tmp;
309 if (list_empty(&imp->imp_replay_list))
311 tmp = imp->imp_replay_list.next;
312 req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
313 *transno = req->rq_transno;
317 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid)
319 struct obd_device *obd = imp->imp_obd;
320 int initial_connect = 0;
323 __u64 committed_before_reconnect = 0;
324 struct ptlrpc_request *request;
326 sizeof(imp->imp_target_uuid),
327 sizeof(obd->obd_uuid),
328 sizeof(imp->imp_dlm_handle),
329 sizeof(imp->imp_connect_flags),
330 sizeof(imp->imp_connect_data)};
332 (char *)imp->imp_target_uuid.uuid,
333 (char *)obd->obd_uuid.uuid,
334 (char *)&imp->imp_dlm_handle,
335 (char *)&imp->imp_connect_flags, /* XXX: make this portable! */
336 (char*) &imp->imp_connect_data};
337 int repsize = sizeof(struct obd_connect_data);
339 struct ptlrpc_connect_async_args *aa;
342 spin_lock_irqsave(&imp->imp_lock, flags);
343 if (imp->imp_state == LUSTRE_IMP_CLOSED) {
344 spin_unlock_irqrestore(&imp->imp_lock, flags);
345 CERROR("can't connect to a closed import\n");
347 } else if (imp->imp_state == LUSTRE_IMP_FULL) {
348 spin_unlock_irqrestore(&imp->imp_lock, flags);
349 CERROR("already connected\n");
351 } else if (imp->imp_state == LUSTRE_IMP_CONNECTING) {
352 spin_unlock_irqrestore(&imp->imp_lock, flags);
353 CERROR("already connecting\n");
357 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CONNECTING);
359 imp->imp_resend_replay = 0;
361 if (imp->imp_remote_handle.cookie == 0) {
364 committed_before_reconnect = imp->imp_peer_committed_transno;;
368 set_transno = ptlrpc_first_transno(imp, &imp->imp_connect_data.transno);
370 spin_unlock_irqrestore(&imp->imp_lock, flags);
373 struct obd_uuid uuid;
375 obd_str2uuid(&uuid, new_uuid);
377 rc = import_set_conn_priority(imp, &uuid);
381 rc = import_select_connection(imp);
385 LASSERT(imp->imp_sec);
387 size[0] = lustre_secdesc_size();
388 request = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION,
389 imp->imp_connect_op, 6, size, tmp);
391 GOTO(out, rc = -ENOMEM);
393 lustre_pack_secdesc(request, size[0]);
396 lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_LIBCLIENT);
398 if (obd->u.cli.cl_async) {
399 lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_ASYNC);
402 request->rq_send_state = LUSTRE_IMP_CONNECTING;
403 request->rq_replen = lustre_msg_size(1, &repsize);
404 request->rq_interpret_reply = ptlrpc_connect_interpret;
406 LASSERT (sizeof (*aa) <= sizeof (request->rq_async_args));
407 aa = (struct ptlrpc_connect_async_args *)&request->rq_async_args;
408 memset(aa, 0, sizeof *aa);
410 aa->pcaa_peer_committed = committed_before_reconnect;
411 aa->pcaa_initial_connect = initial_connect;
413 if (aa->pcaa_initial_connect) {
414 lustre_msg_add_op_flags(request->rq_reqmsg,
415 MSG_CONNECT_INITIAL);
416 imp->imp_replayable = 1;
419 lustre_msg_add_op_flags(request->rq_reqmsg,
420 MSG_CONNECT_TRANSNO);
422 imp->imp_reqs_replayed = imp->imp_locks_replayed = 0;
424 ptlrpcd_add_req(request);
426 imp->imp_connect_start = jiffies;
429 IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
435 static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
438 struct ptlrpc_connect_async_args *aa = data;
439 struct obd_import *imp = request->rq_import;
440 struct lustre_handle old_hdl;
445 spin_lock_irqsave(&imp->imp_lock, flags);
446 if (imp->imp_state == LUSTRE_IMP_CLOSED) {
447 spin_unlock_irqrestore(&imp->imp_lock, flags);
450 spin_unlock_irqrestore(&imp->imp_lock, flags);
454 LASSERT(imp->imp_conn_current);
455 imp->imp_conn_current->oic_last_attempt = 0;
457 remote_flag = lustre_msg_buf(request->rq_repmsg, 0, sizeof(int));
458 LASSERT(remote_flag != NULL);
459 imp->imp_obd->u.cli.cl_remote = *remote_flag;
461 msg_flags = lustre_msg_get_op_flags(request->rq_repmsg);
463 if (aa->pcaa_initial_connect) {
464 struct obd_connect_data *conn_data;
466 conn_data = lustre_swab_repbuf(request, 0, sizeof(*conn_data),
467 lustre_swab_connect);
469 imp->imp_connect_data.ocd_connect_flags =
470 conn_data->ocd_connect_flags;
472 if (msg_flags & MSG_CONNECT_REPLAYABLE) {
473 CDEBUG(D_HA, "connected to replayable target: %s\n",
474 imp->imp_target_uuid.uuid);
475 imp->imp_pingable = imp->imp_replayable = 1;
477 imp->imp_replayable = 0;
479 LASSERTF(imp->imp_conn_cnt < request->rq_repmsg->conn_cnt,
480 "imp conn_cnt %d req conn_cnt %d",
481 imp->imp_conn_cnt, request->rq_repmsg->conn_cnt);
482 imp->imp_conn_cnt = request->rq_repmsg->conn_cnt;
483 imp->imp_remote_handle = request->rq_repmsg->handle;
484 IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
485 ptlrpc_pinger_sending_on_import(imp);
486 GOTO(finish, rc = 0);
489 /* Determine what recovery state to move the import to. */
490 if (MSG_CONNECT_RECONNECT & msg_flags) {
491 memset(&old_hdl, 0, sizeof(old_hdl));
492 if (!memcmp(&old_hdl, &request->rq_repmsg->handle,
494 CERROR("%s@%s didn't like our handle "LPX64
495 ", failed\n", imp->imp_target_uuid.uuid,
496 imp->imp_connection->c_remote_uuid.uuid,
497 imp->imp_dlm_handle.cookie);
498 GOTO(out, rc = -ENOTCONN);
501 if (memcmp(&imp->imp_remote_handle, &request->rq_repmsg->handle,
502 sizeof(imp->imp_remote_handle))) {
503 CERROR("%s@%s changed handle from "LPX64" to "LPX64
504 "; copying, but this may foreshadow disaster\n",
505 imp->imp_target_uuid.uuid,
506 imp->imp_connection->c_remote_uuid.uuid,
507 imp->imp_remote_handle.cookie,
508 request->rq_repmsg->handle.cookie);
509 imp->imp_remote_handle = request->rq_repmsg->handle;
511 CDEBUG(D_HA, "reconnected to %s@%s after partition\n",
512 imp->imp_target_uuid.uuid,
513 imp->imp_connection->c_remote_uuid.uuid);
516 if (imp->imp_invalid) {
517 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
518 } else if (MSG_CONNECT_RECOVERING & msg_flags) {
519 CDEBUG(D_HA, "%s: reconnected to %s during replay\n",
520 imp->imp_obd->obd_name,
521 imp->imp_target_uuid.uuid);
522 imp->imp_resend_replay = 1;
523 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
525 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
527 } else if ((MSG_CONNECT_RECOVERING & msg_flags) && !imp->imp_invalid) {
528 LASSERT(imp->imp_replayable);
529 imp->imp_remote_handle = request->rq_repmsg->handle;
530 imp->imp_last_replay_transno = 0;
531 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
533 CDEBUG(D_HA, "oops! we get evicted from %s\n", imp->imp_target_uuid.uuid);
534 imp->imp_remote_handle = request->rq_repmsg->handle;
535 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
538 /* Sanity checks for a reconnected import. */
539 if (!(imp->imp_replayable) != !(msg_flags & MSG_CONNECT_REPLAYABLE)) {
540 CERROR("imp_replayable flag does not match server "
541 "after reconnect. We should LBUG right here.\n");
544 if (request->rq_repmsg->last_committed < aa->pcaa_peer_committed) {
545 CERROR("%s went back in time (transno "LPD64
546 " was previously committed, server now claims "LPD64
547 ")! is shared storage not coherent?\n",
548 imp->imp_target_uuid.uuid,
549 aa->pcaa_peer_committed,
550 request->rq_repmsg->last_committed);
554 imp->imp_debug_open_replays = 1;
555 rc = ptlrpc_import_recovery_state_machine(imp);
557 if (rc == -ENOTCONN) {
558 CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery;"
559 "invalidating and reconnecting\n",
560 imp->imp_target_uuid.uuid,
561 imp->imp_connection->c_remote_uuid.uuid);
562 ptlrpc_connect_import(imp, NULL);
568 IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
569 if (aa->pcaa_initial_connect && !imp->imp_initial_recov)
570 ptlrpc_deactivate_import(imp);
571 CDEBUG(D_HA, "recovery of %s on %s failed (%d)\n",
572 imp->imp_target_uuid.uuid,
573 (char *)imp->imp_connection->c_remote_uuid.uuid, rc);
576 wake_up(&imp->imp_recovery_waitq);
580 static int completed_replay_interpret(struct ptlrpc_request *req,
583 atomic_dec(&req->rq_import->imp_replay_inflight);
584 if (req->rq_status == 0) {
585 ptlrpc_import_recovery_state_machine(req->rq_import);
587 CDEBUG(D_HA, "%s: LAST_REPLAY message error: %d, "
589 req->rq_import->imp_obd->obd_name, req->rq_status);
590 ptlrpc_connect_import(req->rq_import, NULL);
596 static int signal_completed_replay(struct obd_import *imp)
598 struct ptlrpc_request *req;
601 LASSERT(atomic_read(&imp->imp_replay_inflight) == 0);
602 atomic_inc(&imp->imp_replay_inflight);
604 req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING, 0, NULL, NULL);
606 atomic_dec(&imp->imp_replay_inflight);
610 req->rq_replen = lustre_msg_size(0, NULL);
611 req->rq_send_state = LUSTRE_IMP_REPLAY_WAIT;
612 req->rq_reqmsg->flags |= MSG_LOCK_REPLAY_DONE | MSG_REQ_REPLAY_DONE;
613 req->rq_timeout *= 3;
614 req->rq_interpret_reply = completed_replay_interpret;
616 ptlrpcd_add_req(req);
621 static int ptlrpc_invalidate_import_thread(void *data)
623 struct obd_import *imp = data;
631 SIGNAL_MASK_LOCK(current, flags);
632 sigfillset(¤t->blocked);
634 SIGNAL_MASK_UNLOCK(current, flags);
635 THREAD_NAME(current->comm, sizeof(current->comm), "ll_imp_inval");
638 CDEBUG(D_HA, "thread invalidate import %s to %s@%s\n",
639 imp->imp_obd->obd_name, imp->imp_target_uuid.uuid,
640 imp->imp_connection->c_remote_uuid.uuid);
642 ptlrpc_invalidate_import(imp, 0);
643 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
645 ptlrpc_import_recovery_state_machine(imp);
651 int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
656 if (imp->imp_state == LUSTRE_IMP_EVICTED) {
657 CDEBUG(D_HA, "evicted from %s@%s; invalidating\n",
658 imp->imp_target_uuid.uuid,
659 imp->imp_connection->c_remote_uuid.uuid);
662 rc = kernel_thread(ptlrpc_invalidate_import_thread, imp,
663 CLONE_VM | CLONE_FILES);
665 CERROR("error starting invalidate thread: %d\n", rc);
666 RETURN(rc < 0 ? rc : 0);
668 ptlrpc_invalidate_import(imp, 1);
670 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
674 if (imp->imp_state == LUSTRE_IMP_REPLAY) {
675 CDEBUG(D_HA, "replay requested by %s\n",
676 imp->imp_target_uuid.uuid);
677 rc = ptlrpc_replay_next(imp, &inflight);
679 atomic_read(&imp->imp_replay_inflight) == 0) {
680 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS);
681 rc = ldlm_replay_locks(imp);
688 if (imp->imp_state == LUSTRE_IMP_REPLAY_LOCKS) {
689 if (atomic_read(&imp->imp_replay_inflight) == 0) {
690 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_WAIT);
691 rc = signal_completed_replay(imp);
698 if (imp->imp_state == LUSTRE_IMP_REPLAY_WAIT) {
699 if (atomic_read(&imp->imp_replay_inflight) == 0) {
700 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
704 if (imp->imp_state == LUSTRE_IMP_RECOVER) {
705 CDEBUG(D_HA, "reconnected to %s@%s\n",
706 imp->imp_target_uuid.uuid,
707 imp->imp_connection->c_remote_uuid.uuid);
709 rc = ptlrpc_resend(imp);
712 IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
713 ptlrpc_activate_import(imp);
714 CWARN("%s: connection restored to %s@%s, "
715 "%d/%d req/lock replayed\n",
716 imp->imp_obd->obd_name,
717 imp->imp_target_uuid.uuid,
718 imp->imp_connection->c_remote_uuid.uuid,
719 imp->imp_reqs_replayed,
720 imp->imp_locks_replayed);
723 if (imp->imp_state == LUSTRE_IMP_FULL) {
724 wake_up(&imp->imp_recovery_waitq);
725 ptlrpc_wake_delayed(imp);
732 static int back_to_sleep(void *unused)
737 int ptlrpc_disconnect_import(struct obd_import *imp)
739 struct ptlrpc_request *request;
745 switch (imp->imp_connect_op) {
746 case OST_CONNECT: rq_opc = OST_DISCONNECT; break;
747 case MDS_CONNECT: rq_opc = MDS_DISCONNECT; break;
748 case MGMT_CONNECT: rq_opc = MGMT_DISCONNECT; break;
750 CERROR("don't know how to disconnect from %s (connect_op %d)\n",
751 imp->imp_target_uuid.uuid, imp->imp_connect_op);
756 if (ptlrpc_import_in_recovery(imp)) {
757 struct l_wait_info lwi;
758 unsigned long timeout;
759 if (imp->imp_server_timeout)
760 timeout = obd_timeout / 2;
762 timeout = obd_timeout;
763 timeout = MAX(timeout * HZ, 1);
764 lwi = LWI_TIMEOUT_INTR(obd_timeout, back_to_sleep, NULL, NULL);
765 rc = l_wait_event(imp->imp_recovery_waitq,
766 !ptlrpc_import_in_recovery(imp), &lwi);
770 spin_lock_irqsave(&imp->imp_lock, flags);
771 if (imp->imp_state != LUSTRE_IMP_FULL) {
774 spin_unlock_irqrestore(&imp->imp_lock, flags);
776 request = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, rq_opc,
779 /* For non-replayable connections, don't attempt
780 reconnect if this fails */
781 if (!imp->imp_replayable) {
782 request->rq_no_resend = 1;
783 IMPORT_SET_STATE(imp, LUSTRE_IMP_CONNECTING);
784 request->rq_send_state = LUSTRE_IMP_CONNECTING;
786 request->rq_replen = lustre_msg_size(0, NULL);
787 rc = ptlrpc_queue_wait(request);
788 ptlrpc_req_finished(request);
791 spin_lock_irqsave(&imp->imp_lock, flags);
793 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED);
794 memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle));
795 imp->imp_conn_cnt = 0;
796 spin_unlock_irqrestore(&imp->imp_lock, flags);