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