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