Whamcloud - gitweb
LU-3963 libcfs: remove proc handler wrappers
[fs/lustre-release.git] / lustre / obdclass / capa.c
index 5f5bc1b..fa2affd 100644 (file)
@@ -42,7 +42,6 @@
 
 #define DEBUG_SUBSYSTEM S_SEC
 
-#ifdef __KERNEL__
 #include <linux/version.h>
 #include <linux/fs.h>
 #include <asm/unistd.h>
@@ -53,9 +52,6 @@
 #include <obd_class.h>
 #include <lustre_debug.h>
 #include <lustre/lustre_idl.h>
-#else
-#include <liblustre.h>
-#endif
 
 #include <libcfs/list.h>
 #include <lustre_capa.h>
 
 struct kmem_cache *capa_cachep;
 
-#ifdef __KERNEL__
 /* lock for capa hash/capa_list/fo_capa_keys */
 DEFINE_SPINLOCK(capa_lock);
 
-cfs_list_t capa_list[CAPA_SITE_MAX];
+struct list_head capa_list[CAPA_SITE_MAX];
 
 static struct capa_hmac_alg capa_hmac_algs[] = {
         DEF_CAPA_HMAC_ALG("sha1", SHA1, 20, 20),
 };
-#endif
 /* capa count */
 int capa_count[CAPA_SITE_MAX] = { 0, };
 
@@ -83,25 +77,24 @@ EXPORT_SYMBOL(capa_list);
 EXPORT_SYMBOL(capa_lock);
 EXPORT_SYMBOL(capa_count);
 
-cfs_hlist_head_t *init_capa_hash(void)
+struct hlist_head *init_capa_hash(void)
 {
-       cfs_hlist_head_t *hash;
+       struct hlist_head *hash;
        int nr_hash, i;
 
        OBD_ALLOC(hash, PAGE_CACHE_SIZE);
        if (!hash)
                return NULL;
 
-       nr_hash = PAGE_CACHE_SIZE / sizeof(cfs_hlist_head_t);
+       nr_hash = PAGE_CACHE_SIZE / sizeof(struct hlist_head);
        LASSERT(nr_hash > NR_CAPAHASH);
 
        for (i = 0; i < NR_CAPAHASH; i++)
-               CFS_INIT_HLIST_HEAD(hash + i);
+               INIT_HLIST_HEAD(hash + i);
        return hash;
 }
 EXPORT_SYMBOL(init_capa_hash);
 
