*
* 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
*/
*/
void fld_cache_fini(struct fld_cache *cache)
{
- __u64 pct;
- ENTRY;
+ LASSERT(cache != NULL);
+ fld_cache_flush(cache);
- LASSERT(cache != NULL);
- fld_cache_flush(cache);
-
- if (cache->fci_stat.fst_count > 0) {
- pct = cache->fci_stat.fst_cache * 100;
- do_div(pct, cache->fci_stat.fst_count);
- } else {
- pct = 0;
- }
-
- CDEBUG(D_INFO, "FLD cache statistics (%s):\n", cache->fci_name);
- CDEBUG(D_INFO, " Total reqs: %llu\n", cache->fci_stat.fst_count);
+ CDEBUG(D_INFO, "FLD cache statistics (%s):\n", cache->fci_name);
CDEBUG(D_INFO, " Cache reqs: %llu\n", cache->fci_stat.fst_cache);
- CDEBUG(D_INFO, " Cache hits: %llu%%\n", pct);
-
- OBD_FREE_PTR(cache);
+ CDEBUG(D_INFO, " Total reqs: %llu\n", cache->fci_stat.fst_count);
- EXIT;
+ OBD_FREE_PTR(cache);
}
/**
* delete given node from list.
*/
-void fld_cache_entry_delete(struct fld_cache *cache,
- struct fld_cache_entry *node)
+static void fld_cache_entry_delete(struct fld_cache *cache,
+ struct fld_cache_entry *node)
{
list_del(&node->fce_list);
list_del(&node->fce_lru);
*/
static int fld_cache_shrink(struct fld_cache *cache)
{
- struct fld_cache_entry *flde;
- struct list_head *curr;
- int num = 0;
- ENTRY;
+ int num = 0;
- LASSERT(cache != NULL);
+ ENTRY;
- if (cache->fci_cache_count < cache->fci_cache_size)
- RETURN(0);
+ LASSERT(cache != NULL);
- curr = cache->fci_lru.prev;
+ if (cache->fci_cache_count < cache->fci_cache_size)
+ RETURN(0);
- while (cache->fci_cache_count + cache->fci_threshold >
- cache->fci_cache_size && curr != &cache->fci_lru) {
+ while (cache->fci_cache_count + cache->fci_threshold >
+ cache->fci_cache_size &&
+ !list_empty(&cache->fci_lru)) {
+ struct fld_cache_entry *flde =
+ list_last_entry(&cache->fci_lru, struct fld_cache_entry,
+ fce_lru);
- flde = list_entry(curr, struct fld_cache_entry, fce_lru);
- curr = curr->prev;
- fld_cache_entry_delete(cache, flde);
- num++;
- }
+ fld_cache_entry_delete(cache, flde);
+ num++;
+ }
- CDEBUG(D_INFO, "%s: FLD cache - Shrunk by "
- "%d entries\n", cache->fci_name, num);
+ CDEBUG(D_INFO, "%s: FLD cache - Shrunk by "
+ "%d entries\n", cache->fci_name, num);
- RETURN(0);
+ RETURN(0);
}
/**
* insertion loop.
*/
- if (!cache->fci_no_shrink)
- fld_cache_shrink(cache);
+ fld_cache_shrink(cache);
head = &cache->fci_entries_head;
}
/**
- * Delete FLD entry in FLD cache.
- *
- */
-void fld_cache_delete(struct fld_cache *cache,
- const struct lu_seq_range *range)
-{
- write_lock(&cache->fci_lock);
- fld_cache_delete_nolock(cache, range);
- write_unlock(&cache->fci_lock);
-}
-
-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;
- struct list_head *head;
-
- head = &cache->fci_entries_head;
- list_for_each_entry(flde, head, fce_list) {
- if (range->lsr_start == flde->fce_range.lsr_start ||
- (range->lsr_end == flde->fce_range.lsr_end &&
- range->lsr_flags == flde->fce_range.lsr_flags)) {
- got = flde;
- break;
- }
- }
-
- RETURN(got);
-}
-
-/**
- * lookup \a seq sequence for range in fld cache.
- */
-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;
-
- read_lock(&cache->fci_lock);
- got = fld_cache_entry_lookup_nolock(cache, range);
- read_unlock(&cache->fci_lock);
-
- RETURN(got);
-}
-
-/**
* lookup \a seq sequence for range in fld cache.
*/
int fld_cache_lookup(struct fld_cache *cache,