Thomas Gleixner | 1f32761 | 2019-05-28 09:57:16 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Ceph cache definitions. |
| 4 | * |
| 5 | * Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved. |
| 6 | * Written by Milosz Tanski (milosz@adfin.com) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _CEPH_CACHE_H |
| 10 | #define _CEPH_CACHE_H |
| 11 | |
Jeff Layton | f070287 | 2020-06-01 10:10:21 -0400 | [diff] [blame] | 12 | #include <linux/netfs.h> |
| 13 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 14 | #ifdef CONFIG_CEPH_FSCACHE |
| 15 | |
Milosz Tanski | 971f0bd | 2013-09-06 15:13:18 +0000 | [diff] [blame] | 16 | extern struct fscache_netfs ceph_cache_netfs; |
| 17 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 18 | int ceph_fscache_register(void); |
| 19 | void ceph_fscache_unregister(void); |
| 20 | |
David Howells | 82995cc | 2019-03-25 16:38:32 +0000 | [diff] [blame] | 21 | int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 22 | void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc); |
| 23 | |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 24 | void ceph_fscache_register_inode_cookie(struct inode *inode); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 25 | void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci); |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 26 | void ceph_fscache_file_set_cookie(struct inode *inode, struct file *filp); |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 27 | void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 28 | |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 29 | static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci) |
| 30 | { |
| 31 | ci->fscache = NULL; |
Yan, Zheng | f7f7e7a | 2016-05-18 20:31:55 +0800 | [diff] [blame] | 32 | } |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 33 | |
Jeff Layton | f070287 | 2020-06-01 10:10:21 -0400 | [diff] [blame] | 34 | static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci) |
| 35 | { |
| 36 | return ci->fscache; |
| 37 | } |
| 38 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 39 | static inline void ceph_fscache_invalidate(struct inode *inode) |
| 40 | { |
| 41 | fscache_invalidate(ceph_inode(inode)->fscache); |
| 42 | } |
| 43 | |
Jeff Layton | f070287 | 2020-06-01 10:10:21 -0400 | [diff] [blame] | 44 | static inline bool ceph_is_cache_enabled(struct inode *inode) |
| 45 | { |
| 46 | struct fscache_cookie *cookie = ceph_fscache_cookie(ceph_inode(inode)); |
| 47 | |
| 48 | if (!cookie) |
| 49 | return false; |
| 50 | return fscache_cookie_enabled(cookie); |
| 51 | } |
| 52 | |
| 53 | static inline int ceph_begin_cache_operation(struct netfs_read_request *rreq) |
| 54 | { |
| 55 | struct fscache_cookie *cookie = ceph_fscache_cookie(ceph_inode(rreq->inode)); |
| 56 | |
| 57 | return fscache_begin_read_operation(rreq, cookie); |
| 58 | } |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 59 | #else |
| 60 | |
| 61 | static inline int ceph_fscache_register(void) |
| 62 | { |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static inline void ceph_fscache_unregister(void) |
| 67 | { |
| 68 | } |
| 69 | |
David Howells | 82995cc | 2019-03-25 16:38:32 +0000 | [diff] [blame] | 70 | static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc, |
| 71 | struct fs_context *fc) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci) |
| 81 | { |
| 82 | } |
| 83 | |
Jeff Layton | f070287 | 2020-06-01 10:10:21 -0400 | [diff] [blame] | 84 | static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci) |
| 85 | { |
| 86 | return NULL; |
| 87 | } |
| 88 | |
Yan, Zheng | 46b59b2 | 2016-05-18 15:25:03 +0800 | [diff] [blame] | 89 | static inline void ceph_fscache_register_inode_cookie(struct inode *inode) |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | static inline void ceph_fscache_file_set_cookie(struct inode *inode, |
| 98 | struct file *filp) |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 99 | { |
| 100 | } |
| 101 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 102 | static inline void ceph_fscache_invalidate(struct inode *inode) |
| 103 | { |
| 104 | } |
| 105 | |
Jeff Layton | f070287 | 2020-06-01 10:10:21 -0400 | [diff] [blame] | 106 | static inline bool ceph_is_cache_enabled(struct inode *inode) |
| 107 | { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | static inline int ceph_begin_cache_operation(struct netfs_read_request *rreq) |
| 112 | { |
| 113 | return -ENOBUFS; |
| 114 | } |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 115 | #endif |
| 116 | |
Jeff Layton | e7df452 | 2021-01-21 12:32:05 -0500 | [diff] [blame] | 117 | #endif /* _CEPH_CACHE_H */ |