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