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