1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Request reply cache. This was heavily inspired by the 4 * implementation in 4.3BSD/4.4BSD. 5 * 6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> 7 */ 8 9 #ifndef NFSCACHE_H 10 #define NFSCACHE_H 11 12 #include <linux/sunrpc/svc.h> 13 14 /* 15 * Representation of a reply cache entry. 16 * 17 * Note that we use a sockaddr_in6 to hold the address instead of the more 18 * typical sockaddr_storage. This is for space reasons, since sockaddr_storage 19 * is much larger than a sockaddr_in6. 20 */ 21 struct svc_cacherep { 22 struct { 23 /* Keep often-read xid, csum in the same cache line: */ 24 __be32 k_xid; 25 __wsum k_csum; 26 u32 k_proc; 27 u32 k_prot; 28 u32 k_vers; 29 unsigned int k_len; 30 struct sockaddr_in6 k_addr; 31 } c_key; 32 33 struct rb_node c_node; 34 struct list_head c_lru; 35 unsigned char c_state, /* unused, inprog, done */ 36 c_type, /* status, buffer */ 37 c_secure : 1; /* req came from port < 1024 */ 38 unsigned long c_timestamp; 39 union { 40 struct kvec u_vec; 41 __be32 u_status; 42 } c_u; 43 }; 44 45 #define c_replvec c_u.u_vec 46 #define c_replstat c_u.u_status 47 48 /* cache entry states */ 49 enum { 50 RC_UNUSED, 51 RC_INPROG, 52 RC_DONE 53 }; 54 55 /* return values */ 56 enum { 57 RC_DROPIT, 58 RC_REPLY, 59 RC_DOIT 60 }; 61 62 /* 63 * Cache types. 64 * We may want to add more types one day, e.g. for diropres and 65 * attrstat replies. Using cache entries with fixed length instead 66 * of buffer pointers may be more efficient. 67 */ 68 enum { 69 RC_NOCACHE, 70 RC_REPLSTAT, 71 RC_REPLBUFF, 72 }; 73 74 /* Cache entries expire after this time period */ 75 #define RC_EXPIRE (120 * HZ) 76 77 /* Checksum this amount of the request */ 78 #define RC_CSUMLEN (256U) 79 80 int nfsd_reply_cache_init(void); 81 void nfsd_reply_cache_shutdown(void); 82 int nfsd_cache_lookup(struct svc_rqst *); 83 void nfsd_cache_update(struct svc_rqst *, int, __be32 *); 84 int nfsd_reply_cache_stats_open(struct inode *, struct file *); 85 86 #endif /* NFSCACHE_H */ 87