Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "hypervisor_state_manager.hpp" |
| 4 | |
| 5 | #include <fmt/format.h> |
| 6 | |
| 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include <phosphor-logging/log.hpp> |
| 9 | #include <sdbusplus/exception.hpp> |
| 10 | #include <sdbusplus/server.hpp> |
| 11 | |
| 12 | #include <fstream> |
| 13 | #include <iostream> |
| 14 | #include <map> |
| 15 | #include <string> |
| 16 | |
| 17 | namespace phosphor |
| 18 | { |
| 19 | namespace state |
| 20 | { |
| 21 | namespace manager |
| 22 | { |
| 23 | |
| 24 | // When you see server:: you know we're referencing our base class |
| 25 | namespace server = sdbusplus::xyz::openbmc_project::State::server; |
| 26 | using namespace phosphor::logging; |
| 27 | using sdbusplus::exception::SdBusError; |
| 28 | |
| 29 | server::Host::Transition Hypervisor::requestedHostTransition(Transition value) |
| 30 | { |
| 31 | log<level::INFO>(fmt::format("Hypervisor state transition request of {}", |
| 32 | convertForMessage(value)) |
| 33 | .c_str()); |
| 34 | |
| 35 | // Only support the transition to On |
| 36 | if (value != server::Host::Transition::On) |
| 37 | { |
| 38 | log<level::ERR>("Hypervisor state only supports a transition to On"); |
| 39 | // TODO raise appropriate error exception |
| 40 | return server::Host::Transition::Off; |
| 41 | } |
| 42 | |
| 43 | // This property is monitored by a separate application (for example PLDM) |
| 44 | // which is responsible for propagating the On request to the hypervisor |
| 45 | |
| 46 | return server::Host::requestedHostTransition(value); |
| 47 | } |
| 48 | |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 49 | server::Host::HostState Hypervisor::currentHostState(HostState value) |
| 50 | { |
| 51 | log<level::INFO>( |
| 52 | fmt::format("Change to Hypervisor State: {}", convertForMessage(value)) |
| 53 | .c_str()); |
| 54 | return server::Host::currentHostState(value); |
| 55 | } |
| 56 | |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame^] | 57 | server::Host::HostState Hypervisor::currentHostState() |
| 58 | { |
| 59 | return server::Host::currentHostState(); |
| 60 | } |
| 61 | |
| 62 | void Hypervisor::updateCurrentHostState(std::string& bootProgress) |
| 63 | { |
| 64 | log<level::DEBUG>( |
| 65 | fmt::format("New BootProgress: {}", bootProgress).c_str()); |
| 66 | |
| 67 | if (bootProgress == "xyz.openbmc_project.State.Boot.Progress." |
| 68 | "ProgressStages.SystemInitComplete") |
| 69 | { |
| 70 | currentHostState(server::Host::HostState::Standby); |
| 71 | } |
| 72 | else if (bootProgress == "xyz.openbmc_project.State.Boot.Progress." |
| 73 | "ProgressStages.OSStart") |
| 74 | { |
| 75 | currentHostState(server::Host::HostState::TransitioningToRunning); |
| 76 | } |
| 77 | else if (bootProgress == "xyz.openbmc_project.State.Boot.Progress." |
| 78 | "ProgressStages.OSRunning") |
| 79 | { |
| 80 | currentHostState(server::Host::HostState::Running); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | // BootProgress changed and it is not one of the above so |
| 85 | // set hypervisor state to off |
| 86 | currentHostState(server::Host::HostState::Off); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void Hypervisor::bootProgressChangeEvent(sdbusplus::message::message& msg) |
| 91 | { |
| 92 | std::string statusInterface; |
| 93 | std::map<std::string, std::variant<std::string>> msgData; |
| 94 | msg.read(statusInterface, msgData); |
| 95 | |
| 96 | auto propertyMap = msgData.find("BootProgress"); |
| 97 | if (propertyMap != msgData.end()) |
| 98 | { |
| 99 | // Extract the BootProgress |
| 100 | auto& bootProgress = std::get<std::string>(propertyMap->second); |
| 101 | updateCurrentHostState(bootProgress); |
| 102 | } |
| 103 | } |
| 104 | |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 105 | } // namespace manager |
| 106 | } // namespace state |
| 107 | } // namespace phosphor |