-#ifdef __KERNEL__
 static inline int capa_on_server(struct obd_capa *ocapa)
 {
         return ocapa->c_site == CAPA_SITE_SERVER;
@@ -109,19 +102,20 @@ static inline int capa_on_server(struct obd_capa *ocapa)
 
 static inline void capa_delete(struct obd_capa *ocapa)
 {
-        LASSERT(capa_on_server(ocapa));
-        cfs_hlist_del_init(&ocapa->u.tgt.c_hash);
-        cfs_list_del_init(&ocapa->c_list);
-        capa_count[ocapa->c_site]--;
-        /* release the ref when alloc */
-        capa_put(ocapa);
+       LASSERT(capa_on_server(ocapa));
+       hlist_del_init(&ocapa->u.tgt.c_hash);
+       list_del_init(&ocapa->c_list);
+       capa_count[ocapa->c_site]--;
+       /* release the ref when alloc */
+       capa_put(ocapa);
 }
 
-void cleanup_capa_hash(cfs_hlist_head_t *hash)
+void cleanup_capa_hash(struct hlist_head *hash)
 {
-       int i;
-       cfs_hlist_node_t *pos, *next;
+       struct hlist_node __maybe_unused *pos;
+       struct hlist_node *next;
        struct obd_capa *oc;
+       int i;
 
        spin_lock(&capa_lock);
        for (i = 0; i < NR_CAPAHASH; i++) {
@@ -151,18 +145,18 @@ static inline int capa_is_to_expire(struct obd_capa *oc)
 }
 
 static struct obd_capa *find_capa(struct lustre_capa *capa,
-                                  cfs_hlist_head_t *head, int alive)
+                                 struct hlist_head *head, int alive)
 {
-        cfs_hlist_node_t *pos;
-        struct obd_capa *ocapa;
-        int len = alive ? offsetof(struct lustre_capa, lc_keyid):sizeof(*capa);
+       struct hlist_node __maybe_unused *pos;
+       struct obd_capa *ocapa;
+       int len = alive ? offsetof(struct lustre_capa, lc_keyid):sizeof(*capa);
 
-        cfs_hlist_for_each_entry(ocapa, pos, head, u.tgt.c_hash) {
-                if (memcmp(&ocapa->c_capa, capa, len))
-                        continue;
-                /* don't return one that will expire soon in this case */
-                if (alive && capa_is_to_expire(ocapa))
-                        continue;
+       cfs_hlist_for_each_entry(ocapa, pos, head, u.tgt.c_hash) {
+               if (memcmp(&ocapa->c_capa, capa, len))
+                       continue;
+               /* don't return one that will expire soon in this case */
+               if (alive && capa_is_to_expire(ocapa))
+                       continue;
 
                 LASSERT(capa_on_server(ocapa));
 
@@ -174,30 +168,30 @@ static struct obd_capa *find_capa(struct lustre_capa *capa,
 }
 
 #define LRU_CAPA_DELETE_COUNT 12
-static inline void capa_delete_lru(cfs_list_t *head)
+static inline void capa_delete_lru(struct list_head *head)
 {
-        struct obd_capa *ocapa;
-        cfs_list_t *node = head->next;
-        int count = 0;
-
-        /* free LRU_CAPA_DELETE_COUNT unused capa from head */
-        while (count++ < LRU_CAPA_DELETE_COUNT) {
-                ocapa = cfs_list_entry(node, struct obd_capa, c_list);
-                node = node->next;
+       struct obd_capa *ocapa;
+       struct list_head *node = head->next;
+       int count = 0;
+
+       /* free LRU_CAPA_DELETE_COUNT unused capa from head */
+       while (count++ < LRU_CAPA_DELETE_COUNT) {
+               ocapa = list_entry(node, struct obd_capa, c_list);
+               node = node->next;
                if (atomic_read(&ocapa->c_refc))
-                        continue;
+                       continue;
 
-                DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free lru");
-                capa_delete(ocapa);
-        }
+               DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free lru");
+               capa_delete(ocapa);
+       }
 }
 
 /* add or update */
-struct obd_capa *capa_add(cfs_hlist_head_t *hash, struct lustre_capa *capa)
+struct obd_capa *capa_add(struct hlist_head *hash, struct lustre_capa *capa)
 {
-        cfs_hlist_head_t *head = hash + capa_hashfn(&capa->lc_fid);
+       struct hlist_head *head = hash + capa_hashfn(&capa->lc_fid);
         struct obd_capa *ocapa, *old = NULL;
-        cfs_list_t *list = &capa_list[CAPA_SITE_SERVER];
+       struct list_head *list = &capa_list[CAPA_SITE_SERVER];
 
         ocapa = alloc_capa(CAPA_SITE_SERVER);
         if (IS_ERR(ocapa))
@@ -208,8 +202,8 @@ struct obd_capa *capa_add(cfs_hlist_head_t *hash, struct lustre_capa *capa)
         if (!old) {
                 ocapa->c_capa = *capa;
                 set_capa_expiry(ocapa);
-                cfs_hlist_add_head(&ocapa->u.tgt.c_hash, head);
-                cfs_list_add_tail(&ocapa->c_list, list);
+               hlist_add_head(&ocapa->u.tgt.c_hash, head);
+               list_add_tail(&ocapa->c_list, list);
                 capa_get(ocapa);
                 capa_count[CAPA_SITE_SERVER]++;
                 if (capa_count[CAPA_SITE_SERVER] > CAPA_HASH_SIZE)
@@ -225,7 +219,7 @@ struct obd_capa *capa_add(cfs_hlist_head_t *hash, struct lustre_capa *capa)
 }
 EXPORT_SYMBOL(capa_add);
 
-struct obd_capa *capa_lookup(cfs_hlist_head_t *hash, struct lustre_capa *capa,
+struct obd_capa *capa_lookup(struct hlist_head *hash, struct lustre_capa *capa,
                             int alive)
 {
        struct obd_capa *ocapa;
@@ -233,8 +227,7 @@ struct obd_capa *capa_lookup(cfs_hlist_head_t *hash, struct lustre_capa *capa,
        spin_lock(&capa_lock);
        ocapa = find_capa(capa, hash + capa_hashfn(&capa->lc_fid), alive);
        if (ocapa) {
-               cfs_list_move_tail(&ocapa->c_list,
-                                  &capa_list[CAPA_SITE_SERVER]);
+               list_move_tail(&ocapa->c_list, &capa_list[CAPA_SITE_SERVER]);
                capa_get(ocapa);
        }
        spin_unlock(&capa_lock);
@@ -258,13 +251,14 @@ int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key)
         alg = &capa_hmac_algs[capa_alg(capa)];
 
        tfm = crypto_alloc_hash(alg->ha_name, 0, 0);
-        if (!tfm) {
+        if (IS_ERR(tfm)) {
                 CERROR("crypto_alloc_tfm failed, check whether your kernel"
                        "has crypto support!\n");
-                return -ENOMEM;
+                return PTR_ERR(tfm);
         }
         keylen = alg->ha_keylen;
 
+       sg_init_table(&sl, 1);
         sg_set_page(&sl, virt_to_page(capa),
                     offsetof(struct lustre_capa, lc_hmac),
                    (unsigned long)(capa) % PAGE_CACHE_SIZE);
@@ -307,9 +301,11 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
                 GOTO(out, rc);
         }
 
+       sg_init_table(&sd, 1);
        sg_set_page(&sd, virt_to_page(d), 16,
                    (unsigned long)(d) % PAGE_CACHE_SIZE);
 
+       sg_init_table(&ss, 1);
        sg_set_page(&ss, virt_to_page(s), 16,
                    (unsigned long)(s) % PAGE_CACHE_SIZE);
         desc.tfm   = tfm;
@@ -360,9 +356,11 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
                 GOTO(out, rc);
         }
 
+       sg_init_table(&sd, 1);
        sg_set_page(&sd, virt_to_page(d), 16,
                    (unsigned long)(d) % PAGE_CACHE_SIZE);
 
+       sg_init_table(&ss, 1);
        sg_set_page(&ss, virt_to_page(s), 16,
                    (unsigned long)(s) % PAGE_CACHE_SIZE);
 
@@ -382,7 +380,6 @@ out:
         return rc;
 }
 EXPORT_SYMBOL(capa_decrypt_id);
-#endif
 
 void capa_cpy(void *capa, struct obd_capa *ocapa)
 {