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