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