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 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 15 | auto Activation::activation(Activations value) -> |
| 16 | Activations |
| 17 | { |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 18 | |
| 19 | if (value != softwareServer::Activation::Activations::Active) |
| 20 | { |
| 21 | redundancyPriority.reset(nullptr); |
| 22 | } |
| 23 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 24 | if (value == softwareServer::Activation::Activations::Activating) |
| 25 | { |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 26 | softwareServer::Activation::activation(value); |
| 27 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 28 | if (!activationBlocksTransition) |
| 29 | { |
| 30 | activationBlocksTransition = |
| 31 | std::make_unique<ActivationBlocksTransition>( |
| 32 | bus, |
| 33 | path); |
| 34 | } |
Saqib Khan | 1e9b716 | 2017-04-18 10:21:59 -0500 | [diff] [blame] | 35 | |
Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 36 | constexpr auto ubimountService = "obmc-flash-bios-ubimount@"; |
| 37 | auto ubimountServiceFile = std::string(ubimountService) + |
| 38 | versionId + |
| 39 | ".service"; |
| 40 | auto method = bus.new_method_call( |
| 41 | SYSTEMD_BUSNAME, |
| 42 | SYSTEMD_PATH, |
| 43 | SYSTEMD_INTERFACE, |
| 44 | "StartUnit"); |
| 45 | method.append(ubimountServiceFile, |
| 46 | "replace"); |
| 47 | bus.call_noreply(method); |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 48 | |
| 49 | // The ubimount service files attemps to create the RW and Preserved |
| 50 | // UBI volumes. If the service fails, the mount directories PNOR_PRSV |
| 51 | // and PNOR_RW_PREFIX_<versionid> won't be present. Check for the |
| 52 | // existence of those directories to validate the service file was |
| 53 | // successful, also for the existence of the RO directory where the |
| 54 | // image is supposed to reside. |
Adriana Kobylak | e8320ef | 2017-06-15 15:49:37 -0500 | [diff] [blame] | 55 | if ((fs::is_directory(PNOR_PRSV)) && |
| 56 | (fs::is_directory(PNOR_RW_PREFIX + versionId)) && |
| 57 | (fs::is_directory(PNOR_RO_PREFIX + versionId))) |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 58 | { |
Adriana Kobylak | e8320ef | 2017-06-15 15:49:37 -0500 | [diff] [blame] | 59 | if (!fs::is_directory(PNOR_ACTIVE_PATH)) |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 60 | { |
| 61 | fs::create_directories(PNOR_ACTIVE_PATH); |
| 62 | } |
| 63 | |
| 64 | // If the RW or RO active links exist, remove them and create new |
| 65 | // ones pointing to the active version. |
Adriana Kobylak | e8320ef | 2017-06-15 15:49:37 -0500 | [diff] [blame] | 66 | if (fs::is_symlink(PNOR_RO_ACTIVE_PATH)) |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 67 | { |
| 68 | fs::remove(PNOR_RO_ACTIVE_PATH); |
| 69 | } |
| 70 | fs::create_directory_symlink(PNOR_RO_PREFIX + versionId, |
| 71 | PNOR_RO_ACTIVE_PATH); |
Adriana Kobylak | e8320ef | 2017-06-15 15:49:37 -0500 | [diff] [blame] | 72 | if (fs::is_symlink(PNOR_RW_ACTIVE_PATH)) |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 73 | { |
| 74 | fs::remove(PNOR_RW_ACTIVE_PATH); |
| 75 | } |
| 76 | fs::create_directory_symlink(PNOR_RW_PREFIX + versionId, |
| 77 | PNOR_RW_ACTIVE_PATH); |
| 78 | |
| 79 | // There is only one preserved directory as it is not tied to a |
| 80 | // version, so just create the link if it doesn't exist already. |
Adriana Kobylak | e8320ef | 2017-06-15 15:49:37 -0500 | [diff] [blame] | 81 | if (!fs::is_symlink(PNOR_PRSV_ACTIVE_PATH)) |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 82 | { |
| 83 | fs::create_directory_symlink(PNOR_PRSV, PNOR_PRSV_ACTIVE_PATH); |
| 84 | } |
| 85 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 86 | // Set Redundancy Priority before setting to Active |
| 87 | if (!redundancyPriority) |
| 88 | { |
| 89 | redundancyPriority = |
| 90 | std::make_unique<RedundancyPriority>( |
| 91 | bus, |
| 92 | path); |
| 93 | } |
| 94 | |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 95 | return softwareServer::Activation::activation( |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 96 | softwareServer::Activation::Activations::Active); |
| 97 | } |
| 98 | else |
| 99 | { |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 100 | return softwareServer::Activation::activation( |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 101 | softwareServer::Activation::Activations::Failed); |
| 102 | } |
Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 103 | } |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 104 | else |
| 105 | { |
| 106 | activationBlocksTransition.reset(nullptr); |
| 107 | return softwareServer::Activation::activation(value); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | auto Activation::requestedActivation(RequestedActivations value) -> |
| 112 | RequestedActivations |
| 113 | { |
| 114 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 115 | (softwareServer::Activation::requestedActivation() != |
| 116 | softwareServer::Activation::RequestedActivations::Active)) |
| 117 | { |
| 118 | if ((softwareServer::Activation::activation() == |
| 119 | softwareServer::Activation::Activations::Ready) || |
| 120 | (softwareServer::Activation::activation() == |
| 121 | softwareServer::Activation::Activations::Failed)) |
| 122 | { |
| 123 | Activation::activation( |
| 124 | softwareServer::Activation::Activations::Activating); |
| 125 | |
| 126 | } |
| 127 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 128 | return softwareServer::Activation::requestedActivation(value); |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 129 | } |
| 130 | |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 131 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 132 | { |
| 133 | return softwareServer::RedundancyPriority::priority(value); |
| 134 | } |
| 135 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 136 | } // namespace updater |
| 137 | } // namespace software |
| 138 | } // namespace openpower |
| 139 | |