xref: /netbsd-src/external/cddl/osnet/dev/dtrace/dtrace_modevent.c (revision e7bed289116c9b32f7fb79bfcc85271d4154b7e8)
1*e7bed289Sriastradh /*	$NetBSD: dtrace_modevent.c,v 1.7 2022/03/28 12:33:20 riastradh Exp $	*/
201c9547eSdarran 
3bb8023b5Sdarran /*
4bb8023b5Sdarran  * CDDL HEADER START
5bb8023b5Sdarran  *
6bb8023b5Sdarran  * The contents of this file are subject to the terms of the
7bb8023b5Sdarran  * Common Development and Distribution License (the "License").
8bb8023b5Sdarran  * You may not use this file except in compliance with the License.
9bb8023b5Sdarran  *
10bb8023b5Sdarran  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11bb8023b5Sdarran  * or http://www.opensolaris.org/os/licensing.
12bb8023b5Sdarran  * See the License for the specific language governing permissions
13bb8023b5Sdarran  * and limitations under the License.
14bb8023b5Sdarran  *
15bb8023b5Sdarran  * When distributing Covered Code, include this CDDL HEADER in each
16bb8023b5Sdarran  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17bb8023b5Sdarran  * If applicable, add the following below this CDDL HEADER, with the
18bb8023b5Sdarran  * fields enclosed by brackets "[]" replaced with your own identifying
19bb8023b5Sdarran  * information: Portions Copyright [yyyy] [name of copyright owner]
20bb8023b5Sdarran  *
21bb8023b5Sdarran  * CDDL HEADER END
22bb8023b5Sdarran  *
23ba2539a9Schs  * $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_load.c 309069 2016-11-23 22:50:20Z gnn $
24bb8023b5Sdarran  *
25bb8023b5Sdarran  */
26bb8023b5Sdarran 
27bb8023b5Sdarran /* ARGSUSED */
28bb8023b5Sdarran static int
dtrace_modcmd(modcmd_t cmd,void * data)2901c9547eSdarran dtrace_modcmd(modcmd_t cmd, void *data)
30bb8023b5Sdarran {
3101c9547eSdarran 	int bmajor = -1, cmajor = -1;
329ce3434fSozaki-r 	int error;
33bb8023b5Sdarran 
3401c9547eSdarran 	switch (cmd) {
3501c9547eSdarran 	case MODULE_CMD_INIT:
3601c9547eSdarran 		dtrace_load(NULL);
3782344b6cSpgoyette 		error = devsw_attach("dtrace", NULL, &bmajor,
3801c9547eSdarran 		    &dtrace_cdevsw, &cmajor);
3982344b6cSpgoyette 		if (error != 0)
4082344b6cSpgoyette 			if (dtrace_unload() != 0)
4182344b6cSpgoyette 				panic("failed to unload dtrace");
4282344b6cSpgoyette 		return error;
4382344b6cSpgoyette 
4401c9547eSdarran 	case MODULE_CMD_FINI:
45*e7bed289Sriastradh 		devsw_detach(NULL, &dtrace_cdevsw);
4682344b6cSpgoyette 
4782344b6cSpgoyette 		error = dtrace_unload();
4882344b6cSpgoyette 		if (error != 0) {
4982344b6cSpgoyette 			if (devsw_attach("dtrace", NULL, &bmajor,
5082344b6cSpgoyette 					 &dtrace_cdevsw, &cmajor) != 0)
5182344b6cSpgoyette 				panic("failed to reattach dtrace_devsw");
5282344b6cSpgoyette 		}
5382344b6cSpgoyette 		return error;
5482344b6cSpgoyette 
559ce3434fSozaki-r 	case MODULE_CMD_AUTOUNLOAD:
569ce3434fSozaki-r 		return EBUSY;
57bb8023b5Sdarran 	default:
5801c9547eSdarran 		return ENOTTY;
59bb8023b5Sdarran 	}
60bb8023b5Sdarran }
61