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
35extern "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"
43extern int dm_debug;
44
45#define	NVATTRS	NV_UNIQUE_NAME | NV_UNIQUE_NAME_TYPE
46#define	NVATTRS_STAT	0x0
47
48typedef struct slice_info {
49	char		*devpath;
50	int		slice_num;
51	struct slice_info *next;
52} slice_t;
53
54typedef 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
65typedef 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
75typedef 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
85typedef 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
98typedef 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
117typedef 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
133struct 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
144typedef enum {
145    DM_EV_DISK_ADD = 0,
146    DM_EV_DISK_DELETE
147} dm_event_type_t;
148
149
150/* private internal functions */
151descriptor_t	**alias_get_descriptors(int filter[], int *errp);
152descriptor_t	**alias_get_assoc_descriptors(descriptor_t *desc,
153		    dm_desc_type_t type, int *errp);
154descriptor_t	*alias_get_descriptor_by_name(char *name, int *errp);
155char		*alias_get_name(descriptor_t *desc);
156nvlist_t	*alias_get_attributes(descriptor_t *desc, int *errp);
157nvlist_t	*alias_get_stats(descriptor_t *desc, int stat_type, int *errp);
158int		alias_make_descriptors();
159
160descriptor_t	**bus_get_descriptors(int filter[], int *errp);
161descriptor_t	**bus_get_assoc_descriptors(descriptor_t *desc,
162		    dm_desc_type_t type, int *errp);
163descriptor_t	*bus_get_descriptor_by_name(char *name, int *errp);
164char		*bus_get_name(descriptor_t *desc);
165nvlist_t	*bus_get_attributes(descriptor_t *desc, int *errp);
166nvlist_t	*bus_get_stats(descriptor_t *desc, int stat_type,
167		    int *errp);
168int		bus_make_descriptors();
169
170descriptor_t	**controller_get_descriptors(int filter[], int *errp);
171descriptor_t	**controller_get_assoc_descriptors(descriptor_t *desc,
172		    dm_desc_type_t type, int *errp);
173descriptor_t	*controller_get_descriptor_by_name(char *name, int *errp);
174char		*controller_get_name(descriptor_t *desc);
175nvlist_t	*controller_get_attributes(descriptor_t *desc, int *errp);
176nvlist_t	*controller_get_stats(descriptor_t *desc, int stat_type,
177		    int *errp);
178int		controller_make_descriptors();
179
180descriptor_t	**drive_get_descriptors(int filter[], int *errp);
181descriptor_t	**drive_get_assoc_descriptors(descriptor_t *desc,
182		    dm_desc_type_t type, int *errp);
183descriptor_t	**drive_get_assocs(descriptor_t *desc, int *errp);
184descriptor_t	*drive_get_descriptor_by_name(char *name, int *errp);
185char		*drive_get_name(descriptor_t *desc);
186nvlist_t	*drive_get_attributes(descriptor_t *desc, int *errp);
187nvlist_t	*drive_get_stats(descriptor_t *desc, int stat_type, int *errp);
188int		drive_make_descriptors();
189int		drive_open_disk(disk_t *diskp, char *opath, int len);
190
191descriptor_t	**media_get_descriptors(int filter[], int *errp);
192descriptor_t	**media_get_assoc_descriptors(descriptor_t *desc,
193		    dm_desc_type_t type, int *errp);
194descriptor_t	**media_get_assocs(descriptor_t *desc, int *errp);
195descriptor_t	*media_get_descriptor_by_name(char *name, int *errp);
196char		*media_get_name(descriptor_t *desc);
197nvlist_t	*media_get_attributes(descriptor_t *desc, int *errp);
198nvlist_t	*media_get_stats(descriptor_t *desc, int stat_type, int *errp);
199int		media_make_descriptors();
200int		media_read_info(int fd, struct dk_minfo *minfo);
201int		media_read_name(disk_t *dp, char *mname, int size);
202
203descriptor_t	**path_get_descriptors(int filter[], int *errp);
204descriptor_t	**path_get_assoc_descriptors(descriptor_t *desc,
205		    dm_desc_type_t type, int *errp);
206descriptor_t	*path_get_descriptor_by_name(char *name, int *errp);
207char		*path_get_name(descriptor_t *desc);
208nvlist_t	*path_get_attributes(descriptor_t *desc, int *errp);
209nvlist_t	*path_get_stats(descriptor_t *desc, int stat_type, int *errp);
210int		path_make_descriptors();
211
212descriptor_t	**slice_get_descriptors(int filter[], int *errp);
213descriptor_t	**slice_get_assoc_descriptors(descriptor_t *desc,
214		    dm_desc_type_t type, int *errp);
215descriptor_t	**slice_get_assocs(descriptor_t *desc, int *errp);
216descriptor_t	*slice_get_descriptor_by_name(char *name, int *errp);
217char		*slice_get_name(descriptor_t *desc);
218nvlist_t	*slice_get_attributes(descriptor_t *desc, int *errp);
219nvlist_t	*slice_get_stats(descriptor_t *desc, int stat_type, int *errp);
220int		slice_make_descriptors();
221void		slice_rdsk2dsk(char *rdsk, char *dsk, int size);
222
223/* cache.c */
224void		cache_free_alias(alias_t *aliasp);
225void		cache_free_bus(bus_t *bp);
226void		cache_free_controller(controller_t *cp);
227void		cache_free_descriptor(descriptor_t *desc);
228void		cache_free_descriptors(descriptor_t **desc_list);
229void		cache_free_disk(disk_t *dp);
230void		cache_free_path(path_t *pp);
231bus_t		*cache_get_buslist();
232controller_t	*cache_get_controllerlist();
233descriptor_t	*cache_get_desc(int type, void *gp, char *name,
234		    char *secondary_name, int *errp);
235descriptor_t	**cache_get_descriptors(int type, int *errp);
236disk_t		*cache_get_disklist();
237int		cache_is_valid_desc(descriptor_t *d);
238void		cache_load_desc(int type, void *gp, char *name,
239		    char *secondary_name, int *errp);
240void		cache_rlock();
241void		cache_unlock();
242void		cache_update(dm_event_type_t ev_type, char *devname);
243void		cache_wlock();
244
245/* findevs.c */
246void		findevs(struct search_args *args);
247
248/* events.c */
249int		events_start_event_watcher();
250void		events_new_event(char *name, int dtype, char *etype);
251void		events_new_slice_event(char *dev, char *type);
252
253/* entry.c */
254void		libdiskmgt_add_str(nvlist_t *attrs, char *name, char *val,
255		    int *errp);
256descriptor_t	**libdiskmgt_empty_desc_array(int *errp);
257void		libdiskmgt_init_debug();
258int		libdiskmgt_str_eq(char *nm1, char *nm2);
259
260/* in-use detectors */
261int		inuse_mnt(char *slice, nvlist_t *attrs, int *errp);
262int		inuse_lu(char *slice, nvlist_t *attrs, int *errp);
263int		inuse_active_zpool(char *slice, nvlist_t *attrs, int *errp);
264int		inuse_exported_zpool(char *slice, nvlist_t *attrs, int *errp);
265int		inuse_dump(char *slice, nvlist_t *attrs, int *errp);
266int		inuse_vxvm(char *slice, nvlist_t *attrs, int *errp);
267int		inuse_fs(char *slice, nvlist_t *attrs, int *errp);
268
269#ifdef __cplusplus
270}
271#endif
272
273#endif /* _DISKS_PRIVATE_H */
274