4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include <sys/types.h>
44 #include <sys/sysmacros.h>
45 #include <sys/mkdev.h>
60 typedef u_longlong_t mhd_msec_t
;
65 typedef uint_t mhd_state_t
;
66 #define DRIVE_IDLE 0x0000 /* exclusive state */
67 #define DRIVE_ERRORED 0x0001 /* exclusive state */
68 #define DRIVE_IDLING 0x0002 /* exclusive state */
69 #define DRIVE_RESERVING 0x0004 /* exclusive state */
70 #define DRIVE_FAILFASTING 0x0008 /* exclusive state */
71 #define DRIVE_RELEASING 0x0010 /* exclusive state */
72 #define DRIVE_EXCLUSIVE_STATES 0x00ff /* all exclusive states */
73 #define DRIVE_PROBING 0x0100
74 #define DRIVE_STATUSING 0x0200
75 #define DRIVE_SERIALING 0x0400
76 #define DRIVE_VTOCING 0x0800
77 #define DRIVE_CINFOING 0x1000
78 #define DRIVE_IDENTING (DRIVE_SERIALING | DRIVE_VTOCING | \
80 #define DRIVE_IS_IDLE(dp) (((dp)->dr_state == DRIVE_IDLE) || \
81 ((dp)->dr_state == DRIVE_ERRORED))
82 typedef struct mhd_drive
{
83 struct mhd_drive_set
*dr_sp
; /* back pointer to set */
84 char *dr_rname
; /* raw device name */
85 char *dr_rname0
; /* slice 0 raw device name */
86 cond_t dr_cv
; /* synchronization */
87 thread_t dr_thread
; /* daemon thread */
88 int dr_fd
; /* open slice 0 */
89 mhd_state_t dr_state
; /* drive state */
90 int dr_errnum
; /* errno for DRIVE_ERRORED */
91 mhd_msec_t dr_time
; /* last successful probe time */
92 mhd_drive_id_t dr_drive_id
; /* unique drive identifier */
98 typedef struct mhd_drive_list
{
99 mhd_drive_t
**dl_drives
; /* allocated list */
100 size_t dl_alloc
; /* amount allocated */
101 size_t dl_ndrive
; /* amount used */
103 #define MHD_NULL_LIST { NULL, 0, 0 }
108 typedef struct mhd_drive_set
{
109 char *sr_name
; /* set name */
110 mutex_t sr_mx
; /* set mutex */
111 cond_t sr_cv
; /* synchronization */
112 mhd_opts_t sr_options
; /* common options */
113 mhd_mhiargs_t sr_timeouts
; /* reservation timeouts */
114 mhd_ff_mode_t sr_ff_mode
; /* failfast mode */
115 int sr_ff
; /* failfast device descriptor */
116 mhd_drive_list_t sr_drives
; /* drives in set */
124 extern int mhd_debug
;
125 #define MHDPRINTF(n) if (mhd_debug > 0) mhd_eprintf n
126 #define MHDPRINTF1(n) if (mhd_debug > 1) mhd_eprintf n
127 #define MHDPRINTF2(n) if (mhd_debug > 2) mhd_eprintf n
128 #else /* ! MHD_DEBUG */
130 #define MHDPRINTF1(n)
131 #define MHDPRINTF2(n)
132 #endif /* ! MHD_DEBUG */
138 extern const mhd_drive_list_t mhd_null_list
;
139 extern void mhd_add_drive(mhd_drive_list_t
*dlp
, mhd_drive_t
*dp
);
140 extern void mhd_del_drive(mhd_drive_list_t
*dlp
, mhd_drive_t
*dp
);
141 extern void mhd_free_list(mhd_drive_list_t
*dlp
);
142 extern int mhd_state(mhd_drive_t
*dp
, mhd_state_t new_state
,
144 extern int mhd_state_set(mhd_drive_t
*dp
, mhd_state_t new_state
,
146 extern int mhd_idle(mhd_drive_t
*dp
, mhd_error_t
*mhep
);
147 extern mhd_drive_t
*mhd_create_drive(mhd_drive_set_t
*defaultsp
,
148 char *rname
, int *fdp
, mhd_error_t
*mhep
);
149 extern int mhd_create_drives(char *path
, mhd_error_t
*mhep
);
152 extern void mhd_clrerror(mhd_error_t
*mhep
);
153 extern int mhd_error(mhd_error_t
*mhep
, int errnum
, char *name
);
155 extern void mhde_perror(mhd_error_t
*mhep
, const char *fmt
, ...);
157 extern void mhd_perror(const char *fmt
, ...);
159 extern void mhd_eprintf(const char *fmt
, ...);
162 extern int mhd_ff_disarm(mhd_drive_set_t
*sp
, mhd_error_t
*mhep
);
163 extern int mhd_ff_open(mhd_drive_set_t
*sp
, mhd_error_t
*mhep
);
164 extern int mhd_ff_close(mhd_drive_set_t
*sp
, mhd_error_t
*mhep
);
165 extern int mhd_ff_rearm(mhd_drive_set_t
*sp
, mhd_error_t
*mhep
);
166 extern void mhd_ff_die(mhd_drive_set_t
*sp
);
167 extern void mhd_ff_check(mhd_drive_set_t
*sp
);
170 extern void mhd_exit(int eval
);
171 extern int mhd_init(struct svc_req
*rqstp
, int amode
,
175 extern int tk_own(mhd_set_t
*mhsp
, mhd_error_t
*mhep
);
176 extern int rel_own(mhd_set_t
*mhsp
, mhd_error_t
*mhep
);
177 extern int get_status(mhd_status_args_t
*argsp
,
178 mhd_status_res_t
*resp
);
181 extern void *Malloc(size_t s
);
182 extern void *Zalloc(size_t s
);
183 extern void *Realloc(void *p
, size_t s
);
184 extern void *Calloc(size_t n
, size_t s
);
185 extern char *Strdup(const char *p
);
186 extern void Free(void *p
);
189 extern void mhd_add_drive_to_set(mhd_drive_set_t
*sp
,
191 extern void mhd_del_drive_from_set(mhd_drive_t
*dp
);
192 extern mhd_drive_set_t
*mhd_create_set(mhd_set_t
*mhsp
, mhd_opts_t options
,
193 mhd_drive_list_t
*dlp
, mhd_error_t
*mhep
);
194 extern mhd_drive_t
*mhd_find_drive(char *rname
);
195 extern int mhd_list_drives(char *path
, mhd_did_flags_t flags
,
196 mhd_list_res_t
*resultsp
, mhd_error_t
*mhep
);
197 extern int mhd_release_drives(mhd_set_t
*mhsp
, mhd_opts_t options
,
199 extern int mhd_reserve_drives(mhd_set_t
*mhsp
,
200 mhd_mhiargs_t
*timeoutp
, mhd_ff_mode_t ff_mode
,
201 mhd_opts_t options
, mhd_error_t
*mhep
);
202 extern int mhd_status_drives(mhd_set_t
*mhsp
, mhd_opts_t options
,
203 mhd_drive_status_t
**status
, mhd_error_t
*mhep
);
206 extern void mhd_cv_init(cond_t
*cvp
);
207 extern void mhd_cv_destroy(cond_t
*cvp
);
208 extern void mhd_cv_wait(cond_t
*cvp
, mutex_t
*mp
);
209 extern void mhd_cv_timedwait(cond_t
*cvp
, mutex_t
*mp
,
211 extern void mhd_cv_broadcast(cond_t
*cvp
);
212 extern void mhd_mx_init(mutex_t
*mp
);
213 extern void mhd_mx_destroy(mutex_t
*mp
);
214 extern void mhd_mx_lock(mutex_t
*mp
);
215 extern void mhd_mx_unlock(mutex_t
*mp
);
216 extern void mhd_rw_rdlock(rwlock_t
*rwlp
);
217 extern void mhd_rw_wrlock(rwlock_t
*rwlp
);
218 extern void mhd_rw_unlock(rwlock_t
*rwlp
);
221 extern mhd_msec_t
mhd_time();
227 #endif /* _MHD_LOCAL_H */