Andrew Geissler | ba0163a | 2021-08-11 15:09:50 -0400 | [diff] [blame^] | 1 | #include <phosphor-logging/log.hpp> |
| 2 | #include <sdbusplus/bus.hpp> |
| 3 | #include <sdbusplus/exception.hpp> |
| 4 | |
| 5 | #include <cstdlib> |
| 6 | #include <string> |
| 7 | |
| 8 | constexpr auto HOST_STATE_SVC = "xyz.openbmc_project.State.Host"; |
| 9 | constexpr auto HOST_STATE_PATH = "/xyz/openbmc_project/state/host0"; |
| 10 | constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"; |
| 11 | constexpr auto BOOT_STATE_INTF = "xyz.openbmc_project.State.Boot.Progress"; |
| 12 | constexpr auto BOOT_PROGRESS_PROP = "BootProgress"; |
| 13 | |
| 14 | using namespace phosphor::logging; |
| 15 | |
| 16 | bool wasHostBooting(sdbusplus::bus::bus& bus) |
| 17 | { |
| 18 | try |
| 19 | { |
| 20 | auto method = bus.new_method_call(HOST_STATE_SVC, HOST_STATE_PATH, |
| 21 | PROPERTY_INTERFACE, "Get"); |
| 22 | method.append(BOOT_STATE_INTF, BOOT_PROGRESS_PROP); |
| 23 | |
| 24 | auto response = bus.call(method); |
| 25 | |
| 26 | std::variant<std::string> bootProgress; |
| 27 | response.read(bootProgress); |
| 28 | |
| 29 | if (std::get<std::string>(bootProgress) == |
| 30 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 31 | "Unspecified") |
| 32 | { |
| 33 | log<level::INFO>("Host was not booting before BMC reboot"); |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | log<level::INFO>("Host was booting before BMC reboot", |
| 38 | entry("BOOTPROGRESS=%s", |
| 39 | std::get<std::string>(bootProgress).c_str())); |
| 40 | } |
| 41 | catch (const sdbusplus::exception::exception& e) |
| 42 | { |
| 43 | log<level::ERR>("Error reading BootProgress", |
| 44 | entry("ERROR=%s", e.what()), |
| 45 | entry("SERVICE=%s", HOST_STATE_SVC), |
| 46 | entry("PATH=%s", HOST_STATE_PATH)); |
| 47 | |
| 48 | throw; |
| 49 | } |
| 50 | |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | int main() |
| 55 | { |
| 56 | |
| 57 | auto bus = sdbusplus::bus::new_default(); |
| 58 | |
| 59 | // This application will only be started if chassis power is on and the |
| 60 | // host is not responding after a BMC reboot. |
| 61 | // TODO Wait for chassis power on target to complete |
| 62 | |
| 63 | // Check the last BootProgeress to see if the host was booting before |
| 64 | // the BMC reboot occurred |
| 65 | if (!wasHostBooting(bus)) |
| 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | // Host was booting before the BMC reboot so log an error and go to host |
| 71 | // quiesce target |
| 72 | // TODO Create Error |
| 73 | // TODO Move to Host Quiesce |
| 74 | |
| 75 | return 0; |
| 76 | } |