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
599653d4eSeschrock  * Common Development and Distribution License (the "License").
699653d4eSeschrock  * 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 /*
232174cb7bSVirginia Wray  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25c470f575SYuri Pankov  */
26c470f575SYuri Pankov 
27c470f575SYuri Pankov /*
289bb41d3cSBill Pijewski  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
29c470f575SYuri Pankov  * Copyright 2017 Nexenta Systems, Inc.
307c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate #ifndef _LIBDISKMGT_H
337c478bd9Sstevel@tonic-gate #define	_LIBDISKMGT_H
357c478bd9Sstevel@tonic-gate #ifdef __cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate #include <libnvpair.h>
40181c2f42Smmusante #include <sys/swap.h>
439bb41d3cSBill Pijewski /*
449bb41d3cSBill Pijewski  * Disk Management Library
459bb41d3cSBill Pijewski  *
469bb41d3cSBill Pijewski  * This library provides a common way to gather information about a system's
479bb41d3cSBill Pijewski  * disks, controllers, and related components.
489bb41d3cSBill Pijewski  *
499bb41d3cSBill Pijewski  *
509bb41d3cSBill Pijewski  * THREADS
519bb41d3cSBill Pijewski  * -------
529bb41d3cSBill Pijewski  *
539bb41d3cSBill Pijewski  * In general all of the functions are thread safe, however there are some
549bb41d3cSBill Pijewski  * specific considerations for getting events.  The dm_get_event function may
559bb41d3cSBill Pijewski  * block the calling thread if no event is currently available.  If another
569bb41d3cSBill Pijewski  * thread calls dm_get_event while a thread is already blocked in this function,
579bb41d3cSBill Pijewski  * the second thread will also block.  When an event arrives and multiple
589bb41d3cSBill Pijewski  * threads are waiting for events, it is undefined which thread will be
599bb41d3cSBill Pijewski  * unblocked and receive the event.  If a callback is used for handling events,
609bb41d3cSBill Pijewski  * this is equivalent to the dm_get_event function, so mixing callbacks and
619bb41d3cSBill Pijewski  * dm_get_event is also nondeterministic.
629bb41d3cSBill Pijewski  *
639bb41d3cSBill Pijewski  *
649bb41d3cSBill Pijewski  * ERRORS
659bb41d3cSBill Pijewski  * ------
669bb41d3cSBill Pijewski  *
679bb41d3cSBill Pijewski  * In general all of the functions take an errno pointer.  This is an integer
689bb41d3cSBill Pijewski  * that will contain 0 if the function succeeded or contains an errno (see
699bb41d3cSBill Pijewski  * errno.h) if there was an error.  If the function returns some data, that
709bb41d3cSBill Pijewski  * return data will generally be null if an error occured (see the API comment
719bb41d3cSBill Pijewski  * for the specific function for details).  Many of the functions take a
729bb41d3cSBill Pijewski  * descriptor and provide more information for that descriptor.  These functions
739bb41d3cSBill Pijewski  * may return an error if the object was removed between the call which obtained
749bb41d3cSBill Pijewski  * the descriptor and the call to get more information about the object (errno
759bb41d3cSBill Pijewski  * will be ENODEV).  Only a few of the possible errno values will be returned;
769bb41d3cSBill Pijewski  * typically:
779bb41d3cSBill Pijewski  *     EPERM       not super-user
789bb41d3cSBill Pijewski  *     ENOMEM      not enough memory
799bb41d3cSBill Pijewski  *     ENODEV      no such device
809bb41d3cSBill Pijewski  *     EINVAL      invalid argument
819bb41d3cSBill Pijewski  *     ENOENT      no event queue has been created
829bb41d3cSBill Pijewski  *
839bb41d3cSBill Pijewski  * Many of the functions require the application to be running as root in order
849bb41d3cSBill Pijewski  * to get complete information.  EPERM will be returned if the application is
859bb41d3cSBill Pijewski  * not running as root.  However, not all of the functions have this requirement
869bb41d3cSBill Pijewski  * (i.e. event handling).
879bb41d3cSBill Pijewski  *
889bb41d3cSBill Pijewski  * It is possible for the system to run out of memory while receiving events.
899bb41d3cSBill Pijewski  * Since event receipt is asyncronous from the dm_get_event call there may not
909bb41d3cSBill Pijewski  * be a thread waiting when the event occurs and ENOMEM is detected.  In this
919bb41d3cSBill Pijewski  * case the event will be lost.  The first call to dm_get_event following this
929bb41d3cSBill Pijewski  * condition will immediately return ENOMEM, even if events are queued.
939bb41d3cSBill Pijewski  * Subsequent calls can return events.  The dm_get_event call will clear the
949bb41d3cSBill Pijewski  * pending ENOMEM condition.  There is no way to know how many events were lost
959bb41d3cSBill Pijewski  * when this situation occurs.  If a thread is waiting when the event arrives
969bb41d3cSBill Pijewski  * and the ENOMEM condition occurs, the call will also return with ENOMEM.
979bb41d3cSBill Pijewski  * There is no way to determine if the system ran out of memory before the
989bb41d3cSBill Pijewski  * dm_get_event call or while the thread was blocked in the dm_get_event call
999bb41d3cSBill Pijewski  * since both conditions cause dm_get_event to return ENOMEM.
1009bb41d3cSBill Pijewski  *
1019bb41d3cSBill Pijewski  *
1029bb41d3cSBill Pijewski  * MEMORY MANAGEMENT
1039bb41d3cSBill Pijewski  * -----------------
1049bb41d3cSBill Pijewski  *
1059bb41d3cSBill Pijewski  * Most of the functions that return data are returning memory that has been
1069bb41d3cSBill Pijewski  * allocated and must be freed by the application when no longer needed.  The
1079bb41d3cSBill Pijewski  * application should call the proper free function to free the memory.  Most of
1089bb41d3cSBill Pijewski  * the functions return either a nvlist or an array of descriptors.  The normal
1099bb41d3cSBill Pijewski  * nvlist function (nvlist_free; see libnvpair(3LIB)) can be used to free the
1109bb41d3cSBill Pijewski  * simple nvlists.  Other functions are provided to free the more complex data
1119bb41d3cSBill Pijewski  * structures.
1129bb41d3cSBill Pijewski  *
1139bb41d3cSBill Pijewski  * The following list shows the functions that return allocated memory and the
1149bb41d3cSBill Pijewski  * corresponding function to free the memory:
1159bb41d3cSBill Pijewski  *     dm_get_descriptors            dm_free_descriptors
1169bb41d3cSBill Pijewski  *     dm_get_associated_descriptors dm_free_descriptors
1179bb41d3cSBill Pijewski  *     dm_get_descriptor_by_name     dm_free_descriptor
1189bb41d3cSBill Pijewski  *     dm_get_name                   dm_free_name
1199bb41d3cSBill Pijewski  *     dm_get_attributes             nvlist_free
1209bb41d3cSBill Pijewski  *     dm_get_stats	          nvlist_free
1219bb41d3cSBill Pijewski  *     dm_get_event                  nvlist_free
1229bb41d3cSBill Pijewski  *
1239bb41d3cSBill Pijewski  *
1249bb41d3cSBill Pijewski  * EVENTS
1259bb41d3cSBill Pijewski  * ------
1269bb41d3cSBill Pijewski  *
1279bb41d3cSBill Pijewski  * Event information is returned as a nvlist.  It may be possible to return more
1289bb41d3cSBill Pijewski  * information about events over time, especially information about what has
1299bb41d3cSBill Pijewski  * changed.  However, that may not always be the case, so by using an nvlist we
1309bb41d3cSBill Pijewski  * have a very generic event indication.  At a minimum the event will return the
1319bb41d3cSBill Pijewski  * name of the device, the type of device (see dm_desc_type_t) and the type of
1329bb41d3cSBill Pijewski  * event.  The event type is a string which can currently be; add, remove,
1339bb41d3cSBill Pijewski  * change.
1349bb41d3cSBill Pijewski  *
1359bb41d3cSBill Pijewski  * If a drive goes up or down this could be returned as event type "change".
1369bb41d3cSBill Pijewski  * The application could get the drive information to see that the "status"
1379bb41d3cSBill Pijewski  * attribute has changed value (ideally the event would include an attribute
1389bb41d3cSBill Pijewski  * with the name of the changed attribute as the value).  Although the API can
1399bb41d3cSBill Pijewski  * return events for all drive related changes, events will not necessarily be
1409bb41d3cSBill Pijewski  * delivered for all changes unless the system generates those events.
1419bb41d3cSBill Pijewski  *
1429bb41d3cSBill Pijewski  *
1439bb41d3cSBill Pijewski  * Controller/HBAs
1449bb41d3cSBill Pijewski  * ---------------
1459bb41d3cSBill Pijewski  *
1469bb41d3cSBill Pijewski  * In general the API means "the parent node of the drive in the device tree"
1479bb41d3cSBill Pijewski  * where the word "controller" is used.  This can actually be either the HBA or
1489bb41d3cSBill Pijewski  * the drive controller depending on the type of the drive.
1499bb41d3cSBill Pijewski  *
1509bb41d3cSBill Pijewski  * Drives can be connected to their controller(s) in three different ways:
1519bb41d3cSBill Pijewski  *     single controller
1529bb41d3cSBill Pijewski  *     multiple controllers
1539bb41d3cSBill Pijewski  *     multiple controllers with mpxio
1549bb41d3cSBill Pijewski  * These cases will lead to different information being available for the
1559bb41d3cSBill Pijewski  * configuration.  The two interesting cases are multi-path with and without
1569bb41d3cSBill Pijewski  * mpxio.  With mpxio the drive will have a unique name and a single controller
1579bb41d3cSBill Pijewski  * (scsi_vhci).  The physical controllers, the paths to the drive, can be
1589bb41d3cSBill Pijewski  * obtained by calling dm_get_associated_descriptors with a drive descriptor and
1599bb41d3cSBill Pijewski  * a type of DM_PATH.  This will only return these physical paths when MPXIO, or
1609bb41d3cSBill Pijewski  * possibly some future similar feature, is controlling the drive.
1619bb41d3cSBill Pijewski  *
1629bb41d3cSBill Pijewski  * Without mpxio the drive does not have a unique public name (in all cases the
1639bb41d3cSBill Pijewski  * alias(es) of the drive can be determined by calling
1649bb41d3cSBill Pijewski  * dm_get_associated_descriptors to get the DM_ALIAS descriptors.  There will be
1659bb41d3cSBill Pijewski  * more than one controller returned from dm_get_associated_descriptors when
1669bb41d3cSBill Pijewski  * called with a type of DM_CONTROLLER.  The controllers for each of the aliases
1679bb41d3cSBill Pijewski  * will be returned in the same order as the aliases descriptors.  For example,
1689bb41d3cSBill Pijewski  * a drive with two paths has the aliases c5t3d2 and c7t1d0.  There will be two
1699bb41d3cSBill Pijewski  * controllers returned; the first corresponds to c5 and the second corresponds
1709bb41d3cSBill Pijewski  * to c7.
1719bb41d3cSBill Pijewski  *
1729bb41d3cSBill Pijewski  * In the multi-path, non-mpxio case the drive has more than one alias.
1739bb41d3cSBill Pijewski  * Although most of the drive attributes are represented on the drive (see
1749bb41d3cSBill Pijewski  * dm_get_attributes) there can be some different attributes for the different
1759bb41d3cSBill Pijewski  * aliases for the drive.  Use dm_get_associated_descriptors to get the DM_ALIAS
1769bb41d3cSBill Pijewski  * descriptors which can then be used to obtain these attributes.  Use of this
1779bb41d3cSBill Pijewski  * algorithm is not restricted to the multi-path, non-mpxio case.  For example,
1789bb41d3cSBill Pijewski  * it can be used to get the target/lun for a SCSI drive with a single path.
1799bb41d3cSBill Pijewski  */
1809bb41d3cSBill Pijewski 
1813e1bd7a2Ssjelinek /*
1823e1bd7a2Ssjelinek  * Holds all the data regarding the device.
1833e1bd7a2Ssjelinek  * Private to libdiskmgt. Must use dm_xxx functions to set/get data.
1843e1bd7a2Ssjelinek  */
1857c478bd9Sstevel@tonic-gate typedef uint64_t  dm_descriptor_t;
1873e1bd7a2Ssjelinek typedef enum {
1883e1bd7a2Ssjelinek 	DM_WHO_MKFS = 0,
1893e1bd7a2Ssjelinek 	DM_WHO_ZPOOL,
19046a2abf2Seschrock 	DM_WHO_ZPOOL_FORCE,
1913e1bd7a2Ssjelinek 	DM_WHO_FORMAT,
1923e1bd7a2Ssjelinek 	DM_WHO_SWAP,
19346657f8dSmmusante 	DM_WHO_DUMP,
19446657f8dSmmusante 	DM_WHO_ZPOOL_SPARE
1953e1bd7a2Ssjelinek } dm_who_type_t;
1979bb41d3cSBill Pijewski /*
1989bb41d3cSBill Pijewski  * The API uses a "descriptor" to identify the managed objects such as drives,
1999bb41d3cSBill Pijewski  * controllers, media, slices, partitions, paths and buses.  The descriptors are
2009bb41d3cSBill Pijewski  * opaque and are only returned or used as parameters to the other functions in
2019bb41d3cSBill Pijewski  * the API.  The descriptor definition is a typedef to dm_descriptor_t.
2029bb41d3cSBill Pijewski  *
2039bb41d3cSBill Pijewski  * Applications call either the dm_get_descriptors or
2049bb41d3cSBill Pijewski  * dm_get_associated_descriptors function to obtain a list of descriptors of a
2059bb41d3cSBill Pijewski  * specific type.  The application specifies the desired type from the following
2069bb41d3cSBill Pijewski  * enumeration:
2079bb41d3cSBill Pijewski  */
2087c478bd9Sstevel@tonic-gate typedef enum {
2097c478bd9Sstevel@tonic-gate     DM_DRIVE = 0,
2107c478bd9Sstevel@tonic-gate     DM_CONTROLLER,
2117c478bd9Sstevel@tonic-gate     DM_MEDIA,
2127c478bd9Sstevel@tonic-gate     DM_SLICE,
2137c478bd9Sstevel@tonic-gate     DM_PARTITION,
2147c478bd9Sstevel@tonic-gate     DM_PATH,
2157c478bd9Sstevel@tonic-gate     DM_ALIAS,
2167c478bd9Sstevel@tonic-gate     DM_BUS
2177c478bd9Sstevel@tonic-gate } dm_desc_type_t;
2199bb41d3cSBill Pijewski /*
2209bb41d3cSBill Pijewski  * These descriptors are associated with each other in the following way:
2219bb41d3cSBill Pijewski  *
2229bb41d3cSBill Pijewski  *                      alias                 partition
2239bb41d3cSBill Pijewski  *     _                    \                /   |
2249bb41d3cSBill Pijewski  *    / \                    \              /    |
2259bb41d3cSBill Pijewski  *    \ /                     \            /     |
2269bb41d3cSBill Pijewski  *    bus --- controller --- drive --- media     |
2279bb41d3cSBill Pijewski  *                     |      /            \     |
2289bb41d3cSBill Pijewski  *                     |     /              \    |
2299bb41d3cSBill Pijewski  *                     |    /                \   |
2309bb41d3cSBill Pijewski  *                      path                  slice
2319bb41d3cSBill Pijewski  *
2329bb41d3cSBill Pijewski  * The dm_get_associated_descriptors function can be used get the descriptors
2339bb41d3cSBill Pijewski  * associated with a given descriptor.  The dm_get_associated_types function can
2349bb41d3cSBill Pijewski  * be used to find the types that can be associated with a given type.
2359bb41d3cSBill Pijewski  *
2369bb41d3cSBill Pijewski  * The attributes and values for these objects are described using a list of
2379bb41d3cSBill Pijewski  * name/value pairs (see libnvpair(3LIB) and the specific comments for each
2389bb41d3cSBill Pijewski  * function in the API section of this document).
2399bb41d3cSBill Pijewski  *
2409bb41d3cSBill Pijewski  * Drives and media have a type which are defined as the following enumerations.
2419bb41d3cSBill Pijewski  * There could be additional types added to these enumerations as new drive and
2429bb41d3cSBill Pijewski  * media types are supported by the system.
2439bb41d3cSBill Pijewski  */
2457c478bd9Sstevel@tonic-gate typedef enum {
2467c478bd9Sstevel@tonic-gate     DM_DT_UNKNOWN = 0,
2477c478bd9Sstevel@tonic-gate     DM_DT_FIXED,
2487c478bd9Sstevel@tonic-gate     DM_DT_ZIP,
2497c478bd9Sstevel@tonic-gate     DM_DT_JAZ,
2507c478bd9Sstevel@tonic-gate     DM_DT_FLOPPY,
2517c478bd9Sstevel@tonic-gate     DM_DT_MO_ERASABLE,
2527c478bd9Sstevel@tonic-gate     DM_DT_MO_WRITEONCE,
2537c478bd9Sstevel@tonic-gate     DM_DT_AS_MO,
2547c478bd9Sstevel@tonic-gate     DM_DT_CDROM,
2557c478bd9Sstevel@tonic-gate     DM_DT_CDR,
2567c478bd9Sstevel@tonic-gate     DM_DT_CDRW,
2577c478bd9Sstevel@tonic-gate     DM_DT_DVDROM,
2587c478bd9Sstevel@tonic-gate     DM_DT_DVDR,
2597c478bd9Sstevel@tonic-gate     DM_DT_DVDRAM,
2607c478bd9Sstevel@tonic-gate     DM_DT_DVDRW,
2617c478bd9Sstevel@tonic-gate     DM_DT_DDCDROM,
2627c478bd9Sstevel@tonic-gate     DM_DT_DDCDR,
2637c478bd9Sstevel@tonic-gate     DM_DT_DDCDRW
2647c478bd9Sstevel@tonic-gate } dm_drive_type_t;
2667c478bd9Sstevel@tonic-gate typedef enum {
2677c478bd9Sstevel@tonic-gate     DM_MT_UNKNOWN = 0,
2687c478bd9Sstevel@tonic-gate     DM_MT_FIXED,
2697c478bd9Sstevel@tonic-gate     DM_MT_FLOPPY,
2707c478bd9Sstevel@tonic-gate     DM_MT_CDROM,
2717c478bd9Sstevel@tonic-gate     DM_MT_ZIP,
2727c478bd9Sstevel@tonic-gate     DM_MT_JAZ,
2737c478bd9Sstevel@tonic-gate     DM_MT_CDR,
2747c478bd9Sstevel@tonic-gate     DM_MT_CDRW,
2757c478bd9Sstevel@tonic-gate     DM_MT_DVDROM,
2767c478bd9Sstevel@tonic-gate     DM_MT_DVDR,
2777c478bd9Sstevel@tonic-gate     DM_MT_DVDRAM,
2787c478bd9Sstevel@tonic-gate     DM_MT_MO_ERASABLE,
2797c478bd9Sstevel@tonic-gate     DM_MT_MO_WRITEONCE,
2807c478bd9Sstevel@tonic-gate     DM_MT_AS_MO
2817c478bd9Sstevel@tonic-gate } dm_media_type_t;
2837c478bd9Sstevel@tonic-gate #define	DM_FILTER_END	-1
2859bb41d3cSBill Pijewski /*
2869bb41d3cSBill Pijewski  * The dm_get_stats function takes a stat_type argument for the specific sample
2879bb41d3cSBill Pijewski  * to get for the descriptor.  The following enums specify the drive and slice
2889bb41d3cSBill Pijewski  * stat types.
2899bb41d3cSBill Pijewski  */
2907c478bd9Sstevel@tonic-gate /* drive stat name */
2917c478bd9Sstevel@tonic-gate typedef enum {
2927c478bd9Sstevel@tonic-gate     DM_DRV_STAT_PERFORMANCE = 0,
2937c478bd9Sstevel@tonic-gate     DM_DRV_STAT_DIAGNOSTIC,
2947c478bd9Sstevel@tonic-gate     DM_DRV_STAT_TEMPERATURE
2957c478bd9Sstevel@tonic-gate } dm_drive_stat_t;
2977c478bd9Sstevel@tonic-gate /* slice stat name */
2987c478bd9Sstevel@tonic-gate typedef enum {
2997c478bd9Sstevel@tonic-gate     DM_SLICE_STAT_USE = 0
3007c478bd9Sstevel@tonic-gate } dm_slice_stat_t;
3022174cb7bSVirginia Wray /* partition type */
3032174cb7bSVirginia Wray typedef enum {
3042174cb7bSVirginia Wray 	DM_PRIMARY = 0,
3052174cb7bSVirginia Wray 	DM_EXTENDED,
3062174cb7bSVirginia Wray 	DM_LOGICAL
3072174cb7bSVirginia Wray } dm_partition_type_t;
3082174cb7bSVirginia Wray 
3097c478bd9Sstevel@tonic-gate /* attribute definitions */
3117c478bd9Sstevel@tonic-gate /* drive */
3127c478bd9Sstevel@tonic-gate #define	DM_DISK_UP		1
3137c478bd9Sstevel@tonic-gate #define	DM_DISK_DOWN		0
3157c478bd9Sstevel@tonic-gate #define	DM_DRVTYPE		"drvtype"
3167c478bd9Sstevel@tonic-gate #define	DM_FAILING		"failing"
3177c478bd9Sstevel@tonic-gate #define	DM_LOADED		"loaded"	/* also in media */
3187c478bd9Sstevel@tonic-gate #define	DM_NDNRERRS		"ndevice_not_ready_errors"
3197c478bd9Sstevel@tonic-gate #define	DM_NBYTESREAD		"nbytes_read"
3207c478bd9Sstevel@tonic-gate #define	DM_NBYTESWRITTEN	"nbytes_written"
3217c478bd9Sstevel@tonic-gate #define	DM_NHARDERRS		"nhard_errors"
3227c478bd9Sstevel@tonic-gate #define	DM_NILLREQERRS		"nillegal_req_errors"
3237c478bd9Sstevel@tonic-gate #define	DM_NMEDIAERRS		"nmedia_errors"
3247c478bd9Sstevel@tonic-gate #define	DM_NNODEVERRS		"nno_dev_errors"
3257c478bd9Sstevel@tonic-gate #define	DM_NREADOPS		"nread_ops"
3267c478bd9Sstevel@tonic-gate #define	DM_NRECOVERRS		"nrecoverable_errors"
3277c478bd9Sstevel@tonic-gate #define	DM_NSOFTERRS		"nsoft_errors"
3287c478bd9Sstevel@tonic-gate #define	DM_NTRANSERRS		"ntransport_errors"
3297c478bd9Sstevel@tonic-gate #define	DM_NWRITEOPS		"nwrite_ops"
3307c478bd9Sstevel@tonic-gate #define	DM_OPATH		"opath"
3317c478bd9Sstevel@tonic-gate #define	DM_PRODUCT_ID		"product_id"
3327c478bd9Sstevel@tonic-gate #define	DM_REMOVABLE		"removable"	/* also in media */
3337c478bd9Sstevel@tonic-gate #define	DM_RPM			"rpm"
33459d8f100SGarrett D'Amore #define	DM_SOLIDSTATE		"solid_state"
3357c478bd9Sstevel@tonic-gate #define	DM_STATUS		"status"
3367c478bd9Sstevel@tonic-gate #define	DM_SYNC_SPEED		"sync_speed"
3377c478bd9Sstevel@tonic-gate #define	DM_TEMPERATURE		"temperature"
3387c478bd9Sstevel@tonic-gate #define	DM_VENDOR_ID		"vendor_id"
3397c478bd9Sstevel@tonic-gate #define	DM_WIDE			"wide"		/* also on controller */
3407c478bd9Sstevel@tonic-gate #define	DM_WWN			"wwn"
3427c478bd9Sstevel@tonic-gate /* bus */
3437c478bd9Sstevel@tonic-gate #define	DM_BTYPE		"btype"
3447c478bd9Sstevel@tonic-gate #define	DM_CLOCK		"clock"		/* also on controller */
3457c478bd9Sstevel@tonic-gate #define	DM_PNAME		"pname"
3477c478bd9Sstevel@tonic-gate /* controller */
3487c478bd9Sstevel@tonic-gate #define	DM_FAST			"fast"
3497c478bd9Sstevel@tonic-gate #define	DM_FAST20		"fast20"
3507c478bd9Sstevel@tonic-gate #define	DM_FAST40		"fast40"
3517c478bd9Sstevel@tonic-gate #define	DM_FAST80		"fast80"
3527c478bd9Sstevel@tonic-gate #define	DM_MULTIPLEX		"multiplex"
3537c478bd9Sstevel@tonic-gate #define	DM_PATH_STATE		"path_state"
3557c478bd9Sstevel@tonic-gate #define	DM_CTYPE_ATA		"ata"
356c470f575SYuri Pankov #define	DM_CTYPE_FIBRE		"fibre"
357*f85f43edSRobert Mustacchi #define	DM_CTYPE_LOFI		"lofi"
358c470f575SYuri Pankov #define	DM_CTYPE_NVME		"nvme"
359c470f575SYuri Pankov #define	DM_CTYPE_SATA		"sata"
3607c478bd9Sstevel@tonic-gate #define	DM_CTYPE_SCSI		"scsi"
3617c478bd9Sstevel@tonic-gate #define	DM_CTYPE_USB		"usb"
362c470f575SYuri Pankov #define	DM_CTYPE_XEN		"xen"
3637c478bd9Sstevel@tonic-gate #define	DM_CTYPE_UNKNOWN	"unknown"
3657c478bd9Sstevel@tonic-gate /* media */
3667c478bd9Sstevel@tonic-gate #define	DM_BLOCKSIZE		"blocksize"
3677c478bd9Sstevel@tonic-gate #define	DM_FDISK		"fdisk"
3687c478bd9Sstevel@tonic-gate #define	DM_MTYPE		"mtype"
3697c478bd9Sstevel@tonic-gate #define	DM_NACTUALCYLINDERS	"nactual_cylinders"
3707c478bd9Sstevel@tonic-gate #define	DM_NALTCYLINDERS	"nalt_cylinders"
3717c478bd9Sstevel@tonic-gate #define	DM_NCYLINDERS		"ncylinders"
3727c478bd9Sstevel@tonic-gate #define	DM_NHEADS		"nheads"
3737c478bd9Sstevel@tonic-gate #define	DM_NPHYSCYLINDERS	"nphys_cylinders"
3747c478bd9Sstevel@tonic-gate #define	DM_NSECTORS		"nsectors"	/* also in partition */
3757c478bd9Sstevel@tonic-gate #define	DM_SIZE			"size"		/* also in slice */
3767c478bd9Sstevel@tonic-gate #define	DM_NACCESSIBLE		"naccessible"
3777c478bd9Sstevel@tonic-gate #define	DM_LABEL		"label"
3797c478bd9Sstevel@tonic-gate /* partition */
3807c478bd9Sstevel@tonic-gate #define	DM_BCYL			"bcyl"
3817c478bd9Sstevel@tonic-gate #define	DM_BHEAD		"bhead"
3827c478bd9Sstevel@tonic-gate #define	DM_BOOTID		"bootid"
3837c478bd9Sstevel@tonic-gate #define	DM_BSECT		"bsect"
3847c478bd9Sstevel@tonic-gate #define	DM_ECYL			"ecyl"
3857c478bd9Sstevel@tonic-gate #define	DM_EHEAD		"ehead"
3867c478bd9Sstevel@tonic-gate #define	DM_ESECT		"esect"
3872174cb7bSVirginia Wray #define	DM_PTYPE		"ptype" /* this references the partition id */
3882174cb7bSVirginia Wray #define	DM_PARTITION_TYPE	"part_type" /* primary, extended, logical */
3897c478bd9Sstevel@tonic-gate #define	DM_RELSECT		"relsect"
3917c478bd9Sstevel@tonic-gate /* slice */
3927c478bd9Sstevel@tonic-gate #define	DM_DEVICEID		"deviceid"
3937c478bd9Sstevel@tonic-gate #define	DM_DEVT			"devt"
3947c478bd9Sstevel@tonic-gate #define	DM_INDEX		"index"
3957c478bd9Sstevel@tonic-gate #define	DM_EFI_NAME		"name"
3967c478bd9Sstevel@tonic-gate #define	DM_MOUNTPOINT		"mountpoint"
3977c478bd9Sstevel@tonic-gate #define	DM_LOCALNAME		"localname"
3987c478bd9Sstevel@tonic-gate #define	DM_START		"start"
3997c478bd9Sstevel@tonic-gate #define	DM_TAG			"tag"
4007c478bd9Sstevel@tonic-gate #define	DM_FLAG			"flag"
4017c478bd9Sstevel@tonic-gate #define	DM_EFI			"efi"	/* also on media */
4027c478bd9Sstevel@tonic-gate #define	DM_USED_BY		"used_by"
4037c478bd9Sstevel@tonic-gate #define	DM_USED_NAME		"used_name"
4047c478bd9Sstevel@tonic-gate #define	DM_USE_MOUNT		"mount"
4057c478bd9Sstevel@tonic-gate #define	DM_USE_LU		"lu"
4067c478bd9Sstevel@tonic-gate #define	DM_USE_DUMP		"dump"
4077c478bd9Sstevel@tonic-gate #define	DM_USE_VXVM		"vxvm"
4087c478bd9Sstevel@tonic-gate #define	DM_USE_FS		"fs"
4097c478bd9Sstevel@tonic-gate #define	DM_USE_VFSTAB		"vfstab"
41046a2abf2Seschrock #define	DM_USE_EXPORTED_ZPOOL	"exported_zpool"
41146a2abf2Seschrock #define	DM_USE_ACTIVE_ZPOOL	"active_zpool"
41299653d4eSeschrock #define	DM_USE_SPARE_ZPOOL	"spare_zpool"
413fa94a07fSbrendan #define	DM_USE_L2CACHE_ZPOOL	"l2cache_zpool"
4157c478bd9Sstevel@tonic-gate /* event */
4167c478bd9Sstevel@tonic-gate #define	DM_EV_NAME		"name"
4177c478bd9Sstevel@tonic-gate #define	DM_EV_DTYPE		"edtype"
4187c478bd9Sstevel@tonic-gate #define	DM_EV_TYPE		"evtype"
4197c478bd9Sstevel@tonic-gate #define	DM_EV_TADD		"add"
4207c478bd9Sstevel@tonic-gate #define	DM_EV_TREMOVE		"remove"
4217c478bd9Sstevel@tonic-gate #define	DM_EV_TCHANGE		"change"
4237c478bd9Sstevel@tonic-gate /* findisks */
4247c478bd9Sstevel@tonic-gate #define	DM_CTYPE		"ctype"
4257c478bd9Sstevel@tonic-gate #define	DM_LUN			"lun"
4267c478bd9Sstevel@tonic-gate #define	DM_TARGET		"target"
42882d71480Ssjelinek #define	NOINUSE_SET	getenv("NOINUSE_CHECK") != NULL
4307c478bd9Sstevel@tonic-gate void			dm_free_descriptors(dm_descriptor_t *desc_list);
4317c478bd9Sstevel@tonic-gate void			dm_free_descriptor(dm_descriptor_t desc);
4327c478bd9Sstevel@tonic-gate void			dm_free_name(char *name);
433181c2f42Smmusante void			dm_free_swapentries(swaptbl_t *);
4357c478bd9Sstevel@tonic-gate dm_descriptor_t		*dm_get_descriptors(dm_desc_type_t type, int filter[],
4367c478bd9Sstevel@tonic-gate 			    int *errp);
4377c478bd9Sstevel@tonic-gate dm_descriptor_t		*dm_get_associated_descriptors(dm_descriptor_t desc,
4387c478bd9Sstevel@tonic-gate 			    dm_desc_type_t type, int *errp);
4397c478bd9Sstevel@tonic-gate dm_desc_type_t		*dm_get_associated_types(dm_desc_type_t type);
4407c478bd9Sstevel@tonic-gate dm_descriptor_t		dm_get_descriptor_by_name(dm_desc_type_t desc_type,
4417c478bd9Sstevel@tonic-gate 			    char *name, int *errp);
4427c478bd9Sstevel@tonic-gate char			*dm_get_name(dm_descriptor_t desc, int *errp);
4437c478bd9Sstevel@tonic-gate dm_desc_type_t		dm_get_type(dm_descriptor_t desc);
4447c478bd9Sstevel@tonic-gate nvlist_t		*dm_get_attributes(dm_descriptor_t desc, int *errp);
4457c478bd9Sstevel@tonic-gate nvlist_t		*dm_get_stats(dm_descriptor_t desc, int stat_type,
4467c478bd9Sstevel@tonic-gate 			    int *errp);
4477c478bd9Sstevel@tonic-gate void			dm_init_event_queue(void(*callback)(nvlist_t *, int),
4487c478bd9Sstevel@tonic-gate 			    int *errp);
4497c478bd9Sstevel@tonic-gate nvlist_t		*dm_get_event(int *errp);
4503e1bd7a2Ssjelinek void			dm_get_slices(char *drive, dm_descriptor_t **slices,
4513e1bd7a2Ssjelinek 			    int *errp);
4523e1bd7a2Ssjelinek void			dm_get_slice_stats(char *slice, nvlist_t **dev_stats,
4533e1bd7a2Ssjelinek 			    int *errp);
454181c2f42Smmusante int			dm_get_swapentries(swaptbl_t **, int *);
4553e1bd7a2Ssjelinek void			dm_get_usage_string(char *who, char *data, char **msg);
4563e1bd7a2Ssjelinek int			dm_inuse(char *dev_name, char **msg, dm_who_type_t who,
4573e1bd7a2Ssjelinek 			    int *errp);
458181c2f42Smmusante int			dm_inuse_swap(const char *dev_name, int *errp);
45946a2abf2Seschrock int			dm_isoverlapping(char *dev_name, char **msg, int *errp);
4617c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate #endif
4657c478bd9Sstevel@tonic-gate #endif /* _LIBDISKMGT_H */