3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  24  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  25  * Copyright (c) 2013 by Delphix. All rights reserved.
  26  */
  27 
  28 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  29 /*        All Rights Reserved   */
  30 
  31 #ifndef _NFS_NFS_H
  32 #define _NFS_NFS_H
  33 
  34 /*      nfs.h 2.38 88/08/19 SMI         */
  35 
  36 #include <sys/isa_defs.h>
  37 #include <sys/vfs.h>
  38 #include <sys/stream.h>
  39 #include <rpc/types.h>
  40 #include <sys/types32.h>
  41 #ifdef _KERNEL
  42 #include <rpc/rpc_rdma.h>
  43 #include <rpc/rpc.h>
  44 #include <sys/fcntl.h>
  45 #include <sys/kstat.h>
  46 #include <sys/dirent.h>
  47 #include <sys/zone.h>
  48 #include <sys/tsol/label.h>
  49 #include <sys/nvpair.h>
  50 #include <nfs/mount.h>
  51 #include <sys/vfs_opreg.h>
  52 #endif
  53 #include <vm/page.h>
  54 #include <rpc/rpc_sztypes.h>
  55 #include <sys/sysmacros.h>
  56 #ifdef  __cplusplus
  57 extern "C" {
  58 #endif
  59 
  60 /*
  61  * remote file service numbers
  62  */
  63 #define NFS_PROGRAM     ((rpcprog_t)100003)
  64 #define NFS_VERSMIN     ((rpcvers_t)2)
  65 #define NFS_VERSMAX     ((rpcvers_t)4)
  66 #define NFS_VERSION     ((rpcvers_t)2)
  67 #define NFS_PORT        2049
  68 
  69 /*
  70  * Used to determine registration and service handling of versions
  71  */
  72 #define NFS_VERSMIN_DEFAULT     ((rpcvers_t)2)
  73 #define NFS_VERSMAX_DEFAULT     ((rpcvers_t)4)
  74 
  75 extern rpcvers_t nfs_versmin;
  76 extern rpcvers_t nfs_versmax;
  77 
  78 /*
  79  * Default delegation setting for the server ==> "on"
  80  */
  81 #define NFS_SERVER_DELEGATION_DEFAULT   (TRUE)
  82 
  83 /* Maximum size of data portion of a remote request */
  84 #define NFS_MAXDATA     8192
  85 #define NFS_MAXNAMLEN   255
  86 #define NFS_MAXPATHLEN  1024
  87 
  88 /*
  89  * Rpc retransmission parameters
  90  */
  91 #define NFS_TIMEO       11      /* initial timeout for clts in 10th of a sec */
  92 #define NFS_RETRIES     5       /* times to retry request */
  93 #define NFS_COTS_TIMEO  600     /* initial timeout for cots in 10th of a sec */
  94 
  95 /*
  96  * The value of UID_NOBODY/GID_NOBODY presented to the world via NFS.
  97  * UID_NOBODY/GID_NOBODY is translated to NFS_UID_NOBODY/NFS_GID_NOBODY
  98  * when being sent out over the network and NFS_UID_NOBODY/NFS_GID_NOBODY
 
 226  * we will not accept a negative value otw.
 227  *
 228  * So for nfsv2/3 (uint32_t):
 229  *
 230  * If nfs_allow_preepoch_time is
 231  * FALSE, the maximum time value is INT32_MAX for 32-bit kernels and
 232  * UINT32_MAX for 64-bit kernels (to allow times larger than 2038)
 233  * and the minimum is zero. Note that in that case, a 32-bit application
 234  * running on a 64-bit kernel will not be able to access files with
 235  * the larger time values.
 236  * If nfs_allow_preepoch_time is TRUE, the maximum time value is INT32_MAX
 237  * for both kernel configurations and the minimum is INT32_MIN.
 238  *
 239  * And for nfsv4 (int64_t):
 240  *
 241  * nfsv4 allows for negative values in the protocol, and has a 64-bit
 242  * time field, so nfs_allow_preepoch_time can be ignored.
 243  */
 244 #ifdef _KERNEL
 245 
 246 extern bool_t           nfs_allow_preepoch_time;
 247 
 248 #ifdef _LP64
 249 
 250 /*
 251  * If no negative otw values are allowed, may use the full 32-bits of the
 252  * time to represent time later than 2038, by presenting the value as an
 253  * unsigned (but this can only be used by 64-bit apps due to cstat32
 254  * restrictions). If negative values are allowed, cannot represent times
 255  * after 2038. Either way, all 32 bits have a valid representation.
 256  */
 257 
 258 /* Check if nfstime4 seconds (int64_t) can be stored in the system time */
 259 #define NFS4_TIME_OK(tt)        TRUE
 260 
 261 
 262 #define NFS3_TIME_OVERFLOW(tt)  (FALSE)
 263 #define NFS2_TIME_OVERFLOW(tt)  (FALSE)
 264 
 265 /*
 266  * check if a time_t (int64_t) is ok when preepoch times are allowed -
 
 
 598         nfsstat rl_status;                      /* status of symlink read */
 599         union {
 600                 struct nfssrok  rl_srok_u;      /* name of linked to */
 601         } rl_u;
 602 };
 603 #define rl_srok         rl_u.rl_srok_u
 604 #define rl_count        rl_u.rl_srok_u.srok_count
 605 #define rl_data         rl_u.rl_srok_u.srok_data
 606 
 607 
 608 /*
 609  * Arguments to readdir
 610  */
 611 struct nfsrddirargs {
 612         fhandle_t rda_fh;       /* directory handle */
 613         uint32_t rda_offset;    /* offset in directory (opaque) */
 614         uint32_t rda_count;     /* number of directory bytes to read */
 615 };
 616 
 617 /*
 618  * NFS_OK part of readdir result
 619  */
 620 struct nfsrdok {
 621         uint32_t rdok_offset;           /* next offset (opaque) */
 622         uint32_t rdok_size;             /* size in bytes of entries */
 623         bool_t  rdok_eof;               /* true if last entry is in result */
 624         struct dirent64 *rdok_entries;  /* variable number of entries */
 625 };
 626 
 627 /*
 628  * Readdir result
 629  */
 630 struct nfsrddirres {
 631         nfsstat rd_status;
 632         uint_t          rd_bufsize;     /* client request size (not xdr'ed) */
 633         union {
 634                 struct nfsrdok rd_rdok_u;
 635         } rd_u;
 636 };
 637 #define rd_rdok         rd_u.rd_rdok_u
 638 #define rd_offset       rd_u.rd_rdok_u.rdok_offset
 639 #define rd_size         rd_u.rd_rdok_u.rdok_size
 640 #define rd_eof          rd_u.rd_rdok_u.rdok_eof
 641 #define rd_entries      rd_u.rd_rdok_u.rdok_entries
 642 
 643 
 644 /*
 645  * Arguments for directory operations
 646  */
 647 struct nfsdiropargs {
 648         fhandle_t       *da_fhandle;    /* pointer to directory file handle */
 649         char            *da_name;       /* name (up to NFS_MAXNAMLEN bytes) */
 650         fhandle_t       da_fhandle_buf; /* directory file handle */
 651         int             da_flags;       /* flags, see below */
 652 };
 653 #define DA_FREENAME     1
 654 
 655 /*
 656  * NFS_OK part of directory operation result
 657  */
 658 struct  nfsdrok {
 659         fhandle_t       drok_fhandle;   /* result file handle */
 660         struct nfsfattr drok_attr;      /* result file attributes */
 661 };
 
 887 /*      function defs for NFS kernel */
 888 extern int      nfs_waitfor_purge_complete(vnode_t *);
 889 extern int      nfs_validate_caches(vnode_t *, cred_t *);
 890 extern void     nfs_purge_caches(vnode_t *, int, cred_t *);
 891 extern void     nfs_purge_rddir_cache(vnode_t *);
 892 extern void     nfs_attrcache(vnode_t *, struct nfsfattr *, hrtime_t);
 893 extern int      nfs_cache_fattr(vnode_t *, struct nfsfattr *, vattr_t *,
 894     hrtime_t, cred_t *);
 895 extern void     nfs_attr_cache(vnode_t *, vattr_t *, hrtime_t, cred_t *);
 896 extern void     nfs_attrcache_va(vnode_t *, struct vattr *);
 897 extern int      nfs_getattr_otw(vnode_t *, struct vattr *, cred_t *);
 898 extern int      nfsgetattr(vnode_t *, struct vattr *, cred_t *);
 899 extern int      nattr_to_vattr(vnode_t *, struct nfsfattr *, struct vattr *);
 900 extern void     nfs_async_manager(struct vfs *);
 901 extern void     nfs_async_manager_stop(struct vfs *);
 902 extern void     nfs_async_stop(struct vfs *);
 903 extern int      nfs_async_stop_sig(struct vfs *);
 904 extern int      nfs_clntinit(void);
 905 extern void     nfs_clntfini(void);
 906 extern int      nfstsize(void);
 907 extern int      nfs_srvinit(void);
 908 extern void     nfs_srvfini(void);
 909 extern int      vattr_to_sattr(struct vattr *, struct nfssattr *);
 910 extern void     setdiropargs(struct nfsdiropargs *, char *, vnode_t *);
 911 extern int      setdirgid(vnode_t *, gid_t *, cred_t *);
 912 extern int      setdirmode(vnode_t *, mode_t *, cred_t *);
 913 extern int      newnum(void);
 914 extern char     *newname(void);
 915 extern int      nfs_subrinit(void);
 916 extern void     nfs_subrfini(void);
 917 extern enum nfsstat puterrno(int);
 918 extern int      geterrno(enum nfsstat);
 919 extern int      nfsinit(int, char *);
 920 extern void     nfsfini(void);
 921 extern int      nfs_vfsinit(void);
 922 extern void     nfs_vfsfini(void);
 923 extern int      nfs_dump(vnode_t *, caddr_t, offset_t, offset_t,
 924     caller_context_t *);
 925 extern void     nfs_perror(int, char *, ...);
 926 extern void     nfs_cmn_err(int, int, char *, ...);
 927 extern int      nfs_addcllock(vnode_t *, struct flock64 *);
 
 
 940 extern void     sv_free(struct servinfo *);
 941 extern int      nfsauth_access(struct exportinfo *, struct svc_req *, cred_t *,
 942     uid_t *, gid_t *, uint_t *, gid_t **);
 943 extern void     nfsauth_init(void);
 944 extern void     nfsauth_fini(void);
 945 extern int      nfs_setopts(vnode_t *, model_t, struct nfs_args *);
 946 extern int      nfs_mount_label_policy(vfs_t *, struct netbuf *,
 947     struct knetconfig *, cred_t *);
 948 extern boolean_t nfs_has_ctty(void);
 949 extern void     nfs_srv_stop_all(void);
 950 extern void     nfs_srv_quiesce_all(void);
 951 extern int      rfs4_dss_setpaths(char *, size_t);
 952 extern int      nfs_setmod_check(page_t *);
 953 
 954 extern time_t   rfs4_lease_time;
 955 extern time_t   rfs4_grace_period;
 956 extern nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
 957 
 958 extern kstat_named_t    *global_svstat_ptr[];
 959 
 960 extern krwlock_t        rroklock;
 961 extern vtype_t          nf_to_vt[];
 962 extern kstat_named_t    *rfsproccnt_v2_ptr;
 963 extern kmutex_t         nfs_minor_lock;
 964 extern int              nfs_major;
 965 extern int              nfs_minor;
 966 extern vfsops_t         *nfs_vfsops;
 967 extern struct vnodeops  *nfs_vnodeops;
 968 extern const struct fs_operation_def nfs_vnodeops_template[];
 969 extern int              nfsfstyp;
 970 extern void             (*nfs_srv_quiesce_func)(void);
 971 extern int              (*nfs_srv_dss_func)(char *, size_t);
 972 
 973 /*
 974  * Per-zone stats as consumed by nfsstat(1m)
 975  */
 976 struct nfs_version_stats {
 977         kstat_named_t   *aclreqcnt_ptr;         /* nfs_acl:0:aclreqcnt_v? */
 978         kstat_named_t   *aclproccnt_ptr;        /* nfs_acl:0:aclproccnt_v? */
 979         kstat_named_t   *rfsreqcnt_ptr;         /* nfs:0:rfsreqcnt_v? */
 980         kstat_named_t   *rfsproccnt_ptr;        /* nfs:0:rfsproccnt_v? */
 981 };
 982 
 983 /*
 984  * A bit of asymmetry: nfs:0:nfs_client isn't part of this structure.
 985  */
 986 struct nfs_stats {
 987         kstat_named_t           *nfs_stats_svstat_ptr[NFS_VERSMAX + 1];
 988         struct nfs_version_stats        nfs_stats_v2;
 989         struct nfs_version_stats        nfs_stats_v3;
 990         struct nfs_version_stats        nfs_stats_v4;
 991 };
 992 
 993 /*
 994  * Key used to retrieve counters.
 995  */
 996 extern zone_key_t nfsstat_zone_key;
 997 
 998 /*
 999  * Zone callback functions.
1000  */
1001 extern void     *nfsstat_zone_init(zoneid_t);
1002 extern void     nfsstat_zone_fini(zoneid_t, void *);
1003 
1004 #endif  /* _KERNEL */
1005 
1006 /*
1007  * Version 3 declarations and definitions.
1008  */
1009 
1010 #define NFS3_FHSIZE 64
1011 #define NFS3_COOKIEVERFSIZE 8
1012 #define NFS3_CREATEVERFSIZE 8
1013 #define NFS3_WRITEVERFSIZE 8
1014 
1015 typedef char *filename3;
1016 
1017 typedef char *nfspath3;
1018 
1019 #define nfs3nametoolong ((char *)-1)
1020 
1021 typedef uint64 fileid3;
1022 
1023 typedef uint64 cookie3;
 
