blob: fb7d764becd715cc1a4120777ecf1c91ff2c2158 [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
Michael Tritz9d25b602017-06-14 14:41:43 -050015constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
16constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
17
18void 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 Kobylakbefe5ce2017-04-05 15:57:44 -050029auto Activation::activation(Activations value) ->
30 Activations
31{
Saqib Khan942df8a2017-06-01 14:09:27 -050032
33 if (value != softwareServer::Activation::Activations::Active)
34 {
35 redundancyPriority.reset(nullptr);
36 }
37
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050038 if (value == softwareServer::Activation::Activations::Activating)
39 {
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050040 softwareServer::Activation::activation(value);
41
Michael Tritz9d25b602017-06-14 14:41:43 -050042 if (squashfsLoaded == false && rwVolumesCreated == false)
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050043 {
Michael Tritz9d25b602017-06-14 14:41:43 -050044 // 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 Khan1e9b7162017-04-18 10:21:59 -050047
Michael Tritz9d25b602017-06-14 14:41:43 -050048 if (!activationBlocksTransition)
Adriana Kobylak55f9e832017-05-14 16:13:00 -050049 {
Michael Tritz9d25b602017-06-14 14:41:43 -050050 activationBlocksTransition =
51 std::make_unique<ActivationBlocksTransition>(
Saqib Khan942df8a2017-06-01 14:09:27 -050052 bus,
53 path);
54 }
55
Michael Tritz9d25b602017-06-14 14:41:43 -050056 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 Kobylak55f9e832017-05-14 16:13:00 -0500142 }
143 else
144 {
Michael Tritz9d25b602017-06-14 14:41:43 -0500145 // 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 Kobylak55f9e832017-05-14 16:13:00 -0500149 }
Adriana Kobylak692b5552017-04-17 14:02:58 -0500150 }
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500151 else
152 {
153 activationBlocksTransition.reset(nullptr);
154 return softwareServer::Activation::activation(value);
155 }
156}
157
158auto Activation::requestedActivation(RequestedActivations value) ->
159 RequestedActivations
160{
Michael Tritz9d25b602017-06-14 14:41:43 -0500161 squashfsLoaded = false;
162 rwVolumesCreated = false;
163
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500164 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 Kobylak99c8c0e2017-04-17 13:39:11 -0500178 return softwareServer::Activation::requestedActivation(value);
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500179}
180
Saqib Khan2021b4c2017-06-07 14:37:36 -0500181uint8_t RedundancyPriority::priority(uint8_t value)
182{
183 return softwareServer::RedundancyPriority::priority(value);
184}
185
Michael Tritz9d25b602017-06-14 14:41:43 -0500186void 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 Kobylakbefe5ce2017-04-05 15:57:44 -0500228} // namespace updater
229} // namespace software
230} // namespace openpower