Whamcloud - gitweb
LU-4113 gss: uncatched error in gss_svc_upcall causes drops
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_svc_upcall.c
index 9d2d79f..eb5e493 100644 (file)
@@ -1,11 +1,9 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * Modifications for Lustre
  *
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  *
- * Copyright (c) 2012, Whamcloud, Inc.
+ * Copyright (c) 2012, Intel Corporation.
  *
  * Author: Eric Mei <ericm@clusterfs.com>
  */
 
 #define GSS_SVC_UPCALL_TIMEOUT  (20)
 
-static cfs_spinlock_t __ctx_index_lock;
+static spinlock_t __ctx_index_lock;
 static __u64 __ctx_index;
 
 __u64 gss_get_next_ctx_index(void)
 {
-        __u64 idx;
+       __u64 idx;
 
-        cfs_spin_lock(&__ctx_index_lock);
-        idx = __ctx_index++;
-        cfs_spin_unlock(&__ctx_index_lock);
+       spin_lock(&__ctx_index_lock);
+       idx = __ctx_index++;
+       spin_unlock(&__ctx_index_lock);
 
-        return idx;
+       return idx;
 }
 
 static inline unsigned long hash_mem(char *buf, int length, int bits)
@@ -123,13 +121,13 @@ static inline unsigned long hash_mem(char *buf, int length, int bits)
 #define RSI_HASHMASK    (RSI_HASHMAX - 1)
 
 struct rsi {
-        struct cache_head       h;
-        __u32                   lustre_svc;
-        __u64                   nid;
-        cfs_waitq_t             waitq;
-        rawobj_t                in_handle, in_token;
-        rawobj_t                out_handle, out_token;
-        int                     major_status, minor_status;
+       struct cache_head       h;
+       __u32                   lustre_svc;
+       __u64                   nid;
+       wait_queue_head_t       waitq;
+       rawobj_t                in_handle, in_token;
+       rawobj_t                out_handle, out_token;
+       int                     major_status, minor_status;
 };
 
 static struct cache_head *rsi_table[RSI_HASHMAX];
@@ -179,26 +177,24 @@ static void rsi_request(struct cache_detail *cd,
         (*bpp)[-1] = '\n';
 }
 
-#ifdef HAVE_CACHE_UPCALL
 static int rsi_upcall(struct cache_detail *cd, struct cache_head *h)
 {
         return sunrpc_cache_pipe_upcall(cd, h, rsi_request);
 }
-#endif
 
 static inline void __rsi_init(struct rsi *new, struct rsi *item)
 {
-        new->out_handle = RAWOBJ_EMPTY;
-        new->out_token = RAWOBJ_EMPTY;
+       new->out_handle = RAWOBJ_EMPTY;
+       new->out_token = RAWOBJ_EMPTY;
 
-        new->in_handle = item->in_handle;
-        item->in_handle = RAWOBJ_EMPTY;
-        new->in_token = item->in_token;
-        item->in_token = RAWOBJ_EMPTY;
+       new->in_handle = item->in_handle;
+       item->in_handle = RAWOBJ_EMPTY;
+       new->in_token = item->in_token;
+       item->in_token = RAWOBJ_EMPTY;
 
-        new->lustre_svc = item->lustre_svc;
-        new->nid = item->nid;
-        cfs_waitq_init(&new->waitq);
+       new->lustre_svc = item->lustre_svc;
+       new->nid = item->nid;
+       init_waitqueue_head(&new->waitq);
 }
 
 static inline void __rsi_update(struct rsi *new, struct rsi *item)
@@ -339,17 +335,17 @@ static int rsi_parse(struct cache_detail *cd, char *mesg, int mlen)
         rsip = rsi_update(&rsii, rsip);
         status = 0;
 out:
