Whamcloud - gitweb
LU-3963 libcfs: remove cfs_hash_long
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_svc_upcall.c
index 0b18ff9..3e60767 100644 (file)
@@ -90,28 +90,50 @@ __u64 gss_get_next_ctx_index(void)
 
 static inline unsigned long hash_mem(char *buf, int length, int bits)
 {
-        unsigned long hash = 0;
-        unsigned long l = 0;
-        int len = 0;
-        unsigned char c;
-
-        do {
-                if (len == length) {
-                        c = (char) len;
-                        len = -1;
-                } else
-                        c = *buf++;
-
-                l = (l << 8) | c;
-                len++;
-
-                if ((len & (BITS_PER_LONG/8-1)) == 0)
-                        hash = cfs_hash_long(hash^l, BITS_PER_LONG);
-        } while (len);
-
-        return hash >> (BITS_PER_LONG - bits);
+       unsigned long hash = 0;
+       unsigned long l = 0;
+       int len = 0;
+       unsigned char c;
+
+       do {
+               if (len == length) {
+                       c = (char) len;
+                       len = -1;
+               } else
+                       c = *buf++;
+
+               l = (l << 8) | c;
+               len++;
+
+               if ((len & (BITS_PER_LONG/8-1)) == 0)
+                       hash = hash_long(hash^l, BITS_PER_LONG);
+       } while (len);
+
+       return hash >> (BITS_PER_LONG - bits);
 }
 
+/* This compatibility can be removed once kernel 3.3 is used,
+ * since cache_register_net/cache_unregister_net are exported.
+ * Note that since kernel 3.4 cache_register and cache_unregister
+ * are removed.
+*/
+static inline int _cache_register_net(struct cache_detail *cd, struct net *net)
+{
+#ifdef HAVE_CACHE_REGISTER
+       return cache_register(cd);
+#else
+       return cache_register_net(cd, net);
+#endif
+}
+static inline void _cache_unregister_net(struct cache_detail *cd,
+                                        struct net *net)
+{
+#ifdef HAVE_CACHE_REGISTER
+       cache_unregister(cd);
+#else
+       cache_unregister_net(cd, net);
+#endif
+}
 /****************************************
  * rsi cache                            *
  ****************************************/
@@ -161,26 +183,34 @@ static void rsi_request(struct cache_detail *cd,
                         struct cache_head *h,
                         char **bpp, int *blen)
 {
-        struct rsi *rsi = container_of(h, struct rsi, h);
-        __u64 index = 0;
-
-        /* if in_handle is null, provide kernel suggestion */
-        if (rsi->in_handle.len == 0)
-                index = gss_get_next_ctx_index();
-
-        qword_addhex(bpp, blen, (char *) &rsi->lustre_svc,
-                     sizeof(rsi->lustre_svc));
-        qword_addhex(bpp, blen, (char *) &rsi->nid, sizeof(rsi->nid));
-        qword_addhex(bpp, blen, (char *) &index, sizeof(index));
-        qword_addhex(bpp, blen, rsi->in_handle.data, rsi->in_handle.len);
-        qword_addhex(bpp, blen, rsi->in_token.data, rsi->in_token.len);
-        (*bpp)[-1] = '\n';
+       struct rsi *rsi = container_of(h, struct rsi, h);
+       __u64 index = 0;
+
+       /* if in_handle is null, provide kernel suggestion */
+       if (rsi->in_handle.len == 0)
+               index = gss_get_next_ctx_index();
+
+       qword_addhex(bpp, blen, (char *) &rsi->lustre_svc,
+                       sizeof(rsi->lustre_svc));
+       qword_addhex(bpp, blen, (char *) &rsi->nid, sizeof(rsi->nid));
+       qword_addhex(bpp, blen, (char *) &index, sizeof(index));
+       qword_addhex(bpp, blen, rsi->in_handle.data, rsi->in_handle.len);
+       qword_addhex(bpp, blen, rsi->in_token.data, rsi->in_token.len);
+       (*bpp)[-1] = '\n';
+}
+
+#ifdef HAVE_SUNRPC_UPCALL_HAS_3ARGS
+static int rsi_upcall(struct cache_detail *cd, struct cache_head *h)
+{
+       return sunrpc_cache_pipe_upcall(cd, h, rsi_request);
 }
