blob: d7f9e24ca748ac6933cc907f91dc5060362bf2e7 [file] [log] [blame]
Saqib Khanb0774702017-05-23 16:02:41 -05001#include "activation.hpp"
Saqib Khan4c1aec02017-07-06 11:46:13 -05002#include "item_updater.hpp"
Michael Tritzf2b5e0d2017-07-25 14:39:34 -05003#include "config.h"
Saqib Khan5d532672017-08-09 10:44:50 -05004#include "serialize.hpp"
Saqib Khanb9da6632017-09-13 09:48:37 -05005#include <phosphor-logging/log.hpp>
6
Saqib Khanb0774702017-05-23 16:02:41 -05007
8namespace phosphor
9{
10namespace software
11{
12namespace updater
13{
14
15namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
16
Saqib Khanb9da6632017-09-13 09:48:37 -050017using namespace phosphor::logging;
18
Michael Tritzbed88af2017-07-19 16:00:06 -050019void Activation::subscribeToSystemdSignals()
20{
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050021 auto method = this->bus.new_method_call(SYSTEMD_BUSNAME,
Michael Tritzbed88af2017-07-19 16:00:06 -050022 SYSTEMD_PATH,
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050023 SYSTEMD_INTERFACE,
Michael Tritzbed88af2017-07-19 16:00:06 -050024 "Subscribe");
25 this->bus.call_noreply(method);
26
27 return;
28}
29
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050030void Activation::unsubscribeFromSystemdSignals()
31{
32 auto method = this->bus.new_method_call(SYSTEMD_BUSNAME,
33 SYSTEMD_PATH,
34 SYSTEMD_INTERFACE,
35 "Unsubscribe");
36 this->bus.call_noreply(method);
37
38 return;
39}
40
Eddie James9440f492017-08-30 11:34:16 -050041void Activation::delete_()
42{
43 parent.erase(versionId);
44}
45
Saqib Khanb0774702017-05-23 16:02:41 -050046auto Activation::activation(Activations value) ->
47 Activations
48{
Saqib Khan4c1aec02017-07-06 11:46:13 -050049
50 if (value != softwareServer::Activation::Activations::Active)
51 {
52 redundancyPriority.reset(nullptr);
53 }
54
Saqib Khanb0774702017-05-23 16:02:41 -050055 if (value == softwareServer::Activation::Activations::Activating)
56 {
Michael Tritzbed88af2017-07-19 16:00:06 -050057 if (rwVolumeCreated == false && roVolumeCreated == false)
Saqib Khanb0774702017-05-23 16:02:41 -050058 {
Michael Tritz0edd4ad2017-07-26 14:27:42 -050059 if (!activationProgress)
60 {
61 activationProgress = std::make_unique<ActivationProgress>(bus,
62 path);
63 }
64
Michael Tritzbed88af2017-07-19 16:00:06 -050065 if (!activationBlocksTransition)
66 {
67 activationBlocksTransition =
68 std::make_unique<ActivationBlocksTransition>(
69 bus,
70 path);
71 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050072
Michael Tritzbed88af2017-07-19 16:00:06 -050073 auto method = bus.new_method_call(
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050074 SYSTEMD_BUSNAME,
Michael Tritzbed88af2017-07-19 16:00:06 -050075 SYSTEMD_PATH,
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050076 SYSTEMD_INTERFACE,
Michael Tritzbed88af2017-07-19 16:00:06 -050077 "StartUnit");
78 method.append("obmc-flash-bmc-ubirw.service", "replace");
79 bus.call_noreply(method);
80
81 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId +
82 ".service";
83 method = bus.new_method_call(
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050084 SYSTEMD_BUSNAME,
Michael Tritzbed88af2017-07-19 16:00:06 -050085 SYSTEMD_PATH,
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050086 SYSTEMD_INTERFACE,
Michael Tritzbed88af2017-07-19 16:00:06 -050087 "StartUnit");
88 method.append(roServiceFile, "replace");
89 bus.call_noreply(method);
Michael Tritz0edd4ad2017-07-26 14:27:42 -050090
91 activationProgress->progress(10);
Michael Tritzbed88af2017-07-19 16:00:06 -050092 }
93 else if (rwVolumeCreated == true && roVolumeCreated == true)
Saqib Khan4c1aec02017-07-06 11:46:13 -050094 {
Michael Tritz0edd4ad2017-07-26 14:27:42 -050095 activationProgress->progress(90);
96
Michael Tritzbed88af2017-07-19 16:00:06 -050097 if (!redundancyPriority)
98 {
99 redundancyPriority =
100 std::make_unique<RedundancyPriority>(
101 bus,
102 path,
103 *this,
104 0);
105 }
Saqib Khan4c1aec02017-07-06 11:46:13 -0500106
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500107 activationProgress->progress(100);
108
Michael Tritzbed88af2017-07-19 16:00:06 -0500109 activationBlocksTransition.reset(nullptr);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500110 activationProgress.reset(nullptr);
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500111
112 rwVolumeCreated = false;
113 roVolumeCreated = false;
114 Activation::unsubscribeFromSystemdSignals();
115
Gunnar Millsded875d2017-08-28 16:44:52 -0500116 // Create active association
117 parent.createActiveAssociation(path);
118
Michael Tritzbed88af2017-07-19 16:00:06 -0500119 return softwareServer::Activation::activation(
120 softwareServer::Activation::Activations::Active);
121 }
Saqib Khanb0774702017-05-23 16:02:41 -0500122 }
123 else
124 {
125 activationBlocksTransition.reset(nullptr);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500126 activationProgress.reset(nullptr);
Saqib Khanb0774702017-05-23 16:02:41 -0500127 }
128 return softwareServer::Activation::activation(value);
129}
130
131auto Activation::requestedActivation(RequestedActivations value) ->
132 RequestedActivations
133{
Michael Tritzbed88af2017-07-19 16:00:06 -0500134 rwVolumeCreated = false;
135 roVolumeCreated = false;
136
Saqib Khanb0774702017-05-23 16:02:41 -0500137 if ((value == softwareServer::Activation::RequestedActivations::Active) &&
138 (softwareServer::Activation::requestedActivation() !=
139 softwareServer::Activation::RequestedActivations::Active))
140 {
141 if ((softwareServer::Activation::activation() ==
142 softwareServer::Activation::Activations::Ready) ||
143 (softwareServer::Activation::activation() ==
144 softwareServer::Activation::Activations::Failed))
145 {
146 Activation::activation(
147 softwareServer::Activation::Activations::Activating);
148
149 }
150 }
151 return softwareServer::Activation::requestedActivation(value);
152}
153
Saqib Khan4c1aec02017-07-06 11:46:13 -0500154uint8_t RedundancyPriority::priority(uint8_t value)
155{
Saqib Khanb9da6632017-09-13 09:48:37 -0500156 parent.parent.freePriority(value, parent.versionId);
Saqib Khan5d532672017-08-09 10:44:50 -0500157 storeToFile(parent.versionId, value);
Saqib Khanb9da6632017-09-13 09:48:37 -0500158
159 if(parent.parent.isLowestPriority(value))
160 {
161 parent.updateUbootEnvVars();
162 }
163
Saqib Khan4c1aec02017-07-06 11:46:13 -0500164 return softwareServer::RedundancyPriority::priority(value);
165}
166
Saqib Khanb9da6632017-09-13 09:48:37 -0500167// TODO: openbmc/openbmc#2369 Add recovery policy to updateubootvars
168// unit template.
169// TODO: openbmc/openbmc#2370 Call StartUnit synchronously to handle
170// Errors more gracefully.
171void Activation::updateUbootEnvVars()
172{
173 auto method = bus.new_method_call(
174 SYSTEMD_BUSNAME,
175 SYSTEMD_PATH,
176 SYSTEMD_INTERFACE,
177 "StartUnit");
178 auto updateEnvVarsFile = "obmc-flash-bmc-updateubootvars@" + versionId +
179 ".service";
180 method.append(updateEnvVarsFile, "replace");
181 auto result = bus.call(method);
182
183 //Check that the bus call didn't result in an error
184 if (result.is_method_error())
185 {
186 log<level::ERR>("Failed to update u-boot env variables",
187 entry(" %s", SYSTEMD_INTERFACE));
188 }
189}
190
Michael Tritzbed88af2017-07-19 16:00:06 -0500191void Activation::unitStateChange(sdbusplus::message::message& msg)
192{
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500193 if (softwareServer::Activation::activation() !=
194 softwareServer::Activation::Activations::Activating)
195 {
196 return;
197 }
198
Michael Tritzbed88af2017-07-19 16:00:06 -0500199 uint32_t newStateID {};
200 sdbusplus::message::object_path newStateObjPath;
201 std::string newStateUnit{};
202 std::string newStateResult{};
203
204 //Read the msg and populate each variable
205 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
206
207 auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
208 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
209
210 if(newStateUnit == rwServiceFile && newStateResult == "done")
211 {
212 rwVolumeCreated = true;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500213 activationProgress->progress(activationProgress->progress() + 20);
Michael Tritzbed88af2017-07-19 16:00:06 -0500214 }
215
216 if(newStateUnit == roServiceFile && newStateResult == "done")
217 {
218 roVolumeCreated = true;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500219 activationProgress->progress(activationProgress->progress() + 50);
Michael Tritzbed88af2017-07-19 16:00:06 -0500220 }
221
222 if(rwVolumeCreated && roVolumeCreated)
223 {
224 Activation::activation(
225 softwareServer::Activation::Activations::Activating);
226 }
227
228 if((newStateUnit == rwServiceFile || newStateUnit == roServiceFile) &&
229 (newStateResult == "failed" || newStateResult == "dependency"))
230 {
231 Activation::activation(softwareServer::Activation::Activations::Failed);
232 }
233
234 return;
235}
236
237
Saqib Khanb0774702017-05-23 16:02:41 -0500238} // namespace updater
239} // namespace software
240} // namespace phosphor