xref: /titanic_52/usr/src/uts/common/sys/fs/autofs.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FS_AUTOFS_H
28 #define	_SYS_FS_AUTOFS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <rpcsvc/autofs_prot.h>
33 #include <rpc/rpc.h>
34 #include <sys/note.h>
35 #include <sys/time_impl.h>
36 #include <sys/types.h>
37 #include <sys/mntent.h>
38 #include <sys/zone.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 #ifdef	_KERNEL
45 
46 struct action_list;
47 
48 /*
49  * Tracing macro; expands to nothing for non-debug kernels.
50  */
51 #ifndef DEBUG
52 #define	AUTOFS_DPRINT(x)
53 #else
54 #define	AUTOFS_DPRINT(x)	auto_dprint x
55 #endif
56 
57 /*
58  * Per AUTOFS mountpoint information.
59  */
60 typedef struct fninfo {
61 	struct vfs	*fi_mountvfs;		/* mounted-here VFS */
62 	struct vnode	*fi_rootvp;		/* root vnode */
63 	struct knetconfig fi_knconf;		/* netconfig */
64 	struct netbuf	fi_addr;		/* daemon address */
65 	char		*fi_path;		/* autofs mountpoint */
66 	char 		*fi_map;		/* context/map-name */
67 	char		*fi_subdir;		/* subdir within map */
68 	char		*fi_key;		/* key to use on direct maps */
69 	char		*fi_opts;		/* default mount options */
70 	int		fi_pathlen;		/* autofs mountpoint len */
71 	int		fi_maplen;		/* size of context */
72 	int		fi_subdirlen;
73 	int		fi_keylen;
74 	int		fi_optslen;		/* default mount options len */
75 	int		fi_refcnt;		/* reference count */
76 	int		fi_flags;
77 	int		fi_mount_to;
78 	int		fi_rpc_to;
79 	zoneid_t	fi_zoneid;		/* zone mounted in */
80 } fninfo_t;
81 
82 /*
83  * The AUTOFS locking scheme:
84  *
85  * The locks:
86  * 	fn_lock: protects the fn_node. It must be grabbed to change any
87  *		 field on the fn_node, except for those protected by
88  *		 fn_rwlock.
89  *
90  * 	fn_rwlock: readers/writers lock to protect the subdirectory and
91  *		   top level list traversal.
92  *		   Protects: fn_dirents
93  *			     fn_next
94  *		             fn_size
95  *		             fn_linkcnt
96  *                 - Grab readers when checking if certain fn_node exists
97  *                   under fn_dirents.
98  *		   - Grab readers when attempting to reference a node
99  *                   pointed to by fn_dirents, fn_next, and fn_parent.
100  *                 - Grab writers to add a new fnnode under fn_dirents and
101  *		     to remove a node pointed to by fn_dirents or fn_next.
102  *
103  *
104  * The flags:
105  *	MF_INPROG:
106  *		- Indicates a mount request has been sent to the daemon.
107  *		- If this flag is set, the thread sets MF_WAITING on the
108  *                fnnode and sleeps.
109  *
110  *	MF_WAITING:
111  *		- Set by a thread when it puts itself to sleep waiting for
112  *		  the ongoing operation on this fnnode to be done.
113  *
114  * 	MF_LOOKUP:
115  * 		- Indicates a lookup request has been sent to the daemon.
116  *		- If this flag is set, the thread sets MF_WAITING on the
117  *                fnnode and sleeps.
118  *
119  *	MF_IK_MOUNT:
120  *		- This flag is set to indicate the mount was done in the
121  *		  kernel, and so should the unmount.
122  *
123  *	MF_DIRECT:
124  *		- Direct mountpoint if set, indirect otherwise.
125  *
126  *	MF_TRIGGER:
127  *		- This is a trigger node.
128  *
129  *	MF_THISUID_MATCH_RQD:
130  *		- User-relative context binding kind of node.
131  *		- Node with this flag set requires a name match as well
132  *		  as a cred match in order to be returned from the directory
133  *		  hierarchy.
134  *
135  * 	MF_MOUNTPOINT:
136  * 		- At some point automountd mounted a filesystem on this node.
137  * 		If fn_trigger is non-NULL, v_vfsmountedhere is NULL and this
138  * 		flag is set then the filesystem must have been forcibly
139  * 		unmounted.
140  */
141 
142 /*
143  * The inode of AUTOFS
144  */
145 typedef struct fnnode {
146 	char		*fn_name;
147 	char		*fn_symlink;		/* if VLNK, this is what it */
148 						/* points to */
149 	int		fn_namelen;
150 	int		fn_symlinklen;
151 	uint_t		fn_linkcnt;		/* link count */
152 	mode_t		fn_mode;		/* file mode bits */
153 	uid_t		fn_uid;			/* owner's uid */
154 	gid_t		fn_gid;			/* group's uid */
155 	int		fn_error;		/* mount/lookup error */
156 	ino_t		fn_nodeid;
157 	off_t		fn_offset;		/* offset into directory */
158 	int		fn_flags;
159 	uint_t		fn_size;		/* size of directory */
160 	struct vnode	*fn_vnode;
161 	struct fnnode	*fn_parent;
162 	struct fnnode	*fn_next;		/* sibling */
163 	struct fnnode	*fn_dirents;		/* children */
164 	struct fnnode	*fn_trigger; 		/* pointer to next level */
165 						/* AUTOFS trigger nodes */
166 	struct action_list *fn_alp;		/* Pointer to mount info */
167 						/* used for remounting */
168 						/* trigger nodes */
169 	cred_t		*fn_cred;		/* pointer to cred, used for */
170 						/* "thisuser" processing */
171 	krwlock_t	fn_rwlock;		/* protects list traversal */
172 	kmutex_t	fn_lock;		/* protects the fnnode */
173 	timestruc_t	fn_atime;
174 	timestruc_t	fn_mtime;
175 	timestruc_t	fn_ctime;
176 	time_t		fn_ref_time;		/* time last referenced */
177 	time_t		fn_unmount_ref_time;	/* last time unmount was done */
178 	kcondvar_t	fn_cv_mount;		/* mount blocking variable */
179 	struct vnode	*fn_seen;		/* vnode already traversed */
180 	kthread_t	*fn_thread;		/* thread that has currently */
181 						/* modified fn_seen */
182 	struct autofs_globals *fn_globals;	/* global variables */
183 } fnnode_t;
184 
185 #define	vntofn(vp)	((struct fnnode *)((vp)->v_data))
186 #define	fntovn(fnp)	(((fnp)->fn_vnode))
187 #define	vfstofni(vfsp)	((struct fninfo *)((vfsp)->vfs_data))
188 
189 #define	MF_DIRECT	0x001
190 #define	MF_INPROG	0x002		/* Mount in progress */
191 #define	MF_WAITING	0x004
192 #define	MF_LOOKUP	0x008		/* Lookup in progress */
193 #define	MF_ATTR_WAIT	0x010
194 #define	MF_IK_MOUNT	0x040
195 #define	MF_TRIGGER	0x080
196 #define	MF_THISUID_MATCH_RQD	0x100	/* UID match required for this node */
197 					/* required for thisuser kind of */
198 					/* nodes */
199 #define	MF_MOUNTPOINT	0x200		/* Node is/was a mount point */
200 
201 #define	AUTOFS_MODE		0555
202 #define	AUTOFS_BLOCKSIZE	1024
203 
204 struct autofs_callargs {
205 	fnnode_t	*fnc_fnp;	/* fnnode */
206 	char		*fnc_name;	/* path to lookup/mount */
207 	kthread_t	*fnc_origin;	/* thread that fired up this thread */
208 					/* used for debugging purposes */
209 	cred_t		*fnc_cred;
210 };
211 
212 struct autofs_globals {
213 	fnnode_t		*fng_rootfnnodep;
214 	int			fng_fnnode_count;
215 	int			fng_printed_not_running_msg;
216 	kmutex_t		fng_unmount_threads_lock;
217 	int			fng_unmount_threads;
218 	int			fng_verbose;
219 	zoneid_t		fng_zoneid;
220 };
221 
222 extern zone_key_t autofs_key;
223 
224 /*
225  * Sets the MF_INPROG flag on this fnnode.
226  * fnp->fn_lock should be held before this macro is called,
227  * operation is either MF_INPROG or MF_LOOKUP.
228  */
229 #define	AUTOFS_BLOCK_OTHERS(fnp, operation)	{ \
230 	ASSERT(MUTEX_HELD(&(fnp)->fn_lock)); \
231 	ASSERT(!((fnp)->fn_flags & operation)); \
232 	(fnp)->fn_flags |= (operation); \
233 }
234 
235 #define	AUTOFS_UNBLOCK_OTHERS(fnp, operation)	{ \
236 	auto_unblock_others((fnp), (operation)); \
237 }
238 
239 extern struct vnodeops *auto_vnodeops;
240 extern const struct fs_operation_def auto_vnodeops_template[];
241 
242 /*
243  * Utility routines
244  */
245 extern int auto_search(fnnode_t *, char *, fnnode_t **, cred_t *);
246 extern int auto_enter(fnnode_t *, char *, fnnode_t **, cred_t *);
247 extern void auto_unblock_others(fnnode_t *, uint_t);
248 extern int auto_wait4mount(fnnode_t *);
249 extern fnnode_t *auto_makefnnode(vtype_t, vfs_t *, char *, cred_t *,
250     struct autofs_globals *);
251 extern void auto_freefnnode(fnnode_t *);
252 extern void auto_disconnect(fnnode_t *, fnnode_t *);
253 extern void auto_do_unmount(struct autofs_globals *);
254 /*PRINTFLIKE3*/
255 extern void auto_log(struct autofs_globals *, int level, const char *fmt, ...)
256     __KPRINTFLIKE(3);
257 /*PRINTFLIKE2*/
258 extern void auto_dprint(int level, const char *fmt, ...)
259     __KPRINTFLIKE(2);
260 extern int auto_calldaemon(fninfo_t *, rpcproc_t, xdrproc_t, void *,
261 	xdrproc_t, void *, cred_t *, bool_t);
262 extern int auto_lookup_aux(fnnode_t *, char *, cred_t *);
263 extern void auto_new_mount_thread(fnnode_t *, char *, cred_t *);
264 extern int auto_nobrowse_option(char *);
265 
266 extern void unmount_tree(struct autofs_globals *, int);
267 extern void autofs_free_globals(struct autofs_globals *);
268 extern void autofs_shutdown_zone(struct autofs_globals *);
269 /*
270  * external routines not defined in any header file
271  */
272 extern bool_t xdr_uid_t(XDR *, uid_t *);
273 
274 #endif	/* _KERNEL */
275 
276 /*
277  * Comma separated list of mntoptions which are inherited when the
278  * "restrict" option is present.  The RESTRICT option must be first!
279  * This define is shared between the kernel and the automount daemon.
280  */
281 #define	RESTRICTED_MNTOPTS	\
282 	MNTOPT_RESTRICT, MNTOPT_NOSUID, MNTOPT_NOSETUID, MNTOPT_NODEVICES
283 
284 /*
285  * AUTOFS syscall entry point
286  */
287 enum autofssys_op { AUTOFS_UNMOUNTALL };
288 
289 #ifdef	_KERNEL
290 extern int autofssys(enum autofssys_op, uintptr_t);
291 
292 #endif	/* _KERNEL */
293 
294 #ifdef	__cplusplus
295 }
296 #endif
297 
298 #endif	/* _SYS_FS_AUTOFS_H */
299