blob: 58819c0e35a3b46b092c03a51583462f57d24452 [file] [log] [blame]
Adriana Kobylak55f9e832017-05-14 16:13:00 -05001#include <experimental/filesystem>
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -05002#include "activation.hpp"
Adriana Kobylak692b5552017-04-17 14:02:58 -05003#include "config.h"
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -05004
5namespace openpower
6{
7namespace software
8{
9namespace updater
10{
11
Adriana Kobylak55f9e832017-05-14 16:13:00 -050012namespace fs = std::experimental::filesystem;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050013namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
14
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050015auto Activation::activation(Activations value) ->
16 Activations
17{
Saqib Khan942df8a2017-06-01 14:09:27 -050018
19 if (value != softwareServer::Activation::Activations::Active)
20 {
21 redundancyPriority.reset(nullptr);
22 }
23
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050024 if (value == softwareServer::Activation::Activations::Activating)
25 {
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050026 softwareServer::Activation::activation(value);
27
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050028 if (!activationBlocksTransition)
29 {
30 activationBlocksTransition =
31 std::make_unique<ActivationBlocksTransition>(
32 bus,
33 path);
34 }
Saqib Khan1e9b7162017-04-18 10:21:59 -050035
Adriana Kobylak692b5552017-04-17 14:02:58 -050036 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 Kobylak55f9e832017-05-14 16:13:00 -050048
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.
55 if ((fs::exists(PNOR_PRSV)) &&
56 (fs::exists(PNOR_RW_PREFIX + versionId)) &&
57 (fs::exists(PNOR_RO_PREFIX + versionId)))
58 {
59 if (!fs::exists(PNOR_ACTIVE_PATH))
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.
66 if (fs::exists(PNOR_RO_ACTIVE_PATH))
67 {
68 fs::remove(PNOR_RO_ACTIVE_PATH);
69 }
70 fs::create_directory_symlink(PNOR_RO_PREFIX + versionId,
71 PNOR_RO_ACTIVE_PATH);
72 if (fs::exists(PNOR_RW_ACTIVE_PATH))
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.
81 if (!fs::exists(PNOR_PRSV_ACTIVE_PATH))
82 {
83 fs::create_directory_symlink(PNOR_PRSV, PNOR_PRSV_ACTIVE_PATH);
84 }
85
Saqib Khan942df8a2017-06-01 14:09:27 -050086 // 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 Kobylak2fdb9312017-05-14 19:08:26 -050095 return softwareServer::Activation::activation(
Adriana Kobylak55f9e832017-05-14 16:13:00 -050096 softwareServer::Activation::Activations::Active);
97 }
98 else
99 {
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500100 return softwareServer::Activation::activation(
Adriana Kobylak55f9e832017-05-14 16:13:00 -0500101 softwareServer::Activation::Activations::Failed);
102 }
Adriana Kobylak692b5552017-04-17 14:02:58 -0500103 }
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500104 else
105 {
106 activationBlocksTransition.reset(nullptr);
107 return softwareServer::Activation::activation(value);
108 }
109}
110
111auto 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 Kobylak99c8c0e2017-04-17 13:39:11 -0500128 return softwareServer::Activation::requestedActivation(value);
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500129}
130
131} // namespace updater
132} // namespace software
133} // namespace openpower
134