xref: /titanic_41/usr/src/lib/libdiskmgt/common/disks_private.h (revision fc2d3b38888ecf63e62407cfe5e21a3ac5558897)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
518c2aff7Sartem  * Common Development and Distribution License (the "License").
618c2aff7Sartem  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2246a2abf2Seschrock  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _DISKS_PRIVATE_H
277c478bd9Sstevel@tonic-gate #define	_DISKS_PRIVATE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef __cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <libdevinfo.h>
347c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
357c478bd9Sstevel@tonic-gate #include <devid.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #define	DM_DEBUG	"DM_LIBDISKMGT_DEBUG"
387c478bd9Sstevel@tonic-gate extern int dm_debug;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	NVATTRS	NV_UNIQUE_NAME | NV_UNIQUE_NAME_TYPE
417c478bd9Sstevel@tonic-gate #define	NVATTRS_STAT	0x0
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate typedef struct slice_info {
447c478bd9Sstevel@tonic-gate 	char		*devpath;
457c478bd9Sstevel@tonic-gate 	int		slice_num;
467c478bd9Sstevel@tonic-gate 	struct slice_info *next;
477c478bd9Sstevel@tonic-gate } slice_t;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate typedef struct alias_info {
507c478bd9Sstevel@tonic-gate 	char		*kstat_name;
517c478bd9Sstevel@tonic-gate 	char		*alias;
527c478bd9Sstevel@tonic-gate 	slice_t		*devpaths;
537c478bd9Sstevel@tonic-gate 	slice_t		*orig_paths;
547c478bd9Sstevel@tonic-gate 	char		*wwn;
557c478bd9Sstevel@tonic-gate 	int		cluster;
567c478bd9Sstevel@tonic-gate 	int		lun;
577c478bd9Sstevel@tonic-gate 	int		target;
587c478bd9Sstevel@tonic-gate 	struct alias_info *next;
597c478bd9Sstevel@tonic-gate } alias_t;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate typedef struct path {
627c478bd9Sstevel@tonic-gate 	char			*name;
637c478bd9Sstevel@tonic-gate 	char			*ctype;
647c478bd9Sstevel@tonic-gate 	int			*states;
657c478bd9Sstevel@tonic-gate 	char			**wwns;
667c478bd9Sstevel@tonic-gate 	struct disk		**disks;
677c478bd9Sstevel@tonic-gate 	struct controller_info	*controller;
687c478bd9Sstevel@tonic-gate 	struct path		*next;
697c478bd9Sstevel@tonic-gate } path_t;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate typedef struct bus_info {
727c478bd9Sstevel@tonic-gate 	char			*name;
737c478bd9Sstevel@tonic-gate 	char			*kstat_name;
747c478bd9Sstevel@tonic-gate 	char			*btype;
757c478bd9Sstevel@tonic-gate 	char			*pname;
767c478bd9Sstevel@tonic-gate 	int			freq;
777c478bd9Sstevel@tonic-gate 	struct controller_info	**controllers;
787c478bd9Sstevel@tonic-gate 	struct bus_info		*next;
797c478bd9Sstevel@tonic-gate } bus_t;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate typedef struct controller_info {
827c478bd9Sstevel@tonic-gate 	char		*name;
837c478bd9Sstevel@tonic-gate 	char		*kstat_name;
847c478bd9Sstevel@tonic-gate 	char		*ctype;
857c478bd9Sstevel@tonic-gate 	int		freq;
867c478bd9Sstevel@tonic-gate 	struct disk	**disks;
877c478bd9Sstevel@tonic-gate 	struct path	**paths;
887c478bd9Sstevel@tonic-gate 	struct bus_info	*bus;
897c478bd9Sstevel@tonic-gate 	struct controller_info *next;
907c478bd9Sstevel@tonic-gate 	int		multiplex;
917c478bd9Sstevel@tonic-gate 	int		scsi_options;
927c478bd9Sstevel@tonic-gate } controller_t;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate typedef struct disk {
957c478bd9Sstevel@tonic-gate 	char		*device_id;	/* string encoded device id */
967c478bd9Sstevel@tonic-gate 	ddi_devid_t	devid;		/* decoded device id */
977c478bd9Sstevel@tonic-gate 	char		*kernel_name;	/* handles drives w/ no devlinks */
987c478bd9Sstevel@tonic-gate 	char		*product_id;
997c478bd9Sstevel@tonic-gate 	char		*vendor_id;
1007c478bd9Sstevel@tonic-gate 	controller_t	**controllers;
1017c478bd9Sstevel@tonic-gate 	path_t		**paths;
1027c478bd9Sstevel@tonic-gate 	alias_t		*aliases;
1037c478bd9Sstevel@tonic-gate 	struct disk	*next;
1047c478bd9Sstevel@tonic-gate 	int		drv_type;
1057c478bd9Sstevel@tonic-gate 	int		removable;
1067c478bd9Sstevel@tonic-gate 	int		sync_speed;
1077c478bd9Sstevel@tonic-gate 	int		rpm;
1087c478bd9Sstevel@tonic-gate 	int		wide;
1097c478bd9Sstevel@tonic-gate 	int		cd_rom;
110*fc2d3b38SGarrett D'Amore 	int		solid_state;
1117c478bd9Sstevel@tonic-gate } disk_t;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate typedef struct descriptor {
1147c478bd9Sstevel@tonic-gate 	union {
1157c478bd9Sstevel@tonic-gate 	    void		*generic;
1167c478bd9Sstevel@tonic-gate 	    disk_t		*disk;
1177c478bd9Sstevel@tonic-gate 	    controller_t	*controller;
1187c478bd9Sstevel@tonic-gate 	    bus_t		*bus;
1197c478bd9Sstevel@tonic-gate 	    path_t		*path;
1207c478bd9Sstevel@tonic-gate 	} p;
1217c478bd9Sstevel@tonic-gate 	char			*name;
1227c478bd9Sstevel@tonic-gate 	char			*secondary_name;
1237c478bd9Sstevel@tonic-gate 	struct descriptor	*next;
1247c478bd9Sstevel@tonic-gate 	struct descriptor	*prev;
1257c478bd9Sstevel@tonic-gate 	dm_desc_type_t		type;
1267c478bd9Sstevel@tonic-gate 	int			refcnt;
1277c478bd9Sstevel@tonic-gate } descriptor_t;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate struct search_args {
1307c478bd9Sstevel@tonic-gate 	disk_t			*disk_listp;
1317c478bd9Sstevel@tonic-gate 	controller_t		*controller_listp;
1327c478bd9Sstevel@tonic-gate 	bus_t			*bus_listp;
1337c478bd9Sstevel@tonic-gate 	di_devlink_handle_t	handle;
1347c478bd9Sstevel@tonic-gate 	di_prom_handle_t	ph;
1357c478bd9Sstevel@tonic-gate 	di_node_t		node;
1367c478bd9Sstevel@tonic-gate 	di_minor_t		minor;
1377c478bd9Sstevel@tonic-gate 	int			dev_walk_status;
1387c478bd9Sstevel@tonic-gate };
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate typedef enum {
1417c478bd9Sstevel@tonic-gate     DM_EV_DISK_ADD = 0,
1427c478bd9Sstevel@tonic-gate     DM_EV_DISK_DELETE
1437c478bd9Sstevel@tonic-gate } dm_event_type_t;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /* private internal functions */
1477c478bd9Sstevel@tonic-gate descriptor_t	**alias_get_descriptors(int filter[], int *errp);
1487c478bd9Sstevel@tonic-gate descriptor_t	**alias_get_assoc_descriptors(descriptor_t *desc,
1497c478bd9Sstevel@tonic-gate 		    dm_desc_type_t type, int *errp);
1507c478bd9Sstevel@tonic-gate descriptor_t	*alias_get_descriptor_by_name(char *name, int *errp);
1517c478bd9Sstevel@tonic-gate char		*alias_get_name(descriptor_t *desc);
1527c478bd9Sstevel@tonic-gate nvlist_t	*alias_get_attributes(descriptor_t *desc, int *errp);
1537c478bd9Sstevel@tonic-gate nvlist_t	*alias_get_stats(descriptor_t *desc, int stat_type, int *errp);
1547c478bd9Sstevel@tonic-gate int		alias_make_descriptors();
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate descriptor_t	**bus_get_descriptors(int filter[], int *errp);
1577c478bd9Sstevel@tonic-gate descriptor_t	**bus_get_assoc_descriptors(descriptor_t *desc,
1587c478bd9Sstevel@tonic-gate 		    dm_desc_type_t type, int *errp);
1597c478bd9Sstevel@tonic-gate descriptor_t	*bus_get_descriptor_by_name(char *name, int *errp);
1607c478bd9Sstevel@tonic-gate char		*bus_get_name(descriptor_t *desc);
1617c478bd9Sstevel@tonic-gate nvlist_t	*bus_get_attributes(descriptor_t *desc, int *errp);
1627c478bd9Sstevel@tonic-gate nvlist_t	*bus_get_stats(descriptor_t *desc, int stat_type,
1637c478bd9Sstevel@tonic-gate 		    int *errp);
1647c478bd9Sstevel@tonic-gate int		bus_make_descriptors();
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate descriptor_t	**controller_get_descriptors(int filter[], int *errp);
1677c478bd9Sstevel@tonic-gate descriptor_t	**controller_get_assoc_descriptors(descriptor_t *desc,
1687c478bd9Sstevel@tonic-gate 		    dm_desc_type_t type, int *errp);
1697c478bd9Sstevel@tonic-gate descriptor_t	*controller_get_descriptor_by_name(char *name, int *errp);
1707c478bd9Sstevel@tonic-gate char		*controller_get_name(descriptor_t *desc);
1717c478bd9Sstevel@tonic-gate nvlist_t	*controller_get_attributes(descriptor_t *desc, int *errp);
1727c478bd9Sstevel@tonic-gate nvlist_t	*controller_get_stats(descriptor_t *desc, int stat_type,
1737c478bd9Sstevel@tonic-gate 		    int *errp);
1747c478bd9Sstevel@tonic-gate int		controller_make_descriptors();
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate descriptor_t	**drive_get_descriptors(int filter[], int *errp);
1777c478bd9Sstevel@tonic-gate descriptor_t	**drive_get_assoc_descriptors(descriptor_t *desc,
1787c478bd9Sstevel@tonic-gate 		    dm_desc_type_t type, int *errp);
1797c478bd9Sstevel@tonic-gate descriptor_t	**drive_get_assocs(descriptor_t *desc, int *errp);
1807c478bd9Sstevel@tonic-gate descriptor_t	*drive_get_descriptor_by_name(char *name, int *errp);
1817c478bd9Sstevel@tonic-gate char		*drive_get_name(descriptor_t *desc);
1827c478bd9Sstevel@tonic-gate nvlist_t	*drive_get_attributes(descriptor_t *desc, int *errp);
1837c478bd9Sstevel@tonic-gate nvlist_t	*drive_get_stats(descriptor_t *desc, int stat_type, int *errp);
1847c478bd9Sstevel@tonic-gate int		drive_make_descriptors();
1857c478bd9Sstevel@tonic-gate int		drive_open_disk(disk_t *diskp, char *opath, int len);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate descriptor_t	**media_get_descriptors(int filter[], int *errp);
1887c478bd9Sstevel@tonic-gate descriptor_t	**media_get_assoc_descriptors(descriptor_t *desc,
1897c478bd9Sstevel@tonic-gate 		    dm_desc_type_t type, int *errp);
1907c478bd9Sstevel@tonic-gate descriptor_t	**media_get_assocs(descriptor_t *desc, int *errp);
1917c478bd9Sstevel@tonic-gate descriptor_t	*media_get_descriptor_by_name(char *name, int *errp);
1927c478bd9Sstevel@tonic-gate char		*media_get_name(descriptor_t *desc);
1937c478bd9Sstevel@tonic-gate nvlist_t	*media_get_attributes(descriptor_t *desc, int *errp);
1947c478bd9Sstevel@tonic-gate nvlist_t	*media_get_stats(descriptor_t *desc, int stat_type, int *errp);
1957c478bd9Sstevel@tonic-gate int		media_make_descriptors();
1967c478bd9Sstevel@tonic-gate int		media_read_info(int fd, struct dk_minfo *minfo);
1977c478bd9Sstevel@tonic-gate int		media_read_name(disk_t *dp, char *mname, int size);
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate descriptor_t	**path_get_descriptors(int filter[], int *errp);
2007c478bd9Sstevel@tonic-gate descriptor_t	**path_get_assoc_descriptors(descriptor_t *desc,
2017c478bd9Sstevel@tonic-gate 		    dm_desc_type_t type, int *errp);
2027c478bd9Sstevel@tonic-gate descriptor_t	*path_get_descriptor_by_name(char *name, int *errp);
2037c478bd9Sstevel@tonic-gate char		*path_get_name(descriptor_t *desc);
2047c478bd9Sstevel@tonic-gate nvlist_t	*path_get_attributes(descriptor_t *desc, int *errp);
2057c478bd9Sstevel@tonic-gate nvlist_t	*path_get_stats(descriptor_t *desc, int stat_type, int *errp);
2067c478bd9Sstevel@tonic-gate int		path_make_descriptors();
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate descriptor_t	**slice_get_descriptors(int filter[], int *errp);
2097c478bd9Sstevel@tonic-gate descriptor_t	**slice_get_assoc_descriptors(descriptor_t *desc,
2107c478bd9Sstevel@tonic-gate 		    dm_desc_type_t type, int *errp);
2117c478bd9Sstevel@tonic-gate descriptor_t	**slice_get_assocs(descriptor_t *desc, int *errp);
2127c478bd9Sstevel@tonic-gate descriptor_t	*slice_get_descriptor_by_name(char *name, int *errp);
2137c478bd9Sstevel@tonic-gate char		*slice_get_name(descriptor_t *desc);
2147c478bd9Sstevel@tonic-gate nvlist_t	*slice_get_attributes(descriptor_t *desc, int *errp);
2157c478bd9Sstevel@tonic-gate nvlist_t	*slice_get_stats(descriptor_t *desc, int stat_type, int *errp);
2167c478bd9Sstevel@tonic-gate int		slice_make_descriptors();
2177c478bd9Sstevel@tonic-gate void		slice_rdsk2dsk(char *rdsk, char *dsk, int size);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate /* cache.c */
2207c478bd9Sstevel@tonic-gate void		cache_free_alias(alias_t *aliasp);
2217c478bd9Sstevel@tonic-gate void		cache_free_bus(bus_t *bp);
2227c478bd9Sstevel@tonic-gate void		cache_free_controller(controller_t *cp);
2237c478bd9Sstevel@tonic-gate void		cache_free_descriptor(descriptor_t *desc);
2247c478bd9Sstevel@tonic-gate void		cache_free_descriptors(descriptor_t **desc_list);
2257c478bd9Sstevel@tonic-gate void		cache_free_disk(disk_t *dp);
2267c478bd9Sstevel@tonic-gate void		cache_free_path(path_t *pp);
2277c478bd9Sstevel@tonic-gate bus_t		*cache_get_buslist();
2287c478bd9Sstevel@tonic-gate controller_t	*cache_get_controllerlist();
2297c478bd9Sstevel@tonic-gate descriptor_t	*cache_get_desc(int type, void *gp, char *name,
2307c478bd9Sstevel@tonic-gate 		    char *secondary_name, int *errp);
2317c478bd9Sstevel@tonic-gate descriptor_t	**cache_get_descriptors(int type, int *errp);
2327c478bd9Sstevel@tonic-gate disk_t		*cache_get_disklist();
2337c478bd9Sstevel@tonic-gate int		cache_is_valid_desc(descriptor_t *d);
2347c478bd9Sstevel@tonic-gate void		cache_load_desc(int type, void *gp, char *name,
2357c478bd9Sstevel@tonic-gate 		    char *secondary_name, int *errp);
2367c478bd9Sstevel@tonic-gate void		cache_rlock();
2377c478bd9Sstevel@tonic-gate void		cache_unlock();
2387c478bd9Sstevel@tonic-gate void		cache_update(dm_event_type_t ev_type, char *devname);
2397c478bd9Sstevel@tonic-gate void		cache_wlock();
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate /* findevs.c */
2427c478bd9Sstevel@tonic-gate void		findevs(struct search_args *args);
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /* events.c */
2457c478bd9Sstevel@tonic-gate int		events_start_event_watcher();
2467c478bd9Sstevel@tonic-gate void		events_new_event(char *name, int dtype, char *etype);
2477c478bd9Sstevel@tonic-gate void		events_new_slice_event(char *dev, char *type);
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /* entry.c */
2507c478bd9Sstevel@tonic-gate void		libdiskmgt_add_str(nvlist_t *attrs, char *name, char *val,
2517c478bd9Sstevel@tonic-gate 		    int *errp);
2527c478bd9Sstevel@tonic-gate descriptor_t	**libdiskmgt_empty_desc_array(int *errp);
2537c478bd9Sstevel@tonic-gate void		libdiskmgt_init_debug();
2547c478bd9Sstevel@tonic-gate int		libdiskmgt_str_eq(char *nm1, char *nm2);
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate /* in-use detectors */
2577c478bd9Sstevel@tonic-gate int		inuse_mnt(char *slice, nvlist_t *attrs, int *errp);
2587c478bd9Sstevel@tonic-gate int		inuse_svm(char *slice, nvlist_t *attrs, int *errp);
2597c478bd9Sstevel@tonic-gate int		inuse_lu(char *slice, nvlist_t *attrs, int *errp);
26046a2abf2Seschrock int		inuse_active_zpool(char *slice, nvlist_t *attrs, int *errp);
26146a2abf2Seschrock int		inuse_exported_zpool(char *slice, nvlist_t *attrs, int *errp);
2627c478bd9Sstevel@tonic-gate int		inuse_dump(char *slice, nvlist_t *attrs, int *errp);
2637c478bd9Sstevel@tonic-gate int		inuse_vxvm(char *slice, nvlist_t *attrs, int *errp);
2647c478bd9Sstevel@tonic-gate int		inuse_fs(char *slice, nvlist_t *attrs, int *errp);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate #endif
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate #endif /* _DISKS_PRIVATE_H */
271