xref: /titanic_41/usr/src/cmd/lvm/rpc.mdcommd/mdmn_subr.h (revision ed5289f91b9bf164dccd6c75398362be77a4478d)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _MDMN_SUBR_H
28 #define	_MDMN_SUBR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <syslog.h>
33 #include <synch.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * This is the structure for the wakeup table for the initiator's side.
41  * We need a transportation handle in order to wake up the process waiting
42  * for the rpc call to complete
43  */
44 typedef struct mdmn_wti {
45 	md_mn_msgid_t	wti_id;
46 	mutex_t		wti_mx;
47 	time_t		wti_time;	/* for timeout purpose */
48 	SVCXPRT		*wti_transp;
49 	md_mn_result_t  *wti_result;
50 	char		*wti_args;
51 } mdmn_wti_t;
52 
53 extern mdmn_wti_t initiator_table[MD_MAXSETS][MD_MN_NCLASSES];
54 
55 
56 /*
57  * This is the structure for the wakeup table for the master.
58  * We need the ID for checking purpose, synchronizing cv's and a place to store
59  * a pointer to the results so the master can take over from here.
60  */
61 typedef struct mdmn_wtm {
62 	md_mn_msgid_t	wtm_id;
63 	mutex_t		wtm_mx;
64 	cond_t		wtm_cv;
65 	md_mn_nodeid_t	wtm_addr;
66 	md_mn_result_t	*wtm_result;
67 } mdmn_wtm_t;
68 
69 extern mdmn_wtm_t mdmn_master_table[MD_MAXSETS][MD_MN_NCLASSES];
70 
71 
72 /*
73  * This structure is only needed because we start a thread and we want to
74  * pass more than one argument to that thread.
75  * So we pack all the args into one structure and pass a pointer to it.
76  */
77 typedef struct md_mn_msg_and_transp {
78 	md_mn_msg_t	*mat_msg;
79 	SVCXPRT		*mat_transp;
80 } md_mn_msg_and_transp_t;
81 
82 #define	MAX_SUBMESSAGES 8
83 
84 #define	MAX_OUTERR	1024
85 
86 /*
87  * This is the message completion entry structure that stores the result
88  * for one message incore in an array and on disk
89  * Each entry is identified by the msgid being part of the result structure.
90  * The actual data needs to be stored in a separate pre-allocated field
91  * because the result structure only contains a pointer to stdout / stderr.
92  * mce_flags is set to:
93  *     MDMN_MCT_IN_PROGRESS - if a message is currently being handled and
94  *		no new message handler should be issued.
95  *    MDMN_MCT_DONE - if the message is completely processed and
96  *		the result is available
97  */
98 typedef struct md_mn_mce {
99 	md_mn_result_t  mce_result;
100 	char		mce_data[MAX_OUTERR];
101 	uint_t		mce_flags;
102 } md_mn_mce_t;
103 
104 /*
105  * We need to be able to store one result per each class and for each
106  * possible submessage.
107  * This makes our Message Completion Table mct for one diskset.
108  */
109 typedef struct md_mn_mct {
110 	md_mn_mce_t mct_mce[NNODES][MD_MN_NCLASSES][MAX_SUBMESSAGES];
111 } md_mn_mct_t;
112 
113 extern md_mn_mct_t *mct[];
114 extern int mdmn_mark_completion(md_mn_msg_t *msg, md_mn_result_t *result,
115     uint_t flag);
116 extern int mdmn_check_completion(md_mn_msg_t *msg, md_mn_result_t *result);
117 
118 /* here we find the MCT files on disk */
119 #define	MD_MN_MSG_COMP_TABLE	"/var/run/mct"
120 
121 /* the return values for mdmn_mark_completion and mdmn_check_completion */
122 #define	MDMN_MCT_NOT_DONE	0x0001
123 #define	MDMN_MCT_DONE		0x0002
124 #define	MDMN_MCT_ERROR		0x0004
125 #define	MDMN_MCT_IN_PROGRESS	0x0008
126 
127 /* the different states for md_mn_set_inited[] */
128 #define	MDMN_SET_MUTEXES	0x0001
129 #define	MDMN_SET_NODES		0x0002
130 #define	MDMN_SET_MCT		0x0004
131 #define	MDMN_SET_READY		(MDMN_SET_MUTEXES | MDMN_SET_NODES | \
132 				MDMN_SET_MCT)
133 
134 /* the different states of mdmn_busy[set][class] */
135 #define	MDMN_BUSY		0x0001
136 #define	MDMN_LOCKED		0x0002
137 #define	MDMN_SUSPEND_1		0x0004
138 #define	MDMN_SUSPEND_ALL	0x0008
139 
140 
141 extern mutex_t mdmn_busy_mutex[];
142 extern cond_t mdmn_busy_cv[];
143 extern struct md_set_desc *set_descriptor[];
144 
145 
146 /* Stuff for licensing / checking ip adresses */
147 typedef struct licensed_ip {
148 	union {
149 		in_addr_t	u_lip_ipv4;	/* a licensed ipv4 adress */
150 		in6_addr_t	u_lip_ipv6;	/* a licensed ipv6 adress */
151 	} lip_u;
152 	sa_family_t	lip_family;	/* indicator for IPv4/IPv6 */
153 	int		lip_cnt;	/* it's reference count */
154 } licensed_ip_t;
155 
156 #define	lip_ipv4 lip_u.u_lip_ipv4
157 #define	lip_ipv6 lip_u.u_lip_ipv6
158 
159 extern licensed_ip_t licensed_nodes[];
160 
161 extern bool_t	check_license(struct svc_req *rqstp, md_mn_nodeid_t chknid);
162 extern void	add_license(md_mnnode_desc *node);
163 extern void	rem_license(md_mnnode_desc *node);
164 
165 
166 /* needful things */
167 
168 extern bool_t	mdmn_is_class_busy(set_t setno, md_mn_msgclass_t class);
169 extern bool_t	mdmn_mark_class_busy(set_t setno, md_mn_msgclass_t class);
170 extern void	mdmn_mark_class_unbusy(set_t setno, md_mn_msgclass_t class);
171 
172 extern bool_t	mdmn_is_class_locked(set_t setno, md_mn_msgclass_t class);
173 extern void	mdmn_mark_class_locked(set_t setno, md_mn_msgclass_t class);
174 extern void	mdmn_mark_class_unlocked(set_t setno, md_mn_msgclass_t class);
175 
176 extern bool_t	mdmn_is_class_suspended(set_t setno, md_mn_msgclass_t class);
177 extern int	mdmn_mark_class_suspended(set_t setno, md_mn_msgclass_t class,
178 		    uint_t susptype);
179 extern void	mdmn_mark_class_resumed(set_t setno, md_mn_msgclass_t class,
180 		    uint_t susptype);
181 
182 extern void	commd_debug(uint_t debug_class, const char *message, ...);
183 extern void	dump_result(uint_t dbc, char *prefix, md_mn_result_t *res);
184 
185 
186 
187 /* routines for handling the wakeup table for the master (master_table) */
188 extern void	mdmn_set_master_table_res(set_t setno, md_mn_msgclass_t class,
189 		    md_mn_result_t  *res);
190 extern void	mdmn_set_master_table_id(set_t setno, md_mn_msgclass_t class,
191 		    md_mn_msgid_t *id);
192 extern void	mdmn_get_master_table_id(set_t setno, md_mn_msgclass_t class,
193 		    md_mn_msgid_t *id);
194 extern cond_t	*mdmn_get_master_table_cv(set_t setno, md_mn_msgclass_t class);
195 extern mutex_t	*mdmn_get_master_table_mx(set_t setno, md_mn_msgclass_t class);
196 extern md_mn_result_t	*mdmn_get_master_table_res(set_t setno,
197 			    md_mn_msgclass_t class);
198 extern void	mdmn_set_master_table_addr(set_t setno, md_mn_msgclass_t class,
199 		    md_mn_nodeid_t nid);
200 extern md_mn_nodeid_t	mdmn_get_master_table_addr(set_t setno,
201 			    md_mn_msgclass_t class);
202 
203 
204 /* routines for handling the wakeup table for the initiator (initiator_table) */
205 extern void	mdmn_register_initiator_table(set_t setno,
206 		    md_mn_msgclass_t class, md_mn_msg_t *msg, SVCXPRT *transp);
207 extern void	mdmn_unregister_initiator_table(set_t setno,
208 		    md_mn_msgclass_t class);
209 extern int	mdmn_check_initiator_table(set_t setno, md_mn_msgclass_t class);
210 extern void	mdmn_get_initiator_table_id(set_t setno, md_mn_msgclass_t class,
211 		    md_mn_msgid_t *id);
212 extern SVCXPRT	*mdmn_get_initiator_table_transp(set_t setno,
213 		    md_mn_msgclass_t class);
214 extern char	*mdmn_get_initiator_table_args(set_t setno,
215 		    md_mn_msgclass_t class);
216 extern cond_t	*mdmn_get_initiator_table_cv(set_t setno,
217 		    md_mn_msgclass_t class);
218 extern mutex_t	*mdmn_get_initiator_table_mx(set_t setno,
219 		    md_mn_msgclass_t class);
220 extern time_t	mdmn_get_initiator_table_time(set_t setno,
221 		    md_mn_msgclass_t class);
222 
223 /* the change log interface */
224 extern int	mdmn_log_msg(md_mn_msg_t *);
225 extern int	mdmn_flag_msg(md_mn_msg_t *, uint_t);
226 extern int	mdmn_unlog_msg(md_mn_msg_t *);
227 
228 #ifdef	__cplusplus
229 }
230 #endif
231 
232 #endif	/* _MDMN_SUBR_H */
233