blob: b23611f43cfb318ff409ab43c900eb6062fe623d [file] [log] [blame]
Dan Magenheimer077b1f82011-05-26 10:01:36 -06001#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 */
16struct cleancache_filekey {
17 union {
18 ino_t ino;
19 __u32 fh[CLEANCACHE_KEY_MAX];
20 u32 key[CLEANCACHE_KEY_MAX];
21 } u;
22};
23
24struct 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 Magenheimer91c6cc92012-01-12 14:03:25 -050031 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
32 void (*invalidate_inode)(int, struct cleancache_filekey);
33 void (*invalidate_fs)(int);
Dan Magenheimer077b1f82011-05-26 10:01:36 -060034};
35
Vladimir Davydov53d85c92015-04-14 15:46:45 -070036extern int cleancache_register_ops(struct cleancache_ops *ops);
Dan Magenheimer077b1f82011-05-26 10:01:36 -060037extern void __cleancache_init_fs(struct super_block *);
Vladimir Davydov9de16262015-04-14 15:46:42 -070038extern void __cleancache_init_shared_fs(struct super_block *);
Dan Magenheimer077b1f82011-05-26 10:01:36 -060039extern int __cleancache_get_page(struct page *);
40extern void __cleancache_put_page(struct page *);
Dan Magenheimer31677602011-09-21 11:56:28 -040041extern void __cleancache_invalidate_page(struct address_space *, struct page *);
42extern void __cleancache_invalidate_inode(struct address_space *);
43extern void __cleancache_invalidate_fs(struct super_block *);
Dan Magenheimer077b1f82011-05-26 10:01:36 -060044
45#ifdef CONFIG_CLEANCACHE
Bob Liuff610a12013-04-30 15:26:58 -070046#define cleancache_enabled (1)
Dan Magenheimer077b1f82011-05-26 10:01:36 -060047static inline bool cleancache_fs_enabled(struct page *page)
48{
49 return page->mapping->host->i_sb->cleancache_poolid >= 0;
50}
51static 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/*
62 * The shim layer provided by these inline functions allows the compiler
63 * to reduce all cleancache hooks to nothingness if CONFIG_CLEANCACHE
64 * is disabled, to a single global variable check if CONFIG_CLEANCACHE
65 * is enabled but no cleancache "backend" has dynamically enabled it,
66 * and, for the most frequent cleancache ops, to a single global variable
67 * check plus a superblock element comparison if CONFIG_CLEANCACHE is enabled
68 * and a cleancache backend has dynamically enabled cleancache, but the
69 * filesystem referenced by that cleancache op has not enabled cleancache.
70 * As a result, CONFIG_CLEANCACHE can be enabled by default with essentially
71 * no measurable performance impact.
72 */
73
74static inline void cleancache_init_fs(struct super_block *sb)
75{
76 if (cleancache_enabled)
77 __cleancache_init_fs(sb);
78}
79
Vladimir Davydov9de16262015-04-14 15:46:42 -070080static inline void cleancache_init_shared_fs(struct super_block *sb)
Dan Magenheimer077b1f82011-05-26 10:01:36 -060081{
82 if (cleancache_enabled)
Vladimir Davydov9de16262015-04-14 15:46:42 -070083 __cleancache_init_shared_fs(sb);
Dan Magenheimer077b1f82011-05-26 10:01:36 -060084}
85
86static inline int cleancache_get_page(struct page *page)
87{
88 int ret = -1;
89
90 if (cleancache_enabled && cleancache_fs_enabled(page))
91 ret = __cleancache_get_page(page);
92 return ret;
93}
94
95static inline void cleancache_put_page(struct page *page)
96{
97 if (cleancache_enabled && cleancache_fs_enabled(page))
98 __cleancache_put_page(page);
99}
100
Dan Magenheimer31677602011-09-21 11:56:28 -0400101static inline void cleancache_invalidate_page(struct address_space *mapping,
Dan Magenheimer077b1f82011-05-26 10:01:36 -0600102 struct page *page)
103{
104 /* careful... page->mapping is NULL sometimes when this is called */
105 if (cleancache_enabled && cleancache_fs_enabled_mapping(mapping))
Dan Magenheimer31677602011-09-21 11:56:28 -0400106 __cleancache_invalidate_page(mapping, page);
Dan Magenheimer077b1f82011-05-26 10:01:36 -0600107}
108
Dan Magenheimer31677602011-09-21 11:56:28 -0400109static inline void cleancache_invalidate_inode(struct address_space *mapping)
Dan Magenheimer077b1f82011-05-26 10:01:36 -0600110{
111 if (cleancache_enabled && cleancache_fs_enabled_mapping(mapping))
Dan Magenheimer31677602011-09-21 11:56:28 -0400112 __cleancache_invalidate_inode(mapping);
Dan Magenheimer077b1f82011-05-26 10:01:36 -0600113}
114
Dan Magenheimer31677602011-09-21 11:56:28 -0400115static inline void cleancache_invalidate_fs(struct super_block *sb)
Dan Magenheimer077b1f82011-05-26 10:01:36 -0600116{
117 if (cleancache_enabled)
Dan Magenheimer31677602011-09-21 11:56:28 -0400118 __cleancache_invalidate_fs(sb);
Dan Magenheimer077b1f82011-05-26 10:01:36 -0600119}
120
121#endif /* _LINUX_CLEANCACHE_H */