Print this page
11083 support NFS server in zone
Portions contributed by: Dan Kruchinin <dan.kruchinin@nexenta.com>
Portions contributed by: Stepan Zastupov <stepan.zastupov@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Portions contributed by: Mike Zeller <mike@mikezeller.net>
Portions contributed by: Dan McDonald <danmcd@joyent.com>
Portions contributed by: Gordon Ross <gordon.w.ross@gmail.com>
Portions contributed by: Vitaliy Gusev <gusev.vitaliy@gmail.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Jason King <jbk@joyent.com>
Reviewed by: C Fraire <cfraire@me.com>
Change-Id: I22f289d357503f9b48a0bc2482cc4328a6d43d16


   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


 855     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 856 extern void     *rfs_link_getfh(struct nfslinkargs *);
 857 extern void     rfs_symlink(struct nfsslargs *, enum nfsstat *,
 858     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 859 extern void     *rfs_symlink_getfh(struct nfsslargs *);
 860 extern void     rfs_mkdir(struct nfscreatargs *, struct nfsdiropres *,
 861     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 862 extern void     *rfs_mkdir_getfh(struct nfscreatargs *);
 863 extern void     rfs_rmdir(struct nfsdiropargs *, enum nfsstat *,
 864     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 865 extern void     *rfs_rmdir_getfh(struct nfsdiropargs *);
 866 extern void     rfs_readdir(struct nfsrddirargs *, struct nfsrddirres *,
 867     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 868 extern void     *rfs_readdir_getfh(struct nfsrddirargs *);
 869 extern void     rfs_rddirfree(struct nfsrddirres *);
 870 extern void     rfs_statfs(fhandle_t *, struct nfsstatfs *, struct exportinfo *,
 871     struct svc_req *, cred_t *, bool_t);
 872 extern void     *rfs_statfs_getfh(fhandle_t *);
 873 extern void     rfs_srvrinit(void);
 874 extern void     rfs_srvrfini(void);


 875 
 876 /*
 877  * flags to define path types during Multi Component Lookups
 878  * using the public filehandle
 879  */
 880 #define URLPATH         0x01    /* Universal Resource Locator path */
 881 #define NATIVEPATH      0x02    /* Native path, i.e., via mount protocol */
 882 #define SECURITY_QUERY  0x04    /* Security query */
 883 
 884 /* index for svstat_ptr */
 885 enum nfs_svccounts {NFS_CALLS, NFS_BADCALLS, NFS_REFERRALS, NFS_REFERLINKS};
 886 


 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 *);
 928 extern void     nfs_rmcllock(vnode_t *, struct flock64 *);
 929 extern void     nfs_lockrelease(vnode_t *, int, offset_t, cred_t *);
 930 extern int      vattr_to_nattr(struct vattr *, struct nfsfattr *);
 931 extern int      mount_root(char *, char *, int, struct nfs_args *, int *);
 932 extern void     nfs_lockcompletion(vnode_t *, int);
 933 extern void     nfs_add_locking_id(vnode_t *, pid_t, int, char *, int);
 934 extern void     nfs3copyfh(caddr_t, vnode_t *);
 935 extern void     nfscopyfh(caddr_t, vnode_t *);
 936 extern int      nfs3lookup(vnode_t *, char *, vnode_t **, struct pathname *,
 937     int, vnode_t *, cred_t *, int);
 938 extern int      nfslookup(vnode_t *, char *, vnode_t **, struct pathname *, int,
 939     vnode_t *, cred_t *, int);
 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;


2231 extern void     *rfs3_readdir_getfh(READDIR3args *);
2232 extern void     rfs3_readdir_free(READDIR3res *);
2233 extern void     rfs3_readdirplus(READDIRPLUS3args *, READDIRPLUS3res *,
2234     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
2235 extern void     *rfs3_readdirplus_getfh(READDIRPLUS3args *);
2236 extern void     rfs3_readdirplus_free(READDIRPLUS3res *);
2237 extern void     rfs3_fsstat(FSSTAT3args *, FSSTAT3res *, struct exportinfo *,
2238     struct svc_req *, cred_t *, bool_t);
2239 extern void     *rfs3_fsstat_getfh(FSSTAT3args *);
2240 extern void     rfs3_fsinfo(FSINFO3args *, FSINFO3res *, struct exportinfo *,
2241     struct svc_req *, cred_t *, bool_t);
2242 extern void     *rfs3_fsinfo_getfh(FSINFO3args *);
2243 extern void     rfs3_pathconf(PATHCONF3args *, PATHCONF3res *,
2244     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
2245 extern void     *rfs3_pathconf_getfh(PATHCONF3args *);
2246 extern void     rfs3_commit(COMMIT3args *, COMMIT3res *, struct exportinfo *,
2247     struct svc_req *, cred_t *, bool_t);
2248 extern void     *rfs3_commit_getfh(COMMIT3args *);
2249 extern void     rfs3_srvrinit(void);
2250 extern void     rfs3_srvrfini(void);


2251 
2252 extern int      nfs3_validate_caches(vnode_t *, cred_t *);
2253 extern void     nfs3_cache_post_op_attr(vnode_t *, post_op_attr *, hrtime_t,
2254     cred_t *);
2255 extern void     nfs3_cache_post_op_vattr(vnode_t *, post_op_vattr *, hrtime_t,
2256     cred_t *);
2257 extern void     nfs3_cache_wcc_data(vnode_t *, wcc_data *, hrtime_t, cred_t *);
2258 extern void     nfs3_attrcache(vnode_t *, fattr3 *, hrtime_t);
2259 extern int      nfs3_cache_fattr3(vnode_t *, fattr3 *, vattr_t *, hrtime_t,
2260     cred_t *);
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 extern int      rfs_cross_mnt(vnode_t **, struct exportinfo **);
2282 extern int      rfs_climb_crossmnt(vnode_t **, struct exportinfo **, cred_t *);
2283 
2284 extern vtype_t          nf3_to_vt[];
2285 extern kstat_named_t    *rfsproccnt_v3_ptr;
2286 extern vfsops_t         *nfs3_vfsops;
2287 extern struct vnodeops  *nfs3_vnodeops;
2288 extern const struct fs_operation_def nfs3_vnodeops_template[];
2289 
2290 /*
2291  * Some servers do not properly update the attributes of the
2292  * directory when changes are made.  To allow interoperability
2293  * with these broken servers, the nfs_disable_rddir_cache
2294  * parameter can be used to disable readdir response caching.
2295  */
2296 extern int              nfs_disable_rddir_cache;
2297 
2298 /*
2299  * External functions called by the v2/v3 code into the v4 code
2300  */
2301 extern void     nfs4_clnt_init(void);
2302 extern void     nfs4_clnt_fini(void);
2303 
2304 /*
2305  * Does NFS4 server have a vnode delegated?  TRUE if so, FALSE if not.
2306  */
2307 extern bool_t   rfs4_check_delegated(int mode, vnode_t *, bool_t trunc);
2308 /*
2309  * VOP_GETATTR call. If a NFS4 delegation is present on the supplied vnode
2310  * call back to the delegated client to get attributes for AT_MTIME and
2311  * AT_SIZE. Invoke VOP_GETATTR to get all other attributes or all attributes
2312  * if no delegation is present.
2313  */
2314 extern int      rfs4_delegated_getattr(vnode_t *, vattr_t *, int, cred_t *);
2315 extern void     rfs4_hold_deleg_policy(void);
2316 extern void     rfs4_rele_deleg_policy(void);
2317 
2318 extern int      do_xattr_exists_check(vnode_t *, ulong_t *, cred_t *);
2319 


2320 extern ts_label_t *nfs_getflabel(vnode_t *, struct exportinfo *);
2321 extern boolean_t do_rfs_label_check(bslabel_t *, vnode_t *, int,
2322     struct exportinfo *);
2323 
2324 /*
2325  * Copy Reduction support.
2326  * xuio_t wrapper with additional private data.
2327  */
2328 
2329 typedef struct nfs_xuio {
2330         xuio_t nu_uio;
2331         vnode_t *nu_vp;
2332         uint_t nu_ref;
2333         frtn_t nu_frtn;
2334 } nfs_xuio_t;
2335 
2336 extern xuio_t   *rfs_setup_xuio(vnode_t *);
2337 extern mblk_t   *uio_to_mblk(uio_t *);
2338 extern mblk_t   *rfs_read_alloc(uint_t, struct iovec **, int *);
2339 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 (c) 2013 by Delphix. All rights reserved.
  31  * Copyright 2019 Nexenta by DDN, Inc. 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 /* Forward declarations for nfs_globals */
  89 struct nfs_export;
  90 struct nfs_srv;
  91 struct nfs3_srv;
  92 struct nfs4_srv;
  93 struct nfsauth_globals;
  94 
  95 /*
  96  * Zone globals variables of NFS server
  97  */
  98 typedef struct nfs_globals {
  99         list_node_t             nfs_g_link;     /* all globals list */
 100 
 101         rpcvers_t               nfs_versmin;
 102         rpcvers_t               nfs_versmax;
 103 
 104         /* NFS server locks and state */
 105         nfs_server_running_t    nfs_server_upordown;
 106         kmutex_t                nfs_server_upordown_lock;
 107         kcondvar_t              nfs_server_upordown_cv;
 108 
 109         /* RDMA wait variables */
 110         kcondvar_t              rdma_wait_cv;
 111         kmutex_t                rdma_wait_mutex;
 112 
 113         zoneid_t                nfs_zoneid;
 114         /* Per-zone data structures private to each module */
 115         struct nfs_export       *nfs_export;    /* nfs_export.c */
 116         struct nfs_srv          *nfs_srv;       /* nfs_srv.c */
 117         struct nfs3_srv         *nfs3_srv;      /* nfs3_srv.c */
 118         struct nfs4_srv         *nfs4_srv;      /* nfs4_srv.c */
 119         struct nfsauth_globals  *nfs_auth;      /* nfs_auth.c */
 120 
 121         /* statistic: nfs_stat.c, etc. */
 122         kstat_named_t           *svstat[NFS_VERSMAX + 1];
 123         kstat_named_t           *rfsproccnt[NFS_VERSMAX + 1];
 124         kstat_named_t           *aclproccnt[NFS_VERSMAX + 1];
 125 } nfs_globals_t;
 126 
 127 /*
 128  * Default delegation setting for the server ==> "on"
 129  */
 130 #define NFS_SERVER_DELEGATION_DEFAULT   (TRUE)
 131 
 132 /* Maximum size of data portion of a remote request */
 133 #define NFS_MAXDATA     8192
 134 #define NFS_MAXNAMLEN   255
 135 #define NFS_MAXPATHLEN  1024
 136 
 137 /*
 138  * Rpc retransmission parameters
 139  */
 140 #define NFS_TIMEO       11      /* initial timeout for clts in 10th of a sec */
 141 #define NFS_RETRIES     5       /* times to retry request */
 142 #define NFS_COTS_TIMEO  600     /* initial timeout for cots in 10th of a sec */
 143 
 144 /*
 145  * The value of UID_NOBODY/GID_NOBODY presented to the world via NFS.
 146  * UID_NOBODY/GID_NOBODY is translated to NFS_UID_NOBODY/NFS_GID_NOBODY
 147  * when being sent out over the network and NFS_UID_NOBODY/NFS_GID_NOBODY


 904     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 905 extern void     *rfs_link_getfh(struct nfslinkargs *);
 906 extern void     rfs_symlink(struct nfsslargs *, enum nfsstat *,
 907     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 908 extern void     *rfs_symlink_getfh(struct nfsslargs *);
 909 extern void     rfs_mkdir(struct nfscreatargs *, struct nfsdiropres *,
 910     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 911 extern void     *rfs_mkdir_getfh(struct nfscreatargs *);
 912 extern void     rfs_rmdir(struct nfsdiropargs *, enum nfsstat *,
 913     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 914 extern void     *rfs_rmdir_getfh(struct nfsdiropargs *);
 915 extern void     rfs_readdir(struct nfsrddirargs *, struct nfsrddirres *,
 916     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
 917 extern void     *rfs_readdir_getfh(struct nfsrddirargs *);
 918 extern void     rfs_rddirfree(struct nfsrddirres *);
 919 extern void     rfs_statfs(fhandle_t *, struct nfsstatfs *, struct exportinfo *,
 920     struct svc_req *, cred_t *, bool_t);
 921 extern void     *rfs_statfs_getfh(fhandle_t *);
 922 extern void     rfs_srvrinit(void);
 923 extern void     rfs_srvrfini(void);
 924 extern void     rfs_srv_zone_init(nfs_globals_t *);
 925 extern void     rfs_srv_zone_fini(nfs_globals_t *);
 926 
 927 /*
 928  * flags to define path types during Multi Component Lookups
 929  * using the public filehandle
 930  */
 931 #define URLPATH         0x01    /* Universal Resource Locator path */
 932 #define NATIVEPATH      0x02    /* Native path, i.e., via mount protocol */
 933 #define SECURITY_QUERY  0x04    /* Security query */
 934 
 935 /* index for svstat_ptr */
 936 enum nfs_svccounts {NFS_CALLS, NFS_BADCALLS, NFS_REFERRALS, NFS_REFERLINKS};
 937 
 938 #define NFS_V2  NFS_VERSION
 939 
 940 /*      function defs for NFS kernel */
 941 extern int      nfs_waitfor_purge_complete(vnode_t *);
 942 extern int      nfs_validate_caches(vnode_t *, cred_t *);
 943 extern void     nfs_purge_caches(vnode_t *, int, cred_t *);
 944 extern void     nfs_purge_rddir_cache(vnode_t *);
 945 extern void     nfs_attrcache(vnode_t *, struct nfsfattr *, hrtime_t);
 946 extern int      nfs_cache_fattr(vnode_t *, struct nfsfattr *, vattr_t *,
 947     hrtime_t, cred_t *);
 948 extern void     nfs_attr_cache(vnode_t *, vattr_t *, hrtime_t, cred_t *);
 949 extern void     nfs_attrcache_va(vnode_t *, struct vattr *);
 950 extern int      nfs_getattr_otw(vnode_t *, struct vattr *, cred_t *);
 951 extern int      nfsgetattr(vnode_t *, struct vattr *, cred_t *);
 952 extern int      nattr_to_vattr(vnode_t *, struct nfsfattr *, struct vattr *);
 953 extern void     nfs_async_manager(struct vfs *);
 954 extern void     nfs_async_manager_stop(struct vfs *);
 955 extern void     nfs_async_stop(struct vfs *);
 956 extern int      nfs_async_stop_sig(struct vfs *);
 957 extern int      nfs_clntinit(void);
 958 extern void     nfs_clntfini(void);
 959 extern int      nfstsize(void);
 960 extern void     nfs_srvinit(void);
 961 extern void     nfs_srvfini(void);
 962 extern int      vattr_to_sattr(struct vattr *, struct nfssattr *);
 963 extern void     setdiropargs(struct nfsdiropargs *, char *, vnode_t *);
 964 extern int      setdirgid(vnode_t *, gid_t *, cred_t *);
 965 extern int      setdirmode(vnode_t *, mode_t *, cred_t *);
 966 extern int      newnum(void);
 967 extern char     *newname(void);
 968 extern int      nfs_subrinit(void);
 969 extern void     nfs_subrfini(void);
 970 extern enum nfsstat puterrno(int);
 971 extern int      geterrno(enum nfsstat);
 972 extern int      nfsinit(int, char *);
 973 extern void     nfsfini(void);
 974 extern int      nfs_vfsinit(void);
 975 extern void     nfs_vfsfini(void);
 976 extern int      nfs_dump(vnode_t *, caddr_t, offset_t, offset_t,
 977     caller_context_t *);
 978 extern void     nfs_perror(int, char *, ...);
 979 extern void     nfs_cmn_err(int, int, char *, ...);
 980 extern int      nfs_addcllock(vnode_t *, struct flock64 *);
 981 extern void     nfs_rmcllock(vnode_t *, struct flock64 *);
 982 extern void     nfs_lockrelease(vnode_t *, int, offset_t, cred_t *);
 983 extern int      vattr_to_nattr(struct vattr *, struct nfsfattr *);
 984 extern int      mount_root(char *, char *, int, struct nfs_args *, int *);
 985 extern void     nfs_lockcompletion(vnode_t *, int);
 986 extern void     nfs_add_locking_id(vnode_t *, pid_t, int, char *, int);
 987 extern void     nfs3copyfh(caddr_t, vnode_t *);
 988 extern void     nfscopyfh(caddr_t, vnode_t *);
 989 extern int      nfs3lookup(vnode_t *, char *, vnode_t **, struct pathname *,
 990     int, vnode_t *, cred_t *, int);
 991 extern int      nfslookup(vnode_t *, char *, vnode_t **, struct pathname *, int,
 992     vnode_t *, cred_t *, int);
 993 extern void     sv_free(struct servinfo *);
 994 extern int      nfsauth_access(struct exportinfo *, struct svc_req *, cred_t *,
 995     uid_t *, gid_t *, uint_t *, gid_t **);
 996 extern void     nfsauth_init(void);
 997 extern void     nfsauth_fini(void);
 998 extern void     nfsauth_zone_init(nfs_globals_t *);
 999 extern void     nfsauth_zone_fini(nfs_globals_t *);
1000 extern void     nfsauth_zone_shutdown(nfs_globals_t *);
1001 extern int      nfs_setopts(vnode_t *, model_t, struct nfs_args *);
1002 extern int      nfs_mount_label_policy(vfs_t *, struct netbuf *,
1003     struct knetconfig *, cred_t *);
1004 extern boolean_t nfs_has_ctty(void);
1005 extern nfs_globals_t *nfs_srv_getzg(void);
1006 extern void     nfs_srv_stop_all(void);
1007 extern void     nfs_srv_quiesce_all(void);
1008 extern int      rfs4_dss_setpaths(char *, size_t);
1009 extern int      nfs_setmod_check(page_t *);
1010 
1011 extern time_t   rfs4_lease_time;
1012 extern time_t   rfs4_grace_period;
1013 extern nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
1014 
1015 extern kstat_named_t    *global_svstat_ptr[];
1016 
1017 extern zone_key_t       nfssrv_zone_key;
1018 extern list_t           nfssrv_globals_list;
1019 extern krwlock_t        nfssrv_globals_rwl;
1020 
1021 extern krwlock_t        rroklock;
1022 extern vtype_t          nf_to_vt[];

1023 extern kmutex_t         nfs_minor_lock;
1024 extern int              nfs_major;
1025 extern int              nfs_minor;
1026 extern vfsops_t         *nfs_vfsops;
1027 extern struct vnodeops  *nfs_vnodeops;
1028 extern const struct fs_operation_def nfs_vnodeops_template[];
1029 extern int              nfsfstyp;
1030 extern void             (*nfs_srv_quiesce_func)(void);
1031 extern int              (*nfs_srv_dss_func)(char *, size_t);
1032 
1033 /*
1034  * Per-zone stats as consumed by nfsstat(1m)
1035  */
1036 struct nfs_version_stats {
1037         kstat_named_t   *aclreqcnt_ptr;         /* nfs_acl:0:aclreqcnt_v? */

1038         kstat_named_t   *rfsreqcnt_ptr;         /* nfs:0:rfsreqcnt_v? */

1039 };
1040 
1041 /*
1042  * A bit of asymmetry: nfs:0:nfs_client isn't part of this structure.
1043  */
1044 struct nfs_stats {

1045         struct nfs_version_stats        nfs_stats_v2;
1046         struct nfs_version_stats        nfs_stats_v3;
1047         struct nfs_version_stats        nfs_stats_v4;
1048 };
1049 
1050 /*
1051  * Key used to retrieve counters.
1052  */
1053 extern zone_key_t nfsstat_zone_key;
1054 
1055 /*
1056  * Zone callback functions.
1057  */
1058 extern void     *nfsstat_zone_init(zoneid_t);
1059 extern void     nfsstat_zone_fini(zoneid_t, void *);
1060 
1061 extern void rfs_stat_zone_init(nfs_globals_t *);
1062 extern void rfs_stat_zone_fini(nfs_globals_t *);
1063 
1064 #endif  /* _KERNEL */
1065 
1066 /*
1067  * Version 3 declarations and definitions.
1068  */
1069 
1070 #define NFS3_FHSIZE 64
1071 #define NFS3_COOKIEVERFSIZE 8
1072 #define NFS3_CREATEVERFSIZE 8
1073 #define NFS3_WRITEVERFSIZE 8
1074 
1075 typedef char *filename3;
1076 
1077 typedef char *nfspath3;
1078 
1079 #define nfs3nametoolong ((char *)-1)
1080 
1081 typedef uint64 fileid3;
1082 
1083 typedef uint64 cookie3;


2291 extern void     *rfs3_readdir_getfh(READDIR3args *);
2292 extern void     rfs3_readdir_free(READDIR3res *);
2293 extern void     rfs3_readdirplus(READDIRPLUS3args *, READDIRPLUS3res *,
2294     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
2295 extern void     *rfs3_readdirplus_getfh(READDIRPLUS3args *);
2296 extern void     rfs3_readdirplus_free(READDIRPLUS3res *);
2297 extern void     rfs3_fsstat(FSSTAT3args *, FSSTAT3res *, struct exportinfo *,
2298     struct svc_req *, cred_t *, bool_t);
2299 extern void     *rfs3_fsstat_getfh(FSSTAT3args *);
2300 extern void     rfs3_fsinfo(FSINFO3args *, FSINFO3res *, struct exportinfo *,
2301     struct svc_req *, cred_t *, bool_t);
2302 extern void     *rfs3_fsinfo_getfh(FSINFO3args *);
2303 extern void     rfs3_pathconf(PATHCONF3args *, PATHCONF3res *,
2304     struct exportinfo *, struct svc_req *, cred_t *, bool_t);
2305 extern void     *rfs3_pathconf_getfh(PATHCONF3args *);
2306 extern void     rfs3_commit(COMMIT3args *, COMMIT3res *, struct exportinfo *,
2307     struct svc_req *, cred_t *, bool_t);
2308 extern void     *rfs3_commit_getfh(COMMIT3args *);
2309 extern void     rfs3_srvrinit(void);
2310 extern void     rfs3_srvrfini(void);
2311 extern void     rfs3_srv_zone_init(nfs_globals_t *);
2312 extern void     rfs3_srv_zone_fini(nfs_globals_t *);
2313 
2314 extern int      nfs3_validate_caches(vnode_t *, cred_t *);
2315 extern void     nfs3_cache_post_op_attr(vnode_t *, post_op_attr *, hrtime_t,
2316     cred_t *);
2317 extern void     nfs3_cache_post_op_vattr(vnode_t *, post_op_vattr *, hrtime_t,
2318     cred_t *);
2319 extern void     nfs3_cache_wcc_data(vnode_t *, wcc_data *, hrtime_t, cred_t *);
2320 extern void     nfs3_attrcache(vnode_t *, fattr3 *, hrtime_t);
2321 extern int      nfs3_cache_fattr3(vnode_t *, fattr3 *, vattr_t *, hrtime_t,
2322     cred_t *);
2323 extern int      nfs3_getattr_otw(vnode_t *, struct vattr *, cred_t *);
2324 extern int      nfs3getattr(vnode_t *, struct vattr *, cred_t *);
2325 extern int      fattr3_to_vattr(vnode_t *, fattr3 *, struct vattr *);
2326 extern int      nfs3tsize(void);
2327 extern uint_t   nfs3_tsize(struct knetconfig *);
2328 extern uint_t   rfs3_tsize(struct svc_req *);
2329 extern int      vattr_to_sattr3(struct vattr *, sattr3 *);
2330 extern void     setdiropargs3(diropargs3 *, char *, vnode_t *);
2331 extern enum nfsstat3 puterrno3(int);
2332 extern int      geterrno3(enum nfsstat3);
2333 extern int      nfs3init(int, char *);
2334 extern void     nfs3fini(void);
2335 extern int      nfs3_vfsinit(void);
2336 extern void     nfs3_vfsfini(void);
2337 extern void     vattr_to_post_op_attr(struct vattr *, post_op_attr *);
2338 extern void     mblk_to_iov(mblk_t *, int, struct iovec *);
2339 extern int      rfs_publicfh_mclookup(char *, vnode_t *, cred_t *, vnode_t **,
2340     struct exportinfo **, struct sec_ol *);
2341 extern int      rfs_pathname(char *, vnode_t **, vnode_t **, vnode_t *,
2342     cred_t *, int);
2343 extern int      rfs_cross_mnt(vnode_t **, struct exportinfo **);
2344 extern int      rfs_climb_crossmnt(vnode_t **, struct exportinfo **, cred_t *);
2345 
2346 extern vtype_t          nf3_to_vt[];

2347 extern vfsops_t         *nfs3_vfsops;
2348 extern struct vnodeops  *nfs3_vnodeops;
2349 extern const struct fs_operation_def nfs3_vnodeops_template[];
2350 
2351 /*
2352  * Some servers do not properly update the attributes of the
2353  * directory when changes are made.  To allow interoperability
2354  * with these broken servers, the nfs_disable_rddir_cache
2355  * parameter can be used to disable readdir response caching.
2356  */
2357 extern int              nfs_disable_rddir_cache;
2358 
2359 /*
2360  * External functions called by the v2/v3 code into the v4 code
2361  */
2362 extern void     nfs4_clnt_init(void);
2363 extern void     nfs4_clnt_fini(void);
2364 
2365 /*
2366  * Does NFS4 server have a vnode delegated?  TRUE if so, FALSE if not.
2367  */
2368 extern bool_t   rfs4_check_delegated(int mode, vnode_t *, bool_t trunc);
2369 /*
2370  * VOP_GETATTR call. If a NFS4 delegation is present on the supplied vnode
2371  * call back to the delegated client to get attributes for AT_MTIME and
2372  * AT_SIZE. Invoke VOP_GETATTR to get all other attributes or all attributes
2373  * if no delegation is present.
2374  */
2375 extern int      rfs4_delegated_getattr(vnode_t *, vattr_t *, int, cred_t *);


2376 
2377 extern int      do_xattr_exists_check(vnode_t *, ulong_t *, cred_t *);
2378 
2379 extern int      protect_zfs_mntpt(vnode_t *);
2380 
2381 extern ts_label_t *nfs_getflabel(vnode_t *, struct exportinfo *);
2382 extern boolean_t do_rfs_label_check(bslabel_t *, vnode_t *, int,
2383     struct exportinfo *);
2384 
2385 /*
2386  * Copy Reduction support.
2387  * xuio_t wrapper with additional private data.
2388  */
2389 
2390 typedef struct nfs_xuio {
2391         xuio_t nu_uio;
2392         vnode_t *nu_vp;
2393         uint_t nu_ref;
2394         frtn_t nu_frtn;
2395 } nfs_xuio_t;
2396 
2397 extern xuio_t   *rfs_setup_xuio(vnode_t *);
2398 extern mblk_t   *uio_to_mblk(uio_t *);
2399 extern mblk_t   *rfs_read_alloc(uint_t, struct iovec **, int *);
2400 extern void     rfs_rndup_mblks(mblk_t *, uint_t, int);