Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame^] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "host_state_manager.hpp" |
| 4 | |
| 5 | #include <systemd/sd-bus.h> |
| 6 | |
| 7 | #include <cereal/archives/json.hpp> |
| 8 | #include <cereal/cereal.hpp> |
| 9 | #include <cereal/types/string.hpp> |
| 10 | #include <cereal/types/tuple.hpp> |
| 11 | #include <cereal/types/vector.hpp> |
| 12 | #include <phosphor-logging/elog-errors.hpp> |
| 13 | #include <phosphor-logging/log.hpp> |
| 14 | #include <sdbusplus/exception.hpp> |
| 15 | #include <sdbusplus/server.hpp> |
| 16 | #include <xyz/openbmc_project/Common/error.hpp> |
| 17 | #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp> |
| 18 | |
| 19 | #include <fstream> |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 20 | #include <iostream> |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 21 | #include <map> |
| 22 | #include <string> |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 23 | |
Vishwanatha Subbanna | 0a83873 | 2017-10-05 12:43:19 +0530 | [diff] [blame] | 24 | // Register class version with Cereal |
Andrew Geissler | 769a62f | 2019-12-06 13:36:08 -0600 | [diff] [blame] | 25 | CEREAL_CLASS_VERSION(phosphor::state::manager::Host, CLASS_VERSION) |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 26 | |
| 27 | namespace phosphor |
| 28 | { |
| 29 | namespace state |
| 30 | { |
| 31 | namespace manager |
| 32 | { |
| 33 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 34 | // When you see server:: or reboot:: you know we're referencing our base class |
Andrew Geissler | 3e3b84b | 2016-12-02 15:46:17 -0600 | [diff] [blame] | 35 | namespace server = sdbusplus::xyz::openbmc_project::State::server; |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 36 | namespace reboot = sdbusplus::xyz::openbmc_project::Control::Boot::server; |
Dhruvaraj Subhashchandran | a3b8d7e | 2017-08-10 05:40:04 -0500 | [diff] [blame] | 37 | namespace bootprogress = sdbusplus::xyz::openbmc_project::State::Boot::server; |
| 38 | namespace osstatus = |
| 39 | sdbusplus::xyz::openbmc_project::State::OperatingSystem::server; |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 40 | using namespace phosphor::logging; |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 41 | namespace fs = std::experimental::filesystem; |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 42 | using sdbusplus::exception::SdBusError; |
Andrew Geissler | 2f60aae | 2019-09-12 13:25:21 -0500 | [diff] [blame] | 43 | using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 44 | |
Andrew Geissler | 4f309e8 | 2017-05-24 15:18:01 -0500 | [diff] [blame] | 45 | // host-shutdown notifies host of shutdown and that leads to host-stop being |
| 46 | // called so initiate a host shutdown with the -shutdown target and consider the |
| 47 | // host shut down when the -stop target is complete |
| 48 | constexpr auto HOST_STATE_SOFT_POWEROFF_TGT = "obmc-host-shutdown@0.target"; |
Josh D. King | ca35792 | 2017-04-11 13:44:09 -0500 | [diff] [blame] | 49 | constexpr auto HOST_STATE_POWEROFF_TGT = "obmc-host-stop@0.target"; |
| 50 | constexpr auto HOST_STATE_POWERON_TGT = "obmc-host-start@0.target"; |
Andrew Geissler | 969b261 | 2018-03-29 10:16:51 -0700 | [diff] [blame] | 51 | constexpr auto HOST_STATE_POWERON_MIN_TGT = "obmc-host-startmin@0.target"; |
Andrew Geissler | a27a6e8 | 2017-07-27 16:44:43 -0500 | [diff] [blame] | 52 | constexpr auto HOST_STATE_REBOOT_TGT = "obmc-host-reboot@0.target"; |
Andrew Geissler | 40dd6e7 | 2020-02-07 14:31:12 -0600 | [diff] [blame] | 53 | constexpr auto HOST_STATE_WARM_REBOOT = "obmc-host-warm-reboot@0.target"; |
| 54 | constexpr auto HOST_STATE_FORCE_WARM_REBOOT = |
| 55 | "obmc-host-force-warm-reboot@0.target"; |
Andrew Geissler | 47b9612 | 2020-02-11 16:13:13 -0600 | [diff] [blame] | 56 | constexpr auto HOST_STATE_DIAGNOSTIC_MODE = |
| 57 | "obmc-host-diagnostic-mode@0.target"; |
Andrew Geissler | 40dd6e7 | 2020-02-07 14:31:12 -0600 | [diff] [blame] | 58 | |
Josh D. King | cc3fb5d | 2017-04-19 15:45:10 -0500 | [diff] [blame] | 59 | constexpr auto HOST_STATE_QUIESCE_TGT = "obmc-host-quiesce@0.target"; |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 60 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 61 | constexpr auto ACTIVE_STATE = "active"; |
| 62 | constexpr auto ACTIVATING_STATE = "activating"; |
| 63 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 64 | /* Map a transition to it's systemd target */ |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 65 | const std::map<server::Host::Transition, std::string> SYSTEMD_TARGET_TABLE = { |
| 66 | {server::Host::Transition::Off, HOST_STATE_SOFT_POWEROFF_TGT}, |
| 67 | {server::Host::Transition::On, HOST_STATE_POWERON_TGT}, |
Andrew Geissler | 40dd6e7 | 2020-02-07 14:31:12 -0600 | [diff] [blame] | 68 | {server::Host::Transition::Reboot, HOST_STATE_REBOOT_TGT}, |
| 69 | {server::Host::Transition::GracefulWarmReboot, HOST_STATE_WARM_REBOOT}, |
| 70 | {server::Host::Transition::ForceWarmReboot, HOST_STATE_FORCE_WARM_REBOOT}}; |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 71 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 72 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 73 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 74 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
| 75 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 76 | constexpr auto SYSTEMD_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 77 | constexpr auto SYSTEMD_INTERFACE_UNIT = "org.freedesktop.systemd1.Unit"; |
| 78 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 79 | void Host::subscribeToSystemdSignals() |
| 80 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 81 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 82 | SYSTEMD_INTERFACE, "Subscribe"); |
Andrew Geissler | 2f60aae | 2019-09-12 13:25:21 -0500 | [diff] [blame] | 83 | try |
| 84 | { |
| 85 | this->bus.call_noreply(method); |
| 86 | } |
| 87 | catch (const SdBusError& e) |
| 88 | { |
| 89 | log<level::ERR>("Failed to subscribe to systemd signals", |
| 90 | entry("ERR=%s", e.what())); |
| 91 | elog<InternalFailure>(); |
| 92 | } |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 93 | return; |
| 94 | } |
| 95 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 96 | void Host::determineInitialState() |
| 97 | { |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 98 | |
Andrew Geissler | 969b261 | 2018-03-29 10:16:51 -0700 | [diff] [blame] | 99 | if (stateActive(HOST_STATE_POWERON_MIN_TGT)) |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 100 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 101 | log<level::INFO>("Initial Host State will be Running", |
| 102 | entry("CURRENT_HOST_STATE=%s", |
| 103 | convertForMessage(HostState::Running).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 104 | server::Host::currentHostState(HostState::Running); |
| 105 | server::Host::requestedHostTransition(Transition::On); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 106 | } |
| 107 | else |
| 108 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 109 | log<level::INFO>("Initial Host State will be Off", |
| 110 | entry("CURRENT_HOST_STATE=%s", |
| 111 | convertForMessage(HostState::Off).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 112 | server::Host::currentHostState(HostState::Off); |
| 113 | server::Host::requestedHostTransition(Transition::Off); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 114 | } |
| 115 | |
Andrew Geissler | 033fc3b | 2017-08-30 15:11:44 -0500 | [diff] [blame] | 116 | if (!deserialize(HOST_STATE_PERSIST_PATH)) |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 117 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 118 | // set to default value. |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 119 | server::Host::requestedHostTransition(Transition::Off); |
| 120 | } |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 121 | |
| 122 | return; |
| 123 | } |
| 124 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 125 | void Host::executeTransition(Transition tranReq) |
| 126 | { |
| 127 | auto sysdUnit = SYSTEMD_TARGET_TABLE.find(tranReq)->second; |
| 128 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 129 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 130 | SYSTEMD_INTERFACE, "StartUnit"); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 131 | |
| 132 | method.append(sysdUnit); |
| 133 | method.append("replace"); |
| 134 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 135 | this->bus.call_noreply(method); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 136 | |
| 137 | return; |
| 138 | } |
| 139 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 140 | bool Host::stateActive(const std::string& target) |
| 141 | { |
Patrick Williams | 2975e26 | 2020-05-13 18:01:09 -0500 | [diff] [blame] | 142 | std::variant<std::string> currentState; |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 143 | sdbusplus::message::object_path unitTargetPath; |
| 144 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 145 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 146 | SYSTEMD_INTERFACE, "GetUnit"); |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 147 | |
| 148 | method.append(target); |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 149 | |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 150 | try |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 151 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 152 | auto result = this->bus.call(method); |
| 153 | result.read(unitTargetPath); |
| 154 | } |
| 155 | catch (const SdBusError& e) |
| 156 | { |
| 157 | log<level::ERR>("Error in GetUnit call", entry("ERROR=%s", e.what())); |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 158 | return false; |
| 159 | } |
| 160 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 161 | method = this->bus.new_method_call( |
| 162 | SYSTEMD_SERVICE, |
| 163 | static_cast<const std::string&>(unitTargetPath).c_str(), |
| 164 | SYSTEMD_PROPERTY_IFACE, "Get"); |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 165 | |
| 166 | method.append(SYSTEMD_INTERFACE_UNIT, "ActiveState"); |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 167 | |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 168 | try |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 169 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 170 | auto result = this->bus.call(method); |
| 171 | result.read(currentState); |
| 172 | } |
| 173 | catch (const SdBusError& e) |
| 174 | { |
| 175 | log<level::ERR>("Error in ActiveState Get", |
| 176 | entry("ERROR=%s", e.what())); |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 177 | return false; |
| 178 | } |
| 179 | |
Patrick Williams | 37413dc | 2020-05-13 11:29:54 -0500 | [diff] [blame] | 180 | const auto& currentStateStr = std::get<std::string>(currentState); |
William A. Kennington III | 7a0689a | 2018-11-12 17:19:33 -0800 | [diff] [blame] | 181 | return currentStateStr == ACTIVE_STATE || |
| 182 | currentStateStr == ACTIVATING_STATE; |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 183 | } |
| 184 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 185 | bool Host::isAutoReboot() |
| 186 | { |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 187 | using namespace settings; |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 188 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 189 | auto method = bus.new_method_call( |
| 190 | settings.service(settings.autoReboot, autoRebootIntf).c_str(), |
| 191 | settings.autoReboot.c_str(), "org.freedesktop.DBus.Properties", "Get"); |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 192 | method.append(autoRebootIntf, "AutoReboot"); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 193 | |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 194 | try |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 195 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 196 | auto reply = bus.call(method); |
| 197 | |
Patrick Williams | 2975e26 | 2020-05-13 18:01:09 -0500 | [diff] [blame] | 198 | std::variant<bool> result; |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 199 | reply.read(result); |
Patrick Williams | 37413dc | 2020-05-13 11:29:54 -0500 | [diff] [blame] | 200 | auto autoReboot = std::get<bool>(result); |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 201 | auto rebootCounterParam = reboot::RebootAttempts::attemptsLeft(); |
| 202 | |
| 203 | if (autoReboot) |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 204 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 205 | if (rebootCounterParam > 0) |
| 206 | { |
| 207 | // Reduce BOOTCOUNT by 1 |
| 208 | log<level::INFO>("Auto reboot enabled, rebooting"); |
| 209 | return true; |
| 210 | } |
| 211 | else if (rebootCounterParam == 0) |
| 212 | { |
| 213 | // Reset reboot counter and go to quiesce state |
| 214 | log<level::INFO>("Auto reboot enabled. " |
| 215 | "HOST BOOTCOUNT already set to 0."); |
| 216 | attemptsLeft(BOOT_COUNT_MAX_ALLOWED); |
| 217 | return false; |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | log<level::INFO>("Auto reboot enabled. " |
| 222 | "HOST BOOTCOUNT has an invalid value."); |
| 223 | return false; |
| 224 | } |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 225 | } |
| 226 | else |
| 227 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 228 | log<level::INFO>("Auto reboot disabled."); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 229 | return false; |
| 230 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 231 | } |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 232 | catch (const SdBusError& e) |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 233 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 234 | log<level::ERR>("Error in AutoReboot Get", entry("ERROR=%s", e.what())); |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 235 | return false; |
| 236 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 237 | } |
| 238 | |
Andrew Geissler | e4039a8 | 2020-02-11 15:51:59 -0600 | [diff] [blame] | 239 | void Host::sysStateChangeJobRemoved(sdbusplus::message::message& msg) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 240 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 241 | uint32_t newStateID{}; |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 242 | sdbusplus::message::object_path newStateObjPath; |
| 243 | std::string newStateUnit{}; |
| 244 | std::string newStateResult{}; |
| 245 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 246 | // Read the msg and populate each variable |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 247 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 248 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 249 | if ((newStateUnit == HOST_STATE_POWEROFF_TGT) && |
Andrew Geissler | 969b261 | 2018-03-29 10:16:51 -0700 | [diff] [blame] | 250 | (newStateResult == "done") && |
| 251 | (!stateActive(HOST_STATE_POWERON_MIN_TGT))) |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 252 | { |
Andrew Jeffery | 55b983e | 2017-04-19 11:11:26 +0930 | [diff] [blame] | 253 | log<level::INFO>("Received signal that host is off"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 254 | this->currentHostState(server::Host::HostState::Off); |
Dhruvaraj Subhashchandran | a3b8d7e | 2017-08-10 05:40:04 -0500 | [diff] [blame] | 255 | this->bootProgress(bootprogress::Progress::ProgressStages::Unspecified); |
| 256 | this->operatingSystemState(osstatus::Status::OSStatus::Inactive); |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 257 | } |
Andrew Geissler | 969b261 | 2018-03-29 10:16:51 -0700 | [diff] [blame] | 258 | else if ((newStateUnit == HOST_STATE_POWERON_MIN_TGT) && |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 259 | (newStateResult == "done") && |
Andrew Geissler | 969b261 | 2018-03-29 10:16:51 -0700 | [diff] [blame] | 260 | (stateActive(HOST_STATE_POWERON_MIN_TGT))) |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 261 | { |
| 262 | log<level::INFO>("Received signal that host is running"); |
| 263 | this->currentHostState(server::Host::HostState::Running); |
| 264 | } |
| 265 | else if ((newStateUnit == HOST_STATE_QUIESCE_TGT) && |
Josh D. King | 29d025d | 2017-04-27 12:40:22 -0500 | [diff] [blame] | 266 | (newStateResult == "done") && |
| 267 | (stateActive(HOST_STATE_QUIESCE_TGT))) |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 268 | { |
| 269 | if (Host::isAutoReboot()) |
| 270 | { |
| 271 | log<level::INFO>("Beginning reboot..."); |
| 272 | Host::requestedHostTransition(server::Host::Transition::Reboot); |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | log<level::INFO>("Maintaining quiesce"); |
| 277 | this->currentHostState(server::Host::HostState::Quiesced); |
| 278 | } |
| 279 | } |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 280 | } |
| 281 | |
Andrew Geissler | 47b9612 | 2020-02-11 16:13:13 -0600 | [diff] [blame] | 282 | void Host::sysStateChangeJobNew(sdbusplus::message::message& msg) |
| 283 | { |
| 284 | uint32_t newStateID{}; |
| 285 | sdbusplus::message::object_path newStateObjPath; |
| 286 | std::string newStateUnit{}; |
| 287 | |
| 288 | // Read the msg and populate each variable |
| 289 | msg.read(newStateID, newStateObjPath, newStateUnit); |
| 290 | |
| 291 | if (newStateUnit == HOST_STATE_DIAGNOSTIC_MODE) |
| 292 | { |
| 293 | log<level::INFO>("Received signal that host is in diagnostice mode"); |
| 294 | this->currentHostState(server::Host::HostState::DiagnosticMode); |
| 295 | } |
| 296 | } |
| 297 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 298 | uint32_t Host::decrementRebootCount() |
| 299 | { |
| 300 | auto rebootCount = reboot::RebootAttempts::attemptsLeft(); |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 301 | if (rebootCount > 0) |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 302 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 303 | return (reboot::RebootAttempts::attemptsLeft(rebootCount - 1)); |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 304 | } |
| 305 | return rebootCount; |
| 306 | } |
| 307 | |
Andrew Geissler | 033fc3b | 2017-08-30 15:11:44 -0500 | [diff] [blame] | 308 | fs::path Host::serialize(const fs::path& dir) |
| 309 | { |
| 310 | std::ofstream os(dir.c_str(), std::ios::binary); |
| 311 | cereal::JSONOutputArchive oarchive(os); |
| 312 | oarchive(*this); |
| 313 | return dir; |
| 314 | } |
| 315 | |
| 316 | bool Host::deserialize(const fs::path& path) |
| 317 | { |
Jayanth Othayoth | e39f379 | 2017-09-19 23:53:31 -0500 | [diff] [blame] | 318 | try |
Andrew Geissler | 033fc3b | 2017-08-30 15:11:44 -0500 | [diff] [blame] | 319 | { |
Jayanth Othayoth | e39f379 | 2017-09-19 23:53:31 -0500 | [diff] [blame] | 320 | if (fs::exists(path)) |
| 321 | { |
| 322 | std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); |
| 323 | cereal::JSONInputArchive iarchive(is); |
| 324 | iarchive(*this); |
| 325 | return true; |
| 326 | } |
| 327 | return false; |
Andrew Geissler | 033fc3b | 2017-08-30 15:11:44 -0500 | [diff] [blame] | 328 | } |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 329 | catch (cereal::Exception& e) |
Jayanth Othayoth | e39f379 | 2017-09-19 23:53:31 -0500 | [diff] [blame] | 330 | { |
| 331 | log<level::ERR>(e.what()); |
| 332 | fs::remove(path); |
| 333 | return false; |
| 334 | } |
Andrew Geissler | 033fc3b | 2017-08-30 15:11:44 -0500 | [diff] [blame] | 335 | } |
| 336 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 337 | Host::Transition Host::requestedHostTransition(Transition value) |
| 338 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 339 | log<level::INFO>("Host State transaction request", |
| 340 | entry("REQUESTED_HOST_TRANSITION=%s", |
| 341 | convertForMessage(value).c_str())); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 342 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 343 | // If this is not a power off request then we need to |
| 344 | // decrement the reboot counter. This code should |
| 345 | // never prevent a power on, it should just decrement |
| 346 | // the count to 0. The quiesce handling is where the |
| 347 | // check of this count will occur |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 348 | if (value != server::Host::Transition::Off) |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 349 | { |
| 350 | decrementRebootCount(); |
| 351 | } |
| 352 | |
Andrew Geissler | a27a6e8 | 2017-07-27 16:44:43 -0500 | [diff] [blame] | 353 | executeTransition(value); |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 354 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 355 | auto retVal = server::Host::requestedHostTransition(value); |
Andrew Geissler | 033fc3b | 2017-08-30 15:11:44 -0500 | [diff] [blame] | 356 | serialize(); |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 357 | return retVal; |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 358 | } |
| 359 | |
Dhruvaraj Subhashchandran | 4e6534f | 2017-09-19 06:13:20 -0500 | [diff] [blame] | 360 | Host::ProgressStages Host::bootProgress(ProgressStages value) |
| 361 | { |
| 362 | auto retVal = bootprogress::Progress::bootProgress(value); |
| 363 | serialize(); |
| 364 | return retVal; |
| 365 | } |
| 366 | |
| 367 | Host::OSStatus Host::operatingSystemState(OSStatus value) |
| 368 | { |
| 369 | auto retVal = osstatus::Status::operatingSystemState(value); |
| 370 | serialize(); |
| 371 | return retVal; |
| 372 | } |
| 373 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 374 | Host::HostState Host::currentHostState(HostState value) |
| 375 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 376 | log<level::INFO>( |
| 377 | "Change to Host State", |
| 378 | entry("CURRENT_HOST_STATE=%s", convertForMessage(value).c_str())); |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 379 | return server::Host::currentHostState(value); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 380 | } |
| 381 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 382 | } // namespace manager |
| 383 | } // namespace state |
Andrew Geissler | a965cf0 | 2018-08-31 08:37:05 -0700 | [diff] [blame] | 384 | } // namespace phosphor |