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