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