xref: /titanic_51/usr/src/uts/common/sys/fs/sdev_impl.h (revision 23b5c241225a8ade2b6b9f06ebb891ee459e3b02)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_SDEV_IMPL_H
27 #define	_SYS_SDEV_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <rpc/rpc.h>
36 #include <sys/dirent.h>
37 #include <sys/vfs.h>
38 #include <sys/list.h>
39 #include <sys/nvpair.h>
40 
41 /*
42  * sdev_nodes are the file-system specific part of the
43  * vnodes for the device filesystem.
44  *
45  * The device filesystem exports two node types:
46  *
47  * VDIR nodes		to represent directories
48  * VCHR & VBLK nodes	to represent devices
49  */
50 
51 /*
52  * /dev mount arguments
53  */
54 struct sdev_mountargs {
55 	uint64_t sdev_attrdir;
56 };
57 
58 
59 /*
60  * Nvpair names of profile information (list of device files available) of
61  * non-global /dev mounts.  These strings must be unique among them.
62  */
63 #define	SDEV_NVNAME_MOUNTPT	"prof_mountpt"
64 #define	SDEV_NVNAME_INCLUDE	"prof_include"
65 #define	SDEV_NVNAME_EXCLUDE	"prof_exclude"
66 #define	SDEV_NVNAME_SYMLINK	"prof_symlink"
67 #define	SDEV_NVNAME_MAP		"prof_map"
68 
69 /*
70  * supported devfsadm_cmd
71  */
72 #define	DEVFSADMD_RUN_ALL	1
73 #define	DEVFSADMD_NS_LOOKUP	2
74 #define	DEVFSADMD_NS_READDIR	3
75 
76 /*
77  * supported protocols
78  */
79 typedef enum devname_spec {
80 	DEVNAME_NS_NONE = 0,
81 	DEVNAME_NS_PATH,	/* physical /devices path */
82 	DEVNAME_NS_DEV		/* /dev path */
83 } devname_spec_t;
84 
85 /*
86  * devfsadm_error codes
87  */
88 #define	DEVFSADM_RUN_INVALID		1
89 #define	DEVFSADM_RUN_EPERM		2
90 #define	DEVFSADM_RUN_NOTSUP		3
91 #define	DEVFSADM_NS_FAILED		4
92 
93 typedef struct sdev_ns_handle {
94 	char	ns_name[MAXPATHLEN];	/* device to be looked up */
95 	char	ns_map[MAXPATHLEN];
96 } sdev_ns_handle_t;
97 
98 typedef struct sdev_lkp_handle {
99 	devname_spec_t	devfsadm_spec;	/* returned path property */
100 	char	devfsadm_link[MAXPATHLEN]; /* symlink destination */
101 } sdev_lkp_handle_t;
102 
103 typedef struct sdev_rdr_handle {
104 	uint32_t ns_mapcount;	/* number of entries in the map */
105 	uint32_t maplist_size;
106 } sdev_rdr_handle_t;
107 
108 /*
109  * devfsadm/devname door data structures
110  */
111 typedef struct sdev_door_arg {
112 	uint8_t devfsadm_cmd;	/* what to do for devfsadm[d] */
113 	sdev_ns_handle_t ns_hdl;
114 } sdev_door_arg_t;
115 
116 typedef struct sdev_door_res {
117 	int32_t devfsadm_error;
118 	sdev_lkp_handle_t ns_lkp_hdl;
119 	sdev_rdr_handle_t ns_rdr_hdl;
120 } sdev_door_res_t;
121 
122 #ifdef _KERNEL
123 
124 struct sdev_dprof {
125 	int has_glob;
126 	nvlist_t *dev_name;
127 	nvlist_t *dev_map;
128 	nvlist_t *dev_symlink;
129 	nvlist_t *dev_glob_incdir;
130 	nvlist_t *dev_glob_excdir;
131 };
132 
133 /*
134  * devname_handle_t
135  */
136 struct devname_handle {
137 	struct sdev_node *dh_data;	/* the sdev_node */
138 	devname_spec_t dh_spec;
139 	void    *dh_args;
140 };
141 typedef struct devname_handle devname_handle_t;
142 
143 /*
144  * Per-instance node data for the global zone instance
145  * Only one mount of /dev in the global zone
146  */
147 typedef struct sdev_global_data {
148 	struct devname_handle sdev_ghandle;
149 	struct devname_nsmap *sdev_gmapinfo;	/* VDIR name service info */
150 	ulong_t		sdev_dir_ggen;		/* name space generation # */
151 } sdev_global_data_t;
152 
153 /*
154  * Per-instance node data - profile data per non-global zone mount instance
155  */
156 typedef struct sdev_local_data {
157 	ulong_t sdev_dir_lgen;		/* cached generation # of /dev dir */
158 	ulong_t sdev_devtree_lgen;	/* cached generation # of devtree */
159 	struct sdev_node *sdev_lorigin;	/* corresponding global sdev_node */
160 	struct sdev_dprof sdev_lprof;	/* profile for multi-inst */
161 } sdev_local_data_t;
162 
163 /*
164  * /dev filesystem sdev_node defines
165  */
166 typedef struct sdev_node {
167 	char		*sdev_name;	/* node name */
168 	size_t		sdev_namelen;	/* strlen(sdev_name) */
169 	char		*sdev_path;	/* absolute path */
170 	char		*sdev_symlink;	/* source for a symlink */
171 	struct vnode	*sdev_vnode;	/* vnode */
172 
173 	krwlock_t	sdev_contents;	/* rw lock for this data structure */
174 	struct sdev_node *sdev_dotdot;	/* parent */
175 	struct sdev_node *sdev_dot;	/* child: VDIR: head of children */
176 	struct sdev_node *sdev_next;	/* sibling: next in this directory */
177 
178 	struct vnode	*sdev_attrvp;	/* backing store vnode if persisted */
179 	struct vattr	*sdev_attr;	/* memory copy of the vattr */
180 
181 	ino64_t		sdev_ino;	/* inode */
182 	uint_t		sdev_nlink;	/* link count */
183 	int		sdev_state;	/* state of this node */
184 	int		sdev_flags;	/* flags bit */
185 
186 	kmutex_t	sdev_lookup_lock; /* node creation synch lock */
187 	kcondvar_t	sdev_lookup_cv;	/* node creation sync cv */
188 	int		sdev_lookup_flags; /* node creation flags */
189 
190 	/* per-instance data, either global or non-global zone */
191 	union {
192 		struct sdev_global_data	sdev_globaldata;
193 		struct sdev_local_data	sdev_localdata;
194 	} sdev_instance_data;
195 } sdev_node_t;
196 
197 #define	sdev_ldata sdev_instance_data.sdev_localdata
198 #define	sdev_gdata sdev_instance_data.sdev_globaldata
199 
200 #define	sdev_handle		sdev_gdata.sdev_ghandle
201 #define	sdev_mapinfo		sdev_gdata.sdev_gmapinfo
202 #define	sdev_gdir_gen		sdev_gdata.sdev_dir_ggen
203 
204 #define	sdev_ldir_gen		sdev_ldata.sdev_dir_lgen
205 #define	sdev_devtree_gen	sdev_ldata.sdev_devtree_lgen
206 #define	sdev_origin		sdev_ldata.sdev_lorigin
207 #define	sdev_prof		sdev_ldata.sdev_lprof
208 
209 /*
210  * sdev_state
211  *
212  * A sdev_node may go through 3 states:
213  *	SDEV_INIT: When a new /dev file is first looked up, a sdev_node
214  *		   is allocated, initialized and added to the directory's
215  *		   sdev_node cache. A node at this state will also
216  *		   have the SDEV_LOOKUP flag set.
217  *
218  *		   Other threads that are trying to look up a node at
219  *		   this state will be blocked until the SDEV_LOOKUP flag
220  *		   is cleared.
221  *
222  *		   When the SDEV_LOOKUP flag is cleared, the node may
223  *		   transition into the SDEV_READY state for a successful
224  *		   lookup or the node is removed from the directory cache
225  *		   and destroyed if the named node can not be found.
226  *		   An ENOENT error is returned for the second case.
227  *
228  *	SDEV_READY: A /dev file has been successfully looked up and
229  *		    associated with a vnode. The /dev file is available
230  *		    for the supported /dev filesystem operations.
231  *
232  *	SDEV_ZOMBIE: Deletion of a /dev file has been explicitely issued
233  *		    to an SDEV_READY node. The node is transitioned into
234  *		    the SDEV_ZOMBIE state if the vnode reference count
235  *		    is still held. A SDEV_ZOMBIE node does not support
236  *		    any of the /dev filesystem operations. A SDEV_ZOMBIE
237  *		    node is removed from the directory cache and destroyed
238  *		    once the reference count reaches "zero".
239  */
240 typedef enum {
241 	SDEV_ZOMBIE = -1,
242 	SDEV_INIT = 0,
243 	SDEV_READY
244 } sdev_node_state_t;
245 
246 /* sdev_flags */
247 #define	SDEV_BUILD	0x0001	/* directory cache out-of-date */
248 #define	SDEV_STALE	0x0002	/* stale sdev nodes */
249 #define	SDEV_GLOBAL	0x0004	/* global /dev nodes */
250 #define	SDEV_PERSIST	0x0008	/* backing store persisted node */
251 #define	SDEV_NO_NCACHE	0x0010	/* do not include in neg. cache */
252 #define	SDEV_DYNAMIC	0x0020	/* special-purpose vnode ops (ex: pts) */
253 #define	SDEV_VTOR	0x0040	/* validate sdev_nodes during search */
254 
255 /* sdev_lookup_flags */
256 #define	SDEV_LOOKUP	0x0001	/* node creation in progress */
257 #define	SDEV_READDIR	0x0002	/* VDIR readdir in progress */
258 #define	SDEV_LGWAITING	0x0004	/* waiting for devfsadm completion */
259 
260 #define	SDEV_VTOR_INVALID	-1
261 #define	SDEV_VTOR_SKIP		0
262 #define	SDEV_VTOR_VALID		1
263 
264 /* convenient macros */
265 #define	SDEV_IS_GLOBAL(dv)	\
266 	(dv->sdev_flags & SDEV_GLOBAL)
267 #define	SDEV_IS_PERSIST(dv)	\
268 	(dv->sdev_flags & SDEV_PERSIST)
269 #define	SDEV_IS_DYNAMIC(dv)	\
270 	(dv->sdev_flags & SDEV_DYNAMIC)
271 #define	SDEV_IS_NO_NCACHE(dv)	\
272 	(dv->sdev_flags & SDEV_NO_NCACHE)
273 
274 #define	SDEV_IS_LOOKUP(dv)	\
275 	(dv->sdev_lookup_flags & SDEV_LOOKUP)
276 #define	SDEV_IS_READDIR(dv)	\
277 	(dv->sdev_lookup_flags & SDEV_READDIR)
278 #define	SDEV_IS_LGWAITING(dv)	\
279 	(dv->sdev_lookup_flags  & SDEV_LGWAITING)
280 
281 #define	SDEVTOV(n)	((struct vnode *)(n)->sdev_vnode)
282 #define	VTOSDEV(vp)	((struct sdev_node *)(vp)->v_data)
283 #define	VN_HELD(v)	((v)->v_count != 0)
284 #define	SDEV_HELD(dv)	(VN_HELD(SDEVTOV(dv)))
285 #define	SDEV_HOLD(dv)	VN_HOLD(SDEVTOV(dv))
286 #define	SDEV_RELE(dv)	VN_RELE(SDEVTOV(dv))
287 #define	SDEV_SIMPLE_RELE(dv)	{	\
288 	mutex_enter(&SDEVTOV(dv)->v_lock);	\
289 	SDEVTOV(dv)->v_count--;	\
290 	mutex_exit(&SDEVTOV(dv)->v_lock);	\
291 }
292 
293 #define	SDEV_ACL_FLAVOR(vp)	(VFSTOSDEVFS(vp->v_vfsp)->sdev_acl_flavor)
294 
295 /*
296  * some defaults
297  */
298 #define	SDEV_ROOTINO		((ino_t)2)
299 #define	SDEV_UID_DEFAULT	(0)
300 #define	SDEV_GID_DEFAULT	(3)
301 #define	SDEV_DIRMODE_DEFAULT	(S_IFDIR |0755)
302 #define	SDEV_DEVMODE_DEFAULT	(0600)
303 #define	SDEV_LNKMODE_DEFAULT	(S_IFLNK | 0777)
304 
305 extern struct vattr sdev_vattr_dir;
306 extern struct vattr sdev_vattr_lnk;
307 extern struct vattr sdev_vattr_blk;
308 extern struct vattr sdev_vattr_chr;
309 
310 /*
311  * devname_lookup_func()
312  */
313 extern int devname_lookup_func(struct sdev_node *, char *, struct vnode **,
314     struct cred *, int (*)(struct sdev_node *, char *, void **, struct cred *,
315     void *, char *), int);
316 
317 /*
318  * flags used by devname_lookup_func callbacks
319  */
320 #define	SDEV_PATH	0x1	/* callback returning /devices physical path */
321 #define	SDEV_VNODE	0x2	/* callback returning backing store vnode */
322 #define	SDEV_VATTR	0x4	/* callback returning node vattr */
323 
324 /*
325  * devname_readdir_func()
326  */
327 extern int devname_readdir_func(vnode_t *, uio_t *, cred_t *, int *, int);
328 
329 /*
330  * flags for devname_readdir_func
331  */
332 #define	SDEV_BROWSE	0x1	/* fetch all entries from backing store */
333 
334 /*
335  * devname_setattr_func()
336  */
337 extern int devname_setattr_func(struct vnode *, struct vattr *, int,
338     struct cred *, int (*)(struct sdev_node *, struct vattr *, int), int);
339 
340 /*
341  * /dev file system instance defines
342  */
343 /*
344  * /dev version of vfs_data
345  */
346 struct sdev_data {
347 	struct sdev_data	*sdev_prev;
348 	struct sdev_data	*sdev_next;
349 	struct sdev_node	*sdev_root;
350 	struct vfs		*sdev_vfsp;
351 	struct sdev_mountargs	*sdev_mountargs;
352 	ulong_t			sdev_acl_flavor;
353 };
354 
355 #define	VFSTOSDEVFS(vfsp)	((struct sdev_data *)((vfsp)->vfs_data))
356 
357 /*
358  * sdev_fid overlays the fid structure (for VFS_VGET)
359  */
360 struct sdev_fid {
361 	uint16_t	sdevfid_len;
362 	ino32_t		sdevfid_ino;
363 	int32_t		sdevfid_gen;
364 };
365 
366 /*
367  * devfsadm and devname communication defines
368  */
369 typedef enum {
370 	DEVNAME_DEVFSADM_STOPPED = 0,	/* devfsadm has never run */
371 	DEVNAME_DEVFSADM_RUNNING,	/* devfsadm is running */
372 	DEVNAME_DEVFSADM_RUN		/* devfsadm ran once */
373 } devname_devfsadm_state_t;
374 
375 extern volatile uint_t  devfsadm_state; /* atomic mask for devfsadm status */
376 
377 #define	DEVNAME_DEVFSADM_SET_RUNNING(devfsadm_state)	\
378 	devfsadm_state = DEVNAME_DEVFSADM_RUNNING
379 #define	DEVNAME_DEVFSADM_SET_STOP(devfsadm_state)	\
380 	devfsadm_state = DEVNAME_DEVFSADM_STOPPED
381 #define	DEVNAME_DEVFSADM_SET_RUN(devfsadm_state)	\
382 	devfsadm_state = DEVNAME_DEVFSADM_RUN
383 #define	DEVNAME_DEVFSADM_IS_RUNNING(devfsadm_state)	\
384 	devfsadm_state == DEVNAME_DEVFSADM_RUNNING
385 #define	DEVNAME_DEVFSADM_HAS_RUN(devfsadm_state)	\
386 	(devfsadm_state == DEVNAME_DEVFSADM_RUN)
387 
388 #define	SDEV_BLOCK_OTHERS(dv, cmd)	{	\
389 	ASSERT(MUTEX_HELD(&dv->sdev_lookup_lock));	\
390 	dv->sdev_lookup_flags |= cmd;			\
391 }
392 extern void sdev_unblock_others(struct sdev_node *, uint_t);
393 #define	SDEV_UNBLOCK_OTHERS(dv, cmd)	{	\
394 	sdev_unblock_others(dv, cmd);		\
395 }
396 
397 #define	SDEV_CLEAR_LOOKUP_FLAGS(dv, cmd)	{	\
398 	dv->sdev_lookup_flags &= ~cmd;	\
399 }
400 
401 extern int sdev_wait4lookup(struct sdev_node *, int);
402 extern int devname_filename_register(int, char *);
403 extern int devname_nsmaps_register(char *, size_t);
404 extern void sdev_devfsadm_lockinit(void);
405 extern void sdev_devfsadm_lockdestroy(void);
406 extern void devname_add_devfsadm_node(char *);
407 extern void sdev_devfsadmd_thread(struct sdev_node *, struct sdev_node *,
408     struct cred *);
409 extern int devname_profile_update(char *, size_t);
410 extern struct sdev_data *sdev_find_mntinfo(char *);
411 void sdev_mntinfo_rele(struct sdev_data *);
412 extern struct vnodeops *devpts_getvnodeops(void);
413 
414 /*
415  * Directory Based Device Naming (DBNR) defines
416  */
417 
418 #define	ETC_DEV_DIR		"/etc/dev"
419 #define	DEVNAME_NSCONFIG	"sdev_nsconfig_mod"
420 
421 /*
422  * directory name rule
423  */
424 struct devname_nsmap {
425 	struct devname_nsmap	*prev;	/* previous entry */
426 	struct devname_nsmap	*next;	/* next entry */
427 	char	*dir_name;	/* /dev subdir name, e.g. /dev/disk */
428 	char	*dir_module;	/* devname module impl the operations */
429 	char	*dir_map;	/* dev naming rules, e.g. /etc/dev/disks */
430 	struct devname_ops *dir_ops;	/* directory specific vnode ops */
431 	char    *dir_newmodule; /* to be reloaded  */
432 	char    *dir_newmap;    /* to be reloaded */
433 	int	dir_invalid;    /* map entry obsolete */
434 	int	dir_maploaded;	/* map contents read */
435 	krwlock_t dir_lock;	/* protects the data structure */
436 };
437 
438 /*
439  * name-property pairs to be looked up
440  */
441 typedef struct devname_lkp_arg {
442 	char *devname_dir;	/* the directory to look */
443 	char *devname_name;	/* the device name to be looked up */
444 	char *devname_map;	/* the directory device naming map */
445 	int reserved;
446 } devname_lkp_arg_t;
447 
448 /*
449  * name-value-property restured
450  */
451 typedef struct devname_lkp_result {
452 	devname_spec_t	devname_spec;	/* link to /devices or /dev */
453 	char	*devname_link;		/* the source path */
454 	int	reserved;
455 } devname_lkp_result_t;
456 
457 /*
458  * directory name-value populating results
459  */
460 typedef struct devname_rdr_result {
461 	uint32_t	ns_mapcount;
462 } devname_rdr_result_t;
463 
464 /*
465  * sdev_nsrdr work
466  */
467 typedef struct sdev_nsrdr_work {
468 	char *dir_name;
469 	char *dir_map;
470 	struct sdev_node *dir_dv;
471 	devname_rdr_result_t **result;
472 	struct sdev_nsrdr_work *next;
473 } sdev_nsrdr_work_t;
474 
475 
476 /*
477  * boot states - warning, the ordering here is significant
478  *
479  * the difference between "system available" and "boot complete"
480  * is a debounce timeout to catch some daemon issuing a readdir
481  * triggering a nuisance implict reconfig on each boot.
482  */
483 #define	SDEV_BOOT_STATE_INITIAL		0
484 #define	SDEV_BOOT_STATE_RECONFIG	1	/* reconfig */
485 #define	SDEV_BOOT_STATE_SYSAVAIL	2	/* system available */
486 #define	SDEV_BOOT_STATE_COMPLETE	3	/* boot complete */
487 
488 /*
489  * Negative cache list and list element
490  * The mutex protects the flags against multiple accesses and
491  * must only be acquired when already holding the r/w lock.
492  */
493 typedef struct sdev_nc_list {
494 	list_t		ncl_list;	/* the list itself */
495 	kmutex_t	ncl_mutex;	/* protects ncl_flags */
496 	krwlock_t	ncl_lock;	/* protects ncl_list */
497 	int		ncl_flags;
498 	int		ncl_nentries;
499 } sdev_nc_list_t;
500 
501 typedef struct sdev_nc_node {
502 	char		*ncn_name;	/* name of the node */
503 	int		ncn_flags;	/* state information */
504 	int		ncn_expirecnt;	/* remove once expired */
505 	list_node_t	ncn_link;	/* link to next in list */
506 } sdev_nc_node_t;
507 
508 /* ncl_flags */
509 #define	NCL_LIST_DIRTY		0x01	/* needs to be flushed */
510 #define	NCL_LIST_WRITING	0x02	/* write in progress */
511 #define	NCL_LIST_WENABLE	0x04	/* write-enabled post boot */
512 
513 /* ncn_flags */
514 #define	NCN_ACTIVE	0x01	/* a lookup has occurred */
515 #define	NCN_SRC_STORE	0x02	/* src: persistent store */
516 #define	NCN_SRC_CURRENT	0x04	/* src: current boot */
517 
518 /* sdev_lookup_failed flags */
519 #define	SLF_NO_NCACHE	0x01	/* node should not be added to ncache */
520 #define	SLF_REBUILT	0x02	/* reconfig performed during lookup attempt */
521 
522 /*
523  * The nvlist name and nvpair identifiers in the
524  * /etc/devices/devname_cache nvlist format
525  */
526 #define	DP_DEVNAME_ID			"devname"
527 #define	DP_DEVNAME_NCACHE_ID		"ncache"
528 #define	DP_DEVNAME_NC_EXPIRECNT_ID	"expire-counts"
529 
530 /* devname-cache list element */
531 typedef struct nvp_devname {
532 	char			**nvp_paths;
533 	int			*nvp_expirecnts;
534 	int			nvp_npaths;
535 	list_node_t		nvp_link;
536 } nvp_devname_t;
537 
538 /*
539  * name service globals and prototypes
540  */
541 
542 extern struct devname_ops *devname_ns_ops;
543 extern int devname_nsmaps_loaded;
544 extern kmutex_t devname_nsmaps_lock;
545 
546 extern void sdev_invalidate_nsmaps(void);
547 extern void sdev_validate_nsmaps(void);
548 extern int sdev_module_register(char *, struct devname_ops *);
549 extern struct devname_nsmap *sdev_get_nsmap_by_dir(char *, int);
550 extern struct devname_nsmap *sdev_get_nsmap_by_module(char *);
551 extern void sdev_dispatch_to_nsrdr_thread(struct sdev_node *, char *,
552     devname_rdr_result_t *);
553 extern void sdev_insert_nsmap(char *, char *, char *);
554 extern int devname_nsmap_lookup(devname_lkp_arg_t *, devname_lkp_result_t **);
555 extern struct devname_nsmap *sdev_get_map(struct sdev_node *, int);
556 extern int sdev_nsmaps_loaded(void);
557 extern void sdev_replace_nsmap(struct devname_nsmap *, char *, char *);
558 extern int sdev_nsmaps_reloaded(void);
559 extern int devname_get_dir_nsmap(devname_handle_t *, struct devname_nsmap **);
560 
561 /*
562  * vnodeops and vfsops helpers
563  */
564 
565 typedef enum {
566 	SDEV_CACHE_ADD = 0,
567 	SDEV_CACHE_DELETE
568 } sdev_cache_ops_t;
569 
570 extern struct sdev_node *sdev_cache_lookup(struct sdev_node *, char *);
571 extern int sdev_cache_update(struct sdev_node *, struct sdev_node **, char *,
572     sdev_cache_ops_t);
573 extern void sdev_node_cache_init(void);
574 extern void sdev_node_cache_fini(void);
575 extern struct sdev_node *sdev_mkroot(struct vfs *, dev_t, struct vnode *,
576     struct vnode *, struct cred *);
577 extern int sdev_mknode(struct sdev_node *, char *, struct sdev_node **,
578     struct vattr *, struct vnode *, void *, struct cred *, sdev_node_state_t);
579 extern int sdev_nodeinit(struct sdev_node *, char *, struct sdev_node **,
580     vattr_t *);
581 extern int sdev_nodeready(struct sdev_node *, vattr_t *, vnode_t *, void *,
582     cred_t *);
583 extern int sdev_shadow_node(struct sdev_node *, struct cred *);
584 extern void sdev_nodedestroy(struct sdev_node *, uint_t);
585 extern void sdev_update_timestamps(struct vnode *, cred_t *, uint_t);
586 extern void sdev_vattr_merge(struct sdev_node *, struct vattr *);
587 extern void sdev_devstate_change(void);
588 extern int sdev_lookup_filter(sdev_node_t *, char *);
589 extern void sdev_lookup_failed(sdev_node_t *, char *, int);
590 extern int sdev_unlocked_access(void *, int, struct cred *);
591 
592 #define	SDEV_ENFORCE	0x1
593 extern void sdev_stale(struct sdev_node *);
594 extern int sdev_cleandir(struct sdev_node *, char *, uint_t);
595 extern int sdev_rnmnode(struct sdev_node *, struct sdev_node *,
596     struct sdev_node *, struct sdev_node **, char *, struct cred *);
597 extern size_t add_dir_entry(dirent64_t *, char *, size_t, ino_t, offset_t);
598 extern int sdev_to_vp(struct sdev_node *, struct vnode **);
599 extern ino_t sdev_mkino(struct sdev_node *);
600 extern int devname_backstore_lookup(struct sdev_node *, char *,
601     struct vnode **);
602 extern int sdev_is_devfs_node(char *);
603 extern int sdev_copyin_mountargs(struct mounta *, struct sdev_mountargs *);
604 extern int sdev_reserve_subdirs(struct sdev_node *);
605 extern int prof_lookup();
606 extern void prof_filldir(struct sdev_node *);
607 extern int devpts_validate(struct sdev_node *dv);
608 extern void *sdev_get_vtor(struct sdev_node *dv);
609 
610 /*
611  * devinfo helpers
612  */
613 extern int sdev_modctl_readdir(const char *, char ***, int *, int *);
614 extern void sdev_modctl_readdir_free(char **, int, int);
615 extern int sdev_modctl_devexists(const char *);
616 
617 
618 /*
619  * ncache handlers
620  */
621 
622 extern void sdev_ncache_init(void);
623 extern void sdev_ncache_setup(void);
624 extern void sdev_ncache_teardown(void);
625 extern void sdev_nc_addname(sdev_nc_list_t *, sdev_node_t *, char *, int);
626 extern void sdev_nc_node_exists(sdev_node_t *);
627 extern void sdev_nc_path_exists(sdev_nc_list_t *, char *);
628 extern void sdev_modctl_dump_files(void);
629 
630 /*
631  * globals
632  */
633 extern kmutex_t sdev_lock;
634 extern int devtype;
635 extern kmem_cache_t *sdev_node_cache;
636 extern struct vnodeops		*sdev_vnodeops;
637 extern struct vnodeops		*devpts_vnodeops;
638 extern struct sdev_data *sdev_origins; /* mount info for global /dev instance */
639 extern const fs_operation_def_t	sdev_vnodeops_tbl[];
640 extern const fs_operation_def_t	devpts_vnodeops_tbl[];
641 extern const fs_operation_def_t	devsys_vnodeops_tbl[];
642 extern const fs_operation_def_t	devpseudo_vnodeops_tbl[];
643 
644 extern sdev_nc_list_t	*sdev_ncache;
645 extern int		sdev_reconfig_boot;
646 extern int		sdev_boot_state;
647 extern int		sdev_reconfig_verbose;
648 extern int		sdev_reconfig_disable;
649 extern int		sdev_nc_disable;
650 extern int		sdev_nc_disable_reset;
651 extern int		sdev_nc_verbose;
652 
653 /*
654  * misc. defines
655  */
656 #ifdef DEBUG
657 extern int sdev_debug;
658 #define	SDEV_DEBUG		0x01	/* error messages to console/log */
659 #define	SDEV_DEBUG_VOPS 	0x02	/* vnode ops errors */
660 #define	SDEV_DEBUG_DLF		0x04	/* trace devname_lookup_func */
661 #define	SDEV_DEBUG_DRF		0x08	/* trace devname_readdir_func */
662 #define	SDEV_DEBUG_NCACHE	0x10	/* negative cache tracing */
663 #define	SDEV_DEBUG_DEVFSADMD	0x20	/* comm. of devnamefs & devfsadm */
664 #define	SDEV_DEBUG_PTS		0x40	/* /dev/pts tracing */
665 #define	SDEV_DEBUG_RECONFIG	0x80	/* events triggering reconfig */
666 #define	SDEV_DEBUG_SDEV_NODE	0x100	/* trace sdev_node activities */
667 #define	SDEV_DEBUG_PROFILE	0x200	/* trace sdev_profile */
668 #define	SDEV_DEBUG_MODCTL	0x400	/* trace modctl activity */
669 #define	SDEV_DEBUG_FLK		0x800	/* trace failed lookups */
670 
671 #define	sdcmn_err(args)  if (sdev_debug & SDEV_DEBUG) printf args
672 #define	sdcmn_err2(args) if (sdev_debug & SDEV_DEBUG_VOPS) printf args
673 #define	sdcmn_err3(args) if (sdev_debug & SDEV_DEBUG_DLF) printf args
674 #define	sdcmn_err4(args) if (sdev_debug & SDEV_DEBUG_DRF) printf args
675 #define	sdcmn_err5(args) if (sdev_debug & SDEV_DEBUG_NCACHE) printf args
676 #define	sdcmn_err6(args) if (sdev_debug & SDEV_DEBUG_DEVFSADMD) printf args
677 #define	sdcmn_err7(args) if (sdev_debug & SDEV_DEBUG_PTS) printf args
678 #define	sdcmn_err8(args) if (sdev_debug & SDEV_DEBUG_RECONFIG) printf args
679 #define	sdcmn_err9(args) if (sdev_debug & SDEV_DEBUG_SDEV_NODE) printf args
680 #define	sdcmn_err10(args) if (sdev_debug & SDEV_DEBUG_PROFILE) printf args
681 #define	sdcmn_err11(args) if (sdev_debug & SDEV_DEBUG_MODCTL) printf args
682 #define	impossible(args) printf args
683 #else
684 #define	sdcmn_err(args)		/* does nothing */
685 #define	sdcmn_err2(args)	/* does nothing */
686 #define	sdcmn_err3(args)	/* does nothing */
687 #define	sdcmn_err4(args)	/* does nothing */
688 #define	sdcmn_err5(args)	/* does nothing */
689 #define	sdcmn_err6(args)	/* does nothing */
690 #define	sdcmn_err7(args)	/* does nothing */
691 #define	sdcmn_err8(args)	/* does nothing */
692 #define	sdcmn_err9(args)	/* does nothing */
693 #define	sdcmn_err10(args)	/* does nothing */
694 #define	sdcmn_err11(args)	/* does nothing */
695 #define	impossible(args)	/* does nothing */
696 #endif
697 
698 #ifdef DEBUG
699 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)			\
700 	if ((sdev_debug & SDEV_DEBUG_FLK) ||				\
701 	    ((retried) && (sdev_debug & SDEV_DEBUG_RECONFIG))) {	\
702 		printf("lookup of %s/%s by %s failed, line %d\n",	\
703 		    (ddv)->sdev_name, (nm), curproc->p_user.u_comm,	\
704 		    __LINE__);						\
705 	}
706 #else
707 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)
708 #endif
709 
710 #endif	/* _KERNEL */
711 
712 #ifdef __cplusplus
713 }
714 #endif
715 
716 #endif	/* _SYS_SDEV_IMPL_H */
717