1 /* 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)nqnfs.h 8.2 (Berkeley) 08/18/94 11 */ 12 13 /* 14 * Definitions for NQNFS (Not Quite NFS) cache consistency protocol. 15 */ 16 17 /* Tunable constants */ 18 #define NQ_CLOCKSKEW 3 /* Clock skew factor (sec) */ 19 #define NQ_WRITESLACK 5 /* Delay for write cache flushing */ 20 #define NQ_MAXLEASE 60 /* Max lease duration (sec) */ 21 #define NQ_MINLEASE 5 /* Min lease duration (sec) */ 22 #define NQ_DEFLEASE 30 /* Default lease duration (sec) */ 23 #define NQ_RENEWAL 3 /* Time before expiry (sec) to renew */ 24 #define NQ_TRYLATERDEL 15 /* Initial try later delay (sec) */ 25 #define NQ_MAXNUMLEASE 2048 /* Upper bound on number of server leases */ 26 #define NQ_DEADTHRESH NQ_NEVERDEAD /* Default nm_deadthresh */ 27 #define NQ_NEVERDEAD 9 /* Greater than max. nm_timeouts */ 28 #define NQLCHSZ 256 /* Server hash table size */ 29 30 #define NQNFS_PROG 300105 /* As assigned by Sun */ 31 #define NQNFS_VER1 1 32 #define NQNFS_EVICTSIZ 156 /* Size of eviction request in bytes */ 33 34 /* 35 * Definitions used for saving the "last lease expires" time in Non-volatile 36 * RAM on the server. The default definitions below assume that NOVRAM is not 37 * available. 38 */ 39 #define NQSTORENOVRAM(t) 40 #define NQLOADNOVRAM(t) 41 42 /* 43 * Defn and structs used on the server to maintain state for current leases. 44 * The list of host(s) that hold the lease are kept as nqhost structures. 45 * The first one lives in nqlease and any others are held in a linked 46 * list of nqm structures hanging off of nqlease. 47 * 48 * Each nqlease structure is chained into two lists. The first is a list 49 * ordered by increasing expiry time for nqsrv_timer() and the second is a chain 50 * hashed on lc_fh. 51 */ 52 #define LC_MOREHOSTSIZ 10 53 54 struct nqhost { 55 union { 56 struct { 57 u_short udp_flag; 58 u_short udp_port; 59 union nethostaddr udp_haddr; 60 } un_udp; 61 struct { 62 u_short connless_flag; 63 u_short connless_spare; 64 union nethostaddr connless_haddr; 65 } un_connless; 66 struct { 67 u_short conn_flag; 68 u_short conn_spare; 69 struct nfssvc_sock *conn_slp; 70 } un_conn; 71 } lph_un; 72 }; 73 #define lph_flag lph_un.un_udp.udp_flag 74 #define lph_port lph_un.un_udp.udp_port 75 #define lph_haddr lph_un.un_udp.udp_haddr 76 #define lph_inetaddr lph_un.un_udp.udp_haddr.had_inetaddr 77 #define lph_claddr lph_un.un_connless.connless_haddr 78 #define lph_nam lph_un.un_connless.connless_haddr.had_nam 79 #define lph_slp lph_un.un_conn.conn_slp 80 81 struct nqlease { 82 LIST_ENTRY(nqlease) lc_hash; /* Fhandle hash list */ 83 CIRCLEQ_ENTRY(nqlease) lc_timer; /* Timer queue list */ 84 time_t lc_expiry; /* Expiry time (sec) */ 85 struct nqhost lc_host; /* Host that got lease */ 86 struct nqm *lc_morehosts; /* Other hosts that share read lease */ 87 fsid_t lc_fsid; /* Fhandle */ 88 char lc_fiddata[MAXFIDSZ]; 89 struct vnode *lc_vp; /* Soft reference to associated vnode */ 90 }; 91 #define lc_flag lc_host.lph_un.un_udp.udp_flag 92 93 /* lc_flag bits */ 94 #define LC_VALID 0x0001 /* Host address valid */ 95 #define LC_WRITE 0x0002 /* Write cache */ 96 #define LC_NONCACHABLE 0x0004 /* Non-cachable lease */ 97 #define LC_LOCKED 0x0008 /* Locked */ 98 #define LC_WANTED 0x0010 /* Lock wanted */ 99 #define LC_EXPIREDWANTED 0x0020 /* Want lease when expired */ 100 #define LC_UDP 0x0040 /* Host address for udp socket */ 101 #define LC_CLTP 0x0080 /* Host address for other connectionless */ 102 #define LC_LOCAL 0x0100 /* Host is server */ 103 #define LC_VACATED 0x0200 /* Host has vacated lease */ 104 #define LC_WRITTEN 0x0400 /* Recently wrote to the leased file */ 105 #define LC_SREF 0x0800 /* Holds a nfssvc_sock reference */ 106 107 struct nqm { 108 struct nqm *lpm_next; 109 struct nqhost lpm_hosts[LC_MOREHOSTSIZ]; 110 }; 111 112 /* 113 * Flag bits for flags argument to nqsrv_getlease. 114 */ 115 #define NQL_READ LEASE_READ /* Read Request */ 116 #define NQL_WRITE LEASE_WRITE /* Write Request */ 117 #define NQL_CHECK 0x4 /* Check for lease */ 118 #define NQL_NOVAL 0xffffffff /* Invalid */ 119 120 /* 121 * Special value for slp for local server calls. 122 */ 123 #define NQLOCALSLP ((struct nfssvc_sock *) -1) 124 125 /* 126 * Server side macros. 127 */ 128 #define nqsrv_getl(v, l) \ 129 (void) nqsrv_getlease((v), &nfsd->nd_duration, \ 130 ((nfsd->nd_nqlflag != 0 && nfsd->nd_nqlflag != NQL_NOVAL) ? nfsd->nd_nqlflag : \ 131 ((l) | NQL_CHECK)), \ 132 nfsd, nam, &cache, &frev, cred) 133 134 /* 135 * Client side macros that check for a valid lease. 136 */ 137 #define NQNFS_CKINVALID(v, n, f) \ 138 ((time.tv_sec > (n)->n_expiry && \ 139 VFSTONFS((v)->v_mount)->nm_timeouts < VFSTONFS((v)->v_mount)->nm_deadthresh) \ 140 || ((f) == NQL_WRITE && ((n)->n_flag & NQNFSWRITE) == 0)) 141 142 #define NQNFS_CKCACHABLE(v, f) \ 143 ((time.tv_sec <= VTONFS(v)->n_expiry || \ 144 VFSTONFS((v)->v_mount)->nm_timeouts >= VFSTONFS((v)->v_mount)->nm_deadthresh) \ 145 && (VTONFS(v)->n_flag & NQNFSNONCACHE) == 0 && \ 146 ((f) == NQL_READ || (VTONFS(v)->n_flag & NQNFSWRITE))) 147 148 #define NQNFS_NEEDLEASE(v, p) \ 149 (time.tv_sec > VTONFS(v)->n_expiry ? \ 150 ((VTONFS(v)->n_flag & NQNFSEVICTED) ? 0 : nqnfs_piggy[p]) : \ 151 (((time.tv_sec + NQ_RENEWAL) > VTONFS(v)->n_expiry && \ 152 nqnfs_piggy[p]) ? \ 153 ((VTONFS(v)->n_flag & NQNFSWRITE) ? \ 154 NQL_WRITE : nqnfs_piggy[p]) : 0)) 155 156 /* 157 * List head for timer queue. 158 */ 159 CIRCLEQ_HEAD(nqleases, nqlease) nqtimerhead; 160 161 /* 162 * List head for the file handle hash table. 163 */ 164 #define NQFHHASH(f) \ 165 (&nqfhhashtbl[(*((u_long *)(f))) & nqfhhash]) 166 LIST_HEAD(nqfhhashhead, nqlease) *nqfhhashtbl; 167 u_long nqfhhash; 168 169 /* 170 * Nqnfs return status numbers. 171 */ 172 #define NQNFS_EXPIRED 500 173 #define NQNFS_TRYLATER 501 174 #define NQNFS_AUTHERR 502 175