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