xref: /titanic_51/usr/src/uts/common/sys/devcache_impl.h (revision dfb96a4f56fb431b915bc67e5d9d5c8d4f4f6679)
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_DEVCACHE_IMPL_H
27 #define	_SYS_DEVCACHE_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/list.h>
36 
37 /*
38  * /etc/devices cache files format
39  * Leave some padding for easy extension in the future
40  */
41 
42 #define	NVPF_HDR_MAGIC		0xdeb1dcac
43 #define	NVPF_HDR_VERSION	1
44 #define	NVPF_HDR_SIZE		128
45 
46 typedef struct nvpacked_file_hdr {
47 	union {
48 		struct nvfp_hdr {
49 			uint32_t	magic;
50 			int32_t		version;
51 			int64_t		size;
52 			uint16_t	hdr_chksum;
53 			uint16_t	chksum;
54 		} nvpf;
55 		uchar_t		nvpf_pad[NVPF_HDR_SIZE];
56 	} un;
57 } nvpf_hdr_t;
58 
59 #define	nvpf_magic		un.nvpf.magic
60 #define	nvpf_version		un.nvpf.version
61 #define	nvpf_size		un.nvpf.size
62 #define	nvpf_hdr_chksum		un.nvpf.hdr_chksum
63 #define	nvpf_chksum		un.nvpf.chksum
64 
65 
66 #ifdef	_KERNEL
67 
68 /*
69  * Descriptor used for kernel-level file i/o
70  */
71 typedef struct kfile {
72 	struct vnode	*kf_vp;
73 	int		kf_vnflags;
74 	char		*kf_fname;
75 	offset_t	kf_fpos;
76 	int		kf_state;
77 } kfile_t;
78 
79 /*
80  * File descriptor for files in the nvlist format
81  */
82 typedef struct nvfiledesc nvfd_t;
83 
84 /*
85  * Descriptor for a file managed as a backing store for some
86  * kernel-generated device state such as device devids,
87  * vhci-to-phci mapping, etc.
88  * Each client can manage the data in any form convenient.
89  * providing functions to unpack (read) and pack (write)
90  * the data as an nvlist.
91  *
92  * Clients should not reference this structure directly
93  * but through the handle returned when registering.
94  */
95 struct nvfiledesc {
96 	nvf_ops_t	*nvf_ops;		/* client ops vectors */
97 	int		nvf_flags;		/* flags */
98 	list_t		nvf_data_list;		/* data list */
99 	krwlock_t	nvf_lock;		/* lock for data list */
100 	list_node_t	nvf_link;		/* link to next file desc */
101 };
102 
103 /*
104  * nvf_flags
105  */
106 #define	NVF_F_DIRTY		0x01	/* needs to be flushed */
107 #define	NVF_F_FLUSHING		0x02	/* in process of being flushed */
108 #define	NVF_F_ERROR		0x04	/* most recent flush failed */
109 #define	NVF_F_READONLY		0x10	/* file is read-only */
110 #define	NVF_F_CREATE_MSG	0x20	/* file not found on boot, emit msg */
111 #define	NVF_F_REBUILD_MSG	0x40	/* file was found corrupted, emit msg */
112 
113 #define	NVF_IS_DIRTY(nvfd)	((nvfd)->nvf_flags & NVF_F_DIRTY)
114 #define	NVF_MARK_DIRTY(nvfd)	((nvfd)->nvf_flags |= NVF_F_DIRTY)
115 #define	NVF_CLEAR_DIRTY(nvfd)	((nvfd)->nvf_flags &= ~NVF_F_DIRTY)
116 
117 #define	NVF_IS_READONLY(nvfd)	((nvfd)->nvf_flags & NVF_F_READONLY)
118 #define	NVF_MARK_READONLY(nvfd)	((nvfd)->nvf_flags |= NVF_F_READONLY)
119 
120 /* shorthand to client ops */
121 #define	nvf_cache_path		nvf_ops->nvfr_cache_path
122 #define	nvf_unpack_nvlist	nvf_ops->nvfr_unpack_nvlist
123 #define	nvf_pack_list		nvf_ops->nvfr_pack_list
124 #define	nvf_list_free		nvf_ops->nvfr_list_free
125 #define	nvf_write_complete	nvf_ops->nvfr_write_complete
126 
127 
128 /*
129  * More thorough error reporting available both debug &
130  * non-debug kernels, but turned off by default.
131  */
132 extern int kfio_report_error;		/* kernel file i/o operations */
133 
134 /*
135  * Suffix of temporary file for updates
136  */
137 #define	MAX_SUFFIX_LEN		4
138 #define	NEW_FILENAME_SUFFIX	"new"
139 
140 
141 #ifdef	DEBUG
142 
143 #define	NVPDAEMON_DEBUG(args)	{ if (nvpdaemon_debug) cmn_err args; }
144 #define	KFDEBUG(args)		{ if (kfio_debug) cmn_err args; }
145 #define	KFDEBUG1(args)		{ if (kfio_debug > 1) cmn_err args; }
146 #define	KFDEBUG2(args)		{ if (kfio_debug > 2) cmn_err args; }
147 #define	KFDUMP(args)		{ if (kfio_debug > 2) args; }
148 
149 #else
150 
151 #define	NVPDAEMON_DEBUG(args)
152 #define	KFDEBUG(args)
153 #define	KFDEBUG1(args)
154 #define	KFDEBUG2(args)
155 #define	KFDUMP(args)
156 
157 #endif	/* DEBUG */
158 
159 
160 #endif	/* _KERNEL */
161 
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif	/* _SYS_DEVCACHE_IMPL_H */
167