Whamcloud - gitweb
LU-4322 tests: disable sanity 101a in DNE
[fs/lustre-release.git] / lustre / fld / fld_cache.c
index 4d8b3a4..2254cd3 100644 (file)
 #ifdef __KERNEL__
 # include <libcfs/libcfs.h>
 # include <linux/module.h>
-# include <linux/jbd.h>
 # include <asm/div64.h>
 #else /* __KERNEL__ */
 # include <liblustre.h>
 # include <libcfs/list.h>
 #endif
 
-#include <obd.h>
-#include <obd_class.h>
-#include <lustre_ver.h>
 #include <obd_support.h>
-#include <lprocfs_status.h>
-
-#include <dt_object.h>
-#include <md_object.h>
-#include <lustre_req_layout.h>
 #include <lustre_fld.h>
 #include "fld_internal.h"
 
@@ -85,9 +76,9 @@ struct fld_cache *fld_cache_init(const char *name,
         CFS_INIT_LIST_HEAD(&cache->fci_lru);
 
         cache->fci_cache_count = 0;
-       spin_lock_init(&cache->fci_lock);
+       rwlock_init(&cache->fci_lock);
 
-        strncpy(cache->fci_name, name,
+       strlcpy(cache->fci_name, name,
                 sizeof(cache->fci_name));
 
         cache->fci_cache_size = cache_size;
@@ -263,10 +254,10 @@ void fld_cache_flush(struct fld_cache *cache)
 {
        ENTRY;
 
-       spin_lock(&cache->fci_lock);
+       write_lock(&cache->fci_lock);
        cache->fci_cache_size = 0;
        fld_cache_shrink(cache);
-       spin_unlock(&cache->fci_lock);
+       write_unlock(&cache->fci_lock);
 
        EXIT;
 }
@@ -276,9 +267,9 @@ void fld_cache_flush(struct fld_cache *cache)
  * entry accordingly.
  */
 
-void fld_cache_punch_hole(struct fld_cache *cache,
-                          struct fld_cache_entry *f_curr,
-                          struct fld_cache_entry *f_new)
+static void fld_cache_punch_hole(struct fld_cache *cache,
+                                struct fld_cache_entry *f_curr,
+                                struct fld_cache_entry *f_new)
 {
         const struct lu_seq_range *range = &f_new->fce_range;
         const seqno_t new_start  = range->lsr_start;
@@ -286,7 +277,7 @@ void fld_cache_punch_hole(struct fld_cache *cache,
         struct fld_cache_entry *fldt;
 
         ENTRY;
-        OBD_ALLOC_GFP(fldt, sizeof *fldt, CFS_ALLOC_ATOMIC);
+       OBD_ALLOC_GFP(fldt, sizeof *fldt, GFP_ATOMIC);
         if (!fldt) {
                 OBD_FREE_PTR(f_new);
                 EXIT;
@@ -412,8 +403,6 @@ int fld_cache_insert_nolock(struct fld_cache *cache,
        __u32 new_flags  = f_new->fce_range.lsr_flags;
        ENTRY;
 
-       LASSERT_SPIN_LOCKED(&cache->fci_lock);
-
        /*
         * Duplicate entries are eliminated in insert op.
         * So we don't need to search new entry before starting
@@ -461,9 +450,9 @@ int fld_cache_insert(struct fld_cache *cache,
        if (IS_ERR(flde))
                RETURN(PTR_ERR(flde));
 
-       spin_lock(&cache->fci_lock);
+       write_lock(&cache->fci_lock);
        rc = fld_cache_insert_nolock(cache, flde);
-       spin_unlock(&cache->fci_lock);
+       write_unlock(&cache->fci_lock);
        if (rc)
                OBD_FREE_PTR(flde);
 
@@ -477,7 +466,6 @@ void fld_cache_delete_nolock(struct fld_cache *cache,
        struct fld_cache_entry *tmp;
        cfs_list_t *head;
 
-       LASSERT_SPIN_LOCKED(&cache->fci_lock);
        head = &cache->fci_entries_head;
        cfs_list_for_each_entry_safe(flde, tmp, head, fce_list) {
                /* add list if next is end of list */
@@ -497,20 +485,19 @@ void fld_cache_delete_nolock(struct fld_cache *cache,
 void fld_cache_delete(struct fld_cache *cache,
                      const struct lu_seq_range *range)
 {
-       spin_lock(&cache->fci_lock);
+       write_lock(&cache->fci_lock);
        fld_cache_delete_nolock(cache, range);
-       spin_unlock(&cache->fci_lock);
+       write_unlock(&cache->fci_lock);
 }
 
-struct fld_cache_entry
-*fld_cache_entry_lookup_nolock(struct fld_cache *cache,
-                             struct lu_seq_range *range)
+struct fld_cache_entry *
+fld_cache_entry_lookup_nolock(struct fld_cache *cache,
+                             const struct lu_seq_range *range)
 {
        struct fld_cache_entry *flde;
        struct fld_cache_entry *got = NULL;
        cfs_list_t *head;
 
-       LASSERT_SPIN_LOCKED(&cache->fci_lock);
        head = &cache->fci_entries_head;
        cfs_list_for_each_entry(flde, head, fce_list) {
                if (range->lsr_start == flde->fce_range.lsr_start ||
@@ -527,15 +514,17 @@ struct fld_cache_entry
 /**
  * lookup \a seq sequence for range in fld cache.
  */
-struct fld_cache_entry
-*fld_cache_entry_lookup(struct fld_cache *cache, struct lu_seq_range *range)
+struct fld_cache_entry *
+fld_cache_entry_lookup(struct fld_cache *cache,
+                      const struct lu_seq_range *range)
 {
        struct fld_cache_entry *got = NULL;
        ENTRY;
 
-       spin_lock(&cache->fci_lock);
+       read_lock(&cache->fci_lock);
        got = fld_cache_entry_lookup_nolock(cache, range);
-       spin_unlock(&cache->fci_lock);
+       read_unlock(&cache->fci_lock);
+
        RETURN(got);
 }
 
@@ -550,14 +539,14 @@ int fld_cache_lookup(struct fld_cache *cache,
        cfs_list_t *head;
        ENTRY;
 
-       spin_lock(&cache->fci_lock);
+       read_lock(&cache->fci_lock);
        head = &cache->fci_entries_head;
 
        cache->fci_stat.fst_count++;
        cfs_list_for_each_entry(flde, head, fce_list) {
                if (flde->fce_range.lsr_start > seq) {
                        if (prev != NULL)
-                               memcpy(range, prev, sizeof(*range));
+                               *range = prev->fce_range;
                        break;
                }
 
@@ -565,14 +554,11 @@ int fld_cache_lookup(struct fld_cache *cache,
                 if (range_within(&flde->fce_range, seq)) {
                         *range = flde->fce_range;
 
-                        /* update position of this entry in lru list. */
-                        cfs_list_move(&flde->fce_lru, &cache->fci_lru);
                         cache->fci_stat.fst_cache++;
-                       spin_unlock(&cache->fci_lock);
+                       read_unlock(&cache->fci_lock);
                        RETURN(0);
                }
        }
-       spin_unlock(&cache->fci_lock);
+       read_unlock(&cache->fci_lock);
        RETURN(-ENOENT);
 }
-