nfsd: abstract out the get and set routines into the fault injection ops
[firefly-linux-kernel-4.4.55.git] / fs / nfsd / nfscache.c
index f8f060ffbf4f173888db46dc0c000ce8c1ea34c6..ff9567633245995579be4403f7189de5a7ab2321 100644 (file)
@@ -221,14 +221,12 @@ static void
 hash_refile(struct svc_cacherep *rp)
 {
        hlist_del_init(&rp->c_hash);
-       hlist_add_head(&rp->c_hash, cache_hash + hash_32(rp->c_xid, maskbits));
-}
-
-static inline bool
-nfsd_cache_entry_expired(struct svc_cacherep *rp)
-{
-       return rp->c_state != RC_INPROG &&
-              time_after(jiffies, rp->c_timestamp + RC_EXPIRE);
+       /*
+        * No point in byte swapping c_xid since we're just using it to pick
+        * a hash bucket.
+        */
+       hlist_add_head(&rp->c_hash, cache_hash +
+                       hash_32((__force u32)rp->c_xid, maskbits));
 }
 
 /*
@@ -242,8 +240,14 @@ prune_cache_entries(void)
        long freed = 0;
 
        list_for_each_entry_safe(rp, tmp, &lru_head, c_lru) {
-               if (!nfsd_cache_entry_expired(rp) &&
-                   num_drc_entries <= max_drc_entries)
+               /*
+                * Don't free entries attached to calls that are still
+                * in-progress, but do keep scanning the list.
+                */
+               if (rp->c_state == RC_INPROG)
+                       continue;
+               if (num_drc_entries <= max_drc_entries &&
+                   time_before(jiffies, rp->c_timestamp + RC_EXPIRE))
                        break;
                nfsd_reply_cache_free_locked(rp);
                freed++;
@@ -357,7 +361,11 @@ nfsd_cache_search(struct svc_rqst *rqstp, __wsum csum)
        struct hlist_head       *rh;
        unsigned int            entries = 0;
 
-       rh = &cache_hash[hash_32(rqstp->rq_xid, maskbits)];
+       /*
+        * No point in byte swapping rq_xid since we're just using it to pick
+        * a hash bucket.
+        */
+       rh = &cache_hash[hash_32((__force u32)rqstp->rq_xid, maskbits)];
        hlist_for_each_entry(rp, rh, c_hash) {
                ++entries;
                if (nfsd_cache_match(rqstp, csum, rp)) {