xref: /titanic_41/usr/src/uts/common/sys/fs/sdev_impl.h (revision 7b00d7d872f67ffdfbca4cb2abc79157786acb01)
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 2008 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 
197 	void		*sdev_private;
198 } sdev_node_t;
199 
200 #define	sdev_ldata sdev_instance_data.sdev_localdata
201 #define	sdev_gdata sdev_instance_data.sdev_globaldata
202 
203 #define	sdev_handle		sdev_gdata.sdev_ghandle
204 #define	sdev_mapinfo		sdev_gdata.sdev_gmapinfo
205 #define	sdev_gdir_gen		sdev_gdata.sdev_dir_ggen
206 
207 #define	sdev_ldir_gen		sdev_ldata.sdev_dir_lgen
208 #define	sdev_devtree_gen	sdev_ldata.sdev_devtree_lgen
209 #define	sdev_origin		sdev_ldata.sdev_lorigin
210 #define	sdev_prof		sdev_ldata.sdev_lprof
211 
212 /*
213  * sdev_state
214  *
215  * A sdev_node may go through 3 states:
216  *	SDEV_INIT: When a new /dev file is first looked up, a sdev_node
217  *		   is allocated, initialized and added to the directory's
218  *		   sdev_node cache. A node at this state will also
219  *		   have the SDEV_LOOKUP flag set.
220  *
221  *		   Other threads that are trying to look up a node at
222  *		   this state will be blocked until the SDEV_LOOKUP flag
223  *		   is cleared.
224  *
225  *		   When the SDEV_LOOKUP flag is cleared, the node may
226  *		   transition into the SDEV_READY state for a successful
227  *		   lookup or the node is removed from the directory cache
228  *		   and destroyed if the named node can not be found.
229  *		   An ENOENT error is returned for the second case.
230  *
231  *	SDEV_READY: A /dev file has been successfully looked up and
232  *		    associated with a vnode. The /dev file is available
233  *		    for the supported /dev filesystem operations.
234  *
235  *	SDEV_ZOMBIE: Deletion of a /dev file has been explicitely issued
236  *		    to an SDEV_READY node. The node is transitioned into
237  *		    the SDEV_ZOMBIE state if the vnode reference count
238  *		    is still held. A SDEV_ZOMBIE node does not support
239  *		    any of the /dev filesystem operations. A SDEV_ZOMBIE
240  *		    node is removed from the directory cache and destroyed
241  *		    once the reference count reaches "zero".
242  */
243 typedef enum {
244 	SDEV_ZOMBIE = -1,
245 	SDEV_INIT = 0,
246 	SDEV_READY
247 } sdev_node_state_t;
248 
249 /* sdev_flags */
250 #define	SDEV_BUILD		0x0001	/* directory cache out-of-date */
251 #define	SDEV_STALE		0x0002	/* stale sdev nodes */
252 #define	SDEV_GLOBAL		0x0004	/* global /dev nodes */
253 #define	SDEV_PERSIST		0x0008	/* backing store persisted node */
254 #define	SDEV_NO_NCACHE		0x0010	/* do not include in neg. cache */
255 #define	SDEV_DYNAMIC		0x0020	/* special-purpose vnode ops */
256 					/* (ex: pts) */
257 #define	SDEV_VTOR		0x0040	/* validate sdev_nodes during search */
258 #define	SDEV_ATTR_INVALID	0x0080	/* invalid node attributes, */
259 					/* need update */
260 
261 /* sdev_lookup_flags */
262 #define	SDEV_LOOKUP	0x0001	/* node creation in progress */
263 #define	SDEV_READDIR	0x0002	/* VDIR readdir in progress */
264 #define	SDEV_LGWAITING	0x0004	/* waiting for devfsadm completion */
265 
266 #define	SDEV_VTOR_INVALID	-1
267 #define	SDEV_VTOR_SKIP		0
268 #define	SDEV_VTOR_VALID		1
269 
270 /* convenient macros */
271 #define	SDEV_IS_GLOBAL(dv)	\
272 	(dv->sdev_flags & SDEV_GLOBAL)
273 #define	SDEV_IS_PERSIST(dv)	\
274 	(dv->sdev_flags & SDEV_PERSIST)
275 #define	SDEV_IS_DYNAMIC(dv)	\
276 	(dv->sdev_flags & SDEV_DYNAMIC)
277 #define	SDEV_IS_NO_NCACHE(dv)	\
278 	(dv->sdev_flags & SDEV_NO_NCACHE)
279 
280 #define	SDEV_IS_LOOKUP(dv)	\
281 	(dv->sdev_lookup_flags & SDEV_LOOKUP)
282 #define	SDEV_IS_READDIR(dv)	\
283 	(dv->sdev_lookup_flags & SDEV_READDIR)
284 #define	SDEV_IS_LGWAITING(dv)	\
285 	(dv->sdev_lookup_flags  & SDEV_LGWAITING)
286 
287 #define	SDEVTOV(n)	((struct vnode *)(n)->sdev_vnode)
288 #define	VTOSDEV(vp)	((struct sdev_node *)(vp)->v_data)
289 #define	VN_HELD(v)	((v)->v_count != 0)
290 #define	SDEV_HELD(dv)	(VN_HELD(SDEVTOV(dv)))
291 #define	SDEV_HOLD(dv)	VN_HOLD(SDEVTOV(dv))
292 #define	SDEV_RELE(dv)	VN_RELE(SDEVTOV(dv))
293 #define	SDEV_SIMPLE_RELE(dv)	{	\
294 	mutex_enter(&SDEVTOV(dv)->v_lock);	\
295 	SDEVTOV(dv)->v_count--;	\
296 	mutex_exit(&SDEVTOV(dv)->v_lock);	\
297 }
298 
299 #define	SDEV_ACL_FLAVOR(vp)	(VFSTOSDEVFS(vp->v_vfsp)->sdev_acl_flavor)
300 
301 /*
302  * some defaults
303  */
304 #define	SDEV_ROOTINO		((ino_t)2)
305 #define	SDEV_UID_DEFAULT	(0)
306 #define	SDEV_GID_DEFAULT	(3)
307 #define	SDEV_DIRMODE_DEFAULT	(S_IFDIR |0755)
308 #define	SDEV_DEVMODE_DEFAULT	(0600)
309 #define	SDEV_LNKMODE_DEFAULT	(S_IFLNK | 0777)
310 
311 extern struct vattr sdev_vattr_dir;
312 extern struct vattr sdev_vattr_lnk;
313 extern struct vattr sdev_vattr_blk;
314 extern struct vattr sdev_vattr_chr;
315 
316 /*
317  * devname_lookup_func()
318  */
319 extern int devname_lookup_func(struct sdev_node *, char *, struct vnode **,
320     struct cred *, int (*)(struct sdev_node *, char *, void **, struct cred *,
321     void *, char *), int);
322 
323 /*
324  * flags used by devname_lookup_func callbacks
325  */
326 #define	SDEV_PATH	0x1	/* callback returning /devices physical path */
327 #define	SDEV_VNODE	0x2	/* callback returning backing store vnode */
328 #define	SDEV_VATTR	0x4	/* callback returning node vattr */
329 
330 /*
331  * devname_readdir_func()
332  */
333 extern int devname_readdir_func(vnode_t *, uio_t *, cred_t *, int *, int);
334 
335 /*
336  * flags for devname_readdir_func
337  */
338 #define	SDEV_BROWSE	0x1	/* fetch all entries from backing store */
339 
340 /*
341  * devname_setattr_func()
342  */
343 extern int devname_setattr_func(struct vnode *, struct vattr *, int,
344     struct cred *, int (*)(struct sdev_node *, struct vattr *, int), int);
345 
346 /*
347  * devname_inactive_func()
348  */
349 extern void devname_inactive_func(struct vnode *, struct cred *,
350     void (*)(struct vnode *));
351 
352 /*
353  * /dev file system instance defines
354  */
355 /*
356  * /dev version of vfs_data
357  */
358 struct sdev_data {
359 	struct sdev_data	*sdev_prev;
360 	struct sdev_data	*sdev_next;
361 	struct sdev_node	*sdev_root;
362 	struct vfs		*sdev_vfsp;
363 	struct sdev_mountargs	*sdev_mountargs;
364 	ulong_t			sdev_acl_flavor;
365 };
366 
367 #define	VFSTOSDEVFS(vfsp)	((struct sdev_data *)((vfsp)->vfs_data))
368 
369 /*
370  * sdev_fid overlays the fid structure (for VFS_VGET)
371  */
372 struct sdev_fid {
373 	uint16_t	sdevfid_len;
374 	ino32_t		sdevfid_ino;
375 	int32_t		sdevfid_gen;
376 };
377 
378 /*
379  * devfsadm and devname communication defines
380  */
381 typedef enum {
382 	DEVNAME_DEVFSADM_STOPPED = 0,	/* devfsadm has never run */
383 	DEVNAME_DEVFSADM_RUNNING,	/* devfsadm is running */
384 	DEVNAME_DEVFSADM_RUN		/* devfsadm ran once */
385 } devname_devfsadm_state_t;
386 
387 extern volatile uint_t  devfsadm_state; /* atomic mask for devfsadm status */
388 
389 #define	DEVNAME_DEVFSADM_SET_RUNNING(devfsadm_state)	\
390 	devfsadm_state = DEVNAME_DEVFSADM_RUNNING
391 #define	DEVNAME_DEVFSADM_SET_STOP(devfsadm_state)	\
392 	devfsadm_state = DEVNAME_DEVFSADM_STOPPED
393 #define	DEVNAME_DEVFSADM_SET_RUN(devfsadm_state)	\
394 	devfsadm_state = DEVNAME_DEVFSADM_RUN
395 #define	DEVNAME_DEVFSADM_IS_RUNNING(devfsadm_state)	\
396 	devfsadm_state == DEVNAME_DEVFSADM_RUNNING
397 #define	DEVNAME_DEVFSADM_HAS_RUN(devfsadm_state)	\
398 	(devfsadm_state == DEVNAME_DEVFSADM_RUN)
399 
400 #define	SDEV_BLOCK_OTHERS(dv, cmd)	{	\
401 	ASSERT(MUTEX_HELD(&dv->sdev_lookup_lock));	\
402 	dv->sdev_lookup_flags |= cmd;			\
403 }
404 extern void sdev_unblock_others(struct sdev_node *, uint_t);
405 #define	SDEV_UNBLOCK_OTHERS(dv, cmd)	{	\
406 	sdev_unblock_others(dv, cmd);		\
407 }
408 
409 #define	SDEV_CLEAR_LOOKUP_FLAGS(dv, cmd)	{	\
410 	dv->sdev_lookup_flags &= ~cmd;	\
411 }
412 
413 extern int sdev_wait4lookup(struct sdev_node *, int);
414 extern int devname_filename_register(int, char *);
415 extern int devname_nsmaps_register(char *, size_t);
416 extern void sdev_devfsadm_lockinit(void);
417 extern void sdev_devfsadm_lockdestroy(void);
418 extern void devname_add_devfsadm_node(char *);
419 extern void sdev_devfsadmd_thread(struct sdev_node *, struct sdev_node *,
420     struct cred *);
421 extern int devname_profile_update(char *, size_t);
422 extern struct sdev_data *sdev_find_mntinfo(char *);
423 void sdev_mntinfo_rele(struct sdev_data *);
424 extern struct vnodeops *devpts_getvnodeops(void);
425 
426 /*
427  * Directory Based Device Naming (DBNR) defines
428  */
429 
430 #define	ETC_DEV_DIR		"/etc/dev"
431 #define	DEVNAME_NSCONFIG	"sdev_nsconfig_mod"
432 
433 /*
434  * directory name rule
435  */
436 struct devname_nsmap {
437 	struct devname_nsmap	*prev;	/* previous entry */
438 	struct devname_nsmap	*next;	/* next entry */
439 	char	*dir_name;	/* /dev subdir name, e.g. /dev/disk */
440 	char	*dir_module;	/* devname module impl the operations */
441 	char	*dir_map;	/* dev naming rules, e.g. /etc/dev/disks */
442 	struct devname_ops *dir_ops;	/* directory specific vnode ops */
443 	char    *dir_newmodule; /* to be reloaded  */
444 	char    *dir_newmap;    /* to be reloaded */
445 	int	dir_invalid;    /* map entry obsolete */
446 	int	dir_maploaded;	/* map contents read */
447 	krwlock_t dir_lock;	/* protects the data structure */
448 };
449 
450 /*
451  * name-property pairs to be looked up
452  */
453 typedef struct devname_lkp_arg {
454 	char *devname_dir;	/* the directory to look */
455 	char *devname_name;	/* the device name to be looked up */
456 	char *devname_map;	/* the directory device naming map */
457 	int reserved;
458 } devname_lkp_arg_t;
459 
460 /*
461  * name-value-property restured
462  */
463 typedef struct devname_lkp_result {
464 	devname_spec_t	devname_spec;	/* link to /devices or /dev */
465 	char	*devname_link;		/* the source path */
466 	int	reserved;
467 } devname_lkp_result_t;
468 
469 /*
470  * directory name-value populating results
471  */
472 typedef struct devname_rdr_result {
473 	uint32_t	ns_mapcount;
474 } devname_rdr_result_t;
475 
476 /*
477  * sdev_nsrdr work
478  */
479 typedef struct sdev_nsrdr_work {
480 	char *dir_name;
481 	char *dir_map;
482 	struct sdev_node *dir_dv;
483 	devname_rdr_result_t **result;
484 	struct sdev_nsrdr_work *next;
485 } sdev_nsrdr_work_t;
486 
487 
488 /*
489  * boot states - warning, the ordering here is significant
490  *
491  * the difference between "system available" and "boot complete"
492  * is a debounce timeout to catch some daemon issuing a readdir
493  * triggering a nuisance implict reconfig on each boot.
494  */
495 #define	SDEV_BOOT_STATE_INITIAL		0
496 #define	SDEV_BOOT_STATE_RECONFIG	1	/* reconfig */
497 #define	SDEV_BOOT_STATE_SYSAVAIL	2	/* system available */
498 #define	SDEV_BOOT_STATE_COMPLETE	3	/* boot complete */
499 
500 /*
501  * Negative cache list and list element
502  * The mutex protects the flags against multiple accesses and
503  * must only be acquired when already holding the r/w lock.
504  */
505 typedef struct sdev_nc_list {
506 	list_t		ncl_list;	/* the list itself */
507 	kmutex_t	ncl_mutex;	/* protects ncl_flags */
508 	krwlock_t	ncl_lock;	/* protects ncl_list */
509 	int		ncl_flags;
510 	int		ncl_nentries;
511 } sdev_nc_list_t;
512 
513 typedef struct sdev_nc_node {
514 	char		*ncn_name;	/* name of the node */
515 	int		ncn_flags;	/* state information */
516 	int		ncn_expirecnt;	/* remove once expired */
517 	list_node_t	ncn_link;	/* link to next in list */
518 } sdev_nc_node_t;
519 
520 /* ncl_flags */
521 #define	NCL_LIST_DIRTY		0x01	/* needs to be flushed */
522 #define	NCL_LIST_WRITING	0x02	/* write in progress */
523 #define	NCL_LIST_WENABLE	0x04	/* write-enabled post boot */
524 
525 /* ncn_flags */
526 #define	NCN_ACTIVE	0x01	/* a lookup has occurred */
527 #define	NCN_SRC_STORE	0x02	/* src: persistent store */
528 #define	NCN_SRC_CURRENT	0x04	/* src: current boot */
529 
530 /* sdev_lookup_failed flags */
531 #define	SLF_NO_NCACHE	0x01	/* node should not be added to ncache */
532 #define	SLF_REBUILT	0x02	/* reconfig performed during lookup attempt */
533 
534 /*
535  * The nvlist name and nvpair identifiers in the
536  * /etc/devices/devname_cache nvlist format
537  */
538 #define	DP_DEVNAME_ID			"devname"
539 #define	DP_DEVNAME_NCACHE_ID		"ncache"
540 #define	DP_DEVNAME_NC_EXPIRECNT_ID	"expire-counts"
541 
542 /* devname-cache list element */
543 typedef struct nvp_devname {
544 	char			**nvp_paths;
545 	int			*nvp_expirecnts;
546 	int			nvp_npaths;
547 	list_node_t		nvp_link;
548 } nvp_devname_t;
549 
550 /*
551  * name service globals and prototypes
552  */
553 
554 extern struct devname_ops *devname_ns_ops;
555 extern int devname_nsmaps_loaded;
556 extern kmutex_t devname_nsmaps_lock;
557 
558 extern void sdev_invalidate_nsmaps(void);
559 extern void sdev_validate_nsmaps(void);
560 extern int sdev_module_register(char *, struct devname_ops *);
561 extern struct devname_nsmap *sdev_get_nsmap_by_dir(char *, int);
562 extern struct devname_nsmap *sdev_get_nsmap_by_module(char *);
563 extern void sdev_dispatch_to_nsrdr_thread(struct sdev_node *, char *,
564     devname_rdr_result_t *);
565 extern void sdev_insert_nsmap(char *, char *, char *);
566 extern int devname_nsmap_lookup(devname_lkp_arg_t *, devname_lkp_result_t **);
567 extern struct devname_nsmap *sdev_get_map(struct sdev_node *, int);
568 extern int sdev_nsmaps_loaded(void);
569 extern void sdev_replace_nsmap(struct devname_nsmap *, char *, char *);
570 extern int sdev_nsmaps_reloaded(void);
571 extern int devname_get_dir_nsmap(devname_handle_t *, struct devname_nsmap **);
572 
573 /*
574  * vnodeops and vfsops helpers
575  */
576 
577 typedef enum {
578 	SDEV_CACHE_ADD = 0,
579 	SDEV_CACHE_DELETE
580 } sdev_cache_ops_t;
581 
582 extern struct sdev_node *sdev_cache_lookup(struct sdev_node *, char *);
583 extern int sdev_cache_update(struct sdev_node *, struct sdev_node **, char *,
584     sdev_cache_ops_t);
585 extern void sdev_node_cache_init(void);
586 extern void sdev_node_cache_fini(void);
587 extern struct sdev_node *sdev_mkroot(struct vfs *, dev_t, struct vnode *,
588     struct vnode *, struct cred *);
589 extern void sdev_filldir_dynamic(struct sdev_node *);
590 extern int sdev_mknode(struct sdev_node *, char *, struct sdev_node **,
591     struct vattr *, struct vnode *, void *, struct cred *, sdev_node_state_t);
592 extern int sdev_nodeinit(struct sdev_node *, char *, struct sdev_node **,
593     vattr_t *);
594 extern int sdev_nodeready(struct sdev_node *, vattr_t *, vnode_t *, void *,
595     cred_t *);
596 extern int sdev_shadow_node(struct sdev_node *, struct cred *);
597 extern void sdev_nodedestroy(struct sdev_node *, uint_t);
598 extern void sdev_update_timestamps(struct vnode *, cred_t *, uint_t);
599 extern void sdev_vattr_merge(struct sdev_node *, struct vattr *);
600 extern void sdev_devstate_change(void);
601 extern int sdev_lookup_filter(sdev_node_t *, char *);
602 extern void sdev_lookup_failed(sdev_node_t *, char *, int);
603 extern int sdev_unlocked_access(void *, int, struct cred *);
604 
605 #define	SDEV_ENFORCE	0x1
606 extern void sdev_stale(struct sdev_node *);
607 extern int sdev_cleandir(struct sdev_node *, char *, uint_t);
608 extern int sdev_rnmnode(struct sdev_node *, struct sdev_node *,
609     struct sdev_node *, struct sdev_node **, char *, struct cred *);
610 extern size_t add_dir_entry(dirent64_t *, char *, size_t, ino_t, offset_t);
611 extern int sdev_to_vp(struct sdev_node *, struct vnode **);
612 extern ino_t sdev_mkino(struct sdev_node *);
613 extern int devname_backstore_lookup(struct sdev_node *, char *,
614     struct vnode **);
615 extern int sdev_is_devfs_node(char *);
616 extern int sdev_copyin_mountargs(struct mounta *, struct sdev_mountargs *);
617 extern int sdev_reserve_subdirs(struct sdev_node *);
618 extern int prof_lookup();
619 extern void prof_filldir(struct sdev_node *);
620 extern int devpts_validate(struct sdev_node *dv);
621 extern int devnet_validate(struct sdev_node *dv);
622 extern void *sdev_get_vtor(struct sdev_node *dv);
623 
624 /*
625  * devinfo helpers
626  */
627 extern int sdev_modctl_readdir(const char *, char ***, int *, int *);
628 extern void sdev_modctl_readdir_free(char **, int, int);
629 extern int sdev_modctl_devexists(const char *);
630 
631 /*
632  * ncache handlers
633  */
634 
635 extern void sdev_ncache_init(void);
636 extern void sdev_ncache_setup(void);
637 extern void sdev_ncache_teardown(void);
638 extern void sdev_nc_addname(sdev_nc_list_t *, sdev_node_t *, char *, int);
639 extern void sdev_nc_node_exists(sdev_node_t *);
640 extern void sdev_nc_path_exists(sdev_nc_list_t *, char *);
641 extern void sdev_modctl_dump_files(void);
642 
643 /*
644  * globals
645  */
646 extern kmutex_t sdev_lock;
647 extern int devtype;
648 extern kmem_cache_t *sdev_node_cache;
649 extern struct vnodeops		*sdev_vnodeops;
650 extern struct vnodeops		*devpts_vnodeops;
651 extern struct vnodeops		*devnet_vnodeops;
652 extern struct sdev_data *sdev_origins; /* mount info for global /dev instance */
653 extern const fs_operation_def_t	sdev_vnodeops_tbl[];
654 extern const fs_operation_def_t	devpts_vnodeops_tbl[];
655 extern const fs_operation_def_t	devnet_vnodeops_tbl[];
656 extern const fs_operation_def_t	devsys_vnodeops_tbl[];
657 extern const fs_operation_def_t	devpseudo_vnodeops_tbl[];
658 
659 extern sdev_nc_list_t	*sdev_ncache;
660 extern int		sdev_reconfig_boot;
661 extern int		sdev_boot_state;
662 extern int		sdev_reconfig_verbose;
663 extern int		sdev_reconfig_disable;
664 extern int		sdev_nc_disable;
665 extern int		sdev_nc_disable_reset;
666 extern int		sdev_nc_verbose;
667 
668 /*
669  * misc. defines
670  */
671 #ifdef DEBUG
672 extern int sdev_debug;
673 #define	SDEV_DEBUG		0x01	/* error messages to console/log */
674 #define	SDEV_DEBUG_VOPS 	0x02	/* vnode ops errors */
675 #define	SDEV_DEBUG_DLF		0x04	/* trace devname_lookup_func */
676 #define	SDEV_DEBUG_DRF		0x08	/* trace devname_readdir_func */
677 #define	SDEV_DEBUG_NCACHE	0x10	/* negative cache tracing */
678 #define	SDEV_DEBUG_DEVFSADMD	0x20	/* comm. of devnamefs & devfsadm */
679 #define	SDEV_DEBUG_PTS		0x40	/* /dev/pts tracing */
680 #define	SDEV_DEBUG_RECONFIG	0x80	/* events triggering reconfig */
681 #define	SDEV_DEBUG_SDEV_NODE	0x100	/* trace sdev_node activities */
682 #define	SDEV_DEBUG_PROFILE	0x200	/* trace sdev_profile */
683 #define	SDEV_DEBUG_MODCTL	0x400	/* trace modctl activity */
684 #define	SDEV_DEBUG_FLK		0x800	/* trace failed lookups */
685 #define	SDEV_DEBUG_NET		0x1000	/* /dev/net tracing */
686 
687 #define	sdcmn_err(args)  if (sdev_debug & SDEV_DEBUG) printf args
688 #define	sdcmn_err2(args) if (sdev_debug & SDEV_DEBUG_VOPS) printf args
689 #define	sdcmn_err3(args) if (sdev_debug & SDEV_DEBUG_DLF) printf args
690 #define	sdcmn_err4(args) if (sdev_debug & SDEV_DEBUG_DRF) printf args
691 #define	sdcmn_err5(args) if (sdev_debug & SDEV_DEBUG_NCACHE) printf args
692 #define	sdcmn_err6(args) if (sdev_debug & SDEV_DEBUG_DEVFSADMD) printf args
693 #define	sdcmn_err7(args) if (sdev_debug & SDEV_DEBUG_PTS) printf args
694 #define	sdcmn_err8(args) if (sdev_debug & SDEV_DEBUG_RECONFIG) printf args
695 #define	sdcmn_err9(args) if (sdev_debug & SDEV_DEBUG_SDEV_NODE) printf args
696 #define	sdcmn_err10(args) if (sdev_debug & SDEV_DEBUG_PROFILE) printf args
697 #define	sdcmn_err11(args) if (sdev_debug & SDEV_DEBUG_MODCTL) printf args
698 #define	sdcmn_err12(args) if (sdev_debug & SDEV_DEBUG_NET) printf args
699 #define	impossible(args) printf args
700 #else
701 #define	sdcmn_err(args)		/* does nothing */
702 #define	sdcmn_err2(args)	/* does nothing */
703 #define	sdcmn_err3(args)	/* does nothing */
704 #define	sdcmn_err4(args)	/* does nothing */
705 #define	sdcmn_err5(args)	/* does nothing */
706 #define	sdcmn_err6(args)	/* does nothing */
707 #define	sdcmn_err7(args)	/* does nothing */
708 #define	sdcmn_err8(args)	/* does nothing */
709 #define	sdcmn_err9(args)	/* does nothing */
710 #define	sdcmn_err10(args)	/* does nothing */
711 #define	sdcmn_err11(args)	/* does nothing */
712 #define	sdcmn_err12(args)	/* does nothing */
713 #define	impossible(args)	/* does nothing */
714 #endif
715 
716 #ifdef DEBUG
717 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)			\
718 	if ((sdev_debug & SDEV_DEBUG_FLK) ||				\
719 	    ((retried) && (sdev_debug & SDEV_DEBUG_RECONFIG))) {	\
720 		printf("lookup of %s/%s by %s failed, line %d\n",	\
721 		    (ddv)->sdev_name, (nm), curproc->p_user.u_comm,	\
722 		    __LINE__);						\
723 	}
724 #else
725 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)
726 #endif
727 
728 #endif	/* _KERNEL */
729 
730 #ifdef __cplusplus
731 }
732 #endif
733 
734 #endif	/* _SYS_SDEV_IMPL_H */
735