Whamcloud - gitweb
LU-6496 ptlrpc: Fix wrong code indentation in plain_authorize
[fs/lustre-release.git] / lustre / ptlrpc / pinger.c
index 8b7d472..1e23bab 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  * Portal-RPC reconnection and replay operations, for use in recovery.
  */
 
-#ifndef __KERNEL__
-#include <liblustre.h>
-#else
 #define DEBUG_SUBSYSTEM S_RPC
-#endif
 
+#include <linux/kthread.h>
 #include <obd_support.h>
 #include <obd_class.h>
 #include "ptlrpc_internal.h"
@@ -52,8 +49,10 @@ static int suppress_pings;
 CFS_MODULE_PARM(suppress_pings, "i", int, 0644, "Suppress pings");
 
 struct mutex pinger_mutex;
-static CFS_LIST_HEAD(pinger_imports);
-static cfs_list_t timeout_list = CFS_LIST_HEAD_INIT(timeout_list);
+static struct list_head pinger_imports =
+               LIST_HEAD_INIT(pinger_imports);
+static struct list_head timeout_list =
+               LIST_HEAD_INIT(timeout_list);
 
 int ptlrpc_pinger_suppress_pings()
 {
@@ -95,7 +94,7 @@ int ptlrpc_obd_ping(struct obd_device *obd)
 }
 EXPORT_SYMBOL(ptlrpc_obd_ping);
 
-int ptlrpc_ping(struct obd_import *imp)
+static int ptlrpc_ping(struct obd_import *imp)
 {
         struct ptlrpc_request *req;
         ENTRY;
@@ -115,7 +114,7 @@ int ptlrpc_ping(struct obd_import *imp)
         RETURN(0);
 }
 
-void ptlrpc_update_next_ping(struct obd_import *imp, int soon)
+static void ptlrpc_update_next_ping(struct obd_import *imp, int soon)
 {
 #ifdef ENABLE_PINGER
         int time = soon ? PING_INTERVAL_SHORT : PING_INTERVAL;
@@ -148,89 +147,25 @@ static inline int ptlrpc_next_reconnect(struct obd_import *imp)
                 return cfs_time_shift(obd_timeout);
 }
 
-static cfs_atomic_t suspend_timeouts = CFS_ATOMIC_INIT(0);
-static cfs_time_t suspend_wakeup_time = 0;
-
-cfs_duration_t pinger_check_timeout(cfs_time_t time)
+static cfs_duration_t pinger_check_timeout(cfs_time_t time)
 {
         struct timeout_item *item;
         cfs_time_t timeout = PING_INTERVAL;
 
-        /* The timeout list is a increase order sorted list */
+       /* This list is sorted in increasing timeout order */
        mutex_lock(&pinger_mutex);
-        cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
-                int ti_timeout = item->ti_timeout;
-                if (timeout > ti_timeout)
-                        timeout = ti_timeout;
-                break;
-        }
+       list_for_each_entry(item, &timeout_list, ti_chain) {
+               int ti_timeout = item->ti_timeout;
+               if (timeout > ti_timeout)
+                       timeout = ti_timeout;
+               break;
+       }
        mutex_unlock(&pinger_mutex);
 
         return cfs_time_sub(cfs_time_add(time, cfs_time_seconds(timeout)),
                                          cfs_time_current());
 }
 
-static cfs_waitq_t suspend_timeouts_waitq;
-
-cfs_time_t ptlrpc_suspend_wakeup_time(void)
-{
-        return suspend_wakeup_time;
-}
-
-void ptlrpc_deactivate_timeouts(struct obd_import *imp)
-{
-        /*XXX: disabled for now, will be replaced by adaptive timeouts */
-#if 0
-        if (imp->imp_no_timeout)
-                return;
-        imp->imp_no_timeout = 1;
-        cfs_atomic_inc(&suspend_timeouts);
-        CDEBUG(D_HA|D_WARNING, "deactivate timeouts %u\n",
-               cfs_atomic_read(&suspend_timeouts));
-#endif
-}
-
-void ptlrpc_activate_timeouts(struct obd_import *imp)
-{
-        /*XXX: disabled for now, will be replaced by adaptive timeouts */
-#if 0
-        if (!imp->imp_no_timeout)
-                return;
-        imp->imp_no_timeout = 0;
-        LASSERT(cfs_atomic_read(&suspend_timeouts) > 0);
-        if (cfs_atomic_dec_and_test(&suspend_timeouts)) {
-                suspend_wakeup_time = cfs_time_current();
-                cfs_waitq_signal(&suspend_timeouts_waitq);
-        }
-        CDEBUG(D_HA|D_WARNING, "activate timeouts %u\n",
-               cfs_atomic_read(&suspend_timeouts));
-#endif
-}
-
-int ptlrpc_check_suspend(void)
-{
-        if (cfs_atomic_read(&suspend_timeouts))
-                return 1;
-        return 0;
-}
-
-int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req)
-{
-        struct l_wait_info lwi;
-
-        if (cfs_atomic_read(&suspend_timeouts)) {
-                DEBUG_REQ(D_NET, req, "-- suspend %d regular timeout",
-                          cfs_atomic_read(&suspend_timeouts));
-                lwi = LWI_INTR(NULL, NULL);
-                l_wait_event(suspend_timeouts_waitq,
-                             cfs_atomic_read(&suspend_timeouts) == 0, &lwi);
-                DEBUG_REQ(D_NET, req, "-- recharge regular timeout");
-                return 1;
-        }
-        return 0;
-}
-
-#ifdef __KERNEL__
 
 static bool ir_up;
 
