Whamcloud - gitweb
LU-6158 mdt: always shrink_capsule in getxattr_all
[fs/lustre-release.git] / lustre / llite / remote_perm.c
index b24a4e6..99a30e4 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) 2012, Whamcloud, Inc.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/version.h>
+#include <linux/user_namespace.h>
+#ifdef HAVE_UIDGID_HEADER
+# include <linux/uidgid.h>
+#endif
 
-#include <lustre_lite.h>
 #include <lustre_ha.h>
 #include <lustre_dlm.h>
 #include <lprocfs_status.h>
 #include <lustre_param.h>
 #include "llite_internal.h"
 
-cfs_mem_cache_t *ll_remote_perm_cachep = NULL;
-cfs_mem_cache_t *ll_rmtperm_hash_cachep = NULL;
+struct kmem_cache *ll_remote_perm_cachep;
+struct kmem_cache *ll_rmtperm_hash_cachep;
 
 static inline struct ll_remote_perm *alloc_ll_remote_perm(void)
 {
        struct ll_remote_perm *lrp;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lrp, ll_remote_perm_cachep, CFS_ALLOC_KERNEL);
+       OBD_SLAB_ALLOC_PTR_GFP(lrp, ll_remote_perm_cachep, GFP_KERNEL);
        if (lrp)
-               CFS_INIT_HLIST_NODE(&lrp->lrp_list);
+               INIT_HLIST_NODE(&lrp->lrp_list);
        return lrp;
 }
 
@@ -73,33 +76,34 @@ static inline void free_ll_remote_perm(struct ll_remote_perm *lrp)
         if (!lrp)
                 return;
 
-        if (!cfs_hlist_unhashed(&lrp->lrp_list))
-                cfs_hlist_del(&lrp->lrp_list);
+       if (!hlist_unhashed(&lrp->lrp_list))
+               hlist_del(&lrp->lrp_list);
         OBD_SLAB_FREE(lrp, ll_remote_perm_cachep, sizeof(*lrp));
 }
 
-cfs_hlist_head_t *alloc_rmtperm_hash(void)
+static struct hlist_head *alloc_rmtperm_hash(void)
 {
-        cfs_hlist_head_t *hash;
+       struct hlist_head *hash;
         int i;
 
        OBD_SLAB_ALLOC_GFP(hash, ll_rmtperm_hash_cachep,
                           REMOTE_PERM_HASHSIZE * sizeof(*hash),
-                          CFS_ALLOC_STD);
+                          GFP_IOFS);
         if (!hash)
                 return NULL;
 
         for (i = 0; i < REMOTE_PERM_HASHSIZE; i++)
-                CFS_INIT_HLIST_HEAD(hash + i);
+               INIT_HLIST_HEAD(hash + i);
 
         return hash;
 }
 
