xref: /titanic_41/usr/src/cmd/lvm/rpc.metamhd/mhd_local.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1994, 2000, 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_MHD_LOCAL_H
28 #define	_MHD_LOCAL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <fcntl.h>
35 #include <errno.h>
36 #include <string.h>
37 #include <unistd.h>
38 #include <assert.h>
39 #include <stdarg.h>
40 #include <ctype.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <sys/sysmacros.h>
44 #include <sys/mkdev.h>
45 #include <sys/time.h>
46 #include <sys/dkio.h>
47 #include <sys/vtoc.h>
48 
49 #include <metamhd.h>
50 #include <thread.h>
51 
52 #ifdef	__cplusplus
53 extern "C" {
54 #endif
55 
56 /*
57  * millisecond time
58  */
59 typedef	ulonglong_t	mhd_msec_t;
60 
61 /*
62  * drive record
63  */
64 typedef	uint_t	mhd_state_t;
65 #define	DRIVE_IDLE		0x0000	/* exclusive state */
66 #define	DRIVE_ERRORED		0x0001	/* exclusive state */
67 #define	DRIVE_IDLING		0x0002	/* exclusive state */
68 #define	DRIVE_RESERVING		0x0004	/* exclusive state */
69 #define	DRIVE_FAILFASTING	0x0008	/* exclusive state */
70 #define	DRIVE_RELEASING		0x0010	/* exclusive state */
71 #define	DRIVE_EXCLUSIVE_STATES	0x00ff	/* all exclusive states */
72 #define	DRIVE_PROBING		0x0100
73 #define	DRIVE_STATUSING		0x0200
74 #define	DRIVE_SERIALING		0x0400
75 #define	DRIVE_VTOCING		0x0800
76 #define	DRIVE_CINFOING		0x1000
77 #define	DRIVE_IDENTING		(DRIVE_SERIALING | DRIVE_VTOCING | \
78 				    DRIVE_CINFOING)
79 #define	DRIVE_IS_IDLE(dp)	(((dp)->dr_state == DRIVE_IDLE) || \
80 				    ((dp)->dr_state == DRIVE_ERRORED))
81 typedef struct mhd_drive {
82 	struct mhd_drive_set *dr_sp;	/* back pointer to set */
83 	char		*dr_rname;	/* raw device name */
84 	char		*dr_rname0;	/* slice 0 raw device name */
85 	cond_t		dr_cv;		/* synchronization */
86 	thread_t	dr_thread;	/* daemon thread */
87 	int		dr_fd;		/* open slice 0 */
88 	mhd_state_t	dr_state;	/* drive state */
89 	int		dr_errnum;	/* errno for DRIVE_ERRORED */
90 	mhd_msec_t	dr_time;	/* last successful probe time */
91 	mhd_drive_id_t	dr_drive_id;	/* unique drive identifier */
92 } mhd_drive_t;
93 
94 /*
95  * drive list
96  */
97 typedef	struct mhd_drive_list {
98 	mhd_drive_t	**dl_drives;	/* allocated list */
99 	size_t		dl_alloc;	/* amount allocated */
100 	size_t		dl_ndrive;	/* amount used */
101 } mhd_drive_list_t;
102 #define	MHD_NULL_LIST	{ NULL, 0, 0 }
103 
104 /*
105  * drive set
106  */
107 typedef	struct mhd_drive_set {
108 	char		*sr_name;	/* set name */
109 	mutex_t		sr_mx;		/* set mutex */
110 	cond_t		sr_cv;		/* synchronization */
111 	mhd_opts_t	sr_options;	/* common options */
112 	mhd_mhiargs_t	sr_timeouts;	/* reservation timeouts */
113 	mhd_ff_mode_t	sr_ff_mode;	/* failfast mode */
114 	int		sr_ff;		/* failfast device descriptor */
115 	mhd_drive_list_t sr_drives;	/* drives in set */
116 } mhd_drive_set_t;
117 
118 /*
119  * debug stuff
120  */
121 #define	MHD_DEBUG	0
122 #ifdef	MHD_DEBUG
123 extern	int	mhd_debug;
124 #define	MHDPRINTF(n)	if (mhd_debug > 0) mhd_eprintf n
125 #define	MHDPRINTF1(n)	if (mhd_debug > 1) mhd_eprintf n
126 #define	MHDPRINTF2(n)	if (mhd_debug > 2) mhd_eprintf n
127 #else	/* ! MHD_DEBUG */
128 #define	MHDPRINTF(n)
129 #define	MHDPRINTF1(n)
130 #define	MHDPRINTF2(n)
131 #endif	/* ! MHD_DEBUG */
132 
133 /*
134  * extern functions
135  */
136 /* mhd_drive.c */
137 extern	const mhd_drive_list_t	mhd_null_list;
138 extern	void		mhd_add_drive(mhd_drive_list_t *dlp, mhd_drive_t *dp);
139 extern	void		mhd_del_drive(mhd_drive_list_t *dlp, mhd_drive_t *dp);
140 extern	void		mhd_free_list(mhd_drive_list_t *dlp);
141 extern	int		mhd_state(mhd_drive_t *dp, mhd_state_t new_state,
142 			    mhd_error_t *mhep);
143 extern	int		mhd_state_set(mhd_drive_t *dp, mhd_state_t new_state,
144 			    mhd_error_t *mhep);
145 extern	int		mhd_idle(mhd_drive_t *dp, mhd_error_t *mhep);
146 extern	mhd_drive_t	*mhd_create_drive(mhd_drive_set_t *defaultsp,
147 			    char *rname, int *fdp, mhd_error_t *mhep);
148 extern	int		mhd_create_drives(char *path, mhd_error_t *mhep);
149 
150 /* mhd_error.c */
151 extern	void		mhd_clrerror(mhd_error_t *mhep);
152 extern	int		mhd_error(mhd_error_t *mhep, int errnum, char *name);
153 /*PRINTFLIKE2*/
154 extern	void		mhde_perror(mhd_error_t *mhep, const char *fmt, ...);
155 /*PRINTFLIKE1*/
156 extern	void		mhd_perror(const char *fmt, ...);
157 /*PRINTFLIKE1*/
158 extern	void		mhd_eprintf(const char *fmt, ...);
159 
160 /* mhd_failfast.c */
161 extern	int		mhd_ff_disarm(mhd_drive_set_t *sp, mhd_error_t *mhep);
162 extern	int		mhd_ff_open(mhd_drive_set_t *sp, mhd_error_t *mhep);
163 extern	int		mhd_ff_close(mhd_drive_set_t *sp, mhd_error_t *mhep);
164 extern	int		mhd_ff_rearm(mhd_drive_set_t *sp, mhd_error_t *mhep);
165 extern	void		mhd_ff_die(mhd_drive_set_t *sp);
166 extern	void		mhd_ff_check(mhd_drive_set_t *sp);
167 
168 /* mhd_init.c */
169 extern	void		mhd_exit(int eval);
170 extern	int		mhd_init(struct svc_req *rqstp, int amode,
171 			    mhd_error_t *mhep);
172 
173 /* mhd_ioctl.c */
174 extern	int		tk_own(mhd_set_t *mhsp, mhd_error_t *mhep);
175 extern	int		rel_own(mhd_set_t *mhsp, mhd_error_t *mhep);
176 extern	int		get_status(mhd_status_args_t *argsp,
177 			    mhd_status_res_t *resp);
178 
179 /* mhd_mem.c */
180 extern	void		*Malloc(size_t s);
181 extern	void		*Zalloc(size_t s);
182 extern	void		*Realloc(void *p, size_t s);
183 extern	void		*Calloc(size_t n, size_t s);
184 extern	char		*Strdup(const char *p);
185 extern	void		Free(void *p);
186 
187 /* mhd_set.c */
188 extern	void		mhd_add_drive_to_set(mhd_drive_set_t *sp,
189 			    mhd_drive_t *dp);
190 extern	void		mhd_del_drive_from_set(mhd_drive_t *dp);
191 extern	mhd_drive_set_t	*mhd_create_set(mhd_set_t *mhsp, mhd_opts_t options,
192 			    mhd_drive_list_t *dlp, mhd_error_t *mhep);
193 extern	mhd_drive_t	*mhd_find_drive(char *rname);
194 extern	int		mhd_list_drives(char *path, mhd_did_flags_t flags,
195 			    mhd_list_res_t *resultsp, mhd_error_t *mhep);
196 extern	int		mhd_release_drives(mhd_set_t *mhsp, mhd_opts_t options,
197 			    mhd_error_t *mhep);
198 extern	int		mhd_reserve_drives(mhd_set_t *mhsp,
199 			    mhd_mhiargs_t *timeoutp, mhd_ff_mode_t ff_mode,
200 			    mhd_opts_t options, mhd_error_t *mhep);
201 extern	int		mhd_status_drives(mhd_set_t *mhsp, mhd_opts_t options,
202 			    mhd_drive_status_t **status, mhd_error_t *mhep);
203 
204 /* mhd_synch.c */
205 extern	void		mhd_cv_init(cond_t *cvp);
206 extern	void		mhd_cv_destroy(cond_t *cvp);
207 extern	void		mhd_cv_wait(cond_t *cvp, mutex_t *mp);
208 extern	void		mhd_cv_timedwait(cond_t *cvp, mutex_t *mp,
209 			    mhd_msec_t to);
210 extern	void		mhd_cv_broadcast(cond_t *cvp);
211 extern	void		mhd_mx_init(mutex_t *mp);
212 extern	void		mhd_mx_destroy(mutex_t *mp);
213 extern	void		mhd_mx_lock(mutex_t *mp);
214 extern	void		mhd_mx_unlock(mutex_t *mp);
215 extern	void		mhd_rw_rdlock(rwlock_t *rwlp);
216 extern	void		mhd_rw_wrlock(rwlock_t *rwlp);
217 extern	void		mhd_rw_unlock(rwlock_t *rwlp);
218 
219 /* mhd_time.c */
220 extern	mhd_msec_t	mhd_time();
221 
222 #ifdef	__cplusplus
223 }
224 #endif
225 
226 #endif	/* _MHD_LOCAL_H */
227