cleancache.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /*
  28. * NOTE: per akpm, flush_page, flush_inode and flush_fs will be
  29. * renamed to invalidate_* in a later commit in which all
  30. * dependencies (i.e Xen, zcache) will be renamed simultaneously
  31. */
  32. void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
  33. void (*flush_inode)(int, struct cleancache_filekey);
  34. void (*flush_fs)(int);
  35. };
  36. extern struct cleancache_ops
  37. cleancache_register_ops(struct cleancache_ops *ops);
  38. extern void __cleancache_init_fs(struct super_block *);
  39. extern void __cleancache_init_shared_fs(char *, struct super_block *);
  40. extern int __cleancache_get_page(struct page *);
  41. extern void __cleancache_put_page(struct page *);
  42. extern void __cleancache_invalidate_page(struct address_space *, struct page *);
  43. extern void __cleancache_invalidate_inode(struct address_space *);
  44. extern void __cleancache_invalidate_fs(struct super_block *);
  45. extern int cleancache_enabled;
  46. #ifdef CONFIG_CLEANCACHE
  47. static inline bool cleancache_fs_enabled(struct page *page)
  48. {
  49. return page->mapping->host->i_sb->cleancache_poolid >= 0;
  50. }
  51. static inline bool cleancache_fs_enabled_mapping(struct address_space *mapping)
  52. {
  53. return mapping->host->i_sb->cleancache_poolid >= 0;
  54. }
  55. #else
  56. #define cleancache_enabled (0)
  57. #define cleancache_fs_enabled(_page) (0)
  58. #define cleancache_fs_enabled_mapping(_page) (0)
  59. #endif
  60. /*
  61. * The shim layer provided by these inline functions allows the compiler
  62. * to reduce all cleancache hooks to nothingness if CONFIG_CLEANCACHE
  63. * is disabled, to a single global variable check if CONFIG_CLEANCACHE
  64. * is enabled but no cleancache "backend" has dynamically enabled it,
  65. * and, for the most frequent cleancache ops, to a single global variable
  66. * check plus a superblock element comparison if CONFIG_CLEANCACHE is enabled
  67. * and a cleancache backend has dynamically enabled cleancache, but the
  68. * filesystem referenced by that cleancache op has not enabled cleancache.
  69. * As a result, CONFIG_CLEANCACHE can be enabled by default with essentially
  70. * no measurable performance impact.
  71. */
  72. static inline void cleancache_init_fs(struct super_block *sb)
  73. {
  74. if (cleancache_enabled)
  75. __cleancache_init_fs(sb);
  76. }
  77. static inline void cleancache_init_shared_fs(char *uuid, struct super_block *sb)
  78. {
  79. if (cleancache_enabled)
  80. __cleancache_init_shared_fs(uuid, sb);
  81. }
  82. static inline int cleancache_get_page(struct page *page)
  83. {
  84. int ret = -1;
  85. if (cleancache_enabled && cleancache_fs_enabled(page))
  86. ret = __cleancache_get_page(page);
  87. return ret;
  88. }
  89. static inline void cleancache_put_page(struct page *page)
  90. {
  91. if (cleancache_enabled && cleancache_fs_enabled(page))
  92. __cleancache_put_page(page);
  93. }
  94. static inline void cleancache_invalidate_page(struct address_space *mapping,
  95. struct page *page)
  96. {
  97. /* careful... page->mapping is NULL sometimes when this is called */
  98. if (cleancache_enabled && cleancache_fs_enabled_mapping(mapping))
  99. __cleancache_invalidate_page(mapping, page);
  100. }
  101. static inline void cleancache_invalidate_inode(struct address_space *mapping)
  102. {
  103. if (cleancache_enabled && cleancache_fs_enabled_mapping(mapping))
  104. __cleancache_invalidate_inode(mapping);
  105. }
  106. static inline void cleancache_invalidate_fs(struct super_block *sb)
  107. {
  108. if (cleancache_enabled)
  109. __cleancache_invalidate_fs(sb);
  110. }
  111. #endif /* _LINUX_CLEANCACHE_H */