xref: /titanic_44/usr/src/uts/common/sys/fs/sdev_impl.h (revision 5fd03bc0f2e00e7ba02316c2e08f45d52aab15db)
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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _SYS_SDEV_IMPL_H
26 #define	_SYS_SDEV_IMPL_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <rpc/rpc.h>
33 #include <sys/dirent.h>
34 #include <sys/vfs.h>
35 #include <sys/vfs_opreg.h>
36 #include <sys/list.h>
37 #include <sys/nvpair.h>
38 
39 /*
40  * sdev_nodes are the file-system specific part of the
41  * vnodes for the device filesystem.
42  *
43  * The device filesystem exports two node types:
44  *
45  * VDIR nodes		to represent directories
46  * VCHR & VBLK nodes	to represent devices
47  */
48 
49 /*
50  * /dev mount arguments
51  */
52 struct sdev_mountargs {
53 	uint64_t sdev_attrdir;
54 };
55 
56 
57 /*
58  * Nvpair names of profile information (list of device files available) of
59  * non-global /dev mounts.  These strings must be unique among them.
60  */
61 #define	SDEV_NVNAME_MOUNTPT	"prof_mountpt"
62 #define	SDEV_NVNAME_INCLUDE	"prof_include"
63 #define	SDEV_NVNAME_EXCLUDE	"prof_exclude"
64 #define	SDEV_NVNAME_SYMLINK	"prof_symlink"
65 #define	SDEV_NVNAME_MAP		"prof_map"
66 
67 /*
68  * supported devfsadm_cmd
69  */
70 #define	DEVFSADMD_RUN_ALL	1
71 
72 /*
73  * devfsadm_error codes
74  */
75 #define	DEVFSADM_RUN_INVALID		1
76 #define	DEVFSADM_RUN_EPERM		2
77 #define	DEVFSADM_RUN_NOTSUP		3
78 
79 /*
80  * devfsadm/devname door data structures
81  */
82 typedef struct sdev_door_arg {
83 	uint8_t devfsadm_cmd;	/* what to do for devfsadm[d] */
84 } sdev_door_arg_t;
85 
86 typedef struct sdev_door_res {
87 	int32_t devfsadm_error;
88 } sdev_door_res_t;
89 
90 #ifdef _KERNEL
91 
92 struct sdev_dprof {
93 	int has_glob;
94 	nvlist_t *dev_name;
95 	nvlist_t *dev_map;
96 	nvlist_t *dev_symlink;
97 	nvlist_t *dev_glob_incdir;
98 	nvlist_t *dev_glob_excdir;
99 };
100 
101 /*
102  * devname_handle_t
103  */
104 struct devname_handle {
105 	struct sdev_node *dh_data;	/* the sdev_node */
106 	void    *dh_args;
107 };
108 typedef struct devname_handle devname_handle_t;
109 
110 /*
111  * Per-instance node data for the global zone instance
112  * Only one mount of /dev in the global zone
113  */
114 typedef struct sdev_global_data {
115 	struct devname_handle sdev_ghandle;
116 	ulong_t		sdev_dir_ggen;		/* name space generation # */
117 } sdev_global_data_t;
118 
119 /*
120  * Per-instance node data - profile data per non-global zone mount instance
121  */
122 typedef struct sdev_local_data {
123 	ulong_t sdev_dir_lgen;		/* cached generation # of /dev dir */
124 	ulong_t sdev_devtree_lgen;	/* cached generation # of devtree */
125 	struct sdev_node *sdev_lorigin;	/* corresponding global sdev_node */
126 	struct sdev_dprof sdev_lprof;	/* profile for multi-inst */
127 } sdev_local_data_t;
128 
129 /*
130  * /dev filesystem sdev_node defines
131  */
132 typedef struct sdev_node {
133 	char		*sdev_name;	/* node name */
134 	size_t		sdev_namelen;	/* strlen(sdev_name) */
135 	char		*sdev_path;	/* absolute path */
136 	char		*sdev_symlink;	/* source for a symlink */
137 	struct vnode	*sdev_vnode;	/* vnode */
138 
139 	krwlock_t	sdev_contents;	/* rw lock for this data structure */
140 	struct sdev_node *sdev_dotdot;	/* parent */
141 
142 	avl_tree_t	sdev_entries;	/* VDIR: contents as avl tree */
143 	avl_node_t	sdev_avllink;	/* avl node linkage */
144 
145 	struct vnode	*sdev_attrvp;	/* backing store vnode if persisted */
146 	struct vattr	*sdev_attr;	/* memory copy of the vattr */
147 
148 	ino64_t		sdev_ino;	/* inode */
149 	uint_t		sdev_nlink;	/* link count */
150 	int		sdev_state;	/* state of this node */
151 	int		sdev_flags;	/* flags bit */
152 
153 	kmutex_t	sdev_lookup_lock; /* node creation synch lock */
154 	kcondvar_t	sdev_lookup_cv;	/* node creation sync cv */
155 	int		sdev_lookup_flags; /* node creation flags */
156 
157 	/* per-instance data, either global or non-global zone */
158 	union {
159 		struct sdev_global_data	sdev_globaldata;
160 		struct sdev_local_data	sdev_localdata;
161 	} sdev_instance_data;
162 
163 	void		*sdev_private;
164 } sdev_node_t;
165 
166 #define	sdev_ldata sdev_instance_data.sdev_localdata
167 #define	sdev_gdata sdev_instance_data.sdev_globaldata
168 
169 #define	sdev_handle		sdev_gdata.sdev_ghandle
170 #define	sdev_gdir_gen		sdev_gdata.sdev_dir_ggen
171 
172 #define	sdev_ldir_gen		sdev_ldata.sdev_dir_lgen
173 #define	sdev_devtree_gen	sdev_ldata.sdev_devtree_lgen
174 #define	sdev_origin		sdev_ldata.sdev_lorigin
175 #define	sdev_prof		sdev_ldata.sdev_lprof
176 
177 /*
178  * Directory contents traversal
179  */
180 #define	SDEV_FIRST_ENTRY(ddv)		avl_first(&(ddv)->sdev_entries)
181 #define	SDEV_NEXT_ENTRY(ddv, dv)	AVL_NEXT(&(ddv)->sdev_entries, (dv))
182 
183 /*
184  * See the big theory statement in sdev_vnops.c for an explanation of these
185  * states.
186  */
187 typedef enum {
188 	SDEV_ZOMBIE = -1,
189 	SDEV_INIT = 0,
190 	SDEV_READY
191 } sdev_node_state_t;
192 
193 /* sdev_flags */
194 #define	SDEV_BUILD		0x0001	/* directory cache out-of-date */
195 #define	SDEV_GLOBAL		0x0002	/* global /dev nodes */
196 #define	SDEV_PERSIST		0x0004	/* backing store persisted node */
197 #define	SDEV_NO_NCACHE		0x0008	/* do not include in neg. cache */
198 #define	SDEV_DYNAMIC		0x0010	/* special-purpose vnode ops */
199 					/* (ex: pts) */
200 #define	SDEV_VTOR		0x0020	/* validate sdev_nodes during search */
201 #define	SDEV_ATTR_INVALID	0x0040	/* invalid node attributes, */
202 					/* need update */
203 #define	SDEV_SUBDIR		0x0080	/* match all subdirs under here */
204 #define	SDEV_ZONED		0x0100  /* zoned subdir */
205 
206 /* sdev_lookup_flags */
207 #define	SDEV_LOOKUP	0x0001	/* node creation in progress */
208 #define	SDEV_READDIR	0x0002	/* VDIR readdir in progress */
209 #define	SDEV_LGWAITING	0x0004	/* waiting for devfsadm completion */
210 
211 #define	SDEV_VTOR_INVALID	-1
212 #define	SDEV_VTOR_SKIP		0
213 #define	SDEV_VTOR_VALID		1
214 #define	SDEV_VTOR_STALE		2
215 
216 /* convenient macros */
217 #define	SDEV_IS_GLOBAL(dv)	\
218 	(dv->sdev_flags & SDEV_GLOBAL)
219 #define	SDEV_IS_PERSIST(dv)	\
220 	(dv->sdev_flags & SDEV_PERSIST)
221 #define	SDEV_IS_DYNAMIC(dv)	\
222 	(dv->sdev_flags & SDEV_DYNAMIC)
223 #define	SDEV_IS_NO_NCACHE(dv)	\
224 	(dv->sdev_flags & SDEV_NO_NCACHE)
225 #define	SDEV_IS_LOOKUP(dv)	\
226 	(dv->sdev_lookup_flags & SDEV_LOOKUP)
227 #define	SDEV_IS_READDIR(dv)	\
228 	(dv->sdev_lookup_flags & SDEV_READDIR)
229 #define	SDEV_IS_LGWAITING(dv)	\
230 	(dv->sdev_lookup_flags  & SDEV_LGWAITING)
231 
232 #define	SDEVTOV(n)	((struct vnode *)(n)->sdev_vnode)
233 #define	VTOSDEV(vp)	((struct sdev_node *)(vp)->v_data)
234 #define	VN_HELD(v)	((v)->v_count != 0)
235 #define	SDEV_HELD(dv)	(VN_HELD(SDEVTOV(dv)))
236 #define	SDEV_HOLD(dv)	VN_HOLD(SDEVTOV(dv))
237 #define	SDEV_RELE(dv)	VN_RELE(SDEVTOV(dv))
238 #define	SDEV_SIMPLE_RELE(dv)	{	\
239 	mutex_enter(&SDEVTOV(dv)->v_lock);	\
240 	SDEVTOV(dv)->v_count--;	\
241 	mutex_exit(&SDEVTOV(dv)->v_lock);	\
242 }
243 
244 #define	SDEV_ACL_FLAVOR(vp)	(VFSTOSDEVFS(vp->v_vfsp)->sdev_acl_flavor)
245 
246 /*
247  * some defaults
248  */
249 #define	SDEV_ROOTINO		((ino_t)2)
250 #define	SDEV_UID_DEFAULT	(0)
251 #define	SDEV_GID_DEFAULT	(3)
252 #define	SDEV_DIRMODE_DEFAULT	(S_IFDIR |0755)
253 #define	SDEV_DEVMODE_DEFAULT	(0600)
254 #define	SDEV_LNKMODE_DEFAULT	(S_IFLNK | 0777)
255 
256 extern struct vattr sdev_vattr_dir;
257 extern struct vattr sdev_vattr_lnk;
258 extern struct vattr sdev_vattr_blk;
259 extern struct vattr sdev_vattr_chr;
260 
261 /*
262  * devname_lookup_func()
263  */
264 extern int devname_lookup_func(struct sdev_node *, char *, struct vnode **,
265     struct cred *, int (*)(struct sdev_node *, char *, void **, struct cred *,
266     void *, char *), int);
267 
268 /*
269  * flags used by devname_lookup_func callbacks
270  */
271 #define	SDEV_VATTR	0x4	/* callback returning node vattr */
272 #define	SDEV_VLINK	0x8	/* callback returning /dev link */
273 
274 /*
275  * devname_readdir_func()
276  */
277 extern int devname_readdir_func(vnode_t *, uio_t *, cred_t *, int *, int);
278 
279 /*
280  * flags for devname_readdir_func
281  */
282 #define	SDEV_BROWSE	0x1	/* fetch all entries from backing store */
283 
284 /*
285  * devname_setattr_func()
286  */
287 extern int devname_setattr_func(struct vnode *, struct vattr *, int,
288     struct cred *, int (*)(struct sdev_node *, struct vattr *, int), int);
289 /*
290  * devname_inactive_func()
291  */
292 extern void devname_inactive_func(struct vnode *, struct cred *,
293     void (*)(struct vnode *));
294 
295 /*
296  * /dev file system instance defines
297  */
298 /*
299  * /dev version of vfs_data
300  */
301 struct sdev_data {
302 	struct sdev_data	*sdev_prev;
303 	struct sdev_data	*sdev_next;
304 	struct sdev_node	*sdev_root;
305 	struct vfs		*sdev_vfsp;
306 	struct sdev_mountargs	*sdev_mountargs;
307 	ulong_t			sdev_acl_flavor;
308 };
309 
310 #define	VFSTOSDEVFS(vfsp)	((struct sdev_data *)((vfsp)->vfs_data))
311 
312 /*
313  * sdev_fid overlays the fid structure (for VFS_VGET)
314  */
315 struct sdev_fid {
316 	uint16_t	sdevfid_len;
317 	ino32_t		sdevfid_ino;
318 	int32_t		sdevfid_gen;
319 };
320 
321 /*
322  * devfsadm and devname communication defines
323  */
324 typedef enum {
325 	DEVNAME_DEVFSADM_STOPPED = 0,	/* devfsadm has never run */
326 	DEVNAME_DEVFSADM_RUNNING,	/* devfsadm is running */
327 	DEVNAME_DEVFSADM_RUN		/* devfsadm ran once */
328 } devname_devfsadm_state_t;
329 
330 extern volatile uint_t  devfsadm_state; /* atomic mask for devfsadm status */
331 
332 #define	DEVNAME_DEVFSADM_SET_RUNNING(devfsadm_state)	\
333 	devfsadm_state = DEVNAME_DEVFSADM_RUNNING
334 #define	DEVNAME_DEVFSADM_SET_STOP(devfsadm_state)	\
335 	devfsadm_state = DEVNAME_DEVFSADM_STOPPED
336 #define	DEVNAME_DEVFSADM_SET_RUN(devfsadm_state)	\
337 	devfsadm_state = DEVNAME_DEVFSADM_RUN
338 #define	DEVNAME_DEVFSADM_IS_RUNNING(devfsadm_state)	\
339 	devfsadm_state == DEVNAME_DEVFSADM_RUNNING
340 #define	DEVNAME_DEVFSADM_HAS_RUN(devfsadm_state)	\
341 	(devfsadm_state == DEVNAME_DEVFSADM_RUN)
342 
343 #define	SDEV_BLOCK_OTHERS(dv, cmd)	{	\
344 	ASSERT(MUTEX_HELD(&dv->sdev_lookup_lock));	\
345 	dv->sdev_lookup_flags |= cmd;			\
346 }
347 extern void sdev_unblock_others(struct sdev_node *, uint_t);
348 #define	SDEV_UNBLOCK_OTHERS(dv, cmd)	{	\
349 	sdev_unblock_others(dv, cmd);		\
350 }
351 
352 #define	SDEV_CLEAR_LOOKUP_FLAGS(dv, cmd)	{	\
353 	dv->sdev_lookup_flags &= ~cmd;	\
354 }
355 
356 extern int sdev_wait4lookup(struct sdev_node *, int);
357 extern int devname_filename_register(char *);
358 extern int devname_nsmaps_register(char *, size_t);
359 extern void sdev_devfsadm_lockinit(void);
360 extern void sdev_devfsadm_lockdestroy(void);
361 extern void devname_add_devfsadm_node(char *);
362 extern void sdev_devfsadmd_thread(struct sdev_node *, struct sdev_node *,
363     struct cred *);
364 extern int devname_profile_update(char *, size_t);
365 extern struct sdev_data *sdev_find_mntinfo(char *);
366 void sdev_mntinfo_rele(struct sdev_data *);
367 extern struct vnodeops *devpts_getvnodeops(void);
368 extern struct vnodeops *devvt_getvnodeops(void);
369 
370 /*
371  * boot states - warning, the ordering here is significant
372  *
373  * the difference between "system available" and "boot complete"
374  * is a debounce timeout to catch some daemon issuing a readdir
375  * triggering a nuisance implict reconfig on each boot.
376  */
377 #define	SDEV_BOOT_STATE_INITIAL		0
378 #define	SDEV_BOOT_STATE_RECONFIG	1	/* reconfig */
379 #define	SDEV_BOOT_STATE_SYSAVAIL	2	/* system available */
380 #define	SDEV_BOOT_STATE_COMPLETE	3	/* boot complete */
381 
382 /*
383  * Negative cache list and list element
384  * The mutex protects the flags against multiple accesses and
385  * must only be acquired when already holding the r/w lock.
386  */
387 typedef struct sdev_nc_list {
388 	list_t		ncl_list;	/* the list itself */
389 	kmutex_t	ncl_mutex;	/* protects ncl_flags */
390 	krwlock_t	ncl_lock;	/* protects ncl_list */
391 	int		ncl_flags;
392 	int		ncl_nentries;
393 } sdev_nc_list_t;
394 
395 typedef struct sdev_nc_node {
396 	char		*ncn_name;	/* name of the node */
397 	int		ncn_flags;	/* state information */
398 	int		ncn_expirecnt;	/* remove once expired */
399 	list_node_t	ncn_link;	/* link to next in list */
400 } sdev_nc_node_t;
401 
402 /* ncl_flags */
403 #define	NCL_LIST_DIRTY		0x01	/* needs to be flushed */
404 #define	NCL_LIST_WRITING	0x02	/* write in progress */
405 #define	NCL_LIST_WENABLE	0x04	/* write-enabled post boot */
406 
407 /* ncn_flags */
408 #define	NCN_ACTIVE	0x01	/* a lookup has occurred */
409 #define	NCN_SRC_STORE	0x02	/* src: persistent store */
410 #define	NCN_SRC_CURRENT	0x04	/* src: current boot */
411 
412 /* sdev_lookup_failed flags */
413 #define	SLF_NO_NCACHE	0x01	/* node should not be added to ncache */
414 #define	SLF_REBUILT	0x02	/* reconfig performed during lookup attempt */
415 
416 /*
417  * The nvlist name and nvpair identifiers in the
418  * /etc/devices/devname_cache nvlist format
419  */
420 #define	DP_DEVNAME_ID			"devname"
421 #define	DP_DEVNAME_NCACHE_ID		"ncache"
422 #define	DP_DEVNAME_NC_EXPIRECNT_ID	"expire-counts"
423 
424 /* devname-cache list element */
425 typedef struct nvp_devname {
426 	char			**nvp_paths;
427 	int			*nvp_expirecnts;
428 	int			nvp_npaths;
429 	list_node_t		nvp_link;
430 } nvp_devname_t;
431 
432 /*
433  * name service globals and prototypes
434  */
435 
436 /*
437  * vnodeops and vfsops helpers
438  */
439 
440 typedef enum {
441 	SDEV_CACHE_ADD = 0,
442 	SDEV_CACHE_DELETE
443 } sdev_cache_ops_t;
444 
445 extern struct sdev_node *sdev_cache_lookup(struct sdev_node *, char *);
446 extern void sdev_cache_update(struct sdev_node *, struct sdev_node **, char *,
447     sdev_cache_ops_t);
448 extern void sdev_node_cache_init(void);
449 extern void sdev_node_cache_fini(void);
450 extern struct sdev_node *sdev_mkroot(struct vfs *, dev_t, struct vnode *,
451     struct vnode *, struct cred *);
452 extern void sdev_filldir_dynamic(struct sdev_node *);
453 extern int sdev_mknode(struct sdev_node *, char *, struct sdev_node **,
454     struct vattr *, struct vnode *, void *, struct cred *, sdev_node_state_t);
455 extern int sdev_getlink(struct vnode *linkvp, char **link);
456 
457 extern int sdev_nodeinit(struct sdev_node *, char *, struct sdev_node **,
458     vattr_t *);
459 extern int sdev_nodeready(struct sdev_node *, vattr_t *, vnode_t *, void *,
460     cred_t *);
461 extern int sdev_shadow_node(struct sdev_node *, struct cred *);
462 extern void sdev_nodedestroy(struct sdev_node *, uint_t);
463 extern void sdev_update_timestamps(struct vnode *, cred_t *, uint_t);
464 extern void sdev_vattr_merge(struct sdev_node *, struct vattr *);
465 extern void sdev_devstate_change(void);
466 extern int sdev_lookup_filter(sdev_node_t *, char *);
467 extern void sdev_lookup_failed(sdev_node_t *, char *, int);
468 extern int sdev_unlocked_access(void *, int, struct cred *);
469 
470 #define	SDEV_ENFORCE	0x1
471 extern void sdev_stale(struct sdev_node *);
472 extern int sdev_cleandir(struct sdev_node *, char *, uint_t);
473 extern int sdev_rnmnode(struct sdev_node *, struct sdev_node *,
474     struct sdev_node *, struct sdev_node **, char *, struct cred *);
475 extern size_t add_dir_entry(dirent64_t *, char *, size_t, ino_t, offset_t);
476 extern struct vattr *sdev_getdefault_attr(enum vtype type);
477 extern int sdev_to_vp(struct sdev_node *, struct vnode **);
478 extern ino_t sdev_mkino(struct sdev_node *);
479 extern int devname_backstore_lookup(struct sdev_node *, char *,
480     struct vnode **);
481 extern int sdev_is_devfs_node(char *);
482 extern int sdev_copyin_mountargs(struct mounta *, struct sdev_mountargs *);
483 extern int sdev_reserve_subdirs(struct sdev_node *);
484 extern int prof_lookup();
485 extern void prof_filldir(struct sdev_node *);
486 extern int devpts_validate(struct sdev_node *dv);
487 extern int devnet_validate(struct sdev_node *dv);
488 extern int devipnet_validate(struct sdev_node *dv);
489 extern int devvt_validate(struct sdev_node *dv);
490 extern int devzvol_validate(struct sdev_node *dv);
491 extern void *sdev_get_vtor(struct sdev_node *dv);
492 
493 /*
494  * devinfo helpers
495  */
496 extern int sdev_modctl_readdir(const char *, char ***, int *, int *, int);
497 extern void sdev_modctl_readdir_free(char **, int, int);
498 extern int sdev_modctl_devexists(const char *);
499 
500 /*
501  * ncache handlers
502  */
503 
504 extern void sdev_ncache_init(void);
505 extern void sdev_ncache_setup(void);
506 extern void sdev_ncache_teardown(void);
507 extern void sdev_nc_addname(sdev_nc_list_t *, sdev_node_t *, char *, int);
508 extern void sdev_nc_node_exists(sdev_node_t *);
509 extern void sdev_nc_path_exists(sdev_nc_list_t *, char *);
510 extern void sdev_modctl_dump_files(void);
511 
512 /*
513  * globals
514  */
515 extern kmutex_t sdev_lock;
516 extern int devtype;
517 extern kmem_cache_t *sdev_node_cache;
518 extern struct vnodeops		*sdev_vnodeops;
519 extern struct vnodeops		*devpts_vnodeops;
520 extern struct vnodeops		*devnet_vnodeops;
521 extern struct vnodeops		*devipnet_vnodeops;
522 extern struct vnodeops		*devvt_vnodeops;
523 extern struct sdev_data *sdev_origins; /* mount info for global /dev instance */
524 extern struct vnodeops		*devzvol_vnodeops;
525 
526 extern const fs_operation_def_t	sdev_vnodeops_tbl[];
527 extern const fs_operation_def_t	devpts_vnodeops_tbl[];
528 extern const fs_operation_def_t	devnet_vnodeops_tbl[];
529 extern const fs_operation_def_t devipnet_vnodeops_tbl[];
530 extern const fs_operation_def_t	devvt_vnodeops_tbl[];
531 extern const fs_operation_def_t	devsys_vnodeops_tbl[];
532 extern const fs_operation_def_t	devpseudo_vnodeops_tbl[];
533 extern const fs_operation_def_t	devzvol_vnodeops_tbl[];
534 
535 extern sdev_nc_list_t	*sdev_ncache;
536 extern int		sdev_reconfig_boot;
537 extern int		sdev_boot_state;
538 extern int		sdev_reconfig_verbose;
539 extern int		sdev_reconfig_disable;
540 extern int		sdev_nc_disable;
541 extern int		sdev_nc_disable_reset;
542 extern int		sdev_nc_verbose;
543 
544 /*
545  * misc. defines
546  */
547 #ifdef DEBUG
548 extern int sdev_debug;
549 #define	SDEV_DEBUG		0x01	/* error messages to console/log */
550 #define	SDEV_DEBUG_VOPS 	0x02	/* vnode ops errors */
551 #define	SDEV_DEBUG_DLF		0x04	/* trace devname_lookup_func */
552 #define	SDEV_DEBUG_DRF		0x08	/* trace devname_readdir_func */
553 #define	SDEV_DEBUG_NCACHE	0x10	/* negative cache tracing */
554 #define	SDEV_DEBUG_DEVFSADMD	0x20	/* comm. of devnamefs & devfsadm */
555 #define	SDEV_DEBUG_PTS		0x40	/* /dev/pts tracing */
556 #define	SDEV_DEBUG_RECONFIG	0x80	/* events triggering reconfig */
557 #define	SDEV_DEBUG_SDEV_NODE	0x100	/* trace sdev_node activities */
558 #define	SDEV_DEBUG_PROFILE	0x200	/* trace sdev_profile */
559 #define	SDEV_DEBUG_MODCTL	0x400	/* trace modctl activity */
560 #define	SDEV_DEBUG_FLK		0x800	/* trace failed lookups */
561 #define	SDEV_DEBUG_NET		0x1000	/* /dev/net tracing */
562 #define	SDEV_DEBUG_ZVOL		0x2000	/* /dev/zvol/tracing */
563 
564 #define	sdcmn_err(args)  if (sdev_debug & SDEV_DEBUG) printf args
565 #define	sdcmn_err2(args) if (sdev_debug & SDEV_DEBUG_VOPS) printf args
566 #define	sdcmn_err3(args) if (sdev_debug & SDEV_DEBUG_DLF) printf args
567 #define	sdcmn_err4(args) if (sdev_debug & SDEV_DEBUG_DRF) printf args
568 #define	sdcmn_err5(args) if (sdev_debug & SDEV_DEBUG_NCACHE) printf args
569 #define	sdcmn_err6(args) if (sdev_debug & SDEV_DEBUG_DEVFSADMD) printf args
570 #define	sdcmn_err7(args) if (sdev_debug & SDEV_DEBUG_PTS) printf args
571 #define	sdcmn_err8(args) if (sdev_debug & SDEV_DEBUG_RECONFIG) printf args
572 #define	sdcmn_err9(args) if (sdev_debug & SDEV_DEBUG_SDEV_NODE) printf args
573 #define	sdcmn_err10(args) if (sdev_debug & SDEV_DEBUG_PROFILE) printf args
574 #define	sdcmn_err11(args) if (sdev_debug & SDEV_DEBUG_MODCTL) printf args
575 #define	sdcmn_err12(args) if (sdev_debug & SDEV_DEBUG_NET) printf args
576 #define	sdcmn_err13(args) if (sdev_debug & SDEV_DEBUG_ZVOL) printf args
577 #define	impossible(args) printf args
578 #else
579 #define	sdcmn_err(args)		/* does nothing */
580 #define	sdcmn_err2(args)	/* does nothing */
581 #define	sdcmn_err3(args)	/* does nothing */
582 #define	sdcmn_err4(args)	/* does nothing */
583 #define	sdcmn_err5(args)	/* does nothing */
584 #define	sdcmn_err6(args)	/* does nothing */
585 #define	sdcmn_err7(args)	/* does nothing */
586 #define	sdcmn_err8(args)	/* does nothing */
587 #define	sdcmn_err9(args)	/* does nothing */
588 #define	sdcmn_err10(args)	/* does nothing */
589 #define	sdcmn_err11(args)	/* does nothing */
590 #define	sdcmn_err12(args)	/* does nothing */
591 #define	sdcmn_err13(args) 	/* does nothing */
592 #define	impossible(args)	/* does nothing */
593 #endif
594 
595 #ifdef DEBUG
596 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)			\
597 	if ((sdev_debug & SDEV_DEBUG_FLK) ||				\
598 	    ((retried) && (sdev_debug & SDEV_DEBUG_RECONFIG))) {	\
599 		printf("lookup of %s/%s by %s failed, line %d\n",	\
600 		    (ddv)->sdev_name, (nm), curproc->p_user.u_comm,	\
601 		    __LINE__);						\
602 	}
603 #else
604 #define	SD_TRACE_FAILED_LOOKUP(ddv, nm, retried)
605 #endif
606 
607 #endif	/* _KERNEL */
608 
609 #ifdef __cplusplus
610 }
611 #endif
612 
613 #endif	/* _SYS_SDEV_IMPL_H */
614