blob: 3f16b7b15810634677aabbb59f55762cd48867b6 [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"
Saqib Khan81bac882017-06-08 12:17:01 -05004#include "item_updater.hpp"
Michael Tritz60bc20f2017-07-29 23:32:21 -05005#include "serialize.hpp"
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -05006
7namespace openpower
8{
9namespace software
10{
11namespace updater
12{
13
Adriana Kobylak55f9e832017-05-14 16:13:00 -050014namespace fs = std::experimental::filesystem;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050015namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
16
Michael Tritz9d25b602017-06-14 14:41:43 -050017constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
18constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
19
20void Activation::subscribeToSystemdSignals()
21{
22 auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
23 SYSTEMD_OBJ_PATH,
24 SYSTEMD_INTERFACE,
25 "Subscribe");
26 this->bus.call_noreply(method);
27
28 return;
29}
30
Michael Tritz1cb127f2017-07-26 15:40:38 -050031void Activation::unsubscribeFromSystemdSignals()
32{
33 auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
34 SYSTEMD_OBJ_PATH,
35 SYSTEMD_INTERFACE,
36 "Unsubscribe");
37 this->bus.call_noreply(method);
38
39 return;
40}
41
Michael Tritz1cb127f2017-07-26 15:40:38 -050042void Activation::startActivation()
43{
44 // Since 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.
47
48 if (!activationProgress)
49 {
50 activationProgress = std::make_unique<ActivationProgress>(
51 bus, path);
52 }
53
54 if (!activationBlocksTransition)
55 {
56 activationBlocksTransition =
57 std::make_unique<ActivationBlocksTransition>(bus, path);
58 }
59
60 constexpr auto squashfsMountService =
61 "obmc-flash-bios-squashfsmount@";
62 auto squashfsMountServiceFile = std::string(squashfsMountService) +
63 versionId + ".service";
64 auto method = bus.new_method_call(
65 SYSTEMD_BUSNAME,
66 SYSTEMD_PATH,
67 SYSTEMD_INTERFACE,
68 "StartUnit");
69 method.append(squashfsMountServiceFile, "replace");
70 bus.call_noreply(method);
71
72 constexpr auto ubimountService = "obmc-flash-bios-ubimount@";
73 auto ubimountServiceFile = std::string(ubimountService) +
74 versionId + ".service";
75 method = bus.new_method_call(
76 SYSTEMD_BUSNAME,
77 SYSTEMD_PATH,
78 SYSTEMD_INTERFACE,
79 "StartUnit");
80 method.append(ubimountServiceFile, "replace");
81 bus.call_noreply(method);
82
83 activationProgress->progress(10);
84}
85
86void Activation::finishActivation()
87{
88 activationProgress->progress(90);
Michael Tritz1cb127f2017-07-26 15:40:38 -050089
90 // Set Redundancy Priority before setting to Active
91 if (!redundancyPriority)
92 {
93 redundancyPriority = std::make_unique<RedundancyPriority>(
94 bus, path, *this, 0);
95 }
96
97 activationProgress->progress(100);
98
99 activationBlocksTransition.reset(nullptr);
100 activationProgress.reset(nullptr);
101
102 squashfsLoaded = false;
103 rwVolumesCreated = false;
104 Activation::unsubscribeFromSystemdSignals();
105}
106
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500107auto Activation::activation(Activations value) ->
108 Activations
109{
Saqib Khan942df8a2017-06-01 14:09:27 -0500110
111 if (value != softwareServer::Activation::Activations::Active)
112 {
113 redundancyPriority.reset(nullptr);
114 }
115
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500116 if (value == softwareServer::Activation::Activations::Activating)
117 {
Saqib Khan2cbfa032017-08-17 14:52:37 -0500118 parent.freeSpace();
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500119 softwareServer::Activation::activation(value);
120
Michael Tritz9d25b602017-06-14 14:41:43 -0500121 if (squashfsLoaded == false && rwVolumesCreated == false)
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500122 {
Michael Tritz1cb127f2017-07-26 15:40:38 -0500123 Activation::startActivation();
Michael Tritz9d25b602017-06-14 14:41:43 -0500124 return softwareServer::Activation::activation(value);
125 }
126 else if (squashfsLoaded == true && rwVolumesCreated == true)
127 {
128 // Only when the squashfs image is finished loading AND the RW
Michael Tritz1cb127f2017-07-26 15:40:38 -0500129 // volumes have been created do we proceed with activation. To
130 // verify that this happened, we check for the mount dirs PNOR_PRSV
131 // and PNOR_RW_PREFIX_<versionid>, as well as the image dir R0.
Michael Tritz9d25b602017-06-14 14:41:43 -0500132
Michael Tritz9d25b602017-06-14 14:41:43 -0500133 if ((fs::is_directory(PNOR_PRSV)) &&
134 (fs::is_directory(PNOR_RW_PREFIX + versionId)) &&
135 (fs::is_directory(PNOR_RO_PREFIX + versionId)))
136 {
Michael Tritz1cb127f2017-07-26 15:40:38 -0500137 Activation::finishActivation();
Michael Tritz9d25b602017-06-14 14:41:43 -0500138 return softwareServer::Activation::activation(
139 softwareServer::Activation::Activations::Active);
140 }
141 else
142 {
Saqib Khancb9df4e2017-06-26 11:06:07 -0500143 activationBlocksTransition.reset(nullptr);
Michael Tritz1793b642017-06-28 18:35:58 -0500144 activationProgress.reset(nullptr);
Michael Tritz9d25b602017-06-14 14:41:43 -0500145 return softwareServer::Activation::activation(
146 softwareServer::Activation::Activations::Failed);
147 }
Adriana Kobylak55f9e832017-05-14 16:13:00 -0500148 }
Adriana Kobylak692b5552017-04-17 14:02:58 -0500149 }
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500150 else
151 {
152 activationBlocksTransition.reset(nullptr);
Michael Tritz1793b642017-06-28 18:35:58 -0500153 activationProgress.reset(nullptr);
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500154 }
Michael Tritz1cb127f2017-07-26 15:40:38 -0500155
156 return softwareServer::Activation::activation(value);
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500157}
158
159auto Activation::requestedActivation(RequestedActivations value) ->
160 RequestedActivations
161{
Michael Tritz9d25b602017-06-14 14:41:43 -0500162 squashfsLoaded = false;
163 rwVolumesCreated = false;
164
Adriana Kobylak2fdb9312017-05-14 19:08:26 -0500165 if ((value == softwareServer::Activation::RequestedActivations::Active) &&
166 (softwareServer::Activation::requestedActivation() !=
167 softwareServer::Activation::RequestedActivations::Active))
168 {
169 if ((softwareServer::Activation::activation() ==
170 softwareServer::Activation::Activations::Ready) ||
171 (softwareServer::Activation::activation() ==
172 softwareServer::Activation::Activations::Failed))
173 {
174 Activation::activation(
175 softwareServer::Activation::Activations::Activating);
176
177 }
178 }
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500179 return softwareServer::Activation::requestedActivation(value);
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500180}
181
Saqib Khan2021b4c2017-06-07 14:37:36 -0500182uint8_t RedundancyPriority::priority(uint8_t value)
183{
Saqib Khanb8e7f312017-08-12 10:24:10 -0500184 parent.parent.freePriority(value, parent.versionId);
Michael Tritz60bc20f2017-07-29 23:32:21 -0500185 storeToFile(parent.versionId, value);
Saqib Khan2021b4c2017-06-07 14:37:36 -0500186 return softwareServer::RedundancyPriority::priority(value);
187}
188
Michael Tritz9d25b602017-06-14 14:41:43 -0500189void Activation::unitStateChange(sdbusplus::message::message& msg)
190{
191 uint32_t newStateID {};
192 sdbusplus::message::object_path newStateObjPath;
193 std::string newStateUnit{};
194 std::string newStateResult{};
195
196 //Read the msg and populate each variable
197 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
198
199 auto squashfsMountServiceFile =
200 "obmc-flash-bios-squashfsmount@" + versionId + ".service";
201
202 auto ubimountServiceFile =
203 "obmc-flash-bios-ubimount@" + versionId + ".service";
204
205 if(newStateUnit == squashfsMountServiceFile && newStateResult == "done")
206 {
Michael Tritz1793b642017-06-28 18:35:58 -0500207 squashfsLoaded = true;
208 activationProgress->progress(activationProgress->progress() + 20);
Michael Tritz9d25b602017-06-14 14:41:43 -0500209 }
210
211 if(newStateUnit == ubimountServiceFile && newStateResult == "done")
212 {
213 rwVolumesCreated = true;
Michael Tritz1793b642017-06-28 18:35:58 -0500214 activationProgress->progress(activationProgress->progress() + 50);
Michael Tritz9d25b602017-06-14 14:41:43 -0500215 }
216
217 if(squashfsLoaded && rwVolumesCreated)
218 {
219 Activation::activation(
220 softwareServer::Activation::Activations::Activating);
221 }
222
223 if((newStateUnit == squashfsMountServiceFile ||
224 newStateUnit == ubimountServiceFile) &&
225 (newStateResult == "failed" || newStateResult == "dependency"))
226 {
227 Activation::activation(softwareServer::Activation::Activations::Failed);
228 }
229
230 return;
231}
232
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500233void Activation::delete_()
234{
235 parent.erase(versionId);
236}
237
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500238} // namespace updater
239} // namespace software
240} // namespace openpower