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