Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 3 | #include <string> |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 4 | #include <functional> |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame^] | 6 | #include <phosphor-logging/log.hpp> |
Dhruvaraj Subhashchandran | 2710e73 | 2017-06-19 06:43:22 -0500 | [diff] [blame] | 7 | #include <xyz/openbmc_project/State/Boot/Progress/server.hpp> |
| 8 | #include <xyz/openbmc_project/Control/Boot/RebootAttempts/server.hpp> |
| 9 | #include <xyz/openbmc_project/State/OperatingSystem/Status/server.hpp> |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 10 | #include "xyz/openbmc_project/State/Host/server.hpp" |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 11 | #include "settings.hpp" |
Dhruvaraj Subhashchandran | 2710e73 | 2017-06-19 06:43:22 -0500 | [diff] [blame] | 12 | #include "config.h" |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 13 | |
| 14 | namespace phosphor |
| 15 | { |
| 16 | namespace state |
| 17 | { |
| 18 | namespace manager |
| 19 | { |
| 20 | |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 21 | using HostInherit = sdbusplus::server::object::object< |
Dhruvaraj Subhashchandran | 2710e73 | 2017-06-19 06:43:22 -0500 | [diff] [blame] | 22 | sdbusplus::xyz::openbmc_project::State::server::Host, |
| 23 | sdbusplus::xyz::openbmc_project::State::Boot::server::Progress, |
| 24 | sdbusplus::xyz::openbmc_project::Control::Boot::server::RebootAttempts, |
| 25 | sdbusplus::xyz::openbmc_project::State::OperatingSystem::server::Status>; |
| 26 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame^] | 27 | using namespace phosphor::logging; |
| 28 | |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 29 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 30 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 31 | /** @class Host |
| 32 | * @brief OpenBMC host state management implementation. |
| 33 | * @details A concrete implementation for xyz.openbmc_project.State.Host |
| 34 | * DBus API. |
| 35 | */ |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 36 | class Host : public HostInherit |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | /** @brief Constructs Host State Manager |
| 40 | * |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 41 | * @note This constructor passes 'true' to the base class in order to |
| 42 | * defer dbus object registration until we can run |
| 43 | * determineInitialState() and set our properties |
| 44 | * |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 45 | * @param[in] bus - The Dbus bus object |
| 46 | * @param[in] busName - The Dbus name to own |
| 47 | * @param[in] objPath - The Dbus object path |
| 48 | */ |
| 49 | Host(sdbusplus::bus::bus& bus, |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 50 | const char* busName, |
| 51 | const char* objPath) : |
| 52 | HostInherit(bus, objPath, true), |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 53 | bus(bus), |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 54 | systemdSignals( |
| 55 | bus, |
| 56 | sdbusRule::type::signal() + |
| 57 | sdbusRule::member("JobRemoved") + |
| 58 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 59 | sdbusRule::interface( |
| 60 | "org.freedesktop.systemd1.Manager"), |
| 61 | std::bind(std::mem_fn(&Host::sysStateChange), |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 62 | this, std::placeholders::_1)), |
| 63 | settings(bus) |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 64 | { |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 65 | // Enable systemd signals |
| 66 | subscribeToSystemdSignals(); |
| 67 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 68 | // Will throw exception on fail |
| 69 | determineInitialState(); |
| 70 | |
Dhruvaraj Subhashchandran | 2710e73 | 2017-06-19 06:43:22 -0500 | [diff] [blame] | 71 | attemptsLeft(BOOT_COUNT_MAX_ALLOWED); |
| 72 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 73 | // We deferred this until we could get our property correct |
| 74 | this->emit_object_added(); |
| 75 | } |
| 76 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 77 | /** @brief Set value of HostTransition */ |
| 78 | Transition requestedHostTransition(Transition value) override; |
| 79 | |
| 80 | /** @brief Set value of CurrentHostState */ |
| 81 | HostState currentHostState(HostState value) override; |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 82 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame^] | 83 | /** |
| 84 | * @brief Set host reboot count to default |
| 85 | * |
| 86 | * OpenBMC software controls the number of allowed reboot attempts so |
| 87 | * any external set request of this property will be overridden by |
| 88 | * this function and set to the default. |
| 89 | * |
| 90 | * The only code responsible for decrementing the boot count resides |
| 91 | * within this process and that will use the sub class interface |
| 92 | * directly |
| 93 | * |
| 94 | * @param[in] value - Reboot count value, will be ignored |
| 95 | * |
| 96 | * @return Default number of reboot attempts left |
| 97 | */ |
| 98 | uint32_t attemptsLeft(uint32_t value) override |
| 99 | { |
| 100 | log<level::DEBUG>("External request to reset reboot count"); |
| 101 | return (sdbusplus::xyz::openbmc_project::Control::Boot::server:: |
| 102 | RebootAttempts::attemptsLeft(BOOT_COUNT_MAX_ALLOWED)); |
| 103 | } |
| 104 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 105 | private: |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 106 | /** |
| 107 | * @brief subscribe to the systemd signals |
| 108 | * |
| 109 | * This object needs to capture when it's systemd targets complete |
| 110 | * so it can keep it's state updated |
| 111 | * |
| 112 | **/ |
| 113 | void subscribeToSystemdSignals(); |
| 114 | |
| 115 | /** |
| 116 | * @brief Determine initial host state and set internally |
| 117 | * |
| 118 | * @return Will throw exceptions on failure |
| 119 | **/ |
| 120 | void determineInitialState(); |
| 121 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 122 | /** @brief Execute the transition request |
| 123 | * |
| 124 | * This function assumes the state has been validated and the host |
| 125 | * is in an appropriate state for the transition to be started. |
| 126 | * |
| 127 | * @param[in] tranReq - Transition requested |
| 128 | */ |
| 129 | void executeTransition(Transition tranReq); |
| 130 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 131 | /** |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 132 | * @brief Determine if target is active |
| 133 | * |
| 134 | * This function determines if the target is active and |
| 135 | * helps prevent misleading log recorded states. |
| 136 | * |
| 137 | * @param[in] target - Target string to check on |
| 138 | * |
| 139 | * @return boolean corresponding to state active |
| 140 | **/ |
| 141 | bool stateActive(const std::string& target); |
| 142 | |
| 143 | /** |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 144 | * @brief Determine if auto reboot flag is set |
| 145 | * |
| 146 | * @return boolean corresponding to current auto_reboot setting |
| 147 | **/ |
| 148 | bool isAutoReboot(); |
| 149 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 150 | /** @brief Check if systemd state change is relevant to this object |
| 151 | * |
| 152 | * Instance specific interface to handle the detected systemd state |
| 153 | * change |
| 154 | * |
| 155 | * @param[in] msg - Data associated with subscribed signal |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 156 | * |
| 157 | */ |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 158 | void sysStateChange(sdbusplus::message::message& msg); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 159 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 160 | /** @brief Determine whether restoring of host requested state is enabled |
| 161 | * |
| 162 | * @return boolean corresponding to restore setting |
| 163 | */ |
| 164 | bool getStateRestoreSetting() const; |
| 165 | |
Andrew Geissler | 7b90a62 | 2017-08-08 11:41:08 -0500 | [diff] [blame^] | 166 | /** @brief Decrement reboot count |
| 167 | * |
| 168 | * This is used internally to this application to decrement the boot |
| 169 | * count on each boot attempt. The host will use the external |
| 170 | * attemptsLeft() interface to reset the count when a boot is successful |
| 171 | * |
| 172 | * @return number of reboot count attempts left |
| 173 | */ |
| 174 | uint32_t decrementRebootCount(); |
| 175 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 176 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 177 | sdbusplus::bus::bus& bus; |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 178 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 179 | /** @brief Used to subscribe to dbus systemd signals **/ |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 180 | sdbusplus::bus::match_t systemdSignals; |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 181 | |
| 182 | // Settings objects of interest |
| 183 | settings::Objects settings; |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | } // namespace manager |
| 187 | } // namespace state |
| 188 | } // namespace phosphor |