Whamcloud - gitweb
LU-15421 tests: Add missing error() calls on errors
[fs/lustre-release.git] / lustre / ptlrpc / sec_gc.c
index 042a632..c056aa4 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/ptlrpc/sec_gc.c
  *
 
 #define SEC_GC_INTERVAL (30 * 60)
 
-static struct mutex sec_gc_mutex;
-static spinlock_t sec_gc_list_lock;
-static struct list_head sec_gc_list;
-
-static spinlock_t sec_gc_ctx_list_lock;
-static struct list_head sec_gc_ctx_list;
+static DEFINE_MUTEX(sec_gc_mutex);
+static DEFINE_SPINLOCK(sec_gc_list_lock);
+static DEFINE_SPINLOCK(sec_gc_ctx_list_lock);
+static LIST_HEAD(sec_gc_list);
+static LIST_HEAD(sec_gc_ctx_list);
 
 static atomic_t sec_gc_wait_del = ATOMIC_INIT(0);
 
 void sptlrpc_gc_add_sec(struct ptlrpc_sec *sec)
 {
-        LASSERT(sec->ps_policy->sp_cops->gc_ctx);
-        LASSERT(sec->ps_gc_interval > 0);
+       LASSERT(sec->ps_policy->sp_cops->gc_ctx);
+       LASSERT(sec->ps_gc_interval > 0);
        LASSERT(list_empty(&sec->ps_gc_list));
 
        sec->ps_gc_next = ktime_get_real_seconds() + sec->ps_gc_interval;
@@ -77,8 +75,6 @@ void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec)
        if (list_empty(&sec->ps_gc_list))
                return;
 
-       might_sleep();
-
        /* signal before list_del to make iteration in gc thread safe */
        atomic_inc(&sec_gc_wait_del);
 
@@ -118,9 +114,9 @@ static void sec_process_ctx_list(void)
 
        spin_lock(&sec_gc_ctx_list_lock);
 
-       while (!list_empty(&sec_gc_ctx_list)) {
-               ctx = list_entry(sec_gc_ctx_list.next,
-                                    struct ptlrpc_cli_ctx, cc_gc_chain);
+       while ((ctx = list_first_entry_or_null(&sec_gc_ctx_list,
+                                              struct ptlrpc_cli_ctx,
+                                              cc_gc_chain)) != NULL) {
                list_del_init(&ctx->cc_gc_chain);
                spin_unlock(&sec_gc_ctx_list_lock);
 
@@ -138,20 +134,20 @@ static void sec_process_ctx_list(void)
 
 static void sec_do_gc(struct ptlrpc_sec *sec)
 {
-        LASSERT(sec->ps_policy->sp_cops->gc_ctx);
+       LASSERT(sec->ps_policy->sp_cops->gc_ctx);
 
-        if (unlikely(sec->ps_gc_next == 0)) {
-                CDEBUG(D_SEC, "sec %p(%s) has 0 gc time\n",
-                      sec, sec->ps_policy->sp_name);
-                return;
-        }
+       if (unlikely(sec->ps_gc_next == 0)) {
+               CDEBUG(D_SEC, "sec %p(%s) has 0 gc time\n",
+                      sec, sec->ps_policy->sp_name);
+               return;
+       }
 
-        CDEBUG(D_SEC, "check on sec %p(%s)\n", sec, sec->ps_policy->sp_name);
+       CDEBUG(D_SEC, "check on sec %p(%s)\n", sec, sec->ps_policy->sp_name);
 
        if (sec->ps_gc_next > ktime_get_real_seconds())
-                return;
+               return;
 
-        sec->ps_policy->sp_cops->gc_ctx(sec);
+       sec->ps_policy->sp_cops->gc_ctx(sec);
        sec->ps_gc_next = ktime_get_real_seconds() + sec->ps_gc_interval;
 }
 
@@ -161,7 +157,8 @@ static void sec_gc_main(struct work_struct *ws)
 
        sec_process_ctx_list();
 again:
-       /* go through sec list do gc.
+       /*
+        * go through sec list do gc.
         * FIXME here we iterate through the whole list each time which
         * is not optimal. we perhaps want to use balanced binary tree
         * to trace each sec as order of expiry time.
@@ -170,7 +167,8 @@ again:
         */
        mutex_lock(&sec_gc_mutex);
        list_for_each_entry(sec, &sec_gc_list, ps_gc_list) {
-               /* if someone is waiting to be deleted, let it
+               /*
+                * if someone is waiting to be deleted, let it
                 * proceed as soon as possible.
                 */
                if (atomic_read(&sec_gc_wait_del)) {
@@ -190,13 +188,6 @@ again:
 
 int sptlrpc_gc_init(void)
 {
-       mutex_init(&sec_gc_mutex);
-       spin_lock_init(&sec_gc_list_lock);
-       spin_lock_init(&sec_gc_ctx_list_lock);
-
-       INIT_LIST_HEAD(&sec_gc_list);
-       INIT_LIST_HEAD(&sec_gc_ctx_list);
-
        schedule_delayed_work(&sec_gc_work, cfs_time_seconds(SEC_GC_INTERVAL));
        return 0;
 }