xref: /titanic_44/usr/src/lib/libdiskmgt/common/disks_private.h (revision 87308b749adb04ab3f564c765b089962af3edb4d)
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 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright 2016 Nexenta Systems, Inc.
26  */
27 
28 #ifndef _DISKS_PRIVATE_H
29 #define	_DISKS_PRIVATE_H
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 	int		solid_state;
113 } disk_t;
114 
115 typedef struct descriptor {
116 	union {
117 	    void		*generic;
118 	    disk_t		*disk;
119 	    controller_t	*controller;
120 	    bus_t		*bus;
121 	    path_t		*path;
122 	} p;
123 	char			*name;
124 	char			*secondary_name;
125 	struct descriptor	*next;
126 	struct descriptor	*prev;
127 	dm_desc_type_t		type;
128 	int			refcnt;
129 } descriptor_t;
130 
131 struct search_args {
132 	disk_t			*disk_listp;
133 	controller_t		*controller_listp;
134 	bus_t			*bus_listp;
135 	di_devlink_handle_t	handle;
136 	di_prom_handle_t	ph;
137 	di_node_t		node;
138 	di_minor_t		minor;
139 	int			dev_walk_status;
140 };
141 
142 typedef enum {
143     DM_EV_DISK_ADD = 0,
144     DM_EV_DISK_DELETE
145 } dm_event_type_t;
146 
147 
148 /* private internal functions */
149 descriptor_t	**alias_get_descriptors(int filter[], int *errp);
150 descriptor_t	**alias_get_assoc_descriptors(descriptor_t *desc,
151 		    dm_desc_type_t type, int *errp);
152 descriptor_t	*alias_get_descriptor_by_name(char *name, int *errp);
153 char		*alias_get_name(descriptor_t *desc);
154 nvlist_t	*alias_get_attributes(descriptor_t *desc, int *errp);
155 nvlist_t	*alias_get_stats(descriptor_t *desc, int stat_type, int *errp);
156 int		alias_make_descriptors();
157 
158 descriptor_t	**bus_get_descriptors(int filter[], int *errp);
159 descriptor_t	**bus_get_assoc_descriptors(descriptor_t *desc,
160 		    dm_desc_type_t type, int *errp);
161 descriptor_t	*bus_get_descriptor_by_name(char *name, int *errp);
162 char		*bus_get_name(descriptor_t *desc);
163 nvlist_t	*bus_get_attributes(descriptor_t *desc, int *errp);
164 nvlist_t	*bus_get_stats(descriptor_t *desc, int stat_type,
165 		    int *errp);
166 int		bus_make_descriptors();
167 
168 descriptor_t	**controller_get_descriptors(int filter[], int *errp);
169 descriptor_t	**controller_get_assoc_descriptors(descriptor_t *desc,
170 		    dm_desc_type_t type, int *errp);
171 descriptor_t	*controller_get_descriptor_by_name(char *name, int *errp);
172 char		*controller_get_name(descriptor_t *desc);
173 nvlist_t	*controller_get_attributes(descriptor_t *desc, int *errp);
174 nvlist_t	*controller_get_stats(descriptor_t *desc, int stat_type,
175 		    int *errp);
176 int		controller_make_descriptors();
177 
178 descriptor_t	**drive_get_descriptors(int filter[], int *errp);
179 descriptor_t	**drive_get_assoc_descriptors(descriptor_t *desc,
180 		    dm_desc_type_t type, int *errp);
181 descriptor_t	**drive_get_assocs(descriptor_t *desc, int *errp);
182 descriptor_t	*drive_get_descriptor_by_name(char *name, int *errp);
183 char		*drive_get_name(descriptor_t *desc);
184 nvlist_t	*drive_get_attributes(descriptor_t *desc, int *errp);
185 nvlist_t	*drive_get_stats(descriptor_t *desc, int stat_type, int *errp);
186 int		drive_make_descriptors();
187 int		drive_open_disk(disk_t *diskp, char *opath, int len);
188 
189 descriptor_t	**media_get_descriptors(int filter[], int *errp);
190 descriptor_t	**media_get_assoc_descriptors(descriptor_t *desc,
191 		    dm_desc_type_t type, int *errp);
192 descriptor_t	**media_get_assocs(descriptor_t *desc, int *errp);
193 descriptor_t	*media_get_descriptor_by_name(char *name, int *errp);
194 char		*media_get_name(descriptor_t *desc);
195 nvlist_t	*media_get_attributes(descriptor_t *desc, int *errp);
196 nvlist_t	*media_get_stats(descriptor_t *desc, int stat_type, int *errp);
197 int		media_make_descriptors();
198 int		media_read_info(int fd, struct dk_minfo *minfo);
199 int		media_read_name(disk_t *dp, char *mname, int size);
200 
201 descriptor_t	**path_get_descriptors(int filter[], int *errp);
202 descriptor_t	**path_get_assoc_descriptors(descriptor_t *desc,
203 		    dm_desc_type_t type, int *errp);
204 descriptor_t	*path_get_descriptor_by_name(char *name, int *errp);
205 char		*path_get_name(descriptor_t *desc);
206 nvlist_t	*path_get_attributes(descriptor_t *desc, int *errp);
207 nvlist_t	*path_get_stats(descriptor_t *desc, int stat_type, int *errp);
208 int		path_make_descriptors();
209 
210 descriptor_t	**slice_get_descriptors(int filter[], int *errp);
211 descriptor_t	**slice_get_assoc_descriptors(descriptor_t *desc,
212 		    dm_desc_type_t type, int *errp);
213 descriptor_t	**slice_get_assocs(descriptor_t *desc, int *errp);
214 descriptor_t	*slice_get_descriptor_by_name(char *name, int *errp);
215 char		*slice_get_name(descriptor_t *desc);
216 nvlist_t	*slice_get_attributes(descriptor_t *desc, int *errp);
217 nvlist_t	*slice_get_stats(descriptor_t *desc, int stat_type, int *errp);
218 int		slice_make_descriptors();
219 void		slice_rdsk2dsk(char *rdsk, char *dsk, int size);
220 
221 /* cache.c */
222 void		cache_free_alias(alias_t *aliasp);
223 void		cache_free_bus(bus_t *bp);
224 void		cache_free_controller(controller_t *cp);
225 void		cache_free_descriptor(descriptor_t *desc);
226 void		cache_free_descriptors(descriptor_t **desc_list);
227 void		cache_free_disk(disk_t *dp);
228 void		cache_free_path(path_t *pp);
229 bus_t		*cache_get_buslist();
230 controller_t	*cache_get_controllerlist();
231 descriptor_t	*cache_get_desc(int type, void *gp, char *name,
232 		    char *secondary_name, int *errp);
233 descriptor_t	**cache_get_descriptors(int type, int *errp);
234 disk_t		*cache_get_disklist();
235 int		cache_is_valid_desc(descriptor_t *d);
236 void		cache_load_desc(int type, void *gp, char *name,
237 		    char *secondary_name, int *errp);
238 void		cache_rlock();
239 void		cache_unlock();
240 void		cache_update(dm_event_type_t ev_type, char *devname);
241 void		cache_wlock();
242 
243 /* findevs.c */
244 void		findevs(struct search_args *args);
245 
246 /* events.c */
247 int		events_start_event_watcher();
248 void		events_new_event(char *name, int dtype, char *etype);
249 void		events_new_slice_event(char *dev, char *type);
250 
251 /* entry.c */
252 void		libdiskmgt_add_str(nvlist_t *attrs, char *name, char *val,
253 		    int *errp);
254 descriptor_t	**libdiskmgt_empty_desc_array(int *errp);
255 void		libdiskmgt_init_debug();
256 int		libdiskmgt_str_eq(char *nm1, char *nm2);
257 
258 /* in-use detectors */
259 int		inuse_mnt(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