1804 typedef struct READDIR3args READDIR3args;
1805 
1806 struct entry3 {
1807         fileid3 fileid;
1808         filename3 name;
1809         cookie3 cookie;
1810         struct entry3 *nextentry;
1811 };
1812 typedef struct entry3 entry3;
1813 
1814 struct dirlist3 {
1815         entry3 *entries;
1816         bool_t eof;
1817 };
1818 typedef struct dirlist3 dirlist3;
1819 
1820 struct READDIR3resok {
1821         post_op_attr dir_attributes;
1822         cookieverf3 cookieverf;
1823         dirlist3 reply;
1824         uint_t size;
1825         uint_t count;
1826         uint_t freecount;
1827         cookie3 cookie;
1828 };
1829 typedef struct READDIR3resok READDIR3resok;
1830 
1831 struct READDIR3resfail {
1832         post_op_attr dir_attributes;
1833 };
1834 typedef struct READDIR3resfail READDIR3resfail;
1835 
1836 struct READDIR3res {
1837         nfsstat3 status;
1838         union {
1839                 READDIR3resok ok;
1840                 READDIR3resfail fail;
1841         } res_u;
1842 };
1843 typedef struct READDIR3res READDIR3res;
1844 
1845 #ifdef _KERNEL
1846 struct READDIR3vres {
1847         nfsstat3 status;
 
1864         count3 maxcount;
1865 };
1866 typedef struct READDIRPLUS3args READDIRPLUS3args;
1867 
1868 struct entryplus3 {
1869         fileid3 fileid;
1870         filename3 name;
1871         cookie3 cookie;
1872         post_op_attr name_attributes;
1873         post_op_fh3 name_handle;
1874         struct entryplus3 *nextentry;
1875 };
1876 typedef struct entryplus3 entryplus3;
1877 
1878 struct dirlistplus3 {
1879         entryplus3 *entries;
1880         bool_t eof;
1881 };
1882 typedef struct dirlistplus3 dirlistplus3;
1883 
1884 struct entryplus3_info {
1885         post_op_attr attr;
1886         post_op_fh3 fh;
1887         uint_t namelen;
1888 };
1889 typedef struct entryplus3_info entryplus3_info;
1890 
1891 struct READDIRPLUS3resok {
1892         post_op_attr dir_attributes;
1893         cookieverf3 cookieverf;
1894         dirlistplus3 reply;
1895         uint_t size;
1896         uint_t count;
1897         uint_t maxcount;
1898         entryplus3_info *infop;
1899 };
1900 typedef struct READDIRPLUS3resok READDIRPLUS3resok;
1901 
1902 struct READDIRPLUS3resfail {
1903         post_op_attr dir_attributes;
1904 };
1905 typedef struct READDIRPLUS3resfail READDIRPLUS3resfail;
1906 
1907 struct READDIRPLUS3res {
1908         nfsstat3 status;
1909         union {
1910                 READDIRPLUS3resok ok;
1911                 READDIRPLUS3resfail fail;
1912         } res_u;
1913 };
1914 typedef struct READDIRPLUS3res READDIRPLUS3res;
1915 
1916 #ifdef _KERNEL
1917 struct entryplus3_va_fh {
1918         int va_valid;
 
2261 extern int      nfs3_getattr_otw(vnode_t *, struct vattr *, cred_t *);
2262 extern int      nfs3getattr(vnode_t *, struct vattr *, cred_t *);
2263 extern int      fattr3_to_vattr(vnode_t *, fattr3 *, struct vattr *);
2264 extern int      nfs3tsize(void);
2265 extern uint_t   nfs3_tsize(struct knetconfig *);
2266 extern uint_t   rfs3_tsize(struct svc_req *);
2267 extern int      vattr_to_sattr3(struct vattr *, sattr3 *);
2268 extern void     setdiropargs3(diropargs3 *, char *, vnode_t *);
2269 extern enum nfsstat3 puterrno3(int);
2270 extern int      geterrno3(enum nfsstat3);
2271 extern int      nfs3init(int, char *);
2272 extern void     nfs3fini(void);
2273 extern int      nfs3_vfsinit(void);
2274 extern void     nfs3_vfsfini(void);
2275 extern void     vattr_to_post_op_attr(struct vattr *, post_op_attr *);
2276 extern void     mblk_to_iov(mblk_t *, int, struct iovec *);
2277 extern int      rfs_publicfh_mclookup(char *, vnode_t *, cred_t *, vnode_t **,
2278     struct exportinfo **, struct sec_ol *);
2279 extern int      rfs_pathname(char *, vnode_t **, vnode_t **, vnode_t *,
2280     cred_t *, int);
2281 
2282 extern vtype_t          nf3_to_vt[];
2283 extern kstat_named_t    *rfsproccnt_v3_ptr;
2284 extern vfsops_t         *nfs3_vfsops;
2285 extern struct vnodeops  *nfs3_vnodeops;
2286 extern const struct fs_operation_def nfs3_vnodeops_template[];
2287 
2288 /*
2289  * Some servers do not properly update the attributes of the
2290  * directory when changes are made.  To allow interoperability
2291  * with these broken servers, the nfs_disable_rddir_cache
2292  * parameter can be used to disable readdir response caching.
2293  */
2294 extern int              nfs_disable_rddir_cache;
2295 
2296 /*
2297  * External functions called by the v2/v3 code into the v4 code
2298  */
2299 extern void     nfs4_clnt_init(void);
2300 extern void     nfs4_clnt_fini(void);
2301 
2302 /*
2303  * Does NFS4 server have a vnode delegated?  TRUE if so, FALSE if not.
2304  */
2305 extern bool_t   rfs4_check_delegated(int mode, vnode_t *, bool_t trunc);
2306 /*
2307  * VOP_GETATTR call. If a NFS4 delegation is present on the supplied vnode
2308  * call back to the delegated client to get attributes for AT_MTIME and
2309  * AT_SIZE. Invoke VOP_GETATTR to get all other attributes or all attributes
2310  * if no delegation is present.
2311  */
2312 extern int      rfs4_delegated_getattr(vnode_t *, vattr_t *, int, cred_t *);
2313 extern void     rfs4_hold_deleg_policy(void);
2314 extern void     rfs4_rele_deleg_policy(void);
2315 
2316 extern int      do_xattr_exists_check(vnode_t *, ulong_t *, cred_t *);
2317 
2318 extern ts_label_t *nfs_getflabel(vnode_t *, struct exportinfo *);
2319 extern boolean_t do_rfs_label_check(bslabel_t *, vnode_t *, int,
2320     struct exportinfo *);
2321 
2322 /*
2323  * Copy Reduction support.
2324  * xuio_t wrapper with additional private data.
2325  */
2326 
2327 typedef struct nfs_xuio {
2328         xuio_t nu_uio;
2329         vnode_t *nu_vp;
2330         uint_t nu_ref;
2331         frtn_t nu_frtn;
2332 } nfs_xuio_t;
2333 
2334 extern xuio_t   *rfs_setup_xuio(vnode_t *);
2335 extern mblk_t   *uio_to_mblk(uio_t *);
2336 extern mblk_t   *rfs_read_alloc(uint_t, struct iovec **, int *);
2337 extern void     rfs_rndup_mblks(mblk_t *, uint_t, int);
 | 
 
 
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  27 /*        All Rights Reserved   */
  28 
  29 /*
  30  * Copyright 2018 Nexenta Systems, Inc.
  31  * Copyright (c) 2013 by Delphix. All rights reserved.
  32  */
  33 
  34 #ifndef _NFS_NFS_H
  35 #define _NFS_NFS_H
  36 
  37 #include <sys/isa_defs.h>
  38 #include <sys/vfs.h>
  39 #include <sys/stream.h>
  40 #include <rpc/types.h>
  41 #include <sys/types32.h>
  42 #ifdef _KERNEL
  43 #include <rpc/rpc_rdma.h>
  44 #include <rpc/rpc.h>
  45 #include <sys/fcntl.h>
  46 #include <sys/kstat.h>
  47 #include <sys/dirent.h>
  48 #include <sys/zone.h>
  49 #include <sys/tsol/label.h>
  50 #include <sys/nvpair.h>
  51 #include <nfs/mount.h>
  52 #include <sys/vfs_opreg.h>
  53 #endif
  54 #include <vm/page.h>
  55 #include <rpc/rpc_sztypes.h>
  56 #include <sys/sysmacros.h>
  57 #ifdef  __cplusplus
  58 extern "C" {
  59 #endif
  60 
  61 /*
  62  * remote file service numbers
  63  */
  64 #define NFS_PROGRAM     ((rpcprog_t)100003)
  65 #define NFS_VERSMIN     ((rpcvers_t)2)
  66 #define NFS_VERSMAX     ((rpcvers_t)4)
  67 #define NFS_VERSION     ((rpcvers_t)2)
  68 #define NFS_PORT        2049
  69 
  70 /*
  71  * Used to determine registration and service handling of versions
  72  */
  73 #define NFS_VERSMIN_DEFAULT     ((rpcvers_t)2)
  74 #define NFS_VERSMAX_DEFAULT     ((rpcvers_t)4)
  75 
  76 /*
  77  * Used to track the state of the server so that initialization
  78  * can be done properly.
  79  */
  80 typedef enum {
  81         NFS_SERVER_STOPPED,     /* server state destroyed */
  82         NFS_SERVER_STOPPING,    /* server state being destroyed */
  83         NFS_SERVER_RUNNING,
  84         NFS_SERVER_QUIESCED,    /* server state preserved */
  85         NFS_SERVER_OFFLINE      /* server pool offline */
  86 } nfs_server_running_t;
  87 
  88 /*
  89  * Zone globals variables of NFS server
  90  */
  91 typedef struct nfs_globals {
  92         rpcvers_t               nfs_versmin;
  93         rpcvers_t               nfs_versmax;
  94 
  95         /* NFS server locks and state */
  96         nfs_server_running_t    nfs_server_upordown;
  97         kmutex_t                nfs_server_upordown_lock;
  98         kcondvar_t              nfs_server_upordown_cv;
  99 
 100         /* RDMA wait variables */
 101         kcondvar_t              rdma_wait_cv;
 102         kmutex_t                rdma_wait_mutex;
 103 } nfs_globals_t;
 104 
 105 /*
 106  * Default delegation setting for the server ==> "on"
 107  */
 108 #define NFS_SERVER_DELEGATION_DEFAULT   (TRUE)
 109 
 110 /* Maximum size of data portion of a remote request */
 111 #define NFS_MAXDATA     8192
 112 #define NFS_MAXNAMLEN   255
 113 #define NFS_MAXPATHLEN  1024
 114 
 115 /*
 116  * Rpc retransmission parameters
 117  */
 118 #define NFS_TIMEO       11      /* initial timeout for clts in 10th of a sec */
 119 #define NFS_RETRIES     5       /* times to retry request */
 120 #define NFS_COTS_TIMEO  600     /* initial timeout for cots in 10th of a sec */
 121 
 122 /*
 123  * The value of UID_NOBODY/GID_NOBODY presented to the world via NFS.
 124  * UID_NOBODY/GID_NOBODY is translated to NFS_UID_NOBODY/NFS_GID_NOBODY
 125  * when being sent out over the network and NFS_UID_NOBODY/NFS_GID_NOBODY
 
 253  * we will not accept a negative value otw.
 254  *
 255  * So for nfsv2/3 (uint32_t):
 256  *
 257  * If nfs_allow_preepoch_time is
 258  * FALSE, the maximum time value is INT32_MAX for 32-bit kernels and
 259  * UINT32_MAX for 64-bit kernels (to allow times larger than 2038)
 260  * and the minimum is zero. Note that in that case, a 32-bit application
 261  * running on a 64-bit kernel will not be able to access files with
 262  * the larger time values.
 263  * If nfs_allow_preepoch_time is TRUE, the maximum time value is INT32_MAX
 264  * for both kernel configurations and the minimum is INT32_MIN.
 265  *
 266  * And for nfsv4 (int64_t):
 267  *
 268  * nfsv4 allows for negative values in the protocol, and has a 64-bit
 269  * time field, so nfs_allow_preepoch_time can be ignored.
 270  */
 271 #ifdef _KERNEL
 272 
 273 extern volatile bool_t  nfs_allow_preepoch_time;
 274 
 275 #ifdef _LP64
 276 
 277 /*
 278  * If no negative otw values are allowed, may use the full 32-bits of the
 279  * time to represent time later than 2038, by presenting the value as an
 280  * unsigned (but this can only be used by 64-bit apps due to cstat32
 281  * restrictions). If negative values are allowed, cannot represent times
 282  * after 2038. Either way, all 32 bits have a valid representation.
 283  */
 284 
 285 /* Check if nfstime4 seconds (int64_t) can be stored in the system time */
 286 #define NFS4_TIME_OK(tt)        TRUE
 287 
 288 
 289 #define NFS3_TIME_OVERFLOW(tt)  (FALSE)
 290 #define NFS2_TIME_OVERFLOW(tt)  (FALSE)
 291 
 292 /*
 293  * check if a time_t (int64_t) is ok when preepoch times are allowed -
 
 
 625         nfsstat rl_status;                      /* status of symlink read */
 626         union {
 627                 struct nfssrok  rl_srok_u;      /* name of linked to */
 628         } rl_u;
 629 };
 630 #define rl_srok         rl_u.rl_srok_u
 631 #define rl_count        rl_u.rl_srok_u.srok_count
 632 #define rl_data         rl_u.rl_srok_u.srok_data
 633 
 634 
 635 /*
 636  * Arguments to readdir
 637  */
 638 struct nfsrddirargs {
 639         fhandle_t rda_fh;       /* directory handle */
 640         uint32_t rda_offset;    /* offset in directory (opaque) */
 641         uint32_t rda_count;     /* number of directory bytes to read */
 642 };
 643 
 644 /*
 645  * Entry structure
 646  */
 647 struct nfsentry {
 648         uint32_t fileid;
 649         char *name;
 650         uint32_t cookie;
 651         struct nfsentry *nextentry;
 652 };
 653 
 654 /*
 655  * NFS_OK part of readdir result
 656  */
 657 struct nfsrdok {
 658         struct nfsentry *rdok_entries;  /* variable number of entries */
 659         bool_t rdok_eof;                /* true if last entry is in result */
 660 
 661         uint32_t rdok_offset;           /* next offset (opaque) */
 662         uint32_t rdok_size;             /* size in bytes of entries */
 663         struct dirent64 *rdok_dirents;  /* variable number of entries */
 664 };
 665 
 666 /*
 667  * Readdir result
 668  */
 669 struct nfsrddirres {
 670         nfsstat rd_status;
 671         union {
 672                 struct nfsrdok rd_rdok_u;
 673         } rd_u;
 674 };
 675 #define rd_rdok         rd_u.rd_rdok_u
 676 #define rd_entries      rd_u.rd_rdok_u.rdok_entries
 677 #define rd_eof          rd_u.rd_rdok_u.rdok_eof
 678 
 679 #define rd_offset       rd_u.rd_rdok_u.rdok_offset
 680 #define rd_size         rd_u.rd_rdok_u.rdok_size
 681 #define rd_dirents      rd_u.rd_rdok_u.rdok_dirents
 682 
 683 
 684 /*
 685  * Arguments for directory operations
 686  */
 687 struct nfsdiropargs {
 688         fhandle_t       *da_fhandle;    /* pointer to directory file handle */
 689         char            *da_name;       /* name (up to NFS_MAXNAMLEN bytes) */
 690         fhandle_t       da_fhandle_buf; /* directory file handle */
 691         int             da_flags;       /* flags, see below */
 692 };
 693 #define DA_FREENAME     1
 694 
 695 /*
 696  * NFS_OK part of directory operation result
 697  */
 698 struct  nfsdrok {
 699         fhandle_t       drok_fhandle;   /* result file handle */
 700         struct nfsfattr drok_attr;      /* result file attributes */
 701 };
 
 927 /*      function defs for NFS kernel */
 928 extern int      nfs_waitfor_purge_complete(vnode_t *);
 929 extern int      nfs_validate_caches(vnode_t *, cred_t *);
 930 extern void     nfs_purge_caches(vnode_t *, int, cred_t *);
 931 extern void     nfs_purge_rddir_cache(vnode_t *);
 932 extern void     nfs_attrcache(vnode_t *, struct nfsfattr *, hrtime_t);
 933 extern int      nfs_cache_fattr(vnode_t *, struct nfsfattr *, vattr_t *,
 934     hrtime_t, cred_t *);
 935 extern void     nfs_attr_cache(vnode_t *, vattr_t *, hrtime_t, cred_t *);
 936 extern void     nfs_attrcache_va(vnode_t *, struct vattr *);
 937 extern int      nfs_getattr_otw(vnode_t *, struct vattr *, cred_t *);
 938 extern int      nfsgetattr(vnode_t *, struct vattr *, cred_t *);
 939 extern int      nattr_to_vattr(vnode_t *, struct nfsfattr *, struct vattr *);
 940 extern void     nfs_async_manager(struct vfs *);
 941 extern void     nfs_async_manager_stop(struct vfs *);
 942 extern void     nfs_async_stop(struct vfs *);
 943 extern int      nfs_async_stop_sig(struct vfs *);
 944 extern int      nfs_clntinit(void);
 945 extern void     nfs_clntfini(void);
 946 extern int      nfstsize(void);
 947 extern void     nfs_srvinit(void);
 948 extern void     nfs_srvfini(void);
 949 extern int      vattr_to_sattr(struct vattr *, struct nfssattr *);
 950 extern void     setdiropargs(struct nfsdiropargs *, char *, vnode_t *);
 951 extern int      setdirgid(vnode_t *, gid_t *, cred_t *);
 952 extern int      setdirmode(vnode_t *, mode_t *, cred_t *);
 953 extern int      newnum(void);
 954 extern char     *newname(void);
 955 extern int      nfs_subrinit(void);
 956 extern void     nfs_subrfini(void);
 957 extern enum nfsstat puterrno(int);
 958 extern int      geterrno(enum nfsstat);
 959 extern int      nfsinit(int, char *);
 960 extern void     nfsfini(void);
 961 extern int      nfs_vfsinit(void);
 962 extern void     nfs_vfsfini(void);
 963 extern int      nfs_dump(vnode_t *, caddr_t, offset_t, offset_t,
 964     caller_context_t *);
 965 extern void     nfs_perror(int, char *, ...);
 966 extern void     nfs_cmn_err(int, int, char *, ...);
 967 extern int      nfs_addcllock(vnode_t *, struct flock64 *);
 
 
 980 extern void     sv_free(struct servinfo *);
 981 extern int      nfsauth_access(struct exportinfo *, struct svc_req *, cred_t *,
 982     uid_t *, gid_t *, uint_t *, gid_t **);
 983 extern void     nfsauth_init(void);
 984 extern void     nfsauth_fini(void);
 985 extern int      nfs_setopts(vnode_t *, model_t, struct nfs_args *);
 986 extern int      nfs_mount_label_policy(vfs_t *, struct netbuf *,
 987     struct knetconfig *, cred_t *);
 988 extern boolean_t nfs_has_ctty(void);
 989 extern void     nfs_srv_stop_all(void);
 990 extern void     nfs_srv_quiesce_all(void);
 991 extern int      rfs4_dss_setpaths(char *, size_t);
 992 extern int      nfs_setmod_check(page_t *);
 993 
 994 extern time_t   rfs4_lease_time;
 995 extern time_t   rfs4_grace_period;
 996 extern nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
 997 
 998 extern kstat_named_t    *global_svstat_ptr[];
 999 
1000 extern zone_key_t       rfs4_zone_key;
1001 extern zone_key_t       nfssrv_zone_key;
1002 extern krwlock_t        rroklock;
1003 extern vtype_t          nf_to_vt[];
1004 extern kstat_named_t    *rfsproccnt_v2_ptr;
1005 extern kstat_t          **rfsprocio_v2_ptr;
1006 extern kmutex_t         nfs_minor_lock;
1007 extern int              nfs_major;
1008 extern int              nfs_minor;
1009 extern vfsops_t         *nfs_vfsops;
1010 extern struct vnodeops  *nfs_vnodeops;
1011 extern const struct fs_operation_def nfs_vnodeops_template[];
1012 extern int              nfsfstyp;
1013 extern void             (*nfs_srv_quiesce_func)(void);
1014 extern int              (*nfs_srv_dss_func)(char *, size_t);
1015 
1016 /*
1017  * Per-zone stats
1018  */
1019 struct nfs_version_stats {
1020         kstat_named_t   *aclreqcnt_ptr;         /* nfs_acl:0:aclreqcnt_v? */
1021         kstat_named_t   *aclproccnt_ptr;        /* nfs_acl:0:aclproccnt_v? */
1022         kstat_t         **aclprocio_ptr;        /* nfs_acl:0:aclprocio_v?_* */
1023         kmutex_t        aclprocio_lock;         /* protects aclprocio */
1024         kstat_named_t   *rfsreqcnt_ptr;         /* nfs:0:rfsreqcnt_v? */
1025         kstat_named_t   *rfsproccnt_ptr;        /* nfs:0:rfsproccnt_v? */
1026         kstat_t         **rfsprocio_ptr;        /* nfs:0:rfsprocio_v?_* */
1027         kmutex_t        rfsprocio_lock;         /* protects rfsprocio */
1028 };
1029 
1030 /*
1031  * A bit of asymmetry: nfs:0:nfs_client isn't part of this structure.
1032  */
1033 struct nfs_stats {
1034         kstat_named_t           *nfs_stats_svstat_ptr[NFS_VERSMAX + 1];
1035         struct nfs_version_stats        nfs_stats_v2;
1036         struct nfs_version_stats        nfs_stats_v3;
1037         struct nfs_version_stats        nfs_stats_v4;
1038 };
1039 
1040 /*
1041  * Key used to retrieve counters.
1042  */
1043 extern zone_key_t nfsstat_zone_key;
1044 
1045 /*
1046  * Zone callback functions.
1047  */
1048 extern void     *nfsstat_zone_init(zoneid_t);
1049 extern void     nfsstat_zone_fini(zoneid_t, void *);
1050 
1051 /*
1052  * Per-exportinfo stats
1053  */
1054 struct exp_kstats {
1055         kstat_t         *share_kstat;           /* Generic share kstat */
1056         struct {
1057                 kstat_named_t   path;           /* Shared path */
1058                 kstat_named_t   filesystem;     /* pseudo|real */
1059         } share_kstat_data;                     /* Generic share kstat data */
1060         char            *share_path;            /* Shared path string */
1061         kstat_t         **rfsshr_v3_ptr;        /* NFS v3 per share stats */
1062         kstat_t         **rfsshr_v4_ptr;        /* NFS v4 per share stats */
1063         kmutex_t        procio_lock;            /* protects all exp_kstats */
1064 };
1065 
1066 extern struct exp_kstats *exp_kstats_init(zoneid_t, int, const char *, size_t,
1067     bool_t);
1068 extern void exp_kstats_delete(struct exp_kstats *);
1069 extern void exp_kstats_fini(struct exp_kstats *);
1070 extern void exp_kstats_reset(struct exp_kstats *, const char *, size_t, bool_t);
1071 
1072 extern kstat_t *exp_kstats_v2(struct exp_kstats *, uint_t);
1073 extern kstat_t *exp_kstats_v3(struct exp_kstats *, uint_t);
1074 extern kstat_t *exp_kstats_v4(struct exp_kstats *, uint_t);
1075 
1076 #endif  /* _KERNEL */
1077 
1078 /*
1079  * Version 3 declarations and definitions.
1080  */
1081 
1082 #define NFS3_FHSIZE 64
1083 #define NFS3_COOKIEVERFSIZE 8
1084 #define NFS3_CREATEVERFSIZE 8
1085 #define NFS3_WRITEVERFSIZE 8
1086 
1087 typedef char *filename3;
1088 
1089 typedef char *nfspath3;
1090 
1091 #define nfs3nametoolong ((char *)-1)
1092 
1093 typedef uint64 fileid3;
1094 
1095 typedef uint64 cookie3;
 
1876 typedef struct READDIR3args READDIR3args;
1877 
1878 struct entry3 {
1879         fileid3 fileid;
1880         filename3 name;
1881         cookie3 cookie;
1882         struct entry3 *nextentry;
1883 };
1884 typedef struct entry3 entry3;
1885 
1886 struct dirlist3 {
1887         entry3 *entries;
1888         bool_t eof;
1889 };
1890 typedef struct dirlist3 dirlist3;
1891 
1892 struct READDIR3resok {
1893         post_op_attr dir_attributes;
1894         cookieverf3 cookieverf;
1895         dirlist3 reply;
1896 };
1897 typedef struct READDIR3resok READDIR3resok;
1898 
1899 struct READDIR3resfail {
1900         post_op_attr dir_attributes;
1901 };
1902 typedef struct READDIR3resfail READDIR3resfail;
1903 
1904 struct READDIR3res {
1905         nfsstat3 status;
1906         union {
1907                 READDIR3resok ok;
1908                 READDIR3resfail fail;
1909         } res_u;
1910 };
1911 typedef struct READDIR3res READDIR3res;
1912 
1913 #ifdef _KERNEL
1914 struct READDIR3vres {
1915         nfsstat3 status;
 
1932         count3 maxcount;
1933 };
1934 typedef struct READDIRPLUS3args READDIRPLUS3args;
1935 
1936 struct entryplus3 {
1937         fileid3 fileid;
1938         filename3 name;
1939         cookie3 cookie;
1940         post_op_attr name_attributes;
1941         post_op_fh3 name_handle;
1942         struct entryplus3 *nextentry;
1943 };
1944 typedef struct entryplus3 entryplus3;
1945 
1946 struct dirlistplus3 {
1947         entryplus3 *entries;
1948         bool_t eof;
1949 };
1950 typedef struct dirlistplus3 dirlistplus3;
1951 
1952 struct READDIRPLUS3resok {
1953         post_op_attr dir_attributes;
1954         cookieverf3 cookieverf;
1955         dirlistplus3 reply;
1956 };
1957 typedef struct READDIRPLUS3resok READDIRPLUS3resok;
1958 
1959 struct READDIRPLUS3resfail {
1960         post_op_attr dir_attributes;
1961 };
1962 typedef struct READDIRPLUS3resfail READDIRPLUS3resfail;
1963 
1964 struct READDIRPLUS3res {
1965         nfsstat3 status;
1966         union {
1967                 READDIRPLUS3resok ok;
1968                 READDIRPLUS3resfail fail;
1969         } res_u;
1970 };
1971 typedef struct READDIRPLUS3res READDIRPLUS3res;
1972 
1973 #ifdef _KERNEL
1974 struct entryplus3_va_fh {
1975         int va_valid;
 
2318 extern int      nfs3_getattr_otw(vnode_t *, struct vattr *, cred_t *);
2319 extern int      nfs3getattr(vnode_t *, struct vattr *, cred_t *);
2320 extern int      fattr3_to_vattr(vnode_t *, fattr3 *, struct vattr *);
2321 extern int      nfs3tsize(void);
2322 extern uint_t   nfs3_tsize(struct knetconfig *);
2323 extern uint_t   rfs3_tsize(struct svc_req *);
2324 extern int      vattr_to_sattr3(struct vattr *, sattr3 *);
2325 extern void     setdiropargs3(diropargs3 *, char *, vnode_t *);
2326 extern enum nfsstat3 puterrno3(int);
2327 extern int      geterrno3(enum nfsstat3);
2328 extern int      nfs3init(int, char *);
2329 extern void     nfs3fini(void);
2330 extern int      nfs3_vfsinit(void);
2331 extern void     nfs3_vfsfini(void);
2332 extern void     vattr_to_post_op_attr(struct vattr *, post_op_attr *);
2333 extern void     mblk_to_iov(mblk_t *, int, struct iovec *);
2334 extern int      rfs_publicfh_mclookup(char *, vnode_t *, cred_t *, vnode_t **,
2335     struct exportinfo **, struct sec_ol *);
2336 extern int      rfs_pathname(char *, vnode_t **, vnode_t **, vnode_t *,
2337     cred_t *, int);
2338 extern int      rfs_cross_mnt(vnode_t **, struct exportinfo **);
2339 extern int      rfs_climb_crossmnt(vnode_t **, struct exportinfo **, cred_t *);
2340 
2341 extern vtype_t          nf3_to_vt[];
2342 extern kstat_named_t    *rfsproccnt_v3_ptr;
2343 extern kstat_t          **rfsprocio_v3_ptr;
2344 extern vfsops_t         *nfs3_vfsops;
2345 extern struct vnodeops  *nfs3_vnodeops;
2346 extern const struct fs_operation_def nfs3_vnodeops_template[];
2347 
2348 /*
2349  * Some servers do not properly update the attributes of the
2350  * directory when changes are made.  To allow interoperability
2351  * with these broken servers, the nfs_disable_rddir_cache
2352  * parameter can be used to disable readdir response caching.
2353  */
2354 extern volatile int     nfs_disable_rddir_cache;
2355 
2356 /*
2357  * External functions called by the v2/v3 code into the v4 code
2358  */
2359 extern void     nfs4_clnt_init(void);
2360 extern void     nfs4_clnt_fini(void);
2361 
2362 /*
2363  * Does NFS4 server have a vnode delegated?  TRUE if so, FALSE if not.
2364  */
2365 extern bool_t   rfs4_check_delegated(int mode, vnode_t *, bool_t trunc);
2366 /*
2367  * VOP_GETATTR call. If a NFS4 delegation is present on the supplied vnode
2368  * call back to the delegated client to get attributes for AT_MTIME and
2369  * AT_SIZE. Invoke VOP_GETATTR to get all other attributes or all attributes
2370  * if no delegation is present.
2371  */
2372 extern int      rfs4_delegated_getattr(vnode_t *, vattr_t *, int, cred_t *);
2373 
2374 extern int      do_xattr_exists_check(vnode_t *, ulong_t *, cred_t *);
2375 
2376 extern int      protect_zfs_mntpt(vnode_t *);
2377 
2378 extern ts_label_t *nfs_getflabel(vnode_t *, struct exportinfo *);
2379 extern boolean_t do_rfs_label_check(bslabel_t *, vnode_t *, int,
2380     struct exportinfo *);
2381 
2382 /*
2383  * Copy Reduction support.
2384  * xuio_t wrapper with additional private data.
2385  */
2386 
2387 typedef struct nfs_xuio {
2388         xuio_t nu_uio;
2389         vnode_t *nu_vp;
2390         uint_t nu_ref;
2391         frtn_t nu_frtn;
2392 } nfs_xuio_t;
2393 
2394 extern xuio_t   *rfs_setup_xuio(vnode_t *);
2395 extern mblk_t   *uio_to_mblk(uio_t *);
2396 extern mblk_t   *rfs_read_alloc(uint_t, struct iovec **, int *);
2397 extern void     rfs_rndup_mblks(mblk_t *, uint_t, int);
 |