Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 1 | #include <experimental/filesystem> |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 2 | #include "activation.hpp" |
Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 3 | #include "config.h" |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 4 | #include "item_updater.hpp" |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 5 | #include "serialize.hpp" |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace software |
| 10 | { |
| 11 | namespace updater |
| 12 | { |
| 13 | |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 14 | namespace fs = std::experimental::filesystem; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 15 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 16 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 17 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 18 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 19 | |
| 20 | void Activation::subscribeToSystemdSignals() |
| 21 | { |
| 22 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 23 | SYSTEMD_OBJ_PATH, |
| 24 | SYSTEMD_INTERFACE, |
| 25 | "Subscribe"); |
| 26 | this->bus.call_noreply(method); |
| 27 | |
| 28 | return; |
| 29 | } |
| 30 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 31 | void Activation::unsubscribeFromSystemdSignals() |
| 32 | { |
| 33 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 34 | SYSTEMD_OBJ_PATH, |
| 35 | SYSTEMD_INTERFACE, |
| 36 | "Unsubscribe"); |
| 37 | this->bus.call_noreply(method); |
| 38 | |
| 39 | return; |
| 40 | } |
| 41 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 42 | void Activation::startActivation() |
| 43 | { |
| 44 | // Since the squashfs image has not yet been loaded to pnor and the |
| 45 | // RW volumes have not yet been created, we need to start the |
| 46 | // service files for each of those actions. |
| 47 | |
| 48 | if (!activationProgress) |
| 49 | { |
| 50 | activationProgress = std::make_unique<ActivationProgress>( |
| 51 | bus, path); |
| 52 | } |
| 53 | |
| 54 | if (!activationBlocksTransition) |
| 55 | { |
| 56 | activationBlocksTransition = |
| 57 | std::make_unique<ActivationBlocksTransition>(bus, path); |
| 58 | } |
| 59 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 60 | constexpr auto ubimountService = "obmc-flash-bios-ubimount@"; |
| 61 | auto ubimountServiceFile = std::string(ubimountService) + |
| 62 | versionId + ".service"; |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 63 | auto method = bus.new_method_call( |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 64 | SYSTEMD_BUSNAME, |
| 65 | SYSTEMD_PATH, |
| 66 | SYSTEMD_INTERFACE, |
| 67 | "StartUnit"); |
| 68 | method.append(ubimountServiceFile, "replace"); |
| 69 | bus.call_noreply(method); |
| 70 | |
| 71 | activationProgress->progress(10); |
| 72 | } |
| 73 | |
| 74 | void Activation::finishActivation() |
| 75 | { |
| 76 | activationProgress->progress(90); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 77 | |
| 78 | // Set Redundancy Priority before setting to Active |
| 79 | if (!redundancyPriority) |
| 80 | { |
| 81 | redundancyPriority = std::make_unique<RedundancyPriority>( |
| 82 | bus, path, *this, 0); |
| 83 | } |
| 84 | |
| 85 | activationProgress->progress(100); |
| 86 | |
| 87 | activationBlocksTransition.reset(nullptr); |
| 88 | activationProgress.reset(nullptr); |
| 89 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 90 | ubiVolumesCreated = false; |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 91 | Activation::unsubscribeFromSystemdSignals(); |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 92 | // Create active association |
| 93 | parent.createActiveAssociation(path); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 96 | auto Activation::activation(Activations value) -> |
| 97 | Activations |
| 98 | { |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 99 | |
| 100 | if (value != softwareServer::Activation::Activations::Active) |
| 101 | { |
| 102 | redundancyPriority.reset(nullptr); |
| 103 | } |
| 104 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 105 | if (value == softwareServer::Activation::Activations::Activating) |
| 106 | { |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 107 | parent.freeSpace(); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 108 | softwareServer::Activation::activation(value); |
| 109 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 110 | if (ubiVolumesCreated == false) |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 111 | { |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 112 | Activation::startActivation(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 113 | return softwareServer::Activation::activation(value); |
| 114 | } |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 115 | else if (ubiVolumesCreated == true) |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 116 | { |
| 117 | // Only when the squashfs image is finished loading AND the RW |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 118 | // volumes have been created do we proceed with activation. To |
| 119 | // verify that this happened, we check for the mount dirs PNOR_PRSV |
| 120 | // and PNOR_RW_PREFIX_<versionid>, as well as the image dir R0. |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 121 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 122 | if ((fs::is_directory(PNOR_PRSV)) && |
| 123 | (fs::is_directory(PNOR_RW_PREFIX + versionId)) && |
| 124 | (fs::is_directory(PNOR_RO_PREFIX + versionId))) |
| 125 | { |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 126 | Activation::finishActivation(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 127 | return softwareServer::Activation::activation( |
| 128 | softwareServer::Activation::Activations::Active); |
| 129 | } |
| 130 | else |
| 131 | { |
Saqib Khan | cb9df4e | 2017-06-26 11:06:07 -0500 | [diff] [blame] | 132 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 133 | activationProgress.reset(nullptr); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 134 | return softwareServer::Activation::activation( |
| 135 | softwareServer::Activation::Activations::Failed); |
| 136 | } |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 137 | } |
Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 138 | } |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 139 | else |
| 140 | { |
| 141 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 142 | activationProgress.reset(nullptr); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 143 | } |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 144 | |
| 145 | return softwareServer::Activation::activation(value); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | auto Activation::requestedActivation(RequestedActivations value) -> |
| 149 | RequestedActivations |
| 150 | { |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 151 | ubiVolumesCreated = false; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 152 | |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 153 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 154 | (softwareServer::Activation::requestedActivation() != |
| 155 | softwareServer::Activation::RequestedActivations::Active)) |
| 156 | { |
| 157 | if ((softwareServer::Activation::activation() == |
| 158 | softwareServer::Activation::Activations::Ready) || |
| 159 | (softwareServer::Activation::activation() == |
| 160 | softwareServer::Activation::Activations::Failed)) |
| 161 | { |
| 162 | Activation::activation( |
| 163 | softwareServer::Activation::Activations::Activating); |
| 164 | |
| 165 | } |
| 166 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 167 | return softwareServer::Activation::requestedActivation(value); |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 170 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 171 | { |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 172 | parent.parent.freePriority(value, parent.versionId); |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 173 | storeToFile(parent.versionId, value); |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 174 | return softwareServer::RedundancyPriority::priority(value); |
| 175 | } |
| 176 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 177 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 178 | { |
| 179 | uint32_t newStateID {}; |
| 180 | sdbusplus::message::object_path newStateObjPath; |
| 181 | std::string newStateUnit{}; |
| 182 | std::string newStateResult{}; |
| 183 | |
| 184 | //Read the msg and populate each variable |
| 185 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 186 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 187 | auto ubimountServiceFile = |
| 188 | "obmc-flash-bios-ubimount@" + versionId + ".service"; |
| 189 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 190 | if(newStateUnit == ubimountServiceFile && newStateResult == "done") |
| 191 | { |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 192 | ubiVolumesCreated = true; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 193 | activationProgress->progress(activationProgress->progress() + 50); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 194 | } |
| 195 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 196 | if(ubiVolumesCreated) |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 197 | { |
| 198 | Activation::activation( |
| 199 | softwareServer::Activation::Activations::Activating); |
| 200 | } |
| 201 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame^] | 202 | if((newStateUnit == ubimountServiceFile) && |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 203 | (newStateResult == "failed" || newStateResult == "dependency")) |
| 204 | { |
| 205 | Activation::activation(softwareServer::Activation::Activations::Failed); |
| 206 | } |
| 207 | |
| 208 | return; |
| 209 | } |
| 210 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 211 | void Activation::delete_() |
| 212 | { |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 213 | // Remove active association |
| 214 | parent.removeActiveAssociation(path); |
| 215 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 216 | parent.erase(versionId); |
| 217 | } |
| 218 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 219 | } // namespace updater |
| 220 | } // namespace software |
| 221 | } // namespace openpower |