Whamcloud - gitweb
aba05cfcf2433290a6fb3796496c471c7b59df9b
[fs/lustre-release.git] / lustre / ptlrpc / import.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5  *   Author: Mike Shaver <shaver@clusterfs.com>
6  *
7  *   This file is part of the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
10  *   You may have signed or agreed to another license before downloading
11  *   this software.  If so, you are bound by the terms and conditions
12  *   of that agreement, and the following does not apply to you.  See the
13  *   LICENSE file included with this distribution for more information.
14  *
15  *   If you did not agree to a different license, then this copy of Lustre
16  *   is open source software; you can redistribute it and/or modify it
17  *   under the terms of version 2 of the GNU General Public License as
18  *   published by the Free Software Foundation.
19  *
20  *   In either case, Lustre is distributed in the hope that it will be
21  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
22  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *   license text for more details.
24  */
25
26 #define DEBUG_SUBSYSTEM S_RPC
27 #ifndef __KERNEL__
28 # include <liblustre.h>
29 #endif
30
31 #include <obd_support.h>
32 #include <lustre_ha.h>
33 #include <lustre_net.h>
34 #include <lustre_import.h>
35 #include <lustre_export.h>
36 #include <obd.h>
37 #include <obd_cksum.h>
38 #include <obd_class.h>
39
40 #include "ptlrpc_internal.h"
41
42 struct ptlrpc_connect_async_args {
43          __u64 pcaa_peer_committed;
44         int pcaa_initial_connect;
45 };
46
47 /* A CLOSED import should remain so. */
48 #define IMPORT_SET_STATE_NOLOCK(imp, state)                                    \
49 do {                                                                           \
50         if (imp->imp_state != LUSTRE_IMP_CLOSED) {                             \
51                CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n",    \
52                       imp, obd2cli_tgt(imp->imp_obd),                          \
53                       ptlrpc_import_state_name(imp->imp_state),                \
54                       ptlrpc_import_state_name(state));                        \
55                imp->imp_state = state;                                         \
56         }                                                                      \
57 } while(0)
58
59 #define IMPORT_SET_STATE(imp, state)            \
60 do {                                            \
61         spin_lock(&imp->imp_lock);              \
62         IMPORT_SET_STATE_NOLOCK(imp, state);    \
63         spin_unlock(&imp->imp_lock);            \
64 } while(0)
65
66
67 static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
68                                     void * data, int rc);
69 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
70
71 /* Only this function is allowed to change the import state when it is
72  * CLOSED. I would rather refcount the import and free it after
73  * disconnection like we do with exports. To do that, the client_obd
74  * will need to save the peer info somewhere other than in the import,
75  * though. */
76 int ptlrpc_init_import(struct obd_import *imp)
77 {
78         spin_lock(&imp->imp_lock);
79
80         imp->imp_generation++;
81         imp->imp_state =  LUSTRE_IMP_NEW;
82
83         spin_unlock(&imp->imp_lock);
84
85         return 0;
86 }
87 EXPORT_SYMBOL(ptlrpc_init_import);
88
89 #define UUID_STR "_UUID"
90 static void deuuidify(char *uuid, const char *prefix, char **uuid_start,
91                       int *uuid_len)
92 {
93         *uuid_start = !prefix || strncmp(uuid, prefix, strlen(prefix))
94                 ? uuid : uuid + strlen(prefix);
95
96         *uuid_len = strlen(*uuid_start);
97
98         if (*uuid_len < strlen(UUID_STR))
99                 return;
100
101         if (!strncmp(*uuid_start + *uuid_len - strlen(UUID_STR),
102                     UUID_STR, strlen(UUID_STR)))
103                 *uuid_len -= strlen(UUID_STR);
104 }
105
106 /* Returns true if import was FULL, false if import was already not
107  * connected.
108  * @imp - import to be disconnected
109  * @conn_cnt - connection count (epoch) of the request that timed out
110  *             and caused the disconnection.  In some cases, multiple
111  *             inflight requests can fail to a single target (e.g. OST
112  *             bulk requests) and if one has already caused a reconnection
113  *             (increasing the import->conn_cnt) the older failure should
114  *             not also cause a reconnection.  If zero it forces a reconnect.
115  */
116 int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt)
117 {
118         int rc = 0;
119
120         spin_lock(&imp->imp_lock);
121
122         if (imp->imp_state == LUSTRE_IMP_FULL &&
123             (conn_cnt == 0 || conn_cnt == imp->imp_conn_cnt)) {
124                 char *target_start;
125                 int   target_len;
126
127                 deuuidify(obd2cli_tgt(imp->imp_obd), NULL,
128                           &target_start, &target_len);
129
130                 if (imp->imp_replayable) {
131                         LCONSOLE_WARN("%s: Connection to service %.*s via nid "
132                                "%s was lost; in progress operations using this "
133                                "service will wait for recovery to complete.\n",
134                                imp->imp_obd->obd_name, target_len, target_start,
135                                libcfs_nid2str(imp->imp_connection->c_peer.nid));
136                 } else {
137                         LCONSOLE_ERROR_MSG(0x166, "%s: Connection to service "
138                                            "%.*s via nid %s was lost; in progress"
139                                            "operations using this service will"
140                                            "fail.\n",
141                                            imp->imp_obd->obd_name,
142                                            target_len, target_start,
143                                  libcfs_nid2str(imp->imp_connection->c_peer.nid));
144                 }
145                 ptlrpc_deactivate_timeouts(imp);
146                 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
147                 spin_unlock(&imp->imp_lock);
148     
149                 if (obd_dump_on_timeout)
150                         libcfs_debug_dumplog();
151
152                 obd_import_event(imp->imp_obd, imp, IMP_EVENT_DISCON);
153                 rc = 1;
154         } else {
155                 spin_unlock(&imp->imp_lock);
156                 CDEBUG(D_HA, "%s: import %p already %s (conn %u, was %u): %s\n",
157                        imp->imp_client->cli_name, imp,
158                        (imp->imp_state == LUSTRE_IMP_FULL &&
159                         imp->imp_conn_cnt > conn_cnt) ?
160                        "reconnected" : "not connected", imp->imp_conn_cnt,
161                        conn_cnt, ptlrpc_import_state_name(imp->imp_state));
162         }
163
164         return rc;
165 }
166
167 /* Must be called with imp_lock held! */
168 static void ptlrpc_deactivate_and_unlock_import(struct obd_import *imp)
169 {
170         ENTRY;
171         LASSERT_SPIN_LOCKED(&imp->imp_lock);
172
173         if (imp->imp_invalid) {
174                 spin_unlock(&imp->imp_lock);
175                 EXIT;
176                 return;
177         }
178
179         CDEBUG(D_HA, "setting import %s INVALID\n", obd2cli_tgt(imp->imp_obd));
180         imp->imp_invalid = 1;
181         imp->imp_generation++;
182         spin_unlock(&imp->imp_lock);
183
184         ptlrpc_abort_inflight(imp);
185         obd_import_event(imp->imp_obd, imp, IMP_EVENT_INACTIVE);
186
187         EXIT;
188 }
189
190 /*
191  * This acts as a barrier; all existing requests are rejected, and
192  * no new requests will be accepted until the import is valid again.
193  */
194 void ptlrpc_deactivate_import(struct obd_import *imp)
195 {
196         spin_lock(&imp->imp_lock);
197         ptlrpc_deactivate_and_unlock_import(imp);
198 }
199
200 /*
201  * This function will invalidate the import, if necessary, then block
202  * for all the RPC completions, and finally notify the obd to
203  * invalidate its state (ie cancel locks, clear pending requests,
204  * etc).
205  */
206 void ptlrpc_invalidate_import(struct obd_import *imp)
207 {
208         struct l_wait_info lwi;
209         int rc;
210
211         atomic_inc(&imp->imp_inval_count);
212
213         ptlrpc_deactivate_import(imp);
214
215         LASSERT(imp->imp_invalid);
216
217         /* wait for all requests to error out and call completion callbacks */
218         lwi = LWI_TIMEOUT_INTERVAL(cfs_timeout_cap(cfs_time_seconds(obd_timeout)), 
219                                    HZ, NULL, NULL);
220         rc = l_wait_event(imp->imp_recovery_waitq,
221                           (atomic_read(&imp->imp_inflight) == 0), &lwi);
222
223         if (rc)
224                 CDEBUG(D_HA, "%s: rc = %d waiting for callback (%d != 0)\n",
225                        obd2cli_tgt(imp->imp_obd), rc,
226                        atomic_read(&imp->imp_inflight));
227
228         obd_import_event(imp->imp_obd, imp, IMP_EVENT_INVALIDATE);
229         sptlrpc_import_flush_all_ctx(imp);
230
231         atomic_dec(&imp->imp_inval_count);
232         cfs_waitq_signal(&imp->imp_recovery_waitq);
233 }
234
235 /* unset imp_invalid */
236 void ptlrpc_activate_import(struct obd_import *imp)
237 {
238         struct obd_device *obd = imp->imp_obd;
239
240         spin_lock(&imp->imp_lock);
241         imp->imp_invalid = 0;
242         ptlrpc_activate_timeouts(imp);
243         spin_unlock(&imp->imp_lock);
244         obd_import_event(obd, imp, IMP_EVENT_ACTIVE);
245 }
246
247 void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt)
248 {
249         ENTRY;
250
251         LASSERT(!imp->imp_dlm_fake);
252
253         if (ptlrpc_set_import_discon(imp, conn_cnt)) {
254                 if (!imp->imp_replayable) {
255                         CDEBUG(D_HA, "import %s@%s for %s not replayable, "
256                                "auto-deactivating\n",
257                                obd2cli_tgt(imp->imp_obd),
258                                imp->imp_connection->c_remote_uuid.uuid,
259                                imp->imp_obd->obd_name);
260                         ptlrpc_deactivate_import(imp);
261                 }
262
263                 CDEBUG(D_HA, "%s: waking up pinger\n",
264                        obd2cli_tgt(imp->imp_obd));
265
266                 spin_lock(&imp->imp_lock);
267                 imp->imp_force_verify = 1;
268                 spin_unlock(&imp->imp_lock);
269
270                 ptlrpc_pinger_wake_up();
271         }
272         EXIT;
273 }
274
275 int ptlrpc_reconnect_import(struct obd_import *imp)
276 {
277         
278         ptlrpc_set_import_discon(imp, 0); 
279         /* Force a new connect attempt */
280         ptlrpc_invalidate_import(imp);
281         /* Do a fresh connect next time by zeroing the handle */
282         ptlrpc_disconnect_import(imp, 1);
283         /* Wait for all invalidate calls to finish */
284         if (atomic_read(&imp->imp_inval_count) > 0) {
285                 int rc;
286                 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
287                 rc = l_wait_event(imp->imp_recovery_waitq,
288                                   (atomic_read(&imp->imp_inval_count) == 0),
289                                   &lwi);
290                 if (rc)
291                         CERROR("Interrupted, inval=%d\n", 
292                                atomic_read(&imp->imp_inval_count));
293         }
294
295         /* Allow reconnect attempts */
296         imp->imp_obd->obd_no_recov = 0;
297         /* Remove 'invalid' flag */
298         ptlrpc_activate_import(imp);
299         /* Attempt a new connect */
300         ptlrpc_recover_import(imp, NULL);
301         return 0;
302 }
303
304 EXPORT_SYMBOL(ptlrpc_reconnect_import);
305
306 static int import_select_connection(struct obd_import *imp)
307 {
308         struct obd_import_conn *imp_conn = NULL, *conn;
309         struct obd_export *dlmexp;
310         ENTRY;
311
312         spin_lock(&imp->imp_lock);
313
314         if (list_empty(&imp->imp_conn_list)) {
315                 CERROR("%s: no connections available\n",
316                         imp->imp_obd->obd_name);
317                 spin_unlock(&imp->imp_lock);
318                 RETURN(-EINVAL);
319         }
320
321         list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
322                 CDEBUG(D_HA, "%s: connect to NID %s last attempt "LPU64"\n",
323                        imp->imp_obd->obd_name,
324                        libcfs_nid2str(conn->oic_conn->c_peer.nid),
325                        conn->oic_last_attempt);
326                 /* Throttle the reconnect rate to once per RECONNECT_INTERVAL */
327                 if (cfs_time_before_64(conn->oic_last_attempt + 
328                                        RECONNECT_INTERVAL * HZ,
329                                        cfs_time_current_64())) {
330                         /* If we have never tried this connection since the
331                            the last successful attempt, go with this one */
332                         if (cfs_time_beforeq_64(conn->oic_last_attempt,
333                                                imp->imp_last_success_conn)) {
334                                 imp_conn = conn;
335                                 break;
336                         }
337
338                         /* Both of these connections have already been tried
339                            since the last successful connection; just choose the
340                            least recently used */
341                         if (!imp_conn)
342                                 imp_conn = conn;
343                         else if (cfs_time_before_64(conn->oic_last_attempt,
344                                                     imp_conn->oic_last_attempt))
345                                 imp_conn = conn;
346                 }
347         }
348
349         /* if not found, simply choose the current one */
350         if (!imp_conn) {
351                 LASSERT(imp->imp_conn_current);
352                 imp_conn = imp->imp_conn_current;
353         }
354         LASSERT(imp_conn->oic_conn);
355
356         imp_conn->oic_last_attempt = cfs_time_current_64();
357
358         /* switch connection, don't mind if it's same as the current one */
359         if (imp->imp_connection)
360                 ptlrpc_put_connection(imp->imp_connection);
361         imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
362
363         dlmexp =  class_conn2export(&imp->imp_dlm_handle);
364         LASSERT(dlmexp != NULL);
365         if (dlmexp->exp_connection)
366                 ptlrpc_put_connection(dlmexp->exp_connection);
367         dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
368         class_export_put(dlmexp);
369
370         if (imp->imp_conn_current != imp_conn) {
371                 if (imp->imp_conn_current)
372                         LCONSOLE_INFO("Changing connection for %s to %s/%s\n",
373                                       imp->imp_obd->obd_name,
374                                       imp_conn->oic_uuid.uuid,
375                                       libcfs_nid2str(imp_conn->oic_conn->c_peer.nid));
376                 imp->imp_conn_current = imp_conn;
377         }
378
379         CDEBUG(D_HA, "%s: import %p using connection %s/%s\n",
380                imp->imp_obd->obd_name, imp, imp_conn->oic_uuid.uuid,
381                libcfs_nid2str(imp_conn->oic_conn->c_peer.nid));
382
383         spin_unlock(&imp->imp_lock);
384
385         RETURN(0);
386 }
387
388 /*
389  * must be called under imp_lock
390  */
391 int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno)
392 {
393         struct ptlrpc_request *req;
394         struct list_head *tmp;
395
396         if (list_empty(&imp->imp_replay_list))
397                 return 0;
398         tmp = imp->imp_replay_list.next;
399         req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
400         *transno = req->rq_transno;
401         if (req->rq_transno == 0) {
402                 DEBUG_REQ(D_ERROR, req, "zero transno in replay");
403                 LBUG();
404         }
405
406         return 1;
407 }
408
409 int ptlrpc_connect_import(struct obd_import *imp, char *new_uuid)
410 {
411         struct obd_device *obd = imp->imp_obd;
412         int initial_connect = 0;
413         int set_transno = 0;
414         __u64 committed_before_reconnect = 0;
415         struct ptlrpc_request *request;
416         char *bufs[] = { NULL,
417                          obd2cli_tgt(imp->imp_obd),
418                          obd->obd_uuid.uuid,
419                          (char *)&imp->imp_dlm_handle,
420                          (char *)&imp->imp_connect_data };
421         struct ptlrpc_connect_async_args *aa;
422         int rc;
423         ENTRY;
424
425         spin_lock(&imp->imp_lock);
426         if (imp->imp_state == LUSTRE_IMP_CLOSED) {
427                 spin_unlock(&imp->imp_lock);
428                 CERROR("can't connect to a closed import\n");
429                 RETURN(-EINVAL);
430         } else if (imp->imp_state == LUSTRE_IMP_FULL) {
431                 spin_unlock(&imp->imp_lock);
432                 CERROR("already connected\n");
433                 RETURN(0);
434         } else if (imp->imp_state == LUSTRE_IMP_CONNECTING) {
435                 spin_unlock(&imp->imp_lock);
436                 CERROR("already connecting\n");
437                 RETURN(-EALREADY);
438         }
439
440         IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CONNECTING);
441
442         imp->imp_conn_cnt++;
443         imp->imp_resend_replay = 0;
444
445         if (!lustre_handle_is_used(&imp->imp_remote_handle))
446                 initial_connect = 1;
447         else
448                 committed_before_reconnect = imp->imp_peer_committed_transno;
449
450         set_transno = ptlrpc_first_transno(imp, &imp->imp_connect_data.ocd_transno);
451         spin_unlock(&imp->imp_lock);
452
453         if (new_uuid) {
454                 struct obd_uuid uuid;
455
456                 obd_str2uuid(&uuid, new_uuid);
457                 rc = import_set_conn_priority(imp, &uuid);
458                 if (rc)
459                         GOTO(out, rc);
460         }
461
462         rc = import_select_connection(imp);
463         if (rc)
464                 GOTO(out, rc);
465
466         /* last in connection list */
467         if (imp->imp_conn_current->oic_item.next == &imp->imp_conn_list) {
468                 if (imp->imp_initial_recov_bk && initial_connect) {
469                         CDEBUG(D_HA, "Last connection attempt (%d) for %s\n",
470                                imp->imp_conn_cnt, obd2cli_tgt(imp->imp_obd));
471                         /* Don't retry if connect fails */
472                         rc = 0;
473                         obd_set_info_async(obd->obd_self_export,
474                                            strlen(KEY_INIT_RECOV),
475                                            KEY_INIT_RECOV,
476                                            sizeof(rc), &rc, NULL);
477                 }
478                 if (imp->imp_recon_bk) {
479                         CDEBUG(D_HA, "Last reconnection attempt (%d) for %s\n",
480                                imp->imp_conn_cnt, obd2cli_tgt(imp->imp_obd));
481                         spin_lock(&imp->imp_lock);
482                         imp->imp_last_recon = 1;
483                         spin_unlock(&imp->imp_lock);
484                 }
485         }
486
487         rc = sptlrpc_import_sec_adapt(imp, NULL, 0);
488         if (rc)
489                 GOTO(out, rc);
490
491         /* Reset connect flags to the originally requested flags, in case
492          * the server is updated on-the-fly we will get the new features. */
493         imp->imp_connect_data.ocd_connect_flags = imp->imp_connect_flags_orig;
494         rc = obd_reconnect(NULL, imp->imp_obd->obd_self_export, obd,
495                            &obd->obd_uuid, &imp->imp_connect_data);
496         if (rc)
497                 GOTO(out, rc);
498
499         request = ptlrpc_request_alloc(imp, &RQF_MDS_CONNECT);
500         if (request == NULL)
501                 GOTO(out, rc = -ENOMEM);
502
503         rc = ptlrpc_request_bufs_pack(request, LUSTRE_OBD_VERSION,
504                                       imp->imp_connect_op, bufs, NULL);
505         if (rc) {
506                 ptlrpc_request_free(request);
507                 GOTO(out, rc);
508         }
509
510 #ifndef __KERNEL__
511         lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_LIBCLIENT);
512 #endif
513         lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER);
514
515         request->rq_send_state = LUSTRE_IMP_CONNECTING;
516         /* Allow a slightly larger reply for future growth compatibility */
517         req_capsule_set_size(&request->rq_pill, &RMF_CONNECT_DATA, RCL_SERVER,
518                              sizeof(struct obd_connect_data)+16*sizeof(__u64));
519         ptlrpc_request_set_replen(request);
520         request->rq_interpret_reply = ptlrpc_connect_interpret;
521
522         CLASSERT(sizeof (*aa) <= sizeof (request->rq_async_args));
523         aa = (struct ptlrpc_connect_async_args *)&request->rq_async_args;
524         memset(aa, 0, sizeof *aa);
525
526         aa->pcaa_peer_committed = committed_before_reconnect;
527         aa->pcaa_initial_connect = initial_connect;
528
529         if (aa->pcaa_initial_connect) {
530                 spin_lock(&imp->imp_lock);
531                 imp->imp_replayable = 1;
532                 spin_unlock(&imp->imp_lock);
533                 /* On an initial connect, we don't know which one of a
534                    failover server pair is up.  Don't wait long. */
535 #ifdef CRAY_XT3
536                 request->rq_timeout = max((int)(obd_timeout / 2), 5);
537 #else
538                 request->rq_timeout = max((int)(obd_timeout / 20), 5);
539 #endif
540                 lustre_msg_add_op_flags(request->rq_reqmsg, 
541                                         MSG_CONNECT_INITIAL);
542         }
543
544         if (set_transno)
545                 lustre_msg_add_op_flags(request->rq_reqmsg, 
546                                         MSG_CONNECT_TRANSNO);
547
548         DEBUG_REQ(D_RPCTRACE, request, "(re)connect request");
549         ptlrpcd_add_req(request);
550         rc = 0;
551 out:
552         if (rc != 0) {
553                 IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
554         }
555
556         RETURN(rc);
557 }
558 EXPORT_SYMBOL(ptlrpc_connect_import);
559
560 static void ptlrpc_maybe_ping_import_soon(struct obd_import *imp)
561 {
562 #ifdef __KERNEL__
563         struct obd_import_conn *imp_conn;
564 #endif
565         int wake_pinger = 0;
566
567         ENTRY;
568
569         spin_lock(&imp->imp_lock);
570         if (list_empty(&imp->imp_conn_list))
571                 GOTO(unlock, 0);
572
573 #ifdef __KERNEL__
574         imp_conn = list_entry(imp->imp_conn_list.prev,
575                               struct obd_import_conn,
576                               oic_item);
577
578         /* XXX: When the failover node is the primary node, it is possible
579          * to have two identical connections in imp_conn_list. We must 
580          * compare not conn's pointers but NIDs, otherwise we can defeat
581          * connection throttling. (See bug 14774.) */
582         if (imp->imp_conn_current->oic_conn->c_self != 
583                                 imp_conn->oic_conn->c_self) {
584                 ptlrpc_ping_import_soon(imp);
585                 wake_pinger = 1;
586         }
587 #else
588         /* liblustre has no pinger thead, so we wakup pinger anyway */
589         wake_pinger = 1;
590 #endif 
591
592  unlock:
593         spin_unlock(&imp->imp_lock);
594
595         if (wake_pinger)
596                 ptlrpc_pinger_wake_up();
597
598         EXIT;
599 }
600
601 static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
602                                     void * data, int rc)
603 {
604         struct ptlrpc_connect_async_args *aa = data;
605         struct obd_import *imp = request->rq_import;
606         struct client_obd *cli = &imp->imp_obd->u.cli;
607         struct lustre_handle old_hdl;
608         int msg_flags;
609         ENTRY;
610
611         spin_lock(&imp->imp_lock);
612         if (imp->imp_state == LUSTRE_IMP_CLOSED) {
613                 spin_unlock(&imp->imp_lock);
614                 RETURN(0);
615         }
616         spin_unlock(&imp->imp_lock);
617
618         if (rc)
619                 GOTO(out, rc);
620
621         LASSERT(imp->imp_conn_current);
622
623         msg_flags = lustre_msg_get_op_flags(request->rq_repmsg);
624
625         /* All imports are pingable */
626         spin_lock(&imp->imp_lock);
627         imp->imp_pingable = 1;
628
629         if (aa->pcaa_initial_connect) {
630                 if (msg_flags & MSG_CONNECT_REPLAYABLE) {
631                         imp->imp_replayable = 1;
632                         spin_unlock(&imp->imp_lock);
633                         CDEBUG(D_HA, "connected to replayable target: %s\n",
634                                obd2cli_tgt(imp->imp_obd));
635                 } else {
636                         imp->imp_replayable = 0;
637                         spin_unlock(&imp->imp_lock);
638                 }
639
640                 /* if applies, adjust the imp->imp_msg_magic here
641                  * according to reply flags */
642
643                 imp->imp_remote_handle =
644                                 *lustre_msg_get_handle(request->rq_repmsg);
645
646                 IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
647                 ptlrpc_activate_import(imp);
648                 GOTO(finish, rc = 0);
649         } else {
650                 spin_unlock(&imp->imp_lock);
651         }
652
653         /* Determine what recovery state to move the import to. */
654         if (MSG_CONNECT_RECONNECT & msg_flags) {
655                 memset(&old_hdl, 0, sizeof(old_hdl));
656                 if (!memcmp(&old_hdl, lustre_msg_get_handle(request->rq_repmsg),
657                             sizeof (old_hdl))) {
658                         CERROR("%s@%s didn't like our handle "LPX64
659                                ", failed\n", obd2cli_tgt(imp->imp_obd),
660                                imp->imp_connection->c_remote_uuid.uuid,
661                                imp->imp_dlm_handle.cookie);
662                         GOTO(out, rc = -ENOTCONN);
663                 }
664
665                 if (memcmp(&imp->imp_remote_handle,
666                            lustre_msg_get_handle(request->rq_repmsg),
667                            sizeof(imp->imp_remote_handle))) {
668
669                         CWARN("%s@%s changed server handle from "
670                                LPX64" to "LPX64" - evicting.\n",
671                                obd2cli_tgt(imp->imp_obd),
672                                imp->imp_connection->c_remote_uuid.uuid,
673                                imp->imp_remote_handle.cookie,
674                                lustre_msg_get_handle(request->rq_repmsg)->
675                                          cookie);
676                         imp->imp_remote_handle =
677                                      *lustre_msg_get_handle(request->rq_repmsg);
678
679                         IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
680                         GOTO(finish, rc = 0);
681                 } else {
682                         CDEBUG(D_HA, "reconnected to %s@%s after partition\n",
683                                obd2cli_tgt(imp->imp_obd),
684                                imp->imp_connection->c_remote_uuid.uuid);
685                 }
686
687                 if (imp->imp_invalid) {
688                         IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
689                 } else if (MSG_CONNECT_RECOVERING & msg_flags) {
690                         CDEBUG(D_HA, "%s: reconnected to %s during replay\n",
691                                imp->imp_obd->obd_name,
692                                obd2cli_tgt(imp->imp_obd));
693
694                         spin_lock(&imp->imp_lock);
695                         imp->imp_resend_replay = 1;
696                         spin_unlock(&imp->imp_lock);
697
698                         IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
699                 } else {
700                         IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
701                 }
702         } else if ((MSG_CONNECT_RECOVERING & msg_flags) && !imp->imp_invalid) {
703                 LASSERT(imp->imp_replayable);
704                 imp->imp_remote_handle =
705                                 *lustre_msg_get_handle(request->rq_repmsg);
706                 imp->imp_last_replay_transno = 0;
707                 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
708         } else {
709                 imp->imp_remote_handle =
710                                 *lustre_msg_get_handle(request->rq_repmsg);
711                 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
712         }
713
714         /* Sanity checks for a reconnected import. */
715         if (!(imp->imp_replayable) != !(msg_flags & MSG_CONNECT_REPLAYABLE)) {
716                 CERROR("imp_replayable flag does not match server "
717                        "after reconnect. We should LBUG right here.\n");
718         }
719
720         if (lustre_msg_get_last_committed(request->rq_repmsg) <
721             aa->pcaa_peer_committed) {
722                 CERROR("%s went back in time (transno "LPD64
723                        " was previously committed, server now claims "LPD64
724                        ")!  See https://bugzilla.clusterfs.com/"
725                        "long_list.cgi?buglist=9646\n",
726                        obd2cli_tgt(imp->imp_obd), aa->pcaa_peer_committed,
727                        lustre_msg_get_last_committed(request->rq_repmsg));
728         }
729
730 finish:
731         rc = ptlrpc_import_recovery_state_machine(imp);
732         if (rc != 0) {
733                 if (rc == -ENOTCONN) {
734                         CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery;"
735                                "invalidating and reconnecting\n",
736                                obd2cli_tgt(imp->imp_obd),
737                                imp->imp_connection->c_remote_uuid.uuid);
738                         ptlrpc_connect_import(imp, NULL);
739                         RETURN(0);
740                 }
741         } else {
742                 struct obd_connect_data *ocd;
743                 struct obd_export *exp;
744                 int ret;
745                 ret = req_capsule_get_size(&request->rq_pill, &RMF_CONNECT_DATA,
746                                            RCL_SERVER);
747                 /* server replied obd_connect_data is always bigger */
748                 ocd = req_capsule_server_sized_get(&request->rq_pill,
749                                                    &RMF_CONNECT_DATA, ret);
750
751                 spin_lock(&imp->imp_lock);
752                 list_del(&imp->imp_conn_current->oic_item);
753                 list_add(&imp->imp_conn_current->oic_item, &imp->imp_conn_list);
754                 imp->imp_last_success_conn =
755                         imp->imp_conn_current->oic_last_attempt;
756
757                 if (ocd == NULL) {
758                         spin_unlock(&imp->imp_lock);
759                         CERROR("Wrong connect data from server\n");
760                         rc = -EPROTO;
761                         GOTO(out, rc);
762                 }
763
764                 imp->imp_connect_data = *ocd;
765
766                 exp = class_conn2export(&imp->imp_dlm_handle);
767                 spin_unlock(&imp->imp_lock);
768
769                 /* check that server granted subset of flags we asked for. */
770                 LASSERTF((ocd->ocd_connect_flags &
771                           imp->imp_connect_flags_orig) ==
772                          ocd->ocd_connect_flags, LPX64" != "LPX64,
773                          imp->imp_connect_flags_orig, ocd->ocd_connect_flags);
774
775                 if (!exp) {
776                         /* This could happen if export is cleaned during the 
777                            connect attempt */
778                         CERROR("Missing export for %s\n", 
779                                imp->imp_obd->obd_name);
780                         GOTO(out, rc = -ENODEV);
781                 }
782                 exp->exp_connect_flags = ocd->ocd_connect_flags;
783                 imp->imp_obd->obd_self_export->exp_connect_flags = 
784                                                         ocd->ocd_connect_flags;
785                 class_export_put(exp);
786
787                 obd_import_event(imp->imp_obd, imp, IMP_EVENT_OCD);
788
789                 if (!ocd->ocd_ibits_known &&
790                     ocd->ocd_connect_flags & OBD_CONNECT_IBITS)
791                         CERROR("Inodebits aware server returned zero compatible"
792                                " bits?\n");
793
794                 if ((ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
795                     (ocd->ocd_version > LUSTRE_VERSION_CODE +
796                                         LUSTRE_VERSION_OFFSET_WARN ||
797                      ocd->ocd_version < LUSTRE_VERSION_CODE -
798                                         LUSTRE_VERSION_OFFSET_WARN)) {
799                         /* Sigh, some compilers do not like #ifdef in the middle
800                            of macro arguments */
801 #ifdef __KERNEL__
802                         const char *older =
803                                 "older. Consider upgrading this client";
804 #else
805                         const char *older =
806                                 "older. Consider recompiling this application";
807 #endif
808                         const char *newer = "newer than client version";
809
810                         LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) "
811                                       "is much %s (%s)\n",
812                                       obd2cli_tgt(imp->imp_obd),
813                                       OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
814                                       OBD_OCD_VERSION_MINOR(ocd->ocd_version),
815                                       OBD_OCD_VERSION_PATCH(ocd->ocd_version),
816                                       OBD_OCD_VERSION_FIX(ocd->ocd_version),
817                                       ocd->ocd_version > LUSTRE_VERSION_CODE ?
818                                       newer : older, LUSTRE_VERSION_STRING);
819                 }
820
821                 if (ocd->ocd_connect_flags & OBD_CONNECT_CKSUM) {
822                         /* We sent to the server ocd_cksum_types with bits set
823                          * for algorithms we understand. The server masked off
824                          * the checksum types it doesn't support */
825                         if ((ocd->ocd_cksum_types & OBD_CKSUM_ALL) == 0) {
826                                 LCONSOLE_WARN("The negotiation of the checksum "
827                                               "alogrithm to use with server %s "
828                                               "failed (%x/%x), disabling "
829                                               "checksums\n",
830                                               obd2cli_tgt(imp->imp_obd),
831                                               ocd->ocd_cksum_types,
832                                               OBD_CKSUM_ALL);
833                                 cli->cl_checksum = 0;
834                                 cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
835                                 cli->cl_cksum_type = OBD_CKSUM_CRC32;
836                         } else {
837                                 cli->cl_supp_cksum_types = ocd->ocd_cksum_types;
838
839                                 if (ocd->ocd_cksum_types & OSC_DEFAULT_CKSUM)
840                                         cli->cl_cksum_type = OSC_DEFAULT_CKSUM;
841                                 else if (ocd->ocd_cksum_types & OBD_CKSUM_ADLER)
842                                         cli->cl_cksum_type = OBD_CKSUM_ADLER;
843                                 else
844                                         cli->cl_cksum_type = OBD_CKSUM_CRC32;
845                         }
846                 } else {
847                         /* The server does not support OBD_CONNECT_CKSUM.
848                          * Enforce CRC32 for backward compatibility*/
849                         cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
850                         cli->cl_cksum_type = OBD_CKSUM_CRC32;
851                 }
852
853                 if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
854                         cli->cl_max_pages_per_rpc = 
855                                 ocd->ocd_brw_size >> CFS_PAGE_SHIFT;
856                 }
857
858                 imp->imp_obd->obd_namespace->ns_connect_flags = 
859                                                         ocd->ocd_connect_flags;
860                 imp->imp_obd->obd_namespace->ns_orig_connect_flags = 
861                                                         ocd->ocd_connect_flags;
862
863                 LASSERT((cli->cl_max_pages_per_rpc <= PTLRPC_MAX_BRW_PAGES) &&
864                         (cli->cl_max_pages_per_rpc > 0));
865         }
866
867 out:
868         if (rc != 0) {
869                 IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
870                 spin_lock(&imp->imp_lock);
871                 if (aa->pcaa_initial_connect && !imp->imp_initial_recov &&
872                     (request->rq_import_generation == imp->imp_generation))
873                         ptlrpc_deactivate_and_unlock_import(imp);
874                 else
875                         spin_unlock(&imp->imp_lock);
876
877                 if ((imp->imp_recon_bk && imp->imp_last_recon) ||
878                     (rc == -EACCES)) {
879                         /*
880                          * Give up trying to reconnect
881                          * EACCES means client has no permission for connection
882                          */
883                         imp->imp_obd->obd_no_recov = 1;
884                         ptlrpc_deactivate_import(imp);
885                 }
886
887                 if (rc == -EPROTO) {
888                         struct obd_connect_data *ocd;
889
890                         /* reply message might not be ready */
891                         if (request->rq_repmsg == NULL)
892                                 RETURN(-EPROTO);
893
894                         ocd = req_capsule_server_get(&request->rq_pill,
895                                                      &RMF_CONNECT_DATA);
896                         if (ocd &&
897                             (ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
898                             (ocd->ocd_version != LUSTRE_VERSION_CODE)) {
899                            /* Actually servers are only supposed to refuse
900                               connection from liblustre clients, so we should
901                               never see this from VFS context */
902                                 LCONSOLE_ERROR_MSG(0x16a, "Server %s version "
903                                         "(%d.%d.%d.%d)"
904                                         " refused connection from this client "
905                                         "with an incompatible version (%s).  "
906                                         "Client must be recompiled\n",
907                                         obd2cli_tgt(imp->imp_obd),
908                                         OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
909                                         OBD_OCD_VERSION_MINOR(ocd->ocd_version),
910                                         OBD_OCD_VERSION_PATCH(ocd->ocd_version),
911                                         OBD_OCD_VERSION_FIX(ocd->ocd_version),
912                                         LUSTRE_VERSION_STRING);
913                                 ptlrpc_deactivate_import(imp);
914                                 IMPORT_SET_STATE(imp, LUSTRE_IMP_CLOSED);
915                         }
916                         RETURN(-EPROTO);
917                 }
918
919                 ptlrpc_maybe_ping_import_soon(imp);
920
921                 CDEBUG(D_HA, "recovery of %s on %s failed (%d)\n",
922                        obd2cli_tgt(imp->imp_obd),
923                        (char *)imp->imp_connection->c_remote_uuid.uuid, rc);
924         }
925         
926         spin_lock(&imp->imp_lock);
927         imp->imp_last_recon = 0;
928         spin_unlock(&imp->imp_lock);
929
930         cfs_waitq_signal(&imp->imp_recovery_waitq);
931         RETURN(rc);
932 }
933
934 static int completed_replay_interpret(struct ptlrpc_request *req,
935                                     void * data, int rc)
936 {
937         ENTRY;
938         atomic_dec(&req->rq_import->imp_replay_inflight);
939         if (req->rq_status == 0) {
940                 ptlrpc_import_recovery_state_machine(req->rq_import);
941         } else {
942                 CDEBUG(D_HA, "%s: LAST_REPLAY message error: %d, "
943                        "reconnecting\n",
944                        req->rq_import->imp_obd->obd_name, req->rq_status);
945                 ptlrpc_connect_import(req->rq_import, NULL);
946         }
947
948         RETURN(0);
949 }
950
951 static int signal_completed_replay(struct obd_import *imp)
952 {
953         struct ptlrpc_request *req;
954         ENTRY;
955
956         LASSERT(atomic_read(&imp->imp_replay_inflight) == 0);
957         atomic_inc(&imp->imp_replay_inflight);
958
959         req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING, LUSTRE_OBD_VERSION,
960                                         OBD_PING);
961         if (req == NULL) {
962                 atomic_dec(&imp->imp_replay_inflight);
963                 RETURN(-ENOMEM);
964         }
965
966         ptlrpc_request_set_replen(req);
967         req->rq_send_state = LUSTRE_IMP_REPLAY_WAIT;
968         lustre_msg_add_flags(req->rq_reqmsg, 
969                              MSG_LOCK_REPLAY_DONE | MSG_REQ_REPLAY_DONE);
970         req->rq_timeout *= 3;
971         req->rq_interpret_reply = completed_replay_interpret;
972
973         ptlrpcd_add_req(req);
974         RETURN(0);
975 }
976
977 #ifdef __KERNEL__
978 static int ptlrpc_invalidate_import_thread(void *data)
979 {
980         struct obd_import *imp = data;
981
982         ENTRY;
983
984         ptlrpc_daemonize("ll_imp_inval");
985         
986         CDEBUG(D_HA, "thread invalidate import %s to %s@%s\n",
987                imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd),
988                imp->imp_connection->c_remote_uuid.uuid);
989
990         ptlrpc_invalidate_import(imp);
991
992         if (obd_dump_on_eviction) {
993                 CERROR("dump the log upon eviction\n");
994                 libcfs_debug_dumplog();
995         }
996
997         IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
998         ptlrpc_import_recovery_state_machine(imp);
999
1000         RETURN(0);
1001 }
1002 #endif
1003
1004 int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
1005 {
1006         int rc = 0;
1007         int inflight;
1008         char *target_start;
1009         int target_len;
1010
1011         ENTRY;
1012         if (imp->imp_state == LUSTRE_IMP_EVICTED) {
1013                 deuuidify(obd2cli_tgt(imp->imp_obd), NULL,
1014                           &target_start, &target_len);
1015                 /* Don't care about MGC eviction */
1016                 if (strcmp(imp->imp_obd->obd_type->typ_name,
1017                            LUSTRE_MGC_NAME) != 0) {
1018                         LCONSOLE_ERROR_MSG(0x167, "This client was evicted by "
1019                                            "%.*s; in progress operations using "
1020                                            "this service will fail.\n",
1021                                            target_len, target_start);
1022                 }
1023                 CDEBUG(D_HA, "evicted from %s@%s; invalidating\n",
1024                        obd2cli_tgt(imp->imp_obd),
1025                        imp->imp_connection->c_remote_uuid.uuid);
1026
1027 #ifdef __KERNEL__
1028                 rc = cfs_kernel_thread(ptlrpc_invalidate_import_thread, imp,
1029                                        CLONE_VM | CLONE_FILES);
1030                 if (rc < 0)
1031                         CERROR("error starting invalidate thread: %d\n", rc);
1032                 else
1033                         rc = 0;
1034                 RETURN(rc);
1035 #else
1036                 ptlrpc_invalidate_import(imp);
1037
1038                 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
1039 #endif
1040         }
1041
1042         if (imp->imp_state == LUSTRE_IMP_REPLAY) {
1043                 CDEBUG(D_HA, "replay requested by %s\n",
1044                        obd2cli_tgt(imp->imp_obd));
1045                 rc = ptlrpc_replay_next(imp, &inflight);
1046                 if (inflight == 0 &&
1047                     atomic_read(&imp->imp_replay_inflight) == 0) {
1048                         IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS);
1049                         rc = ldlm_replay_locks(imp);
1050                         if (rc)
1051                                 GOTO(out, rc);
1052                 }
1053                 rc = 0;
1054         }
1055
1056         if (imp->imp_state == LUSTRE_IMP_REPLAY_LOCKS) {
1057                 if (atomic_read(&imp->imp_replay_inflight) == 0) {
1058                         IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_WAIT);
1059                         rc = signal_completed_replay(imp);
1060                         if (rc)
1061                                 GOTO(out, rc);
1062                 }
1063
1064         }
1065
1066         if (imp->imp_state == LUSTRE_IMP_REPLAY_WAIT) {
1067                 if (atomic_read(&imp->imp_replay_inflight) == 0) {
1068                         IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
1069                 }
1070         }
1071
1072         if (imp->imp_state == LUSTRE_IMP_RECOVER) {
1073                 CDEBUG(D_HA, "reconnected to %s@%s\n",
1074                        obd2cli_tgt(imp->imp_obd),
1075                        imp->imp_connection->c_remote_uuid.uuid);
1076
1077                 rc = ptlrpc_resend(imp);
1078                 if (rc)
1079                         GOTO(out, rc);
1080                 IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
1081                 ptlrpc_activate_import(imp);
1082
1083                 deuuidify(obd2cli_tgt(imp->imp_obd), NULL,
1084                           &target_start, &target_len);
1085                 LCONSOLE_INFO("%s: Connection restored to service %.*s "
1086                               "using nid %s.\n", imp->imp_obd->obd_name,
1087                               target_len, target_start,
1088                               libcfs_nid2str(imp->imp_connection->c_peer.nid));
1089         }
1090
1091         if (imp->imp_state == LUSTRE_IMP_FULL) {
1092                 cfs_waitq_signal(&imp->imp_recovery_waitq);
1093                 ptlrpc_wake_delayed(imp);
1094         }
1095
1096 out:
1097         RETURN(rc);
1098 }
1099
1100 static int back_to_sleep(void *unused)
1101 {
1102         return 0;
1103 }
1104
1105 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose)
1106 {
1107         struct ptlrpc_request *req;
1108         int rq_opc, rc = 0;
1109         int nowait = imp->imp_obd->obd_force;
1110         ENTRY;
1111
1112         if (nowait)
1113                 GOTO(set_state, rc);
1114
1115         switch (imp->imp_connect_op) {
1116         case OST_CONNECT: rq_opc = OST_DISCONNECT; break;
1117         case MDS_CONNECT: rq_opc = MDS_DISCONNECT; break;
1118         case MGS_CONNECT: rq_opc = MGS_DISCONNECT; break;
1119         default:
1120                 CERROR("don't know how to disconnect from %s (connect_op %d)\n",
1121                        obd2cli_tgt(imp->imp_obd), imp->imp_connect_op);
1122                 RETURN(-EINVAL);
1123         }
1124
1125         if (ptlrpc_import_in_recovery(imp)) {
1126                 struct l_wait_info lwi;
1127                 cfs_duration_t timeout;
1128                 if (imp->imp_server_timeout)
1129                         timeout = cfs_time_seconds(obd_timeout / 2);
1130                 else
1131                         timeout = cfs_time_seconds(obd_timeout);
1132                 
1133                 timeout = MAX(timeout * HZ, 1);
1134                 
1135                 lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), 
1136                                        back_to_sleep, LWI_ON_SIGNAL_NOOP, NULL);
1137                 rc = l_wait_event(imp->imp_recovery_waitq,
1138                                   !ptlrpc_import_in_recovery(imp), &lwi);
1139
1140         }
1141
1142         spin_lock(&imp->imp_lock);
1143         if (imp->imp_state != LUSTRE_IMP_FULL)
1144                 GOTO(out, 0);
1145
1146         spin_unlock(&imp->imp_lock);
1147
1148         req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_DISCONNECT,
1149                                         LUSTRE_OBD_VERSION, rq_opc);
1150         if (req) {
1151                 /* We are disconnecting, do not retry a failed DISCONNECT rpc if
1152                  * it fails.  We can get through the above with a down server
1153                  * if the client doesn't know the server is gone yet. */
1154                 req->rq_no_resend = 1;
1155 #ifdef CRAY_XT3
1156                 req->rq_timeout = obd_timeout / 3;
1157 #else
1158                 req->rq_timeout = 5;
1159 #endif
1160                 IMPORT_SET_STATE(imp, LUSTRE_IMP_CONNECTING);
1161                 req->rq_send_state =  LUSTRE_IMP_CONNECTING;
1162                 ptlrpc_request_set_replen(req);
1163                 rc = ptlrpc_queue_wait(req);
1164                 ptlrpc_req_finished(req);
1165         }
1166
1167 set_state:
1168         spin_lock(&imp->imp_lock);
1169 out:
1170         if (noclose) 
1171                 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
1172         else
1173                 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED);
1174         memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle));
1175         imp->imp_conn_cnt = 0;
1176         imp->imp_last_recon = 0;
1177         spin_unlock(&imp->imp_lock);
1178
1179         RETURN(rc);
1180 }
1181