blob: 85fc8edd0dbb3cf6a36d5b2ba672dbd34c66fab2 [file] [log] [blame]
Saqib Khan35e83f32017-05-22 11:37:32 -05001#include <fstream>
Gunnar Millsec1b41c2017-05-02 12:20:36 -05002#include <string>
Gunnar Mills2ce7da22017-05-04 15:37:56 -05003#include <phosphor-logging/log.hpp>
Gunnar Millsec1b41c2017-05-02 12:20:36 -05004#include "config.h"
Gunnar Mills2ce7da22017-05-04 15:37:56 -05005#include "item_updater.hpp"
6#include "xyz/openbmc_project/Software/Version/server.hpp"
Saqib Khan35e83f32017-05-22 11:37:32 -05007#include <experimental/filesystem>
Saqib Khan705f1bf2017-06-09 23:58:38 -05008#include "version.hpp"
Saqib Khan5d532672017-08-09 10:44:50 -05009#include "serialize.hpp"
Gunnar Millsec1b41c2017-05-02 12:20:36 -050010
11namespace phosphor
12{
13namespace software
14{
15namespace updater
16{
17
Gunnar Mills2ce7da22017-05-04 15:37:56 -050018// When you see server:: you know we're referencing our base class
19namespace server = sdbusplus::xyz::openbmc_project::Software::server;
Michael Tritz0129d922017-08-10 19:33:46 -050020namespace control = sdbusplus::xyz::openbmc_project::Control::server;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050021
22using namespace phosphor::logging;
Saqib Khan35e83f32017-05-22 11:37:32 -050023namespace fs = std::experimental::filesystem;
24
Gunnar Mills9a782242017-08-22 16:23:15 -050025const std::vector<std::string> bmcImages = { "image-kernel",
26 "image-rofs",
27 "image-rwfs",
28 "image-u-boot" };
Gunnar Mills2ce7da22017-05-04 15:37:56 -050029
Patrick Williamse75d10f2017-05-30 16:56:32 -050030void ItemUpdater::createActivation(sdbusplus::message::message& msg)
Gunnar Millsec1b41c2017-05-02 12:20:36 -050031{
Saqib Khan84a0e692017-06-28 17:27:01 -050032
33 using SVersion = server::Version;
34 using VersionPurpose = SVersion::VersionPurpose;
Gunnar Mills9a782242017-08-22 16:23:15 -050035 using VersionClass = phosphor::software::manager::Version;
Saqib Khan84a0e692017-06-28 17:27:01 -050036 namespace mesg = sdbusplus::message;
37 namespace variant_ns = mesg::variant_ns;
38
39 mesg::object_path objPath;
40 auto purpose = VersionPurpose::Unknown;
Saqib Khan705f1bf2017-06-09 23:58:38 -050041 std::string version;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050042 std::map<std::string,
Patrick Williamse75d10f2017-05-30 16:56:32 -050043 std::map<std::string,
Saqib Khan84a0e692017-06-28 17:27:01 -050044 mesg::variant<std::string>>> interfaces;
Patrick Williamse75d10f2017-05-30 16:56:32 -050045 msg.read(objPath, interfaces);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050046 std::string path(std::move(objPath));
Saqib Khan19177d32017-06-20 08:11:49 -050047 std::string filePath;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050048
49 for (const auto& intf : interfaces)
50 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050051 if (intf.first == VERSION_IFACE)
Gunnar Mills2ce7da22017-05-04 15:37:56 -050052 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050053 for (const auto& property : intf.second)
Gunnar Mills2ce7da22017-05-04 15:37:56 -050054 {
Saqib Khan705f1bf2017-06-09 23:58:38 -050055 if (property.first == "Purpose")
Gunnar Mills2ce7da22017-05-04 15:37:56 -050056 {
Saqib Khan84a0e692017-06-28 17:27:01 -050057 auto value = SVersion::convertVersionPurposeFromString(
Gunnar Mills9a782242017-08-22 16:23:15 -050058 variant_ns::get<std::string>(property.second));
Saqib Khan84a0e692017-06-28 17:27:01 -050059 if (value == VersionPurpose::BMC ||
60 value == VersionPurpose::System)
61 {
62 purpose = value;
63 }
Saqib Khan705f1bf2017-06-09 23:58:38 -050064 }
65 else if (property.first == "Version")
66 {
Saqib Khan84a0e692017-06-28 17:27:01 -050067 version = variant_ns::get<std::string>(property.second);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050068 }
69 }
70 }
Saqib Khan19177d32017-06-20 08:11:49 -050071 else if (intf.first == FILEPATH_IFACE)
72 {
73 for (const auto& property : intf.second)
74 {
75 if (property.first == "Path")
76 {
Saqib Khan84a0e692017-06-28 17:27:01 -050077 filePath = variant_ns::get<std::string>(property.second);
Saqib Khan19177d32017-06-20 08:11:49 -050078 }
79 }
80 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -050081 }
Saqib Khan705f1bf2017-06-09 23:58:38 -050082 if (version.empty() ||
Saqib Khan19177d32017-06-20 08:11:49 -050083 filePath.empty() ||
Saqib Khan84a0e692017-06-28 17:27:01 -050084 purpose == VersionPurpose::Unknown)
Saqib Khan705f1bf2017-06-09 23:58:38 -050085 {
86 return;
87 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -050088
89 // Version id is the last item in the path
90 auto pos = path.rfind("/");
91 if (pos == std::string::npos)
92 {
93 log<level::ERR>("No version id found in object path",
94 entry("OBJPATH=%s", path));
Patrick Williamse75d10f2017-05-30 16:56:32 -050095 return;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050096 }
97
98 auto versionId = path.substr(pos + 1);
99
Patrick Williamse75d10f2017-05-30 16:56:32 -0500100 if (activations.find(versionId) == activations.end())
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500101 {
Saqib Khan35e83f32017-05-22 11:37:32 -0500102 // Determine the Activation state by processing the given image dir.
103 auto activationState = server::Activation::Activations::Invalid;
Gunnar Mills9a782242017-08-22 16:23:15 -0500104 ItemUpdater::ActivationStatus result =
105 ItemUpdater::validateSquashFSImage(filePath);
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500106 AssociationList associations = {};
107
Saqib Khan35e83f32017-05-22 11:37:32 -0500108 if (result == ItemUpdater::ActivationStatus::ready)
109 {
110 activationState = server::Activation::Activations::Ready;
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500111 // Create an association to the BMC inventory item
112 associations.emplace_back(std::make_tuple(
113 ACTIVATION_FWD_ASSOCIATION,
114 ACTIVATION_REV_ASSOCIATION,
115 bmcInventoryPath));
Saqib Khan35e83f32017-05-22 11:37:32 -0500116 }
Gunnar Millsb60add12017-08-24 16:41:42 -0500117
Saqib Khan35e83f32017-05-22 11:37:32 -0500118 activations.insert(std::make_pair(
Saqib Khan705f1bf2017-06-09 23:58:38 -0500119 versionId,
120 std::make_unique<Activation>(
121 bus,
122 path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500123 *this,
Saqib Khan35e83f32017-05-22 11:37:32 -0500124 versionId,
Gunnar Millsb60add12017-08-24 16:41:42 -0500125 activationState,
126 associations)));
Saqib Khan705f1bf2017-06-09 23:58:38 -0500127 versions.insert(std::make_pair(
128 versionId,
Gunnar Mills9a782242017-08-22 16:23:15 -0500129 std::make_unique<VersionClass>(
Saqib Khan705f1bf2017-06-09 23:58:38 -0500130 bus,
131 path,
132 version,
133 purpose,
Eddie James9440f492017-08-30 11:34:16 -0500134 filePath)));
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500135 }
Saqib Khan7b5010f2017-08-09 10:03:11 -0500136 else
137 {
138 log<level::INFO>("Software Object with the same version already exists",
Gunnar Mills9a782242017-08-22 16:23:15 -0500139 entry("VERSION_ID=%s", versionId));
Saqib Khan7b5010f2017-08-09 10:03:11 -0500140 }
Patrick Williamse75d10f2017-05-30 16:56:32 -0500141 return;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500142}
143
Saqib Khanba239882017-05-26 08:41:54 -0500144void ItemUpdater::processBMCImage()
145{
Gunnar Mills88e8a322017-09-13 11:09:28 -0500146 using VersionClass = phosphor::software::manager::Version;
147 // Read os-release from /etc/ to get the functional BMC version
148 auto functionalVersion = VersionClass::getBMCVersion(OS_RELEASE_FILE);
149
Saqib Khan1eef62d2017-08-10 15:29:34 -0500150 // Read os-release from folders under /media/ to get
151 // BMC Software Versions.
152 for(const auto& iter : fs::directory_iterator(MEDIA_DIR))
153 {
154 auto activationState = server::Activation::Activations::Active;
Saqib Khan6fab70d2017-09-07 00:13:50 -0500155 static const auto BMC_RO_PREFIX_LEN = strlen(BMC_ROFS_PREFIX);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500156
157 // Check if the BMC_RO_PREFIXis the prefix of the iter.path
158 if (0 == iter.path().native().compare(0, BMC_RO_PREFIX_LEN,
Saqib Khan6fab70d2017-09-07 00:13:50 -0500159 BMC_ROFS_PREFIX))
Saqib Khan1eef62d2017-08-10 15:29:34 -0500160 {
Saqib Khan021c3652017-09-26 12:11:02 -0500161 // The versionId is extracted from the path
162 // for example /media/ro-2a1022fe.
163 auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500164 auto osRelease = iter.path() / OS_RELEASE_FILE;
165 if (!fs::is_regular_file(osRelease))
166 {
167 log<level::ERR>("Failed to read osRelease\n",
168 entry("FileName=%s", osRelease.string()));
Saqib Khan021c3652017-09-26 12:11:02 -0500169 ItemUpdater::erase(id);
170 continue;
Saqib Khan1eef62d2017-08-10 15:29:34 -0500171 }
Gunnar Mills88e8a322017-09-13 11:09:28 -0500172 auto version = VersionClass::getBMCVersion(osRelease);
Saqib Khan1eef62d2017-08-10 15:29:34 -0500173 if (version.empty())
174 {
175 log<level::ERR>("Failed to read version from osRelease",
176 entry("FILENAME=%s", osRelease.string()));
177 activationState = server::Activation::Activations::Invalid;
178 }
Saqib Khan021c3652017-09-26 12:11:02 -0500179
Saqib Khan1eef62d2017-08-10 15:29:34 -0500180 auto purpose = server::Version::VersionPurpose::BMC;
181 auto path = fs::path(SOFTWARE_OBJPATH) / id;
182
Gunnar Mills88e8a322017-09-13 11:09:28 -0500183 // Create functional association if this is the functional version
184 if (version.compare(functionalVersion) == 0)
185 {
186 createFunctionalAssociation(path);
187 }
188
Gunnar Mills43b25cd2017-09-07 13:19:34 -0500189 AssociationList associations = {};
190
191 if (activationState == server::Activation::Activations::Active)
192 {
193 // Create an association to the BMC inventory item
194 associations.emplace_back(std::make_tuple(
195 ACTIVATION_FWD_ASSOCIATION,
196 ACTIVATION_REV_ASSOCIATION,
197 bmcInventoryPath));
198
199 // Create an active association since this image is active
200 createActiveAssociation(path);
201 }
202
Saqib Khan1eef62d2017-08-10 15:29:34 -0500203 // Create Activation instance for this version.
204 activations.insert(std::make_pair(
205 id,
206 std::make_unique<Activation>(
207 bus,
208 path,
209 *this,
210 id,
211 server::Activation::Activations::Active,
212 associations)));
213
214 // If Active, create RedundancyPriority instance for this version.
215 if (activationState == server::Activation::Activations::Active)
216 {
217 uint8_t priority = std::numeric_limits<uint8_t>::max();
218 if (!restoreFromFile(id, priority))
219 {
220 log<level::ERR>("Unable to restore priority from file.",
221 entry("VERSIONID=%s", id));
222 }
223 activations.find(id)->second->redundancyPriority =
224 std::make_unique<RedundancyPriority>(
Saqib Khanba239882017-05-26 08:41:54 -0500225 bus,
226 path,
Saqib Khan1eef62d2017-08-10 15:29:34 -0500227 *(activations.find(id)->second),
228 priority);
229 }
230
231 // Create Version instance for this version.
232 versions.insert(std::make_pair(
233 id,
234 std::make_unique<
235 phosphor::software::manager::Version>(
236 bus,
237 path,
238 version,
239 purpose,
Eddie James9440f492017-08-30 11:34:16 -0500240 "")));
Saqib Khan1eef62d2017-08-10 15:29:34 -0500241 }
242 }
Saqib Khanba239882017-05-26 08:41:54 -0500243 return;
244}
245
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500246void ItemUpdater::erase(std::string entryId)
247{
Eddie James6d873712017-09-01 11:29:07 -0500248 // Find entry in versions map
249 auto it = versions.find(entryId);
250 if (it != versions.end())
251 {
252 if (it->second->isFunctional())
253 {
254 log<level::ERR>(("Error: Version " + entryId + \
255 " is currently running on the BMC." \
256 " Unable to remove.").c_str());
257 return;
258 }
259
260 // Delete ReadOnly partitions if it's not active
261 removeReadOnlyPartition(entryId);
262 removeFile(entryId);
263 }
264 else
265 {
266 // Delete ReadOnly partitions even if we can't find the version
267 removeReadOnlyPartition(entryId);
268 removeFile(entryId);
269
270 log<level::ERR>(("Error: Failed to find version " + entryId + \
271 " in item updater versions map." \
272 " Unable to remove.").c_str());
273 return;
274 }
Saqib Khan1eef62d2017-08-10 15:29:34 -0500275
276 // Remove the priority environment variable.
277 auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service";
278 auto method = bus.new_method_call(
279 SYSTEMD_BUSNAME,
280 SYSTEMD_PATH,
281 SYSTEMD_INTERFACE,
282 "StartUnit");
283 method.append(serviceFile, "replace");
284 bus.call_noreply(method);
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500285
286 // Removing entry in versions map
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500287 this->versions.erase(entryId);
288
289 // Removing entry in activations map
290 auto ita = activations.find(entryId);
291 if (ita == activations.end())
292 {
293 log<level::ERR>(("Error: Failed to find version " + entryId + \
Gunnar Mills9a782242017-08-22 16:23:15 -0500294 " in item updater activations map." \
295 " Unable to remove.").c_str());
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500296 return;
297 }
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500298
299 this->activations.erase(entryId);
300}
301
Michael Tritzbc1bf3a2017-09-18 16:38:23 -0500302void ItemUpdater::deleteAll()
303{
304 std::vector<std::string> deletableVersions;
305
306 for (const auto& versionIt : versions)
307 {
308 if (!versionIt.second->isFunctional())
309 {
310 deletableVersions.push_back(versionIt.first);
311 }
312 }
313
314 for (const auto& deletableIt : deletableVersions)
315 {
316 ItemUpdater::erase(deletableIt);
317 }
318
319 // Remove any volumes that do not match current versions.
320 auto method = bus.new_method_call(
321 SYSTEMD_BUSNAME,
322 SYSTEMD_PATH,
323 SYSTEMD_INTERFACE,
324 "StartUnit");
325 method.append("obmc-flash-bmc-cleanup.service", "replace");
326 bus.call_noreply(method);
327}
328
Saqib Khan35e83f32017-05-22 11:37:32 -0500329ItemUpdater::ActivationStatus ItemUpdater::validateSquashFSImage(
Gunnar Mills9a782242017-08-22 16:23:15 -0500330 const std::string& filePath)
Saqib Khan35e83f32017-05-22 11:37:32 -0500331{
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500332 bool invalid = false;
Saqib Khan35e83f32017-05-22 11:37:32 -0500333
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500334 for (auto& bmcImage : bmcImages)
Saqib Khan35e83f32017-05-22 11:37:32 -0500335 {
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500336 fs::path file(filePath);
337 file /= bmcImage;
338 std::ifstream efile(file.c_str());
339 if (efile.good() != 1)
340 {
341 log<level::ERR>("Failed to find the BMC image.",
Gunnar Mills9a782242017-08-22 16:23:15 -0500342 entry("IMAGE=%s", bmcImage.c_str()));
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500343 invalid = true;
344 }
Saqib Khan35e83f32017-05-22 11:37:32 -0500345 }
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500346
347 if (invalid)
Saqib Khan35e83f32017-05-22 11:37:32 -0500348 {
Saqib Khan35e83f32017-05-22 11:37:32 -0500349 return ItemUpdater::ActivationStatus::invalid;
350 }
Michael Tritzb1cfdf92017-08-14 14:33:30 -0500351
352 return ItemUpdater::ActivationStatus::ready;
Saqib Khan35e83f32017-05-22 11:37:32 -0500353}
354
Saqib Khanb9da6632017-09-13 09:48:37 -0500355void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500356{
357 //TODO openbmc/openbmc#1896 Improve the performance of this function
358 for (const auto& intf : activations)
359 {
Gunnar Mills9a782242017-08-22 16:23:15 -0500360 if (intf.second->redundancyPriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500361 {
Saqib Khanb9da6632017-09-13 09:48:37 -0500362 if (intf.second->redundancyPriority.get()->priority() == value &&
363 intf.second->versionId != versionId)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500364 {
Gunnar Mills9a782242017-08-22 16:23:15 -0500365 intf.second->redundancyPriority.get()->priority(value + 1);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500366 }
367 }
368 }
369}
370
Michael Tritz37a59042017-07-12 13:44:53 -0500371void ItemUpdater::reset()
372{
373 // Mark the read-write partition for recreation upon reboot.
374 auto method = bus.new_method_call(
375 SYSTEMD_BUSNAME,
376 SYSTEMD_PATH,
377 SYSTEMD_INTERFACE,
378 "StartUnit");
Michael Tritz0129d922017-08-10 19:33:46 -0500379 method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace");
Michael Tritz37a59042017-07-12 13:44:53 -0500380 bus.call_noreply(method);
381
382 log<level::INFO>("BMC factory reset will take effect upon reboot.");
383
384 return;
385}
386
Leonel Gonzalez3526ef72017-07-07 14:38:25 -0500387void ItemUpdater::removeReadOnlyPartition(std::string versionId)
388{
389 auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId +
390 ".service";
391
392 // Remove the read-only partitions.
393 auto method = bus.new_method_call(
394 SYSTEMD_BUSNAME,
395 SYSTEMD_PATH,
396 SYSTEMD_INTERFACE,
397 "StartUnit");
398 method.append(serviceFile, "replace");
399 bus.call_noreply(method);
400}
401
Michael Tritz0129d922017-08-10 19:33:46 -0500402bool ItemUpdater::fieldModeEnabled(bool value)
403{
404 // enabling field mode is intended to be one way: false -> true
405 if (value && !control::FieldMode::fieldModeEnabled())
406 {
407 control::FieldMode::fieldModeEnabled(value);
408
409 auto method = bus.new_method_call(
410 SYSTEMD_BUSNAME,
411 SYSTEMD_PATH,
412 SYSTEMD_INTERFACE,
413 "StartUnit");
414 method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service",
Gunnar Mills9a782242017-08-22 16:23:15 -0500415 "replace");
Michael Tritz0129d922017-08-10 19:33:46 -0500416 bus.call_noreply(method);
417
418 method = bus.new_method_call(
419 SYSTEMD_BUSNAME,
420 SYSTEMD_PATH,
421 SYSTEMD_INTERFACE,
422 "StopUnit");
423 method.append("usr-local.mount", "replace");
424 bus.call_noreply(method);
425
426 std::vector<std::string> usrLocal = {"usr-local.mount"};
427
428 method = bus.new_method_call(
429 SYSTEMD_BUSNAME,
430 SYSTEMD_PATH,
431 SYSTEMD_INTERFACE,
432 "MaskUnitFiles");
433 method.append(usrLocal, false, true);
434 bus.call_noreply(method);
435 }
436
437 return control::FieldMode::fieldModeEnabled();
438}
439
440void ItemUpdater::restoreFieldModeStatus()
441{
442 std::ifstream input("/run/fw_env");
443 std::string envVar;
444 std::getline(input, envVar);
445
Gunnar Mills9a782242017-08-22 16:23:15 -0500446 if (envVar.find("fieldmode=true") != std::string::npos)
Michael Tritz0129d922017-08-10 19:33:46 -0500447 {
448 ItemUpdater::fieldModeEnabled(true);
449 }
450}
451
Gunnar Millsb60add12017-08-24 16:41:42 -0500452void ItemUpdater::setBMCInventoryPath()
453{
454 //TODO: openbmc/openbmc#1786 - Get the BMC path by looking for objects
455 // that implement the BMC inventory interface
456 auto depth = 0;
457 auto mapperCall = bus.new_method_call(MAPPER_BUSNAME,
458 MAPPER_PATH,
459 MAPPER_INTERFACE,
460 "GetSubTreePaths");
461
462 mapperCall.append(CHASSIS_INVENTORY_PATH);
463 mapperCall.append(depth);
464
465 // TODO: openbmc/openbmc#2226 - Add Inventory Item filter when
466 // mapper is fixed.
467 std::vector<std::string> filter = {};
468 mapperCall.append(filter);
469
470 auto response = bus.call(mapperCall);
471 if (response.is_method_error())
472 {
473 log<level::ERR>("Error in mapper GetSubTreePath");
474 return;
475 }
476
477 using ObjectPaths = std::vector<std::string>;
478 ObjectPaths result;
479 response.read(result);
480
481 if (result.empty())
482 {
483 log<level::ERR>("Invalid response from mapper");
484 return;
485 }
486
487 for (auto& iter : result)
488 {
489 const auto& path = iter;
490 if (path.substr(path.find_last_of('/') + 1).compare("bmc") == 0)
491 {
492 bmcInventoryPath = path;
493 return;
494 }
495 }
496}
497
Gunnar Millsf10b2322017-09-21 15:31:55 -0500498void ItemUpdater::createActiveAssociation(const std::string& path)
Gunnar Millsded875d2017-08-28 16:44:52 -0500499{
500 assocs.emplace_back(std::make_tuple(ACTIVE_FWD_ASSOCIATION,
501 ACTIVE_REV_ASSOCIATION,
502 path));
503 associations(assocs);
504}
505
Gunnar Mills88e8a322017-09-13 11:09:28 -0500506void ItemUpdater::createFunctionalAssociation(const std::string& path)
507{
508 assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION,
509 FUNCTIONAL_REV_ASSOCIATION,
510 path));
511 associations(assocs);
512}
513
Gunnar Millsf10b2322017-09-21 15:31:55 -0500514void ItemUpdater::removeActiveAssociation(const std::string& path)
Gunnar Millsded875d2017-08-28 16:44:52 -0500515{
516 for (auto iter = assocs.begin(); iter != assocs.end();)
517 {
Gunnar Mills88e8a322017-09-13 11:09:28 -0500518 // Since there could be multiple associations to the same path,
519 // only remove ones that have an active forward association.
520 if ((std::get<0>(*iter)).compare(ACTIVE_FWD_ASSOCIATION) == 0 &&
521 (std::get<2>(*iter)).compare(path) == 0)
Gunnar Millsded875d2017-08-28 16:44:52 -0500522 {
523 iter = assocs.erase(iter);
524 associations(assocs);
525 }
526 else
527 {
528 ++iter;
529 }
530 }
531}
532
Saqib Khanb9da6632017-09-13 09:48:37 -0500533bool ItemUpdater::isLowestPriority(uint8_t value)
534{
535 for (const auto& intf : activations)
536 {
537 if(intf.second->redundancyPriority)
538 {
539 if (intf.second->redundancyPriority.get()->priority() < value)
540 {
541 return false;
542 }
543 }
544 }
545 return true;
546}
547
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500548} // namespace updater
549} // namespace software
550} // namespace phosphor