xref: /titanic_52/usr/src/uts/common/sys/fs/sdev_impl.h (revision 700c902c445eb3882848aaddc19d13638818cfd6)
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  * name service globals and prototypes
524  */
525 
526 extern struct devname_ops *devname_ns_ops;
527 extern int devname_nsmaps_loaded;
528 extern kmutex_t devname_nsmaps_lock;
529 
530 extern void sdev_invalidate_nsmaps(void);
531 extern void sdev_validate_nsmaps(void);
532 extern int sdev_module_register(char *, struct devname_ops *);
533 extern struct devname_nsmap *sdev_get_nsmap_by_dir(char *, int);
534 extern struct devname_nsmap *sdev_get_nsmap_by_module(char *);
535 extern void sdev_dispatch_to_nsrdr_thread(struct sdev_node *, char *,
536     devname_rdr_result_t *);
537 extern void sdev_insert_nsmap(char *, char *, char *);
538 extern int devname_nsmap_lookup(devname_lkp_arg_t *, devname_lkp_result_t **);
539 extern struct devname_nsmap *sdev_get_map(struct sdev_node *, int);
540 extern int sdev_nsmaps_loaded(void);
541 extern void sdev_replace_nsmap(struct devname_nsmap *, char *, char *);
542 extern int sdev_nsmaps_reloaded(void);
543 extern int devname_get_dir_nsmap(devname_handle_t *, struct devname_nsmap **);
544 
545 /*
546  * vnodeops and vfsops helpers
547  */
548 
549 typedef enum {
550 	SDEV_CACHE_ADD = 0,
551 	SDEV_CACHE_DELETE
552 } sdev_cache_ops_t;
553 
554 extern struct sdev_node *sdev_cache_lookup(struct sdev_node *, char *);
555 extern int sdev_cache_update(struct sdev_node *, struct sdev_node **, char *,
556     sdev_cache_ops_t);
557 extern void sdev_node_cache_init(void);
558 extern void sdev_node_cache_fini(void);
559 extern struct sdev_node *sdev_mkroot(struct vfs *, dev_t, struct vnode *,
560     struct vnode *, struct cred *);
561 extern int sdev_mknode(struct sdev_node *, char *, struct sdev_node **,
562     struct vattr *, struct vnode *, void *, struct cred *, sdev_node_state_t);
563 extern int sdev_nodeinit(struct sdev_node *, char *, struct sdev_node **,
564     vattr_t *);
565 extern int sdev_nodeready(struct sdev_node *, vattr_t *, vnode_t *, void *,
566     cred_t *);
567 extern int sdev_shadow_node(struct sdev_node *, struct cred *);
568 extern void sdev_nodedestroy(struct sdev_node *, uint_t);
569 extern void sdev_update_timestamps(struct vnode *, cred_t *, uint_t);
570 extern void sdev_vattr_merge(struct sdev_node *, struct vattr *);
571 extern void sdev_devstate_change(void);
572 extern int sdev_lookup_filter(sdev_node_t *, char *);
573 extern void sdev_lookup_failed(sdev_node_t *, char *, int);
574 extern int sdev_unlocked_access(void *, int, struct cred *);
575 
576 #define	SDEV_ENFORCE	0x1
577 extern void sdev_stale(struct sdev_node *);
578 extern int sdev_cleandir(struct sdev_node *, char *, uint_t);
579 extern int sdev_rnmnode(struct sdev_node *, struct sdev_node *,
580     struct sdev_node *, struct sdev_node **, char *, struct cred *);
581 extern size_t add_dir_entry(dirent64_t *, char *, size_t, ino_t, offset_t);
582 extern int sdev_to_vp(struct sdev_node *, struct vnode **);
583 extern ino_t sdev_mkino(struct sdev_node *);
584 extern int devname_backstore_lookup(struct sdev_node *, char *,
585     struct vnode **);
586 extern int sdev_is_devfs_node(char *);
587 extern int sdev_copyin_mountargs(struct mounta *, struct sdev_mountargs *);
588 extern int sdev_reserve_subdirs(struct sdev_node *);
589 extern int prof_lookup();
590 extern void prof_filldir(struct sdev_node *);
591 extern int devpts_validate(struct sdev_node *dv);
592 extern void *sdev_get_vtor(struct sdev_node *dv);
593 
594 /*
595  * devinfo helpers
596  */
597 extern int sdev_modctl_readdir(const char *, char ***, int *, int *);
598 extern void sdev_modctl_readdir_free(char **, int, int);
599 extern int sdev_modctl_devexists(const char *);
600 
601 
602 /*
603  * ncache handlers
604  */
605 
606 extern void sdev_ncache_init(void);
607 extern void sdev_ncache_setup(void);
608 extern void sdev_ncache_teardown(void);
609 extern void sdev_nc_addname(sdev_nc_list_t *, sdev_node_t *, char *, int);
610 extern void sdev_nc_node_exists(sdev_node_t *);
611 extern void sdev_nc_path_exists(sdev_nc_list_t *, char *);
612 extern void sdev_modctl_dump_files(void);
613 
614 /*
615  * globals
616  */
617 extern int devtype;
618 extern kmem_cache_t *sdev_node_cache;
619 extern struct vnodeops		*sdev_vnodeops;
620 extern struct vnodeops		*devpts_vnodeops;
621 extern struct sdev_data *sdev_origins; /* mount info for global /dev instance */
622 extern const fs_operation_def_t	sdev_vnodeops_tbl[];
623 extern const fs_operation_def_t	devpts_vnodeops_tbl[];
624 extern const fs_operation_def_t	devsys_vnodeops_tbl[];
625 extern const fs_operation_def_t	devpseudo_vnodeops_tbl[];
626 
627 extern sdev_nc_list_t	*sdev_ncache;
628 extern int		sdev_reconfig_boot;
629 extern int		sdev_boot_state;
630 extern int		sdev_reconfig_verbose;
631 extern int		sdev_reconfig_disable;
632 extern int		sdev_nc_disable;
633 extern int		sdev_nc_disable_reset;
634 extern int		sdev_nc_verbose;
635 
636 /*
637  * misc. defines
638  */
639 #ifdef DEBUG
640 extern int sdev_debug;
641 #define	SDEV_DEBUG		0x01	/* error messages to console/log */
642 #define	SDEV_DEBUG_VOPS 	0x02	/* vnode ops errors */
643 #define	SDEV_DEBUG_DLF		0x04	/* trace devname_lookup_func */
644 #define	SDEV_DEBUG_DRF		0x08	/* trace devname_readdir_func */
645 #define	SDEV_DEBUG_NCACHE	0x10	/* negative cache tracing */
646 #define	SDEV_DEBUG_DEVFSADMD	0x20	/* comm. of devnamefs & devfsadm */
647 #define	SDEV_DEBUG_PTS		0x40	/* /dev/pts tracing */
648 #define	SDEV_DEBUG_RECONFIG	0x80	/* events triggering reconfig */
649 #define	SDEV_DEBUG_SDEV_NODE	0x100	/* trace sdev_node activities */
650 #define	SDEV_DEBUG_PROFILE	0x200	/* trace sdev_profile */
651 #define	SDEV_DEBUG_MODCTL	0x400	/* trace modctl activity */
652 #define	SDEV_DEBUG_FLK		0x800	/* trace failed lookups */
653 
654 #define	sdcmn_err(args)  if (sdev_debug & SDEV_DEBUG) printf args
655 #define	sdcmn_err2(args) if (sdev_debug & SDEV_DEBUG_VOPS) printf args
656 #define	sdcmn_err3(args) if (sdev_debug & SDEV_DEBUG_DLF) printf args
657 #define	sdcmn_err4(args) if (sdev_debug & SDEV_DEBUG_DRF) printf args
658 #define	sdcmn_err5(args) if (sdev_debug & SDEV_DEBUG_NCACHE) printf args
659 #define	sdcmn_err6(args) if (sdev_debug & SDEV_DEBUG_DEVFSADMD) printf args
660 #define	sdcmn_err7(args) if (sdev_debug & SDEV_DEBUG_PTS) printf args
661 #define	sdcmn_err8(args) if (sdev_debug & SDEV_DEBUG_RECONFIG) printf args
662 #define	sdcmn_err9(args) if (sdev_debug & SDEV_DEBUG_SDEV_NODE) printf args
663 #define	sdcmn_err10(args) if (sdev_debug & SDEV_DEBUG_PROFILE) printf args
664 #define	sdcmn_err11(args) if (sdev_debug & SDEV_DEBUG_MODCTL) printf args
665 #define	impossible(args) printf args
666 #else
667 #define	sdcmn_err(args)		/* does nothing */
668 #define	sdcmn_err2(args)	/* does nothing */
669 #define	sdcmn_err3(args)	/* does nothing */
670 #define	sdcmn_err4(args)	/* does nothing */
671 #define	sdcmn_err5(args)	/* does nothing */
672 #define	sdcmn_err6(args)	/* does nothing */
673 #define	sdcmn_err7(args)	/* does nothing */
674 #define	sdcmn_err8(args)	/* does nothing */
675 #define	sdcmn_err9(args)	/* does nothing */
676 #define	sdcmn_err10(args)	/* does nothing */
677 #define	sdcmn_err11(args)	/* does nothing */
678 #define	impossible(args)	/* does nothing */
679 #endif
680 
681 #ifdef DEBUG
682 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)			\
683 	if ((sdev_debug & SDEV_DEBUG_FLK) ||				\
684 	    ((retried) && (sdev_debug & SDEV_DEBUG_RECONFIG))) {	\
685 		printf("lookup of %s/%s by %s failed, line %d\n",	\
686 		    (ddv)->sdev_name, (nm), curproc->p_user.u_comm,	\
687 		    __LINE__);						\
688 	}
689 #else
690 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)
691 #endif
692 
693 #endif	/* _KERNEL */
694 
695 #ifdef __cplusplus
696 }
697 #endif
698 
699 #endif	/* _SYS_SDEV_IMPL_H */
700