| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 1 | #include "activation.hpp" | 
| Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 2 | #include "item_updater.hpp" | 
| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 3 |  | 
|  | 4 | namespace phosphor | 
|  | 5 | { | 
|  | 6 | namespace software | 
|  | 7 | { | 
|  | 8 | namespace updater | 
|  | 9 | { | 
|  | 10 |  | 
|  | 11 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; | 
|  | 12 |  | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 13 | constexpr auto SYSTEMD_SERVICE   = "org.freedesktop.systemd1"; | 
|  | 14 | constexpr auto SYSTEMD_PATH      = "/org/freedesktop/systemd1"; | 
|  | 15 | constexpr auto SIGNAL_INTERFACE  = "/org/freedesktop/systemd1"; | 
|  | 16 | constexpr auto MANAGER_INTERFACE = "org.freedesktop.systemd1.Manager"; | 
|  | 17 |  | 
|  | 18 | void Activation::subscribeToSystemdSignals() | 
|  | 19 | { | 
|  | 20 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, | 
|  | 21 | SYSTEMD_PATH, | 
|  | 22 | SIGNAL_INTERFACE, | 
|  | 23 | "Subscribe"); | 
|  | 24 | this->bus.call_noreply(method); | 
|  | 25 |  | 
|  | 26 | return; | 
|  | 27 | } | 
|  | 28 |  | 
| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 29 | auto Activation::activation(Activations value) -> | 
|  | 30 | Activations | 
|  | 31 | { | 
| Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 32 |  | 
|  | 33 | if (value != softwareServer::Activation::Activations::Active) | 
|  | 34 | { | 
|  | 35 | redundancyPriority.reset(nullptr); | 
|  | 36 | } | 
|  | 37 |  | 
| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 38 | if (value == softwareServer::Activation::Activations::Activating) | 
|  | 39 | { | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 40 | if (rwVolumeCreated == false && roVolumeCreated == false) | 
| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 41 | { | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 42 | if (!activationBlocksTransition) | 
|  | 43 | { | 
|  | 44 | activationBlocksTransition = | 
|  | 45 | std::make_unique<ActivationBlocksTransition>( | 
|  | 46 | bus, | 
|  | 47 | path); | 
|  | 48 | } | 
| Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 49 |  | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 50 | auto method = bus.new_method_call( | 
|  | 51 | SYSTEMD_SERVICE, | 
|  | 52 | SYSTEMD_PATH, | 
|  | 53 | MANAGER_INTERFACE, | 
|  | 54 | "StartUnit"); | 
|  | 55 | method.append("obmc-flash-bmc-ubirw.service", "replace"); | 
|  | 56 | bus.call_noreply(method); | 
|  | 57 |  | 
|  | 58 | auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + | 
|  | 59 | ".service"; | 
|  | 60 | method = bus.new_method_call( | 
|  | 61 | SYSTEMD_SERVICE, | 
|  | 62 | SYSTEMD_PATH, | 
|  | 63 | MANAGER_INTERFACE, | 
|  | 64 | "StartUnit"); | 
|  | 65 | method.append(roServiceFile, "replace"); | 
|  | 66 | bus.call_noreply(method); | 
|  | 67 | } | 
|  | 68 | else if (rwVolumeCreated == true && roVolumeCreated == true) | 
| Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 69 | { | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 70 | if (!redundancyPriority) | 
|  | 71 | { | 
|  | 72 | redundancyPriority = | 
|  | 73 | std::make_unique<RedundancyPriority>( | 
|  | 74 | bus, | 
|  | 75 | path, | 
|  | 76 | *this, | 
|  | 77 | 0); | 
|  | 78 | } | 
| Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 79 |  | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 80 | activationBlocksTransition.reset(nullptr); | 
|  | 81 | return softwareServer::Activation::activation( | 
|  | 82 | softwareServer::Activation::Activations::Active); | 
|  | 83 | } | 
| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 84 | } | 
|  | 85 | else | 
|  | 86 | { | 
|  | 87 | activationBlocksTransition.reset(nullptr); | 
|  | 88 | } | 
|  | 89 | return softwareServer::Activation::activation(value); | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | auto Activation::requestedActivation(RequestedActivations value) -> | 
|  | 93 | RequestedActivations | 
|  | 94 | { | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 95 | rwVolumeCreated = false; | 
|  | 96 | roVolumeCreated = false; | 
|  | 97 |  | 
| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 98 | if ((value == softwareServer::Activation::RequestedActivations::Active) && | 
|  | 99 | (softwareServer::Activation::requestedActivation() != | 
|  | 100 | softwareServer::Activation::RequestedActivations::Active)) | 
|  | 101 | { | 
|  | 102 | if ((softwareServer::Activation::activation() == | 
|  | 103 | softwareServer::Activation::Activations::Ready) || | 
|  | 104 | (softwareServer::Activation::activation() == | 
|  | 105 | softwareServer::Activation::Activations::Failed)) | 
|  | 106 | { | 
|  | 107 | Activation::activation( | 
|  | 108 | softwareServer::Activation::Activations::Activating); | 
|  | 109 |  | 
|  | 110 | } | 
|  | 111 | } | 
|  | 112 | return softwareServer::Activation::requestedActivation(value); | 
|  | 113 | } | 
|  | 114 |  | 
| Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 115 | uint8_t RedundancyPriority::priority(uint8_t value) | 
|  | 116 | { | 
|  | 117 | parent.parent.freePriority(value); | 
|  | 118 | return softwareServer::RedundancyPriority::priority(value); | 
|  | 119 | } | 
|  | 120 |  | 
| Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 121 | void Activation::unitStateChange(sdbusplus::message::message& msg) | 
|  | 122 | { | 
|  | 123 | uint32_t newStateID {}; | 
|  | 124 | sdbusplus::message::object_path newStateObjPath; | 
|  | 125 | std::string newStateUnit{}; | 
|  | 126 | std::string newStateResult{}; | 
|  | 127 |  | 
|  | 128 | //Read the msg and populate each variable | 
|  | 129 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); | 
|  | 130 |  | 
|  | 131 | auto rwServiceFile = "obmc-flash-bmc-ubirw.service"; | 
|  | 132 | auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service"; | 
|  | 133 |  | 
|  | 134 | if(newStateUnit == rwServiceFile && newStateResult == "done") | 
|  | 135 | { | 
|  | 136 | rwVolumeCreated = true; | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | if(newStateUnit == roServiceFile && newStateResult == "done") | 
|  | 140 | { | 
|  | 141 | roVolumeCreated = true; | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | if(rwVolumeCreated && roVolumeCreated) | 
|  | 145 | { | 
|  | 146 | Activation::activation( | 
|  | 147 | softwareServer::Activation::Activations::Activating); | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | if((newStateUnit == rwServiceFile || newStateUnit == roServiceFile) && | 
|  | 151 | (newStateResult == "failed" || newStateResult == "dependency")) | 
|  | 152 | { | 
|  | 153 | Activation::activation(softwareServer::Activation::Activations::Failed); | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | return; | 
|  | 157 | } | 
|  | 158 |  | 
|  | 159 |  | 
| Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 160 | } // namespace updater | 
|  | 161 | } // namespace software | 
|  | 162 | } // namespace phosphor |