Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 1 | #include <iostream> |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 2 | #include <map> |
| 3 | #include <string> |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 4 | #include <systemd/sd-bus.h> |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 5 | #include <sdbusplus/server.hpp> |
Saqib Khan | a8006a2 | 2017-02-14 11:37:08 -0600 | [diff] [blame] | 6 | #include <phosphor-logging/log.hpp> |
Deepak Kodihalli | 55f132b | 2017-07-25 07:36:06 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 8 | #include <experimental/filesystem> |
| 9 | #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp> |
Deepak Kodihalli | 55f132b | 2017-07-25 07:36:06 -0500 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Common/error.hpp> |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 11 | #include "host_state_manager.hpp" |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 12 | #include "host_state_serialize.hpp" |
| 13 | #include "config.h" |
| 14 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace state |
| 19 | { |
| 20 | namespace manager |
| 21 | { |
| 22 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 23 | // 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] | 24 | namespace server = sdbusplus::xyz::openbmc_project::State::server; |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 25 | namespace reboot = sdbusplus::xyz::openbmc_project::Control::Boot::server; |
Dhruvaraj Subhashchandran | a3b8d7e | 2017-08-10 05:40:04 -0500 | [diff] [blame^] | 26 | namespace bootprogress = sdbusplus::xyz::openbmc_project::State::Boot::server; |
| 27 | namespace osstatus = |
| 28 | sdbusplus::xyz::openbmc_project::State::OperatingSystem::server; |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 29 | using namespace phosphor::logging; |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 30 | namespace fs = std::experimental::filesystem; |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 31 | |
Andrew Geissler | 4f309e8 | 2017-05-24 15:18:01 -0500 | [diff] [blame] | 32 | // host-shutdown notifies host of shutdown and that leads to host-stop being |
| 33 | // called so initiate a host shutdown with the -shutdown target and consider the |
| 34 | // host shut down when the -stop target is complete |
| 35 | 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] | 36 | constexpr auto HOST_STATE_POWEROFF_TGT = "obmc-host-stop@0.target"; |
| 37 | constexpr auto HOST_STATE_POWERON_TGT = "obmc-host-start@0.target"; |
Andrew Geissler | a27a6e8 | 2017-07-27 16:44:43 -0500 | [diff] [blame] | 38 | constexpr auto HOST_STATE_REBOOT_TGT = "obmc-host-reboot@0.target"; |
Josh D. King | cc3fb5d | 2017-04-19 15:45:10 -0500 | [diff] [blame] | 39 | constexpr auto HOST_STATE_QUIESCE_TGT = "obmc-host-quiesce@0.target"; |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 40 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 41 | constexpr auto ACTIVE_STATE = "active"; |
| 42 | constexpr auto ACTIVATING_STATE = "activating"; |
| 43 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 44 | /* Map a transition to it's systemd target */ |
| 45 | const std::map<server::Host::Transition,std::string> SYSTEMD_TARGET_TABLE = |
| 46 | { |
Andrew Geissler | 4f309e8 | 2017-05-24 15:18:01 -0500 | [diff] [blame] | 47 | {server::Host::Transition::Off, HOST_STATE_SOFT_POWEROFF_TGT}, |
Andrew Geissler | a27a6e8 | 2017-07-27 16:44:43 -0500 | [diff] [blame] | 48 | {server::Host::Transition::On, HOST_STATE_POWERON_TGT}, |
| 49 | {server::Host::Transition::Reboot, HOST_STATE_REBOOT_TGT} |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 53 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 54 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
| 55 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 56 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
Leonel Gonzalez | f318d87 | 2017-03-16 13:47:49 -0500 | [diff] [blame] | 57 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 58 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 59 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 60 | constexpr auto SYSTEMD_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 61 | constexpr auto SYSTEMD_INTERFACE_UNIT = "org.freedesktop.systemd1.Unit"; |
| 62 | |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 63 | /* Map a system state to the HostState */ |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 64 | const std::map<std::string, server::Host::HostState> SYS_HOST_STATE_TABLE = { |
| 65 | {"HOST_BOOTING", server::Host::HostState::Running}, |
Saqib Khan | adaa721 | 2017-02-23 13:19:28 -0600 | [diff] [blame] | 66 | {"HOST_POWERED_OFF", server::Host::HostState::Off}, |
| 67 | {"HOST_QUIESCED", server::Host::HostState::Quiesced} |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 68 | }; |
| 69 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 70 | void Host::subscribeToSystemdSignals() |
| 71 | { |
| 72 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 73 | SYSTEMD_OBJ_PATH, |
| 74 | SYSTEMD_INTERFACE, |
| 75 | "Subscribe"); |
| 76 | this->bus.call_noreply(method); |
| 77 | |
| 78 | return; |
| 79 | } |
| 80 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 81 | void Host::determineInitialState() |
| 82 | { |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 83 | |
Josh D. King | 222014e | 2017-05-16 13:35:21 -0500 | [diff] [blame] | 84 | if(stateActive(HOST_STATE_POWERON_TGT)) |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 85 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 86 | log<level::INFO>("Initial Host State will be Running", |
| 87 | entry("CURRENT_HOST_STATE=%s", |
| 88 | convertForMessage(HostState::Running).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 89 | server::Host::currentHostState(HostState::Running); |
| 90 | server::Host::requestedHostTransition(Transition::On); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 91 | } |
| 92 | else |
| 93 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 94 | log<level::INFO>("Initial Host State will be Off", |
| 95 | entry("CURRENT_HOST_STATE=%s", |
| 96 | convertForMessage(HostState::Off).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 97 | server::Host::currentHostState(HostState::Off); |
| 98 | server::Host::requestedHostTransition(Transition::Off); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 99 | } |
| 100 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 101 | auto restore = getStateRestoreSetting(); |
| 102 | |
Dhruvaraj Subhashchandran | 2710e73 | 2017-06-19 06:43:22 -0500 | [diff] [blame] | 103 | if ((!restore) || (!deserialize(HOST_STATE_PERSIST_PATH, *this))) |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 104 | { |
| 105 | //set to default value. |
| 106 | server::Host::requestedHostTransition(Transition::Off); |
| 107 | } |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 108 | |
| 109 | return; |
| 110 | } |
| 111 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 112 | bool Host::getStateRestoreSetting() const |
| 113 | { |
Deepak Kodihalli | 55f132b | 2017-07-25 07:36:06 -0500 | [diff] [blame] | 114 | using namespace settings; |
| 115 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 116 | using namespace sdbusplus::xyz::openbmc_project::Control::Power::server; |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 117 | |
Deepak Kodihalli | 55f132b | 2017-07-25 07:36:06 -0500 | [diff] [blame] | 118 | auto method = |
| 119 | bus.new_method_call( |
| 120 | settings.service(settings.powerRestorePolicy, |
| 121 | powerRestoreIntf).c_str(), |
| 122 | settings.powerRestorePolicy.c_str(), |
| 123 | "org.freedesktop.DBus.Properties", |
| 124 | "Get"); |
| 125 | |
| 126 | method.append(powerRestoreIntf, "PowerRestorePolicy"); |
| 127 | auto reply = bus.call(method); |
| 128 | if (reply.is_method_error()) |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 129 | { |
Deepak Kodihalli | 55f132b | 2017-07-25 07:36:06 -0500 | [diff] [blame] | 130 | log<level::ERR>("Error in PowerRestorePolicy Get"); |
| 131 | elog<InternalFailure>(); |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | sdbusplus::message::variant<std::string> result; |
Deepak Kodihalli | 55f132b | 2017-07-25 07:36:06 -0500 | [diff] [blame] | 135 | reply.read(result); |
| 136 | auto powerPolicy = result.get<std::string>(); |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 137 | |
Deepak Kodihalli | 55f132b | 2017-07-25 07:36:06 -0500 | [diff] [blame] | 138 | if (RestorePolicy::Policy::Restore == |
| 139 | RestorePolicy::convertPolicyFromString(powerPolicy)) |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 140 | { |
| 141 | return true; |
| 142 | } |
| 143 | return false; |
| 144 | } |
| 145 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 146 | void Host::executeTransition(Transition tranReq) |
| 147 | { |
| 148 | auto sysdUnit = SYSTEMD_TARGET_TABLE.find(tranReq)->second; |
| 149 | |
| 150 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 151 | SYSTEMD_OBJ_PATH, |
| 152 | SYSTEMD_INTERFACE, |
| 153 | "StartUnit"); |
| 154 | |
| 155 | method.append(sysdUnit); |
| 156 | method.append("replace"); |
| 157 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 158 | this->bus.call_noreply(method); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 159 | |
| 160 | return; |
| 161 | } |
| 162 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 163 | bool Host::stateActive(const std::string& target) |
| 164 | { |
| 165 | sdbusplus::message::variant<std::string> currentState; |
| 166 | sdbusplus::message::object_path unitTargetPath; |
| 167 | |
| 168 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 169 | SYSTEMD_OBJ_PATH, |
| 170 | SYSTEMD_INTERFACE, |
| 171 | "GetUnit"); |
| 172 | |
| 173 | method.append(target); |
| 174 | auto result = this->bus.call(method); |
| 175 | |
| 176 | //Check that the bus call didn't result in an error |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 177 | if (result.is_method_error()) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 178 | { |
| 179 | log<level::ERR>("Error in bus call - could not resolve GetUnit for:", |
| 180 | entry(" %s", SYSTEMD_INTERFACE)); |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | result.read(unitTargetPath); |
| 185 | |
| 186 | method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 187 | static_cast<const std::string&> |
| 188 | (unitTargetPath).c_str(), |
| 189 | SYSTEMD_PROPERTY_IFACE, |
| 190 | "Get"); |
| 191 | |
| 192 | method.append(SYSTEMD_INTERFACE_UNIT, "ActiveState"); |
| 193 | result = this->bus.call(method); |
| 194 | |
| 195 | //Check that the bus call didn't result in an error |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 196 | if (result.is_method_error()) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 197 | { |
| 198 | log<level::ERR>("Error in bus call - could not resolve Get for:", |
| 199 | entry(" %s", SYSTEMD_PROPERTY_IFACE)); |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | result.read(currentState); |
| 204 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 205 | if (currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 206 | { |
| 207 | //False - not active |
| 208 | return false; |
| 209 | } |
| 210 | //True - active |
| 211 | return true; |
| 212 | } |
| 213 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 214 | bool Host::isAutoReboot() |
| 215 | { |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 216 | using namespace settings; |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 217 | |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 218 | auto method = |
| 219 | bus.new_method_call( |
| 220 | settings.service(settings.autoReboot, autoRebootIntf).c_str(), |
| 221 | settings.autoReboot.c_str(), |
| 222 | "org.freedesktop.DBus.Properties", |
| 223 | "Get"); |
| 224 | method.append(autoRebootIntf, "AutoReboot"); |
| 225 | auto reply = bus.call(method); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 226 | if (reply.is_method_error()) |
| 227 | { |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 228 | log<level::ERR>("Error in AutoReboot Get"); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 229 | return false; |
| 230 | } |
| 231 | |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 232 | sdbusplus::message::variant<bool> result; |
| 233 | reply.read(result); |
| 234 | auto autoReboot = result.get<bool>(); |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 235 | auto rebootCounterParam = reboot::RebootAttempts::attemptsLeft(); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 236 | |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 237 | if (autoReboot) |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 238 | { |
Dhruvaraj Subhashchandran | 2710e73 | 2017-06-19 06:43:22 -0500 | [diff] [blame] | 239 | if (rebootCounterParam > 0) |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 240 | { |
| 241 | // Reduce BOOTCOUNT by 1 |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 242 | log<level::INFO>("Auto reboot enabled, rebooting"); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 243 | return true; |
| 244 | } |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 245 | else if(rebootCounterParam == 0) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 246 | { |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 247 | // Reset reboot counter and go to quiesce state |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 248 | log<level::INFO>("Auto reboot enabled. " |
| 249 | "HOST BOOTCOUNT already set to 0."); |
Dhruvaraj Subhashchandran | 2710e73 | 2017-06-19 06:43:22 -0500 | [diff] [blame] | 250 | attemptsLeft(BOOT_COUNT_MAX_ALLOWED); |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 251 | return false; |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | log<level::INFO>("Auto reboot enabled. " |
| 256 | "HOST BOOTCOUNT has an invalid value."); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 257 | return false; |
| 258 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 259 | } |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 260 | else |
| 261 | { |
| 262 | log<level::INFO>("Auto reboot disabled."); |
| 263 | return false; |
| 264 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 265 | } |
| 266 | |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 267 | void Host::sysStateChange(sdbusplus::message::message& msg) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 268 | { |
| 269 | uint32_t newStateID {}; |
| 270 | sdbusplus::message::object_path newStateObjPath; |
| 271 | std::string newStateUnit{}; |
| 272 | std::string newStateResult{}; |
| 273 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 274 | //Read the msg and populate each variable |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 275 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 276 | |
| 277 | if((newStateUnit == HOST_STATE_POWEROFF_TGT) && |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 278 | (newStateResult == "done") && |
| 279 | (!stateActive(HOST_STATE_POWERON_TGT))) |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 280 | { |
Andrew Jeffery | 55b983e | 2017-04-19 11:11:26 +0930 | [diff] [blame] | 281 | log<level::INFO>("Received signal that host is off"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 282 | this->currentHostState(server::Host::HostState::Off); |
Dhruvaraj Subhashchandran | a3b8d7e | 2017-08-10 05:40:04 -0500 | [diff] [blame^] | 283 | this->bootProgress(bootprogress::Progress::ProgressStages::Unspecified); |
| 284 | this->operatingSystemState(osstatus::Status::OSStatus::Inactive); |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 285 | |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 286 | } |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 287 | else if((newStateUnit == HOST_STATE_POWERON_TGT) && |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 288 | (newStateResult == "done") && |
| 289 | (stateActive(HOST_STATE_POWERON_TGT))) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 290 | { |
Andrew Jeffery | 55b983e | 2017-04-19 11:11:26 +0930 | [diff] [blame] | 291 | log<level::INFO>("Received signal that host is running"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 292 | this->currentHostState(server::Host::HostState::Running); |
| 293 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 294 | else if((newStateUnit == HOST_STATE_QUIESCE_TGT) && |
Josh D. King | 29d025d | 2017-04-27 12:40:22 -0500 | [diff] [blame] | 295 | (newStateResult == "done") && |
| 296 | (stateActive(HOST_STATE_QUIESCE_TGT))) |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 297 | { |
| 298 | if (Host::isAutoReboot()) |
| 299 | { |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 300 | log<level::INFO>("Beginning reboot..."); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 301 | Host::requestedHostTransition(server::Host::Transition::Reboot); |
| 302 | } |
| 303 | else |
| 304 | { |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 305 | log<level::INFO>("Maintaining quiesce"); |
Saqib Khan | adaa721 | 2017-02-23 13:19:28 -0600 | [diff] [blame] | 306 | this->currentHostState(server::Host::HostState::Quiesced); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | } |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 310 | } |
| 311 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 312 | uint32_t Host::decrementRebootCount() |
| 313 | { |
| 314 | auto rebootCount = reboot::RebootAttempts::attemptsLeft(); |
| 315 | if(rebootCount > 0) |
| 316 | { |
| 317 | return(reboot::RebootAttempts::attemptsLeft(rebootCount - 1)); |
| 318 | } |
| 319 | return rebootCount; |
| 320 | } |
| 321 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 322 | Host::Transition Host::requestedHostTransition(Transition value) |
| 323 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 324 | log<level::INFO>( |
| 325 | "Host State transaction request", |
| 326 | entry("REQUESTED_HOST_TRANSITION=%s", |
| 327 | convertForMessage(value).c_str())); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 328 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 329 | // If this is not a power off request then we need to |
| 330 | // decrement the reboot counter. This code should |
| 331 | // never prevent a power on, it should just decrement |
| 332 | // the count to 0. The quiesce handling is where the |
| 333 | // check of this count will occur |
| 334 | if(value != server::Host::Transition::Off) |
| 335 | { |
| 336 | decrementRebootCount(); |
| 337 | } |
| 338 | |
Andrew Geissler | a27a6e8 | 2017-07-27 16:44:43 -0500 | [diff] [blame] | 339 | executeTransition(value); |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame] | 340 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 341 | auto retVal = server::Host::requestedHostTransition(value); |
| 342 | serialize(*this); |
| 343 | return retVal; |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 344 | } |
| 345 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 346 | Host::HostState Host::currentHostState(HostState value) |
| 347 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 348 | log<level::INFO>("Change to Host State", |
| 349 | entry("CURRENT_HOST_STATE=%s", |
| 350 | convertForMessage(value).c_str())); |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 351 | return server::Host::currentHostState(value); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 352 | } |
| 353 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 354 | } // namespace manager |
| 355 | } // namespace state |
| 356 | } // namepsace phosphor |