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