]>
| Commit | Line | Data |
|---|---|---|
| 959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 48c46ee3 | 2 | /* |
| da23017d NS |
3 | * Copyright (c) 2004-2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. | |
| 48c46ee3 NS |
5 | */ |
| 6 | ||
| 6b803e5a CH |
7 | #include "command.h" |
| 8 | #include "input.h" | |
| 48c46ee3 NS |
9 | #include "init.h" |
| 10 | #include "io.h" | |
| 11 | ||
| 12 | static cmdinfo_t shutdown_cmd; | |
| 13 | ||
| 14 | static int | |
| 15 | shutdown_f( | |
| 16 | int argc, | |
| 17 | char **argv) | |
| 18 | { | |
| 19 | int c, flag = XFS_FSOP_GOING_FLAGS_NOLOGFLUSH; | |
| 20 | ||
| 21 | while ((c = getopt(argc, argv, "fv")) != -1) { | |
| 22 | switch (c) { | |
| 23 | case 'f': | |
| 24 | flag = XFS_FSOP_GOING_FLAGS_LOGFLUSH; | |
| 25 | break; | |
| 26 | default: | |
| 9e1595e6 | 27 | exitcode = 1; |
| 48c46ee3 NS |
28 | return command_usage(&shutdown_cmd); |
| 29 | } | |
| 30 | } | |
| 31 | ||
| 32 | if ((xfsctl(file->name, file->fd, XFS_IOC_GOINGDOWN, &flag)) < 0) { | |
| 33 | perror("XFS_IOC_GOINGDOWN"); | |
| 9e1595e6 | 34 | exitcode = 1; |
| 48c46ee3 NS |
35 | return 0; |
| 36 | } | |
| 37 | return 0; | |
| 38 | } | |
| 39 | ||
| 0d88afd6 CM |
40 | static void |
| 41 | shutdown_help(void) | |
| 42 | { | |
| 43 | printf(_( | |
| 44 | "\n" | |
| 45 | " Shuts down the filesystem and prevents any further IO from occurring.\n" | |
| 46 | "\n" | |
| 47 | " By default, shutdown will not flush completed transactions to disk\n" | |
| 48 | " before shutting the filesystem down, simulating a disk failure or crash.\n" | |
| 49 | " With -f, the log will be flushed to disk, matching XFS behavior when\n" | |
| 50 | " metadata corruption is encountered.\n" | |
| 51 | "\n" | |
| 52 | " -f -- Flush completed transactions to disk before shut down.\n" | |
| 53 | "\n")); | |
| 54 | } | |
| 55 | ||
| 48c46ee3 NS |
56 | void |
| 57 | shutdown_init(void) | |
| 58 | { | |
| ad765595 | 59 | shutdown_cmd.name = "shutdown"; |
| 48c46ee3 NS |
60 | shutdown_cmd.cfunc = shutdown_f; |
| 61 | shutdown_cmd.argmin = 0; | |
| 62 | shutdown_cmd.argmax = 1; | |
| 75dc6781 | 63 | shutdown_cmd.flags = CMD_NOMAP_OK | CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK; |
| 48c46ee3 | 64 | shutdown_cmd.args = _("[-f]"); |
| 0d88afd6 | 65 | shutdown_cmd.help = shutdown_help; |
| 48c46ee3 NS |
66 | shutdown_cmd.oneline = |
| 67 | _("shuts down the filesystem where the current file resides"); | |
| 68 | ||
| 69 | if (expert) | |
| 70 | add_command(&shutdown_cmd); | |
| 71 | } |