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> |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 7 | #include <experimental/filesystem> |
| 8 | #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp> |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 9 | #include "host_state_manager.hpp" |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 10 | #include "host_state_serialize.hpp" |
| 11 | #include "config.h" |
| 12 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 13 | |
| 14 | namespace phosphor |
| 15 | { |
| 16 | namespace state |
| 17 | { |
| 18 | namespace manager |
| 19 | { |
| 20 | |
Andrew Geissler | 3e3b84b | 2016-12-02 15:46:17 -0600 | [diff] [blame] | 21 | // When you see server:: you know we're referencing our base class |
| 22 | namespace server = sdbusplus::xyz::openbmc_project::State::server; |
| 23 | |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 24 | using namespace phosphor::logging; |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 25 | namespace fs = std::experimental::filesystem; |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 26 | |
Andrew Geissler | 4f309e8 | 2017-05-24 15:18:01 -0500 | [diff] [blame] | 27 | // host-shutdown notifies host of shutdown and that leads to host-stop being |
| 28 | // called so initiate a host shutdown with the -shutdown target and consider the |
| 29 | // host shut down when the -stop target is complete |
| 30 | 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] | 31 | constexpr auto HOST_STATE_POWEROFF_TGT = "obmc-host-stop@0.target"; |
| 32 | constexpr auto HOST_STATE_POWERON_TGT = "obmc-host-start@0.target"; |
Josh D. King | cc3fb5d | 2017-04-19 15:45:10 -0500 | [diff] [blame] | 33 | constexpr auto HOST_STATE_QUIESCE_TGT = "obmc-host-quiesce@0.target"; |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 34 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 35 | constexpr auto ACTIVE_STATE = "active"; |
| 36 | constexpr auto ACTIVATING_STATE = "activating"; |
| 37 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 38 | /* Map a transition to it's systemd target */ |
| 39 | const std::map<server::Host::Transition,std::string> SYSTEMD_TARGET_TABLE = |
| 40 | { |
Andrew Geissler | 4f309e8 | 2017-05-24 15:18:01 -0500 | [diff] [blame] | 41 | {server::Host::Transition::Off, HOST_STATE_SOFT_POWEROFF_TGT}, |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 42 | {server::Host::Transition::On, HOST_STATE_POWERON_TGT} |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 46 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 47 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
| 48 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 49 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
Leonel Gonzalez | f318d87 | 2017-03-16 13:47:49 -0500 | [diff] [blame] | 50 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 51 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 52 | |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 53 | constexpr auto REBOOTCOUNTER_SERVICE("org.openbmc.Sensors"); |
| 54 | constexpr auto REBOOTCOUNTER_PATH("/org/openbmc/sensors/host/BootCount"); |
| 55 | constexpr auto REBOOTCOUNTER_INTERFACE("org.openbmc.SensorValue"); |
| 56 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 57 | constexpr auto SYSTEMD_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 58 | constexpr auto SYSTEMD_INTERFACE_UNIT = "org.freedesktop.systemd1.Unit"; |
| 59 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 60 | constexpr auto SETTINGS_INTERFACE = |
| 61 | "xyz.openbmc_project.Control.Power.RestorePolicy"; |
| 62 | constexpr auto SETTINGS_SERVICE_ROOT = "/"; |
| 63 | constexpr auto SETTINGS_HOST_STATE_RESTORE = "PowerRestorePolicy"; |
| 64 | |
Andrew Geissler | 48696ce | 2017-05-22 14:41:58 -0500 | [diff] [blame] | 65 | // TODO openbmc/openbmc#1646 - boot count needs to be defined in 1 place |
| 66 | constexpr auto DEFAULT_BOOTCOUNT = 3; |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 67 | |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 68 | /* Map a system state to the HostState */ |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 69 | const std::map<std::string, server::Host::HostState> SYS_HOST_STATE_TABLE = { |
| 70 | {"HOST_BOOTING", server::Host::HostState::Running}, |
Saqib Khan | adaa721 | 2017-02-23 13:19:28 -0600 | [diff] [blame] | 71 | {"HOST_POWERED_OFF", server::Host::HostState::Off}, |
| 72 | {"HOST_QUIESCED", server::Host::HostState::Quiesced} |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 73 | }; |
| 74 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 75 | void Host::subscribeToSystemdSignals() |
| 76 | { |
| 77 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 78 | SYSTEMD_OBJ_PATH, |
| 79 | SYSTEMD_INTERFACE, |
| 80 | "Subscribe"); |
| 81 | this->bus.call_noreply(method); |
| 82 | |
| 83 | return; |
| 84 | } |
| 85 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 86 | void Host::determineInitialState() |
| 87 | { |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 88 | |
Josh D. King | 222014e | 2017-05-16 13:35:21 -0500 | [diff] [blame] | 89 | if(stateActive(HOST_STATE_POWERON_TGT)) |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 90 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 91 | log<level::INFO>("Initial Host State will be Running", |
| 92 | entry("CURRENT_HOST_STATE=%s", |
| 93 | convertForMessage(HostState::Running).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 94 | server::Host::currentHostState(HostState::Running); |
| 95 | server::Host::requestedHostTransition(Transition::On); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 96 | } |
| 97 | else |
| 98 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 99 | log<level::INFO>("Initial Host State will be Off", |
| 100 | entry("CURRENT_HOST_STATE=%s", |
| 101 | convertForMessage(HostState::Off).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 102 | server::Host::currentHostState(HostState::Off); |
| 103 | server::Host::requestedHostTransition(Transition::Off); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 104 | } |
| 105 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 106 | auto restore = getStateRestoreSetting(); |
| 107 | |
| 108 | if ((!restore) || (!deserialize(HOST_STATE_PERSIST_PATH,*this))) |
| 109 | { |
| 110 | //set to default value. |
| 111 | server::Host::requestedHostTransition(Transition::Off); |
| 112 | } |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 113 | |
| 114 | return; |
| 115 | } |
| 116 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 117 | bool Host::getStateRestoreSetting() const |
| 118 | { |
| 119 | using namespace phosphor::logging; |
| 120 | auto depth = 0; |
| 121 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, |
| 122 | MAPPER_PATH, |
| 123 | MAPPER_INTERFACE, |
| 124 | "GetSubTree"); |
| 125 | mapperCall.append(SETTINGS_SERVICE_ROOT); |
| 126 | mapperCall.append(depth); |
| 127 | mapperCall.append(std::vector<std::string>({SETTINGS_INTERFACE})); |
| 128 | |
| 129 | auto mapperResponseMsg = bus.call(mapperCall); |
| 130 | if (mapperResponseMsg.is_method_error()) |
| 131 | { |
| 132 | log<level::ERR>("Error in mapper call"); |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | using MapperResponseType = std::map<std::string, |
| 137 | std::map<std::string, std::vector<std::string>>>; |
| 138 | MapperResponseType mapperResponse; |
| 139 | mapperResponseMsg.read(mapperResponse); |
| 140 | if (mapperResponse.empty()) |
| 141 | { |
| 142 | log<level::ERR>("Invalid response from mapper"); |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | auto& settingsPath = mapperResponse.begin()->first; |
| 147 | auto& service = mapperResponse.begin()->second.begin()->first; |
| 148 | |
| 149 | auto cmdMsg = bus.new_method_call(service.c_str(), |
| 150 | settingsPath.c_str(), |
| 151 | SYSTEMD_PROPERTY_IFACE, |
| 152 | "Get"); |
| 153 | cmdMsg.append(SETTINGS_INTERFACE); |
| 154 | cmdMsg.append(SETTINGS_HOST_STATE_RESTORE); |
| 155 | |
| 156 | auto response = bus.call(cmdMsg); |
| 157 | if (response.is_method_error()) |
| 158 | { |
| 159 | log<level::ERR>("Error in fetching host state restore settings"); |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | sdbusplus::message::variant<std::string> result; |
| 164 | response.read(result); |
| 165 | |
| 166 | using RestorePolicy = sdbusplus::xyz::openbmc_project::Control:: |
| 167 | Power::server::RestorePolicy; |
| 168 | |
| 169 | if (RestorePolicy::convertPolicyFromString(result.get<std::string>()) == |
| 170 | RestorePolicy::Policy::Restore) |
| 171 | { |
| 172 | return true; |
| 173 | } |
| 174 | return false; |
| 175 | } |
| 176 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 177 | void Host::executeTransition(Transition tranReq) |
| 178 | { |
| 179 | auto sysdUnit = SYSTEMD_TARGET_TABLE.find(tranReq)->second; |
| 180 | |
| 181 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 182 | SYSTEMD_OBJ_PATH, |
| 183 | SYSTEMD_INTERFACE, |
| 184 | "StartUnit"); |
| 185 | |
| 186 | method.append(sysdUnit); |
| 187 | method.append("replace"); |
| 188 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 189 | this->bus.call_noreply(method); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 190 | |
| 191 | return; |
| 192 | } |
| 193 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 194 | bool Host::stateActive(const std::string& target) |
| 195 | { |
| 196 | sdbusplus::message::variant<std::string> currentState; |
| 197 | sdbusplus::message::object_path unitTargetPath; |
| 198 | |
| 199 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 200 | SYSTEMD_OBJ_PATH, |
| 201 | SYSTEMD_INTERFACE, |
| 202 | "GetUnit"); |
| 203 | |
| 204 | method.append(target); |
| 205 | auto result = this->bus.call(method); |
| 206 | |
| 207 | //Check that the bus call didn't result in an error |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 208 | if (result.is_method_error()) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 209 | { |
| 210 | log<level::ERR>("Error in bus call - could not resolve GetUnit for:", |
| 211 | entry(" %s", SYSTEMD_INTERFACE)); |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | result.read(unitTargetPath); |
| 216 | |
| 217 | method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 218 | static_cast<const std::string&> |
| 219 | (unitTargetPath).c_str(), |
| 220 | SYSTEMD_PROPERTY_IFACE, |
| 221 | "Get"); |
| 222 | |
| 223 | method.append(SYSTEMD_INTERFACE_UNIT, "ActiveState"); |
| 224 | result = this->bus.call(method); |
| 225 | |
| 226 | //Check that the bus call didn't result in an error |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 227 | if (result.is_method_error()) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 228 | { |
| 229 | log<level::ERR>("Error in bus call - could not resolve Get for:", |
| 230 | entry(" %s", SYSTEMD_PROPERTY_IFACE)); |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | result.read(currentState); |
| 235 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 236 | if (currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 237 | { |
| 238 | //False - not active |
| 239 | return false; |
| 240 | } |
| 241 | //True - active |
| 242 | return true; |
| 243 | } |
| 244 | |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 245 | void Host::setHostbootCount(int bootCount) |
| 246 | { |
| 247 | auto method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE, |
| 248 | REBOOTCOUNTER_PATH, |
| 249 | REBOOTCOUNTER_INTERFACE, |
| 250 | "setValue"); |
| 251 | sdbusplus::message::variant<int> newParam = bootCount; |
| 252 | method.append(newParam); |
| 253 | this->bus.call_noreply(method); |
| 254 | } |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 255 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 256 | bool Host::isAutoReboot() |
| 257 | { |
| 258 | sdbusplus::message::variant<std::string> autoRebootParam; |
| 259 | std::string strParam; |
| 260 | |
| 261 | std::string HOST_PATH("/org/openbmc/settings/host0"); |
| 262 | std::string HOST_INTERFACE("org.openbmc.settings.Host"); |
| 263 | |
| 264 | auto mapper = this->bus.new_method_call(MAPPER_BUSNAME, |
| 265 | MAPPER_PATH, |
| 266 | MAPPER_INTERFACE, |
| 267 | "GetObject"); |
| 268 | |
| 269 | mapper.append(HOST_PATH, std::vector<std::string>({HOST_INTERFACE})); |
| 270 | auto mapperResponseMsg = this->bus.call(mapper); |
| 271 | |
| 272 | if (mapperResponseMsg.is_method_error()) |
| 273 | { |
| 274 | log<level::ERR>("Error in mapper call"); |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 279 | mapperResponseMsg.read(mapperResponse); |
| 280 | if (mapperResponse.empty()) |
| 281 | { |
| 282 | log<level::ERR>("Error reading mapper response"); |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | const auto& host = mapperResponse.begin()->first; |
| 287 | |
| 288 | auto method = this->bus.new_method_call(host.c_str(), |
| 289 | HOST_PATH.c_str(), |
| 290 | "org.freedesktop.DBus.Properties", |
| 291 | "Get"); |
| 292 | |
| 293 | method.append(HOST_INTERFACE.c_str(), "auto_reboot"); |
| 294 | auto reply = this->bus.call(method); |
| 295 | |
| 296 | if (reply.is_method_error()) |
| 297 | { |
| 298 | log<level::ERR>("Error in auto_reboot Get"); |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | reply.read(autoRebootParam); |
| 303 | strParam = |
| 304 | sdbusplus::message::variant_ns::get<std::string>(autoRebootParam); |
| 305 | |
| 306 | if (strParam.empty()) |
| 307 | { |
| 308 | log<level::ERR>("Error reading auto_reboot response"); |
| 309 | return false; |
| 310 | } |
| 311 | |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 312 | sdbusplus::message::variant<int> rebootCounterParam = 0; |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 313 | method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE, |
| 314 | REBOOTCOUNTER_PATH, |
| 315 | REBOOTCOUNTER_INTERFACE, |
| 316 | "getValue"); |
| 317 | reply = this->bus.call(method); |
| 318 | if (reply.is_method_error()) |
| 319 | { |
| 320 | log<level::ERR>("Error in BOOTCOUNT getValue"); |
| 321 | return false; |
| 322 | } |
| 323 | reply.read(rebootCounterParam); |
| 324 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 325 | if (strParam == "yes") |
| 326 | { |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 327 | if ( rebootCounterParam > 0) |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 328 | { |
| 329 | // Reduce BOOTCOUNT by 1 |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 330 | log<level::INFO>("Auto reboot enabled. " |
| 331 | "Reducing HOST BOOTCOUNT by 1."); |
| 332 | Host::setHostbootCount((sdbusplus::message::variant_ns:: |
| 333 | get<int>(rebootCounterParam)) - 1); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 334 | return true; |
| 335 | } |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 336 | else if(rebootCounterParam == 0) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 337 | { |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 338 | // Reset reboot counter and go to quiesce state |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 339 | log<level::INFO>("Auto reboot enabled. " |
| 340 | "HOST BOOTCOUNT already set to 0."); |
| 341 | Host::setHostbootCount(DEFAULT_BOOTCOUNT); |
| 342 | return false; |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | log<level::INFO>("Auto reboot enabled. " |
| 347 | "HOST BOOTCOUNT has an invalid value."); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 348 | return false; |
| 349 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 350 | } |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 351 | else |
| 352 | { |
| 353 | log<level::INFO>("Auto reboot disabled."); |
| 354 | return false; |
| 355 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 356 | } |
| 357 | |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 358 | void Host::sysStateChange(sdbusplus::message::message& msg) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 359 | { |
| 360 | uint32_t newStateID {}; |
| 361 | sdbusplus::message::object_path newStateObjPath; |
| 362 | std::string newStateUnit{}; |
| 363 | std::string newStateResult{}; |
| 364 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 365 | //Read the msg and populate each variable |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 366 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 367 | |
| 368 | if((newStateUnit == HOST_STATE_POWEROFF_TGT) && |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 369 | (newStateResult == "done") && |
| 370 | (!stateActive(HOST_STATE_POWERON_TGT))) |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 371 | { |
Andrew Jeffery | 55b983e | 2017-04-19 11:11:26 +0930 | [diff] [blame] | 372 | log<level::INFO>("Received signal that host is off"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 373 | this->currentHostState(server::Host::HostState::Off); |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 374 | |
| 375 | // Check if we need to start a new transition (i.e. a Reboot) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 376 | if(this->server::Host::requestedHostTransition() == |
| 377 | Transition::Reboot) |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 378 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 379 | log<level::DEBUG>("Reached intermediate state, going to next"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 380 | this->executeTransition(server::Host::Transition::On); |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 381 | } |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 382 | } |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 383 | else if((newStateUnit == HOST_STATE_POWERON_TGT) && |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 384 | (newStateResult == "done") && |
| 385 | (stateActive(HOST_STATE_POWERON_TGT))) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 386 | { |
Andrew Jeffery | 55b983e | 2017-04-19 11:11:26 +0930 | [diff] [blame] | 387 | log<level::INFO>("Received signal that host is running"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 388 | this->currentHostState(server::Host::HostState::Running); |
| 389 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 390 | else if((newStateUnit == HOST_STATE_QUIESCE_TGT) && |
Josh D. King | 29d025d | 2017-04-27 12:40:22 -0500 | [diff] [blame] | 391 | (newStateResult == "done") && |
| 392 | (stateActive(HOST_STATE_QUIESCE_TGT))) |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 393 | { |
| 394 | if (Host::isAutoReboot()) |
| 395 | { |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 396 | log<level::INFO>("Beginning reboot..."); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 397 | Host::requestedHostTransition(server::Host::Transition::Reboot); |
| 398 | } |
| 399 | else |
| 400 | { |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 401 | log<level::INFO>("Maintaining quiesce"); |
Saqib Khan | adaa721 | 2017-02-23 13:19:28 -0600 | [diff] [blame] | 402 | this->currentHostState(server::Host::HostState::Quiesced); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | } |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 406 | } |
| 407 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 408 | Host::Transition Host::requestedHostTransition(Transition value) |
| 409 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 410 | log<level::INFO>( |
| 411 | "Host State transaction request", |
| 412 | entry("REQUESTED_HOST_TRANSITION=%s", |
| 413 | convertForMessage(value).c_str())); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 414 | |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 415 | Transition tranReq = value; |
| 416 | if(value == server::Host::Transition::Reboot) |
| 417 | { |
| 418 | // On reboot requests we just need to do a off if we're on and |
| 419 | // vice versa. The handleSysStateChange() code above handles the |
| 420 | // second part of the reboot |
| 421 | if(this->server::Host::currentHostState() == |
| 422 | server::Host::HostState::Off) |
| 423 | { |
| 424 | tranReq = server::Host::Transition::On; |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | tranReq = server::Host::Transition::Off; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | executeTransition(tranReq); |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame^] | 433 | auto retVal = server::Host::requestedHostTransition(value); |
| 434 | serialize(*this); |
| 435 | return retVal; |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 436 | } |
| 437 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 438 | Host::HostState Host::currentHostState(HostState value) |
| 439 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 440 | log<level::INFO>("Change to Host State", |
| 441 | entry("CURRENT_HOST_STATE=%s", |
| 442 | convertForMessage(value).c_str())); |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 443 | return server::Host::currentHostState(value); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 444 | } |
| 445 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 446 | } // namespace manager |
| 447 | } // namespace state |
| 448 | } // namepsace phosphor |