blob: 81aa5e744148941df153bdb03638530d5a41fe2d [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{
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050018 if (value == softwareServer::Activation::Activations::Activating)
19 {
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050020 softwareServer::Activation::activation(value);
21
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050022 if (!activationBlocksTransition)
23 {
24 activationBlocksTransition =
25 std::make_unique<ActivationBlocksTransition>(
26 bus,
27 path);
28 }
Saqib Khan1e9b7162017-04-18 10:21:59 -050029
Adriana Kobylak692b5552017-04-17 14:02:58 -050030 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 Kobylak55f9e832017-05-14 16:13:00 -050042
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 Kobylak2fdb9312017-05-14 19:08:26 -050080 return softwareServer::Activation::activation(
Adriana Kobylak55f9e832017-05-14 16:13:00 -050081 softwareServer::Activation::Activations::Active);
82 }
83 else
84 {
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050085 return softwareServer::Activation::activation(
Adriana Kobylak55f9e832017-05-14 16:13:00 -050086 softwareServer::Activation::Activations::Failed);
87 }
Adriana Kobylak692b5552017-04-17 14:02:58 -050088 }
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050089 else
90 {
91 activationBlocksTransition.reset(nullptr);
92 return softwareServer::Activation::activation(value);
93 }
94}
95
96auto 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 Kobylak99c8c0e2017-04-17 13:39:11 -0500113 return softwareServer::Activation::requestedActivation(value);
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500114}
115
116} // namespace updater
117} // namespace software
118} // namespace openpower
119