home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / include / nfs / nqnfs.h < prev    next >
C/C++ Source or Header  |  1996-12-11  |  7KB  |  203 lines

  1. /*    $NetBSD: nqnfs.h,v 1.4 1994/12/13 17:17:08 mycroft Exp $    */
  2.  
  3. /*
  4.  * Copyright (c) 1992, 1993
  5.  *    The Regents of the University of California.  All rights reserved.
  6.  *
  7.  * This code is derived from software contributed to Berkeley by
  8.  * Rick Macklem at The University of Guelph.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    @(#)nqnfs.h    8.2 (Berkeley) 8/18/94
  39.  */
  40.  
  41. /*
  42.  * Definitions for NQNFS (Not Quite NFS) cache consistency protocol.
  43.  */
  44.  
  45. /* Tunable constants */
  46. #define    NQ_CLOCKSKEW    3    /* Clock skew factor (sec) */
  47. #define    NQ_WRITESLACK    5    /* Delay for write cache flushing */
  48. #define    NQ_MAXLEASE    60    /* Max lease duration (sec) */
  49. #define    NQ_MINLEASE    5    /* Min lease duration (sec) */
  50. #define    NQ_DEFLEASE    30    /* Default lease duration (sec) */
  51. #define    NQ_RENEWAL    3    /* Time before expiry (sec) to renew */
  52. #define    NQ_TRYLATERDEL    15    /* Initial try later delay (sec) */
  53. #define    NQ_MAXNUMLEASE    2048    /* Upper bound on number of server leases */
  54. #define    NQ_DEADTHRESH    NQ_NEVERDEAD    /* Default nm_deadthresh */
  55. #define    NQ_NEVERDEAD    9    /* Greater than max. nm_timeouts */
  56. #define    NQLCHSZ        256    /* Server hash table size */
  57.  
  58. #define    NQNFS_PROG    300105    /* As assigned by Sun */
  59. #define    NQNFS_VER1    1
  60. #define    NQNFS_EVICTSIZ    156    /* Size of eviction request in bytes */
  61.  
  62. /*
  63.  * Definitions used for saving the "last lease expires" time in Non-volatile
  64.  * RAM on the server. The default definitions below assume that NOVRAM is not
  65.  * available.
  66.  */
  67. #define    NQSTORENOVRAM(t)
  68. #define    NQLOADNOVRAM(t)
  69.  
  70. /*
  71.  * Defn and structs used on the server to maintain state for current leases.
  72.  * The list of host(s) that hold the lease are kept as nqhost structures.
  73.  * The first one lives in nqlease and any others are held in a linked
  74.  * list of nqm structures hanging off of nqlease.
  75.  *
  76.  * Each nqlease structure is chained into two lists. The first is a list
  77.  * ordered by increasing expiry time for nqsrv_timer() and the second is a chain
  78.  * hashed on lc_fh.
  79.  */
  80. #define    LC_MOREHOSTSIZ    10
  81.  
  82. struct nqhost {
  83.     union {
  84.         struct {
  85.             u_short udp_flag;
  86.             u_short    udp_port;
  87.             union nethostaddr udp_haddr;
  88.         } un_udp;
  89.         struct {
  90.             u_short connless_flag;
  91.             u_short connless_spare;
  92.             union nethostaddr connless_haddr;
  93.         } un_connless;
  94.         struct {
  95.             u_short conn_flag;
  96.             u_short conn_spare;
  97.             struct nfssvc_sock *conn_slp;
  98.         } un_conn;
  99.     } lph_un;
  100. };
  101. #define    lph_flag    lph_un.un_udp.udp_flag
  102. #define    lph_port    lph_un.un_udp.udp_port
  103. #define    lph_haddr    lph_un.un_udp.udp_haddr
  104. #define    lph_inetaddr    lph_un.un_udp.udp_haddr.had_inetaddr
  105. #define    lph_claddr    lph_un.un_connless.connless_haddr
  106. #define    lph_nam        lph_un.un_connless.connless_haddr.had_nam
  107. #define    lph_slp        lph_un.un_conn.conn_slp
  108.  
  109. struct nqlease {
  110.     LIST_ENTRY(nqlease) lc_hash;    /* Fhandle hash list */
  111.     CIRCLEQ_ENTRY(nqlease) lc_timer; /* Timer queue list */
  112.     time_t        lc_expiry;    /* Expiry time (sec) */
  113.     struct nqhost    lc_host;    /* Host that got lease */
  114.     struct nqm    *lc_morehosts;    /* Other hosts that share read lease */
  115.     fsid_t        lc_fsid;    /* Fhandle */
  116.     char        lc_fiddata[MAXFIDSZ];
  117.     struct vnode    *lc_vp;        /* Soft reference to associated vnode */
  118. };
  119. #define    lc_flag        lc_host.lph_un.un_udp.udp_flag
  120.  
  121. /* lc_flag bits */
  122. #define    LC_VALID    0x0001    /* Host address valid */
  123. #define    LC_WRITE    0x0002    /* Write cache */
  124. #define    LC_NONCACHABLE    0x0004    /* Non-cachable lease */
  125. #define    LC_LOCKED    0x0008    /* Locked */
  126. #define    LC_WANTED    0x0010    /* Lock wanted */
  127. #define    LC_EXPIREDWANTED 0x0020    /* Want lease when expired */
  128. #define    LC_UDP        0x0040    /* Host address for udp socket */
  129. #define    LC_CLTP        0x0080    /* Host address for other connectionless */
  130. #define    LC_LOCAL    0x0100    /* Host is server */
  131. #define    LC_VACATED    0x0200    /* Host has vacated lease */
  132. #define    LC_WRITTEN    0x0400    /* Recently wrote to the leased file */
  133. #define    LC_SREF        0x0800    /* Holds a nfssvc_sock reference */
  134.  
  135. struct nqm {
  136.     struct nqm    *lpm_next;
  137.     struct nqhost    lpm_hosts[LC_MOREHOSTSIZ];
  138. };
  139.  
  140. /*
  141.  * Flag bits for flags argument to nqsrv_getlease.
  142.  */
  143. #define    NQL_READ    LEASE_READ    /* Read Request */
  144. #define    NQL_WRITE    LEASE_WRITE    /* Write Request */
  145. #define    NQL_CHECK    0x4        /* Check for lease */
  146. #define    NQL_NOVAL    0xffffffff    /* Invalid */
  147.  
  148. /*
  149.  * Special value for slp for local server calls.
  150.  */
  151. #define    NQLOCALSLP    ((struct nfssvc_sock *) -1)
  152.  
  153. /*
  154.  * Server side macros.
  155.  */
  156. #define    nqsrv_getl(v, l) \
  157.         (void) nqsrv_getlease((v), &nfsd->nd_duration, \
  158.          ((nfsd->nd_nqlflag != 0 && nfsd->nd_nqlflag != NQL_NOVAL) ? nfsd->nd_nqlflag : \
  159.          ((l) | NQL_CHECK)), \
  160.          nfsd, nam, &cache, &frev, cred)
  161.  
  162. /*
  163.  * Client side macros that check for a valid lease.
  164.  */
  165. #define    NQNFS_CKINVALID(v, n, f) \
  166.  ((time.tv_sec > (n)->n_expiry && \
  167.  VFSTONFS((v)->v_mount)->nm_timeouts < VFSTONFS((v)->v_mount)->nm_deadthresh) \
  168.   || ((f) == NQL_WRITE && ((n)->n_flag & NQNFSWRITE) == 0))
  169.  
  170. #define    NQNFS_CKCACHABLE(v, f) \
  171.  ((time.tv_sec <= VTONFS(v)->n_expiry || \
  172.   VFSTONFS((v)->v_mount)->nm_timeouts >= VFSTONFS((v)->v_mount)->nm_deadthresh) \
  173.    && (VTONFS(v)->n_flag & NQNFSNONCACHE) == 0 && \
  174.    ((f) == NQL_READ || (VTONFS(v)->n_flag & NQNFSWRITE)))
  175.  
  176. #define    NQNFS_NEEDLEASE(v, p) \
  177.         (time.tv_sec > VTONFS(v)->n_expiry ? \
  178.          ((VTONFS(v)->n_flag & NQNFSEVICTED) ? 0 : nqnfs_piggy[p]) : \
  179.          (((time.tv_sec + NQ_RENEWAL) > VTONFS(v)->n_expiry && \
  180.            nqnfs_piggy[p]) ? \
  181.            ((VTONFS(v)->n_flag & NQNFSWRITE) ? \
  182.             NQL_WRITE : nqnfs_piggy[p]) : 0))
  183.  
  184. /*
  185.  * List head for timer queue.
  186.  */
  187. CIRCLEQ_HEAD(, nqlease) nqtimerhead;
  188.  
  189. /*
  190.  * List head for the file handle hash table.
  191.  */
  192. #define    NQFHHASH(f) \
  193.     (&nqfhhashtbl[(*((u_long *)(f))) & nqfhhash])
  194. LIST_HEAD(nqfhhashhead, nqlease) *nqfhhashtbl;
  195. u_long nqfhhash;
  196.  
  197. /*
  198.  * Nqnfs return status numbers.
  199.  */
  200. #define    NQNFS_EXPIRED    500
  201. #define    NQNFS_TRYLATER    501
  202. #define NQNFS_AUTHERR    502
  203.