xref: /illumos-gate/usr/src/lib/libdiskmgt/common/disks_private.h (revision b0fe7b8fa79924061f3bdf7f240ea116c2c0b704)
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 _DISKS_PRIVATE_H
27 #define	_DISKS_PRIVATE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <libdevinfo.h>
36 #include <sys/dkio.h>
37 #include <devid.h>
38 
39 #define	DM_DEBUG	"DM_LIBDISKMGT_DEBUG"
40 extern int dm_debug;
41 
42 #define	NVATTRS	NV_UNIQUE_NAME | NV_UNIQUE_NAME_TYPE
43 #define	NVATTRS_STAT	0x0
44 
45 typedef struct slice_info {
46 	char		*devpath;
47 	int		slice_num;
48 	struct slice_info *next;
49 } slice_t;
50 
51 typedef struct alias_info {
52 	char		*kstat_name;
53 	char		*alias;
54 	slice_t		*devpaths;
55 	slice_t		*orig_paths;
56 	char		*wwn;
57 	int		cluster;
58 	int		lun;
59 	int		target;
60 	struct alias_info *next;
61 } alias_t;
62 
63 typedef struct path {
64 	char			*name;
65 	char			*ctype;
66 	int			*states;
67 	char			**wwns;
68 	struct disk		**disks;
69 	struct controller_info	*controller;
70 	struct path		*next;
71 } path_t;
72 
73 typedef struct bus_info {
74 	char			*name;
75 	char			*kstat_name;
76 	char			*btype;
77 	char			*pname;
78 	int			freq;
79 	struct controller_info	**controllers;
80 	struct bus_info		*next;
81 } bus_t;
82 
83 typedef struct controller_info {
84 	char		*name;
85 	char		*kstat_name;
86 	char		*ctype;
87 	int		freq;
88 	struct disk	**disks;
89 	struct path	**paths;
90 	struct bus_info	*bus;
91 	struct controller_info *next;
92 	int		multiplex;
93 	int		scsi_options;
94 } controller_t;
95 
96 typedef struct disk {
97 	char		*device_id;	/* string encoded device id */
98 	ddi_devid_t	devid;		/* decoded device id */
99 	char		*kernel_name;	/* handles drives w/ no devlinks */
100 	char		*product_id;
101 	char		*vendor_id;
102 	controller_t	**controllers;
103 	path_t		**paths;
104 	alias_t		*aliases;
105 	struct disk	*next;
106 	int		drv_type;
107 	int		removable;
108 	int		sync_speed;
109 	int		rpm;
110 	int		wide;
111 	int		cd_rom;
112 } disk_t;
113 
114 typedef struct descriptor {
115 	union {
116 	    void		*generic;
117 	    disk_t		*disk;
118 	    controller_t	*controller;
119 	    bus_t		*bus;
120 	    path_t		*path;
121 	} p;
122 	char			*name;
123 	char			*secondary_name;
124 	struct descriptor	*next;
125 	struct descriptor	*prev;
126 	dm_desc_type_t		type;
127 	int			refcnt;
128 } descriptor_t;
129 
130 struct search_args {
131 	disk_t			*disk_listp;
132 	controller_t		*controller_listp;
133 	bus_t			*bus_listp;
134 	di_devlink_handle_t	handle;
135 	di_prom_handle_t	ph;
136 	di_node_t		node;
137 	di_minor_t		minor;
138 	int			dev_walk_status;
139 };
140 
141 typedef enum {
142     DM_EV_DISK_ADD = 0,
143     DM_EV_DISK_DELETE
144 } dm_event_type_t;
145 
146 
147 /* private internal functions */
148 descriptor_t	**alias_get_descriptors(int filter[], int *errp);
149 descriptor_t	**alias_get_assoc_descriptors(descriptor_t *desc,
150 		    dm_desc_type_t type, int *errp);
151 descriptor_t	*alias_get_descriptor_by_name(char *name, int *errp);
152 char		*alias_get_name(descriptor_t *desc);
153 nvlist_t	*alias_get_attributes(descriptor_t *desc, int *errp);
154 nvlist_t	*alias_get_stats(descriptor_t *desc, int stat_type, int *errp);
155 int		alias_make_descriptors();
156 
157 descriptor_t	**bus_get_descriptors(int filter[], int *errp);
158 descriptor_t	**bus_get_assoc_descriptors(descriptor_t *desc,
159 		    dm_desc_type_t type, int *errp);
160 descriptor_t	*bus_get_descriptor_by_name(char *name, int *errp);
161 char		*bus_get_name(descriptor_t *desc);
162 nvlist_t	*bus_get_attributes(descriptor_t *desc, int *errp);
163 nvlist_t	*bus_get_stats(descriptor_t *desc, int stat_type,
164 		    int *errp);
165 int		bus_make_descriptors();
166 
167 descriptor_t	**controller_get_descriptors(int filter[], int *errp);
168 descriptor_t	**controller_get_assoc_descriptors(descriptor_t *desc,
169 		    dm_desc_type_t type, int *errp);
170 descriptor_t	*controller_get_descriptor_by_name(char *name, int *errp);
171 char		*controller_get_name(descriptor_t *desc);
172 nvlist_t	*controller_get_attributes(descriptor_t *desc, int *errp);
173 nvlist_t	*controller_get_stats(descriptor_t *desc, int stat_type,
174 		    int *errp);
175 int		controller_make_descriptors();
176 
177 descriptor_t	**drive_get_descriptors(int filter[], int *errp);
178 descriptor_t	**drive_get_assoc_descriptors(descriptor_t *desc,
179 		    dm_desc_type_t type, int *errp);
180 descriptor_t	**drive_get_assocs(descriptor_t *desc, int *errp);
181 descriptor_t	*drive_get_descriptor_by_name(char *name, int *errp);
182 char		*drive_get_name(descriptor_t *desc);
183 nvlist_t	*drive_get_attributes(descriptor_t *desc, int *errp);
184 nvlist_t	*drive_get_stats(descriptor_t *desc, int stat_type, int *errp);
185 int		drive_make_descriptors();
186 int		drive_open_disk(disk_t *diskp, char *opath, int len);
187 
188 descriptor_t	**media_get_descriptors(int filter[], int *errp);
189 descriptor_t	**media_get_assoc_descriptors(descriptor_t *desc,
190 		    dm_desc_type_t type, int *errp);
191 descriptor_t	**media_get_assocs(descriptor_t *desc, int *errp);
192 descriptor_t	*media_get_descriptor_by_name(char *name, int *errp);
193 char		*media_get_name(descriptor_t *desc);
194 nvlist_t	*media_get_attributes(descriptor_t *desc, int *errp);
195 nvlist_t	*media_get_stats(descriptor_t *desc, int stat_type, int *errp);
196 int		media_make_descriptors();
197 int		media_read_info(int fd, struct dk_minfo *minfo);
198 int		media_read_name(disk_t *dp, char *mname, int size);
199 
200 descriptor_t	**path_get_descriptors(int filter[], int *errp);
201 descriptor_t	**path_get_assoc_descriptors(descriptor_t *desc,
202 		    dm_desc_type_t type, int *errp);
203 descriptor_t	*path_get_descriptor_by_name(char *name, int *errp);
204 char		*path_get_name(descriptor_t *desc);
205 nvlist_t	*path_get_attributes(descriptor_t *desc, int *errp);
206 nvlist_t	*path_get_stats(descriptor_t *desc, int stat_type, int *errp);
207 int		path_make_descriptors();
208 
209 descriptor_t	**slice_get_descriptors(int filter[], int *errp);
210 descriptor_t	**slice_get_assoc_descriptors(descriptor_t *desc,
211 		    dm_desc_type_t type, int *errp);
212 descriptor_t	**slice_get_assocs(descriptor_t *desc, int *errp);
213 descriptor_t	*slice_get_descriptor_by_name(char *name, int *errp);
214 char		*slice_get_name(descriptor_t *desc);
215 nvlist_t	*slice_get_attributes(descriptor_t *desc, int *errp);
216 nvlist_t	*slice_get_stats(descriptor_t *desc, int stat_type, int *errp);
217 int		slice_make_descriptors();
218 void		slice_rdsk2dsk(char *rdsk, char *dsk, int size);
219 
220 /* cache.c */
221 void		cache_free_alias(alias_t *aliasp);
222 void		cache_free_bus(bus_t *bp);
223 void		cache_free_controller(controller_t *cp);
224 void		cache_free_descriptor(descriptor_t *desc);
225 void		cache_free_descriptors(descriptor_t **desc_list);
226 void		cache_free_disk(disk_t *dp);
227 void		cache_free_path(path_t *pp);
228 bus_t		*cache_get_buslist();
229 controller_t	*cache_get_controllerlist();
230 descriptor_t	*cache_get_desc(int type, void *gp, char *name,
231 		    char *secondary_name, int *errp);
232 descriptor_t	**cache_get_descriptors(int type, int *errp);
233 disk_t		*cache_get_disklist();
234 int		cache_is_valid_desc(descriptor_t *d);
235 void		cache_load_desc(int type, void *gp, char *name,
236 		    char *secondary_name, int *errp);
237 void		cache_rlock();
238 void		cache_unlock();
239 void		cache_update(dm_event_type_t ev_type, char *devname);
240 void		cache_wlock();
241 
242 /* findevs.c */
243 void		findevs(struct search_args *args);
244 
245 /* events.c */
246 int		events_start_event_watcher();
247 void		events_new_event(char *name, int dtype, char *etype);
248 void		events_new_slice_event(char *dev, char *type);
249 
250 /* entry.c */
251 void		libdiskmgt_add_str(nvlist_t *attrs, char *name, char *val,
252 		    int *errp);
253 descriptor_t	**libdiskmgt_empty_desc_array(int *errp);
254 void		libdiskmgt_init_debug();
255 int		libdiskmgt_str_eq(char *nm1, char *nm2);
256 
257 /* in-use detectors */
258 int		inuse_mnt(char *slice, nvlist_t *attrs, int *errp);
259 int		inuse_svm(char *slice, nvlist_t *attrs, int *errp);
260 int		inuse_lu(char *slice, nvlist_t *attrs, int *errp);
261 int		inuse_active_zpool(char *slice, nvlist_t *attrs, int *errp);
262 int		inuse_exported_zpool(char *slice, nvlist_t *attrs, int *errp);
263 int		inuse_dump(char *slice, nvlist_t *attrs, int *errp);
264 int		inuse_vxvm(char *slice, nvlist_t *attrs, int *errp);
265 int		inuse_fs(char *slice, nvlist_t *attrs, int *errp);
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif /* _DISKS_PRIVATE_H */
272