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