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