-        rsi_free(&rsii);
-        if (rsip) {
-                cfs_waitq_broadcast(&rsip->waitq);
-                cache_put(&rsip->h, &rsi_cache);
-        } else {
-                status = -ENOMEM;
-        }
-
-        if (status)
-                CERROR("rsi parse error %d\n", status);
-        RETURN(status);
+       rsi_free(&rsii);
+       if (rsip) {
+               wake_up_all(&rsip->waitq);
+               cache_put(&rsip->h, &rsi_cache);
+       } else {
+               status = -ENOMEM;
+       }
+
+       if (status)
+               CERROR("rsi parse error %d\n", status);
+       RETURN(status);
 }
 
 static struct cache_detail rsi_cache = {
@@ -357,11 +353,7 @@ static struct cache_detail rsi_cache = {
         .hash_table     = rsi_table,
         .name           = "auth.sptlrpc.init",
         .cache_put      = rsi_put,
-#ifdef HAVE_CACHE_UPCALL
         .cache_upcall   = rsi_upcall,
-#else
-        .cache_request  = rsi_request,
-#endif
         .cache_parse    = rsi_parse,
         .match          = rsi_match,
         .init           = rsi_init,
@@ -448,7 +440,7 @@ static inline void __rsc_update(struct rsc *new, struct rsc *tmp)
         tmp->ctx.gsc_mechctx = NULL;
 
         memset(&new->ctx.gsc_seqdata, 0, sizeof(new->ctx.gsc_seqdata));
-        cfs_spin_lock_init(&new->ctx.gsc_seqdata.ssd_lock);
+       spin_lock_init(&new->ctx.gsc_seqdata.ssd_lock);
 }
 
 static void rsc_put(struct kref *ref)
@@ -569,7 +561,7 @@ static int rsc_parse(struct cache_detail *cd, char *mesg, int mlen)
                 goto out;
         if (rv == -ENOENT) {
                 CERROR("NOENT? set rsc entry negative\n");
-                cfs_set_bit(CACHE_NEGATIVE, &rsci.h.flags);
+               set_bit(CACHE_NEGATIVE, &rsci.h.flags);
         } else {
                 rawobj_t tmp_buf;
                 unsigned long ctx_expiry;
@@ -676,7 +668,7 @@ static void rsc_flush(rsc_entry_match *match, long data)
         int n;
         ENTRY;
 
-        cfs_write_lock(&rsc_cache.hash_lock);
+       write_lock(&rsc_cache.hash_lock);
         for (n = 0; n < RSC_HASHMAX; n++) {
                 for (ch = &rsc_cache.hash_table[n]; *ch;) {
                         rscp = container_of(*ch, struct rsc, h);
@@ -690,12 +682,12 @@ static void rsc_flush(rsc_entry_match *match, long data)
                         *ch = (*ch)->next;
                         rscp->h.next = NULL;
                         cache_get(&rscp->h);
-                        cfs_set_bit(CACHE_NEGATIVE, &rscp->h.flags);
+                       set_bit(CACHE_NEGATIVE, &rscp->h.flags);
                         COMPAT_RSC_PUT(&rscp->h, &rsc_cache);
                         rsc_cache.entries--;
                 }
         }
-        cfs_write_unlock(&rsc_cache.hash_lock);
+       write_unlock(&rsc_cache.hash_lock);
         EXIT;
 }
 
@@ -852,22 +844,22 @@ static struct cache_deferred_req* cache_upcall_defer(struct cache_req *req)
 static struct cache_req cache_upcall_chandle = { cache_upcall_defer };
 
 int gss_svc_upcall_handle_init(struct ptlrpc_request *req,
-                               struct gss_svc_reqctx *grctx,
-                               struct gss_wire_ctx *gw,
-                               struct obd_device *target,
-                               __u32 lustre_svc,
-                               rawobj_t *rvs_hdl,
-                               rawobj_t *in_token)
+                              struct gss_svc_reqctx *grctx,
+                              struct gss_wire_ctx *gw,
+                              struct obd_device *target,
+                              __u32 lustre_svc,
+                              rawobj_t *rvs_hdl,
+                              rawobj_t *in_token)
 {
-        struct ptlrpc_reply_state *rs;
-        struct rsc                *rsci = NULL;
-        struct rsi                *rsip = NULL, rsikey;
-        cfs_waitlink_t             wait;
-        int                        replen = sizeof(struct ptlrpc_body);
-        struct gss_rep_header     *rephdr;
-        int                        first_check = 1;
-        int                        rc = SECSVC_DROP;
-        ENTRY;
+       struct ptlrpc_reply_state *rs;
+       struct rsc                *rsci = NULL;
+       struct rsi                *rsip = NULL, rsikey;
+       wait_queue_t             wait;
+       int                        replen = sizeof(struct ptlrpc_body);
+       struct gss_rep_header     *rephdr;
+       int                        first_check = 1;
+       int                        rc = SECSVC_DROP;
+       ENTRY;
 
         memset(&rsikey, 0, sizeof(rsikey));
         rsikey.lustre_svc = lustre_svc;
@@ -896,35 +888,36 @@ int gss_svc_upcall_handle_init(struct ptlrpc_request *req,
                 GOTO(out, rc);
         }
 
-        cache_get(&rsip->h); /* take an extra ref */
-        cfs_waitq_init(&rsip->waitq);
-        cfs_waitlink_init(&wait);
-        cfs_waitq_add(&rsip->waitq, &wait);
+       cache_get(&rsip->h); /* take an extra ref */
+       init_waitqueue_head(&rsip->waitq);
+       init_waitqueue_entry_current(&wait);
+       add_wait_queue(&rsip->waitq, &wait);
 
 cache_check:
-        /* Note each time cache_check() will drop a reference if return
-         * non-zero. We hold an extra reference on initial rsip, but must
-         * take care of following calls. */
-        rc = cache_check(&rsi_cache, &rsip->h, &cache_upcall_chandle);
-        switch (rc) {
-        case -EAGAIN: {
+       /* Note each time cache_check() will drop a reference if return
+        * non-zero. We hold an extra reference on initial rsip, but must
+        * take care of following calls. */
+       rc = cache_check(&rsi_cache, &rsip->h, &cache_upcall_chandle);
+       switch (rc) {
+       case -ETIMEDOUT:
+       case -EAGAIN: {
                 int valid;
 
                 if (first_check) {
                         first_check = 0;
 
                         read_lock(&rsi_cache.hash_lock);
-                        valid = cfs_test_bit(CACHE_VALID, &rsip->h.flags);
+                       valid = test_bit(CACHE_VALID, &rsip->h.flags);
                         if (valid == 0)
-                                cfs_set_current_state(CFS_TASK_INTERRUPTIBLE);
+                               set_current_state(TASK_INTERRUPTIBLE);
                         read_unlock(&rsi_cache.hash_lock);
 
-                        if (valid == 0)
-                                cfs_schedule_timeout(GSS_SVC_UPCALL_TIMEOUT *
-                                                     CFS_HZ);
+                       if (valid == 0)
+                               schedule_timeout(GSS_SVC_UPCALL_TIMEOUT *
+                                                    HZ);
 
-                        cache_get(&rsip->h);
-                        goto cache_check;
+                       cache_get(&rsip->h);
+                       goto cache_check;
                 }
                 CWARN("waited %ds timeout, drop\n", GSS_SVC_UPCALL_TIMEOUT);
                 break;
@@ -935,17 +928,17 @@ cache_check:
         case 0:
                 /* if not the first check, we have to release the extra
                  * reference we just added on it. */
-                if (!first_check)
-                        cache_put(&rsip->h, &rsi_cache);
-                CDEBUG(D_SEC, "cache_check is good\n");
-                break;
-        }
+               if (!first_check)
+                       cache_put(&rsip->h, &rsi_cache);
+               CDEBUG(D_SEC, "cache_check is good\n");
+               break;
+       }
 
-        cfs_waitq_del(&rsip->waitq, &wait);
-        cache_put(&rsip->h, &rsi_cache);
+       remove_wait_queue(&rsip->waitq, &wait);
+       cache_put(&rsip->h, &rsi_cache);
 
-        if (rc)
-                GOTO(out, rc = SECSVC_DROP);
+       if (rc)
+               GOTO(out, rc = SECSVC_DROP);
 
         rc = SECSVC_DROP;
         rsci = gss_svc_searchbyctx(&rsip->out_handle);
@@ -1021,7 +1014,7 @@ out:
         if (rsci) {
                 /* if anything went wrong, we don't keep the context too */
                 if (rc != SECSVC_OK)
-                        cfs_set_bit(CACHE_NEGATIVE, &rsci->h.flags);
+                       set_bit(CACHE_NEGATIVE, &rsci->h.flags);
                 else
                         CDEBUG(D_SEC, "create rsc with idx "LPX64"\n",
                                gss_handle_to_u64(&rsci->handle));
@@ -1059,16 +1052,16 @@ void gss_svc_upcall_destroy_ctx(struct gss_svc_ctx *ctx)
         struct rsc *rsc = container_of(ctx, struct rsc, ctx);
 
         /* can't be found */
-        cfs_set_bit(CACHE_NEGATIVE, &rsc->h.flags);
+       set_bit(CACHE_NEGATIVE, &rsc->h.flags);
         /* to be removed at next scan */
         rsc->h.expiry_time = 1;
 }
 
 int __init gss_init_svc_upcall(void)
 {
-        int     i;
+       int     i;
 
-        cfs_spin_lock_init(&__ctx_index_lock);
+       spin_lock_init(&__ctx_index_lock);
         /*
          * this helps reducing context index confliction. after server reboot,
          * conflicting request from clients might be filtered out by initial
@@ -1086,13 +1079,13 @@ int __init gss_init_svc_upcall(void)
          * upcall issued before the channel be opened thus nfsv4 cache code will
          * drop the request direclty, thus lead to unnecessary recovery time.
          * here we wait at miximum 1.5 seconds. */
-        for (i = 0; i < 6; i++) {
-                if (atomic_read(&rsi_cache.readers) > 0)
-                        break;
-                cfs_set_current_state(TASK_UNINTERRUPTIBLE);
-                LASSERT(CFS_HZ >= 4);
-                cfs_schedule_timeout(CFS_HZ / 4);
-        }
+       for (i = 0; i < 6; i++) {
+               if (atomic_read(&rsi_cache.readers) > 0)
+                       break;
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               LASSERT(HZ >= 4);
+               schedule_timeout(HZ / 4);
+       }
 
         if (atomic_read(&rsi_cache.readers) == 0)
                 CWARN("Init channel is not opened by lsvcgssd, following "