Whamcloud - gitweb
fix forever blocking umount on error
[fs/lustre-release.git] / lustre / ptlrpc / pinger.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Portal-RPC reconnection and replay operations, for use in recovery.
5  *
6  *  Copyright (c) 2003 Cluster File Systems, Inc.
7  *   Authors: Phil Schwan <phil@clusterfs.com>
8  *            Mike Shaver <shaver@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28
29 #ifndef __KERNEL__
30 #include <liblustre.h>
31 #else
32 #define DEBUG_SUBSYSTEM S_RPC
33 #endif
34
35 #include <obd_support.h>
36 #include <obd_class.h>
37 #include "ptlrpc_internal.h"
38
39 struct semaphore pinger_sem;
40 static struct list_head pinger_imports = CFS_LIST_HEAD_INIT(pinger_imports);
41
42 int ptlrpc_ping(struct obd_import *imp)
43 {
44         struct ptlrpc_request *req;
45         int rc = 0;
46         ENTRY;
47
48         req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING, 1, NULL, NULL);
49         if (req) {
50                 DEBUG_REQ(D_INFO, req, "pinging %s->%s",
51                           imp->imp_obd->obd_uuid.uuid,
52                           obd2cli_tgt(imp->imp_obd));
53                 req->rq_no_resend = req->rq_no_delay = 1;
54                 ptlrpc_req_set_repsize(req, 1, NULL);
55                 ptlrpcd_add_req(req);
56         } else {
57                 CERROR("OOM trying to ping %s->%s\n",
58                        imp->imp_obd->obd_uuid.uuid,
59                        obd2cli_tgt(imp->imp_obd));
60                 rc = -ENOMEM;
61         }
62
63         RETURN(rc);
64 }
65
66 static void ptlrpc_update_next_ping(struct obd_import *imp)
67 {
68         imp->imp_next_ping = cfs_time_shift(
69                                 (imp->imp_state == LUSTRE_IMP_DISCON ?
70                                  RECONNECT_INTERVAL : PING_INTERVAL));
71 }
72
73 void ptlrpc_ping_import_soon(struct obd_import *imp)
74 {
75         imp->imp_next_ping = cfs_time_current();
76 }
77
78 #ifdef __KERNEL__
79 static int ptlrpc_pinger_main(void *arg)
80 {
81         struct ptlrpc_svc_data *data = (struct ptlrpc_svc_data *)arg;
82         struct ptlrpc_thread *thread = data->thread;
83         ENTRY;
84
85         cfs_daemonize(data->name);
86
87         /* Record that the thread is running */
88         thread->t_flags = SVC_RUNNING;
89         cfs_waitq_signal(&thread->t_ctl_waitq);
90
91         /* And now, loop forever, pinging as needed. */
92         while (1) {
93                 cfs_time_t this_ping = cfs_time_current();
94                 struct l_wait_info lwi;
95                 cfs_duration_t time_to_next_ping;
96                 struct list_head *iter;
97
98                 mutex_down(&pinger_sem);
99                 list_for_each(iter, &pinger_imports) {
100                         struct obd_import *imp =
101                                 list_entry(iter, struct obd_import,
102                                            imp_pinger_chain);
103                         int force, level;
104
105                         spin_lock(&imp->imp_lock);
106                         level = imp->imp_state;
107                         force = imp->imp_force_verify;
108                         imp->imp_force_verify = 0;
109                         spin_unlock(&imp->imp_lock);
110
111                         CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_RPCTRACE,
112                                "level %s/%u force %u deactive %u pingable %u\n",
113                                ptlrpc_import_state_name(level), level,
114                                force, imp->imp_deactive, imp->imp_pingable);
115
116                         if (force ||
117                             /* if the next ping is within, say, 5 jiffies from
118                                now, go ahead and ping. See note below. */
119                             cfs_time_aftereq(this_ping, 
120                                              imp->imp_next_ping - 5 * CFS_TICK)) {
121                                 if (level == LUSTRE_IMP_DISCON &&
122                                     !imp->imp_deactive) {
123                                         /* wait at least a timeout before
124                                            trying recovery again. */
125                                         imp->imp_next_ping = cfs_time_shift(obd_timeout);
126                                         ptlrpc_initiate_recovery(imp);
127                                 } else if (level != LUSTRE_IMP_FULL ||
128                                          imp->imp_obd->obd_no_recov ||
129                                          imp->imp_deactive) {
130                                         CDEBUG(D_HA, "not pinging %s "
131                                                "(in recovery: %s or recovery "
132                                                "disabled: %u/%u)\n",
133                                                obd2cli_tgt(imp->imp_obd),
134                                                ptlrpc_import_state_name(level),
135                                                imp->imp_deactive,
136                                                imp->imp_obd->obd_no_recov);
137                                 } else if (imp->imp_pingable || force) {
138                                         ptlrpc_ping(imp);
139                                 }
140                         } else {
141                                 if (!imp->imp_pingable)
142                                         continue;
143                                 CDEBUG(D_INFO,
144                                        "don't need to ping %s ("CFS_TIME_T
145                                        " > "CFS_TIME_T")\n",
146                                        obd2cli_tgt(imp->imp_obd),
147                                        imp->imp_next_ping, this_ping);
148                         }
149
150                         /* obd_timeout might have changed */
151                         if (cfs_time_after(imp->imp_next_ping,
152                                            cfs_time_add(this_ping, 
153                                                         cfs_time_seconds(PING_INTERVAL))))
154                                 ptlrpc_update_next_ping(imp);
155                 }
156                 mutex_up(&pinger_sem);
157
158                 /* Wait until the next ping time, or until we're stopped. */
159                 time_to_next_ping = cfs_time_sub(cfs_time_add(this_ping, 
160                                                               cfs_time_seconds(PING_INTERVAL)), 
161                                                  cfs_time_current());
162
163                 /* The ping sent by ptlrpc_send_rpc may get sent out
164                    say .01 second after this.
165                    ptlrpc_pinger_eending_on_import will then set the
166                    next ping time to next_ping + .01 sec, which means
167                    we will SKIP the next ping at next_ping, and the
168                    ping will get sent 2 timeouts from now!  Beware. */
169                 CDEBUG(D_INFO, "next ping in "CFS_DURATION_T" ("CFS_TIME_T")\n", 
170                                time_to_next_ping, 
171                                cfs_time_add(this_ping, cfs_time_seconds(PING_INTERVAL)));
172                 if (time_to_next_ping > 0) {
173                         lwi = LWI_TIMEOUT(max_t(cfs_duration_t, time_to_next_ping, cfs_time_seconds(1)),
174                                           NULL, NULL);
175                         l_wait_event(thread->t_ctl_waitq,
176                                      thread->t_flags & (SVC_STOPPING|SVC_EVENT),
177                                      &lwi);
178                         if (thread->t_flags & SVC_STOPPING) {
179                                 thread->t_flags &= ~SVC_STOPPING;
180                                 EXIT;
181                                 break;
182                         } else if (thread->t_flags & SVC_EVENT) {
183                                 /* woken after adding import to reset timer */
184                                 thread->t_flags &= ~SVC_EVENT;
185                         }
186                 }
187         }
188
189         thread->t_flags = SVC_STOPPED;
190         cfs_waitq_signal(&thread->t_ctl_waitq);
191
192         CDEBUG(D_NET, "pinger thread exiting, process %d\n", cfs_curproc_pid());
193         return 0;
194 }
195
196 static struct ptlrpc_thread *pinger_thread = NULL;
197
198 int ptlrpc_start_pinger(void)
199 {
200         struct l_wait_info lwi = { 0 };
201         struct ptlrpc_svc_data d;
202         int rc;
203 #ifndef ENABLE_PINGER
204         return 0;
205 #endif
206         ENTRY;
207
208         if (pinger_thread != NULL)
209                 RETURN(-EALREADY);
210
211         OBD_ALLOC(pinger_thread, sizeof(*pinger_thread));
212         if (pinger_thread == NULL)
213                 RETURN(-ENOMEM);
214         cfs_waitq_init(&pinger_thread->t_ctl_waitq);
215
216         d.name = "ll_ping";
217         d.thread = pinger_thread;
218
219         /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
220          * just drop the VM and FILES in ptlrpc_daemonize() right away. */
221         rc = cfs_kernel_thread(ptlrpc_pinger_main, &d, CLONE_VM | CLONE_FILES);
222         if (rc < 0) {
223                 CERROR("cannot start thread: %d\n", rc);
224                 OBD_FREE(pinger_thread, sizeof(*pinger_thread));
225                 pinger_thread = NULL;
226                 RETURN(rc);
227         }
228         l_wait_event(pinger_thread->t_ctl_waitq,
229                      pinger_thread->t_flags & SVC_RUNNING, &lwi);
230
231         RETURN(0);
232 }
233
234 int ptlrpc_stop_pinger(void)
235 {
236         struct l_wait_info lwi = { 0 };
237         int rc = 0;
238 #ifndef ENABLE_PINGER
239         return 0;
240 #endif
241         ENTRY;
242
243         if (pinger_thread == NULL)
244                 RETURN(-EALREADY);
245         mutex_down(&pinger_sem);
246         pinger_thread->t_flags = SVC_STOPPING;
247         cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
248         mutex_up(&pinger_sem);
249
250         l_wait_event(pinger_thread->t_ctl_waitq,
251                      (pinger_thread->t_flags & SVC_STOPPED), &lwi);
252
253         OBD_FREE(pinger_thread, sizeof(*pinger_thread));
254         pinger_thread = NULL;
255         RETURN(rc);
256 }
257
258 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
259 {
260         ptlrpc_update_next_ping(imp);
261 }
262
263 int ptlrpc_pinger_add_import(struct obd_import *imp)
264 {
265         ENTRY;
266         if (!list_empty(&imp->imp_pinger_chain))
267                 RETURN(-EALREADY);
268
269         mutex_down(&pinger_sem);
270         CDEBUG(D_HA, "adding pingable import %s->%s\n",
271                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
272         /* if we add to pinger we want recovery on this import */
273         imp->imp_obd->obd_no_recov = 0;
274
275         ptlrpc_update_next_ping(imp);
276         /* XXX sort, blah blah */
277         list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
278         class_import_get(imp);
279
280         ptlrpc_pinger_wake_up();
281         mutex_up(&pinger_sem);
282
283         RETURN(0);
284 }
285
286 int ptlrpc_pinger_del_import(struct obd_import *imp)
287 {
288         ENTRY;
289         if (list_empty(&imp->imp_pinger_chain))
290                 RETURN(-ENOENT);
291
292         mutex_down(&pinger_sem);
293         list_del_init(&imp->imp_pinger_chain);
294         CDEBUG(D_HA, "removing pingable import %s->%s\n",
295                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
296         /* if we remove from pinger we don't want recovery on this import */
297         imp->imp_obd->obd_no_recov = 1;
298         class_import_put(imp);
299         mutex_up(&pinger_sem);
300         RETURN(0);
301 }
302
303 void ptlrpc_pinger_wake_up()
304 {
305 #ifdef ENABLE_PINGER
306         pinger_thread->t_flags |= SVC_EVENT;
307         cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
308 #endif
309 }
310
311 /* Ping evictor thread */
312 #define PET_READY     1
313 #define PET_TERMINATE 2
314
315 static int               pet_refcount = 0;
316 static int               pet_state;
317 static wait_queue_head_t pet_waitq;
318 static struct obd_export *pet_exp = NULL;
319 static spinlock_t        pet_lock = SPIN_LOCK_UNLOCKED;
320
321 int ping_evictor_wake(struct obd_export *exp)
322 {
323         spin_lock(&pet_lock);
324         if (pet_exp) {
325                 /* eventually the new obd will call here again. */
326                 spin_unlock(&pet_lock);
327                 return 1;
328         }
329
330         /* We have to make sure the obd isn't destroyed between now and when
331          * the ping evictor runs.  We'll take a reference here, and drop it
332          * when we finish in the evictor.  We don't really care about this
333          * export in particular; we just need one to keep the obd alive. */
334         pet_exp = class_export_get(exp);
335         spin_unlock(&pet_lock);
336
337         wake_up(&pet_waitq);
338         return 0;
339 }
340
341 static int ping_evictor_main(void *arg)
342 {
343         struct obd_device *obd;
344         struct obd_export *exp;
345         struct l_wait_info lwi = { 0 };
346         time_t expire_time;
347         ENTRY;
348
349         ptlrpc_daemonize("ll_evictor");
350
351         CDEBUG(D_HA, "Starting Ping Evictor\n");
352         pet_exp = NULL;
353         pet_state = PET_READY;
354         while (1) {
355                 l_wait_event(pet_waitq, pet_exp ||
356                              (pet_state == PET_TERMINATE), &lwi);
357                 if (pet_state == PET_TERMINATE)
358                         break;
359
360                 /* we only get here if pet_exp != NULL, and the end of this
361                  * loop is the only place which sets it NULL again, so lock
362                  * is not strictly necessary. */
363                 spin_lock(&pet_lock);
364                 obd = pet_exp->exp_obd;
365                 spin_unlock(&pet_lock);
366
367                 expire_time = CURRENT_SECONDS - (3 * obd_timeout / 2);
368
369                 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
370                        obd->obd_name, expire_time);
371
372                 /* Exports can't be deleted out of the list while we hold
373                  * the obd lock (class_unlink_export), which means we can't
374                  * lose the last ref on the export.  If they've already been
375                  * removed from the list, we won't find them here. */
376                 spin_lock(&obd->obd_dev_lock);
377                 while (!list_empty(&obd->obd_exports_timed)) {
378                         exp = list_entry(obd->obd_exports_timed.next,
379                                          struct obd_export,exp_obd_chain_timed);
380                         if (expire_time > exp->exp_last_request_time) {
381                                 class_export_get(exp);
382                                 spin_unlock(&obd->obd_dev_lock);
383                                 LCONSOLE_WARN("%s: haven't heard from client %s"
384                                               " (at %s) in %ld seconds. I think"
385                                               " it's dead, and I am evicting"
386                                               " it.\n", obd->obd_name,
387                                               obd_uuid2str(&exp->exp_client_uuid),
388                                               obd_export_nid2str(exp),
389                                               (long)(CURRENT_SECONDS -
390                                                      exp->exp_last_request_time));
391                                 CDEBUG(D_HA, "Last request was at %ld\n",
392                                        exp->exp_last_request_time);
393                                 class_fail_export(exp);
394                                 class_export_put(exp);
395                                 spin_lock(&obd->obd_dev_lock);
396                         } else {
397                                 /* List is sorted, so everyone below is ok */
398                                 break;
399                         }
400                 }
401                 spin_unlock(&obd->obd_dev_lock);
402
403                 class_export_put(pet_exp);
404
405                 spin_lock(&pet_lock);
406                 pet_exp = NULL;
407                 spin_unlock(&pet_lock);
408         }
409         CDEBUG(D_HA, "Exiting Ping Evictor\n");
410
411         RETURN(0);
412 }
413
414 void ping_evictor_start(void)
415 {
416         int rc;
417
418         if (++pet_refcount > 1)
419                 return;
420
421         init_waitqueue_head(&pet_waitq);
422
423         rc = cfs_kernel_thread(ping_evictor_main, NULL, CLONE_VM | CLONE_FILES);
424         if (rc < 0) {
425                 pet_refcount--;
426                 CERROR("Cannot start ping evictor thread: %d\n", rc);
427         }
428 }
429 EXPORT_SYMBOL(ping_evictor_start);
430
431 void ping_evictor_stop(void)
432 {
433         if (--pet_refcount > 0)
434                 return;
435
436         pet_state = PET_TERMINATE;
437         wake_up(&pet_waitq);
438 }
439 EXPORT_SYMBOL(ping_evictor_stop);
440 #else /* !__KERNEL__ */
441
442 /* XXX
443  * the current implementation of pinger in liblustre is not optimized
444  */
445
446 #ifdef ENABLE_PINGER
447 static struct pinger_data {
448         int             pd_recursion;
449         cfs_time_t      pd_this_ping;   /* jiffies */
450         cfs_time_t      pd_next_ping;   /* jiffies */
451         struct ptlrpc_request_set *pd_set;
452 } pinger_args;
453
454 static int pinger_check_rpcs(void *arg)
455 {
456         cfs_time_t curtime = cfs_time_current();
457         struct ptlrpc_request *req;
458         struct ptlrpc_request_set *set;
459         struct list_head *iter;
460         struct pinger_data *pd = &pinger_args;
461         int rc;
462
463         /* prevent recursion */
464         if (pd->pd_recursion++) {
465                 CDEBUG(D_HA, "pinger: recursion! quit\n");
466                 LASSERT(pd->pd_set);
467                 pd->pd_recursion--;
468                 return 0;
469         }
470
471         /* have we reached ping point? */
472         if (!pd->pd_set && time_before(curtime, pd->pd_next_ping)) {
473                 pd->pd_recursion--;
474                 return 0;
475         }
476
477         /* if we have rpc_set already, continue processing it */
478         if (pd->pd_set) {
479                 LASSERT(pd->pd_this_ping);
480                 set = pd->pd_set;
481                 goto do_check_set;
482         }
483
484         pd->pd_this_ping = curtime;
485         pd->pd_set = ptlrpc_prep_set();
486         if (pd->pd_set == NULL)
487                 goto out;
488         set = pd->pd_set;
489
490         /* add rpcs into set */
491         mutex_down(&pinger_sem);
492         list_for_each(iter, &pinger_imports) {
493                 struct obd_import *imp =
494                         list_entry(iter, struct obd_import, imp_pinger_chain);
495                 int generation, level;
496
497                 if (cfs_time_aftereq(pd->pd_this_ping, 
498                                      imp->imp_next_ping - 5 * CFS_TICK)) {
499                         /* Add a ping. */
500                         spin_lock(&imp->imp_lock);
501                         generation = imp->imp_generation;
502                         level = imp->imp_state;
503                         spin_unlock(&imp->imp_lock);
504
505                         if (level != LUSTRE_IMP_FULL) {
506                                 CDEBUG(D_HA,
507                                        "not pinging %s (in recovery)\n",
508                                        obd2cli_tgt(imp->imp_obd));
509                                 continue;
510                         }
511
512                         req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING,
513                                               1, NULL, NULL);
514                         if (!req) {
515                                 CERROR("out of memory\n");
516                                 break;
517                         }
518                         req->rq_no_resend = 1;
519                         ptlrpc_req_set_repsize(req, 1, NULL);
520                         req->rq_send_state = LUSTRE_IMP_FULL;
521                         req->rq_phase = RQ_PHASE_RPC;
522                         req->rq_import_generation = generation;
523                         ptlrpc_set_add_req(set, req);
524                 } else {
525                         CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
526                                " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
527                                imp->imp_next_ping, pd->pd_this_ping);
528                 }
529         }
530         pd->pd_this_ping = curtime;
531         mutex_up(&pinger_sem);
532
533         /* Might be empty, that's OK. */
534         if (set->set_remaining == 0)
535                 CDEBUG(D_RPCTRACE, "nothing to ping\n");
536
537         list_for_each(iter, &set->set_requests) {
538                 struct ptlrpc_request *req =
539                         list_entry(iter, struct ptlrpc_request,
540                                    rq_set_chain);
541                 DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
542                           req->rq_import->imp_obd->obd_uuid.uuid,
543                           obd2cli_tgt(req->rq_import->imp_obd));
544                 (void)ptl_send_rpc(req, 0);
545         }
546
547 do_check_set:
548         rc = ptlrpc_check_set(set);
549
550         /* not finished, and we are not expired, simply return */
551         if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
552                                             cfs_time_seconds(PING_INTERVAL)))) {
553                 CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
554                 pd->pd_recursion--;
555                 return 0;
556         }
557
558         /* Expire all the requests that didn't come back. */
559         mutex_down(&pinger_sem);
560         list_for_each(iter, &set->set_requests) {
561                 req = list_entry(iter, struct ptlrpc_request,
562                                  rq_set_chain);
563
564                 if (req->rq_phase == RQ_PHASE_COMPLETE)
565                         continue;
566
567                 req->rq_phase = RQ_PHASE_COMPLETE;
568                 atomic_dec(&req->rq_import->imp_inflight);
569                 set->set_remaining--;
570                 /* If it was disconnected, don't sweat it. */
571                 if (list_empty(&req->rq_import->imp_pinger_chain)) {
572                         ptlrpc_unregister_reply(req);
573                         continue;
574                 }
575
576                 CDEBUG(D_RPCTRACE, "pinger initiate expire_one_request\n");
577                 ptlrpc_expire_one_request(req);
578         }
579         mutex_up(&pinger_sem);
580
581         ptlrpc_set_destroy(set);
582         pd->pd_set = NULL;
583
584 out:
585         pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
586                                         cfs_time_seconds(PING_INTERVAL));
587         pd->pd_this_ping = 0; /* XXX for debug */
588
589         CDEBUG(D_INFO, "finished a round ping\n");
590         pd->pd_recursion--;
591         return 0;
592 }
593
594 static void *pinger_callback = NULL;
595 #endif /* ENABLE_PINGER */
596
597 int ptlrpc_start_pinger(void)
598 {
599 #ifdef ENABLE_PINGER
600         memset(&pinger_args, 0, sizeof(pinger_args));
601         pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
602                                                            &pinger_check_rpcs,
603                                                            &pinger_args);
604 #endif
605         return 0;
606 }
607
608 int ptlrpc_stop_pinger(void)
609 {
610 #ifdef ENABLE_PINGER
611         if (pinger_callback)
612                 liblustre_deregister_wait_callback(pinger_callback);
613 #endif
614         return 0;
615 }
616
617 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
618 {
619 #ifdef ENABLE_PINGER
620         mutex_down(&pinger_sem);
621         ptlrpc_update_next_ping(imp);
622         if (pinger_args.pd_set == NULL &&
623             time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
624                 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
625                         imp->imp_next_ping, cfs_time_current());
626                 pinger_args.pd_next_ping = imp->imp_next_ping;
627         }
628         mutex_up(&pinger_sem);
629 #endif
630 }
631
632 int ptlrpc_pinger_add_import(struct obd_import *imp)
633 {
634         ENTRY;
635         if (!list_empty(&imp->imp_pinger_chain))
636                 RETURN(-EALREADY);
637
638         CDEBUG(D_HA, "adding pingable import %s->%s\n",
639                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
640         ptlrpc_pinger_sending_on_import(imp);
641
642         mutex_down(&pinger_sem);
643         list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
644         class_import_get(imp);
645         mutex_up(&pinger_sem);
646
647         RETURN(0);
648 }
649
650 int ptlrpc_pinger_del_import(struct obd_import *imp)
651 {
652         ENTRY;
653         if (list_empty(&imp->imp_pinger_chain))
654                 RETURN(-ENOENT);
655
656         mutex_down(&pinger_sem);
657         list_del_init(&imp->imp_pinger_chain);
658         CDEBUG(D_HA, "removing pingable import %s->%s\n",
659                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
660         class_import_put(imp);
661         mutex_up(&pinger_sem);
662         RETURN(0);
663 }
664
665 void ptlrpc_pinger_wake_up()
666 {
667 #ifdef ENABLE_PINGER
668         ENTRY;
669         /* XXX force pinger to run, if needed */
670         struct obd_import *imp;
671         list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
672                 CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
673                        imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
674 #ifdef ENABLE_LIBLUSTRE_RECOVERY
675                 if (imp->imp_state == LUSTRE_IMP_DISCON && !imp->imp_deactive)
676 #else
677                 /*XXX only recover for the initial connection */
678                 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
679                     imp->imp_state == LUSTRE_IMP_DISCON && !imp->imp_deactive)
680 #endif
681                         ptlrpc_initiate_recovery(imp);
682                 else if (imp->imp_state != LUSTRE_IMP_FULL)
683                         CDEBUG(D_HA, "Refused to recover import %s->%s "
684                                      "state %d, deactive %d\n",
685                                      imp->imp_obd->obd_uuid.uuid,
686                                      obd2cli_tgt(imp->imp_obd), imp->imp_state,
687                                      imp->imp_deactive);
688         }
689 #endif
690         EXIT;
691 }
692 #endif /* !__KERNEL__ */