-void free_rmtperm_hash(cfs_hlist_head_t *hash)
+void free_rmtperm_hash(struct hlist_head *hash)
 {
-        int i;
-        struct ll_remote_perm *lrp;
-        cfs_hlist_node_t *node, *next;
+       int i;
+       struct ll_remote_perm *lrp;
+       struct hlist_node __maybe_unused *node;
+       struct hlist_node *next;
 
         if(!hash)
                 return;
@@ -121,30 +125,31 @@ static inline int remote_perm_hashfunc(uid_t uid)
  * MDT when client get remote permission. */
 static int do_check_remote_perm(struct ll_inode_info *lli, int mask)
 {
-        cfs_hlist_head_t *head;
-        struct ll_remote_perm *lrp;
-        cfs_hlist_node_t *node;
-        int found = 0, rc;
-        ENTRY;
+       struct hlist_head *head;
+       struct ll_remote_perm *lrp;
+       struct hlist_node __maybe_unused *node;
+       int found = 0, rc;
+       ENTRY;
 
-        if (!lli->lli_remote_perms)
-                RETURN(-ENOENT);
+       if (!lli->lli_remote_perms)
+               RETURN(-ENOENT);
 
-        head = lli->lli_remote_perms + remote_perm_hashfunc(cfs_curproc_uid());
+       head = lli->lli_remote_perms +
+               remote_perm_hashfunc(from_kuid(&init_user_ns, current_uid()));
 
        spin_lock(&lli->lli_lock);
-        cfs_hlist_for_each_entry(lrp, node, head, lrp_list) {
-                if (lrp->lrp_uid != cfs_curproc_uid())
-                        continue;
-                if (lrp->lrp_gid != cfs_curproc_gid())
-                        continue;
-                if (lrp->lrp_fsuid != cfs_curproc_fsuid())
-                        continue;
-                if (lrp->lrp_fsgid != cfs_curproc_fsgid())
-                        continue;
-                found = 1;
-                break;
-        }
+       cfs_hlist_for_each_entry(lrp, node, head, lrp_list) {
+               if (lrp->lrp_uid != from_kuid(&init_user_ns, current_uid()))
+                       continue;
+               if (lrp->lrp_gid != from_kgid(&init_user_ns, current_gid()))
+                       continue;
+               if (lrp->lrp_fsuid != from_kuid(&init_user_ns, current_fsuid()))
+                       continue;
+               if (lrp->lrp_fsgid != from_kgid(&init_user_ns, current_fsgid()))
+                       continue;
+               found = 1;
+               break;
+       }
 
         if (!found)
                 GOTO(out, rc = -ENOENT);
@@ -161,11 +166,11 @@ out:
 
 int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm)
 {
-        struct ll_inode_info *lli = ll_i2info(inode);
-        struct ll_remote_perm *lrp = NULL, *tmp = NULL;
-        cfs_hlist_head_t *head, *perm_hash = NULL;
-        cfs_hlist_node_t *node;
-        ENTRY;
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct ll_remote_perm *lrp = NULL, *tmp = NULL;
+       struct hlist_head *head, *perm_hash = NULL;
+       struct hlist_node __maybe_unused *node;
+       ENTRY;
 
         LASSERT(ll_i2sbi(inode)->ll_flags & LL_SBI_RMT_CLIENT);
 
@@ -234,7 +239,7 @@ again:
                 lrp->lrp_gid         = perm->rp_gid;
                 lrp->lrp_fsuid       = perm->rp_fsuid;
                 lrp->lrp_fsgid       = perm->rp_fsgid;
-                cfs_hlist_add_head(&lrp->lrp_list, head);
+               hlist_add_head(&lrp->lrp_list, head);
         }
         lli->lli_rmtperm_time = cfs_time_current();
        spin_unlock(&lli->lli_lock);
@@ -252,38 +257,35 @@ int lustre_check_remote_perm(struct inode *inode, int mask)
         struct ll_sb_info *sbi = ll_i2sbi(inode);
         struct ptlrpc_request *req = NULL;
         struct mdt_remote_perm *perm;
-        struct obd_capa *oc;
         cfs_time_t save;
         int i = 0, rc;
         ENTRY;
 
-        do {
-                save = lli->lli_rmtperm_time;
-                rc = do_check_remote_perm(lli, mask);
-                if (!rc || (rc != -ENOENT && i))
-                        break;
+       do {
+               save = lli->lli_rmtperm_time;
+               rc = do_check_remote_perm(lli, mask);
+               if (!rc || (rc != -ENOENT && i))
+                       break;
 
-                cfs_might_sleep();
+               might_sleep();
 
                mutex_lock(&lli->lli_rmtperm_mutex);
-                /* check again */
-                if (save != lli->lli_rmtperm_time) {
-                        rc = do_check_remote_perm(lli, mask);
-                        if (!rc || (rc != -ENOENT && i)) {
+               /* check again */
+               if (save != lli->lli_rmtperm_time) {
+                       rc = do_check_remote_perm(lli, mask);
+                       if (!rc || (rc != -ENOENT && i)) {
                                mutex_unlock(&lli->lli_rmtperm_mutex);
-                                break;
-                        }
-                }
+                               break;
+                       }
+               }
 
                 if (i++ > 5) {
                         CERROR("check remote perm falls in dead loop!\n");
                         LBUG();
                 }
 
-                oc = ll_mdscapa_get(inode);
-                rc = md_get_remote_perm(sbi->ll_md_exp, ll_inode2fid(inode), oc,
-                                        ll_i2suppgid(inode), &req);
-                capa_put(oc);
+               rc = md_get_remote_perm(sbi->ll_md_exp, ll_inode2fid(inode),
+                                       ll_i2suppgid(inode), &req);
                 if (rc) {
                        mutex_unlock(&lli->lli_rmtperm_mutex);
                         break;
@@ -308,28 +310,3 @@ int lustre_check_remote_perm(struct inode *inode, int mask)
         ptlrpc_req_finished(req);
         RETURN(rc);
 }
-
-#if 0  /* NB: remote perms can't be freed in ll_mdc_blocking_ast of UPDATE lock,
-        * because it will fail sanity test 48.
-        */
-void ll_free_remote_perms(struct inode *inode)
-{
-        struct ll_inode_info *lli = ll_i2info(inode);
-        cfs_hlist_head_t *hash = lli->lli_remote_perms;
-        struct ll_remote_perm *lrp;
-        cfs_hlist_node_t *node, *next;
-        int i;
-
-        LASSERT(hash);
-
-       spin_lock(&lli->lli_lock);
-
-       for (i = 0; i < REMOTE_PERM_HASHSIZE; i++) {
-               cfs_hlist_for_each_entry_safe(lrp, node, next, hash + i,
-                                             lrp_list)
-                       free_ll_remote_perm(lrp);
-       }
-
-       spin_unlock(&lli->lli_lock);
-}
-#endif