^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * V9FS cache definitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _9P_CACHE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _9P_CACHE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/fscache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) extern struct fscache_netfs v9fs_cache_netfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) extern const struct fscache_cookie_def v9fs_cache_session_index_def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) extern const struct fscache_cookie_def v9fs_cache_inode_index_def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) extern void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) extern void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) extern void v9fs_cache_inode_get_cookie(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) extern void v9fs_cache_inode_put_cookie(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) extern void v9fs_cache_inode_flush_cookie(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) extern void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) extern void v9fs_cache_inode_reset_cookie(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) extern int __v9fs_cache_register(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) extern void __v9fs_cache_unregister(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) extern void __v9fs_fscache_invalidate_page(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) extern int __v9fs_readpage_from_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) extern int __v9fs_readpages_from_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct list_head *pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned *nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) extern void __v9fs_fscache_wait_on_page_write(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static inline int v9fs_fscache_release_page(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return __v9fs_fscache_release_page(page, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static inline void v9fs_fscache_invalidate_page(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __v9fs_fscache_invalidate_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static inline int v9fs_readpage_from_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return __v9fs_readpage_from_fscache(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static inline int v9fs_readpages_from_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct list_head *pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned *nr_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return __v9fs_readpages_from_fscache(inode, mapping, pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static inline void v9fs_readpage_to_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (PageFsCache(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __v9fs_readpage_to_fscache(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) fscache_uncache_page(v9inode->fscache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) BUG_ON(PageFsCache(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return __v9fs_fscache_wait_on_page_write(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #else /* CONFIG_9P_FSCACHE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static inline void v9fs_cache_inode_get_cookie(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static inline void v9fs_cache_inode_put_cookie(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static inline void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static inline int v9fs_fscache_release_page(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) gfp_t gfp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static inline void v9fs_fscache_invalidate_page(struct page *page) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static inline int v9fs_readpage_from_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static inline int v9fs_readpages_from_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct list_head *pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) unsigned *nr_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static inline void v9fs_readpage_to_fscache(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #endif /* CONFIG_9P_FSCACHE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif /* _9P_CACHE_H */