Whamcloud - gitweb
be3840ba83a6fb0eb60aa310a04dad18479b5ddd
[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_HA,
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         ptlrpc_update_next_ping(imp);
273         /* XXX sort, blah blah */
274         list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
275         class_import_get(imp);
276
277         ptlrpc_pinger_wake_up();
278         mutex_up(&pinger_sem);
279
280         RETURN(0);
281 }
282
283 int ptlrpc_pinger_del_import(struct obd_import *imp)
284 {
285         ENTRY;
286         if (list_empty(&imp->imp_pinger_chain))
287                 RETURN(-ENOENT);
288
289         mutex_down(&pinger_sem);
290         list_del_init(&imp->imp_pinger_chain);
291         CDEBUG(D_HA, "removing pingable import %s->%s\n",
292                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
293         class_import_put(imp);
294         mutex_up(&pinger_sem);
295         RETURN(0);
296 }
297
298 void ptlrpc_pinger_wake_up()
299 {
300 #ifdef ENABLE_PINGER
301         pinger_thread->t_flags |= SVC_EVENT;
302         cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
303 #endif
304 }
305
306 /* Ping evictor thread */
307 #define PET_READY     1
308 #define PET_TERMINATE 2
309
310 static int               pet_refcount = 0;
311 static int               pet_state;
312 static wait_queue_head_t pet_waitq;
313 static struct obd_export *pet_exp = NULL;
314 static spinlock_t        pet_lock = SPIN_LOCK_UNLOCKED;
315
316 int ping_evictor_wake(struct obd_export *exp)
317 {
318         spin_lock(&pet_lock);
319         if (pet_exp) {
320                 /* eventually the new obd will call here again. */
321                 spin_unlock(&pet_lock);
322                 return 1;
323         }
324
325         /* We have to make sure the obd isn't destroyed between now and when
326          * the ping evictor runs.  We'll take a reference here, and drop it
327          * when we finish in the evictor.  We don't really care about this
328          * export in particular; we just need one to keep the obd alive. */
329         pet_exp = class_export_get(exp);
330         spin_unlock(&pet_lock);
331
332         wake_up(&pet_waitq);
333         return 0;
334 }
335
336 static int ping_evictor_main(void *arg)
337 {
338         struct obd_device *obd;
339         struct obd_export *exp;
340         struct l_wait_info lwi = { 0 };
341         time_t expire_time;
342         ENTRY;
343
344         ptlrpc_daemonize("ll_evictor");
345
346         CDEBUG(D_HA, "Starting Ping Evictor\n");
347         pet_exp = NULL;
348         pet_state = PET_READY;
349         while (1) {
350                 l_wait_event(pet_waitq, pet_exp ||
351                              (pet_state == PET_TERMINATE), &lwi);
352                 if (pet_state == PET_TERMINATE)
353                         break;
354
355                 /* we only get here if pet_exp != NULL, and the end of this
356                  * loop is the only place which sets it NULL again, so lock
357                  * is not strictly necessary. */
358                 spin_lock(&pet_lock);
359                 obd = pet_exp->exp_obd;
360                 spin_unlock(&pet_lock);
361
362                 expire_time = CURRENT_SECONDS - (3 * obd_timeout / 2);
363
364                 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
365                        obd->obd_name, expire_time);
366
367                 /* Exports can't be deleted out of the list while we hold
368                  * the obd lock (class_unlink_export), which means we can't
369                  * lose the last ref on the export.  If they've already been
370                  * removed from the list, we won't find them here. */
371                 spin_lock(&obd->obd_dev_lock);
372                 while (!list_empty(&obd->obd_exports_timed)) {
373                         exp = list_entry(obd->obd_exports_timed.next,
374                                          struct obd_export,exp_obd_chain_timed);
375                         if (expire_time > exp->exp_last_request_time) {
376                                 class_export_get(exp);
377                                 spin_unlock(&obd->obd_dev_lock);
378                                 LCONSOLE_WARN("%s: haven't heard from client %s"
379                                               " (at %s) in %ld seconds. I think"
380                                               " it's dead, and I am evicting"
381                                               " it.\n", obd->obd_name,
382                                               obd_uuid2str(&exp->exp_client_uuid),
383                                               obd_export_nid2str(exp),
384                                               (long)(CURRENT_SECONDS -
385                                                      exp->exp_last_request_time));
386                                 CDEBUG(D_HA, "Last request was at %ld\n",
387                                        exp->exp_last_request_time);
388                                 class_fail_export(exp);
389                                 class_export_put(exp);
390                                 spin_lock(&obd->obd_dev_lock);
391                         } else {
392                                 /* List is sorted, so everyone below is ok */
393                                 break;
394                         }
395                 }
396                 spin_unlock(&obd->obd_dev_lock);
397
398                 class_export_put(pet_exp);
399
400                 spin_lock(&pet_lock);
401                 pet_exp = NULL;
402                 spin_unlock(&pet_lock);
403         }
404         CDEBUG(D_HA, "Exiting Ping Evictor\n");
405
406         RETURN(0);
407 }
408
409 void ping_evictor_start(void)
410 {
411         int rc;
412
413         if (++pet_refcount > 1)
414                 return;
415
416         init_waitqueue_head(&pet_waitq);
417
418         rc = cfs_kernel_thread(ping_evictor_main, NULL, CLONE_VM | CLONE_FILES);
419         if (rc < 0) {
420                 pet_refcount--;
421                 CERROR("Cannot start ping evictor thread: %d\n", rc);
422         }
423 }
424 EXPORT_SYMBOL(ping_evictor_start);
425
426 void ping_evictor_stop(void)
427 {
428         if (--pet_refcount > 0)
429                 return;
430
431         pet_state = PET_TERMINATE;
432         wake_up(&pet_waitq);
433 }
434 EXPORT_SYMBOL(ping_evictor_stop);
435 #else /* !__KERNEL__ */
436
437 /* XXX
438  * the current implementation of pinger in liblustre is not optimized
439  */
440
441 #ifdef ENABLE_PINGER
442 static struct pinger_data {
443         int             pd_recursion;
444         cfs_time_t      pd_this_ping;   /* jiffies */
445         cfs_time_t      pd_next_ping;   /* jiffies */
446         struct ptlrpc_request_set *pd_set;
447 } pinger_args;
448
449 static int pinger_check_rpcs(void *arg)
450 {
451         cfs_time_t curtime = cfs_time_current();
452         struct ptlrpc_request *req;
453         struct ptlrpc_request_set *set;
454         struct list_head *iter;
455         struct pinger_data *pd = &pinger_args;
456         int rc;
457
458         /* prevent recursion */
459         if (pd->pd_recursion++) {
460                 CDEBUG(D_HA, "pinger: recursion! quit\n");
461                 LASSERT(pd->pd_set);
462                 pd->pd_recursion--;
463                 return 0;
464         }
465
466         /* have we reached ping point? */
467         if (!pd->pd_set && time_before(curtime, pd->pd_next_ping)) {
468                 pd->pd_recursion--;
469                 return 0;
470         }
471
472         /* if we have rpc_set already, continue processing it */
473         if (pd->pd_set) {
474                 LASSERT(pd->pd_this_ping);
475                 set = pd->pd_set;
476                 goto do_check_set;
477         }
478
479         pd->pd_this_ping = curtime;
480         pd->pd_set = ptlrpc_prep_set();
481         if (pd->pd_set == NULL)
482                 goto out;
483         set = pd->pd_set;
484
485         /* add rpcs into set */
486         mutex_down(&pinger_sem);
487         list_for_each(iter, &pinger_imports) {
488                 struct obd_import *imp =
489                         list_entry(iter, struct obd_import, imp_pinger_chain);
490                 int generation, level;
491
492                 if (cfs_time_aftereq(pd->pd_this_ping, 
493                                      imp->imp_next_ping - 5 * CFS_TICK)) {
494                         /* Add a ping. */
495                         spin_lock(&imp->imp_lock);
496                         generation = imp->imp_generation;
497                         level = imp->imp_state;
498                         spin_unlock(&imp->imp_lock);
499
500                         if (level != LUSTRE_IMP_FULL) {
501                                 CDEBUG(D_HA,
502                                        "not pinging %s (in recovery)\n",
503                                        obd2cli_tgt(imp->imp_obd));
504                                 continue;
505                         }
506
507                         req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING,
508                                               1, NULL, NULL);
509                         if (!req) {
510                                 CERROR("out of memory\n");
511                                 break;
512                         }
513                         req->rq_no_resend = 1;
514                         ptlrpc_req_set_repsize(req, 1, NULL);
515                         req->rq_send_state = LUSTRE_IMP_FULL;
516                         req->rq_phase = RQ_PHASE_RPC;
517                         req->rq_import_generation = generation;
518                         ptlrpc_set_add_req(set, req);
519                 } else {
520                         CDEBUG(D_HA, "don't need to ping %s ("CFS_TIME_T" > "
521                                CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
522                                imp->imp_next_ping, pd->pd_this_ping);
523                 }
524         }
525         pd->pd_this_ping = curtime;
526         mutex_up(&pinger_sem);
527
528         /* Might be empty, that's OK. */
529         if (set->set_remaining == 0)
530                 CDEBUG(D_HA, "nothing to ping\n");
531
532         list_for_each(iter, &set->set_requests) {
533                 struct ptlrpc_request *req =
534                         list_entry(iter, struct ptlrpc_request,
535                                    rq_set_chain);
536                 DEBUG_REQ(D_HA, req, "pinging %s->%s",
537                           req->rq_import->imp_obd->obd_uuid.uuid,
538                           obd2cli_tgt(req->rq_import->imp_obd));
539                 (void)ptl_send_rpc(req, 0);
540         }
541
542 do_check_set:
543         rc = ptlrpc_check_set(set);
544
545         /* not finished, and we are not expired, simply return */
546         if (!rc && cfs_time_before(curtime, 
547                                    cfs_time_add(pd->pd_this_ping, 
548                                                 cfs_time_seconds(PING_INTERVAL)))) {
549                 CDEBUG(D_HA, "not finished, but also not expired\n");
550                 pd->pd_recursion--;
551                 return 0;
552         }
553
554         /* Expire all the requests that didn't come back. */
555         mutex_down(&pinger_sem);
556         list_for_each(iter, &set->set_requests) {
557                 req = list_entry(iter, struct ptlrpc_request,
558                                  rq_set_chain);
559
560                 if (req->rq_replied)
561                         continue;
562
563                 req->rq_phase = RQ_PHASE_COMPLETE;
564                 atomic_dec(&req->rq_import->imp_inflight);
565                 set->set_remaining--;
566                 /* If it was disconnected, don't sweat it. */
567                 if (list_empty(&req->rq_import->imp_pinger_chain)) {
568                         ptlrpc_unregister_reply(req);
569                         continue;
570                 }
571
572                 CDEBUG(D_HA, "pinger initiate expire_one_request\n");
573                 ptlrpc_expire_one_request(req);
574         }
575         mutex_up(&pinger_sem);
576
577         ptlrpc_set_destroy(set);
578         pd->pd_set = NULL;
579
580 out:
581         pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
582                                         cfs_time_seconds(PING_INTERVAL));
583         pd->pd_this_ping = 0; /* XXX for debug */
584
585         CDEBUG(D_HA, "finished a round ping\n");
586         pd->pd_recursion--;
587         return 0;
588 }
589
590 static void *pinger_callback = NULL;
591 #endif /* ENABLE_PINGER */
592
593 int ptlrpc_start_pinger(void)
594 {
595 #ifdef ENABLE_PINGER
596         memset(&pinger_args, 0, sizeof(pinger_args));
597         pinger_callback = liblustre_register_wait_callback(&pinger_check_rpcs,
598                                                            &pinger_args);
599 #endif
600         return 0;
601 }
602
603 int ptlrpc_stop_pinger(void)
604 {
605 #ifdef ENABLE_PINGER
606         if (pinger_callback)
607                 liblustre_deregister_wait_callback(pinger_callback);
608 #endif
609         return 0;
610 }
611
612 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
613 {
614 #ifdef ENABLE_PINGER
615         mutex_down(&pinger_sem);
616         ptlrpc_update_next_ping(imp);
617         if (pinger_args.pd_set == NULL &&
618             time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
619                 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
620                         imp->imp_next_ping, cfs_time_current());
621                 pinger_args.pd_next_ping = imp->imp_next_ping;
622         }
623         mutex_up(&pinger_sem);
624 #endif
625 }
626
627 int ptlrpc_pinger_add_import(struct obd_import *imp)
628 {
629         ENTRY;
630         if (!list_empty(&imp->imp_pinger_chain))
631                 RETURN(-EALREADY);
632
633         CDEBUG(D_HA, "adding pingable import %s->%s\n",
634                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
635         ptlrpc_pinger_sending_on_import(imp);
636
637         mutex_down(&pinger_sem);
638         list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
639         class_import_get(imp);
640         mutex_up(&pinger_sem);
641
642         RETURN(0);
643 }
644
645 int ptlrpc_pinger_del_import(struct obd_import *imp)
646 {
647         ENTRY;
648         if (list_empty(&imp->imp_pinger_chain))
649                 RETURN(-ENOENT);
650
651         mutex_down(&pinger_sem);
652         list_del_init(&imp->imp_pinger_chain);
653         CDEBUG(D_HA, "removing pingable import %s->%s\n",
654                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
655         class_import_put(imp);
656         mutex_up(&pinger_sem);
657         RETURN(0);
658 }
659
660 void ptlrpc_pinger_wake_up()
661 {
662 #ifdef ENABLE_PINGER
663         ENTRY;
664         /* XXX force pinger to run, if needed */
665         struct obd_import *imp;
666         list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
667                 CDEBUG(D_HA, "Checking that we need to do anything about import"
668                              " %s->%s\n", imp->imp_obd->obd_uuid.uuid,
669                              obd2cli_tgt(imp->imp_obd));
670 #ifdef ENABLE_LIBLUSTRE_RECOVERY
671                 if (imp->imp_state == LUSTRE_IMP_DISCON && !imp->imp_deactive)
672 #else
673                 /*XXX only recover for the initial connection */
674                 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
675                     imp->imp_state == LUSTRE_IMP_DISCON && !imp->imp_deactive)
676 #endif
677                         ptlrpc_initiate_recovery(imp);
678                 else if (imp->imp_state != LUSTRE_IMP_FULL)
679                         CDEBUG(D_HA, "Refused to recover import %s->%s "
680                                      "state %d, deactive %d\n",
681                                      imp->imp_obd->obd_uuid.uuid,
682                                      obd2cli_tgt(imp->imp_obd), imp->imp_state,
683                                      imp->imp_deactive);
684         }
685 #endif
686         EXIT;
687 }
688 #endif /* !__KERNEL__ */