xref: /titanic_51/usr/src/uts/common/sys/fs/autofs.h (revision dd1104fbe0f0f41434502f335b9f0b34999f771c)
1 /*
2  * CDDL HEADER START
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_FS_AUTOFS_H
27 #define	_SYS_FS_AUTOFS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <rpc/clnt.h>
32 #include <gssapi/gssapi.h>
33 #include <sys/vfs.h>
34 #include <sys/dirent.h>
35 #include <sys/types.h>
36 #include <sys/types32.h>
37 #include <sys/note.h>
38 #include <sys/time_impl.h>
39 #include <sys/mntent.h>
40 #include <nfs/mount.h>
41 #include <rpc/rpcsec_gss.h>
42 #include <sys/zone.h>
43 #include <sys/door.h>
44 #include <rpcsvc/autofs_prot.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 
51 #ifdef	_KERNEL
52 
53 
54 /*
55  * Tracing macro; expands to nothing for non-debug kernels.
56  */
57 #ifndef DEBUG
58 #define	AUTOFS_DPRINT(x)
59 #else
60 #define	AUTOFS_DPRINT(x)	auto_dprint x
61 #endif
62 
63 /*
64  * Per AUTOFS mountpoint information.
65  */
66 typedef struct fninfo {
67 	struct vfs	*fi_mountvfs;		/* mounted-here VFS */
68 	struct vnode	*fi_rootvp;		/* root vnode */
69 	struct knetconfig fi_knconf;		/* netconfig */
70 	struct netbuf	fi_addr;		/* daemon address */
71 	char		*fi_path;		/* autofs mountpoint */
72 	char 		*fi_map;		/* context/map-name */
73 	char		*fi_subdir;		/* subdir within map */
74 	char		*fi_key;		/* key to use on direct maps */
75 	char		*fi_opts;		/* default mount options */
76 	int		fi_pathlen;		/* autofs mountpoint len */
77 	int		fi_maplen;		/* size of context */
78 	int		fi_subdirlen;
79 	int		fi_keylen;
80 	int		fi_optslen;		/* default mount options len */
81 	int		fi_refcnt;		/* reference count */
82 	int		fi_flags;
83 	int		fi_mount_to;
84 	int		fi_rpc_to;
85 	zoneid_t	fi_zoneid;		/* zone mounted in */
86 } fninfo_t;
87 
88 /*
89  * The AUTOFS locking scheme:
90  *
91  * The locks:
92  * 	fn_lock: protects the fn_node. It must be grabbed to change any
93  *		 field on the fn_node, except for those protected by
94  *		 fn_rwlock.
95  *
96  * 	fn_rwlock: readers/writers lock to protect the subdirectory and
97  *		   top level list traversal.
98  *		   Protects: fn_dirents
99  *			     fn_next
100  *		             fn_size
101  *		             fn_linkcnt
102  *                 - Grab readers when checking if certain fn_node exists
103  *                   under fn_dirents.
104  *		   - Grab readers when attempting to reference a node
105  *                   pointed to by fn_dirents, fn_next, and fn_parent.
106  *                 - Grab writers to add a new fnnode under fn_dirents and
107  *		     to remove a node pointed to by fn_dirents or fn_next.
108  *
109  *
110  * The flags:
111  *	MF_INPROG:
112  *		- Indicates a mount request has been sent to the daemon.
113  *		- If this flag is set, the thread sets MF_WAITING on the
114  *                fnnode and sleeps.
115  *
116  *	MF_WAITING:
117  *		- Set by a thread when it puts itself to sleep waiting for
118  *		  the ongoing operation on this fnnode to be done.
119  *
120  * 	MF_LOOKUP:
121  * 		- Indicates a lookup request has been sent to the daemon.
122  *		- If this flag is set, the thread sets MF_WAITING on the
123  *                fnnode and sleeps.
124  *
125  *	MF_IK_MOUNT:
126  *		- This flag is set to indicate the mount was done in the
127  *		  kernel, and so should the unmount.
128  *
129  *	MF_DIRECT:
130  *		- Direct mountpoint if set, indirect otherwise.
131  *
132  *	MF_TRIGGER:
133  *		- This is a trigger node.
134  *
135  *	MF_THISUID_MATCH_RQD:
136  *		- User-relative context binding kind of node.
137  *		- Node with this flag set requires a name match as well
138  *		  as a cred match in order to be returned from the directory
139  *		  hierarchy.
140  *
141  * 	MF_MOUNTPOINT:
142  * 		- At some point automountd mounted a filesystem on this node.
143  * 		If fn_trigger is non-NULL, v_vfsmountedhere is NULL and this
144  * 		flag is set then the filesystem must have been forcibly
145  * 		unmounted.
146  */
147 
148 /*
149  * The inode of AUTOFS
150  */
151 typedef struct fnnode {
152 	char		*fn_name;
153 	char		*fn_symlink;		/* if VLNK, this is what it */
154 						/* points to */
155 	int		fn_namelen;
156 	int		fn_symlinklen;
157 	uint_t		fn_linkcnt;		/* link count */
158 	mode_t		fn_mode;		/* file mode bits */
159 	uid_t		fn_uid;			/* owner's uid */
160 	gid_t		fn_gid;			/* group's uid */
161 	int		fn_error;		/* mount/lookup error */
162 	ino_t		fn_nodeid;
163 	off_t		fn_offset;		/* offset into directory */
164 	int		fn_flags;
165 	uint_t		fn_size;		/* size of directory */
166 	struct vnode	*fn_vnode;
167 	struct fnnode	*fn_parent;
168 	struct fnnode	*fn_next;		/* sibling */
169 	struct fnnode	*fn_dirents;		/* children */
170 	struct fnnode	*fn_trigger; 		/* pointer to next level */
171 						/* AUTOFS trigger nodes */
172 	struct action_list *fn_alp;		/* Pointer to mount info */
173 						/* used for remounting */
174 						/* trigger nodes */
175 	cred_t		*fn_cred;		/* pointer to cred, used for */
176 						/* "thisuser" processing */
177 	krwlock_t	fn_rwlock;		/* protects list traversal */
178 	kmutex_t	fn_lock;		/* protects the fnnode */
179 	timestruc_t	fn_atime;
180 	timestruc_t	fn_mtime;
181 	timestruc_t	fn_ctime;
182 	time_t		fn_ref_time;		/* time last referenced */
183 	time_t		fn_unmount_ref_time;	/* last time unmount was done */
184 	kcondvar_t	fn_cv_mount;		/* mount blocking variable */
185 	struct vnode	*fn_seen;		/* vnode already traversed */
186 	kthread_t	*fn_thread;		/* thread that has currently */
187 						/* modified fn_seen */
188 	struct autofs_globals *fn_globals;	/* global variables */
189 } fnnode_t;
190 
191 
192 #define	vntofn(vp)	((struct fnnode *)((vp)->v_data))
193 #define	fntovn(fnp)	(((fnp)->fn_vnode))
194 #define	vfstofni(vfsp)	((struct fninfo *)((vfsp)->vfs_data))
195 
196 #define	MF_DIRECT	0x001
197 #define	MF_INPROG	0x002		/* Mount in progress */
198 #define	MF_WAITING	0x004
199 #define	MF_LOOKUP	0x008		/* Lookup in progress */
200 #define	MF_ATTR_WAIT	0x010
201 #define	MF_IK_MOUNT	0x040
202 #define	MF_TRIGGER	0x080
203 #define	MF_THISUID_MATCH_RQD	0x100	/* UID match required for this node */
204 					/* required for thisuser kind of */
205 					/* nodes */
206 #define	MF_MOUNTPOINT	0x200		/* Node is/was a mount point */
207 
208 #define	AUTOFS_MODE		0555
209 #define	AUTOFS_BLOCKSIZE	1024
210 
211 struct autofs_callargs {
212 	fnnode_t	*fnc_fnp;	/* fnnode */
213 	char		*fnc_name;	/* path to lookup/mount */
214 	kthread_t	*fnc_origin;	/* thread that fired up this thread */
215 					/* used for debugging purposes */
216 	cred_t		*fnc_cred;
217 };
218 
219 struct autofs_globals {
220 	fnnode_t		*fng_rootfnnodep;
221 	int			fng_fnnode_count;
222 	int			fng_printed_not_running_msg;
223 	kmutex_t		fng_unmount_threads_lock;
224 	int			fng_unmount_threads;
225 	int			fng_verbose;
226 	zoneid_t		fng_zoneid;
227 	pid_t			fng_autofs_pid;
228 	kmutex_t		fng_autofs_daemon_lock;
229 	/*
230 	 * autofs_daemon_lock protects fng_autofs_daemon_dh
231 	 */
232 	door_handle_t		fng_autofs_daemon_dh;
233 };
234 
235 extern kmutex_t autofs_minor_lock;
236 extern zone_key_t autofs_key;
237 
238 /*
239  * Sets the MF_INPROG flag on this fnnode.
240  * fnp->fn_lock should be held before this macro is called,
241  * operation is either MF_INPROG or MF_LOOKUP.
242  */
243 #define	AUTOFS_BLOCK_OTHERS(fnp, operation)	{ \
244 	ASSERT(MUTEX_HELD(&(fnp)->fn_lock)); \
245 	ASSERT(!((fnp)->fn_flags & operation)); \
246 	(fnp)->fn_flags |= (operation); \
247 }
248 
249 #define	AUTOFS_UNBLOCK_OTHERS(fnp, operation)	{ \
250 	auto_unblock_others((fnp), (operation)); \
251 }
252 
253 extern struct vnodeops *auto_vnodeops;
254 extern const struct fs_operation_def auto_vnodeops_template[];
255 
256 /*
257  * Utility routines
258  */
259 extern int auto_search(fnnode_t *, char *, fnnode_t **, cred_t *);
260 extern int auto_enter(fnnode_t *, char *, fnnode_t **, cred_t *);
261 extern void auto_unblock_others(fnnode_t *, uint_t);
262 extern int auto_wait4mount(fnnode_t *);
263 extern fnnode_t *auto_makefnnode(vtype_t, vfs_t *, char *, cred_t *,
264     struct autofs_globals *);
265 extern void auto_freefnnode(fnnode_t *);
266 extern void auto_disconnect(fnnode_t *, fnnode_t *);
267 extern void auto_do_unmount(struct autofs_globals *);
268 /*PRINTFLIKE4*/
269 extern void auto_log(int verbose, zoneid_t zoneid, int level,
270 	const char *fmt, ...)
271     __KPRINTFLIKE(4);
272 /*PRINTFLIKE2*/
273 extern void auto_dprint(int level, const char *fmt, ...)
274     __KPRINTFLIKE(2);
275 extern int auto_calldaemon(zoneid_t, int, xdrproc_t, void *, xdrproc_t,
276 	void *, int, bool_t);
277 extern int auto_lookup_aux(fnnode_t *, char *, cred_t *);
278 extern void auto_new_mount_thread(fnnode_t *, char *, cred_t *);
279 extern int auto_nobrowse_option(char *);
280 
281 extern void unmount_tree(struct autofs_globals *, int);
282 extern void autofs_free_globals(struct autofs_globals *);
283 extern void autofs_shutdown_zone(struct autofs_globals *);
284 /*
285  * external routines not defined in any header file
286  */
287 extern bool_t xdr_uid_t(XDR *, uid_t *);
288 
289 #endif	/* _KERNEL */
290 
291 /*
292  * autofs structures and defines needed for use with doors.
293  */
294 #define	AUTOFS_NULL	0
295 #define	AUTOFS_MOUNT	1
296 #define	AUTOFS_UNMOUNT	2
297 #define	AUTOFS_READDIR	3
298 #define	AUTOFS_LOOKUP	4
299 #define	AUTOFS_SRVINFO	5
300 #define	AUTOFS_MNTINFO	6
301 
302 /*
303  * autofs_door_args is a generic structure used to grab the command
304  * from any of the argument structures passed in.
305  */
306 
307 typedef struct {
308 	int cmd;
309 	int xdr_len;
310 	char xdr_arg[1];	/* buffer holding xdr encoded data */
311 } autofs_door_args_t;
312 
313 
314 typedef struct {
315 	int res_status;
316 	int xdr_len;
317 	char xdr_res[1];	/* buffer holding xdr encoded data */
318 } autofs_door_res_t;
319 
320 typedef enum autofs_res autofs_res_t;
321 typedef enum autofs_stat autofs_stat_t;
322 typedef enum autofs_action autofs_action_t;
323 
324 typedef struct {
325 	void *	atsd_buf;
326 	size_t	atsd_len;
327 } autofs_tsd_t;
328 
329 typedef struct sec_desdata {
330 	int		nd_sec_syncaddr_len;
331 	int		nd_sec_knc_semantics;
332 	int		nd_sec_netnamelen;
333 	uint64_t	nd_sec_knc_rdev;
334 	int		nd_sec_knc_unused[8];
335 } sec_desdata_t;
336 
337 typedef struct sec_gssdata {
338 	int			element_length;
339 	rpc_gss_service_t	service;
340 	char			uname[MAX_NAME_LEN];
341 	char			inst[MAX_NAME_LEN];
342 	char			realm[MAX_NAME_LEN];
343 	uint_t			qop;
344 } sec_gssdata_t;
345 
346 typedef struct nfs_secdata  {
347 	sec_desdata_t	nfs_des_clntdata;
348 	sec_gssdata_t	nfs_gss_clntdata;
349 } nfs_secdata_t;
350 
351 /*
352  * Comma separated list of mntoptions which are inherited when the
353  * "restrict" option is present.  The RESTRICT option must be first!
354  * This define is shared between the kernel and the automount daemon.
355  */
356 #define	RESTRICTED_MNTOPTS	\
357 	MNTOPT_RESTRICT, MNTOPT_NOSUID, MNTOPT_NOSETUID, MNTOPT_NODEVICES
358 
359 /*
360  * AUTOFS syscall entry point
361  */
362 enum autofssys_op { AUTOFS_UNMOUNTALL, AUTOFS_SETDOOR };
363 
364 #ifdef	_KERNEL
365 extern int autofssys(enum autofssys_op, uintptr_t);
366 
367 #endif	/* _KERNEL */
368 
369 #ifdef	__cplusplus
370 }
371 #endif
372 
373 #endif	/* _SYS_FS_AUTOFS_H */
374