+#else
 
 static int rsi_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-        return sunrpc_cache_pipe_upcall(cd, h, rsi_request);
+       return sunrpc_cache_pipe_upcall(cd, h);
 }
+#endif
 
 static inline void __rsi_init(struct rsi *new, struct rsi *item)
 {
@@ -349,16 +379,19 @@ out:
 }
 
 static struct cache_detail rsi_cache = {
-        .hash_size      = RSI_HASHMAX,
-        .hash_table     = rsi_table,
-        .name           = "auth.sptlrpc.init",
-        .cache_put      = rsi_put,
-        .cache_upcall   = rsi_upcall,
-        .cache_parse    = rsi_parse,
-        .match          = rsi_match,
-        .init           = rsi_init,
-        .update         = update_rsi,
-        .alloc          = rsi_alloc,
+       .hash_size      = RSI_HASHMAX,
+       .hash_table     = rsi_table,
+       .name           = "auth.sptlrpc.init",
+       .cache_put      = rsi_put,
+#ifndef HAVE_SUNRPC_UPCALL_HAS_3ARGS
+       .cache_request  = rsi_request,
+#endif
+       .cache_upcall   = rsi_upcall,
+       .cache_parse    = rsi_parse,
+       .match          = rsi_match,
+       .init           = rsi_init,
+       .update         = update_rsi,
+       .alloc          = rsi_alloc,
 };
 
 static struct rsi *rsi_lookup(struct rsi *item)
@@ -899,6 +932,7 @@ cache_check:
         * take care of following calls. */
        rc = cache_check(&rsi_cache, &rsip->h, &cache_upcall_chandle);
        switch (rc) {
+       case -ETIMEDOUT:
        case -EAGAIN: {
                 int valid;
 
@@ -1058,26 +1092,32 @@ void gss_svc_upcall_destroy_ctx(struct gss_svc_ctx *ctx)
 
 int __init gss_init_svc_upcall(void)
 {
-       int     i;
+       int     i, rc;
 
        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
-         * sequence number checking, thus no chance to sent error notification
-         * back to clients.
-         */
-        cfs_get_random_bytes(&__ctx_index, sizeof(__ctx_index));
-
-
-        cache_register(&rsi_cache);
-        cache_register(&rsc_cache);
-
-        /* FIXME this looks stupid. we intend to give lsvcgssd a chance to open
-         * the init upcall channel, otherwise there's big chance that the first
-         * 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. */
+       /*
+        * this helps reducing context index confliction. after server reboot,
+        * conflicting request from clients might be filtered out by initial
+        * sequence number checking, thus no chance to sent error notification
+        * back to clients.
+        */
+       cfs_get_random_bytes(&__ctx_index, sizeof(__ctx_index));
+
+       rc = _cache_register_net(&rsi_cache, &init_net);
+       if (rc != 0)
+               return rc;
+
+       rc = _cache_register_net(&rsc_cache, &init_net);
+       if (rc != 0) {
+               _cache_unregister_net(&rsi_cache, &init_net);
+               return rc;
+       }
+
+       /* FIXME this looks stupid. we intend to give lsvcgssd a chance to open
+        * the init upcall channel, otherwise there's big chance that the first
+        * 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;
@@ -1086,18 +1126,18 @@ int __init gss_init_svc_upcall(void)
                schedule_timeout(HZ / 4);
        }
 
-        if (atomic_read(&rsi_cache.readers) == 0)
-                CWARN("Init channel is not opened by lsvcgssd, following "
-                      "request might be dropped until lsvcgssd is active\n");
+       if (atomic_read(&rsi_cache.readers) == 0)
+               CWARN("Init channel is not opened by lsvcgssd, following "
+                     "request might be dropped until lsvcgssd is active\n");
 
-        return 0;
+       return 0;
 }
 
-void __exit gss_exit_svc_upcall(void)
+void gss_exit_svc_upcall(void)
 {
-        cache_purge(&rsi_cache);
-        cache_unregister(&rsi_cache);
+       cache_purge(&rsi_cache);
+       _cache_unregister_net(&rsi_cache, &init_net);
 
-        cache_purge(&rsc_cache);
-        cache_unregister(&rsc_cache);
+       cache_purge(&rsc_cache);
+       _cache_unregister_net(&rsc_cache, &init_net);
 }