1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/pinger.c
38 * Portal-RPC reconnection and replay operations, for use in recovery.
42 #include <liblustre.h>
44 #define DEBUG_SUBSYSTEM S_RPC
47 #include <obd_support.h>
48 #include <obd_class.h>
49 #include "ptlrpc_internal.h"
51 struct semaphore pinger_sem;
52 static CFS_LIST_HEAD(pinger_imports);
53 static struct list_head timeout_list = CFS_LIST_HEAD_INIT(timeout_list);
54 struct ptlrpc_request *
55 ptlrpc_prep_ping(struct obd_import *imp)
57 struct ptlrpc_request *req;
59 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
60 LUSTRE_OBD_VERSION, OBD_PING);
62 ptlrpc_request_set_replen(req);
63 req->rq_no_resend = req->rq_no_delay = 1;
68 int ptlrpc_obd_ping(struct obd_device *obd)
71 struct ptlrpc_request *req;
74 req = ptlrpc_prep_ping(obd->u.cli.cl_import);
78 req->rq_send_state = LUSTRE_IMP_FULL;
80 rc = ptlrpc_queue_wait(req);
82 ptlrpc_req_finished(req);
86 EXPORT_SYMBOL(ptlrpc_obd_ping);
88 int ptlrpc_ping(struct obd_import *imp)
90 struct ptlrpc_request *req;
93 req = ptlrpc_prep_ping(imp);
95 CERROR("OOM trying to ping %s->%s\n",
96 imp->imp_obd->obd_uuid.uuid,
97 obd2cli_tgt(imp->imp_obd));
101 DEBUG_REQ(D_INFO, req, "pinging %s->%s",
102 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
103 ptlrpcd_add_req(req, PSCOPE_OTHER);
108 void ptlrpc_update_next_ping(struct obd_import *imp)
111 int time = PING_INTERVAL;
112 if (imp->imp_state == LUSTRE_IMP_DISCON) {
113 int dtime = max_t(int, CONNECTION_SWITCH_MIN,
115 at_get(&imp->imp_at.iat_net_latency));
116 time = min(time, dtime);
118 imp->imp_next_ping = cfs_time_shift(time);
119 #endif /* ENABLE_PINGER */
122 void ptlrpc_ping_import_soon(struct obd_import *imp)
124 imp->imp_next_ping = cfs_time_current();
127 static inline int imp_is_deactive(struct obd_import *imp)
129 return (imp->imp_deactive ||
130 OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_IMP_DEACTIVE));
133 static inline int ptlrpc_next_reconnect(struct obd_import *imp)
135 if (imp->imp_server_timeout)
136 return cfs_time_shift(obd_timeout / 2);
138 return cfs_time_shift(obd_timeout);
141 static atomic_t suspend_timeouts = ATOMIC_INIT(0);
142 static cfs_time_t suspend_wakeup_time = 0;
144 cfs_duration_t pinger_check_timeout(cfs_time_t time)
146 struct timeout_item *item;
147 cfs_time_t timeout = PING_INTERVAL;
149 /* The timeout list is a increase order sorted list */
150 mutex_down(&pinger_sem);
151 list_for_each_entry(item, &timeout_list, ti_chain) {
152 int ti_timeout = item->ti_timeout;
153 if (timeout > ti_timeout)
154 timeout = ti_timeout;
157 mutex_up(&pinger_sem);
159 return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)),
164 static wait_queue_head_t suspend_timeouts_waitq;
167 cfs_time_t ptlrpc_suspend_wakeup_time(void)
169 return suspend_wakeup_time;
172 void ptlrpc_deactivate_timeouts(struct obd_import *imp)
174 /*XXX: disabled for now, will be replaced by adaptive timeouts */
176 if (imp->imp_no_timeout)
178 imp->imp_no_timeout = 1;
179 atomic_inc(&suspend_timeouts);
180 CDEBUG(D_HA|D_WARNING, "deactivate timeouts %u\n", atomic_read(&suspend_timeouts));
184 void ptlrpc_activate_timeouts(struct obd_import *imp)
186 /*XXX: disabled for now, will be replaced by adaptive timeouts */
188 if (!imp->imp_no_timeout)
190 imp->imp_no_timeout = 0;
191 LASSERT(atomic_read(&suspend_timeouts) > 0);
192 if (atomic_dec_and_test(&suspend_timeouts)) {
193 suspend_wakeup_time = cfs_time_current();
194 wake_up(&suspend_timeouts_waitq);
196 CDEBUG(D_HA|D_WARNING, "activate timeouts %u\n", atomic_read(&suspend_timeouts));
200 int ptlrpc_check_suspend(void)
202 if (atomic_read(&suspend_timeouts))
207 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req)
209 struct l_wait_info lwi;
211 if (atomic_read(&suspend_timeouts)) {
212 DEBUG_REQ(D_NET, req, "-- suspend %d regular timeout",
213 atomic_read(&suspend_timeouts));
214 lwi = LWI_INTR(NULL, NULL);
215 l_wait_event(suspend_timeouts_waitq,
216 atomic_read(&suspend_timeouts) == 0, &lwi);
217 DEBUG_REQ(D_NET, req, "-- recharge regular timeout");
225 static void ptlrpc_pinger_process_import(struct obd_import *imp,
226 unsigned long this_ping)
230 spin_lock(&imp->imp_lock);
231 level = imp->imp_state;
232 force = imp->imp_force_verify;
234 imp->imp_force_verify = 0;
235 spin_unlock(&imp->imp_lock);
237 CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_HA,
238 "level %s/%u force %u deactive %u pingable %u\n",
239 ptlrpc_import_state_name(level), level,
240 force, imp->imp_deactive, imp->imp_pingable);
242 if (cfs_time_aftereq(imp->imp_next_ping - 5 * CFS_TICK,
243 this_ping) && force == 0)
246 if (level == LUSTRE_IMP_DISCON && !imp_is_deactive(imp)) {
247 /* wait at least a timeout before trying recovery again */
248 imp->imp_next_ping = ptlrpc_next_reconnect(imp);
249 ptlrpc_initiate_recovery(imp);
250 } else if (level != LUSTRE_IMP_FULL ||
251 imp->imp_obd->obd_no_recov ||
252 imp_is_deactive(imp)) {
253 CDEBUG(D_HA, "not pinging %s (in recovery "
254 " or recovery disabled: %s)\n",
255 obd2cli_tgt(imp->imp_obd),
256 ptlrpc_import_state_name(level));
257 } else if (imp->imp_pingable || force) {
262 static int ptlrpc_pinger_main(void *arg)
264 struct ptlrpc_svc_data *data = (struct ptlrpc_svc_data *)arg;
265 struct ptlrpc_thread *thread = data->thread;
268 cfs_daemonize(data->name);
270 /* Record that the thread is running */
271 thread->t_flags = SVC_RUNNING;
272 cfs_waitq_signal(&thread->t_ctl_waitq);
274 /* And now, loop forever, pinging as needed. */
276 cfs_time_t this_ping = cfs_time_current();
277 struct l_wait_info lwi;
278 cfs_duration_t time_to_next_wake;
279 struct timeout_item *item;
280 struct list_head *iter;
282 mutex_down(&pinger_sem);
283 list_for_each_entry(item, &timeout_list, ti_chain) {
284 item->ti_cb(item, item->ti_cb_data);
286 list_for_each(iter, &pinger_imports) {
287 struct obd_import *imp =
288 list_entry(iter, struct obd_import,
291 ptlrpc_pinger_process_import(imp, this_ping);
292 /* obd_timeout might have changed */
293 if (imp->imp_pingable && imp->imp_next_ping &&
294 cfs_time_after(imp->imp_next_ping,
295 cfs_time_add(this_ping,
296 cfs_time_seconds(PING_INTERVAL))))
297 ptlrpc_update_next_ping(imp);
299 mutex_up(&pinger_sem);
300 /* update memory usage info */
301 obd_update_maxusage();
303 /* Wait until the next ping time, or until we're stopped. */
304 time_to_next_wake = pinger_check_timeout(this_ping);
305 /* The ping sent by ptlrpc_send_rpc may get sent out
306 say .01 second after this.
307 ptlrpc_pinger_sending_on_import will then set the
308 next ping time to next_ping + .01 sec, which means
309 we will SKIP the next ping at next_ping, and the
310 ping will get sent 2 timeouts from now! Beware. */
311 CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("CFS_TIME_T")\n",
313 cfs_time_add(this_ping, cfs_time_seconds(PING_INTERVAL)));
314 if (time_to_next_wake > 0) {
315 lwi = LWI_TIMEOUT(max_t(cfs_duration_t, time_to_next_wake, cfs_time_seconds(1)),
317 l_wait_event(thread->t_ctl_waitq,
318 thread->t_flags & (SVC_STOPPING|SVC_EVENT),
320 if (thread->t_flags & SVC_STOPPING) {
321 thread->t_flags &= ~SVC_STOPPING;
324 } else if (thread->t_flags & SVC_EVENT) {
325 /* woken after adding import to reset timer */
326 thread->t_flags &= ~SVC_EVENT;
331 thread->t_flags = SVC_STOPPED;
332 cfs_waitq_signal(&thread->t_ctl_waitq);
334 CDEBUG(D_NET, "pinger thread exiting, process %d\n", cfs_curproc_pid());
338 static struct ptlrpc_thread *pinger_thread = NULL;
340 int ptlrpc_start_pinger(void)
342 struct l_wait_info lwi = { 0 };
343 struct ptlrpc_svc_data d;
345 #ifndef ENABLE_PINGER
350 if (pinger_thread != NULL)
353 OBD_ALLOC_PTR(pinger_thread);
354 if (pinger_thread == NULL)
356 cfs_waitq_init(&pinger_thread->t_ctl_waitq);
357 cfs_waitq_init(&suspend_timeouts_waitq);
360 d.thread = pinger_thread;
362 /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
363 * just drop the VM and FILES in cfs_daemonize_ctxt() right away. */
364 rc = cfs_kernel_thread(ptlrpc_pinger_main, &d, CLONE_VM | CLONE_FILES);
366 CERROR("cannot start thread: %d\n", rc);
367 OBD_FREE(pinger_thread, sizeof(*pinger_thread));
368 pinger_thread = NULL;
371 l_wait_event(pinger_thread->t_ctl_waitq,
372 pinger_thread->t_flags & SVC_RUNNING, &lwi);
377 int ptlrpc_pinger_remove_timeouts(void);
379 int ptlrpc_stop_pinger(void)
381 struct l_wait_info lwi = { 0 };
383 #ifndef ENABLE_PINGER
388 if (pinger_thread == NULL)
391 ptlrpc_pinger_remove_timeouts();
392 mutex_down(&pinger_sem);
393 pinger_thread->t_flags = SVC_STOPPING;
394 cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
395 mutex_up(&pinger_sem);
397 l_wait_event(pinger_thread->t_ctl_waitq,
398 (pinger_thread->t_flags & SVC_STOPPED), &lwi);
400 OBD_FREE_PTR(pinger_thread);
401 pinger_thread = NULL;
405 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
407 ptlrpc_update_next_ping(imp);
410 int ptlrpc_pinger_add_import(struct obd_import *imp)
413 if (!list_empty(&imp->imp_pinger_chain))
416 mutex_down(&pinger_sem);
417 CDEBUG(D_HA, "adding pingable import %s->%s\n",
418 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
419 /* if we add to pinger we want recovery on this import */
420 imp->imp_obd->obd_no_recov = 0;
421 ptlrpc_update_next_ping(imp);
422 /* XXX sort, blah blah */
423 list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
424 class_import_get(imp);
426 ptlrpc_pinger_wake_up();
427 mutex_up(&pinger_sem);
432 int ptlrpc_pinger_del_import(struct obd_import *imp)
435 if (list_empty(&imp->imp_pinger_chain))
438 mutex_down(&pinger_sem);
439 list_del_init(&imp->imp_pinger_chain);
440 CDEBUG(D_HA, "removing pingable import %s->%s\n",
441 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
442 /* if we remove from pinger we don't want recovery on this import */
443 imp->imp_obd->obd_no_recov = 1;
444 class_import_put(imp);
445 mutex_up(&pinger_sem);
450 * Register a timeout callback to the pinger list, and the callback will
451 * be called when timeout happens.
453 struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
454 timeout_cb_t cb, void *data)
456 struct timeout_item *ti;
462 CFS_INIT_LIST_HEAD(&ti->ti_obd_list);
463 CFS_INIT_LIST_HEAD(&ti->ti_chain);
464 ti->ti_timeout = time;
465 ti->ti_event = event;
467 ti->ti_cb_data = data;
473 * Register timeout event on the the pinger thread.
474 * Note: the timeout list is an sorted list with increased timeout value.
476 static struct timeout_item*
477 ptlrpc_pinger_register_timeout(int time, enum timeout_event event,
478 timeout_cb_t cb, void *data)
480 struct timeout_item *item, *tmp;
482 LASSERT_SEM_LOCKED(&pinger_sem);
484 list_for_each_entry(item, &timeout_list, ti_chain)
485 if (item->ti_event == event)
488 item = ptlrpc_new_timeout(time, event, cb, data);
490 list_for_each_entry_reverse(tmp, &timeout_list, ti_chain) {
491 if (tmp->ti_timeout < time) {
492 list_add(&item->ti_chain, &tmp->ti_chain);
496 list_add(&item->ti_chain, &timeout_list);
502 /* Add a client_obd to the timeout event list, when timeout(@time)
503 * happens, the callback(@cb) will be called.
505 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
506 timeout_cb_t cb, void *data,
507 struct list_head *obd_list)
509 struct timeout_item *ti;
511 mutex_down(&pinger_sem);
512 ti = ptlrpc_pinger_register_timeout(time, event, cb, data);
514 mutex_up(&pinger_sem);
517 list_add(obd_list, &ti->ti_obd_list);
518 mutex_up(&pinger_sem);
522 int ptlrpc_del_timeout_client(struct list_head *obd_list,
523 enum timeout_event event)
525 struct timeout_item *ti = NULL, *item;
527 if (list_empty(obd_list))
529 mutex_down(&pinger_sem);
530 list_del_init(obd_list);
532 * If there are no obd attached to the timeout event
533 * list, remove this timeout event from the pinger
535 list_for_each_entry(item, &timeout_list, ti_chain) {
536 if (item->ti_event == event) {
541 LASSERTF(ti != NULL, "ti is NULL ! \n");
542 if (list_empty(&ti->ti_obd_list)) {
543 list_del(&ti->ti_chain);
546 mutex_up(&pinger_sem);
550 int ptlrpc_pinger_remove_timeouts(void)
552 struct timeout_item *item, *tmp;
554 mutex_down(&pinger_sem);
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);
560 mutex_up(&pinger_sem);
564 void ptlrpc_pinger_wake_up()
567 pinger_thread->t_flags |= SVC_EVENT;
568 cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
572 /* Ping evictor thread */
574 #define PET_TERMINATE 2
576 static int pet_refcount = 0;
577 static int pet_state;
578 static wait_queue_head_t pet_waitq;
579 static struct obd_export *pet_exp = NULL;
580 static spinlock_t pet_lock = SPIN_LOCK_UNLOCKED;
582 int ping_evictor_wake(struct obd_export *exp)
584 spin_lock(&pet_lock);
585 if (pet_exp || (pet_state != PET_READY)) {
586 /* eventually the new obd will call here again. */
587 spin_unlock(&pet_lock);
591 /* We have to make sure the obd isn't destroyed between now and when
592 * the ping evictor runs. We'll take a reference here, and drop it
593 * when we finish in the evictor. We don't really care about this
594 * export in particular; we just need one to keep the obd alive. */
595 pet_exp = class_export_get(exp);
596 spin_unlock(&pet_lock);
602 static int ping_evictor_main(void *arg)
604 struct obd_device *obd;
605 struct obd_export *exp;
606 struct l_wait_info lwi = { 0 };
610 cfs_daemonize_ctxt("ll_evictor");
612 CDEBUG(D_HA, "Starting Ping Evictor\n");
614 pet_state = PET_READY;
616 l_wait_event(pet_waitq, pet_exp ||
617 (pet_state == PET_TERMINATE), &lwi);
618 if (pet_state == PET_TERMINATE)
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 = pet_exp->exp_obd;
626 spin_unlock(&pet_lock);
628 expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
630 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
631 obd->obd_name, expire_time);
633 /* Exports can't be deleted out of the list while we hold
634 * the obd lock (class_unlink_export), which means we can't
635 * lose the last ref on the export. If they've already been
636 * removed from the list, we won't find them here. */
637 spin_lock(&obd->obd_dev_lock);
638 while (!list_empty(&obd->obd_exports_timed)) {
639 exp = list_entry(obd->obd_exports_timed.next,
640 struct obd_export,exp_obd_chain_timed);
641 if (expire_time > exp->exp_last_request_time) {
642 class_export_get(exp);
643 spin_unlock(&obd->obd_dev_lock);
644 LCONSOLE_WARN("%s: haven't heard from client %s"
645 " (at %s) in %ld seconds. I think"
646 " it's dead, and I am evicting"
647 " it. exp %p, cur %ld expire %ld"
650 obd_uuid2str(&exp->exp_client_uuid),
651 obd_export_nid2str(exp),
652 (long)(cfs_time_current_sec() -
653 exp->exp_last_request_time),
654 exp, (long)cfs_time_current_sec(),
656 (long)exp->exp_last_request_time);
657 CDEBUG(D_HA, "Last request was at %ld\n",
658 exp->exp_last_request_time);
659 class_fail_export(exp);
660 class_export_put(exp);
661 spin_lock(&obd->obd_dev_lock);
663 /* List is sorted, so everyone below is ok */
667 spin_unlock(&obd->obd_dev_lock);
669 class_export_put(pet_exp);
671 spin_lock(&pet_lock);
673 spin_unlock(&pet_lock);
675 CDEBUG(D_HA, "Exiting Ping Evictor\n");
680 void ping_evictor_start(void)
684 if (++pet_refcount > 1)
687 init_waitqueue_head(&pet_waitq);
689 rc = cfs_kernel_thread(ping_evictor_main, NULL, CLONE_VM | CLONE_FILES);
692 CERROR("Cannot start ping evictor thread: %d\n", rc);
695 EXPORT_SYMBOL(ping_evictor_start);
697 void ping_evictor_stop(void)
699 if (--pet_refcount > 0)
702 pet_state = PET_TERMINATE;
705 EXPORT_SYMBOL(ping_evictor_stop);
706 #else /* !__KERNEL__ */
709 * the current implementation of pinger in liblustre is not optimized
713 static struct pinger_data {
715 cfs_time_t pd_this_ping; /* jiffies */
716 cfs_time_t pd_next_ping; /* jiffies */
717 struct ptlrpc_request_set *pd_set;
720 static int pinger_check_rpcs(void *arg)
722 cfs_time_t curtime = cfs_time_current();
723 struct ptlrpc_request *req;
724 struct ptlrpc_request_set *set;
725 struct list_head *iter;
726 struct obd_import *imp;
727 struct pinger_data *pd = &pinger_args;
730 /* prevent recursion */
731 if (pd->pd_recursion++) {
732 CDEBUG(D_HA, "pinger: recursion! quit\n");
738 /* have we reached ping point? */
739 if (!pd->pd_set && time_before(curtime, pd->pd_next_ping)) {
744 /* if we have rpc_set already, continue processing it */
746 LASSERT(pd->pd_this_ping);
751 pd->pd_this_ping = curtime;
752 pd->pd_set = ptlrpc_prep_set();
753 if (pd->pd_set == NULL)
757 /* add rpcs into set */
758 mutex_down(&pinger_sem);
759 list_for_each(iter, &pinger_imports) {
760 struct obd_import *imp =
761 list_entry(iter, struct obd_import, imp_pinger_chain);
762 int generation, level;
764 if (cfs_time_aftereq(pd->pd_this_ping,
765 imp->imp_next_ping - 5 * CFS_TICK)) {
767 spin_lock(&imp->imp_lock);
768 generation = imp->imp_generation;
769 level = imp->imp_state;
770 spin_unlock(&imp->imp_lock);
772 if (level != LUSTRE_IMP_FULL) {
774 "not pinging %s (in recovery)\n",
775 obd2cli_tgt(imp->imp_obd));
779 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
783 CERROR("OOM trying to ping %s->%s\n",
784 imp->imp_obd->obd_uuid.uuid,
785 obd2cli_tgt(imp->imp_obd));
789 req->rq_no_resend = 1;
790 ptlrpc_request_set_replen(req);
791 req->rq_send_state = LUSTRE_IMP_FULL;
792 ptlrpc_rqphase_move(req, RQ_PHASE_RPC);
793 req->rq_import_generation = generation;
794 ptlrpc_set_add_req(set, req);
796 CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
797 " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
798 imp->imp_next_ping, pd->pd_this_ping);
801 pd->pd_this_ping = curtime;
802 mutex_up(&pinger_sem);
804 /* Might be empty, that's OK. */
805 if (set->set_remaining == 0)
806 CDEBUG(D_RPCTRACE, "nothing to ping\n");
808 list_for_each(iter, &set->set_requests) {
809 struct ptlrpc_request *req =
810 list_entry(iter, struct ptlrpc_request,
812 DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
813 req->rq_import->imp_obd->obd_uuid.uuid,
814 obd2cli_tgt(req->rq_import->imp_obd));
815 (void)ptl_send_rpc(req, 0);
819 rc = ptlrpc_check_set(NULL, set);
821 /* not finished, and we are not expired, simply return */
822 if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
823 cfs_time_seconds(PING_INTERVAL)))) {
824 CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
829 /* Expire all the requests that didn't come back. */
830 mutex_down(&pinger_sem);
831 list_for_each(iter, &set->set_requests) {
832 req = list_entry(iter, struct ptlrpc_request,
835 if (req->rq_phase == RQ_PHASE_COMPLETE)
838 CDEBUG(D_RPCTRACE, "Pinger initiate expire request(%p)\n",
841 /* This will also unregister reply. */
842 ptlrpc_expire_one_request(req, 0);
844 /* We're done with this req, let's finally move it to complete
845 * phase and take care of inflights. */
846 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
847 imp = req->rq_import;
848 spin_lock(&imp->imp_lock);
849 if (!list_empty(&req->rq_list)) {
850 list_del_init(&req->rq_list);
851 atomic_dec(&imp->imp_inflight);
853 spin_unlock(&imp->imp_lock);
854 set->set_remaining--;
856 mutex_up(&pinger_sem);
858 ptlrpc_set_destroy(set);
862 pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
863 cfs_time_seconds(PING_INTERVAL));
864 pd->pd_this_ping = 0; /* XXX for debug */
866 CDEBUG(D_INFO, "finished a round ping\n");
871 static void *pinger_callback = NULL;
872 #endif /* ENABLE_PINGER */
874 int ptlrpc_start_pinger(void)
877 memset(&pinger_args, 0, sizeof(pinger_args));
878 pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
885 int ptlrpc_stop_pinger(void)
889 liblustre_deregister_wait_callback(pinger_callback);
894 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
897 mutex_down(&pinger_sem);
898 ptlrpc_update_next_ping(imp);
899 if (pinger_args.pd_set == NULL &&
900 time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
901 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
902 imp->imp_next_ping, cfs_time_current());
903 pinger_args.pd_next_ping = imp->imp_next_ping;
905 mutex_up(&pinger_sem);
909 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
910 timeout_cb_t cb, void *data,
911 struct list_head *obd_list)
916 int ptlrpc_del_timeout_client(struct list_head *obd_list,
917 enum timeout_event event)
922 int ptlrpc_pinger_add_import(struct obd_import *imp)
925 if (!list_empty(&imp->imp_pinger_chain))
928 CDEBUG(D_HA, "adding pingable import %s->%s\n",
929 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
930 ptlrpc_pinger_sending_on_import(imp);
932 mutex_down(&pinger_sem);
933 list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
934 class_import_get(imp);
935 mutex_up(&pinger_sem);
940 int ptlrpc_pinger_del_import(struct obd_import *imp)
943 if (list_empty(&imp->imp_pinger_chain))
946 mutex_down(&pinger_sem);
947 list_del_init(&imp->imp_pinger_chain);
948 CDEBUG(D_HA, "removing pingable import %s->%s\n",
949 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
950 class_import_put(imp);
951 mutex_up(&pinger_sem);
955 void ptlrpc_pinger_wake_up()
958 /* XXX force pinger to run, if needed */
959 struct obd_import *imp;
961 list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
962 CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
963 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
964 #ifdef ENABLE_LIBLUSTRE_RECOVERY
965 if (imp->imp_state == LUSTRE_IMP_DISCON &&
966 !imp_is_deactive(imp))
968 /*XXX only recover for the initial connection */
969 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
970 imp->imp_state == LUSTRE_IMP_DISCON &&
971 !imp_is_deactive(imp))
973 ptlrpc_initiate_recovery(imp);
974 else if (imp->imp_state != LUSTRE_IMP_FULL)
975 CDEBUG(D_HA, "Refused to recover import %s->%s "
976 "state %d, deactive %d\n",
977 imp->imp_obd->obd_uuid.uuid,
978 obd2cli_tgt(imp->imp_obd), imp->imp_state,
979 imp_is_deactive(imp));
984 #endif /* !__KERNEL__ */