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 ptlrpc_daemonize() 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;
481 struct timeout_item *ti = NULL;
483 LASSERT_SEM_LOCKED(&pinger_sem);
484 list_for_each_entry_reverse(item, &timeout_list, ti_chain) {
485 if (item->ti_event == event) {
489 if (item->ti_timeout < ti->ti_timeout) {
490 ti = ptlrpc_new_timeout(time, event, cb, data);
492 ti = ERR_PTR(-ENOMEM);
495 list_add(&ti->ti_chain, &item->ti_chain);
499 ti = ptlrpc_new_timeout(time, event, cb, data);
501 list_add(&ti->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_down(&pinger_sem);
516 ti = ptlrpc_pinger_register_timeout(time, event, cb, data);
518 mutex_up(&pinger_sem);
521 list_add(obd_list, &ti->ti_obd_list);
522 mutex_up(&pinger_sem);
526 int ptlrpc_del_timeout_client(struct list_head *obd_list)
528 mutex_down(&pinger_sem);
529 list_del_init(obd_list);
530 mutex_up(&pinger_sem);
534 int ptlrpc_pinger_remove_timeouts(void)
536 struct timeout_item *item, *tmp;
538 mutex_down(&pinger_sem);
539 list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
540 LASSERT(list_empty(&item->ti_obd_list));
541 list_del(&item->ti_chain);
544 mutex_up(&pinger_sem);
548 void ptlrpc_pinger_wake_up()
551 pinger_thread->t_flags |= SVC_EVENT;
552 cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
556 /* Ping evictor thread */
558 #define PET_TERMINATE 2
560 static int pet_refcount = 0;
561 static int pet_state;
562 static wait_queue_head_t pet_waitq;
563 static struct obd_export *pet_exp = NULL;
564 static spinlock_t pet_lock = SPIN_LOCK_UNLOCKED;
566 int ping_evictor_wake(struct obd_export *exp)
568 spin_lock(&pet_lock);
569 if (pet_exp || (pet_state != PET_READY)) {
570 /* eventually the new obd will call here again. */
571 spin_unlock(&pet_lock);
575 /* We have to make sure the obd isn't destroyed between now and when
576 * the ping evictor runs. We'll take a reference here, and drop it
577 * when we finish in the evictor. We don't really care about this
578 * export in particular; we just need one to keep the obd alive. */
579 pet_exp = class_export_get(exp);
580 spin_unlock(&pet_lock);
586 static int ping_evictor_main(void *arg)
588 struct obd_device *obd;
589 struct obd_export *exp;
590 struct l_wait_info lwi = { 0 };
594 ptlrpc_daemonize("ll_evictor");
596 CDEBUG(D_HA, "Starting Ping Evictor\n");
598 pet_state = PET_READY;
600 l_wait_event(pet_waitq, pet_exp ||
601 (pet_state == PET_TERMINATE), &lwi);
602 if (pet_state == PET_TERMINATE)
605 /* we only get here if pet_exp != NULL, and the end of this
606 * loop is the only place which sets it NULL again, so lock
607 * is not strictly necessary. */
608 spin_lock(&pet_lock);
609 obd = pet_exp->exp_obd;
610 spin_unlock(&pet_lock);
612 expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
614 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
615 obd->obd_name, expire_time);
617 /* Exports can't be deleted out of the list while we hold
618 * the obd lock (class_unlink_export), which means we can't
619 * lose the last ref on the export. If they've already been
620 * removed from the list, we won't find them here. */
621 spin_lock(&obd->obd_dev_lock);
622 while (!list_empty(&obd->obd_exports_timed)) {
623 exp = list_entry(obd->obd_exports_timed.next,
624 struct obd_export,exp_obd_chain_timed);
625 if (expire_time > exp->exp_last_request_time) {
626 class_export_get(exp);
627 spin_unlock(&obd->obd_dev_lock);
628 LCONSOLE_WARN("%s: haven't heard from client %s"
629 " (at %s) in %ld seconds. I think"
630 " it's dead, and I am evicting"
631 " it. exp %p, cur %ld expire %ld"
634 obd_uuid2str(&exp->exp_client_uuid),
635 obd_export_nid2str(exp),
636 (long)(cfs_time_current_sec() -
637 exp->exp_last_request_time),
638 exp, (long)cfs_time_current_sec(),
640 (long)exp->exp_last_request_time);
641 CDEBUG(D_HA, "Last request was at %ld\n",
642 exp->exp_last_request_time);
643 class_fail_export(exp);
644 class_export_put(exp);
645 spin_lock(&obd->obd_dev_lock);
647 /* List is sorted, so everyone below is ok */
651 spin_unlock(&obd->obd_dev_lock);
653 class_export_put(pet_exp);
655 spin_lock(&pet_lock);
657 spin_unlock(&pet_lock);
659 CDEBUG(D_HA, "Exiting Ping Evictor\n");
664 void ping_evictor_start(void)
668 if (++pet_refcount > 1)
671 init_waitqueue_head(&pet_waitq);
673 rc = cfs_kernel_thread(ping_evictor_main, NULL, CLONE_VM | CLONE_FILES);
676 CERROR("Cannot start ping evictor thread: %d\n", rc);
679 EXPORT_SYMBOL(ping_evictor_start);
681 void ping_evictor_stop(void)
683 if (--pet_refcount > 0)
686 pet_state = PET_TERMINATE;
689 EXPORT_SYMBOL(ping_evictor_stop);
690 #else /* !__KERNEL__ */
693 * the current implementation of pinger in liblustre is not optimized
697 static struct pinger_data {
699 cfs_time_t pd_this_ping; /* jiffies */
700 cfs_time_t pd_next_ping; /* jiffies */
701 struct ptlrpc_request_set *pd_set;
704 static int pinger_check_rpcs(void *arg)
706 cfs_time_t curtime = cfs_time_current();
707 struct ptlrpc_request *req;
708 struct ptlrpc_request_set *set;
709 struct list_head *iter;
710 struct obd_import *imp;
711 struct pinger_data *pd = &pinger_args;
714 /* prevent recursion */
715 if (pd->pd_recursion++) {
716 CDEBUG(D_HA, "pinger: recursion! quit\n");
722 /* have we reached ping point? */
723 if (!pd->pd_set && time_before(curtime, pd->pd_next_ping)) {
728 /* if we have rpc_set already, continue processing it */
730 LASSERT(pd->pd_this_ping);
735 pd->pd_this_ping = curtime;
736 pd->pd_set = ptlrpc_prep_set();
737 if (pd->pd_set == NULL)
741 /* add rpcs into set */
742 mutex_down(&pinger_sem);
743 list_for_each(iter, &pinger_imports) {
744 struct obd_import *imp =
745 list_entry(iter, struct obd_import, imp_pinger_chain);
746 int generation, level;
748 if (cfs_time_aftereq(pd->pd_this_ping,
749 imp->imp_next_ping - 5 * CFS_TICK)) {
751 spin_lock(&imp->imp_lock);
752 generation = imp->imp_generation;
753 level = imp->imp_state;
754 spin_unlock(&imp->imp_lock);
756 if (level != LUSTRE_IMP_FULL) {
758 "not pinging %s (in recovery)\n",
759 obd2cli_tgt(imp->imp_obd));
763 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
767 CERROR("OOM trying to ping %s->%s\n",
768 imp->imp_obd->obd_uuid.uuid,
769 obd2cli_tgt(imp->imp_obd));
773 req->rq_no_resend = 1;
774 ptlrpc_request_set_replen(req);
775 req->rq_send_state = LUSTRE_IMP_FULL;
776 ptlrpc_rqphase_move(req, RQ_PHASE_RPC);
777 req->rq_import_generation = generation;
778 ptlrpc_set_add_req(set, req);
780 CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
781 " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
782 imp->imp_next_ping, pd->pd_this_ping);
785 pd->pd_this_ping = curtime;
786 mutex_up(&pinger_sem);
788 /* Might be empty, that's OK. */
789 if (set->set_remaining == 0)
790 CDEBUG(D_RPCTRACE, "nothing to ping\n");
792 list_for_each(iter, &set->set_requests) {
793 struct ptlrpc_request *req =
794 list_entry(iter, struct ptlrpc_request,
796 DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
797 req->rq_import->imp_obd->obd_uuid.uuid,
798 obd2cli_tgt(req->rq_import->imp_obd));
799 (void)ptl_send_rpc(req, 0);
803 rc = ptlrpc_check_set(NULL, set);
805 /* not finished, and we are not expired, simply return */
806 if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
807 cfs_time_seconds(PING_INTERVAL)))) {
808 CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
813 /* Expire all the requests that didn't come back. */
814 mutex_down(&pinger_sem);
815 list_for_each(iter, &set->set_requests) {
816 req = list_entry(iter, struct ptlrpc_request,
819 if (req->rq_phase == RQ_PHASE_COMPLETE)
822 CDEBUG(D_RPCTRACE, "Pinger initiate expire request(%p)\n",
825 /* This will also unregister reply. */
826 ptlrpc_expire_one_request(req, 0);
828 /* We're done with this req, let's finally move it to complete
829 * phase and take care of inflights. */
830 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
831 imp = req->rq_import;
832 spin_lock(&imp->imp_lock);
833 if (!list_empty(&req->rq_list)) {
834 list_del_init(&req->rq_list);
835 atomic_dec(&imp->imp_inflight);
837 spin_unlock(&imp->imp_lock);
838 set->set_remaining--;
840 mutex_up(&pinger_sem);
842 ptlrpc_set_destroy(set);
846 pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
847 cfs_time_seconds(PING_INTERVAL));
848 pd->pd_this_ping = 0; /* XXX for debug */
850 CDEBUG(D_INFO, "finished a round ping\n");
855 static void *pinger_callback = NULL;
856 #endif /* ENABLE_PINGER */
858 int ptlrpc_start_pinger(void)
861 memset(&pinger_args, 0, sizeof(pinger_args));
862 pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
869 int ptlrpc_stop_pinger(void)
873 liblustre_deregister_wait_callback(pinger_callback);
878 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
881 mutex_down(&pinger_sem);
882 ptlrpc_update_next_ping(imp);
883 if (pinger_args.pd_set == NULL &&
884 time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
885 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
886 imp->imp_next_ping, cfs_time_current());
887 pinger_args.pd_next_ping = imp->imp_next_ping;
889 mutex_up(&pinger_sem);
893 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
894 timeout_cb_t cb, void *data,
895 struct list_head *obd_list)
900 int ptlrpc_del_timeout_client(struct list_head *obd_list)
905 int ptlrpc_pinger_add_import(struct obd_import *imp)
908 if (!list_empty(&imp->imp_pinger_chain))
911 CDEBUG(D_HA, "adding pingable import %s->%s\n",
912 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
913 ptlrpc_pinger_sending_on_import(imp);
915 mutex_down(&pinger_sem);
916 list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
917 class_import_get(imp);
918 mutex_up(&pinger_sem);
923 int ptlrpc_pinger_del_import(struct obd_import *imp)
926 if (list_empty(&imp->imp_pinger_chain))
929 mutex_down(&pinger_sem);
930 list_del_init(&imp->imp_pinger_chain);
931 CDEBUG(D_HA, "removing pingable import %s->%s\n",
932 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
933 class_import_put(imp);
934 mutex_up(&pinger_sem);
938 void ptlrpc_pinger_wake_up()
941 /* XXX force pinger to run, if needed */
942 struct obd_import *imp;
944 list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
945 CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
946 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
947 #ifdef ENABLE_LIBLUSTRE_RECOVERY
948 if (imp->imp_state == LUSTRE_IMP_DISCON &&
949 !imp_is_deactive(imp))
951 /*XXX only recover for the initial connection */
952 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
953 imp->imp_state == LUSTRE_IMP_DISCON &&
954 !imp_is_deactive(imp))
956 ptlrpc_initiate_recovery(imp);
957 else if (imp->imp_state != LUSTRE_IMP_FULL)
958 CDEBUG(D_HA, "Refused to recover import %s->%s "
959 "state %d, deactive %d\n",
960 imp->imp_obd->obd_uuid.uuid,
961 obd2cli_tgt(imp->imp_obd), imp->imp_state,
962 imp_is_deactive(imp));
967 #endif /* !__KERNEL__ */