Whamcloud - gitweb
LU-6496 ptlrpc: Fix wrong code indentation in plain_authorize
[fs/lustre-release.git] / lustre / ptlrpc / sec_bulk.c
index 9da60ad..473943c 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 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/
 #define DEBUG_SUBSYSTEM S_SEC
 
 #include <libcfs/libcfs.h>
-#ifndef __KERNEL__
-#include <liblustre.h>
-#include <libcfs/list.h>
-#else
-#include <linux/crypto.h>
-#endif
 
 #include <obd.h>
 #include <obd_cksum.h>
@@ -63,7 +57,6 @@
  * bulk encryption page pools           *
  ****************************************/
 
-#ifdef __KERNEL__
 
 #define PTRS_PER_PAGE   (PAGE_CACHE_SIZE / sizeof(void *))
 #define PAGES_PER_POOL  (PTRS_PER_PAGE)
@@ -129,7 +122,7 @@ static struct ptlrpc_enc_page_pool {
 /*
  * memory shrinker
  */
-const int pools_shrinker_seeks = DEFAULT_SEEKS;
+static const int pools_shrinker_seeks = DEFAULT_SEEKS;
 static struct shrinker *pools_shrinker;
 
 
@@ -160,7 +153,7 @@ int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v)
                       "cache missing:           %lu\n"
                       "low free mark:           %lu\n"
                       "max waitqueue depth:     %u\n"
-                      "max wait time:           "CFS_TIME_T"/%u\n"
+                     "max wait time:           "CFS_TIME_T"/%lu\n"
                       ,
                      totalram_pages,
                       PAGES_PER_POOL,
@@ -179,7 +172,8 @@ int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v)
                      page_pools.epp_st_missings,
                      page_pools.epp_st_lowfree,
                      page_pools.epp_st_max_wqlen,
-                     page_pools.epp_st_max_wait, HZ
+                     page_pools.epp_st_max_wait,
+                     msecs_to_jiffies(MSEC_PER_SEC)
                     );
 
        spin_unlock(&page_pools.epp_lock);
@@ -579,11 +573,11 @@ again:
                                                page_pools.epp_waitqlen;
 
                        set_current_state(TASK_UNINTERRUPTIBLE);
-                       init_waitqueue_entry_current(&waitlink);
+                       init_waitqueue_entry(&waitlink, current);
                        add_wait_queue(&page_pools.epp_waitq, &waitlink);
 
                        spin_unlock(&page_pools.epp_lock);
-                       waitq_wait(&waitlink, TASK_UNINTERRUPTIBLE);
+                       schedule();
                        remove_wait_queue(&page_pools.epp_waitq, &waitlink);
                        LASSERT(page_pools.epp_waitqlen > 0);
                        spin_lock(&page_pools.epp_lock);
@@ -686,7 +680,6 @@ void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc)
                 desc->bd_iov_count * sizeof(*desc->bd_enc_iov));
        desc->bd_enc_iov = NULL;
 }
