Whamcloud - gitweb
LU-12275 sec: add llcrypt as file encryption library
[fs/lustre-release.git] / lustre / obdclass / upcall_cache.c
index 4d9ef1c..5622410 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -40,7 +36,7 @@
 #define DEBUG_SUBSYSTEM S_SEC
 
 #include <libcfs/libcfs.h>
-#include <lnet/types.h>
+#include <uapi/linux/lnet/lnet-types.h>
 #include <upcall_cache.h>
 
 static struct upcall_cache_entry *alloc_entry(struct upcall_cache *cache,
@@ -70,7 +66,7 @@ static void free_entry(struct upcall_cache *cache,
                cache->uc_ops->free_entry(cache, entry);
 
        list_del(&entry->ue_hash);
-       CDEBUG(D_OTHER, "destroy cache entry %p for key "LPU64"\n",
+       CDEBUG(D_OTHER, "destroy cache entry %p for key %llu\n",
                entry, entry->ue_key);
        LIBCFS_FREE(entry, sizeof(*entry));
 }
@@ -118,14 +114,14 @@ static inline void put_entry(struct upcall_cache *cache,
 static int check_unlink_entry(struct upcall_cache *cache,
                              struct upcall_cache_entry *entry)
 {
-       if (UC_CACHE_IS_VALID(entry) &&
-           cfs_time_before(cfs_time_current(), entry->ue_expire))
+       time64_t now = ktime_get_seconds();
+
+       if (UC_CACHE_IS_VALID(entry) && now < entry->ue_expire)
                return 0;
 
        if (UC_CACHE_IS_ACQUIRING(entry)) {
                if (entry->ue_acquire_expire == 0 ||
-                   cfs_time_before(cfs_time_current(),
-                                   entry->ue_acquire_expire))
+                   now < entry->ue_acquire_expire)
                        return 0;
 
                UC_CACHE_SET_EXPIRED(entry);
@@ -152,7 +148,7 @@ struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache,
 {
        struct upcall_cache_entry *entry = NULL, *new = NULL, *next;
        struct list_head *head;
-       wait_queue_t wait;
+       wait_queue_entry_t wait;
        int rc, found;
        ENTRY;
 
@@ -201,8 +197,8 @@ find_again:
                spin_unlock(&cache->uc_lock);
                rc = refresh_entry(cache, entry);
                spin_lock(&cache->uc_lock);
-               entry->ue_acquire_expire =
-                       cfs_time_shift(cache->uc_acquire_expire);
+               entry->ue_acquire_expire = ktime_get_seconds() +
+                                          cache->uc_acquire_expire;
                if (rc < 0) {
                        UC_CACHE_CLEAR_ACQUIRING(entry);
                        UC_CACHE_SET_INVALID(entry);
@@ -221,20 +217,19 @@ find_again:
                              MAX_SCHEDULE_TIMEOUT;
                long left;
 
-               init_waitqueue_entry_current(&wait);
+               init_waitqueue_entry(&wait, current);
                add_wait_queue(&entry->ue_waitq, &wait);
                set_current_state(TASK_INTERRUPTIBLE);
                spin_unlock(&cache->uc_lock);
 
-               left = waitq_timedwait(&wait, TASK_INTERRUPTIBLE,
-                                          expiry);
+               left = schedule_timeout(expiry);
 
                spin_lock(&cache->uc_lock);
                remove_wait_queue(&entry->ue_waitq, &wait);
                if (UC_CACHE_IS_ACQUIRING(entry)) {
                        /* we're interrupted or upcall failed in the middle */
                        rc = left > 0 ? -EINTR : -ETIMEDOUT;
-                       CERROR("acquire for key "LPU64": error %d\n",
+                       CERROR("acquire for key %llu: error %d\n",
                               entry->ue_key, rc);
                        put_entry(cache, entry);
                        GOTO(out, entry = ERR_PTR(rc));
@@ -312,7 +307,7 @@ int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
        }
 
        if (!found) {
-               CDEBUG(D_OTHER, "%s: upcall for key "LPU64" not expected\n",
+               CDEBUG(D_OTHER, "%s: upcall for key %llu not expected\n",
                       cache->uc_name, key);
                /* haven't found, it's possible */
                spin_unlock(&cache->uc_lock);
@@ -320,19 +315,19 @@ int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
        }
 
        if (err) {
-               CDEBUG(D_OTHER, "%s: upcall for key "LPU64" returned %d\n",
+               CDEBUG(D_OTHER, "%s: upcall for key %llu returned %d\n",
                       cache->uc_name, entry->ue_key, err);
                GOTO(out, rc = -EINVAL);
        }
 
        if (!UC_CACHE_IS_ACQUIRING(entry)) {
-               CDEBUG(D_RPCTRACE, "%s: found uptodate entry %p (key "LPU64")"
+               CDEBUG(D_RPCTRACE, "%s: found uptodate entry %p (key %llu)"
                       "\n", cache->uc_name, entry, entry->ue_key);
                GOTO(out, rc = 0);
        }
 
        if (UC_CACHE_IS_INVALID(entry) || UC_CACHE_IS_EXPIRED(entry)) {
-               CERROR("%s: found a stale entry %p (key "LPU64") in ioctl\n",
+               CERROR("%s: found a stale entry %p (key %llu) in ioctl\n",
                       cache->uc_name, entry, entry->ue_key);
                GOTO(out, rc = -EINVAL);
        }
@@ -344,9 +339,9 @@ int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key,
        if (rc)
                GOTO(out, rc);
 
-       entry->ue_expire = cfs_time_shift(cache->uc_entry_expire);
+       entry->ue_expire = ktime_get_seconds() + cache->uc_entry_expire;
        UC_CACHE_SET_VALID(entry);
-       CDEBUG(D_OTHER, "%s: created upcall cache entry %p for key "LPU64"\n",
+       CDEBUG(D_OTHER, "%s: created upcall cache entry %p for key %llu\n",
               cache->uc_name, entry, entry->ue_key);
 out:
        if (rc) {
@@ -403,11 +398,11 @@ void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args)
        }
 
        if (found) {
-               CWARN("%s: flush entry %p: key "LPU64", ref %d, fl %x, "
-                     "cur %lu, ex %ld/%ld\n",
+               CWARN("%s: flush entry %p: key %llu, ref %d, fl %x, "
+                     "cur %lld, ex %lld/%lld\n",
                      cache->uc_name, entry, entry->ue_key,
                      atomic_read(&entry->ue_refcount), entry->ue_flags,
-                     cfs_time_current_sec(), entry->ue_acquire_expire,
+                     ktime_get_real_seconds(), entry->ue_acquire_expire,
                      entry->ue_expire);
                UC_CACHE_SET_EXPIRED(entry);
                if (!atomic_read(&entry->ue_refcount))
@@ -429,7 +424,7 @@ struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
                RETURN(ERR_PTR(-ENOMEM));
 
        spin_lock_init(&cache->uc_lock);
-       rwlock_init(&cache->uc_upcall_rwlock);
+       init_rwsem(&cache->uc_upcall_rwsem);
        for (i = 0; i < UC_CACHE_HASH_SIZE; i++)
                INIT_LIST_HEAD(&cache->uc_hashtable[i]);
        strlcpy(cache->uc_name, name, sizeof(cache->uc_name));