xref: /onnv-gate/usr/src/uts/common/sys/devcache_impl.h (revision 2797:3782a13773c1)
1*2797Sjg /*
2*2797Sjg  * CDDL HEADER START
3*2797Sjg  *
4*2797Sjg  * The contents of this file are subject to the terms of the
5*2797Sjg  * Common Development and Distribution License (the "License").
6*2797Sjg  * You may not use this file except in compliance with the License.
7*2797Sjg  *
8*2797Sjg  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2797Sjg  * or http://www.opensolaris.org/os/licensing.
10*2797Sjg  * See the License for the specific language governing permissions
11*2797Sjg  * and limitations under the License.
12*2797Sjg  *
13*2797Sjg  * When distributing Covered Code, include this CDDL HEADER in each
14*2797Sjg  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2797Sjg  * If applicable, add the following below this CDDL HEADER, with the
16*2797Sjg  * fields enclosed by brackets "[]" replaced with your own identifying
17*2797Sjg  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2797Sjg  *
19*2797Sjg  * CDDL HEADER END
20*2797Sjg  */
21*2797Sjg /*
22*2797Sjg  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*2797Sjg  * Use is subject to license terms.
24*2797Sjg  */
25*2797Sjg 
26*2797Sjg #ifndef	_SYS_DEVCACHE_IMPL_H
27*2797Sjg #define	_SYS_DEVCACHE_IMPL_H
28*2797Sjg 
29*2797Sjg #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*2797Sjg 
31*2797Sjg #ifdef	__cplusplus
32*2797Sjg extern "C" {
33*2797Sjg #endif
34*2797Sjg 
35*2797Sjg #include <sys/list.h>
36*2797Sjg 
37*2797Sjg /*
38*2797Sjg  * /etc/devices cache files format
39*2797Sjg  * Leave some padding for easy extension in the future
40*2797Sjg  */
41*2797Sjg 
42*2797Sjg #define	NVPF_HDR_MAGIC		0xdeb1dcac
43*2797Sjg #define	NVPF_HDR_VERSION	1
44*2797Sjg #define	NVPF_HDR_SIZE		128
45*2797Sjg 
46*2797Sjg typedef struct nvpacked_file_hdr {
47*2797Sjg 	union {
48*2797Sjg 		struct nvfp_hdr {
49*2797Sjg 			uint32_t	magic;
50*2797Sjg 			int32_t		version;
51*2797Sjg 			int64_t		size;
52*2797Sjg 			uint16_t	hdr_chksum;
53*2797Sjg 			uint16_t	chksum;
54*2797Sjg 		} nvpf;
55*2797Sjg 		uchar_t		nvpf_pad[NVPF_HDR_SIZE];
56*2797Sjg 	} un;
57*2797Sjg } nvpf_hdr_t;
58*2797Sjg 
59*2797Sjg #define	nvpf_magic		un.nvpf.magic
60*2797Sjg #define	nvpf_version		un.nvpf.version
61*2797Sjg #define	nvpf_size		un.nvpf.size
62*2797Sjg #define	nvpf_hdr_chksum		un.nvpf.hdr_chksum
63*2797Sjg #define	nvpf_chksum		un.nvpf.chksum
64*2797Sjg 
65*2797Sjg 
66*2797Sjg #ifdef	_KERNEL
67*2797Sjg 
68*2797Sjg /*
69*2797Sjg  * Descriptor used for kernel-level file i/o
70*2797Sjg  */
71*2797Sjg typedef struct kfile {
72*2797Sjg 	struct vnode	*kf_vp;
73*2797Sjg 	int		kf_vnflags;
74*2797Sjg 	char		*kf_fname;
75*2797Sjg 	offset_t	kf_fpos;
76*2797Sjg 	int		kf_state;
77*2797Sjg } kfile_t;
78*2797Sjg 
79*2797Sjg /*
80*2797Sjg  * File descriptor for files in the nvlist format
81*2797Sjg  */
82*2797Sjg typedef struct nvfiledesc nvfd_t;
83*2797Sjg 
84*2797Sjg /*
85*2797Sjg  * Descriptor for a file managed as a backing store for some
86*2797Sjg  * kernel-generated device state such as device devids,
87*2797Sjg  * vhci-to-phci mapping, etc.
88*2797Sjg  * Each client can manage the data in any form convenient.
89*2797Sjg  * providing functions to unpack (read) and pack (write)
90*2797Sjg  * the data as an nvlist.
91*2797Sjg  *
92*2797Sjg  * Clients should not reference this structure directly
93*2797Sjg  * but through the handle returned when registering.
94*2797Sjg  */
95*2797Sjg struct nvfiledesc {
96*2797Sjg 	nvf_ops_t	*nvf_ops;		/* client ops vectors */
97*2797Sjg 	int		nvf_flags;		/* flags */
98*2797Sjg 	list_t		nvf_data_list;		/* data list */
99*2797Sjg 	krwlock_t	nvf_lock;		/* lock for data list */
100*2797Sjg 	list_node_t	nvf_link;		/* link to next file desc */
101*2797Sjg };
102*2797Sjg 
103*2797Sjg /*
104*2797Sjg  * nvf_flags
105*2797Sjg  */
106*2797Sjg #define	NVF_F_DIRTY		0x01	/* needs to be flushed */
107*2797Sjg #define	NVF_F_FLUSHING		0x02	/* in process of being flushed */
108*2797Sjg #define	NVF_F_ERROR		0x04	/* most recent flush failed */
109*2797Sjg #define	NVF_F_READONLY		0x10	/* file is read-only */
110*2797Sjg #define	NVF_F_CREATE_MSG	0x20	/* file not found on boot, emit msg */
111*2797Sjg #define	NVF_F_REBUILD_MSG	0x40	/* file was found corrupted, emit msg */
112*2797Sjg 
113*2797Sjg #define	NVF_IS_DIRTY(nvfd)	((nvfd)->nvf_flags & NVF_F_DIRTY)
114*2797Sjg #define	NVF_MARK_DIRTY(nvfd)	((nvfd)->nvf_flags |= NVF_F_DIRTY)
115*2797Sjg #define	NVF_CLEAR_DIRTY(nvfd)	((nvfd)->nvf_flags &= ~NVF_F_DIRTY)
116*2797Sjg 
117*2797Sjg #define	NVF_IS_READONLY(nvfd)	((nvfd)->nvf_flags & NVF_F_READONLY)
118*2797Sjg #define	NVF_MARK_READONLY(nvfd)	((nvfd)->nvf_flags |= NVF_F_READONLY)
119*2797Sjg 
120*2797Sjg /* shorthand to client ops */
121*2797Sjg #define	nvf_cache_path		nvf_ops->nvfr_cache_path
122*2797Sjg #define	nvf_unpack_nvlist	nvf_ops->nvfr_unpack_nvlist
123*2797Sjg #define	nvf_pack_list		nvf_ops->nvfr_pack_list
124*2797Sjg #define	nvf_list_free		nvf_ops->nvfr_list_free
125*2797Sjg #define	nvf_write_complete	nvf_ops->nvfr_write_complete
126*2797Sjg 
127*2797Sjg 
128*2797Sjg /*
129*2797Sjg  * More thorough error reporting available both debug &
130*2797Sjg  * non-debug kernels, but turned off by default.
131*2797Sjg  */
132*2797Sjg extern int kfio_report_error;		/* kernel file i/o operations */
133*2797Sjg 
134*2797Sjg /*
135*2797Sjg  * Suffix of temporary file for updates
136*2797Sjg  */
137*2797Sjg #define	MAX_SUFFIX_LEN		4
138*2797Sjg #define	NEW_FILENAME_SUFFIX	"new"
139*2797Sjg 
140*2797Sjg 
141*2797Sjg #ifdef	DEBUG
142*2797Sjg 
143*2797Sjg #define	NVPDAEMON_DEBUG(args)	{ if (nvpdaemon_debug) cmn_err args; }
144*2797Sjg #define	KFDEBUG(args)		{ if (kfio_debug) cmn_err args; }
145*2797Sjg #define	KFDEBUG1(args)		{ if (kfio_debug > 1) cmn_err args; }
146*2797Sjg #define	KFDEBUG2(args)		{ if (kfio_debug > 2) cmn_err args; }
147*2797Sjg #define	KFDUMP(args)		{ if (kfio_debug > 2) args; }
148*2797Sjg 
149*2797Sjg #else
150*2797Sjg 
151*2797Sjg #define	NVPDAEMON_DEBUG(args)
152*2797Sjg #define	KFDEBUG(args)
153*2797Sjg #define	KFDEBUG1(args)
154*2797Sjg #define	KFDEBUG2(args)
155*2797Sjg #define	KFDUMP(args)
156*2797Sjg 
157*2797Sjg #endif	/* DEBUG */
158*2797Sjg 
159*2797Sjg 
160*2797Sjg #endif	/* _KERNEL */
161*2797Sjg 
162*2797Sjg #ifdef	__cplusplus
163*2797Sjg }
164*2797Sjg #endif
165*2797Sjg 
166*2797Sjg #endif	/* _SYS_DEVCACHE_IMPL_H */
167