* Shutdown the system cleanly to prepare for reboot, halt, or power off. */
| 1334 | * Shutdown the system cleanly to prepare for reboot, halt, or power off. |
| 1335 | */ |
| 1336 | void |
| 1337 | bufshutdown(int show_busybufs) |
| 1338 | { |
| 1339 | static int first_buf_printf = 1; |
| 1340 | struct buf *bp; |
| 1341 | int i, iter, nbusy, pbusy; |
| 1342 | #ifndef PREEMPTION |
| 1343 | int subiter; |
| 1344 | #endif |
| 1345 | |
| 1346 | /* |
| 1347 | * Sync filesystems for shutdown |
| 1348 | */ |
| 1349 | wdog_kern_pat(WD_LASTVAL); |
| 1350 | kern_sync(curthread); |
| 1351 | |
| 1352 | /* |
| 1353 | * With soft updates, some buffers that are |
| 1354 | * written will be remarked as dirty until other |
| 1355 | * buffers are written. |
| 1356 | */ |
| 1357 | for (iter = pbusy = 0; iter < 20; iter++) { |
| 1358 | nbusy = 0; |
| 1359 | for (i = nbuf - 1; i >= 0; i--) { |
| 1360 | bp = nbufp(i); |
| 1361 | if (isbufbusy(bp)) |
| 1362 | nbusy++; |
| 1363 | } |
| 1364 | if (nbusy == 0) { |
| 1365 | if (first_buf_printf) |
| 1366 | printf("All buffers synced."); |
| 1367 | break; |
| 1368 | } |
| 1369 | if (first_buf_printf) { |
| 1370 | printf("Syncing disks, buffers remaining... "); |
| 1371 | first_buf_printf = 0; |
| 1372 | } |
| 1373 | printf("%d ", nbusy); |
| 1374 | if (nbusy < pbusy) |
| 1375 | iter = 0; |
| 1376 | pbusy = nbusy; |
| 1377 | |
| 1378 | wdog_kern_pat(WD_LASTVAL); |
| 1379 | kern_sync(curthread); |
| 1380 | |
| 1381 | #ifdef PREEMPTION |
| 1382 | /* |
| 1383 | * Spin for a while to allow interrupt threads to run. |
| 1384 | */ |
| 1385 | DELAY(50000 * iter); |
| 1386 | #else |
| 1387 | /* |
| 1388 | * Context switch several times to allow interrupt |
| 1389 | * threads to run. |
| 1390 | */ |
| 1391 | for (subiter = 0; subiter < 50 * iter; subiter++) { |
| 1392 | thread_lock(curthread); |
| 1393 | mi_switch(SW_VOL); |
no test coverage detected