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