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