Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 3 | #include <sdbusplus/server.hpp> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 4 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp" |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp" |
Gunnar Mills | f5eaf39 | 2017-08-22 16:36:55 -0500 | [diff] [blame] | 8 | #include "org/openbmc/Associations/server.hpp" |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace software |
| 13 | { |
| 14 | namespace updater |
| 15 | { |
| 16 | |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 17 | using AssociationList = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 18 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 19 | using ActivationInherit = sdbusplus::server::object::object< |
Gunnar Mills | f5eaf39 | 2017-08-22 16:36:55 -0500 | [diff] [blame] | 20 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 21 | sdbusplus::org::openbmc::server::Associations>; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 22 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 23 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 24 | ActivationBlocksTransition>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 25 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 26 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 27 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 28 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 29 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 30 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 31 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 32 | class ItemUpdater; |
| 33 | class Activation; |
| 34 | class RedundancyPriority; |
| 35 | |
| 36 | /** @class RedundancyPriority |
| 37 | * @brief OpenBMC RedundancyPriority implementation |
| 38 | * @details A concrete implementation for |
| 39 | * xyz.openbmc_project.Software.RedundancyPriority DBus API. |
| 40 | */ |
| 41 | class RedundancyPriority : public RedundancyPriorityInherit |
| 42 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 43 | public: |
| 44 | /** @brief Constructs RedundancyPriority. |
| 45 | * |
| 46 | * @param[in] bus - The Dbus bus object |
| 47 | * @param[in] path - The Dbus object path |
| 48 | * @param[in] parent - Parent object. |
| 49 | * @param[in] value - The redundancyPriority value |
| 50 | * @param[in] freePriority - Call freePriorioty, default to true |
| 51 | */ |
| 52 | RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path, |
| 53 | Activation& parent, uint8_t value, |
| 54 | bool freePriority = true) : |
| 55 | RedundancyPriorityInherit(bus, path.c_str(), true), |
| 56 | parent(parent), bus(bus), path(path) |
| 57 | { |
| 58 | // Set Property |
| 59 | if (freePriority) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 60 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 61 | priority(value); |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | sdbusPriority(value); |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 68 | std::vector<std::string> interfaces({interface}); |
| 69 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 70 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 71 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 72 | ~RedundancyPriority() |
| 73 | { |
| 74 | std::vector<std::string> interfaces({interface}); |
| 75 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 76 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 77 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 78 | /** @brief Overriden Priority property set function, calls freePriority |
| 79 | * to bump the duplicated priority values. |
| 80 | * |
| 81 | * @param[in] value - uint8_t |
| 82 | * |
| 83 | * @return Success or exception thrown |
| 84 | */ |
| 85 | uint8_t priority(uint8_t value) override; |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 86 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 87 | /** @brief Non-Overriden Priority property set function |
| 88 | * |
| 89 | * @param[in] value - uint8_t |
| 90 | * |
| 91 | * @return Success or exception thrown |
| 92 | */ |
| 93 | uint8_t sdbusPriority(uint8_t value); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 94 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 95 | /** @brief Priority property get function |
| 96 | * |
| 97 | * @returns uint8_t - The Priority value |
| 98 | */ |
| 99 | using RedundancyPriorityInherit::priority; |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 100 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 101 | /** @brief Parent Object. */ |
| 102 | Activation& parent; |
| 103 | |
| 104 | private: |
| 105 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 106 | static constexpr auto interface = |
| 107 | "xyz.openbmc_project.Software.RedundancyPriority"; |
| 108 | sdbusplus::bus::bus& bus; |
| 109 | std::string path; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 110 | }; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 111 | |
| 112 | /** @class ActivationBlocksTransition |
| 113 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 114 | * @details A concrete implementation for |
| 115 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 116 | */ |
| 117 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 118 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 119 | public: |
| 120 | /** @brief Constructs ActivationBlocksTransition. |
| 121 | * |
| 122 | * @param[in] bus - The Dbus bus object |
| 123 | * @param[in] path - The Dbus object path |
| 124 | */ |
| 125 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 126 | const std::string& path) : |
| 127 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 128 | bus(bus), path(path) |
| 129 | { |
| 130 | std::vector<std::string> interfaces({interface}); |
| 131 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 132 | enableRebootGuard(); |
| 133 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 134 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 135 | ~ActivationBlocksTransition() |
| 136 | { |
| 137 | std::vector<std::string> interfaces({interface}); |
| 138 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 139 | disableRebootGuard(); |
| 140 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 141 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 142 | private: |
| 143 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 144 | static constexpr auto interface = |
| 145 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 146 | sdbusplus::bus::bus& bus; |
| 147 | std::string path; |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 148 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 149 | /** @brief Enables a Guard that blocks any BMC reboot commands */ |
| 150 | void enableRebootGuard(); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 151 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 152 | /** @brief Disables any guard that was blocking the BMC reboot */ |
| 153 | void disableRebootGuard(); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 154 | }; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 155 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 156 | class ActivationProgress : public ActivationProgressInherit |
| 157 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 158 | public: |
| 159 | /** @brief Constructs ActivationProgress. |
| 160 | * |
| 161 | * @param[in] bus - The Dbus bus object |
| 162 | * @param[in] path - The Dbus object path |
| 163 | */ |
| 164 | ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) : |
| 165 | ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path) |
| 166 | { |
| 167 | progress(0); |
| 168 | std::vector<std::string> interfaces({interface}); |
| 169 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 170 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 171 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 172 | ~ActivationProgress() |
| 173 | { |
| 174 | std::vector<std::string> interfaces({interface}); |
| 175 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 176 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 177 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 178 | private: |
| 179 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 180 | static constexpr auto interface = |
| 181 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 182 | sdbusplus::bus::bus& bus; |
| 183 | std::string path; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 184 | }; |
| 185 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 186 | /** @class Activation |
| 187 | * @brief OpenBMC activation software management implementation. |
| 188 | * @details A concrete implementation for |
| 189 | * xyz.openbmc_project.Software.Activation DBus API. |
| 190 | */ |
| 191 | class Activation : public ActivationInherit |
| 192 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 193 | public: |
| 194 | /** @brief Constructs Activation Software Manager |
| 195 | * |
| 196 | * @param[in] bus - The Dbus bus object |
| 197 | * @param[in] path - The Dbus object path |
| 198 | * @param[in] parent - Parent object. |
| 199 | * @param[in] versionId - The software version id |
| 200 | * @param[in] activationStatus - The status of Activation |
| 201 | * @param[in] assocs - Association objects |
| 202 | */ |
| 203 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
| 204 | ItemUpdater& parent, std::string& versionId, |
| 205 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
| 206 | Activations activationStatus, |
| 207 | AssociationList& assocs) : |
| 208 | ActivationInherit(bus, path.c_str(), true), |
| 209 | bus(bus), path(path), parent(parent), versionId(versionId), |
| 210 | systemdSignals( |
| 211 | bus, |
| 212 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 213 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 214 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 215 | std::bind(std::mem_fn(&Activation::unitStateChange), this, |
| 216 | std::placeholders::_1)) |
| 217 | { |
| 218 | // Enable systemd signals |
| 219 | subscribeToSystemdSignals(); |
| 220 | // Set Properties. |
| 221 | activation(activationStatus); |
| 222 | associations(assocs); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 223 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 224 | // Emit deferred signal. |
| 225 | emit_object_added(); |
| 226 | } |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 227 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 228 | /** @brief Overloaded Activation property setter function |
| 229 | * |
| 230 | * @param[in] value - One of Activation::Activations |
| 231 | * |
| 232 | * @return Success or exception thrown |
| 233 | */ |
| 234 | Activations activation(Activations value) override; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 235 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 236 | /** @brief Activation */ |
| 237 | using ActivationInherit::activation; |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 238 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 239 | /** @brief Overloaded requestedActivation property setter function |
| 240 | * |
| 241 | * @param[in] value - One of Activation::RequestedActivations |
| 242 | * |
| 243 | * @return Success or exception thrown |
| 244 | */ |
| 245 | RequestedActivations |
| 246 | requestedActivation(RequestedActivations value) override; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 247 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 248 | /** @brief Check if systemd state change is relevant to this object |
| 249 | * |
| 250 | * Instance specific interface to handle the detected systemd state |
| 251 | * change |
| 252 | * |
| 253 | * @param[in] msg - Data associated with subscribed signal |
| 254 | * |
| 255 | */ |
| 256 | void unitStateChange(sdbusplus::message::message& msg); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 257 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 258 | /** |
| 259 | * @brief subscribe to the systemd signals |
| 260 | * |
| 261 | * This object needs to capture when it's systemd targets complete |
| 262 | * so it can keep it's state updated |
| 263 | * |
| 264 | */ |
| 265 | void subscribeToSystemdSignals(); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 266 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 267 | /** |
| 268 | * @brief unsubscribe from the systemd signals |
| 269 | * |
| 270 | * systemd signals are only of interest during the activation process. |
| 271 | * Once complete, we want to unsubscribe to avoid unnecessary calls of |
| 272 | * unitStateChange(). |
| 273 | * |
| 274 | */ |
| 275 | void unsubscribeFromSystemdSignals(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 276 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 277 | /** |
| 278 | * @brief Deletes the version from Image Manager and the |
| 279 | * untar image from image upload dir. |
| 280 | */ |
| 281 | void deleteImageManagerObject(); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 282 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 283 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 284 | sdbusplus::bus::bus& bus; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 285 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 286 | /** @brief Persistent DBus object path */ |
| 287 | std::string path; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 288 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 289 | /** @brief Parent Object. */ |
| 290 | ItemUpdater& parent; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 291 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 292 | /** @brief Version id */ |
| 293 | std::string versionId; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 294 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 295 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 296 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 297 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 298 | /** @brief Persistent RedundancyPriority dbus object */ |
| 299 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 300 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 301 | /** @brief Persistent ActivationProgress dbus object */ |
| 302 | std::unique_ptr<ActivationProgress> activationProgress; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 303 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 304 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 305 | sdbusplus::bus::match_t systemdSignals; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 306 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 307 | /** @brief Tracks whether the read-write volume has been created as |
| 308 | * part of the activation process. **/ |
| 309 | bool rwVolumeCreated = false; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 310 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 311 | /** @brief Tracks whether the read-only volume has been created as |
| 312 | * part of the activation process. **/ |
| 313 | bool roVolumeCreated = false; |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 314 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame^] | 315 | /** @brief Tracks if the service that updates the U-Boot environment |
| 316 | * variables has completed. **/ |
| 317 | bool ubootEnvVarsUpdated = false; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | } // namespace updater |
| 321 | } // namespace software |
| 322 | } // namespace phosphor |