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 CFS_LIST_HEAD(pinger_imports);
56 static cfs_list_t timeout_list = CFS_LIST_HEAD_INIT(timeout_list);
58 int ptlrpc_pinger_suppress_pings()
60 return suppress_pings;
62 EXPORT_SYMBOL(ptlrpc_pinger_suppress_pings);
64 struct ptlrpc_request *
65 ptlrpc_prep_ping(struct obd_import *imp)
67 struct ptlrpc_request *req;
69 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
70 LUSTRE_OBD_VERSION, OBD_PING);
72 ptlrpc_request_set_replen(req);
73 req->rq_no_resend = req->rq_no_delay = 1;
78 int ptlrpc_obd_ping(struct obd_device *obd)
81 struct ptlrpc_request *req;
84 req = ptlrpc_prep_ping(obd->u.cli.cl_import);
88 req->rq_send_state = LUSTRE_IMP_FULL;
90 rc = ptlrpc_queue_wait(req);
92 ptlrpc_req_finished(req);
96 EXPORT_SYMBOL(ptlrpc_obd_ping);
98 int ptlrpc_ping(struct obd_import *imp)
100 struct ptlrpc_request *req;
103 req = ptlrpc_prep_ping(imp);
105 CERROR("OOM trying to ping %s->%s\n",
106 imp->imp_obd->obd_uuid.uuid,
107 obd2cli_tgt(imp->imp_obd));
111 DEBUG_REQ(D_INFO, req, "pinging %s->%s",
112 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
113 ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
118 void ptlrpc_update_next_ping(struct obd_import *imp, int soon)
121 int time = soon ? PING_INTERVAL_SHORT : PING_INTERVAL;
122 if (imp->imp_state == LUSTRE_IMP_DISCON) {
123 int dtime = max_t(int, CONNECTION_SWITCH_MIN,
125 at_get(&imp->imp_at.iat_net_latency));
126 time = min(time, dtime);
128 imp->imp_next_ping = cfs_time_shift(time);
129 #endif /* ENABLE_PINGER */
132 void ptlrpc_ping_import_soon(struct obd_import *imp)
134 imp->imp_next_ping = cfs_time_current();
137 static inline int imp_is_deactive(struct obd_import *imp)
139 return (imp->imp_deactive ||
140 OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_IMP_DEACTIVE));
143 static inline int ptlrpc_next_reconnect(struct obd_import *imp)
145 if (imp->imp_server_timeout)
146 return cfs_time_shift(obd_timeout / 2);
148 return cfs_time_shift(obd_timeout);
151 cfs_duration_t pinger_check_timeout(cfs_time_t time)
153 struct timeout_item *item;
154 cfs_time_t timeout = PING_INTERVAL;
156 /* The timeout list is a increase order sorted list */
157 mutex_lock(&pinger_mutex);
158 cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
159 int ti_timeout = item->ti_timeout;
160 if (timeout > ti_timeout)
161 timeout = ti_timeout;
164 mutex_unlock(&pinger_mutex);
166 return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)),
174 void ptlrpc_pinger_ir_up(void)
176 CDEBUG(D_HA, "IR up\n");
179 EXPORT_SYMBOL(ptlrpc_pinger_ir_up);
181 void ptlrpc_pinger_ir_down(void)
183 CDEBUG(D_HA, "IR down\n");
186 EXPORT_SYMBOL(ptlrpc_pinger_ir_down);
188 static void ptlrpc_pinger_process_import(struct obd_import *imp,
189 unsigned long this_ping)
196 spin_lock(&imp->imp_lock);
198 level = imp->imp_state;
199 force = imp->imp_force_verify;
200 force_next = imp->imp_force_next_verify;
202 * This will be used below only if the import is "FULL".
204 suppress = ir_up && OCD_HAS_FLAG(&imp->imp_connect_data, PINGLESS);
206 imp->imp_force_verify = 0;
208 if (cfs_time_aftereq(imp->imp_next_ping - 5 * CFS_TICK, this_ping) &&
210 spin_unlock(&imp->imp_lock);
214 imp->imp_force_next_verify = 0;
216 spin_unlock(&imp->imp_lock);
218 CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_HA, "%s->%s: level %s/%u "
219 "force %u force_next %u deactive %u pingable %u suppress %u\n",
220 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
221 ptlrpc_import_state_name(level), level, force, force_next,
222 imp->imp_deactive, imp->imp_pingable, suppress);
224 if (level == LUSTRE_IMP_DISCON && !imp_is_deactive(imp)) {
225 /* wait for a while before trying recovery again */
226 imp->imp_next_ping = ptlrpc_next_reconnect(imp);
227 if (!imp->imp_no_pinger_recover)
228 ptlrpc_initiate_recovery(imp);
229 } else if (level != LUSTRE_IMP_FULL ||
230 imp->imp_obd->obd_no_recov ||
231 imp_is_deactive(imp)) {
232 CDEBUG(D_HA, "%s->%s: not pinging (in recovery "
233 "or recovery disabled: %s)\n",
234 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
235 ptlrpc_import_state_name(level));
237 spin_lock(&imp->imp_lock);
238 imp->imp_force_verify = 1;
239 spin_unlock(&imp->imp_lock);
241 } else if ((imp->imp_pingable && !suppress) || force_next || force) {
246 static int ptlrpc_pinger_main(void *arg)
248 struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
251 /* Record that the thread is running */
252 thread_set_flags(thread, SVC_RUNNING);
253 wake_up(&thread->t_ctl_waitq);
255 /* And now, loop forever, pinging as needed. */
257 cfs_time_t this_ping = cfs_time_current();
258 struct l_wait_info lwi;
259 cfs_duration_t time_to_next_wake;
260 struct timeout_item *item;
263 mutex_lock(&pinger_mutex);
264 cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
265 item->ti_cb(item, item->ti_cb_data);
267 cfs_list_for_each(iter, &pinger_imports) {
268 struct obd_import *imp =
269 cfs_list_entry(iter, struct obd_import,
272 ptlrpc_pinger_process_import(imp, this_ping);
273 /* obd_timeout might have changed */
274 if (imp->imp_pingable && imp->imp_next_ping &&
275 cfs_time_after(imp->imp_next_ping,
276 cfs_time_add(this_ping,
277 cfs_time_seconds(PING_INTERVAL))))
278 ptlrpc_update_next_ping(imp, 0);
280 mutex_unlock(&pinger_mutex);
281 /* update memory usage info */
282 obd_update_maxusage();
284 /* Wait until the next ping time, or until we're stopped. */
285 time_to_next_wake = pinger_check_timeout(this_ping);
286 /* The ping sent by ptlrpc_send_rpc may get sent out
287 say .01 second after this.
288 ptlrpc_pinger_sending_on_import will then set the
289 next ping time to next_ping + .01 sec, which means
290 we will SKIP the next ping at next_ping, and the
291 ping will get sent 2 timeouts from now! Beware. */
292 CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("
293 CFS_TIME_T")\n", time_to_next_wake,
294 cfs_time_add(this_ping,cfs_time_seconds(PING_INTERVAL)));
295 if (time_to_next_wake > 0) {
296 lwi = LWI_TIMEOUT(max_t(cfs_duration_t,
298 cfs_time_seconds(1)),
300 l_wait_event(thread->t_ctl_waitq,
301 thread_is_stopping(thread) ||
302 thread_is_event(thread),
304 if (thread_test_and_clear_flags(thread, SVC_STOPPING)) {
308 /* woken after adding import to reset timer */
309 thread_test_and_clear_flags(thread, SVC_EVENT);
314 thread_set_flags(thread, SVC_STOPPED);
315 wake_up(&thread->t_ctl_waitq);
317 CDEBUG(D_NET, "pinger thread exiting, process %d\n", current_pid());
321 static struct ptlrpc_thread pinger_thread;
323 int ptlrpc_start_pinger(void)
325 struct l_wait_info lwi = { 0 };
326 struct task_struct *task;
328 #ifndef ENABLE_PINGER
333 if (!thread_is_init(&pinger_thread) &&
334 !thread_is_stopped(&pinger_thread))
337 init_waitqueue_head(&pinger_thread.t_ctl_waitq);
339 strcpy(pinger_thread.t_name, "ll_ping");
341 /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
342 * just drop the VM and FILES in kthread_run() right away. */
343 task = kthread_run(ptlrpc_pinger_main, &pinger_thread,
344 pinger_thread.t_name);
347 CERROR("cannot start pinger thread: rc = %d\n", rc);
351 l_wait_event(pinger_thread.t_ctl_waitq,
352 thread_is_running(&pinger_thread), &lwi);
355 CWARN("Pings will be suppressed at the request of the "
356 "administrator. The configuration shall meet the "
357 "additional requirements described in the manual. "
358 "(Search for the \"suppress_pings\" kernel module "
364 int ptlrpc_pinger_remove_timeouts(void);
366 int ptlrpc_stop_pinger(void)
368 struct l_wait_info lwi = { 0 };
369 #ifndef ENABLE_PINGER
374 if (thread_is_init(&pinger_thread) ||
375 thread_is_stopped(&pinger_thread))
378 ptlrpc_pinger_remove_timeouts();
380 thread_set_flags(&pinger_thread, SVC_STOPPING);
381 wake_up(&pinger_thread.t_ctl_waitq);
383 l_wait_event(pinger_thread.t_ctl_waitq,
384 thread_is_stopped(&pinger_thread), &lwi);
388 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
390 ptlrpc_update_next_ping(imp, 0);
392 EXPORT_SYMBOL(ptlrpc_pinger_sending_on_import);
394 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
396 ptlrpc_update_next_ping(imp, 1);
397 assert_spin_locked(&imp->imp_lock);
399 * Avoid reading stale imp_connect_data. When not sure if pings are
400 * expected or not on next connection, we assume they are not and force
401 * one anyway to guarantee the chance of updating
402 * imp_peer_committed_transno.
404 if (imp->imp_state != LUSTRE_IMP_FULL ||
405 OCD_HAS_FLAG(&imp->imp_connect_data, PINGLESS))
406 imp->imp_force_next_verify = 1;
409 int ptlrpc_pinger_add_import(struct obd_import *imp)
412 if (!cfs_list_empty(&imp->imp_pinger_chain))
415 mutex_lock(&pinger_mutex);
416 CDEBUG(D_HA, "adding pingable import %s->%s\n",
417 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
418 /* if we add to pinger we want recovery on this import */
419 imp->imp_obd->obd_no_recov = 0;
420 ptlrpc_update_next_ping(imp, 0);
421 /* XXX sort, blah blah */
422 cfs_list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
423 class_import_get(imp);
425 ptlrpc_pinger_wake_up();
426 mutex_unlock(&pinger_mutex);
430 EXPORT_SYMBOL(ptlrpc_pinger_add_import);
432 int ptlrpc_pinger_del_import(struct obd_import *imp)
435 if (cfs_list_empty(&imp->imp_pinger_chain))
438 mutex_lock(&pinger_mutex);
439 cfs_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_unlock(&pinger_mutex);
448 EXPORT_SYMBOL(ptlrpc_pinger_del_import);
451 * Register a timeout callback to the pinger list, and the callback will
452 * be called when timeout happens.
454 struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
455 timeout_cb_t cb, void *data)
457 struct timeout_item *ti;
463 CFS_INIT_LIST_HEAD(&ti->ti_obd_list);
464 CFS_INIT_LIST_HEAD(&ti->ti_chain);
465 ti->ti_timeout = time;
466 ti->ti_event = event;
468 ti->ti_cb_data = data;
474 * Register timeout event on the the pinger thread.
475 * Note: the timeout list is an sorted list with increased timeout value.
477 static struct timeout_item*
478 ptlrpc_pinger_register_timeout(int time, enum timeout_event event,
479 timeout_cb_t cb, void *data)
481 struct timeout_item *item, *tmp;
483 LASSERT(mutex_is_locked(&pinger_mutex));
485 cfs_list_for_each_entry(item, &timeout_list, ti_chain)
486 if (item->ti_event == event)
489 item = ptlrpc_new_timeout(time, event, cb, data);
491 cfs_list_for_each_entry_reverse(tmp, &timeout_list, ti_chain) {
492 if (tmp->ti_timeout < time) {
493 cfs_list_add(&item->ti_chain, &tmp->ti_chain);
497 cfs_list_add(&item->ti_chain, &timeout_list);
503 /* Add a client_obd to the timeout event list, when timeout(@time)
504 * happens, the callback(@cb) will be called.
506 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
507 timeout_cb_t cb, void *data,
508 cfs_list_t *obd_list)
510 struct timeout_item *ti;
512 mutex_lock(&pinger_mutex);
513 ti = ptlrpc_pinger_register_timeout(time, event, cb, data);
515 mutex_unlock(&pinger_mutex);
518 cfs_list_add(obd_list, &ti->ti_obd_list);
519 mutex_unlock(&pinger_mutex);
522 EXPORT_SYMBOL(ptlrpc_add_timeout_client);
524 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
525 enum timeout_event event)
527 struct timeout_item *ti = NULL, *item;
529 if (cfs_list_empty(obd_list))
531 mutex_lock(&pinger_mutex);
532 cfs_list_del_init(obd_list);
534 * If there are no obd attached to the timeout event
535 * list, remove this timeout event from the pinger
537 cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
538 if (item->ti_event == event) {
543 LASSERTF(ti != NULL, "ti is NULL ! \n");
544 if (cfs_list_empty(&ti->ti_obd_list)) {
545 cfs_list_del(&ti->ti_chain);
548 mutex_unlock(&pinger_mutex);
551 EXPORT_SYMBOL(ptlrpc_del_timeout_client);
553 int ptlrpc_pinger_remove_timeouts(void)
555 struct timeout_item *item, *tmp;
557 mutex_lock(&pinger_mutex);
558 cfs_list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
559 LASSERT(cfs_list_empty(&item->ti_obd_list));
560 cfs_list_del(&item->ti_chain);
563 mutex_unlock(&pinger_mutex);
567 void ptlrpc_pinger_wake_up()
570 thread_add_flags(&pinger_thread, SVC_EVENT);
571 wake_up(&pinger_thread.t_ctl_waitq);
575 /* Ping evictor thread */
577 #define PET_TERMINATE 2
579 static int pet_refcount = 0;
580 static int pet_state;
581 static wait_queue_head_t pet_waitq;
582 CFS_LIST_HEAD(pet_list);
583 static DEFINE_SPINLOCK(pet_lock);
585 int ping_evictor_wake(struct obd_export *exp)
587 struct obd_device *obd;
589 spin_lock(&pet_lock);
590 if (pet_state != PET_READY) {
591 /* eventually the new obd will call here again. */
592 spin_unlock(&pet_lock);
596 obd = class_exp2obd(exp);
597 if (cfs_list_empty(&obd->obd_evict_list)) {
598 class_incref(obd, "evictor", obd);
599 cfs_list_add(&obd->obd_evict_list, &pet_list);
601 spin_unlock(&pet_lock);
607 static int ping_evictor_main(void *arg)
609 struct obd_device *obd;
610 struct obd_export *exp;
611 struct l_wait_info lwi = { 0 };
617 CDEBUG(D_HA, "Starting Ping Evictor\n");
618 pet_state = PET_READY;
620 l_wait_event(pet_waitq, (!cfs_list_empty(&pet_list)) ||
621 (pet_state == PET_TERMINATE), &lwi);
623 /* loop until all obd's will be removed */
624 if ((pet_state == PET_TERMINATE) && cfs_list_empty(&pet_list))
627 /* we only get here if pet_exp != NULL, and the end of this
628 * loop is the only place which sets it NULL again, so lock
629 * is not strictly necessary. */
630 spin_lock(&pet_lock);
631 obd = cfs_list_entry(pet_list.next, struct obd_device,
633 spin_unlock(&pet_lock);
635 expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
637 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
638 obd->obd_name, expire_time);
640 /* Exports can't be deleted out of the list while we hold
641 * the obd lock (class_unlink_export), which means we can't
642 * lose the last ref on the export. If they've already been
643 * removed from the list, we won't find them here. */
644 spin_lock(&obd->obd_dev_lock);
645 while (!cfs_list_empty(&obd->obd_exports_timed)) {
646 exp = cfs_list_entry(obd->obd_exports_timed.next,
648 exp_obd_chain_timed);
649 if (expire_time > exp->exp_last_request_time) {
650 class_export_get(exp);
651 spin_unlock(&obd->obd_dev_lock);
652 LCONSOLE_WARN("%s: haven't heard from client %s"
653 " (at %s) in %ld seconds. I think"
654 " it's dead, and I am evicting"
655 " it. exp %p, cur %ld expire %ld"
658 obd_uuid2str(&exp->exp_client_uuid),
659 obd_export_nid2str(exp),
660 (long)(cfs_time_current_sec() -
661 exp->exp_last_request_time),
662 exp, (long)cfs_time_current_sec(),
664 (long)exp->exp_last_request_time);
665 CDEBUG(D_HA, "Last request was at %ld\n",
666 exp->exp_last_request_time);
667 class_fail_export(exp);
668 class_export_put(exp);
669 spin_lock(&obd->obd_dev_lock);
671 /* List is sorted, so everyone below is ok */
675 spin_unlock(&obd->obd_dev_lock);
677 spin_lock(&pet_lock);
678 cfs_list_del_init(&obd->obd_evict_list);
679 spin_unlock(&pet_lock);
681 class_decref(obd, "evictor", obd);
683 CDEBUG(D_HA, "Exiting Ping Evictor\n");
688 void ping_evictor_start(void)
690 struct task_struct *task;
692 if (++pet_refcount > 1)
695 init_waitqueue_head(&pet_waitq);
697 task = kthread_run(ping_evictor_main, NULL, "ll_evictor");
700 CERROR("Cannot start ping evictor thread: %ld\n",
704 EXPORT_SYMBOL(ping_evictor_start);
706 void ping_evictor_stop(void)
708 if (--pet_refcount > 0)
711 pet_state = PET_TERMINATE;
714 EXPORT_SYMBOL(ping_evictor_stop);
715 #else /* !__KERNEL__ */
718 * the current implementation of pinger in liblustre is not optimized
722 static struct pinger_data {
724 cfs_time_t pd_this_ping; /* jiffies */
725 cfs_time_t pd_next_ping; /* jiffies */
726 struct ptlrpc_request_set *pd_set;
729 static int pinger_check_rpcs(void *arg)
731 cfs_time_t curtime = cfs_time_current();
732 struct ptlrpc_request *req;
733 struct ptlrpc_request_set *set;
735 struct obd_import *imp;
736 struct pinger_data *pd = &pinger_args;
739 /* prevent recursion */
740 if (pd->pd_recursion++) {
741 CDEBUG(D_HA, "pinger: recursion! quit\n");
747 /* have we reached ping point? */
748 if (!pd->pd_set && cfs_time_before(curtime, pd->pd_next_ping)) {
753 /* if we have rpc_set already, continue processing it */
755 LASSERT(pd->pd_this_ping);
760 pd->pd_this_ping = curtime;
761 pd->pd_set = ptlrpc_prep_set();
762 if (pd->pd_set == NULL)
766 /* add rpcs into set */
767 mutex_lock(&pinger_mutex);
768 cfs_list_for_each(iter, &pinger_imports) {
769 struct obd_import *imp = cfs_list_entry(iter, struct obd_import,
771 int generation, level;
773 if (cfs_time_aftereq(pd->pd_this_ping,
774 imp->imp_next_ping - 5 * CFS_TICK)) {
776 spin_lock(&imp->imp_lock);
777 generation = imp->imp_generation;
778 level = imp->imp_state;
779 spin_unlock(&imp->imp_lock);
781 if (level != LUSTRE_IMP_FULL) {
783 "not pinging %s (in recovery)\n",
784 obd2cli_tgt(imp->imp_obd));
788 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
792 CERROR("OOM trying to ping %s->%s\n",
793 imp->imp_obd->obd_uuid.uuid,
794 obd2cli_tgt(imp->imp_obd));
798 req->rq_no_resend = 1;
799 ptlrpc_request_set_replen(req);
800 req->rq_send_state = LUSTRE_IMP_FULL;
801 ptlrpc_rqphase_move(req, RQ_PHASE_RPC);
802 req->rq_import_generation = generation;
803 ptlrpc_set_add_req(set, req);
805 CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
806 " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
807 imp->imp_next_ping, pd->pd_this_ping);
810 pd->pd_this_ping = curtime;
811 mutex_unlock(&pinger_mutex);
813 /* Might be empty, that's OK. */
814 if (atomic_read(&set->set_remaining) == 0)
815 CDEBUG(D_RPCTRACE, "nothing to ping\n");
817 cfs_list_for_each(iter, &set->set_requests) {
818 struct ptlrpc_request *req =
819 cfs_list_entry(iter, struct ptlrpc_request,
821 DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
822 req->rq_import->imp_obd->obd_uuid.uuid,
823 obd2cli_tgt(req->rq_import->imp_obd));
824 (void)ptl_send_rpc(req, 0);
828 rc = ptlrpc_check_set(NULL, set);
830 /* not finished, and we are not expired, simply return */
831 if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
832 cfs_time_seconds(PING_INTERVAL)))) {
833 CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
838 /* Expire all the requests that didn't come back. */
839 mutex_lock(&pinger_mutex);
840 cfs_list_for_each(iter, &set->set_requests) {
841 req = cfs_list_entry(iter, struct ptlrpc_request,
844 if (req->rq_phase == RQ_PHASE_COMPLETE)
847 CDEBUG(D_RPCTRACE, "Pinger initiate expire request(%p)\n",
850 /* This will also unregister reply. */
851 ptlrpc_expire_one_request(req, 0);
853 /* We're done with this req, let's finally move it to complete
854 * phase and take care of inflights. */
855 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
856 imp = req->rq_import;
857 spin_lock(&imp->imp_lock);
858 if (!cfs_list_empty(&req->rq_list)) {
859 cfs_list_del_init(&req->rq_list);
860 atomic_dec(&imp->imp_inflight);
862 spin_unlock(&imp->imp_lock);
863 atomic_dec(&set->set_remaining);
865 mutex_unlock(&pinger_mutex);
867 ptlrpc_set_destroy(set);
871 pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
872 cfs_time_seconds(PING_INTERVAL));
873 pd->pd_this_ping = 0; /* XXX for debug */
875 CDEBUG(D_INFO, "finished a round ping\n");
880 static void *pinger_callback = NULL;
881 #endif /* ENABLE_PINGER */
883 int ptlrpc_start_pinger(void)
886 memset(&pinger_args, 0, sizeof(pinger_args));
887 pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
894 int ptlrpc_stop_pinger(void)
898 liblustre_deregister_wait_callback(pinger_callback);
903 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
906 mutex_lock(&pinger_mutex);
907 ptlrpc_update_next_ping(imp, 0);
908 if (pinger_args.pd_set == NULL &&
909 cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
910 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
911 imp->imp_next_ping, cfs_time_current());
912 pinger_args.pd_next_ping = imp->imp_next_ping;
914 mutex_unlock(&pinger_mutex);
918 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
921 mutex_lock(&pinger_mutex);
922 ptlrpc_update_next_ping(imp, 1);
923 if (pinger_args.pd_set == NULL &&
924 cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
925 CDEBUG(D_HA,"set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
926 imp->imp_next_ping, cfs_time_current());
927 pinger_args.pd_next_ping = imp->imp_next_ping;
929 mutex_unlock(&pinger_mutex);
933 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
934 timeout_cb_t cb, void *data,
935 cfs_list_t *obd_list)
940 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
941 enum timeout_event event)
946 int ptlrpc_pinger_add_import(struct obd_import *imp)
949 if (!cfs_list_empty(&imp->imp_pinger_chain))
952 CDEBUG(D_HA, "adding pingable import %s->%s\n",
953 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
954 ptlrpc_pinger_sending_on_import(imp);
956 mutex_lock(&pinger_mutex);
957 cfs_list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
958 class_import_get(imp);
959 mutex_unlock(&pinger_mutex);
964 int ptlrpc_pinger_del_import(struct obd_import *imp)
967 if (cfs_list_empty(&imp->imp_pinger_chain))
970 mutex_lock(&pinger_mutex);
971 cfs_list_del_init(&imp->imp_pinger_chain);
972 CDEBUG(D_HA, "removing pingable import %s->%s\n",
973 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
974 class_import_put(imp);
975 mutex_unlock(&pinger_mutex);
979 void ptlrpc_pinger_wake_up()
982 /* XXX force pinger to run, if needed */
983 struct obd_import *imp;
985 cfs_list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
986 CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
987 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
988 #ifdef ENABLE_LIBLUSTRE_RECOVERY
989 if (imp->imp_state == LUSTRE_IMP_DISCON &&
990 !imp_is_deactive(imp))
992 /*XXX only recover for the initial connection */
993 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
994 imp->imp_state == LUSTRE_IMP_DISCON &&
995 !imp_is_deactive(imp))
997 ptlrpc_initiate_recovery(imp);
998 else if (imp->imp_state != LUSTRE_IMP_FULL)
999 CDEBUG(D_HA, "Refused to recover import %s->%s "
1000 "state %d, deactive %d\n",
1001 imp->imp_obd->obd_uuid.uuid,
1002 obd2cli_tgt(imp->imp_obd), imp->imp_state,
1003 imp_is_deactive(imp));
1008 #endif /* !__KERNEL__ */