cleancache.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef _LINUX_CLEANCACHE_H
  2. #define _LINUX_CLEANCACHE_H
  3. #include <linux/fs.h>
  4. #include <linux/exportfs.h>
  5. #include <linux/mm.h>
  6. #define CLEANCACHE_NO_POOL -1
  7. #define CLEANCACHE_NO_BACKEND -2
  8. #define CLEANCACHE_NO_BACKEND_SHARED -3
  9. #define CLEANCACHE_KEY_MAX 6
  10. /*
  11. * cleancache requires every file with a page in cleancache to have a
  12. * unique key unless/until the file is removed/truncated. For some
  13. * filesystems, the inode number is unique, but for "modern" filesystems
  14. * an exportable filehandle is required (see exportfs.h)
  15. */
  16. struct cleancache_filekey {
  17. union {
  18. ino_t ino;
  19. __u32 fh[CLEANCACHE_KEY_MAX];
  20. u32 key[CLEANCACHE_KEY_MAX];
  21. } u;
  22. };
  23. struct cleancache_ops {
  24. int (*init_fs)(size_t);
  25. int (*init_shared_fs)(char *uuid, size_t);
  26. int (*get_page)(int, struct cleancache_filekey,
  27. pgoff_t, struct page *);
  28. void (*put_page)(int, struct cleancache_filekey,
  29. pgoff_t, struct page *);
  30. void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
  31. void (*invalidate_inode)(int, struct cleancache_filekey);
  32. void (*invalidate_fs)(int);
  33. };
  34. extern int cleancache_register_ops(const struct cleancache_ops *ops);
  35. extern void __cleancache_init_fs(struct super_block *);
  36. extern void __cleancache_init_shared_fs(struct super_block *);
  37. extern int __cleancache_get_page(struct page *);
  38. extern void __cleancache_put_page(struct page *);
  39. extern void __cleancache_invalidate_page(struct address_space *, struct page *);
  40. extern void __cleancache_invalidate_inode(struct address_space *);
  41. extern void __cleancache_invalidate_fs(struct super_block *);
  42. #ifdef CONFIG_CLEANCACHE
  43. #define cleancache_enabled (1)
  44. static inline bool cleancache_fs_enabled_mapping(struct address_space *mapping)
  45. {
  46. return mapping->host->i_sb->cleancache_poolid >= 0;
  47. }
  48. static inline bool cleancache_fs_enabled(struct page *page)
  49. {
  50. return cleancache_fs_enabled_mapping(page->mapping);
  51. }
  52. #else
  53. #define cleancache_enabled (0)
  54. #define cleancache_fs_enabled(_page) (0)
  55. #define cleancache_fs_enabled_mapping(_page) (0)
  56. #endif
  57. /*
  58. * The shim layer provided by these inline functions allows the compiler
  59. * to reduce all cleancache hooks to nothingness if CONFIG_CLEANCACHE
  60. * is disabled, to a single global variable check if CONFIG_CLEANCACHE
  61. * is enabled but no cleancache "backend" has dynamically enabled it,
  62. * and, for the most frequent cleancache ops, to a single global variable
  63. * check plus a superblock element comparison if CONFIG_CLEANCACHE is enabled
  64. * and a cleancache backend has dynamically enabled cleancache, but the
  65. * filesystem referenced by that cleancache op has not enabled cleancache.
  66. * As a result, CONFIG_CLEANCACHE can be enabled by default with essentially
  67. * no measurable performance impact.
  68. */
  69. static inline void cleancache_init_fs(struct super_block *sb)
  70. {
  71. if (cleancache_enabled)
  72. __cleancache_init_fs(sb);
  73. }
  74. static inline void cleancache_init_shared_fs(struct super_block *sb)
  75. {
  76. if (cleancache_enabled)
  77. __cleancache_init_shared_fs(sb);
  78. }
  79. static inline int cleancache_get_page(struct page *page)
  80. {
  81. if (cleancache_enabled && cleancache_fs_enabled(page))
  82. return __cleancache_get_page(page);
  83. return -1;
  84. }
  85. static inline void cleancache_put_page(struct page *page)
  86. {
  87. if (cleancache_enabled && cleancache_fs_enabled(page))
  88. __cleancache_put_page(page);
  89. }
  90. static inline void cleancache_invalidate_page(struct address_space *mapping,
  91. struct page *page)
  92. {
  93. /* careful... page->mapping is NULL sometimes when this is called */
  94. if (cleancache_enabled && cleancache_fs_enabled_mapping(mapping))
  95. __cleancache_invalidate_page(mapping, page);
  96. }
  97. static inline void cleancache_invalidate_inode(struct address_space *mapping)
  98. {
  99. if (cleancache_enabled && cleancache_fs_enabled_mapping(mapping))
  100. __cleancache_invalidate_inode(mapping);
  101. }
  102. static inline void cleancache_invalidate_fs(struct super_block *sb)
  103. {
  104. if (cleancache_enabled)
  105. __cleancache_invalidate_fs(sb);
  106. }
  107. #endif /* _LINUX_CLEANCACHE_H */