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 ptlrpc_next_reconnect(struct obd_import *imp)
129 if (imp->imp_server_timeout)
130 return cfs_time_shift(obd_timeout / 2);
132 return cfs_time_shift(obd_timeout);
135 static atomic_t suspend_timeouts = ATOMIC_INIT(0);
136 static cfs_time_t suspend_wakeup_time = 0;
138 cfs_duration_t pinger_check_timeout(cfs_time_t time)
140 struct timeout_item *item;
141 cfs_time_t timeout = PING_INTERVAL;
143 /* The timeout list is a increase order sorted list */
144 mutex_down(&pinger_sem);
145 list_for_each_entry(item, &timeout_list, ti_chain) {
146 int ti_timeout = item->ti_timeout;
147 if (timeout > ti_timeout)
148 timeout = ti_timeout;
151 mutex_up(&pinger_sem);
153 return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)),
158 static wait_queue_head_t suspend_timeouts_waitq;
161 cfs_time_t ptlrpc_suspend_wakeup_time(void)
163 return suspend_wakeup_time;
166 void ptlrpc_deactivate_timeouts(struct obd_import *imp)
168 /*XXX: disabled for now, will be replaced by adaptive timeouts */
170 if (imp->imp_no_timeout)
172 imp->imp_no_timeout = 1;
173 atomic_inc(&suspend_timeouts);
174 CDEBUG(D_HA|D_WARNING, "deactivate timeouts %u\n", atomic_read(&suspend_timeouts));
178 void ptlrpc_activate_timeouts(struct obd_import *imp)
180 /*XXX: disabled for now, will be replaced by adaptive timeouts */
182 if (!imp->imp_no_timeout)
184 imp->imp_no_timeout = 0;
185 LASSERT(atomic_read(&suspend_timeouts) > 0);
186 if (atomic_dec_and_test(&suspend_timeouts)) {
187 suspend_wakeup_time = cfs_time_current();
188 wake_up(&suspend_timeouts_waitq);
190 CDEBUG(D_HA|D_WARNING, "activate timeouts %u\n", atomic_read(&suspend_timeouts));
194 int ptlrpc_check_suspend(void)
196 if (atomic_read(&suspend_timeouts))
201 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req)
203 struct l_wait_info lwi;
205 if (atomic_read(&suspend_timeouts)) {
206 DEBUG_REQ(D_NET, req, "-- suspend %d regular timeout",
207 atomic_read(&suspend_timeouts));
208 lwi = LWI_INTR(NULL, NULL);
209 l_wait_event(suspend_timeouts_waitq,
210 atomic_read(&suspend_timeouts) == 0, &lwi);
211 DEBUG_REQ(D_NET, req, "-- recharge regular timeout");
219 static void ptlrpc_pinger_process_import(struct obd_import *imp,
220 unsigned long this_ping)
224 spin_lock(&imp->imp_lock);
225 level = imp->imp_state;
226 force = imp->imp_force_verify;
228 imp->imp_force_verify = 0;
229 spin_unlock(&imp->imp_lock);
231 CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_HA,
232 "level %s/%u force %u deactive %u pingable %u\n",
233 ptlrpc_import_state_name(level), level,
234 force, imp->imp_deactive, imp->imp_pingable);
236 if (cfs_time_aftereq(imp->imp_next_ping - 5 * CFS_TICK,
237 this_ping) && force == 0)
240 if (level == LUSTRE_IMP_DISCON && !imp->imp_deactive) {
241 /* wait at least a timeout before trying recovery again */
242 imp->imp_next_ping = ptlrpc_next_reconnect(imp);
243 ptlrpc_initiate_recovery(imp);
244 } else if (level != LUSTRE_IMP_FULL ||
245 imp->imp_obd->obd_no_recov ||
247 CDEBUG(D_HA, "not pinging %s (in recovery "
248 " or recovery disabled: %s)\n",
249 obd2cli_tgt(imp->imp_obd),
250 ptlrpc_import_state_name(level));
251 } else if (imp->imp_pingable || force) {
256 static int ptlrpc_pinger_main(void *arg)
258 struct ptlrpc_svc_data *data = (struct ptlrpc_svc_data *)arg;
259 struct ptlrpc_thread *thread = data->thread;
262 cfs_daemonize(data->name);
264 /* Record that the thread is running */
265 thread->t_flags = SVC_RUNNING;
266 cfs_waitq_signal(&thread->t_ctl_waitq);
268 /* And now, loop forever, pinging as needed. */
270 cfs_time_t this_ping = cfs_time_current();
271 struct l_wait_info lwi;
272 cfs_duration_t time_to_next_wake;
273 struct timeout_item *item;
274 struct list_head *iter;
276 mutex_down(&pinger_sem);
277 list_for_each_entry(item, &timeout_list, ti_chain) {
278 item->ti_cb(item, item->ti_cb_data);
280 list_for_each(iter, &pinger_imports) {
281 struct obd_import *imp =
282 list_entry(iter, struct obd_import,
285 ptlrpc_pinger_process_import(imp, this_ping);
286 /* obd_timeout might have changed */
287 if (imp->imp_pingable && imp->imp_next_ping &&
288 cfs_time_after(imp->imp_next_ping,
289 cfs_time_add(this_ping,
290 cfs_time_seconds(PING_INTERVAL))))
291 ptlrpc_update_next_ping(imp);
293 mutex_up(&pinger_sem);
294 /* update memory usage info */
295 obd_update_maxusage();
297 /* Wait until the next ping time, or until we're stopped. */
298 time_to_next_wake = pinger_check_timeout(this_ping);
299 /* The ping sent by ptlrpc_send_rpc may get sent out
300 say .01 second after this.
301 ptlrpc_pinger_sending_on_import will then set the
302 next ping time to next_ping + .01 sec, which means
303 we will SKIP the next ping at next_ping, and the
304 ping will get sent 2 timeouts from now! Beware. */
305 CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("CFS_TIME_T")\n",
307 cfs_time_add(this_ping, cfs_time_seconds(PING_INTERVAL)));
308 if (time_to_next_wake > 0) {
309 lwi = LWI_TIMEOUT(max_t(cfs_duration_t, time_to_next_wake, cfs_time_seconds(1)),
311 l_wait_event(thread->t_ctl_waitq,
312 thread->t_flags & (SVC_STOPPING|SVC_EVENT),
314 if (thread->t_flags & SVC_STOPPING) {
315 thread->t_flags &= ~SVC_STOPPING;
318 } else if (thread->t_flags & SVC_EVENT) {
319 /* woken after adding import to reset timer */
320 thread->t_flags &= ~SVC_EVENT;
325 thread->t_flags = SVC_STOPPED;
326 cfs_waitq_signal(&thread->t_ctl_waitq);
328 CDEBUG(D_NET, "pinger thread exiting, process %d\n", cfs_curproc_pid());
332 static struct ptlrpc_thread *pinger_thread = NULL;
334 int ptlrpc_start_pinger(void)
336 struct l_wait_info lwi = { 0 };
337 struct ptlrpc_svc_data d;
339 #ifndef ENABLE_PINGER
344 if (pinger_thread != NULL)
347 OBD_ALLOC_PTR(pinger_thread);
348 if (pinger_thread == NULL)
350 cfs_waitq_init(&pinger_thread->t_ctl_waitq);
351 cfs_waitq_init(&suspend_timeouts_waitq);
354 d.thread = pinger_thread;
356 /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
357 * just drop the VM and FILES in ptlrpc_daemonize() right away. */
358 rc = cfs_kernel_thread(ptlrpc_pinger_main, &d, CLONE_VM | CLONE_FILES);
360 CERROR("cannot start thread: %d\n", rc);
361 OBD_FREE(pinger_thread, sizeof(*pinger_thread));
362 pinger_thread = NULL;
365 l_wait_event(pinger_thread->t_ctl_waitq,
366 pinger_thread->t_flags & SVC_RUNNING, &lwi);
371 int ptlrpc_pinger_remove_timeouts(void);
373 int ptlrpc_stop_pinger(void)
375 struct l_wait_info lwi = { 0 };
377 #ifndef ENABLE_PINGER
382 if (pinger_thread == NULL)
385 ptlrpc_pinger_remove_timeouts();
386 mutex_down(&pinger_sem);
387 pinger_thread->t_flags = SVC_STOPPING;
388 cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
389 mutex_up(&pinger_sem);
391 l_wait_event(pinger_thread->t_ctl_waitq,
392 (pinger_thread->t_flags & SVC_STOPPED), &lwi);
394 OBD_FREE_PTR(pinger_thread);
395 pinger_thread = NULL;
399 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
401 ptlrpc_update_next_ping(imp);
404 int ptlrpc_pinger_add_import(struct obd_import *imp)
407 if (!list_empty(&imp->imp_pinger_chain))
410 mutex_down(&pinger_sem);
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);
416 /* XXX sort, blah blah */
417 list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
418 class_import_get(imp);
420 ptlrpc_pinger_wake_up();
421 mutex_up(&pinger_sem);
426 int ptlrpc_pinger_del_import(struct obd_import *imp)
429 if (list_empty(&imp->imp_pinger_chain))
432 mutex_down(&pinger_sem);
433 list_del_init(&imp->imp_pinger_chain);
434 CDEBUG(D_HA, "removing pingable import %s->%s\n",
435 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
436 /* if we remove from pinger we don't want recovery on this import */
437 imp->imp_obd->obd_no_recov = 1;
438 class_import_put(imp);
439 mutex_up(&pinger_sem);
444 * Register a timeout callback to the pinger list, and the callback will
445 * be called when timeout happens.
447 struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
448 timeout_cb_t cb, void *data)
450 struct timeout_item *ti;
456 CFS_INIT_LIST_HEAD(&ti->ti_obd_list);
457 CFS_INIT_LIST_HEAD(&ti->ti_chain);
458 ti->ti_timeout = time;
459 ti->ti_event = event;
461 ti->ti_cb_data = data;
467 * Register timeout event on the the pinger thread.
468 * Note: the timeout list is an sorted list with increased timeout value.
470 static struct timeout_item*
471 ptlrpc_pinger_register_timeout(int time, enum timeout_event event,
472 timeout_cb_t cb, void *data)
474 struct timeout_item *item;
475 struct timeout_item *ti = NULL;
477 LASSERT_SEM_LOCKED(&pinger_sem);
478 list_for_each_entry_reverse(item, &timeout_list, ti_chain) {
479 if (item->ti_event == event) {
483 if (item->ti_timeout < ti->ti_timeout) {
484 ti = ptlrpc_new_timeout(time, event, cb, data);
486 ti = ERR_PTR(-ENOMEM);
489 list_add(&ti->ti_chain, &item->ti_chain);
493 ti = ptlrpc_new_timeout(time, event, cb, data);
495 list_add(&ti->ti_chain, &timeout_list);
500 /* Add a client_obd to the timeout event list, when timeout(@time)
501 * happens, the callback(@cb) will be called.
503 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
504 timeout_cb_t cb, void *data,
505 struct list_head *obd_list)
507 struct timeout_item *ti;
509 mutex_down(&pinger_sem);
510 ti = ptlrpc_pinger_register_timeout(time, event, cb, data);
512 mutex_up(&pinger_sem);
515 list_add(obd_list, &ti->ti_obd_list);
516 mutex_up(&pinger_sem);
520 int ptlrpc_del_timeout_client(struct list_head *obd_list)
522 mutex_down(&pinger_sem);
523 list_del_init(obd_list);
524 mutex_up(&pinger_sem);
528 int ptlrpc_pinger_remove_timeouts(void)
530 struct timeout_item *item, *tmp;
532 mutex_down(&pinger_sem);
533 list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
534 LASSERT(list_empty(&item->ti_obd_list));
535 list_del(&item->ti_chain);
538 mutex_up(&pinger_sem);
542 void ptlrpc_pinger_wake_up()
545 pinger_thread->t_flags |= SVC_EVENT;
546 cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
550 /* Ping evictor thread */
552 #define PET_TERMINATE 2
554 static int pet_refcount = 0;
555 static int pet_state;
556 static wait_queue_head_t pet_waitq;
557 static struct obd_export *pet_exp = NULL;
558 static spinlock_t pet_lock = SPIN_LOCK_UNLOCKED;
560 int ping_evictor_wake(struct obd_export *exp)
562 spin_lock(&pet_lock);
563 if (pet_exp || (pet_state != PET_READY)) {
564 /* eventually the new obd will call here again. */
565 spin_unlock(&pet_lock);
569 /* We have to make sure the obd isn't destroyed between now and when
570 * the ping evictor runs. We'll take a reference here, and drop it
571 * when we finish in the evictor. We don't really care about this
572 * export in particular; we just need one to keep the obd alive. */
573 pet_exp = class_export_get(exp);
574 spin_unlock(&pet_lock);
580 static int ping_evictor_main(void *arg)
582 struct obd_device *obd;
583 struct obd_export *exp;
584 struct l_wait_info lwi = { 0 };
588 ptlrpc_daemonize("ll_evictor");
590 CDEBUG(D_HA, "Starting Ping Evictor\n");
592 pet_state = PET_READY;
594 l_wait_event(pet_waitq, pet_exp ||
595 (pet_state == PET_TERMINATE), &lwi);
596 if (pet_state == PET_TERMINATE)
599 /* we only get here if pet_exp != NULL, and the end of this
600 * loop is the only place which sets it NULL again, so lock
601 * is not strictly necessary. */
602 spin_lock(&pet_lock);
603 obd = pet_exp->exp_obd;
604 spin_unlock(&pet_lock);
606 expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
608 CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
609 obd->obd_name, expire_time);
611 /* Exports can't be deleted out of the list while we hold
612 * the obd lock (class_unlink_export), which means we can't
613 * lose the last ref on the export. If they've already been
614 * removed from the list, we won't find them here. */
615 spin_lock(&obd->obd_dev_lock);
616 while (!list_empty(&obd->obd_exports_timed)) {
617 exp = list_entry(obd->obd_exports_timed.next,
618 struct obd_export,exp_obd_chain_timed);
619 if (expire_time > exp->exp_last_request_time) {
620 class_export_get(exp);
621 spin_unlock(&obd->obd_dev_lock);
622 LCONSOLE_WARN("%s: haven't heard from client %s"
623 " (at %s) in %ld seconds. I think"
624 " it's dead, and I am evicting"
625 " it. exp %p, cur %ld expire %ld"
628 obd_uuid2str(&exp->exp_client_uuid),
629 obd_export_nid2str(exp),
630 (long)(cfs_time_current_sec() -
631 exp->exp_last_request_time),
632 exp, (long)cfs_time_current_sec(),
634 (long)exp->exp_last_request_time);
635 CDEBUG(D_HA, "Last request was at %ld\n",
636 exp->exp_last_request_time);
637 class_fail_export(exp);
638 class_export_put(exp);
639 spin_lock(&obd->obd_dev_lock);
641 /* List is sorted, so everyone below is ok */
645 spin_unlock(&obd->obd_dev_lock);
647 class_export_put(pet_exp);
649 spin_lock(&pet_lock);
651 spin_unlock(&pet_lock);
653 CDEBUG(D_HA, "Exiting Ping Evictor\n");
658 void ping_evictor_start(void)
662 if (++pet_refcount > 1)
665 init_waitqueue_head(&pet_waitq);
667 rc = cfs_kernel_thread(ping_evictor_main, NULL, CLONE_VM | CLONE_FILES);
670 CERROR("Cannot start ping evictor thread: %d\n", rc);
673 EXPORT_SYMBOL(ping_evictor_start);
675 void ping_evictor_stop(void)
677 if (--pet_refcount > 0)
680 pet_state = PET_TERMINATE;
683 EXPORT_SYMBOL(ping_evictor_stop);
684 #else /* !__KERNEL__ */
687 * the current implementation of pinger in liblustre is not optimized
691 static struct pinger_data {
693 cfs_time_t pd_this_ping; /* jiffies */
694 cfs_time_t pd_next_ping; /* jiffies */
695 struct ptlrpc_request_set *pd_set;
698 static int pinger_check_rpcs(void *arg)
700 cfs_time_t curtime = cfs_time_current();
701 struct ptlrpc_request *req;
702 struct ptlrpc_request_set *set;
703 struct list_head *iter;
704 struct obd_import *imp;
705 struct pinger_data *pd = &pinger_args;
708 /* prevent recursion */
709 if (pd->pd_recursion++) {
710 CDEBUG(D_HA, "pinger: recursion! quit\n");
716 /* have we reached ping point? */
717 if (!pd->pd_set && time_before(curtime, pd->pd_next_ping)) {
722 /* if we have rpc_set already, continue processing it */
724 LASSERT(pd->pd_this_ping);
729 pd->pd_this_ping = curtime;
730 pd->pd_set = ptlrpc_prep_set();
731 if (pd->pd_set == NULL)
735 /* add rpcs into set */
736 mutex_down(&pinger_sem);
737 list_for_each(iter, &pinger_imports) {
738 struct obd_import *imp =
739 list_entry(iter, struct obd_import, imp_pinger_chain);
740 int generation, level;
742 if (cfs_time_aftereq(pd->pd_this_ping,
743 imp->imp_next_ping - 5 * CFS_TICK)) {
745 spin_lock(&imp->imp_lock);
746 generation = imp->imp_generation;
747 level = imp->imp_state;
748 spin_unlock(&imp->imp_lock);
750 if (level != LUSTRE_IMP_FULL) {
752 "not pinging %s (in recovery)\n",
753 obd2cli_tgt(imp->imp_obd));
757 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
761 CERROR("OOM trying to ping %s->%s\n",
762 imp->imp_obd->obd_uuid.uuid,
763 obd2cli_tgt(imp->imp_obd));
767 req->rq_no_resend = 1;
768 ptlrpc_request_set_replen(req);
769 req->rq_send_state = LUSTRE_IMP_FULL;
770 ptlrpc_rqphase_move(req, RQ_PHASE_RPC);
771 req->rq_import_generation = generation;
772 ptlrpc_set_add_req(set, req);
774 CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
775 " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
776 imp->imp_next_ping, pd->pd_this_ping);
779 pd->pd_this_ping = curtime;
780 mutex_up(&pinger_sem);
782 /* Might be empty, that's OK. */
783 if (set->set_remaining == 0)
784 CDEBUG(D_RPCTRACE, "nothing to ping\n");
786 list_for_each(iter, &set->set_requests) {
787 struct ptlrpc_request *req =
788 list_entry(iter, struct ptlrpc_request,
790 DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
791 req->rq_import->imp_obd->obd_uuid.uuid,
792 obd2cli_tgt(req->rq_import->imp_obd));
793 (void)ptl_send_rpc(req, 0);
797 rc = ptlrpc_check_set(NULL, set);
799 /* not finished, and we are not expired, simply return */
800 if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
801 cfs_time_seconds(PING_INTERVAL)))) {
802 CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
807 /* Expire all the requests that didn't come back. */
808 mutex_down(&pinger_sem);
809 list_for_each(iter, &set->set_requests) {
810 req = list_entry(iter, struct ptlrpc_request,
813 if (req->rq_phase == RQ_PHASE_COMPLETE)
816 CDEBUG(D_RPCTRACE, "Pinger initiate expire request(%p)\n",
819 /* This will also unregister reply. */
820 ptlrpc_expire_one_request(req, 0);
822 /* We're done with this req, let's finally move it to complete
823 * phase and take care of inflights. */
824 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
825 imp = req->rq_import;
826 spin_lock(&imp->imp_lock);
827 if (!list_empty(&req->rq_list)) {
828 list_del_init(&req->rq_list);
829 atomic_dec(&imp->imp_inflight);
831 spin_unlock(&imp->imp_lock);
832 set->set_remaining--;
834 mutex_up(&pinger_sem);
836 ptlrpc_set_destroy(set);
840 pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
841 cfs_time_seconds(PING_INTERVAL));
842 pd->pd_this_ping = 0; /* XXX for debug */
844 CDEBUG(D_INFO, "finished a round ping\n");
849 static void *pinger_callback = NULL;
850 #endif /* ENABLE_PINGER */
852 int ptlrpc_start_pinger(void)
855 memset(&pinger_args, 0, sizeof(pinger_args));
856 pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
863 int ptlrpc_stop_pinger(void)
867 liblustre_deregister_wait_callback(pinger_callback);
872 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
875 mutex_down(&pinger_sem);
876 ptlrpc_update_next_ping(imp);
877 if (pinger_args.pd_set == NULL &&
878 time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
879 CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
880 imp->imp_next_ping, cfs_time_current());
881 pinger_args.pd_next_ping = imp->imp_next_ping;
883 mutex_up(&pinger_sem);
887 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
888 timeout_cb_t cb, void *data,
889 struct list_head *obd_list)
894 int ptlrpc_del_timeout_client(struct list_head *obd_list)
899 int ptlrpc_pinger_add_import(struct obd_import *imp)
902 if (!list_empty(&imp->imp_pinger_chain))
905 CDEBUG(D_HA, "adding pingable import %s->%s\n",
906 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
907 ptlrpc_pinger_sending_on_import(imp);
909 mutex_down(&pinger_sem);
910 list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
911 class_import_get(imp);
912 mutex_up(&pinger_sem);
917 int ptlrpc_pinger_del_import(struct obd_import *imp)
920 if (list_empty(&imp->imp_pinger_chain))
923 mutex_down(&pinger_sem);
924 list_del_init(&imp->imp_pinger_chain);
925 CDEBUG(D_HA, "removing pingable import %s->%s\n",
926 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
927 class_import_put(imp);
928 mutex_up(&pinger_sem);
932 void ptlrpc_pinger_wake_up()
935 /* XXX force pinger to run, if needed */
936 struct obd_import *imp;
938 list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
939 CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
940 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
941 #ifdef ENABLE_LIBLUSTRE_RECOVERY
942 if (imp->imp_state == LUSTRE_IMP_DISCON && !imp->imp_deactive)
944 /*XXX only recover for the initial connection */
945 if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
946 imp->imp_state == LUSTRE_IMP_DISCON && !imp->imp_deactive)
948 ptlrpc_initiate_recovery(imp);
949 else if (imp->imp_state != LUSTRE_IMP_FULL)
950 CDEBUG(D_HA, "Refused to recover import %s->%s "
951 "state %d, deactive %d\n",
952 imp->imp_obd->obd_uuid.uuid,
953 obd2cli_tgt(imp->imp_obd), imp->imp_state,
959 #endif /* !__KERNEL__ */