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