mbcache.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef _LINUX_MBCACHE_H
  2. #define _LINUX_MBCACHE_H
  3. #include <linux/hash.h>
  4. #include <linux/list_bl.h>
  5. #include <linux/list.h>
  6. #include <linux/atomic.h>
  7. #include <linux/fs.h>
  8. struct mb_cache;
  9. struct mb_cache_entry {
  10. /* List of entries in cache - protected by cache->c_list_lock */
  11. struct list_head e_list;
  12. /* Hash table list - protected by hash chain bitlock */
  13. struct hlist_bl_node e_hash_list;
  14. atomic_t e_refcnt;
  15. /* Key in hash - stable during lifetime of the entry */
  16. u32 e_key;
  17. u32 e_referenced:1;
  18. u32 e_reusable:1;
  19. /* Block number of hashed block - stable during lifetime of the entry */
  20. sector_t e_block;
  21. };
  22. struct mb_cache *mb_cache_create(int bucket_bits);
  23. void mb_cache_destroy(struct mb_cache *cache);
  24. int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
  25. sector_t block, bool reusable);
  26. void __mb_cache_entry_free(struct mb_cache_entry *entry);
  27. static inline int mb_cache_entry_put(struct mb_cache *cache,
  28. struct mb_cache_entry *entry)
  29. {
  30. if (!atomic_dec_and_test(&entry->e_refcnt))
  31. return 0;
  32. __mb_cache_entry_free(entry);
  33. return 1;
  34. }
  35. void mb_cache_entry_delete_block(struct mb_cache *cache, u32 key,
  36. sector_t block);
  37. struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key,
  38. sector_t block);
  39. struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache,
  40. u32 key);
  41. struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,
  42. struct mb_cache_entry *entry);
  43. void mb_cache_entry_touch(struct mb_cache *cache,
  44. struct mb_cache_entry *entry);
  45. #endif /* _LINUX_MBCACHE_H */