Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 1 | #include <fstream> |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame^] | 2 | #include <queue> |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 3 | #include <set> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 4 | #include <string> |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/elog.hpp> |
| 7 | #include <elog-errors.hpp> |
| 8 | #include <xyz/openbmc_project/Software/Version/error.hpp> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 9 | #include "config.h" |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 10 | #include "item_updater.hpp" |
| 11 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 12 | #include <experimental/filesystem> |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 13 | #include "version.hpp" |
Saqib Khan | 5d53267 | 2017-08-09 10:44:50 -0500 | [diff] [blame] | 14 | #include "serialize.hpp" |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace software |
| 19 | { |
| 20 | namespace updater |
| 21 | { |
| 22 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 23 | // When you see server:: you know we're referencing our base class |
| 24 | namespace server = sdbusplus::xyz::openbmc_project::Software::server; |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 25 | namespace control = sdbusplus::xyz::openbmc_project::Control::server; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 26 | |
| 27 | using namespace phosphor::logging; |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 28 | using namespace sdbusplus::xyz::openbmc_project::Software::Version::Error; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 29 | namespace fs = std::experimental::filesystem; |
| 30 | |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 31 | const std::vector<std::string> bmcImages = { "image-kernel", |
| 32 | "image-rofs", |
| 33 | "image-rwfs", |
| 34 | "image-u-boot" }; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 35 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 36 | void ItemUpdater::createActivation(sdbusplus::message::message& msg) |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 37 | { |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 38 | |
| 39 | using SVersion = server::Version; |
| 40 | using VersionPurpose = SVersion::VersionPurpose; |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 41 | using VersionClass = phosphor::software::manager::Version; |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 42 | namespace mesg = sdbusplus::message; |
| 43 | namespace variant_ns = mesg::variant_ns; |
| 44 | |
| 45 | mesg::object_path objPath; |
| 46 | auto purpose = VersionPurpose::Unknown; |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 47 | std::string version; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 48 | std::map<std::string, |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 49 | std::map<std::string, |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 50 | mesg::variant<std::string>>> interfaces; |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 51 | msg.read(objPath, interfaces); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 52 | std::string path(std::move(objPath)); |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 53 | std::string filePath; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 54 | |
| 55 | for (const auto& intf : interfaces) |
| 56 | { |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 57 | if (intf.first == VERSION_IFACE) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 58 | { |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 59 | for (const auto& property : intf.second) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 60 | { |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 61 | if (property.first == "Purpose") |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 62 | { |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 63 | auto value = SVersion::convertVersionPurposeFromString( |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 64 | variant_ns::get<std::string>(property.second)); |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 65 | if (value == VersionPurpose::BMC || |
| 66 | value == VersionPurpose::System) |
| 67 | { |
| 68 | purpose = value; |
| 69 | } |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 70 | } |
| 71 | else if (property.first == "Version") |
| 72 | { |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 73 | version = variant_ns::get<std::string>(property.second); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | } |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 77 | else if (intf.first == FILEPATH_IFACE) |
| 78 | { |
| 79 | for (const auto& property : intf.second) |
| 80 | { |
| 81 | if (property.first == "Path") |
| 82 | { |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 83 | filePath = variant_ns::get<std::string>(property.second); |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | } |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 87 | } |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 88 | if (version.empty() || |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 89 | filePath.empty() || |
Saqib Khan | 84a0e69 | 2017-06-28 17:27:01 -0500 | [diff] [blame] | 90 | purpose == VersionPurpose::Unknown) |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 91 | { |
| 92 | return; |
| 93 | } |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 94 | |
| 95 | // Version id is the last item in the path |
| 96 | auto pos = path.rfind("/"); |
| 97 | if (pos == std::string::npos) |
| 98 | { |
| 99 | log<level::ERR>("No version id found in object path", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 100 | entry("OBJPATH=%s", path.c_str())); |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 101 | return; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | auto versionId = path.substr(pos + 1); |
| 105 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 106 | if (activations.find(versionId) == activations.end()) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 107 | { |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 108 | // Determine the Activation state by processing the given image dir. |
| 109 | auto activationState = server::Activation::Activations::Invalid; |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 110 | ItemUpdater::ActivationStatus result = |
| 111 | ItemUpdater::validateSquashFSImage(filePath); |
Gunnar Mills | 43b25cd | 2017-09-07 13:19:34 -0500 | [diff] [blame] | 112 | AssociationList associations = {}; |
| 113 | |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 114 | if (result == ItemUpdater::ActivationStatus::ready) |
| 115 | { |
| 116 | activationState = server::Activation::Activations::Ready; |
Gunnar Mills | 43b25cd | 2017-09-07 13:19:34 -0500 | [diff] [blame] | 117 | // Create an association to the BMC inventory item |
| 118 | associations.emplace_back(std::make_tuple( |
| 119 | ACTIVATION_FWD_ASSOCIATION, |
| 120 | ACTIVATION_REV_ASSOCIATION, |
| 121 | bmcInventoryPath)); |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 122 | } |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 123 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 124 | activations.insert(std::make_pair( |
| 125 | versionId, |
| 126 | std::make_unique<Activation>( |
| 127 | bus, |
| 128 | path, |
| 129 | *this, |
| 130 | versionId, |
| 131 | activationState, |
| 132 | associations))); |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 133 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 134 | auto versionPtr = std::make_unique<VersionClass>( |
| 135 | bus, |
| 136 | path, |
| 137 | version, |
| 138 | purpose, |
| 139 | filePath, |
| 140 | std::bind(&ItemUpdater::erase, |
| 141 | this, |
| 142 | std::placeholders::_1)); |
| 143 | versionPtr->deleteObject = |
| 144 | std::make_unique<phosphor::software::manager::Delete>( |
| 145 | bus, path, *versionPtr); |
| 146 | versions.insert(std::make_pair(versionId, std::move(versionPtr))); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 147 | } |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 148 | return; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 149 | } |
| 150 | |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 151 | void ItemUpdater::processBMCImage() |
| 152 | { |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 153 | using VersionClass = phosphor::software::manager::Version; |
| 154 | // Read os-release from /etc/ to get the functional BMC version |
| 155 | auto functionalVersion = VersionClass::getBMCVersion(OS_RELEASE_FILE); |
| 156 | |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 157 | // Read os-release from folders under /media/ to get |
| 158 | // BMC Software Versions. |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 159 | for (const auto& iter : fs::directory_iterator(MEDIA_DIR)) |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 160 | { |
| 161 | auto activationState = server::Activation::Activations::Active; |
Saqib Khan | 6fab70d | 2017-09-07 00:13:50 -0500 | [diff] [blame] | 162 | static const auto BMC_RO_PREFIX_LEN = strlen(BMC_ROFS_PREFIX); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 163 | |
| 164 | // Check if the BMC_RO_PREFIXis the prefix of the iter.path |
| 165 | if (0 == iter.path().native().compare(0, BMC_RO_PREFIX_LEN, |
Saqib Khan | 6fab70d | 2017-09-07 00:13:50 -0500 | [diff] [blame] | 166 | BMC_ROFS_PREFIX)) |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 167 | { |
Saqib Khan | 021c365 | 2017-09-26 12:11:02 -0500 | [diff] [blame] | 168 | // The versionId is extracted from the path |
| 169 | // for example /media/ro-2a1022fe. |
| 170 | auto id = iter.path().native().substr(BMC_RO_PREFIX_LEN); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 171 | auto osRelease = iter.path() / OS_RELEASE_FILE; |
| 172 | if (!fs::is_regular_file(osRelease)) |
| 173 | { |
Gunnar Mills | 2ad1b55 | 2017-10-19 15:58:52 -0500 | [diff] [blame] | 174 | log<level::ERR>("Failed to read osRelease", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 175 | entry("FILENAME=%s", osRelease.string().c_str())); |
Saqib Khan | 021c365 | 2017-09-26 12:11:02 -0500 | [diff] [blame] | 176 | ItemUpdater::erase(id); |
| 177 | continue; |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 178 | } |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 179 | auto version = VersionClass::getBMCVersion(osRelease); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 180 | if (version.empty()) |
| 181 | { |
| 182 | log<level::ERR>("Failed to read version from osRelease", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 183 | entry("FILENAME=%s", osRelease.string().c_str())); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 184 | activationState = server::Activation::Activations::Invalid; |
| 185 | } |
Saqib Khan | 021c365 | 2017-09-26 12:11:02 -0500 | [diff] [blame] | 186 | |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 187 | auto purpose = server::Version::VersionPurpose::BMC; |
| 188 | auto path = fs::path(SOFTWARE_OBJPATH) / id; |
| 189 | |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 190 | // Create functional association if this is the functional version |
| 191 | if (version.compare(functionalVersion) == 0) |
| 192 | { |
| 193 | createFunctionalAssociation(path); |
| 194 | } |
| 195 | |
Gunnar Mills | 43b25cd | 2017-09-07 13:19:34 -0500 | [diff] [blame] | 196 | AssociationList associations = {}; |
| 197 | |
| 198 | if (activationState == server::Activation::Activations::Active) |
| 199 | { |
| 200 | // Create an association to the BMC inventory item |
| 201 | associations.emplace_back(std::make_tuple( |
| 202 | ACTIVATION_FWD_ASSOCIATION, |
| 203 | ACTIVATION_REV_ASSOCIATION, |
| 204 | bmcInventoryPath)); |
| 205 | |
| 206 | // Create an active association since this image is active |
| 207 | createActiveAssociation(path); |
| 208 | } |
| 209 | |
Adriana Kobylak | ee590c7 | 2017-09-26 15:16:06 -0500 | [diff] [blame] | 210 | // Create Version instance for this version. |
| 211 | auto versionPtr = std::make_unique<VersionClass>( |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 212 | bus, |
| 213 | path, |
| 214 | version, |
| 215 | purpose, |
| 216 | "", |
| 217 | std::bind(&ItemUpdater::erase, |
| 218 | this, |
| 219 | std::placeholders::_1)); |
Adriana Kobylak | ee590c7 | 2017-09-26 15:16:06 -0500 | [diff] [blame] | 220 | auto isVersionFunctional = versionPtr->isFunctional(); |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 221 | if (!isVersionFunctional) |
| 222 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 223 | versionPtr->deleteObject = |
| 224 | std::make_unique<phosphor::software::manager::Delete>( |
| 225 | bus, path, *versionPtr); |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 226 | } |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 227 | versions.insert(std::make_pair( |
| 228 | id, |
| 229 | std::move(versionPtr))); |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 230 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 231 | // Create Activation instance for this version. |
| 232 | activations.insert(std::make_pair( |
| 233 | id, |
| 234 | std::make_unique<Activation>( |
| 235 | bus, |
| 236 | path, |
| 237 | *this, |
| 238 | id, |
| 239 | activationState, |
| 240 | associations))); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 241 | |
| 242 | // If Active, create RedundancyPriority instance for this version. |
| 243 | if (activationState == server::Activation::Activations::Active) |
| 244 | { |
| 245 | uint8_t priority = std::numeric_limits<uint8_t>::max(); |
| 246 | if (!restoreFromFile(id, priority)) |
| 247 | { |
Adriana Kobylak | ee590c7 | 2017-09-26 15:16:06 -0500 | [diff] [blame] | 248 | if (isVersionFunctional) |
| 249 | { |
| 250 | priority = 0; |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | log<level::ERR>("Unable to restore priority from file.", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 255 | entry("VERSIONID=%s", id.c_str())); |
Adriana Kobylak | ee590c7 | 2017-09-26 15:16:06 -0500 | [diff] [blame] | 256 | } |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 257 | } |
| 258 | activations.find(id)->second->redundancyPriority = |
| 259 | std::make_unique<RedundancyPriority>( |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 260 | bus, |
| 261 | path, |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 262 | *(activations.find(id)->second), |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 263 | priority, |
| 264 | false); |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 265 | } |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 266 | } |
| 267 | } |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 268 | |
| 269 | // If there is no ubi volume for bmc version then read the /etc/os-release |
| 270 | // and create rofs-<versionId> under /media |
| 271 | if (activations.size() == 0) |
| 272 | { |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 273 | auto version = VersionClass::getBMCVersion(OS_RELEASE_FILE); |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 274 | auto id = phosphor::software::manager::Version::getId(version); |
| 275 | auto versionFileDir = BMC_ROFS_PREFIX + id + "/etc/"; |
| 276 | try |
| 277 | { |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 278 | if (!fs::is_directory(versionFileDir)) |
Saqib Khan | dcbfa04 | 2017-09-18 13:08:39 -0500 | [diff] [blame] | 279 | { |
| 280 | fs::create_directories(versionFileDir); |
| 281 | } |
| 282 | auto versionFilePath = BMC_ROFS_PREFIX + id + OS_RELEASE_FILE; |
| 283 | fs::create_directory_symlink(OS_RELEASE_FILE, versionFilePath); |
| 284 | ItemUpdater::processBMCImage(); |
| 285 | } |
| 286 | catch (const std::exception& e) |
| 287 | { |
| 288 | log<level::ERR>(e.what()); |
| 289 | } |
| 290 | } |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 294 | void ItemUpdater::erase(std::string entryId) |
| 295 | { |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 296 | // Find entry in versions map |
| 297 | auto it = versions.find(entryId); |
| 298 | if (it != versions.end()) |
| 299 | { |
| 300 | if (it->second->isFunctional()) |
| 301 | { |
| 302 | log<level::ERR>(("Error: Version " + entryId + \ |
| 303 | " is currently running on the BMC." \ |
| 304 | " Unable to remove.").c_str()); |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 305 | return; |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | // Delete ReadOnly partitions if it's not active |
| 309 | removeReadOnlyPartition(entryId); |
| 310 | removeFile(entryId); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 311 | |
| 312 | // Removing entry in versions map |
| 313 | this->versions.erase(entryId); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 314 | } |
| 315 | else |
| 316 | { |
| 317 | // Delete ReadOnly partitions even if we can't find the version |
| 318 | removeReadOnlyPartition(entryId); |
| 319 | removeFile(entryId); |
| 320 | |
| 321 | log<level::ERR>(("Error: Failed to find version " + entryId + \ |
| 322 | " in item updater versions map." \ |
| 323 | " Unable to remove.").c_str()); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 324 | } |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 325 | |
| 326 | // Remove the priority environment variable. |
| 327 | auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service"; |
| 328 | auto method = bus.new_method_call( |
| 329 | SYSTEMD_BUSNAME, |
| 330 | SYSTEMD_PATH, |
| 331 | SYSTEMD_INTERFACE, |
| 332 | "StartUnit"); |
| 333 | method.append(serviceFile, "replace"); |
| 334 | bus.call_noreply(method); |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 335 | |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 336 | // Removing entry in activations map |
| 337 | auto ita = activations.find(entryId); |
| 338 | if (ita == activations.end()) |
| 339 | { |
| 340 | log<level::ERR>(("Error: Failed to find version " + entryId + \ |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 341 | " in item updater activations map." \ |
| 342 | " Unable to remove.").c_str()); |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 343 | } |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 344 | else |
| 345 | { |
| 346 | this->activations.erase(entryId); |
| 347 | } |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 348 | ItemUpdater::resetUbootEnvVars(); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 349 | return; |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 350 | } |
| 351 | |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 352 | void ItemUpdater::deleteAll() |
| 353 | { |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 354 | for (const auto& versionIt : versions) |
| 355 | { |
| 356 | if (!versionIt.second->isFunctional()) |
| 357 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 358 | ItemUpdater::erase(versionIt.first); |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Michael Tritz | bc1bf3a | 2017-09-18 16:38:23 -0500 | [diff] [blame] | 362 | // Remove any volumes that do not match current versions. |
| 363 | auto method = bus.new_method_call( |
| 364 | SYSTEMD_BUSNAME, |
| 365 | SYSTEMD_PATH, |
| 366 | SYSTEMD_INTERFACE, |
| 367 | "StartUnit"); |
| 368 | method.append("obmc-flash-bmc-cleanup.service", "replace"); |
| 369 | bus.call_noreply(method); |
| 370 | } |
| 371 | |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 372 | ItemUpdater::ActivationStatus ItemUpdater::validateSquashFSImage( |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 373 | const std::string& filePath) |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 374 | { |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 375 | bool invalid = false; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 376 | |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 377 | for (auto& bmcImage : bmcImages) |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 378 | { |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 379 | fs::path file(filePath); |
| 380 | file /= bmcImage; |
| 381 | std::ifstream efile(file.c_str()); |
| 382 | if (efile.good() != 1) |
| 383 | { |
| 384 | log<level::ERR>("Failed to find the BMC image.", |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 385 | entry("IMAGE=%s", bmcImage.c_str())); |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 386 | invalid = true; |
| 387 | } |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 388 | } |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 389 | |
| 390 | if (invalid) |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 391 | { |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 392 | return ItemUpdater::ActivationStatus::invalid; |
| 393 | } |
Michael Tritz | b1cfdf9 | 2017-08-14 14:33:30 -0500 | [diff] [blame] | 394 | |
| 395 | return ItemUpdater::ActivationStatus::ready; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 396 | } |
| 397 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 398 | void ItemUpdater::freePriority(uint8_t value, const std::string& versionId) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 399 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 400 | std::map<std::string, uint8_t> priorityMap; |
| 401 | |
| 402 | // Insert the requested version and priority, it may not exist yet. |
| 403 | priorityMap.insert(std::make_pair(versionId, value)); |
| 404 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 405 | for (const auto& intf : activations) |
| 406 | { |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 407 | if (intf.second->redundancyPriority) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 408 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 409 | priorityMap.insert(std::make_pair( |
| 410 | intf.first, |
| 411 | intf.second->redundancyPriority.get()->priority())); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 412 | } |
| 413 | } |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 414 | |
| 415 | // Lambda function to compare 2 priority values, use <= to allow duplicates |
| 416 | typedef std::function<bool( |
| 417 | std::pair<std::string, uint8_t>, |
| 418 | std::pair<std::string, uint8_t>)> cmpPriority; |
| 419 | cmpPriority cmpPriorityFunc = []( |
| 420 | std::pair<std::string, uint8_t> priority1, |
| 421 | std::pair<std::string, uint8_t> priority2) |
| 422 | { |
| 423 | return priority1.second <= priority2.second; |
| 424 | }; |
| 425 | |
| 426 | // Sort versions by ascending priority |
| 427 | std::set<std::pair<std::string, uint8_t>, cmpPriority> prioritySet( |
| 428 | priorityMap.begin(), priorityMap.end(), cmpPriorityFunc); |
| 429 | |
| 430 | auto freePriorityValue = value; |
| 431 | for (auto& element : prioritySet) |
| 432 | { |
| 433 | if (element.first == versionId) |
| 434 | { |
| 435 | continue; |
| 436 | } |
| 437 | if (element.second == freePriorityValue) |
| 438 | { |
| 439 | ++freePriorityValue; |
| 440 | auto it = activations.find(element.first); |
| 441 | it->second->redundancyPriority.get()->sdbusPriority( |
| 442 | freePriorityValue); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | auto lowestVersion = prioritySet.begin()->first; |
| 447 | if (value == prioritySet.begin()->second) |
| 448 | { |
| 449 | lowestVersion = versionId; |
| 450 | } |
| 451 | updateUbootEnvVars(lowestVersion); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 452 | } |
| 453 | |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 454 | void ItemUpdater::reset() |
| 455 | { |
| 456 | // Mark the read-write partition for recreation upon reboot. |
| 457 | auto method = bus.new_method_call( |
| 458 | SYSTEMD_BUSNAME, |
| 459 | SYSTEMD_PATH, |
| 460 | SYSTEMD_INTERFACE, |
| 461 | "StartUnit"); |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 462 | method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace"); |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 463 | bus.call_noreply(method); |
| 464 | |
| 465 | log<level::INFO>("BMC factory reset will take effect upon reboot."); |
| 466 | |
| 467 | return; |
| 468 | } |
| 469 | |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 470 | void ItemUpdater::removeReadOnlyPartition(std::string versionId) |
| 471 | { |
| 472 | auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + |
| 473 | ".service"; |
| 474 | |
| 475 | // Remove the read-only partitions. |
| 476 | auto method = bus.new_method_call( |
| 477 | SYSTEMD_BUSNAME, |
| 478 | SYSTEMD_PATH, |
| 479 | SYSTEMD_INTERFACE, |
| 480 | "StartUnit"); |
| 481 | method.append(serviceFile, "replace"); |
| 482 | bus.call_noreply(method); |
| 483 | } |
| 484 | |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 485 | bool ItemUpdater::fieldModeEnabled(bool value) |
| 486 | { |
| 487 | // enabling field mode is intended to be one way: false -> true |
| 488 | if (value && !control::FieldMode::fieldModeEnabled()) |
| 489 | { |
| 490 | control::FieldMode::fieldModeEnabled(value); |
| 491 | |
| 492 | auto method = bus.new_method_call( |
| 493 | SYSTEMD_BUSNAME, |
| 494 | SYSTEMD_PATH, |
| 495 | SYSTEMD_INTERFACE, |
| 496 | "StartUnit"); |
| 497 | method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service", |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 498 | "replace"); |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 499 | bus.call_noreply(method); |
| 500 | |
| 501 | method = bus.new_method_call( |
| 502 | SYSTEMD_BUSNAME, |
| 503 | SYSTEMD_PATH, |
| 504 | SYSTEMD_INTERFACE, |
| 505 | "StopUnit"); |
| 506 | method.append("usr-local.mount", "replace"); |
| 507 | bus.call_noreply(method); |
| 508 | |
| 509 | std::vector<std::string> usrLocal = {"usr-local.mount"}; |
| 510 | |
| 511 | method = bus.new_method_call( |
| 512 | SYSTEMD_BUSNAME, |
| 513 | SYSTEMD_PATH, |
| 514 | SYSTEMD_INTERFACE, |
| 515 | "MaskUnitFiles"); |
| 516 | method.append(usrLocal, false, true); |
| 517 | bus.call_noreply(method); |
| 518 | } |
| 519 | |
| 520 | return control::FieldMode::fieldModeEnabled(); |
| 521 | } |
| 522 | |
| 523 | void ItemUpdater::restoreFieldModeStatus() |
| 524 | { |
Michael Tritz | ff0b421 | 2017-10-24 17:38:09 -0500 | [diff] [blame] | 525 | std::ifstream input("/dev/mtd/u-boot-env"); |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 526 | std::string envVar; |
| 527 | std::getline(input, envVar); |
| 528 | |
Gunnar Mills | 9a78224 | 2017-08-22 16:23:15 -0500 | [diff] [blame] | 529 | if (envVar.find("fieldmode=true") != std::string::npos) |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 530 | { |
| 531 | ItemUpdater::fieldModeEnabled(true); |
| 532 | } |
| 533 | } |
| 534 | |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 535 | void ItemUpdater::setBMCInventoryPath() |
| 536 | { |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 537 | auto depth = 0; |
| 538 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, |
| 539 | MAPPER_PATH, |
| 540 | MAPPER_INTERFACE, |
| 541 | "GetSubTreePaths"); |
| 542 | |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 543 | mapperCall.append(INVENTORY_PATH); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 544 | mapperCall.append(depth); |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 545 | std::vector<std::string> filter = {BMC_INVENTORY_INTERFACE}; |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 546 | mapperCall.append(filter); |
| 547 | |
| 548 | auto response = bus.call(mapperCall); |
| 549 | if (response.is_method_error()) |
| 550 | { |
| 551 | log<level::ERR>("Error in mapper GetSubTreePath"); |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | using ObjectPaths = std::vector<std::string>; |
| 556 | ObjectPaths result; |
| 557 | response.read(result); |
| 558 | |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 559 | if (!result.empty()) |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 560 | { |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 561 | bmcInventoryPath = result.front(); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 562 | } |
| 563 | |
Adriana Kobylak | 1254c62 | 2017-12-07 12:24:56 -0600 | [diff] [blame] | 564 | return; |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 565 | } |
| 566 | |
Gunnar Mills | f10b232 | 2017-09-21 15:31:55 -0500 | [diff] [blame] | 567 | void ItemUpdater::createActiveAssociation(const std::string& path) |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 568 | { |
| 569 | assocs.emplace_back(std::make_tuple(ACTIVE_FWD_ASSOCIATION, |
| 570 | ACTIVE_REV_ASSOCIATION, |
| 571 | path)); |
| 572 | associations(assocs); |
| 573 | } |
| 574 | |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 575 | void ItemUpdater::createFunctionalAssociation(const std::string& path) |
| 576 | { |
| 577 | assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION, |
| 578 | FUNCTIONAL_REV_ASSOCIATION, |
| 579 | path)); |
| 580 | associations(assocs); |
| 581 | } |
| 582 | |
Gunnar Mills | f10b232 | 2017-09-21 15:31:55 -0500 | [diff] [blame] | 583 | void ItemUpdater::removeActiveAssociation(const std::string& path) |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 584 | { |
| 585 | for (auto iter = assocs.begin(); iter != assocs.end();) |
| 586 | { |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 587 | // Since there could be multiple associations to the same path, |
| 588 | // only remove ones that have an active forward association. |
| 589 | if ((std::get<0>(*iter)).compare(ACTIVE_FWD_ASSOCIATION) == 0 && |
| 590 | (std::get<2>(*iter)).compare(path) == 0) |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 591 | { |
| 592 | iter = assocs.erase(iter); |
| 593 | associations(assocs); |
| 594 | } |
| 595 | else |
| 596 | { |
| 597 | ++iter; |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 602 | bool ItemUpdater::isLowestPriority(uint8_t value) |
| 603 | { |
| 604 | for (const auto& intf : activations) |
| 605 | { |
Gunnar Mills | d16bcbd | 2017-10-08 16:50:42 -0500 | [diff] [blame] | 606 | if (intf.second->redundancyPriority) |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 607 | { |
| 608 | if (intf.second->redundancyPriority.get()->priority() < value) |
| 609 | { |
| 610 | return false; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | return true; |
| 615 | } |
| 616 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 617 | void ItemUpdater::updateUbootEnvVars(const std::string& versionId) |
| 618 | { |
| 619 | auto method = bus.new_method_call( |
| 620 | SYSTEMD_BUSNAME, |
| 621 | SYSTEMD_PATH, |
| 622 | SYSTEMD_INTERFACE, |
| 623 | "StartUnit"); |
| 624 | auto updateEnvVarsFile = "obmc-flash-bmc-updateubootvars@" + versionId + |
| 625 | ".service"; |
| 626 | method.append(updateEnvVarsFile, "replace"); |
| 627 | auto result = bus.call(method); |
| 628 | |
| 629 | //Check that the bus call didn't result in an error |
| 630 | if (result.is_method_error()) |
| 631 | { |
| 632 | log<level::ERR>("Failed to update u-boot env variables", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 633 | entry("VERSIONID=%s", versionId.c_str())); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 637 | void ItemUpdater::resetUbootEnvVars() |
| 638 | { |
| 639 | decltype(activations.begin()->second->redundancyPriority.get()->priority()) |
| 640 | lowestPriority = std::numeric_limits<uint8_t>::max(); |
| 641 | decltype(activations.begin()->second->versionId) lowestPriorityVersion; |
| 642 | for (const auto& intf : activations) |
| 643 | { |
| 644 | if (!intf.second->redundancyPriority.get()) |
| 645 | { |
| 646 | // Skip this version if the redundancyPriority is not initialized. |
| 647 | continue; |
| 648 | } |
| 649 | |
| 650 | if (intf.second->redundancyPriority.get()->priority() |
| 651 | <= lowestPriority) |
| 652 | { |
| 653 | lowestPriority = intf.second->redundancyPriority.get()->priority(); |
| 654 | lowestPriorityVersion = intf.second->versionId; |
| 655 | } |
| 656 | } |
| 657 | |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 658 | // Update the U-boot environment variable to point to the lowest priority |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 659 | updateUbootEnvVars(lowestPriorityVersion); |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 660 | } |
| 661 | |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame^] | 662 | void ItemUpdater::freeSpace() |
| 663 | { |
| 664 | // Versions with the highest priority in front |
| 665 | std::priority_queue<std::pair<int, std::string>, |
| 666 | std::vector<std::pair<int, std::string>>, |
| 667 | std::less<std::pair<int, std::string>>> versionsPQ; |
| 668 | |
| 669 | std::size_t count = 0; |
| 670 | for (const auto& iter : activations) |
| 671 | { |
| 672 | if ((iter.second.get()->activation() == |
| 673 | server::Activation::Activations::Active) || |
| 674 | (iter.second.get()->activation() == |
| 675 | server::Activation::Activations::Failed)) |
| 676 | { |
| 677 | count++; |
| 678 | // Don't put the functional version on the queue since we can't |
| 679 | // remove the "running" BMC version. |
| 680 | if (versions.find(iter.second->versionId)->second->isFunctional()) |
| 681 | { |
| 682 | continue; |
| 683 | } |
| 684 | versionsPQ.push(std::make_pair( |
| 685 | iter.second->redundancyPriority.get()->priority(), |
| 686 | iter.second->versionId)); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | // If the number of BMC versions is over ACTIVE_BMC_MAX_ALLOWED -1, |
| 691 | // remove the highest priority one(s). |
| 692 | while ((count >= ACTIVE_BMC_MAX_ALLOWED) && (!versionsPQ.empty())) |
| 693 | { |
| 694 | erase(versionsPQ.top().second); |
| 695 | versionsPQ.pop(); |
| 696 | count--; |
| 697 | } |
| 698 | } |
| 699 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 700 | } // namespace updater |
| 701 | } // namespace software |
| 702 | } // namespace phosphor |