Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/cpr/cpr_mod.c
+++ new/usr/src/uts/common/cpr/cpr_mod.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 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
25 25 * Copyright 2012 Milan Jurik. All rights reserved.
26 26 */
27 27
28 28 /*
29 29 * System call to checkpoint and resume the currently running kernel
30 30 */
31 31 #include <sys/types.h>
32 32 #include <sys/errno.h>
33 33 #include <sys/modctl.h>
34 34 #include <sys/syscall.h>
35 35 #include <sys/cred.h>
36 36 #include <sys/uadmin.h>
37 37 #include <sys/cmn_err.h>
38 38 #include <sys/systm.h>
39 39 #include <sys/cpr.h>
40 40 #include <sys/swap.h>
41 41 #include <sys/vfs.h>
42 42 #include <sys/autoconf.h>
43 43 #include <sys/machsystm.h>
44 44
45 45 extern int i_cpr_is_supported(int sleeptype);
46 46 extern int cpr_is_ufs(struct vfs *);
47 47 extern int cpr_is_zfs(struct vfs *);
48 48 extern int cpr_check_spec_statefile(void);
49 49 extern int cpr_reusable_mount_check(void);
50 50 extern int i_cpr_reusable_supported(void);
51 51 extern int i_cpr_reusefini(void);
52 52 extern struct mod_ops mod_miscops;
53 53
54 54 extern int cpr_init(int);
55 55 extern void cpr_done(void);
56 56 extern void i_cpr_stop_other_cpus(void);
57 57 extern int i_cpr_power_down(int);
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
58 58
59 59 #if defined(__sparc)
60 60 extern void cpr_forget_cprconfig(void);
61 61 #endif
62 62
63 63 static struct modlmisc modlmisc = {
64 64 &mod_miscops, "checkpoint resume"
65 65 };
66 66
67 67 static struct modlinkage modlinkage = {
68 - MODREV_1, (void *)&modlmisc, NULL
68 + MODREV_1, { (void *)&modlmisc, NULL }
69 69 };
70 70
71 71 int cpr_reusable_mode;
72 72
73 73 kmutex_t cpr_slock; /* cpr serial lock */
74 74 cpr_t cpr_state;
75 75 int cpr_debug;
76 76 int cpr_test_mode; /* true if called via uadmin testmode */
77 77 int cpr_test_point = LOOP_BACK_NONE; /* cpr test point */
78 78 int cpr_mp_enable = 0; /* set to 1 to enable MP suspend */
79 79 major_t cpr_device = 0; /* major number for S3 on one device */
80 80
81 81 /*
82 82 * All the loadable module related code follows
83 83 */
84 84 int
85 85 _init(void)
86 86 {
87 87 register int e;
88 88
89 89 if ((e = mod_install(&modlinkage)) == 0) {
90 90 mutex_init(&cpr_slock, NULL, MUTEX_DEFAULT, NULL);
91 91 }
92 92 return (e);
93 93 }
94 94
95 95 int
96 96 _fini(void)
97 97 {
98 98 register int e;
99 99
100 100 if ((e = mod_remove(&modlinkage)) == 0) {
101 101 mutex_destroy(&cpr_slock);
102 102 }
103 103 return (e);
104 104 }
105 105
106 106 int
107 107 _info(struct modinfo *modinfop)
108 108 {
109 109 return (mod_info(&modlinkage, modinfop));
110 110 }
111 111
112 112 static
113 113 int
114 114 atoi(char *p)
115 115 {
116 116 int i;
117 117
118 118 i = (*p++ - '0');
119 119
120 120 while (*p != '\0')
121 121 i = 10 * i + (*p++ - '0');
122 122
123 123 return (i);
124 124 }
125 125
126 126 int
127 127 cpr(int fcn, void *mdep)
128 128 {
129 129
130 130 #if defined(__sparc)
131 131 static const char noswapstr[] = "reusable statefile requires "
132 132 "that no swap area be configured.\n";
133 133 static const char blockstr[] = "reusable statefile must be "
134 134 "a block device. See power.conf(4) and pmconfig(1M).\n";
135 135 static const char normalfmt[] = "cannot run normal "
136 136 "checkpoint/resume when in reusable statefile mode. "
137 137 "use uadmin A_FREEZE AD_REUSEFINI (uadmin %d %d) "
138 138 "to exit reusable statefile mode.\n";
139 139 static const char modefmt[] = "%s in reusable mode.\n";
140 140 #endif
141 141 register int rc = 0;
142 142 int cpr_sleeptype;
143 143
144 144 /*
145 145 * First, reject commands that we don't (yet) support on this arch.
146 146 * This is easier to understand broken out like this than grotting
147 147 * through the second switch below.
148 148 */
149 149
150 150 switch (fcn) {
151 151 #if defined(__sparc)
152 152 case AD_CHECK_SUSPEND_TO_RAM:
153 153 case AD_SUSPEND_TO_RAM:
154 154 return (ENOTSUP);
155 155 case AD_CHECK_SUSPEND_TO_DISK:
156 156 case AD_SUSPEND_TO_DISK:
157 157 case AD_CPR_REUSEINIT:
158 158 case AD_CPR_NOCOMPRESS:
159 159 case AD_CPR_FORCE:
160 160 case AD_CPR_REUSABLE:
161 161 case AD_CPR_REUSEFINI:
162 162 case AD_CPR_TESTZ:
163 163 case AD_CPR_TESTNOZ:
164 164 case AD_CPR_TESTHALT:
165 165 case AD_CPR_SUSP_DEVICES:
166 166 cpr_sleeptype = CPR_TODISK;
167 167 break;
168 168 #endif
169 169 #if defined(__x86)
170 170 case AD_CHECK_SUSPEND_TO_DISK:
171 171 case AD_SUSPEND_TO_DISK:
172 172 case AD_CPR_REUSEINIT:
173 173 case AD_CPR_NOCOMPRESS:
174 174 case AD_CPR_FORCE:
175 175 case AD_CPR_REUSABLE:
176 176 case AD_CPR_REUSEFINI:
177 177 case AD_CPR_TESTZ:
178 178 case AD_CPR_TESTNOZ:
179 179 case AD_CPR_TESTHALT:
180 180 case AD_CPR_PRINT:
181 181 return (ENOTSUP);
182 182 /* The DEV_* values need to be removed after sys-syspend is fixed */
183 183 case DEV_CHECK_SUSPEND_TO_RAM:
184 184 case DEV_SUSPEND_TO_RAM:
185 185 case AD_CPR_SUSP_DEVICES:
186 186 case AD_CHECK_SUSPEND_TO_RAM:
187 187 case AD_SUSPEND_TO_RAM:
188 188 case AD_LOOPBACK_SUSPEND_TO_RAM_PASS:
189 189 case AD_LOOPBACK_SUSPEND_TO_RAM_FAIL:
190 190 case AD_FORCE_SUSPEND_TO_RAM:
191 191 case AD_DEVICE_SUSPEND_TO_RAM:
192 192 cpr_sleeptype = CPR_TORAM;
193 193 break;
194 194 #endif
195 195 }
196 196 #if defined(__sparc)
197 197 /*
198 198 * Need to know if we're in reusable mode, but we will likely have
199 199 * rebooted since REUSEINIT, so we have to get the info from the
200 200 * file system
201 201 */
202 202 if (!cpr_reusable_mode)
203 203 cpr_reusable_mode = cpr_get_reusable_mode();
204 204
205 205 cpr_forget_cprconfig();
206 206 #endif
207 207
208 208 switch (fcn) {
209 209
210 210 #if defined(__sparc)
211 211 case AD_CPR_REUSEINIT:
212 212 if (!i_cpr_reusable_supported())
213 213 return (ENOTSUP);
214 214 if (!cpr_statefile_is_spec()) {
215 215 cpr_err(CE_CONT, blockstr);
216 216 return (EINVAL);
217 217 }
218 218 if ((rc = cpr_check_spec_statefile()) != 0)
219 219 return (rc);
220 220 if (swapinfo) {
221 221 cpr_err(CE_CONT, noswapstr);
222 222 return (EINVAL);
223 223 }
224 224 cpr_test_mode = 0;
225 225 break;
226 226
227 227 case AD_CPR_NOCOMPRESS:
228 228 case AD_CPR_COMPRESS:
229 229 case AD_CPR_FORCE:
230 230 if (cpr_reusable_mode) {
231 231 cpr_err(CE_CONT, normalfmt, A_FREEZE, AD_REUSEFINI);
232 232 return (ENOTSUP);
233 233 }
234 234 cpr_test_mode = 0;
235 235 break;
236 236
237 237 case AD_CPR_REUSABLE:
238 238 if (!i_cpr_reusable_supported())
239 239 return (ENOTSUP);
240 240 if (!cpr_statefile_is_spec()) {
241 241 cpr_err(CE_CONT, blockstr);
242 242 return (EINVAL);
243 243 }
244 244 if ((rc = cpr_check_spec_statefile()) != 0)
245 245 return (rc);
246 246 if (swapinfo) {
247 247 cpr_err(CE_CONT, noswapstr);
248 248 return (EINVAL);
249 249 }
250 250 if ((rc = cpr_reusable_mount_check()) != 0)
251 251 return (rc);
252 252 cpr_test_mode = 0;
253 253 break;
254 254
255 255 case AD_CPR_REUSEFINI:
256 256 if (!i_cpr_reusable_supported())
257 257 return (ENOTSUP);
258 258 cpr_test_mode = 0;
259 259 break;
260 260
261 261 case AD_CPR_TESTZ:
262 262 case AD_CPR_TESTNOZ:
263 263 case AD_CPR_TESTHALT:
264 264 if (cpr_reusable_mode) {
265 265 cpr_err(CE_CONT, normalfmt, A_FREEZE, AD_REUSEFINI);
266 266 return (ENOTSUP);
267 267 }
268 268 cpr_test_mode = 1;
269 269 break;
270 270
271 271 case AD_CPR_CHECK:
272 272 if (!i_cpr_is_supported(cpr_sleeptype) || cpr_reusable_mode)
273 273 return (ENOTSUP);
274 274 return (0);
275 275
276 276 case AD_CPR_PRINT:
277 277 CPR_STAT_EVENT_END("POST CPR DELAY");
278 278 cpr_stat_event_print();
279 279 return (0);
280 280 #endif
281 281
282 282 case AD_CPR_DEBUG0:
283 283 cpr_debug = 0;
284 284 return (0);
285 285
286 286 case AD_CPR_DEBUG1:
287 287 case AD_CPR_DEBUG2:
288 288 case AD_CPR_DEBUG3:
289 289 case AD_CPR_DEBUG4:
290 290 case AD_CPR_DEBUG5:
291 291 case AD_CPR_DEBUG7:
292 292 case AD_CPR_DEBUG8:
293 293 cpr_debug |= CPR_DEBUG_BIT(fcn);
294 294 return (0);
295 295
296 296 case AD_CPR_DEBUG9:
297 297 cpr_debug |= CPR_DEBUG6;
298 298 return (0);
299 299
300 300 /* The DEV_* values need to be removed after sys-syspend is fixed */
301 301 case DEV_CHECK_SUSPEND_TO_RAM:
302 302 case DEV_SUSPEND_TO_RAM:
303 303 case AD_CHECK_SUSPEND_TO_RAM:
304 304 case AD_SUSPEND_TO_RAM:
305 305 cpr_test_point = LOOP_BACK_NONE;
306 306 break;
307 307
308 308 case AD_LOOPBACK_SUSPEND_TO_RAM_PASS:
309 309 cpr_test_point = LOOP_BACK_PASS;
310 310 break;
311 311
312 312 case AD_LOOPBACK_SUSPEND_TO_RAM_FAIL:
313 313 cpr_test_point = LOOP_BACK_FAIL;
314 314 break;
315 315
316 316 case AD_FORCE_SUSPEND_TO_RAM:
317 317 cpr_test_point = FORCE_SUSPEND_TO_RAM;
318 318 break;
319 319
320 320 case AD_DEVICE_SUSPEND_TO_RAM:
321 321 if (mdep == NULL) {
322 322 /* Didn't pass enough arguments */
323 323 return (EINVAL);
324 324 }
325 325 cpr_test_point = DEVICE_SUSPEND_TO_RAM;
326 326 cpr_device = (major_t)atoi((char *)mdep);
327 327 break;
328 328
329 329 case AD_CPR_SUSP_DEVICES:
330 330 cpr_test_point = FORCE_SUSPEND_TO_RAM;
331 331 if (cpr_suspend_devices(ddi_root_node()) != DDI_SUCCESS)
332 332 cmn_err(CE_WARN,
333 333 "Some devices did not suspend "
334 334 "and may be unusable");
335 335 (void) cpr_resume_devices(ddi_root_node(), 0);
336 336 return (0);
337 337
338 338 default:
339 339 return (ENOTSUP);
340 340 }
341 341
342 342 if (!i_cpr_is_supported(cpr_sleeptype))
343 343 return (ENOTSUP);
344 344
345 345 #if defined(__sparc)
346 346 if ((cpr_sleeptype == CPR_TODISK &&
347 347 !cpr_is_ufs(rootvfs) && !cpr_is_zfs(rootvfs)))
348 348 return (ENOTSUP);
349 349 #endif
350 350
351 351 if (fcn == AD_CHECK_SUSPEND_TO_RAM ||
352 352 fcn == DEV_CHECK_SUSPEND_TO_RAM) {
353 353 ASSERT(i_cpr_is_supported(cpr_sleeptype));
354 354 return (0);
355 355 }
356 356
357 357 #if defined(__sparc)
358 358 if (fcn == AD_CPR_REUSEINIT) {
359 359 if (mutex_tryenter(&cpr_slock) == 0)
360 360 return (EBUSY);
361 361 if (cpr_reusable_mode) {
362 362 cpr_err(CE_CONT, modefmt, "already");
363 363 mutex_exit(&cpr_slock);
364 364 return (EBUSY);
365 365 }
366 366 rc = i_cpr_reuseinit();
367 367 mutex_exit(&cpr_slock);
368 368 return (rc);
369 369 }
370 370
371 371 if (fcn == AD_CPR_REUSEFINI) {
372 372 if (mutex_tryenter(&cpr_slock) == 0)
373 373 return (EBUSY);
374 374 if (!cpr_reusable_mode) {
375 375 cpr_err(CE_CONT, modefmt, "not");
376 376 mutex_exit(&cpr_slock);
377 377 return (EINVAL);
378 378 }
379 379 rc = i_cpr_reusefini();
380 380 mutex_exit(&cpr_slock);
381 381 return (rc);
382 382 }
383 383 #endif
384 384
385 385 /*
386 386 * acquire cpr serial lock and init cpr state structure.
387 387 */
388 388 if (rc = cpr_init(fcn))
389 389 return (rc);
390 390
391 391 #if defined(__sparc)
392 392 if (fcn == AD_CPR_REUSABLE) {
393 393 if ((rc = i_cpr_check_cprinfo()) != 0) {
394 394 mutex_exit(&cpr_slock);
395 395 return (rc);
396 396 }
397 397 }
398 398 #endif
399 399
400 400 /*
401 401 * Call the main cpr routine. If we are successful, we will be coming
402 402 * down from the resume side, otherwise we are still in suspend.
403 403 */
404 404 cpr_err(CE_CONT, "System is being suspended");
405 405 if (rc = cpr_main(cpr_sleeptype)) {
406 406 CPR->c_flags |= C_ERROR;
407 407 PMD(PMD_SX, ("cpr: Suspend operation failed.\n"))
408 408 cpr_err(CE_NOTE, "Suspend operation failed.");
409 409 } else if (CPR->c_flags & C_SUSPENDING) {
410 410
411 411 /*
412 412 * In the suspend to RAM case, by the time we get
413 413 * control back we're already resumed
414 414 */
415 415 if (cpr_sleeptype == CPR_TORAM) {
416 416 PMD(PMD_SX, ("cpr: cpr CPR_TORAM done\n"))
417 417 cpr_done();
418 418 return (rc);
419 419 }
420 420
421 421 #if defined(__sparc)
422 422
423 423 PMD(PMD_SX, ("cpr: Suspend operation succeeded.\n"))
424 424 /*
425 425 * Back from a successful checkpoint
426 426 */
427 427 if (fcn == AD_CPR_TESTZ || fcn == AD_CPR_TESTNOZ) {
428 428 mdboot(0, AD_BOOT, "", B_FALSE);
429 429 /* NOTREACHED */
430 430 }
431 431
432 432 /* make sure there are no more changes to the device tree */
433 433 PMD(PMD_SX, ("cpr: dev tree freeze\n"))
434 434 devtree_freeze();
435 435
436 436 /*
437 437 * stop other cpus and raise our priority. since there is only
438 438 * one active cpu after this, and our priority will be too high
439 439 * for us to be preempted, we're essentially single threaded
440 440 * from here on out.
441 441 */
442 442 PMD(PMD_SX, ("cpr: stop other cpus\n"))
443 443 i_cpr_stop_other_cpus();
444 444 PMD(PMD_SX, ("cpr: spl6\n"))
445 445 (void) spl6();
446 446
447 447 /*
448 448 * try and reset leaf devices. reset_leaves() should only
449 449 * be called when there are no other threads that could be
450 450 * accessing devices
451 451 */
452 452 PMD(PMD_SX, ("cpr: reset leaves\n"))
453 453 reset_leaves();
454 454
455 455 /*
456 456 * If i_cpr_power_down() succeeds, it'll not return
457 457 *
458 458 * Drives with write-cache enabled need to flush
459 459 * their cache.
460 460 */
461 461 if (fcn != AD_CPR_TESTHALT) {
462 462 PMD(PMD_SX, ("cpr: power down\n"))
463 463 (void) i_cpr_power_down(cpr_sleeptype);
464 464 }
465 465 ASSERT(cpr_sleeptype == CPR_TODISK);
466 466 /* currently CPR_TODISK comes back via a boot path */
467 467 CPR_DEBUG(CPR_DEBUG1, "(Done. Please Switch Off)\n");
468 468 halt(NULL);
469 469 /* NOTREACHED */
470 470 #endif
471 471 }
472 472 PMD(PMD_SX, ("cpr: cpr done\n"))
473 473 cpr_done();
474 474 return (rc);
475 475 }
↓ open down ↓ |
397 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX