root/nfs/nfs.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. TAILQ_HEAD
  2. TAILQ_HEAD

    1 /*      $OpenBSD: nfs.h,v 1.28 2007/01/16 17:52:18 thib Exp $   */
    2 /*      $NetBSD: nfs.h,v 1.10.4.1 1996/05/27 11:23:56 fvdl Exp $        */
    3 
    4 /*
    5  * Copyright (c) 1989, 1993, 1995
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * This code is derived from software contributed to Berkeley by
    9  * Rick Macklem at The University of Guelph.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. Neither the name of the University nor the names of its contributors
   20  *    may be used to endorse or promote products derived from this software
   21  *    without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   33  * SUCH DAMAGE.
   34  *
   35  *      @(#)nfs.h       8.4 (Berkeley) 5/1/95
   36  */
   37 
   38 #ifndef _NFS_NFS_H_
   39 #define _NFS_NFS_H_
   40 
   41 /*
   42  * Tunable constants for nfs
   43  */
   44 
   45 #define NFS_MAXIOVEC    34
   46 #define NFS_TICKINTVL   5               /* Desired time for a tick (msec) */
   47 #define NFS_HZ          (hz / nfs_ticks) /* Ticks/sec */
   48 #define NFS_TIMEO       (1 * NFS_HZ)    /* Default timeout = 1 second */
   49 #define NFS_MINTIMEO    (1 * NFS_HZ)    /* Min timeout to use */
   50 #define NFS_MAXTIMEO    (60 * NFS_HZ)   /* Max timeout to backoff to */
   51 #define NFS_MINIDEMTIMEO (5 * NFS_HZ)   /* Min timeout for non-idempotent ops*/
   52 #define NFS_TIMEOUTMUL  2               /* Timeout/Delay multiplier */
   53 #define NFS_MAXREXMIT   100             /* Stop counting after this many */
   54 #define NFS_MAXWINDOW   1024            /* Max number of outstanding requests */
   55 #define NFS_RETRANS     10              /* Num of retrans for soft mounts */
   56 #define NFS_MAXGRPS     16              /* Max. size of groups list */
   57 #ifndef NFS_MINATTRTIMO
   58 #define NFS_MINATTRTIMO 5               /* Attribute cache timeout in sec */
   59 #endif
   60 #ifndef NFS_MAXATTRTIMO
   61 #define NFS_MAXATTRTIMO 60
   62 #endif
   63 #define NFS_WSIZE       8192            /* Def. write data size <= 8192 */
   64 #define NFS_RSIZE       8192            /* Def. read data size <= 8192 */
   65 #define NFS_READDIRSIZE 8192            /* Def. readdir size */
   66 #define NFS_DEFRAHEAD   1               /* Def. read ahead # blocks */
   67 #define NFS_MAXRAHEAD   4               /* Max. read ahead # blocks */
   68 #define NFS_MAXUIDHASH  64              /* Max. # of hashed uid entries/mp */
   69 #define NFS_MAXASYNCDAEMON      20      /* Max. number async_daemons runable */
   70 #define NFS_MAXGATHERDELAY      100     /* Max. write gather delay (msec) */
   71 #ifndef NFS_GATHERDELAY
   72 #define NFS_GATHERDELAY         10      /* Default write gather delay (msec) */
   73 #endif
   74 /*
   75  * Ideally, NFS_DIRBLKSIZ should be bigger, but I've seen servers with
   76  * broken NFS/ethernet drivers that won't work with anything bigger (Linux..)
   77  */
   78 #define NFS_DIRBLKSIZ   1024            /* Must be a multiple of DIRBLKSIZ */
   79 #define NFS_READDIRBLKSIZ       512     /* Size of read dir blocks. XXX */
   80 
   81 /*
   82  * Oddballs
   83  */
   84 #define NMOD(a)         ((a) % nfs_asyncdaemons)
   85 #define NFS_CMPFH(n, f, s) \
   86         ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
   87 #define NFS_ISV3(v)     (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
   88 #define NFS_SRVMAXDATA(n) \
   89                 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
   90                  NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
   91 
   92 /*
   93  * sys/malloc.h needs M_NFSDIROFF, M_NFSRVDESC and M_NFSBIGFH added.
   94  * The VA_EXCLUSIVE flag should be added for va_vaflags and set for an
   95  * exclusive create.
   96  */
   97 #ifndef M_NFSRVDESC
   98 #define M_NFSRVDESC     M_TEMP
   99 #endif
  100 #ifndef M_NFSDIROFF
  101 #define M_NFSDIROFF     M_TEMP
  102 #endif
  103 #ifndef M_NFSBIGFH
  104 #define M_NFSBIGFH      M_TEMP
  105 #endif
  106 #ifndef VA_EXCLUSIVE
  107 #define VA_EXCLUSIVE    0
  108 #endif
  109 
  110 /*
  111  * The B_INVAFTERWRITE flag should be set to whatever is required by the
  112  * buffer cache code to say "Invalidate the block after it is written back".
  113  */
  114 #define B_INVAFTERWRITE B_INVAL
  115 
  116 /*
  117  * The IO_METASYNC flag should be implemented for local file systems.
  118  * (Until then, it is nothin at all.)
  119  */
  120 #ifndef IO_METASYNC
  121 #define IO_METASYNC     0
  122 #endif
  123 
  124 /*
  125  * Set the attribute timeout based on how recently the file has been modified.
  126  */
  127 #if 0 /* replaced by nfs_attrtimeo() in nfs_subs.c */
  128 #define NFS_ATTRTIMEO(np) \
  129         ((((np)->n_flag & NMODIFIED) || \
  130          (time_second - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
  131          ((time_second - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
  132           (time_second - (np)->n_mtime) / 10))
  133 #endif
  134 
  135 /*
  136  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
  137  * should ever try and use it.
  138  */
  139 struct nfsd_args {
  140         int     sock;           /* Socket to serve */
  141         caddr_t name;           /* Client addr for connection based sockets */
  142         int     namelen;        /* Length of name */
  143 };
  144 
  145 struct nfsd_srvargs {
  146         struct nfsd     *nsd_nfsd;      /* Pointer to in kernel nfsd struct */
  147         uid_t           nsd_uid;        /* Effective uid mapped to cred */
  148         u_int32_t       nsd_haddr;      /* IP address of client */
  149         struct ucred    nsd_cr;         /* Cred. uid maps to */
  150         int             nsd_authlen;    /* Length of auth string (ret) */
  151         u_char          *nsd_authstr;   /* Auth string (ret) */
  152         int             nsd_verflen;    /* and the verifier */
  153         u_char          *nsd_verfstr;
  154         struct timeval  nsd_timestamp;  /* timestamp from verifier */
  155         u_int32_t       nsd_ttl;        /* credential ttl (sec) */
  156         NFSKERBKEY_T    nsd_key;        /* Session key */
  157 };
  158 
  159 struct nfsd_cargs {
  160         char            *ncd_dirp;      /* Mount dir path */
  161         uid_t           ncd_authuid;    /* Effective uid */
  162         int             ncd_authtype;   /* Type of authenticator */
  163         u_int           ncd_authlen;    /* Length of authenticator string */
  164         u_char          *ncd_authstr;   /* Authenticator string */
  165         u_int           ncd_verflen;    /* and the verifier */
  166         u_char          *ncd_verfstr;
  167         NFSKERBKEY_T    ncd_key;        /* Session key */
  168 };
  169 
  170 /*
  171  * Stats structure
  172  */
  173 struct nfsstats {
  174         uint64_t        attrcache_hits;
  175         uint64_t        attrcache_misses;
  176         uint64_t        lookupcache_hits;
  177         uint64_t        lookupcache_misses;
  178         uint64_t        direofcache_hits;
  179         uint64_t        direofcache_misses;
  180         uint64_t        biocache_reads;
  181         uint64_t        read_bios;
  182         uint64_t        read_physios;
  183         uint64_t        biocache_writes;
  184         uint64_t        write_bios;
  185         uint64_t        write_physios;
  186         uint64_t        biocache_readlinks;
  187         uint64_t        readlink_bios;
  188         uint64_t        biocache_readdirs;
  189         uint64_t        readdir_bios;
  190         uint64_t        rpccnt[NFS_NPROCS];
  191         uint64_t        rpcretries;
  192         uint64_t        srvrpccnt[NFS_NPROCS];
  193         uint64_t        srvrpc_errs;
  194         uint64_t        srv_errs;
  195         uint64_t        rpcrequests;
  196         uint64_t        rpctimeouts;
  197         uint64_t        rpcunexpected;
  198         uint64_t        rpcinvalid;
  199         uint64_t        srvcache_inproghits;
  200         uint64_t        srvcache_idemdonehits;
  201         uint64_t        srvcache_nonidemdonehits;
  202         uint64_t        srvcache_misses;
  203         uint64_t        srvnqnfs_leases;
  204         uint64_t        srvnqnfs_maxleases;
  205         uint64_t        srvnqnfs_getleases;
  206         uint64_t        srvvop_writes;
  207 };
  208 
  209 /*
  210  * Flags for nfssvc() system call.
  211  */
  212 #define NFSSVC_BIOD     0x002
  213 #define NFSSVC_NFSD     0x004
  214 #define NFSSVC_ADDSOCK  0x008
  215 #define NFSSVC_AUTHIN   0x010
  216 #define NFSSVC_GOTAUTH  0x040
  217 #define NFSSVC_AUTHINFAIL 0x080
  218 #define NFSSVC_MNTD     0x100
  219 
  220 /*
  221  * fs.nfs sysctl(3) identifiers
  222  */
  223 #define NFS_NFSSTATS    1       /* struct: struct nfsstats */
  224 #define NFS_NIOTHREADS  2       /* number of i/o threads */
  225 #define NFS_MAXID       3
  226 
  227 #define FS_NFS_NAMES { \
  228                         { 0, 0 }, \
  229                         { "nfsstats", CTLTYPE_STRUCT }, \
  230                         { "iothreads", CTLTYPE_INT } \
  231 }
  232 
  233 /*
  234  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
  235  * What should be in this set is open to debate, but I believe that since
  236  * I/O system calls on ufs are never interrupted by signals the set should
  237  * be minimal. My reasoning is that many current programs that use signals
  238  * such as SIGALRM will not expect file I/O system calls to be interrupted
  239  * by them and break.
  240  */
  241 #ifdef _KERNEL
  242 extern int nfs_niothreads;
  243 
  244 struct uio; struct buf; struct vattr; struct nameidata; /* XXX */
  245 
  246 #define NFSINT_SIGMASK  (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
  247                          sigmask(SIGHUP)|sigmask(SIGQUIT))
  248 
  249 /*
  250  * Socket errors ignored for connectionless sockets??
  251  * For now, ignore them all
  252  */
  253 #define NFSIGNORE_SOERROR(s, e) \
  254                 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
  255                 ((s) & PR_CONNREQUIRED) == 0)
  256 
  257 /*
  258  * Nfs outstanding request list element
  259  */
  260 struct nfsreq {
  261         TAILQ_ENTRY(nfsreq) r_chain;
  262         struct mbuf     *r_mreq;
  263         struct mbuf     *r_mrep;
  264         struct mbuf     *r_md;
  265         caddr_t         r_dpos;
  266         struct nfsmount *r_nmp;
  267         struct vnode    *r_vp;
  268         u_int32_t       r_xid;
  269         int             r_flags;        /* flags on request, see below */
  270         int             r_retry;        /* max retransmission count */
  271         int             r_rexmit;       /* current retrans count */
  272         int             r_timer;        /* tick counter on reply */
  273         int             r_procnum;      /* NFS procedure number */
  274         int             r_rtt;          /* RTT for rpc */
  275         struct proc     *r_procp;       /* Proc that did I/O system call */
  276 };
  277 
  278 /*
  279  * Queue head for nfsreq's
  280  */
  281 extern TAILQ_HEAD(nfsreqhead, nfsreq) nfs_reqq;
  282 
  283 /* Flag values for r_flags */
  284 #define R_TIMING        0x01            /* timing request (in mntp) */
  285 #define R_SENT          0x02            /* request has been sent */
  286 #define R_SOFTTERM      0x04            /* soft mnt, too many retries */
  287 #define R_INTR          0x08            /* intr mnt, signal pending */
  288 #define R_SOCKERR       0x10            /* Fatal error on socket */
  289 #define R_TPRINTFMSG    0x20            /* Did a tprintf msg. */
  290 #define R_MUSTRESEND    0x40            /* Must resend request */
  291 #define R_GETONEREP     0x80            /* Probe for one reply only */
  292 
  293 /*
  294  * A list of nfssvc_sock structures is maintained with all the sockets
  295  * that require service by the nfsd.
  296  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
  297  * and uid hash lists.
  298  */
  299 #ifndef NFS_UIDHASHSIZ
  300 #define NFS_UIDHASHSIZ  29      /* Tune the size of nfssvc_sock with this */
  301 #endif
  302 #define NUIDHASH(sock, uid) \
  303         (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
  304 #ifndef NFS_WDELAYHASHSIZ
  305 #define NFS_WDELAYHASHSIZ 16    /* and with this */
  306 #endif
  307 #define NWDELAYHASH(sock, f) \
  308         (&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
  309 #ifndef NFS_MUIDHASHSIZ
  310 #define NFS_MUIDHASHSIZ 67      /* Tune the size of nfsmount with this */
  311 #endif
  312 #define NMUIDHASH(nmp, uid) \
  313         (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
  314 #define NFSNOHASH(fhsum) \
  315         (&nfsnodehashtbl[(fhsum) & nfsnodehash])
  316 
  317 /*
  318  * Network address hash list element
  319  */
  320 union nethostaddr {
  321         u_int32_t had_inetaddr;
  322         struct mbuf *had_nam;
  323 };
  324 
  325 struct nfsuid {
  326         TAILQ_ENTRY(nfsuid) nu_lru;     /* LRU chain */
  327         LIST_ENTRY(nfsuid) nu_hash;     /* Hash list */
  328         int             nu_flag;        /* Flags */
  329         union nethostaddr nu_haddr;     /* Host addr. for dgram sockets */
  330         struct ucred    nu_cr;          /* Cred uid mapped to */
  331         int             nu_expire;      /* Expiry time (sec) */
  332         struct timeval  nu_timestamp;   /* Kerb. timestamp */
  333         u_int32_t       nu_nickname;    /* Nickname on server */
  334         NFSKERBKEY_T    nu_key;         /* and session key */
  335 };
  336 
  337 #define nu_inetaddr     nu_haddr.had_inetaddr
  338 #define nu_nam          nu_haddr.had_nam
  339 /* Bits for nu_flag */
  340 #define NU_INETADDR     0x1
  341 #define NU_NAM          0x2
  342 #define NU_NETFAM(u)    (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
  343 
  344 struct nfssvc_sock {
  345         TAILQ_ENTRY(nfssvc_sock) ns_chain;      /* List of all nfssvc_sock's */
  346         TAILQ_HEAD(, nfsuid) ns_uidlruhead;
  347         struct file     *ns_fp;
  348         struct socket   *ns_so;
  349         struct mbuf     *ns_nam;
  350         struct mbuf     *ns_raw;
  351         struct mbuf     *ns_rawend;
  352         struct mbuf     *ns_rec;
  353         struct mbuf     *ns_recend;
  354         struct mbuf     *ns_frag;
  355         int             ns_flag;
  356         int             ns_solock;
  357         int             ns_cc;
  358         int             ns_reclen;
  359         int             ns_numuids;
  360         u_int32_t       ns_sref;
  361         LIST_HEAD(, nfsrv_descript) ns_tq;      /* Write gather lists */
  362         LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
  363         LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
  364 };
  365 
  366 /* Bits for "ns_flag" */
  367 #define SLP_VALID       0x01
  368 #define SLP_DOREC       0x02
  369 #define SLP_NEEDQ       0x04
  370 #define SLP_DISCONN     0x08
  371 #define SLP_GETSTREAM   0x10
  372 #define SLP_LASTFRAG    0x20
  373 #define SLP_ALLFLAGS    0xff
  374 
  375 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
  376 extern int nfssvc_sockhead_flag;
  377 #define SLP_INIT        0x01
  378 #define SLP_WANTINIT    0x02
  379 
  380 /*
  381  * One of these structures is allocated for each nfsd.
  382  */
  383 struct nfsd {
  384         TAILQ_ENTRY(nfsd) nfsd_chain;   /* List of all nfsd's */
  385         int             nfsd_flag;      /* NFSD_ flags */
  386         struct nfssvc_sock *nfsd_slp;   /* Current socket */
  387         int             nfsd_authlen;   /* Authenticator len */
  388         u_char          nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
  389         int             nfsd_verflen;   /* and the Verifier */
  390         u_char          nfsd_verfstr[RPCVERF_MAXSIZ];
  391         struct proc     *nfsd_procp;    /* Proc ptr */
  392         struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */
  393 };
  394 
  395 /* Bits for "nfsd_flag" */
  396 #define NFSD_WAITING    0x01
  397 #define NFSD_REQINPROG  0x02
  398 #define NFSD_NEEDAUTH   0x04
  399 #define NFSD_AUTHFAIL   0x08
  400 
  401 /*
  402  * This structure is used by the server for describing each request.
  403  * Some fields are used only when write request gathering is performed.
  404  */
  405 struct nfsrv_descript {
  406         u_quad_t                nd_time;        /* Write deadline (usec) */
  407         off_t                   nd_off;         /* Start byte offset */
  408         off_t                   nd_eoff;        /* and end byte offset */
  409         LIST_ENTRY(nfsrv_descript) nd_hash;     /* Hash list */
  410         LIST_ENTRY(nfsrv_descript) nd_tq;               /* and timer list */
  411         LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */
  412         struct mbuf             *nd_mrep;       /* Request mbuf list */
  413         struct mbuf             *nd_md;         /* Current dissect mbuf */
  414         struct mbuf             *nd_mreq;       /* Reply mbuf list */
  415         struct mbuf             *nd_nam;        /* and socket addr */
  416         struct mbuf             *nd_nam2;       /* return socket addr */
  417         caddr_t                 nd_dpos;        /* Current dissect pos */
  418         unsigned int            nd_procnum;     /* RPC # */
  419         int                     nd_stable;      /* storage type */
  420         int                     nd_flag;        /* nd_flag */
  421         int                     nd_len;         /* Length of this write */
  422         int                     nd_repstat;     /* Reply status */
  423         u_int32_t               nd_retxid;      /* Reply xid */
  424         struct timeval          nd_starttime;   /* Time RPC initiated */
  425         fhandle_t               nd_fh;          /* File handle */
  426         struct ucred            nd_cr;          /* Credentials */
  427 };
  428 
  429 /* Bits for "nd_flag" */
  430 #define ND_NFSV3        0x08
  431 #define ND_KERBNICK     0x20
  432 #define ND_KERBFULL     0x40
  433 #define ND_KERBAUTH     (ND_KERBNICK | ND_KERBFULL)
  434 
  435 extern struct pool nfsreqpl;
  436 extern TAILQ_HEAD(nfsdhead, nfsd) nfsd_head;
  437 extern int nfsd_head_flag;
  438 #define NFSD_CHECKSLP   0x01
  439 
  440 /*
  441  * These macros compare nfsrv_descript structures.
  442  */
  443 #define NFSW_CONTIG(o, n) \
  444                 ((o)->nd_eoff >= (n)->nd_off && \
  445                  !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
  446 
  447 #define NFSW_SAMECRED(o, n) \
  448         (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
  449          !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
  450                 sizeof (struct ucred)))
  451 
  452 #endif  /* _KERNEL */
  453 #endif /* _NFS_NFS_H */

/* [<][>][^][v][top][bottom][index][help] */