xref: /titanic_41/usr/src/lib/libdiskmgt/common/libdiskmgt.h (revision 182c91496a82a606d31c680cedf9351196cc76e6)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _LIBDISKMGT_H
27 #define	_LIBDISKMGT_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <libnvpair.h>
34 #include <sys/swap.h>
35 
36 
37 /*
38  * Holds all the data regarding the device.
39  * Private to libdiskmgt. Must use dm_xxx functions to set/get data.
40  */
41 typedef uint64_t  dm_descriptor_t;
42 
43 typedef enum {
44 	DM_WHO_MKFS = 0,
45 	DM_WHO_ZPOOL,
46 	DM_WHO_ZPOOL_FORCE,
47 	DM_WHO_FORMAT,
48 	DM_WHO_SWAP,
49 	DM_WHO_DUMP,
50 	DM_WHO_ZPOOL_SPARE
51 } dm_who_type_t;
52 
53 typedef enum {
54     DM_DRIVE = 0,
55     DM_CONTROLLER,
56     DM_MEDIA,
57     DM_SLICE,
58     DM_PARTITION,
59     DM_PATH,
60     DM_ALIAS,
61     DM_BUS
62 } dm_desc_type_t;
63 
64 
65 typedef enum {
66     DM_DT_UNKNOWN = 0,
67     DM_DT_FIXED,
68     DM_DT_ZIP,
69     DM_DT_JAZ,
70     DM_DT_FLOPPY,
71     DM_DT_MO_ERASABLE,
72     DM_DT_MO_WRITEONCE,
73     DM_DT_AS_MO,
74     DM_DT_CDROM,
75     DM_DT_CDR,
76     DM_DT_CDRW,
77     DM_DT_DVDROM,
78     DM_DT_DVDR,
79     DM_DT_DVDRAM,
80     DM_DT_DVDRW,
81     DM_DT_DDCDROM,
82     DM_DT_DDCDR,
83     DM_DT_DDCDRW
84 } dm_drive_type_t;
85 
86 typedef enum {
87     DM_MT_UNKNOWN = 0,
88     DM_MT_FIXED,
89     DM_MT_FLOPPY,
90     DM_MT_CDROM,
91     DM_MT_ZIP,
92     DM_MT_JAZ,
93     DM_MT_CDR,
94     DM_MT_CDRW,
95     DM_MT_DVDROM,
96     DM_MT_DVDR,
97     DM_MT_DVDRAM,
98     DM_MT_MO_ERASABLE,
99     DM_MT_MO_WRITEONCE,
100     DM_MT_AS_MO
101 } dm_media_type_t;
102 
103 #define	DM_FILTER_END	-1
104 
105 /* drive stat name */
106 typedef enum {
107     DM_DRV_STAT_PERFORMANCE = 0,
108     DM_DRV_STAT_DIAGNOSTIC,
109     DM_DRV_STAT_TEMPERATURE
110 } dm_drive_stat_t;
111 
112 /* slice stat name */
113 typedef enum {
114     DM_SLICE_STAT_USE = 0
115 } dm_slice_stat_t;
116 
117 /* partition type */
118 typedef enum {
119 	DM_PRIMARY = 0,
120 	DM_EXTENDED,
121 	DM_LOGICAL
122 } dm_partition_type_t;
123 
124 /* attribute definitions */
125 
126 /* drive */
127 #define	DM_DISK_UP		1
128 #define	DM_DISK_DOWN		0
129 
130 #define	DM_CLUSTERED		"clustered"
131 #define	DM_DRVTYPE		"drvtype"
132 #define	DM_FAILING		"failing"
133 #define	DM_LOADED		"loaded"	/* also in media */
134 #define	DM_NDNRERRS		"ndevice_not_ready_errors"
135 #define	DM_NBYTESREAD		"nbytes_read"
136 #define	DM_NBYTESWRITTEN	"nbytes_written"
137 #define	DM_NHARDERRS		"nhard_errors"
138 #define	DM_NILLREQERRS		"nillegal_req_errors"
139 #define	DM_NMEDIAERRS		"nmedia_errors"
140 #define	DM_NNODEVERRS		"nno_dev_errors"
141 #define	DM_NREADOPS		"nread_ops"
142 #define	DM_NRECOVERRS		"nrecoverable_errors"
143 #define	DM_NSOFTERRS		"nsoft_errors"
144 #define	DM_NTRANSERRS		"ntransport_errors"
145 #define	DM_NWRITEOPS		"nwrite_ops"
146 #define	DM_OPATH		"opath"
147 #define	DM_PRODUCT_ID		"product_id"
148 #define	DM_REMOVABLE		"removable"	/* also in media */
149 #define	DM_RPM			"rpm"
150 #define	DM_SOLIDSTATE		"solid_state"
151 #define	DM_STATUS		"status"
152 #define	DM_SYNC_SPEED		"sync_speed"
153 #define	DM_TEMPERATURE		"temperature"
154 #define	DM_VENDOR_ID		"vendor_id"
155 #define	DM_WIDE			"wide"		/* also on controller */
156 #define	DM_WWN			"wwn"
157 
158 /* bus */
159 #define	DM_BTYPE		"btype"
160 #define	DM_CLOCK		"clock"		/* also on controller */
161 #define	DM_PNAME		"pname"
162 
163 /* controller */
164 #define	DM_FAST			"fast"
165 #define	DM_FAST20		"fast20"
166 #define	DM_FAST40		"fast40"
167 #define	DM_FAST80		"fast80"
168 #define	DM_MULTIPLEX		"multiplex"
169 #define	DM_PATH_STATE		"path_state"
170 
171 #define	DM_CTYPE_ATA		"ata"
172 #define	DM_CTYPE_SCSI		"scsi"
173 #define	DM_CTYPE_FIBRE		"fibre channel"
174 #define	DM_CTYPE_USB		"usb"
175 #define	DM_CTYPE_UNKNOWN	"unknown"
176 
177 /* media */
178 #define	DM_BLOCKSIZE		"blocksize"
179 #define	DM_FDISK		"fdisk"
180 #define	DM_MTYPE		"mtype"
181 #define	DM_NACTUALCYLINDERS	"nactual_cylinders"
182 #define	DM_NALTCYLINDERS	"nalt_cylinders"
183 #define	DM_NCYLINDERS		"ncylinders"
184 #define	DM_NHEADS		"nheads"
185 #define	DM_NPHYSCYLINDERS	"nphys_cylinders"
186 #define	DM_NSECTORS		"nsectors"	/* also in partition */
187 #define	DM_SIZE			"size"		/* also in slice */
188 #define	DM_NACCESSIBLE		"naccessible"
189 #define	DM_LABEL		"label"
190 
191 /* partition */
192 #define	DM_BCYL			"bcyl"
193 #define	DM_BHEAD		"bhead"
194 #define	DM_BOOTID		"bootid"
195 #define	DM_BSECT		"bsect"
196 #define	DM_ECYL			"ecyl"
197 #define	DM_EHEAD		"ehead"
198 #define	DM_ESECT		"esect"
199 #define	DM_PTYPE		"ptype" /* this references the partition id */
200 #define	DM_PARTITION_TYPE	"part_type" /* primary, extended, logical */
201 #define	DM_RELSECT		"relsect"
202 
203 /* slice */
204 #define	DM_DEVICEID		"deviceid"
205 #define	DM_DEVT			"devt"
206 #define	DM_INDEX		"index"
207 #define	DM_EFI_NAME		"name"
208 #define	DM_MOUNTPOINT		"mountpoint"
209 #define	DM_LOCALNAME		"localname"
210 #define	DM_START		"start"
211 #define	DM_TAG			"tag"
212 #define	DM_FLAG			"flag"
213 #define	DM_EFI			"efi"	/* also on media */
214 #define	DM_USED_BY		"used_by"
215 #define	DM_USED_NAME		"used_name"
216 #define	DM_USE_MOUNT		"mount"
217 #define	DM_USE_SVM		"svm"
218 #define	DM_USE_LU		"lu"
219 #define	DM_USE_DUMP		"dump"
220 #define	DM_USE_VXVM		"vxvm"
221 #define	DM_USE_FS		"fs"
222 #define	DM_USE_VFSTAB		"vfstab"
223 #define	DM_USE_EXPORTED_ZPOOL	"exported_zpool"
224 #define	DM_USE_ACTIVE_ZPOOL	"active_zpool"
225 #define	DM_USE_SPARE_ZPOOL	"spare_zpool"
226 #define	DM_USE_L2CACHE_ZPOOL	"l2cache_zpool"
227 
228 /* event */
229 #define	DM_EV_NAME		"name"
230 #define	DM_EV_DTYPE		"edtype"
231 #define	DM_EV_TYPE		"evtype"
232 #define	DM_EV_TADD		"add"
233 #define	DM_EV_TREMOVE		"remove"
234 #define	DM_EV_TCHANGE		"change"
235 
236 /* findisks */
237 #define	DM_CTYPE		"ctype"
238 #define	DM_LUN			"lun"
239 #define	DM_TARGET		"target"
240 
241 #define	NOINUSE_SET	getenv("NOINUSE_CHECK") != NULL
242 
243 void			dm_free_descriptors(dm_descriptor_t *desc_list);
244 void			dm_free_descriptor(dm_descriptor_t desc);
245 void			dm_free_name(char *name);
246 void			dm_free_swapentries(swaptbl_t *);
247 
248 dm_descriptor_t		*dm_get_descriptors(dm_desc_type_t type, int filter[],
249 			    int *errp);
250 dm_descriptor_t		*dm_get_associated_descriptors(dm_descriptor_t desc,
251 			    dm_desc_type_t type, int *errp);
252 dm_desc_type_t		*dm_get_associated_types(dm_desc_type_t type);
253 dm_descriptor_t		dm_get_descriptor_by_name(dm_desc_type_t desc_type,
254 			    char *name, int *errp);
255 char			*dm_get_name(dm_descriptor_t desc, int *errp);
256 dm_desc_type_t		dm_get_type(dm_descriptor_t desc);
257 nvlist_t		*dm_get_attributes(dm_descriptor_t desc, int *errp);
258 nvlist_t		*dm_get_stats(dm_descriptor_t desc, int stat_type,
259 			    int *errp);
260 void			dm_init_event_queue(void(*callback)(nvlist_t *, int),
261 			    int *errp);
262 nvlist_t		*dm_get_event(int *errp);
263 void			dm_get_slices(char *drive, dm_descriptor_t **slices,
264 			    int *errp);
265 void			dm_get_slice_stats(char *slice, nvlist_t **dev_stats,
266 			    int *errp);
267 int			dm_get_swapentries(swaptbl_t **, int *);
268 void			dm_get_usage_string(char *who, char *data, char **msg);
269 int			dm_inuse(char *dev_name, char **msg, dm_who_type_t who,
270 			    int *errp);
271 int			dm_inuse_swap(const char *dev_name, int *errp);
272 int			dm_isoverlapping(char *dev_name, char **msg, int *errp);
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 
278 #endif /* _LIBDISKMGT_H */
279