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