@@ -296,6 +231,11 @@ static void ptlrpc_pinger_process_import(struct obd_import *imp,
                       "or recovery disabled: %s)\n",
                       imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
                       ptlrpc_import_state_name(level));
+               if (force) {
+                       spin_lock(&imp->imp_lock);
+                       imp->imp_force_verify = 1;
+                       spin_unlock(&imp->imp_lock);
+               }
        } else if ((imp->imp_pingable && !suppress) || force_next || force) {
                ptlrpc_ping(imp);
        }
@@ -303,31 +243,29 @@ static void ptlrpc_pinger_process_import(struct obd_import *imp,
 
 static int ptlrpc_pinger_main(void *arg)
 {
-        struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
+       struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
        ENTRY;
 
-        cfs_daemonize(thread->t_name);
-
-        /* Record that the thread is running */
-        thread_set_flags(thread, SVC_RUNNING);
-        cfs_waitq_signal(&thread->t_ctl_waitq);
+       /* Record that the thread is running */
+       thread_set_flags(thread, SVC_RUNNING);
+       wake_up(&thread->t_ctl_waitq);
 
-        /* And now, loop forever, pinging as needed. */
-        while (1) {
-                cfs_time_t this_ping = cfs_time_current();
-                struct l_wait_info lwi;
-                cfs_duration_t time_to_next_wake;
-                struct timeout_item *item;
-                cfs_list_t *iter;
+       /* And now, loop forever, pinging as needed. */
+       while (1) {
+               cfs_time_t this_ping = cfs_time_current();
+               struct l_wait_info lwi;
+               cfs_duration_t time_to_next_wake;
+               struct timeout_item *item;
+               struct list_head *iter;
 
                mutex_lock(&pinger_mutex);
-                cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
+               list_for_each_entry(item, &timeout_list, ti_chain)
                         item->ti_cb(item, item->ti_cb_data);
-                }
-                cfs_list_for_each(iter, &pinger_imports) {
-                        struct obd_import *imp =
-                                cfs_list_entry(iter, struct obd_import,
-                                               imp_pinger_chain);
+
+               list_for_each(iter, &pinger_imports) {
+                       struct obd_import *imp = list_entry(iter,
+                                                           struct obd_import,
+                                                           imp_pinger_chain);
 
                         ptlrpc_pinger_process_import(imp, this_ping);
                         /* obd_timeout might have changed */
@@ -371,47 +309,45 @@ static int ptlrpc_pinger_main(void *arg)
                 }
         }
 
-        thread_set_flags(thread, SVC_STOPPED);
-        cfs_waitq_signal(&thread->t_ctl_waitq);
+       thread_set_flags(thread, SVC_STOPPED);
+       wake_up(&thread->t_ctl_waitq);
 
-        CDEBUG(D_NET, "pinger thread exiting, process %d\n", cfs_curproc_pid());
-        return 0;
+       CDEBUG(D_NET, "pinger thread exiting, process %d\n", current_pid());
+       return 0;
 }
 
-static struct ptlrpc_thread *pinger_thread = NULL;
+static struct ptlrpc_thread pinger_thread;
 
 int ptlrpc_start_pinger(void)
 {
-        struct l_wait_info lwi = { 0 };
-        int rc;
+       struct l_wait_info lwi = { 0 };
+       struct task_struct *task;
+       int rc;
 #ifndef ENABLE_PINGER
-        return 0;
+       return 0;
 #endif
-        ENTRY;
+       ENTRY;
 
-        if (pinger_thread != NULL)
-                RETURN(-EALREADY);
+       if (!thread_is_init(&pinger_thread) &&
+           !thread_is_stopped(&pinger_thread))
+               RETURN(-EALREADY);
 
-        OBD_ALLOC_PTR(pinger_thread);
-        if (pinger_thread == NULL)
-                RETURN(-ENOMEM);
-        cfs_waitq_init(&pinger_thread->t_ctl_waitq);
-        cfs_waitq_init(&suspend_timeouts_waitq);
+       init_waitqueue_head(&pinger_thread.t_ctl_waitq);
 
-       strcpy(pinger_thread->t_name, "ll_ping");
+       strcpy(pinger_thread.t_name, "ll_ping");
 
        /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
-        * just drop the VM and FILES in cfs_daemonize_ctxt() right away. */
-        rc = cfs_create_thread(ptlrpc_pinger_main,
-                              pinger_thread, CFS_DAEMON_FLAGS);
-        if (rc < 0) {
-                CERROR("cannot start thread: %d\n", rc);
-                OBD_FREE(pinger_thread, sizeof(*pinger_thread));
-                pinger_thread = NULL;
-                RETURN(rc);
-        }
-        l_wait_event(pinger_thread->t_ctl_waitq,
-                     thread_is_running(pinger_thread), &lwi);
+        * just drop the VM and FILES in kthread_run() right away. */
+       task = kthread_run(ptlrpc_pinger_main, &pinger_thread,
+                          pinger_thread.t_name);
+       if (IS_ERR(task)) {
+               rc = PTR_ERR(task);
+               CERROR("cannot start pinger thread: rc = %d\n", rc);
+               RETURN(rc);
+       }
+
+       l_wait_event(pinger_thread.t_ctl_waitq,
+                    thread_is_running(&pinger_thread), &lwi);
 
        if (suppress_pings)
                CWARN("Pings will be suppressed at the request of the "
@@ -427,40 +363,35 @@ int ptlrpc_pinger_remove_timeouts(void);
 
 int ptlrpc_stop_pinger(void)
 {
-        struct l_wait_info lwi = { 0 };
-        int rc = 0;
+       struct l_wait_info lwi = { 0 };
 #ifndef ENABLE_PINGER
-        return 0;
+       return 0;
 #endif
-        ENTRY;
+       ENTRY;
 
-        if (pinger_thread == NULL)
-                RETURN(-EALREADY);
+       if (thread_is_init(&pinger_thread) ||
+           thread_is_stopped(&pinger_thread))
+               RETURN(-EALREADY);
 
-        ptlrpc_pinger_remove_timeouts();
-       mutex_lock(&pinger_mutex);
-        thread_set_flags(pinger_thread, SVC_STOPPING);
-        cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
-       mutex_unlock(&pinger_mutex);
+       ptlrpc_pinger_remove_timeouts();
 
-        l_wait_event(pinger_thread->t_ctl_waitq,
-                     thread_is_stopped(pinger_thread), &lwi);
+       thread_set_flags(&pinger_thread, SVC_STOPPING);
+       wake_up(&pinger_thread.t_ctl_waitq);
 
-        OBD_FREE_PTR(pinger_thread);
-        pinger_thread = NULL;
-        RETURN(rc);
+       l_wait_event(pinger_thread.t_ctl_waitq,
+                    thread_is_stopped(&pinger_thread), &lwi);
+       RETURN(0);
 }
 
 void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
 {
         ptlrpc_update_next_ping(imp, 0);
 }
-EXPORT_SYMBOL(ptlrpc_pinger_sending_on_import);
 
 void ptlrpc_pinger_commit_expected(struct obd_import *imp)
 {
        ptlrpc_update_next_ping(imp, 1);
-       LASSERT_SPIN_LOCKED(&imp->imp_lock);
+       assert_spin_locked(&imp->imp_lock);
        /*
         * Avoid reading stale imp_connect_data.  When not sure if pings are
         * expected or not on next connection, we assume they are not and force
@@ -475,7 +406,7 @@ void ptlrpc_pinger_commit_expected(struct obd_import *imp)
 int ptlrpc_pinger_add_import(struct obd_import *imp)
 {
         ENTRY;
-        if (!cfs_list_empty(&imp->imp_pinger_chain))
+       if (!list_empty(&imp->imp_pinger_chain))
                 RETURN(-EALREADY);
 
        mutex_lock(&pinger_mutex);
@@ -485,7 +416,7 @@ int ptlrpc_pinger_add_import(struct obd_import *imp)
         imp->imp_obd->obd_no_recov = 0;
         ptlrpc_update_next_ping(imp, 0);
         /* XXX sort, blah blah */
-        cfs_list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
+       list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
         class_import_get(imp);
 
         ptlrpc_pinger_wake_up();
@@ -497,19 +428,20 @@ EXPORT_SYMBOL(ptlrpc_pinger_add_import);
 
 int ptlrpc_pinger_del_import(struct obd_import *imp)
 {
-        ENTRY;
-        if (cfs_list_empty(&imp->imp_pinger_chain))
-                RETURN(-ENOENT);
+       ENTRY;
+
+       if (list_empty(&imp->imp_pinger_chain))
+               RETURN(-ENOENT);
 
        mutex_lock(&pinger_mutex);
-        cfs_list_del_init(&imp->imp_pinger_chain);
-        CDEBUG(D_HA, "removing pingable import %s->%s\n",
-               imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
-        /* if we remove from pinger we don't want recovery on this import */
-        imp->imp_obd->obd_no_recov = 1;
-        class_import_put(imp);
+       list_del_init(&imp->imp_pinger_chain);
+       CDEBUG(D_HA, "removing pingable import %s->%s\n",
+              imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
+       /* if we remove from pinger we don't want recovery on this import */
+       imp->imp_obd->obd_no_recov = 1;
+       class_import_put(imp);
        mutex_unlock(&pinger_mutex);
-        RETURN(0);
+       RETURN(0);
 }
 EXPORT_SYMBOL(ptlrpc_pinger_del_import);
 
@@ -517,8 +449,9 @@ EXPORT_SYMBOL(ptlrpc_pinger_del_import);
  * Register a timeout callback to the pinger list, and the callback will
  * be called when timeout happens.
  */
-struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
-                                        timeout_cb_t cb, void *data)
+static struct timeout_item *ptlrpc_new_timeout(int time,
+                                              enum timeout_event event,
+                                              timeout_cb_t cb, void *data)
 {
         struct timeout_item *ti;
 
@@ -526,8 +459,8 @@ struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
         if (!ti)
                 return(NULL);
 
-        CFS_INIT_LIST_HEAD(&ti->ti_obd_list);
-        CFS_INIT_LIST_HEAD(&ti->ti_chain);
+       INIT_LIST_HEAD(&ti->ti_obd_list);
+       INIT_LIST_HEAD(&ti->ti_chain);
         ti->ti_timeout = time;
         ti->ti_event = event;
         ti->ti_cb = cb;
@@ -544,26 +477,26 @@ static struct timeout_item*
 ptlrpc_pinger_register_timeout(int time, enum timeout_event event,
                                timeout_cb_t cb, void *data)
 {
-        struct timeout_item *item, *tmp;
+       struct timeout_item *item, *tmp;
 
-        LASSERT_MUTEX_LOCKED(&pinger_mutex);
+       LASSERT(mutex_is_locked(&pinger_mutex));
 
-        cfs_list_for_each_entry(item, &timeout_list, ti_chain)
-                if (item->ti_event == event)
-                        goto out;
+       list_for_each_entry(item, &timeout_list, ti_chain)
+               if (item->ti_event == event)
+                       goto out;
 
-        item = ptlrpc_new_timeout(time, event, cb, data);
-        if (item) {
-                cfs_list_for_each_entry_reverse(tmp, &timeout_list, ti_chain) {
-                        if (tmp->ti_timeout < time) {
-                                cfs_list_add(&item->ti_chain, &tmp->ti_chain);
-                                goto out;
-                        }
-                }
-                cfs_list_add(&item->ti_chain, &timeout_list);
-        }
+       item = ptlrpc_new_timeout(time, event, cb, data);
+       if (item) {
+               list_for_each_entry_reverse(tmp, &timeout_list, ti_chain) {
+                       if (tmp->ti_timeout < time) {
+                               list_add(&item->ti_chain, &tmp->ti_chain);
+                               goto out;
+                       }
+               }
+               list_add(&item->ti_chain, &timeout_list);
+       }
 out:
-        return item;
+       return item;
 }
 
 /* Add a client_obd to the timeout event list, when timeout(@time)
@@ -571,7 +504,7 @@ out:
  */
 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
                               timeout_cb_t cb, void *data,
-                              cfs_list_t *obd_list)
+                             struct list_head *obd_list)
 {
         struct timeout_item *ti;
 
@@ -581,38 +514,38 @@ int ptlrpc_add_timeout_client(int time, enum timeout_event event,
                mutex_unlock(&pinger_mutex);
                 return (-EINVAL);
         }
-        cfs_list_add(obd_list, &ti->ti_obd_list);
+       list_add(obd_list, &ti->ti_obd_list);
        mutex_unlock(&pinger_mutex);
         return 0;
 }
 EXPORT_SYMBOL(ptlrpc_add_timeout_client);
 
-int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
-                              enum timeout_event event)
+int ptlrpc_del_timeout_client(struct list_head *obd_list,
+                             enum timeout_event event)
 {
-        struct timeout_item *ti = NULL, *item;
+       struct timeout_item *ti = NULL, *item;
 
-        if (cfs_list_empty(obd_list))
-                return 0;
+       if (list_empty(obd_list))
+               return 0;
        mutex_lock(&pinger_mutex);
-        cfs_list_del_init(obd_list);
-        /**
-         * If there are no obd attached to the timeout event
-         * list, remove this timeout event from the pinger
-         */
-        cfs_list_for_each_entry(item, &timeout_list, ti_chain) {
-                if (item->ti_event == event) {
-                        ti = item;
-                        break;
-                }
-        }
-        LASSERTF(ti != NULL, "ti is NULL ! \n");
-        if (cfs_list_empty(&ti->ti_obd_list)) {
-                cfs_list_del(&ti->ti_chain);
-                OBD_FREE_PTR(ti);
-        }
+       list_del_init(obd_list);
+       /**
+        * If there are no obd attached to the timeout event
+        * list, remove this timeout event from the pinger
+        */
+       list_for_each_entry(item, &timeout_list, ti_chain) {
+               if (item->ti_event == event) {
+                       ti = item;
+                       break;
+               }
+       }
+       LASSERTF(ti != NULL, "ti is NULL !\n");
+       if (list_empty(&ti->ti_obd_list)) {
+               list_del(&ti->ti_chain);
+               OBD_FREE_PTR(ti);
+       }
        mutex_unlock(&pinger_mutex);
-        return 0;
+       return 0;
 }
 EXPORT_SYMBOL(ptlrpc_del_timeout_client);
 
@@ -621,9 +554,9 @@ int ptlrpc_pinger_remove_timeouts(void)
         struct timeout_item *item, *tmp;
 
        mutex_lock(&pinger_mutex);
-        cfs_list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
-                LASSERT(cfs_list_empty(&item->ti_obd_list));
-                cfs_list_del(&item->ti_chain);
+       list_for_each_entry_safe(item, tmp, &timeout_list, ti_chain) {
+               LASSERT(list_empty(&item->ti_obd_list));
+               list_del(&item->ti_chain);
                 OBD_FREE_PTR(item);
         }
        mutex_unlock(&pinger_mutex);
@@ -633,8 +566,8 @@ int ptlrpc_pinger_remove_timeouts(void)
 void ptlrpc_pinger_wake_up()
 {
 #ifdef ENABLE_PINGER
-        thread_add_flags(pinger_thread, SVC_EVENT);
-        cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
+       thread_add_flags(&pinger_thread, SVC_EVENT);
+       wake_up(&pinger_thread.t_ctl_waitq);
 #endif
 }
 
@@ -644,8 +577,8 @@ void ptlrpc_pinger_wake_up()
 
 static int               pet_refcount = 0;
 static int               pet_state;
-static cfs_waitq_t       pet_waitq;
-CFS_LIST_HEAD(pet_list);
+static wait_queue_head_t pet_waitq;
+static struct list_head         pet_list;
 static DEFINE_SPINLOCK(pet_lock);
 
 int ping_evictor_wake(struct obd_export *exp)
@@ -660,13 +593,13 @@ int ping_evictor_wake(struct obd_export *exp)
        }
 
        obd = class_exp2obd(exp);
-       if (cfs_list_empty(&obd->obd_evict_list)) {
+       if (list_empty(&obd->obd_evict_list)) {
                class_incref(obd, "evictor", obd);
-               cfs_list_add(&obd->obd_evict_list, &pet_list);
+               list_add(&obd->obd_evict_list, &pet_list);
        }
        spin_unlock(&pet_lock);
 
-       cfs_waitq_signal(&pet_waitq);
+       wake_up(&pet_waitq);
        return 0;
 }
 
@@ -678,40 +611,40 @@ static int ping_evictor_main(void *arg)
         time_t expire_time;
         ENTRY;
 
-        cfs_daemonize_ctxt("ll_evictor");
+       unshare_fs_struct();
 
-        CDEBUG(D_HA, "Starting Ping Evictor\n");
-        pet_state = PET_READY;
-        while (1) {
-                l_wait_event(pet_waitq, (!cfs_list_empty(&pet_list)) ||
-                             (pet_state == PET_TERMINATE), &lwi);
+       CDEBUG(D_HA, "Starting Ping Evictor\n");
+       pet_state = PET_READY;
+       while (1) {
+               l_wait_event(pet_waitq, (!list_empty(&pet_list)) ||
+                           (pet_state == PET_TERMINATE), &lwi);
 
-                /* loop until all obd's will be removed */
-                if ((pet_state == PET_TERMINATE) && cfs_list_empty(&pet_list))
-                        break;
+               /* loop until all obd's will be removed */
+               if ((pet_state == PET_TERMINATE) && list_empty(&pet_list))
+                       break;
 
-                /* we only get here if pet_exp != NULL, and the end of this
-                 * loop is the only place which sets it NULL again, so lock
-                 * is not strictly necessary. */
+               /* we only get here if pet_exp != NULL, and the end of this
+                * loop is the only place which sets it NULL again, so lock
+                * is not strictly necessary. */
                spin_lock(&pet_lock);
-               obd = cfs_list_entry(pet_list.next, struct obd_device,
-                                    obd_evict_list);
+               obd = list_entry(pet_list.next, struct obd_device,
+                                obd_evict_list);
                spin_unlock(&pet_lock);
 
-                expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
+               expire_time = cfs_time_current_sec() - PING_EVICT_TIMEOUT;
 
-                CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
-                       obd->obd_name, expire_time);
+               CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
+                      obd->obd_name, expire_time);
 
-                /* Exports can't be deleted out of the list while we hold
-                 * the obd lock (class_unlink_export), which means we can't
-                 * lose the last ref on the export.  If they've already been
-                 * removed from the list, we won't find them here. */
+               /* Exports can't be deleted out of the list while we hold
+                * the obd lock (class_unlink_export), which means we can't
+                * lose the last ref on the export.  If they've already been
+                * removed from the list, we won't find them here. */
                spin_lock(&obd->obd_dev_lock);
-               while (!cfs_list_empty(&obd->obd_exports_timed)) {
-                       exp = cfs_list_entry(obd->obd_exports_timed.next,
-                                            struct obd_export,
-                                            exp_obd_chain_timed);
+               while (!list_empty(&obd->obd_exports_timed)) {
+                       exp = list_entry(obd->obd_exports_timed.next,
+                                        struct obd_export,
+                                        exp_obd_chain_timed);
                        if (expire_time > exp->exp_last_request_time) {
                                class_export_get(exp);
                                spin_unlock(&obd->obd_dev_lock);
@@ -741,7 +674,7 @@ static int ping_evictor_main(void *arg)
                spin_unlock(&obd->obd_dev_lock);
 
                spin_lock(&pet_lock);
-               cfs_list_del_init(&obd->obd_evict_list);
+               list_del_init(&obd->obd_evict_list);
                spin_unlock(&pet_lock);
 
                 class_decref(obd, "evictor", obd);
@@ -753,18 +686,20 @@ static int ping_evictor_main(void *arg)
 
 void ping_evictor_start(void)
 {
-        int rc;
+       struct task_struct *task;
 
-        if (++pet_refcount > 1)
-                return;
+       if (++pet_refcount > 1)
+               return;
 
-        cfs_waitq_init(&pet_waitq);
+       INIT_LIST_HEAD(&pet_list);
+       init_waitqueue_head(&pet_waitq);
 
-        rc = cfs_create_thread(ping_evictor_main, NULL, CFS_DAEMON_FLAGS);
-        if (rc < 0) {
-                pet_refcount--;
-                CERROR("Cannot start ping evictor thread: %d\n", rc);
-        }
+       task = kthread_run(ping_evictor_main, NULL, "ll_evictor");
+       if (IS_ERR(task)) {
+               pet_refcount--;
+               CERROR("Cannot start ping evictor thread: %ld\n",
+                       PTR_ERR(task));
+       }
 }
 EXPORT_SYMBOL(ping_evictor_start);
 
@@ -774,300 +709,6 @@ void ping_evictor_stop(void)
                 return;
 
         pet_state = PET_TERMINATE;
-        cfs_waitq_signal(&pet_waitq);
+       wake_up(&pet_waitq);
 }
 EXPORT_SYMBOL(ping_evictor_stop);
-#else /* !__KERNEL__ */
-
-/* XXX
- * the current implementation of pinger in liblustre is not optimized
- */
-
-#ifdef ENABLE_PINGER
-static struct pinger_data {
-        int             pd_recursion;
-        cfs_time_t      pd_this_ping;   /* jiffies */
-        cfs_time_t      pd_next_ping;   /* jiffies */
-        struct ptlrpc_request_set *pd_set;
-} pinger_args;
-
-static int pinger_check_rpcs(void *arg)
-{
-        cfs_time_t curtime = cfs_time_current();
-        struct ptlrpc_request *req;
-        struct ptlrpc_request_set *set;
-        cfs_list_t *iter;
-        struct obd_import *imp;
-        struct pinger_data *pd = &pinger_args;
-        int rc;
-
-        /* prevent recursion */
-        if (pd->pd_recursion++) {
-                CDEBUG(D_HA, "pinger: recursion! quit\n");
-                LASSERT(pd->pd_set);
-                pd->pd_recursion--;
-                return 0;
-        }
-
-        /* have we reached ping point? */
-        if (!pd->pd_set && cfs_time_before(curtime, pd->pd_next_ping)) {
-                pd->pd_recursion--;
-                return 0;
-        }
-
-        /* if we have rpc_set already, continue processing it */
-        if (pd->pd_set) {
-                LASSERT(pd->pd_this_ping);
-                set = pd->pd_set;
-                goto do_check_set;
-        }
-
-        pd->pd_this_ping = curtime;
-        pd->pd_set = ptlrpc_prep_set();
-        if (pd->pd_set == NULL)
-                goto out;
-        set = pd->pd_set;
-
-        /* add rpcs into set */
-       mutex_lock(&pinger_mutex);
-        cfs_list_for_each(iter, &pinger_imports) {
-                struct obd_import *imp = cfs_list_entry(iter, struct obd_import,
-                                                        imp_pinger_chain);
-                int generation, level;
-
-                if (cfs_time_aftereq(pd->pd_this_ping,
-                                     imp->imp_next_ping - 5 * CFS_TICK)) {
-                        /* Add a ping. */
-                       spin_lock(&imp->imp_lock);
-                       generation = imp->imp_generation;
-                       level = imp->imp_state;
-                       spin_unlock(&imp->imp_lock);
-
-                        if (level != LUSTRE_IMP_FULL) {
-                                CDEBUG(D_HA,
-                                       "not pinging %s (in recovery)\n",
-                                       obd2cli_tgt(imp->imp_obd));
-                                continue;
-                        }
-
-                        req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING,
-                                                        LUSTRE_OBD_VERSION,
-                                                        OBD_PING);
-                        if (req == NULL) {
-                                CERROR("OOM trying to ping %s->%s\n",
-                                       imp->imp_obd->obd_uuid.uuid,
-                                       obd2cli_tgt(imp->imp_obd));
-                                break;
-                        }
-
-                        req->rq_no_resend = 1;
-                        ptlrpc_request_set_replen(req);
-                        req->rq_send_state = LUSTRE_IMP_FULL;
-                        ptlrpc_rqphase_move(req, RQ_PHASE_RPC);
-                        req->rq_import_generation = generation;
-                        ptlrpc_set_add_req(set, req);
-                } else {
-                        CDEBUG(D_INFO, "don't need to ping %s ("CFS_TIME_T
-                               " > "CFS_TIME_T")\n", obd2cli_tgt(imp->imp_obd),
-                               imp->imp_next_ping, pd->pd_this_ping);
-                }
-        }
-        pd->pd_this_ping = curtime;
-       mutex_unlock(&pinger_mutex);
-
-        /* Might be empty, that's OK. */
-        if (cfs_atomic_read(&set->set_remaining) == 0)
-                CDEBUG(D_RPCTRACE, "nothing to ping\n");
-
-        cfs_list_for_each(iter, &set->set_requests) {
-                struct ptlrpc_request *req =
-                        cfs_list_entry(iter, struct ptlrpc_request,
-                                       rq_set_chain);
-                DEBUG_REQ(D_RPCTRACE, req, "pinging %s->%s",
-                          req->rq_import->imp_obd->obd_uuid.uuid,
-                          obd2cli_tgt(req->rq_import->imp_obd));
-                (void)ptl_send_rpc(req, 0);
-        }
-
-do_check_set:
-        rc = ptlrpc_check_set(NULL, set);
-
-        /* not finished, and we are not expired, simply return */
-        if (!rc && cfs_time_before(curtime, cfs_time_add(pd->pd_this_ping,
-                                            cfs_time_seconds(PING_INTERVAL)))) {
-                CDEBUG(D_RPCTRACE, "not finished, but also not expired\n");
-                pd->pd_recursion--;
-                return 0;
-        }
-
-        /* Expire all the requests that didn't come back. */
-       mutex_lock(&pinger_mutex);
-        cfs_list_for_each(iter, &set->set_requests) {
-                req = cfs_list_entry(iter, struct ptlrpc_request,
-                                     rq_set_chain);
-
-                if (req->rq_phase == RQ_PHASE_COMPLETE)
-                        continue;
-
-                CDEBUG(D_RPCTRACE, "Pinger initiate expire request(%p)\n",
-                       req);
-
-                /* This will also unregister reply. */
-                ptlrpc_expire_one_request(req, 0);
-
-                /* We're done with this req, let's finally move it to complete
-                 * phase and take care of inflights. */
-                ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
-                imp = req->rq_import;
-               spin_lock(&imp->imp_lock);
-               if (!cfs_list_empty(&req->rq_list)) {
-                       cfs_list_del_init(&req->rq_list);
-                       cfs_atomic_dec(&imp->imp_inflight);
-               }
-               spin_unlock(&imp->imp_lock);
-               cfs_atomic_dec(&set->set_remaining);
-       }
-       mutex_unlock(&pinger_mutex);
-
-        ptlrpc_set_destroy(set);
-        pd->pd_set = NULL;
-
-out:
-        pd->pd_next_ping = cfs_time_add(pd->pd_this_ping,
-                                        cfs_time_seconds(PING_INTERVAL));
-        pd->pd_this_ping = 0; /* XXX for debug */
-
-        CDEBUG(D_INFO, "finished a round ping\n");
-        pd->pd_recursion--;
-        return 0;
-}
-
-static void *pinger_callback = NULL;
-#endif /* ENABLE_PINGER */
-
-int ptlrpc_start_pinger(void)
-{
-#ifdef ENABLE_PINGER
-        memset(&pinger_args, 0, sizeof(pinger_args));
-        pinger_callback = liblustre_register_wait_callback("pinger_check_rpcs",
-                                                           &pinger_check_rpcs,
-                                                           &pinger_args);
-#endif
-        return 0;
-}
-
-int ptlrpc_stop_pinger(void)
-{
-#ifdef ENABLE_PINGER
-        if (pinger_callback)
-                liblustre_deregister_wait_callback(pinger_callback);
-#endif
-        return 0;
-}
-
-void ptlrpc_pinger_sending_on_import(struct obd_import *imp)
-{
-#ifdef ENABLE_PINGER
-       mutex_lock(&pinger_mutex);
-        ptlrpc_update_next_ping(imp, 0);
-        if (pinger_args.pd_set == NULL &&
-            cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
-                CDEBUG(D_HA, "set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
-                        imp->imp_next_ping, cfs_time_current());
-                pinger_args.pd_next_ping = imp->imp_next_ping;
-        }
-       mutex_unlock(&pinger_mutex);
-#endif
-}
-
-void ptlrpc_pinger_commit_expected(struct obd_import *imp)
-{
-#ifdef ENABLE_PINGER
-       mutex_lock(&pinger_mutex);
-        ptlrpc_update_next_ping(imp, 1);
-        if (pinger_args.pd_set == NULL &&
-            cfs_time_before(imp->imp_next_ping, pinger_args.pd_next_ping)) {
-                CDEBUG(D_HA,"set next ping to "CFS_TIME_T"(cur "CFS_TIME_T")\n",
-                        imp->imp_next_ping, cfs_time_current());
-                pinger_args.pd_next_ping = imp->imp_next_ping;
-        }
-       mutex_unlock(&pinger_mutex);
-#endif
-}
-
-int ptlrpc_add_timeout_client(int time, enum timeout_event event,
-                              timeout_cb_t cb, void *data,
-                              cfs_list_t *obd_list)
-{
-        return 0;
-}
-
-int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
-                              enum timeout_event event)
-{
-        return 0;
-}
-
-int ptlrpc_pinger_add_import(struct obd_import *imp)
-{
-        ENTRY;
-        if (!cfs_list_empty(&imp->imp_pinger_chain))
-                RETURN(-EALREADY);
-
-        CDEBUG(D_HA, "adding pingable import %s->%s\n",
-               imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
-        ptlrpc_pinger_sending_on_import(imp);
-
-       mutex_lock(&pinger_mutex);
-        cfs_list_add_tail(&imp->imp_pinger_chain, &pinger_imports);
-        class_import_get(imp);
-       mutex_unlock(&pinger_mutex);
-
-        RETURN(0);
-}
-
-int ptlrpc_pinger_del_import(struct obd_import *imp)
-{
-        ENTRY;
-        if (cfs_list_empty(&imp->imp_pinger_chain))
-                RETURN(-ENOENT);
-
-       mutex_lock(&pinger_mutex);
-        cfs_list_del_init(&imp->imp_pinger_chain);
-        CDEBUG(D_HA, "removing pingable import %s->%s\n",
-               imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
-        class_import_put(imp);
-       mutex_unlock(&pinger_mutex);
-        RETURN(0);
-}
-
-void ptlrpc_pinger_wake_up()
-{
-#ifdef ENABLE_PINGER
-        /* XXX force pinger to run, if needed */
-        struct obd_import *imp;
-        ENTRY;
-        cfs_list_for_each_entry(imp, &pinger_imports, imp_pinger_chain) {
-                CDEBUG(D_RPCTRACE, "checking import %s->%s\n",
-                       imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
-#ifdef ENABLE_LIBLUSTRE_RECOVERY
-                if (imp->imp_state == LUSTRE_IMP_DISCON &&
-                    !imp_is_deactive(imp))
-#else
-                /*XXX only recover for the initial connection */
-                if (!lustre_handle_is_used(&imp->imp_remote_handle) &&
-                    imp->imp_state == LUSTRE_IMP_DISCON &&
-                    !imp_is_deactive(imp))
-#endif
-                        ptlrpc_initiate_recovery(imp);
-                else if (imp->imp_state != LUSTRE_IMP_FULL)
-                        CDEBUG(D_HA, "Refused to recover import %s->%s "
-                                     "state %d, deactive %d\n",
-                                     imp->imp_obd->obd_uuid.uuid,
-                                     obd2cli_tgt(imp->imp_obd), imp->imp_state,
-                                     imp_is_deactive(imp));
-        }
-        EXIT;
-#endif
-}
-#endif /* !__KERNEL__ */