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 */ 215f10ef69SYuri Pankov 227c478bd9Sstevel@tonic-gate /* 2346a2abf2Seschrock * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*c470f575SYuri Pankov */ 26*c470f575SYuri Pankov 27*c470f575SYuri Pankov /* 28*c470f575SYuri Pankov * Copyright 2017 Nexenta Systems, Inc. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifndef _DISKS_PRIVATE_H 327c478bd9Sstevel@tonic-gate #define _DISKS_PRIVATE_H 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 397c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 407c478bd9Sstevel@tonic-gate #include <devid.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #define DM_DEBUG "DM_LIBDISKMGT_DEBUG" 437c478bd9Sstevel@tonic-gate extern int dm_debug; 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #define NVATTRS NV_UNIQUE_NAME | NV_UNIQUE_NAME_TYPE 467c478bd9Sstevel@tonic-gate #define NVATTRS_STAT 0x0 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate typedef struct slice_info { 497c478bd9Sstevel@tonic-gate char *devpath; 507c478bd9Sstevel@tonic-gate int slice_num; 517c478bd9Sstevel@tonic-gate struct slice_info *next; 527c478bd9Sstevel@tonic-gate } slice_t; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate typedef struct alias_info { 557c478bd9Sstevel@tonic-gate char *kstat_name; 567c478bd9Sstevel@tonic-gate char *alias; 577c478bd9Sstevel@tonic-gate slice_t *devpaths; 587c478bd9Sstevel@tonic-gate slice_t *orig_paths; 597c478bd9Sstevel@tonic-gate char *wwn; 607c478bd9Sstevel@tonic-gate int lun; 617c478bd9Sstevel@tonic-gate int target; 627c478bd9Sstevel@tonic-gate struct alias_info *next; 637c478bd9Sstevel@tonic-gate } alias_t; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate typedef struct path { 667c478bd9Sstevel@tonic-gate char *name; 677c478bd9Sstevel@tonic-gate char *ctype; 687c478bd9Sstevel@tonic-gate int *states; 697c478bd9Sstevel@tonic-gate char **wwns; 707c478bd9Sstevel@tonic-gate struct disk **disks; 717c478bd9Sstevel@tonic-gate struct controller_info *controller; 727c478bd9Sstevel@tonic-gate struct path *next; 737c478bd9Sstevel@tonic-gate } path_t; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate typedef struct bus_info { 767c478bd9Sstevel@tonic-gate char *name; 777c478bd9Sstevel@tonic-gate char *kstat_name; 787c478bd9Sstevel@tonic-gate char *btype; 797c478bd9Sstevel@tonic-gate char *pname; 807c478bd9Sstevel@tonic-gate int freq; 817c478bd9Sstevel@tonic-gate struct controller_info **controllers; 827c478bd9Sstevel@tonic-gate struct bus_info *next; 837c478bd9Sstevel@tonic-gate } bus_t; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate typedef struct controller_info { 867c478bd9Sstevel@tonic-gate char *name; 877c478bd9Sstevel@tonic-gate char *kstat_name; 887c478bd9Sstevel@tonic-gate char *ctype; 897c478bd9Sstevel@tonic-gate int freq; 907c478bd9Sstevel@tonic-gate struct disk **disks; 917c478bd9Sstevel@tonic-gate struct path **paths; 927c478bd9Sstevel@tonic-gate struct bus_info *bus; 937c478bd9Sstevel@tonic-gate struct controller_info *next; 947c478bd9Sstevel@tonic-gate int multiplex; 957c478bd9Sstevel@tonic-gate int scsi_options; 967c478bd9Sstevel@tonic-gate } controller_t; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate typedef struct disk { 997c478bd9Sstevel@tonic-gate char *device_id; /* string encoded device id */ 1007c478bd9Sstevel@tonic-gate ddi_devid_t devid; /* decoded device id */ 1017c478bd9Sstevel@tonic-gate char *kernel_name; /* handles drives w/ no devlinks */ 1027c478bd9Sstevel@tonic-gate char *product_id; 1037c478bd9Sstevel@tonic-gate char *vendor_id; 1047c478bd9Sstevel@tonic-gate controller_t **controllers; 1057c478bd9Sstevel@tonic-gate path_t **paths; 1067c478bd9Sstevel@tonic-gate alias_t *aliases; 1077c478bd9Sstevel@tonic-gate struct disk *next; 1087c478bd9Sstevel@tonic-gate int drv_type; 1097c478bd9Sstevel@tonic-gate int removable; 1107c478bd9Sstevel@tonic-gate int sync_speed; 1117c478bd9Sstevel@tonic-gate int rpm; 1127c478bd9Sstevel@tonic-gate int wide; 1137c478bd9Sstevel@tonic-gate int cd_rom; 11459d8f100SGarrett D'Amore int solid_state; 1157c478bd9Sstevel@tonic-gate } disk_t; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate typedef struct descriptor { 1187c478bd9Sstevel@tonic-gate union { 1197c478bd9Sstevel@tonic-gate void *generic; 1207c478bd9Sstevel@tonic-gate disk_t *disk; 1217c478bd9Sstevel@tonic-gate controller_t *controller; 1227c478bd9Sstevel@tonic-gate bus_t *bus; 1237c478bd9Sstevel@tonic-gate path_t *path; 1247c478bd9Sstevel@tonic-gate } p; 1257c478bd9Sstevel@tonic-gate char *name; 1267c478bd9Sstevel@tonic-gate char *secondary_name; 1277c478bd9Sstevel@tonic-gate struct descriptor *next; 1287c478bd9Sstevel@tonic-gate struct descriptor *prev; 1297c478bd9Sstevel@tonic-gate dm_desc_type_t type; 1307c478bd9Sstevel@tonic-gate int refcnt; 1317c478bd9Sstevel@tonic-gate } descriptor_t; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate struct search_args { 1347c478bd9Sstevel@tonic-gate disk_t *disk_listp; 1357c478bd9Sstevel@tonic-gate controller_t *controller_listp; 1367c478bd9Sstevel@tonic-gate bus_t *bus_listp; 1377c478bd9Sstevel@tonic-gate di_devlink_handle_t handle; 1387c478bd9Sstevel@tonic-gate di_prom_handle_t ph; 1397c478bd9Sstevel@tonic-gate di_node_t node; 1407c478bd9Sstevel@tonic-gate di_minor_t minor; 1417c478bd9Sstevel@tonic-gate int dev_walk_status; 1427c478bd9Sstevel@tonic-gate }; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate typedef enum { 1457c478bd9Sstevel@tonic-gate DM_EV_DISK_ADD = 0, 1467c478bd9Sstevel@tonic-gate DM_EV_DISK_DELETE 1477c478bd9Sstevel@tonic-gate } dm_event_type_t; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* private internal functions */ 1517c478bd9Sstevel@tonic-gate descriptor_t **alias_get_descriptors(int filter[], int *errp); 1527c478bd9Sstevel@tonic-gate descriptor_t **alias_get_assoc_descriptors(descriptor_t *desc, 1537c478bd9Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1547c478bd9Sstevel@tonic-gate descriptor_t *alias_get_descriptor_by_name(char *name, int *errp); 1557c478bd9Sstevel@tonic-gate char *alias_get_name(descriptor_t *desc); 1567c478bd9Sstevel@tonic-gate nvlist_t *alias_get_attributes(descriptor_t *desc, int *errp); 1577c478bd9Sstevel@tonic-gate nvlist_t *alias_get_stats(descriptor_t *desc, int stat_type, int *errp); 1587c478bd9Sstevel@tonic-gate int alias_make_descriptors(); 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate descriptor_t **bus_get_descriptors(int filter[], int *errp); 1617c478bd9Sstevel@tonic-gate descriptor_t **bus_get_assoc_descriptors(descriptor_t *desc, 1627c478bd9Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1637c478bd9Sstevel@tonic-gate descriptor_t *bus_get_descriptor_by_name(char *name, int *errp); 1647c478bd9Sstevel@tonic-gate char *bus_get_name(descriptor_t *desc); 1657c478bd9Sstevel@tonic-gate nvlist_t *bus_get_attributes(descriptor_t *desc, int *errp); 1667c478bd9Sstevel@tonic-gate nvlist_t *bus_get_stats(descriptor_t *desc, int stat_type, 1677c478bd9Sstevel@tonic-gate int *errp); 1687c478bd9Sstevel@tonic-gate int bus_make_descriptors(); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate descriptor_t **controller_get_descriptors(int filter[], int *errp); 1717c478bd9Sstevel@tonic-gate descriptor_t **controller_get_assoc_descriptors(descriptor_t *desc, 1727c478bd9Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1737c478bd9Sstevel@tonic-gate descriptor_t *controller_get_descriptor_by_name(char *name, int *errp); 1747c478bd9Sstevel@tonic-gate char *controller_get_name(descriptor_t *desc); 1757c478bd9Sstevel@tonic-gate nvlist_t *controller_get_attributes(descriptor_t *desc, int *errp); 1767c478bd9Sstevel@tonic-gate nvlist_t *controller_get_stats(descriptor_t *desc, int stat_type, 1777c478bd9Sstevel@tonic-gate int *errp); 1787c478bd9Sstevel@tonic-gate int controller_make_descriptors(); 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate descriptor_t **drive_get_descriptors(int filter[], int *errp); 1817c478bd9Sstevel@tonic-gate descriptor_t **drive_get_assoc_descriptors(descriptor_t *desc, 1827c478bd9Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1837c478bd9Sstevel@tonic-gate descriptor_t **drive_get_assocs(descriptor_t *desc, int *errp); 1847c478bd9Sstevel@tonic-gate descriptor_t *drive_get_descriptor_by_name(char *name, int *errp); 1857c478bd9Sstevel@tonic-gate char *drive_get_name(descriptor_t *desc); 1867c478bd9Sstevel@tonic-gate nvlist_t *drive_get_attributes(descriptor_t *desc, int *errp); 1877c478bd9Sstevel@tonic-gate nvlist_t *drive_get_stats(descriptor_t *desc, int stat_type, int *errp); 1887c478bd9Sstevel@tonic-gate int drive_make_descriptors(); 1897c478bd9Sstevel@tonic-gate int drive_open_disk(disk_t *diskp, char *opath, int len); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate descriptor_t **media_get_descriptors(int filter[], int *errp); 1927c478bd9Sstevel@tonic-gate descriptor_t **media_get_assoc_descriptors(descriptor_t *desc, 1937c478bd9Sstevel@tonic-gate dm_desc_type_t type, int *errp); 1947c478bd9Sstevel@tonic-gate descriptor_t **media_get_assocs(descriptor_t *desc, int *errp); 1957c478bd9Sstevel@tonic-gate descriptor_t *media_get_descriptor_by_name(char *name, int *errp); 1967c478bd9Sstevel@tonic-gate char *media_get_name(descriptor_t *desc); 1977c478bd9Sstevel@tonic-gate nvlist_t *media_get_attributes(descriptor_t *desc, int *errp); 1987c478bd9Sstevel@tonic-gate nvlist_t *media_get_stats(descriptor_t *desc, int stat_type, int *errp); 1997c478bd9Sstevel@tonic-gate int media_make_descriptors(); 2007c478bd9Sstevel@tonic-gate int media_read_info(int fd, struct dk_minfo *minfo); 2017c478bd9Sstevel@tonic-gate int media_read_name(disk_t *dp, char *mname, int size); 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate descriptor_t **path_get_descriptors(int filter[], int *errp); 2047c478bd9Sstevel@tonic-gate descriptor_t **path_get_assoc_descriptors(descriptor_t *desc, 2057c478bd9Sstevel@tonic-gate dm_desc_type_t type, int *errp); 2067c478bd9Sstevel@tonic-gate descriptor_t *path_get_descriptor_by_name(char *name, int *errp); 2077c478bd9Sstevel@tonic-gate char *path_get_name(descriptor_t *desc); 2087c478bd9Sstevel@tonic-gate nvlist_t *path_get_attributes(descriptor_t *desc, int *errp); 2097c478bd9Sstevel@tonic-gate nvlist_t *path_get_stats(descriptor_t *desc, int stat_type, int *errp); 2107c478bd9Sstevel@tonic-gate int path_make_descriptors(); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate descriptor_t **slice_get_descriptors(int filter[], int *errp); 2137c478bd9Sstevel@tonic-gate descriptor_t **slice_get_assoc_descriptors(descriptor_t *desc, 2147c478bd9Sstevel@tonic-gate dm_desc_type_t type, int *errp); 2157c478bd9Sstevel@tonic-gate descriptor_t **slice_get_assocs(descriptor_t *desc, int *errp); 2167c478bd9Sstevel@tonic-gate descriptor_t *slice_get_descriptor_by_name(char *name, int *errp); 2177c478bd9Sstevel@tonic-gate char *slice_get_name(descriptor_t *desc); 2187c478bd9Sstevel@tonic-gate nvlist_t *slice_get_attributes(descriptor_t *desc, int *errp); 2197c478bd9Sstevel@tonic-gate nvlist_t *slice_get_stats(descriptor_t *desc, int stat_type, int *errp); 2207c478bd9Sstevel@tonic-gate int slice_make_descriptors(); 2217c478bd9Sstevel@tonic-gate void slice_rdsk2dsk(char *rdsk, char *dsk, int size); 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate /* cache.c */ 2247c478bd9Sstevel@tonic-gate void cache_free_alias(alias_t *aliasp); 2257c478bd9Sstevel@tonic-gate void cache_free_bus(bus_t *bp); 2267c478bd9Sstevel@tonic-gate void cache_free_controller(controller_t *cp); 2277c478bd9Sstevel@tonic-gate void cache_free_descriptor(descriptor_t *desc); 2287c478bd9Sstevel@tonic-gate void cache_free_descriptors(descriptor_t **desc_list); 2297c478bd9Sstevel@tonic-gate void cache_free_disk(disk_t *dp); 2307c478bd9Sstevel@tonic-gate void cache_free_path(path_t *pp); 2317c478bd9Sstevel@tonic-gate bus_t *cache_get_buslist(); 2327c478bd9Sstevel@tonic-gate controller_t *cache_get_controllerlist(); 2337c478bd9Sstevel@tonic-gate descriptor_t *cache_get_desc(int type, void *gp, char *name, 2347c478bd9Sstevel@tonic-gate char *secondary_name, int *errp); 2357c478bd9Sstevel@tonic-gate descriptor_t **cache_get_descriptors(int type, int *errp); 2367c478bd9Sstevel@tonic-gate disk_t *cache_get_disklist(); 2377c478bd9Sstevel@tonic-gate int cache_is_valid_desc(descriptor_t *d); 2387c478bd9Sstevel@tonic-gate void cache_load_desc(int type, void *gp, char *name, 2397c478bd9Sstevel@tonic-gate char *secondary_name, int *errp); 2407c478bd9Sstevel@tonic-gate void cache_rlock(); 2417c478bd9Sstevel@tonic-gate void cache_unlock(); 2427c478bd9Sstevel@tonic-gate void cache_update(dm_event_type_t ev_type, char *devname); 2437c478bd9Sstevel@tonic-gate void cache_wlock(); 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate /* findevs.c */ 2467c478bd9Sstevel@tonic-gate void findevs(struct search_args *args); 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* events.c */ 2497c478bd9Sstevel@tonic-gate int events_start_event_watcher(); 2507c478bd9Sstevel@tonic-gate void events_new_event(char *name, int dtype, char *etype); 2517c478bd9Sstevel@tonic-gate void events_new_slice_event(char *dev, char *type); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate /* entry.c */ 2547c478bd9Sstevel@tonic-gate void libdiskmgt_add_str(nvlist_t *attrs, char *name, char *val, 2557c478bd9Sstevel@tonic-gate int *errp); 2567c478bd9Sstevel@tonic-gate descriptor_t **libdiskmgt_empty_desc_array(int *errp); 2577c478bd9Sstevel@tonic-gate void libdiskmgt_init_debug(); 2587c478bd9Sstevel@tonic-gate int libdiskmgt_str_eq(char *nm1, char *nm2); 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* in-use detectors */ 2617c478bd9Sstevel@tonic-gate int inuse_mnt(char *slice, nvlist_t *attrs, int *errp); 2627c478bd9Sstevel@tonic-gate int inuse_lu(char *slice, nvlist_t *attrs, int *errp); 26346a2abf2Seschrock int inuse_active_zpool(char *slice, nvlist_t *attrs, int *errp); 26446a2abf2Seschrock int inuse_exported_zpool(char *slice, nvlist_t *attrs, int *errp); 2657c478bd9Sstevel@tonic-gate int inuse_dump(char *slice, nvlist_t *attrs, int *errp); 2667c478bd9Sstevel@tonic-gate int inuse_vxvm(char *slice, nvlist_t *attrs, int *errp); 2677c478bd9Sstevel@tonic-gate int inuse_fs(char *slice, nvlist_t *attrs, int *errp); 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate #endif 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate #endif /* _DISKS_PRIVATE_H */ 274