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));
236 } else if ((imp->imp_pingable && !suppress) || force_next || force) {
241 static int ptlrpc_pinger_main(void *arg)
243 struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
246 /* Record that the thread is running */
247 thread_set_flags(thread, SVC_RUNNING);
248 wake_up(&thread->t_ctl_waitq);
250 /* And now, loop forever, pinging as needed. */
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;
258 mutex_lock(&pinger_mutex);
259 cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
260 item->ti_cb(item, item->ti_cb_data);
262 cfs_list_for_each(iter, &pinger_imports) {
263 struct obd_import *imp =
264 cfs_list_entry(iter, struct obd_import,
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);
275 mutex_unlock(&pinger_mutex);
276 /* update memory usage info */
277 obd_update_maxusage();
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,
293 cfs_time_seconds(1)),
295 l_wait_event(thread->t_ctl_waitq,
296 thread_is_stopping(thread) ||
297 thread_is_event(thread),
299 if (thread_test_and_clear_flags(thread, SVC_STOPPING)) {
303 /* woken after adding import to reset timer */
304 thread_test_and_clear_flags(thread, SVC_EVENT);
309 thread_set_flags(thread, SVC_STOPPED);
310 wake_up(&thread->t_ctl_waitq);
312 CDEBUG(D_NET, "pinger thread exiting, process %d\n", current_pid());
316 static struct ptlrpc_thread pinger_thread;
318 int ptlrpc_start_pinger(void)
320 struct l_wait_info lwi = { 0 };
321 struct task_struct *task;
323 #ifndef ENABLE_PINGER
328 if (!thread_is_init(&pinger_thread) &&
329 !thread_is_stopped(&pinger_thread))
332 init_waitqueue_head(&pinger_thread.t_ctl_waitq);
334 strcpy(pinger_thread.t_name, "ll_ping");
336 /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
337 * just drop the VM and FILES in kthread_run() right away. */
338 task = kthread_run(ptlrpc_pinger_main, &pinger_thread,
339 pinger_thread.t_name);
342 CERROR("cannot start pinger thread: rc = %d\n", rc);
346 l_wait_event(pinger_thread.t_ctl_waitq,
347 thread_is_running(&pinger_thread), &lwi);
350 CWARN("Pings will be suppressed at the request of the "
351 "administrator. The configuration shall meet the "
352 "additional requirements described in the manual. "
353 "(Search for the \"suppress_pings\" kernel module "
359 int ptlrpc_pinger_remove_timeouts(void);
361 int ptlrpc_stop_pinger(void)
363 struct l_wait_info lwi = { 0 };
364 #ifndef ENABLE_PINGER
369 if (thread_is_init(&pinger_thread) ||
370 thread_is_stopped(&pinger_thread))
373 ptlrpc_pinger_remove_timeouts();
375 thread_set_flags(&pinger_thread, SVC_STOPPING);
376 wake_up(&pinger_thread.t_ctl_waitq);
378 l_wait_event(pinger_thread.t_ctl_waitq,
379 thread_is_stopped(&pinger_thread), &lwi);
383 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
385 ptlrpc_update_next_ping(imp, 0);
387 EXPORT_SYMBOL(ptlrpc_pinger_sending_on_import);
389 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
391 ptlrpc_update_next_ping(imp, 1);
392 LASSERT(spin_is_locked(&imp->imp_lock));
394 * Avoid reading stale imp_connect_data. When not sure if pings are
395 * expected or not on next connection, we assume they are not and force
396 * one anyway to guarantee the chance of updating
397 * imp_peer_committed_transno.
399 if (imp->imp_state != LUSTRE_IMP_FULL ||
400 OCD_HAS_FLAG(&imp->imp_connect_data, PINGLESS))
401 imp->imp_force_next_verify = 1;
404 int ptlrpc_pinger_add_import(struct obd_import *imp)
407 if (!cfs_list_empty(&imp->imp_pinger_chain))
410 mutex_lock(&pinger_mutex);
411 CDEBUG(D_HA, "adding pingable import %s->%s\n",
412 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
413 /* if we add to pinger we want recovery on this import */
414 imp->imp_obd->obd_no_recov = 0;
415 ptlrpc_update_next_ping(imp, 0);
416 /* XXX sort, blah blah */
417 cfs_list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
418 class_import_get(imp);
420 ptlrpc_pinger_wake_up();
421 mutex_unlock(&pinger_mutex);
425 EXPORT_SYMBOL(ptlrpc_pinger_add_import);
427 int ptlrpc_pinger_del_import(struct obd_import *imp)
430 if (cfs_list_empty(&imp->imp_pinger_chain))
433 mutex_lock(&pinger_mutex);
434 cfs_list_del_init(&imp->imp_pinger_chain);
435 CDEBUG(D_HA, "removing pingable import %s->%s\n",
436 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
437 /* if we remove from pinger we don't want recovery on this import */
438 imp->imp_obd->obd_no_recov = 1;
439 class_import_put(imp);
440 mutex_unlock(&pinger_mutex);
443 EXPORT_SYMBOL(ptlrpc_pinger_del_import);
446 * Register a timeout callback to the pinger list, and the callback will
447 * be called when timeout happens.
449 struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
450 timeout_cb_t cb, void *data)
452 struct timeout_item *ti;
458 CFS_INIT_LIST_HEAD(&ti->ti_obd_list);
459 CFS_INIT_LIST_HEAD(&ti->ti_chain);
460 ti->ti_timeout = time;
461 ti->ti_event = event;
463 ti->ti_cb_data = data;
469 * Register timeout event on the the pinger thread.
470 * Note: the timeout list is an sorted list with increased timeout value.
472 static struct timeout_item*
473 ptlrpc_pinger_register_timeout(int time, enum timeout_event event,
474 timeout_cb_t cb, void *data)
476 struct timeout_item *item, *tmp;
478 LASSERT(mutex_is_locked(&pinger_mutex));
480 cfs_list_for_each_entry(item, &timeout_list, ti_chain)
481 if (item->ti_event == event)
484 item = ptlrpc_new_timeout(time, event, cb, data);
486 cfs_list_for_each_entry_reverse(tmp, &timeout_list, ti_chain) {
487 if (tmp->ti_timeout < time) {
488 cfs_list_add(&item->ti_chain, &tmp->ti_chain);
492 cfs_list_add(&item->ti_chain, &timeout_list);
498 /* Add a client_obd to the timeout event list, when timeout(@time)
499 * happens, the callback(@cb) will be called.
501 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
502 timeout_cb_t cb, void *data,
503 cfs_list_t *obd_list)
505 struct timeout_item *ti;
507 mutex_lock(&pinger_mutex);
508 ti = ptlrpc_pinger_register_timeout(time, event, cb, data);
510 mutex_unlock(&pinger_mutex);
513 cfs_list_add(obd_list, &ti->ti_obd_list);
514 mutex_unlock(&pinger_mutex);
517 EXPORT_SYMBOL(ptlrpc_add_timeout_client);
519 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
520 enum timeout_event event)
522 struct timeout_item *ti = NULL, *item;
524 if (cfs_list_empty(obd_list))
526 mutex_lock(&pinger_mutex);
527 cfs_list_del_init(obd_list);
529 * If there are no obd attached to the timeout event
530 * list, remove this timeout event from the pinger
532 cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
533 if (item->ti_event == event) {
538 LASSERTF(ti != NULL, "ti is NULL ! \n");
539 if (cfs_list_empty(&ti->ti_obd_list)) {
540 cfs_list_del(&ti->ti_chain);
543 mutex_unlock(&pinger_mutex);
546 EXPORT_SYMBOL(ptlrpc_del_timeout_client);
548 int ptlrpc_pinger_remove_timeouts(void)
550 struct timeout_item *item, *tmp;
552 mutex_lock(&pinger_mutex);
553 cfs_list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
554 LASSERT(cfs_list_empty(&item->ti_obd_list));
555 cfs_list_del(&item->ti_chain);
558 mutex_unlock(&pinger_mutex);
562 void ptlrpc_pinger_wake_up()
565 thread_add_flags(&pinger_thread, SVC_EVENT);
566 wake_up(&pinger_thread.t_ctl_waitq);
570 /* Ping evictor thread */
572 #define PET_TERMINATE 2
574 static int pet_refcount = 0;
575 static int pet_state;
576 static wait_queue_head_t pet_waitq;
577 CFS_LIST_HEAD(pet_list);
578 static DEFINE_SPINLOCK(pet_lock);
580 int ping_evictor_wake(struct obd_export *exp)
582 struct obd_device *obd;
584 spin_lock(&pet_lock);
585 if (pet_state != PET_READY) {
586 /* eventually the new obd will call here again. */
587 spin_unlock(&pet_lock);
591 obd = class_exp2obd(exp);
592 if (cfs_list_empty(&obd->obd_evict_list)) {
593 class_incref(obd, "evictor", obd);
594 cfs_list_add(&obd->obd_evict_list, &pet_list);
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 };
612 CDEBUG(D_HA, "Starting Ping Evictor\n");
613 pet_state = PET_READY;
615 l_wait_event(pet_waitq, (!cfs_list_empty(&pet_list)) ||
616 (pet_state == PET_TERMINATE), &lwi);
618 /* loop until all obd's will be removed */
619 if ((pet_state == PET_TERMINATE) && cfs_list_empty(&pet_list))
622 /* we only get here if pet_exp != NULL, and the end of this
623 * loop is the only place which sets it NULL again, so lock
624 * is not strictly necessary. */
625 spin_lock(&pet_lock);
626 obd = cfs_list_entry(pet_list.next, struct obd_device,
628 spin_unlock(&pet_lock);
630 expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
632 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
633 obd->obd_name, expire_time);
635 /* Exports can't be deleted out of the list while we hold
636 * the obd lock (class_unlink_export), which means we can't
637 * lose the last ref on the export. If they've already been
638 * removed from the list, we won't find them here. */
639 spin_lock(&obd->obd_dev_lock);
640 while (!cfs_list_empty(&obd->obd_exports_timed)) {
641 exp = cfs_list_entry(obd->obd_exports_timed.next,
643 exp_obd_chain_timed);
644 if (expire_time > exp->exp_last_request_time) {
645 class_export_get(exp);
646 spin_unlock(&obd->obd_dev_lock);
647 LCONSOLE_WARN("%s: haven't heard from client %s"
648 " (at %s) in %ld seconds. I think"
649 " it's dead, and I am evicting"
650 " it. exp %p, cur %ld expire %ld"
653 obd_uuid2str(&exp->exp_client_uuid),
654 obd_export_nid2str(exp),
655 (long)(cfs_time_current_sec() -
656 exp->exp_last_request_time),
657 exp, (long)cfs_time_current_sec(),
659 (long)exp->exp_last_request_time);
660 CDEBUG(D_HA, "Last request was at %ld\n",
661 exp->exp_last_request_time);
662 class_fail_export(exp);
663 class_export_put(exp);
664 spin_lock(&obd->obd_dev_lock);
666 /* List is sorted, so everyone below is ok */
670 spin_unlock(&obd->obd_dev_lock);
672 spin_lock(&pet_lock);
673 cfs_list_del_init(&obd->obd_evict_list);
674 spin_unlock(&pet_lock);
676 class_decref(obd, "evictor", obd);
678 CDEBUG(D_HA, "Exiting Ping Evictor\n");
683 void ping_evictor_start(void)
685 struct task_struct *task;
687 if (++pet_refcount > 1)
690 init_waitqueue_head(&pet_waitq);
692 task = kthread_run(ping_evictor_main, NULL, "ll_evictor");
695 CERROR("Cannot start ping evictor thread: %ld\n",
699 EXPORT_SYMBOL(ping_evictor_start);
701 void ping_evictor_stop(void)
703 if (--pet_refcount > 0)
706 pet_state = PET_TERMINATE;
709 EXPORT_SYMBOL(ping_evictor_stop);
710 #else /* !__KERNEL__ */
713 * the current implementation of pinger in liblustre is not optimized
717 static struct pinger_data {
719 cfs_time_t pd_this_ping; /* jiffies */
720 cfs_time_t pd_next_ping; /* jiffies */
721 struct ptlrpc_request_set *pd_set;
724 static int pinger_check_rpcs(void *arg)
726 cfs_time_t curtime = cfs_time_current();
727 struct ptlrpc_request *req;
728 struct ptlrpc_request_set *set;
730 struct obd_import *imp;
731 struct pinger_data *pd = &pinger_args;
734 /* prevent recursion */
735 if (pd->pd_recursion++) {
736 CDEBUG(D_HA, "pinger: recursion! quit\n");
742 /* have we reached ping point? */
743 if (!pd->pd_set && cfs_time_before(curtime, pd->pd_next_ping)) {
748 /* if we have rpc_set already, continue processing it */
750 LASSERT(pd->pd_this_ping);
755 pd->pd_this_ping = curtime;
756 pd->pd_set = ptlrpc_prep_set();
757 if (pd->pd_set == NULL)
761 /* add rpcs into set */
762 mutex_lock(&pinger_mutex);
763 cfs_list_for_each(iter, &pinger_imports) {
764 struct obd_import *imp = cfs_list_entry(iter, struct obd_import,
766 int generation, level;
768 if (cfs_time_aftereq(pd->pd_this_ping,
769 imp->imp_next_ping - 5 * CFS_TICK)) {
771 spin_lock(&imp->imp_lock);
772 generation = imp->imp_generation;
773 level = imp->imp_state;
774 spin_unlock(&imp->imp_lock);
776 if (level != LUSTRE_IMP_FULL) {
778 "not pinging %s (in recovery)\n",
779 obd2cli_tgt(imp->imp_obd));
783 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
787 CERROR("OOM trying to ping %s->%s\n",
788 imp->imp_obd->obd_uuid.uuid,
789 obd2cli_tgt(imp->imp_obd));
793 req->rq_no_resend = 1;
794 ptlrpc_request_set_replen(req);
795 req->rq_send_state = LUSTRE_IMP_FULL;
796 ptlrpc_rqphase_move(req, RQ_PHASE_RPC);
797 req->rq_import_generation = generation;
798 ptlrpc_set_add_req(set, req);
800 CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
801 " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
802 imp->imp_next_ping, pd->pd_this_ping);
805 pd->pd_this_ping = curtime;
806 mutex_unlock(&pinger_mutex);
808 /* Might be empty, that's OK. */
809 if (cfs_atomic_read(&set->set_remaining) == 0)
810 CDEBUG(D_RPCTRACE, "nothing to ping\n");
812 cfs_list_for_each(iter, &set->set_requests) {
813 struct ptlrpc_request *req =
814 cfs_list_entry(iter, struct ptlrpc_request,
816 DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
817 req->rq_import->imp_obd->obd_uuid.uuid,
818 obd2cli_tgt(req->rq_import->imp_obd));
819 (void)ptl_send_rpc(req, 0);
823 rc = ptlrpc_check_set(NULL, set);
825 /* not finished, and we are not expired, simply return */
826 if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
827 cfs_time_seconds(PING_INTERVAL)))) {
828 CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
833 /* Expire all the requests that didn't come back. */
834 mutex_lock(&pinger_mutex);
835 cfs_list_for_each(iter, &set->set_requests) {
836 req = cfs_list_entry(iter, struct ptlrpc_request,
839 if (req->rq_phase == RQ_PHASE_COMPLETE)
842 CDEBUG(D_RPCTRACE, "Pinger initiate expire request(%p)\n",
845 /* This will also unregister reply. */
846 ptlrpc_expire_one_request(req, 0);
848 /* We're done with this req, let's finally move it to complete
849 * phase and take care of inflights. */
850 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
851 imp = req->rq_import;
852 spin_lock(&imp->imp_lock);
853 if (!cfs_list_empty(&req->rq_list)) {
854 cfs_list_del_init(&req->rq_list);
855 cfs_atomic_dec(&imp->imp_inflight);
857 spin_unlock(&imp->imp_lock);
858 cfs_atomic_dec(&set->set_remaining);
860 mutex_unlock(&pinger_mutex);
862 ptlrpc_set_destroy(set);
866 pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
867 cfs_time_seconds(PING_INTERVAL));
868 pd->pd_this_ping = 0; /* XXX for debug */
870 CDEBUG(D_INFO, "finished a round ping\n");
875 static void *pinger_callback = NULL;
876 #endif /* ENABLE_PINGER */
878 int ptlrpc_start_pinger(void)
881 memset(&pinger_args, 0, sizeof(pinger_args));
882 pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
889 int ptlrpc_stop_pinger(void)
893 liblustre_deregister_wait_callback(pinger_callback);
898 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
901 mutex_lock(&pinger_mutex);
902 ptlrpc_update_next_ping(imp, 0);
903 if (pinger_args.pd_set == NULL &&
904 cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
905 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
906 imp->imp_next_ping, cfs_time_current());
907 pinger_args.pd_next_ping = imp->imp_next_ping;
909 mutex_unlock(&pinger_mutex);
913 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
916 mutex_lock(&pinger_mutex);
917 ptlrpc_update_next_ping(imp, 1);
918 if (pinger_args.pd_set == NULL &&
919 cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
920 CDEBUG(D_HA,"set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
921 imp->imp_next_ping, cfs_time_current());
922 pinger_args.pd_next_ping = imp->imp_next_ping;
924 mutex_unlock(&pinger_mutex);
928 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
929 timeout_cb_t cb, void *data,
930 cfs_list_t *obd_list)
935 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
936 enum timeout_event event)
941 int ptlrpc_pinger_add_import(struct obd_import *imp)
944 if (!cfs_list_empty(&imp->imp_pinger_chain))
947 CDEBUG(D_HA, "adding pingable import %s->%s\n",
948 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
949 ptlrpc_pinger_sending_on_import(imp);
951 mutex_lock(&pinger_mutex);
952 cfs_list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
953 class_import_get(imp);
954 mutex_unlock(&pinger_mutex);
959 int ptlrpc_pinger_del_import(struct obd_import *imp)
962 if (cfs_list_empty(&imp->imp_pinger_chain))
965 mutex_lock(&pinger_mutex);
966 cfs_list_del_init(&imp->imp_pinger_chain);
967 CDEBUG(D_HA, "removing pingable import %s->%s\n",
968 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
969 class_import_put(imp);
970 mutex_unlock(&pinger_mutex);
974 void ptlrpc_pinger_wake_up()
977 /* XXX force pinger to run, if needed */
978 struct obd_import *imp;
980 cfs_list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
981 CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
982 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
983 #ifdef ENABLE_LIBLUSTRE_RECOVERY
984 if (imp->imp_state == LUSTRE_IMP_DISCON &&
985 !imp_is_deactive(imp))
987 /*XXX only recover for the initial connection */
988 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
989 imp->imp_state == LUSTRE_IMP_DISCON &&
990 !imp_is_deactive(imp))
992 ptlrpc_initiate_recovery(imp);
993 else if (imp->imp_state != LUSTRE_IMP_FULL)
994 CDEBUG(D_HA, "Refused to recover import %s->%s "
995 "state %d, deactive %d\n",
996 imp->imp_obd->obd_uuid.uuid,
997 obd2cli_tgt(imp->imp_obd), imp->imp_state,
998 imp_is_deactive(imp));
1003 #endif /* !__KERNEL__ */