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