-EXPORT_SYMBOL(sptlrpc_enc_pool_put_pages);
 
 /*
  * we don't do much stuff for add_user/del_user anymore, except adding some
@@ -805,39 +798,20 @@ void sptlrpc_enc_pool_fini(void)
 
         enc_pools_free();
 
-        if (page_pools.epp_st_access > 0) {
-                CDEBUG(D_SEC,
-                       "max pages %lu, grows %u, grow fails %u, shrinks %u, "
-                       "access %lu, missing %lu, max qlen %u, max wait "
-                       CFS_TIME_T"/%d\n",
-                       page_pools.epp_st_max_pages, page_pools.epp_st_grows,
-                       page_pools.epp_st_grow_fails,
+       if (page_pools.epp_st_access > 0) {
+               CDEBUG(D_SEC,
+                      "max pages %lu, grows %u, grow fails %u, shrinks %u, "
+                      "access %lu, missing %lu, max qlen %u, max wait "
+                      CFS_TIME_T"/%lu\n",
+                      page_pools.epp_st_max_pages, page_pools.epp_st_grows,
+                      page_pools.epp_st_grow_fails,
                       page_pools.epp_st_shrinks, page_pools.epp_st_access,
                       page_pools.epp_st_missings, page_pools.epp_st_max_wqlen,
-                      page_pools.epp_st_max_wait, HZ);
+                      page_pools.epp_st_max_wait,
+                      msecs_to_jiffies(MSEC_PER_SEC));
        }
 }
 
-#else /* !__KERNEL__ */
-
-int sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc)
-{
-        return 0;
-}
-
-void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc)
-{
-}
-
-int sptlrpc_enc_pool_init(void)
-{
-        return 0;
-}
-
-void sptlrpc_enc_pool_fini(void)
-{
-}
-#endif
 
 static int cfs_hash_alg_id[] = {
        [BULK_HASH_ALG_NULL]    = CFS_HASH_ALG_NULL,
@@ -853,13 +827,11 @@ const char * sptlrpc_get_hash_name(__u8 hash_alg)
 {
        return cfs_crypto_hash_name(cfs_hash_alg_id[hash_alg]);
 }
-EXPORT_SYMBOL(sptlrpc_get_hash_name);
 
 __u8 sptlrpc_get_hash_alg(const char *algname)
 {
        return cfs_crypto_hash_alg(algname);
 }
-EXPORT_SYMBOL(sptlrpc_get_hash_alg);
 
 int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed)
 {
@@ -899,12 +871,17 @@ int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed)
 }
 EXPORT_SYMBOL(bulk_sec_desc_unpack);
 
+/*
+ * Compute the checksum of an RPC buffer payload.  If the return \a buflen
+ * is not large enough, truncate the result to fit so that it is possible
+ * to use a hash function with a large hash space, but only use a part of
+ * the resulting hash.
+ */
 int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
                              void *buf, int buflen)
 {
        struct cfs_crypto_hash_desc     *hdesc;
        int                             hashsize;
-       char                            hashbuf[64];
        unsigned int                    bufsize;
        int                             i, err;
 
@@ -921,30 +898,23 @@ int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
        hashsize = cfs_crypto_hash_digestsize(cfs_hash_alg_id[alg]);
 
        for (i = 0; i < desc->bd_iov_count; i++) {
-#ifdef __KERNEL__
                cfs_crypto_hash_update_page(hdesc, desc->bd_iov[i].kiov_page,
-                                 desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK,
+                                 desc->bd_iov[i].kiov_offset & ~PAGE_MASK,
                                  desc->bd_iov[i].kiov_len);
-#else
-               cfs_crypto_hash_update(hdesc, desc->bd_iov[i].iov_base,
-                                 desc->bd_iov[i].iov_len);
-#endif
        }
+
        if (hashsize > buflen) {
+               unsigned char hashbuf[CFS_CRYPTO_HASH_DIGESTSIZE_MAX];
+
                bufsize = sizeof(hashbuf);
-               err = cfs_crypto_hash_final(hdesc, (unsigned char *)hashbuf,
-                                           &bufsize);
+               LASSERTF(bufsize >= hashsize, "bufsize = %u < hashsize %u\n",
+                        bufsize, hashsize);
+               err = cfs_crypto_hash_final(hdesc, hashbuf, &bufsize);
                memcpy(buf, hashbuf, buflen);
        } else {
                bufsize = buflen;
-               err = cfs_crypto_hash_final(hdesc, (unsigned char *)buf,
-                                           &bufsize);
+               err = cfs_crypto_hash_final(hdesc, buf, &bufsize);
        }
 
-       if (err)
-               cfs_crypto_hash_final(hdesc, NULL, NULL);
        return err;
 }
-EXPORT_SYMBOL(sptlrpc_get_bulk_checksum);
-
-