Whamcloud - gitweb
a29283e81f91b9f62303d4aaf137014ba08d986e
[fs/lustre-release.git] / lustre / ptlrpc / pinger.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ptlrpc/pinger.c
37  *
38  * Portal-RPC reconnection and replay operations, for use in recovery.
39  */
40
41 #define DEBUG_SUBSYSTEM S_RPC
42
43 #include <obd_support.h>
44 #include <obd_class.h>
45 #include "ptlrpc_internal.h"
46
47 static int suppress_pings;
48 CFS_MODULE_PARM(suppress_pings, "i", int, 0644, "Suppress pings");
49
50 struct mutex pinger_mutex;
51 static struct list_head pinger_imports =
52                 LIST_HEAD_INIT(pinger_imports);
53 static struct list_head timeout_list =
54                 LIST_HEAD_INIT(timeout_list);
55
56 int ptlrpc_pinger_suppress_pings()
57 {
58         return suppress_pings;
59 }
60 EXPORT_SYMBOL(ptlrpc_pinger_suppress_pings);
61
62 struct ptlrpc_request *
63 ptlrpc_prep_ping(struct obd_import *imp)
64 {
65         struct ptlrpc_request *req;
66
67         req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
68                                         LUSTRE_OBD_VERSION, OBD_PING);
69         if (req) {
70                 ptlrpc_request_set_replen(req);
71                 req->rq_no_resend = req->rq_no_delay = 1;
72         }
73         return req;
74 }
75
76 int ptlrpc_obd_ping(struct obd_device *obd)
77 {
78         int rc;
79         struct ptlrpc_request *req;
80         ENTRY;
81
82         req = ptlrpc_prep_ping(obd->u.cli.cl_import);
83         if (req == NULL)
84                 RETURN(-ENOMEM);
85
86         req->rq_send_state = LUSTRE_IMP_FULL;
87
88         rc = ptlrpc_queue_wait(req);
89
90         ptlrpc_req_finished(req);
91
92         RETURN(rc);
93 }
94 EXPORT_SYMBOL(ptlrpc_obd_ping);
95
96 static int ptlrpc_ping(struct obd_import *imp)
97 {
98         struct ptlrpc_request *req;
99         ENTRY;
100
101         req = ptlrpc_prep_ping(imp);
102         if (req == NULL) {
103                 CERROR("OOM trying to ping %s->%s\n",
104                        imp->imp_obd->obd_uuid.uuid,
105                        obd2cli_tgt(imp->imp_obd));
106                 RETURN(-ENOMEM);
107         }
108
109         DEBUG_REQ(D_INFO, req, "pinging %s->%s",
110                   imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
111         ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
112
113         RETURN(0);
114 }
115
116 static void ptlrpc_update_next_ping(struct obd_import *imp, int soon)
117 {
118 #ifdef ENABLE_PINGER
119         int time = soon ? PING_INTERVAL_SHORT : PING_INTERVAL;
120         if (imp->imp_state == LUSTRE_IMP_DISCON) {
121                 int dtime = max_t(int, CONNECTION_SWITCH_MIN,
122                                   AT_OFF ? 0 :
123                                   at_get(&imp->imp_at.iat_net_latency));
124                 time = min(time, dtime);
125         }
126         imp->imp_next_ping = cfs_time_shift(time);
127 #endif /* ENABLE_PINGER */
128 }
129
130 void ptlrpc_ping_import_soon(struct obd_import *imp)
131 {
132         imp->imp_next_ping = cfs_time_current();
133 }
134
135 static inline int imp_is_deactive(struct obd_import *imp)
136 {
137         return (imp->imp_deactive ||
138                 OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_IMP_DEACTIVE));
139 }
140
141 static inline int ptlrpc_next_reconnect(struct obd_import *imp)
142 {
143         if (imp->imp_server_timeout)
144                 return cfs_time_shift(obd_timeout / 2);
145         else
146                 return cfs_time_shift(obd_timeout);
147 }
148
149 static cfs_duration_t pinger_check_timeout(cfs_time_t time)
150 {
151         struct timeout_item *item;
152         cfs_time_t timeout = PING_INTERVAL;
153
154         /* The timeout list is a increase order sorted list */
155         mutex_lock(&pinger_mutex);
156         list_for_each_entry(item, &timeout_list, ti_chain) {
157                 int ti_timeout = item->ti_timeout;
158                 if (timeout > ti_timeout)
159                         timeout = ti_timeout;
160                 break;
161         }
162         mutex_unlock(&pinger_mutex);
163
164         return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)),
165                                          cfs_time_current());
166 }
167
168
169 static bool ir_up;
170
171 void ptlrpc_pinger_ir_up(void)
172 {
173         CDEBUG(D_HA, "IR up\n");
174         ir_up = true;
175 }
176 EXPORT_SYMBOL(ptlrpc_pinger_ir_up);
177
178 void ptlrpc_pinger_ir_down(void)
179 {
180         CDEBUG(D_HA, "IR down\n");
181         ir_up = false;
182 }
183 EXPORT_SYMBOL(ptlrpc_pinger_ir_down);
184
185 static void ptlrpc_pinger_process_import(struct obd_import *imp,
186                                          unsigned long this_ping)
187 {
188         int level;
189         int force;
190         int force_next;
191         int suppress;
192
193         spin_lock(&imp->imp_lock);
194
195         level = imp->imp_state;
196         force = imp->imp_force_verify;
197         force_next = imp->imp_force_next_verify;
198         /*
199          * This will be used below only if the import is "FULL".
200          */
201         suppress = ir_up && OCD_HAS_FLAG(&imp->imp_connect_data, PINGLESS);
202
203         imp->imp_force_verify = 0;
204
205         if (cfs_time_aftereq(imp->imp_next_ping - 5 * CFS_TICK, this_ping) &&
206             !force) {
207                 spin_unlock(&imp->imp_lock);
208                 return;
209         }
210
211         imp->imp_force_next_verify = 0;
212
213         spin_unlock(&imp->imp_lock);
214
215         CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_HA, "%s->%s: level %s/%u "
216                "force %u force_next %u deactive %u pingable %u suppress %u\n",
217                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
218                ptlrpc_import_state_name(level), level, force, force_next,
219                imp->imp_deactive, imp->imp_pingable, suppress);
220
221         if (level == LUSTRE_IMP_DISCON && !imp_is_deactive(imp)) {
222                 /* wait for a while before trying recovery again */
223                 imp->imp_next_ping = ptlrpc_next_reconnect(imp);
224                 if (!imp->imp_no_pinger_recover)
225                         ptlrpc_initiate_recovery(imp);
226         } else if (level != LUSTRE_IMP_FULL ||
227                    imp->imp_obd->obd_no_recov ||
228                    imp_is_deactive(imp)) {
229                 CDEBUG(D_HA, "%s->%s: not pinging (in recovery "
230                        "or recovery disabled: %s)\n",
231                        imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
232                        ptlrpc_import_state_name(level));
233                 if (force) {
234                         spin_lock(&imp->imp_lock);
235                         imp->imp_force_verify = 1;
236                         spin_unlock(&imp->imp_lock);
237                 }
238         } else if ((imp->imp_pingable && !suppress) || force_next || force) {
239                 ptlrpc_ping(imp);
240         }
241 }
242
243 static int ptlrpc_pinger_main(void *arg)
244 {
245         struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
246         ENTRY;
247
248         /* Record that the thread is running */
249         thread_set_flags(thread, SVC_RUNNING);
250         wake_up(&thread->t_ctl_waitq);
251
252         /* And now, loop forever, pinging as needed. */
253         while (1) {
254                 cfs_time_t this_ping = cfs_time_current();
255                 struct l_wait_info lwi;
256                 cfs_duration_t time_to_next_wake;
257                 struct timeout_item *item;
258                 struct list_head *iter;
259
260                 mutex_lock(&pinger_mutex);
261                 list_for_each_entry(item, &timeout_list, ti_chain)
262                         item->ti_cb(item, item->ti_cb_data);
263
264                 list_for_each(iter, &pinger_imports) {
265                         struct obd_import *imp = list_entry(iter,
266                                                             struct obd_import,
267                                                             imp_pinger_chain);
268
269                         ptlrpc_pinger_process_import(imp, this_ping);
270                         /* obd_timeout might have changed */
271                         if (imp->imp_pingable && imp->imp_next_ping &&
272                             cfs_time_after(imp->imp_next_ping,
273                                            cfs_time_add(this_ping,
274                                                         cfs_time_seconds(PING_INTERVAL))))
275                                 ptlrpc_update_next_ping(imp, 0);
276                 }
277                 mutex_unlock(&pinger_mutex);
278                 /* update memory usage info */
279                 obd_update_maxusage();
280
281                 /* Wait until the next ping time, or until we're stopped. */
282                 time_to_next_wake = pinger_check_timeout(this_ping);
283                 /* The ping sent by ptlrpc_send_rpc may get sent out
284                    say .01 second after this.
285                    ptlrpc_pinger_sending_on_import will then set the
286                    next ping time to next_ping + .01 sec, which means
287                    we will SKIP the next ping at next_ping, and the
288                    ping will get sent 2 timeouts from now!  Beware. */
289                 CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("
290                        CFS_TIME_T")\n", time_to_next_wake,
291                        cfs_time_add(this_ping,cfs_time_seconds(PING_INTERVAL)));
292                 if (time_to_next_wake > 0) {
293                         lwi = LWI_TIMEOUT(max_t(cfs_duration_t,
294                                                 time_to_next_wake,
295                                                 cfs_time_seconds(1)),
296                                           NULL, NULL);
297                         l_wait_event(thread->t_ctl_waitq,
298                                      thread_is_stopping(thread) ||
299                                      thread_is_event(thread),
300                                      &lwi);
301                         if (thread_test_and_clear_flags(thread, SVC_STOPPING)) {
302                                 EXIT;
303                                 break;
304                         } else {
305                                 /* woken after adding import to reset timer */
306                                 thread_test_and_clear_flags(thread, SVC_EVENT);
307                         }
308                 }
309         }
310
311         thread_set_flags(thread, SVC_STOPPED);
312         wake_up(&thread->t_ctl_waitq);
313
314         CDEBUG(D_NET, "pinger thread exiting, process %d\n", current_pid());
315         return 0;
316 }
317
318 static struct ptlrpc_thread pinger_thread;
319
320 int ptlrpc_start_pinger(void)
321 {
322         struct l_wait_info lwi = { 0 };
323         struct task_struct *task;
324         int rc;
325 #ifndef ENABLE_PINGER
326         return 0;
327 #endif
328         ENTRY;
329
330         if (!thread_is_init(&pinger_thread) &&
331             !thread_is_stopped(&pinger_thread))
332                 RETURN(-EALREADY);
333
334         init_waitqueue_head(&pinger_thread.t_ctl_waitq);
335
336         strcpy(pinger_thread.t_name, "ll_ping");
337
338         /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
339          * just drop the VM and FILES in kthread_run() right away. */
340         task = kthread_run(ptlrpc_pinger_main, &pinger_thread,
341                            pinger_thread.t_name);
342         if (IS_ERR(task)) {
343                 rc = PTR_ERR(task);
344                 CERROR("cannot start pinger thread: rc = %d\n", rc);
345                 RETURN(rc);
346         }
347
348         l_wait_event(pinger_thread.t_ctl_waitq,
349                      thread_is_running(&pinger_thread), &lwi);
350
351         if (suppress_pings)
352                 CWARN("Pings will be suppressed at the request of the "
353                       "administrator.  The configuration shall meet the "
354                       "additional requirements described in the manual.  "
355                       "(Search for the \"suppress_pings\" kernel module "
356                       "parameter.)\n");
357
358         RETURN(0);
359 }
360
361 int ptlrpc_pinger_remove_timeouts(void);
362
363 int ptlrpc_stop_pinger(void)
364 {
365         struct l_wait_info lwi = { 0 };
366 #ifndef ENABLE_PINGER
367         return 0;
368 #endif
369         ENTRY;
370
371         if (thread_is_init(&pinger_thread) ||
372             thread_is_stopped(&pinger_thread))
373                 RETURN(-EALREADY);
374
375         ptlrpc_pinger_remove_timeouts();
376
377         thread_set_flags(&pinger_thread, SVC_STOPPING);
378         wake_up(&pinger_thread.t_ctl_waitq);
379
380         l_wait_event(pinger_thread.t_ctl_waitq,
381                      thread_is_stopped(&pinger_thread), &lwi);
382         RETURN(0);
383 }
384
385 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
386 {
387         ptlrpc_update_next_ping(imp, 0);
388 }
389
390 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
391 {
392         ptlrpc_update_next_ping(imp, 1);
393         assert_spin_locked(&imp->imp_lock);
394         /*
395          * Avoid reading stale imp_connect_data.  When not sure if pings are
396          * expected or not on next connection, we assume they are not and force
397          * one anyway to guarantee the chance of updating
398          * imp_peer_committed_transno.
399          */
400         if (imp->imp_state != LUSTRE_IMP_FULL ||
401             OCD_HAS_FLAG(&imp->imp_connect_data, PINGLESS))
402                 imp->imp_force_next_verify = 1;
403 }
404
405 int ptlrpc_pinger_add_import(struct obd_import *imp)
406 {
407         ENTRY;
408         if (!list_empty(&imp->imp_pinger_chain))
409                 RETURN(-EALREADY);
410
411         mutex_lock(&pinger_mutex);
412         CDEBUG(D_HA, "adding pingable import %s->%s\n",
413                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
414         /* if we add to pinger we want recovery on this import */
415         imp->imp_obd->obd_no_recov = 0;
416         ptlrpc_update_next_ping(imp, 0);
417         /* XXX sort, blah blah */
418         list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
419         class_import_get(imp);
420
421         ptlrpc_pinger_wake_up();
422         mutex_unlock(&pinger_mutex);
423
424         RETURN(0);
425 }
426 EXPORT_SYMBOL(ptlrpc_pinger_add_import);
427
428 int ptlrpc_pinger_del_import(struct obd_import *imp)
429 {
430         ENTRY;
431
432         if (list_empty(&imp->imp_pinger_chain))
433                 RETURN(-ENOENT);
434
435         mutex_lock(&pinger_mutex);
436         list_del_init(&imp->imp_pinger_chain);
437         CDEBUG(D_HA, "removing pingable import %s->%s\n",
438                imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
439         /* if we remove from pinger we don't want recovery on this import */
440         imp->imp_obd->obd_no_recov = 1;
441         class_import_put(imp);
442         mutex_unlock(&pinger_mutex);
443         RETURN(0);
444 }
445 EXPORT_SYMBOL(ptlrpc_pinger_del_import);
446
447 /**
448  * Register a timeout callback to the pinger list, and the callback will
449  * be called when timeout happens.
450  */
451 static struct timeout_item *ptlrpc_new_timeout(int time,
452                                                enum timeout_event event,
453                                                timeout_cb_t cb, void *data)
454 {
455         struct timeout_item *ti;
456
457         OBD_ALLOC_PTR(ti);
458         if (!ti)
459                 return(NULL);
460
461         INIT_LIST_HEAD(&ti->ti_obd_list);
462         INIT_LIST_HEAD(&ti->ti_chain);
463         ti->ti_timeout = time;
464         ti->ti_event = event;
465         ti->ti_cb = cb;
466         ti->ti_cb_data = data;
467
468         return ti;
469 }
470
471 /**
472  * Register timeout event on the the pinger thread.
473  * Note: the timeout list is an sorted list with increased timeout value.
474  */
475 static struct timeout_item*
476 ptlrpc_pinger_register_timeout(int time, enum timeout_event event,
477                                timeout_cb_t cb, void *data)
478 {
479         struct timeout_item *item, *tmp;
480
481         LASSERT(mutex_is_locked(&pinger_mutex));
482
483         list_for_each_entry(item, &timeout_list, ti_chain)
484                 if (item->ti_event == event)
485                         goto out;
486
487         item = ptlrpc_new_timeout(time, event, cb, data);
488         if (item) {
489                 list_for_each_entry_reverse(tmp, &timeout_list, ti_chain) {
490                         if (tmp->ti_timeout < time) {
491                                 list_add(&item->ti_chain, &tmp->ti_chain);
492                                 goto out;
493                         }
494                 }
495                 list_add(&item->ti_chain, &timeout_list);
496         }
497 out:
498         return item;
499 }
500
501 /* Add a client_obd to the timeout event list, when timeout(@time)
502  * happens, the callback(@cb) will be called.
503  */
504 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
505                               timeout_cb_t cb, void *data,
506                               struct list_head *obd_list)
507 {
508         struct timeout_item *ti;
509
510         mutex_lock(&pinger_mutex);
511         ti = ptlrpc_pinger_register_timeout(time, event, cb, data);
512         if (!ti) {
513                 mutex_unlock(&pinger_mutex);
514                 return (-EINVAL);
515         }
516         list_add(obd_list, &ti->ti_obd_list);
517         mutex_unlock(&pinger_mutex);
518         return 0;
519 }
520 EXPORT_SYMBOL(ptlrpc_add_timeout_client);
521
522 int ptlrpc_del_timeout_client(struct list_head *obd_list,
523                               enum timeout_event event)
524 {
525         struct timeout_item *ti = NULL, *item;
526
527         if (list_empty(obd_list))
528                 return 0;
529         mutex_lock(&pinger_mutex);
530         list_del_init(obd_list);
531         /**
532          * If there are no obd attached to the timeout event
533          * list, remove this timeout event from the pinger
534          */
535         list_for_each_entry(item, &timeout_list, ti_chain) {
536                 if (item->ti_event == event) {
537                         ti = item;
538                         break;
539                 }
540         }
541         LASSERTF(ti != NULL, "ti is NULL !\n");
542         if (list_empty(&ti->ti_obd_list)) {
543                 list_del(&ti->ti_chain);
544                 OBD_FREE_PTR(ti);
545         }
546         mutex_unlock(&pinger_mutex);
547         return 0;
548 }
549 EXPORT_SYMBOL(ptlrpc_del_timeout_client);
550
551 int ptlrpc_pinger_remove_timeouts(void)
552 {
553         struct timeout_item *item, *tmp;
554
555         mutex_lock(&pinger_mutex);
556         list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
557                 LASSERT(list_empty(&item->ti_obd_list));
558                 list_del(&item->ti_chain);
559                 OBD_FREE_PTR(item);
560         }
561         mutex_unlock(&pinger_mutex);
562         return 0;
563 }
564
565 void ptlrpc_pinger_wake_up()
566 {
567 #ifdef ENABLE_PINGER
568         thread_add_flags(&pinger_thread, SVC_EVENT);
569         wake_up(&pinger_thread.t_ctl_waitq);
570 #endif
571 }
572
573 /* Ping evictor thread */
574 #define PET_READY     1
575 #define PET_TERMINATE 2
576
577 static int               pet_refcount = 0;
578 static int               pet_state;
579 static wait_queue_head_t pet_waitq;
580 static struct list_head  pet_list;
581 static DEFINE_SPINLOCK(pet_lock);
582
583 int ping_evictor_wake(struct obd_export *exp)
584 {
585         struct obd_device *obd;
586
587         spin_lock(&pet_lock);
588         if (pet_state != PET_READY) {
589                 /* eventually the new obd will call here again. */
590                 spin_unlock(&pet_lock);
591                 return 1;
592         }
593
594         obd = class_exp2obd(exp);
595         if (list_empty(&obd->obd_evict_list)) {
596                 class_incref(obd, "evictor", obd);
597                 list_add(&obd->obd_evict_list, &pet_list);
598         }
599         spin_unlock(&pet_lock);
600
601         wake_up(&pet_waitq);
602         return 0;
603 }
604
605 static int ping_evictor_main(void *arg)
606 {
607         struct obd_device *obd;
608         struct obd_export *exp;
609         struct l_wait_info lwi = { 0 };
610         time_t expire_time;
611         ENTRY;
612
613         unshare_fs_struct();
614
615         CDEBUG(D_HA, "Starting Ping Evictor\n");
616         pet_state = PET_READY;
617         while (1) {
618                 l_wait_event(pet_waitq, (!list_empty(&pet_list)) ||
619                             (pet_state == PET_TERMINATE), &lwi);
620
621                 /* loop until all obd's will be removed */
622                 if ((pet_state == PET_TERMINATE) && list_empty(&pet_list))
623                         break;
624
625                 /* we only get here if pet_exp != NULL, and the end of this
626                  * loop is the only place which sets it NULL again, so lock
627                  * is not strictly necessary. */
628                 spin_lock(&pet_lock);
629                 obd = list_entry(pet_list.next, struct obd_device,
630                                  obd_evict_list);
631                 spin_unlock(&pet_lock);
632
633                 expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
634
635                 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
636                        obd->obd_name, expire_time);
637
638                 /* Exports can't be deleted out of the list while we hold
639                  * the obd lock (class_unlink_export), which means we can't
640                  * lose the last ref on the export.  If they've already been
641                  * removed from the list, we won't find them here. */
642                 spin_lock(&obd->obd_dev_lock);
643                 while (!list_empty(&obd->obd_exports_timed)) {
644                         exp = list_entry(obd->obd_exports_timed.next,
645                                          struct obd_export,
646                                          exp_obd_chain_timed);
647                         if (expire_time > exp->exp_last_request_time) {
648                                 class_export_get(exp);
649                                 spin_unlock(&obd->obd_dev_lock);
650                                 LCONSOLE_WARN("%s: haven't heard from client %s"
651                                               " (at %s) in %ld seconds. I think"
652                                               " it's dead, and I am evicting"
653                                               " it. exp %p, cur %ld expire %ld"
654                                               " last %ld\n",
655                                               obd->obd_name,
656                                               obd_uuid2str(&exp->exp_client_uuid),
657                                               obd_export_nid2str(exp),
658                                               (long)(cfs_time_current_sec() -
659                                                      exp->exp_last_request_time),
660                                               exp, (long)cfs_time_current_sec(),
661                                               (long)expire_time,
662                                               (long)exp->exp_last_request_time);
663                                 CDEBUG(D_HA, "Last request was at %ld\n",
664                                        exp->exp_last_request_time);
665                                 class_fail_export(exp);
666                                 class_export_put(exp);
667                                 spin_lock(&obd->obd_dev_lock);
668                         } else {
669                                 /* List is sorted, so everyone below is ok */
670                                 break;
671                         }
672                 }
673                 spin_unlock(&obd->obd_dev_lock);
674
675                 spin_lock(&pet_lock);
676                 list_del_init(&obd->obd_evict_list);
677                 spin_unlock(&pet_lock);
678
679                 class_decref(obd, "evictor", obd);
680         }
681         CDEBUG(D_HA, "Exiting Ping Evictor\n");
682
683         RETURN(0);
684 }
685
686 void ping_evictor_start(void)
687 {
688         struct task_struct *task;
689
690         if (++pet_refcount > 1)
691                 return;
692
693         INIT_LIST_HEAD(&pet_list);
694         init_waitqueue_head(&pet_waitq);
695
696         task = kthread_run(ping_evictor_main, NULL, "ll_evictor");
697         if (IS_ERR(task)) {
698                 pet_refcount--;
699                 CERROR("Cannot start ping evictor thread: %ld\n",
700                         PTR_ERR(task));
701         }
702 }
703 EXPORT_SYMBOL(ping_evictor_start);
704
705 void ping_evictor_stop(void)
706 {
707         if (--pet_refcount > 0)
708                 return;
709
710         pet_state = PET_TERMINATE;
711         wake_up(&pet_waitq);
712 }
713 EXPORT_SYMBOL(ping_evictor_stop);