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" |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 4 | |
| 5 | namespace openpower |
| 6 | { |
| 7 | namespace software |
| 8 | { |
| 9 | namespace updater |
| 10 | { |
| 11 | |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 12 | namespace fs = std::experimental::filesystem; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 13 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 14 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 15 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 16 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 17 | |
| 18 | void Activation::subscribeToSystemdSignals() |
| 19 | { |
| 20 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 21 | SYSTEMD_OBJ_PATH, |
| 22 | SYSTEMD_INTERFACE, |
| 23 | "Subscribe"); |
| 24 | this->bus.call_noreply(method); |
| 25 | |
| 26 | return; |
| 27 | } |
| 28 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 29 | auto Activation::activation(Activations value) -> |
| 30 | Activations |
| 31 | { |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 32 | |
| 33 | if (value != softwareServer::Activation::Activations::Active) |
| 34 | { |
| 35 | redundancyPriority.reset(nullptr); |
| 36 | } |
| 37 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 38 | if (value == softwareServer::Activation::Activations::Activating) |
| 39 | { |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 40 | softwareServer::Activation::activation(value); |
| 41 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 42 | if (squashfsLoaded == false && rwVolumesCreated == false) |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 43 | { |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 44 | // If 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. |
Saqib Khan | 1e9b716 | 2017-04-18 10:21:59 -0500 | [diff] [blame] | 47 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 48 | if (!activationBlocksTransition) |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 49 | { |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 50 | activationBlocksTransition = |
| 51 | std::make_unique<ActivationBlocksTransition>( |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 52 | bus, |
| 53 | path); |
| 54 | } |
| 55 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 56 | constexpr auto squashfsMountService = |
| 57 | "obmc-flash-bios-squashfsmount@"; |
| 58 | auto squashfsMountServiceFile = std::string(squashfsMountService) + |
| 59 | versionId + ".service"; |
| 60 | auto method = bus.new_method_call( |
| 61 | SYSTEMD_BUSNAME, |
| 62 | SYSTEMD_PATH, |
| 63 | SYSTEMD_INTERFACE, |
| 64 | "StartUnit"); |
| 65 | method.append(squashfsMountServiceFile, "replace"); |
| 66 | bus.call_noreply(method); |
| 67 | |
| 68 | constexpr auto ubimountService = "obmc-flash-bios-ubimount@"; |
| 69 | auto ubimountServiceFile = std::string(ubimountService) + |
| 70 | versionId + |
| 71 | ".service"; |
| 72 | method = bus.new_method_call( |
| 73 | SYSTEMD_BUSNAME, |
| 74 | SYSTEMD_PATH, |
| 75 | SYSTEMD_INTERFACE, |
| 76 | "StartUnit"); |
| 77 | method.append(ubimountServiceFile, "replace"); |
| 78 | bus.call_noreply(method); |
| 79 | |
| 80 | return softwareServer::Activation::activation(value); |
| 81 | } |
| 82 | else if (squashfsLoaded == true && rwVolumesCreated == true) |
| 83 | { |
| 84 | // Only when the squashfs image is finished loading AND the RW |
| 85 | // volumes have been created do we proceed with activation. |
| 86 | |
| 87 | // The ubimount service files attemps to create the RW and Preserved |
| 88 | // UBI volumes. If the service fails, the mount dirs PNOR_PRSV |
| 89 | // and PNOR_RW_PREFIX_<versionid> won't be present. Check for the |
| 90 | // existence of those directories to validate the service file was |
| 91 | // successful, also for the existence of the RO directory where the |
| 92 | // image is supposed to reside. |
| 93 | if ((fs::is_directory(PNOR_PRSV)) && |
| 94 | (fs::is_directory(PNOR_RW_PREFIX + versionId)) && |
| 95 | (fs::is_directory(PNOR_RO_PREFIX + versionId))) |
| 96 | { |
| 97 | if (!fs::is_directory(PNOR_ACTIVE_PATH)) |
| 98 | { |
| 99 | fs::create_directories(PNOR_ACTIVE_PATH); |
| 100 | } |
| 101 | |
| 102 | // If the RW or RO active links exist, remove them and create new |
| 103 | // ones pointing to the active version. |
| 104 | if (fs::is_symlink(PNOR_RO_ACTIVE_PATH)) |
| 105 | { |
| 106 | fs::remove(PNOR_RO_ACTIVE_PATH); |
| 107 | } |
| 108 | fs::create_directory_symlink(PNOR_RO_PREFIX + versionId, |
| 109 | PNOR_RO_ACTIVE_PATH); |
| 110 | if (fs::is_symlink(PNOR_RW_ACTIVE_PATH)) |
| 111 | { |
| 112 | fs::remove(PNOR_RW_ACTIVE_PATH); |
| 113 | } |
| 114 | fs::create_directory_symlink(PNOR_RW_PREFIX + versionId, |
| 115 | PNOR_RW_ACTIVE_PATH); |
| 116 | |
| 117 | // There is only one preserved directory as it is not tied to a |
| 118 | // version, so just create the link if it doesn't exist already. |
| 119 | if (!fs::is_symlink(PNOR_PRSV_ACTIVE_PATH)) |
| 120 | { |
| 121 | fs::create_directory_symlink(PNOR_PRSV, |
| 122 | PNOR_PRSV_ACTIVE_PATH); |
| 123 | } |
| 124 | |
| 125 | // Set Redundancy Priority before setting to Active |
| 126 | if (!redundancyPriority) |
| 127 | { |
| 128 | redundancyPriority = |
| 129 | std::make_unique<RedundancyPriority>( |
| 130 | bus, |
| 131 | path); |
| 132 | } |
| 133 | |
| 134 | return softwareServer::Activation::activation( |
| 135 | softwareServer::Activation::Activations::Active); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | return softwareServer::Activation::activation( |
| 140 | softwareServer::Activation::Activations::Failed); |
| 141 | } |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 142 | } |
| 143 | else |
| 144 | { |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 145 | // If either the squashfs image has not yet been loaded or the RW |
| 146 | // volumes have not yet been created, the activation process is |
| 147 | // ongoing, so we return "Activating" status. |
| 148 | return softwareServer::Activation::activation(value); |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 149 | } |
Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 150 | } |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 151 | else |
| 152 | { |
| 153 | activationBlocksTransition.reset(nullptr); |
| 154 | return softwareServer::Activation::activation(value); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | auto Activation::requestedActivation(RequestedActivations value) -> |
| 159 | RequestedActivations |
| 160 | { |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 161 | squashfsLoaded = false; |
| 162 | rwVolumesCreated = false; |
| 163 | |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 164 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 165 | (softwareServer::Activation::requestedActivation() != |
| 166 | softwareServer::Activation::RequestedActivations::Active)) |
| 167 | { |
| 168 | if ((softwareServer::Activation::activation() == |
| 169 | softwareServer::Activation::Activations::Ready) || |
| 170 | (softwareServer::Activation::activation() == |
| 171 | softwareServer::Activation::Activations::Failed)) |
| 172 | { |
| 173 | Activation::activation( |
| 174 | softwareServer::Activation::Activations::Activating); |
| 175 | |
| 176 | } |
| 177 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 178 | return softwareServer::Activation::requestedActivation(value); |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 179 | } |
| 180 | |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 181 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 182 | { |
| 183 | return softwareServer::RedundancyPriority::priority(value); |
| 184 | } |
| 185 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame^] | 186 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 187 | { |
| 188 | uint32_t newStateID {}; |
| 189 | sdbusplus::message::object_path newStateObjPath; |
| 190 | std::string newStateUnit{}; |
| 191 | std::string newStateResult{}; |
| 192 | |
| 193 | //Read the msg and populate each variable |
| 194 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 195 | |
| 196 | auto squashfsMountServiceFile = |
| 197 | "obmc-flash-bios-squashfsmount@" + versionId + ".service"; |
| 198 | |
| 199 | auto ubimountServiceFile = |
| 200 | "obmc-flash-bios-ubimount@" + versionId + ".service"; |
| 201 | |
| 202 | if(newStateUnit == squashfsMountServiceFile && newStateResult == "done") |
| 203 | { |
| 204 | squashfsLoaded = true; |
| 205 | } |
| 206 | |
| 207 | if(newStateUnit == ubimountServiceFile && newStateResult == "done") |
| 208 | { |
| 209 | rwVolumesCreated = true; |
| 210 | } |
| 211 | |
| 212 | if(squashfsLoaded && rwVolumesCreated) |
| 213 | { |
| 214 | Activation::activation( |
| 215 | softwareServer::Activation::Activations::Activating); |
| 216 | } |
| 217 | |
| 218 | if((newStateUnit == squashfsMountServiceFile || |
| 219 | newStateUnit == ubimountServiceFile) && |
| 220 | (newStateResult == "failed" || newStateResult == "dependency")) |
| 221 | { |
| 222 | Activation::activation(softwareServer::Activation::Activations::Failed); |
| 223 | } |
| 224 | |
| 225 | return; |
| 226 | } |
| 227 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 228 | } // namespace updater |
| 229 | } // namespace software |
| 230 | } // namespace openpower |