xref: /onnv-gate/usr/src/uts/common/nfs/export.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #ifndef	_NFS_EXPORT_H
31*0Sstevel@tonic-gate #define	_NFS_EXPORT_H
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #include <nfs/nfs_sec.h>
36*0Sstevel@tonic-gate #include <rpcsvc/nfsauth_prot.h>
37*0Sstevel@tonic-gate #include <sys/vnode.h>
38*0Sstevel@tonic-gate #include <nfs/nfs4.h>
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #ifdef	__cplusplus
41*0Sstevel@tonic-gate extern "C" {
42*0Sstevel@tonic-gate #endif
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /*
45*0Sstevel@tonic-gate  * nfs pseudo flavor number is owned by IANA. Need to make sure the
46*0Sstevel@tonic-gate  * Solaris specific NFS_FLAVOR_NOMAP number will not overlap with any
47*0Sstevel@tonic-gate  * new IANA defined pseudo flavor numbers. The chance for the overlap
48*0Sstevel@tonic-gate  * is very small since the growth of new flavor numbers is expected
49*0Sstevel@tonic-gate  * to be limited.
50*0Sstevel@tonic-gate  */
51*0Sstevel@tonic-gate #define	NFS_FLAVOR_NOMAP	999999	/* no nfs flavor mapping */
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate /*
54*0Sstevel@tonic-gate  * Note: exported_lock is currently used to ensure the integrity of
55*0Sstevel@tonic-gate  * the secinfo fields.
56*0Sstevel@tonic-gate  */
57*0Sstevel@tonic-gate struct secinfo {
58*0Sstevel@tonic-gate 	seconfig_t	s_secinfo;	/* /etc/nfssec.conf entry */
59*0Sstevel@tonic-gate 	unsigned int	s_flags;	/* flags (see below) */
60*0Sstevel@tonic-gate 	uint32_t	s_refcnt;	/* reference count for tracking */
61*0Sstevel@tonic-gate 					/* how many children (self included) */
62*0Sstevel@tonic-gate 					/* use this flavor. */
63*0Sstevel@tonic-gate 	int 		s_window;	/* window */
64*0Sstevel@tonic-gate 	int		s_rootcnt;	/* count of root names */
65*0Sstevel@tonic-gate 	caddr_t		*s_rootnames;	/* array of root names */
66*0Sstevel@tonic-gate 					/* they are strings for AUTH_DES and */
67*0Sstevel@tonic-gate 					/* rpc_gss_principal_t for RPCSEC_GSS */
68*0Sstevel@tonic-gate };
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate #ifdef _SYSCALL32
71*0Sstevel@tonic-gate struct secinfo32 {
72*0Sstevel@tonic-gate 	seconfig32_t	s_secinfo;	/* /etc/nfssec.conf entry */
73*0Sstevel@tonic-gate 	uint32_t	s_flags;	/* flags (see below) */
74*0Sstevel@tonic-gate 	uint32_t	s_refcnt;	/* reference count for tracking */
75*0Sstevel@tonic-gate 					/* how many children (self included) */
76*0Sstevel@tonic-gate 					/* use this flavor. */
77*0Sstevel@tonic-gate 	int32_t 	s_window;	/* window */
78*0Sstevel@tonic-gate 	int32_t		s_rootcnt;	/* count of root names */
79*0Sstevel@tonic-gate 	caddr32_t	s_rootnames;	/* array of root names */
80*0Sstevel@tonic-gate 					/* they are strings for AUTH_DES and */
81*0Sstevel@tonic-gate 					/* rpc_gss_principal_t for RPCSEC_GSS */
82*0Sstevel@tonic-gate };
83*0Sstevel@tonic-gate #endif /* _SYSCALL32 */
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate /*
86*0Sstevel@tonic-gate  * security negotiation related
87*0Sstevel@tonic-gate  */
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate #define	SEC_QUERY	0x01	/* query sec modes */
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate struct sec_ol {
92*0Sstevel@tonic-gate 	int		sec_flags;	/* security nego flags */
93*0Sstevel@tonic-gate 	uint_t		sec_index;	/* index into sec flavor array */
94*0Sstevel@tonic-gate };
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate /*
97*0Sstevel@tonic-gate  * Per-mode flags (secinfo.s_flags)
98*0Sstevel@tonic-gate  */
99*0Sstevel@tonic-gate #define	M_RO		0x01	/* exported ro to all */
100*0Sstevel@tonic-gate #define	M_ROL		0x02	/* exported ro to all listed */
101*0Sstevel@tonic-gate #define	M_RW		0x04	/* exported rw to all */
102*0Sstevel@tonic-gate #define	M_RWL		0x08	/* exported ro to all listed */
103*0Sstevel@tonic-gate #define	M_ROOT		0x10	/* root list is defined */
104*0Sstevel@tonic-gate #define	M_4SEC_EXPORTED	0x20	/* this is an explicitly shared flavor */
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate /* invalid secinfo reference count */
107*0Sstevel@tonic-gate #define	SEC_REF_INVALID(p) ((p)->s_refcnt < 1)
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate /* last secinfo reference */
110*0Sstevel@tonic-gate #define	SEC_REF_LAST(p) ((p)->s_refcnt == 1)
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate /* sec flavor explicitly shared for the exported node */
113*0Sstevel@tonic-gate #define	SEC_REF_EXPORTED(p) ((p)->s_flags & M_4SEC_EXPORTED)
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate /* the only reference count left is for referring itself */
116*0Sstevel@tonic-gate #define	SEC_REF_SELF(p) (SEC_REF_LAST(p) && SEC_REF_EXPORTED(p))
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate /*
119*0Sstevel@tonic-gate  * The export information passed to exportfs() (Version 2)
120*0Sstevel@tonic-gate  */
121*0Sstevel@tonic-gate #define	EX_CURRENT_VERSION 2	/* current version of exportdata struct */
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate struct exportdata {
124*0Sstevel@tonic-gate 	int		ex_version;	/* structure version */
125*0Sstevel@tonic-gate 	char		*ex_path;	/* exported path */
126*0Sstevel@tonic-gate 	size_t		ex_pathlen;	/* path length */
127*0Sstevel@tonic-gate 	int		ex_flags;	/* flags */
128*0Sstevel@tonic-gate 	unsigned int	ex_anon;	/* uid for unauthenticated requests */
129*0Sstevel@tonic-gate 	int		ex_seccnt;	/* count of security modes */
130*0Sstevel@tonic-gate 	struct secinfo	*ex_secinfo;	/* security mode info */
131*0Sstevel@tonic-gate 	char		*ex_index;	/* index file for public filesystem */
132*0Sstevel@tonic-gate 	char		*ex_log_buffer;	/* path to logging buffer file */
133*0Sstevel@tonic-gate 	size_t		ex_log_bufferlen;	/* buffer file path len */
134*0Sstevel@tonic-gate 	char		*ex_tag;	/* tag used to identify log config */
135*0Sstevel@tonic-gate 	size_t		ex_taglen;	/* tag length */
136*0Sstevel@tonic-gate };
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate #ifdef _SYSCALL32
139*0Sstevel@tonic-gate struct exportdata32 {
140*0Sstevel@tonic-gate 	int32_t		ex_version;	/* structure version */
141*0Sstevel@tonic-gate 	caddr32_t	ex_path;	/* exported path */
142*0Sstevel@tonic-gate 	int32_t		ex_pathlen;	/* path length */
143*0Sstevel@tonic-gate 	int32_t		ex_flags;	/* flags */
144*0Sstevel@tonic-gate 	uint32_t	ex_anon;	/* uid for unauthenticated requests */
145*0Sstevel@tonic-gate 	int32_t		ex_seccnt;	/* count of security modes */
146*0Sstevel@tonic-gate 	caddr32_t	ex_secinfo;	/* security mode info */
147*0Sstevel@tonic-gate 	caddr32_t	ex_index;	/* index file for public filesystem */
148*0Sstevel@tonic-gate 	caddr32_t	ex_log_buffer;	/* path to logging buffer file */
149*0Sstevel@tonic-gate 	int32_t		ex_log_bufferlen;	/* buffer file path len */
150*0Sstevel@tonic-gate 	caddr32_t	ex_tag;		/* tag used to identify log config */
151*0Sstevel@tonic-gate 	int32_t		ex_taglen;	/* tag length */
152*0Sstevel@tonic-gate };
153*0Sstevel@tonic-gate #endif /* _SYSCALL32 */
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate /*
156*0Sstevel@tonic-gate  * exported vfs flags.
157*0Sstevel@tonic-gate  */
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate #define	EX_NOSUID	0x01	/* exported with unsetable set[ug]ids */
160*0Sstevel@tonic-gate #define	EX_ACLOK	0x02	/* exported with maximal access if acl exists */
161*0Sstevel@tonic-gate #define	EX_PUBLIC	0x04	/* exported with public filehandle */
162*0Sstevel@tonic-gate #define	EX_NOSUB	0x08	/* no nfs_getfh or MCL below export point */
163*0Sstevel@tonic-gate #define	EX_INDEX	0x10	/* exported with index file specified */
164*0Sstevel@tonic-gate #define	EX_LOG		0x20	/* logging enabled */
165*0Sstevel@tonic-gate #define	EX_LOG_ALLOPS	0x40	/* logging of all RPC operations enabled */
166*0Sstevel@tonic-gate 				/* by default only operations which affect */
167*0Sstevel@tonic-gate 				/* transaction logging are enabled */
168*0Sstevel@tonic-gate #define	EX_PSEUDO	0x80	/* pseudo filesystem export */
169*0Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST
170*0Sstevel@tonic-gate #define	EX_VOLFH	0x100	/* XXX nfsv4 fh may expire anytime */
171*0Sstevel@tonic-gate #define	EX_VOLRNM	0x200	/* XXX nfsv4 fh expire at rename */
172*0Sstevel@tonic-gate #define	EX_VOLMIG	0x400	/* XXX nfsv4 fh expire at migration */
173*0Sstevel@tonic-gate #define	EX_NOEXPOPEN	0x800	/* XXX nfsv4 fh no expire with open */
174*0Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate #ifdef	_KERNEL
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate #define	RPC_IDEMPOTENT	0x1	/* idempotent or not */
179*0Sstevel@tonic-gate /*
180*0Sstevel@tonic-gate  * Be very careful about which NFS procedures get the RPC_ALLOWANON bit.
181*0Sstevel@tonic-gate  * Right now, it this bit is on, we ignore the results of per NFS request
182*0Sstevel@tonic-gate  * access control.
183*0Sstevel@tonic-gate  */
184*0Sstevel@tonic-gate #define	RPC_ALLOWANON	0x2	/* allow anonymous access */
185*0Sstevel@tonic-gate #define	RPC_MAPRESP	0x4	/* use mapped response buffer */
186*0Sstevel@tonic-gate #define	RPC_AVOIDWORK	0x8	/* do work avoidance for dups */
187*0Sstevel@tonic-gate #define	RPC_PUBLICFH_OK	0x10	/* allow use of public filehandle */
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate /*
190*0Sstevel@tonic-gate  * RPC_ALL is an or of all above bits to be used with "don't care"
191*0Sstevel@tonic-gate  * nfsv4 ops. The flags of an nfsv4 request is the bit-AND of the
192*0Sstevel@tonic-gate  * per-op flags.
193*0Sstevel@tonic-gate  */
194*0Sstevel@tonic-gate #define	RPC_ALL	(RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_AVOIDWORK|RPC_PUBLICFH_OK)
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST
198*0Sstevel@tonic-gate struct ex_vol_rename {
199*0Sstevel@tonic-gate 	nfs_fh4_fmt_t vrn_fh_fmt;
200*0Sstevel@tonic-gate 	struct ex_vol_rename *vrn_next;
201*0Sstevel@tonic-gate };
202*0Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate /*
205*0Sstevel@tonic-gate  * An authorization cache entry
206*0Sstevel@tonic-gate  */
207*0Sstevel@tonic-gate struct auth_cache {
208*0Sstevel@tonic-gate 	struct netbuf		auth_addr;
209*0Sstevel@tonic-gate 	int			auth_flavor;
210*0Sstevel@tonic-gate 	int			auth_access;
211*0Sstevel@tonic-gate 	time_t			auth_time;
212*0Sstevel@tonic-gate 	struct auth_cache	*auth_next;
213*0Sstevel@tonic-gate };
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate #define	AUTH_TABLESIZE	32
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate /*
218*0Sstevel@tonic-gate  * Structure containing log file meta-data.
219*0Sstevel@tonic-gate  */
220*0Sstevel@tonic-gate struct log_file {
221*0Sstevel@tonic-gate 	unsigned int	lf_flags;	/* flags (see below) */
222*0Sstevel@tonic-gate 	int		lf_writers;	/* outstanding writers */
223*0Sstevel@tonic-gate 	int		lf_refcnt;	/* references to this struct */
224*0Sstevel@tonic-gate 	caddr_t		lf_path;	/* buffer file location */
225*0Sstevel@tonic-gate 	vnode_t		*lf_vp;		/* vnode for the buffer file */
226*0Sstevel@tonic-gate 	kmutex_t	lf_lock;
227*0Sstevel@tonic-gate 	kcondvar_t	lf_cv_waiters;
228*0Sstevel@tonic-gate };
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate /*
231*0Sstevel@tonic-gate  * log_file and log_buffer flags.
232*0Sstevel@tonic-gate  */
233*0Sstevel@tonic-gate #define	L_WAITING	0x01		/* flush of in-core data to stable */
234*0Sstevel@tonic-gate 					/* storage in progress */
235*0Sstevel@tonic-gate #define	L_PRINTED	0x02		/* error message printed to console */
236*0Sstevel@tonic-gate #define	L_ERROR		0x04		/* error condition detected */
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate /*
239*0Sstevel@tonic-gate  * The logging buffer information.
240*0Sstevel@tonic-gate  * This structure may be shared by multiple exportinfo structures,
241*0Sstevel@tonic-gate  * if they share the same buffer file.
242*0Sstevel@tonic-gate  * This structure contains the basic information about the buffer, such
243*0Sstevel@tonic-gate  * as it's location in the filesystem.
244*0Sstevel@tonic-gate  *
245*0Sstevel@tonic-gate  * 'lb_lock' protects all the fields in this structure except for 'lb_path',
246*0Sstevel@tonic-gate  * and 'lb_next'.
247*0Sstevel@tonic-gate  * 'lb_path' is a write-once/read-many field which needs no locking, it is
248*0Sstevel@tonic-gate  * set before the structure is linked to any exportinfo structure.
249*0Sstevel@tonic-gate  * 'lb_next' is protected by the log_buffer_list_lock.
250*0Sstevel@tonic-gate  */
251*0Sstevel@tonic-gate struct log_buffer {
252*0Sstevel@tonic-gate 	unsigned int	lb_flags;	/* L_ONLIST set? */
253*0Sstevel@tonic-gate 	int		lb_refcnt;	/* references to this struct */
254*0Sstevel@tonic-gate 	unsigned int	lb_rec_id;	/* used to generate unique id */
255*0Sstevel@tonic-gate 	caddr_t		lb_path;	/* buffer file pathname */
256*0Sstevel@tonic-gate 	struct log_file	*lb_logfile;	/* points to log_file structure */
257*0Sstevel@tonic-gate 	kmutex_t	lb_lock;
258*0Sstevel@tonic-gate 	struct log_buffer	*lb_next;
259*0Sstevel@tonic-gate 	kcondvar_t	lb_cv_waiters;
260*0Sstevel@tonic-gate 	caddr_t		lb_records;	/* linked list of records to write */
261*0Sstevel@tonic-gate 	int		lb_num_recs;	/* # of records to write */
262*0Sstevel@tonic-gate 	ssize_t		lb_size_queued; /* number of bytes queued for write */
263*0Sstevel@tonic-gate };
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate #define	LOG_BUFFER_HOLD(lbp)	{ \
266*0Sstevel@tonic-gate 	mutex_enter(&(lbp)->lb_lock); \
267*0Sstevel@tonic-gate 	(lbp)->lb_refcnt++; \
268*0Sstevel@tonic-gate 	mutex_exit(&(lbp)->lb_lock); \
269*0Sstevel@tonic-gate }
270*0Sstevel@tonic-gate 
271*0Sstevel@tonic-gate #define	LOG_BUFFER_RELE(lbp)	{ \
272*0Sstevel@tonic-gate 	log_buffer_rele(lbp); \
273*0Sstevel@tonic-gate }
274*0Sstevel@tonic-gate 
275*0Sstevel@tonic-gate #define	EXPTABLESIZE	16
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate /*
278*0Sstevel@tonic-gate  * A node associated with an export entry on the
279*0Sstevel@tonic-gate  * list of exported filesystems.
280*0Sstevel@tonic-gate  *
281*0Sstevel@tonic-gate  * exi_count+exi_lock protects an individual exportinfo from being freed
282*0Sstevel@tonic-gate  * when in use.
283*0Sstevel@tonic-gate  * You must have the writer lock on exported_lock to add/delete an exportinfo
284*0Sstevel@tonic-gate  * structure to/from the list.
285*0Sstevel@tonic-gate  *
286*0Sstevel@tonic-gate  * exi_volatile_dev maps to VSW_VOLATILEDEV.  It means that the
287*0Sstevel@tonic-gate  * underlying fs devno can change on each mount.  When set, the server
288*0Sstevel@tonic-gate  * should not use va_fsid for a GETATTR(FATTR4_FSID) reply.  It must
289*0Sstevel@tonic-gate  * use exi_fsid because it is guaranteed to be persistent.  This isn't
290*0Sstevel@tonic-gate  * in any way related to NFS4 volatile filehandles.
291*0Sstevel@tonic-gate  */
292*0Sstevel@tonic-gate struct exportinfo {
293*0Sstevel@tonic-gate 	struct exportdata	exi_export;
294*0Sstevel@tonic-gate 	fsid_t			exi_fsid;
295*0Sstevel@tonic-gate 	struct fid		exi_fid;
296*0Sstevel@tonic-gate 	struct exportinfo	*exi_hash;
297*0Sstevel@tonic-gate 	fhandle_t		exi_fh;
298*0Sstevel@tonic-gate 	krwlock_t		exi_cache_lock;
299*0Sstevel@tonic-gate 	kmutex_t		exi_lock;
300*0Sstevel@tonic-gate 	uint_t			exi_count;
301*0Sstevel@tonic-gate 	vnode_t			*exi_vp;
302*0Sstevel@tonic-gate 	vnode_t			*exi_dvp;
303*0Sstevel@tonic-gate 	struct auth_cache	*exi_cache[AUTH_TABLESIZE];
304*0Sstevel@tonic-gate 	struct log_buffer	*exi_logbuffer;
305*0Sstevel@tonic-gate 	struct exp_visible	*exi_visible;
306*0Sstevel@tonic-gate 	unsigned		exi_volatile_dev:1;
307*0Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST
308*0Sstevel@tonic-gate 	uint32_t		exi_volatile_id;
309*0Sstevel@tonic-gate 	struct ex_vol_rename	*exi_vol_rename;
310*0Sstevel@tonic-gate 	kmutex_t		exi_vol_rename_lock;
311*0Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */
312*0Sstevel@tonic-gate };
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate /*
315*0Sstevel@tonic-gate  * exp_visible is a visible list per filesystem. It is for filesystems
316*0Sstevel@tonic-gate  * that may need a limited view of its contents. A pseudo export and
317*0Sstevel@tonic-gate  * a real export at the mount point (VROOT) which has a subtree shared
318*0Sstevel@tonic-gate  * has a visible list.
319*0Sstevel@tonic-gate  *
320*0Sstevel@tonic-gate  * The exi_visible field is NULL for normal, non=pseudo filesystems
321*0Sstevel@tonic-gate  * which do not have any subtree exported. If the field is non-null,
322*0Sstevel@tonic-gate  * it points to a list of visible entries, identified by vis_fid and/or
323*0Sstevel@tonic-gate  * vis_ino. The presence of a "visible" list means that if this export
324*0Sstevel@tonic-gate  * can only have a limited view, it can only view the entries in the
325*0Sstevel@tonic-gate  * exp_visible list. The directories in the fid list comprise paths that
326*0Sstevel@tonic-gate  * lead to exported directories.
327*0Sstevel@tonic-gate  *
328*0Sstevel@tonic-gate  * The vis_count field records the number of paths in this filesystem
329*0Sstevel@tonic-gate  * that use this directory. The vis_exported field is non-zero if the
330*0Sstevel@tonic-gate  * entry is an exported directory (leaf node).
331*0Sstevel@tonic-gate  */
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate struct exp_visible {
334*0Sstevel@tonic-gate 	vnode_t			*vis_vp;
335*0Sstevel@tonic-gate 	fid_t			vis_fid;
336*0Sstevel@tonic-gate 	u_longlong_t		vis_ino;
337*0Sstevel@tonic-gate 	int			vis_count;
338*0Sstevel@tonic-gate 	int			vis_exported;
339*0Sstevel@tonic-gate 	struct exp_visible	*vis_next;
340*0Sstevel@tonic-gate };
341*0Sstevel@tonic-gate 
342*0Sstevel@tonic-gate #define	PSEUDO(exi)	((exi)->exi_export.ex_flags & EX_PSEUDO)
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate #define	EQFSID(fsidp1, fsidp2)	\
345*0Sstevel@tonic-gate 	(((fsidp1)->val[0] == (fsidp2)->val[0]) && \
346*0Sstevel@tonic-gate 	    ((fsidp1)->val[1] == (fsidp2)->val[1]))
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate #define	EQFID(fidp1, fidp2)	\
349*0Sstevel@tonic-gate 	((fidp1)->fid_len == (fidp2)->fid_len && \
350*0Sstevel@tonic-gate 	    nfs_fhbcmp((char *)(fidp1)->fid_data, (char *)(fidp2)->fid_data, \
351*0Sstevel@tonic-gate 	    (uint_t)(fidp1)->fid_len) == 0)
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate #define	exportmatch(exi, fsid, fid)	\
354*0Sstevel@tonic-gate 	(EQFSID(&(exi)->exi_fsid, (fsid)) && EQFID(&(exi)->exi_fid, (fid)))
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate /*
357*0Sstevel@tonic-gate  * Returns true iff exported filesystem is read-only to the given host.
358*0Sstevel@tonic-gate  *
359*0Sstevel@tonic-gate  * Note:  this macro should be as fast as possible since it's called
360*0Sstevel@tonic-gate  * on each NFS modification request.
361*0Sstevel@tonic-gate  */
362*0Sstevel@tonic-gate #define	rdonly(exi, req)  (nfsauth_access(exi, req) & NFSAUTH_RO)
363*0Sstevel@tonic-gate #define	rdonly4(exi, vp, req)  \
364*0Sstevel@tonic-gate 	(vn_is_readonly(vp) || \
365*0Sstevel@tonic-gate 	    (nfsauth4_access(exi, vp, req) & (NFSAUTH_RO | NFSAUTH_LIMITED)))
366*0Sstevel@tonic-gate 
367*0Sstevel@tonic-gate extern int	nfsauth4_access(struct exportinfo *, vnode_t *,
368*0Sstevel@tonic-gate 				struct svc_req *);
369*0Sstevel@tonic-gate extern int	nfsauth4_secinfo_access(struct exportinfo *,
370*0Sstevel@tonic-gate 				struct svc_req *, int, int);
371*0Sstevel@tonic-gate extern int	nfs_fhhash(fsid_t *, fid_t *);
372*0Sstevel@tonic-gate extern int	nfs_fhbcmp(char *, char *, int);
373*0Sstevel@tonic-gate extern int	nfs_exportinit(void);
374*0Sstevel@tonic-gate extern void	nfs_exportfini(void);
375*0Sstevel@tonic-gate extern int	chk_clnt_sec(struct exportinfo *, struct svc_req *req);
376*0Sstevel@tonic-gate extern int	makefh(fhandle_t *, struct vnode *, struct exportinfo *);
377*0Sstevel@tonic-gate extern int	makefh_ol(fhandle_t *, struct exportinfo *, uint_t);
378*0Sstevel@tonic-gate extern int	makefh3(nfs_fh3 *, struct vnode *, struct exportinfo *);
379*0Sstevel@tonic-gate extern int	makefh3_ol(nfs_fh3 *, struct exportinfo *, uint_t);
380*0Sstevel@tonic-gate extern vnode_t *nfs_fhtovp(fhandle_t *, struct exportinfo *);
381*0Sstevel@tonic-gate extern vnode_t *nfs3_fhtovp(nfs_fh3 *, struct exportinfo *);
382*0Sstevel@tonic-gate extern vnode_t *lm_fhtovp(fhandle_t *fh);
383*0Sstevel@tonic-gate extern vnode_t *lm_nfs3_fhtovp(nfs_fh3 *fh);
384*0Sstevel@tonic-gate extern struct	exportinfo *checkexport(fsid_t *, struct fid *);
385*0Sstevel@tonic-gate extern struct	exportinfo *checkexport4(fsid_t *, struct fid *, vnode_t *vp);
386*0Sstevel@tonic-gate extern void	exi_rele(struct exportinfo *);
387*0Sstevel@tonic-gate extern struct exportinfo *nfs_vptoexi(vnode_t *, vnode_t *, cred_t *, int *,
388*0Sstevel@tonic-gate     int *, bool_t);
389*0Sstevel@tonic-gate extern int	nfs_check_vpexi(vnode_t *, vnode_t *, cred_t *,
390*0Sstevel@tonic-gate 			struct exportinfo **);
391*0Sstevel@tonic-gate extern void	export_link(struct exportinfo *);
392*0Sstevel@tonic-gate extern int	export_unlink(fsid_t *, fid_t *, vnode_t *,
393*0Sstevel@tonic-gate 			struct exportinfo **);
394*0Sstevel@tonic-gate extern vnode_t *untraverse(vnode_t *);
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate /*
397*0Sstevel@tonic-gate  * Functions that handle the NFSv4 server namespace
398*0Sstevel@tonic-gate  */
399*0Sstevel@tonic-gate extern int	treeclimb_export(struct exportinfo *);
400*0Sstevel@tonic-gate extern int	treeclimb_unexport(struct exportinfo *);
401*0Sstevel@tonic-gate extern int	nfs_visible(struct exportinfo *, vnode_t *, int *);
402*0Sstevel@tonic-gate extern int	nfs_visible_inode(struct exportinfo *, ino64_t, int *);
403*0Sstevel@tonic-gate extern int	has_visible(struct exportinfo *, vnode_t *);
404*0Sstevel@tonic-gate extern void	free_visible(struct exp_visible *);
405*0Sstevel@tonic-gate extern int	nfs_exported(struct exportinfo *, vnode_t *);
406*0Sstevel@tonic-gate extern int	pseudo_exportfs(vnode_t *, struct exp_visible *,
407*0Sstevel@tonic-gate 					struct exportdata *);
408*0Sstevel@tonic-gate extern int	vop_fid_pseudo(vnode_t *, fid_t *fidp);
409*0Sstevel@tonic-gate extern int	nfs4_vget_pseudo(struct exportinfo *, vnode_t **, fid_t *);
410*0Sstevel@tonic-gate /*
411*0Sstevel@tonic-gate  * Functions that handle the NFSv4 server namespace security flavors
412*0Sstevel@tonic-gate  * information.
413*0Sstevel@tonic-gate  */
414*0Sstevel@tonic-gate extern void	srv_secinfo_exp2pseu(struct exportdata *, struct exportdata *);
415*0Sstevel@tonic-gate 
416*0Sstevel@tonic-gate /*
417*0Sstevel@tonic-gate  * "public" and default (root) location for public filehandle
418*0Sstevel@tonic-gate  */
419*0Sstevel@tonic-gate extern struct exportinfo *exi_public, *exi_root;
420*0Sstevel@tonic-gate extern fhandle_t nullfh2;	/* for comparing V2 filehandles */
421*0Sstevel@tonic-gate extern krwlock_t exported_lock;
422*0Sstevel@tonic-gate extern struct exportinfo *exptable[];
423*0Sstevel@tonic-gate 
424*0Sstevel@tonic-gate /*
425*0Sstevel@tonic-gate  * Two macros for identifying public filehandles.
426*0Sstevel@tonic-gate  * A v2 public filehandle is 32 zero bytes.
427*0Sstevel@tonic-gate  * A v3 public filehandle is zero length.
428*0Sstevel@tonic-gate  */
429*0Sstevel@tonic-gate #define	PUBLIC_FH2(fh) \
430*0Sstevel@tonic-gate 	((fh)->fh_fsid.val[1] == 0 && \
431*0Sstevel@tonic-gate 	bcmp((fh), &nullfh2, sizeof (fhandle_t)) == 0)
432*0Sstevel@tonic-gate 
433*0Sstevel@tonic-gate #define	PUBLIC_FH3(fh) \
434*0Sstevel@tonic-gate 	((fh)->fh3_length == 0)
435*0Sstevel@tonic-gate 
436*0Sstevel@tonic-gate extern int	makefh4(nfs_fh4 *, struct vnode *, struct exportinfo *);
437*0Sstevel@tonic-gate extern vnode_t *nfs4_fhtovp(nfs_fh4 *, struct exportinfo *, nfsstat4 *);
438*0Sstevel@tonic-gate 
439*0Sstevel@tonic-gate #endif /* _KERNEL */
440*0Sstevel@tonic-gate 
441*0Sstevel@tonic-gate #ifdef	__cplusplus
442*0Sstevel@tonic-gate }
443*0Sstevel@tonic-gate #endif
444*0Sstevel@tonic-gate 
445*0Sstevel@tonic-gate #endif	/* _NFS_EXPORT_H */
446