xref: /onnv-gate/usr/src/cmd/lvm/rpc.metamhd/mhd_local.h (revision 132:e3f7eaf7dde4)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*132Srobinson 
230Sstevel@tonic-gate /*
24*132Srobinson  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25*132Srobinson  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #ifndef	_MHD_LOCAL_H
290Sstevel@tonic-gate #define	_MHD_LOCAL_H
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <stdio.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <fcntl.h>
360Sstevel@tonic-gate #include <errno.h>
370Sstevel@tonic-gate #include <string.h>
380Sstevel@tonic-gate #include <unistd.h>
390Sstevel@tonic-gate #include <assert.h>
400Sstevel@tonic-gate #include <stdarg.h>
410Sstevel@tonic-gate #include <ctype.h>
420Sstevel@tonic-gate #include <sys/types.h>
430Sstevel@tonic-gate #include <sys/stat.h>
440Sstevel@tonic-gate #include <sys/sysmacros.h>
450Sstevel@tonic-gate #include <sys/mkdev.h>
460Sstevel@tonic-gate #include <sys/time.h>
470Sstevel@tonic-gate #include <sys/dkio.h>
480Sstevel@tonic-gate #include <sys/vtoc.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #include <metamhd.h>
510Sstevel@tonic-gate #include <thread.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #ifdef	__cplusplus
540Sstevel@tonic-gate extern "C" {
550Sstevel@tonic-gate #endif
560Sstevel@tonic-gate 
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate  * millisecond time
590Sstevel@tonic-gate  */
60*132Srobinson typedef	u_longlong_t	mhd_msec_t;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * drive record
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate typedef	uint_t	mhd_state_t;
660Sstevel@tonic-gate #define	DRIVE_IDLE		0x0000	/* exclusive state */
670Sstevel@tonic-gate #define	DRIVE_ERRORED		0x0001	/* exclusive state */
680Sstevel@tonic-gate #define	DRIVE_IDLING		0x0002	/* exclusive state */
690Sstevel@tonic-gate #define	DRIVE_RESERVING		0x0004	/* exclusive state */
700Sstevel@tonic-gate #define	DRIVE_FAILFASTING	0x0008	/* exclusive state */
710Sstevel@tonic-gate #define	DRIVE_RELEASING		0x0010	/* exclusive state */
720Sstevel@tonic-gate #define	DRIVE_EXCLUSIVE_STATES	0x00ff	/* all exclusive states */
730Sstevel@tonic-gate #define	DRIVE_PROBING		0x0100
740Sstevel@tonic-gate #define	DRIVE_STATUSING		0x0200
750Sstevel@tonic-gate #define	DRIVE_SERIALING		0x0400
760Sstevel@tonic-gate #define	DRIVE_VTOCING		0x0800
770Sstevel@tonic-gate #define	DRIVE_CINFOING		0x1000
780Sstevel@tonic-gate #define	DRIVE_IDENTING		(DRIVE_SERIALING | DRIVE_VTOCING | \
790Sstevel@tonic-gate 				    DRIVE_CINFOING)
800Sstevel@tonic-gate #define	DRIVE_IS_IDLE(dp)	(((dp)->dr_state == DRIVE_IDLE) || \
810Sstevel@tonic-gate 				    ((dp)->dr_state == DRIVE_ERRORED))
820Sstevel@tonic-gate typedef struct mhd_drive {
830Sstevel@tonic-gate 	struct mhd_drive_set *dr_sp;	/* back pointer to set */
840Sstevel@tonic-gate 	char		*dr_rname;	/* raw device name */
850Sstevel@tonic-gate 	char		*dr_rname0;	/* slice 0 raw device name */
860Sstevel@tonic-gate 	cond_t		dr_cv;		/* synchronization */
870Sstevel@tonic-gate 	thread_t	dr_thread;	/* daemon thread */
880Sstevel@tonic-gate 	int		dr_fd;		/* open slice 0 */
890Sstevel@tonic-gate 	mhd_state_t	dr_state;	/* drive state */
900Sstevel@tonic-gate 	int		dr_errnum;	/* errno for DRIVE_ERRORED */
910Sstevel@tonic-gate 	mhd_msec_t	dr_time;	/* last successful probe time */
920Sstevel@tonic-gate 	mhd_drive_id_t	dr_drive_id;	/* unique drive identifier */
930Sstevel@tonic-gate } mhd_drive_t;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate  * drive list
970Sstevel@tonic-gate  */
980Sstevel@tonic-gate typedef	struct mhd_drive_list {
990Sstevel@tonic-gate 	mhd_drive_t	**dl_drives;	/* allocated list */
1000Sstevel@tonic-gate 	size_t		dl_alloc;	/* amount allocated */
1010Sstevel@tonic-gate 	size_t		dl_ndrive;	/* amount used */
1020Sstevel@tonic-gate } mhd_drive_list_t;
1030Sstevel@tonic-gate #define	MHD_NULL_LIST	{ NULL, 0, 0 }
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * drive set
1070Sstevel@tonic-gate  */
1080Sstevel@tonic-gate typedef	struct mhd_drive_set {
1090Sstevel@tonic-gate 	char		*sr_name;	/* set name */
1100Sstevel@tonic-gate 	mutex_t		sr_mx;		/* set mutex */
1110Sstevel@tonic-gate 	cond_t		sr_cv;		/* synchronization */
1120Sstevel@tonic-gate 	mhd_opts_t	sr_options;	/* common options */
1130Sstevel@tonic-gate 	mhd_mhiargs_t	sr_timeouts;	/* reservation timeouts */
1140Sstevel@tonic-gate 	mhd_ff_mode_t	sr_ff_mode;	/* failfast mode */
1150Sstevel@tonic-gate 	int		sr_ff;		/* failfast device descriptor */
1160Sstevel@tonic-gate 	mhd_drive_list_t sr_drives;	/* drives in set */
1170Sstevel@tonic-gate } mhd_drive_set_t;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate  * debug stuff
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate #define	MHD_DEBUG	0
1230Sstevel@tonic-gate #ifdef	MHD_DEBUG
1240Sstevel@tonic-gate extern	int	mhd_debug;
1250Sstevel@tonic-gate #define	MHDPRINTF(n)	if (mhd_debug > 0) mhd_eprintf n
1260Sstevel@tonic-gate #define	MHDPRINTF1(n)	if (mhd_debug > 1) mhd_eprintf n
1270Sstevel@tonic-gate #define	MHDPRINTF2(n)	if (mhd_debug > 2) mhd_eprintf n
1280Sstevel@tonic-gate #else	/* ! MHD_DEBUG */
1290Sstevel@tonic-gate #define	MHDPRINTF(n)
1300Sstevel@tonic-gate #define	MHDPRINTF1(n)
1310Sstevel@tonic-gate #define	MHDPRINTF2(n)
1320Sstevel@tonic-gate #endif	/* ! MHD_DEBUG */
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate  * extern functions
1360Sstevel@tonic-gate  */
1370Sstevel@tonic-gate /* mhd_drive.c */
1380Sstevel@tonic-gate extern	const mhd_drive_list_t	mhd_null_list;
1390Sstevel@tonic-gate extern	void		mhd_add_drive(mhd_drive_list_t *dlp, mhd_drive_t *dp);
1400Sstevel@tonic-gate extern	void		mhd_del_drive(mhd_drive_list_t *dlp, mhd_drive_t *dp);
1410Sstevel@tonic-gate extern	void		mhd_free_list(mhd_drive_list_t *dlp);
1420Sstevel@tonic-gate extern	int		mhd_state(mhd_drive_t *dp, mhd_state_t new_state,
1430Sstevel@tonic-gate 			    mhd_error_t *mhep);
1440Sstevel@tonic-gate extern	int		mhd_state_set(mhd_drive_t *dp, mhd_state_t new_state,
1450Sstevel@tonic-gate 			    mhd_error_t *mhep);
1460Sstevel@tonic-gate extern	int		mhd_idle(mhd_drive_t *dp, mhd_error_t *mhep);
1470Sstevel@tonic-gate extern	mhd_drive_t	*mhd_create_drive(mhd_drive_set_t *defaultsp,
1480Sstevel@tonic-gate 			    char *rname, int *fdp, mhd_error_t *mhep);
1490Sstevel@tonic-gate extern	int		mhd_create_drives(char *path, mhd_error_t *mhep);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate /* mhd_error.c */
1520Sstevel@tonic-gate extern	void		mhd_clrerror(mhd_error_t *mhep);
1530Sstevel@tonic-gate extern	int		mhd_error(mhd_error_t *mhep, int errnum, char *name);
1540Sstevel@tonic-gate /*PRINTFLIKE2*/
1550Sstevel@tonic-gate extern	void		mhde_perror(mhd_error_t *mhep, const char *fmt, ...);
1560Sstevel@tonic-gate /*PRINTFLIKE1*/
1570Sstevel@tonic-gate extern	void		mhd_perror(const char *fmt, ...);
1580Sstevel@tonic-gate /*PRINTFLIKE1*/
1590Sstevel@tonic-gate extern	void		mhd_eprintf(const char *fmt, ...);
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /* mhd_failfast.c */
1620Sstevel@tonic-gate extern	int		mhd_ff_disarm(mhd_drive_set_t *sp, mhd_error_t *mhep);
1630Sstevel@tonic-gate extern	int		mhd_ff_open(mhd_drive_set_t *sp, mhd_error_t *mhep);
1640Sstevel@tonic-gate extern	int		mhd_ff_close(mhd_drive_set_t *sp, mhd_error_t *mhep);
1650Sstevel@tonic-gate extern	int		mhd_ff_rearm(mhd_drive_set_t *sp, mhd_error_t *mhep);
1660Sstevel@tonic-gate extern	void		mhd_ff_die(mhd_drive_set_t *sp);
1670Sstevel@tonic-gate extern	void		mhd_ff_check(mhd_drive_set_t *sp);
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate /* mhd_init.c */
1700Sstevel@tonic-gate extern	void		mhd_exit(int eval);
1710Sstevel@tonic-gate extern	int		mhd_init(struct svc_req *rqstp, int amode,
1720Sstevel@tonic-gate 			    mhd_error_t *mhep);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate /* mhd_ioctl.c */
1750Sstevel@tonic-gate extern	int		tk_own(mhd_set_t *mhsp, mhd_error_t *mhep);
1760Sstevel@tonic-gate extern	int		rel_own(mhd_set_t *mhsp, mhd_error_t *mhep);
1770Sstevel@tonic-gate extern	int		get_status(mhd_status_args_t *argsp,
1780Sstevel@tonic-gate 			    mhd_status_res_t *resp);
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate /* mhd_mem.c */
1810Sstevel@tonic-gate extern	void		*Malloc(size_t s);
1820Sstevel@tonic-gate extern	void		*Zalloc(size_t s);
1830Sstevel@tonic-gate extern	void		*Realloc(void *p, size_t s);
1840Sstevel@tonic-gate extern	void		*Calloc(size_t n, size_t s);
1850Sstevel@tonic-gate extern	char		*Strdup(const char *p);
1860Sstevel@tonic-gate extern	void		Free(void *p);
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate /* mhd_set.c */
1890Sstevel@tonic-gate extern	void		mhd_add_drive_to_set(mhd_drive_set_t *sp,
1900Sstevel@tonic-gate 			    mhd_drive_t *dp);
1910Sstevel@tonic-gate extern	void		mhd_del_drive_from_set(mhd_drive_t *dp);
1920Sstevel@tonic-gate extern	mhd_drive_set_t	*mhd_create_set(mhd_set_t *mhsp, mhd_opts_t options,
1930Sstevel@tonic-gate 			    mhd_drive_list_t *dlp, mhd_error_t *mhep);
1940Sstevel@tonic-gate extern	mhd_drive_t	*mhd_find_drive(char *rname);
1950Sstevel@tonic-gate extern	int		mhd_list_drives(char *path, mhd_did_flags_t flags,
1960Sstevel@tonic-gate 			    mhd_list_res_t *resultsp, mhd_error_t *mhep);
1970Sstevel@tonic-gate extern	int		mhd_release_drives(mhd_set_t *mhsp, mhd_opts_t options,
1980Sstevel@tonic-gate 			    mhd_error_t *mhep);
1990Sstevel@tonic-gate extern	int		mhd_reserve_drives(mhd_set_t *mhsp,
2000Sstevel@tonic-gate 			    mhd_mhiargs_t *timeoutp, mhd_ff_mode_t ff_mode,
2010Sstevel@tonic-gate 			    mhd_opts_t options, mhd_error_t *mhep);
2020Sstevel@tonic-gate extern	int		mhd_status_drives(mhd_set_t *mhsp, mhd_opts_t options,
2030Sstevel@tonic-gate 			    mhd_drive_status_t **status, mhd_error_t *mhep);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate /* mhd_synch.c */
2060Sstevel@tonic-gate extern	void		mhd_cv_init(cond_t *cvp);
2070Sstevel@tonic-gate extern	void		mhd_cv_destroy(cond_t *cvp);
2080Sstevel@tonic-gate extern	void		mhd_cv_wait(cond_t *cvp, mutex_t *mp);
2090Sstevel@tonic-gate extern	void		mhd_cv_timedwait(cond_t *cvp, mutex_t *mp,
2100Sstevel@tonic-gate 			    mhd_msec_t to);
2110Sstevel@tonic-gate extern	void		mhd_cv_broadcast(cond_t *cvp);
2120Sstevel@tonic-gate extern	void		mhd_mx_init(mutex_t *mp);
2130Sstevel@tonic-gate extern	void		mhd_mx_destroy(mutex_t *mp);
2140Sstevel@tonic-gate extern	void		mhd_mx_lock(mutex_t *mp);
2150Sstevel@tonic-gate extern	void		mhd_mx_unlock(mutex_t *mp);
2160Sstevel@tonic-gate extern	void		mhd_rw_rdlock(rwlock_t *rwlp);
2170Sstevel@tonic-gate extern	void		mhd_rw_wrlock(rwlock_t *rwlp);
2180Sstevel@tonic-gate extern	void		mhd_rw_unlock(rwlock_t *rwlp);
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate /* mhd_time.c */
2210Sstevel@tonic-gate extern	mhd_msec_t	mhd_time();
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate #ifdef	__cplusplus
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate #endif
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate #endif	/* _MHD_LOCAL_H */
228