xref: /titanic_41/usr/src/cmd/lvm/rpc.metamhd/mhd_local.h (revision cde2885fdf538266ee2a3b08dee2d5075ce8fa2b)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_MHD_LOCAL_H
29 #define	_MHD_LOCAL_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <fcntl.h>
36 #include <errno.h>
37 #include <string.h>
38 #include <unistd.h>
39 #include <assert.h>
40 #include <stdarg.h>
41 #include <ctype.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <sys/sysmacros.h>
45 #include <sys/mkdev.h>
46 #include <sys/time.h>
47 #include <sys/dkio.h>
48 #include <sys/vtoc.h>
49 
50 #include <metamhd.h>
51 #include <thread.h>
52 
53 #ifdef	__cplusplus
54 extern "C" {
55 #endif
56 
57 /*
58  * millisecond time
59  */
60 typedef	u_longlong_t	mhd_msec_t;
61 
62 /*
63  * drive record
64  */
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 | \
79 				    DRIVE_CINFOING)
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 */
93 } mhd_drive_t;
94 
95 /*
96  * drive list
97  */
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 */
102 } mhd_drive_list_t;
103 #define	MHD_NULL_LIST	{ NULL, 0, 0 }
104 
105 /*
106  * drive set
107  */
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 */
117 } mhd_drive_set_t;
118 
119 /*
120  * debug stuff
121  */
122 #define	MHD_DEBUG	0
123 #ifdef	MHD_DEBUG
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 */
129 #define	MHDPRINTF(n)
130 #define	MHDPRINTF1(n)
131 #define	MHDPRINTF2(n)
132 #endif	/* ! MHD_DEBUG */
133 
134 /*
135  * extern functions
136  */
137 /* mhd_drive.c */
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,
143 			    mhd_error_t *mhep);
144 extern	int		mhd_state_set(mhd_drive_t *dp, mhd_state_t new_state,
145 			    mhd_error_t *mhep);
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);
150 
151 /* mhd_error.c */
152 extern	void		mhd_clrerror(mhd_error_t *mhep);
153 extern	int		mhd_error(mhd_error_t *mhep, int errnum, char *name);
154 /*PRINTFLIKE2*/
155 extern	void		mhde_perror(mhd_error_t *mhep, const char *fmt, ...);
156 /*PRINTFLIKE1*/
157 extern	void		mhd_perror(const char *fmt, ...);
158 /*PRINTFLIKE1*/
159 extern	void		mhd_eprintf(const char *fmt, ...);
160 
161 /* mhd_failfast.c */
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);
168 
169 /* mhd_init.c */
170 extern	void		mhd_exit(int eval);
171 extern	int		mhd_init(struct svc_req *rqstp, int amode,
172 			    mhd_error_t *mhep);
173 
174 /* mhd_ioctl.c */
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);
179 
180 /* mhd_mem.c */
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);
187 
188 /* mhd_set.c */
189 extern	void		mhd_add_drive_to_set(mhd_drive_set_t *sp,
190 			    mhd_drive_t *dp);
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,
198 			    mhd_error_t *mhep);
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);
204 
205 /* mhd_synch.c */
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,
210 			    mhd_msec_t to);
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);
219 
220 /* mhd_time.c */
221 extern	mhd_msec_t	mhd_time();
222 
223 #ifdef	__cplusplus
224 }
225 #endif
226 
227 #endif	/* _MHD_LOCAL_H */
228