Print this page
cstyle sort of updates
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/avs/ns/nsctl/nsc_freeze.c
+++ new/usr/src/uts/common/avs/ns/nsctl/nsc_freeze.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/errno.h>
28 28 #include <sys/cmn_err.h>
29 29 #include <sys/ksynch.h>
30 30 #include <sys/kmem.h>
31 31 #include <sys/ddi.h>
32 32
33 33 #define __NSC_GEN__
34 34 #include "nsc_dev.h"
35 35 #include "../nsctl.h"
36 36
37 37 /*
38 38 * (Un)Freeze Module
39 39 *
40 40 * This module provides a means to 'freeze' a device and ensure
41 41 * that no SP software has an open reference to that device. Later
42 42 * the device can be 'unfrozen' and the SP software can resume
43 43 * normal operations.
44 44 *
45 45 * This module is required because it is possible to place a virtual
46 46 * volume driver (RAID-0, 1 or 5) into a state whereby it needs to be
47 47 * disabled for corrective action. The (un)freeze facility provides a
48 48 * method of doing this without downtime.
49 49 *
50 50 * A device that is frozen should be frozen on all nodes. It is the
51 51 * responsibility of the management software or the user to perform
52 52 * the freeze and unfreeze on the required nodes.
53 53 */
54 54
55 55 extern nsc_mem_t *_nsc_local_mem;
56 56
57 57 typedef struct _nsc_frz_s {
58 58 struct _nsc_frz_s *next;
59 59 nsc_path_t *token;
60 60 char path[NSC_MAXPATH];
61 61 } _nsc_frz_t;
62 62
63 63
64 64 extern int _nsc_frz_stop(char *, int *); /* forward decl */
65 65
66 66 static _nsc_frz_t *_nsc_frz_top;
67 67 static nsc_def_t _nsc_frz_def[];
68 68 static kmutex_t _nsc_frz_sleep;
69 69 static nsc_io_t *_nsc_frz_io;
70 70
71 71
72 72 void
73 73 _nsc_init_frz(void)
74 74 {
75 75 mutex_init(&_nsc_frz_sleep, NULL, MUTEX_DRIVER, NULL);
76 76
77 77 _nsc_frz_io = nsc_register_io("frz",
78 78 NSC_FREEZE_ID | NSC_FILTER, _nsc_frz_def);
79 79
80 80 if (!_nsc_frz_io)
81 81 cmn_err(CE_WARN, "nsctl: _nsc_init_frz: register failed");
82 82 }
83 83
84 84
85 85 void
86 86 _nsc_deinit_frz(void)
87 87 {
88 88 if (_nsc_frz_io)
89 89 (void) nsc_unregister_io(_nsc_frz_io, 0);
90 90
91 91 _nsc_frz_io = NULL;
92 92
93 93 mutex_destroy(&_nsc_frz_sleep);
94 94 }
95 95
96 96
97 97 /*
98 98 * int _nsc_frz_start(char *path, int *rvp)
99 99 * Freeze a device
100 100 *
101 101 * Calling/Exit State:
102 102 * Must be called from a context that can block.
103 103 * Returns 0 for success, or one of the following error codes:
104 104 * EINVAL - invalid 'path' argument
105 105 * ENOMEM - failed to allocate memory
106 106 * EALREADY - 'path' is already frozen
107 107 *
108 108 * Description:
109 109 * Registers 'path' to be accessed through the NSC_FREEZE_ID
110 110 * io module, and forces any open file descriptors for 'path'
111 111 * to be re-opened as appropriate.
112 112 */
113 113 int
114 114 _nsc_frz_start(path, rvp)
115 115 char *path;
116 116 int *rvp;
117 117 {
118 118 _nsc_frz_t *frz, *xfrz;
119 119 int rc;
120 120
121 121 *rvp = 0;
122 122
123 123 if (strlen(path) >= NSC_MAXPATH)
124 124 return (EINVAL);
125 125
126 126 frz = nsc_kmem_zalloc(sizeof (*frz), KM_SLEEP, _nsc_local_mem);
127 127 if (!frz)
128 128 return (ENOMEM);
129 129
130 130 (void) strcpy(frz->path, path);
131 131
132 132 mutex_enter(&_nsc_frz_sleep);
133 133
134 134 for (xfrz = _nsc_frz_top; xfrz; xfrz = xfrz->next)
135 135 if (strcmp(frz->path, xfrz->path) == 0)
136 136 break;
137 137
138 138 if (!xfrz) {
139 139 frz->next = _nsc_frz_top;
140 140 _nsc_frz_top = frz;
141 141 }
142 142
143 143 mutex_exit(&_nsc_frz_sleep);
144 144
145 145 if (xfrz) {
146 146 nsc_kmem_free(frz, sizeof (*frz));
147 147 return (EALREADY);
148 148 }
149 149
150 150 frz->token = nsc_register_path(path, NSC_DEVICE, _nsc_frz_io);
151 151
152 152 if (!frz->token) {
153 153 (void) _nsc_frz_stop(path, &rc);
154 154 return (EINVAL);
155 155 }
156 156
157 157 return (0);
158 158 }
159 159
160 160
161 161 /*
162 162 * int _nsc_frz_stop(char *path, int *rvp)
163 163 * Unfreeze a device
164 164 *
165 165 * Calling/Exit State:
166 166 * Must be called from a context that can block.
167 167 * Returns 0 or an error code.
168 168 *
169 169 * Description:
170 170 * Removes the path registration for the NSC_FREEZE_ID io module
171 171 * and forces any re-opens as appropriate.
172 172 */
173 173 int
174 174 _nsc_frz_stop(path, rvp)
175 175 char *path;
176 176 int *rvp;
177 177 {
178 178 _nsc_frz_t **xfrz, *frz = NULL;
179 179 int rc = 0;
180 180
181 181 *rvp = 0;
182 182
183 183 mutex_enter(&_nsc_frz_sleep);
184 184
185 185 for (xfrz = &_nsc_frz_top; *xfrz; xfrz = &(*xfrz)->next)
186 186 if (strcmp(path, (*xfrz)->path) == 0) {
187 187 frz = *xfrz;
188 188 break;
189 189 }
190 190
191 191 if (!frz) {
192 192 mutex_exit(&_nsc_frz_sleep);
193 193 return (EINVAL);
194 194 }
195 195
196 196 if (frz->token)
197 197 rc = nsc_unregister_path(frz->token, NSC_PCATCH);
198 198
199 199 if (rc) {
200 200 mutex_exit(&_nsc_frz_sleep);
201 201 return (rc);
202 202 }
203 203
204 204 (*xfrz) = frz->next;
205 205
206 206 mutex_exit(&_nsc_frz_sleep);
207 207
208 208 nsc_kmem_free(frz, sizeof (*frz));
209 209
210 210 return (0);
211 211 }
212 212
213 213
214 214 /*
215 215 * int _nsc_frz_isfrozen(char *path, int *rvp)
216 216 * Tests whether a device is frozen.
217 217 *
218 218 * Calling/Exit State:
219 219 * Returns 0 or EINVAL.
220 220 * Sets *rvp to 1 if the device was not frozen, and 0 otherwise.
221 221 * This function returns historical information.
222 222 */
223 223 int
224 224 _nsc_frz_isfrozen(path, rvp)
225 225 char *path;
226 226 int *rvp;
227 227 {
228 228 _nsc_frz_t *frz;
229 229
230 230 *rvp = 1;
231 231
232 232 if (! _nsc_frz_io)
233 233 return (EINVAL);
234 234
235 235 mutex_enter(&_nsc_frz_sleep);
236 236
237 237 for (frz = _nsc_frz_top; frz; frz = frz->next)
238 238 if (strcmp(frz->path, path) == 0) {
239 239 *rvp = 0;
240 240 break;
241 241 }
242 242
243 243 mutex_exit(&_nsc_frz_sleep);
244 244
245 245 return (0);
246 246 }
247 247
248 248
249 249 /*
250 250 * static int
251 251 * _nsc_frz_open(char *path, int flag, blind_t *cdp)
252 252 * Dummy open function.
253 253 *
254 254 * Description:
255 255 * This is the "Open" function for the I/O module.
256 256 * It is just a dummy.
257 257 */
258 258
259 259 /* ARGSUSED */
260 260
261 261 static int
262 262 _nsc_frz_open(path, flag, cdp)
263 263 char *path;
264 264 int flag;
265 265 blind_t *cdp;
266 266 {
267 267 *cdp = 0;
268 268 return (0);
269 269 }
270 270
271 271
272 272 /*
273 273 * static int
274 274 * _nsc_frz_close()
275 275 * Dummy close function.
276 276 *
277 277 * Description:
278 278 * This is the "Close" function for the I/O module.
279 279 * It is just a dummy.
280 280 */
281 281 static int
282 282 _nsc_frz_close() { return (0); }
283 283
284 284
285 285 /*
286 286 * static int
287 287 * _nsc_frz_attach()
288 288 * Attach a device to this i/o module.
289 289 *
290 290 * Calling/Exit State:
291 291 * Returns EACCES in all cricumstances.
292 292 *
293 293 * Description:
294 294 * This function is called by the nsctl module when it wishes
↓ open down ↓ |
294 lines elided |
↑ open up ↑ |
295 295 * to attach the device to this I/O module (ie. as part of
296 296 * nsc_reserve() processing). This function unconditionally
297 297 * returns an error which forces the nsc_reserve() to fail, and
298 298 * so no access to possible to the underlying device.
299 299 */
300 300 static int
301 301 _nsc_frz_attach() { return (EACCES); }
302 302
303 303
304 304 static nsc_def_t _nsc_frz_def[] = {
305 - "Open", (uintptr_t)_nsc_frz_open, 0,
306 - "Close", (uintptr_t)_nsc_frz_close, 0,
307 - "Attach", (uintptr_t)_nsc_frz_attach, 0,
308 - "Provide", 0, 0,
309 - 0, 0, 0
305 + { "Open", (uintptr_t)_nsc_frz_open, 0 },
306 + { "Close", (uintptr_t)_nsc_frz_close, 0 },
307 + { "Attach", (uintptr_t)_nsc_frz_attach, 0 },
308 + { "Provide", (uintptr_t)NULL, 0 },
309 + { NULL, (uintptr_t)NULL, 0 }
310 310 };
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX