xref: /freebsd-src/sys/contrib/openzfs/module/os/freebsd/spl/callb.c (revision 15f0b8c309dea1dcb14d3e374686576ff68ac43f)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21eda14cbcSMatt Macy /*
22eda14cbcSMatt Macy  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23eda14cbcSMatt Macy  * Use is subject to license terms.
24eda14cbcSMatt Macy  */
25eda14cbcSMatt Macy 
26eda14cbcSMatt Macy #include <sys/types.h>
27eda14cbcSMatt Macy #include <sys/param.h>
28eda14cbcSMatt Macy #include <sys/time.h>
29eda14cbcSMatt Macy #include <sys/sysmacros.h>
30eda14cbcSMatt Macy #include <sys/systm.h>
31eda14cbcSMatt Macy #include <sys/proc.h>
32eda14cbcSMatt Macy #include <sys/mutex.h>
33eda14cbcSMatt Macy #include <sys/condvar.h>
34eda14cbcSMatt Macy #include <sys/callb.h>
35eda14cbcSMatt Macy #include <sys/kmem.h>
36eda14cbcSMatt Macy #include <sys/cmn_err.h>
37eda14cbcSMatt Macy #include <sys/debug.h>
38eda14cbcSMatt Macy #include <sys/kobj.h>
39eda14cbcSMatt Macy #include <sys/systm.h>	/* for delay() */
40eda14cbcSMatt Macy #include <sys/taskq.h>  /* For TASKQ_NAMELEN */
41eda14cbcSMatt Macy #include <sys/kernel.h>
42eda14cbcSMatt Macy 
43eda14cbcSMatt Macy #define	CB_MAXNAME	TASKQ_NAMELEN
44eda14cbcSMatt Macy 
45eda14cbcSMatt Macy /*
46eda14cbcSMatt Macy  * The callb mechanism provides generic event scheduling/echoing.
47eda14cbcSMatt Macy  * A callb function is registered and called on behalf of the event.
48eda14cbcSMatt Macy  */
49eda14cbcSMatt Macy typedef struct callb {
50eda14cbcSMatt Macy 	struct callb	*c_next; 	/* next in class or on freelist */
51eda14cbcSMatt Macy 	kthread_id_t	c_thread;	/* ptr to caller's thread struct */
52eda14cbcSMatt Macy 	char		c_flag;		/* info about the callb state */
53eda14cbcSMatt Macy 	uchar_t		c_class;	/* this callb's class */
54eda14cbcSMatt Macy 	kcondvar_t	c_done_cv;	/* signal callb completion */
55eda14cbcSMatt Macy 	boolean_t	(*c_func)(void *, int);
56eda14cbcSMatt Macy 					/* cb function: returns true if ok */
57eda14cbcSMatt Macy 	void		*c_arg;		/* arg to c_func */
58eda14cbcSMatt Macy 	char		c_name[CB_MAXNAME+1]; /* debug:max func name length */
59eda14cbcSMatt Macy } callb_t;
60eda14cbcSMatt Macy 
61eda14cbcSMatt Macy /*
62eda14cbcSMatt Macy  * callb c_flag bitmap definitions
63eda14cbcSMatt Macy  */
64eda14cbcSMatt Macy #define	CALLB_FREE		0x0
65eda14cbcSMatt Macy #define	CALLB_TAKEN		0x1
66eda14cbcSMatt Macy #define	CALLB_EXECUTING		0x2
67eda14cbcSMatt Macy 
68eda14cbcSMatt Macy /*
69eda14cbcSMatt Macy  * Basic structure for a callb table.
70eda14cbcSMatt Macy  * All callbs are organized into different class groups described
71eda14cbcSMatt Macy  * by ct_class array.
72eda14cbcSMatt Macy  * The callbs within a class are single-linked and normally run by a
73eda14cbcSMatt Macy  * serial execution.
74eda14cbcSMatt Macy  */
75eda14cbcSMatt Macy typedef struct callb_table {
76eda14cbcSMatt Macy 	kmutex_t ct_lock;		/* protect all callb states */
77eda14cbcSMatt Macy 	callb_t	*ct_freelist; 		/* free callb structures */
7816038816SMartin Matuska 	boolean_t ct_busy;		/* B_TRUE prevents additions */
79eda14cbcSMatt Macy 	kcondvar_t ct_busy_cv;		/* to wait for not busy    */
80eda14cbcSMatt Macy 	int	ct_ncallb; 		/* num of callbs allocated */
81eda14cbcSMatt Macy 	callb_t	*ct_first_cb[NCBCLASS];	/* ptr to 1st callb in a class */
82eda14cbcSMatt Macy } callb_table_t;
83eda14cbcSMatt Macy 
84eda14cbcSMatt Macy int callb_timeout_sec = CPR_KTHREAD_TIMEOUT_SEC;
85eda14cbcSMatt Macy 
86eda14cbcSMatt Macy static callb_id_t callb_add_common(boolean_t (*)(void *, int),
87eda14cbcSMatt Macy     void *, int, char *, kthread_id_t);
88eda14cbcSMatt Macy 
89eda14cbcSMatt Macy static callb_table_t callb_table;	/* system level callback table */
90eda14cbcSMatt Macy static callb_table_t *ct = &callb_table;
91eda14cbcSMatt Macy static kmutex_t	callb_safe_mutex;
92eda14cbcSMatt Macy callb_cpr_t	callb_cprinfo_safe = {
93eda14cbcSMatt Macy 	&callb_safe_mutex, CALLB_CPR_ALWAYS_SAFE, 0, {0, 0} };
94eda14cbcSMatt Macy 
95eda14cbcSMatt Macy /*
96eda14cbcSMatt Macy  * Init all callb tables in the system.
97eda14cbcSMatt Macy  */
98eda14cbcSMatt Macy static void
callb_init(void * dummy __unused)99eda14cbcSMatt Macy callb_init(void *dummy __unused)
100eda14cbcSMatt Macy {
10116038816SMartin Matuska 	callb_table.ct_busy = B_FALSE;	/* mark table open for additions */
102eda14cbcSMatt Macy 	mutex_init(&callb_safe_mutex, NULL, MUTEX_DEFAULT, NULL);
103eda14cbcSMatt Macy 	mutex_init(&callb_table.ct_lock, NULL, MUTEX_DEFAULT, NULL);
104eda14cbcSMatt Macy }
105eda14cbcSMatt Macy 
106eda14cbcSMatt Macy static void
callb_fini(void * dummy __unused)107eda14cbcSMatt Macy callb_fini(void *dummy __unused)
108eda14cbcSMatt Macy {
109eda14cbcSMatt Macy 	callb_t *cp;
110eda14cbcSMatt Macy 	int i;
111eda14cbcSMatt Macy 
112eda14cbcSMatt Macy 	mutex_enter(&ct->ct_lock);
113eda14cbcSMatt Macy 	for (i = 0; i < 16; i++) {
114eda14cbcSMatt Macy 		while ((cp = ct->ct_freelist) != NULL) {
115eda14cbcSMatt Macy 			ct->ct_freelist = cp->c_next;
116eda14cbcSMatt Macy 			ct->ct_ncallb--;
117eda14cbcSMatt Macy 			kmem_free(cp, sizeof (callb_t));
118eda14cbcSMatt Macy 		}
119eda14cbcSMatt Macy 		if (ct->ct_ncallb == 0)
120eda14cbcSMatt Macy 			break;
121eda14cbcSMatt Macy 		/* Not all callbacks finished, waiting for the rest. */
122eda14cbcSMatt Macy 		mutex_exit(&ct->ct_lock);
123eda14cbcSMatt Macy 		tsleep(ct, 0, "callb", hz / 4);
124eda14cbcSMatt Macy 		mutex_enter(&ct->ct_lock);
125eda14cbcSMatt Macy 	}
126eda14cbcSMatt Macy 	if (ct->ct_ncallb > 0)
127eda14cbcSMatt Macy 		printf("%s: Leaked %d callbacks!\n", __func__, ct->ct_ncallb);
128eda14cbcSMatt Macy 	mutex_exit(&ct->ct_lock);
129eda14cbcSMatt Macy 	mutex_destroy(&callb_safe_mutex);
130eda14cbcSMatt Macy 	mutex_destroy(&callb_table.ct_lock);
131eda14cbcSMatt Macy }
132eda14cbcSMatt Macy 
133eda14cbcSMatt Macy /*
134eda14cbcSMatt Macy  * callout_add() is called to register func() be called later.
135eda14cbcSMatt Macy  */
136eda14cbcSMatt Macy static callb_id_t
callb_add_common(boolean_t (* func)(void * arg,int code),void * arg,int class,char * name,kthread_id_t t)137eda14cbcSMatt Macy callb_add_common(boolean_t (*func)(void *arg, int code),
138eda14cbcSMatt Macy     void *arg, int class, char *name, kthread_id_t t)
139eda14cbcSMatt Macy {
140eda14cbcSMatt Macy 	callb_t *cp;
141eda14cbcSMatt Macy 
14216038816SMartin Matuska 	ASSERT3S(class, <, NCBCLASS);
143eda14cbcSMatt Macy 
144eda14cbcSMatt Macy 	mutex_enter(&ct->ct_lock);
145eda14cbcSMatt Macy 	while (ct->ct_busy)
146eda14cbcSMatt Macy 		cv_wait(&ct->ct_busy_cv, &ct->ct_lock);
147eda14cbcSMatt Macy 	if ((cp = ct->ct_freelist) == NULL) {
148eda14cbcSMatt Macy 		ct->ct_ncallb++;
149*15f0b8c3SMartin Matuska 		cp = kmem_zalloc(sizeof (callb_t), KM_SLEEP);
150eda14cbcSMatt Macy 	}
151eda14cbcSMatt Macy 	ct->ct_freelist = cp->c_next;
152eda14cbcSMatt Macy 	cp->c_thread = t;
153eda14cbcSMatt Macy 	cp->c_func = func;
154eda14cbcSMatt Macy 	cp->c_arg = arg;
155eda14cbcSMatt Macy 	cp->c_class = (uchar_t)class;
156eda14cbcSMatt Macy 	cp->c_flag |= CALLB_TAKEN;
157eda14cbcSMatt Macy #ifdef ZFS_DEBUG
158eda14cbcSMatt Macy 	if (strlen(name) > CB_MAXNAME)
159eda14cbcSMatt Macy 		cmn_err(CE_WARN, "callb_add: name of callback function '%s' "
160eda14cbcSMatt Macy 		    "too long -- truncated to %d chars",
161eda14cbcSMatt Macy 		    name, CB_MAXNAME);
162eda14cbcSMatt Macy #endif
163be181ee2SMartin Matuska 	(void) strlcpy(cp->c_name, name, sizeof (cp->c_name));
164eda14cbcSMatt Macy 
165eda14cbcSMatt Macy 	/*
166eda14cbcSMatt Macy 	 * Insert the new callb at the head of its class list.
167eda14cbcSMatt Macy 	 */
168eda14cbcSMatt Macy 	cp->c_next = ct->ct_first_cb[class];
169eda14cbcSMatt Macy 	ct->ct_first_cb[class] = cp;
170eda14cbcSMatt Macy 
171eda14cbcSMatt Macy 	mutex_exit(&ct->ct_lock);
172eda14cbcSMatt Macy 	return ((callb_id_t)cp);
173eda14cbcSMatt Macy }
174eda14cbcSMatt Macy 
175eda14cbcSMatt Macy /*
176eda14cbcSMatt Macy  * The default function to add an entry to the callback table.  Since
177eda14cbcSMatt Macy  * it uses curthread as the thread identifier to store in the table,
178eda14cbcSMatt Macy  * it should be used for the normal case of a thread which is calling
179eda14cbcSMatt Macy  * to add ITSELF to the table.
180eda14cbcSMatt Macy  */
181eda14cbcSMatt Macy callb_id_t
callb_add(boolean_t (* func)(void * arg,int code),void * arg,int class,char * name)182eda14cbcSMatt Macy callb_add(boolean_t (*func)(void *arg, int code),
183eda14cbcSMatt Macy     void *arg, int class, char *name)
184eda14cbcSMatt Macy {
185eda14cbcSMatt Macy 	return (callb_add_common(func, arg, class, name, curthread));
186eda14cbcSMatt Macy }
187eda14cbcSMatt Macy 
188eda14cbcSMatt Macy /*
189eda14cbcSMatt Macy  * A special version of callb_add() above for use by threads which
190eda14cbcSMatt Macy  * might be adding an entry to the table on behalf of some other
191eda14cbcSMatt Macy  * thread (for example, one which is constructed but not yet running).
192eda14cbcSMatt Macy  * In this version the thread id is an argument.
193eda14cbcSMatt Macy  */
194eda14cbcSMatt Macy callb_id_t
callb_add_thread(boolean_t (* func)(void * arg,int code),void * arg,int class,char * name,kthread_id_t t)195eda14cbcSMatt Macy callb_add_thread(boolean_t (*func)(void *arg, int code),
196eda14cbcSMatt Macy     void *arg, int class, char *name, kthread_id_t t)
197eda14cbcSMatt Macy {
198eda14cbcSMatt Macy 	return (callb_add_common(func, arg, class, name, t));
199eda14cbcSMatt Macy }
200eda14cbcSMatt Macy 
201eda14cbcSMatt Macy /*
202eda14cbcSMatt Macy  * callout_delete() is called to remove an entry identified by id
203eda14cbcSMatt Macy  * that was originally placed there by a call to callout_add().
204eda14cbcSMatt Macy  * return -1 if fail to delete a callb entry otherwise return 0.
205eda14cbcSMatt Macy  */
206eda14cbcSMatt Macy int
callb_delete(callb_id_t id)207eda14cbcSMatt Macy callb_delete(callb_id_t id)
208eda14cbcSMatt Macy {
209eda14cbcSMatt Macy 	callb_t **pp;
210eda14cbcSMatt Macy 	callb_t *me = (callb_t *)id;
211eda14cbcSMatt Macy 
212eda14cbcSMatt Macy 	mutex_enter(&ct->ct_lock);
213eda14cbcSMatt Macy 
214eda14cbcSMatt Macy 	for (;;) {
215eda14cbcSMatt Macy 		pp = &ct->ct_first_cb[me->c_class];
216eda14cbcSMatt Macy 		while (*pp != NULL && *pp != me)
217eda14cbcSMatt Macy 			pp = &(*pp)->c_next;
218eda14cbcSMatt Macy 
219eda14cbcSMatt Macy #ifdef ZFS_DEBUG
220eda14cbcSMatt Macy 		if (*pp != me) {
221eda14cbcSMatt Macy 			cmn_err(CE_WARN, "callb delete bogus entry 0x%p",
222eda14cbcSMatt Macy 			    (void *)me);
223eda14cbcSMatt Macy 			mutex_exit(&ct->ct_lock);
224eda14cbcSMatt Macy 			return (-1);
225eda14cbcSMatt Macy 		}
226eda14cbcSMatt Macy #endif /* DEBUG */
227eda14cbcSMatt Macy 
228eda14cbcSMatt Macy 		/*
229eda14cbcSMatt Macy 		 * It is not allowed to delete a callb in the middle of
230eda14cbcSMatt Macy 		 * executing otherwise, the callb_execute() will be confused.
231eda14cbcSMatt Macy 		 */
232eda14cbcSMatt Macy 		if (!(me->c_flag & CALLB_EXECUTING))
233eda14cbcSMatt Macy 			break;
234eda14cbcSMatt Macy 
235eda14cbcSMatt Macy 		cv_wait(&me->c_done_cv, &ct->ct_lock);
236eda14cbcSMatt Macy 	}
237eda14cbcSMatt Macy 	/* relink the class list */
238eda14cbcSMatt Macy 	*pp = me->c_next;
239eda14cbcSMatt Macy 
240eda14cbcSMatt Macy 	/* clean up myself and return the free callb to the head of freelist */
241eda14cbcSMatt Macy 	me->c_flag = CALLB_FREE;
242eda14cbcSMatt Macy 	me->c_next = ct->ct_freelist;
243eda14cbcSMatt Macy 	ct->ct_freelist = me;
244eda14cbcSMatt Macy 
245eda14cbcSMatt Macy 	mutex_exit(&ct->ct_lock);
246eda14cbcSMatt Macy 	return (0);
247eda14cbcSMatt Macy }
248eda14cbcSMatt Macy 
249eda14cbcSMatt Macy /*
250eda14cbcSMatt Macy  * class:	indicates to execute all callbs in the same class;
251eda14cbcSMatt Macy  * code:	optional argument for the callb functions.
252eda14cbcSMatt Macy  * return:	 = 0: success
253eda14cbcSMatt Macy  *		!= 0: ptr to string supplied when callback was registered
254eda14cbcSMatt Macy  */
255eda14cbcSMatt Macy void *
callb_execute_class(int class,int code)256eda14cbcSMatt Macy callb_execute_class(int class, int code)
257eda14cbcSMatt Macy {
258eda14cbcSMatt Macy 	callb_t *cp;
259eda14cbcSMatt Macy 	void *ret = NULL;
260eda14cbcSMatt Macy 
26116038816SMartin Matuska 	ASSERT3S(class, <, NCBCLASS);
262eda14cbcSMatt Macy 
263eda14cbcSMatt Macy 	mutex_enter(&ct->ct_lock);
264eda14cbcSMatt Macy 
265eda14cbcSMatt Macy 	for (cp = ct->ct_first_cb[class];
266*15f0b8c3SMartin Matuska 	    cp != NULL && ret == NULL; cp = cp->c_next) {
267eda14cbcSMatt Macy 		while (cp->c_flag & CALLB_EXECUTING)
268eda14cbcSMatt Macy 			cv_wait(&cp->c_done_cv, &ct->ct_lock);
269eda14cbcSMatt Macy 		/*
270eda14cbcSMatt Macy 		 * cont if the callb is deleted while we're sleeping
271eda14cbcSMatt Macy 		 */
272eda14cbcSMatt Macy 		if (cp->c_flag == CALLB_FREE)
273eda14cbcSMatt Macy 			continue;
274eda14cbcSMatt Macy 		cp->c_flag |= CALLB_EXECUTING;
275eda14cbcSMatt Macy 
276eda14cbcSMatt Macy #ifdef CALLB_DEBUG
277eda14cbcSMatt Macy 		printf("callb_execute: name=%s func=%p arg=%p\n",
278eda14cbcSMatt Macy 		    cp->c_name, (void *)cp->c_func, (void *)cp->c_arg);
279eda14cbcSMatt Macy #endif /* CALLB_DEBUG */
280eda14cbcSMatt Macy 
281eda14cbcSMatt Macy 		mutex_exit(&ct->ct_lock);
282eda14cbcSMatt Macy 		/* If callback function fails, pass back client's name */
283eda14cbcSMatt Macy 		if (!(*cp->c_func)(cp->c_arg, code))
284eda14cbcSMatt Macy 			ret = cp->c_name;
285eda14cbcSMatt Macy 		mutex_enter(&ct->ct_lock);
286eda14cbcSMatt Macy 
287eda14cbcSMatt Macy 		cp->c_flag &= ~CALLB_EXECUTING;
288eda14cbcSMatt Macy 		cv_broadcast(&cp->c_done_cv);
289eda14cbcSMatt Macy 	}
290eda14cbcSMatt Macy 	mutex_exit(&ct->ct_lock);
291eda14cbcSMatt Macy 	return (ret);
292eda14cbcSMatt Macy }
293eda14cbcSMatt Macy 
294eda14cbcSMatt Macy /*
295eda14cbcSMatt Macy  * callers make sure no recursive entries to this func.
296eda14cbcSMatt Macy  * dp->cc_lockp is registered by callb_add to protect callb_cpr_t structure.
297eda14cbcSMatt Macy  *
298eda14cbcSMatt Macy  * When calling to stop a kernel thread (code == CB_CODE_CPR_CHKPT) we
299eda14cbcSMatt Macy  * use a cv_timedwait() in case the kernel thread is blocked.
300eda14cbcSMatt Macy  *
301eda14cbcSMatt Macy  * Note that this is a generic callback handler for daemon CPR and
302eda14cbcSMatt Macy  * should NOT be changed to accommodate any specific requirement in a daemon.
303eda14cbcSMatt Macy  * Individual daemons that require changes to the handler shall write
304eda14cbcSMatt Macy  * callback routines in their own daemon modules.
305eda14cbcSMatt Macy  */
306eda14cbcSMatt Macy boolean_t
callb_generic_cpr(void * arg,int code)307eda14cbcSMatt Macy callb_generic_cpr(void *arg, int code)
308eda14cbcSMatt Macy {
309eda14cbcSMatt Macy 	callb_cpr_t *cp = (callb_cpr_t *)arg;
310eda14cbcSMatt Macy 	clock_t ret = 0;			/* assume success */
311eda14cbcSMatt Macy 
312eda14cbcSMatt Macy 	mutex_enter(cp->cc_lockp);
313eda14cbcSMatt Macy 
314eda14cbcSMatt Macy 	switch (code) {
315eda14cbcSMatt Macy 	case CB_CODE_CPR_CHKPT:
316eda14cbcSMatt Macy 		cp->cc_events |= CALLB_CPR_START;
317eda14cbcSMatt Macy #ifdef CPR_NOT_THREAD_SAFE
318eda14cbcSMatt Macy 		while (!(cp->cc_events & CALLB_CPR_SAFE))
319eda14cbcSMatt Macy 			/* cv_timedwait() returns -1 if it times out. */
320eda14cbcSMatt Macy 			if ((ret = cv_reltimedwait(&cp->cc_callb_cv,
321eda14cbcSMatt Macy 			    cp->cc_lockp, (callb_timeout_sec * hz),
322eda14cbcSMatt Macy 			    TR_CLOCK_TICK)) == -1)
323eda14cbcSMatt Macy 				break;
324eda14cbcSMatt Macy #endif
325eda14cbcSMatt Macy 		break;
326eda14cbcSMatt Macy 
327eda14cbcSMatt Macy 	case CB_CODE_CPR_RESUME:
328eda14cbcSMatt Macy 		cp->cc_events &= ~CALLB_CPR_START;
329eda14cbcSMatt Macy 		cv_signal(&cp->cc_stop_cv);
330eda14cbcSMatt Macy 		break;
331eda14cbcSMatt Macy 	}
332eda14cbcSMatt Macy 	mutex_exit(cp->cc_lockp);
333eda14cbcSMatt Macy 	return (ret != -1);
334eda14cbcSMatt Macy }
335eda14cbcSMatt Macy 
336eda14cbcSMatt Macy /*
337eda14cbcSMatt Macy  * The generic callback function associated with kernel threads which
338eda14cbcSMatt Macy  * are always considered safe.
339eda14cbcSMatt Macy  */
340eda14cbcSMatt Macy boolean_t
callb_generic_cpr_safe(void * arg,int code)341eda14cbcSMatt Macy callb_generic_cpr_safe(void *arg, int code)
342eda14cbcSMatt Macy {
343c03c5b1cSMartin Matuska 	(void) arg, (void) code;
344eda14cbcSMatt Macy 	return (B_TRUE);
345eda14cbcSMatt Macy }
346eda14cbcSMatt Macy /*
347eda14cbcSMatt Macy  * Prevent additions to callback table.
348eda14cbcSMatt Macy  */
349eda14cbcSMatt Macy void
callb_lock_table(void)350eda14cbcSMatt Macy callb_lock_table(void)
351eda14cbcSMatt Macy {
352eda14cbcSMatt Macy 	mutex_enter(&ct->ct_lock);
35316038816SMartin Matuska 	ASSERT(!ct->ct_busy);
35416038816SMartin Matuska 	ct->ct_busy = B_TRUE;
355eda14cbcSMatt Macy 	mutex_exit(&ct->ct_lock);
356eda14cbcSMatt Macy }
357eda14cbcSMatt Macy 
358eda14cbcSMatt Macy /*
359eda14cbcSMatt Macy  * Allow additions to callback table.
360eda14cbcSMatt Macy  */
361eda14cbcSMatt Macy void
callb_unlock_table(void)362eda14cbcSMatt Macy callb_unlock_table(void)
363eda14cbcSMatt Macy {
364eda14cbcSMatt Macy 	mutex_enter(&ct->ct_lock);
36516038816SMartin Matuska 	ASSERT(ct->ct_busy);
36616038816SMartin Matuska 	ct->ct_busy = B_FALSE;
367eda14cbcSMatt Macy 	cv_broadcast(&ct->ct_busy_cv);
368eda14cbcSMatt Macy 	mutex_exit(&ct->ct_lock);
369eda14cbcSMatt Macy }
370eda14cbcSMatt Macy 
371eda14cbcSMatt Macy SYSINIT(sol_callb, SI_SUB_DRIVERS, SI_ORDER_FIRST, callb_init, NULL);
372eda14cbcSMatt Macy SYSUNINIT(sol_callb, SI_SUB_DRIVERS, SI_ORDER_FIRST, callb_fini, NULL);
373