xref: /illumos-gate/usr/src/lib/libdiskmgt/common/disks_private.h (revision 3ce5372277f4657ad0e52d36c979527c4ca22de2)
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  */
26 
27 /*
28  * Copyright 2017 Nexenta Systems, Inc.
29  */
30 
31 #ifndef _DISKS_PRIVATE_H
32 #define	_DISKS_PRIVATE_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include <libdevinfo.h>
39 #include <sys/dkio.h>
40 #include <devid.h>
41 
42 #define	DM_DEBUG	"DM_LIBDISKMGT_DEBUG"
43 extern int dm_debug;
44 
45 #define	NVATTRS	NV_UNIQUE_NAME | NV_UNIQUE_NAME_TYPE
46 #define	NVATTRS_STAT	0x0
47 
48 typedef struct slice_info {
49 	char		*devpath;
50 	int		slice_num;
51 	struct slice_info *next;
52 } slice_t;
53 
54 typedef struct alias_info {
55 	char		*kstat_name;
56 	char		*alias;
57 	slice_t		*devpaths;
58 	slice_t		*orig_paths;
59 	char		*wwn;
60 	int		lun;
61 	int		target;
62 	struct alias_info *next;
63 } alias_t;
64 
65 typedef struct path {
66 	char			*name;
67 	char			*ctype;
68 	int			*states;
69 	char			**wwns;
70 	struct disk		**disks;
71 	struct controller_info	*controller;
72 	struct path		*next;
73 } path_t;
74 
75 typedef struct bus_info {
76 	char			*name;
77 	char			*kstat_name;
78 	char			*btype;
79 	char			*pname;
80 	int			freq;
81 	struct controller_info	**controllers;
82 	struct bus_info		*next;
83 } bus_t;
84 
85 typedef struct controller_info {
86 	char		*name;
87 	char		*kstat_name;
88 	char		*ctype;
89 	int		freq;
90 	struct disk	**disks;
91 	struct path	**paths;
92 	struct bus_info	*bus;
93 	struct controller_info *next;
94 	int		multiplex;
95 	int		scsi_options;
96 } controller_t;
97 
98 typedef struct disk {
99 	char		*device_id;	/* string encoded device id */
100 	ddi_devid_t	devid;		/* decoded device id */
101 	char		*kernel_name;	/* handles drives w/ no devlinks */
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		solid_state;
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_make_descriptors();
200 int		media_read_info(int fd, struct dk_minfo *minfo);
201 int		media_read_name(disk_t *dp, char *mname, int size);
202 
203 descriptor_t	**path_get_descriptors(int filter[], int *errp);
204 descriptor_t	**path_get_assoc_descriptors(descriptor_t *desc,
205 		    dm_desc_type_t type, int *errp);
206 descriptor_t	*path_get_descriptor_by_name(char *name, int *errp);
207 char		*path_get_name(descriptor_t *desc);
208 nvlist_t	*path_get_attributes(descriptor_t *desc, int *errp);
209 nvlist_t	*path_get_stats(descriptor_t *desc, int stat_type, int *errp);
210 int		path_make_descriptors();
211 
212 descriptor_t	**slice_get_descriptors(int filter[], int *errp);
213 descriptor_t	**slice_get_assoc_descriptors(descriptor_t *desc,
214 		    dm_desc_type_t type, int *errp);
215 descriptor_t	**slice_get_assocs(descriptor_t *desc, int *errp);
216 descriptor_t	*slice_get_descriptor_by_name(char *name, int *errp);
217 char		*slice_get_name(descriptor_t *desc);
218 nvlist_t	*slice_get_attributes(descriptor_t *desc, int *errp);
219 nvlist_t	*slice_get_stats(descriptor_t *desc, int stat_type, int *errp);
220 int		slice_make_descriptors();
221 void		slice_rdsk2dsk(char *rdsk, char *dsk, int size);
222 
223 /* cache.c */
224 void		cache_free_alias(alias_t *aliasp);
225 void		cache_free_bus(bus_t *bp);
226 void		cache_free_controller(controller_t *cp);
227 void		cache_free_descriptor(descriptor_t *desc);
228 void		cache_free_descriptors(descriptor_t **desc_list);
229 void		cache_free_disk(disk_t *dp);
230 void		cache_free_path(path_t *pp);
231 bus_t		*cache_get_buslist();
232 controller_t	*cache_get_controllerlist();
233 descriptor_t	*cache_get_desc(int type, void *gp, char *name,
234 		    char *secondary_name, int *errp);
235 descriptor_t	**cache_get_descriptors(int type, int *errp);
236 disk_t		*cache_get_disklist();
237 int		cache_is_valid_desc(descriptor_t *d);
238 void		cache_load_desc(int type, void *gp, char *name,
239 		    char *secondary_name, int *errp);
240 void		cache_rlock();
241 void		cache_unlock();
242 void		cache_update(dm_event_type_t ev_type, char *devname);
243 void		cache_wlock();
244 
245 /* findevs.c */
246 void		findevs(struct search_args *args);
247 
248 /* events.c */
249 int		events_start_event_watcher();
250 void		events_new_event(char *name, int dtype, char *etype);
251 void		events_new_slice_event(char *dev, char *type);
252 
253 /* entry.c */
254 void		libdiskmgt_add_str(nvlist_t *attrs, char *name, char *val,
255 		    int *errp);
256 descriptor_t	**libdiskmgt_empty_desc_array(int *errp);
257 void		libdiskmgt_init_debug();
258 int		libdiskmgt_str_eq(char *nm1, char *nm2);
259 
260 /* in-use detectors */
261 int		inuse_mnt(char *slice, nvlist_t *attrs, int *errp);
262 int		inuse_lu(char *slice, nvlist_t *attrs, int *errp);
263 int		inuse_active_zpool(char *slice, nvlist_t *attrs, int *errp);
264 int		inuse_exported_zpool(char *slice, nvlist_t *attrs, int *errp);
265 int		inuse_dump(char *slice, nvlist_t *attrs, int *errp);
266 int		inuse_vxvm(char *slice, nvlist_t *attrs, int *errp);
267 int		inuse_fs(char *slice, nvlist_t *attrs, int *errp);
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 
273 #endif /* _DISKS_PRIVATE_H */
274