Whamcloud - gitweb
LU-1877 mdt: initialize lock and expiration
[fs/lustre-release.git] / lustre / llite / remote_perm.c
index 9d26e87..37471ae 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -45,7 +45,6 @@
 
 #include <linux/module.h>
 #include <linux/types.h>
-#include <linux/random.h>
 #include <linux/version.h>
 
 #include <lustre_lite.h>
@@ -61,12 +60,12 @@ cfs_mem_cache_t *ll_rmtperm_hash_cachep = NULL;
 
 static inline struct ll_remote_perm *alloc_ll_remote_perm(void)
 {
-        struct ll_remote_perm *lrp;
+       struct ll_remote_perm *lrp;
 
-        OBD_SLAB_ALLOC_PTR_GFP(lrp, ll_remote_perm_cachep, GFP_KERNEL);
-        if (lrp)
-                CFS_INIT_HLIST_NODE(&lrp->lrp_list);
-        return lrp;
+       OBD_SLAB_ALLOC_PTR_GFP(lrp, ll_remote_perm_cachep, CFS_ALLOC_KERNEL);
+       if (lrp)
+               CFS_INIT_HLIST_NODE(&lrp->lrp_list);
+       return lrp;
 }
 
 static inline void free_ll_remote_perm(struct ll_remote_perm *lrp)
@@ -84,9 +83,9 @@ cfs_hlist_head_t *alloc_rmtperm_hash(void)
         cfs_hlist_head_t *hash;
         int i;
 
-        OBD_SLAB_ALLOC(hash, ll_rmtperm_hash_cachep, GFP_KERNEL,
-                       REMOTE_PERM_HASHSIZE * sizeof(*hash));
-
+       OBD_SLAB_ALLOC_GFP(hash, ll_rmtperm_hash_cachep,
+                          REMOTE_PERM_HASHSIZE * sizeof(*hash),
+                          CFS_ALLOC_STD);
         if (!hash)
                 return NULL;
 
@@ -131,17 +130,17 @@ static int do_check_remote_perm(struct ll_inode_info *lli, int mask)
         if (!lli->lli_remote_perms)
                 RETURN(-ENOENT);
 
-        head = lli->lli_remote_perms + remote_perm_hashfunc(current->uid);
+        head = lli->lli_remote_perms + remote_perm_hashfunc(cfs_curproc_uid());
 
         cfs_spin_lock(&lli->lli_lock);
         cfs_hlist_for_each_entry(lrp, node, head, lrp_list) {
-                if (lrp->lrp_uid != current->uid)
+                if (lrp->lrp_uid != cfs_curproc_uid())
                         continue;
-                if (lrp->lrp_gid != current->gid)
+                if (lrp->lrp_gid != cfs_curproc_gid())
                         continue;
-                if (lrp->lrp_fsuid != current->fsuid)
+                if (lrp->lrp_fsuid != cfs_curproc_fsuid())
                         continue;
-                if (lrp->lrp_fsgid != current->fsgid)
+                if (lrp->lrp_fsgid != cfs_curproc_fsgid())
                         continue;
                 found = 1;
                 break;
@@ -237,7 +236,7 @@ again:
                 lrp->lrp_fsgid       = perm->rp_fsgid;
                 cfs_hlist_add_head(&lrp->lrp_list, head);
         }
-        lli->lli_rmtperm_utime = jiffies;
+        lli->lli_rmtperm_time = cfs_time_current();
         cfs_spin_unlock(&lli->lli_lock);
 
         CDEBUG(D_SEC, "new remote perm@%p: %u/%u/%u/%u - %#x\n",
@@ -254,24 +253,24 @@ int lustre_check_remote_perm(struct inode *inode, int mask)
         struct ptlrpc_request *req = NULL;
         struct mdt_remote_perm *perm;
         struct obd_capa *oc;
-        unsigned long utime;
+        cfs_time_t save;
         int i = 0, rc;
         ENTRY;
 
         do {
-                utime = lli->lli_rmtperm_utime;
+                save = lli->lli_rmtperm_time;
                 rc = do_check_remote_perm(lli, mask);
                 if (!rc || (rc != -ENOENT && i))
                         break;
 
                 cfs_might_sleep();
 
-                cfs_down(&lli->lli_rmtperm_sem);
+                cfs_mutex_lock(&lli->lli_rmtperm_mutex);
                 /* check again */
-                if (utime != lli->lli_rmtperm_utime) {
+                if (save != lli->lli_rmtperm_time) {
                         rc = do_check_remote_perm(lli, mask);
                         if (!rc || (rc != -ENOENT && i)) {
-                                cfs_up(&lli->lli_rmtperm_sem);
+                                cfs_mutex_unlock(&lli->lli_rmtperm_mutex);
                                 break;
                         }
                 }
@@ -286,20 +285,20 @@ int lustre_check_remote_perm(struct inode *inode, int mask)
                                         ll_i2suppgid(inode), &req);
                 capa_put(oc);
                 if (rc) {
-                        cfs_up(&lli->lli_rmtperm_sem);
+                        cfs_mutex_unlock(&lli->lli_rmtperm_mutex);
                         break;
                 }
 
                 perm = req_capsule_server_swab_get(&req->rq_pill, &RMF_ACL,
                                                    lustre_swab_mdt_remote_perm);
                 if (unlikely(perm == NULL)) {
-                        cfs_up(&lli->lli_rmtperm_sem);
+                        cfs_mutex_unlock(&lli->lli_rmtperm_mutex);
                         rc = -EPROTO;
                         break;
                 }
 
                 rc = ll_update_remote_perm(inode, perm);
-                cfs_up(&lli->lli_rmtperm_sem);
+                cfs_mutex_unlock(&lli->lli_rmtperm_mutex);
                 if (rc == -ENOMEM)
                         break;