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