xref: /onnv-gate/usr/src/uts/common/sys/lvm/md_notify.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _SYS_MD_NOTIFY_H
28*0Sstevel@tonic-gate #define	_SYS_MD_NOTIFY_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/lvm/mdvar.h>
33*0Sstevel@tonic-gate #include <sys/proc.h>
34*0Sstevel@tonic-gate #include <sys/lvm/md_mirror_shared.h>
35*0Sstevel@tonic-gate #include <sys/time.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #ifdef	__cplusplus
38*0Sstevel@tonic-gate extern "C" {
39*0Sstevel@tonic-gate #endif
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate #define	MD_EVENT_ID		(0xda1eab1e)
42*0Sstevel@tonic-gate #define	MD_ALLSETS		((ulong_t)0xffffffff)
43*0Sstevel@tonic-gate #define	MD_ALLDEVS		((ulong_t)0xffffffff)
44*0Sstevel@tonic-gate #define	MD_NOTIFY_HALT_TRIES	(4)
45*0Sstevel@tonic-gate #define	MD_NOTIFY_NAME_SIZE	(64)
46*0Sstevel@tonic-gate #define	MD_NOTIFY_REVISION	1
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate /* mdn_flags bits in struct md_event_queue */
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #define	MD_EVENT_QUEUE_DESTROY	(0x00000001)
51*0Sstevel@tonic-gate #define	MD_EVENT_QUEUE_INVALID	(0x00000002)
52*0Sstevel@tonic-gate #define	MD_EVENT_QUEUE_PERM	(0x00000004) /* do not delete when proc dies */
53*0Sstevel@tonic-gate #define	MD_EVENT_QUEUE_FULL	(0x00000008)
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate typedef enum md_event_type {
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate 	EQ_EMPTY = 0,
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate 	/* Configuration Changes */
60*0Sstevel@tonic-gate 	EQ_CREATE = 1,
61*0Sstevel@tonic-gate 	EQ_DELETE,
62*0Sstevel@tonic-gate 	EQ_ADD,
63*0Sstevel@tonic-gate 	EQ_REMOVE,
64*0Sstevel@tonic-gate 	EQ_REPLACE,
65*0Sstevel@tonic-gate 	EQ_GROW,
66*0Sstevel@tonic-gate 	EQ_RENAME_SRC,
67*0Sstevel@tonic-gate 	EQ_RENAME_DST,
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate 	EQ_MEDIATOR_ADD,
70*0Sstevel@tonic-gate 	EQ_MEDIATOR_DELETE,
71*0Sstevel@tonic-gate 	EQ_HOST_ADD,
72*0Sstevel@tonic-gate 	EQ_HOST_DELETE,
73*0Sstevel@tonic-gate 	EQ_DRIVE_ADD,
74*0Sstevel@tonic-gate 	EQ_DRIVE_DELETE,
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	/* State Changes */
77*0Sstevel@tonic-gate 	EQ_INIT_START = 0x00000400,
78*0Sstevel@tonic-gate 	EQ_INIT_FAILED,
79*0Sstevel@tonic-gate 	EQ_INIT_FATAL,
80*0Sstevel@tonic-gate 	EQ_INIT_SUCCESS,
81*0Sstevel@tonic-gate 	EQ_IOERR,
82*0Sstevel@tonic-gate 	EQ_ERRED,
83*0Sstevel@tonic-gate 	EQ_LASTERRED,
84*0Sstevel@tonic-gate 	EQ_OK,
85*0Sstevel@tonic-gate 	EQ_ENABLE,
86*0Sstevel@tonic-gate 	EQ_RESYNC_START,
87*0Sstevel@tonic-gate 	EQ_RESYNC_FAILED,
88*0Sstevel@tonic-gate 	EQ_RESYNC_SUCCESS,	/* resync has succeeded */
89*0Sstevel@tonic-gate 	EQ_RESYNC_DONE,		/* resync completed */
90*0Sstevel@tonic-gate 	EQ_HOTSPARED,		/* hot spare aquired for use */
91*0Sstevel@tonic-gate 	EQ_HS_FREED,		/* hotspare no longer in use */
92*0Sstevel@tonic-gate 	EQ_HS_CHANGED,		/* change of metadevice hotspare pool */
93*0Sstevel@tonic-gate 	EQ_TAKEOVER,
94*0Sstevel@tonic-gate 	EQ_RELEASE,
95*0Sstevel@tonic-gate 	EQ_OPEN_FAIL,
96*0Sstevel@tonic-gate 	EQ_OFFLINE,
97*0Sstevel@tonic-gate 	EQ_ONLINE,
98*0Sstevel@tonic-gate 	EQ_DETACH,
99*0Sstevel@tonic-gate 	EQ_DETACHING,
100*0Sstevel@tonic-gate 	EQ_ATTACH,
101*0Sstevel@tonic-gate 	EQ_ATTACHING,
102*0Sstevel@tonic-gate 	EQ_CHANGE,
103*0Sstevel@tonic-gate 	EQ_EXCHANGE,
104*0Sstevel@tonic-gate 	EQ_REGEN_START,
105*0Sstevel@tonic-gate 	EQ_REGEN_DONE,
106*0Sstevel@tonic-gate 	EQ_REGEN_FAILED,
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 	/* User defined event */
109*0Sstevel@tonic-gate 	EQ_USER = 0x00100000,
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 	/* Notify Specfic */
112*0Sstevel@tonic-gate 	EQ_NOTIFY_LOST,
113*0Sstevel@tonic-gate 	EQ_LAST }
114*0Sstevel@tonic-gate 	md_event_type_t;
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate typedef enum md_event_cmds {
117*0Sstevel@tonic-gate 	EQ_NONE =	0x00000000,
118*0Sstevel@tonic-gate 	EQ_ON =		0x00000001,
119*0Sstevel@tonic-gate 	EQ_OFF =	0x00000002,
120*0Sstevel@tonic-gate 	EQ_GET_NOWAIT =	0x00000010,
121*0Sstevel@tonic-gate 	EQ_GET_WAIT =	0x00000040,
122*0Sstevel@tonic-gate 	EQ_PUT =	0x00000020,
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate 	EQ_ALLVALID =	0x00000073
125*0Sstevel@tonic-gate 	}md_event_cmds_t;
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate typedef enum md_tags {
128*0Sstevel@tonic-gate 	TAG_EMPTY,
129*0Sstevel@tonic-gate 	TAG_METADEVICE,
130*0Sstevel@tonic-gate 	TAG_REPLICA,
131*0Sstevel@tonic-gate 	TAG_HSP,
132*0Sstevel@tonic-gate 	TAG_HS,
133*0Sstevel@tonic-gate 	TAG_SET,
134*0Sstevel@tonic-gate 	TAG_DRIVE,
135*0Sstevel@tonic-gate 	TAG_HOST,
136*0Sstevel@tonic-gate 	TAG_MEDIATOR,
137*0Sstevel@tonic-gate 	TAG_UNK,
138*0Sstevel@tonic-gate 	TAG_LAST
139*0Sstevel@tonic-gate } md_tags_t;
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
142*0Sstevel@tonic-gate #pragma pack(4)
143*0Sstevel@tonic-gate #endif
144*0Sstevel@tonic-gate typedef struct md_event_ioctl {
145*0Sstevel@tonic-gate 	MD_DRIVER
146*0Sstevel@tonic-gate 	md_error_t	mde;		/* error return */
147*0Sstevel@tonic-gate 	uint_t		mdn_magic;	/* magic number for structure */
148*0Sstevel@tonic-gate 	int		mdn_rev;	/* revision number */
149*0Sstevel@tonic-gate 	char		mdn_name[MD_NOTIFY_NAME_SIZE];
150*0Sstevel@tonic-gate 					/* queue name */
151*0Sstevel@tonic-gate 	int		mdn_flags;	/* ioctl flags */
152*0Sstevel@tonic-gate 	md_event_cmds_t	mdn_cmd;	/* command value */
153*0Sstevel@tonic-gate 	md_tags_t	mdn_tag;	/* object tag */
154*0Sstevel@tonic-gate 	set_t		mdn_set;	/* set number */
155*0Sstevel@tonic-gate 	md_dev64_t	mdn_dev;	/* device event occurred on */
156*0Sstevel@tonic-gate 	md_event_type_t	mdn_event;	/* event */
157*0Sstevel@tonic-gate 	u_longlong_t	mdn_user;	/* user defined event */
158*0Sstevel@tonic-gate 	md_timeval32_t	mdn_time;	/* time stamp of event */
159*0Sstevel@tonic-gate } md_event_ioctl_t;
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
162*0Sstevel@tonic-gate #pragma pack()
163*0Sstevel@tonic-gate #endif
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate /* ioctl flags */
166*0Sstevel@tonic-gate #define	EQ_Q_PERM	(0x00000001)	/* do not delete when proc dies */
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate #define	EQ_Q_ALLVALID	(0x00000001)	/* all valid notify ioctl flags */
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate typedef enum notify_cmds_t
171*0Sstevel@tonic-gate 	{ EQ_LIST_ADD = 1, EQ_LIST_DELETE }
172*0Sstevel@tonic-gate 	notify_cmds_t;
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate typedef struct notify {
175*0Sstevel@tonic-gate 	notify_cmds_t	mdn_cmd;	/* list function (add/delete) */
176*0Sstevel@tonic-gate 	md_tags_t	mdn_tag;	/* type of object */
177*0Sstevel@tonic-gate 	set_t		mdn_set;	/* set where event occurred */
178*0Sstevel@tonic-gate 	md_dev64_t	mdn_dev;	/* device that event occurred on */
179*0Sstevel@tonic-gate 	md_event_type_t	mdn_event;	/* event */
180*0Sstevel@tonic-gate }notify_t;
181*0Sstevel@tonic-gate 
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate #ifdef _KERNEL
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate #define	NOTIFY_MD(tag, set, dev, event) 				\
186*0Sstevel@tonic-gate 	(void) md_notify_interface(EQ_PUT, (tag), (set), (dev), (event))
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate #define	SE_NOTIFY(se_class, se_subclass, tag, set, dev)		\
189*0Sstevel@tonic-gate 	svm_gen_sysevent((se_class), (se_subclass), (tag), (set), (dev))
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate typedef struct md_event {
192*0Sstevel@tonic-gate 	struct md_event *mdn_next;	/* pointer to next element */
193*0Sstevel@tonic-gate 	md_tags_t	mdn_tag;	/* object type */
194*0Sstevel@tonic-gate 	set_t		mdn_set;	/* set where event occurred */
195*0Sstevel@tonic-gate 	md_dev64_t	mdn_dev;	/* device that event occurred on */
196*0Sstevel@tonic-gate 	md_event_type_t	mdn_event;	/* event */
197*0Sstevel@tonic-gate 	u_longlong_t	mdn_user;	/* user defined event */
198*0Sstevel@tonic-gate 	struct timeval	mdn_time;	/* time stamp of event */
199*0Sstevel@tonic-gate }md_event_t;
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate typedef struct md_event_queue {
202*0Sstevel@tonic-gate 	struct md_event_queue	*mdn_nextq;	/* next event queue */
203*0Sstevel@tonic-gate 	char		mdn_name[MD_NOTIFY_NAME_SIZE];
204*0Sstevel@tonic-gate 					/* queue name */
205*0Sstevel@tonic-gate 	int		mdn_flags;	/* queue flags */
206*0Sstevel@tonic-gate 	pid_t		mdn_pid;	/* pid that created the queue */
207*0Sstevel@tonic-gate 	proc_t		*mdn_proc;	/* process that created the queue */
208*0Sstevel@tonic-gate 	uid_t		mdn_uid;	/* uid of queue creator */
209*0Sstevel@tonic-gate 	size_t		mdn_size;	/* size of the queue in elements */
210*0Sstevel@tonic-gate 	md_event_t	*mdn_front;	/* front element in queue */
211*0Sstevel@tonic-gate 	md_event_t	*mdn_tail;	/* last element of queue */
212*0Sstevel@tonic-gate 	int		mdn_waiting;	/* number of process waiting */
213*0Sstevel@tonic-gate 	kcondvar_t	mdn_cv;		/* waiting condition varaible */
214*0Sstevel@tonic-gate } md_event_queue_t;
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate /*
217*0Sstevel@tonic-gate  * The remainder of this file defines items that are used for testing
218*0Sstevel@tonic-gate  * md_notify.
219*0Sstevel@tonic-gate  */
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate /*
222*0Sstevel@tonic-gate  * Named services for testing
223*0Sstevel@tonic-gate  */
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate #define	MD_NOTIFY_REAP_OFF	"notify turn reap off"
226*0Sstevel@tonic-gate #define	MD_NOTIFY_REAP_ON	"notify turn reap on"
227*0Sstevel@tonic-gate #define	MD_NOTIFY_TEST_STATS	"notify test statistics"
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate /*
230*0Sstevel@tonic-gate  * The MD_NOTIFY_TEST_STATS named service can be invoked to get md_notify
231*0Sstevel@tonic-gate  * to set the values of this structure.  The md_tnotify module uses this
232*0Sstevel@tonic-gate  * structure.
233*0Sstevel@tonic-gate  */
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate typedef struct md_notify_stats {
236*0Sstevel@tonic-gate 	kmutex_t	*mds_eventq_mx;	/* Address of mutex protecting */
237*0Sstevel@tonic-gate 					/*   event queue. */
238*0Sstevel@tonic-gate 	int		mds_max_queue;	/* Max. # events in notify queue. */
239*0Sstevel@tonic-gate 	int		mds_reap;	/* events since last reap. */
240*0Sstevel@tonic-gate 	int		mds_reap_count;	/* # events between reaps. */
241*0Sstevel@tonic-gate 	int		mds_reap_off;	/* non-zero -> reaping is off. */
242*0Sstevel@tonic-gate } md_notify_stats_t;
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate #endif	/* _KERNEL */
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate #ifdef	__cplusplus
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate #endif
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate #endif	/* _SYS_MD_NOTIFY_H */
251