10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2912Sartem * Common Development and Distribution License (the "License"). 6*2912Sartem * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 221352Seschrock * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _DISKS_PRIVATE_H 270Sstevel@tonic-gate #define _DISKS_PRIVATE_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <libdevinfo.h> 360Sstevel@tonic-gate #include <sys/dkio.h> 370Sstevel@tonic-gate #include <devid.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #define DM_DEBUG "DM_LIBDISKMGT_DEBUG" 400Sstevel@tonic-gate extern int dm_debug; 410Sstevel@tonic-gate 420Sstevel@tonic-gate #define NVATTRS NV_UNIQUE_NAME | NV_UNIQUE_NAME_TYPE 430Sstevel@tonic-gate #define NVATTRS_STAT 0x0 440Sstevel@tonic-gate 450Sstevel@tonic-gate typedef struct slice_info { 460Sstevel@tonic-gate char *devpath; 470Sstevel@tonic-gate int slice_num; 480Sstevel@tonic-gate struct slice_info *next; 490Sstevel@tonic-gate } slice_t; 500Sstevel@tonic-gate 510Sstevel@tonic-gate typedef struct alias_info { 520Sstevel@tonic-gate char *kstat_name; 530Sstevel@tonic-gate char *alias; 540Sstevel@tonic-gate slice_t *devpaths; 550Sstevel@tonic-gate slice_t *orig_paths; 560Sstevel@tonic-gate char *wwn; 570Sstevel@tonic-gate int cluster; 580Sstevel@tonic-gate int lun; 590Sstevel@tonic-gate int target; 600Sstevel@tonic-gate struct alias_info *next; 610Sstevel@tonic-gate } alias_t; 620Sstevel@tonic-gate 630Sstevel@tonic-gate typedef struct path { 640Sstevel@tonic-gate char *name; 650Sstevel@tonic-gate char *ctype; 660Sstevel@tonic-gate int *states; 670Sstevel@tonic-gate char **wwns; 680Sstevel@tonic-gate struct disk **disks; 690Sstevel@tonic-gate struct controller_info *controller; 700Sstevel@tonic-gate struct path *next; 710Sstevel@tonic-gate } path_t; 720Sstevel@tonic-gate 730Sstevel@tonic-gate typedef struct bus_info { 740Sstevel@tonic-gate char *name; 750Sstevel@tonic-gate char *kstat_name; 760Sstevel@tonic-gate char *btype; 770Sstevel@tonic-gate char *pname; 780Sstevel@tonic-gate int freq; 790Sstevel@tonic-gate struct controller_info **controllers; 800Sstevel@tonic-gate struct bus_info *next; 810Sstevel@tonic-gate } bus_t; 820Sstevel@tonic-gate 830Sstevel@tonic-gate typedef struct controller_info { 840Sstevel@tonic-gate char *name; 850Sstevel@tonic-gate char *kstat_name; 860Sstevel@tonic-gate char *ctype; 870Sstevel@tonic-gate int freq; 880Sstevel@tonic-gate struct disk **disks; 890Sstevel@tonic-gate struct path **paths; 900Sstevel@tonic-gate struct bus_info *bus; 910Sstevel@tonic-gate struct controller_info *next; 920Sstevel@tonic-gate int multiplex; 930Sstevel@tonic-gate int scsi_options; 940Sstevel@tonic-gate } controller_t; 950Sstevel@tonic-gate 960Sstevel@tonic-gate typedef struct disk { 970Sstevel@tonic-gate char *device_id; /* string encoded device id */ 980Sstevel@tonic-gate ddi_devid_t devid; /* decoded device id */ 990Sstevel@tonic-gate char *kernel_name; /* handles drives w/ no devlinks */ 1000Sstevel@tonic-gate char *product_id; 1010Sstevel@tonic-gate char *vendor_id; 1020Sstevel@tonic-gate controller_t **controllers; 1030Sstevel@tonic-gate path_t **paths; 1040Sstevel@tonic-gate alias_t *aliases; 1050Sstevel@tonic-gate struct disk *next; 1060Sstevel@tonic-gate int drv_type; 1070Sstevel@tonic-gate int removable; 1080Sstevel@tonic-gate int sync_speed; 1090Sstevel@tonic-gate int rpm; 1100Sstevel@tonic-gate int wide; 1110Sstevel@tonic-gate int cd_rom; 1120Sstevel@tonic-gate } disk_t; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate typedef struct descriptor { 1150Sstevel@tonic-gate union { 1160Sstevel@tonic-gate void *generic; 1170Sstevel@tonic-gate disk_t *disk; 1180Sstevel@tonic-gate controller_t *controller; 1190Sstevel@tonic-gate bus_t *bus; 1200Sstevel@tonic-gate path_t *path; 1210Sstevel@tonic-gate } p; 1220Sstevel@tonic-gate char *name; 1230Sstevel@tonic-gate char *secondary_name; 1240Sstevel@tonic-gate struct descriptor *next; 1250Sstevel@tonic-gate struct descriptor *prev; 1260Sstevel@tonic-gate dm_desc_type_t type; 1270Sstevel@tonic-gate int refcnt; 1280Sstevel@tonic-gate } descriptor_t; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate struct search_args { 1310Sstevel@tonic-gate disk_t *disk_listp; 1320Sstevel@tonic-gate controller_t *controller_listp; 1330Sstevel@tonic-gate bus_t *bus_listp; 1340Sstevel@tonic-gate di_devlink_handle_t handle; 1350Sstevel@tonic-gate di_prom_handle_t ph; 1360Sstevel@tonic-gate di_node_t node; 1370Sstevel@tonic-gate di_minor_t minor; 1380Sstevel@tonic-gate int dev_walk_status; 1390Sstevel@tonic-gate }; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate typedef enum { 1420Sstevel@tonic-gate DM_EV_DISK_ADD = 0, 1430Sstevel@tonic-gate DM_EV_DISK_DELETE 1440Sstevel@tonic-gate } dm_event_type_t; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* private internal functions */ 1480Sstevel@tonic-gate descriptor_t **alias_get_descriptors(int filter[], int *errp); 1490Sstevel@tonic-gate descriptor_t **alias_get_assoc_descriptors(descriptor_t *desc, 1500Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1510Sstevel@tonic-gate descriptor_t *alias_get_descriptor_by_name(char *name, int *errp); 1520Sstevel@tonic-gate char *alias_get_name(descriptor_t *desc); 1530Sstevel@tonic-gate nvlist_t *alias_get_attributes(descriptor_t *desc, int *errp); 1540Sstevel@tonic-gate nvlist_t *alias_get_stats(descriptor_t *desc, int stat_type, int *errp); 1550Sstevel@tonic-gate int alias_make_descriptors(); 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate descriptor_t **bus_get_descriptors(int filter[], int *errp); 1580Sstevel@tonic-gate descriptor_t **bus_get_assoc_descriptors(descriptor_t *desc, 1590Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1600Sstevel@tonic-gate descriptor_t *bus_get_descriptor_by_name(char *name, int *errp); 1610Sstevel@tonic-gate char *bus_get_name(descriptor_t *desc); 1620Sstevel@tonic-gate nvlist_t *bus_get_attributes(descriptor_t *desc, int *errp); 1630Sstevel@tonic-gate nvlist_t *bus_get_stats(descriptor_t *desc, int stat_type, 1640Sstevel@tonic-gate int *errp); 1650Sstevel@tonic-gate int bus_make_descriptors(); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate descriptor_t **controller_get_descriptors(int filter[], int *errp); 1680Sstevel@tonic-gate descriptor_t **controller_get_assoc_descriptors(descriptor_t *desc, 1690Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1700Sstevel@tonic-gate descriptor_t *controller_get_descriptor_by_name(char *name, int *errp); 1710Sstevel@tonic-gate char *controller_get_name(descriptor_t *desc); 1720Sstevel@tonic-gate nvlist_t *controller_get_attributes(descriptor_t *desc, int *errp); 1730Sstevel@tonic-gate nvlist_t *controller_get_stats(descriptor_t *desc, int stat_type, 1740Sstevel@tonic-gate int *errp); 1750Sstevel@tonic-gate int controller_make_descriptors(); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate descriptor_t **drive_get_descriptors(int filter[], int *errp); 1780Sstevel@tonic-gate descriptor_t **drive_get_assoc_descriptors(descriptor_t *desc, 1790Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1800Sstevel@tonic-gate descriptor_t **drive_get_assocs(descriptor_t *desc, int *errp); 1810Sstevel@tonic-gate descriptor_t *drive_get_descriptor_by_name(char *name, int *errp); 1820Sstevel@tonic-gate char *drive_get_name(descriptor_t *desc); 1830Sstevel@tonic-gate nvlist_t *drive_get_attributes(descriptor_t *desc, int *errp); 1840Sstevel@tonic-gate nvlist_t *drive_get_stats(descriptor_t *desc, int stat_type, int *errp); 1850Sstevel@tonic-gate int drive_make_descriptors(); 1860Sstevel@tonic-gate int drive_open_disk(disk_t *diskp, char *opath, int len); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate descriptor_t **media_get_descriptors(int filter[], int *errp); 1890Sstevel@tonic-gate descriptor_t **media_get_assoc_descriptors(descriptor_t *desc, 1900Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1910Sstevel@tonic-gate descriptor_t **media_get_assocs(descriptor_t *desc, int *errp); 1920Sstevel@tonic-gate descriptor_t *media_get_descriptor_by_name(char *name, int *errp); 1930Sstevel@tonic-gate char *media_get_name(descriptor_t *desc); 1940Sstevel@tonic-gate nvlist_t *media_get_attributes(descriptor_t *desc, int *errp); 1950Sstevel@tonic-gate nvlist_t *media_get_stats(descriptor_t *desc, int stat_type, int *errp); 1960Sstevel@tonic-gate int media_make_descriptors(); 1970Sstevel@tonic-gate int media_read_info(int fd, struct dk_minfo *minfo); 1980Sstevel@tonic-gate int media_read_name(disk_t *dp, char *mname, int size); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate descriptor_t **path_get_descriptors(int filter[], int *errp); 2010Sstevel@tonic-gate descriptor_t **path_get_assoc_descriptors(descriptor_t *desc, 2020Sstevel@tonic-gate dm_desc_type_t type, int *errp); 2030Sstevel@tonic-gate descriptor_t *path_get_descriptor_by_name(char *name, int *errp); 2040Sstevel@tonic-gate char *path_get_name(descriptor_t *desc); 2050Sstevel@tonic-gate nvlist_t *path_get_attributes(descriptor_t *desc, int *errp); 2060Sstevel@tonic-gate nvlist_t *path_get_stats(descriptor_t *desc, int stat_type, int *errp); 2070Sstevel@tonic-gate int path_make_descriptors(); 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate descriptor_t **slice_get_descriptors(int filter[], int *errp); 2100Sstevel@tonic-gate descriptor_t **slice_get_assoc_descriptors(descriptor_t *desc, 2110Sstevel@tonic-gate dm_desc_type_t type, int *errp); 2120Sstevel@tonic-gate descriptor_t **slice_get_assocs(descriptor_t *desc, int *errp); 2130Sstevel@tonic-gate descriptor_t *slice_get_descriptor_by_name(char *name, int *errp); 2140Sstevel@tonic-gate char *slice_get_name(descriptor_t *desc); 2150Sstevel@tonic-gate nvlist_t *slice_get_attributes(descriptor_t *desc, int *errp); 2160Sstevel@tonic-gate nvlist_t *slice_get_stats(descriptor_t *desc, int stat_type, int *errp); 2170Sstevel@tonic-gate int slice_make_descriptors(); 2180Sstevel@tonic-gate void slice_rdsk2dsk(char *rdsk, char *dsk, int size); 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /* cache.c */ 2210Sstevel@tonic-gate void cache_free_alias(alias_t *aliasp); 2220Sstevel@tonic-gate void cache_free_bus(bus_t *bp); 2230Sstevel@tonic-gate void cache_free_controller(controller_t *cp); 2240Sstevel@tonic-gate void cache_free_descriptor(descriptor_t *desc); 2250Sstevel@tonic-gate void cache_free_descriptors(descriptor_t **desc_list); 2260Sstevel@tonic-gate void cache_free_disk(disk_t *dp); 2270Sstevel@tonic-gate void cache_free_path(path_t *pp); 2280Sstevel@tonic-gate bus_t *cache_get_buslist(); 2290Sstevel@tonic-gate controller_t *cache_get_controllerlist(); 2300Sstevel@tonic-gate descriptor_t *cache_get_desc(int type, void *gp, char *name, 2310Sstevel@tonic-gate char *secondary_name, int *errp); 2320Sstevel@tonic-gate descriptor_t **cache_get_descriptors(int type, int *errp); 2330Sstevel@tonic-gate disk_t *cache_get_disklist(); 2340Sstevel@tonic-gate int cache_is_valid_desc(descriptor_t *d); 2350Sstevel@tonic-gate void cache_load_desc(int type, void *gp, char *name, 2360Sstevel@tonic-gate char *secondary_name, int *errp); 2370Sstevel@tonic-gate void cache_rlock(); 2380Sstevel@tonic-gate void cache_unlock(); 2390Sstevel@tonic-gate void cache_update(dm_event_type_t ev_type, char *devname); 2400Sstevel@tonic-gate void cache_wlock(); 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate /* findevs.c */ 2430Sstevel@tonic-gate void findevs(struct search_args *args); 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate /* events.c */ 2460Sstevel@tonic-gate int events_start_event_watcher(); 2470Sstevel@tonic-gate void events_new_event(char *name, int dtype, char *etype); 2480Sstevel@tonic-gate void events_new_slice_event(char *dev, char *type); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* entry.c */ 2510Sstevel@tonic-gate void libdiskmgt_add_str(nvlist_t *attrs, char *name, char *val, 2520Sstevel@tonic-gate int *errp); 2530Sstevel@tonic-gate descriptor_t **libdiskmgt_empty_desc_array(int *errp); 2540Sstevel@tonic-gate void libdiskmgt_init_debug(); 2550Sstevel@tonic-gate int libdiskmgt_str_eq(char *nm1, char *nm2); 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate /* in-use detectors */ 2580Sstevel@tonic-gate int inuse_mnt(char *slice, nvlist_t *attrs, int *errp); 2590Sstevel@tonic-gate int inuse_svm(char *slice, nvlist_t *attrs, int *errp); 2600Sstevel@tonic-gate int inuse_lu(char *slice, nvlist_t *attrs, int *errp); 2611352Seschrock int inuse_active_zpool(char *slice, nvlist_t *attrs, int *errp); 2621352Seschrock int inuse_exported_zpool(char *slice, nvlist_t *attrs, int *errp); 2630Sstevel@tonic-gate int inuse_dump(char *slice, nvlist_t *attrs, int *errp); 2640Sstevel@tonic-gate int inuse_vxvm(char *slice, nvlist_t *attrs, int *errp); 2650Sstevel@tonic-gate int inuse_fs(char *slice, nvlist_t *attrs, int *errp); 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate #ifdef __cplusplus 2680Sstevel@tonic-gate } 2690Sstevel@tonic-gate #endif 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate #endif /* _DISKS_PRIVATE_H */ 272