Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 */
0002 /*
0003  *   CIFS filesystem cache interface definitions
0004  *
0005  *   Copyright (c) 2010 Novell, Inc.
0006  *   Authors(s): Suresh Jayaraman (sjayaraman@suse.de>
0007  *
0008  */
0009 #ifndef _CIFS_FSCACHE_H
0010 #define _CIFS_FSCACHE_H
0011 
0012 #include <linux/swap.h>
0013 #include <linux/fscache.h>
0014 
0015 #include "cifsglob.h"
0016 
0017 /*
0018  * Coherency data attached to CIFS volume within the cache
0019  */
0020 struct cifs_fscache_volume_coherency_data {
0021     __le64  resource_id;        /* unique server resource id */
0022     __le64  vol_create_time;
0023     __le32  vol_serial_number;
0024 } __packed;
0025 
0026 /*
0027  * Coherency data attached to CIFS inode within the cache.
0028  */
0029 struct cifs_fscache_inode_coherency_data {
0030     __le64 last_write_time_sec;
0031     __le64 last_change_time_sec;
0032     __le32 last_write_time_nsec;
0033     __le32 last_change_time_nsec;
0034 };
0035 
0036 #ifdef CONFIG_CIFS_FSCACHE
0037 
0038 /*
0039  * fscache.c
0040  */
0041 extern int cifs_fscache_get_super_cookie(struct cifs_tcon *);
0042 extern void cifs_fscache_release_super_cookie(struct cifs_tcon *);
0043 
0044 extern void cifs_fscache_get_inode_cookie(struct inode *inode);
0045 extern void cifs_fscache_release_inode_cookie(struct inode *);
0046 extern void cifs_fscache_unuse_inode_cookie(struct inode *inode, bool update);
0047 
0048 static inline
0049 void cifs_fscache_fill_coherency(struct inode *inode,
0050                  struct cifs_fscache_inode_coherency_data *cd)
0051 {
0052     struct cifsInodeInfo *cifsi = CIFS_I(inode);
0053 
0054     memset(cd, 0, sizeof(*cd));
0055     cd->last_write_time_sec   = cpu_to_le64(cifsi->netfs.inode.i_mtime.tv_sec);
0056     cd->last_write_time_nsec  = cpu_to_le32(cifsi->netfs.inode.i_mtime.tv_nsec);
0057     cd->last_change_time_sec  = cpu_to_le64(cifsi->netfs.inode.i_ctime.tv_sec);
0058     cd->last_change_time_nsec = cpu_to_le32(cifsi->netfs.inode.i_ctime.tv_nsec);
0059 }
0060 
0061 
0062 static inline struct fscache_cookie *cifs_inode_cookie(struct inode *inode)
0063 {
0064     return netfs_i_cookie(&CIFS_I(inode)->netfs);
0065 }
0066 
0067 static inline void cifs_invalidate_cache(struct inode *inode, unsigned int flags)
0068 {
0069     struct cifs_fscache_inode_coherency_data cd;
0070 
0071     cifs_fscache_fill_coherency(inode, &cd);
0072     fscache_invalidate(cifs_inode_cookie(inode), &cd,
0073                i_size_read(inode), flags);
0074 }
0075 
0076 extern int __cifs_fscache_query_occupancy(struct inode *inode,
0077                       pgoff_t first, unsigned int nr_pages,
0078                       pgoff_t *_data_first,
0079                       unsigned int *_data_nr_pages);
0080 
0081 static inline int cifs_fscache_query_occupancy(struct inode *inode,
0082                            pgoff_t first, unsigned int nr_pages,
0083                            pgoff_t *_data_first,
0084                            unsigned int *_data_nr_pages)
0085 {
0086     if (!cifs_inode_cookie(inode))
0087         return -ENOBUFS;
0088     return __cifs_fscache_query_occupancy(inode, first, nr_pages,
0089                           _data_first, _data_nr_pages);
0090 }
0091 
0092 extern int __cifs_readpage_from_fscache(struct inode *pinode, struct page *ppage);
0093 extern void __cifs_readpage_to_fscache(struct inode *pinode, struct page *ppage);
0094 
0095 
0096 static inline int cifs_readpage_from_fscache(struct inode *inode,
0097                          struct page *page)
0098 {
0099     if (cifs_inode_cookie(inode))
0100         return __cifs_readpage_from_fscache(inode, page);
0101     return -ENOBUFS;
0102 }
0103 
0104 static inline void cifs_readpage_to_fscache(struct inode *inode,
0105                         struct page *page)
0106 {
0107     if (cifs_inode_cookie(inode))
0108         __cifs_readpage_to_fscache(inode, page);
0109 }
0110 
0111 #else /* CONFIG_CIFS_FSCACHE */
0112 static inline
0113 void cifs_fscache_fill_coherency(struct inode *inode,
0114                  struct cifs_fscache_inode_coherency_data *cd)
0115 {
0116 }
0117 
0118 static inline int cifs_fscache_get_super_cookie(struct cifs_tcon *tcon) { return 0; }
0119 static inline void cifs_fscache_release_super_cookie(struct cifs_tcon *tcon) {}
0120 
0121 static inline void cifs_fscache_get_inode_cookie(struct inode *inode) {}
0122 static inline void cifs_fscache_release_inode_cookie(struct inode *inode) {}
0123 static inline void cifs_fscache_unuse_inode_cookie(struct inode *inode, bool update) {}
0124 static inline struct fscache_cookie *cifs_inode_cookie(struct inode *inode) { return NULL; }
0125 static inline void cifs_invalidate_cache(struct inode *inode, unsigned int flags) {}
0126 
0127 static inline int cifs_fscache_query_occupancy(struct inode *inode,
0128                            pgoff_t first, unsigned int nr_pages,
0129                            pgoff_t *_data_first,
0130                            unsigned int *_data_nr_pages)
0131 {
0132     *_data_first = ULONG_MAX;
0133     *_data_nr_pages = 0;
0134     return -ENOBUFS;
0135 }
0136 
0137 static inline int
0138 cifs_readpage_from_fscache(struct inode *inode, struct page *page)
0139 {
0140     return -ENOBUFS;
0141 }
0142 
0143 static inline
0144 void cifs_readpage_to_fscache(struct inode *inode, struct page *page) {}
0145 
0146 #endif /* CONFIG_CIFS_FSCACHE */
0147 
0148 #endif /* _CIFS_FSCACHE_H */