]> git.proxmox.com Git - mirror_zfs.git/blame - module/icp/os/modconf.c
Use cstyle -cpP in `make cstyle` check
[mirror_zfs.git] / module / icp / os / modconf.c
CommitLineData
0b04990a
TC
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/zfs_context.h>
27#include <sys/modctl.h>
28
29/*
30 * Null operations; used for uninitialized and "misc" modules.
31 */
32static int mod_null(struct modlmisc *, struct modlinkage *);
33static int mod_infonull(void *, struct modlinkage *, int *);
34
35/*
36 * Cryptographic Modules
37 */
38struct mod_ops mod_cryptoops = {
39 mod_null, mod_null, mod_infonull
40};
41
42/*
43 * Null operation; return 0.
44 */
45static int
46mod_null(struct modlmisc *modl, struct modlinkage *modlp)
47{
48 return (0);
49}
50
51/*
52 * Status for User modules.
53 */
54static int
55mod_infonull(void *modl, struct modlinkage *modlp, int *p0)
56{
57 *p0 = -1; /* for modinfo display */
58 return (0);
59}
60
61/*
62 * Install a module.
63 * (This routine is in the Solaris SPARC DDI/DKI)
64 */
65int
66mod_install(struct modlinkage *modlp)
67{
68 int retval = -1; /* No linkage structures */
69 struct modlmisc **linkpp;
70 struct modlmisc **linkpp1;
71
72 if (modlp->ml_rev != MODREV_1) {
73 cmn_err(CE_WARN, "mod_install: "
02730c33 74 "modlinkage structure is not MODREV_1\n");
0b04990a
TC
75 return (EINVAL);
76 }
77 linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
78
79 while (*linkpp != NULL) {
80 if ((retval = MODL_INSTALL(*linkpp, modlp)) != 0) {
81 linkpp1 = (struct modlmisc **)&modlp->ml_linkage[0];
82
83 while (linkpp1 != linkpp) {
84 MODL_REMOVE(*linkpp1, modlp); /* clean up */
85 linkpp1++;
86 }
87 break;
88 }
89 linkpp++;
90 }
91 return (retval);
92}
93
94static char *reins_err =
95 "Could not reinstall %s\nReboot to correct the problem";
96
97/*
98 * Remove a module. This is called by the module wrapper routine.
99 * (This routine is in the Solaris SPARC DDI/DKI)
100 */
101int
102mod_remove(struct modlinkage *modlp)
103{
104 int retval = 0;
105 struct modlmisc **linkpp, *last_linkp;
106
107 linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
108
109 while (*linkpp != NULL) {
110 if ((retval = MODL_REMOVE(*linkpp, modlp)) != 0) {
111 last_linkp = *linkpp;
112 linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
113 while (*linkpp != last_linkp) {
114 if (MODL_INSTALL(*linkpp, modlp) != 0) {
115 cmn_err(CE_WARN, reins_err,
116 (*linkpp)->misc_linkinfo);
117 break;
118 }
119 linkpp++;
120 }
121 break;
122 }
123 linkpp++;
124 }
125 return (retval);
126}
127
128/*
129 * Get module status.
130 * (This routine is in the Solaris SPARC DDI/DKI)
131 */
132int
133mod_info(struct modlinkage *modlp, struct modinfo *modinfop)
134{
135 int i;
136 int retval = 0;
137 struct modspecific_info *msip;
138 struct modlmisc **linkpp;
139
140 modinfop->mi_rev = modlp->ml_rev;
141
142 linkpp = (struct modlmisc **)modlp->ml_linkage;
143 msip = &modinfop->mi_msinfo[0];
144
145 for (i = 0; i < MODMAXLINK; i++) {
146 if (*linkpp == NULL) {
147 msip->msi_linkinfo[0] = '\0';
148 } else {
1f723944 149 (void) strlcpy(msip->msi_linkinfo,
0b04990a
TC
150 (*linkpp)->misc_linkinfo, MODMAXLINKINFOLEN);
151 retval = MODL_INFO(*linkpp, modlp, &msip->msi_p0);
152 if (retval != 0)
153 break;
154 linkpp++;
155 }
156 msip++;
157 }
158
159 if (modinfop->mi_info == MI_INFO_LINKAGE) {
160 /*
161 * Slight kludge used to extract the address of the
162 * modlinkage structure from the module (just after
163 * loading a module for the very first time)
164 */
165 modinfop->mi_base = (void *)modlp;
166 }
167
168 if (retval == 0)
169 return (1);
170 return (0);
02730c33 171}