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