xref: /illumos-gate/usr/src/cmd/syseventd/daemons/syseventd/syseventd.h (revision f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01)
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) 2000-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_SYSEVENTD_H
28 #define	_SYSEVENTD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #define	MAX_SLM			20	/* Max sysevent loadable modules */
37 #define	MAX_MODCTL_RETRY	3	/* Maximum number of modctl retries */
38 					/* for free and get data */
39 #define	LOGEVENT_BUFSIZE	1024	/* message size greater than this */
40 					/* requires another kernel trip */
41 
42 /* Debug and errlogging stuff */
43 extern void syseventd_print(int level, char *message, ...);
44 extern void syseventd_err_print(char *message, ...);
45 extern void syseventd_exit(int status);
46 extern int debug_level;
47 
48 /*
49  * struct event_dispatch_pkg - per-client event dispatch package
50  */
51 struct event_dispatch_pkg {
52 	hrtime_t			start_time; /* start time ev delivery */
53 	struct sysevent_client		*scp;	/* Client data */
54 	sysevent_t			*ev;	/* event buf to deliver */
55 	sema_t				*completion_sema;
56 	int				completion_state;
57 	int				completion_status;
58 	int				retry_count; /* running retry counter */
59 };
60 
61 /* completion states */
62 #define	SE_NOT_DISPATCHED	0	/* Not yet dispatched to client */
63 #define	SE_OUTSTANDING		1	/* Dispatched and outstanding */
64 #define	SE_COMPLETE		2	/* Delivery complete */
65 
66 /*
67  * struct event_dispatchq - queue of dispatched event dispatch pacakges
68  */
69 struct event_dispatchq {
70 	struct event_dispatchq		*next;
71 	struct event_dispatch_pkg	*d_pkg;
72 };
73 
74 /*
75  * struct ev_completion - event completion data
76  *		This structure contains information regarding the
77  *		event delivery status for each client dispatched.
78  */
79 struct ev_completion {
80 	sysevent_t		*ev;		/* event */
81 	struct ev_completion   *next;
82 	struct event_dispatchq *dispatch_list; /* per_client dspatch packages */
83 	int			client_count;   /* Number of clients */
84 						/* event was dispatched to. */
85 	sema_t			client_sema;	/* Client completion */
86 						/* synchronization */
87 };
88 
89 /*
90  * module_t - SLM client module data
91  */
92 typedef struct module {
93 struct module *next;
94 	char *name;
95 	void *dlhandle;
96 	int (*deliver_event)();
97 	struct slm_mod_ops *(*event_mod_init)();
98 	void (*event_mod_fini)();
99 } module_t;
100 
101 /*
102  * struct sysevent_client - per-client data
103  */
104 struct sysevent_client {
105 	mutex_t			client_lock;	/* Lock for struct data */
106 	cond_t			client_cv;	/* Deliver cond variable */
107 	thread_t		tid;		/* Client deliver thread id */
108 	int			client_type;	/* SLM only */
109 	int			client_num;	/* Assigned at load time */
110 	int			client_flags;	/* Client flags */
111 	int			retry_limit;	/* Defined by slm_mod_ops */
112 	void			*client_data;	/* Client-type specific data */
113 	struct event_dispatchq	*eventq;	/* Client event queue */
114 };
115 
116 /* Client types */
117 #define	SLM_CLIENT	0
118 
119 /* Client flags */
120 #define	SE_CLIENT_UNLOADED	0
121 #define	SE_CLIENT_LOADED	0X00000001
122 #define	SE_CLIENT_SUSPENDED	0X00000002
123 #define	SE_CLIENT_THR_RUNNING	0X00000004
124 
125 #define	SE_CLIENT_IS_UNLOADED(scp) \
126 	((scp)->client_flags == SE_CLIENT_UNLOADED)
127 #define	SE_CLIENT_IS_LOADED(scp) \
128 	((scp)->client_flags & SE_CLIENT_LOADED)
129 #define	SE_CLIENT_IS_SUSPENDED(scp) \
130 	((scp)->client_flags & SE_CLIENT_SUSPENDED)
131 #define	SE_CLIENT_IS_THR_RUNNING(scp) \
132 	((scp)->client_flags & SE_CLIENT_THR_RUNNING)
133 
134 
135 #ifdef	__cplusplus
136 }
137 #endif
138 
139 #endif	/* _SYSEVENTD_H */
140