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