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  */
217c478bd9Sstevel@tonic-gate /*
222174cb7bSVirginia Wray  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*9bb41d3cSBill Pijewski  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _LIBDISKMGT_H
287c478bd9Sstevel@tonic-gate #define	_LIBDISKMGT_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <libnvpair.h>
35181c2f42Smmusante #include <sys/swap.h>
3682d71480Ssjelinek 
3782d71480Ssjelinek 
38*9bb41d3cSBill Pijewski /*
39*9bb41d3cSBill Pijewski  * Disk Management Library
40*9bb41d3cSBill Pijewski  *
41*9bb41d3cSBill Pijewski  * This library provides a common way to gather information about a system's
42*9bb41d3cSBill Pijewski  * disks, controllers, and related components.
43*9bb41d3cSBill Pijewski  *
44*9bb41d3cSBill Pijewski  *
45*9bb41d3cSBill Pijewski  * THREADS
46*9bb41d3cSBill Pijewski  * -------
47*9bb41d3cSBill Pijewski  *
48*9bb41d3cSBill Pijewski  * In general all of the functions are thread safe, however there are some
49*9bb41d3cSBill Pijewski  * specific considerations for getting events.  The dm_get_event function may
50*9bb41d3cSBill Pijewski  * block the calling thread if no event is currently available.  If another
51*9bb41d3cSBill Pijewski  * thread calls dm_get_event while a thread is already blocked in this function,
52*9bb41d3cSBill Pijewski  * the second thread will also block.  When an event arrives and multiple
53*9bb41d3cSBill Pijewski  * threads are waiting for events, it is undefined which thread will be
54*9bb41d3cSBill Pijewski  * unblocked and receive the event.  If a callback is used for handling events,
55*9bb41d3cSBill Pijewski  * this is equivalent to the dm_get_event function, so mixing callbacks and
56*9bb41d3cSBill Pijewski  * dm_get_event is also nondeterministic.
57*9bb41d3cSBill Pijewski  *
58*9bb41d3cSBill Pijewski  *
59*9bb41d3cSBill Pijewski  * ERRORS
60*9bb41d3cSBill Pijewski  * ------
61*9bb41d3cSBill Pijewski  *
62*9bb41d3cSBill Pijewski  * In general all of the functions take an errno pointer.  This is an integer
63*9bb41d3cSBill Pijewski  * that will contain 0 if the function succeeded or contains an errno (see
64*9bb41d3cSBill Pijewski  * errno.h) if there was an error.  If the function returns some data, that
65*9bb41d3cSBill Pijewski  * return data will generally be null if an error occured (see the API comment
66*9bb41d3cSBill Pijewski  * for the specific function for details).  Many of the functions take a
67*9bb41d3cSBill Pijewski  * descriptor and provide more information for that descriptor.  These functions
68*9bb41d3cSBill Pijewski  * may return an error if the object was removed between the call which obtained
69*9bb41d3cSBill Pijewski  * the descriptor and the call to get more information about the object (errno
70*9bb41d3cSBill Pijewski  * will be ENODEV).  Only a few of the possible errno values will be returned;
71*9bb41d3cSBill Pijewski  * typically:
72*9bb41d3cSBill Pijewski  *     EPERM       not super-user
73*9bb41d3cSBill Pijewski  *     ENOMEM      not enough memory
74*9bb41d3cSBill Pijewski  *     ENODEV      no such device
75*9bb41d3cSBill Pijewski  *     EINVAL      invalid argument
76*9bb41d3cSBill Pijewski  *     ENOENT      no event queue has been created
77*9bb41d3cSBill Pijewski  *
78*9bb41d3cSBill Pijewski  * Many of the functions require the application to be running as root in order
79*9bb41d3cSBill Pijewski  * to get complete information.  EPERM will be returned if the application is
80*9bb41d3cSBill Pijewski  * not running as root.  However, not all of the functions have this requirement
81*9bb41d3cSBill Pijewski  * (i.e. event handling).
82*9bb41d3cSBill Pijewski  *
83*9bb41d3cSBill Pijewski  * It is possible for the system to run out of memory while receiving events.
84*9bb41d3cSBill Pijewski  * Since event receipt is asyncronous from the dm_get_event call there may not
85*9bb41d3cSBill Pijewski  * be a thread waiting when the event occurs and ENOMEM is detected.  In this
86*9bb41d3cSBill Pijewski  * case the event will be lost.  The first call to dm_get_event following this
87*9bb41d3cSBill Pijewski  * condition will immediately return ENOMEM, even if events are queued.
88*9bb41d3cSBill Pijewski  * Subsequent calls can return events.  The dm_get_event call will clear the
89*9bb41d3cSBill Pijewski  * pending ENOMEM condition.  There is no way to know how many events were lost
90*9bb41d3cSBill Pijewski  * when this situation occurs.  If a thread is waiting when the event arrives
91*9bb41d3cSBill Pijewski  * and the ENOMEM condition occurs, the call will also return with ENOMEM.
92*9bb41d3cSBill Pijewski  * There is no way to determine if the system ran out of memory before the
93*9bb41d3cSBill Pijewski  * dm_get_event call or while the thread was blocked in the dm_get_event call
94*9bb41d3cSBill Pijewski  * since both conditions cause dm_get_event to return ENOMEM.
95*9bb41d3cSBill Pijewski  *
96*9bb41d3cSBill Pijewski  *
97*9bb41d3cSBill Pijewski  * MEMORY MANAGEMENT
98*9bb41d3cSBill Pijewski  * -----------------
99*9bb41d3cSBill Pijewski  *
100*9bb41d3cSBill Pijewski  * Most of the functions that return data are returning memory that has been
101*9bb41d3cSBill Pijewski  * allocated and must be freed by the application when no longer needed.  The
102*9bb41d3cSBill Pijewski  * application should call the proper free function to free the memory.  Most of
103*9bb41d3cSBill Pijewski  * the functions return either a nvlist or an array of descriptors.  The normal
104*9bb41d3cSBill Pijewski  * nvlist function (nvlist_free; see libnvpair(3LIB)) can be used to free the
105*9bb41d3cSBill Pijewski  * simple nvlists.  Other functions are provided to free the more complex data
106*9bb41d3cSBill Pijewski  * structures.
107*9bb41d3cSBill Pijewski  *
108*9bb41d3cSBill Pijewski  * The following list shows the functions that return allocated memory and the
109*9bb41d3cSBill Pijewski  * corresponding function to free the memory:
110*9bb41d3cSBill Pijewski  *     dm_get_descriptors            dm_free_descriptors
111*9bb41d3cSBill Pijewski  *     dm_get_associated_descriptors dm_free_descriptors
112*9bb41d3cSBill Pijewski  *     dm_get_descriptor_by_name     dm_free_descriptor
113*9bb41d3cSBill Pijewski  *     dm_get_name                   dm_free_name
114*9bb41d3cSBill Pijewski  *     dm_get_attributes             nvlist_free
115*9bb41d3cSBill Pijewski  *     dm_get_stats	          nvlist_free
116*9bb41d3cSBill Pijewski  *     dm_get_event                  nvlist_free
117*9bb41d3cSBill Pijewski  *
118*9bb41d3cSBill Pijewski  *
119*9bb41d3cSBill Pijewski  * EVENTS
120*9bb41d3cSBill Pijewski  * ------
121*9bb41d3cSBill Pijewski  *
122*9bb41d3cSBill Pijewski  * Event information is returned as a nvlist.  It may be possible to return more
123*9bb41d3cSBill Pijewski  * information about events over time, especially information about what has
124*9bb41d3cSBill Pijewski  * changed.  However, that may not always be the case, so by using an nvlist we
125*9bb41d3cSBill Pijewski  * have a very generic event indication.  At a minimum the event will return the
126*9bb41d3cSBill Pijewski  * name of the device, the type of device (see dm_desc_type_t) and the type of
127*9bb41d3cSBill Pijewski  * event.  The event type is a string which can currently be; add, remove,
128*9bb41d3cSBill Pijewski  * change.
129*9bb41d3cSBill Pijewski  *
130*9bb41d3cSBill Pijewski  * If a drive goes up or down this could be returned as event type "change".
131*9bb41d3cSBill Pijewski  * The application could get the drive information to see that the "status"
132*9bb41d3cSBill Pijewski  * attribute has changed value (ideally the event would include an attribute
133*9bb41d3cSBill Pijewski  * with the name of the changed attribute as the value).  Although the API can
134*9bb41d3cSBill Pijewski  * return events for all drive related changes, events will not necessarily be
135*9bb41d3cSBill Pijewski  * delivered for all changes unless the system generates those events.
136*9bb41d3cSBill Pijewski  *
137*9bb41d3cSBill Pijewski  *
138*9bb41d3cSBill Pijewski  * Controller/HBAs
139*9bb41d3cSBill Pijewski  * ---------------
140*9bb41d3cSBill Pijewski  *
141*9bb41d3cSBill Pijewski  * In general the API means "the parent node of the drive in the device tree"
142*9bb41d3cSBill Pijewski  * where the word "controller" is used.  This can actually be either the HBA or
143*9bb41d3cSBill Pijewski  * the drive controller depending on the type of the drive.
144*9bb41d3cSBill Pijewski  *
145*9bb41d3cSBill Pijewski  * Drives can be connected to their controller(s) in three different ways:
146*9bb41d3cSBill Pijewski  *     single controller
147*9bb41d3cSBill Pijewski  *     multiple controllers
148*9bb41d3cSBill Pijewski  *     multiple controllers with mpxio
149*9bb41d3cSBill Pijewski  * These cases will lead to different information being available for the
150*9bb41d3cSBill Pijewski  * configuration.  The two interesting cases are multi-path with and without
151*9bb41d3cSBill Pijewski  * mpxio.  With mpxio the drive will have a unique name and a single controller
152*9bb41d3cSBill Pijewski  * (scsi_vhci).  The physical controllers, the paths to the drive, can be
153*9bb41d3cSBill Pijewski  * obtained by calling dm_get_associated_descriptors with a drive descriptor and
154*9bb41d3cSBill Pijewski  * a type of DM_PATH.  This will only return these physical paths when MPXIO, or
155*9bb41d3cSBill Pijewski  * possibly some future similar feature, is controlling the drive.
156*9bb41d3cSBill Pijewski  *
157*9bb41d3cSBill Pijewski  * Without mpxio the drive does not have a unique public name (in all cases the
158*9bb41d3cSBill Pijewski  * alias(es) of the drive can be determined by calling
159*9bb41d3cSBill Pijewski  * dm_get_associated_descriptors to get the DM_ALIAS descriptors.  There will be
160*9bb41d3cSBill Pijewski  * more than one controller returned from dm_get_associated_descriptors when
161*9bb41d3cSBill Pijewski  * called with a type of DM_CONTROLLER.  The controllers for each of the aliases
162*9bb41d3cSBill Pijewski  * will be returned in the same order as the aliases descriptors.  For example,
163*9bb41d3cSBill Pijewski  * a drive with two paths has the aliases c5t3d2 and c7t1d0.  There will be two
164*9bb41d3cSBill Pijewski  * controllers returned; the first corresponds to c5 and the second corresponds
165*9bb41d3cSBill Pijewski  * to c7.
166*9bb41d3cSBill Pijewski  *
167*9bb41d3cSBill Pijewski  * In the multi-path, non-mpxio case the drive has more than one alias.
168*9bb41d3cSBill Pijewski  * Although most of the drive attributes are represented on the drive (see
169*9bb41d3cSBill Pijewski  * dm_get_attributes) there can be some different attributes for the different
170*9bb41d3cSBill Pijewski  * aliases for the drive.  Use dm_get_associated_descriptors to get the DM_ALIAS
171*9bb41d3cSBill Pijewski  * descriptors which can then be used to obtain these attributes.  Use of this
172*9bb41d3cSBill Pijewski  * algorithm is not restricted to the multi-path, non-mpxio case.  For example,
173*9bb41d3cSBill Pijewski  * it can be used to get the target/lun for a SCSI drive with a single path.
174*9bb41d3cSBill Pijewski  */
175*9bb41d3cSBill Pijewski 
1763e1bd7a2Ssjelinek /*
1773e1bd7a2Ssjelinek  * Holds all the data regarding the device.
1783e1bd7a2Ssjelinek  * Private to libdiskmgt. Must use dm_xxx functions to set/get data.
1793e1bd7a2Ssjelinek  */
1807c478bd9Sstevel@tonic-gate typedef uint64_t  dm_descriptor_t;
1817c478bd9Sstevel@tonic-gate 
1823e1bd7a2Ssjelinek typedef enum {
1833e1bd7a2Ssjelinek 	DM_WHO_MKFS = 0,
1843e1bd7a2Ssjelinek 	DM_WHO_ZPOOL,
18546a2abf2Seschrock 	DM_WHO_ZPOOL_FORCE,
1863e1bd7a2Ssjelinek 	DM_WHO_FORMAT,
1873e1bd7a2Ssjelinek 	DM_WHO_SWAP,
18846657f8dSmmusante 	DM_WHO_DUMP,
18946657f8dSmmusante 	DM_WHO_ZPOOL_SPARE
1903e1bd7a2Ssjelinek } dm_who_type_t;
1913e1bd7a2Ssjelinek 
192*9bb41d3cSBill Pijewski /*
193*9bb41d3cSBill Pijewski  * The API uses a "descriptor" to identify the managed objects such as drives,
194*9bb41d3cSBill Pijewski  * controllers, media, slices, partitions, paths and buses.  The descriptors are
195*9bb41d3cSBill Pijewski  * opaque and are only returned or used as parameters to the other functions in
196*9bb41d3cSBill Pijewski  * the API.  The descriptor definition is a typedef to dm_descriptor_t.
197*9bb41d3cSBill Pijewski  *
198*9bb41d3cSBill Pijewski  * Applications call either the dm_get_descriptors or
199*9bb41d3cSBill Pijewski  * dm_get_associated_descriptors function to obtain a list of descriptors of a
200*9bb41d3cSBill Pijewski  * specific type.  The application specifies the desired type from the following
201*9bb41d3cSBill Pijewski  * enumeration:
202*9bb41d3cSBill Pijewski  */
2037c478bd9Sstevel@tonic-gate typedef enum {
2047c478bd9Sstevel@tonic-gate     DM_DRIVE = 0,
2057c478bd9Sstevel@tonic-gate     DM_CONTROLLER,
2067c478bd9Sstevel@tonic-gate     DM_MEDIA,
2077c478bd9Sstevel@tonic-gate     DM_SLICE,
2087c478bd9Sstevel@tonic-gate     DM_PARTITION,
2097c478bd9Sstevel@tonic-gate     DM_PATH,
2107c478bd9Sstevel@tonic-gate     DM_ALIAS,
2117c478bd9Sstevel@tonic-gate     DM_BUS
2127c478bd9Sstevel@tonic-gate } dm_desc_type_t;
2137c478bd9Sstevel@tonic-gate 
214*9bb41d3cSBill Pijewski /*
215*9bb41d3cSBill Pijewski  * These descriptors are associated with each other in the following way:
216*9bb41d3cSBill Pijewski  *
217*9bb41d3cSBill Pijewski  *                      alias                 partition
218*9bb41d3cSBill Pijewski  *     _                    \                /   |
219*9bb41d3cSBill Pijewski  *    / \                    \              /    |
220*9bb41d3cSBill Pijewski  *    \ /                     \            /     |
221*9bb41d3cSBill Pijewski  *    bus --- controller --- drive --- media     |
222*9bb41d3cSBill Pijewski  *                     |      /            \     |
223*9bb41d3cSBill Pijewski  *                     |     /              \    |
224*9bb41d3cSBill Pijewski  *                     |    /                \   |
225*9bb41d3cSBill Pijewski  *                      path                  slice
226*9bb41d3cSBill Pijewski  *
227*9bb41d3cSBill Pijewski  * The dm_get_associated_descriptors function can be used get the descriptors
228*9bb41d3cSBill Pijewski  * associated with a given descriptor.  The dm_get_associated_types function can
229*9bb41d3cSBill Pijewski  * be used to find the types that can be associated with a given type.
230*9bb41d3cSBill Pijewski  *
231*9bb41d3cSBill Pijewski  * The attributes and values for these objects are described using a list of
232*9bb41d3cSBill Pijewski  * name/value pairs (see libnvpair(3LIB) and the specific comments for each
233*9bb41d3cSBill Pijewski  * function in the API section of this document).
234*9bb41d3cSBill Pijewski  *
235*9bb41d3cSBill Pijewski  * Drives and media have a type which are defined as the following enumerations.
236*9bb41d3cSBill Pijewski  * There could be additional types added to these enumerations as new drive and
237*9bb41d3cSBill Pijewski  * media types are supported by the system.
238*9bb41d3cSBill Pijewski  */
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate typedef enum {
2417c478bd9Sstevel@tonic-gate     DM_DT_UNKNOWN = 0,
2427c478bd9Sstevel@tonic-gate     DM_DT_FIXED,
2437c478bd9Sstevel@tonic-gate     DM_DT_ZIP,
2447c478bd9Sstevel@tonic-gate     DM_DT_JAZ,
2457c478bd9Sstevel@tonic-gate     DM_DT_FLOPPY,
2467c478bd9Sstevel@tonic-gate     DM_DT_MO_ERASABLE,
2477c478bd9Sstevel@tonic-gate     DM_DT_MO_WRITEONCE,
2487c478bd9Sstevel@tonic-gate     DM_DT_AS_MO,
2497c478bd9Sstevel@tonic-gate     DM_DT_CDROM,
2507c478bd9Sstevel@tonic-gate     DM_DT_CDR,
2517c478bd9Sstevel@tonic-gate     DM_DT_CDRW,
2527c478bd9Sstevel@tonic-gate     DM_DT_DVDROM,
2537c478bd9Sstevel@tonic-gate     DM_DT_DVDR,
2547c478bd9Sstevel@tonic-gate     DM_DT_DVDRAM,
2557c478bd9Sstevel@tonic-gate     DM_DT_DVDRW,
2567c478bd9Sstevel@tonic-gate     DM_DT_DDCDROM,
2577c478bd9Sstevel@tonic-gate     DM_DT_DDCDR,
2587c478bd9Sstevel@tonic-gate     DM_DT_DDCDRW
2597c478bd9Sstevel@tonic-gate } dm_drive_type_t;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate typedef enum {
2627c478bd9Sstevel@tonic-gate     DM_MT_UNKNOWN = 0,
2637c478bd9Sstevel@tonic-gate     DM_MT_FIXED,
2647c478bd9Sstevel@tonic-gate     DM_MT_FLOPPY,
2657c478bd9Sstevel@tonic-gate     DM_MT_CDROM,
2667c478bd9Sstevel@tonic-gate     DM_MT_ZIP,
2677c478bd9Sstevel@tonic-gate     DM_MT_JAZ,
2687c478bd9Sstevel@tonic-gate     DM_MT_CDR,
2697c478bd9Sstevel@tonic-gate     DM_MT_CDRW,
2707c478bd9Sstevel@tonic-gate     DM_MT_DVDROM,
2717c478bd9Sstevel@tonic-gate     DM_MT_DVDR,
2727c478bd9Sstevel@tonic-gate     DM_MT_DVDRAM,
2737c478bd9Sstevel@tonic-gate     DM_MT_MO_ERASABLE,
2747c478bd9Sstevel@tonic-gate     DM_MT_MO_WRITEONCE,
2757c478bd9Sstevel@tonic-gate     DM_MT_AS_MO
2767c478bd9Sstevel@tonic-gate } dm_media_type_t;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate #define	DM_FILTER_END	-1
2797c478bd9Sstevel@tonic-gate 
280*9bb41d3cSBill Pijewski /*
281*9bb41d3cSBill Pijewski  * The dm_get_stats function takes a stat_type argument for the specific sample
282*9bb41d3cSBill Pijewski  * to get for the descriptor.  The following enums specify the drive and slice
283*9bb41d3cSBill Pijewski  * stat types.
284*9bb41d3cSBill Pijewski  */
2857c478bd9Sstevel@tonic-gate /* drive stat name */
2867c478bd9Sstevel@tonic-gate typedef enum {
2877c478bd9Sstevel@tonic-gate     DM_DRV_STAT_PERFORMANCE = 0,
2887c478bd9Sstevel@tonic-gate     DM_DRV_STAT_DIAGNOSTIC,
2897c478bd9Sstevel@tonic-gate     DM_DRV_STAT_TEMPERATURE
2907c478bd9Sstevel@tonic-gate } dm_drive_stat_t;
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate /* slice stat name */
2937c478bd9Sstevel@tonic-gate typedef enum {
2947c478bd9Sstevel@tonic-gate     DM_SLICE_STAT_USE = 0
2957c478bd9Sstevel@tonic-gate } dm_slice_stat_t;
2967c478bd9Sstevel@tonic-gate 
2972174cb7bSVirginia Wray /* partition type */
2982174cb7bSVirginia Wray typedef enum {
2992174cb7bSVirginia Wray 	DM_PRIMARY = 0,
3002174cb7bSVirginia Wray 	DM_EXTENDED,
3012174cb7bSVirginia Wray 	DM_LOGICAL
3022174cb7bSVirginia Wray } dm_partition_type_t;
3032174cb7bSVirginia Wray 
3047c478bd9Sstevel@tonic-gate /* attribute definitions */
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate /* drive */
3077c478bd9Sstevel@tonic-gate #define	DM_DISK_UP		1
3087c478bd9Sstevel@tonic-gate #define	DM_DISK_DOWN		0
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate #define	DM_CLUSTERED		"clustered"
3117c478bd9Sstevel@tonic-gate #define	DM_DRVTYPE		"drvtype"
3127c478bd9Sstevel@tonic-gate #define	DM_FAILING		"failing"
3137c478bd9Sstevel@tonic-gate #define	DM_LOADED		"loaded"	/* also in media */
3147c478bd9Sstevel@tonic-gate #define	DM_NDNRERRS		"ndevice_not_ready_errors"
3157c478bd9Sstevel@tonic-gate #define	DM_NBYTESREAD		"nbytes_read"
3167c478bd9Sstevel@tonic-gate #define	DM_NBYTESWRITTEN	"nbytes_written"
3177c478bd9Sstevel@tonic-gate #define	DM_NHARDERRS		"nhard_errors"
3187c478bd9Sstevel@tonic-gate #define	DM_NILLREQERRS		"nillegal_req_errors"
3197c478bd9Sstevel@tonic-gate #define	DM_NMEDIAERRS		"nmedia_errors"
3207c478bd9Sstevel@tonic-gate #define	DM_NNODEVERRS		"nno_dev_errors"
3217c478bd9Sstevel@tonic-gate #define	DM_NREADOPS		"nread_ops"
3227c478bd9Sstevel@tonic-gate #define	DM_NRECOVERRS		"nrecoverable_errors"
3237c478bd9Sstevel@tonic-gate #define	DM_NSOFTERRS		"nsoft_errors"
3247c478bd9Sstevel@tonic-gate #define	DM_NTRANSERRS		"ntransport_errors"
3257c478bd9Sstevel@tonic-gate #define	DM_NWRITEOPS		"nwrite_ops"
3267c478bd9Sstevel@tonic-gate #define	DM_OPATH		"opath"
3277c478bd9Sstevel@tonic-gate #define	DM_PRODUCT_ID		"product_id"
3287c478bd9Sstevel@tonic-gate #define	DM_REMOVABLE		"removable"	/* also in media */
3297c478bd9Sstevel@tonic-gate #define	DM_RPM			"rpm"
33059d8f100SGarrett D'Amore #define	DM_SOLIDSTATE		"solid_state"
3317c478bd9Sstevel@tonic-gate #define	DM_STATUS		"status"
3327c478bd9Sstevel@tonic-gate #define	DM_SYNC_SPEED		"sync_speed"
3337c478bd9Sstevel@tonic-gate #define	DM_TEMPERATURE		"temperature"
3347c478bd9Sstevel@tonic-gate #define	DM_VENDOR_ID		"vendor_id"
3357c478bd9Sstevel@tonic-gate #define	DM_WIDE			"wide"		/* also on controller */
3367c478bd9Sstevel@tonic-gate #define	DM_WWN			"wwn"
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate /* bus */
3397c478bd9Sstevel@tonic-gate #define	DM_BTYPE		"btype"
3407c478bd9Sstevel@tonic-gate #define	DM_CLOCK		"clock"		/* also on controller */
3417c478bd9Sstevel@tonic-gate #define	DM_PNAME		"pname"
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate /* controller */
3447c478bd9Sstevel@tonic-gate #define	DM_FAST			"fast"
3457c478bd9Sstevel@tonic-gate #define	DM_FAST20		"fast20"
3467c478bd9Sstevel@tonic-gate #define	DM_FAST40		"fast40"
3477c478bd9Sstevel@tonic-gate #define	DM_FAST80		"fast80"
3487c478bd9Sstevel@tonic-gate #define	DM_MULTIPLEX		"multiplex"
3497c478bd9Sstevel@tonic-gate #define	DM_PATH_STATE		"path_state"
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate #define	DM_CTYPE_ATA		"ata"
3527c478bd9Sstevel@tonic-gate #define	DM_CTYPE_SCSI		"scsi"
3537c478bd9Sstevel@tonic-gate #define	DM_CTYPE_FIBRE		"fibre channel"
3547c478bd9Sstevel@tonic-gate #define	DM_CTYPE_USB		"usb"
3557c478bd9Sstevel@tonic-gate #define	DM_CTYPE_UNKNOWN	"unknown"
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate /* media */
3587c478bd9Sstevel@tonic-gate #define	DM_BLOCKSIZE		"blocksize"
3597c478bd9Sstevel@tonic-gate #define	DM_FDISK		"fdisk"
3607c478bd9Sstevel@tonic-gate #define	DM_MTYPE		"mtype"
3617c478bd9Sstevel@tonic-gate #define	DM_NACTUALCYLINDERS	"nactual_cylinders"
3627c478bd9Sstevel@tonic-gate #define	DM_NALTCYLINDERS	"nalt_cylinders"
3637c478bd9Sstevel@tonic-gate #define	DM_NCYLINDERS		"ncylinders"
3647c478bd9Sstevel@tonic-gate #define	DM_NHEADS		"nheads"
3657c478bd9Sstevel@tonic-gate #define	DM_NPHYSCYLINDERS	"nphys_cylinders"
3667c478bd9Sstevel@tonic-gate #define	DM_NSECTORS		"nsectors"	/* also in partition */
3677c478bd9Sstevel@tonic-gate #define	DM_SIZE			"size"		/* also in slice */
3687c478bd9Sstevel@tonic-gate #define	DM_NACCESSIBLE		"naccessible"
3697c478bd9Sstevel@tonic-gate #define	DM_LABEL		"label"
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate /* partition */
3727c478bd9Sstevel@tonic-gate #define	DM_BCYL			"bcyl"
3737c478bd9Sstevel@tonic-gate #define	DM_BHEAD		"bhead"
3747c478bd9Sstevel@tonic-gate #define	DM_BOOTID		"bootid"
3757c478bd9Sstevel@tonic-gate #define	DM_BSECT		"bsect"
3767c478bd9Sstevel@tonic-gate #define	DM_ECYL			"ecyl"
3777c478bd9Sstevel@tonic-gate #define	DM_EHEAD		"ehead"
3787c478bd9Sstevel@tonic-gate #define	DM_ESECT		"esect"
3792174cb7bSVirginia Wray #define	DM_PTYPE		"ptype" /* this references the partition id */
3802174cb7bSVirginia Wray #define	DM_PARTITION_TYPE	"part_type" /* primary, extended, logical */
3817c478bd9Sstevel@tonic-gate #define	DM_RELSECT		"relsect"
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate /* slice */
3847c478bd9Sstevel@tonic-gate #define	DM_DEVICEID		"deviceid"
3857c478bd9Sstevel@tonic-gate #define	DM_DEVT			"devt"
3867c478bd9Sstevel@tonic-gate #define	DM_INDEX		"index"
3877c478bd9Sstevel@tonic-gate #define	DM_EFI_NAME		"name"
3887c478bd9Sstevel@tonic-gate #define	DM_MOUNTPOINT		"mountpoint"
3897c478bd9Sstevel@tonic-gate #define	DM_LOCALNAME		"localname"
3907c478bd9Sstevel@tonic-gate #define	DM_START		"start"
3917c478bd9Sstevel@tonic-gate #define	DM_TAG			"tag"
3927c478bd9Sstevel@tonic-gate #define	DM_FLAG			"flag"
3937c478bd9Sstevel@tonic-gate #define	DM_EFI			"efi"	/* also on media */
3947c478bd9Sstevel@tonic-gate #define	DM_USED_BY		"used_by"
3957c478bd9Sstevel@tonic-gate #define	DM_USED_NAME		"used_name"
3967c478bd9Sstevel@tonic-gate #define	DM_USE_MOUNT		"mount"
3977c478bd9Sstevel@tonic-gate #define	DM_USE_SVM		"svm"
3987c478bd9Sstevel@tonic-gate #define	DM_USE_LU		"lu"
3997c478bd9Sstevel@tonic-gate #define	DM_USE_DUMP		"dump"
4007c478bd9Sstevel@tonic-gate #define	DM_USE_VXVM		"vxvm"
4017c478bd9Sstevel@tonic-gate #define	DM_USE_FS		"fs"
4027c478bd9Sstevel@tonic-gate #define	DM_USE_VFSTAB		"vfstab"
40346a2abf2Seschrock #define	DM_USE_EXPORTED_ZPOOL	"exported_zpool"
40446a2abf2Seschrock #define	DM_USE_ACTIVE_ZPOOL	"active_zpool"
40599653d4eSeschrock #define	DM_USE_SPARE_ZPOOL	"spare_zpool"
406fa94a07fSbrendan #define	DM_USE_L2CACHE_ZPOOL	"l2cache_zpool"
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /* event */
4097c478bd9Sstevel@tonic-gate #define	DM_EV_NAME		"name"
4107c478bd9Sstevel@tonic-gate #define	DM_EV_DTYPE		"edtype"
4117c478bd9Sstevel@tonic-gate #define	DM_EV_TYPE		"evtype"
4127c478bd9Sstevel@tonic-gate #define	DM_EV_TADD		"add"
4137c478bd9Sstevel@tonic-gate #define	DM_EV_TREMOVE		"remove"
4147c478bd9Sstevel@tonic-gate #define	DM_EV_TCHANGE		"change"
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate /* findisks */
4177c478bd9Sstevel@tonic-gate #define	DM_CTYPE		"ctype"
4187c478bd9Sstevel@tonic-gate #define	DM_LUN			"lun"
4197c478bd9Sstevel@tonic-gate #define	DM_TARGET		"target"
4207c478bd9Sstevel@tonic-gate 
42182d71480Ssjelinek #define	NOINUSE_SET	getenv("NOINUSE_CHECK") != NULL
42282d71480Ssjelinek 
4237c478bd9Sstevel@tonic-gate void			dm_free_descriptors(dm_descriptor_t *desc_list);
4247c478bd9Sstevel@tonic-gate void			dm_free_descriptor(dm_descriptor_t desc);
4257c478bd9Sstevel@tonic-gate void			dm_free_name(char *name);
426181c2f42Smmusante void			dm_free_swapentries(swaptbl_t *);
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate dm_descriptor_t		*dm_get_descriptors(dm_desc_type_t type, int filter[],
4297c478bd9Sstevel@tonic-gate 			    int *errp);
4307c478bd9Sstevel@tonic-gate dm_descriptor_t		*dm_get_associated_descriptors(dm_descriptor_t desc,
4317c478bd9Sstevel@tonic-gate 			    dm_desc_type_t type, int *errp);
4327c478bd9Sstevel@tonic-gate dm_desc_type_t		*dm_get_associated_types(dm_desc_type_t type);
4337c478bd9Sstevel@tonic-gate dm_descriptor_t		dm_get_descriptor_by_name(dm_desc_type_t desc_type,
4347c478bd9Sstevel@tonic-gate 			    char *name, int *errp);
4357c478bd9Sstevel@tonic-gate char			*dm_get_name(dm_descriptor_t desc, int *errp);
4367c478bd9Sstevel@tonic-gate dm_desc_type_t		dm_get_type(dm_descriptor_t desc);
4377c478bd9Sstevel@tonic-gate nvlist_t		*dm_get_attributes(dm_descriptor_t desc, int *errp);
4387c478bd9Sstevel@tonic-gate nvlist_t		*dm_get_stats(dm_descriptor_t desc, int stat_type,
4397c478bd9Sstevel@tonic-gate 			    int *errp);
4407c478bd9Sstevel@tonic-gate void			dm_init_event_queue(void(*callback)(nvlist_t *, int),
4417c478bd9Sstevel@tonic-gate 			    int *errp);
4427c478bd9Sstevel@tonic-gate nvlist_t		*dm_get_event(int *errp);
4433e1bd7a2Ssjelinek void			dm_get_slices(char *drive, dm_descriptor_t **slices,
4443e1bd7a2Ssjelinek 			    int *errp);
4453e1bd7a2Ssjelinek void			dm_get_slice_stats(char *slice, nvlist_t **dev_stats,
4463e1bd7a2Ssjelinek 			    int *errp);
447181c2f42Smmusante int			dm_get_swapentries(swaptbl_t **, int *);
4483e1bd7a2Ssjelinek void			dm_get_usage_string(char *who, char *data, char **msg);
4493e1bd7a2Ssjelinek int			dm_inuse(char *dev_name, char **msg, dm_who_type_t who,
4503e1bd7a2Ssjelinek 			    int *errp);
451181c2f42Smmusante int			dm_inuse_swap(const char *dev_name, int *errp);
45246a2abf2Seschrock int			dm_isoverlapping(char *dev_name, char **msg, int *errp);
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4557c478bd9Sstevel@tonic-gate }
4567c478bd9Sstevel@tonic-gate #endif
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate #endif /* _LIBDISKMGT_H */
459