152138Smckusick /* 263236Sbostic * Copyright (c) 1992, 1993 363236Sbostic * The Regents of the University of California. All rights reserved. 452138Smckusick * 552138Smckusick * This code is derived from software contributed to Berkeley by 652138Smckusick * Rick Macklem at The University of Guelph. 752138Smckusick * 852138Smckusick * %sccs.include.redist.c% 952138Smckusick * 10*68653Smckusick * @(#)nqnfs.h 8.3 (Berkeley) 03/30/95 1152138Smckusick */ 1252138Smckusick 13*68653Smckusick 14*68653Smckusick #ifndef _NFS_NQNFS_H_ 15*68653Smckusick #define _NFS_NQNFS_H_ 16*68653Smckusick 1752138Smckusick /* 1852138Smckusick * Definitions for NQNFS (Not Quite NFS) cache consistency protocol. 1952138Smckusick */ 2052138Smckusick 2152138Smckusick /* Tunable constants */ 2252138Smckusick #define NQ_CLOCKSKEW 3 /* Clock skew factor (sec) */ 2352138Smckusick #define NQ_WRITESLACK 5 /* Delay for write cache flushing */ 2456280Smckusick #define NQ_MAXLEASE 60 /* Max lease duration (sec) */ 2556280Smckusick #define NQ_MINLEASE 5 /* Min lease duration (sec) */ 2656280Smckusick #define NQ_DEFLEASE 30 /* Default lease duration (sec) */ 2752138Smckusick #define NQ_RENEWAL 3 /* Time before expiry (sec) to renew */ 2852138Smckusick #define NQ_TRYLATERDEL 15 /* Initial try later delay (sec) */ 2952138Smckusick #define NQ_MAXNUMLEASE 2048 /* Upper bound on number of server leases */ 3059703Smckusick #define NQ_DEADTHRESH NQ_NEVERDEAD /* Default nm_deadthresh */ 3152138Smckusick #define NQ_NEVERDEAD 9 /* Greater than max. nm_timeouts */ 3252138Smckusick #define NQLCHSZ 256 /* Server hash table size */ 3352138Smckusick 3452138Smckusick #define NQNFS_PROG 300105 /* As assigned by Sun */ 35*68653Smckusick #define NQNFS_VER3 3 3652138Smckusick #define NQNFS_EVICTSIZ 156 /* Size of eviction request in bytes */ 3752138Smckusick 3852138Smckusick /* 3952138Smckusick * Definitions used for saving the "last lease expires" time in Non-volatile 4052138Smckusick * RAM on the server. The default definitions below assume that NOVRAM is not 4152138Smckusick * available. 4252138Smckusick */ 43*68653Smckusick #ifdef HASNVRAM 44*68653Smckusick # undef HASNVRAM 45*68653Smckusick #endif 4652138Smckusick #define NQSTORENOVRAM(t) 4752138Smckusick #define NQLOADNOVRAM(t) 4852138Smckusick 4952138Smckusick /* 5052138Smckusick * Defn and structs used on the server to maintain state for current leases. 5152138Smckusick * The list of host(s) that hold the lease are kept as nqhost structures. 5252138Smckusick * The first one lives in nqlease and any others are held in a linked 5352138Smckusick * list of nqm structures hanging off of nqlease. 5452138Smckusick * 5552138Smckusick * Each nqlease structure is chained into two lists. The first is a list 5652138Smckusick * ordered by increasing expiry time for nqsrv_timer() and the second is a chain 5752138Smckusick * hashed on lc_fh. 5852138Smckusick */ 5952138Smckusick #define LC_MOREHOSTSIZ 10 6052138Smckusick 6152138Smckusick struct nqhost { 6252138Smckusick union { 6352138Smckusick struct { 6452138Smckusick u_short udp_flag; 6552138Smckusick u_short udp_port; 6652138Smckusick union nethostaddr udp_haddr; 6752138Smckusick } un_udp; 6852138Smckusick struct { 6952138Smckusick u_short connless_flag; 7052138Smckusick u_short connless_spare; 7152138Smckusick union nethostaddr connless_haddr; 7252138Smckusick } un_connless; 7352138Smckusick struct { 7452138Smckusick u_short conn_flag; 7552903Smckusick u_short conn_spare; 7652138Smckusick struct nfssvc_sock *conn_slp; 7752138Smckusick } un_conn; 7852138Smckusick } lph_un; 7952138Smckusick }; 8052138Smckusick #define lph_flag lph_un.un_udp.udp_flag 8152138Smckusick #define lph_port lph_un.un_udp.udp_port 8252138Smckusick #define lph_haddr lph_un.un_udp.udp_haddr 8352138Smckusick #define lph_inetaddr lph_un.un_udp.udp_haddr.had_inetaddr 8452138Smckusick #define lph_claddr lph_un.un_connless.connless_haddr 8552138Smckusick #define lph_nam lph_un.un_connless.connless_haddr.had_nam 8652138Smckusick #define lph_slp lph_un.un_conn.conn_slp 8752138Smckusick 8852138Smckusick struct nqlease { 8967708Smckusick LIST_ENTRY(nqlease) lc_hash; /* Fhandle hash list */ 9067708Smckusick CIRCLEQ_ENTRY(nqlease) lc_timer; /* Timer queue list */ 9152138Smckusick time_t lc_expiry; /* Expiry time (sec) */ 9252138Smckusick struct nqhost lc_host; /* Host that got lease */ 9352138Smckusick struct nqm *lc_morehosts; /* Other hosts that share read lease */ 9452138Smckusick fsid_t lc_fsid; /* Fhandle */ 9552138Smckusick char lc_fiddata[MAXFIDSZ]; 9652138Smckusick struct vnode *lc_vp; /* Soft reference to associated vnode */ 9752138Smckusick }; 9852138Smckusick #define lc_flag lc_host.lph_un.un_udp.udp_flag 9952138Smckusick 10052138Smckusick /* lc_flag bits */ 10152138Smckusick #define LC_VALID 0x0001 /* Host address valid */ 10252138Smckusick #define LC_WRITE 0x0002 /* Write cache */ 10352138Smckusick #define LC_NONCACHABLE 0x0004 /* Non-cachable lease */ 10452138Smckusick #define LC_LOCKED 0x0008 /* Locked */ 10552138Smckusick #define LC_WANTED 0x0010 /* Lock wanted */ 10652138Smckusick #define LC_EXPIREDWANTED 0x0020 /* Want lease when expired */ 10752138Smckusick #define LC_UDP 0x0040 /* Host address for udp socket */ 10852138Smckusick #define LC_CLTP 0x0080 /* Host address for other connectionless */ 10952138Smckusick #define LC_LOCAL 0x0100 /* Host is server */ 11052138Smckusick #define LC_VACATED 0x0200 /* Host has vacated lease */ 11152138Smckusick #define LC_WRITTEN 0x0400 /* Recently wrote to the leased file */ 11252903Smckusick #define LC_SREF 0x0800 /* Holds a nfssvc_sock reference */ 11352138Smckusick 11452138Smckusick struct nqm { 11552138Smckusick struct nqm *lpm_next; 11652138Smckusick struct nqhost lpm_hosts[LC_MOREHOSTSIZ]; 11752138Smckusick }; 11852138Smckusick 11952138Smckusick /* 12052138Smckusick * Special value for slp for local server calls. 12152138Smckusick */ 12252138Smckusick #define NQLOCALSLP ((struct nfssvc_sock *) -1) 12352138Smckusick 12452138Smckusick /* 12552138Smckusick * Server side macros. 12652138Smckusick */ 12752138Smckusick #define nqsrv_getl(v, l) \ 12852138Smckusick (void) nqsrv_getlease((v), &nfsd->nd_duration, \ 129*68653Smckusick ((nfsd->nd_flag & ND_LEASE) ? (nfsd->nd_flag & ND_LEASE) : \ 130*68653Smckusick ((l) | ND_CHECK)), \ 131*68653Smckusick slp, procp, nfsd->nd_nam, &cache, &frev, cred) 13252138Smckusick 13352138Smckusick /* 13452138Smckusick * Client side macros that check for a valid lease. 13552138Smckusick */ 13652138Smckusick #define NQNFS_CKINVALID(v, n, f) \ 13752138Smckusick ((time.tv_sec > (n)->n_expiry && \ 13852138Smckusick VFSTONFS((v)->v_mount)->nm_timeouts < VFSTONFS((v)->v_mount)->nm_deadthresh) \ 139*68653Smckusick || ((f) == ND_WRITE && ((n)->n_flag & NQNFSWRITE) == 0)) 14052138Smckusick 14152138Smckusick #define NQNFS_CKCACHABLE(v, f) \ 14252138Smckusick ((time.tv_sec <= VTONFS(v)->n_expiry || \ 14352138Smckusick VFSTONFS((v)->v_mount)->nm_timeouts >= VFSTONFS((v)->v_mount)->nm_deadthresh) \ 14452138Smckusick && (VTONFS(v)->n_flag & NQNFSNONCACHE) == 0 && \ 145*68653Smckusick ((f) == ND_READ || (VTONFS(v)->n_flag & NQNFSWRITE))) 14652138Smckusick 14752138Smckusick #define NQNFS_NEEDLEASE(v, p) \ 14852138Smckusick (time.tv_sec > VTONFS(v)->n_expiry ? \ 14952138Smckusick ((VTONFS(v)->n_flag & NQNFSEVICTED) ? 0 : nqnfs_piggy[p]) : \ 15052138Smckusick (((time.tv_sec + NQ_RENEWAL) > VTONFS(v)->n_expiry && \ 15152138Smckusick nqnfs_piggy[p]) ? \ 15252138Smckusick ((VTONFS(v)->n_flag & NQNFSWRITE) ? \ 153*68653Smckusick ND_WRITE : nqnfs_piggy[p]) : 0)) 15452138Smckusick 15552138Smckusick /* 15655520Smckusick * List head for timer queue. 15752138Smckusick */ 158*68653Smckusick CIRCLEQ_HEAD(, nqlease) nqtimerhead; 15952138Smckusick 16052138Smckusick /* 16167708Smckusick * List head for the file handle hash table. 16267708Smckusick */ 16367708Smckusick #define NQFHHASH(f) \ 16467708Smckusick (&nqfhhashtbl[(*((u_long *)(f))) & nqfhhash]) 16567708Smckusick LIST_HEAD(nqfhhashhead, nqlease) *nqfhhashtbl; 16667708Smckusick u_long nqfhhash; 16767708Smckusick 16867708Smckusick /* 16952138Smckusick * Nqnfs return status numbers. 17052138Smckusick */ 17152138Smckusick #define NQNFS_EXPIRED 500 17252138Smckusick #define NQNFS_TRYLATER 501 173*68653Smckusick 174*68653Smckusick #ifdef KERNEL 175*68653Smckusick void nqnfs_lease_updatetime __P((int)); 176*68653Smckusick int nqsrv_cmpnam __P((struct nfssvc_sock *,struct mbuf *,struct nqhost *)); 177*68653Smckusick int nqsrv_getlease __P((struct vnode *, u_long *, int, 178*68653Smckusick struct nfssvc_sock *, struct proc *, struct mbuf *, int *, 179*68653Smckusick u_quad_t *, struct ucred *)); 180*68653Smckusick int nqnfs_getlease __P((struct vnode *, int, struct ucred *,struct proc *)); 181*68653Smckusick int nqnfs_callback __P((struct nfsmount *, struct mbuf *, struct mbuf *, 182*68653Smckusick caddr_t)); 183*68653Smckusick int nqnfs_clientd __P((struct nfsmount *, struct ucred *, 184*68653Smckusick struct nfsd_cargs *, int, caddr_t, struct proc *)); 185*68653Smckusick #endif 186*68653Smckusick 187*68653Smckusick #endif 188