4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
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 static int suppress_pings;
52 CFS_MODULE_PARM(suppress_pings, "i", int, 0644, "Suppress pings");
54 struct mutex pinger_mutex;
55 static struct list_head pinger_imports =
56 LIST_HEAD_INIT(pinger_imports);
57 static struct list_head timeout_list =
58 LIST_HEAD_INIT(timeout_list);
60 int ptlrpc_pinger_suppress_pings()
62 return suppress_pings;
64 EXPORT_SYMBOL(ptlrpc_pinger_suppress_pings);
66 struct ptlrpc_request *
67 ptlrpc_prep_ping(struct obd_import *imp)
69 struct ptlrpc_request *req;
71 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
72 LUSTRE_OBD_VERSION, OBD_PING);
74 ptlrpc_request_set_replen(req);
75 req->rq_no_resend = req->rq_no_delay = 1;
80 int ptlrpc_obd_ping(struct obd_device *obd)
83 struct ptlrpc_request *req;
86 req = ptlrpc_prep_ping(obd->u.cli.cl_import);
90 req->rq_send_state = LUSTRE_IMP_FULL;
92 rc = ptlrpc_queue_wait(req);
94 ptlrpc_req_finished(req);
98 EXPORT_SYMBOL(ptlrpc_obd_ping);
100 int ptlrpc_ping(struct obd_import *imp)
102 struct ptlrpc_request *req;
105 req = ptlrpc_prep_ping(imp);
107 CERROR("OOM trying to ping %s->%s\n",
108 imp->imp_obd->obd_uuid.uuid,
109 obd2cli_tgt(imp->imp_obd));
113 DEBUG_REQ(D_INFO, req, "pinging %s->%s",
114 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
115 ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
120 void ptlrpc_update_next_ping(struct obd_import *imp, int soon)
123 int time = soon ? PING_INTERVAL_SHORT : PING_INTERVAL;
124 if (imp->imp_state == LUSTRE_IMP_DISCON) {
125 int dtime = max_t(int, CONNECTION_SWITCH_MIN,
127 at_get(&imp->imp_at.iat_net_latency));
128 time = min(time, dtime);
130 imp->imp_next_ping = cfs_time_shift(time);
131 #endif /* ENABLE_PINGER */
134 void ptlrpc_ping_import_soon(struct obd_import *imp)
136 imp->imp_next_ping = cfs_time_current();
139 static inline int imp_is_deactive(struct obd_import *imp)
141 return (imp->imp_deactive ||
142 OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_IMP_DEACTIVE));
145 static inline int ptlrpc_next_reconnect(struct obd_import *imp)
147 if (imp->imp_server_timeout)
148 return cfs_time_shift(obd_timeout / 2);
150 return cfs_time_shift(obd_timeout);
153 cfs_duration_t pinger_check_timeout(cfs_time_t time)
155 struct timeout_item *item;
156 cfs_time_t timeout = PING_INTERVAL;
158 /* The timeout list is a increase order sorted list */
159 mutex_lock(&pinger_mutex);
160 list_for_each_entry(item, &timeout_list, ti_chain) {
161 int ti_timeout = item->ti_timeout;
162 if (timeout > ti_timeout)
163 timeout = ti_timeout;
166 mutex_unlock(&pinger_mutex);
168 return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)),
176 void ptlrpc_pinger_ir_up(void)
178 CDEBUG(D_HA, "IR up\n");
181 EXPORT_SYMBOL(ptlrpc_pinger_ir_up);
183 void ptlrpc_pinger_ir_down(void)
185 CDEBUG(D_HA, "IR down\n");
188 EXPORT_SYMBOL(ptlrpc_pinger_ir_down);
190 static void ptlrpc_pinger_process_import(struct obd_import *imp,
191 unsigned long this_ping)
198 spin_lock(&imp->imp_lock);
200 level = imp->imp_state;
201 force = imp->imp_force_verify;
202 force_next = imp->imp_force_next_verify;
204 * This will be used below only if the import is "FULL".
206 suppress = ir_up && OCD_HAS_FLAG(&imp->imp_connect_data, PINGLESS);
208 imp->imp_force_verify = 0;
210 if (cfs_time_aftereq(imp->imp_next_ping - 5 * CFS_TICK, this_ping) &&
212 spin_unlock(&imp->imp_lock);
216 imp->imp_force_next_verify = 0;
218 spin_unlock(&imp->imp_lock);
220 CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_HA, "%s->%s: level %s/%u "
221 "force %u force_next %u deactive %u pingable %u suppress %u\n",
222 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
223 ptlrpc_import_state_name(level), level, force, force_next,
224 imp->imp_deactive, imp->imp_pingable, suppress);
226 if (level == LUSTRE_IMP_DISCON && !imp_is_deactive(imp)) {
227 /* wait for a while before trying recovery again */
228 imp->imp_next_ping = ptlrpc_next_reconnect(imp);
229 if (!imp->imp_no_pinger_recover)
230 ptlrpc_initiate_recovery(imp);
231 } else if (level != LUSTRE_IMP_FULL ||
232 imp->imp_obd->obd_no_recov ||
233 imp_is_deactive(imp)) {
234 CDEBUG(D_HA, "%s->%s: not pinging (in recovery "
235 "or recovery disabled: %s)\n",
236 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
237 ptlrpc_import_state_name(level));
239 spin_lock(&imp->imp_lock);
240 imp->imp_force_verify = 1;
241 spin_unlock(&imp->imp_lock);
243 } else if ((imp->imp_pingable && !suppress) || force_next || force) {
248 static int ptlrpc_pinger_main(void *arg)
250 struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
253 /* Record that the thread is running */
254 thread_set_flags(thread, SVC_RUNNING);
255 wake_up(&thread->t_ctl_waitq);
257 /* And now, loop forever, pinging as needed. */
259 cfs_time_t this_ping = cfs_time_current();
260 struct l_wait_info lwi;
261 cfs_duration_t time_to_next_wake;
262 struct timeout_item *item;
263 struct list_head *iter;
265 mutex_lock(&pinger_mutex);
266 list_for_each_entry(item, &timeout_list, ti_chain)
267 item->ti_cb(item, item->ti_cb_data);
269 list_for_each(iter, &pinger_imports) {
270 struct obd_import *imp = list_entry(iter,
274 ptlrpc_pinger_process_import(imp, this_ping);
275 /* obd_timeout might have changed */
276 if (imp->imp_pingable && imp->imp_next_ping &&
277 cfs_time_after(imp->imp_next_ping,
278 cfs_time_add(this_ping,
279 cfs_time_seconds(PING_INTERVAL))))
280 ptlrpc_update_next_ping(imp, 0);
282 mutex_unlock(&pinger_mutex);
283 /* update memory usage info */
284 obd_update_maxusage();
286 /* Wait until the next ping time, or until we're stopped. */
287 time_to_next_wake = pinger_check_timeout(this_ping);
288 /* The ping sent by ptlrpc_send_rpc may get sent out
289 say .01 second after this.
290 ptlrpc_pinger_sending_on_import will then set the
291 next ping time to next_ping + .01 sec, which means
292 we will SKIP the next ping at next_ping, and the
293 ping will get sent 2 timeouts from now! Beware. */
294 CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("
295 CFS_TIME_T")\n", time_to_next_wake,
296 cfs_time_add(this_ping,cfs_time_seconds(PING_INTERVAL)));
297 if (time_to_next_wake > 0) {
298 lwi = LWI_TIMEOUT(max_t(cfs_duration_t,
300 cfs_time_seconds(1)),
302 l_wait_event(thread->t_ctl_waitq,
303 thread_is_stopping(thread) ||
304 thread_is_event(thread),
306 if (thread_test_and_clear_flags(thread, SVC_STOPPING)) {
310 /* woken after adding import to reset timer */
311 thread_test_and_clear_flags(thread, SVC_EVENT);
316 thread_set_flags(thread, SVC_STOPPED);
317 wake_up(&thread->t_ctl_waitq);
319 CDEBUG(D_NET, "pinger thread exiting, process %d\n", current_pid());
323 static struct ptlrpc_thread pinger_thread;
325 int ptlrpc_start_pinger(void)
327 struct l_wait_info lwi = { 0 };
328 struct task_struct *task;
330 #ifndef ENABLE_PINGER
335 if (!thread_is_init(&pinger_thread) &&
336 !thread_is_stopped(&pinger_thread))
339 init_waitqueue_head(&pinger_thread.t_ctl_waitq);
341 strcpy(pinger_thread.t_name, "ll_ping");
343 /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
344 * just drop the VM and FILES in kthread_run() right away. */
345 task = kthread_run(ptlrpc_pinger_main, &pinger_thread,
346 pinger_thread.t_name);
349 CERROR("cannot start pinger thread: rc = %d\n", rc);
353 l_wait_event(pinger_thread.t_ctl_waitq,
354 thread_is_running(&pinger_thread), &lwi);
357 CWARN("Pings will be suppressed at the request of the "
358 "administrator. The configuration shall meet the "
359 "additional requirements described in the manual. "
360 "(Search for the \"suppress_pings\" kernel module "
366 int ptlrpc_pinger_remove_timeouts(void);
368 int ptlrpc_stop_pinger(void)
370 struct l_wait_info lwi = { 0 };
371 #ifndef ENABLE_PINGER
376 if (thread_is_init(&pinger_thread) ||
377 thread_is_stopped(&pinger_thread))
380 ptlrpc_pinger_remove_timeouts();
382 thread_set_flags(&pinger_thread, SVC_STOPPING);
383 wake_up(&pinger_thread.t_ctl_waitq);
385 l_wait_event(pinger_thread.t_ctl_waitq,
386 thread_is_stopped(&pinger_thread), &lwi);
390 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
392 ptlrpc_update_next_ping(imp, 0);
394 EXPORT_SYMBOL(ptlrpc_pinger_sending_on_import);
396 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
398 ptlrpc_update_next_ping(imp, 1);
399 assert_spin_locked(&imp->imp_lock);
401 * Avoid reading stale imp_connect_data. When not sure if pings are
402 * expected or not on next connection, we assume they are not and force
403 * one anyway to guarantee the chance of updating
404 * imp_peer_committed_transno.
406 if (imp->imp_state != LUSTRE_IMP_FULL ||
407 OCD_HAS_FLAG(&imp->imp_connect_data, PINGLESS))
408 imp->imp_force_next_verify = 1;
411 int ptlrpc_pinger_add_import(struct obd_import *imp)
414 if (!list_empty(&imp->imp_pinger_chain))
417 mutex_lock(&pinger_mutex);
418 CDEBUG(D_HA, "adding pingable import %s->%s\n",
419 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
420 /* if we add to pinger we want recovery on this import */
421 imp->imp_obd->obd_no_recov = 0;
422 ptlrpc_update_next_ping(imp, 0);
423 /* XXX sort, blah blah */
424 list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
425 class_import_get(imp);
427 ptlrpc_pinger_wake_up();
428 mutex_unlock(&pinger_mutex);
432 EXPORT_SYMBOL(ptlrpc_pinger_add_import);
434 int ptlrpc_pinger_del_import(struct obd_import *imp)
438 if (list_empty(&imp->imp_pinger_chain))
441 mutex_lock(&pinger_mutex);
442 list_del_init(&imp->imp_pinger_chain);
443 CDEBUG(D_HA, "removing pingable import %s->%s\n",
444 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
445 /* if we remove from pinger we don't want recovery on this import */
446 imp->imp_obd->obd_no_recov = 1;
447 class_import_put(imp);
448 mutex_unlock(&pinger_mutex);
451 EXPORT_SYMBOL(ptlrpc_pinger_del_import);
454 * Register a timeout callback to the pinger list, and the callback will
455 * be called when timeout happens.
457 struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
458 timeout_cb_t cb, void *data)
460 struct timeout_item *ti;
466 INIT_LIST_HEAD(&ti->ti_obd_list);
467 INIT_LIST_HEAD(&ti->ti_chain);
468 ti->ti_timeout = time;
469 ti->ti_event = event;
471 ti->ti_cb_data = data;
477 * Register timeout event on the the pinger thread.
478 * Note: the timeout list is an sorted list with increased timeout value.
480 static struct timeout_item*
481 ptlrpc_pinger_register_timeout(int time, enum timeout_event event,
482 timeout_cb_t cb, void *data)
484 struct timeout_item *item, *tmp;
486 LASSERT(mutex_is_locked(&pinger_mutex));
488 list_for_each_entry(item, &timeout_list, ti_chain)
489 if (item->ti_event == event)
492 item = ptlrpc_new_timeout(time, event, cb, data);
494 list_for_each_entry_reverse(tmp, &timeout_list, ti_chain) {
495 if (tmp->ti_timeout < time) {
496 list_add(&item->ti_chain, &tmp->ti_chain);
500 list_add(&item->ti_chain, &timeout_list);
506 /* Add a client_obd to the timeout event list, when timeout(@time)
507 * happens, the callback(@cb) will be called.
509 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
510 timeout_cb_t cb, void *data,
511 struct list_head *obd_list)
513 struct timeout_item *ti;
515 mutex_lock(&pinger_mutex);
516 ti = ptlrpc_pinger_register_timeout(time, event, cb, data);
518 mutex_unlock(&pinger_mutex);
521 list_add(obd_list, &ti->ti_obd_list);
522 mutex_unlock(&pinger_mutex);
525 EXPORT_SYMBOL(ptlrpc_add_timeout_client);
527 int ptlrpc_del_timeout_client(struct list_head *obd_list,
528 enum timeout_event event)
530 struct timeout_item *ti = NULL, *item;
532 if (list_empty(obd_list))
534 mutex_lock(&pinger_mutex);
535 list_del_init(obd_list);
537 * If there are no obd attached to the timeout event
538 * list, remove this timeout event from the pinger
540 list_for_each_entry(item, &timeout_list, ti_chain) {
541 if (item->ti_event == event) {
546 LASSERTF(ti != NULL, "ti is NULL !\n");
547 if (list_empty(&ti->ti_obd_list)) {
548 list_del(&ti->ti_chain);
551 mutex_unlock(&pinger_mutex);
554 EXPORT_SYMBOL(ptlrpc_del_timeout_client);
556 int ptlrpc_pinger_remove_timeouts(void)
558 struct timeout_item *item, *tmp;
560 mutex_lock(&pinger_mutex);
561 list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
562 LASSERT(list_empty(&item->ti_obd_list));
563 list_del(&item->ti_chain);
566 mutex_unlock(&pinger_mutex);
570 void ptlrpc_pinger_wake_up()
573 thread_add_flags(&pinger_thread, SVC_EVENT);
574 wake_up(&pinger_thread.t_ctl_waitq);
578 /* Ping evictor thread */
580 #define PET_TERMINATE 2
582 static int pet_refcount = 0;
583 static int pet_state;
584 static wait_queue_head_t pet_waitq;
585 struct list_head pet_list;
586 static DEFINE_SPINLOCK(pet_lock);
588 int ping_evictor_wake(struct obd_export *exp)
590 struct obd_device *obd;
592 spin_lock(&pet_lock);
593 if (pet_state != PET_READY) {
594 /* eventually the new obd will call here again. */
595 spin_unlock(&pet_lock);
599 obd = class_exp2obd(exp);
600 if (list_empty(&obd->obd_evict_list)) {
601 class_incref(obd, "evictor", obd);
602 list_add(&obd->obd_evict_list, &pet_list);
604 spin_unlock(&pet_lock);
610 static int ping_evictor_main(void *arg)
612 struct obd_device *obd;
613 struct obd_export *exp;
614 struct l_wait_info lwi = { 0 };
620 CDEBUG(D_HA, "Starting Ping Evictor\n");
621 pet_state = PET_READY;
623 l_wait_event(pet_waitq, (!list_empty(&pet_list)) ||
624 (pet_state == PET_TERMINATE), &lwi);
626 /* loop until all obd's will be removed */
627 if ((pet_state == PET_TERMINATE) && list_empty(&pet_list))
630 /* we only get here if pet_exp != NULL, and the end of this
631 * loop is the only place which sets it NULL again, so lock
632 * is not strictly necessary. */
633 spin_lock(&pet_lock);
634 obd = list_entry(pet_list.next, struct obd_device,
636 spin_unlock(&pet_lock);
638 expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
640 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
641 obd->obd_name, expire_time);
643 /* Exports can't be deleted out of the list while we hold
644 * the obd lock (class_unlink_export), which means we can't
645 * lose the last ref on the export. If they've already been
646 * removed from the list, we won't find them here. */
647 spin_lock(&obd->obd_dev_lock);
648 while (!list_empty(&obd->obd_exports_timed)) {
649 exp = list_entry(obd->obd_exports_timed.next,
651 exp_obd_chain_timed);
652 if (expire_time > exp->exp_last_request_time) {
653 class_export_get(exp);
654 spin_unlock(&obd->obd_dev_lock);
655 LCONSOLE_WARN("%s: haven't heard from client %s"
656 " (at %s) in %ld seconds. I think"
657 " it's dead, and I am evicting"
658 " it. exp %p, cur %ld expire %ld"
661 obd_uuid2str(&exp->exp_client_uuid),
662 obd_export_nid2str(exp),
663 (long)(cfs_time_current_sec() -
664 exp->exp_last_request_time),
665 exp, (long)cfs_time_current_sec(),
667 (long)exp->exp_last_request_time);
668 CDEBUG(D_HA, "Last request was at %ld\n",
669 exp->exp_last_request_time);
670 class_fail_export(exp);
671 class_export_put(exp);
672 spin_lock(&obd->obd_dev_lock);
674 /* List is sorted, so everyone below is ok */
678 spin_unlock(&obd->obd_dev_lock);
680 spin_lock(&pet_lock);
681 list_del_init(&obd->obd_evict_list);
682 spin_unlock(&pet_lock);
684 class_decref(obd, "evictor", obd);
686 CDEBUG(D_HA, "Exiting Ping Evictor\n");
691 void ping_evictor_start(void)
693 struct task_struct *task;
695 if (++pet_refcount > 1)
698 INIT_LIST_HEAD(&pet_list);
699 init_waitqueue_head(&pet_waitq);
701 task = kthread_run(ping_evictor_main, NULL, "ll_evictor");
704 CERROR("Cannot start ping evictor thread: %ld\n",
708 EXPORT_SYMBOL(ping_evictor_start);
710 void ping_evictor_stop(void)
712 if (--pet_refcount > 0)
715 pet_state = PET_TERMINATE;
718 EXPORT_SYMBOL(ping_evictor_stop);
719 #else /* !__KERNEL__ */
722 * the current implementation of pinger in liblustre is not optimized
726 static struct pinger_data {
728 cfs_time_t pd_this_ping; /* jiffies */
729 cfs_time_t pd_next_ping; /* jiffies */
730 struct ptlrpc_request_set *pd_set;
733 static int pinger_check_rpcs(void *arg)
735 cfs_time_t curtime = cfs_time_current();
736 struct ptlrpc_request *req;
737 struct ptlrpc_request_set *set;
738 struct list_head *iter;
739 struct obd_import *imp;
740 struct pinger_data *pd = &pinger_args;
743 /* prevent recursion */
744 if (pd->pd_recursion++) {
745 CDEBUG(D_HA, "pinger: recursion! quit\n");
751 /* have we reached ping point? */
752 if (!pd->pd_set && cfs_time_before(curtime, pd->pd_next_ping)) {
757 /* if we have rpc_set already, continue processing it */
759 LASSERT(pd->pd_this_ping);
764 pd->pd_this_ping = curtime;
765 pd->pd_set = ptlrpc_prep_set();
766 if (pd->pd_set == NULL)
770 /* add rpcs into set */
771 mutex_lock(&pinger_mutex);
772 list_for_each(iter, &pinger_imports) {
773 struct obd_import *imp = list_entry(iter, struct obd_import,
775 int generation, level;
777 if (cfs_time_aftereq(pd->pd_this_ping,
778 imp->imp_next_ping - 5 * CFS_TICK)) {
780 spin_lock(&imp->imp_lock);
781 generation = imp->imp_generation;
782 level = imp->imp_state;
783 spin_unlock(&imp->imp_lock);
785 if (level != LUSTRE_IMP_FULL) {
787 "not pinging %s (in recovery)\n",
788 obd2cli_tgt(imp->imp_obd));
792 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
796 CERROR("OOM trying to ping %s->%s\n",
797 imp->imp_obd->obd_uuid.uuid,
798 obd2cli_tgt(imp->imp_obd));
802 req->rq_no_resend = 1;
803 ptlrpc_request_set_replen(req);
804 req->rq_send_state = LUSTRE_IMP_FULL;
805 ptlrpc_rqphase_move(req, RQ_PHASE_RPC);
806 req->rq_import_generation = generation;
807 ptlrpc_set_add_req(set, req);
809 CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
810 " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
811 imp->imp_next_ping, pd->pd_this_ping);
814 pd->pd_this_ping = curtime;
815 mutex_unlock(&pinger_mutex);
817 /* Might be empty, that's OK. */
818 if (atomic_read(&set->set_remaining) == 0)
819 CDEBUG(D_RPCTRACE, "nothing to ping\n");
821 list_for_each(iter, &set->set_requests) {
822 struct ptlrpc_request *req =
823 list_entry(iter, struct ptlrpc_request,
825 DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
826 req->rq_import->imp_obd->obd_uuid.uuid,
827 obd2cli_tgt(req->rq_import->imp_obd));
828 (void)ptl_send_rpc(req, 0);
832 rc = ptlrpc_check_set(NULL, set);
834 /* not finished, and we are not expired, simply return */
835 if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
836 cfs_time_seconds(PING_INTERVAL)))) {
837 CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
842 /* Expire all the requests that didn't come back. */
843 mutex_lock(&pinger_mutex);
844 list_for_each(iter, &set->set_requests) {
845 req = list_entry(iter, struct ptlrpc_request,
848 if (req->rq_phase == RQ_PHASE_COMPLETE)
851 CDEBUG(D_RPCTRACE, "Pinger initiate expire request(%p)\n",
854 /* This will also unregister reply. */
855 ptlrpc_expire_one_request(req, 0);
857 /* We're done with this req, let's finally move it to complete
858 * phase and take care of inflights. */
859 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
860 imp = req->rq_import;
861 spin_lock(&imp->imp_lock);
862 if (!list_empty(&req->rq_list)) {
863 list_del_init(&req->rq_list);
864 atomic_dec(&imp->imp_inflight);
866 spin_unlock(&imp->imp_lock);
867 atomic_dec(&set->set_remaining);
869 mutex_unlock(&pinger_mutex);
871 ptlrpc_set_destroy(set);
875 pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
876 cfs_time_seconds(PING_INTERVAL));
877 pd->pd_this_ping = 0; /* XXX for debug */
879 CDEBUG(D_INFO, "finished a round ping\n");
884 static void *pinger_callback = NULL;
885 #endif /* ENABLE_PINGER */
887 int ptlrpc_start_pinger(void)
890 memset(&pinger_args, 0, sizeof(pinger_args));
891 pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
898 int ptlrpc_stop_pinger(void)
902 liblustre_deregister_wait_callback(pinger_callback);
907 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
910 mutex_lock(&pinger_mutex);
911 ptlrpc_update_next_ping(imp, 0);
912 if (pinger_args.pd_set == NULL &&
913 cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
914 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
915 imp->imp_next_ping, cfs_time_current());
916 pinger_args.pd_next_ping = imp->imp_next_ping;
918 mutex_unlock(&pinger_mutex);
922 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
925 mutex_lock(&pinger_mutex);
926 ptlrpc_update_next_ping(imp, 1);
927 if (pinger_args.pd_set == NULL &&
928 cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
929 CDEBUG(D_HA,"set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
930 imp->imp_next_ping, cfs_time_current());
931 pinger_args.pd_next_ping = imp->imp_next_ping;
933 mutex_unlock(&pinger_mutex);
937 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
938 timeout_cb_t cb, void *data,
939 struct list_head *obd_list)
944 int ptlrpc_del_timeout_client(struct list_head *obd_list,
945 enum timeout_event event)
950 int ptlrpc_pinger_add_import(struct obd_import *imp)
954 if (!list_empty(&imp->imp_pinger_chain))
957 CDEBUG(D_HA, "adding pingable import %s->%s\n",
958 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
959 ptlrpc_pinger_sending_on_import(imp);
961 mutex_lock(&pinger_mutex);
962 list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
963 class_import_get(imp);
964 mutex_unlock(&pinger_mutex);
969 int ptlrpc_pinger_del_import(struct obd_import *imp)
973 if (list_empty(&imp->imp_pinger_chain))
976 mutex_lock(&pinger_mutex);
977 list_del_init(&imp->imp_pinger_chain);
978 CDEBUG(D_HA, "removing pingable import %s->%s\n",
979 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
980 class_import_put(imp);
981 mutex_unlock(&pinger_mutex);
985 void ptlrpc_pinger_wake_up()
988 /* XXX force pinger to run, if needed */
989 struct obd_import *imp;
991 list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
992 CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
993 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
994 #ifdef ENABLE_LIBLUSTRE_RECOVERY
995 if (imp->imp_state == LUSTRE_IMP_DISCON &&
996 !imp_is_deactive(imp))
998 /*XXX only recover for the initial connection */
999 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
1000 imp->imp_state == LUSTRE_IMP_DISCON &&
1001 !imp_is_deactive(imp))
1003 ptlrpc_initiate_recovery(imp);
1004 else if (imp->imp_state != LUSTRE_IMP_FULL)
1005 CDEBUG(D_HA, "Refused to recover import %s->%s "
1006 "state %d, deactive %d\n",
1007 imp->imp_obd->obd_uuid.uuid,
1008 obd2cli_tgt(imp->imp_obd), imp->imp_state,
1009 imp_is_deactive(imp));
1014 #endif /* !__KERNEL__ */