bmc-reset: check host boot progress prior to reset
This series of commits will add logic within the phosphor-state-manager
to log an error and initiate recovery operations when the BMC is
rebooted while the host is booting or if the host shuts itself down
while the BMC is rebooting. If the host continues to boot and
responds to the BMC queries when it comes out of reboot, then this new
service will never run. It is only if the host fails to respond (and it
was booting or booted prior to the BMC reboot) that this service runs.
The goal is to log an error and move the host to the Quiesce state so
the system recovery policy can be checked and executed by the existing
state management code.
Testing statements will be in the final commit of this series.
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I18312ac55f0d0c3082992b6aecd10b0620966b20
diff --git a/host_reset_recovery.cpp b/host_reset_recovery.cpp
new file mode 100644
index 0000000..cd61aa9
--- /dev/null
+++ b/host_reset_recovery.cpp
@@ -0,0 +1,76 @@
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/exception.hpp>
+
+#include <cstdlib>
+#include <string>
+
+constexpr auto HOST_STATE_SVC = "xyz.openbmc_project.State.Host";
+constexpr auto HOST_STATE_PATH = "/xyz/openbmc_project/state/host0";
+constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
+constexpr auto BOOT_STATE_INTF = "xyz.openbmc_project.State.Boot.Progress";
+constexpr auto BOOT_PROGRESS_PROP = "BootProgress";
+
+using namespace phosphor::logging;
+
+bool wasHostBooting(sdbusplus::bus::bus& bus)
+{
+ try
+ {
+ auto method = bus.new_method_call(HOST_STATE_SVC, HOST_STATE_PATH,
+ PROPERTY_INTERFACE, "Get");
+ method.append(BOOT_STATE_INTF, BOOT_PROGRESS_PROP);
+
+ auto response = bus.call(method);
+
+ std::variant<std::string> bootProgress;
+ response.read(bootProgress);
+
+ if (std::get<std::string>(bootProgress) ==
+ "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
+ "Unspecified")
+ {
+ log<level::INFO>("Host was not booting before BMC reboot");
+ return false;
+ }
+
+ log<level::INFO>("Host was booting before BMC reboot",
+ entry("BOOTPROGRESS=%s",
+ std::get<std::string>(bootProgress).c_str()));
+ }
+ catch (const sdbusplus::exception::exception& e)
+ {
+ log<level::ERR>("Error reading BootProgress",
+ entry("ERROR=%s", e.what()),
+ entry("SERVICE=%s", HOST_STATE_SVC),
+ entry("PATH=%s", HOST_STATE_PATH));
+
+ throw;
+ }
+
+ return true;
+}
+
+int main()
+{
+
+ auto bus = sdbusplus::bus::new_default();
+
+ // This application will only be started if chassis power is on and the
+ // host is not responding after a BMC reboot.
+ // TODO Wait for chassis power on target to complete
+
+ // Check the last BootProgeress to see if the host was booting before
+ // the BMC reboot occurred
+ if (!wasHostBooting(bus))
+ {
+ return 0;
+ }
+
+ // Host was booting before the BMC reboot so log an error and go to host
+ // quiesce target
+ // TODO Create Error
+ // TODO Move to Host Quiesce
+
+ return 0;
+}
diff --git a/meson.build b/meson.build
index 51a2ddd..faec1e1 100644
--- a/meson.build
+++ b/meson.build
@@ -139,6 +139,15 @@
install: true
)
+executable('phosphor-host-reset-recovery',
+ 'host_reset_recovery.cpp',
+ dependencies: [
+ sdbusplus, phosphorlogging
+ ],
+ implicit_include_directories: true,
+ install: true
+)
+
install_data('obmcutil',
install_mode: 'rwxr-xr-x',
install_dir: get_option('bindir')