nfsport.h revision 220648
125605Skjc/*- 2139823Simp * Copyright (c) 1989, 1993 325605Skjc * The Regents of the University of California. All rights reserved. 425605Skjc * 5156812Srwatson * This code is derived from software contributed to Berkeley by 625605Skjc * Rick Macklem at The University of Guelph. 725605Skjc * 825605Skjc * Redistribution and use in source and binary forms, with or without 925605Skjc * modification, are permitted provided that the following conditions 1025605Skjc * are met: 1125605Skjc * 1. Redistributions of source code must retain the above copyright 1225605Skjc * notice, this list of conditions and the following disclaimer. 1325605Skjc * 2. Redistributions in binary form must reproduce the above copyright 1425605Skjc * notice, this list of conditions and the following disclaimer in the 1525605Skjc * documentation and/or other materials provided with the distribution. 1625605Skjc * 4. Neither the name of the University nor the names of its contributors 1725605Skjc * may be used to endorse or promote products derived from this software 1825605Skjc * without specific prior written permission. 1925605Skjc * 2025605Skjc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2125605Skjc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2225605Skjc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2325605Skjc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2425605Skjc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2525605Skjc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2625605Skjc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2725605Skjc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2825605Skjc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2925605Skjc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3025605Skjc * SUCH DAMAGE. 3125605Skjc * 3225605Skjc * $FreeBSD: head/sys/fs/nfs/nfsport.h 220648 2011-04-14 23:46:15Z rmacklem $ 3325605Skjc */ 3425605Skjc 3525605Skjc#ifndef _NFS_NFSPORT_H_ 36157985Srwatson#define _NFS_NFSPORT_H_ 3725605Skjc 3825605Skjc/* 39116189Sobrien * In general, I'm not fond of #includes in .h files, but this seems 40116189Sobrien * to be the cleanest way to handle #include files for the ports. 41116189Sobrien */ 4225605Skjc#ifdef _KERNEL 4395759Stanimura#include <sys/unistd.h> 4425605Skjc#include <sys/param.h> 4595759Stanimura#include <sys/systm.h> 4629024Sbde#include <sys/conf.h> 4725605Skjc#include <sys/dirent.h> 4895759Stanimura#include <sys/domain.h> 4995759Stanimura#include <sys/fcntl.h> 5025605Skjc#include <sys/file.h> 5125605Skjc#include <sys/filedesc.h> 5295759Stanimura#include <sys/jail.h> 5395759Stanimura#include <sys/kernel.h> 5495759Stanimura#include <sys/lockf.h> 55118541Sharti#include <sys/malloc.h> 5625605Skjc#include <sys/mbuf.h> 5725605Skjc#include <sys/mount.h> 5825605Skjc#include <sys/namei.h> 5925605Skjc#include <sys/proc.h> 6025605Skjc#include <sys/protosw.h> 6125605Skjc#include <sys/reboot.h> 6225605Skjc#include <sys/resourcevar.h> 6325605Skjc#include <sys/signalvar.h> 6425605Skjc#include <sys/socket.h> 65157985Srwatson#include <sys/socketvar.h> 66157985Srwatson#include <sys/stat.h> 6725605Skjc#include <sys/syslog.h> 68157985Srwatson#include <sys/sysproto.h> 69157985Srwatson#include <sys/time.h> 7025605Skjc#include <sys/uio.h> 71157985Srwatson#include <sys/vnode.h> 72157985Srwatson#include <sys/bio.h> 73157985Srwatson#include <sys/buf.h> 74157985Srwatson#include <sys/acl.h> 75157985Srwatson#include <sys/module.h> 76148125Srwatson#include <sys/sysent.h> 7725605Skjc#include <sys/syscall.h> 78157985Srwatson#include <sys/priv.h> 7925605Skjc#include <sys/kthread.h> 80157985Srwatson#include <sys/syscallsubr.h> 81157985Srwatson#include <fs/fifofs/fifo.h> 82157985Srwatson#include <net/if.h> 83157985Srwatson#include <net/radix.h> 84157985Srwatson#include <net/route.h> 85157985Srwatson#include <net/if_dl.h> 86157985Srwatson#include <netinet/in.h> 87157985Srwatson#include <netinet/in_pcb.h> 88157985Srwatson#include <netinet/in_systm.h> 89157985Srwatson#include <netinet/in_var.h> 90157985Srwatson#include <netinet/ip.h> 91157985Srwatson#include <netinet/ip_var.h> 92157985Srwatson#include <netinet/tcp.h> 93157985Srwatson#include <netinet/tcp_fsm.h> 94157985Srwatson#include <netinet/tcp_seq.h> 9525605Skjc#include <netinet/tcp_timer.h> 9625605Skjc#include <netinet/tcp_var.h> 9791458Speter#include <machine/in_cksum.h> 9825605Skjc#include <crypto/des/des.h> 99157985Srwatson#include <sys/md5.h> 100157985Srwatson#include <rpc/rpc.h> 10125605Skjc#include <rpc/rpcsec_gss.h> 102157985Srwatson 103157985Srwatson/* 10425605Skjc * For Darwin, these functions should be "static" when built in a kext. 105157985Srwatson * (This is always defined as nil otherwise.) 106157985Srwatson */ 107157985Srwatson#define APPLESTATIC 108157985Srwatson#include <ufs/ufs/dir.h> 109157985Srwatson#include <ufs/ufs/quota.h> 110157985Srwatson#include <ufs/ufs/inode.h> 111157985Srwatson#include <ufs/ufs/extattr.h> 112157985Srwatson#include <ufs/ufs/ufsmount.h> 113157985Srwatson#include <vm/uma.h> 114157985Srwatson#include <vm/vm.h> 115157985Srwatson#include <vm/vm_object.h> 116157985Srwatson#include <vm/vm_extern.h> 117157985Srwatson#include <nfs/nfssvc.h> 11825605Skjc#include "opt_nfs.h" 11925605Skjc#include "opt_ufs.h" 120157370Srwatson 12125605Skjc/* 12225605Skjc * These types must be defined before the nfs includes. 123157985Srwatson */ 12425605Skjc#define NFSSOCKADDR_T struct sockaddr * 125157985Srwatson#define NFSPROC_T struct thread 126157985Srwatson#define NFSDEV_T dev_t 127157983Srwatson#define NFSSVCARGS nfssvc_args 128157985Srwatson#define NFSACL_T struct acl 129157985Srwatson 130157985Srwatson/* 131157985Srwatson * These should be defined as the types used for the corresponding VOP's 13225605Skjc * argument type. 13325605Skjc */ 13425605Skjc#define NFS_ACCESS_ARGS struct vop_access_args 13591458Speter#define NFS_OPEN_ARGS struct vop_open_args 13625605Skjc#define NFS_GETATTR_ARGS struct vop_getattr_args 137157985Srwatson#define NFS_LOOKUP_ARGS struct vop_lookup_args 138157985Srwatson#define NFS_READDIR_ARGS struct vop_readdir_args 139157985Srwatson 140157985Srwatson/* 141157985Srwatson * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL. 142157985Srwatson */ 14325605Skjc#define NFSMGET(m) do { \ 144157985Srwatson MGET((m), M_TRYWAIT, MT_DATA); \ 145157985Srwatson while ((m) == NULL ) { \ 14625605Skjc (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 147157985Srwatson MGET((m), M_TRYWAIT, MT_DATA); \ 148157985Srwatson } \ 149157985Srwatson } while (0) 150157985Srwatson#define NFSMGETHDR(m) do { \ 151157985Srwatson MGETHDR((m), M_TRYWAIT, MT_DATA); \ 152157985Srwatson while ((m) == NULL ) { \ 153157985Srwatson (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 154157985Srwatson MGETHDR((m), M_TRYWAIT, MT_DATA); \ 155157985Srwatson } \ 156157985Srwatson } while (0) 157157985Srwatson#define NFSMCLGET(m, w) do { \ 158157985Srwatson MGET((m), M_TRYWAIT, MT_DATA); \ 159157985Srwatson while ((m) == NULL ) { \ 160157985Srwatson (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 16125605Skjc MGET((m), M_TRYWAIT, MT_DATA); \ 162157985Srwatson } \ 163118541Sharti MCLGET((m), (w)); \ 16425605Skjc } while (0) 165157985Srwatson#define NFSMCLGETHDR(m, w) do { \ 166157985Srwatson MGETHDR((m), M_TRYWAIT, MT_DATA); \ 167157985Srwatson while ((m) == NULL ) { \ 168157985Srwatson (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 169157985Srwatson MGETHDR((m), M_TRYWAIT, MT_DATA); \ 170157985Srwatson } \ 171157985Srwatson } while (0) 172157985Srwatson#define NFSMTOD mtod 173157985Srwatson 174157985Srwatson/* 175157985Srwatson * Client side constant for size of a lockowner name. 176157985Srwatson */ 17725605Skjc#define NFSV4CL_LOCKNAMELEN 12 178157985Srwatson 179157985Srwatson/* 180157985Srwatson * Type for a mutex lock. 181157985Srwatson */ 182157985Srwatson#define NFSMUTEX_T struct mtx 183157985Srwatson 184157985Srwatson#endif /* _KERNEL */ 185157985Srwatson 186157985Srwatson/* 187157985Srwatson * NFSv4 Operation numbers. 188157985Srwatson */ 189157985Srwatson#define NFSV4OP_ACCESS 3 190157985Srwatson#define NFSV4OP_CLOSE 4 191157985Srwatson#define NFSV4OP_COMMIT 5 192157985Srwatson#define NFSV4OP_CREATE 6 193157985Srwatson#define NFSV4OP_DELEGPURGE 7 194157985Srwatson#define NFSV4OP_DELEGRETURN 8 195157985Srwatson#define NFSV4OP_GETATTR 9 196157985Srwatson#define NFSV4OP_GETFH 10 197157985Srwatson#define NFSV4OP_LINK 11 198157985Srwatson#define NFSV4OP_LOCK 12 199157984Srwatson#define NFSV4OP_LOCKT 13 20025605Skjc#define NFSV4OP_LOCKU 14 201157985Srwatson#define NFSV4OP_LOOKUP 15 202157985Srwatson#define NFSV4OP_LOOKUPP 16 203157985Srwatson#define NFSV4OP_NVERIFY 17 204157985Srwatson#define NFSV4OP_OPEN 18 205157985Srwatson#define NFSV4OP_OPENATTR 19 206157985Srwatson#define NFSV4OP_OPENCONFIRM 20 207148125Srwatson#define NFSV4OP_OPENDOWNGRADE 21 208157985Srwatson#define NFSV4OP_PUTFH 22 209157985Srwatson#define NFSV4OP_PUTPUBFH 23 21025605Skjc#define NFSV4OP_PUTROOTFH 24 21125605Skjc#define NFSV4OP_READ 25 21225605Skjc#define NFSV4OP_READDIR 26 21325605Skjc#define NFSV4OP_READLINK 27 21425605Skjc#define NFSV4OP_REMOVE 28 215157985Srwatson#define NFSV4OP_RENAME 29 216157985Srwatson#define NFSV4OP_RENEW 30 217157985Srwatson#define NFSV4OP_RESTOREFH 31 218157985Srwatson#define NFSV4OP_SAVEFH 32 21925605Skjc#define NFSV4OP_SECINFO 33 220157985Srwatson#define NFSV4OP_SETATTR 34 221157985Srwatson#define NFSV4OP_SETCLIENTID 35 22225605Skjc#define NFSV4OP_SETCLIENTIDCFRM 36 223157985Srwatson#define NFSV4OP_VERIFY 37 224157985Srwatson#define NFSV4OP_WRITE 38 225157985Srwatson#define NFSV4OP_RELEASELCKOWN 39 226157985Srwatson 227157985Srwatson/* 228157985Srwatson * Must be one greater than the last Operation#. 229157985Srwatson */ 230157985Srwatson#define NFSV4OP_NOPS 40 231157985Srwatson 232157985Srwatson/* Quirky case if the illegal op code */ 233157985Srwatson#define NFSV4OP_OPILLEGAL 10044 234157985Srwatson 235157985Srwatson/* 236157985Srwatson * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV4OP_NOPS. 237157985Srwatson */ 238157984Srwatson#define NFSV4OP_SYMLINK (NFSV4OP_NOPS) 239157985Srwatson#define NFSV4OP_MKDIR (NFSV4OP_NOPS + 1) 240157985Srwatson#define NFSV4OP_RMDIR (NFSV4OP_NOPS + 2) 241157985Srwatson#define NFSV4OP_READDIRPLUS (NFSV4OP_NOPS + 3) 242157985Srwatson#define NFSV4OP_MKNOD (NFSV4OP_NOPS + 4) 243157985Srwatson#define NFSV4OP_FSSTAT (NFSV4OP_NOPS + 5) 244157985Srwatson#define NFSV4OP_FSINFO (NFSV4OP_NOPS + 6) 245157985Srwatson#define NFSV4OP_PATHCONF (NFSV4OP_NOPS + 7) 24625605Skjc#define NFSV4OP_V3CREATE (NFSV4OP_NOPS + 8) 24725605Skjc 24825605Skjc/* 24925605Skjc * This is the count of the fake operations listed above. 25025605Skjc */ 251157985Srwatson#define NFSV4OP_FAKENOPS 9 252157985Srwatson 253157985Srwatson/* 25425605Skjc * and the Callback OPs 25525605Skjc */ 25625605Skjc#define NFSV4OP_CBGETATTR 3 25728270Swollman#define NFSV4OP_CBRECALL 4 258157985Srwatson 25925605Skjc/* 260157985Srwatson * Must be one greater than the last Callback Operation#. 261157985Srwatson */ 262157985Srwatson#define NFSV4OP_CBNOPS 5 263157985Srwatson 26425605Skjc/* 265157985Srwatson * The lower numbers -> 21 are used by NFSv2 and v3. These define higher 266157985Srwatson * numbers used by NFSv4. 26725605Skjc * NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is 268157985Srwatson * one greater than the last number. 269157985Srwatson */ 270157985Srwatson#define NFS_V3NPROCS 22 271157985Srwatson 272157985Srwatson#define NFSPROC_LOOKUPP 22 273157985Srwatson#define NFSPROC_SETCLIENTID 23 274157985Srwatson#define NFSPROC_SETCLIENTIDCFRM 24 27525605Skjc#define NFSPROC_LOCK 25 276157985Srwatson#define NFSPROC_LOCKU 26 277157985Srwatson#define NFSPROC_OPEN 27 278157985Srwatson#define NFSPROC_CLOSE 28 279157985Srwatson#define NFSPROC_OPENCONFIRM 29 280157985Srwatson#define NFSPROC_LOCKT 30 281157985Srwatson#define NFSPROC_OPENDOWNGRADE 31 282157985Srwatson#define NFSPROC_RENEW 32 283157985Srwatson#define NFSPROC_PUTROOTFH 33 284157985Srwatson#define NFSPROC_RELEASELCKOWN 34 285157985Srwatson#define NFSPROC_DELEGRETURN 35 286157985Srwatson#define NFSPROC_RETDELEGREMOVE 36 287157985Srwatson#define NFSPROC_RETDELEGRENAME1 37 288157985Srwatson#define NFSPROC_RETDELEGRENAME2 38 289157985Srwatson#define NFSPROC_GETACL 39 290157984Srwatson#define NFSPROC_SETACL 40 291157985Srwatson 29225605Skjc/* 29325605Skjc * Must be defined as one higher than the last Proc# above. 29425605Skjc */ 29528270Swollman#define NFSV4_NPROCS 41 29625605Skjc 297157985Srwatson/* 298157985Srwatson * Stats structure 29925605Skjc */ 300157985Srwatsonstruct ext_nfsstats { 301157985Srwatson int attrcache_hits; 30225605Skjc int attrcache_misses; 303157985Srwatson int lookupcache_hits; 304157985Srwatson int lookupcache_misses; 305157985Srwatson int direofcache_hits; 306157985Srwatson int direofcache_misses; 307157985Srwatson int accesscache_hits; 308157985Srwatson int accesscache_misses; 309157985Srwatson int biocache_reads; 310157985Srwatson int read_bios; 311157985Srwatson int read_physios; 312157985Srwatson int biocache_writes; 313157985Srwatson int write_bios; 314157985Srwatson int write_physios; 31525605Skjc int biocache_readlinks; 31625605Skjc int readlink_bios; 31725605Skjc int biocache_readdirs; 31836735Sdfr int readdir_bios; 319157985Srwatson int rpccnt[NFSV4_NPROCS]; 32025605Skjc int rpcretries; 321157985Srwatson int srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS]; 322157985Srwatson int srvrpc_errs; 32325605Skjc int srv_errs; 324157985Srwatson int rpcrequests; 325157985Srwatson int rpctimeouts; 32625605Skjc int rpcunexpected; 327157985Srwatson int rpcinvalid; 328157985Srwatson int srvcache_inproghits; 329157985Srwatson int srvcache_idemdonehits; 330157985Srwatson int srvcache_nonidemdonehits; 331157985Srwatson int srvcache_misses; 332157985Srwatson int srvcache_tcppeak; 33325605Skjc int srvcache_size; 33425605Skjc int srvclients; 335157366Srwatson int srvopenowners; 33625605Skjc int srvopens; 33725605Skjc int srvlockowners; 338157985Srwatson int srvlocks; 33925605Skjc int srvdelegates; 34025605Skjc int cbrpccnt[NFSV4OP_CBNOPS]; 341160549Srwatson int clopenowners; 342160549Srwatson int clopens; 343160549Srwatson int cllockowners; 344160549Srwatson int cllocks; 345160549Srwatson int cldelegates; 346160549Srwatson int cllocalopenowners; 34725605Skjc int cllocalopens; 34891458Speter int cllocallockowners; 34925605Skjc int cllocallocks; 350157985Srwatson}; 351157985Srwatson 35225605Skjc#ifdef _KERNEL 35325605Skjc/* 35425605Skjc * Define the ext_nfsstats as nfsstats for the kernel code. 35528270Swollman */ 35625605Skjc#define nfsstats ext_nfsstats 357157985Srwatson 358157985Srwatson/* 35925605Skjc * Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code. 36025605Skjc */ 36125605Skjc#define NFS_NPROCS NFSV4_NPROCS 36225605Skjc 363137386Sphk#include <fs/nfs/nfskpiport.h> 364137386Sphk#include <fs/nfs/nfsdport.h> 365137386Sphk#include <fs/nfs/rpcv2.h> 366137386Sphk#include <fs/nfs/nfsproto.h> 367137386Sphk#include <fs/nfs/nfs.h> 368137386Sphk#include <fs/nfs/nfs_var.h> 369137386Sphk#include <fs/nfs/nfsm_subs.h> 370137386Sphk#include <fs/nfs/nfsrvcache.h> 371137386Sphk#include <fs/nfs/nfsrvstate.h> 372137386Sphk#include <fs/nfs/xdr_subs.h> 373137386Sphk#include <fs/nfs/nfscl.h> 374160549Srwatson#include <fs/nfs/nfsclstate.h> 37525605Skjc#include <fs/nfsclient/nfsargs.h> 37625605Skjc#include <fs/nfsclient/nfsmount.h> 37725605Skjc 378148158Srwatson/* 37925605Skjc * Just to keep nfs_var.h happy. 380157985Srwatson */ 381157985Srwatsonstruct nfs_vattr { 382157985Srwatson int junk; 38325605Skjc}; 38425605Skjc 385111888Sjlemonstruct nfsvattr { 38625605Skjc struct vattr na_vattr; 387118541Sharti nfsattrbit_t na_suppattr; 388118541Sharti u_int32_t na_mntonfileno; 38925605Skjc u_int64_t na_filesid[2]; 39025605Skjc}; 391118541Sharti 39225605Skjc#define na_type na_vattr.va_type 39325605Skjc#define na_mode na_vattr.va_mode 394148125Srwatson#define na_nlink na_vattr.va_nlink 395118541Sharti#define na_uid na_vattr.va_uid 396118541Sharti#define na_gid na_vattr.va_gid 39725605Skjc#define na_fsid na_vattr.va_fsid 398118541Sharti#define na_fileid na_vattr.va_fileid 39925605Skjc#define na_size na_vattr.va_size 400118541Sharti#define na_blocksize na_vattr.va_blocksize 401118541Sharti#define na_atime na_vattr.va_atime 402118541Sharti#define na_mtime na_vattr.va_mtime 403148125Srwatson#define na_ctime na_vattr.va_ctime 404148125Srwatson#define na_gen na_vattr.va_gen 405118541Sharti#define na_flags na_vattr.va_flags 406118541Sharti#define na_rdev na_vattr.va_rdev 40725605Skjc#define na_bytes na_vattr.va_bytes 408118541Sharti#define na_filerev na_vattr.va_filerev 409148125Srwatson#define na_vaflags na_vattr.va_vaflags 410118541Sharti 411118541Sharti#include <fs/nfsclient/nfsnode.h> 412118541Sharti 41325605Skjc/* 41425605Skjc * This is the header structure used for the lists, etc. (It has the 415118541Sharti * above record in it. 41625605Skjc */ 41725605Skjcstruct nfsrv_stablefirst { 418118541Sharti LIST_HEAD(, nfsrv_stable) nsf_head; /* Head of nfsrv_stable list */ 41925605Skjc time_t nsf_eograce; /* Time grace period ends */ 42025605Skjc time_t *nsf_bootvals; /* Previous boottime values */ 42125605Skjc struct file *nsf_fp; /* File table pointer */ 422118547Sharti u_char nsf_flags; /* NFSNSF_ flags */ 42325605Skjc struct nfsf_rec nsf_rec; /* and above first record */ 424118541Sharti}; 425118541Sharti#define nsf_lease nsf_rec.lease 42625605Skjc#define nsf_numboots nsf_rec.numboots 427118541Sharti 428118541Sharti/* NFSNSF_xxx flags */ 429148125Srwatson#define NFSNSF_UPDATEDONE 0x01 430118541Sharti#define NFSNSF_GRACEOVER 0x02 43125605Skjc#define NFSNSF_NEEDLOCK 0x04 432118541Sharti#define NFSNSF_EXPIREDCLIENT 0x08 433118541Sharti#define NFSNSF_NOOPENS 0x10 43425605Skjc#define NFSNSF_OK 0x20 435148125Srwatson 436118541Sharti/* 437118541Sharti * Maximum number of boot times allowed in record. Although there is 43825605Skjc * really no need for a fixed upper bound, this serves as a sanity check 43925605Skjc * for a corrupted file. 44025605Skjc */ 44125605Skjc#define NFSNSF_MAXNUMBOOTS 10000 44225605Skjc 44325605Skjc/* 444118541Sharti * This structure defines the other records in the file. The 445118541Sharti * nst_client array is actually the size of the client string name. 44625605Skjc */ 447157985Srwatsonstruct nfst_rec { 448118541Sharti u_int16_t len; 449118541Sharti u_char flag; 45025605Skjc u_char client[1]; 45125605Skjc}; 45225605Skjc/* and the values for flag */ 45325605Skjc#define NFSNST_NEWSTATE 0x1 45425605Skjc#define NFSNST_REVOKE 0x2 45525605Skjc#define NFSNST_GOTSTATE 0x4 456118541Sharti 457118541Sharti/* 45825605Skjc * This structure is linked onto nfsrv_stablefirst for the duration of 459157985Srwatson * reclaim. 460118541Sharti */ 461118541Shartistruct nfsrv_stable { 46225605Skjc LIST_ENTRY(nfsrv_stable) nst_list; 463 struct nfsclient *nst_clp; 464 struct nfst_rec nst_rec; 465}; 466#define nst_timestamp nst_rec.timestamp 467#define nst_len nst_rec.len 468#define nst_flag nst_rec.flag 469#define nst_client nst_rec.client 470 471/* 472 * At some point the server will run out of kernel storage for 473 * state structures. For FreeBSD5.2, this results in a panic 474 * kmem_map is full. It happens at well over 1000000 opens plus 475 * locks on a PIII-800 with 256Mbytes, so that is where I've set 476 * the limit. If your server panics due to too many opens/locks, 477 * decrease the size of NFSRV_V4STATELIMIT. If you find the server 478 * returning NFS4ERR_RESOURCE a lot and have lots of memory, try 479 * increasing it. 480 */ 481#define NFSRV_V4STATELIMIT 500000 /* Max # of Opens + Locks */ 482 483/* 484 * The type required differs with BSDen (just the second arg). 485 */ 486void nfsrvd_rcv(struct socket *, void *, int); 487 488/* 489 * Macros for handling socket addresses. (Hopefully this makes the code 490 * more portable, since I've noticed some 'BSD don't have sockaddrs in 491 * mbufs any more.) 492 */ 493#define NFSSOCKADDR(a, t) ((t)(a)) 494#define NFSSOCKADDRALLOC(a) \ 495 do { \ 496 MALLOC((a), struct sockaddr *, sizeof (struct sockaddr), \ 497 M_SONAME, M_WAITOK); \ 498 NFSBZERO((a), sizeof (struct sockaddr)); \ 499 } while (0) 500#define NFSSOCKADDRSIZE(a, s) ((a)->sa_len = (s)) 501#define NFSSOCKADDRFREE(a) \ 502 do { \ 503 if (a) \ 504 FREE((caddr_t)(a), M_SONAME); \ 505 } while (0) 506 507/* 508 * These should be defined as a process or thread structure, as required 509 * for signal handling, etc. 510 */ 511#define NFSNEWCRED(c) (crdup(c)) 512#define NFSPROCCRED(p) ((p)->td_ucred) 513#define NFSFREECRED(c) (crfree(c)) 514#define NFSUIOPROC(u, p) ((u)->uio_td = NULL) 515#define NFSPROCP(p) ((p)->td_proc) 516 517/* 518 * Define these so that cn_hash and its length is ignored. 519 */ 520#define NFSCNHASHZERO(c) 521#define NFSCNHASH(c, v) 522#define NCHNAMLEN 9999999 523 524/* 525 * Define these to use the time of day clock. 526 */ 527#define NFSGETTIME(t) (getmicrotime(t)) 528#define NFSGETNANOTIME(t) (getnanotime(t)) 529 530/* 531 * These macros are defined to initialize and set the timer routine. 532 */ 533#define NFS_TIMERINIT \ 534 newnfs_timer(NULL) 535 536/* 537 * Handle SMP stuff: 538 */ 539#define NFSSTATESPINLOCK extern struct mtx nfs_state_mutex 540#define NFSLOCKSTATE() mtx_lock(&nfs_state_mutex) 541#define NFSUNLOCKSTATE() mtx_unlock(&nfs_state_mutex) 542#define NFSSTATEMUTEXPTR (&nfs_state_mutex) 543#define NFSREQSPINLOCK extern struct mtx nfs_req_mutex 544#define NFSLOCKREQ() mtx_lock(&nfs_req_mutex) 545#define NFSUNLOCKREQ() mtx_unlock(&nfs_req_mutex) 546#define NFSCACHEMUTEX extern struct mtx nfs_cache_mutex 547#define NFSCACHEMUTEXPTR (&nfs_cache_mutex) 548#define NFSLOCKCACHE() mtx_lock(&nfs_cache_mutex) 549#define NFSUNLOCKCACHE() mtx_unlock(&nfs_cache_mutex) 550#define NFSCACHELOCKREQUIRED() mtx_assert(&nfs_cache_mutex, MA_OWNED) 551#define NFSSOCKMUTEX extern struct mtx nfs_slock_mutex 552#define NFSSOCKMUTEXPTR (&nfs_slock_mutex) 553#define NFSLOCKSOCK() mtx_lock(&nfs_slock_mutex) 554#define NFSUNLOCKSOCK() mtx_unlock(&nfs_slock_mutex) 555#define NFSNAMEIDMUTEX extern struct mtx nfs_nameid_mutex 556#define NFSLOCKNAMEID() mtx_lock(&nfs_nameid_mutex) 557#define NFSUNLOCKNAMEID() mtx_unlock(&nfs_nameid_mutex) 558#define NFSNAMEIDREQUIRED() mtx_assert(&nfs_nameid_mutex, MA_OWNED) 559#define NFSCLSTATEMUTEX extern struct mtx nfs_clstate_mutex 560#define NFSCLSTATEMUTEXPTR (&nfs_clstate_mutex) 561#define NFSLOCKCLSTATE() mtx_lock(&nfs_clstate_mutex) 562#define NFSUNLOCKCLSTATE() mtx_unlock(&nfs_clstate_mutex) 563#define NFSDLOCKMUTEX extern struct mtx newnfsd_mtx 564#define NFSDLOCKMUTEXPTR (&newnfsd_mtx) 565#define NFSD_LOCK() mtx_lock(&newnfsd_mtx) 566#define NFSD_UNLOCK() mtx_unlock(&newnfsd_mtx) 567#define NFSD_LOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_OWNED) 568#define NFSD_UNLOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_NOTOWNED) 569#define NFSV4ROOTLOCKMUTEX extern struct mtx nfs_v4root_mutex 570#define NFSV4ROOTLOCKMUTEXPTR (&nfs_v4root_mutex) 571#define NFSLOCKV4ROOTMUTEX() mtx_lock(&nfs_v4root_mutex) 572#define NFSUNLOCKV4ROOTMUTEX() mtx_unlock(&nfs_v4root_mutex) 573#define NFSLOCKNODE(n) mtx_lock(&((n)->n_mtx)) 574#define NFSUNLOCKNODE(n) mtx_unlock(&((n)->n_mtx)) 575#define NFSLOCKMNT(m) mtx_lock(&((m)->nm_mtx)) 576#define NFSUNLOCKMNT(m) mtx_unlock(&((m)->nm_mtx)) 577#define NFSLOCKREQUEST(r) mtx_lock(&((r)->r_mtx)) 578#define NFSUNLOCKREQUEST(r) mtx_unlock(&((r)->r_mtx)) 579#define NFSPROCLISTLOCK() sx_slock(&allproc_lock) 580#define NFSPROCLISTUNLOCK() sx_sunlock(&allproc_lock) 581#define NFSLOCKSOCKREQ(r) mtx_lock(&((r)->nr_mtx)) 582#define NFSUNLOCKSOCKREQ(r) mtx_unlock(&((r)->nr_mtx)) 583 584/* 585 * Use these macros to initialize/free a mutex. 586 */ 587#define NFSINITSOCKMUTEX(m) mtx_init((m), "nfssock", NULL, MTX_DEF) 588#define NFSFREEMUTEX(m) mtx_destroy((m)) 589 590int nfsmsleep(void *, void *, int, const char *, struct timespec *); 591 592/* 593 * And weird vm stuff in the nfs server. 594 */ 595#define PDIRUNLOCK 0x0 596#define MAX_COMMIT_COUNT (1024 * 1024) 597 598/* 599 * Define these to handle the type of va_rdev. 600 */ 601#define NFSMAKEDEV(m, n) makedev((m), (n)) 602#define NFSMAJOR(d) major(d) 603#define NFSMINOR(d) minor(d) 604 605/* 606 * Define this to be the macro that returns the minimum size required 607 * for a directory entry. 608 */ 609#define DIRENT_SIZE(dp) GENERIC_DIRSIZ(dp) 610 611/* 612 * The vnode tag for nfsv4root. 613 */ 614#define VT_NFSV4ROOT "nfsv4root" 615 616/* 617 * Define whatever it takes to do a vn_rdwr(). 618 */ 619#define NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \ 620 vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p)) 621 622/* 623 * Macros for handling memory for different BSDen. 624 * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping 625 * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap 626 * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same 627 * NFSBZERO(cp, len) - set len bytes to 0x0 628 */ 629#define NFSBCOPY(s, d, l) bcopy((s), (d), (l)) 630#define NFSOVBCOPY(s, d, l) ovbcopy((s), (d), (l)) 631#define NFSBCMP(s, d, l) bcmp((s), (d), (l)) 632#define NFSBZERO(s, l) bzero((s), (l)) 633 634/* 635 * Some queue.h files don't have these dfined in them. 636 */ 637#define LIST_END(head) NULL 638#define SLIST_END(head) NULL 639#define TAILQ_END(head) NULL 640 641/* 642 * This must be defined to be a global variable that increments once 643 * per second, but never stops or goes backwards, even when a "date" 644 * command changes the TOD clock. It is used for delta times for 645 * leases, etc. 646 */ 647#define NFSD_MONOSEC time_uptime 648 649/* 650 * Declare the malloc types. 651 */ 652MALLOC_DECLARE(M_NEWNFSRVCACHE); 653MALLOC_DECLARE(M_NEWNFSDCLIENT); 654MALLOC_DECLARE(M_NEWNFSDSTATE); 655MALLOC_DECLARE(M_NEWNFSDLOCK); 656MALLOC_DECLARE(M_NEWNFSDLOCKFILE); 657MALLOC_DECLARE(M_NEWNFSSTRING); 658MALLOC_DECLARE(M_NEWNFSUSERGROUP); 659MALLOC_DECLARE(M_NEWNFSDREQ); 660MALLOC_DECLARE(M_NEWNFSFH); 661MALLOC_DECLARE(M_NEWNFSCLOWNER); 662MALLOC_DECLARE(M_NEWNFSCLOPEN); 663MALLOC_DECLARE(M_NEWNFSCLDELEG); 664MALLOC_DECLARE(M_NEWNFSCLCLIENT); 665MALLOC_DECLARE(M_NEWNFSCLLOCKOWNER); 666MALLOC_DECLARE(M_NEWNFSCLLOCK); 667MALLOC_DECLARE(M_NEWNFSDIROFF); 668MALLOC_DECLARE(M_NEWNFSV4NODE); 669MALLOC_DECLARE(M_NEWNFSDIRECTIO); 670MALLOC_DECLARE(M_NEWNFSMNT); 671MALLOC_DECLARE(M_NEWNFSDROLLBACK); 672#define M_NFSRVCACHE M_NEWNFSRVCACHE 673#define M_NFSDCLIENT M_NEWNFSDCLIENT 674#define M_NFSDSTATE M_NEWNFSDSTATE 675#define M_NFSDLOCK M_NEWNFSDLOCK 676#define M_NFSDLOCKFILE M_NEWNFSDLOCKFILE 677#define M_NFSSTRING M_NEWNFSSTRING 678#define M_NFSUSERGROUP M_NEWNFSUSERGROUP 679#define M_NFSDREQ M_NEWNFSDREQ 680#define M_NFSFH M_NEWNFSFH 681#define M_NFSCLOWNER M_NEWNFSCLOWNER 682#define M_NFSCLOPEN M_NEWNFSCLOPEN 683#define M_NFSCLDELEG M_NEWNFSCLDELEG 684#define M_NFSCLCLIENT M_NEWNFSCLCLIENT 685#define M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER 686#define M_NFSCLLOCK M_NEWNFSCLLOCK 687#define M_NFSDIROFF M_NEWNFSDIROFF 688#define M_NFSV4NODE M_NEWNFSV4NODE 689#define M_NFSDIRECTIO M_NEWNFSDIRECTIO 690#define M_NFSDROLLBACK M_NEWNFSDROLLBACK 691 692#define NFSINT_SIGMASK(set) \ 693 (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 694 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 695 SIGISMEMBER(set, SIGQUIT)) 696 697/* 698 * Convert a quota block count to byte count. 699 */ 700#define NFSQUOTABLKTOBYTE(q, b) (q) *= (b) 701 702/* 703 * Define this as the largest file size supported. (It should probably 704 * be available via a VFS_xxx Op, but it isn't. 705 */ 706#define NFSRV_MAXFILESIZE ((u_int64_t)0x800000000000) 707 708/* 709 * Set this macro to index() or strchr(), whichever is supported. 710 */ 711#define STRCHR(s, c) index((s), (c)) 712 713/* 714 * Set the n_time in the client write rpc, as required. 715 */ 716#define NFSWRITERPC_SETTIME(w, n, v4) \ 717 do { \ 718 if (w) { \ 719 (n)->n_mtime = (n)->n_vattr.na_vattr.va_mtime; \ 720 if (v4) \ 721 (n)->n_change = (n)->n_vattr.na_vattr.va_filerev; \ 722 } \ 723 } while (0) 724 725/* 726 * Fake value, just to make the client work. 727 */ 728#define NFS_LATTR_NOSHRINK 1 729 730/* 731 * Prototypes for functions where the arguments vary for different ports. 732 */ 733int nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *, 734 int, int); 735void newnfs_realign(struct mbuf **); 736 737/* 738 * If the port runs on an SMP box that can enforce Atomic ops with low 739 * overheads, define these as atomic increments/decrements. If not, 740 * don't worry about it, since these are used for stats that can be 741 * "out by one" without disastrous consequences. 742 */ 743#define NFSINCRGLOBAL(a) ((a)++) 744 745/* 746 * Assorted funky stuff to make things work under Darwin8. 747 */ 748/* 749 * These macros checks for a field in vattr being set. 750 */ 751#define NFSATTRISSET(t, v, a) ((v)->a != (t)VNOVAL) 752#define NFSATTRISSETTIME(v, a) ((v)->a.tv_sec != VNOVAL) 753 754/* 755 * Manipulate mount flags. 756 */ 757#define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier */ 758#define NFSSTA_GOTFSINFO 0x00100000 /* Got the fsinfo */ 759#define NFSSTA_TIMEO 0x10000000 /* Experiencing a timeout */ 760#define NFSSTA_LOCKTIMEO 0x20000000 /* Experiencing a lockd timeout */ 761#define NFSSTA_HASSETFSID 0x40000000 /* Has set the fsid */ 762 763#define NFSHASNFSV3(n) ((n)->nm_flag & NFSMNT_NFSV3) 764#define NFSHASNFSV4(n) ((n)->nm_flag & NFSMNT_NFSV4) 765#define NFSHASNFSV3OR4(n) ((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4)) 766#define NFSHASGOTFSINFO(n) ((n)->nm_state & NFSSTA_GOTFSINFO) 767#define NFSHASHASSETFSID(n) ((n)->nm_state & NFSSTA_HASSETFSID) 768#define NFSHASSTRICT3530(n) ((n)->nm_flag & NFSMNT_STRICT3530) 769#define NFSHASWRITEVERF(n) ((n)->nm_state & NFSSTA_HASWRITEVERF) 770#define NFSHASINT(n) ((n)->nm_flag & NFSMNT_INT) 771#define NFSHASSOFT(n) ((n)->nm_flag & NFSMNT_SOFT) 772#define NFSHASINTORSOFT(n) ((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT)) 773#define NFSHASDUMBTIMR(n) ((n)->nm_flag & NFSMNT_DUMBTIMR) 774#define NFSHASNOCONN(n) ((n)->nm_flag & NFSMNT_MNTD) 775#define NFSHASKERB(n) ((n)->nm_flag & NFSMNT_KERB) 776#define NFSHASALLGSSNAME(n) ((n)->nm_flag & NFSMNT_ALLGSSNAME) 777#define NFSHASINTEGRITY(n) ((n)->nm_flag & NFSMNT_INTEGRITY) 778#define NFSHASPRIVACY(n) ((n)->nm_flag & NFSMNT_PRIVACY) 779#define NFSSETWRITEVERF(n) ((n)->nm_state |= NFSSTA_HASWRITEVERF) 780#define NFSSETHASSETFSID(n) ((n)->nm_state |= NFSSTA_HASSETFSID) 781 782/* 783 * Gets the stats field out of the mount structure. 784 */ 785#define vfs_statfs(m) (&((m)->mnt_stat)) 786 787/* 788 * Set boottime. 789 */ 790#define NFSSETBOOTTIME(b) ((b) = boottime) 791 792/* 793 * The size of directory blocks in the buffer cache. 794 * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!! 795 */ 796#define NFS_DIRBLKSIZ (16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */ 797 798/* 799 * Define these macros to access mnt_flag fields. 800 */ 801#define NFSMNT_RDONLY(m) ((m)->mnt_flag & MNT_RDONLY) 802#endif /* _KERNEL */ 803 804/* 805 * Define a structure similar to ufs_args for use in exporting the V4 root. 806 */ 807struct nfsex_args { 808 char *fspec; 809 struct export_args export; 810}; 811 812/* 813 * These export flags should be defined, but there are no bits left. 814 * Maybe a separate mnt_exflag field could be added or the mnt_flag 815 * field increased to 64 bits? 816 */ 817#ifndef MNT_EXSTRICTACCESS 818#define MNT_EXSTRICTACCESS 0x0 819#endif 820#ifndef MNT_EXV4ONLY 821#define MNT_EXV4ONLY 0x0 822#endif 823 824#ifdef _KERNEL 825/* 826 * Define this to invalidate the attribute cache for the nfs node. 827 */ 828#define NFSINVALATTRCACHE(n) ((n)->n_attrstamp = 0) 829 830/* Used for FreeBSD only */ 831void nfsd_mntinit(void); 832 833/* 834 * Define these for vnode lock/unlock ops. 835 */ 836#define NFSVOPLOCK(v, f, p) vn_lock((v), (f)) 837#define NFSVOPUNLOCK(v, f, p) VOP_UNLOCK((v), (f)) 838#define NFSVOPISLOCKED(v, p) VOP_ISLOCKED((v)) 839 840/* 841 * Define ncl_hash(). 842 */ 843#define ncl_hash(f, l) (fnv_32_buf((f), (l), FNV1_32_INIT)) 844 845int newnfs_iosize(struct nfsmount *); 846 847#ifdef NFS_DEBUG 848 849extern int nfs_debug; 850#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 851#define NFS_DEBUG_WG 2 /* server write gathering */ 852#define NFS_DEBUG_RC 4 /* server request caching */ 853 854#define NFS_DPF(cat, args) \ 855 do { \ 856 if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 857 } while (0) 858 859#else 860 861#define NFS_DPF(cat, args) 862 863#endif 864 865int newnfs_vncmpf(struct vnode *, void *); 866 867#ifndef NFS_MINDIRATTRTIMO 868#define NFS_MINDIRATTRTIMO 3 /* VDIR attrib cache timeout in sec */ 869#endif 870#ifndef NFS_MAXDIRATTRTIMO 871#define NFS_MAXDIRATTRTIMO 60 872#endif 873 874/* 875 * Nfs outstanding request list element 876 */ 877struct nfsreq { 878 TAILQ_ENTRY(nfsreq) r_chain; 879 u_int32_t r_flags; /* flags on request, see below */ 880 struct nfsmount *r_nmp; /* Client mnt ptr */ 881 struct mtx r_mtx; /* Mutex lock for this structure */ 882}; 883 884#ifndef NFS_MAXBSIZE 885#define NFS_MAXBSIZE MAXBSIZE 886#endif 887 888/* 889 * This macro checks to see if issuing of delegations is allowed for this 890 * vnode. 891 */ 892#ifdef VV_DISABLEDELEG 893#define NFSVNO_DELEGOK(v) \ 894 ((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0) 895#else 896#define NFSVNO_DELEGOK(v) (1) 897#endif 898 899/* 900 * Define this as the flags argument for msleep() when catching signals 901 * while holding a resource that other threads would block for, such as 902 * a vnode lock. 903 */ 904#define NFS_PCATCH (PCATCH | PBDRY) 905 906#endif /* _KERNEL */ 907 908#endif /* _NFS_NFSPORT_H */ 909