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